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>
This commit is contained in:
morluto
2026-08-10 14:57:44 +08:00
committed by GitHub
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 344b9b6dff
commit e91c8c39c2
302 changed files with 6822 additions and 5781 deletions
+163
View File
@@ -0,0 +1,163 @@
import { describe, expect, it } from "vitest";
import { RECONSTRUCTION_READINESS_EXAMPLE } from "../contracts/reconstructionReadinessExample.js";
import { createReconstructionReadinessReport } from "./reconstructionReadiness.js";
import type { ReconstructionReadinessInput } from "./reconstructionReadinessSchemas.js";
const input = (
overrides: Partial<ReconstructionReadinessInput> = {},
): ReconstructionReadinessInput => ({
...structuredClone(RECONSTRUCTION_READINESS_EXAMPLE),
...overrides,
});
describe("reconstruction readiness report", () => {
it("passes the complete public-contract journey deterministically", () => {
const first = createReconstructionReadinessReport(input());
const second = createReconstructionReadinessReport(input());
expect(first.status).toBe("pass");
expect(first.summary).toMatchObject({
required_stages: 9,
passed_required_stages: 9,
findings: 0,
});
expect(first.report_id).toBe(second.report_id);
expect(first.report_digest).toBe(second.report_digest);
expect(first.metrics).toMatchObject({
first_valid_workflow_selection_rate: 1,
incompatible_provider_invocations: 0,
false_equivalence_count: 0,
unowned_obligation_count: 0,
cleanup_leak_count: 0,
nondeterministic_replay_count: 0,
});
});
it("rejects equivalence over truncated concurrent evidence", () => {
const value = input();
const comparison = value.comparisons[0];
if (comparison === undefined) throw new TypeError("Missing comparison");
value.comparisons[0] = {
...comparison,
schedule_semantics: "total-order",
truncated: true,
};
const report = createReconstructionReadinessReport(value);
expect(report.status).toBe("fail");
expect(report.findings.map(({ code }) => code)).toEqual(
expect.arrayContaining([
"false-equivalence",
"unsafe-concurrency-semantics",
]),
);
expect(report.metrics.false_equivalence_count).toBe(1);
});
it("keeps green stages unknown while one reconstruction obligation is open", () => {
const value = input();
value.obligation_ledger = {
...value.obligation_ledger,
status: "open",
summary: {
...value.obligation_ledger.summary,
verified: 0,
required_open: 1,
},
};
const report = createReconstructionReadinessReport(value);
expect(report.status).toBe("unknown");
expect(report.stages).toContainEqual(
expect.objectContaining({
stage_id: "verify-reconstruction-closure",
status: "unknown",
}),
);
expect(report.findings).toContainEqual(
expect.objectContaining({ code: "reconstruction-closure-open" }),
);
});
it("fails typed operation outcomes that ordinary automation sees as success", () => {
const value = input();
const cliOutcome = value.operation_outcomes[2];
const mcpOutcome = value.operation_outcomes[3];
if (cliOutcome === undefined || mcpOutcome === undefined)
throw new TypeError("Missing operation outcome pair");
value.operation_outcomes[2] = {
...cliOutcome,
cli_exit_code: 0,
};
value.operation_outcomes[3] = {
...mcpOutcome,
mcp_status: "success",
};
const report = createReconstructionReadinessReport(value);
expect(report.status).toBe("fail");
expect(report.findings.map(({ code }) => code)).toEqual(
expect.arrayContaining(["cli-status-mismatch", "mcp-status-mismatch"]),
);
});
it("detects tampering against the exported source digest", () => {
const baseline = createReconstructionReadinessReport(input());
const replay = input({
replay: {
...RECONSTRUCTION_READINESS_EXAMPLE.replay,
expected_source_digest: baseline.source_digest,
},
});
expect(createReconstructionReadinessReport(replay).source_digest).toBe(
baseline.source_digest,
);
replay.identity.cli_version = "tampered";
const tampered = createReconstructionReadinessReport(replay);
expect(tampered.status).toBe("fail");
expect(tampered.findings).toContainEqual(
expect.objectContaining({ code: "replay-source-digest-mismatch" }),
);
});
it("fails a reconstruction candidate that delegates to the authority", () => {
const value = input();
const check = value.delegation_checks[0];
if (check === undefined) throw new TypeError("Missing delegation check");
value.delegation_checks[0] = {
...check,
delegates_to_authority: true,
};
const report = createReconstructionReadinessReport(value);
expect(report.status).toBe("fail");
expect(report.findings).toContainEqual(
expect.objectContaining({ code: "candidate-delegates-to-authority" }),
);
});
it("preserves an exact unsupported stage without collapsing it to pass", () => {
const value = input();
const stage = value.stages.find(
({ stage_id: stageId }) => stageId === "reactive-scenarios",
);
const check = stage?.checks[0];
if (stage === undefined || check === undefined)
throw new TypeError("Missing reactive stage");
stage.status = "unsupported";
check.status = "unsupported";
stage.capability_issue = "electron-runtime-unavailable";
stage.next_action = "Run on a host with the approved Electron runtime.";
const report = createReconstructionReadinessReport(value);
expect(report.status).toBe("unsupported");
expect(report.stages).toContainEqual(
expect.objectContaining({
stage_id: "reactive-scenarios",
status: "unsupported",
}),
);
});
});