@feigi/fleet-ctl 0.0.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 (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,379 @@
1
+ // #1752 (parent #1743). The Renovate bot and the two release workflows keep a
2
+ // JOINT contract that none of the three files can state alone:
3
+ //
4
+ // renovate.json decides which labels a bot PR carries
5
+ // and whether it automerges;
6
+ // .github/workflows/release-label.yml counts release labels (exactly one is
7
+ // required) and, on an UNLABELLED bot
8
+ // PR, stamps a blind fallback label;
9
+ // .github/workflows/release.yml turns the one release label into the
10
+ // version segment it bumps.
11
+ //
12
+ // Before #1752 the bot config set no labels at all, so every bot PR reached the
13
+ // fallback and was stamped `patch` whatever it carried, and every bot PR was
14
+ // automerged — a Node major could ship with nobody watching AND announce
15
+ // itself as a patch. Each file read fine on its own; the defect was the
16
+ // disagreement between them. So this test reads all three as DATA and checks
17
+ // the contract they must keep together:
18
+ //
19
+ // 1. every update type the bot can emit resolves, from the bot config
20
+ // itself, to exactly one label the gate counts — the fallback reclaiming
21
+ // the labelling job is the defect, not a simplification;
22
+ // 2. that label is one the fallback's own guard recognises, so the
23
+ // fallback stands down instead of adding a second release label;
24
+ // 3. release.yml bumps the segment matching the update type's size;
25
+ // 4. no update type is simultaneously major and automergeable.
26
+ //
27
+ // It pins the contract, not the wording: label NAMES are read out of the
28
+ // workflows (rename them consistently in all three files and this stays
29
+ // green), the schedule is never read, and the bot config may express its
30
+ // rules through `labels`, `addLabels` or top-level update-type objects.
31
+ //
32
+ // WHICH UPDATE TYPES THE BOT CAN EMIT. Renovate's schema (44.115.6, fetched
33
+ // 2026-09-25) names ten: major, minor, patch, pin, pinDigest, digest,
34
+ // lockFileMaintenance, rollback, bump, replacement. With `enabledManagers:
35
+ // ["nvm"]` over an exact `.nvmrc` (ADR 0010) the `node-version` datasource
36
+ // yields only the semver three — no digests, no lock file, no range to pin or
37
+ // bump — and `rollback` only once `rollbackPrs` (default false) is opted into.
38
+ // That derivation holds only for the nvm manager, so a widened
39
+ // `enabledManagers` reds here rather than silently checking too few types.
40
+ //
41
+ // HOW THE BOT CONFIG RESOLVES, per Renovate's own source and docs rather than
42
+ // guessed: `labels` is non-mergeable (a later setting replaces it), `addLabels`
43
+ // appends, and the PR carries both; `automerge` defaults to false.
44
+ // `lib/workers/repository/updates/flatten.ts` applies packageRules, merges the
45
+ // top-level update-type object (`"major": {…}`), then applies packageRules
46
+ // AGAIN, so packageRules win over that object — modelled in that order below.
47
+ // The presets `config:recommended` extends set neither labels nor automerge
48
+ // (checked against renovate's `lib/config/presets/internal/*.preset.ts`), so the
49
+ // repo file alone decides both.
50
+ //
51
+ // CEILINGS. The workflows are read with targeted patterns, not a YAML parser —
52
+ // this repo has no package.json and no YAML dependency, the same trade
53
+ // ci-state.mjs makes; whole-line `#` comments are blanked first so a comment
54
+ // cannot satisfy a pattern. A packageRule is treated as applying to every
55
+ // update type it names regardless of any other matcher on it. That is
56
+ // one-sided, not simply conservative: an extra matcher on a rule that ADDS
57
+ // `automerge:false`/labels can make Renovate apply the safety settings to
58
+ // FEWER packages than this test assumes — narrow the major rule away from
59
+ // the real dependency it must cover and nothing here reds, while real
60
+ // Renovate falls through to the unattended top-level automerge for it; this
61
+ // repo's actual major rule matches on update type alone, which is what
62
+ // keeps that gap closed, not this test. An extra matcher on a rule that
63
+ // only LOOSENS settings is the direction that stays merely stricter than
64
+ // Renovate. And the ordering of Renovate's label write against the
65
+ // fallback job on the `opened` event is runtime behaviour no file here
66
+ // records.
67
+ import { test } from "node:test";
68
+ import assert from "node:assert/strict";
69
+ import { readFileSync } from "node:fs";
70
+ import { join } from "node:path";
71
+
72
+ const ROOT = join(import.meta.dirname, "..", "..");
73
+ const BOT = "renovate.json";
74
+ const GATE = ".github/workflows/release-label.yml";
75
+ const RELEASE = ".github/workflows/release.yml";
76
+
77
+ // Renovate's vocabulary on one side, release.yml's segment variables on the
78
+ // other: the size a semver update type must be announced as.
79
+ const SEGMENT_OF = { major: "MAJOR", minor: "MINOR", patch: "PATCH" };
80
+
81
+ const code = (text) =>
82
+ text
83
+ .split("\n")
84
+ .map((line) => (/^\s*#/.test(line) ? "" : line))
85
+ .join("\n");
86
+
87
+ // The `select(. == "a" or . == "b")` jq filter both workflows use to decide
88
+ // which labels are release labels.
89
+ function releaseLabelFilter(src, file, problems) {
90
+ const hits = [...src.matchAll(/select\(((?:\s*\.\s*==\s*"[^"]*"\s*(?:or)?)+)\s*\)/g)];
91
+ if (hits.length !== 1) {
92
+ problems.push(
93
+ `${file}: expected exactly one \`select(. == "…" or …)\` release-label filter, found ${hits.length} — cannot tell which labels it treats as release labels`,
94
+ );
95
+ return null;
96
+ }
97
+ return new Set([...hits[0][1].matchAll(/"([^"]*)"/g)].map((m) => m[1]));
98
+ }
99
+
100
+ function readGate(text, problems) {
101
+ const src = code(text);
102
+ const counted = releaseLabelFilter(src, GATE, problems);
103
+ const guard = src.match(/grep\s+-qE\s+'\^\(([^)]*)\)\$'/);
104
+ if (!guard) {
105
+ problems.push(
106
+ `${GATE}: no \`grep -qE '^(…)$'\` guard found — cannot tell which labels make the bot fallback stand down`,
107
+ );
108
+ }
109
+ const fallbacks = [...src.matchAll(/--add-label\s+["']?([^\s"']+)/g)].map((m) => m[1]);
110
+ if (fallbacks.length !== 1) {
111
+ problems.push(
112
+ `${GATE}: expected exactly one \`--add-label\` bot fallback, found ${fallbacks.length}`,
113
+ );
114
+ }
115
+ return {
116
+ counted,
117
+ guard: guard ? new Set(guard[1].split("|")) : null,
118
+ fallback: fallbacks.length === 1 ? fallbacks[0] : null,
119
+ };
120
+ }
121
+
122
+ function readRelease(text, problems) {
123
+ const src = code(text);
124
+ const labels = releaseLabelFilter(src, RELEASE, problems);
125
+ const bumps = new Map();
126
+ for (const m of src.matchAll(/([^\s()|;]+)\)\s*(MAJOR|MINOR|PATCH)=\$\(\(\s*\2\s*\+\s*1\s*\)\)/g)) {
127
+ bumps.set(m[1], m[2]);
128
+ }
129
+ if (labels) {
130
+ for (const label of labels) {
131
+ if (!bumps.has(label)) {
132
+ problems.push(`${RELEASE}: reads \`${label}\` as a release label but no case arm bumps a segment for it`);
133
+ }
134
+ }
135
+ }
136
+ for (const segment of Object.values(SEGMENT_OF)) {
137
+ const by = [...bumps].filter(([, s]) => s === segment).map(([l]) => l);
138
+ if (by.length !== 1) {
139
+ problems.push(`${RELEASE}: expected exactly one label to bump ${segment}, found ${by.length} (${by.join(", ") || "none"})`);
140
+ }
141
+ }
142
+ return { labels, bumps };
143
+ }
144
+
145
+ // What a bot PR of `type` ends up carrying, in Renovate's own merge order.
146
+ function resolveBot(cfg, type) {
147
+ let labels = cfg.labels ?? [];
148
+ const added = [...(cfg.addLabels ?? [])];
149
+ let automerge = cfg.automerge ?? false;
150
+ const apply = (layer) => {
151
+ if ("labels" in layer) labels = layer.labels;
152
+ if (layer.addLabels) added.push(...layer.addLabels);
153
+ if ("automerge" in layer) automerge = layer.automerge;
154
+ };
155
+ if (cfg[type]) apply(cfg[type]);
156
+ for (const rule of cfg.packageRules ?? []) {
157
+ if (rule.matchUpdateTypes === undefined || [].concat(rule.matchUpdateTypes).includes(type)) apply(rule);
158
+ }
159
+ return { labels: [...new Set([...labels, ...added])], automerge: automerge === true };
160
+ }
161
+
162
+ function emittableTypes(cfg) {
163
+ const types = Object.keys(SEGMENT_OF);
164
+ const rollback = cfg.rollbackPrs === true || (cfg.packageRules ?? []).some((r) => r.rollbackPrs === true);
165
+ return rollback ? [...types, "rollback"] : types;
166
+ }
167
+
168
+ // A JSON-valid renovate.json can still have the wrong SHAPE at exactly the
169
+ // spots resolveBot/emittableTypes read without a type check — an update-type
170
+ // override or a packageRules entry that is not a plain object, or
171
+ // packageRules itself not an array — and both throw a raw TypeError instead
172
+ // of a problem naming which file disagreed, breaking this test's own
173
+ // contract (the ticket's AC: "failure message names the file... and what the
174
+ // disagreement was"). Checked once, up front, so every downstream read can
175
+ // assume the shape it needs.
176
+ function isPlainObject(v) {
177
+ return v !== null && typeof v === "object" && !Array.isArray(v);
178
+ }
179
+ function botShapeProblem(cfg) {
180
+ if (cfg.packageRules !== undefined && !Array.isArray(cfg.packageRules)) {
181
+ return `${BOT}: \`packageRules\` must be an array, got ${typeof cfg.packageRules}`;
182
+ }
183
+ for (const rule of cfg.packageRules ?? []) {
184
+ if (!isPlainObject(rule)) return `${BOT}: a \`packageRules\` entry must be an object, got ${JSON.stringify(rule)}`;
185
+ }
186
+ for (const type of [...Object.keys(SEGMENT_OF), "rollback"]) {
187
+ if (cfg[type] !== undefined && !isPlainObject(cfg[type])) {
188
+ return `${BOT}: top-level \`${type}\` override must be an object, got ${JSON.stringify(cfg[type])}`;
189
+ }
190
+ }
191
+ return null;
192
+ }
193
+
194
+ function contractProblems({ bot, gate, release }) {
195
+ const problems = [];
196
+ let cfg;
197
+ try {
198
+ cfg = JSON.parse(bot);
199
+ } catch (err) {
200
+ return [`${BOT}: not valid JSON (${err.message})`];
201
+ }
202
+ const shapeProblem = botShapeProblem(cfg);
203
+ if (shapeProblem) return [shapeProblem];
204
+
205
+ // The one check #1752 exists to guarantee — a major update must never
206
+ // automerge — needs only `cfg` and `resolveBot`, so it runs before, and
207
+ // independently of, the gate/release parsing below: a cosmetic mismatch in
208
+ // either workflow (e.g. a quoting style neither readGate nor readRelease
209
+ // recognises) must not mask a live major-automerge regression behind an
210
+ // unrelated "cannot tell which labels…" problem.
211
+ if (resolveBot(cfg, "major").automerge) {
212
+ problems.push(
213
+ `${BOT}: \`major\` updates are automerged — a major must wait for a human, so the rule for \`major\` needs \`"automerge": false\``,
214
+ );
215
+ }
216
+
217
+ const g = readGate(gate, problems);
218
+ const r = readRelease(release, problems);
219
+ if (!g.counted || !g.guard || !g.fallback || !r.labels) return problems;
220
+
221
+ if (g.counted.size !== r.labels.size || [...g.counted].some((l) => !r.labels.has(l))) {
222
+ problems.push(
223
+ `${GATE} vs ${RELEASE}: the gate counts [${[...g.counted]}] as release labels but release.yml reads [${[...r.labels]}] — a label only one side knows either passes the gate and mints nothing, or mints from a PR the gate refused`,
224
+ );
225
+ }
226
+
227
+ if (JSON.stringify(cfg.enabledManagers) !== JSON.stringify(["nvm"])) {
228
+ problems.push(
229
+ `${BOT}: enabledManagers is ${JSON.stringify(cfg.enabledManagers)}, not ["nvm"] — the update types this test checks were derived for the nvm manager alone, so a new manager's update types (digest, pin, …) would go unchecked; extend emittableTypes before widening it`,
230
+ );
231
+ }
232
+
233
+ for (const type of emittableTypes(cfg)) {
234
+ const { labels, automerge } = resolveBot(cfg, type);
235
+ const releaseLabels = labels.filter((l) => g.counted.has(l));
236
+ const segments = releaseLabels.map((l) => r.bumps.get(l));
237
+ // `major` itself is covered unconditionally above, before g/r even
238
+ // parse; here we only catch OTHER types whose resolved label maps to a
239
+ // MAJOR segment (a minor/patch rule mislabelled onto `major`).
240
+ if (automerge && type !== "major" && segments.includes("MAJOR")) {
241
+ problems.push(
242
+ `${BOT}: \`${type}\` updates are automerged while carrying a major change — a major must wait for a human, so the rule for \`${type}\` needs \`"automerge": false\``,
243
+ );
244
+ }
245
+ if (releaseLabels.length === 0) {
246
+ problems.push(
247
+ `${BOT}: \`${type}\` updates get no release label from the bot config (resolved labels: [${labels}]) — ${GATE}'s bot fallback then stamps them \`${g.fallback}\` whatever their size`,
248
+ );
249
+ continue;
250
+ }
251
+ if (releaseLabels.length > 1) {
252
+ problems.push(
253
+ `${BOT}: \`${type}\` updates resolve to ${releaseLabels.length} release labels [${releaseLabels}] — ${GATE} refuses more than one, so the PR can never merge`,
254
+ );
255
+ continue;
256
+ }
257
+ const [label] = releaseLabels;
258
+ if (!g.guard.has(label)) {
259
+ problems.push(
260
+ `${GATE} vs ${BOT}: the bot fallback's guard does not recognise \`${label}\`, which the bot sets on \`${type}\` updates — the fallback adds \`${g.fallback}\` on top and the PR carries two release labels`,
261
+ );
262
+ }
263
+ const want = SEGMENT_OF[type];
264
+ if (want && segments[0] !== want) {
265
+ problems.push(
266
+ `${BOT} vs ${RELEASE}: \`${type}\` updates are labelled \`${label}\`, which release.yml bumps as ${segments[0] ?? "nothing"} — a ${type} update must mint a ${want} release`,
267
+ );
268
+ }
269
+ }
270
+ return problems;
271
+ }
272
+
273
+ const REAL = {
274
+ bot: readFileSync(join(ROOT, BOT), "utf8"),
275
+ gate: readFileSync(join(ROOT, GATE), "utf8"),
276
+ release: readFileSync(join(ROOT, RELEASE), "utf8"),
277
+ };
278
+
279
+ const withBot = (mutate) => {
280
+ const cfg = JSON.parse(REAL.bot);
281
+ mutate(cfg);
282
+ return { ...REAL, bot: JSON.stringify(cfg) };
283
+ };
284
+ const ruleFor = (cfg, type) =>
285
+ cfg.packageRules.find((r) => [].concat(r.matchUpdateTypes ?? []).includes(type));
286
+
287
+ const report = (problems) => `\n ${problems.join("\n ")}`;
288
+ const assertClean = (files) => {
289
+ const problems = contractProblems(files);
290
+ assert.deepEqual(problems, [], `the bot/release contract is broken:${report(problems)}`);
291
+ };
292
+ const assertBroken = (files, file, pattern) => {
293
+ const problems = contractProblems(files);
294
+ assert.ok(
295
+ problems.some((p) => p.startsWith(file) && pattern.test(p)),
296
+ `expected a problem naming ${file} matching ${pattern}, got:${report(problems)}`,
297
+ );
298
+ };
299
+
300
+ test("the committed bot config and both release workflows keep the joint contract", () => {
301
+ assertClean(REAL);
302
+ });
303
+
304
+ test("dropping the bot's label rules reds: the blind fallback would label every update", () => {
305
+ const files = withBot((cfg) => {
306
+ for (const rule of cfg.packageRules) delete rule.labels;
307
+ });
308
+ for (const type of ["major", "minor", "patch"]) {
309
+ assertBroken(files, BOT, new RegExp(`\`${type}\` updates get no release label.*bot fallback`));
310
+ }
311
+ assertBroken(withBot((cfg) => delete cfg.packageRules), BOT, /`major` updates get no release label/);
312
+ });
313
+
314
+ test("re-enabling major automerge reds, whether set outright or inherited from the default", () => {
315
+ assertBroken(withBot((cfg) => (ruleFor(cfg, "major").automerge = true)), BOT, /`major` updates are automerged/);
316
+ assertBroken(withBot((cfg) => delete ruleFor(cfg, "major").automerge), BOT, /`major` updates are automerged/);
317
+ assertBroken(withBot((cfg) => delete cfg.packageRules), BOT, /`major` updates are automerged/);
318
+ });
319
+
320
+ test("a mislabelled update type reds, naming the bot config and release.yml", () => {
321
+ assertBroken(
322
+ withBot((cfg) => (ruleFor(cfg, "major").labels = ["patch"])),
323
+ `${BOT} vs ${RELEASE}`,
324
+ /`major` updates are labelled `patch`, which release.yml bumps as PATCH/,
325
+ );
326
+ // Top-level `automerge: true` stays in force for minor; relabelling its
327
+ // rule `major` makes it a major change by release.yml's reading.
328
+ assertBroken(
329
+ withBot((cfg) => (ruleFor(cfg, "minor").labels = ["major"])),
330
+ BOT,
331
+ /`minor` updates are automerged while carrying a major change/,
332
+ );
333
+ });
334
+
335
+ // A literal, checked edit: a mutant whose target text has drifted away would
336
+ // otherwise leave the file unchanged and assert against the real tree.
337
+ const swap = (text, from, to) => {
338
+ assert.ok(text.includes(from), `mutation target \`${from}\` not found — update this test's mutant`);
339
+ return text.split(from).join(to);
340
+ };
341
+
342
+ test("a workflow that stops agreeing with the other two reds, naming that workflow", () => {
343
+ assertBroken(
344
+ { ...REAL, gate: swap(REAL.gate, "'^(patch|minor|major)$'", "'^(patch|minor)$'") },
345
+ `${GATE} vs ${BOT}`,
346
+ /guard does not recognise `major`/,
347
+ );
348
+ assertBroken(
349
+ { ...REAL, release: swap(swap(REAL.release, '"major"', '"breaking"'), "major) MAJOR=", "breaking) MAJOR=") },
350
+ `${GATE} vs ${RELEASE}`,
351
+ /the gate counts .* but release.yml reads/,
352
+ );
353
+ });
354
+
355
+ test("rewording the schedule or renaming the labels in all three files stays green", () => {
356
+ assertClean(withBot((cfg) => (cfg.schedule = ["on the first day of the month"])));
357
+
358
+ const rename = (text) => text.replace(/\b(patch|minor|major)\b/g, "semver:$1");
359
+ assertClean({
360
+ ...withBot((cfg) => {
361
+ for (const r of cfg.packageRules) r.labels = r.labels.map((l) => `semver:${l}`);
362
+ }),
363
+ gate: rename(REAL.gate),
364
+ release: rename(REAL.release),
365
+ });
366
+ });
367
+
368
+ test("the same contract expressed through addLabels and update-type objects stays green", () => {
369
+ assertClean(
370
+ withBot((cfg) => {
371
+ cfg.labels = ["dependencies"];
372
+ cfg.major = { automerge: false, addLabels: ["major"] };
373
+ cfg.packageRules = [
374
+ { matchUpdateTypes: "minor", addLabels: ["minor"] },
375
+ { matchUpdateTypes: ["patch"], addLabels: ["patch"] },
376
+ ];
377
+ }),
378
+ );
379
+ });