The Open Framework for Building Agents
test(eve): trim duplicate dev-server scenario tests (#3846)
Andrew Barba99ce440b0281
diff --git a/packages/eve/src/execution/sandbox/development-lazy-prewarm.scenario.test.ts b/packages/eve/src/execution/sandbox/development-lazy-prewarm.scenario.test.tsindex 00eb0f3e8..6792bcb59 100644--- a/packages/eve/src/execution/sandbox/development-lazy-prewarm.scenario.test.ts+++ b/packages/eve/src/execution/sandbox/development-lazy-prewarm.scenario.test.ts@@ -1,9 +1,9 @@-import { mkdir, utimes } from "node:fs/promises";+import { mkdir, stat, utimes } from "node:fs/promises";import { once } from "node:events";import { Worker } from "node:worker_threads";import { resolvePackageSourceFilePath } from "#internal/application/package.js";import { pathToFileURL } from "node:url";-import { join } from "node:path";+import { dirname, join } from "node:path";import { describe, expect, it, vi } from "vitest";@@ -35,6 +35,16 @@ async function fixture() {};}+function leasePathFor(app: Awaited<ReturnType<typeof fixture>>): string {+ return join(+ app.input.compiledArtifactsSource.appRoot,+ ".eve",+ "compile",+ "sandbox-preparation.lock",+ "lease",+ );+}+describe("lazy development preparation", () => {it("deduplicates concurrent first access and reuses published artifacts", async () => {const app = await fixture();@@ -52,29 +62,46 @@ describe("lazy development preparation", () => {expect(prewarmAppSandboxes).toHaveBeenCalledTimes(1);});+ // The stale-owner interval is 15s; these tests backdate the lease journal+ // instead of waiting it out, and their 10s timeout ensures the backdate, not+ // wall-clock expiry, is what the contender observes.it("keeps a live preparation lease beyond the stale-owner interval", async () => {const app = await fixture();+ const journalPath = join(leasePathFor(app), "owner.json");+ const ownerStarted = Promise.withResolvers<void>();+ const releaseOwner = Promise.withResolvers<void>();vi.mocked(prewarmAppSandboxes).mockReset().mockImplementation(async () => {- await new Promise((resolve) => setTimeout(resolve, 16_000));+ ownerStarted.resolve();+ await releaseOwner.promise;await app.publish();});- await Promise.all([- ensureDevelopmentSandboxesPrepared(app.input),- ensureDevelopmentSandboxesPrepared(app.input),- ]);+ const owner = ensureDevelopmentSandboxesPrepared(app.input);+ await ownerStarted.promise;+ const stale = new Date(Date.now() - 60_000);+ await utimes(journalPath, stale, stale);+ await vi.waitFor(+ async () => {+ expect(+ (await stat(journalPath)).mtimeMs,+ "the owner's heartbeat should refresh its backdated lease journal",+ ).toBeGreaterThan(stale.getTime() + 30_000);+ },+ { interval: 50, timeout: 5_000 },+ );++ const contender = ensureDevelopmentSandboxesPrepared(app.input);+ // Let the contender poll the held lease (every 250ms) before the owner finishes.+ await new Promise((resolve) => setTimeout(resolve, 600));+ releaseOwner.resolve();+ await Promise.all([owner, contender]);expect(prewarmAppSandboxes).toHaveBeenCalledTimes(1);- });+ }, 10_000);it("recovers after a worker terminates while its parent pid stays alive", async () => {const app = await fixture();- const lockPath = join(- app.input.compiledArtifactsSource.appRoot,- ".eve",- "compile",- "sandbox-preparation.lock",- );+ const lockPath = dirname(leasePathFor(app));const moduleUrl = pathToFileURL(resolvePackageSourceFilePath("src/internal/application/output-publication-lock.ts"),).href;@@ -98,23 +125,19 @@ describe("lazy development preparation", () => {} finally {await worker.terminate();}+ const stale = new Date(Date.now() - 60_000);+ await utimes(join(leasePathFor(app), "owner.json"), stale, stale);vi.mocked(prewarmAppSandboxes).mockReset().mockImplementation(app.publish);await Promise.all([ensureDevelopmentSandboxesPrepared(app.input),ensureDevelopmentSandboxesPrepared(app.input),]);expect(prewarmAppSandboxes).toHaveBeenCalledTimes(1);- });+ }, 10_000);it("recovers an abandoned lock with no owner journal", async () => {const app = await fixture();- const leasePath = join(- app.input.compiledArtifactsSource.appRoot,- ".eve",- "compile",- "sandbox-preparation.lock",- "lease",- );+ const leasePath = leasePathFor(app);await mkdir(leasePath, { recursive: true });const old = new Date(Date.now() - 60_000);await utimes(leasePath, old, old);diff --git a/packages/eve/src/internal/authored-module-conditions.test.ts b/packages/eve/src/internal/authored-module-conditions.test.tsindex e2d58a94f..1a8130ac6 100644--- a/packages/eve/src/internal/authored-module-conditions.test.ts+++ b/packages/eve/src/internal/authored-module-conditions.test.ts@@ -1,8 +1,10 @@-import { describe, expect, it } from "vitest";+import { afterEach, describe, expect, it, vi } from "vitest";import { authoredModuleConditions } from "./authored-module-conditions.js";describe("authoredModuleConditions", () => {+ afterEach(() => vi.unstubAllEnvs());+it("leaves ordinary builds on eve's source condition", () => {expect(authoredModuleConditions(["--enable-source-maps"], "")).toEqual(["eve-source"]);});@@ -15,13 +17,17 @@ describe("authoredModuleConditions", () => {expect(authoredModuleConditions(args, "")).toEqual(["eve-source", "react-server"]);});- it("reads quoted NODE_OPTIONS and combines repeated conditions", () => {- expect(- authoredModuleConditions(- ["--conditions=react-server", "-C", "custom"],- '--conditions="react-server" --require "./path with spaces/preload.js" -C "custom condition"',- ),- ).toEqual(["eve-source", "react-server", "custom condition", "custom"]);+ it("reads quoted NODE_OPTIONS from the environment and combines repeated conditions", () => {+ vi.stubEnv(+ "NODE_OPTIONS",+ '--conditions="react-server" --require "./path with spaces/preload.js" -C "custom condition"',+ );+ expect(authoredModuleConditions(["--conditions=react-server", "-C", "custom"])).toEqual([+ "eve-source",+ "react-server",+ "custom condition",+ "custom",+ ]);});it("preserves escaped quotes in NODE_OPTIONS", () => {diff --git a/packages/eve/src/internal/nitro/host/react-server-module-map.scenario.test.ts b/packages/eve/src/internal/nitro/host/react-server-module-map.scenario.test.tsindex 4c0b2a406..ee6fddf49 100644--- a/packages/eve/src/internal/nitro/host/react-server-module-map.scenario.test.ts+++ b/packages/eve/src/internal/nitro/host/react-server-module-map.scenario.test.ts@@ -11,61 +11,50 @@ const execFileAsync = promisify(execFile);describe("react-server module maps", () => {const scenarioApp = useScenarioApp();- it.each(["argument", "NODE_OPTIONS"])(- "builds and loads server-only channels with conditions from %s",- async (conditionSource) => {- const app = await scenarioApp({- name: "react-server-module-map",- installDependencies: true,- dependencies: { "server-only": "0.0.1" },- files: {- "agent/agent.ts": 'export default { model: "openai/gpt-5.4" };',- "agent/instructions.md": "Reply concisely.",- "agent/channels/probe.ts":- 'import "server-only"; import { defineChannel, GET } from "eve/channels"; export default defineChannel({ routes: [GET("/probe", () => new Response("server-only-ready"))] });',- "check.mjs": [- 'import { createServer } from "node:net";',- 'import { spawn } from "node:child_process";',- 'import { once } from "node:events";',- 'const portProbe = createServer().listen(0, "127.0.0.1");',- 'await once(portProbe, "listening");',- "const port = portProbe.address().port;",- "await new Promise((resolve) => portProbe.close(resolve));",- 'const child = spawn(process.execPath, [".output/server/index.mjs"], { env: { ...process.env, HOST: "127.0.0.1", PORT: String(port) }, stdio: "ignore" });',- 'const exited = once(child, "exit");',- "try {",- " for (let attempt = 0; attempt < 100; attempt++) {",- " try { const response = await fetch(`http://127.0.0.1:${port}/probe`); if (response.ok) { console.log(await response.text()); break; } } catch {}",- " await new Promise((resolve) => setTimeout(resolve, 100));",- " }",- '} finally { if (child.exitCode === null) child.kill("SIGTERM"); await exited; }',- ].join("\n"),- },- });- await execFileAsync(- process.execPath,- [- ...(conditionSource === "argument" ? ["--conditions=react-server"] : []),- join(app.appRoot, "node_modules/eve/bin/eve.js"),- "build",- ],- {- cwd: app.appRoot,- timeout: 90_000,- maxBuffer: 10 * 1024 * 1024,- env: {- ...process.env,- ...(conditionSource === "NODE_OPTIONS"- ? { NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --conditions="react-server"` }- : {}),- },- },- );- const { stdout } = await execFileAsync(process.execPath, ["check.mjs"], {+ // NODE_OPTIONS conditions resolve through the same `authoredModuleConditions`+ // call; its unit test owns reading them from the environment.+ it("builds and loads server-only channels with conditions from the Node command line", async () => {+ const app = await scenarioApp({+ name: "react-server-module-map",+ installDependencies: true,+ dependencies: { "server-only": "0.0.1" },+ files: {+ "agent/agent.ts": 'export default { model: "openai/gpt-5.4" };',+ "agent/instructions.md": "Reply concisely.",+ "agent/channels/probe.ts":+ 'import "server-only"; import { defineChannel, GET } from "eve/channels"; export default defineChannel({ routes: [GET("/probe", () => new Response("server-only-ready"))] });',+ "check.mjs": [+ 'import { createServer } from "node:net";',+ 'import { spawn } from "node:child_process";',+ 'import { once } from "node:events";',+ 'const portProbe = createServer().listen(0, "127.0.0.1");',+ 'await once(portProbe, "listening");',+ "const port = portProbe.address().port;",+ "await new Promise((resolve) => portProbe.close(resolve));",+ 'const child = spawn(process.execPath, [".output/server/index.mjs"], { env: { ...process.env, HOST: "127.0.0.1", PORT: String(port) }, stdio: "ignore" });',+ 'const exited = once(child, "exit");',+ "try {",+ " for (let attempt = 0; attempt < 100; attempt++) {",+ " try { const response = await fetch(`http://127.0.0.1:${port}/probe`); if (response.ok) { console.log(await response.text()); break; } } catch {}",+ " await new Promise((resolve) => setTimeout(resolve, 100));",+ " }",+ '} finally { if (child.exitCode === null) child.kill("SIGTERM"); await exited; }',+ ].join("\n"),+ },+ });+ await execFileAsync(+ process.execPath,+ ["--conditions=react-server", join(app.appRoot, "node_modules/eve/bin/eve.js"), "build"],+ {cwd: app.appRoot,- timeout: 20_000,- });- expect(stdout).toContain("server-only-ready");- },- );+ timeout: 90_000,+ maxBuffer: 10 * 1024 * 1024,+ },+ );+ const { stdout } = await execFileAsync(process.execPath, ["check.mjs"], {+ cwd: app.appRoot,+ timeout: 20_000,+ });+ expect(stdout).toContain("server-only-ready");+ });});diff --git a/packages/eve/src/internal/nitro/host/workspace-extensions.scenario.test.ts b/packages/eve/src/internal/nitro/host/workspace-extensions.scenario.test.tsindex aa58abd00..91cba5fcb 100644--- a/packages/eve/src/internal/nitro/host/workspace-extensions.scenario.test.ts+++ b/packages/eve/src/internal/nitro/host/workspace-extensions.scenario.test.ts@@ -5,7 +5,6 @@ import { dirname, join } from "node:path";import { afterEach, describe, expect, it } from "vitest";-import { resolveExtensionBuildLockPath } from "#internal/nitro/host/extension-build-lock.js";import { buildWorkspaceExtensions } from "#internal/nitro/host/workspace-extensions.js";// These run the real extension publisher (rolldown and TypeScript), so they@@ -38,17 +37,6 @@ describe("buildWorkspaceExtensions", () => {expect(secondBuild.ino).toBe(firstBuild.ino);expect(secondBuild.mtimeMs).toBe(firstBuild.mtimeMs);});-- it("publishes a shared stale extension when agent builds run concurrently", async () => {- const { appRoot, packageRoot } = await createWorkspaceAgent();-- await Promise.all([buildWorkspaceExtensions(appRoot), buildWorkspaceExtensions(appRoot)]);-- await expect(- stat(join(packageRoot, "dist", "extension", "_manifest.json")),- ).resolves.toBeDefined();- await expect(stat(resolveExtensionBuildLockPath(packageRoot))).rejects.toThrow();- });});async function createWorkspaceAgent(): Promise<{ appRoot: string; packageRoot: string }> {diff --git a/packages/eve/test/scenarios/bin-build-output.scenario.test.ts b/packages/eve/test/scenarios/bin-build-output.scenario.test.tsindex 0db694b85..8af492fa4 100644--- a/packages/eve/test/scenarios/bin-build-output.scenario.test.ts+++ b/packages/eve/test/scenarios/bin-build-output.scenario.test.ts@@ -328,38 +328,6 @@ describe("eve build process output", () => {expect(result.stderr).toContain(`source: ${join(resolvedAppRoot, "agent")}`);}, 120_000);- it("prints bundled missing-import errors to stderr when build fails", async () => {- const appRoot = await createTemporaryAppRoot({- prefix: "eve-bin-build-output-missing-import-",- });-- await mkdir(join(appRoot, "agent", "tools"), {- recursive: true,- });- await writeFile(- join(appRoot, "agent", "tools", "bad.ts"),- [- 'import { missing } from "./does-not-exist";',- "export default {",- ' description: "Missing import test.",',- ' inputSchema: { type: "object", properties: {}, required: [] },',- " execute: async () => String(missing),",- "};",- "",- ].join("\n"),- );-- const result = await runEveBuild(appRoot);-- expect(result.code).toBe(1);- expect(result.signal).toBeNull();- expect(result.stdout).toBe("");- expect(result.stderr).toContain("Could not resolve './does-not-exist'");- expect(result.stderr).toContain("Build failed with 1 error:");- expect(result.stderr).toContain("agent/tools/bad.ts");- expect(result.stderr).not.toContain("Diagnostics artifact:");- }, 120_000);-it("prints bundled syntax errors to stderr when build fails", async () => {const appRoot = await createTemporaryAppRoot({prefix: "eve-bin-build-output-syntax-error-",diff --git a/packages/eve/test/scenarios/dev-server-chaos.scenario.test.ts b/packages/eve/test/scenarios/dev-server-chaos.scenario.test.tsindex 7396c9a6b..7fbc92ffa 100644--- a/packages/eve/test/scenarios/dev-server-chaos.scenario.test.ts+++ b/packages/eve/test/scenarios/dev-server-chaos.scenario.test.ts@@ -164,28 +164,26 @@ describe("eve dev server chaos", () => {"Timed out waiting for the initial chaos health probe.",);- for (let round = 1; round <= 3; round += 1) {- const probesBeforeRound = probe.count();- await writeFile(toolPath, toolSource(`storm-${String(round)}-a`));- await writeFile(toolPath, toolSource(`storm-${String(round)}-b`));- const revisionBeforeBreak = await readDevelopmentRevision(server.url);- await writeFile(toolPath, "export default { this is not valid typescript\n");- // The watcher survives a failed candidate, so the forced rebuild- // resolves — the deterministic proof the broken build was- // attempted and rejected is the unchanged revision.- await forceDevelopmentRebuild(server.url);- await expect(readDevelopmentRevision(server.url)).resolves.toBe(revisionBeforeBreak);- await rm(toolPath);- await writeFile(toolPath, toolSource(`storm-${String(round)}-fixed`));- await Promise.all([- forceDevelopmentRebuild(server.url),- forceDevelopmentRebuild(server.url),- ]);- await waitForCondition(- () => probe.count() > probesBeforeRound,- `Health probe did not run during chaos round ${String(round)}.`,- );- }+ const probesBeforeStorm = probe.count();+ await writeFile(toolPath, toolSource("storm-a"));+ await writeFile(toolPath, toolSource("storm-b"));+ const revisionBeforeBreak = await readDevelopmentRevision(server.url);+ await writeFile(toolPath, "export default { this is not valid typescript\n");+ // The watcher survives a failed candidate, so the forced rebuild+ // resolves — the deterministic proof the broken build was+ // attempted and rejected is the unchanged revision.+ await forceDevelopmentRebuild(server.url);+ await expect(readDevelopmentRevision(server.url)).resolves.toBe(revisionBeforeBreak);+ await rm(toolPath);+ await writeFile(toolPath, toolSource("storm-fixed"));+ await Promise.all([+ forceDevelopmentRebuild(server.url),+ forceDevelopmentRebuild(server.url),+ ]);+ await waitForCondition(+ () => probe.count() > probesBeforeStorm,+ "Health probe did not run during the edit storm.",+ );const probesBeforeStructuralReload = probe.count();await writeFile(join(app.appRoot, ".env.local"), "EVE_CHAOS_STRUCTURAL=1\n");@@ -210,7 +208,7 @@ describe("eve dev server chaos", () => {);it(- "recovers through worker crashes, aborted streams, and concurrent rebuilds",+ "ends streams on a crashed worker and recovers through crashes, aborts, and concurrent rebuilds",async () => {const app = await scenarioApp(CHAOS_DESCRIPTOR);const server = await startEveDev(app.appRoot);@@ -226,8 +224,25 @@ describe("eve dev server chaos", () => {await reader?.read();abort.abort();+ const heldStream = await fetch(new URL("/chaos/slow-stream", server.url));+ const heldReader = heldStream.body?.getReader();+ await heldReader?.read();+const crashResponse = await fetch(new URL("/chaos/crash", server.url));expect([200, 503]).toContain(crashResponse.status);+ // A stream still open on the crashed worker must end, not hang.+ await withinDeadline(+ (async () => {+ for (;;) {+ const result = await heldReader?.read();+ if (result === undefined || result.done) {+ return;+ }+ }+ })().catch(() => undefined),+ "Timed out waiting for the crashed worker's stream to settle.",+ 15_000,+ );await waitForCondition(async () => {try {return (await fetchText(server.url, "/chaos/worker-id")) !== firstWorkerId;@@ -265,47 +280,6 @@ describe("eve dev server chaos", () => {CHAOS_SCENARIO_TIMEOUT_MS,);- it(- "terminates an open stream within a bounded deadline when its worker crashes",- async () => {- const app = await scenarioApp(CHAOS_DESCRIPTOR);- const server = await startEveDev(app.appRoot);-- try {- const streamResponse = await fetch(new URL("/chaos/slow-stream", server.url));- const reader = streamResponse.body?.getReader();- await reader?.read();-- await fetch(new URL("/chaos/crash", server.url));- await withinDeadline(- (async () => {- for (;;) {- const result = await reader?.read();- if (result === undefined || result.done) {- return;- }- }- })().catch(() => undefined),- "Timed out waiting for the crashed worker's stream to settle.",- 15_000,- );-- await waitForCondition(async () => {- try {- const response = await fetch(new URL(EVE_HEALTH_ROUTE_PATH, server.url));- return response.status === 200;- } catch {- return false;- }- }, "Timed out waiting for the dev server to recover after the crash.");- await completeStreamedTurn(server, "What's the weather in Lisbon?");- } finally {- await server.stop();- }- },- CHAOS_SCENARIO_TIMEOUT_MS,- );-it("shuts down within a bounded deadline while a stream is open",async () => {@@ -339,7 +313,7 @@ describe("eve dev server chaos", () => {);it(- "reports the socket peer as the client address despite forged headers",+ "stamps the socket peer and rejects untrusted internal transport on the public listener",async () => {const app = await scenarioApp(CHAOS_DESCRIPTOR);const server = await startEveDev(app.appRoot);@@ -357,20 +331,7 @@ describe("eve dev server chaos", () => {});expect(response.status).toBe(200);await expect(response.text()).resolves.toBe("127.0.0.1");- } finally {- await server.stop();- }- },- CHAOS_SCENARIO_TIMEOUT_MS,- );-- it(- "rejects untrusted internal transport requests on the public listener",- async () => {- const app = await scenarioApp(CHAOS_DESCRIPTOR);- const server = await startEveDev(app.appRoot);- try {const worldCall = await fetch(new URL("/eve/v1/dev/internal/workflow-world", server.url), {body: "{}",method: "POST",diff --git a/packages/eve/test/scenarios/dev-server-drain.scenario.test.ts b/packages/eve/test/scenarios/dev-server-drain.scenario.test.tsdeleted file mode 100644index c906112ee..000000000--- a/packages/eve/test/scenarios/dev-server-drain.scenario.test.ts+++ /dev/null@@ -1,254 +0,0 @@-import { Agent } from "node:http";-import { writeFile } from "node:fs/promises";-import { join } from "node:path";--import { describe, expect, it } from "vitest";--import { EVE_HEALTH_ROUTE_PATH } from "../../src/protocol/routes.js";-import { WEATHER_AGENT_DESCRIPTOR } from "../../src/internal/testing/scenario-apps/weather-agent.js";-import {- type ScenarioAppDescriptor,- useScenarioApp,-} from "../../src/internal/testing/scenario-app.js";-import { sendDevelopmentMessage } from "../dev-client-harness/send-message.js";-import { createDevelopmentSessionState } from "../dev-client-harness/session.js";-import {- fetchText,- hasKnownDevServerFailure,- requestWithAgent,- startEveDev,- waitForCondition,- type RunningEveDev,-} from "./dev-server-harness.js";--const scenarioApp = useScenarioApp();--const DRAIN_SCENARIO_TIMEOUT_MS = 360_000;--const DRAIN_CHANNEL_SOURCE = [- 'import { randomUUID } from "node:crypto";',- 'import { defineChannel, GET } from "eve/channels";',- "",- "const workerId = randomUUID();",- "",- "export default defineChannel({",- " routes: [",- ' GET("/drain/worker-id", () => new Response(workerId)),',- ' GET("/drain/request-ip", (_request, context) => new Response(String(context.requestIp))),',- ' GET("/drain/crash", () => {',- " setTimeout(() => process.exit(7), 25);",- ' return new Response("crashing");',- " }),",- ' GET("/drain/slow-stream", () => {',- " let timer: ReturnType<typeof setInterval> | undefined;",- " const body = new ReadableStream({",- " start(controller) {",- ' controller.enqueue(new TextEncoder().encode("chunk\\n"));',- " timer = setInterval(() => {",- ' controller.enqueue(new TextEncoder().encode("chunk\\n"));',- " }, 50);",- " },",- " cancel() {",- " clearInterval(timer);",- " },",- " });",- " return new Response(body);",- " }),",- " ],",- "});",- "",-].join("\n");--const DRAIN_DESCRIPTOR: ScenarioAppDescriptor = {- ...WEATHER_AGENT_DESCRIPTOR,- files: {- ...WEATHER_AGENT_DESCRIPTOR.files,- "agent/channels/drain.ts": DRAIN_CHANNEL_SOURCE,- },- name: "weather-agent-drain",-};--async function readWorkerId(server: RunningEveDev, agent?: Agent): Promise<string> {- if (agent === undefined) {- return await fetchText(server.url, "/drain/worker-id");- }-- const response = await requestWithAgent(new URL("/drain/worker-id", server.url).href, agent);- if (response.statusCode < 200 || response.statusCode >= 300) {- throw new Error(- `Expected /drain/worker-id to succeed, received ${String(response.statusCode)}.`,- );- }- return response.body;-}--async function triggerWorkerReplacement(- server: RunningEveDev,- appRoot: string,- agent?: Agent,-): Promise<void> {- const previousWorkerId = await readWorkerId(server, agent);- await writeFile(join(appRoot, ".env.local"), `EVE_DRAIN_RELOAD=${Date.now()}\n`);- await waitForCondition(- async () => {- try {- return (await readWorkerId(server, agent)) !== previousWorkerId;- } catch {- return false;- }- },- () =>- [- "Timed out waiting for a replacement worker.",- `stdout:\n${server.stdout()}`,- `stderr:\n${server.stderr()}`,- ].join("\n\n"),- );-}--describe("eve dev drained worker replacement", () => {- it(- "keeps an admitted stream flowing on the retired worker across a replacement",- async () => {- const app = await scenarioApp(DRAIN_DESCRIPTOR);- const server = await startEveDev(app.appRoot);-- try {- const streamResponse = await fetch(new URL("/drain/slow-stream", server.url));- const reader = streamResponse.body?.getReader();- await reader?.read();-- await triggerWorkerReplacement(server, app.appRoot);-- // The retired worker must still be producing: several further chunks- // arrive after the swap, then the client walks away cleanly.- for (let i = 0; i < 5; i += 1) {- const result = await reader?.read();- expect(result?.done).toBe(false);- }- await reader?.cancel();-- const turn = await sendDevelopmentMessage({- message: "What's the weather in Lisbon?",- session: createDevelopmentSessionState(),- serverUrl: server.url,- });- expect(turn.events.some((event) => event.type === "message.completed")).toBe(true);- expect(hasKnownDevServerFailure(`${server.stdout()}\n${server.stderr()}`)).toBe(false);- } finally {- await server.stop();- }- },- DRAIN_SCENARIO_TIMEOUT_MS,- );-- it(- "serves a kept-alive connection across a worker replacement",- async () => {- const app = await scenarioApp(DRAIN_DESCRIPTOR);- const server = await startEveDev(app.appRoot);- const agent = new Agent({ keepAlive: true, maxSockets: 1 });-- try {- const first = await requestWithAgent(new URL("/drain/worker-id", server.url).href, agent);- expect(first.localPort).toBeDefined();-- // Keep the asserted socket active while the replacement builds so the- // test does not depend on finishing before Node's idle keep-alive timeout.- await triggerWorkerReplacement(server, app.appRoot, agent);-- const second = await requestWithAgent(new URL("/drain/worker-id", server.url).href, agent);- expect(second.localPort).toBe(first.localPort);- expect(second.body).not.toBe(first.body);- expect(hasKnownDevServerFailure(`${server.stdout()}\n${server.stderr()}`)).toBe(false);- } finally {- agent.destroy();- await server.stop();- }- },- DRAIN_SCENARIO_TIMEOUT_MS,- );-- it(- "restarts the worker after a crash and keeps serving",- async () => {- const app = await scenarioApp(DRAIN_DESCRIPTOR);- const server = await startEveDev(app.appRoot);-- try {- const firstWorkerId = await fetchText(server.url, "/drain/worker-id");- await fetch(new URL("/drain/crash", server.url));-- await waitForCondition(- async () => {- try {- return (await fetchText(server.url, "/drain/worker-id")) !== firstWorkerId;- } catch {- return false;- }- },- () =>- [- "Timed out waiting for the crashed worker to restart.",- `stdout:\n${server.stdout()}`,- `stderr:\n${server.stderr()}`,- ].join("\n\n"),- );- const health = await fetch(new URL(EVE_HEALTH_ROUTE_PATH, server.url));- expect(health.status).toBe(200);- } finally {- await server.stop();- }- },- DRAIN_SCENARIO_TIMEOUT_MS,- );-- it(- "shuts down within a bounded deadline while a stream is open",- async () => {- const app = await scenarioApp(DRAIN_DESCRIPTOR);- const server = await startEveDev(app.appRoot);- const streamResponse = await fetch(new URL("/drain/slow-stream", server.url));- const reader = streamResponse.body?.getReader();- await reader?.read();-- const stopStart = Date.now();- await server.stop();-- // The harness escalates to SIGKILL at 10s; a graceful exit must beat it.- expect(Date.now() - stopStart).toBeLessThan(9_000);- await expect(- (async () => {- for (;;) {- const result = await reader?.read();- if (result === undefined || result.done) {- return "done";- }- }- })().catch(() => "errored"),- ).resolves.toBeDefined();- },- DRAIN_SCENARIO_TIMEOUT_MS,- );-- it(- "reports a socket-derived client address despite forged forwarding headers",- async () => {- const app = await scenarioApp(DRAIN_DESCRIPTOR);- const server = await startEveDev(app.appRoot);-- try {- const response = await fetch(new URL("/drain/request-ip", server.url), {- headers: { "x-forwarded-for": "203.0.113.7" },- });- expect(response.status).toBe(200);- const address = await response.text();- expect(address).not.toBe("203.0.113.7");- expect(address).toContain("127.0.0.1");- } finally {- await server.stop();- }- },- DRAIN_SCENARIO_TIMEOUT_MS,- );-});diff --git a/packages/eve/test/scenarios/dev-server-rebuild.scenario.test.ts b/packages/eve/test/scenarios/dev-server-rebuild.scenario.test.tsindex 3763ba1dd..d67374dad 100644--- a/packages/eve/test/scenarios/dev-server-rebuild.scenario.test.ts+++ b/packages/eve/test/scenarios/dev-server-rebuild.scenario.test.ts@@ -180,44 +180,17 @@ describe("eve dev server rebuild transactions", () => {);it(- "replaces the worker for instrumentation changes and preserves compiled routes",+ "keeps the complete prior generation active when a structural candidate fails",async () => {const app = await scenarioApp(TRANSACTIONAL_REBUILD_DESCRIPTOR);const server = await startEveDev(app.appRoot);try {- await expect(fetchText(server.url, "/instrumentation-marker")).resolves.toBe("one");- await expect(fetchText(server.url, "/overlap/static")).resolves.toBe("static");+ const initialRevision = await readDevelopmentRevision(server.url);const initialWorkerId = await fetchText(server.url, "/worker-id");-await forceDevelopmentRebuild(server.url);await expect(fetchText(server.url, "/worker-id")).resolves.toBe(initialWorkerId);- await writeFile(- join(app.appRoot, "agent", "instrumentation", "reload.ts"),- createInstrumentationSource("two"),- );- await forceDevelopmentRebuild(server.url);-- await expect(fetchText(server.url, "/instrumentation-marker")).resolves.toBe("two");- await expect(fetchText(server.url, "/worker-id")).resolves.not.toBe(initialWorkerId);- await expect(fetchText(server.url, "/overlap/static")).resolves.toBe("static");- expect(hasKnownDevServerFailure(`${server.stdout()}\n${server.stderr()}`)).toBe(false);- } finally {- await server.stop();- }- },- DEV_SERVER_SCENARIO_TIMEOUT_MS,- );-- it(- "keeps the complete prior generation active when a structural candidate fails",- async () => {- const app = await scenarioApp(TRANSACTIONAL_REBUILD_DESCRIPTOR);- const server = await startEveDev(app.appRoot);-- try {- const initialRevision = await readDevelopmentRevision(server.url);await writeFile(join(app.appRoot, "agent", "channels", "dev-generation.ts"),['import "./missing-candidate-module.ts";', createCandidateChannelSource()].join("\n"),@@ -247,6 +220,7 @@ describe("eve dev server rebuild transactions", () => {await expect(fetchText(server.url, "/instrumentation-marker")).resolves.toBe("one");const candidateRoute = await fetch(new URL("/candidate-only", server.url));expect(candidateRoute.status).toBe(404);+ await expect(fetchText(server.url, "/worker-id")).resolves.toBe(initialWorkerId);await writeFile(join(app.appRoot, "agent", "instrumentation", "reload.ts"),@@ -256,6 +230,7 @@ describe("eve dev server rebuild transactions", () => {await expect(readDevelopmentRevision(server.url)).resolves.not.toBe(initialRevision);await expect(fetchText(server.url, "/instrumentation-marker")).resolves.toBe("two");await expect(fetchText(server.url, "/candidate-only")).resolves.toBe("candidate");+ await expect(fetchText(server.url, "/worker-id")).resolves.not.toBe(initialWorkerId);await writeFile(join(app.appRoot, "agent", "channels", "dev-generation.ts"),diff --git a/packages/eve/test/scenarios/dev-server-shutdown.scenario.test.ts b/packages/eve/test/scenarios/dev-server-shutdown.scenario.test.tsindex af2663c17..556351e7b 100644--- a/packages/eve/test/scenarios/dev-server-shutdown.scenario.test.ts+++ b/packages/eve/test/scenarios/dev-server-shutdown.scenario.test.ts@@ -7,20 +7,20 @@ import { signalEveDevDuringStartup, startEveDev } from "./dev-server-harness.js"const scenarioApp = useScenarioApp();describe("eve dev shutdown", () => {- for (const signal of ["SIGINT", "SIGTERM"] as const) {- it(`returns within one second after ${signal}`, async () => {- const app = await scenarioApp(WEATHER_AGENT_DESCRIPTOR);- const server = await startEveDev(app.appRoot);+ // SIGINT and SIGTERM share one handler in `installShutdownSignal`; every+ // scenario's `server.stop()` exercises the SIGTERM path.+ it("returns within one second after SIGINT", async () => {+ const app = await scenarioApp(WEATHER_AGENT_DESCRIPTOR);+ const server = await startEveDev(app.appRoot);- const exit = await server.signalAndAwaitExit(signal);+ const exit = await server.signalAndAwaitExit("SIGINT");- expect(exit.forcedKill).toBe(false);- expect(exit.durationMs).toBeLessThan(1_000);- expect(exit.code).toBe(0);- expect(exit.signal).toBe(null);- await expect(fetch(server.url)).rejects.toThrow();- }, 120_000);- }+ expect(exit.forcedKill).toBe(false);+ expect(exit.durationMs).toBeLessThan(1_000);+ expect(exit.code).toBe(0);+ expect(exit.signal).toBe(null);+ await expect(fetch(server.url)).rejects.toThrow();+ }, 120_000);it("returns within one second when signalled during startup", async () => {const app = await scenarioApp(WEATHER_AGENT_DESCRIPTOR);diff --git a/packages/eve/test/scenarios/production-build-isolation.scenario.test.ts b/packages/eve/test/scenarios/production-build-isolation.scenario.test.tsindex 726ca1149..2c36729da 100644--- a/packages/eve/test/scenarios/production-build-isolation.scenario.test.ts+++ b/packages/eve/test/scenarios/production-build-isolation.scenario.test.ts@@ -1,16 +1,7 @@import { spawn, type ChildProcessByStdio } from "node:child_process";import { createHash } from "node:crypto";import { watch } from "node:fs";-import {- lstat,- mkdir,- readFile,- readdir,- readlink,- rename,- utimes,- writeFile,-} from "node:fs/promises";+import { lstat, mkdir, readFile, readdir, readlink, writeFile } from "node:fs/promises";import { join } from "node:path";import type { Readable } from "node:stream";import { pathToFileURL } from "node:url";@@ -526,7 +517,11 @@ describe("production build isolation", () => {expect(failedResult.code).toBe(1);expect(failedResult.signal).toBeNull();- expect(failedResult.stderr).toContain("does-not-exist");+ expect(failedResult.stdout).toBe("");+ expect(failedResult.stderr).toContain("Could not resolve './does-not-exist'");+ expect(failedResult.stderr).toContain("Build failed with 1 error:");+ expect(failedResult.stderr).toContain("agent/tools/broken.ts");+ expect(failedResult.stderr).not.toContain("Diagnostics artifact:");expect(await hashPath(outputDir)).toBe(lastGoodOutputHash);expect(await hashPath(summaryPath)).toBe(lastGoodSummaryHash);expect(await listBuildWorkspaces(app.appRoot)).toEqual([]);@@ -534,70 +529,6 @@ describe("production build isolation", () => {SCENARIO_DEADLINE_MS,);- it(- "recovers a crashed publication through a real build while a real dev server stays healthy",- async () => {- const app = await scenarioApp(WEATHER_AGENT_DESCRIPTOR);- const firstBuild = startEveProcess({ appRoot: app.appRoot, args: ["build"] });- await expect(firstBuild.result).resolves.toMatchObject({ code: 0, signal: null });-- const outputDir = join(app.appRoot, ".output");- const summaryPath = join(app.appRoot, ".eve", "agent-summary.json");- const token = "crashed-publisher";- const outputBackupPath = `${outputDir}.eve-backup-${token}`;- const summaryBackupPath = `${summaryPath}.eve-backup-${token}`;- const crashedWorkspace = join(app.appRoot, ".eve", "builds", "crashed");- const crashedStagedOutputDir = join(crashedWorkspace, "output");- const crashedStagedSummaryPath = join(crashedWorkspace, "agent-summary.json");- await mkdir(crashedStagedOutputDir, { recursive: true });- await writeFile(join(crashedStagedOutputDir, "marker.txt"), "crashed\n");- await writeFile(crashedStagedSummaryPath, "crashed\n");- await rename(outputDir, outputBackupPath);- await rename(summaryPath, summaryBackupPath);- const lockPath = join(app.appRoot, ".eve", "locks", "output-publication.lock");- await mkdir(lockPath, { recursive: true });- const journalPath = join(lockPath, "owner.json");- await writeFile(- journalPath,- `${JSON.stringify({- finalOutputDir: outputDir,- finalSummaryPath: summaryPath,- hadOutput: true,- hadSummary: true,- liveness: "active",- outputBackupPath,- phase: "backed-up",- // This test's own live pid simulates pid reuse after a crash: only- // the stale journal mtime marks the recorded owner as dead.- pid: process.pid,- scratchDir: crashedWorkspace,- stagedOutputDir: crashedStagedOutputDir,- stagedSummaryPath: crashedStagedSummaryPath,- summaryBackupPath,- token,- })}\n`,- );- const staleTime = new Date(Date.now() - 60_000);- await utimes(journalPath, staleTime, staleTime);-- const server = await startEveDev(app.appRoot);- try {- await expectHealthy(server);- const recoveringBuild = startEveProcess({ appRoot: app.appRoot, args: ["build"] });- await expect(recoveringBuild.result).resolves.toMatchObject({ code: 0, signal: null });- await expectHealthy(server);- } finally {- await server.stop();- }-- expect(await readdir(join(app.appRoot, ".eve", "locks"))).toEqual([]);- expect(await listBuildWorkspaces(app.appRoot)).toEqual([]);- await expect(lstat(outputBackupPath)).rejects.toMatchObject({ code: "ENOENT" });- expect((await lstat(join(outputDir, "server", "index.mjs"))).isFile()).toBe(true);- },- SCENARIO_DEADLINE_MS,- );-it("publishes relocatable compiler artifacts without workspace-derived step ids",async () => {