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
@@ -0,0 +1,262 @@
import { describe, expect, it } from "vitest";
import {
runPairedProcessExperiment,
type ProcessCapturePort,
} from "./ProcessPairedExperiment.js";
import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../contracts/processCaptureExample.js";
import {
parseProcessCapture,
type EnabledProcessExecutionPolicy,
} from "../domain/processCapture.js";
import {
analyzeProcessRepeatability,
bindProcessScenario,
processPairedExperimentSchema,
} from "../domain/processPairedExperiment.js";
import { ok } from "../domain/result.js";
const experiment = () =>
processPairedExperimentSchema.parse({
approved: true,
shared_scenario: {
approved: true,
executable: "/bin/template",
arguments: ["shared"],
working_directory: "/tmp",
environment: { SHARED: "yes" },
},
authority: {
id: "authority",
executable: "/bin/authority",
environment: { SIDE: "authority" },
},
candidate: {
id: "candidate",
executable: "/bin/candidate",
arguments: ["candidate"],
environment: { SIDE: "candidate" },
},
repeat_count: 3,
freshness_policy: { max_capture_age_ms: 60_000 },
required_dimensions: [
"terminal",
"interaction",
"exit",
"filesystem",
"protocol",
"process",
"shim",
],
});
const policy: EnabledProcessExecutionPolicy = {
status: "enabled",
executableRoots: ["/bin"],
workingRoots: ["/tmp"],
allowedEnvironment: ["SHARED", "SIDE"],
networkAccess: "none",
};
const cloneCapture = (
capture: ReturnType<typeof parseProcessCapture>,
): ReturnType<typeof parseProcessCapture> =>
parseProcessCapture(structuredClone(capture));
describe("paired process experiments", () => {
it("binds only declared side inputs onto the shared observation contract", () => {
const parsed = experiment();
const authority = bindProcessScenario(
parsed.shared_scenario,
parsed.authority,
);
const candidate = bindProcessScenario(
parsed.shared_scenario,
parsed.candidate,
);
expect(authority).toMatchObject({
executable: "/bin/authority",
arguments: ["shared"],
environment: { SHARED: "yes", SIDE: "authority" },
});
expect(candidate).toMatchObject({
executable: "/bin/candidate",
arguments: ["candidate"],
environment: { SHARED: "yes", SIDE: "candidate" },
});
});
it("runs same-side comparisons first and compares stable sides", async () => {
const observedExecutables: string[] = [];
const capture = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
const capturePort: ProcessCapturePort = {
capture: (scenario) => {
observedExecutables.push(scenario.executable);
return Promise.resolve(ok(cloneCapture(capture)));
},
};
const result = await runPairedProcessExperiment(experiment(), policy, {
capturePort,
now: () => Date.parse("2026-01-01T00:00:01.000Z"),
});
expect(result.ok).toBe(true);
if (!result.ok) return;
expect(observedExecutables).toEqual([
"/bin/authority",
"/bin/authority",
"/bin/authority",
"/bin/candidate",
"/bin/candidate",
"/bin/candidate",
]);
expect(result.value.authority_repeatability.stable).toBe(true);
expect(result.value.candidate_repeatability.stable).toBe(true);
expect(result.value.cross_side?.status).toBe("unchanged");
expect(result.value.cross_side_blocked_reason).toBeNull();
});
it("blocks cross-side claims when a candidate has a flaky exit", async () => {
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
let candidateRun = 0;
const capturePort: ProcessCapturePort = {
capture: (scenario) => {
let capture = cloneCapture(base);
if (scenario.executable === "/bin/candidate") {
candidateRun += 1;
if (candidateRun === 2)
capture = parseProcessCapture({
...capture,
exit: { code: 1, signal: null, reason: "exited" },
});
}
return Promise.resolve(ok(capture));
},
};
const result = await runPairedProcessExperiment(experiment(), policy, {
capturePort,
now: () => Date.parse("2026-01-01T00:00:01.000Z"),
});
expect(result.ok).toBe(true);
if (!result.ok) return;
expect(result.value.candidate_repeatability).toMatchObject({
stable: false,
classification: "flaky_exit",
unstable_dimensions: ["exit"],
});
expect(result.value.cross_side).toBeNull();
expect(result.value.cross_side_blocked_reason).toMatch(/unstable/u);
});
});
describe("paired process experiment comparisons", () => {
it("distinguishes normalized timing variance from semantic output drift", () => {
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
const early = parseProcessCapture({
...base,
frames: [{ sequence: 0, at_ms: 10, data: "ready" }],
});
const late = parseProcessCapture({
...base,
frames: [{ sequence: 0, at_ms: 20, data: "ready" }],
});
expect(
analyzeProcessRepeatability([early, late], ["terminal"]),
).toMatchObject({
stable: false,
classification: "timing_variance",
unstable_dimensions: ["terminal"],
});
const changed = parseProcessCapture({
...base,
frames: [{ sequence: 0, at_ms: 20, data: "failed" }],
});
expect(
analyzeProcessRepeatability([early, changed], ["terminal"]),
).toMatchObject({ classification: "nondeterministic_output" });
});
it("stops before capture when the experiment is cancelled", async () => {
const controller = new AbortController();
controller.abort();
const capturePort: ProcessCapturePort = {
capture: () => {
throw new Error("capture must not start after cancellation");
},
};
const result = await runPairedProcessExperiment(experiment(), policy, {
capturePort,
signal: controller.signal,
});
expect(result).toMatchObject({
ok: false,
error: { _tag: "ProcessCaptureError", reason: "cancelled" },
});
});
it("blocks full cross-side output when only a subset was repeatable", async () => {
const capture = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
const capturePort: ProcessCapturePort = {
capture: () => Promise.resolve(ok(cloneCapture(capture))),
};
const subset = processPairedExperimentSchema.parse({
...experiment(),
required_dimensions: ["exit"],
});
const result = await runPairedProcessExperiment(subset, policy, {
capturePort,
});
expect(result).toMatchObject({
ok: true,
value: {
cross_side: null,
cross_side_blocked_reason: expect.stringMatching(/every returned/u),
},
});
});
});
describe("paired process experiment freshness", () => {
it("compares the newest stable captures under the freshness policy", async () => {
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
let captureIndex = 0;
const capturePort: ProcessCapturePort = {
capture: () => {
const completedAt =
captureIndex === 0
? "2026-01-01T00:00:00.000Z"
: "2026-01-01T00:00:09.500Z";
captureIndex += 1;
return Promise.resolve(
ok(
parseProcessCapture({
...structuredClone(base),
manifest: {
...base.manifest,
started_at: completedAt,
completed_at: completedAt,
},
}),
),
);
},
};
const shortFreshness = processPairedExperimentSchema.parse({
...experiment(),
freshness_policy: { max_capture_age_ms: 1_000 },
});
const result = await runPairedProcessExperiment(shortFreshness, policy, {
capturePort,
now: () => Date.parse("2026-01-01T00:00:10.000Z"),
});
expect(result).toMatchObject({
ok: true,
value: { cross_side: { status: "unchanged" } },
});
});
});