diff --git a/server/src/__tests__/workspace-runtime.test.ts b/server/src/__tests__/workspace-runtime.test.ts index c3d17eae425..d870f42b295 100644 --- a/server/src/__tests__/workspace-runtime.test.ts +++ b/server/src/__tests__/workspace-runtime.test.ts @@ -7974,22 +7974,11 @@ describeEmbeddedPostgres("workspace runtime startup reconciliation", () => { const reservePort = async () => { for (let attempt = 0; attempt < 100; attempt += 1) { - const probe = net.createServer(); - // macOS can allocate an entire ephemeral range above 55535. Pick a - // bounded candidate so the test's HMR companion remains a valid port. - await new Promise((resolve) => { - probe.once("error", () => resolve()); - probe.listen(20_000 + Math.floor(Math.random() * 20_000), "127.0.0.1", resolve); - }); - if (!probe.listening) continue; - const address = probe.address(); - const port = typeof address === "object" && address ? address.port : null; - await new Promise((resolve, reject) => { - probe.close((error) => error ? reject(error) : resolve()); - }); - if (port && port <= 55_535 && (port < 42_000 || port > 42_999)) return port; + // Keep both listeners below ephemeral client ports and outside the broker range. + const port = 12_000 + Math.floor(Math.random() * 6_000); + if (await isLoopbackPortFree(port) && await isLoopbackPortFree(port + 10_000)) return port; } - throw new Error("Failed to reserve an HTTPS backfill test port outside the broker range"); + throw new Error("Failed to reserve app and HMR ports for the HTTPS backfill test"); }; const isLoopbackPortFree = async (port: number) => { const probe = net.createServer(); diff --git a/tests/e2e/agent-configuration.spec.ts b/tests/e2e/agent-configuration.spec.ts index 10a43c88b2f..f0ce7810e32 100644 --- a/tests/e2e/agent-configuration.spec.ts +++ b/tests/e2e/agent-configuration.spec.ts @@ -218,8 +218,9 @@ test("a lost creation response requires reload and cannot blindly replay command }, { capture: true, once: true })); expect((await document(page)).spec.apiKeys!.create).toHaveLength(2); await page.getByRole("button", { name: "Reload saved", exact: true }).click(); - await expect.poll(async () => (await document(page)).spec.apiKeys!.create).toEqual([]); await expect(page).toHaveURL(/\/agents\/partially-renamed-yaml-engineer\/advanced$/); + await expect(page.getByRole("button", { name: "Reload saved", exact: true })).toBeEnabled(); + expect((await document(page)).spec.apiKeys!.create).toEqual([]); await expect(page.getByRole("textbox", { name: "API key: First key token" })).toBeVisible(); await edit(page, value => { value.spec.title = "Recovered save"; }); await save(page); diff --git a/tests/e2e/signoff-policy.spec.ts b/tests/e2e/signoff-policy.spec.ts index 31276258904..a9483e31bb8 100644 --- a/tests/e2e/signoff-policy.spec.ts +++ b/tests/e2e/signoff-policy.spec.ts @@ -589,12 +589,12 @@ test("a deferred signoff wake ignores cancelled history from an earlier stage", test.describe("Signoff execution policy", () => { let ctx: TestContext; - test.beforeAll(async () => { + test.beforeEach(async () => { const boardRequest = await pwRequest.newContext({ baseURL: BASE_URL }); ctx = await setupCompany(boardRequest); }); - test.afterAll(async () => { + test.afterEach(async () => { if (!ctx) return; const board = ctx.boardRequest;