rungate 0.5.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 +209 -0
- package/lib/behavioral-cache.ts +150 -2
- package/lib/branch-diff.ts +139 -0
- 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 +347 -0
- package/lib/check-remedy.ts +140 -0
- package/lib/ci-checkout.ts +18 -1
- 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 +196 -20
- package/lib/config-loader.ts +51 -1
- package/lib/config-trackable.ts +391 -0
- package/lib/conformity.ts +1272 -189
- package/lib/containment.ts +238 -0
- package/lib/content-hash.ts +24 -0
- package/lib/context-docs.ts +143 -28
- package/lib/create-brief.ts +2 -1
- package/lib/create-sc.ts +323 -4
- 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/doc-scan-targets.ts +9 -0
- package/lib/evidence-command-transport.ts +160 -0
- package/lib/evidence-prevalidator.ts +246 -2
- package/lib/evidence-satisfiability.ts +534 -12
- package/lib/failure-intake.ts +317 -0
- package/lib/fallow-availability.ts +286 -0
- package/lib/fs-write-capabilities.ts +232 -0
- package/lib/gate-refusal-currency.ts +112 -0
- package/lib/gate-run-split.ts +147 -0
- package/lib/gate-timeouts.ts +82 -0
- package/lib/generators/agent-briefs.ts +4 -1
- package/lib/generators/agents-md.ts +204 -48
- package/lib/generators/code-map.ts +2 -1
- package/lib/generators/types.ts +8 -0
- package/lib/git-dates.ts +55 -0
- 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 +536 -0
- package/lib/launch-base.ts +253 -0
- package/lib/line-citation.ts +372 -0
- package/lib/local-calendar-day.ts +78 -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/project-state-shape.ts +59 -0
- package/lib/promote-outputs.ts +6 -2
- package/lib/published-artifact.ts +525 -0
- package/lib/readdir-sorted.ts +45 -0
- package/lib/report-provenance.ts +156 -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-claim-forms.ts +75 -0
- package/lib/sc-id-cross-tree.ts +323 -0
- 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 +4777 -0
- package/lib/scaffold/managed-workflow.ts +587 -192
- package/lib/scaffold/owned-files.ts +186 -39
- package/lib/scaffold/pre-push-hook.ts +49 -5
- package/lib/scaffold/rehearsal.ts +205 -71
- package/lib/scaffold/steps.ts +1517 -293
- package/lib/scaffold/workflow-census.ts +217 -0
- package/lib/scaffold/workflow-drift.ts +217 -0
- package/lib/scaffold/write-steps.ts +10 -4
- package/lib/scan-budget.ts +247 -0
- package/lib/scanner.ts +80 -62
- 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/spec-listing.ts +148 -0
- package/lib/spec-requirements.ts +209 -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 +411 -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-command.ts +133 -0
- package/lib/test-suite-lock.ts +325 -26
- package/lib/tool-probe.ts +142 -0
- package/lib/top-level-cd.ts +393 -0
- package/lib/tracked-vs-ignored.ts +234 -0
- package/lib/tree-entries.ts +89 -0
- package/lib/ts-ast.ts +200 -0
- package/lib/validators/spec-validators.ts +3 -2
- 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/audit-specs.ts +247 -12
- package/scripts/audit-transcript.ts +2 -1
- package/scripts/convert-spec.ts +2 -1
- package/scripts/create-sc.ts +37 -7
- package/scripts/create-spec.ts +2 -1
- package/scripts/create-success.ts +2 -1
- package/scripts/extract-constraints.ts +197 -26
- package/scripts/generate-code-map.ts +62 -28
- package/scripts/scaffold-project.ts +12 -2
- package/scripts/split-spec.ts +2 -1
- package/scripts/sync-sc-status.ts +127 -14
- package/scripts/sync-spec-tests.ts +2 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a registration's path actually RESOLVES — the tree the settings
|
|
3
|
+
* register, against the tree the repo tests (#713).
|
|
4
|
+
*
|
|
5
|
+
* A near-leaf module: its only relative imports are `hook-trees` (one argv
|
|
6
|
+
* parse) and `hook-scopes` (one definition of a complete scope reading), so
|
|
7
|
+
* there is one binding to mutate per question and no second opinion about
|
|
8
|
+
* either.
|
|
9
|
+
*
|
|
10
|
+
* ## The reading that was missing, with the cost attached
|
|
11
|
+
*
|
|
12
|
+
* `lib/hook-trees.ts` decides the tree by SPELLING: a command containing
|
|
13
|
+
* `${RUNGATE_HOOKS_DIR}` reads as `"rungate"`, which every check in this repo
|
|
14
|
+
* then treats as *this checkout*. Measured 2026-10-21 on the author's
|
|
15
|
+
* machine, `~/.claude/settings.json` defines
|
|
16
|
+
*
|
|
17
|
+
* RUNGATE_HOOKS_DIR = <a checkout that is not this one>
|
|
18
|
+
*
|
|
19
|
+
* and registers fourteen hook commands through it. So the spelling says
|
|
20
|
+
* "rungate" and the bytes that execute are a different tree's. `#999` merged
|
|
21
|
+
* a shell-injection fix into `hooks/ProjectStateSync.hook.ts` — replacing an
|
|
22
|
+
* `execSync` template literal carrying tool input with an argv
|
|
23
|
+
* `execFileSync` — and the file the registration resolves to still carries
|
|
24
|
+
* the `execSync` form. **A merged security fix did not reach the code that
|
|
25
|
+
* runs**, and the whole suite was green through it, including a case titled
|
|
26
|
+
* *"every hook this repo owns is wired to this repo's copy"*.
|
|
27
|
+
*
|
|
28
|
+
* That case is not wrong about what it asserts. It asserts the spelling, and
|
|
29
|
+
* the spelling was right. Nothing resolved it.
|
|
30
|
+
*
|
|
31
|
+
* ## The property
|
|
32
|
+
*
|
|
33
|
+
* **The tree the settings register is the tree the repo tests.** It is a
|
|
34
|
+
* statement about a RESOLVED path, and it cannot be decided from any amount
|
|
35
|
+
* of reading the command string — which is why this module exists beside
|
|
36
|
+
* `registrationTree` rather than inside it. `registrationTree` answers
|
|
37
|
+
* *which root is this spelled with*; this answers *which directory does that
|
|
38
|
+
* root name on the machine doing the reading*. They are different questions
|
|
39
|
+
* and the first one has been standing in for the second.
|
|
40
|
+
*
|
|
41
|
+
* ## Why this is a REFUSAL, and the three ways it would otherwise fail open
|
|
42
|
+
*
|
|
43
|
+
* Each of these produces a clean-looking reading from no evidence, and all
|
|
44
|
+
* three are reachable here (`.claude/rules/config-access.md`):
|
|
45
|
+
*
|
|
46
|
+
* | the silent pass | what it must read as instead |
|
|
47
|
+
* |---|---|
|
|
48
|
+
* | a variable no readable scope defines, assumed to mean this repo | `unresolved` → UNMEASURED |
|
|
49
|
+
* | a scope nobody could open, counted as registering nothing | UNMEASURED, with the scope named |
|
|
50
|
+
* | **zero registrations examined** | UNMEASURED — *zero trees compared is not perfect agreement* |
|
|
51
|
+
*
|
|
52
|
+
* The third is the one with no analogue in the existing census and the one a
|
|
53
|
+
* reader is least likely to write a case for: `foreign.length === 0` is the
|
|
54
|
+
* same value for a tree with every hook correctly wired and for a run that
|
|
55
|
+
* looked at nothing. `examined` is carried so the two are distinguishable,
|
|
56
|
+
* and the reading refuses rather than leaving it to a caller to notice.
|
|
57
|
+
*
|
|
58
|
+
* ## `CLAUDE_PROJECT_DIR` resolves only in a scope the repo owns
|
|
59
|
+
*
|
|
60
|
+
* In `.claude/settings.json` it is this repository by definition — that file
|
|
61
|
+
* loads only for a session started here. In `~/.claude/settings.json` it is
|
|
62
|
+
* **whatever directory the session was started in**, which is session state
|
|
63
|
+
* and not knowable from any file. Resolving it to the repo root in both
|
|
64
|
+
* places would be the first row of the table above, wearing the costume of
|
|
65
|
+
* an obvious simplification: it would turn a user-scope registration that may
|
|
66
|
+
* execute any checkout into a confident `in-repo`.
|
|
67
|
+
*
|
|
68
|
+
* ## A variable with two values is UNRESOLVED, not a precedence puzzle
|
|
69
|
+
*
|
|
70
|
+
* Two scopes defining the same variable differently is a state this module
|
|
71
|
+
* refuses rather than ranks. Picking a winner means encoding a precedence
|
|
72
|
+
* order nobody has written down, and being wrong about it produces exactly
|
|
73
|
+
* the confident-and-wrong path this file exists to stop.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
import { executedHookPath } from "./hook-trees";
|
|
77
|
+
import {
|
|
78
|
+
type RegistrationScope,
|
|
79
|
+
type ScopeReading,
|
|
80
|
+
assertEveryScopeRead,
|
|
81
|
+
settingsScopePaths,
|
|
82
|
+
} from "./hook-scopes";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The scopes in which `${CLAUDE_PROJECT_DIR}` is THIS repository.
|
|
86
|
+
*
|
|
87
|
+
* Derived from nothing: it is the list of scopes that only load for a session
|
|
88
|
+
* started in this tree. `repo-registry` is included because
|
|
89
|
+
* `.claude/rungate/hooks.json` is scaffolded into the project settings and
|
|
90
|
+
* has the same reach.
|
|
91
|
+
*/
|
|
92
|
+
const PROJECT_DIR_SCOPES: RegistrationScope[] = [
|
|
93
|
+
"project-settings",
|
|
94
|
+
"project-local-settings",
|
|
95
|
+
"repo-registry",
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
/** `env` assignments read from one settings scope. `null` means unreadable. */
|
|
99
|
+
export interface EnvReading {
|
|
100
|
+
scope: RegistrationScope;
|
|
101
|
+
env: Record<string, string> | null;
|
|
102
|
+
/** Why it could not be read. REQUIRED when `env` is null. */
|
|
103
|
+
unreadable?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The `env` block of one settings document.
|
|
108
|
+
*
|
|
109
|
+
* A document that does not parse THROWS, for the same reason
|
|
110
|
+
* `settingsCommands` throws: a corrupt settings file is not a settings file
|
|
111
|
+
* with no variables in it, and swallowing it would turn every variable it
|
|
112
|
+
* defines into `unresolved` — a refusal, but for the wrong reason, and one
|
|
113
|
+
* nobody could act on.
|
|
114
|
+
*
|
|
115
|
+
* Non-string values are DROPPED rather than coerced. `"X": 3` is not a path
|
|
116
|
+
* fragment and `String(3)` would build one.
|
|
117
|
+
*/
|
|
118
|
+
export function settingsEnv(doc: string): Record<string, string> {
|
|
119
|
+
const parsed = JSON.parse(doc) as { env?: unknown };
|
|
120
|
+
const env = parsed?.env;
|
|
121
|
+
if (env === null || typeof env !== "object" || Array.isArray(env)) return {};
|
|
122
|
+
const out: Record<string, string> = {};
|
|
123
|
+
for (const [k, v] of Object.entries(env as Record<string, unknown>)) {
|
|
124
|
+
if (typeof v === "string") out[k] = v;
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Every distinct value each variable is given, across the scopes that could
|
|
131
|
+
* be read.
|
|
132
|
+
*
|
|
133
|
+
* A list rather than a value, so a variable defined twice differently is
|
|
134
|
+
* visible as such at the point of use instead of being resolved by whichever
|
|
135
|
+
* scope happened to be last.
|
|
136
|
+
*/
|
|
137
|
+
export function mergeEnv(readings: EnvReading[]): Record<string, string[]> {
|
|
138
|
+
const out: Record<string, string[]> = {};
|
|
139
|
+
for (const r of readings) {
|
|
140
|
+
for (const [k, v] of Object.entries(r.env ?? {})) {
|
|
141
|
+
const seen = (out[k] ??= []);
|
|
142
|
+
if (!seen.includes(v)) seen.push(v);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Assemble a complete env reading from a filesystem.
|
|
150
|
+
*
|
|
151
|
+
* Deliberately shaped like `readRegistrationScopes` and reading the SAME
|
|
152
|
+
* `settingsScopePaths` declaration, including its `ownership` field — so what
|
|
153
|
+
* an absent file means is decided in one place for both readings. A reader
|
|
154
|
+
* with its own idea of that is how `unregistered` became unreachable once
|
|
155
|
+
* already (battery row M6 of #970).
|
|
156
|
+
*
|
|
157
|
+
* `repo-registry` is a hooks array, not a settings document, so it defines no
|
|
158
|
+
* variables. It is present with an empty reading rather than omitted: an
|
|
159
|
+
* omitted scope is what `assertEveryScopeRead` exists to refuse, and "this
|
|
160
|
+
* scope cannot define variables" is a reading.
|
|
161
|
+
*/
|
|
162
|
+
export function readEnvScopes(
|
|
163
|
+
repoRoot: string,
|
|
164
|
+
home: string,
|
|
165
|
+
readFile: (path: string) => string | null,
|
|
166
|
+
): EnvReading[] {
|
|
167
|
+
const readings: EnvReading[] = settingsScopePaths(repoRoot, home).map(
|
|
168
|
+
({ scope, path, ownership }) => {
|
|
169
|
+
const doc = readFile(path);
|
|
170
|
+
if (doc !== null) return { scope, env: settingsEnv(doc) };
|
|
171
|
+
if (ownership === "repo") return { scope, env: {} };
|
|
172
|
+
return {
|
|
173
|
+
scope,
|
|
174
|
+
env: null,
|
|
175
|
+
unreadable:
|
|
176
|
+
`${path} is not on this machine, and it is machine state the repo does not own — so ` +
|
|
177
|
+
`any variable it defines is a value this run never saw`,
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
);
|
|
181
|
+
readings.push({ scope: "repo-registry", env: {} });
|
|
182
|
+
return readings;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type Resolution =
|
|
186
|
+
| { kind: "resolved"; path: string }
|
|
187
|
+
| { kind: "unresolved"; reason: string };
|
|
188
|
+
|
|
189
|
+
const VAR = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The first variable a raw path is reached through, or `"literal"`.
|
|
193
|
+
*
|
|
194
|
+
* This is what a ratchet keys on. Not the resolved directory — that is a
|
|
195
|
+
* machine path, and a machine path in a committed file is wrong on the next
|
|
196
|
+
* machine and churns on this one. Not the hook name either: a hundred hooks
|
|
197
|
+
* behind one misdirected variable is ONE fact, and banking it a hundred times
|
|
198
|
+
* means the entry churns on every hook added.
|
|
199
|
+
*/
|
|
200
|
+
export function pathSpelling(raw: string): string {
|
|
201
|
+
VAR.lastIndex = 0;
|
|
202
|
+
const m = VAR.exec(raw);
|
|
203
|
+
return m ? (m[1] ?? m[2]) : "literal";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Expand `${VAR}` and `$VAR` against a reading, or say which variable stopped
|
|
208
|
+
* it.
|
|
209
|
+
*
|
|
210
|
+
* `projectDir` is `null` in a scope where `${CLAUDE_PROJECT_DIR}` is session
|
|
211
|
+
* state — see the header. Passing the repo root there regardless is the
|
|
212
|
+
* cheapest wrong fix available at this call site and it is the one that
|
|
213
|
+
* reintroduces the defect.
|
|
214
|
+
*/
|
|
215
|
+
export function resolvePath(
|
|
216
|
+
raw: string,
|
|
217
|
+
env: Record<string, string[]>,
|
|
218
|
+
projectDir: string | null,
|
|
219
|
+
): Resolution {
|
|
220
|
+
const unresolved: string[] = [];
|
|
221
|
+
const expanded = raw.replace(VAR, (whole, braced?: string, bare?: string) => {
|
|
222
|
+
const name = braced ?? bare ?? "";
|
|
223
|
+
if (name === "CLAUDE_PROJECT_DIR") {
|
|
224
|
+
if (projectDir !== null) return projectDir;
|
|
225
|
+
unresolved.push(
|
|
226
|
+
`${name} is the directory the session was started in, which is session state and is ` +
|
|
227
|
+
`not readable from this scope`,
|
|
228
|
+
);
|
|
229
|
+
return whole;
|
|
230
|
+
}
|
|
231
|
+
const values = env[name];
|
|
232
|
+
if (values === undefined || values.length === 0) {
|
|
233
|
+
unresolved.push(`${name} is not defined by any scope this run could read`);
|
|
234
|
+
return whole;
|
|
235
|
+
}
|
|
236
|
+
if (values.length > 1) {
|
|
237
|
+
unresolved.push(
|
|
238
|
+
`${name} is defined ${values.length} times with different values, and which one applies ` +
|
|
239
|
+
`is a precedence question nobody has written down`,
|
|
240
|
+
);
|
|
241
|
+
return whole;
|
|
242
|
+
}
|
|
243
|
+
return values[0];
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (unresolved.length > 0) return { kind: "unresolved", reason: unresolved.join("; ") };
|
|
247
|
+
if (!expanded.startsWith("/")) {
|
|
248
|
+
return {
|
|
249
|
+
kind: "unresolved",
|
|
250
|
+
reason:
|
|
251
|
+
`${expanded} is not absolute, so which directory it names depends on the working ` +
|
|
252
|
+
`directory of whatever spawns the hook`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return { kind: "resolved", path: normalize(expanded) };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Collapse `//`, `/./` and a trailing slash. No `fs`, so no symlink resolution. */
|
|
259
|
+
function normalize(path: string): string {
|
|
260
|
+
const parts: string[] = [];
|
|
261
|
+
for (const seg of path.split("/")) {
|
|
262
|
+
if (seg === "" || seg === ".") continue;
|
|
263
|
+
if (seg === ".." ) { parts.pop(); continue; }
|
|
264
|
+
parts.push(seg);
|
|
265
|
+
}
|
|
266
|
+
return "/" + parts.join("/");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export type Target = "in-repo" | "foreign" | "unresolved";
|
|
270
|
+
|
|
271
|
+
export interface TargetReading {
|
|
272
|
+
hook: string;
|
|
273
|
+
scope: RegistrationScope;
|
|
274
|
+
command: string;
|
|
275
|
+
/** The variable the path is reached through, or `"literal"`. */
|
|
276
|
+
spelling: string;
|
|
277
|
+
target: Target;
|
|
278
|
+
/** The absolute path the registration resolves to, when it resolved. */
|
|
279
|
+
resolved: string | null;
|
|
280
|
+
detail: string;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface TargetTreeCensus {
|
|
284
|
+
reading: "MEASURED" | "UNMEASURED";
|
|
285
|
+
unmeasuredReasons: string[];
|
|
286
|
+
/** How many registrations this run actually looked at. */
|
|
287
|
+
examined: number;
|
|
288
|
+
inRepo: TargetReading[];
|
|
289
|
+
foreign: TargetReading[];
|
|
290
|
+
unresolved: TargetReading[];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Resolve every registration of every hook this repo owns, and say which tree
|
|
295
|
+
* it lands in.
|
|
296
|
+
*
|
|
297
|
+
* `readings` carries the commands and `envReadings` carries the variables,
|
|
298
|
+
* and BOTH go through `assertEveryScopeRead` — the one binding deciding what
|
|
299
|
+
* a complete reading is. A second definition of completeness here would be
|
|
300
|
+
* two deciders for one question
|
|
301
|
+
* (`.claude/rules/checks-must-be-able-to-fail.md`, the fourth shape), and the
|
|
302
|
+
* env half is the one that would quietly acquire a narrower scope list: a
|
|
303
|
+
* variable defined in a scope nobody read is indistinguishable from a
|
|
304
|
+
* variable nobody defined, and only the first of those is innocent.
|
|
305
|
+
*/
|
|
306
|
+
export function registeredTreeCensus(
|
|
307
|
+
owned: string[],
|
|
308
|
+
readings: ScopeReading[],
|
|
309
|
+
envReadings: EnvReading[],
|
|
310
|
+
repoRoot: string,
|
|
311
|
+
): TargetTreeCensus {
|
|
312
|
+
assertEveryScopeRead(readings);
|
|
313
|
+
assertEveryScopeRead(
|
|
314
|
+
envReadings.map(r => ({
|
|
315
|
+
scope: r.scope,
|
|
316
|
+
commands: r.env === null ? null : [],
|
|
317
|
+
unreadable: r.unreadable,
|
|
318
|
+
})),
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const reasons: string[] = [];
|
|
322
|
+
for (const r of readings) {
|
|
323
|
+
if (r.commands === null) reasons.push(`${r.scope} commands: ${r.unreadable}`);
|
|
324
|
+
}
|
|
325
|
+
for (const r of envReadings) {
|
|
326
|
+
if (r.env === null) reasons.push(`${r.scope} env: ${r.unreadable}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const env = mergeEnv(envReadings);
|
|
330
|
+
const hooksDir = normalize(`${repoRoot}/hooks`);
|
|
331
|
+
const out: TargetReading[] = [];
|
|
332
|
+
let examined = 0;
|
|
333
|
+
|
|
334
|
+
for (const reading of readings) {
|
|
335
|
+
const projectDir = PROJECT_DIR_SCOPES.includes(reading.scope) ? repoRoot : null;
|
|
336
|
+
for (const command of reading.commands ?? []) {
|
|
337
|
+
const raw = executedHookPath(command);
|
|
338
|
+
if (raw === null) continue;
|
|
339
|
+
const base = raw.slice(raw.lastIndexOf("/") + 1).replace(/\.hook\.ts$/, "");
|
|
340
|
+
if (!owned.includes(base)) continue;
|
|
341
|
+
|
|
342
|
+
examined++;
|
|
343
|
+
const spelling = pathSpelling(raw);
|
|
344
|
+
const res = resolvePath(raw, env, projectDir);
|
|
345
|
+
if (res.kind === "unresolved") {
|
|
346
|
+
out.push({
|
|
347
|
+
hook: base,
|
|
348
|
+
scope: reading.scope,
|
|
349
|
+
command,
|
|
350
|
+
spelling,
|
|
351
|
+
target: "unresolved",
|
|
352
|
+
resolved: null,
|
|
353
|
+
detail:
|
|
354
|
+
`${base} is registered in ${reading.scope} as ${raw}, and which directory that names ` +
|
|
355
|
+
`could not be read: ${res.reason}. An unresolved path is not this repo's copy; it is ` +
|
|
356
|
+
`no reading at all`,
|
|
357
|
+
});
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const dir = res.path.slice(0, res.path.lastIndexOf("/"));
|
|
362
|
+
const inRepo = dir === hooksDir;
|
|
363
|
+
out.push({
|
|
364
|
+
hook: base,
|
|
365
|
+
scope: reading.scope,
|
|
366
|
+
command,
|
|
367
|
+
spelling,
|
|
368
|
+
target: inRepo ? "in-repo" : "foreign",
|
|
369
|
+
resolved: res.path,
|
|
370
|
+
detail: inRepo
|
|
371
|
+
? `${base} is registered in ${reading.scope} and resolves to ${res.path}, inside the ` +
|
|
372
|
+
`tree this suite runs against`
|
|
373
|
+
: `${base} is registered in ${reading.scope} as ${raw}, which resolves to ${res.path} — ` +
|
|
374
|
+
`OUTSIDE ${hooksDir}. Nothing merged into this repository reaches that file, and ` +
|
|
375
|
+
`every check here is measuring bytes that do not execute`,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const unresolved = out.filter(r => r.target === "unresolved");
|
|
381
|
+
for (const r of unresolved) reasons.push(r.detail);
|
|
382
|
+
if (examined === 0) {
|
|
383
|
+
reasons.push(
|
|
384
|
+
`no registration of a hook this repo owns was examined, so no tree was compared with any ` +
|
|
385
|
+
`other. Zero trees compared is not perfect agreement — an empty violation list here means ` +
|
|
386
|
+
`the run found nothing to read, which is the state CI is in and is not a pass`,
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
reading: reasons.length === 0 ? "MEASURED" : "UNMEASURED",
|
|
392
|
+
unmeasuredReasons: reasons,
|
|
393
|
+
examined,
|
|
394
|
+
inRepo: out.filter(r => r.target === "in-repo"),
|
|
395
|
+
foreign: out.filter(r => r.target === "foreign"),
|
|
396
|
+
unresolved,
|
|
397
|
+
};
|
|
398
|
+
}
|