feat: publish coauthoring-sidecar JSON Schema + rung-neutral validator (F5 SLICE-1, PUC-5, #14)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-10 22:54:39 -07:00
parent 0ddeaba5a6
commit 7c4d3ed79f
4 changed files with 227 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* Schema-conformance helper (F5 SLICE-1, PUC-5): every serialized artifact in
* the unit suite must validate against the published cross-rung schema —
* contract drift fails CI (spec §7.4).
*/
import { readFileSync } from "node:fs";
import Ajv from "ajv/dist/2020";
import { serializeArtifact, type Artifact } from "../../src/model";
const schemaUrl = new URL("../../schemas/coauthoring-sidecar.schema.json", import.meta.url);
const schema = JSON.parse(readFileSync(schemaUrl, "utf8"));
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
export function validateSidecar(data: unknown): { valid: boolean; errors: string[] } {
const valid = validate(data) as boolean;
const errors = (validate.errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message}`);
return { valid, errors };
}
export function expectValidSidecar(artifact: Artifact): void {
const { valid, errors } = validateSidecar(JSON.parse(serializeArtifact(artifact)));
if (!valid) throw new Error(`sidecar failed schema validation:\n${errors.join("\n")}`);
}