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.
Files changed (142) hide show
  1. package/lib/affected-tests.ts +398 -0
  2. package/lib/agent-audit.ts +2 -3
  3. package/lib/agent-worktree.ts +287 -0
  4. package/lib/agents-md-sections.ts +209 -0
  5. package/lib/behavioral-cache.ts +150 -2
  6. package/lib/branch-diff.ts +139 -0
  7. package/lib/branch-protection.ts +790 -0
  8. package/lib/brief-ac-alignment.ts +104 -0
  9. package/lib/brief-references.ts +205 -0
  10. package/lib/bun-version.ts +347 -0
  11. package/lib/check-remedy.ts +140 -0
  12. package/lib/ci-checkout.ts +18 -1
  13. package/lib/ci-history-depth.ts +159 -0
  14. package/lib/ci-setup-step.ts +96 -0
  15. package/lib/claude-code-action.ts +85 -0
  16. package/lib/claude-tool-vocabulary.ts +188 -0
  17. package/lib/cli-commands.ts +15 -0
  18. package/lib/commit-sha.ts +42 -0
  19. package/lib/commit-subject.ts +90 -0
  20. package/lib/compliance-report.ts +377 -45
  21. package/lib/compliance.ts +196 -20
  22. package/lib/config-loader.ts +51 -1
  23. package/lib/config-trackable.ts +391 -0
  24. package/lib/conformity.ts +1272 -189
  25. package/lib/containment.ts +238 -0
  26. package/lib/content-hash.ts +24 -0
  27. package/lib/context-docs.ts +143 -28
  28. package/lib/create-brief.ts +2 -1
  29. package/lib/create-sc.ts +323 -4
  30. package/lib/dev-liveness.ts +180 -0
  31. package/lib/discovery-branch-points.ts +432 -0
  32. package/lib/discovery-stability.ts +481 -0
  33. package/lib/distribution-currency.ts +186 -0
  34. package/lib/doc-routing.ts +157 -0
  35. package/lib/doc-scan-targets.ts +9 -0
  36. package/lib/evidence-command-transport.ts +160 -0
  37. package/lib/evidence-prevalidator.ts +246 -2
  38. package/lib/evidence-satisfiability.ts +534 -12
  39. package/lib/failure-intake.ts +317 -0
  40. package/lib/fallow-availability.ts +286 -0
  41. package/lib/fs-write-capabilities.ts +232 -0
  42. package/lib/gate-refusal-currency.ts +112 -0
  43. package/lib/gate-run-split.ts +147 -0
  44. package/lib/gate-timeouts.ts +82 -0
  45. package/lib/generators/agent-briefs.ts +4 -1
  46. package/lib/generators/agents-md.ts +204 -48
  47. package/lib/generators/code-map.ts +2 -1
  48. package/lib/generators/types.ts +8 -0
  49. package/lib/git-dates.ts +55 -0
  50. package/lib/git-isolation.ts +140 -0
  51. package/lib/github.ts +15 -0
  52. package/lib/google-auth-action.ts +93 -0
  53. package/lib/harness-project.ts +48 -0
  54. package/lib/harness-provenance.ts +255 -0
  55. package/lib/hook-evidence.ts +235 -0
  56. package/lib/hook-scopes.ts +386 -0
  57. package/lib/hook-target-tree.ts +398 -0
  58. package/lib/hook-trees.ts +447 -0
  59. package/lib/js-top-level-code.ts +78 -10
  60. package/lib/junit-checks.ts +536 -0
  61. package/lib/launch-base.ts +253 -0
  62. package/lib/line-citation.ts +372 -0
  63. package/lib/local-calendar-day.ts +78 -0
  64. package/lib/orphan-reaper.ts +468 -0
  65. package/lib/parity-binding.ts +205 -0
  66. package/lib/per-test-timeouts.ts +219 -0
  67. package/lib/plan-coverage.ts +151 -0
  68. package/lib/prior-branch.ts +201 -8
  69. package/lib/process-table.ts +146 -0
  70. package/lib/project-state-derivation.ts +219 -0
  71. package/lib/project-state-root.ts +258 -0
  72. package/lib/project-state-shape.ts +59 -0
  73. package/lib/promote-outputs.ts +6 -2
  74. package/lib/published-artifact.ts +525 -0
  75. package/lib/readdir-sorted.ts +45 -0
  76. package/lib/report-provenance.ts +156 -0
  77. package/lib/review-execution-reading.ts +206 -0
  78. package/lib/review-tool-agreement.ts +433 -0
  79. package/lib/rule-promotion.ts +234 -0
  80. package/lib/rule-retirement.ts +525 -0
  81. package/lib/run-branch.ts +612 -0
  82. package/lib/rungate-schema.ts +19 -0
  83. package/lib/runner-home.ts +274 -0
  84. package/lib/sc-claim-forms.ts +75 -0
  85. package/lib/sc-id-cross-tree.ts +323 -0
  86. package/lib/sc-ids.ts +121 -13
  87. package/lib/sc-reservations.ts +289 -0
  88. package/lib/scaffold/ai-review-findings.ts +403 -0
  89. package/lib/scaffold/ai-review-step.ts +4777 -0
  90. package/lib/scaffold/managed-workflow.ts +587 -192
  91. package/lib/scaffold/owned-files.ts +186 -39
  92. package/lib/scaffold/pre-push-hook.ts +49 -5
  93. package/lib/scaffold/rehearsal.ts +205 -71
  94. package/lib/scaffold/steps.ts +1517 -293
  95. package/lib/scaffold/workflow-census.ts +217 -0
  96. package/lib/scaffold/workflow-drift.ts +217 -0
  97. package/lib/scaffold/write-steps.ts +10 -4
  98. package/lib/scan-budget.ts +247 -0
  99. package/lib/scanner.ts +80 -62
  100. package/lib/scratch-roots.ts +50 -5
  101. package/lib/screenshot-discovery.ts +121 -0
  102. package/lib/screenshot-upload.ts +41 -1
  103. package/lib/secret-patterns.ts +511 -8
  104. package/lib/ship-mode.ts +219 -0
  105. package/lib/source-slice.ts +294 -0
  106. package/lib/spec-listing.ts +148 -0
  107. package/lib/spec-requirements.ts +209 -0
  108. package/lib/stale-cleanup.ts +37 -3
  109. package/lib/suite-flake.ts +278 -0
  110. package/lib/suite-measurement.ts +23 -4
  111. package/lib/suite-run-reading.ts +411 -1
  112. package/lib/suite-timeout-margin.ts +193 -0
  113. package/lib/test-case-bodies.ts +883 -0
  114. package/lib/test-case-deletion.ts +653 -0
  115. package/lib/test-census.ts +97 -29
  116. package/lib/test-command-positions.ts +274 -0
  117. package/lib/test-command.ts +133 -0
  118. package/lib/test-suite-lock.ts +325 -26
  119. package/lib/tool-probe.ts +142 -0
  120. package/lib/top-level-cd.ts +393 -0
  121. package/lib/tracked-vs-ignored.ts +234 -0
  122. package/lib/tree-entries.ts +89 -0
  123. package/lib/ts-ast.ts +200 -0
  124. package/lib/validators/spec-validators.ts +3 -2
  125. package/lib/walk-test-files.ts +97 -0
  126. package/lib/workflow-actions.ts +263 -0
  127. package/lib/worktree-collect.ts +177 -5
  128. package/lib/worktree-repo.ts +36 -1
  129. package/package.json +2 -1
  130. package/scripts/ai-review-findings.ts +45 -0
  131. package/scripts/audit-specs.ts +247 -12
  132. package/scripts/audit-transcript.ts +2 -1
  133. package/scripts/convert-spec.ts +2 -1
  134. package/scripts/create-sc.ts +37 -7
  135. package/scripts/create-spec.ts +2 -1
  136. package/scripts/create-success.ts +2 -1
  137. package/scripts/extract-constraints.ts +197 -26
  138. package/scripts/generate-code-map.ts +62 -28
  139. package/scripts/scaffold-project.ts +12 -2
  140. package/scripts/split-spec.ts +2 -1
  141. package/scripts/sync-sc-status.ts +127 -14
  142. package/scripts/sync-spec-tests.ts +2 -1
