rungate 0.6.0 → 0.7.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/lib/affected-tests.ts +398 -0
- package/lib/agent-audit.ts +2 -3
- package/lib/agent-worktree.ts +287 -0
- package/lib/agents-md-sections.ts +81 -16
- package/lib/behavioral-cache.ts +150 -2
- package/lib/branch-protection.ts +790 -0
- package/lib/brief-ac-alignment.ts +104 -0
- package/lib/brief-references.ts +205 -0
- package/lib/bun-version.ts +93 -14
- package/lib/check-remedy.ts +140 -0
- package/lib/ci-checkout.ts +17 -0
- package/lib/ci-history-depth.ts +159 -0
- package/lib/ci-setup-step.ts +96 -0
- package/lib/claude-code-action.ts +85 -0
- package/lib/claude-tool-vocabulary.ts +188 -0
- package/lib/cli-commands.ts +15 -0
- package/lib/commit-sha.ts +42 -0
- package/lib/commit-subject.ts +90 -0
- package/lib/compliance-report.ts +377 -45
- package/lib/compliance.ts +191 -17
- package/lib/config-loader.ts +39 -1
- package/lib/config-trackable.ts +391 -0
- package/lib/conformity.ts +1087 -100
- package/lib/containment.ts +238 -0
- package/lib/content-hash.ts +24 -0
- package/lib/create-sc.ts +249 -16
- package/lib/dev-liveness.ts +180 -0
- package/lib/discovery-branch-points.ts +432 -0
- package/lib/discovery-stability.ts +481 -0
- package/lib/distribution-currency.ts +186 -0
- package/lib/doc-routing.ts +157 -0
- package/lib/evidence-prevalidator.ts +224 -2
- package/lib/evidence-satisfiability.ts +534 -12
- package/lib/failure-intake.ts +317 -0
- package/lib/fallow-availability.ts +157 -0
- package/lib/fs-write-capabilities.ts +232 -0
- package/lib/gate-run-split.ts +147 -0
- package/lib/generators/agents-md.ts +140 -32
- package/lib/git-isolation.ts +140 -0
- package/lib/github.ts +15 -0
- package/lib/google-auth-action.ts +93 -0
- package/lib/harness-project.ts +48 -0
- package/lib/harness-provenance.ts +255 -0
- package/lib/hook-evidence.ts +235 -0
- package/lib/hook-scopes.ts +386 -0
- package/lib/hook-target-tree.ts +398 -0
- package/lib/hook-trees.ts +447 -0
- package/lib/js-top-level-code.ts +78 -10
- package/lib/junit-checks.ts +52 -0
- package/lib/launch-base.ts +253 -0
- package/lib/line-citation.ts +372 -0
- package/lib/orphan-reaper.ts +468 -0
- package/lib/parity-binding.ts +205 -0
- package/lib/per-test-timeouts.ts +219 -0
- package/lib/plan-coverage.ts +151 -0
- package/lib/prior-branch.ts +201 -8
- package/lib/process-table.ts +146 -0
- package/lib/project-state-derivation.ts +219 -0
- package/lib/project-state-root.ts +258 -0
- package/lib/published-artifact.ts +525 -0
- package/lib/readdir-sorted.ts +45 -0
- package/lib/review-execution-reading.ts +206 -0
- package/lib/review-tool-agreement.ts +433 -0
- package/lib/rule-promotion.ts +234 -0
- package/lib/rule-retirement.ts +525 -0
- package/lib/run-branch.ts +612 -0
- package/lib/rungate-schema.ts +19 -0
- package/lib/runner-home.ts +274 -0
- package/lib/sc-id-cross-tree.ts +19 -7
- package/lib/sc-ids.ts +121 -13
- package/lib/sc-reservations.ts +289 -0
- package/lib/scaffold/ai-review-findings.ts +403 -0
- package/lib/scaffold/ai-review-step.ts +4661 -64
- package/lib/scaffold/managed-workflow.ts +587 -192
- package/lib/scaffold/owned-files.ts +152 -45
- package/lib/scaffold/pre-push-hook.ts +49 -5
- package/lib/scaffold/steps.ts +1413 -244
- package/lib/scaffold/workflow-census.ts +217 -0
- package/lib/scaffold/workflow-drift.ts +217 -0
- package/lib/scaffold/write-steps.ts +4 -0
- package/lib/scan-budget.ts +247 -0
- package/lib/scanner.ts +43 -51
- package/lib/scratch-roots.ts +50 -5
- package/lib/screenshot-discovery.ts +121 -0
- package/lib/screenshot-upload.ts +41 -1
- package/lib/secret-patterns.ts +511 -8
- package/lib/ship-mode.ts +219 -0
- package/lib/source-slice.ts +294 -0
- package/lib/stale-cleanup.ts +37 -3
- package/lib/suite-flake.ts +278 -0
- package/lib/suite-measurement.ts +23 -4
- package/lib/suite-run-reading.ts +241 -1
- package/lib/suite-timeout-margin.ts +193 -0
- package/lib/test-case-bodies.ts +883 -0
- package/lib/test-case-deletion.ts +653 -0
- package/lib/test-census.ts +97 -29
- package/lib/test-command-positions.ts +274 -0
- package/lib/test-suite-lock.ts +159 -16
- package/lib/tool-probe.ts +31 -9
- package/lib/top-level-cd.ts +393 -0
- package/lib/tree-entries.ts +89 -0
- package/lib/ts-ast.ts +200 -0
- package/lib/walk-test-files.ts +97 -0
- package/lib/workflow-actions.ts +263 -0
- package/lib/worktree-collect.ts +177 -5
- package/lib/worktree-repo.ts +36 -1
- package/package.json +2 -1
- package/scripts/ai-review-findings.ts +45 -0
- package/scripts/create-sc.ts +21 -1
- package/scripts/extract-constraints.ts +107 -7
- package/scripts/generate-code-map.ts +23 -30
- package/scripts/scaffold-project.ts +8 -1
- package/scripts/sync-sc-status.ts +77 -16
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which test files can reach a given set of changed files (#676).
|
|
3
|
+
*
|
|
4
|
+
* A ship run pays for the whole suite to learn about the handful of files it
|
|
5
|
+
* changed: 374 files, 13,915 tests, ~8.9 minutes and 5,360 MB. That last
|
|
6
|
+
* number is why `lib/test-suite-lock.ts` sets `DEFAULT_CAPACITY = 2` — the
|
|
7
|
+
* suite, not the checkout, is what holds concurrent runs at two.
|
|
8
|
+
*
|
|
9
|
+
* **The direction this is allowed to be wrong in is TOWARD running too much.**
|
|
10
|
+
* A selection that is too large costs minutes. A selection that is too small
|
|
11
|
+
* reports a green suite over a regression, wearing the most convincing
|
|
12
|
+
* disguise available. So every question this module cannot answer resolves to
|
|
13
|
+
* "run everything", and it says which question it was.
|
|
14
|
+
*
|
|
15
|
+
* In particular an empty `tests` list is NEVER an instruction to run nothing.
|
|
16
|
+
* `0`, `{}`, `null` and `SKIP` are indistinguishable from success
|
|
17
|
+
* (`.claude/rules/config-access.md`); `UNMEASURED` is not. A caller must be
|
|
18
|
+
* able to tell "nothing is affected" from "I could not work out what is
|
|
19
|
+
* affected", and those are `reading`, not `tests.length`.
|
|
20
|
+
*
|
|
21
|
+
* Three ways a test reaches a file, because a graph that knows only the first
|
|
22
|
+
* reads exactly like a graph that is satisfied (#484 — an import and a
|
|
23
|
+
* `readFileSync(join(...))` are one question in two syntaxes):
|
|
24
|
+
*
|
|
25
|
+
* 1. a chain of relative imports, followed transitively
|
|
26
|
+
* 2. a module-relative `readFileSync(join(import.meta.dir, ...))`
|
|
27
|
+
* 3. a sweep — `readdirSync` or a glob — which is affected by anything
|
|
28
|
+
* under the tree it walks and cannot be expressed as an edge at all
|
|
29
|
+
*
|
|
30
|
+
* Sweeps are included unconditionally AND listed in `sweeps`. Including one
|
|
31
|
+
* silently would make "the graph selected this" and "I could not reason about
|
|
32
|
+
* this so I kept it" the same output, which is the reporting-position defect
|
|
33
|
+
* this repo keeps finding.
|
|
34
|
+
*/
|
|
35
|
+
import { readdirSync, readFileSync, realpathSync, statSync } from "fs";
|
|
36
|
+
import { join, dirname } from "path";
|
|
37
|
+
|
|
38
|
+
import { relativeImports, runtimeReads, unresolvedModuleRelativeJoins } from "./package-closure";
|
|
39
|
+
import { stripJsComments } from "./strip-js-comments";
|
|
40
|
+
|
|
41
|
+
/** Extensions whose dependencies this module can actually resolve. */
|
|
42
|
+
export const SELECTABLE_SOURCE = /\.(ts|tsx|js|jsx|mts|cts)$/;
|
|
43
|
+
|
|
44
|
+
/** A test file, by the convention this repo uses everywhere. */
|
|
45
|
+
export const TEST_FILE = /\.test\.(ts|tsx)$/;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Directories walked when building the graph.
|
|
49
|
+
*
|
|
50
|
+
* `workflows` is in this list for a reason worth stating: `ship.js` is the
|
|
51
|
+
* most-changed file in this repository and it cannot be imported (#69), so
|
|
52
|
+
* it is reached only by the tests that read it as text. Leaving the
|
|
53
|
+
* directory out did not make a change to it UNMEASURED — it made the change
|
|
54
|
+
* resolve to nothing and report MEASURED, which is silent under-selection
|
|
55
|
+
* and the exact failure this module exists to prevent. Found in review
|
|
56
|
+
* before it shipped; every fixture in the battery put its changed files
|
|
57
|
+
* inside the walked tree, so the branch where that is false was outside the
|
|
58
|
+
* battery's reach entirely (#492).
|
|
59
|
+
*/
|
|
60
|
+
export const SCAN_DIRS = ["test", "lib", "scripts", "gates", "bin", "hooks", "workflows"];
|
|
61
|
+
|
|
62
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", "coverage"]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A test that discovers its subjects at runtime rather than importing them.
|
|
66
|
+
*
|
|
67
|
+
* Deliberately a family rather than one spelling: a detector that knows only
|
|
68
|
+
* `readdirSync` is the narrow-detector shape in
|
|
69
|
+
* `.claude/rules/checks-must-be-able-to-fail.md`, and the cost of missing a
|
|
70
|
+
* sweep is a green run over a tree it never walked.
|
|
71
|
+
*
|
|
72
|
+
* `execSync`/`spawnSync` are included ONLY when the command text contains an
|
|
73
|
+
* enumeration verb. Marking every shell-out a sweep would catch the tests
|
|
74
|
+
* that `git grep` the tree — which are genuine sweeps — and also every test
|
|
75
|
+
* that runs `git rev-parse`, which is most of them, and the selection would
|
|
76
|
+
* collapse to the whole suite. The matched spelling is reported so the
|
|
77
|
+
* over-inclusion stays visible rather than becoming a number nobody can
|
|
78
|
+
* explain.
|
|
79
|
+
*/
|
|
80
|
+
const SWEEP_PATTERNS: Array<[string, RegExp]> = [
|
|
81
|
+
["readdir", /\b(readdirSync|readdir|opendirSync|opendir)\s*\(/],
|
|
82
|
+
["glob", /\b(globSync|glob)\s*\(|\bGlob\b|\.scan\s*\(/],
|
|
83
|
+
["shell-enumeration", /\b(execSync|spawnSync|execFileSync)\s*\([^)]*?(grep\s+-r|git\s+grep|git\s+ls-files|\bfind\b|\bls\b)/],
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
export interface AffectedTestsReading {
|
|
87
|
+
/** `UNMEASURED` means run the full suite; `tests` is empty and means nothing. */
|
|
88
|
+
reading: "MEASURED" | "UNMEASURED";
|
|
89
|
+
/** Repo-relative test files to run, sorted. Empty under UNMEASURED. */
|
|
90
|
+
tests: string[];
|
|
91
|
+
/** Why the selection cannot be trusted. Empty when MEASURED. */
|
|
92
|
+
unmeasuredReasons: string[];
|
|
93
|
+
/** Test files the walk found — the denominator for `selected`. */
|
|
94
|
+
testFilesSeen: number;
|
|
95
|
+
/** `tests.length`, stated so a reader does not have to count. */
|
|
96
|
+
selected: number;
|
|
97
|
+
/** Selected because they enumerate a directory, not because of an edge. */
|
|
98
|
+
sweeps: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Repo-relative, forward slashes, no leading `./`. */
|
|
102
|
+
function norm(p: string): string {
|
|
103
|
+
return p.split("\\").join("/").replace(/^\.\//, "");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every source file under SCAN_DIRS, repo-relative.
|
|
108
|
+
*
|
|
109
|
+
* Symlinked directories are followed — a monorepo whose packages are linked
|
|
110
|
+
* into place is a real layout, and `readdirSync(withFileTypes)` reports a
|
|
111
|
+
* symlink as not-a-directory, so a `statSync` is the only thing that makes
|
|
112
|
+
* them visible (#500). Following them means a link cycle would recurse
|
|
113
|
+
* forever, so every directory is recorded by its REAL path and visited
|
|
114
|
+
* once, and a link pointing outside the root is declined rather than
|
|
115
|
+
* walked.
|
|
116
|
+
*/
|
|
117
|
+
function sourceFiles(root: string): string[] {
|
|
118
|
+
const out: string[] = [];
|
|
119
|
+
const seenDirs = new Set<string>();
|
|
120
|
+
const rootReal = (() => {
|
|
121
|
+
try {
|
|
122
|
+
return realpathSync(root);
|
|
123
|
+
} catch {
|
|
124
|
+
return root;
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
|
|
128
|
+
const walk = (rel: string): void => {
|
|
129
|
+
const abs = join(root, rel);
|
|
130
|
+
let real: string;
|
|
131
|
+
try {
|
|
132
|
+
real = realpathSync(abs);
|
|
133
|
+
} catch {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (real !== rootReal && !real.startsWith(rootReal + "/")) return; // escaped the tree
|
|
137
|
+
if (seenDirs.has(real)) return; // a cycle, or two links to one directory
|
|
138
|
+
seenDirs.add(real);
|
|
139
|
+
|
|
140
|
+
let entries;
|
|
141
|
+
try {
|
|
142
|
+
entries = readdirSync(abs, { withFileTypes: true });
|
|
143
|
+
} catch {
|
|
144
|
+
return; // a directory this project does not have
|
|
145
|
+
}
|
|
146
|
+
for (const e of entries) {
|
|
147
|
+
if (SKIP_DIRS.has(e.name)) continue;
|
|
148
|
+
const child = norm(join(rel, e.name));
|
|
149
|
+
let isDir = e.isDirectory();
|
|
150
|
+
if (e.isSymbolicLink()) {
|
|
151
|
+
try {
|
|
152
|
+
isDir = statSync(join(root, child)).isDirectory();
|
|
153
|
+
} catch {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (isDir) walk(child);
|
|
158
|
+
else if (SELECTABLE_SOURCE.test(e.name)) out.push(child);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
for (const d of SCAN_DIRS) walk(d);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Resolve a relative specifier written in `from` to a file in `known`.
|
|
167
|
+
*
|
|
168
|
+
* The `.js` → `.ts` candidates are not decoration: TypeScript source that
|
|
169
|
+
* targets ESM writes `./x.js` for a file on disk called `x.ts`, and a
|
|
170
|
+
* resolver that does not know that drops the edge silently.
|
|
171
|
+
*/
|
|
172
|
+
function resolveSpec(from: string, spec: string, known: Set<string>): string | null {
|
|
173
|
+
const base = norm(join(dirname(from), spec));
|
|
174
|
+
const candidates = [
|
|
175
|
+
base,
|
|
176
|
+
`${base}.ts`,
|
|
177
|
+
`${base}.tsx`,
|
|
178
|
+
`${base}.js`,
|
|
179
|
+
base.replace(/\.js$/, ".ts"),
|
|
180
|
+
base.replace(/\.js$/, ".tsx"),
|
|
181
|
+
norm(join(base, "index.ts")),
|
|
182
|
+
norm(join(base, "index.tsx")),
|
|
183
|
+
];
|
|
184
|
+
for (const c of candidates) if (known.has(c)) return c;
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Where a module-relative `join(import.meta.dir, ...)` points, repo-relative. */
|
|
189
|
+
function resolveRuntimeRead(from: string, up: number, segments: string[]): string {
|
|
190
|
+
let base = dirname(from);
|
|
191
|
+
for (let i = 0; i < up; i++) base = dirname(base);
|
|
192
|
+
return norm(join(base, ...segments));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The test files that can reach any of `changed`.
|
|
197
|
+
*
|
|
198
|
+
* `changed` is repo-relative. The reading is UNMEASURED — meaning "run the
|
|
199
|
+
* full suite" — when the graph provably cannot answer: an empty change set,
|
|
200
|
+
* a changed module the walk never saw, a changed non-module nothing in the
|
|
201
|
+
* tree names, or a walk that found no tests at all. That last one is #492's
|
|
202
|
+
* lesson: a scan that reached nothing reports the same clean result as a
|
|
203
|
+
* scan that found nothing wrong.
|
|
204
|
+
*/
|
|
205
|
+
export function affectedTests(root: string, changed: string[]): AffectedTestsReading {
|
|
206
|
+
const unmeasuredReasons: string[] = [];
|
|
207
|
+
const wanted = changed.map(norm);
|
|
208
|
+
|
|
209
|
+
if (wanted.length === 0) {
|
|
210
|
+
unmeasuredReasons.push(
|
|
211
|
+
"no changed files were supplied, so nothing constrains the selection — " +
|
|
212
|
+
"an unconstrained selection is the whole suite, not an empty one",
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const nonModule = wanted.filter(c => !SELECTABLE_SOURCE.test(c));
|
|
217
|
+
const files = sourceFiles(root);
|
|
218
|
+
const known = new Set(files);
|
|
219
|
+
const testFiles = files.filter(f => TEST_FILE.test(f));
|
|
220
|
+
|
|
221
|
+
// A changed file the walk never saw has NO EDGE to it by construction, so
|
|
222
|
+
// every test comes back unaffected and the reading would say MEASURED over
|
|
223
|
+
// a question it never asked. This is the one that nearly shipped: before
|
|
224
|
+
// `workflows` was in SCAN_DIRS, a change to `ship.js` landed here.
|
|
225
|
+
for (const c of wanted) {
|
|
226
|
+
if (SELECTABLE_SOURCE.test(c) && !known.has(c)) {
|
|
227
|
+
unmeasuredReasons.push(
|
|
228
|
+
`${c} is outside the walked tree (${SCAN_DIRS.join(", ")}) or no longer exists, so no ` +
|
|
229
|
+
"edge to it can exist — \"nothing is affected\" would be an artefact of not looking",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (testFiles.length === 0) {
|
|
235
|
+
unmeasuredReasons.push(
|
|
236
|
+
`the walk over ${SCAN_DIRS.join(", ")} found no test files, which is not the ` +
|
|
237
|
+
"same as finding no affected ones",
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// REVERSE edges: for each file, who depends on it.
|
|
242
|
+
//
|
|
243
|
+
// Walking dependents outward from the changed set is linear and has no
|
|
244
|
+
// interaction with cycles at all. The first draft walked forward from each
|
|
245
|
+
// test with a memo, which is unsound in exactly one way that is hard to
|
|
246
|
+
// see: a `false` computed while a cycle edge was cut gets cached, and a
|
|
247
|
+
// later query reads the wrong answer. Reversing the question removes the
|
|
248
|
+
// bug rather than guarding it.
|
|
249
|
+
const dependents = new Map<string, Set<string>>();
|
|
250
|
+
const sweeps: string[] = [];
|
|
251
|
+
const opaque: string[] = [];
|
|
252
|
+
|
|
253
|
+
const addEdge = (from: string, to: string): void => {
|
|
254
|
+
let s = dependents.get(to);
|
|
255
|
+
if (!s) {
|
|
256
|
+
s = new Set();
|
|
257
|
+
dependents.set(to, s);
|
|
258
|
+
}
|
|
259
|
+
s.add(from);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
for (const f of files) {
|
|
263
|
+
let source: string;
|
|
264
|
+
try {
|
|
265
|
+
source = readFileSync(join(root, f), "utf-8");
|
|
266
|
+
} catch {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for (const spec of relativeImports(source)) {
|
|
270
|
+
const target = resolveSpec(f, spec, known);
|
|
271
|
+
if (target) addEdge(f, target);
|
|
272
|
+
}
|
|
273
|
+
const resolvedBasenames = new Set<string>();
|
|
274
|
+
for (const read of runtimeReads(source)) {
|
|
275
|
+
const target = resolveRuntimeRead(f, read.up, read.segments);
|
|
276
|
+
resolvedBasenames.add(target.split("/").pop() as string);
|
|
277
|
+
addEdge(f, target);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// A changed file that is not a module is reached by the files that NAME
|
|
281
|
+
// it. Nothing imports a rule file, a spec or a YAML, so the first draft
|
|
282
|
+
// refused the whole selection whenever one appeared in the change set —
|
|
283
|
+
// and measured against eight real commits of this repository, seven
|
|
284
|
+
// carried at least one, so the feature was inert on the input it exists
|
|
285
|
+
// to serve.
|
|
286
|
+
//
|
|
287
|
+
// **Over a COMMENT-STRIPPED view.** A citation and a read are the same
|
|
288
|
+
// bytes, and this repository cites its own rule files constantly:
|
|
289
|
+
// matching raw source, `.claude/rules/checks-must-be-able-to-fail.md`
|
|
290
|
+
// alone selected 322 of 388 files — 83% of the suite — because almost
|
|
291
|
+
// every test mentions it in a docstring. Over code only it is 108, of
|
|
292
|
+
// which 72 are the sweep floor. `blankLiterals` stays OFF: the path
|
|
293
|
+
// lives in a string literal, which is exactly the thing a read is made
|
|
294
|
+
// of.
|
|
295
|
+
//
|
|
296
|
+
// The direction of error is unchanged. A reader that does not write the
|
|
297
|
+
// path down in code is assembling it at runtime, and a file that does
|
|
298
|
+
// that is already a sweep.
|
|
299
|
+
const code = stripJsComments(source);
|
|
300
|
+
for (const c of nonModule) {
|
|
301
|
+
if (code.includes(c)) addEdge(f, c);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// The same question in a third syntax (#484). `runtimeReads` sees
|
|
305
|
+
// `join(import.meta.dir, "..", "workflows", "ship.js")` and nothing
|
|
306
|
+
// else, so one const of indirection hides the read:
|
|
307
|
+
//
|
|
308
|
+
// const REPO_ROOT = join(import.meta.dir, "..");
|
|
309
|
+
// readFileSync(join(REPO_ROOT, "workflows", "ship.js"), "utf-8")
|
|
310
|
+
//
|
|
311
|
+
// Measured on this repository, that is not hypothetical — it is how
|
|
312
|
+
// `test/implement-empty-result.test.ts` and
|
|
313
|
+
// `test/files-changed-path-shape.test.ts` reach `ship.js`, and both
|
|
314
|
+
// were silently unselected by a change to it. Resolving the
|
|
315
|
+
// indirection means evaluating the module, so instead the BASENAME as
|
|
316
|
+
// a quoted literal in code is an edge. It over-selects for a common
|
|
317
|
+
// basename and that is the direction this is allowed to be wrong in;
|
|
318
|
+
// a missed read is the direction that reports green over code it
|
|
319
|
+
// never ran.
|
|
320
|
+
//
|
|
321
|
+
// **Skipped for a basename this file already reads resolvably**, and
|
|
322
|
+
// that clause is what keeps `runtimeReads` load-bearing rather than a
|
|
323
|
+
// second decider agreeing with this one. Measured before it was added:
|
|
324
|
+
// deleting the `runtimeReads` call entirely was 0 red and moved the
|
|
325
|
+
// real selection by 0 files, because a resolvable read always quotes
|
|
326
|
+
// its own basename. With the clause, a file that resolvably reads
|
|
327
|
+
// `lib/a/config.ts` is NOT selected by a change to `lib/b/config.ts`
|
|
328
|
+
// — it has shown it can name that basename precisely — while a file
|
|
329
|
+
// that reaches the same path through a const still is. Two deciders,
|
|
330
|
+
// each with an input only it can reach.
|
|
331
|
+
for (const c of wanted) {
|
|
332
|
+
const b = c.split("/").pop();
|
|
333
|
+
if (!b || resolvedBasenames.has(b)) continue;
|
|
334
|
+
if (new RegExp(`["'\`]${b.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}["'\`]`).test(code)) {
|
|
335
|
+
addEdge(f, c);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// A module-relative join whose segments are not all literals reads a
|
|
340
|
+
// path nobody can name statically. `runtimeReads` drops those; dropping
|
|
341
|
+
// them here would be the fail-open `lib/package-closure.ts` built
|
|
342
|
+
// `unresolvedModuleRelativeJoins` to prevent. A test that does it is a
|
|
343
|
+
// sweep; anything else becomes a seed, so every test that can reach it
|
|
344
|
+
// runs too.
|
|
345
|
+
const unresolved = unresolvedModuleRelativeJoins(source).length > 0;
|
|
346
|
+
if (TEST_FILE.test(f)) {
|
|
347
|
+
if (unresolved || SWEEP_PATTERNS.some(([, re]) => re.test(code))) sweeps.push(f);
|
|
348
|
+
} else if (unresolved) {
|
|
349
|
+
opaque.push(f);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// A non-module file nothing in the tree names is not an unaffected file —
|
|
354
|
+
// it is a file whose readers, if it has any, build its path at runtime,
|
|
355
|
+
// and the graph has no way to see them. Refuse by name.
|
|
356
|
+
for (const c of nonModule) {
|
|
357
|
+
if (!dependents.has(c)) {
|
|
358
|
+
unmeasuredReasons.push(
|
|
359
|
+
`${c} is not a module, and no file under ${SCAN_DIRS.join(", ")} names it, so any test ` +
|
|
360
|
+
"that reads it builds the path at runtime where the graph cannot follow",
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (unmeasuredReasons.length > 0) {
|
|
366
|
+
return {
|
|
367
|
+
reading: "UNMEASURED",
|
|
368
|
+
tests: [],
|
|
369
|
+
unmeasuredReasons,
|
|
370
|
+
testFilesSeen: testFiles.length,
|
|
371
|
+
selected: 0,
|
|
372
|
+
sweeps: [],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Breadth-first over dependents, seeded with the change set and with every
|
|
377
|
+
// module whose own reads could not be resolved.
|
|
378
|
+
const reached = new Set<string>();
|
|
379
|
+
const queue = [...wanted, ...opaque];
|
|
380
|
+
while (queue.length > 0) {
|
|
381
|
+
const cur = queue.pop() as string;
|
|
382
|
+
if (reached.has(cur)) continue;
|
|
383
|
+
reached.add(cur);
|
|
384
|
+
for (const d of dependents.get(cur) ?? []) if (!reached.has(d)) queue.push(d);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const sweepSet = new Set(sweeps);
|
|
388
|
+
const tests = testFiles.filter(t => sweepSet.has(t) || reached.has(t)).sort();
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
reading: "MEASURED",
|
|
392
|
+
tests,
|
|
393
|
+
unmeasuredReasons: [],
|
|
394
|
+
testFilesSeen: testFiles.length,
|
|
395
|
+
selected: tests.length,
|
|
396
|
+
sweeps: sweeps.sort(),
|
|
397
|
+
};
|
|
398
|
+
}
|
package/lib/agent-audit.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
11
11
|
import { join } from 'path';
|
|
12
12
|
import { auditAgent, type Role } from '../scripts/audit-transcript';
|
|
13
|
-
import { writeCache, type BehavioralCache } from './behavioral-cache';
|
|
13
|
+
import { behavioralCachePath, writeCache, type BehavioralCache } from './behavioral-cache';
|
|
14
14
|
|
|
15
15
|
export interface AgentAuditResult {
|
|
16
16
|
role: Role;
|
|
@@ -109,8 +109,7 @@ export function populateBehavioralCache(
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (Object.keys(cacheData).length > 0) {
|
|
112
|
-
|
|
113
|
-
writeCache(cachePath, cacheData);
|
|
112
|
+
writeCache(behavioralCachePath(projectRoot), cacheData);
|
|
114
113
|
return Object.keys(cacheData).length;
|
|
115
114
|
}
|
|
116
115
|
} catch {
|