Files
reverse-engineering-anything/tests/boundary/process/environmentServeShutdown.test.ts
T
Edgar ArakelyanandClaude Fable 5.1 fe55c94e66 feat(environment): serve an environment manifest as a replay environment
Add rea environment-serve <manifest.json> --evidence <capture.json>
[--host] [--port]: it loads an environment-manifest view and the capture
Evidence it was projected from, refuses a manifest whose parent evidence id
does not match the capture, builds one MCP tool per manifest tool and serves
them over streamable HTTP beside an environment card at
/.well-known/agent-env.json and a data plane at /agentenv that refuses every
method. Each tool call replays the retained record whose path and query
values best match the arguments, cites the record ordinal and evidence id,
marks replayed content as untrusted target content, and truncates bodies
over 256 KiB with a flag. Nothing executes the captured application.

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 19:43:09 -07:00

52 lines
1.8 KiB
TypeScript

import { once } from "node:events";
import { describe, expect } from "vitest";
import { writeEnvironmentServeFiles } from "../../fixtures/environmentServe.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { rawHttpRequest } from "../../support/http/rawRequest.js";
import { startListeningProcess } from "../../support/mcp/streamableHttpProcess.js";
import { processTest } from "../../support/process/processFixture.js";
const SHUTDOWN_TIMEOUT_MS = 90_000;
describe("rea environment-serve shutdown", () => {
processTest(
"closes the listener on SIGTERM, prints one stopped document and exits 143",
async ({ processes }) => {
const root = await createTestTempDirectory("rea-environment-serve-stop-");
const files = await writeEnvironmentServeFiles(root);
const started = await startListeningProcess(processes, [
"environment-serve",
files.manifestPath,
"--evidence",
files.capturePath,
"--port",
"0",
"--json",
]);
let stdout = "";
started.child.stdout.on("data", (chunk: Buffer) => {
stdout += chunk.toString("utf8");
});
const card = await rawHttpRequest(
new URL("/.well-known/agent-env.json", started.url.origin),
);
expect(card.status).toBe(200);
started.child.kill("SIGTERM");
const [code, signalCode] = await once(started.child, "close");
expect(code).toBe(143);
expect(signalCode).toBeNull();
expect(JSON.parse(stdout)).toMatchObject({
status: "stopped",
url: started.url.href,
environment: "grafana-example",
});
await expect(rawHttpRequest(started.url)).rejects.toMatchObject({
code: "ECONNREFUSED",
});
},
SHUTDOWN_TIMEOUT_MS,
);
});