@@ -52,6 +52,14 @@
52
52
  */
53
53
 
54
54
  import { createHash } from "crypto";
55
+ import { PROJECT_STATE_OWNERSHIP } from "../project-state-derivation";
56
+
57
+ import {
58
+ BRIEF_CONSTRAINTS_SECTION,
59
+ HARD_CONSTRAINTS_SECTION,
60
+ preserveSections,
61
+ type SectionSpec,
62
+ } from "../agents-md-sections";
55
63
 
56
64
  /** How the generator writes one owned file. */
57
65
  export type WriteStrategy =
@@ -61,6 +69,8 @@ export type WriteStrategy =
61
69
  | "provenance"
62
70
  /** The harness owns named jobs inside a file a consumer also writes to. */
63
71
  | "job-preserving"
72
+ /** The harness owns the file except for named sections, which carry forward (#568). */
73
+ | "section-preserving"
64
74
  /** Seeded once and never rewritten. Someone else owns the content. */
65
75
  | "create-only";
66
76
 
@@ -72,6 +82,32 @@ export interface OwnedFile {
72
82
  customize: string;
73
83
  /** The thing not to do. */
74
84
  avoid: string;
85
+ /**
86
+ * Which section carries forward. REQUIRED on a `section-preserving` row,
87
+ * and asserted as such by `test/scaffold-ownership.test.ts` — a row that
88
+ * declared the strategy and no section would silently merge against
89
+ * AGENTS.md's heading, which is *Silent Default Substitution* in the one
90
+ * place the declaration is supposed to be the whole answer.
91
+ */
92
+ sections?: SectionSpec;
93
+ /**
94
+ * The binding that implements this row's strategy, when it is NOT
95
+ * `decideOwnedWrite` (#759).
96
+ *
97
+ * `decideOwnedWrite` is the one decider for files written through
98
+ * `regenerateOwned`, and for a while the table read as though it were the
99
+ * one decider for EVERY owned file. It is not: `.claude/rules/*.md` go
100
+ * through `decideRuleWrite` because a markdown file has no `//` comments,
101
+ * and the two workflow rows go through `writeManagedFile` because YAML
102
+ * jobs merge rather than replace.
103
+ *
104
+ * A row that names no `servedBy` is claiming `decideOwnedWrite` handles
105
+ * it, and `test/owned-strategy-reachability.test.ts` refuses that claim
106
+ * when the function has no branch for the strategy. Unset is therefore a
107
+ * claim, not an absence — which is the direction this has to be wrong in,
108
+ * because the silent version is what #759 is about.
109
+ */
110
+ servedBy?: string;
75
111
  }
