Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(scripts): isolate mock server ports from concurrent E2E runs

Steven Enamakelf3a10e5073ac
diff --git a/scripts/__tests__/e2e-web-bundle-guard.test.mjs b/scripts/__tests__/e2e-web-bundle-guard.test.mjs
index 0b1078ee19..44951ea635 100644
--- a/scripts/__tests__/e2e-web-bundle-guard.test.mjs
+++ b/scripts/__tests__/e2e-web-bundle-guard.test.mjs
@@ -101,6 +101,9 @@ fi
);
writeExecutable(path.join(bin, "rustc"), `#!/usr/bin/env bash\necho 'host: test-triple'\n`);
writeExecutable(path.join(bin, "cargo"), `#!/usr/bin/env bash\n${record("cargo")}\n`);
+ // Port availability belongs to e2e-web-port-guard.test.mjs. This fixture
+ // starts no real listeners, so its probes must not inspect other sessions.
+ writeExecutable(path.join(bin, "python3"), `#!/usr/bin/env bash\n${record("python3")}\nexit 0\n`);
// The repo-level helpers e2e-web-build.sh shells out to.
writeExecutable(
diff --git a/scripts/mock-api/chaos.test.mjs b/scripts/mock-api/chaos.test.mjs
index 7a5af0dc5a..1b42457262 100644
--- a/scripts/mock-api/chaos.test.mjs
+++ b/scripts/mock-api/chaos.test.mjs
@@ -27,7 +27,9 @@ function setFaultRules(rules) {
test.beforeEach(async () => {
await stopMockServer();
resetMockBehavior();
- await startMockServer();
+ const started = await startMockServer(0);
+ assert.equal(started.requestedPort, 0, "explicit port zero must ask the OS for a free port");
+ assert.ok(started.port > 0);
});
test.afterEach(async () => {
diff --git a/scripts/mock-api/server.mjs b/scripts/mock-api/server.mjs
index 60a7371c68..6964db3c3b 100644
--- a/scripts/mock-api/server.mjs
+++ b/scripts/mock-api/server.mjs
@@ -262,7 +262,7 @@ export async function startMockServer(port = DEFAULT_PORT, options = {}) {
}
const preferredPort =
- Number.isInteger(port) && port > 0 ? port : DEFAULT_PORT;
+ Number.isInteger(port) && port >= 0 ? port : DEFAULT_PORT;
const retryIfInUse = options.retryIfInUse === true;
const candidatePorts = retryIfInUse
? [