fix(conformance): fail the CI gate on unparseable manifests
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>
This commit is contained in:
@@ -8,6 +8,9 @@
|
|||||||
*
|
*
|
||||||
* - Orphan consumer: a feature declares `consumes: ["X"]` but no
|
* - Orphan consumer: a feature declares `consumes: ["X"]` but no
|
||||||
* feature publishes "X".
|
* feature publishes "X".
|
||||||
|
* - Unparseable manifest: a feature.manifest.ts exists but the AST
|
||||||
|
* parser cannot read it — silence here would disable every gate that
|
||||||
|
* keys off the manifest.
|
||||||
*
|
*
|
||||||
* Exits 0 on success, 1 on any violation. Prints a tabular summary of
|
* Exits 0 on success, 1 on any violation. Prints a tabular summary of
|
||||||
* the event graph for transparency.
|
* the event graph for transparency.
|
||||||
@@ -25,7 +28,12 @@ export function findAllManifests(repoRoot = REPO_ROOT) {
|
|||||||
if (!fs.existsSync(packagesDir)) return [];
|
if (!fs.existsSync(packagesDir)) return [];
|
||||||
const out = [];
|
const out = [];
|
||||||
for (const entry of fs.readdirSync(packagesDir)) {
|
for (const entry of fs.readdirSync(packagesDir)) {
|
||||||
const manifestPath = path.join(packagesDir, entry, "src", "feature.manifest.ts");
|
const manifestPath = path.join(
|
||||||
|
packagesDir,
|
||||||
|
entry,
|
||||||
|
"src",
|
||||||
|
"feature.manifest.ts",
|
||||||
|
);
|
||||||
if (fs.existsSync(manifestPath)) {
|
if (fs.existsSync(manifestPath)) {
|
||||||
out.push({ feature: entry, path: manifestPath });
|
out.push({ feature: entry, path: manifestPath });
|
||||||
}
|
}
|
||||||
@@ -33,6 +41,12 @@ export function findAllManifests(repoRoot = REPO_ROOT) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findUnparseableManifests(manifests) {
|
||||||
|
return manifests.filter(
|
||||||
|
({ path: manifestPath }) => parseManifestUseCases(manifestPath) === null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function buildEventGraph(manifests) {
|
export function buildEventGraph(manifests) {
|
||||||
const graph = new Map();
|
const graph = new Map();
|
||||||
for (const { feature, path: manifestPath } of manifests) {
|
for (const { feature, path: manifestPath } of manifests) {
|
||||||
@@ -40,11 +54,13 @@ export function buildEventGraph(manifests) {
|
|||||||
if (!useCases) continue;
|
if (!useCases) continue;
|
||||||
for (const [useCase, entry] of Object.entries(useCases)) {
|
for (const [useCase, entry] of Object.entries(useCases)) {
|
||||||
for (const event of entry.publishes) {
|
for (const event of entry.publishes) {
|
||||||
if (!graph.has(event)) graph.set(event, { publishers: [], consumers: [] });
|
if (!graph.has(event))
|
||||||
|
graph.set(event, { publishers: [], consumers: [] });
|
||||||
graph.get(event).publishers.push({ feature, useCase });
|
graph.get(event).publishers.push({ feature, useCase });
|
||||||
}
|
}
|
||||||
for (const event of entry.consumes) {
|
for (const event of entry.consumes) {
|
||||||
if (!graph.has(event)) graph.set(event, { publishers: [], consumers: [] });
|
if (!graph.has(event))
|
||||||
|
graph.set(event, { publishers: [], consumers: [] });
|
||||||
graph.get(event).consumers.push({ feature, useCase });
|
graph.get(event).consumers.push({ feature, useCase });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,32 +84,61 @@ function main() {
|
|||||||
for (const { feature } of manifests) console.log(` - ${feature}`);
|
for (const { feature } of manifests) console.log(` - ${feature}`);
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
|
let failures = 0;
|
||||||
|
|
||||||
|
// An unparseable manifest blinds every manifest-keyed gate, so check it
|
||||||
|
// BEFORE the empty-graph early exit (an unparseable manifest contributes
|
||||||
|
// zero events and would otherwise slip through as "nothing to check").
|
||||||
|
const unparseable = findUnparseableManifests(manifests);
|
||||||
|
if (unparseable.length > 0) {
|
||||||
|
failures += unparseable.length;
|
||||||
|
console.error(`✗ ${unparseable.length} unparseable manifest(s):`);
|
||||||
|
for (const { feature } of unparseable) {
|
||||||
|
console.error(
|
||||||
|
` ${feature}/src/feature.manifest.ts could not be parsed — every manifest-keyed gate is blind to it`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const graph = buildEventGraph(manifests);
|
const graph = buildEventGraph(manifests);
|
||||||
if (graph.size === 0) {
|
if (graph.size === 0 && failures === 0) {
|
||||||
console.log("No cross-feature events declared yet — nothing to check.");
|
console.log("No cross-feature events declared yet — nothing to check.");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Event graph (${graph.size} event(s)):`);
|
if (graph.size > 0) {
|
||||||
for (const [event, { publishers, consumers }] of graph.entries()) {
|
console.log(`Event graph (${graph.size} event(s)):`);
|
||||||
console.log(` ${event}`);
|
for (const [event, { publishers, consumers }] of graph.entries()) {
|
||||||
console.log(` publishers: ${publishers.length === 0 ? "(none)" : publishers.map((p) => `${p.feature}.${p.useCase}`).join(", ")}`);
|
console.log(` ${event}`);
|
||||||
console.log(` consumers: ${consumers.length === 0 ? "(none)" : consumers.map((c) => `${c.feature}.${c.useCase}`).join(", ")}`);
|
console.log(
|
||||||
|
` publishers: ${publishers.length === 0 ? "(none)" : publishers.map((p) => `${p.feature}.${p.useCase}`).join(", ")}`,
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
` consumers: ${consumers.length === 0 ? "(none)" : consumers.map((c) => `${c.feature}.${c.useCase}`).join(", ")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log();
|
||||||
}
|
}
|
||||||
console.log();
|
|
||||||
|
|
||||||
const orphans = findOrphanConsumers(graph);
|
const orphans = findOrphanConsumers(graph);
|
||||||
if (orphans.length === 0) {
|
if (orphans.length > 0) {
|
||||||
|
failures += orphans.length;
|
||||||
|
console.error(`✗ ${orphans.length} orphan consumer(s):`);
|
||||||
|
for (const { event, consumers } of orphans) {
|
||||||
|
console.error(` ${event}`);
|
||||||
|
for (const c of consumers) {
|
||||||
|
console.error(
|
||||||
|
` consumed by ${c.feature}.${c.useCase}, but no feature publishes it`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failures === 0) {
|
||||||
console.log("✓ pnpm conformance — passed");
|
console.log("✓ pnpm conformance — passed");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
console.error(`✗ pnpm conformance — ${orphans.length} orphan consumer(s):`);
|
console.error(`✗ pnpm conformance — ${failures} violation(s)`);
|
||||||
for (const { event, consumers } of orphans) {
|
|
||||||
console.error(` ${event}`);
|
|
||||||
for (const c of consumers) {
|
|
||||||
console.error(` consumed by ${c.feature}.${c.useCase}, but no feature publishes it`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ import { describe, it, expect } from "vitest";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { findAllManifests, buildEventGraph, findOrphanConsumers } from "./conformance.mjs";
|
import {
|
||||||
|
findAllManifests,
|
||||||
|
findUnparseableManifests,
|
||||||
|
buildEventGraph,
|
||||||
|
findOrphanConsumers,
|
||||||
|
} from "./conformance.mjs";
|
||||||
|
|
||||||
function makeRepo(features) {
|
function makeRepo(features) {
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-"));
|
||||||
@@ -10,8 +15,9 @@ function makeRepo(features) {
|
|||||||
const dir = path.join(root, "packages", name, "src");
|
const dir = path.join(root, "packages", name, "src");
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
const useCasesStr = Object.entries(useCases)
|
const useCasesStr = Object.entries(useCases)
|
||||||
.map(([ucName, uc]) =>
|
.map(
|
||||||
` ${ucName}: { mutates: ${uc.mutates ?? false}, audits: [], publishes: [${(uc.publishes ?? []).map((p) => `"${p}"`).join(", ")}], consumes: [${(uc.consumes ?? []).map((c) => `"${c}"`).join(", ")}] },`,
|
([ucName, uc]) =>
|
||||||
|
` ${ucName}: { mutates: ${uc.mutates ?? false}, audits: [], publishes: [${(uc.publishes ?? []).map((p) => `"${p}"`).join(", ")}], consumes: [${(uc.consumes ?? []).map((c) => `"${c}"`).join(", ")}] },`,
|
||||||
)
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
@@ -43,11 +49,34 @@ describe("conformance script", () => {
|
|||||||
|
|
||||||
it("skips packages without a manifest", () => {
|
it("skips packages without a manifest", () => {
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-empty-"));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "conformance-empty-"));
|
||||||
fs.mkdirSync(path.join(root, "packages", "no-manifest", "src"), { recursive: true });
|
fs.mkdirSync(path.join(root, "packages", "no-manifest", "src"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
expect(findAllManifests(root)).toEqual([]);
|
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", () => {
|
describe("buildEventGraph + findOrphanConsumers", () => {
|
||||||
it("finds zero orphans when consumers and publishers line up", () => {
|
it("finds zero orphans when consumers and publishers line up", () => {
|
||||||
const root = makeRepo({
|
const root = makeRepo({
|
||||||
@@ -68,7 +97,9 @@ describe("conformance script", () => {
|
|||||||
const orphans = findOrphanConsumers(graph);
|
const orphans = findOrphanConsumers(graph);
|
||||||
expect(orphans).toHaveLength(1);
|
expect(orphans).toHaveLength(1);
|
||||||
expect(orphans[0].event).toBe("auth.signed-up");
|
expect(orphans[0].event).toBe("auth.signed-up");
|
||||||
expect(orphans[0].consumers).toEqual([{ feature: "marketing", useCase: "onAuthSignedUp" }]);
|
expect(orphans[0].consumers).toEqual([
|
||||||
|
{ feature: "marketing", useCase: "onAuthSignedUp" },
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("treats publish-only events as fine (no consumers is not an orphan)", () => {
|
it("treats publish-only events as fine (no consumers is not an orphan)", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user