76
112
 
77
113
  /**
@@ -81,27 +117,62 @@ export interface OwnedFile {
81
117
  * code does not have — which is the whole of #208.
82
118
  */
83
119
  export const OWNED_FILES: OwnedFile[] = [
120
+ {
121
+ // Absent from this list until #568, which is how a run could delete 37
122
+ // lines of a consumer's Hard Constraints and report `REGENERATED`: the
123
+ // most-rewritten file in the tree was the one file with no declared
124
+ // strategy and no route through `decideOwnedWrite`.
125
+ path: "AGENTS.md",
126
+ strategy: "section-preserving",
127
+ customize: "Everything but `## Hard Constraints` is generated from the scan and `.claude/rungate/`; put non-inferable project rules in that section and they carry forward",
128
+ avoid: "Don't hand-edit the generated sections — a re-scaffold rewrites them without reporting it",
129
+ sections: HARD_CONSTRAINTS_SECTION,
130
+ },
84
131
  {
85
132
  path: ".github/workflows/ci.yml",
86
133
  strategy: "job-preserving",
134
+ servedBy: "writeManagedFile (lib/scaffold/steps.ts) via mergeManagedWorkflow — the harness owns named jobs, not the file",
87
135
  customize: "Set `ci` fields in `.claude/rungate/config.json`; add your own jobs alongside the generated `test` job",
88
136
  avoid: "Don't edit the generated `test` job",
89
137
  },
90
138
  {
91
139
  path: ".github/workflows/gates.yml",
92
140
  strategy: "job-preserving",
141
+ servedBy: "writeManagedFile (lib/scaffold/steps.ts) via mergeManagedWorkflow — the harness owns named jobs, not the file",
93
142
  customize: "Settings from `.claude/rungate/config.json`; add your own jobs alongside the generated `gates` job",
94
143
  avoid: "Don't edit the generated `gates` job",
95
144
  },
96
145
  {
146
+ // Absent from this list, and from the prose table, for the whole life of
147
+ // the file (#630 through #631). `createCiWorkflows` has written it since
148
+ // #630 — through the same `writeManagedFile` its two siblings above use
149
+ // — so a consumer's hand edit to the `ai-review` job was overwritten on
150
+ // every scaffold and reported as nothing, while the two files beside it
151
+ // reported the overwrite by name. The ownership did not travel with the
152
+ // bytes, which is #722's property met from the other side.
153
+ path: ".github/workflows/ai-review.yml",
154
+ strategy: "job-preserving",
155
+ servedBy: "writeManagedFile (lib/scaffold/steps.ts) via mergeManagedWorkflow — the harness owns named jobs, not the file",
156
+ customize: "Set `ci.vertex` in `.claude/rungate/config.json` to authenticate on Vertex with Workload Identity Federation; add your own jobs alongside the generated `ai-review` job",
157
+ avoid: "Don't edit the generated `ai-review` job",
158
+ },
159
+ {
160
+ // `regenerate` until #655, and the declaration was never consulted:
161
+ // `generateAgentBriefsStep` called `writeFileSync` directly, so the row
162
+ // described behaviour that a bare overwrite happened to coincide with.
163
+ // The cost was that a rule mined from a project's own compliance history
164
+ // had nowhere in that project to live — every brief surface was rebuilt
165
+ // from harness-wide templates on the next scaffold.
97
166
  path: ".claude/agents/*.md",
98
- strategy: "regenerate",
99
- customize: "Settings from `.claude/rungate/roles.json`",
100
- avoid: "Don't edit briefs",
167
+ strategy: "section-preserving",
168
+ customize: "Everything but `## Project Constraints` is generated from `.claude/rungate/roles.json` and the templates; put rules mined from this repo's own history in that section and they carry forward",
169
+ avoid: "Don't hand-edit the generated sections — a re-scaffold rewrites them without reporting it",
170
+ sections: BRIEF_CONSTRAINTS_SECTION,
101
171
  },
102
172
  {
103
173
  path: ".claude/rules/*.md",
104
174
  strategy: "provenance",
175
+ servedBy: "decideRuleWrite (lib/rule-provenance.ts) — a frontmatter `generated-sha:` key, because a markdown file has no line comments",
105
176
  customize: "Edit freely — a hand-edited rule is preserved and reported (#370)",
106
177
  avoid: "Don't expect edits to survive if you also delete the `generated-sha` marker",
107
178
  },
@@ -126,7 +197,10 @@ export const OWNED_FILES: OwnedFile[] = [
126
197
  {
127
198
  path: "PROJECT-STATE.md",
128
199
  strategy: "create-only",
129
- customize: "DA-owned (#296) — generated from project-state.json by the DA",
200
+ // #781: whether this project GENERATES the file is a reading, not a
201
+ // constant — see lib/project-state-derivation.ts. This table has no
202
+ // root to scan, so it states only the part that is true everywhere.
203
+ customize: `${PROJECT_STATE_OWNERSHIP} — maintained by the DA; whether this project derives it from the state JSON is reported per project in .claude/rules/key-files.md`,
130
204
  avoid: "Don't edit directly; don't expect re-scaffold to update it",
131
205
  },
132
206
  {
@@ -137,6 +211,24 @@ export const OWNED_FILES: OwnedFile[] = [
137
211
  },
138
212
  ];
139
213
 
214
+ /**
215
+ * The declared row for a label, or null.
216
+ *
217
+ * One matcher. `ownedStrategy` and `ownedSections` are two questions about
218
+ * one row, and a second copy of the glob rule would be a second answer to
219
+ * "which row is this" that nothing compares against the first.
220
+ */
221
+ export function ownedFileFor(label: string): OwnedFile | null {
222
+ for (const owned of OWNED_FILES) {
223
+ if (owned.path === label) return owned;
224
+ if (owned.path.includes("*")) {
225
+ const [prefix, suffix] = owned.path.split("*");
226
+ if (label.startsWith(prefix) && label.endsWith(suffix)) return owned;
227
+ }
228
+ }
229
+ return null;
230
+ }
231
+
140
232
  /**
141
233
  * The markdown table for `.claude/rules/harness-managed.md`, generated.
142
234
  *
@@ -177,38 +269,43 @@ export function bytesIdentical(existing: string | null, generated: string): bool
177
269
  }
178
270
 
179
271
  /**
180
- * The provenance marker for a file whose comment syntax is `//`.
272
+ * The provenance marker for one line-comment syntax.
181
273
  *
182
- * The frontmatter form in `lib/rule-provenance.ts` is the same idea and
183
- * cannot be reused verbatim: a TypeScript file has no `---` block. Both
184
- * stamp a digest of the body the generator wrote, so the next run can ask
185
- * "has anyone touched this since?" with nothing that can desync from the
186
- * tree it describes.
274
+ * A factory rather than a second copy, because `.github/workflows/*.yml`
275
+ * needs the same marker with `#` and the digest logic is the part that must
276
+ * not fork (#722). Two independent implementations of "has anyone touched
277
+ * this since" are two deciders answering one question, and a mutation of
278
+ * either leaves the other holding the case up
279
+ * (`.claude/rules/checks-must-be-able-to-fail.md`, fourth shape).
187
280
  */
188
- const MARKER = /^\/\/ generated-sha: ([0-9a-f]{16})\n/;
189
-
190
- export function commentBody(text: string): string {
191
- return text.replace(MARKER, "");
281
+ export function lineCommentProvenance(prefix: string) {
282
+ const marker = new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\\/]/g, "\\$&")} generated-sha: ([0-9a-f]{16})\\n`);
283
+ const body = (text: string): string => text.replace(marker, "");
284
+ const sha = (text: string): string =>
285
+ createHash("sha256").update(body(text)).digest("hex").slice(0, 16);
286
+ return {
287
+ body,
288
+ sha,
289
+ declared: (text: string): string | null => {
290
+ const m = marker.exec(text);
291
+ return m ? m[1] : null;
292
+ },
293
+ /** Idempotent: stamping an already-stamped document re-stamps the body. */
294
+ stamp: (generated: string): string => {
295
+ const b = body(generated);
296
+ return `${prefix} generated-sha: ${sha(b)}\n${b}`;
297
+ },
298
+ };
192
299
  }
193
300
 
194
- export function commentSha(text: string): string {
195
- return createHash("sha256").update(commentBody(text)).digest("hex").slice(0, 16);
196
- }
197
301
 
198
- export function declaredCommentSha(text: string): string | null {
199
- const m = MARKER.exec(text);
200
- return m ? m[1] : null;
201
- }
202
302
 
203
- export function stampComment(generated: string): string {
204
- const body = commentBody(generated);
205
- return `// generated-sha: ${commentSha(body)}\n${body}`;
206
- }
303
+
207
304
 
