mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
9405bd660d
Move whole-graph commitment and batched integrity checks into owned domain steps while retaining eager input capture, canonical IDs, full validation and completion-only immutable proofs. Verified complete real Notion identity parity and actual stdio MCP cancellation, Evidence retention and connection reuse. Refs #1065.
111 lines
4.0 KiB
TypeScript
111 lines
4.0 KiB
TypeScript
import { setImmediate } from "node:timers";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
|
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
|
import { analyzeJavaScriptApplication } from "./JavaScriptApplicationService.js";
|
|
|
|
describe("JavaScript analysis cancellation before publication", () => {
|
|
it("interrupts semantic graph commitment before result validation", async () => {
|
|
const root = await createTestTempDirectory("rea-js-cancel-semantic-");
|
|
await writeFile(
|
|
join(root, "main.js"),
|
|
Array.from(
|
|
{ length: 500 },
|
|
(_, index) =>
|
|
`export function inspect${index}(value) { return JSON.stringify(value); }`,
|
|
).join("\n"),
|
|
);
|
|
const controller = new AbortController();
|
|
const phases: string[] = [];
|
|
const result = await analyzeJavaScriptApplication(
|
|
{ input_path: root, format: "directory" },
|
|
{
|
|
signal: controller.signal,
|
|
progress: {
|
|
async report(event) {
|
|
phases.push(event.phase);
|
|
if (event.phase === "seal_javascript_semantic_graph")
|
|
setImmediate(() => controller.abort());
|
|
},
|
|
},
|
|
},
|
|
);
|
|
if (result.ok)
|
|
throw new Error("Cancelled commitment must not publish Evidence");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "cancelled",
|
|
details: { reason: "cancelled" },
|
|
});
|
|
expect(phases).toContain("seal_javascript_semantic_graph");
|
|
expect(phases).not.toContain("validate_javascript_application_result");
|
|
});
|
|
|
|
it.each([
|
|
"parse_javascript_source",
|
|
"build_javascript_application_graph",
|
|
"seal_javascript_application_graph",
|
|
"build_javascript_semantic_graph",
|
|
"seal_javascript_semantic_graph",
|
|
"validate_javascript_application_result",
|
|
"create_javascript_application_evidence",
|
|
"seal_javascript_application_result",
|
|
"validate_javascript_application_evidence",
|
|
"hash_javascript_application_evidence",
|
|
])("rejects cancellation scheduled during %s", async (phase) => {
|
|
const root = await createTestTempDirectory("rea-js-cancel-phase-");
|
|
await writeFile(
|
|
join(root, "main.js"),
|
|
"export function inspect(value) { return JSON.stringify(value); }\n",
|
|
);
|
|
const controller = new AbortController();
|
|
let requested = false;
|
|
const terminal: string[] = [];
|
|
const result = await analyzeJavaScriptApplication(
|
|
{ input_path: root, format: "directory" },
|
|
{
|
|
signal: controller.signal,
|
|
progress: {
|
|
async report(event) {
|
|
if (event.terminal) terminal.push(event.phase);
|
|
if (event.phase === phase) {
|
|
requested = true;
|
|
setImmediate(() => controller.abort());
|
|
}
|
|
},
|
|
},
|
|
},
|
|
);
|
|
expect(requested).toBe(true);
|
|
if (result.ok)
|
|
throw new Error("Cancelled analysis must not publish Evidence");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "cancelled",
|
|
details: { reason: "cancelled" },
|
|
});
|
|
expect(terminal).toEqual([]);
|
|
});
|
|
|
|
it("honors cancellation observed during the terminal publication race", async () => {
|
|
const root = await createTestTempDirectory("rea-js-cancel-terminal-");
|
|
await writeFile(join(root, "main.js"), "export const value = 1;\n");
|
|
const controller = new AbortController();
|
|
const result = await analyzeJavaScriptApplication(
|
|
{ input_path: root, format: "directory" },
|
|
{
|
|
signal: controller.signal,
|
|
progress: {
|
|
async report(event) {
|
|
if (event.terminal) controller.abort();
|
|
},
|
|
},
|
|
},
|
|
);
|
|
if (result.ok) throw new Error("Expected cancellation before admission");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
details: { reason: "cancelled" },
|
|
});
|
|
});
|
|
});
|