feat(conformance): add portable conformance export package format
Define a committed scenario/replay/shim/evidence package format for portable process-fidelity conformance fixtures (#336). The package format is versioned, path-independent, and consumable from a clean checkout. - conformancePackage.ts: top-level package schema with scenario manifests, replay plans, shim plans, expected evidence, and verifier contracts. Deterministic package ID computed from canonical JSON. Cross-reference validation ensures internal consistency. - conformanceTrustGate.ts: trust gates that compare captured runs against committed conformance packages (#337). Classifies semantic diffs from timing/normalization noise. Unknown/truncated evidence is never treated as equivalence. - conformanceReplay.ts: CI replay engine that runs each scenario, evaluates trust gates, and detects drift between captured and committed evidence (#338). Closes #336, #337, #338
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CONFORMANCE_PACKAGE_VERSION,
|
||||
conformancePackageSchema,
|
||||
computePackageId,
|
||||
createConformancePackage,
|
||||
validateConformancePackage,
|
||||
type ScenarioManifest,
|
||||
type ReplayPlan,
|
||||
type ShimPlan,
|
||||
type ExpectedEvidence,
|
||||
} from "../src/domain/conformancePackage.js";
|
||||
|
||||
const validPackage = createConformancePackage({
|
||||
schema_version: CONFORMANCE_PACKAGE_VERSION,
|
||||
name: "test-fixture",
|
||||
description: "A test conformance fixture",
|
||||
created_at: "2026-07-28T00:00:00Z",
|
||||
scenarios: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
name: "Simple spawn",
|
||||
description: "A simple process spawn scenario",
|
||||
fixture_path: "tests/conformance/c/fixture.c",
|
||||
expected_exit_code: 0,
|
||||
expected_patterns: ["Hello", "World"],
|
||||
},
|
||||
],
|
||||
replay_plans: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
steps: [
|
||||
{
|
||||
step_id: "step1",
|
||||
action: "compile",
|
||||
arguments: ["gcc", "fixture.c"],
|
||||
timeout_ms: 5000,
|
||||
},
|
||||
],
|
||||
environment: {},
|
||||
},
|
||||
],
|
||||
shim_plans: [],
|
||||
expected_evidence: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
envelopes: [],
|
||||
bundle: null,
|
||||
required_dimensions: ["exit_code", "stdout"],
|
||||
},
|
||||
],
|
||||
verifier_contracts: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
dimensions: [
|
||||
{
|
||||
name: "exit_code",
|
||||
required: true,
|
||||
comparison: "exact",
|
||||
},
|
||||
],
|
||||
timing_tolerance_ms: 100,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
describe("conformance package format", () => {
|
||||
it("validates a well-formed package", () => {
|
||||
const result = validateConformancePackage(validPackage);
|
||||
expect(result.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects invalid schema version", () => {
|
||||
const result = validateConformancePackage({
|
||||
...validPackage,
|
||||
schema_version: 999,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects duplicate scenario IDs", () => {
|
||||
const result = validateConformancePackage({
|
||||
...validPackage,
|
||||
scenarios: [validPackage.scenarios[0], validPackage.scenarios[0]],
|
||||
});
|
||||
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",
|
||||
shims: [],
|
||||
};
|
||||
expect(shim.scenario_id).toBe("s1");
|
||||
|
||||
const evidence: ExpectedEvidence = validPackage.expected_evidence[0]!;
|
||||
expect(evidence.scenario_id).toBe("s1");
|
||||
});
|
||||
|
||||
it("parses via zod schema", () => {
|
||||
const result = conformancePackageSchema.safeParse(validPackage);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,190 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CONFORMANCE_PACKAGE_VERSION,
|
||||
createConformancePackage,
|
||||
type ConformancePackage,
|
||||
} from "../src/domain/conformancePackage.js";
|
||||
import {
|
||||
replayConformancePackage,
|
||||
type ScenarioReplayResult,
|
||||
} from "../src/domain/conformanceReplay.js";
|
||||
|
||||
const validPackage = createConformancePackage({
|
||||
schema_version: CONFORMANCE_PACKAGE_VERSION,
|
||||
name: "test-fixture",
|
||||
description: "A test conformance fixture",
|
||||
created_at: "2026-07-28T00:00:00Z",
|
||||
scenarios: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
name: "Simple spawn",
|
||||
description: "A simple process spawn scenario",
|
||||
fixture_path: "tests/conformance/c/fixture.c",
|
||||
expected_exit_code: 0,
|
||||
expected_patterns: [],
|
||||
},
|
||||
],
|
||||
replay_plans: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
steps: [
|
||||
{
|
||||
step_id: "step1",
|
||||
action: "run",
|
||||
arguments: [],
|
||||
timeout_ms: 1000,
|
||||
},
|
||||
],
|
||||
environment: {},
|
||||
},
|
||||
],
|
||||
shim_plans: [],
|
||||
expected_evidence: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
envelopes: [],
|
||||
bundle: null,
|
||||
required_dimensions: [],
|
||||
},
|
||||
],
|
||||
verifier_contracts: [
|
||||
{
|
||||
scenario_id: "s1",
|
||||
dimensions: [{ name: "exit_code", required: true, comparison: "exact" }],
|
||||
timing_tolerance_ms: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
async function passingRunner(
|
||||
scenarioId: string,
|
||||
): Promise<ScenarioReplayResult> {
|
||||
return {
|
||||
scenario_id: scenarioId,
|
||||
status: "pass",
|
||||
exit_code: 0,
|
||||
duration_ms: 10,
|
||||
output: "ok",
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
async function failingRunner(
|
||||
scenarioId: string,
|
||||
): Promise<ScenarioReplayResult> {
|
||||
return {
|
||||
scenario_id: scenarioId,
|
||||
status: "fail",
|
||||
exit_code: 1,
|
||||
duration_ms: 10,
|
||||
output: "fail",
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
describe("conformance CI replay", () => {
|
||||
it("replays a package with passing scenarios", async () => {
|
||||
const result = await replayConformancePackage(
|
||||
validPackage,
|
||||
{},
|
||||
passingRunner,
|
||||
);
|
||||
expect(result.total_scenarios).toBe(1);
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.failed).toBe(0);
|
||||
expect(result.errored).toBe(0);
|
||||
});
|
||||
|
||||
it("replays a package with failing scenarios", async () => {
|
||||
const result = await replayConformancePackage(
|
||||
validPackage,
|
||||
{},
|
||||
failingRunner,
|
||||
);
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.passed).toBe(0);
|
||||
});
|
||||
|
||||
it("does not detect drift when expected and actual match", async () => {
|
||||
const result = await replayConformancePackage(
|
||||
validPackage,
|
||||
{},
|
||||
passingRunner,
|
||||
);
|
||||
expect(result.drift_detected).toBe(false);
|
||||
});
|
||||
|
||||
it("throws on invalid package", async () => {
|
||||
await expect(replayConformancePackage({}, {})).rejects.toThrow(
|
||||
/invalid conformance package/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("counts all result types", async () => {
|
||||
const base: ConformancePackage = validPackage;
|
||||
const multiPackage = createConformancePackage({
|
||||
...base,
|
||||
scenarios: [
|
||||
base.scenarios[0]!,
|
||||
{
|
||||
scenario_id: "s2",
|
||||
name: "Second scenario",
|
||||
description: "Second",
|
||||
fixture_path: "tests/conformance/c/fixture2.c",
|
||||
expected_exit_code: 1,
|
||||
expected_patterns: [],
|
||||
},
|
||||
],
|
||||
replay_plans: [
|
||||
base.replay_plans[0]!,
|
||||
{
|
||||
scenario_id: "s2",
|
||||
steps: [
|
||||
{
|
||||
step_id: "step1",
|
||||
action: "run",
|
||||
arguments: [],
|
||||
timeout_ms: 1000,
|
||||
},
|
||||
],
|
||||
environment: {},
|
||||
},
|
||||
],
|
||||
expected_evidence: [
|
||||
base.expected_evidence[0]!,
|
||||
{
|
||||
scenario_id: "s2",
|
||||
envelopes: [],
|
||||
bundle: null,
|
||||
required_dimensions: [],
|
||||
},
|
||||
],
|
||||
verifier_contracts: [
|
||||
base.verifier_contracts[0]!,
|
||||
{
|
||||
scenario_id: "s2",
|
||||
dimensions: [
|
||||
{ name: "exit_code", required: true, comparison: "exact" },
|
||||
],
|
||||
timing_tolerance_ms: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
const result = await replayConformancePackage(
|
||||
multiPackage,
|
||||
{},
|
||||
async (scenarioId) => ({
|
||||
scenario_id: scenarioId,
|
||||
status: scenarioId === "s1" ? "pass" : "fail",
|
||||
exit_code: scenarioId === "s1" ? 0 : 1,
|
||||
duration_ms: 10,
|
||||
output: "",
|
||||
error: null,
|
||||
}),
|
||||
);
|
||||
expect(result.total_scenarios).toBe(2);
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { VerifierContract } from "../src/domain/conformancePackage.js";
|
||||
import {
|
||||
compareDimension,
|
||||
evaluateTrustGate,
|
||||
isSemanticDimension,
|
||||
isVolatileDimension,
|
||||
} from "../src/domain/conformanceTrustGate.js";
|
||||
|
||||
const contract: VerifierContract = {
|
||||
scenario_id: "s1",
|
||||
dimensions: [
|
||||
{ name: "exit_code", required: true, comparison: "exact" },
|
||||
{ name: "stdout", required: true, comparison: "semantic" },
|
||||
{ name: "timing", required: true, comparison: "fuzzy" },
|
||||
],
|
||||
timing_tolerance_ms: 100,
|
||||
};
|
||||
|
||||
describe("conformance trust gates", () => {
|
||||
it("classifies volatile dimensions correctly", () => {
|
||||
expect(isVolatileDimension("timing")).toBe(true);
|
||||
expect(isVolatileDimension("timestamp")).toBe(true);
|
||||
expect(isVolatileDimension("pid")).toBe(true);
|
||||
expect(isVolatileDimension("exit_code")).toBe(false);
|
||||
});
|
||||
|
||||
it("classifies semantic dimensions correctly", () => {
|
||||
expect(isSemanticDimension("exit_code")).toBe(true);
|
||||
expect(isSemanticDimension("stdout")).toBe(true);
|
||||
expect(isSemanticDimension("timing")).toBe(false);
|
||||
});
|
||||
|
||||
it("matches identical values", () => {
|
||||
const result = compareDimension("exit_code", 0, 0);
|
||||
expect(result.status).toBe("match");
|
||||
});
|
||||
|
||||
it("detects mismatches", () => {
|
||||
const result = compareDimension("exit_code", 0, 1);
|
||||
expect(result.status).toBe("mismatch");
|
||||
});
|
||||
|
||||
it("ignores volatile dimensions", () => {
|
||||
const result = compareDimension("timing", 100, 200);
|
||||
expect(result.status).toBe("match");
|
||||
expect(result.message).toContain("volatile");
|
||||
});
|
||||
|
||||
it("handles truncated evidence", () => {
|
||||
const result = compareDimension("exit_code", 0, null, {
|
||||
truncated: true,
|
||||
});
|
||||
expect(result.status).toBe("truncated");
|
||||
});
|
||||
|
||||
it("handles undefined values", () => {
|
||||
const result = compareDimension("exit_code", undefined, undefined);
|
||||
expect(result.status).toBe("unknown");
|
||||
});
|
||||
|
||||
it("handles missing actual", () => {
|
||||
const result = compareDimension("exit_code", 0, undefined);
|
||||
expect(result.status).toBe("mismatch");
|
||||
});
|
||||
|
||||
it("passes when all dimensions match", () => {
|
||||
const result = evaluateTrustGate(
|
||||
contract,
|
||||
{ exit_code: 0, stdout: "hello" },
|
||||
{ exit_code: 0, stdout: "hello" },
|
||||
);
|
||||
expect(result.verdict).toBe("pass");
|
||||
});
|
||||
|
||||
it("fails when a required dimension mismatches", () => {
|
||||
const result = evaluateTrustGate(
|
||||
contract,
|
||||
{ exit_code: 0, stdout: "hello" },
|
||||
{ exit_code: 1, stdout: "hello" },
|
||||
);
|
||||
expect(result.verdict).toBe("fail");
|
||||
expect(result.first_divergence).not.toBeNull();
|
||||
expect(result.first_divergence!.dimension).toBe("exit_code");
|
||||
});
|
||||
|
||||
it("reports unknown when both dimensions are undefined", () => {
|
||||
const result = evaluateTrustGate(contract, {}, {});
|
||||
// exit_code and stdout are both undefined -> unknown
|
||||
// timing is volatile -> match
|
||||
expect(result.verdict).toBe("unknown");
|
||||
});
|
||||
|
||||
it("ignores volatile dimension differences", () => {
|
||||
const result = evaluateTrustGate(
|
||||
contract,
|
||||
{ exit_code: 0, stdout: "hello", timing: 100 },
|
||||
{ exit_code: 0, stdout: "hello", timing: 200 },
|
||||
);
|
||||
expect(result.verdict).toBe("pass");
|
||||
});
|
||||
|
||||
it("truncated evidence is not treated as equivalence", () => {
|
||||
const result = evaluateTrustGate(
|
||||
contract,
|
||||
{ exit_code: 0, stdout: "hello" },
|
||||
{ exit_code: 0, stdout: "hello" },
|
||||
{ truncated: true },
|
||||
);
|
||||
expect(result.verdict).toBe("fail");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user