Skip to content

Commit ffb10b0

Browse files
committed
fix(dashboard): enforce monotonic strict baseline
1 parent 8b3b4a4 commit ffb10b0

3 files changed

Lines changed: 118 additions & 34 deletions

File tree

‎scripts/check-dashboard-strict.mjs‎

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,94 @@
1+
/**
2+
* Enforce the dashboard strict allowlist as a monotonic ratchet. When a module
3+
* joins the allowlist, add the same one-line entry to the baseline below in
4+
* that PR; baseline entries must never be removed.
5+
*/
16
import { spawnSync } from "node:child_process";
27
import path from "node:path";
38
import process from "node:process";
9+
import { pathToFileURL } from "node:url";
410

511
const configPath = "tsconfig.dashboard-strict.json";
612
const tscPath = path.resolve("node_modules/typescript/bin/tsc");
7-
const showConfig = runTsc(["-p", configPath, "--showConfig"]);
8-
if (showConfig.status !== 0) {
9-
process.stderr.write(showConfig.output);
10-
process.exit(1);
11-
}
1213

13-
const config = JSON.parse(showConfig.stdout);
14-
const strictFiles = new Set(config.files.map(normalizeFile));
15-
if (
16-
strictFiles.size === 0 ||
17-
config.compilerOptions?.strict !== true ||
18-
config.compilerOptions?.noUncheckedIndexedAccess !== true ||
19-
config.compilerOptions?.exactOptionalPropertyTypes !== true
14+
export const DASHBOARD_STRICT_BASELINE_FILES = Object.freeze([
15+
"dashboard/apply-observability.ts",
16+
"dashboard/automerge-metrics.ts",
17+
"dashboard/dashboard-health.ts",
18+
"dashboard/error-safety.ts",
19+
"dashboard/exact-review-decision.ts",
20+
"dashboard/exact-review-publication-retry.ts",
21+
"dashboard/exact-review-queue-shared.ts",
22+
"dashboard/exact-review-read-model.ts",
23+
"dashboard/github-api.ts",
24+
"dashboard/operational-health.ts",
25+
"dashboard/review-observability.ts",
26+
"dashboard/review-run-telemetry.ts",
27+
"dashboard/state-blobs.ts",
28+
]);
29+
30+
export function assertDashboardStrictBaseline(
31+
files,
32+
baselineFiles = DASHBOARD_STRICT_BASELINE_FILES,
2033
) {
21-
throw new Error(
22-
"dashboard strict config must enable all strict flags and list at least one file",
23-
);
34+
const strictFiles = new Set(files.map(normalizeFile));
35+
const baseline = new Set(baselineFiles.map(normalizeFile));
36+
const missing = [...baseline].filter((file) => !strictFiles.has(file));
37+
if (missing.length > 0) {
38+
throw new Error(`dashboard strict config is missing baseline files:\n${missing.join("\n")}`);
39+
}
40+
41+
const unrecorded = [...strictFiles].filter((file) => !baseline.has(file));
42+
if (unrecorded.length > 0) {
43+
throw new Error(
44+
`dashboard strict config has files missing from its baseline:\n${unrecorded.join("\n")}`,
45+
);
46+
}
2447
}
2548

26-
const check = runTsc(["-p", configPath, "--pretty", "false"]);
27-
if (check.status === 0) process.exit(0);
49+
function main() {
50+
const showConfig = runTsc(["-p", configPath, "--showConfig"]);
51+
if (showConfig.status !== 0) {
52+
process.stderr.write(showConfig.output);
53+
process.exitCode = 1;
54+
return;
55+
}
2856

29-
const selected = [];
30-
let includeContinuation = false;
31-
let recognizedDiagnostic = false;
32-
for (const line of check.output.split(/(?<=\n)/)) {
33-
const match = /^(.+?)\(\d+,\d+\): error TS\d+:/.exec(line);
34-
if (match) {
35-
recognizedDiagnostic = true;
36-
includeContinuation = strictFiles.has(normalizeFile(match[1]));
37-
} else if (/^error TS\d+:/.test(line)) {
38-
recognizedDiagnostic = true;
39-
includeContinuation = true;
57+
const config = JSON.parse(showConfig.stdout);
58+
if (
59+
config.compilerOptions?.strict !== true ||
60+
config.compilerOptions?.noUncheckedIndexedAccess !== true ||
61+
config.compilerOptions?.exactOptionalPropertyTypes !== true
62+
) {
63+
throw new Error("dashboard strict config must enable all strict flags");
4064
}
41-
if (includeContinuation) selected.push(line);
42-
}
4365

44-
if (selected.length > 0 || !recognizedDiagnostic) {
45-
process.stderr.write(selected.length > 0 ? selected.join("") : check.output);
46-
process.exitCode = 1;
66+
const configuredFiles = Array.isArray(config.files) ? config.files : [];
67+
assertDashboardStrictBaseline(configuredFiles);
68+
const strictFiles = new Set(configuredFiles.map(normalizeFile));
69+
70+
const check = runTsc(["-p", configPath, "--pretty", "false"]);
71+
if (check.status === 0) return;
72+
73+
const selected = [];
74+
let includeContinuation = false;
75+
let recognizedDiagnostic = false;
76+
for (const line of check.output.split(/(?<=\n)/)) {
77+
const match = /^(.+?)\(\d+,\d+\): error TS\d+:/.exec(line);
78+
if (match) {
79+
recognizedDiagnostic = true;
80+
includeContinuation = strictFiles.has(normalizeFile(match[1]));
81+
} else if (/^error TS\d+:/.test(line)) {
82+
recognizedDiagnostic = true;
83+
includeContinuation = true;
84+
}
85+
if (includeContinuation) selected.push(line);
86+
}
87+
88+
if (selected.length > 0 || !recognizedDiagnostic) {
89+
process.stderr.write(selected.length > 0 ? selected.join("") : check.output);
90+
process.exitCode = 1;
91+
}
4792
}
4893

4994
function normalizeFile(file) {
@@ -62,3 +107,5 @@ function runTsc(args) {
62107
output: `${result.stdout}${result.stderr}`,
63108
};
64109
}
110+
111+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) main();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import {
5+
assertDashboardStrictBaseline,
6+
DASHBOARD_STRICT_BASELINE_FILES,
7+
} from "../scripts/check-dashboard-strict.mjs";
8+
9+
test("dashboard strict accepts the full baseline", () => {
10+
assert.doesNotThrow(() => assertDashboardStrictBaseline(DASHBOARD_STRICT_BASELINE_FILES));
11+
});
12+
13+
test("dashboard strict rejects a missing baseline file and names it", () => {
14+
const missing = "dashboard/github-api.ts";
15+
const configuredFiles = DASHBOARD_STRICT_BASELINE_FILES.filter((file) => file !== missing);
16+
17+
assert.throws(() => assertDashboardStrictBaseline(configuredFiles), {
18+
message: `dashboard strict config is missing baseline files:\n${missing}`,
19+
});
20+
});
21+
22+
test("dashboard strict accepts the baseline plus a new file", () => {
23+
const extendedBaseline = [
24+
...DASHBOARD_STRICT_BASELINE_FILES,
25+
"dashboard/future-strict-module.ts",
26+
];
27+
28+
assert.doesNotThrow(() => assertDashboardStrictBaseline(extendedBaseline, extendedBaseline));
29+
});
30+
31+
test("dashboard strict requires new files to extend the baseline", () => {
32+
const added = "dashboard/future-strict-module.ts";
33+
34+
assert.throws(() => assertDashboardStrictBaseline([...DASHBOARD_STRICT_BASELINE_FILES, added]), {
35+
message: `dashboard strict config has files missing from its baseline:\n${added}`,
36+
});
37+
});

‎tsconfig.dashboard-strict.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"noUncheckedIndexedAccess": true,
66
"exactOptionalPropertyTypes": true
77
},
8-
// This allowlist is a monotonic strictness ratchet: files must never be removed.
8+
// Monotonic ratchet: never remove files; add each new root to the checker's baseline in the same PR.
99
"files": [
1010
"dashboard/apply-observability.ts",
1111
"dashboard/automerge-metrics.ts",

0 commit comments

Comments
 (0)