@feigi/fleet-ctl 3.23.35 → 3.23.37

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 (204) hide show
  1. package/package.json +1 -1
  2. package/scripts/main-checkout.mjs +1 -1
  3. package/scripts/member-write-guard.mjs +1 -1
  4. package/scripts/repo-root.mjs +1 -1
  5. package/skills/run-team/references/reaping.md +1 -1
  6. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  7. package/scripts/agent-test.test.mjs +0 -1640
  8. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  9. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  10. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  11. package/scripts/apply-ruleset.test.mjs +0 -421
  12. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  13. package/scripts/arg.test.mjs +0 -1354
  14. package/scripts/board-cli.test.mjs +0 -710
  15. package/scripts/board-identity.test.mjs +0 -429
  16. package/scripts/board-liveness-banner.test.mjs +0 -119
  17. package/scripts/board-prev-shape.test.mjs +0 -228
  18. package/scripts/board-tryparse-null.test.mjs +0 -119
  19. package/scripts/board.test.mjs +0 -3121
  20. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  21. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  22. package/scripts/candidates.test.mjs +0 -2312
  23. package/scripts/caveat-unification-prose.test.mjs +0 -98
  24. package/scripts/cell-readout.test.mjs +0 -615
  25. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  26. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  27. package/scripts/ci-state-prose.test.mjs +0 -113
  28. package/scripts/ci-state.test.mjs +0 -1933
  29. package/scripts/ci-vacuous-green.test.mjs +0 -368
  30. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  31. package/scripts/claim-lifecycle.test.mjs +0 -187
  32. package/scripts/claim-ticket.test.mjs +0 -1122
  33. package/scripts/closing-keyword-prose.test.mjs +0 -193
  34. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  35. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  36. package/scripts/compute-board.test.mjs +0 -1214
  37. package/scripts/compute-spend.test.mjs +0 -517
  38. package/scripts/consumer-technology-prose.test.mjs +0 -126
  39. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  40. package/scripts/cwd-isolation-pins.mjs +0 -83
  41. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  42. package/scripts/delete-merged-branch.test.mjs +0 -576
  43. package/scripts/derive-testcmd.test.mjs +0 -595
  44. package/scripts/diff-stats.test.mjs +0 -404
  45. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  46. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  47. package/scripts/dispositions-check.test.mjs +0 -936
  48. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  49. package/scripts/drop-merged-label.test.mjs +0 -479
  50. package/scripts/exec-stub.mjs +0 -93
  51. package/scripts/exec-stub.test.mjs +0 -69
  52. package/scripts/expected-jobs-prose.test.mjs +0 -80
  53. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  54. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  55. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  56. package/scripts/finisher-died-prose.test.mjs +0 -31
  57. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  58. package/scripts/finisher-halt-prose.test.mjs +0 -106
  59. package/scripts/finisher-name-prose.test.mjs +0 -134
  60. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  61. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  62. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  63. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  64. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  65. package/scripts/fleet-bootstrap.test.mjs +0 -75
  66. package/scripts/fleet-heartbeat.test.mjs +0 -450
  67. package/scripts/fleet-provenance.test.mjs +0 -138
  68. package/scripts/fleet-run.test.mjs +0 -90
  69. package/scripts/fleet-state.test.mjs +0 -460
  70. package/scripts/fleet-tick-prose.test.mjs +0 -300
  71. package/scripts/fleet-tick.test.mjs +0 -2444
  72. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  73. package/scripts/frontmatter-check.test.mjs +0 -436
  74. package/scripts/git-env.test.mjs +0 -149
  75. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  76. package/scripts/gone-walk.test.mjs +0 -213
  77. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  78. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  79. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  80. package/scripts/implementer-model-tier.test.mjs +0 -235
  81. package/scripts/inflight-citation-prose.test.mjs +0 -144
  82. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  83. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  84. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  85. package/scripts/inflight.test.mjs +0 -2882
  86. package/scripts/injection-control-prose.test.mjs +0 -404
  87. package/scripts/install-root-audit.test.mjs +0 -464
  88. package/scripts/instrument-check-prose.test.mjs +0 -235
  89. package/scripts/instruments.test.mjs +0 -787
  90. package/scripts/is-cli.test.mjs +0 -99
  91. package/scripts/issue-tracker-prose.test.mjs +0 -71
  92. package/scripts/json.test.mjs +0 -364
  93. package/scripts/ledger-dispatch.test.mjs +0 -927
  94. package/scripts/ledger-grammar.test.mjs +0 -227
  95. package/scripts/ledger-read-require-file.test.mjs +0 -197
  96. package/scripts/ledger-rotate.test.mjs +0 -142
  97. package/scripts/ledger.test.mjs +0 -3436
  98. package/scripts/line-distance-prose.test.mjs +0 -245
  99. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  100. package/scripts/locale-pin-prose.test.mjs +0 -189
  101. package/scripts/main-checkout.test.mjs +0 -332
  102. package/scripts/member-outcome-prose.test.mjs +0 -167
  103. package/scripts/member-outcomes-header.test.mjs +0 -129
  104. package/scripts/member-outcomes-prose.test.mjs +0 -63
  105. package/scripts/member-outcomes.test.mjs +0 -638
  106. package/scripts/member-prompt-prose.test.mjs +0 -165
  107. package/scripts/member-record.test.mjs +0 -541
  108. package/scripts/member-write-guard.test.mjs +0 -214
  109. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  110. package/scripts/merge-gate.test.mjs +0 -613
  111. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  112. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  113. package/scripts/net-watchdog-prose.test.mjs +0 -79
  114. package/scripts/net.test.mjs +0 -211
  115. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  116. package/scripts/no-undo-audit.test.mjs +0 -3961
  117. package/scripts/no-wave.test.mjs +0 -138
  118. package/scripts/node-floor-sweep.test.mjs +0 -611
  119. package/scripts/pointer-target-prose.test.mjs +0 -186
  120. package/scripts/pr-cost.test.mjs +0 -521
  121. package/scripts/pr-overlap.test.mjs +0 -692
  122. package/scripts/printf-die-sweep.test.mjs +0 -384
  123. package/scripts/prompt-renderer.mjs +0 -40
  124. package/scripts/prompt-renderer.test.mjs +0 -68
  125. package/scripts/prose-pin.mjs +0 -807
  126. package/scripts/prose-pin.test.mjs +0 -1034
  127. package/scripts/prove-merge.test.mjs +0 -995
  128. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  129. package/scripts/quiet-payload-prose.test.mjs +0 -222
  130. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  131. package/scripts/reap.test.mjs +0 -4432
  132. package/scripts/reaping-prose.test.mjs +0 -239
  133. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  134. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  135. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  136. package/scripts/recipe-prove.test.mjs +0 -1042
  137. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  138. package/scripts/release-label-required-prose.test.mjs +0 -71
  139. package/scripts/release-label-split-prose.test.mjs +0 -184
  140. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  141. package/scripts/release-ticket.test.mjs +0 -5099
  142. package/scripts/renovate-release-contract.test.mjs +0 -379
  143. package/scripts/repo-root.test.mjs +0 -873
  144. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  145. package/scripts/review-agent-report-only.test.mjs +0 -49
  146. package/scripts/review-core-booking.test.mjs +0 -35
  147. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  148. package/scripts/review-core-reads.test.mjs +0 -478
  149. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  150. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  151. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  152. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  153. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  154. package/scripts/review-core-testcmd.test.mjs +0 -335
  155. package/scripts/review-core-unrun.test.mjs +0 -566
  156. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  157. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  158. package/scripts/review-host-fixture.mjs +0 -89
  159. package/scripts/review-in-run-retry.test.mjs +0 -211
  160. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  161. package/scripts/review-path-default.test.mjs +0 -796
  162. package/scripts/review-runner-spawns.test.mjs +0 -95
  163. package/scripts/review-runner.test.mjs +0 -166
  164. package/scripts/review-tier-audit.test.mjs +0 -140
  165. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  166. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  167. package/scripts/run-team-local-hook.test.mjs +0 -442
  168. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  169. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  170. package/scripts/section-between-guard-prose.test.mjs +0 -379
  171. package/scripts/select-dimensions.test.mjs +0 -674
  172. package/scripts/shared-refusal.test.mjs +0 -388
  173. package/scripts/shell-traps-prose.test.mjs +0 -504
  174. package/scripts/shortlist.test.mjs +0 -380
  175. package/scripts/slow-transport.mjs +0 -72
  176. package/scripts/snapshot-repo.test.mjs +0 -1006
  177. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  178. package/scripts/spend-view.test.mjs +0 -312
  179. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  180. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  181. package/scripts/staleness.test.mjs +0 -893
  182. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  183. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  184. package/scripts/strip-comments.mjs +0 -44
  185. package/scripts/temp-dir.mjs +0 -47
  186. package/scripts/ticket-router.test.mjs +0 -981
  187. package/scripts/tier-check.test.mjs +0 -828
  188. package/scripts/tier-outcomes-header.test.mjs +0 -518
  189. package/scripts/tier-outcomes.test.mjs +0 -572
  190. package/scripts/tier-roles.test.mjs +0 -535
  191. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  192. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  193. package/scripts/unattended-git-sweep.test.mjs +0 -142
  194. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  195. package/scripts/verify-sha.test.mjs +0 -692
  196. package/scripts/watcher-degraded-block.test.mjs +0 -369
  197. package/scripts/watcher-key-prose.test.mjs +0 -106
  198. package/scripts/within-run-pair-prose.test.mjs +0 -212
  199. package/scripts/worktree-audit.test.mjs +0 -1408
  200. package/scripts/worktree-head-prose.test.mjs +0 -276
  201. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  202. package/scripts/worktree-model-prose.test.mjs +0 -216
  203. package/scripts/worktree-porcelain.mjs +0 -35
  204. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,404 +0,0 @@
