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
@@ -2,17 +2,12 @@ import { describe, expect, it } from "vitest";
import {
CONFORMANCE_PACKAGE_VERSION,
conformancePackageSchema,
computePackageId,
createConformancePackage,
validateConformancePackage,
type ScenarioManifest,
type ReplayPlan,
type ShimPlan,
type ExpectedEvidence,
parseConformancePackage,
type ConformancePackageInput,
} from "../../../src/domain/conformancePackage.js";
const validPackage = createConformancePackage({
const validPackageInput: ConformancePackageInput = {
schema_version: CONFORMANCE_PACKAGE_VERSION,
name: "test-fixture",
description: "A test conformance fixture",
@@ -63,119 +58,147 @@ const validPackage = createConformancePackage({
timing_tolerance_ms: 100,
},
],
});
};
describe("conformance package format", () => {
it("validates a well-formed package", () => {
const result = validateConformancePackage(validPackage);
expect(result.ok).toBe(true);
const validPackage = createConformancePackage(validPackageInput);
describe("conformance package parsing", () => {
it("parses a well-formed content-addressed package", () => {
expect(parseConformancePackage(validPackage)).toEqual({
ok: true,
value: validPackage,
});
});
it("rejects invalid schema version", () => {
const result = validateConformancePackage({
...validPackage,
schema_version: 999,
});
expect(result.ok).toBe(false);
it("rejects invalid package structure", () => {
expect(
parseConformancePackage({ ...validPackage, schema_version: 999 }),
).toMatchObject({ ok: false, error: { kind: "invalid_package" } });
});
it("rejects duplicate scenario IDs", () => {
const result = validateConformancePackage({
...validPackage,
scenarios: [validPackage.scenarios[0], validPackage.scenarios[0]],
expect(
parseConformancePackage({
...validPackage,
scenarios: [validPackage.scenarios[0], validPackage.scenarios[0]],
}),
).toMatchObject({
ok: false,
error: { kind: "duplicate_scenario", scenario_id: "s1" },
});
expect(result.ok).toBe(false);
});
it("rejects replay plan referencing non-existent scenario", () => {
const result = validateConformancePackage({
...validPackage,
replay_plans: [
{
scenario_id: "nonexistent",
steps: [
{
step_id: "step1",
action: "run",
arguments: [],
timeout_ms: 1000,
},
],
environment: {},
},
],
});
expect(result.ok).toBe(false);
});
it("rejects verifier contract referencing non-existent scenario", () => {
const result = validateConformancePackage({
...validPackage,
verifier_contracts: [
{
scenario_id: "nonexistent",
dimensions: [
{ name: "exit_code", required: true, comparison: "exact" },
],
timing_tolerance_ms: 0,
},
],
});
expect(result.ok).toBe(false);
});
it("rejects expected evidence referencing non-existent scenario", () => {
const result = validateConformancePackage({
...validPackage,
expected_evidence: [
{
scenario_id: "nonexistent",
envelopes: [],
bundle: null,
required_dimensions: [],
},
],
});
expect(result.ok).toBe(false);
});
it("computes a deterministic package ID", () => {
const id = computePackageId({
...validPackage,
});
expect(id).toMatch(/^cp_[a-f0-9]{64}$/u);
// Same input yields same ID
const id2 = computePackageId({
...validPackage,
});
expect(id).toBe(id2);
});
it("produces different IDs for different packages", () => {
const id1 = computePackageId({ ...validPackage, name: "packageA" });
const id2 = computePackageId({ ...validPackage, name: "packageB" });
expect(id1).not.toBe(id2);
});
it("uses all exported types", () => {
const scenario: ScenarioManifest = validPackage.scenarios[0]!;
expect(scenario.scenario_id).toBe("s1");
const replay: ReplayPlan = validPackage.replay_plans[0]!;
expect(replay.scenario_id).toBe("s1");
const shim: ShimPlan = validPackage.shim_plans[0] ?? {
scenario_id: "s1",
it.each([
["replay_plans", "replay_plans"],
["shim_plans", "shim_plans"],
["expected_evidence", "expected_evidence"],
["verifier_contracts", "verifier_contracts"],
] as const)("rejects an unknown scenario in %s", (field, section) => {
const existing = validPackage[field][0];
const candidate = existing ?? {
scenario_id: "nonexistent",
shims: [],
};
expect(shim.scenario_id).toBe("s1");
const evidence: ExpectedEvidence = validPackage.expected_evidence[0]!;
expect(evidence.scenario_id).toBe("s1");
expect(
parseConformancePackage({
...validPackage,
[field]: [{ ...candidate, scenario_id: "nonexistent" }],
}),
).toMatchObject({
ok: false,
error: {
kind: "unknown_scenario_reference",
section,
scenario_id: "nonexistent",
},
});
});
it("parses via zod schema", () => {
const result = conformancePackageSchema.safeParse(validPackage);
expect(result.success).toBe(true);
it("requires one replay plan for every scenario", () => {
expect(
parseConformancePackage({
...validPackage,
scenarios: [
...validPackage.scenarios,
{
scenario_id: "s2",
name: "Second scenario",
description: "A second process scenario",
fixture_path: "tests/conformance/c/fixture2.c",
expected_exit_code: 0,
expected_patterns: [],
},
],
}),
).toMatchObject({
ok: false,
error: {
kind: "missing_scenario_reference",
section: "replay_plans",
scenario_id: "s2",
},
});
});
it("rejects duplicate per-scenario records", () => {
expect(
parseConformancePackage({
...validPackage,
verifier_contracts: [
validPackage.verifier_contracts[0],
validPackage.verifier_contracts[0],
],
}),
).toMatchObject({
ok: false,
error: {
kind: "duplicate_scenario_reference",
section: "verifier_contracts",
scenario_id: "s1",
},
});
});
it("rejects a stale package identifier", () => {
expect(
parseConformancePackage({ ...validPackage, name: "modified" }),
).toMatchObject({
ok: false,
error: { kind: "package_id_mismatch" },
});
});
});
describe("conformance package construction", () => {
it("derives a deterministic identifier from parsed contents", () => {
const same = createConformancePackage(validPackageInput);
const changed = createConformancePackage({
...validPackageInput,
name: "another-package",
});
expect(same.package_id).toBe(validPackage.package_id);
expect(changed.package_id).not.toBe(validPackage.package_id);
});
it("applies schema defaults before committing the identifier", () => {
const { shim_plans: _shimPlans, ...withoutOptionalShimPlans } =
validPackageInput;
const created = createConformancePackage(withoutOptionalShimPlans);
expect(created.shim_plans).toEqual([]);
expect(parseConformancePackage(created)).toEqual({
ok: true,
value: created,
});
});
it("cannot construct a package with contradictory scenario relations", () => {
expect(() =>
createConformancePackage({
...validPackageInput,
scenarios: [...validPackage.scenarios, ...validPackage.scenarios],
}),
).toThrow(/Duplicate scenario s1/u);
});
});
@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
import {
CONFORMANCE_PACKAGE_VERSION,
createConformancePackage,
type ConformancePackage,
type ConformancePackageInput,
} from "../../../src/domain/conformancePackage.js";
import { createEvidence } from "../../../src/domain/evidence.js";
import {
@@ -11,7 +11,7 @@ import {
type ScenarioReplayResult,
} from "../../../src/domain/conformanceReplay.js";
const validPackage = createConformancePackage({
const validPackageInput: ConformancePackageInput = {
schema_version: CONFORMANCE_PACKAGE_VERSION,
name: "test-fixture",
description: "A test conformance fixture",
@@ -56,7 +56,9 @@ const validPackage = createConformancePackage({
timing_tolerance_ms: 0,
},
],
});
};
const validPackage = createConformancePackage(validPackageInput);
async function passingRunner(
scenarioId: string,
@@ -123,7 +125,7 @@ describe("conformance CI replay", () => {
{ operation: "run", parameters: {}, result: { exit_code: 0 } },
);
const pkg = createConformancePackage({
...validPackage,
...validPackageInput,
expected_evidence: [
{
scenario_id: "s1",
@@ -158,11 +160,10 @@ describe("conformance CI replay", () => {
});
it("counts all result types", async () => {
const base: ConformancePackage = validPackage;
const multiPackage = createConformancePackage({
...base,
...validPackageInput,
scenarios: [
base.scenarios[0]!,
...validPackage.scenarios,
{
scenario_id: "s2",
name: "Second scenario",
@@ -173,7 +174,7 @@ describe("conformance CI replay", () => {
},
],
replay_plans: [
base.replay_plans[0]!,
...validPackage.replay_plans,
{
scenario_id: "s2",
steps: [
@@ -188,7 +189,7 @@ describe("conformance CI replay", () => {
},
],
expected_evidence: [
base.expected_evidence[0]!,
...validPackage.expected_evidence,
{
scenario_id: "s2",
envelopes: [],
@@ -197,7 +198,7 @@ describe("conformance CI replay", () => {
},
],
verifier_contracts: [
base.verifier_contracts[0]!,
...validPackage.verifier_contracts,
{
scenario_id: "s2",
dimensions: [
@@ -224,3 +225,30 @@ describe("conformance CI replay", () => {
expect(result.failed).toBe(1);
});
});
describe("conformance replay package boundary", () => {
it("rejects shape-valid packages with broken scenario relations", async () => {
await expect(
replayConformancePackage(
{
...validPackage,
replay_plans: [
{
scenario_id: "missing",
steps: [
{
step_id: "step1",
action: "run",
arguments: [],
timeout_ms: 1000,
},
],
environment: {},
},
],
},
{},
),
).rejects.toThrow(/replay_plans references unknown scenario missing/u);
});
});
@@ -5,6 +5,7 @@ import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../../../../src/contracts/m
import { createEvidence } from "../../../../src/domain/evidence.js";
import {
managedNativeVerificationInputSchema,
managedNativeVerificationResultSchema,
verifyManagedNativeBoundaries,
} from "../../../../src/domain/managedNativeVerification.js";
import { inspectMachoSchema } from "../../../../src/domain/nativeInspection.js";
@@ -206,3 +207,48 @@ describe("managed/native boundary verification", () => {
expect(evidence.value.evidence_links).toHaveLength(2);
});
});
describe("managed/native verification result algebra", () => {
it("rejects states without their required native match", () => {
const result = verifyManagedNativeBoundaries(exampleInput());
const verification = result.pinvoke_imports[0];
expect(verification).toBeDefined();
if (verification === undefined) return;
expect(
managedNativeVerificationResultSchema.safeParse({
...result,
pinvoke_imports: [
{
...verification,
matched_native: null,
candidates: [],
},
],
}).success,
).toBe(false);
expect(
managedNativeVerificationResultSchema.safeParse({
...result,
pinvoke_imports: [
{
...verification,
status: "unresolved",
basis: "no-native-candidate",
confidence: "unknown",
},
],
}).success,
).toBe(false);
expect(
managedNativeVerificationResultSchema.safeParse({
...result,
coverage: {
status: "complete-within-inputs",
omitted_native_observations: 0,
omitted_candidates: 1,
},
}).success,
).toBe(false);
});
});