Files
agentic-dev/scripts/conformance.test.mjs
Danijel Martinek f77e6ea881 chore(template): clean-slate template snapshot from bb4a0c7
Curated, product-agnostic snapshot of the post-story-04 tree: demo
content deleted, auth-only reference feature, web-next shell, all gates
green. Product-specific docs, ADRs 027-029, PRDs/epics/archive, editor
library traces, and product naming are curated out; generic template
repairs (coverage provider devDeps, root test:coverage script, live
lint fixes, root-only release-please) are kept. See TEMPLATE.md for
provenance, curation list, and usage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
2026-07-12 20:40:54 +02:00

93 lines
3.1 KiB
JavaScript

import { describe, it, expect } from "vitest";
import path from "node:path";
import os from "node:os";
import fs from "node:fs";
import {
findAllManifests,
buildEventGraph,
findOrphanConsumers,
} from "./conformance.mjs";
function makeRepo(features) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-"));
for (const [name, useCases] of Object.entries(features)) {
const dir = path.join(root, "packages", name, "src");
fs.mkdirSync(dir, { recursive: true });
const useCasesStr = Object.entries(useCases)
.map(
([ucName, uc]) =>
` ${ucName}: { mutates: ${uc.mutates ?? false}, audits: [], publishes: [${(uc.publishes ?? []).map((p) => `"${p}"`).join(", ")}], consumes: [${(uc.consumes ?? []).map((c) => `"${c}"`).join(", ")}] },`,
)
.join("\n");
fs.writeFileSync(
path.join(dir, "feature.manifest.ts"),
`export const ${name}Manifest = defineFeature({
name: "${name}",
requiredCores: [],
useCases: {
${useCasesStr}
},
realtimeChannels: [],
jobs: [],
} as const);`,
);
}
return root;
}
describe("conformance script", () => {
describe("findAllManifests", () => {
it("returns one entry per feature with a manifest", () => {
const root = makeRepo({
auth: { signIn: {} },
blog: { getArticles: {} },
});
const ms = findAllManifests(root);
expect(ms.map((m) => m.feature).sort()).toEqual(["auth", "blog"]);
});
it("skips packages without a manifest", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-empty-"));
fs.mkdirSync(path.join(root, "packages", "no-manifest", "src"), {
recursive: true,
});
expect(findAllManifests(root)).toEqual([]);
});
});
describe("buildEventGraph + findOrphanConsumers", () => {
it("finds zero orphans when consumers and publishers line up", () => {
const root = makeRepo({
auth: { signUp: { mutates: true, publishes: ["auth.signed-up"] } },
marketing: { onAuthSignedUp: { consumes: ["auth.signed-up"] } },
});
const manifests = findAllManifests(root);
const graph = buildEventGraph(manifests);
expect(findOrphanConsumers(graph)).toEqual([]);
});
it("flags orphan consumers", () => {
const root = makeRepo({
marketing: { onAuthSignedUp: { consumes: ["auth.signed-up"] } },
});
const manifests = findAllManifests(root);
const graph = buildEventGraph(manifests);
const orphans = findOrphanConsumers(graph);
expect(orphans).toHaveLength(1);
expect(orphans[0].event).toBe("auth.signed-up");
expect(orphans[0].consumers).toEqual([
{ feature: "marketing", useCase: "onAuthSignedUp" },
]);
});
it("treats publish-only events as fine (no consumers is not an orphan)", () => {
const root = makeRepo({
auth: { signUp: { mutates: true, publishes: ["auth.signed-up"] } },
});
const manifests = findAllManifests(root);
const graph = buildEventGraph(manifests);
expect(findOrphanConsumers(graph)).toEqual([]);
});
});
});