Files
rea/tests/boundary/filesystem/investigationWorkspaceIntegrity.test.ts
T
morlutoGitHubDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
e91c8c39c2 refactor(test): colocate pure-domain tests and reduce test debt (#471)
* 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>
2026-08-10 14:57:44 +08:00

174 lines
5.6 KiB
TypeScript

import {
chmod,
mkdir,
readFile,
rm,
stat,
symlink,
writeFile,
} from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { runCrossVersionInvestigation } from "../../../src/application/CrossVersionInvestigation.js";
import { readInvestigationWorkspace } from "../../../src/application/InvestigationWorkspaceStore.js";
import type { EvidenceFilePolicy } from "../../../src/domain/evidenceBundle.js";
import { crossVersionInvestigationInputSchema } from "../../../src/domain/investigationWorkspace.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("fails closed on locks, CAS conflicts, tampering, and cancellation", async () => {
const { directory, path, input } = await fixture();
await writeFile(`${path}.lock`, `${String(process.pid)}\n`, {
mode: 0o600,
});
expect(
await runCrossVersionInvestigation(input, policy(directory), {
inputRoots: [directory],
}),
).toMatchObject({
ok: false,
error: { _tag: "InvestigationWorkspaceError", reason: "locked" },
});
await rm(`${path}.lock`);
await writeFile(`${path}.lock`, "occupied\n", { mode: 0o600 });
expect(
await runCrossVersionInvestigation(input, policy(directory), {
inputRoots: [directory],
}),
).toMatchObject({
ok: false,
error: { _tag: "InvestigationWorkspaceError", reason: "locked" },
});
await rm(`${path}.lock`);
await writeFile(`${path}.lock`, "2147483647\n", { mode: 0o600 });
const completed = await runCrossVersionInvestigation(
input,
policy(directory),
{ inputRoots: [directory] },
);
if (!completed.ok) throw completed.error;
await expect(stat(`${path}.lock`)).rejects.toMatchObject({
code: "ENOENT",
});
expect(
await runCrossVersionInvestigation(
{ ...input, expected_workspace_revision: 2 },
policy(directory),
{ inputRoots: [directory] },
),
).toMatchObject({
ok: false,
error: {
_tag: "InvestigationWorkspaceError",
reason: "revision-conflict",
},
});
const decoded = JSON.parse(await readFile(path, "utf8")) as unknown;
if (typeof decoded !== "object" || decoded === null)
throw new Error("invalid workspace fixture");
await chmod(path, 0o600);
await writeFile(path, JSON.stringify({ ...decoded, revision: 99 }));
expect(
await readInvestigationWorkspace(path, policy(directory)),
).toMatchObject({
ok: false,
error: { _tag: "InvestigationWorkspaceError", reason: "integrity" },
});
const cancelledPath = join(directory, "cancelled.json");
const controller = new AbortController();
controller.abort();
expect(
await runCrossVersionInvestigation(
{ ...input, workspace_path: cancelledPath },
policy(directory),
{ inputRoots: [directory], signal: controller.signal },
),
).toMatchObject({
ok: false,
error: { _tag: "AnalysisCancelledError" },
});
});
it("rejects workspace paths and symlinks outside approved roots", async () => {
const { directory, input } = await fixture();
const approved = join(directory, "approved");
await mkdir(approved);
expect(
await runCrossVersionInvestigation(input, policy(approved), {
inputRoots: [directory],
}),
).toMatchObject({
ok: false,
error: {
_tag: "InvestigationWorkspaceError",
reason: "outside-root",
},
});
const outside = join(directory, "outside.json");
await writeFile(outside, "{}", { mode: 0o600 });
const escaped = join(approved, "escaped.json");
await symlink(outside, escaped);
expect(
await runCrossVersionInvestigation(
{ ...input, workspace_path: escaped },
policy(approved),
{ inputRoots: [directory] },
),
).toMatchObject({
ok: false,
error: { _tag: "InvestigationWorkspaceError", reason: "not-file" },
});
});
it("rejects artifact inputs outside independently approved roots", async () => {
const { directory, input, path } = await fixture();
const approvedInputs = join(directory, "approved-inputs");
await mkdir(approvedInputs);
expect(
await runCrossVersionInvestigation(input, policy(directory), {
inputRoots: [approvedInputs],
}),
).toMatchObject({
ok: false,
error: { _tag: "ArtifactOperationError", reason: "path" },
});
await expect(stat(path)).rejects.toMatchObject({ code: "ENOENT" });
});
});