1
- // Regression gate for the diff-sizing classifier and profile ladder that scale a
2
- // review's fan-out. Zero deps: `node --test plugin/scripts/diff-stats.test.mjs`.
3
- // Locks the load-bearing behaviours a "simplification" could silently break —
4
- // especially that code under docs/ or .github/ keeps `src`, and that a mixed
5
- // docs+src PR is NOT docsOnly (so it keeps the fuller review).
6
-
7
- import { test } from "node:test";
8
- import assert from "node:assert/strict";
9
- import { readFileSync, mkdtempSync, writeFileSync, rmSync } from "node:fs";
10
- import { tmpdir } from "node:os";
11
- import { join } from "node:path";
12
- import { spawnSync } from "node:child_process";
13
- import { classify, computeStats } from "./diff-stats.mjs";
14
- import { writeExecStub } from "./exec-stub.mjs";
15
-
16
- // `main()` runs only when this file is executed directly, so the CLI wiring is
17
- // unreachable from a unit test. Pinned as source text instead — see the
18
- // truncation test at the bottom for why it needs pinning at all.
19
- const SCRIPT = join(import.meta.dirname, "diff-stats.mjs");
20
- const CLI = readFileSync(SCRIPT, "utf8");
21
-
22
- test("classifier priority: test > code-ext > docs/config-dir", () => {
23
- // src is the residue
24
- assert.equal(classify("src/a.ts"), "src");
25
- assert.equal(classify("scripts/review-core.mjs"), "src");
26
- // test wins even though a .test.ts is also a .ts
27
- assert.equal(classify("a.test.ts"), "test");
28
- assert.equal(classify("pkg/__tests__/a.ts"), "test");
29
- // prose
30
- assert.equal(classify("README.md"), "docs");
31
- assert.equal(classify("docs/guide.md"), "docs");
32
- // config by extension / location / naming convention
33
- assert.equal(classify(".github/workflows/ci.yml"), "config");
34
- assert.equal(classify("package.json"), "config");
35
- assert.equal(classify("vite.config.ts"), "config");
36
- assert.equal(classify(".eslintrc"), "config");
37
- // M1: a code file stays `src` even under docs/ or .github/, so the src-gated
38
- // dimensions (types, silent-failure, simplify) are not silently dropped on it.
39
- assert.equal(classify("docs/examples/deploy.ts"), "src");
40
- assert.equal(classify(".github/scripts/action.mjs"), "src");
41
- assert.equal(classify("packages/x/docs/gen.mjs"), "src");
42
- });
43
-
44
- test("computeStats: profile ladder", () => {
45
- assert.equal(computeStats([]).profile, "empty");
46
- assert.equal(computeStats([{ path: "a.md", additions: 3, deletions: 1 }]).profile, "docs");
47
- assert.equal(computeStats([{ path: "a.test.ts", additions: 5, deletions: 0 }]).profile, "tests-only");
48
- assert.equal(computeStats([{ path: "a.ts", additions: 1, deletions: 0 }]).profile, "single-file");
49
- assert.equal(
50
- computeStats([
51
- { path: "a.ts", additions: 2, deletions: 0 },
52
- { path: "b.ts", additions: 2, deletions: 0 },
53
- ]).profile,
54
- "small",
55
- );
56
- assert.equal(
57
- computeStats([
58
- { path: "a.ts", additions: 20, deletions: 0 },
59
- { path: "b.ts", additions: 20, deletions: 0 },
60
- ]).profile,
61
- "production",
62
- );
63
- });
64
-
65
- test("computeStats: docsOnly is strict — docs+src keeps the fuller review", () => {
66
- const docs = computeStats([{ path: "a.md", additions: 3, deletions: 1 }]);
67
- assert.equal(docs.docsOnly, true);
68
- assert.equal(docs.hasSrc, false);
69
- assert.equal(docs.loc, 4);
70
-
71
- const mixed = computeStats([
72
- { path: "a.md", additions: 2, deletions: 0 },
73
- { path: "b.ts", additions: 2, deletions: 0 },
74
- ]);
75
- assert.equal(mixed.docsOnly, false, "docs+src must not be docsOnly");
76
- assert.equal(mixed.hasSrc, true);
77
-
78
- // docs + a CI workflow is also not docsOnly (config present)
79
- const docsPlusCi = computeStats([
80
- { path: "a.md", additions: 2, deletions: 0 },
81
- { path: ".github/workflows/ci.yml", additions: 1, deletions: 0 },
82
- ]);
83
- assert.equal(docsPlusCi.docsOnly, false);
84
- assert.equal(docsPlusCi.hasConfig, true);
85
- });
86
-
87
- test("computeStats: the four routing booleans are pinned together on a production PR", () => {
88
- // review-core.mjs selectDimensions routes on exactly hasSrc/hasTests/hasConfig/
89
- // docsOnly. Assert all four at once so any single one flipping is caught here,
90
- // not only transitively via the profile-ladder test.
91
- const prod = computeStats([
92
- { path: "src/a.ts", additions: 5, deletions: 0 },
93
- { path: "a.test.ts", additions: 5, deletions: 0 },
94
- { path: "package.json", additions: 1, deletions: 0 },
95
- ]);
96
- assert.deepEqual(
97
- { hasSrc: prod.hasSrc, hasTests: prod.hasTests, hasConfig: prod.hasConfig, docsOnly: prod.docsOnly },
98
- { hasSrc: true, hasTests: true, hasConfig: true, docsOnly: false },
99
- );
100
- });
101
-
102
- test("classify: extensionless files fall to src (fail-open residue)", () => {
103
- // The residue default keeps the src-gated dimensions (types/silent-failure/
104
- // simplify) running on unknown files — the safe direction. Pin it so a future
105
- // "tidy the residue" edit can't silently reroute unknowns to docs/config.
106
- assert.equal(classify("Dockerfile"), "src");
107
- assert.equal(classify("Makefile"), "src");
108
- assert.equal(classify("bin/deploy"), "src");
109
- assert.equal(classify("foo.config.mjs"), "config"); // config-by-name still wins
110
- });
111
-
112
- test("computeStats: loc tolerates a file missing additions/deletions", () => {
113
- assert.equal(computeStats([{ path: "a.ts" }]).loc, 0);
114
- assert.equal(computeStats([{ path: "a.ts", additions: 3 }]).loc, 3);
115
- });
116
-
117
- // `gh pr view --json files` pages at 100 and exits 0, so a 124-file PR arrives
118
- // as a fully-formed 100-file measurement with nothing contradicting it —
119
- // measured on microsoft/vscode#329568. `changedFiles` from the same query is the
120
- // only disagreement available. Absent on every normal PR: `review-core.mjs` reads
121
- // its PRESENCE as "widen the fan-out, this list is short", so a flag set when
122
- // the counts agree would widen every review.
123
- test("computeStats: truncated is set only when gh's file list is short", () => {
124
- const files = Array.from({ length: 100 }, (_, i) => ({ path: `src/f${i}.ts`, additions: 1 }));
125
- assert.equal(computeStats(files, 124).truncated, 124);
126
- assert.equal(computeStats(files, 100).truncated, undefined, "counts agree — a complete list is not truncated");
127
- assert.equal(computeStats(files).truncated, undefined, "gh omitted changedFiles — no cap can be inferred");
128
- // A short list under-reports `files` too, so nothing else in the blob can
129
- // stand in for the flag.
130
- assert.equal(computeStats(files, 124).files, 100);
131
- });
132
-
133
- // `truncated` is computed from an argument, and nothing above proves the CLI
134
- // ever passes one. Both tokens are needed and each disconnects the whole cap
135
- // detection alone: drop `changedFiles` from the query and `info.changedFiles` is
136
- // undefined, drop the second argument and the value never reaches computeStats.
137
- // Either way every PR reports as complete, `review-core.mjs` keeps stamping its
138
- // file list "and no others", and the tests above stay green against a copy
139
- // nothing calls.
140
- test("the CLI actually asks gh for changedFiles and passes it through", () => {
141
- assert.match(
142
- CLI,
143
- /"pr", "view", String\(pr\), "--json", "files,changedFiles"/,
144
- "the gh query no longer requests changedFiles — nothing can reveal the 100-file cap",
145
- );
146
- assert.match(
147
- CLI,
148
- /computeStats\(info\.files, info\.changedFiles\)/,
149
- "the CLI computes stats without the uncapped count — `truncated` is never set in production",
150
- );
151
- });
152
-
153
- // #169: `--pr` given with no value was already caught by `if (!pr) die(...)`
154
- // below — `undefined` is falsy — so this was never a silent-widening site.
155
- // Pin that it now refuses explicitly, by name, instead of falling through to
156
- // the generic usage message; and that `--pr=5` (invisible to `indexOf`) is
157
- // rejected the same way rather than reading as absent.
158
- test("CLI: trailing --pr (no value) dies (exit 2) naming the flag", () => {
159
- const r = spawnSync(process.execPath, [SCRIPT, "--pr"], { encoding: "utf8" });
160
- assert.equal(r.status, 2);
161
- assert.match(r.stderr, /--pr needs a value/);
162
- });
163
-
164
- test("CLI: --pr=5 form dies by name, not silently read as absent", () => {
165
- const r = spawnSync(process.execPath, [SCRIPT, "--pr=5"], { encoding: "utf8" });
166
- assert.equal(r.status, 2);
167
- assert.match(r.stderr, /--pr needs a space-separated value/);
168
- });
169
-
170
- // The other two branches of the same guard. `--pr` is this script's only flag,
171
- // so the next-flag case needs an unknown one to collide with — the guard is on
172
- // the value's shape, not on the following flag being real.
173
- test("CLI: --pr followed by another flag is rejected, not consumed as the PR ref", () => {
174
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "--json"], { encoding: "utf8" });
175
- assert.equal(r.status, 2);
176
- assert.match(r.stderr, /--pr needs a value/);
177
- });
178
-
179
- test("CLI: --pr given an empty value dies naming the flag", () => {
180
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", ""], { encoding: "utf8" });
181
- assert.equal(r.status, 2);
182
- assert.match(r.stderr, /--pr needs a value/);
183
- });
184
-
185
- // The other half of arg()'s guard: every case above is a value it must
186
- // REFUSE. Nothing above ever hands main() a well-formed value, so #367's
187
- // shared arg() could return `undefined` for every accepted input and this
188
- // file would stay green. `--pr 5` must reach gh and succeed.
189
- // The fail-closed guard this file never exercised: `gh pr view --json
190
- // files,changedFiles` can exit 0 with a body holding no `files` key at all
191
- // (an unexpected `gh` output shape, or a proxy's JSON error envelope). Before
192
- // this guard, `info.files` read as `undefined` and computeStats([]) silently
193
- // reported `profile: "empty"` — exit 0, indistinguishable from a real empty
194
- // PR, review-core.mjs WIDENS that to the full specialist set on the strength of
195
- // a lie. The guard must refuse instead.
196
- test("CLI: gh returning no files array dies (exit 2) rather than reporting a fabricated empty PR", () => {
197
- const bin = mkdtempSync(join(tmpdir(), "diff-stats-bin-"));
198
- const gh = join(bin, "gh");
199
- writeExecStub(gh, '#!/bin/sh\necho \'{"changedFiles":1}\'\n');
200
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "5"], {
201
- encoding: "utf8",
202
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
203
- });
204
- rmSync(bin, { recursive: true, force: true });
205
- assert.equal(r.status, 2, `a missing files array must refuse, not report an empty PR; got ${r.status} ${r.stdout}${r.stderr}`);
206
- assert.equal(r.stdout.trim(), "", "exit 2 emits no payload — a payload here would be the fabricated measurement this guard exists to prevent");
207
- assert.match(r.stderr, /gh returned no files array/);
208
- });
209
-
210
- // The one case the guard above still missed: `JSON.parse("null")` succeeds
211
- // and returns `null`, not an object — so `info.files` threw a TypeError
212
- // before `!Array.isArray(info.files)` ever ran, crashing at exit 1 with a raw
213
- // stack trace instead of refusing at the named exit 2 this file's own
214
- // comment says the guard exists to produce (#1307). The message is worded
215
- // "no body" rather than reusing "no files array", so a reader chasing a
216
- // missing key is not sent looking for a key that was never the problem —
217
- // nothing came back at all.
218
- test("CLI: gh returning a null body dies (exit 2) naming the missing body, not a TypeError", () => {
219
- const bin = mkdtempSync(join(tmpdir(), "diff-stats-bin-"));
220
- const gh = join(bin, "gh");
221
- writeExecStub(gh, "#!/bin/sh\necho null\n");
222
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "5"], {
223
- encoding: "utf8",
224
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
225
- });
226
- rmSync(bin, { recursive: true, force: true });
227
- assert.equal(r.status, 2, `a null body must refuse, not crash; got ${r.status} ${r.stdout}${r.stderr}`);
228
- assert.equal(r.stdout.trim(), "", "exit 2 emits no payload");
229
- assert.match(r.stderr, /gh returned no body/);
230
- assert.doesNotMatch(r.stderr, /TypeError/, "a null body must not reach the raw TypeError this guard exists to prevent");
231
- });
232
-
233
- test("CLI: a well-formed --pr value is accepted and the CLI succeeds", () => {
234
- const bin = mkdtempSync(join(tmpdir(), "diff-stats-bin-"));
235
- const gh = join(bin, "gh");
236
- writeExecStub(gh, '#!/bin/sh\necho \'{"files":[{"path":"a.ts","additions":1,"deletions":0}],"changedFiles":1}\'\n');
237
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "5"], {
238
- encoding: "utf8",
239
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
240
- });
241
- rmSync(bin, { recursive: true, force: true });
242
- assert.equal(r.status, 0, r.stdout + r.stderr);
243
- const payload = JSON.parse(r.stdout);
244
- assert.equal(payload.pr, 5);
245
- assert.equal(payload.profile, "single-file");
246
- });
247
-
248
- // #932: the non-JSON die above quoted `raw.trim().slice(0, 120)` with NO
249
- // marker, so a 269 KB portal page and a 90-character one rendered identically —
250
- // a reader could not tell gh's whole output from this script's clip of it. The
251
- // length quoted is gh's, not this script's, which is the lie the marker closes.
252
- // Nothing in this file reached that path at all before these four tests: the
253
- // guards above cover a missing `files` key and a `null` body, both of which
254
- // PARSE. A suite that never enters the mode cannot see the defect in it.
255
- //
256
- // DIRECTION, measured here rather than inherited (#638/PR #931 fixed the same
257
- // unmarked clip in ledger.mjs by keeping the TAIL, and copying that here would
258
- // keep the noise and discard the cause):
259
- // - `run()` passes no `stdio`, so execFileSync forwards the child's stderr to
260
- // this process's stderr and returns stdout ALONE. `raw` is gh's stdout, not
261
- // its stderr — the stream-check below pins exactly that, and it is the whole
262
- // of why ledger.mjs's tail rationale (a FATAL line behind seven warnings)
263
- // does not transfer.
264
- // - Real gh 2.100.0 never puts non-JSON on stdout: a missing PR, bad
265
- // credentials and an intercepting proxy all report on stderr at exit 1,
266
- // which `run()`'s catch takes, and stdout stays empty. Forcing a TTY, a
267
- // pager and `GH_DEBUG=api` each left stdout pure JSON. A payload past
268
- // execFileSync's 1 MiB maxBuffer throws ENOBUFS rather than returning a
269
- // mid-JSON cut, so the one shape whose cause would sit at the tail cannot
270
- // reach `raw` either.
271
- // - So this path is only ever reached when something OTHER than gh owns that
272
- // stdout — a wrapper, shim or portal interposed on it — and such a producer
273
- // leads with its own message. Measured on real bytes: github.com's 404 body
274
- // ends `</div>\n </body>\n</html>`, boilerplate every HTML page on earth
275
- // shares, while its first 120 characters carry `<!DOCTYPE html>`; a wrapper
276
- // that prints a notice and then delegates ends in `"changeType":"MODIFIED"}]}`,
277
- // which reads as gh having answered perfectly and the parser being at fault.
278
- // The head carries the cause on both, and the tail actively misleads on one.
279
- const runWithGhStdout = (body) => {
280
- const bin = mkdtempSync(join(tmpdir(), "diff-stats-bin-"));
281
- const payload = join(bin, "payload");
282
- writeFileSync(payload, body);
283
- // `cat` of a file, not `echo` of an inlined string: the payloads below are
284
- // real captured bytes, quotes and all, and must reach stdout unmangled.
285
- writeExecStub(join(bin, "gh"), `#!/bin/sh\ncat "${payload}"\n`);
286
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "5"], {
287
- encoding: "utf8",
288
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
289
- });
290
- rmSync(bin, { recursive: true, force: true });
291
- return r;
292
- };
293
-
294
- // What the refusal actually quoted: everything after the em-dash to the end of
295
- // stderr. `[\s\S]*` (not `.`, which excludes `\n`) reads a multi-line clip in
296
- // full — a `.`-based capture stopped at the first newline and would pass a
297
- // mutant that clips to gh's first line alone, unmarked, whenever that first
298
- // line is itself under the cap (the exact #932 defect the fixture below pins).
299
- const quoted = (stderr) => {
300
- const m = /returned no JSON — ([\s\S]*)\n$/.exec(stderr);
301
- assert.ok(m, `no non-JSON refusal on stderr: ${stderr}`);
302
- return m[1];
303
- };
304
-
305
- // A real intercepting-proxy body: nginx's 502 template, the measured shape of
306
- // what a corporate portal hands back in place of api.github.com's JSON.
307
- const PORTAL = '<!DOCTYPE html><html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><center>corp-proxy-7 could not reach api.github.com: upstream refused</center><hr><center>nginx/1.24.0</center></body></html>';
308
-
309
- // The opening of a real github.com 404 body (fetched live, trimmed to its
310
- // first 366 bytes — enough to prove the shape without vendoring the page's
311
- // full ~269 KB). Every fixture above is single-line — `.split("\n")` and
312
- // unsplit `s` behave identically on them — so none can distinguish the real
313
- // `cut()` from a mutant that clips gh's FIRST LINE alone and skips the marker
314
- // whenever that line is itself under the cap: on `PORTAL` the mutant's first
315
- // "line" is the whole 274-char string, over the cap either way. This body is
316
- // genuinely multi-line and its own first line — `<!DOCTYPE html>`, 15
317
- // characters — is nowhere near 120, so a first-line-only mutant returns it
318
- // verbatim, dropping the other 351 bytes with no marker at all: the exact
319
- // #932 defect, at real-page scale a ~269 KB silent drop.
320
- const GITHUB_404 =
321
- '<!DOCTYPE html>\n<html\n lang="en"\n \n data-color-mode="auto" data-light-theme="light" data-dark-theme="dark"\n data-a11y-animated-images="system" data-a11y-link-underlines="true"\n \n >\n\n\n\n\n <head>\n <meta charset="utf-8">\n <link rel="dns-prefetch" href="https://github.githubassets.com">\n <link rel="dns-prefetch" href="https://avatars.githubusercontent.com">';
322
-
323
- test("CLI: an over-long non-JSON payload is quoted behind a visible truncation marker", () => {
324
- const r = runWithGhStdout(PORTAL);
325
- assert.equal(r.status, 2, `a non-JSON body must refuse; got ${r.status} ${r.stdout}${r.stderr}`);
326
- assert.equal(r.stdout.trim(), "", "exit 2 emits no payload");
327
- assert.match(
328
- quoted(r.stderr),
329
- /… \(truncated\)$/,
330
- "a clipped diagnostic must say it was clipped — unmarked, the reader takes this script's 120 characters for the whole of gh's output",
331
- );
332
- });
333
-
334
- // The other half of the guard. A marker appended unconditionally would make
335
- // every complete diagnostic read as a cut one — the same lie inverted, and a
336
- // suite that only ever feeds this path an over-long payload pins neither half.
337
- // 88 characters, the measured length of a real portal's 403 body, is a payload
338
- // it must ACCEPT and quote whole.
339
- test("CLI: a non-JSON payload that fits is quoted whole, with no marker", () => {
340
- const short = '<!DOCTYPE html><html><head><title>403 Forbidden</title></head><body>portal</body></html>';
341
- assert.ok(short.length <= 120, "this fixture only tests the accept path while it fits the cap");
342
- const r = runWithGhStdout(short);
343
- assert.equal(r.status, 2);
344
- assert.equal(quoted(r.stderr), short, "a payload that fits must be quoted exactly, not reshaped");
345
- assert.doesNotMatch(quoted(r.stderr), /truncated/, "nothing was cut, so nothing may claim it was");
346
- });
347
-
348
- test("CLI: the clip keeps the HEAD of gh's stdout, where this path's cause sits", () => {
349
- const q = quoted(runWithGhStdout(PORTAL).stderr);
350
- assert.match(q, /^<!DOCTYPE html>/, "the head identifies the payload as an HTML page — the one fact this refusal exists to deliver");
351
- assert.match(q, /502 Bad Gateway/, "and carries the proxy's own status line");
352
- assert.doesNotMatch(
353
- q,
354
- /<\/html>/,
355
- "keeping the tail here would quote `</body></html>` — boilerplate shared by every HTML error page, naming no cause at all",
356
- );
357
- });
358
-
359
- // ci-state.mjs's sibling `cut` (#1479) makes the opposite choice: its
360
- // `s.slice(0, n)` appends the marker unconditionally, so a clipped value
361
- // there measures 133 characters against its own 120-char cap — a cap the
362
- // marker can push past is not a cap. This script's stderr is read by
363
- // review-core.mjs's snapshot agent — markdown fed to a model, the same context
364
- // budget `run()`'s comment measures in bytes — so the cap is the contract
365
- // and the marker is part of what it bounds.
366
- test("CLI: the marker lives inside the 120-char cap, not past it", () => {
367
- const q = quoted(runWithGhStdout(PORTAL).stderr);
368
- assert.ok(
369
- q.length <= 120,
370
- `the quoted payload including its marker must fit the 120-char cap; got ${q.length}: ${JSON.stringify(q)}`,
371
- );
372
- });
373
-
374
- // Every fixture above is single-line, so none can tell the real `cut()` from
375
- // a mutant that clips gh's first line alone and skips the marker whenever
376
- // that line is itself under the cap — the exact #932 defect. `GITHUB_404` is
377
- // genuinely multi-line with a short first line, so it pins both halves: the
378
- // marker is present, and the whole quote (marker included) still fits 120.
379
- test("CLI: a multi-line non-JSON payload is still clipped and marked, not just its first line", () => {
380
- const q = quoted(runWithGhStdout(GITHUB_404).stderr);
381
- assert.match(
382
- q,
383
- /… \(truncated\)$/,
384
- "a first-line-only clip would return `<!DOCTYPE html>` (15 chars) unmarked, silently dropping the other 351 fixture bytes",
385
- );
386
- assert.ok(q.length <= 120, `the quoted payload including its marker must fit the 120-char cap; got ${q.length}: ${JSON.stringify(q)}`);
387
- });
388
-
389
- // The premise the direction above rests on, pinned so it cannot rot silently:
390
- // `raw` is gh's stdout ALONE. If a future edit added `stdio: ["ignore","pipe","pipe"]`
391
- // to run() and folded stderr in, the cause would move to the tail and the head
392
- // clip would start discarding it — the inversion this ticket exists to avoid.
393
- test("CLI: the quoted payload is gh's stdout alone — stderr never enters it", () => {
394
- const bin = mkdtempSync(join(tmpdir(), "diff-stats-bin-"));
395
- writeExecStub(join(bin, "gh"), '#!/bin/sh\necho "STDERR-ONLY-LINE" >&2\necho "<html>not json</html>"\n');
396
- const r = spawnSync(process.execPath, [SCRIPT, "--pr", "5"], {
397
- encoding: "utf8",
398
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
399
- });
400
- rmSync(bin, { recursive: true, force: true });
401
- assert.equal(r.status, 2);
402
- assert.equal(quoted(r.stderr), "<html>not json</html>", "the payload is stdout");
403
- assert.match(r.stderr, /STDERR-ONLY-LINE/, "the child's stderr is still forwarded — it is not swallowed, just not quoted");
404
- });