rungate 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rungate.ts +70 -0
- package/lib/aes-calculator.ts +66 -0
- package/lib/agent-audit.ts +139 -0
- package/lib/agent-brief-validation.ts +359 -0
- package/lib/agents-md-refs.ts +90 -0
- package/lib/bash-file-read.ts +197 -0
- package/lib/behavioral-cache.ts +78 -0
- package/lib/branch-cleanup.ts +234 -0
- package/lib/brief-context-parser.ts +35 -0
- package/lib/brief-precedence.ts +114 -0
- package/lib/canary.ts +117 -0
- package/lib/check-registry.ts +226 -0
- package/lib/ci-checkout.ts +426 -0
- package/lib/cli-commands.ts +137 -0
- package/lib/compliance-backfill.ts +232 -0
- package/lib/compliance-report.ts +605 -0
- package/lib/compliance.ts +361 -0
- package/lib/config-loader.ts +255 -0
- package/lib/config-readers.ts +86 -0
- package/lib/conformity.ts +2161 -137
- package/lib/container-provenance.ts +230 -0
- package/lib/create-brief.ts +150 -0
- package/lib/create-sc.ts +267 -0
- package/lib/decomposition-waves.ts +197 -0
- package/lib/deep-merge.ts +69 -0
- package/lib/dev-liveness.ts +214 -0
- package/lib/directive-extractor.ts +210 -0
- package/lib/distribution-standing.ts +113 -0
- package/lib/doc-hygiene.ts +238 -0
- package/lib/eval-criteria.ts +6 -0
- package/lib/evidence-portability.ts +123 -0
- package/lib/evidence-prevalidator.ts +390 -0
- package/lib/evidence-required.ts +150 -0
- package/lib/evidence-satisfiability.ts +288 -0
- package/lib/frontmatter.ts +163 -0
- package/lib/gap-scanner.ts +348 -0
- package/lib/gate-check-audit.ts +190 -0
- package/lib/gate-enforcement.ts +366 -0
- package/lib/generators/agent-briefs.ts +136 -0
- package/lib/generators/agents-md.ts +511 -0
- package/lib/generators/code-map.ts +60 -0
- package/lib/generators/types.ts +184 -0
- package/lib/git-ref-normalizer.ts +107 -0
- package/lib/github.ts +539 -0
- package/lib/harness-identity.ts +63 -0
- package/lib/hill-climb.ts +164 -0
- package/lib/instruction-effectiveness.ts +131 -0
- package/lib/issue-closure-audit.ts +225 -0
- package/lib/issue-create-override.ts +343 -0
- package/lib/issue-extraction.ts +368 -0
- package/lib/js-top-level-code.ts +250 -0
- package/lib/liveness-contradiction.ts +149 -0
- package/lib/organize.ts +505 -0
- package/lib/paths.ts +197 -6
- package/lib/phase2-decomposition.ts +270 -0
- package/lib/post-fix-verify.ts +157 -0
- package/lib/prior-branch.ts +512 -0
- package/lib/project-state-shape.ts +166 -0
- package/lib/promote-outputs.ts +156 -0
- package/lib/prove-label-gate.ts +128 -0
- package/lib/reachability.ts +302 -0
- package/lib/release-preflight.ts +288 -0
- package/lib/rule-health-pipeline.ts +264 -0
- package/lib/rule-health-trend.ts +161 -0
- package/lib/rule-provenance.ts +149 -0
- package/lib/rule-registry.ts +128 -0
- package/lib/rungate-schema.ts +127 -5
- package/lib/sc-claim-forms.ts +179 -0
- package/lib/sc-cover.ts +150 -0
- package/lib/sc-guard.ts +157 -0
- package/lib/sc-ids.ts +344 -0
- package/lib/scaffold/defaults.ts +165 -0
- package/lib/scaffold/managed-workflow.ts +370 -0
- package/lib/scaffold/owned-files.ts +265 -0
- package/lib/scaffold/pre-push-hook.ts +165 -0
- package/lib/scaffold/steps.ts +2621 -0
- package/lib/scanner.ts +701 -0
- package/lib/scope-denylist.ts +258 -0
- package/lib/screenshot-upload.ts +73 -0
- package/lib/secret-patterns.ts +112 -0
- package/lib/security-verdict.ts +616 -0
- package/lib/signal-phrases.ts +1 -0
- package/lib/spec-change-conformity.ts +80 -0
- package/lib/spec-files.ts +62 -0
- package/lib/spec-registry.ts +133 -0
- package/lib/spec-updater.ts +96 -0
- package/lib/stale-cleanup.ts +224 -0
- package/lib/stale-issue-scanner.ts +36 -0
- package/lib/strip-js-comments.ts +269 -0
- package/lib/suite-measurement.ts +228 -0
- package/lib/task-completion-checks.ts +224 -0
- package/lib/test-suite-lock.ts +1136 -0
- package/lib/transcript-checker.ts +1140 -0
- package/lib/typescript-project.ts +233 -0
- package/lib/validators/spec-validators.ts +171 -0
- package/lib/verdict-capture.ts +73 -0
- package/lib/verified-push.ts +535 -0
- package/lib/workflow-security.ts +174 -0
- package/lib/worktree-cleanup.ts +432 -0
- package/lib/worktree-collect.ts +283 -0
- package/lib/worktree-isolation.ts +82 -0
- package/lib/worktree-repo.ts +300 -0
- package/package.json +27 -3
- package/prompts/ac-adversary.md +14 -2
- package/prompts/aditi.md +5 -0
- package/prompts/blast-radius.md +5 -0
- package/prompts/container-verify.md +5 -0
- package/prompts/discovery.md +4 -0
- package/prompts/environment.md +5 -0
- package/prompts/evidence-hierarchy.md +5 -0
- package/prompts/evidence-validator.md +11 -0
- package/prompts/marcus.md +5 -0
- package/prompts/prevention.md +5 -0
- package/prompts/prove-reproducer.md +12 -0
- package/prompts/quinn-decision-tree.md +5 -0
- package/prompts/quinn-ui-brief.md +5 -0
- package/prompts/quinn.md +5 -0
- package/prompts/rca.md +5 -0
- package/prompts/read-before-write.md +4 -0
- package/prompts/regression.md +5 -0
- package/prompts/serena.md +5 -0
- package/scripts/audit-specs.ts +464 -0
- package/scripts/convert-spec.ts +293 -0
- package/scripts/create-sc.ts +92 -0
- package/scripts/create-spec.ts +166 -0
- package/scripts/extract-constraints.ts +4 -3
- package/scripts/generate-code-map.ts +1 -1
- package/scripts/scaffold-project.ts +138 -1426
- package/scripts/sync-spec-tests.ts +211 -126
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, existsSync, statSync } from "fs";
|
|
2
|
+
import { collectSpecFiles } from "./spec-files";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
|
|
6
|
+
export interface GapResult {
|
|
7
|
+
check: string;
|
|
8
|
+
status: "PASS" | "WARN" | "SKIP";
|
|
9
|
+
detail: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface GapScanResult {
|
|
13
|
+
results: GapResult[];
|
|
14
|
+
warnings: number;
|
|
15
|
+
passes: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function scanGaps(
|
|
19
|
+
projectRoot: string,
|
|
20
|
+
workDir?: string
|
|
21
|
+
): GapScanResult {
|
|
22
|
+
const runGateWorkDir =
|
|
23
|
+
workDir || process.env.RUNGATE_WORK_DIR || join(process.env.HOME!, ".rungate");
|
|
24
|
+
|
|
25
|
+
const results: GapResult[] = [];
|
|
26
|
+
|
|
27
|
+
// 1. orphaned-workdirs
|
|
28
|
+
results.push(checkOrphanedWorkdirs(runGateWorkDir));
|
|
29
|
+
|
|
30
|
+
// 2. stale-doc-refs
|
|
31
|
+
results.push(checkStaleDocRefs(projectRoot));
|
|
32
|
+
|
|
33
|
+
// 3. no-new-todos-without-issue
|
|
34
|
+
results.push(checkTodosWithoutIssue(projectRoot));
|
|
35
|
+
|
|
36
|
+
// 4. spec-sc-unchecked-ratio
|
|
37
|
+
results.push(checkSpecScRatio(projectRoot));
|
|
38
|
+
|
|
39
|
+
// 5. hook-line-budget
|
|
40
|
+
results.push(checkHookLineBudget(projectRoot));
|
|
41
|
+
|
|
42
|
+
// 6. test-suite-health
|
|
43
|
+
results.push(checkTestSuiteHealth(projectRoot));
|
|
44
|
+
|
|
45
|
+
const warnings = results.filter((r) => r.status === "WARN").length;
|
|
46
|
+
const passes = results.filter((r) => r.status === "PASS").length;
|
|
47
|
+
|
|
48
|
+
return { results, warnings, passes };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function checkOrphanedWorkdirs(workDir: string): GapResult {
|
|
52
|
+
if (!existsSync(workDir)) {
|
|
53
|
+
return {
|
|
54
|
+
check: "orphaned-workdirs",
|
|
55
|
+
status: "SKIP",
|
|
56
|
+
detail: "Work directory does not exist",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const dirs = readdirSync(workDir).filter((entry) => {
|
|
62
|
+
const fullPath = join(workDir, entry);
|
|
63
|
+
try {
|
|
64
|
+
return statSync(fullPath).isDirectory();
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const orphaned = dirs.filter((dir) => {
|
|
71
|
+
const stateFile = join(workDir, dir, "workflow-state.json");
|
|
72
|
+
return !existsSync(stateFile);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const count = orphaned.length;
|
|
76
|
+
if (count > 5) {
|
|
77
|
+
return {
|
|
78
|
+
check: "orphaned-workdirs",
|
|
79
|
+
status: "WARN",
|
|
80
|
+
detail: `${count} orphaned work directories without workflow-state.json`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
check: "orphaned-workdirs",
|
|
86
|
+
status: "PASS",
|
|
87
|
+
detail: `${count} orphaned work directories (threshold: 5)`,
|
|
88
|
+
};
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return {
|
|
91
|
+
check: "orphaned-workdirs",
|
|
92
|
+
status: "SKIP",
|
|
93
|
+
detail: `Error checking work directories: ${error}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function checkStaleDocRefs(projectRoot: string): GapResult {
|
|
99
|
+
const docFiles = ["CLAUDE.md", "AGENTS.md"];
|
|
100
|
+
const missing: string[] = [];
|
|
101
|
+
|
|
102
|
+
for (const docFile of docFiles) {
|
|
103
|
+
const docPath = join(projectRoot, docFile);
|
|
104
|
+
if (!existsSync(docPath)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const content = readFileSync(docPath, "utf-8");
|
|
110
|
+
const lines = content.split("\n");
|
|
111
|
+
|
|
112
|
+
// Look for markdown table rows with file references
|
|
113
|
+
for (const line of lines) {
|
|
114
|
+
// Match table rows: | filename | ...
|
|
115
|
+
const match = line.match(/^\|\s*([^|]+?)\s*\|/);
|
|
116
|
+
if (match && match[1]) {
|
|
117
|
+
const potentialFile = match[1].trim();
|
|
118
|
+
|
|
119
|
+
// Skip headers, separators, non-file entries, and prose descriptions
|
|
120
|
+
if (
|
|
121
|
+
potentialFile === "File" ||
|
|
122
|
+
potentialFile.includes("---") ||
|
|
123
|
+
potentialFile.length === 0 ||
|
|
124
|
+
potentialFile.startsWith("**") ||
|
|
125
|
+
potentialFile.startsWith("I ") ||
|
|
126
|
+
potentialFile.includes("...") ||
|
|
127
|
+
/^[A-Z][a-z]+ [a-z]/.test(potentialFile)
|
|
128
|
+
) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Strip backticks from paths like `CODE-MAP.md`
|
|
133
|
+
const cleanFile = potentialFile.replace(/`/g, "").trim();
|
|
134
|
+
if (!cleanFile || cleanFile.includes("---")) continue;
|
|
135
|
+
|
|
136
|
+
// Check if it looks like a file reference (has extension or is a directory)
|
|
137
|
+
if (cleanFile.includes(".") || cleanFile.endsWith("/")) {
|
|
138
|
+
// Try the path as-is, then with common prefixes
|
|
139
|
+
const candidates = [
|
|
140
|
+
join(projectRoot, cleanFile),
|
|
141
|
+
join(projectRoot, "specs", cleanFile),
|
|
142
|
+
join(projectRoot, "test", cleanFile),
|
|
143
|
+
join(projectRoot, "docs", cleanFile),
|
|
144
|
+
join(projectRoot, "reference", cleanFile),
|
|
145
|
+
];
|
|
146
|
+
const found = candidates.some((p) => existsSync(p));
|
|
147
|
+
if (!found) {
|
|
148
|
+
// Skip glob patterns like *.md
|
|
149
|
+
if (cleanFile.includes("*")) continue;
|
|
150
|
+
missing.push(cleanFile);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
// Continue to next file on error
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (missing.length > 0) {
|
|
161
|
+
return {
|
|
162
|
+
check: "stale-doc-refs",
|
|
163
|
+
status: "WARN",
|
|
164
|
+
detail: `Missing file references: ${missing.join(", ")}`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
check: "stale-doc-refs",
|
|
170
|
+
status: "PASS",
|
|
171
|
+
detail: "All file references exist",
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function checkTodosWithoutIssue(projectRoot: string): GapResult {
|
|
176
|
+
try {
|
|
177
|
+
const diff = execSync("git diff HEAD~5 --unified=0", {
|
|
178
|
+
cwd: projectRoot,
|
|
179
|
+
encoding: "utf-8",
|
|
180
|
+
stdio: "pipe",
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const lines = diff.split("\n");
|
|
184
|
+
const todosWithoutIssue: string[] = [];
|
|
185
|
+
|
|
186
|
+
for (const line of lines) {
|
|
187
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
188
|
+
const content = line.slice(1).trim();
|
|
189
|
+
if (
|
|
190
|
+
/\/\/.*\b(TODO|FIXME|HACK)\b/.test(content) &&
|
|
191
|
+
!/#\d+/.test(content) &&
|
|
192
|
+
!/["'`].*\b(TODO|FIXME|HACK)\b.*["'`]/.test(content)
|
|
193
|
+
) {
|
|
194
|
+
todosWithoutIssue.push(content);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (todosWithoutIssue.length > 0) {
|
|
200
|
+
return {
|
|
201
|
+
check: "no-new-todos-without-issue",
|
|
202
|
+
status: "WARN",
|
|
203
|
+
detail: `${todosWithoutIssue.length} new code comments with TODO/FIXME/HACK (missing #NNN)`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
check: "no-new-todos-without-issue",
|
|
209
|
+
status: "PASS",
|
|
210
|
+
detail: "No new code comments with TODO/FIXME/HACK missing issue reference",
|
|
211
|
+
};
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return {
|
|
214
|
+
check: "no-new-todos-without-issue",
|
|
215
|
+
status: "SKIP",
|
|
216
|
+
detail: "Not in a git repository or insufficient history",
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function checkSpecScRatio(projectRoot: string): GapResult {
|
|
222
|
+
const specsDir = join(projectRoot, "specs");
|
|
223
|
+
|
|
224
|
+
if (!existsSync(specsDir)) {
|
|
225
|
+
return {
|
|
226
|
+
check: "spec-sc-unchecked-ratio",
|
|
227
|
+
status: "SKIP",
|
|
228
|
+
detail: "No specs directory found",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let totalChecked = 0;
|
|
233
|
+
let totalUnchecked = 0;
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
const specFiles = collectSpecFiles(specsDir); // #225 — subdirectories too
|
|
237
|
+
|
|
238
|
+
for (const file of specFiles) {
|
|
239
|
+
const content = readFileSync(join(specsDir, file), "utf-8");
|
|
240
|
+
const lines = content.split("\n");
|
|
241
|
+
|
|
242
|
+
for (const line of lines) {
|
|
243
|
+
if (/^- \[x\] SC-/i.test(line)) {
|
|
244
|
+
totalChecked++;
|
|
245
|
+
} else if (/^- \[ \] SC-/i.test(line)) {
|
|
246
|
+
totalUnchecked++;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const total = totalChecked + totalUnchecked;
|
|
252
|
+
if (total === 0) {
|
|
253
|
+
return {
|
|
254
|
+
check: "spec-sc-unchecked-ratio",
|
|
255
|
+
status: "SKIP",
|
|
256
|
+
detail: "No SCs found in spec files",
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const uncheckedPercent = Math.round((totalUnchecked / total) * 100);
|
|
261
|
+
|
|
262
|
+
if (uncheckedPercent > 60) {
|
|
263
|
+
return {
|
|
264
|
+
check: "spec-sc-unchecked-ratio",
|
|
265
|
+
status: "WARN",
|
|
266
|
+
detail: `${uncheckedPercent}% unchecked SCs (${totalUnchecked}/${total})`,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
check: "spec-sc-unchecked-ratio",
|
|
272
|
+
status: "PASS",
|
|
273
|
+
detail: `${uncheckedPercent}% unchecked SCs (${totalUnchecked}/${total})`,
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return {
|
|
277
|
+
check: "spec-sc-unchecked-ratio",
|
|
278
|
+
status: "SKIP",
|
|
279
|
+
detail: `Error checking spec files: ${error}`,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function checkHookLineBudget(projectRoot: string): GapResult {
|
|
285
|
+
const hooksDir = join(projectRoot, "hooks");
|
|
286
|
+
|
|
287
|
+
if (!existsSync(hooksDir)) {
|
|
288
|
+
return {
|
|
289
|
+
check: "hook-line-budget",
|
|
290
|
+
status: "SKIP",
|
|
291
|
+
detail: "No hooks directory found",
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
const hookFiles = readdirSync(hooksDir).filter((f) => f.endsWith(".hook.ts"));
|
|
297
|
+
const violations: string[] = [];
|
|
298
|
+
|
|
299
|
+
for (const file of hookFiles) {
|
|
300
|
+
const content = readFileSync(join(hooksDir, file), "utf-8");
|
|
301
|
+
const lines = content.split("\n").length;
|
|
302
|
+
|
|
303
|
+
if (lines > 150) {
|
|
304
|
+
violations.push(`${file} (${lines} lines)`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (violations.length > 0) {
|
|
309
|
+
return {
|
|
310
|
+
check: "hook-line-budget",
|
|
311
|
+
status: "WARN",
|
|
312
|
+
detail: `Hooks exceeding 150 lines: ${violations.join(", ")}`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
check: "hook-line-budget",
|
|
318
|
+
status: "PASS",
|
|
319
|
+
detail: `All ${hookFiles.length} hooks under 150 lines`,
|
|
320
|
+
};
|
|
321
|
+
} catch (error) {
|
|
322
|
+
return {
|
|
323
|
+
check: "hook-line-budget",
|
|
324
|
+
status: "SKIP",
|
|
325
|
+
detail: `Error checking hook files: ${error}`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function checkTestSuiteHealth(projectRoot: string): GapResult {
|
|
331
|
+
const packageJsonPath = join(projectRoot, "package.json");
|
|
332
|
+
|
|
333
|
+
if (!existsSync(packageJsonPath)) {
|
|
334
|
+
return {
|
|
335
|
+
check: "test-suite-health",
|
|
336
|
+
status: "SKIP",
|
|
337
|
+
detail: "No package.json found",
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// For now, just return SKIP since running the full test suite is expensive
|
|
342
|
+
// This check would need more sophisticated implementation in real usage
|
|
343
|
+
return {
|
|
344
|
+
check: "test-suite-health",
|
|
345
|
+
status: "SKIP",
|
|
346
|
+
detail: "Test suite health check not implemented (would run bun test)",
|
|
347
|
+
};
|
|
348
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which gate checks cannot fail, and which of those meant to (#183, #176).
|
|
3
|
+
*
|
|
4
|
+
* #176 found three checks in `gates/workflow.test.ts` that were satisfied by
|
|
5
|
+
* configuration or by nothing at all. `tsc-pass` was the clearest: two early
|
|
6
|
+
* returns and an empty tail, no `expect`, no `tsc` invocation, no baseline
|
|
7
|
+
* comparison. It had been counted as a passing gate check for its whole life.
|
|
8
|
+
*
|
|
9
|
+
* #183 is the audit of the rest of that list, and the thing worth building is
|
|
10
|
+
* not a one-time report. **Nothing in the repo could tell a check that is
|
|
11
|
+
* deliberately a warning from a check whose assertion was forgotten**, and
|
|
12
|
+
* that is exactly the gap `tsc-pass` lived in. Three checks are warn-only
|
|
13
|
+
* today; two say so in their own comments and one does not.
|
|
14
|
+
*
|
|
15
|
+
* So the audit is a binding instead of a paragraph: every check with no
|
|
16
|
+
* assertion must be named here with a reason, and every name here must still
|
|
17
|
+
* be a check with no assertion. Both directions fail. Adding an `expect` to a
|
|
18
|
+
* warn-tier check means deleting its entry in the same commit, and adding a
|
|
19
|
+
* check with no assertion means either writing the reason down or writing the
|
|
20
|
+
* assertion.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** One `test(...)` in a gate suite, with the body a brace matcher found. */
|
|
24
|
+
export interface GateCheck {
|
|
25
|
+
/** The first argument to `test(...)`, as written. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** 1-indexed line of the `test(` call. */
|
|
28
|
+
line: number;
|
|
29
|
+
/** Everything between the callback's braces. */
|
|
30
|
+
body: string;
|
|
31
|
+
/** Does any `expect(` appear in the body? */
|
|
32
|
+
hasAssertion: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Checks that intentionally only warn, each with the reason.
|
|
37
|
+
*
|
|
38
|
+
* A reason is required because the entry is the documentation. "It is on the
|
|
39
|
+
* list" is the same non-answer as a green check that never looked.
|
|
40
|
+
*/
|
|
41
|
+
export const WARN_TIER_CHECKS: Readonly<Record<string, string>> = Object.freeze({
|
|
42
|
+
"quinn-container-port: Quinn tested the container, not the dev server":
|
|
43
|
+
"#344 — turning this into a refusal changes what blocks live runs and needs its own " +
|
|
44
|
+
"measurement. The fix there was that it stops being WRONG (it compared against one " +
|
|
45
|
+
"consumer's literal port); making it block is a separate decision.",
|
|
46
|
+
"spec-decision-compliance: AC language aligns with spec decisions":
|
|
47
|
+
"#409 Decision #9 placed this in the WARN tier explicitly: it matches AC prose against " +
|
|
48
|
+
"regex anti-patterns, and a regex over prose is not a basis for refusing a run.",
|
|
49
|
+
"outcome-evidence-behavioral: OUTCOME AC evidence is not just a number":
|
|
50
|
+
"#183 — reported, not fixed. This one is NOT a documented decision like the two above; " +
|
|
51
|
+
"it is `tsc-pass`'s shape with a console.warn where the assertion should be, and the " +
|
|
52
|
+
"sibling check `outcome-acs-no-skip` two tests above it does assert. Tightening it is a " +
|
|
53
|
+
"behaviour change to a live gate and belongs to its own issue.",
|
|
54
|
+
"ac-issue-alignment: ACs cover goal keywords":
|
|
55
|
+
"#183 — reported, not fixed. Found by this audit, not by #176. ADR-009 C4 asks that ACs " +
|
|
56
|
+
"cover the goal's keywords; the body computes a coverage ratio and warns under 50%. A " +
|
|
57
|
+
"stopword-filtered substring match is not a basis for refusing a run, but nothing said " +
|
|
58
|
+
"so until this entry, which is the whole point of the list.",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The stub a `describe` block substitutes when there is no workflow state.
|
|
63
|
+
*
|
|
64
|
+
* Not a check and not a warn-tier check — a placeholder so bun does not report
|
|
65
|
+
* an empty describe. It is separated out rather than allowlisted because the
|
|
66
|
+
* property that matters is different: a stub must have an EMPTY body. A stub
|
|
67
|
+
* that grew logic would be a check that runs only when nothing is being gated.
|
|
68
|
+
*/
|
|
69
|
+
export const STANDALONE_STUB_NAME = "skipped — no active workflow (standalone run)";
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `expect(` — and `expect<T>(`, which the first draft of this regex missed.
|
|
73
|
+
*
|
|
74
|
+
* It reported `workflow-state.json validates` as having no assertion when the
|
|
75
|
+
* assertion is on the line below, written `expect<boolean>(...)` to widen a
|
|
76
|
+
* narrowed type. A detector that misses a form in its own tree is the second
|
|
77
|
+
* shape in `.claude/rules/checks-must-be-able-to-fail.md`, so the generic form
|
|
78
|
+
* is a case in the test rather than a note here.
|
|
79
|
+
*/
|
|
80
|
+
const ASSERTION = /\bexpect\s*(?:<[^>()]*>)?\s*\(/;
|
|
81
|
+
|
|
82
|
+
/** `(`/`[`/`{` depth-aware scan that skips strings, templates and comments. */
|
|
83
|
+
function matchingParen(source: string, openAt: number): number {
|
|
84
|
+
let depth = 0;
|
|
85
|
+
for (let i = openAt; i < source.length; i++) {
|
|
86
|
+
const c = source[i];
|
|
87
|
+
const next = source[i + 1];
|
|
88
|
+
if (c === "/" && next === "/") {
|
|
89
|
+
const nl = source.indexOf("\n", i);
|
|
90
|
+
i = nl === -1 ? source.length : nl;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (c === "/" && next === "*") {
|
|
94
|
+
const close = source.indexOf("*/", i + 2);
|
|
95
|
+
i = close === -1 ? source.length : close + 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
99
|
+
const quote = c;
|
|
100
|
+
i++;
|
|
101
|
+
for (; i < source.length; i++) {
|
|
102
|
+
if (source[i] === "\\") { i++; continue; }
|
|
103
|
+
if (source[i] === quote) break;
|
|
104
|
+
// A `${` inside a template can itself contain the quote character, so
|
|
105
|
+
// the expression is skipped as a unit rather than scanned for one.
|
|
106
|
+
if (quote === "`" && source[i] === "$" && source[i + 1] === "{") {
|
|
107
|
+
let d = 1;
|
|
108
|
+
i += 2;
|
|
109
|
+
for (; i < source.length && d > 0; i++) {
|
|
110
|
+
if (source[i] === "{") d++;
|
|
111
|
+
else if (source[i] === "}") d--;
|
|
112
|
+
}
|
|
113
|
+
i--;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
119
|
+
else if (c === ")" || c === "]" || c === "}") {
|
|
120
|
+
depth--;
|
|
121
|
+
if (depth === 0) return i;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return -1;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Every `test("...", ...)` in a suite source, with its body.
|
|
129
|
+
*
|
|
130
|
+
* Brace-matched rather than indentation-matched. An indentation heuristic was
|
|
131
|
+
* the first attempt and it found 27 of 79 — it stopped at the first `});` that
|
|
132
|
+
* happened to sit at the right column, which in a file of nested `describe`
|
|
133
|
+
* blocks is almost immediately. A parser that silently sees a third of its
|
|
134
|
+
* input is the defect this whole file is about, so `parsesEveryCheck` below is
|
|
135
|
+
* asserted by the test rather than assumed here.
|
|
136
|
+
*/
|
|
137
|
+
export function gateChecks(source: string): GateCheck[] {
|
|
138
|
+
const checks: GateCheck[] = [];
|
|
139
|
+
const re = /(^|\n)(\s*)test\(\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`)/g;
|
|
140
|
+
let m: RegExpExecArray | null;
|
|
141
|
+
while ((m = re.exec(source)) !== null) {
|
|
142
|
+
const name = (m[3] ?? m[4] ?? m[5])!;
|
|
143
|
+
const callAt = m.index + m[1]!.length + m[2]!.length;
|
|
144
|
+
const openAt = source.indexOf("(", callAt);
|
|
145
|
+
const closeAt = matchingParen(source, openAt);
|
|
146
|
+
if (closeAt === -1) continue;
|
|
147
|
+
const call = source.slice(openAt, closeAt);
|
|
148
|
+
// The body is everything after the first `=> {` or `function () {` inside
|
|
149
|
+
// the call. Taking the whole call would count an `expect` in the test's
|
|
150
|
+
// own name or options object as an assertion.
|
|
151
|
+
const arrow = call.indexOf("=> {");
|
|
152
|
+
const body = arrow === -1 ? call : call.slice(arrow + 4);
|
|
153
|
+
checks.push({
|
|
154
|
+
name,
|
|
155
|
+
line: source.slice(0, callAt).split("\n").length,
|
|
156
|
+
body,
|
|
157
|
+
hasAssertion: ASSERTION.test(body),
|
|
158
|
+
});
|
|
159
|
+
re.lastIndex = closeAt;
|
|
160
|
+
}
|
|
161
|
+
return checks;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Checks with no `expect(` anywhere in the body, in source order. */
|
|
165
|
+
export function checksWithoutAssertions(source: string): GateCheck[] {
|
|
166
|
+
return gateChecks(source).filter(c => !c.hasAssertion && c.name !== STANDALONE_STUB_NAME);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The standalone placeholders, so their emptiness can be asserted. */
|
|
170
|
+
export function standaloneStubs(source: string): GateCheck[] {
|
|
171
|
+
return gateChecks(source).filter(c => c.name === STANDALONE_STUB_NAME);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Reads a field off `environments` that something other than a measurement
|
|
176
|
+
* writes — #176's second shape.
|
|
177
|
+
*
|
|
178
|
+
* Returns one entry per `sf("environments")?.<env>?.<field>` read, so the
|
|
179
|
+
* audit can name the writer of each. Text, deliberately: the point is to
|
|
180
|
+
* enumerate the reads so a human checks each writer, not to decide which are
|
|
181
|
+
* honest. A detector that tried to decide would be the narrower-than-what-it-
|
|
182
|
+
* detects shape in `.claude/rules/checks-must-be-able-to-fail.md`.
|
|
183
|
+
*/
|
|
184
|
+
export function environmentVerdictReads(source: string): string[] {
|
|
185
|
+
const out = new Set<string>();
|
|
186
|
+
for (const m of source.matchAll(/sf\("environments"\)\?\.(\w+)\?\.(\w+)/g)) {
|
|
187
|
+
out.add(`${m[1]}.${m[2]}`);
|
|
188
|
+
}
|
|
189
|
+
return [...out].sort();
|
|
190
|
+
}
|