test: stabilize scoped runners and qa ports

This commit is contained in:
Peter Steinberger
2026-04-07 15:28:10 +01:00
parent 067f158b74
commit a3d5630232
7 changed files with 131 additions and 4 deletions
@@ -1,9 +1,35 @@
import { mkdtemp, readFile, rm } from "node:fs/promises"; import { mkdtemp, readFile, rm } from "node:fs/promises";
import { createServer } from "node:net";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { runQaDockerUp } from "./docker-up.runtime.js"; import { runQaDockerUp } from "./docker-up.runtime.js";
async function occupyPortOrAcceptExisting(port: number): Promise<{ close: () => Promise<void> }> {
const server = createServer();
const listening = await new Promise<boolean>((resolve, reject) => {
server.once("error", (error: NodeJS.ErrnoException) => {
if (error.code === "EADDRINUSE") {
resolve(false);
return;
}
reject(error);
});
server.listen(port, "127.0.0.1", () => resolve(true));
});
return {
close: async () => {
if (!listening) {
return;
}
await new Promise<void>((resolve, reject) =>
server.close((error) => (error ? reject(error) : resolve())),
);
},
};
}
describe("runQaDockerUp", () => { describe("runQaDockerUp", () => {
it("builds the QA UI, writes the harness, starts compose, and waits for health", async () => { it("builds the QA UI, writes the harness, starts compose, and waits for health", async () => {
const calls: string[] = []; const calls: string[] = [];
@@ -109,6 +135,8 @@ describe("runQaDockerUp", () => {
} }
return preferredPort; return preferredPort;
}); });
const gatewayPortReservation = await occupyPortOrAcceptExisting(18789);
const qaLabPortReservation = await occupyPortOrAcceptExisting(43124);
try { try {
const result = await runQaDockerUp( const result = await runQaDockerUp(
@@ -138,6 +166,8 @@ describe("runQaDockerUp", () => {
expect(result.gatewayUrl).toBe("http://127.0.0.1:28001/"); expect(result.gatewayUrl).toBe("http://127.0.0.1:28001/");
expect(result.qaLabUrl).toBe("http://127.0.0.1:28002"); expect(result.qaLabUrl).toBe("http://127.0.0.1:28002");
} finally { } finally {
await gatewayPortReservation.close();
await qaLabPortReservation.close();
await rm(outputDir, { recursive: true, force: true }); await rm(outputDir, { recursive: true, force: true });
} }
}); });
@@ -440,6 +440,7 @@ describe("dispatchReplyFromConfig ACP abort", () => {
acpMocks.listAcpSessionEntries.mockReset().mockResolvedValue([]); acpMocks.listAcpSessionEntries.mockReset().mockResolvedValue([]);
acpMocks.readAcpSessionEntry.mockReset().mockReturnValue(null); acpMocks.readAcpSessionEntry.mockReset().mockReturnValue(null);
acpMocks.upsertAcpSessionMeta.mockReset().mockResolvedValue(null); acpMocks.upsertAcpSessionMeta.mockReset().mockResolvedValue(null);
acpMocks.getAcpRuntimeBackend.mockReset();
acpMocks.requireAcpRuntimeBackend.mockReset(); acpMocks.requireAcpRuntimeBackend.mockReset();
sessionBindingMocks.listBySession.mockReset().mockReturnValue([]); sessionBindingMocks.listBySession.mockReset().mockReturnValue([]);
sessionBindingMocks.resolveByConversation.mockReset().mockReturnValue(null); sessionBindingMocks.resolveByConversation.mockReset().mockReturnValue(null);
@@ -617,6 +617,7 @@ describe("dispatchReplyFromConfig", () => {
acpMocks.readAcpSessionEntry.mockReturnValue(null); acpMocks.readAcpSessionEntry.mockReturnValue(null);
acpMocks.upsertAcpSessionMeta.mockReset(); acpMocks.upsertAcpSessionMeta.mockReset();
acpMocks.upsertAcpSessionMeta.mockResolvedValue(null); acpMocks.upsertAcpSessionMeta.mockResolvedValue(null);
acpMocks.getAcpRuntimeBackend.mockReset();
acpMocks.requireAcpRuntimeBackend.mockReset(); acpMocks.requireAcpRuntimeBackend.mockReset();
agentEventMocks.emitAgentEvent.mockReset(); agentEventMocks.emitAgentEvent.mockReset();
agentEventMocks.onAgentEvent.mockReset(); agentEventMocks.onAgentEvent.mockReset();
+2 -2
View File
@@ -635,10 +635,10 @@ describe("test-projects args", () => {
]); ]);
}); });
it("routes browser extension targets to the extension channel config", () => { it("routes browser extension targets to the extensions config", () => {
expect(buildVitestRunPlans(["extensions/browser/index.test.ts"])).toEqual([ expect(buildVitestRunPlans(["extensions/browser/index.test.ts"])).toEqual([
{ {
config: "vitest.extension-channels.config.ts", config: "vitest.extensions.config.ts",
forwardedArgs: [], forwardedArgs: [],
includePatterns: ["extensions/browser/index.test.ts"], includePatterns: ["extensions/browser/index.test.ts"],
watchMode: false, watchMode: false,
-1
View File
@@ -313,7 +313,6 @@ describe("scoped vitest configs", () => {
expect(defaultExtensionChannelsConfig.test?.dir).toBe("extensions"); expect(defaultExtensionChannelsConfig.test?.dir).toBe("extensions");
expect(defaultExtensionChannelsConfig.test?.include).toEqual( expect(defaultExtensionChannelsConfig.test?.include).toEqual(
expect.arrayContaining([ expect.arrayContaining([
"browser/**/*.test.ts",
"discord/**/*.test.ts", "discord/**/*.test.ts",
"line/**/*.test.ts", "line/**/*.test.ts",
"slack/**/*.test.ts", "slack/**/*.test.ts",
-1
View File
@@ -16,7 +16,6 @@ export const channelTestRoots = [
bundledPluginRoot("slack"), bundledPluginRoot("slack"),
bundledPluginRoot("signal"), bundledPluginRoot("signal"),
bundledPluginRoot("imessage"), bundledPluginRoot("imessage"),
bundledPluginRoot("browser"),
bundledPluginRoot("line"), bundledPluginRoot("line"),
]; ];
+97
View File
@@ -35,6 +35,94 @@ export function resolveVitestIsolation(
return false; return false;
} }
const SCOPED_PROJECT_GROUP_ORDER_BY_NAME = new Map(
[
"acp",
"agents",
"auto-reply",
"auto-reply-core",
"auto-reply-reply",
"auto-reply-top-level",
"boundary",
"bundled",
"channels",
"cli",
"commands",
"commands-light",
"cron",
"daemon",
"extension-acpx",
"extension-bluebubbles",
"extension-channels",
"extension-diffs",
"extension-feishu",
"extension-irc",
"extension-mattermost",
"extension-matrix",
"extension-memory",
"extension-messaging",
"extension-msteams",
"extension-providers",
"extension-telegram",
"extension-voice-call",
"extension-whatsapp",
"extension-zalo",
"extensions",
"gateway",
"hooks",
"infra",
"logging",
"media",
"media-understanding",
"plugin-sdk",
"plugin-sdk-light",
"plugins",
"process",
"runtime-config",
"secrets",
"shared-core",
"tasks",
"tooling",
"tui",
"ui",
"unit-fast",
"unit-security",
"unit-src",
"unit-support",
"unit-ui",
"utils",
"wizard",
].map((name, index) => [name, index + 10]),
);
function hashFallbackScopedProjectGroupOrder(key: string): number {
let hash = 0;
for (const char of key) {
hash = (hash * 33 + char.charCodeAt(0)) % 10_000;
}
return hash + 1_000;
}
function resolveScopedProjectGroupOrder(
name?: string,
dir?: string,
include?: string[],
): number | undefined {
const normalizedName = name?.trim();
if (normalizedName) {
return (
SCOPED_PROJECT_GROUP_ORDER_BY_NAME.get(normalizedName) ??
hashFallbackScopedProjectGroupOrder(normalizedName)
);
}
const normalizedInclude = include?.map(normalizePathPattern).join("|") ?? "";
const key = [dir?.trim(), normalizedInclude].filter(Boolean).join("|");
if (!key) {
return undefined;
}
return hashFallbackScopedProjectGroupOrder(key);
}
export function createScopedVitestConfig( export function createScopedVitestConfig(
include: string[], include: string[],
options?: { options?: {
@@ -73,6 +161,7 @@ export function createScopedVitestConfig(
]; ];
const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate; const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate;
const runner = useNonIsolatedRunner ? "./test/non-isolated-runner.ts" : undefined; const runner = useNonIsolatedRunner ? "./test/non-isolated-runner.ts" : undefined;
const scopedGroupOrder = resolveScopedProjectGroupOrder(options?.name, scopedDir, include);
return defineConfig({ return defineConfig({
...base, ...base,
@@ -88,6 +177,14 @@ export function createScopedVitestConfig(
include: relativizeScopedPatterns(includeFromEnv ?? cliInclude ?? include, scopedDir), include: relativizeScopedPatterns(includeFromEnv ?? cliInclude ?? include, scopedDir),
exclude, exclude,
...(options?.pool ? { pool: options.pool } : {}), ...(options?.pool ? { pool: options.pool } : {}),
...(scopedGroupOrder === undefined
? {}
: {
sequence: {
...baseTest.sequence,
groupOrder: scopedGroupOrder,
},
}),
...(options?.passWithNoTests !== undefined || cliInclude !== null ...(options?.passWithNoTests !== undefined || cliInclude !== null
? { passWithNoTests: options?.passWithNoTests ?? true } ? { passWithNoTests: options?.passWithNoTests ?? true }
: {}), : {}),