271 lines
8.1 KiB
JavaScript
271 lines
8.1 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 = [];
|
|
|
|
function rel(...parts) {
|
|
return path.join(...parts);
|
|
}
|
|
|
|
function abs(relativePath) {
|
|
return path.join(root, relativePath);
|
|
}
|
|
|
|
function pass(message) {
|
|
passes.push(message);
|
|
}
|
|
|
|
function fail(message) {
|
|
failures.push(message);
|
|
}
|
|
|
|
function exists(relativePath) {
|
|
return fs.existsSync(abs(relativePath));
|
|
}
|
|
|
|
function isNonEmptyFile(relativePath) {
|
|
try {
|
|
return fs.statSync(abs(relativePath)).isFile() && fs.readFileSync(abs(relativePath), "utf8").trim().length > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function hasDirectoryEntries(relativePath) {
|
|
try {
|
|
const stat = fs.statSync(abs(relativePath));
|
|
return stat.isDirectory() && fs.readdirSync(abs(relativePath)).length > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function requireReportText(report, text) {
|
|
if (report.includes(text)) {
|
|
pass(`report references ${text}`);
|
|
} else {
|
|
fail(`report must reference ${text}`);
|
|
}
|
|
}
|
|
|
|
function requireDocumentText(label, document, text) {
|
|
if (document.includes(text)) {
|
|
pass(`${label} references ${text}`);
|
|
} else {
|
|
fail(`${label} must reference ${text}`);
|
|
}
|
|
}
|
|
|
|
function requirePath(relativePath) {
|
|
if (exists(relativePath)) {
|
|
pass(`path exists: ${relativePath}`);
|
|
} else {
|
|
fail(`missing path: ${relativePath}`);
|
|
}
|
|
}
|
|
|
|
function requireRouteGlob(globText, directoryPath) {
|
|
if (hasDirectoryEntries(directoryPath)) {
|
|
pass(`glob resolves: ${globText} -> ${directoryPath}`);
|
|
} else {
|
|
fail(`glob does not resolve to a non-empty directory: ${globText} -> ${directoryPath}`);
|
|
}
|
|
}
|
|
|
|
function requireJsonArrayIncludes(fileLabel, array, expected, messagePrefix) {
|
|
if (Array.isArray(array) && array.includes(expected)) {
|
|
pass(`${messagePrefix}: ${expected}`);
|
|
} else {
|
|
fail(`${fileLabel} missing ${messagePrefix}: ${expected}`);
|
|
}
|
|
}
|
|
|
|
const reportPath = rel("docs", "feature-decisions", "portals-sites-decision-report.md");
|
|
const inventoryPath = rel("docs", "feature-inventory.md");
|
|
const pluginCandidatesPath = rel("docs", "feature-manifests", "plugin-candidates.json");
|
|
|
|
let report = "";
|
|
if (isNonEmptyFile(reportPath)) {
|
|
report = fs.readFileSync(abs(reportPath), "utf8");
|
|
pass(`report exists and is non-empty: ${reportPath}`);
|
|
} else {
|
|
fail(`report is missing or empty: ${reportPath}`);
|
|
}
|
|
|
|
if (report) {
|
|
const requiredHeadings = [
|
|
"## Decision",
|
|
"## Scope",
|
|
"## Current Code Surfaces",
|
|
"## Couplings",
|
|
"## Billing Provider Boundary",
|
|
"## Schema and Data Impact",
|
|
"## Sidebar Command Docs Impact",
|
|
"## Execution Plan",
|
|
"## Verification Plan",
|
|
"## Risks",
|
|
];
|
|
|
|
for (const heading of requiredHeadings) {
|
|
if (report.includes(heading)) {
|
|
pass(`heading present: ${heading}`);
|
|
} else {
|
|
fail(`missing required heading: ${heading}`);
|
|
}
|
|
}
|
|
|
|
if (report.includes("Decision: `extract-plugin`")) {
|
|
pass("decision token present: Decision: `extract-plugin`");
|
|
} else {
|
|
fail("report must contain exact decision token: Decision: `extract-plugin`");
|
|
}
|
|
|
|
for (const decisionText of ["D007", "D006"] ) {
|
|
requireReportText(report, decisionText);
|
|
}
|
|
|
|
const placeholderPattern = /\b(?:TODO|TBD)\b/i;
|
|
const placeholderMatch = report.split(/\r?\n/).find((line) => placeholderPattern.test(line));
|
|
if (placeholderMatch) {
|
|
fail(`report contains unresolved placeholder line: ${placeholderMatch}`);
|
|
} else {
|
|
pass("report has no TODO/TBD placeholder lines");
|
|
}
|
|
|
|
const requiredReportReferences = [
|
|
"apps/web/app/modules/portals",
|
|
"apps/web/app/modules/sites",
|
|
"apps/web/app/routes/app.$tenant/__portals/*",
|
|
"apps/web/app/routes/app.$tenant/sites/*",
|
|
"apps/web/app/modules/portals/db/portals.db.server.ts",
|
|
"apps/web/app/modules/sites/db/sites.db.server.ts",
|
|
"apps/web/app/modules/sites/site-types.ts",
|
|
"prisma/schema/analytics.prisma",
|
|
"apps/web/app/modules/domains/services/Domains.server.ts",
|
|
"apps/web/app/application/sidebar/AppSidebar.test.tsx",
|
|
"prisma/schema/portals.prisma",
|
|
"prisma/schema/sites.prisma",
|
|
".env.example",
|
|
".env.production.example",
|
|
inventoryPath,
|
|
pluginCandidatesPath,
|
|
];
|
|
|
|
for (const reference of requiredReportReferences) {
|
|
requireReportText(report, reference);
|
|
}
|
|
|
|
for (const coverageText of [
|
|
"analytics",
|
|
"domains",
|
|
"sidebar",
|
|
"environment",
|
|
"schema/data migration plan",
|
|
"without browser or E2E execution",
|
|
]) {
|
|
requireReportText(report, coverageText);
|
|
}
|
|
}
|
|
|
|
const requiredConcretePaths = [
|
|
"apps/web/app/modules/portals",
|
|
"apps/web/app/modules/sites",
|
|
"apps/web/app/modules/portals/db/portals.db.server.ts",
|
|
"apps/web/app/modules/sites/db/sites.db.server.ts",
|
|
"apps/web/app/modules/sites/site-types.ts",
|
|
"prisma/schema/analytics.prisma",
|
|
"apps/web/app/modules/domains/services/Domains.server.ts",
|
|
"apps/web/app/application/sidebar/AppSidebar.test.tsx",
|
|
"prisma/schema/portals.prisma",
|
|
"prisma/schema/sites.prisma",
|
|
".env.example",
|
|
".env.production.example",
|
|
inventoryPath,
|
|
pluginCandidatesPath,
|
|
];
|
|
|
|
for (const requiredPath of requiredConcretePaths) {
|
|
requirePath(requiredPath);
|
|
}
|
|
|
|
requireRouteGlob("apps/web/app/routes/app.$tenant/__portals/*", "apps/web/app/routes/app.$tenant/__portals");
|
|
requireRouteGlob("apps/web/app/routes/app.$tenant/sites/*", "apps/web/app/routes/app.$tenant/sites");
|
|
|
|
if (isNonEmptyFile(inventoryPath)) {
|
|
const inventory = fs.readFileSync(abs(inventoryPath), "utf8");
|
|
for (const text of ["Portals/Sites", reportPath, "extract-plugin"]) {
|
|
requireDocumentText("inventory", inventory, text);
|
|
}
|
|
} else {
|
|
fail(`inventory is missing or empty: ${inventoryPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(pluginCandidatesPath)) {
|
|
try {
|
|
const manifest = JSON.parse(fs.readFileSync(abs(pluginCandidatesPath), "utf8"));
|
|
const portalsSites = Array.isArray(manifest.components)
|
|
? manifest.components.find((component) => component && component.id === "portals-sites")
|
|
: undefined;
|
|
|
|
if (portalsSites) {
|
|
pass('manifest contains component id "portals-sites"');
|
|
} else {
|
|
fail('manifest must contain component id "portals-sites"');
|
|
}
|
|
|
|
const rationale = typeof portalsSites?.rationale === "string" ? portalsSites.rationale : "";
|
|
if (rationale.trim().length > 0) {
|
|
pass("manifest portals-sites rationale is present");
|
|
} else {
|
|
fail("manifest portals-sites rationale must be present");
|
|
}
|
|
|
|
const validationSources = Array.isArray(manifest.validation?.source) ? manifest.validation.source : [];
|
|
requireJsonArrayIncludes("plugin-candidates manifest", validationSources, reportPath, "validation source present");
|
|
|
|
const manifestText = fs.readFileSync(abs(pluginCandidatesPath), "utf8");
|
|
for (const text of [reportPath, "extract-plugin"]) {
|
|
requireDocumentText("plugin-candidates manifest", manifestText, text);
|
|
}
|
|
|
|
const codeAreas = Array.isArray(portalsSites?.codeAreas) ? portalsSites.codeAreas : [];
|
|
for (const codeArea of [
|
|
"apps/web/app/modules/portals",
|
|
"apps/web/app/modules/sites",
|
|
"apps/web/app/routes/app.$tenant/__portals/*",
|
|
"apps/web/app/routes/app.$tenant/sites/*",
|
|
]) {
|
|
requireJsonArrayIncludes("plugin-candidates manifest", codeAreas, codeArea, "manifest Portals/Sites code area present");
|
|
}
|
|
|
|
|
|
if (manifest.pruning?.action === "extract-plugin") {
|
|
pass("manifest pruning.action is extract-plugin");
|
|
} else {
|
|
fail(`manifest pruning.action must be extract-plugin, got ${JSON.stringify(manifest.pruning?.action)}`);
|
|
}
|
|
} catch (error) {
|
|
fail(`manifest JSON parse failed: ${error.message}`);
|
|
}
|
|
} else {
|
|
fail(`manifest is missing or empty: ${pluginCandidatesPath}`);
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(
|
|
[
|
|
"FAIL portals/sites decision report verification",
|
|
...failures.map((failure) => `- ${failure}`),
|
|
`Summary: ${passes.length} passed, ${failures.length} failed`,
|
|
].join("\n") + "\n",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.stdout.write(
|
|
`PASS portals/sites decision report verification\nSummary: ${passes.length} passed, 0 failed\n`,
|
|
);
|