Skip to content

Commit f6fcd47

Browse files
committed
test: bind health docs to runtime fields
1 parent 3df1b25 commit f6fcd47

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎scripts/check-docs.mjs‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,35 @@ function checkOperationalHealthDocumentation({ root, findings }) {
162162
.reduce((total, value) => total * value, 1) / 60_000
163163
);
164164
};
165-
const expected = [
166-
`queued runs from ${minutes("OPERATIONAL_QUEUE_DEGRADED_MS")} through ${minutes("OPERATIONAL_QUEUE_ZOMBIE_MS")} minutes old degrade operational health`,
167-
`queued runs older than ${minutes("OPERATIONAL_QUEUE_ZOMBIE_MS")} minutes are reported separately as zombies`,
168-
`in-progress runs become stalled after ${minutes("OPERATIONAL_RUNNING_STALLED_MS")} minutes`,
165+
const documentedFields = [
169166
"zombie_queued_runs",
170167
"oldest_zombie_queued_minutes",
171168
"approval_gated_runs",
172169
"oldest_approval_gated_minutes",
173170
];
171+
const operationalHealthType = source.match(
172+
/export type OperationalHealth = \{([\s\S]*?)\n\};/,
173+
)?.[1];
174+
for (const field of documentedFields) {
175+
if (
176+
!operationalHealthType ||
177+
!new RegExp(`^\\s*${field}\\s*:`, "m").test(operationalHealthType)
178+
) {
179+
addFinding(
180+
findings,
181+
sourcePath,
182+
1,
183+
"operational-health-source",
184+
`documented field is missing from OperationalHealth: ${field}`,
185+
);
186+
}
187+
}
188+
const expected = [
189+
`queued runs from ${minutes("OPERATIONAL_QUEUE_DEGRADED_MS")} through ${minutes("OPERATIONAL_QUEUE_ZOMBIE_MS")} minutes old degrade operational health`,
190+
`queued runs older than ${minutes("OPERATIONAL_QUEUE_ZOMBIE_MS")} minutes are reported separately as zombies`,
191+
`in-progress runs become stalled after ${minutes("OPERATIONAL_RUNNING_STALLED_MS")} minutes`,
192+
...documentedFields,
193+
];
174194
for (const claim of expected) {
175195
if (!document.includes(claim)) {
176196
addFinding(

‎test/check-docs.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ function fixture(): string {
6161
"export const OPERATIONAL_QUEUE_DEGRADED_MS = 30 * 60 * 1000;",
6262
"export const OPERATIONAL_QUEUE_ZOMBIE_MS = 24 * 60 * 60 * 1000;",
6363
"export const OPERATIONAL_RUNNING_STALLED_MS = 150 * 60 * 1000;",
64+
"export type OperationalHealth = {",
65+
" zombie_queued_runs: number;",
66+
" oldest_zombie_queued_minutes: number;",
67+
" approval_gated_runs: number;",
68+
" oldest_approval_gated_minutes: number;",
69+
"};",
6470
].join("\n"),
6571
"config/targets.json": JSON.stringify({ close: { issue: "implemented" } }),
6672
"config/documentation-sync.json": JSON.stringify({
@@ -138,6 +144,24 @@ test("reports operational health documentation drift", () => {
138144
});
139145
});
140146

147+
test("reports documented operational health fields missing from the runtime type", () => {
148+
withFixture((root) => {
149+
const sourcePath = join(root, "dashboard/operational-health.ts");
150+
writeFileSync(
151+
sourcePath,
152+
String(readFileSync(sourcePath)).replace(" oldest_approval_gated_minutes: number;\n", ""),
153+
);
154+
const findings = checkDocumentation(root);
155+
assert.ok(
156+
findings.some(
157+
(finding) =>
158+
finding.kind === "operational-health-source" &&
159+
finding.message.includes("oldest_approval_gated_minutes"),
160+
),
161+
);
162+
});
163+
});
164+
141165
test("accepts the full URI scheme syntax for external links", () => {
142166
withFixture((root) => {
143167
writeFileSync(

0 commit comments

Comments
 (0)