test(gate): stabilize env- and timing-sensitive process/web-search checks

This commit is contained in:
Peter Steinberger
2026-02-23 19:19:39 +00:00
parent 46dee26600
commit fe62711342
4 changed files with 25 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ async function waitForSessionCompletion(params: {
return true; return true;
}, },
{ {
timeout: process.platform === "win32" ? 4000 : 2000, timeout: process.platform === "win32" ? 12_000 : 8_000,
interval: 30, interval: 30,
}, },
) )

View File

@@ -72,6 +72,8 @@ describe("web search provider auto-detection", () => {
delete process.env.PERPLEXITY_API_KEY; delete process.env.PERPLEXITY_API_KEY;
delete process.env.OPENROUTER_API_KEY; delete process.env.OPENROUTER_API_KEY;
delete process.env.XAI_API_KEY; delete process.env.XAI_API_KEY;
delete process.env.KIMI_API_KEY;
delete process.env.MOONSHOT_API_KEY;
}); });
afterEach(() => { afterEach(() => {
@@ -103,6 +105,16 @@ describe("web search provider auto-detection", () => {
expect(resolveSearchProvider({})).toBe("grok"); expect(resolveSearchProvider({})).toBe("grok");
}); });
it("auto-detects kimi when only KIMI_API_KEY is set", () => {
process.env.KIMI_API_KEY = "test-kimi-key";
expect(resolveSearchProvider({})).toBe("kimi");
});
it("auto-detects kimi when only MOONSHOT_API_KEY is set", () => {
process.env.MOONSHOT_API_KEY = "test-moonshot-key";
expect(resolveSearchProvider({})).toBe("kimi");
});
it("follows priority order — brave wins when multiple keys available", () => { it("follows priority order — brave wins when multiple keys available", () => {
process.env.BRAVE_API_KEY = "test-brave-key"; process.env.BRAVE_API_KEY = "test-brave-key";
process.env.GEMINI_API_KEY = "test-gemini-key"; process.env.GEMINI_API_KEY = "test-gemini-key";

View File

@@ -110,7 +110,7 @@ describe("runCommandWithTimeout", () => {
], ],
{ {
timeoutMs: 5_000, timeoutMs: 5_000,
noOutputTimeoutMs: 500, noOutputTimeoutMs: 1_500,
}, },
); );

View File

@@ -18,8 +18,9 @@ describe("process supervisor", () => {
const supervisor = createProcessSupervisor(); const supervisor = createProcessSupervisor();
const run = await spawnChild(supervisor, { const run = await spawnChild(supervisor, {
sessionId: "s1", sessionId: "s1",
argv: [process.execPath, "-e", 'process.stdout.write("ok")'], // Delay stdout slightly so listeners are attached even on heavily loaded runners.
timeoutMs: 1_000, argv: [process.execPath, "-e", 'setTimeout(() => process.stdout.write("ok"), 200)'],
timeoutMs: 10_000,
stdinMode: "pipe-closed", stdinMode: "pipe-closed",
}); });
const exit = await run.wait(); const exit = await run.wait();
@@ -48,8 +49,8 @@ describe("process supervisor", () => {
const first = await spawnChild(supervisor, { const first = await spawnChild(supervisor, {
sessionId: "s1", sessionId: "s1",
scopeKey: "scope:a", scopeKey: "scope:a",
argv: [process.execPath, "-e", "setTimeout(() => {}, 40)"], argv: [process.execPath, "-e", "setTimeout(() => {}, 2_000)"],
timeoutMs: 500, timeoutMs: 10_000,
stdinMode: "pipe-open", stdinMode: "pipe-open",
}); });
@@ -57,8 +58,9 @@ describe("process supervisor", () => {
sessionId: "s1", sessionId: "s1",
scopeKey: "scope:a", scopeKey: "scope:a",
replaceExistingScope: true, replaceExistingScope: true,
argv: [process.execPath, "-e", 'process.stdout.write("new")'], // Small delay makes stdout capture deterministic by giving listeners time to attach.
timeoutMs: 1_000, argv: [process.execPath, "-e", 'setTimeout(() => process.stdout.write("new"), 200)'],
timeoutMs: 10_000,
stdinMode: "pipe-closed", stdinMode: "pipe-closed",
}); });
@@ -87,8 +89,9 @@ describe("process supervisor", () => {
let streamed = ""; let streamed = "";
const run = await spawnChild(supervisor, { const run = await spawnChild(supervisor, {
sessionId: "s-capture", sessionId: "s-capture",
argv: [process.execPath, "-e", 'process.stdout.write("streamed")'], // Avoid race where child exits before stdout listeners are attached.
timeoutMs: 1_000, argv: [process.execPath, "-e", 'setTimeout(() => process.stdout.write("streamed"), 200)'],
timeoutMs: 10_000,
stdinMode: "pipe-closed", stdinMode: "pipe-closed",
captureOutput: false, captureOutput: false,
onStdout: (chunk) => { onStdout: (chunk) => {