Keep dashboard API registration modular while preserving Express route precedence. - Route all top-level dashboard registrars through a runtime-checked canonical mount sequence - Add mount-order and inline-route-ratchet coverage with CI enforcement - Document registrar ownership and mount-order conventions Files changed: .github/workflows/pr-checks.yml | 3 + AGENTS.md | 2 + package.json | 5 +- packages/dashboard/src/routes.ts | 136 +++++----- packages/dashboard/src/routes/README.md | 276 ++++++++++----------- packages/dashboard/src/routes/__tests__/create-api-routes-mount-order.test.ts | 66 +++++ packages/dashboard/src/routes/create-api-routes-mount-sequence.ts | 54 ++++ scripts/__tests__/check-routes-modular.test.mjs | 28 +++ scripts/check-routes-modular.mjs | 65 +++++ scripts/lib/routes-modular-baseline.json | 3 + 10 files changed, 433 insertions(+), 205 deletions(-) Fusion-Task-Id: FN-8365 Fusion-Task-Lineage: 9c36a263-ed5e-4524-8ea5-71ed3f3e34d9 Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, it } from "node:test";
|
|
import { countInlineRouteRegistrations, evaluate, formatFailureMessage, main } from "../check-routes-modular.mjs";
|
|
|
|
describe("check-routes-modular", () => {
|
|
it("ignores comments and strings while counting executable inline registrations", () => {
|
|
assert.equal(countInlineRouteRegistrations('// router.get("/example", handler)\nconst x = "router.post(";\nrouter.get("/live", handler);'), 1);
|
|
});
|
|
it("passes at or below baseline and fails above it", () => {
|
|
assert.equal(evaluate(4, { inlineRouteRegistrations: 4 }).passes, true);
|
|
const failure = evaluate(5, { inlineRouteRegistrations: 4 });
|
|
assert.equal(failure.passes, false);
|
|
assert.match(formatFailureMessage(failure), /packages\/dashboard\/src\/routes\/ registrars/);
|
|
assert.equal(evaluate(3, { inlineRouteRegistrations: 4 }).passes, true);
|
|
});
|
|
it("rewrites the baseline with --update", () => {
|
|
const directory = mkdtempSync(join(tmpdir(), "routes-modular-"));
|
|
const routesPath = join(directory, "routes.ts");
|
|
const baselinePath = join(directory, "baseline.json");
|
|
writeFileSync(routesPath, 'router.get("/one", handler);\nrouter.post("/two", handler);\n');
|
|
writeFileSync(baselinePath, '{"inlineRouteRegistrations": 99}\n');
|
|
assert.equal(main(["--update"], { routesPath, baselinePath }), 0);
|
|
assert.deepEqual(JSON.parse(readFileSync(baselinePath, "utf8")), { inlineRouteRegistrations: 2 });
|
|
});
|
|
});
|