* refactor(test): colocate pure-domain tests and reduce test debt Move focused immutable domain/contracts/adapter tests from tests/composition/** beside their production owners under src/** as colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped composition tests under tests/boundary/filesystem/**. Update import paths, the Vitest project topology (shared worker context for pure domain/contracts and recording-port service projects), the test migration ledger, testing docs, and AGENTS.md to match. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: remove test migration ledger The cutover is complete and the ledger is no longer referenced anywhere in source, scripts, or the docs gate. Drop the standalone artifact. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: clean up stale migration artifacts Remove empty directories left by the test migration and replace the "final cutover" language in docs/testing.md with standing PR guidance that no longer references the completed migration. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: repair CI failures from schema, knip, and stale generated artifacts Three root causes fixed: 1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a discriminated union produces oneOf, so the product catalog generator could not derive the web_screenshot_diff schema version. Add oneOf traversal. 2. conformancePackage.ts: the test rewrite removed the only imports of ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making them unused exports that knip flags. Remove the dead type aliases. 3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill metadata, conformance manifest) that drifted from the source changes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
268 lines
8.8 KiB
TypeScript
268 lines
8.8 KiB
TypeScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { createPackageWithOptions } from "@electron/asar";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
import { runCrossVersionInvestigation } from "../../../src/application/CrossVersionInvestigation.js";
|
|
import {
|
|
readInvestigationWorkspace,
|
|
writeInvestigationWorkspace,
|
|
} from "../../../src/application/InvestigationWorkspaceStore.js";
|
|
import { createEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
|
import type { EvidenceFilePolicy } from "../../../src/domain/evidenceBundle.js";
|
|
import {
|
|
createInvestigationWorkspace,
|
|
crossVersionInvestigationInputSchema,
|
|
investigationRunSchema,
|
|
} from "../../../src/domain/investigationWorkspace.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
|
|
const policy = (root: string): EvidenceFilePolicy => ({
|
|
roots: [root],
|
|
maxBytes: 64 * 1024 * 1024,
|
|
maxDepth: 64,
|
|
maxStringLength: 1024 * 1024,
|
|
maxNodes: 1_000_000,
|
|
});
|
|
|
|
const fixture = async () => {
|
|
const directory = await createTestTempDirectory("rea-workspace-");
|
|
const left = join(directory, "left");
|
|
const right = join(directory, "right");
|
|
await Promise.all([mkdir(left), mkdir(right)]);
|
|
await Promise.all([
|
|
writeFile(join(left, "app.txt"), "version one\n"),
|
|
writeFile(join(right, "app.txt"), "version two\n"),
|
|
writeFile(join(right, "added.txt"), "new behavior candidate\n"),
|
|
]);
|
|
const path = join(directory, "workspace.json");
|
|
const input = crossVersionInvestigationInputSchema.parse({
|
|
approved: true,
|
|
workspace_path: path,
|
|
workspace_name: "release-diff",
|
|
left_path: left,
|
|
right_path: right,
|
|
options: { page_size: 2, change_limit: 100 },
|
|
});
|
|
return { directory, left, right, path, input };
|
|
};
|
|
|
|
describe("persistent cross-version investigation workspace", () => {
|
|
it("enforces shared JSON depth limits while reading workspaces", async () => {
|
|
const { directory, path, input } = await fixture();
|
|
const completed = await runCrossVersionInvestigation(
|
|
input,
|
|
policy(directory),
|
|
{ inputRoots: [directory] },
|
|
);
|
|
if (!completed.ok) throw completed.error;
|
|
|
|
await expect(
|
|
readInvestigationWorkspace(path, {
|
|
...policy(directory),
|
|
maxDepth: 1,
|
|
}),
|
|
).resolves.toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "InvestigationWorkspaceError", reason: "too-large" },
|
|
});
|
|
});
|
|
|
|
it("resumes from a comparison checkpoint without recomputing its identity", async () => {
|
|
const { directory, input } = await fixture();
|
|
const completed = await runCrossVersionInvestigation(
|
|
input,
|
|
policy(directory),
|
|
{ inputRoots: [directory] },
|
|
);
|
|
if (!completed.ok) throw completed.error;
|
|
const run = completed.value.workspace.runs[0];
|
|
if (run === undefined || run.comparison_evidence_id === null)
|
|
throw new Error("missing completed run");
|
|
const partialRun = investigationRunSchema.parse({
|
|
...run,
|
|
status: "running",
|
|
completed_stages: [
|
|
"inventory_left",
|
|
"inventory_right",
|
|
"compare_artifacts",
|
|
],
|
|
result_evidence_id: null,
|
|
});
|
|
const records = completed.value.workspace.bundle.records.filter(
|
|
({ evidence_id: id }) => id !== run.result_evidence_id,
|
|
);
|
|
const partial = createInvestigationWorkspace(
|
|
"release-diff",
|
|
createEvidenceBundle(records),
|
|
[partialRun],
|
|
);
|
|
const resumePath = join(directory, "resume.json");
|
|
expect(
|
|
await writeInvestigationWorkspace(
|
|
partial,
|
|
resumePath,
|
|
null,
|
|
policy(directory),
|
|
),
|
|
).toMatchObject({ ok: true });
|
|
|
|
const replayAuthorization = vi.fn(() => Promise.resolve(ok(null)));
|
|
await expect(
|
|
runCrossVersionInvestigation(
|
|
{
|
|
...input,
|
|
workspace_path: resumePath,
|
|
replay_run_id: partialRun.run_id,
|
|
},
|
|
policy(directory),
|
|
{ inputRoots: [], authorizeInputRead: replayAuthorization },
|
|
),
|
|
).resolves.toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "InvestigationWorkspaceError",
|
|
reason: "revision-conflict",
|
|
},
|
|
});
|
|
expect(replayAuthorization).not.toHaveBeenCalled();
|
|
|
|
const resumed = await runCrossVersionInvestigation(
|
|
{ ...input, workspace_path: resumePath },
|
|
policy(directory),
|
|
{ inputRoots: [directory] },
|
|
);
|
|
expect(resumed).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
reused: false,
|
|
evidence: { evidence_id: completed.value.evidence.evidence_id },
|
|
workspace: { revision: 2 },
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("persistent investigation workspace history", () => {
|
|
it("appends a changed-content run without replacing earlier Evidence", async () => {
|
|
const { directory, right, input } = await fixture();
|
|
const first = await runCrossVersionInvestigation(input, policy(directory), {
|
|
inputRoots: [directory],
|
|
});
|
|
if (!first.ok) throw first.error;
|
|
const firstRun = first.value.workspace.runs[0];
|
|
if (firstRun === undefined || firstRun.result_evidence_id === null)
|
|
throw new Error("missing first completed run");
|
|
|
|
await writeFile(join(right, "app.txt"), "version three\n");
|
|
const second = await runCrossVersionInvestigation(
|
|
input,
|
|
policy(directory),
|
|
{ inputRoots: [directory] },
|
|
);
|
|
expect(second).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
reused: false,
|
|
workspace: {
|
|
revision: 6,
|
|
runs: [{ status: "complete" }, { status: "complete" }],
|
|
},
|
|
},
|
|
});
|
|
if (!second.ok) throw second.error;
|
|
expect(second.value.workspace.runs).toHaveLength(2);
|
|
expect(second.value.workspace.runs.map(({ run_id: id }) => id)).toContain(
|
|
firstRun.run_id,
|
|
);
|
|
expect(
|
|
second.value.workspace.bundle.records.some(
|
|
({ evidence_id: id }) => id === firstRun.result_evidence_id,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("checkpoints bounded integrity contradictions and safely reuses them", async () => {
|
|
const directory = await createTestTempDirectory("rea-workspace-integrity-");
|
|
const source = join(directory, "source");
|
|
await mkdir(source);
|
|
await writeFile(join(source, "addon.node"), "verified native addon\n");
|
|
const left = join(directory, "left.asar");
|
|
const right = join(directory, "right.asar");
|
|
await Promise.all([
|
|
createPackageWithOptions(source, left, { unpack: "*.node" }),
|
|
createPackageWithOptions(source, right, { unpack: "*.node" }),
|
|
]);
|
|
await writeFile(join(`${right}.unpacked`, "addon.node"), "tampered\n");
|
|
const base = {
|
|
approved: true as const,
|
|
workspace_path: join(directory, "strict.json"),
|
|
workspace_name: "integrity-diff",
|
|
left_path: left,
|
|
right_path: right,
|
|
options: { page_size: 500, change_limit: 100 },
|
|
};
|
|
const strict = await runCrossVersionInvestigation(
|
|
crossVersionInvestigationInputSchema.parse(base),
|
|
policy(directory),
|
|
{ inputRoots: [directory] },
|
|
);
|
|
expect(strict).toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "ArtifactOperationError", reason: "integrity" },
|
|
});
|
|
|
|
const continuedInput = crossVersionInvestigationInputSchema.parse({
|
|
...base,
|
|
workspace_path: join(directory, "continued.json"),
|
|
integrity_policy: "record-and-continue",
|
|
integrity_continue_approved: true,
|
|
max_integrity_mismatches: 2,
|
|
});
|
|
const continued = await runCrossVersionInvestigation(
|
|
continuedInput,
|
|
policy(directory),
|
|
{ inputRoots: [directory], integrityContinueEnabled: true },
|
|
);
|
|
expect(continued).toMatchObject({
|
|
ok: true,
|
|
value: { reused: false, workspace: { revision: 3 } },
|
|
});
|
|
if (!continued.ok) throw continued.error;
|
|
expect(
|
|
continued.value.workspace.bundle.records.some((record) =>
|
|
JSON.stringify(record.normalized_result).includes(
|
|
'"integrity_contradictions":[{',
|
|
),
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
continued.value.workspace.bundle.records.find(
|
|
({ operation }) => operation === "compare_artifacts",
|
|
)?.normalized_result,
|
|
).toMatchObject({ status: "contradiction" });
|
|
await expect(
|
|
runCrossVersionInvestigation(continuedInput, policy(directory), {
|
|
inputRoots: [directory],
|
|
integrityContinueEnabled: true,
|
|
}),
|
|
).resolves.toMatchObject({ ok: true, value: { reused: true } });
|
|
|
|
const strictAfterContinuation = crossVersionInvestigationInputSchema.parse({
|
|
...base,
|
|
workspace_path: continuedInput.workspace_path,
|
|
});
|
|
await expect(
|
|
runCrossVersionInvestigation(strictAfterContinuation, policy(directory), {
|
|
inputRoots: [directory],
|
|
}),
|
|
).resolves.toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "ArtifactOperationError", reason: "integrity" },
|
|
});
|
|
});
|
|
});
|