208
305
  export interface WriteDecision {
209
- action: "create" | "unchanged" | "changed" | "preserve";
306
+ action: "create" | "unchanged" | "changed" | "preserve" | "refuse";
210
307
  reason: string;
211
- /** The bytes to write. Absent for `unchanged` and `preserve`. */
308
+ /** The bytes to write. Absent for `unchanged`, `preserve` and `refuse`. */
212
309
  content?: string;
213
310
  }
214
311
 
@@ -232,16 +329,54 @@ export interface WriteDecision {
232
329
  * never reports a hand-edit, because there is no edit to report — the
233
330
  * content was never the harness's.
234
331
  */
332
+ /**
333
+ * The strategies `decideOwnedWrite` actually has a branch for.
334
+ *
335
+ * Declared once and asserted against the branches by
336
+ * `test/owned-strategy-reachability.test.ts`, so a strategy cannot be added
337
+ * to the union, declared on a row, and left with no code behind it.
338
+ */
339
+ export const DECIDED_HERE: readonly WriteStrategy[] = [
340
+ "regenerate",
341
+ "create-only",
342
+ "section-preserving",
343
+ ];
344
+
235
345
  export function decideOwnedWrite(
236
346
  strategy: WriteStrategy,
237
347
  existing: string | null,
238
348
  generated: string,
349
+ sections: SectionSpec = HARD_CONSTRAINTS_SECTION,
239
350
  ): WriteDecision {
351
+ // Refuse a strategy this function does not implement, BEFORE anything
352
+ // else looks at the file (#759).
353
+ //
354
+ // `job-preserving` and `provenance` are served elsewhere — `servedBy` on
355
+ // their rows says where — and neither has a branch below. Until this
356
+ // throw they fell through to the regenerate tail, so a caller that let
357
+ // `ownedStrategy()` supply the default for `.github/workflows/ci.yml`
358
+ // would have replaced a consumer's whole file, every job in it, and
359
+ // reported `CHANGED: regenerated output differs`. Nothing does that
360
+ // today; `regenerateOwned` defaults to exactly that expression, so it is
361
+ // one forgotten argument away.
362
+ //
363
+ // A dead branch and a silently wrong one look identical in a green suite.
364
+ // This is the loud version.
365
+ if (!DECIDED_HERE.includes(strategy)) {
366
+ const row = OWNED_FILES.find(f => f.strategy === strategy);
367
+ throw new Error(
368
+ `decideOwnedWrite does not implement the '${strategy}' strategy. ` +
369
+ (row?.servedBy
370
+ ? `It is served by ${row.servedBy}. Route this write there, or pass a strategy this function implements.`
371
+ : `No OWNED_FILES row says what serves it, which means nothing does.`),
372
+ );
373
+ }
374
+
240
375
  if (existing === null) {
241
376
  return {
242
377
  action: "create",
243
378
  reason: "no such file",
244
- content: strategy === "provenance" ? stampComment(generated) : generated,
379
+ content: generated,
245
380
  };
246
381
  }
247
382
 
@@ -249,19 +384,31 @@ export function decideOwnedWrite(
249
384
  return { action: "unchanged", reason: "seeded once; its content is not the harness's" };
250
385
  }
251
386
 
252
- if (strategy === "provenance") {
253
- const stamped = stampComment(generated);
254
- if (bytesIdentical(existing, stamped)) {
255
- return { action: "unchanged", reason: "identical to generator output" };
387
+ if (strategy === "section-preserving") {
388
+ // The merge is in `lib/agents-md-sections.ts`; what belongs HERE is the
389
+ // decision, so a strategy cannot be implemented at a call site and left
390
+ // out of the one binding every owned file routes through.
391
+ const merged = preserveSections(existing, generated, sections);
392
+ if (merged.lost.length > 0) {
393
+ return {
394
+ action: "refuse",
395
+ reason:
396
+ `${merged.lost.length} line(s) of user-owned content would be lost from ` +
397
+ `${sections.label}, and the spec guarantees they survive regeneration: ` +
398
+ merged.lost.join(" | "),
399
+ };
256
400
  }
257
- const declared = declaredCommentSha(existing);
258
- if (declared === null) {
259
- return { action: "preserve", reason: "hand-authored — no harness provenance marker" };
401
+ if (bytesIdentical(existing, merged.content)) {
402
+ return { action: "unchanged", reason: "regenerated output is byte-identical" };
260
403
  }
261
- if (declared !== commentSha(existing)) {
262
- return { action: "preserve", reason: "hand-edited since the harness wrote it" };
263
- }
264
- return { action: "changed", reason: "harness-written and untouched since", content: stamped };
404
+ return {
405
+ action: "changed",
406
+ reason:
407
+ merged.preserved === null
408
+ ? "regenerated output differs"
409
+ : `regenerated output differs; ${merged.preserved.lines.length} line(s) of user-owned content carried forward`,
410
+ content: merged.content,
411
+ };
265
412
  }
266
413
 
267
414
  if (bytesIdentical(existing, generated)) {
@@ -30,6 +30,22 @@
30
30
  * message is wrong either way — a developer reading "conformity failed" goes
31
31
  * and looks at conformity, which is green.
32
32
  *
33
+ * ## What was wrong the second time (#728)
34
+ *
35
+ * It asked `--show-toplevel` where the dependencies are. That answers "where
36
+ * is this working tree", and in a LINKED worktree that is not where
37
+ * `node_modules` lives — it is gitignored, so it exists only in the main
38
+ * checkout. `ln -s` does not look at its target, so the link succeeded, the
39
+ * suite could not resolve its imports, and every worktree push was refused as
40
+ * UNMEASURED. The refusal was right and is unchanged; what it could not say
41
+ * is that the cause was the worktree, so three agent sessions in agentgrit
42
+ * reached for `--no-verify` instead.
43
+ *
44
+ * The same wrong root made the lockfile arm vacuous — it compared the pushed
45
+ * commit's lockfile with its own copy in the temp checkout. `MODULES_ROOT`
46
+ * answers the right question, and `link_modules` refuses by name rather than
47
+ * leaving a dangling link.
48
+ *
33
49
  * ## The three outcomes, and why UNMEASURED blocks
34
50
  *
35
51
  * | what happened | exit | message |
@@ -69,10 +85,31 @@ ${PRE_PUSH_MANAGED_MARKER}
69
85
  REFUSE=${PRE_PUSH_REFUSE_EXIT}
70
86
  ZERO=0000000000000000000000000000000000000000
71
87
  TOPLEVEL=$(git rev-parse --show-toplevel) || exit $REFUSE
88
+ # Where this repository's installed dependencies are, which is NOT "where is
89
+ # this working tree" (#728). node_modules is gitignored, so a LINKED worktree
90
+ # has none and never will. --git-common-dir answers the main checkout's .git
91
+ # from any worktree and plain .git in the main checkout itself, so the
92
+ # non-worktree case is unchanged.
93
+ MODULES_ROOT=$(cd "$TOPLEVEL" && cd "$(git rev-parse --git-common-dir)/.." && pwd) || exit $REFUSE
72
94
  conformity=0
73
95
  unmeasured=0
74
96
  why=""
75
97
 
98
+ # Link the main checkout's modules into the temp checkout, or say why not.
99
+ #
100
+ # 'ln -s' does not look at its target: a link to a path that does not exist
101
+ # succeeds, and the suite then dies on an import error that names no cause.
102
+ # That is what a worktree push did before #728 — "the conformity suite did not
103
+ # load" over a repository whose dependencies were installed the whole time.
104
+ link_modules() {
105
+ if [ ! -d "$MODULES_ROOT/node_modules" ]; then
106
+ unmeasured=1
107
+ why="no node_modules at $MODULES_ROOT/node_modules — run bun install there"
108
+ return 0
109
+ fi
110
+ ln -s "$MODULES_ROOT/node_modules" "$1/node_modules" 2>/dev/null
111
+ }
112
+
76
113
  while read -r _lref lsha _rref _rsha; do
77
114
  # Branch deletion: there is no commit to check out.
78
115
  [ "$lsha" = "$ZERO" ] && continue
@@ -91,13 +128,20 @@ while read -r _lref lsha _rref _rsha; do
91
128
  # checkout has no lockfile" as "the dependencies differ" and installs. But a
92
129
  # lockfile absent from the checkout is a lockfile git does not track — it is
93
130
  # gitignored, or the project has none — and then there is nothing in this
94
- # push that can change the dependency graph. The working tree's modules are
95
- # the right ones by definition, and installing is both slower and less
131
+ # push that can change the dependency graph. The main checkout's modules
132
+ # are the right ones by definition, and installing is both slower and less
96
133
  # accurate.
134
+ #
135
+ # The lockfile read here is the one beside the modules being linked, for
136
+ # the same reason (#728). Rooted at the working tree, a worktree push
137
+ # compared the PUSHED commit's lockfile against its own copy in the temp
138
+ # checkout — equal whenever you push what you committed, so the arm that
139
+ # exists to check the installed modules match the pushed ones never looked
140
+ # at the installed modules at all.
97
141
  if [ ! -f "$tmp/bun.lock" ]; then
98
- ln -s "$TOPLEVEL/node_modules" "$tmp/node_modules" 2>/dev/null
99
- elif [ -f "$TOPLEVEL/bun.lock" ] && cmp -s "$TOPLEVEL/bun.lock" "$tmp/bun.lock"; then
100
- ln -s "$TOPLEVEL/node_modules" "$tmp/node_modules" 2>/dev/null
142
+ link_modules "$tmp"
143
+ elif [ -f "$MODULES_ROOT/bun.lock" ] && cmp -s "$MODULES_ROOT/bun.lock" "$tmp/bun.lock"; then
144
+ link_modules "$tmp"
101
145
  else
102
146
  echo "pre-push: dependencies differ from the working tree — installing from the pushed lockfile" >&2
103
147
  if ! ( cd "$tmp" && bun install --frozen-lockfile ) >&2; then