182 lines
9.9 KiB
JavaScript
182 lines
9.9 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const root = path.resolve(process.argv[2] ?? process.cwd());
|
|
const failures = [];
|
|
const passes = [];
|
|
const reportPath = path.join("docs", "feature-decisions", "kb-widgets-workflow-marketing-decision-report.md");
|
|
const inventoryPath = path.join("docs", "feature-inventory.md");
|
|
const pluginCandidatesPath = path.join("docs", "feature-manifests", "plugin-candidates.json");
|
|
const removeCandidatesPath = path.join("docs", "feature-manifests", "remove-candidates.json");
|
|
|
|
const pluginComponents = [
|
|
["knowledge-base", "extract-plugin", ["apps/web/app/modules/knowledgeBase", "apps/web/app/routes/docs/*", "apps/web/app/routes/admin/knowledge-base*", "apps/web/app/routes/help/*", "prisma/schema/knowledgeBase.prisma"]],
|
|
["widgets", "extract-plugin", ["apps/web/app/modules/widgets", "apps/web/app/routes/app.$tenant/__widgets/*", "apps/api/src/app.ts", "packages/db/src/widgets.server.ts"]],
|
|
["workflow-engine", "extract-plugin", ["apps/web/app/modules/workflowEngine", "apps/web/app/routes/admin/__workflows/*", "apps/web/app/routes/app.$tenant/__workflows/*", "apps/web/app/routes/internal/api/__workflows/*", "prisma/schema/workflows.prisma"]],
|
|
];
|
|
const removalComponents = [
|
|
["marketing-public-site-remnants", "remove-from-core", []],
|
|
["blog-changelog-remnants", "remove-from-core", []],
|
|
["marketing-chatbot", "remove-from-core", []],
|
|
];
|
|
const stalePrunedPathTokens = [
|
|
"apps/web/app/routes/brand.tsx",
|
|
"apps/web/app/modules/blog",
|
|
"removed marketing chatbot route",
|
|
"removed marketing chatbot routes",
|
|
"apps/web/app/modules/chatbot/lib/tools-marketing/*",
|
|
];
|
|
|
|
function abs(relativePath) {
|
|
return path.join(root, relativePath);
|
|
}
|
|
function pass(message) {
|
|
passes.push(message);
|
|
}
|
|
function fail(message) {
|
|
failures.push(message);
|
|
}
|
|
function readIfNonEmpty(relativePath) {
|
|
try {
|
|
const text = fs.readFileSync(abs(relativePath), "utf8");
|
|
if (fs.statSync(abs(relativePath)).isFile() && text.trim()) {
|
|
pass(`file exists and is non-empty: ${relativePath}`);
|
|
return text;
|
|
}
|
|
} catch {}
|
|
fail(`file is missing or empty: ${relativePath}`);
|
|
return "";
|
|
}
|
|
function requireText(label, document, text) {
|
|
if (document.includes(text)) pass(`${label} references ${text}`);
|
|
else fail(`${label} must reference ${text}`);
|
|
}
|
|
function findComponent(manifest, id) {
|
|
return Array.isArray(manifest.components) ? manifest.components.find((component) => component?.id === id) : undefined;
|
|
}
|
|
function requireArrayIncludes(label, array, expected, prefix) {
|
|
if (Array.isArray(array) && array.includes(expected)) pass(`${prefix}: ${expected}`);
|
|
else fail(`${label} missing ${prefix}: ${expected}`);
|
|
}
|
|
function wildcardExists(pattern) {
|
|
const star = pattern.indexOf("*");
|
|
if (star === -1) return fs.existsSync(abs(pattern));
|
|
const beforeStar = pattern.slice(0, star);
|
|
const slash = beforeStar.lastIndexOf(path.sep);
|
|
const directoryPath = slash === -1 ? "." : beforeStar.slice(0, slash);
|
|
const prefix = slash === -1 ? beforeStar : beforeStar.slice(slash + 1);
|
|
try {
|
|
return fs.readdirSync(abs(directoryPath)).some((entry) => entry.startsWith(prefix));
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
function requireSurface(surface, allowAbsent = false) {
|
|
if (wildcardExists(surface)) pass(`surface resolves: ${surface}`);
|
|
else if (allowAbsent) pass(`surface allowed absent: ${surface}`);
|
|
else fail(`surface does not resolve: ${surface}`);
|
|
}
|
|
function isRepresentedSurface(surface) {
|
|
return wildcardExists(surface) || inventory.includes(surface) || removalText.includes(surface);
|
|
}
|
|
function requireRepresentedSurface(surface) {
|
|
if (isRepresentedSurface(surface)) pass(`surface represented or resolves: ${surface}`);
|
|
else fail(`surface is neither present nor represented in inventory/removal manifest: ${surface}`);
|
|
}
|
|
function requireComponentAlignment(manifestLabel, manifest, tuple) {
|
|
const [id, action, areas] = tuple;
|
|
const component = findComponent(manifest, id);
|
|
if (!component) {
|
|
fail(`${manifestLabel} must contain component id "${id}"`);
|
|
return;
|
|
}
|
|
pass(`${manifestLabel} contains component id "${id}"`);
|
|
const rationale = typeof component.rationale === "string" ? component.rationale : "";
|
|
const source = `${rationale}\n${report}\n${manifest.validation?.source?.join("\n") ?? ""}`;
|
|
for (const text of ["D009", reportPath, action]) requireText(`${manifestLabel} ${id} action alignment`, source, text);
|
|
for (const area of areas) requireArrayIncludes(manifestLabel, component.codeAreas, area, `${id} code area present`);
|
|
}
|
|
function forbidText(label, document, text) {
|
|
if (document.includes(text)) fail(`${label} must not reference stale pruned path token: ${text}`);
|
|
else pass(`${label} excludes stale pruned path token: ${text}`);
|
|
}
|
|
|
|
const report = readIfNonEmpty(reportPath);
|
|
if (report) {
|
|
for (const heading of ["## Decision", "## Scope", "## Current Code Surfaces", "## Knowledge Base Boundary", "## Widgets Boundary", "## Workflow Engine Boundary", "## Public Marketing Removal Boundary", "## Schema and Data Impact", "## Sidebar API and Package Dependency Impact", "## Execution Plan", "## Verification Plan", "## Risks"]) {
|
|
requireText("report", report, heading);
|
|
}
|
|
for (const text of ["Knowledge Base: `extract-plugin`", "Widgets: `extract-plugin`", "Workflow Engine: `extract-plugin`", "Public Marketing remnants: `remove-from-core`", "Decision: `extract-plugin` for Knowledge Base, Widgets, and Workflow Engine.", "Decision: `remove-from-core` for Public Marketing remnants", "D009", "R001", "R002", "R003", "R009", inventoryPath, pluginCandidatesPath, removeCandidatesPath, "public-data boundary", "public/API boundary", "PII", "without browser, Playwright, Cypress, or other E2E execution"]) {
|
|
requireText("report", report, text);
|
|
}
|
|
for (const [, , areas] of [...pluginComponents, ...removalComponents]) for (const area of areas) requireText("report", report, area);
|
|
const placeholder = report.split(/\r?\n/).find((line) => /\b(?:TODO|TBD|PLACEHOLDER)\b/.test(line));
|
|
if (placeholder) fail(`report contains unresolved placeholder line: ${placeholder}`);
|
|
else pass("report has no TODO/TBD/PLACEHOLDER markers");
|
|
const imperative = report.split(/\r?\n/).find((line) => /\b(?:remove|delete|move|alter|change|prune|extract)\s+(?:routes?|schema|runtime|api handlers?|package dependencies|dependencies|code|workers?|queues?|data records?)\s+(?:in this slice|during Feature Decision\/S05|now|immediately)\b/i.test(line) && !/\b(?:no|does not|must not|do not|should not|not authorize|are changed|without)\b/i.test(line));
|
|
if (imperative) fail(`report contains runtime-change instruction for this slice: ${imperative}`);
|
|
else pass("report contains no imperative runtime-change instructions for this slice");
|
|
}
|
|
|
|
const inventory = readIfNonEmpty(inventoryPath);
|
|
const removalText = readIfNonEmpty(removeCandidatesPath);
|
|
const pluginText = readIfNonEmpty(pluginCandidatesPath);
|
|
|
|
for (const [, , areas] of pluginComponents) for (const area of areas) requireSurface(area);
|
|
for (const [, , areas] of removalComponents) for (const area of areas) requireRepresentedSurface(area);
|
|
requireSurface("apps/web/app/routes/contact.tsx", true);
|
|
requireSurface("apps/web/app/routes/newsletter.tsx", true);
|
|
|
|
if (inventory) {
|
|
for (const text of ["Workflow Engine", "Knowledge Base", "Widgets", "Marketing/Public Site Reste", "Blog/Changelog Remnants", "Marketing Chatbot", reportPath, "D009", "extract-plugin", "remove-from-core", "Public `/contact` und `/newsletter`"]) requireText("inventory", inventory, text);
|
|
}
|
|
|
|
for (const [label, document] of [
|
|
["report", report],
|
|
["inventory", inventory],
|
|
["plugin-candidates manifest", pluginText],
|
|
["remove-candidates manifest", removalText],
|
|
]) {
|
|
if (!document) continue;
|
|
for (const token of stalePrunedPathTokens) forbidText(label, document, token);
|
|
}
|
|
|
|
if (pluginText) {
|
|
try {
|
|
const manifest = JSON.parse(pluginText);
|
|
for (const component of pluginComponents) requireComponentAlignment("plugin-candidates manifest", manifest, component);
|
|
for (const id of ["marketing-public-site-remnants", "blog-changelog-remnants", "marketing-chatbot"]) {
|
|
if (findComponent(manifest, id)) fail(`plugin-candidates manifest must not contain removal component id "${id}"`);
|
|
else pass(`plugin-candidates manifest excludes removal component id "${id}"`);
|
|
}
|
|
requireArrayIncludes("plugin-candidates manifest", manifest.validation?.source, reportPath, "validation source present");
|
|
if (manifest.pruning?.action === "extract-plugin") pass("plugin-candidates pruning.action is extract-plugin");
|
|
else fail(`plugin-candidates pruning.action must be extract-plugin, got ${JSON.stringify(manifest.pruning?.action)}`);
|
|
} catch (error) {
|
|
fail(`plugin-candidates JSON parse failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
if (removalText) {
|
|
try {
|
|
const manifest = JSON.parse(removalText);
|
|
for (const component of removalComponents) requireComponentAlignment("remove-candidates manifest", manifest, component);
|
|
for (const [id] of pluginComponents) {
|
|
if (findComponent(manifest, id)) fail(`remove-candidates manifest must not contain plugin component id "${id}"`);
|
|
else pass(`remove-candidates manifest excludes plugin component id "${id}"`);
|
|
}
|
|
requireArrayIncludes("remove-candidates manifest", manifest.validation?.source, reportPath, "validation source present");
|
|
if (manifest.pruning?.action === "remove") pass("remove-candidates pruning.action is remove");
|
|
else fail(`remove-candidates pruning.action must be remove, got ${JSON.stringify(manifest.pruning?.action)}`);
|
|
} catch (error) {
|
|
fail(`remove-candidates JSON parse failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(["FAIL kb/widgets/workflow/marketing decision report verification", ...failures.map((failure) => `- ${failure}`), `Summary: ${passes.length} passed, ${failures.length} failed`].join("\n") + "\n");
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(`PASS kb/widgets/workflow/marketing decision report verification\nSummary: ${passes.length} passed, 0 failed\n`);
|