parseManifestUseCases returning null for a manifest that exists made the cross-feature gate silently skip that feature. findUnparseableManifests now runs before the empty-graph early exit (an unparseable manifest contributes zero events and would otherwise pass as nothing-to-check) and any hit fails the run. Reader-closure from the downstream fork is not ported: this tree has no reads: manifests or ./reader exports yet. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
115 lines
4.0 KiB
JavaScript
115 lines
4.0 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,
|
|
findUnparseableManifests,
|
|
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("findUnparseableManifests", () => {
|
|
it("flags a manifest the AST parser cannot read", () => {
|
|
const root = makeRepo({ auth: { signIn: {} } });
|
|
const brokenDir = path.join(root, "packages", "broken", "src");
|
|
fs.mkdirSync(brokenDir, { recursive: true });
|
|
// No defineFeature call — parseManifestUseCases returns null.
|
|
fs.writeFileSync(
|
|
path.join(brokenDir, "feature.manifest.ts"),
|
|
`export const brokenManifest = { name: "broken" };`,
|
|
);
|
|
const manifests = findAllManifests(root);
|
|
const unparseable = findUnparseableManifests(manifests);
|
|
expect(unparseable.map((m) => m.feature)).toEqual(["broken"]);
|
|
});
|
|
|
|
it("returns [] when every manifest parses", () => {
|
|
const root = makeRepo({ auth: { signIn: {} } });
|
|
expect(findUnparseableManifests(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([]);
|
|
});
|
|
});
|
|
});
|