@intentius/chant 0.124.62 → 0.124.64

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 (262) hide show
  1. package/dist/cli/handlers/approve.d.ts +26 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +167 -18
  4. package/dist/cli/handlers/plan.d.ts +10 -0
  5. package/dist/cli/handlers/plan.d.ts.map +1 -0
  6. package/dist/cli/handlers/plan.js +71 -0
  7. package/dist/cli/handlers/pr.d.ts.map +1 -1
  8. package/dist/cli/handlers/pr.js +2 -1
  9. package/dist/cli/handlers/release.d.ts +11 -7
  10. package/dist/cli/handlers/release.d.ts.map +1 -1
  11. package/dist/cli/handlers/release.js +93 -20
  12. package/dist/cli/main.d.ts.map +1 -1
  13. package/dist/cli/main.js +48 -7
  14. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  15. package/dist/cli/mcp/workspace-tools.js +2 -1
  16. package/dist/cli/parse-args.d.ts.map +1 -1
  17. package/dist/cli/parse-args.js +43 -0
  18. package/dist/cli/registry.d.ts +18 -2
  19. package/dist/cli/registry.d.ts.map +1 -1
  20. package/dist/config.d.ts +50 -0
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +1 -0
  23. package/dist/gate-decision.d.ts +1 -1
  24. package/dist/gate-decision.d.ts.map +1 -1
  25. package/dist/gate-decision.js +4 -2
  26. package/dist/gate-statement.schema.json +46 -0
  27. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  28. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  29. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  30. package/dist/lifecycle/gate-ledger.d.ts +28 -5
  31. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  32. package/dist/lifecycle/gate-ledger.js +6 -0
  33. package/dist/lifecycle/gate-seal.d.ts +59 -7
  34. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  35. package/dist/lifecycle/gate-seal.js +68 -15
  36. package/dist/lifecycle/gate-statement.d.ts +95 -0
  37. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  38. package/dist/lifecycle/gate-statement.js +110 -0
  39. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  40. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  41. package/dist/lifecycle/gate-webauthn.js +105 -0
  42. package/dist/lifecycle/git.d.ts +1 -1
  43. package/dist/lifecycle/git.d.ts.map +1 -1
  44. package/dist/lifecycle/git.js +24 -19
  45. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  46. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  47. package/dist/lifecycle/ledger-remote.js +42 -0
  48. package/dist/lifecycle/plan-stale.d.ts +76 -0
  49. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  50. package/dist/lifecycle/plan-stale.js +120 -0
  51. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  52. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  53. package/dist/lifecycle/publish-credentials.js +2 -0
  54. package/dist/lifecycle/publish-declaration.d.ts +107 -0
  55. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  56. package/dist/lifecycle/publish-declaration.js +110 -1
  57. package/dist/lifecycle/publish-forge.d.ts +5 -1
  58. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  59. package/dist/lifecycle/publish-forge.js +13 -4
  60. package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
  61. package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
  62. package/dist/lifecycle/publish-git-ssh.js +180 -0
  63. package/dist/lifecycle/publish-github.d.ts +69 -0
  64. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  65. package/dist/lifecycle/publish-github.js +153 -0
  66. package/dist/lifecycle/publish-homebrew.d.ts +77 -0
  67. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  68. package/dist/lifecycle/publish-homebrew.js +265 -0
  69. package/dist/lifecycle/publish-marketplace.d.ts +85 -0
  70. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  71. package/dist/lifecycle/publish-marketplace.js +398 -0
  72. package/dist/lifecycle/publish-targets.d.ts +6 -0
  73. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  74. package/dist/lifecycle/publish-targets.js +15 -0
  75. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  76. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  77. package/dist/lifecycle/publish-tauri.js +181 -0
  78. package/dist/lifecycle/release-cut.d.ts +51 -5
  79. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  80. package/dist/lifecycle/release-cut.js +165 -16
  81. package/dist/lifecycle/release-publish.d.ts +18 -2
  82. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  83. package/dist/lifecycle/release-publish.js +5 -0
  84. package/dist/lifecycle/release-revocation.d.ts +4 -3
  85. package/dist/lifecycle/release-revocation.d.ts.map +1 -1
  86. package/dist/lifecycle/release-revocation.js +5 -4
  87. package/dist/lifecycle/release-store.d.ts +32 -0
  88. package/dist/lifecycle/release-store.d.ts.map +1 -1
  89. package/dist/lifecycle/release-store.js +11 -0
  90. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  91. package/dist/lifecycle/snapshot-store.js +17 -9
  92. package/dist/lifecycle/test-passkey.d.ts +25 -0
  93. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  94. package/dist/lifecycle/test-passkey.js +39 -0
  95. package/dist/notify.d.ts +23 -3
  96. package/dist/notify.d.ts.map +1 -1
  97. package/dist/notify.js +8 -2
  98. package/dist/notify.schema.json +12 -3
  99. package/dist/op/gate.d.ts +1 -1
  100. package/dist/op/gate.d.ts.map +1 -1
  101. package/dist/op/gate.js +2 -1
  102. package/dist/pr-forge.d.ts +20 -0
  103. package/dist/pr-forge.d.ts.map +1 -1
  104. package/dist/pr-forge.js +87 -8
  105. package/dist/release-floors.d.ts +1 -1
  106. package/dist/release-floors.js +1 -1
  107. package/dist/wave-runtime.mjs +333 -331
  108. package/dist/workspace/ci-builds.d.ts +21 -0
  109. package/dist/workspace/ci-builds.d.ts.map +1 -1
  110. package/dist/workspace/ci-builds.js +14 -0
  111. package/dist/workspace/ci-green.d.ts +45 -2
  112. package/dist/workspace/ci-green.d.ts.map +1 -1
  113. package/dist/workspace/ci-green.js +123 -5
  114. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  115. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  116. package/dist/workspace/ci-quarantine-report.js +204 -0
  117. package/dist/workspace/ci-quarantine.d.ts +73 -0
  118. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  119. package/dist/workspace/ci-quarantine.js +170 -0
  120. package/dist/workspace/ci-serve.d.ts.map +1 -1
  121. package/dist/workspace/ci-serve.js +7 -4
  122. package/dist/workspace/class-data.d.ts +3 -1
  123. package/dist/workspace/class-data.d.ts.map +1 -1
  124. package/dist/workspace/class-data.js +4 -1
  125. package/dist/workspace/declaration.d.ts +45 -2
  126. package/dist/workspace/declaration.d.ts.map +1 -1
  127. package/dist/workspace/declaration.js +45 -2
  128. package/dist/workspace/declaration.schema.json +51 -3
  129. package/dist/workspace/forge-work.d.ts +76 -0
  130. package/dist/workspace/forge-work.d.ts.map +1 -0
  131. package/dist/workspace/forge-work.js +160 -0
  132. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  133. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  134. package/dist/workspace/identity-gate-rule.js +5 -7
  135. package/dist/workspace/identity.d.ts +3 -2
  136. package/dist/workspace/identity.d.ts.map +1 -1
  137. package/dist/workspace/identity.js +6 -3
  138. package/dist/workspace/intent-cli.d.ts +3 -2
  139. package/dist/workspace/intent-cli.d.ts.map +1 -1
  140. package/dist/workspace/intent-cli.js +26 -5
  141. package/dist/workspace/intent-record.d.ts +3 -0
  142. package/dist/workspace/intent-record.d.ts.map +1 -1
  143. package/dist/workspace/intent-record.schema.json +32 -0
  144. package/dist/workspace/intent.d.ts +9 -0
  145. package/dist/workspace/intent.d.ts.map +1 -1
  146. package/dist/workspace/intent.js +2 -0
  147. package/dist/workspace/intent.schema.json +32 -0
  148. package/dist/workspace/kind-readers.d.ts.map +1 -1
  149. package/dist/workspace/kind-readers.js +2 -1
  150. package/dist/workspace/kinds.d.ts +6 -1
  151. package/dist/workspace/kinds.d.ts.map +1 -1
  152. package/dist/workspace/kinds.js +8 -3
  153. package/dist/workspace/plan-stale.schema.json +286 -0
  154. package/dist/workspace/release-candidates.d.ts +42 -7
  155. package/dist/workspace/release-candidates.d.ts.map +1 -1
  156. package/dist/workspace/release-candidates.js +64 -23
  157. package/dist/workspace/release-candidates.schema.json +55 -2
  158. package/dist/workspace/releases.schema.json +47 -0
  159. package/dist/workspace/trust/policy.d.ts +10 -0
  160. package/dist/workspace/trust/policy.d.ts.map +1 -1
  161. package/dist/workspace/trust/policy.js +19 -1
  162. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  163. package/dist/workspace/trust/run-commits.js +2 -1
  164. package/dist/workspace/trust/seal.d.ts.map +1 -1
  165. package/dist/workspace/trust/seal.js +34 -3
  166. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  167. package/dist/workspace/trust/trust-files.js +6 -1
  168. package/package.json +2 -1
  169. package/src/cli/handlers/approve-external-signature.test.ts +328 -0
  170. package/src/cli/handlers/approve.ts +206 -18
  171. package/src/cli/handlers/plan.ts +74 -0
  172. package/src/cli/handlers/pr.ts +2 -1
  173. package/src/cli/handlers/release.ts +84 -20
  174. package/src/cli/main.ts +48 -7
  175. package/src/cli/mcp/workspace-tools.ts +2 -1
  176. package/src/cli/parse-args.ts +33 -0
  177. package/src/cli/registry.ts +18 -2
  178. package/src/config.ts +8 -0
  179. package/src/gate-decision-bundle.test.ts +4 -2
  180. package/src/gate-decision.ts +11 -2
  181. package/src/gate-statement.schema.json +46 -0
  182. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  183. package/src/lifecycle/gate-ledger.ts +34 -5
  184. package/src/lifecycle/gate-seal.ts +86 -15
  185. package/src/lifecycle/gate-statement.ts +144 -0
  186. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  187. package/src/lifecycle/gate-webauthn.ts +133 -0
  188. package/src/lifecycle/git.ts +23 -19
  189. package/src/lifecycle/ledger-remote.test.ts +183 -0
  190. package/src/lifecycle/ledger-remote.ts +46 -0
  191. package/src/lifecycle/plan-stale.test.ts +149 -0
  192. package/src/lifecycle/plan-stale.ts +172 -0
  193. package/src/lifecycle/publish-credentials.ts +2 -0
  194. package/src/lifecycle/publish-declaration.ts +116 -1
  195. package/src/lifecycle/publish-forge.ts +14 -4
  196. package/src/lifecycle/publish-git-ssh.ts +202 -0
  197. package/src/lifecycle/publish-github.ts +174 -0
  198. package/src/lifecycle/publish-homebrew.test.ts +358 -0
  199. package/src/lifecycle/publish-homebrew.ts +283 -0
  200. package/src/lifecycle/publish-marketplace.test.ts +406 -0
  201. package/src/lifecycle/publish-marketplace.ts +421 -0
  202. package/src/lifecycle/publish-resume.test.ts +40 -0
  203. package/src/lifecycle/publish-target-context.test.ts +2 -2
  204. package/src/lifecycle/publish-targets.test.ts +23 -0
  205. package/src/lifecycle/publish-targets.ts +15 -0
  206. package/src/lifecycle/publish-tauri.test.ts +163 -0
  207. package/src/lifecycle/publish-tauri.ts +198 -0
  208. package/src/lifecycle/release-cut-lane.test.ts +177 -0
  209. package/src/lifecycle/release-cut-override.test.ts +213 -0
  210. package/src/lifecycle/release-cut.ts +198 -17
  211. package/src/lifecycle/release-publish.ts +23 -3
  212. package/src/lifecycle/release-revocation.ts +5 -4
  213. package/src/lifecycle/release-store.ts +44 -0
  214. package/src/lifecycle/snapshot-store.ts +16 -9
  215. package/src/lifecycle/test-passkey.ts +55 -0
  216. package/src/notify-bundle.test.ts +3 -1
  217. package/src/notify.schema.json +12 -3
  218. package/src/notify.ts +20 -3
  219. package/src/op/gate.ts +2 -1
  220. package/src/override-gate-bundle.test.ts +2 -0
  221. package/src/pr-forge-bundle.test.ts +2 -2
  222. package/src/pr-forge.test.ts +38 -0
  223. package/src/pr-forge.ts +93 -11
  224. package/src/pr-requires.test.ts +9 -0
  225. package/src/release-floors.ts +1 -1
  226. package/src/stage-hooks-bundle.test.ts +2 -0
  227. package/src/wave-runtime-bundle.test.ts +3 -2
  228. package/src/workspace/ci-builds.ts +27 -0
  229. package/src/workspace/ci-green-stale.test.ts +193 -0
  230. package/src/workspace/ci-green.ts +137 -6
  231. package/src/workspace/ci-quarantine-report.test.ts +145 -0
  232. package/src/workspace/ci-quarantine-report.ts +234 -0
  233. package/src/workspace/ci-quarantine.test.ts +160 -0
  234. package/src/workspace/ci-quarantine.ts +188 -0
  235. package/src/workspace/ci-serve.ts +7 -4
  236. package/src/workspace/class-data.ts +5 -1
  237. package/src/workspace/declaration.schema.json +51 -3
  238. package/src/workspace/declaration.test.ts +1 -0
  239. package/src/workspace/declaration.ts +88 -5
  240. package/src/workspace/forge-work.test.ts +143 -0
  241. package/src/workspace/forge-work.ts +195 -0
  242. package/src/workspace/identity-gate-rule.ts +6 -8
  243. package/src/workspace/identity.ts +6 -3
  244. package/src/workspace/intent-cli.ts +24 -5
  245. package/src/workspace/intent-record.schema.json +32 -0
  246. package/src/workspace/intent-record.ts +3 -0
  247. package/src/workspace/intent.schema.json +32 -0
  248. package/src/workspace/intent.ts +9 -0
  249. package/src/workspace/kind-readers.ts +2 -1
  250. package/src/workspace/kinds.test.ts +13 -0
  251. package/src/workspace/kinds.ts +12 -3
  252. package/src/workspace/plan-stale.schema.json +286 -0
  253. package/src/workspace/release-candidates.schema.json +55 -2
  254. package/src/workspace/release-candidates.test.ts +77 -4
  255. package/src/workspace/release-candidates.ts +80 -23
  256. package/src/workspace/releases.schema.json +47 -0
  257. package/src/workspace/trust/gate-seal.test.ts +44 -0
  258. package/src/workspace/trust/policy.ts +24 -1
  259. package/src/workspace/trust/run-commits.ts +2 -1
  260. package/src/workspace/trust/seal.ts +35 -3
  261. package/src/workspace/trust/trust-files.test.ts +5 -0
  262. package/src/workspace/trust/trust-files.ts +15 -1
@@ -102,6 +102,20 @@ export interface CiRecord {
102
102
  notified?: { red?: string; culprit?: string; green?: string };
103
103
  }
104
104
 
105
+ /**
106
+ * What the tick remembers about a branch rather than a commit (#4678),
107
+ * `_ci/branch/<branch>.json` on `chant/lifecycle`, the branch name
108
+ * URI-encoded. `stale` is the `ci.stale` it sent last: the stretch's oldest
109
+ * commit above the newest green one (`since`), that green commit, when, and
110
+ * once a newer commit is green, the green commit that ended the stretch.
111
+ * A stretch without `ended` has been told, however long it lasts.
112
+ */
113
+ export interface CiBranchRecord {
114
+ schema: 1;
115
+ branch: string;
116
+ stale?: { since: string; lastGreen: string | null; at: string; ended?: string };
117
+ }
118
+
105
119
  export interface CiRecordRun {
106
120
  name: string;
107
121
  id: number | null;
@@ -348,6 +362,19 @@ export function sameRecord(a: CiRecord | undefined, b: CiRecord): boolean {
348
362
  }
349
363
 
350
364
  export const recordPath = (sha: string) => `${CI_RECORDS_DIR}/${sha}.json`;
365
+ export const branchRecordPath = (branch: string) => `${CI_RECORDS_DIR}/branch/${encodeURIComponent(branch)}.json`;
366
+
367
+ /** A branch's record (#4678), from the local `chant/lifecycle` (or `ref`). Undefined when there is none or it doesn't parse. */
368
+ export function readCiBranchRecord(top: string, branch: string, ref: string = LEDGER_REF): CiBranchRecord | undefined {
369
+ const text = tryGit(top, ["show", `${ref}:${branchRecordPath(branch)}`]);
370
+ if (!text) return undefined;
371
+ try {
372
+ const r = JSON.parse(text) as CiBranchRecord;
373
+ return r && r.schema === 1 && r.branch === branch ? r : undefined;
374
+ } catch {
375
+ return undefined;
376
+ }
377
+ }
351
378
 
352
379
  function tryGit(top: string, args: string[]): string | null {
353
380
  try {
@@ -0,0 +1,193 @@
1
+ /**
2
+ * #4678 — ci.stale: the branch has had no green commit for staleAfter hours.
3
+ * Sent once per red stretch, remembered in _ci/branch/<branch>.json, and
4
+ * ended by the ci.green of a newer green commit.
5
+ */
6
+
7
+ import { execFileSync } from "node:child_process";
8
+ import { afterAll, describe, expect, test } from "vitest";
9
+ import { cleanScratch, declaration, git, scratchDir, writeFiles } from "./__fixtures__/contract-repo";
10
+ import { ciTick, readGreen, staleEvents, type StaleWalkCommit } from "./ci-green";
11
+ import type { CheckRun, CiForge } from "./ci-green-forge";
12
+ import { readCiBranchRecord, type CiBranchRecord } from "./ci-builds";
13
+ import type { CiGreen } from "./declaration";
14
+ import type { NotifyConfig, NotifyEvent } from "../notify";
15
+
16
+ afterAll(cleanScratch);
17
+
18
+ const NOW = new Date("2026-10-20T12:00:00Z");
19
+ const hoursAgo = (h: number, now = NOW) => new Date(now.getTime() - h * 3_600_000).toISOString().replace(/\.\d{3}Z$/, "Z");
20
+ const later = (h: number) => new Date(NOW.getTime() + h * 3_600_000);
21
+ const sha = (n: number) => n.toString(16).padStart(40, "0");
22
+
23
+ const GREEN: CiGreen = { branch: "main", window: "24h", phases: [], require: [], signedSince: null, source: "checks", notify: { slack: "SLACK", staleAfter: 6 }, pointer: "/ci/green" };
24
+
25
+ /** Commits newest first, `hours` ago each. */
26
+ const walkOf = (...hours: number[]): StaleWalkCommit[] => hours.map((h, i) => ({ sha: sha(hours.length - i), committed: hoursAgo(h) }));
27
+
28
+ function decide(walk: StaleWalkCommit[], green: number[], more: { stale?: CiBranchRecord["stale"]; answering?: string; judged?: (s: string) => boolean; staleAfter?: number | null } = {}) {
29
+ return staleEvents({
30
+ green: { ...GREEN, notify: { slack: "SLACK", ...(more.staleAfter === null ? {} : { staleAfter: more.staleAfter ?? 6 }) } },
31
+ walk,
32
+ isGreen: (s) => green.map(sha).includes(s),
33
+ judged: more.judged ?? (() => true),
34
+ stale: more.stale,
35
+ answering: more.answering,
36
+ now: NOW,
37
+ });
38
+ }
39
+
40
+ describe("which stretch is stale (#4678)", () => {
41
+ test("ci.stale when the oldest commit above the newest green one is staleAfter hours old, naming the tip, it and the green commit", () => {
42
+ // 4 is the tip, 1 is green; 2 landed 7 hours ago.
43
+ const { events } = decide(walkOf(1, 5, 7, 30), [1]);
44
+ expect(events).toHaveLength(1);
45
+ expect(events[0]!.fields).toMatchObject({
46
+ event: "ci.stale",
47
+ summary: `main has had no green commit for 7 hours: 3 commits since ${sha(2).slice(0, 12)}, above the green ${sha(1).slice(0, 12)}`,
48
+ ci: { branch: "main", commit: sha(4), since: sha(2), lastGreen: sha(1), hours: 7 },
49
+ run: { commit: sha(4) },
50
+ });
51
+ expect(events[0]!.stale).toEqual({ since: sha(2), lastGreen: sha(1), at: "2026-10-20T12:00:00Z" });
52
+ });
53
+
54
+ test("nothing before staleAfter, with a green tip, or without staleAfter", () => {
55
+ expect(decide(walkOf(1, 5, 30), [1]).events).toEqual([]);
56
+ expect(decide(walkOf(10, 30), [2]).events).toEqual([]);
57
+ expect(decide(walkOf(1, 7, 30), [1], { staleAfter: null }).events).toEqual([]);
58
+ });
59
+
60
+ test("with no green commit in the walk, the stretch starts at the oldest commit the tick judged", () => {
61
+ const judged = (s: string) => s !== sha(1);
62
+ // 1 (100 hours ago) was never judged, so the stretch is 3 and 2, from 8 hours ago.
63
+ const { events } = decide(walkOf(1, 8, 100), [], { judged });
64
+ expect(events[0]!.fields.ci).toEqual({ branch: "main", commit: sha(3), since: sha(2), hours: 8 });
65
+ expect(decide(walkOf(1, 8, 100), [], { judged: () => false }).events).toEqual([]);
66
+ });
67
+
68
+ test("an open stretch is told once, however long it lasts and wherever its first commit has gone", () => {
69
+ const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
70
+ expect(decide(walkOf(1, 5, 7, 30), [1], { stale: open }).events).toEqual([]);
71
+ // No green commit within the walk: still the same stretch.
72
+ expect(decide(walkOf(1, 5, 7), [], { stale: { ...open, since: sha(99) } }).events).toEqual([]);
73
+ });
74
+
75
+ test("a newer green commit ends the stretch with ci.green naming its since", () => {
76
+ const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
77
+ // 3 turned green.
78
+ const { events, endedBy } = decide(walkOf(1, 5, 7, 30), [1, 3], { stale: open });
79
+ expect(endedBy).toBeUndefined();
80
+ expect(events.map((e) => [e.fields.event, e.fields.ci])).toEqual([["ci.green", { branch: "main", commit: sha(3), since: sha(2) }]]);
81
+ expect(events[0]!.stale).toEqual({ ...open, ended: sha(3) });
82
+ });
83
+
84
+ test("when the tick sends ci.green anyway, that one ends the stretch and no second is sent", () => {
85
+ const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
86
+ const { events, endedBy } = decide(walkOf(1, 5, 7, 30), [1, 4], { stale: open, answering: sha(4) });
87
+ expect(events).toEqual([]);
88
+ expect(endedBy).toEqual({ ...open, ended: sha(4) });
89
+ });
90
+
91
+ test("an ended stretch doesn't hold back the next one", () => {
92
+ const ended = { since: sha(2), lastGreen: sha(1), at: hoursAgo(20), ended: sha(3) };
93
+ // 3 was green; 4 and 5 came after it, 4 nine hours ago.
94
+ const { events } = decide(walkOf(2, 9, 12, 13, 30), [1, 3], { stale: ended });
95
+ expect(events.map((e) => [e.fields.event, e.fields.ci?.since])).toEqual([["ci.stale", sha(4)]]);
96
+ });
97
+ });
98
+
99
+ // ── through the tick ─────────────────────────────────────────────────────────
100
+
101
+ const NOTIFY = { webhook: "HOOK_URL", key: "HOOK_KEY", staleAfter: 6 };
102
+ const DECLARED = { branch: "main", phases: { lint: ["lint"], test: ["test"] }, require: ["lint", "test"], notify: NOTIFY };
103
+
104
+ function commitAt(root: string, hours: number, file: string): string {
105
+ writeFiles(root, { [file]: `${file} ${hours}\n` });
106
+ const env = { ...process.env, GIT_AUTHOR_DATE: hoursAgo(hours), GIT_COMMITTER_DATE: hoursAgo(hours) };
107
+ const g = (...args: string[]) => execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd: root, env, stdio: ["ignore", "pipe", "pipe"] });
108
+ g("add", "-A");
109
+ g("commit", "-q", "-m", file);
110
+ return git(root, "rev-parse", "HEAD");
111
+ }
112
+
113
+ function workspace(green: unknown = DECLARED): string {
114
+ const origin = scratchDir("chant-stale-origin-");
115
+ git(origin, "init", "-q", "--bare");
116
+ const root = scratchDir("chant-stale-work-");
117
+ git(root, "init", "-q");
118
+ git(root, "symbolic-ref", "HEAD", "refs/heads/main");
119
+ writeFiles(root, { "chant.workspace.json": declaration([{ name: "app", dir: "app", kind: "other", because: "the app" }], { ci: { green } }), "app/a.txt": "a\n" });
120
+ git(root, "remote", "add", "origin", origin);
121
+ return root;
122
+ }
123
+
124
+ let id = 1;
125
+ const run = (name: string, conclusion: string | null): CheckRun => ({ id: id++, name, status: conclusion === null ? "in_progress" : "completed", conclusion, completedAt: null, url: null });
126
+ const pass = () => [run("lint", "success"), run("test", "success")];
127
+ const stuck = () => [run("lint", "success"), run("test", null)];
128
+
129
+ function sink() {
130
+ const sent: NotifyEvent[] = [];
131
+ const send = async (config: NotifyConfig | undefined, e: NotifyEvent | undefined) => {
132
+ if (!config || !e) return [];
133
+ sent.push(e);
134
+ return [{ target: "webhook" as const, ok: true, detail: "delivered" }];
135
+ };
136
+ return { sent, send };
137
+ }
138
+
139
+ const tick = (root: string, runs: Map<string, CheckRun[]>, s: ReturnType<typeof sink>, now: Date, more: { dryRun?: boolean } = {}) =>
140
+ ciTick({ cwd: root, forge: { kind: "github", checkRuns: async (c) => runs.get(c) ?? [] }, now, env: {}, sendNotify: s.send, ...more });
141
+
142
+ describe("ci.stale through the tick (#4678)", () => {
143
+ test("staleAfter is read with notify's settings, and must be more than 0 hours", () => {
144
+ expect(readGreen(workspace()).green.notify).toEqual(NOTIFY);
145
+ for (const staleAfter of [0, "6h"]) expect(() => readGreen(workspace({ ...DECLARED, notify: { ...NOTIFY, staleAfter } }))).toThrow(/staleAfter/);
146
+ });
147
+
148
+ /** a is green; b, 4 hours old at NOW, has a run that never finishes. */
149
+ function stuckBranch() {
150
+ const root = workspace();
151
+ const a = commitAt(root, 10, "app/a.txt");
152
+ const b = commitAt(root, 4, "app/b.txt");
153
+ git(root, "push", "-q", "origin", "main");
154
+ const runs = new Map([
155
+ [a, pass()],
156
+ [b, stuck()],
157
+ ]);
158
+ return { root, a, b, runs };
159
+ }
160
+
161
+ test("later ticks with no new commit send ci.stale once, marked in the branch's record", async () => {
162
+ const { root, a, b, runs } = stuckBranch();
163
+ const s = sink();
164
+ await tick(root, runs, s, NOW);
165
+ expect(s.sent).toEqual([]);
166
+ // Three hours on, nothing has landed and b is still running.
167
+ const dry = await tick(root, runs, s, later(3), { dryRun: true });
168
+ expect(dry.notified).toEqual([{ event: "ci.stale", commit: b, sent: false }]);
169
+ const told = await tick(root, runs, s, later(3));
170
+ expect(s.sent.map((e) => [e.event, e.ci])).toEqual([["ci.stale", { branch: "main", commit: b, since: b, lastGreen: a, hours: 7 }]]);
171
+ expect(told.recorded).toContain("_ci/branch/main.json");
172
+ expect(readCiBranchRecord(root, "main")?.stale).toEqual({ since: b, lastGreen: a, at: hoursAgo(-3) });
173
+ await tick(root, runs, s, later(5));
174
+ expect(s.sent).toHaveLength(1);
175
+ });
176
+
177
+ test("a newer green commit ends the stretch with one ci.green naming since", async () => {
178
+ const { root, b, runs } = stuckBranch();
179
+ const s = sink();
180
+ await tick(root, runs, s, later(3));
181
+ const c = commitAt(root, -6, "app/c.txt");
182
+ git(root, "push", "-q", "origin", "main");
183
+ runs.set(c, pass());
184
+ await tick(root, runs, s, later(7));
185
+ expect(s.sent.map((e) => [e.event, e.ci?.commit, e.ci?.since])).toEqual([
186
+ ["ci.stale", b, b],
187
+ ["ci.green", c, b],
188
+ ]);
189
+ expect(readCiBranchRecord(root, "main")?.stale?.ended).toBe(c);
190
+ await tick(root, runs, s, later(8));
191
+ expect(s.sent).toHaveLength(2);
192
+ });
193
+ });
@@ -57,12 +57,13 @@ import { judgeCommits, mergeCommits, readWorkIndex, type CommitLink } from "./co
57
57
  import { execFileSync } from "node:child_process";
58
58
  import { greenBranches, laneOf, laneTagPrefixes, readDeclaration, readerVersion, WORKSPACE_ERROR_CODES, WorkspaceReadError, type CiGreen, type CiPhase, type CiSource } from "./declaration";
59
59
  import { makeNotifyEvent, sendNotify, type NotifyFields } from "../notify";
60
+ import { lifecycleRemoteOverride } from "../lifecycle/ledger-remote";
60
61
  import type { CheckRun, CiForge, OpRunRef } from "./ci-green-forge";
61
62
  import type { OpRunRecord } from "../op/runtime";
62
63
  import { readRunLedger } from "../lifecycle/run-ledger";
63
64
  import { fetchLifecycleStatus, listFilesInDir, listLedgerTrees, pushLifecycleStatus, writeLedgerFiles } from "../lifecycle/git";
64
65
  import { ledgerRecordingOff } from "../lifecycle/no-record";
65
- import { agedOut, buildRequestAnnotation, CI_BUILD_TAG_PREFIX, CI_LEDGER_REF, planBuilds, readBuildRequests, readCiRecords, recordOf, recordPath, requestedBuild, sameRecord, type BuildRequest, type CiRecord } from "./ci-builds";
66
+ import { agedOut, branchRecordPath, buildRequestAnnotation, CI_BUILD_TAG_PREFIX, CI_LEDGER_REF, planBuilds, readBuildRequests, readCiBranchRecord, readCiRecords, recordOf, recordPath, requestedBuild, sameRecord, type BuildRequest, type CiBranchRecord, type CiRecord } from "./ci-builds";
66
67
  import { dispatchableWorkflows, MERGE_QUEUE_VERDICT_JOB, readWorkflowSources } from "./ci-green-workflow";
67
68
  import { signOpRunRecord, verifyOpRunStatement } from "./trust/op-run-statement";
68
69
  import type { ReasonCode } from "./reason-codes";
@@ -83,6 +84,10 @@ export const CI_REVOKED_TAG_PREFIX = "ci/revoked/";
83
84
  export const CI_GREEN_LANES_FLOOR = "0.124.61";
84
85
  /** The first chant whose tick sends `ci.red`, `ci.culprit` and `ci.green` through `ci.green.notify` (#4645). */
85
86
  export const CI_TICK_NOTIFY_FLOOR = "0.124.61";
87
+ /** The first chant whose tick sends `ci.stale` after `ci.green.notify.staleAfter` hours without a green commit (#4678). */
88
+ export const CI_STALE_NOTIFY_FLOOR = "0.124.63";
89
+ /** How many first-parent commits the tick reads back looking for the newest green one, for `ci.stale` (#4678). */
90
+ export const CI_STALE_WALK = 200;
86
91
  /** The first chant that writes a merge queue's trigger and verdict job, and reads `chant ci verdict` (#4644). */
87
92
  export const CI_MERGE_QUEUE_FLOOR = "0.124.61";
88
93
 
@@ -806,7 +811,35 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
806
811
  // #4645: what to tell people, decided from the records this tick writes. Without records a tick can't
807
812
  // remember what it sent, so it sends nothing rather than the same event every time.
808
813
  const canRecord = ledgerOk && !ledgerRecordingOff();
809
- const events = green.notify && canRecord ? tickEvents({ green, planned, records, builds, requests, now }) : [];
814
+ const events: { fields: NotifyFields; mark?: ReturnType<typeof tickEvents>[number]["mark"]; stale?: CiBranchRecord["stale"] }[] =
815
+ green.notify && canRecord ? tickEvents({ green, planned, records, builds, requests, now }) : [];
816
+ // #4678: ci.stale, from the tags as this tick leaves them, and the ci.green that ends its stretch.
817
+ const branchBefore = green.notify && canRecord ? readCiBranchRecord(top, green.branch) : undefined;
818
+ let branchAfter = branchBefore;
819
+ if (green.notify && canRecord && (green.notify.staleAfter !== undefined || (branchBefore?.stale && !branchBefore.stale.ended))) {
820
+ const greenNow = new Set(tags.green.keys());
821
+ const revokedNow = new Set(tags.revoked.keys());
822
+ for (const c of planned) {
823
+ if (c.made?.tag === `${CI_GREEN_TAG_PREFIX}${c.sha}`) greenNow.add(c.sha);
824
+ if (c.made?.tag === `${CI_REVOKED_TAG_PREFIX}${c.sha}`) revokedNow.add(c.sha);
825
+ }
826
+ const inWindow = new Set(planned.map((c) => c.sha));
827
+ const answering = events.find((e) => e.fields.event === "ci.green");
828
+ const stale = staleEvents({
829
+ green,
830
+ walk: firstParents(top, tracking, CI_STALE_WALK),
831
+ isGreen: (sha) => greenNow.has(sha) && !revokedNow.has(sha),
832
+ judged: (sha) => inWindow.has(sha) || records.has(sha),
833
+ stale: branchBefore?.stale,
834
+ answering: answering?.fields.ci!.commit,
835
+ now,
836
+ });
837
+ if (stale.endedBy && answering) {
838
+ answering.fields = { ...answering.fields, ci: { ...answering.fields.ci!, since: stale.endedBy.since } };
839
+ answering.stale = stale.endedBy;
840
+ }
841
+ events.push(...stale.events);
842
+ }
810
843
  const notified: TickResult["notified"] = [];
811
844
  const marks = new Map<string, NonNullable<CiRecord["notified"]>>();
812
845
  for (const e of events) {
@@ -823,12 +856,15 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
823
856
  continue;
824
857
  }
825
858
  notified.push({ event: e.fields.event, commit: e.fields.ci!.commit, sent: deliveries.length > 0 });
826
- marks.set(e.mark.sha, { ...(marks.get(e.mark.sha) ?? {}), ...e.mark.notified });
859
+ if (e.mark) marks.set(e.mark.sha, { ...(marks.get(e.mark.sha) ?? {}), ...e.mark.notified });
860
+ if (e.stale) branchAfter = { schema: 1, branch: green.branch, stale: e.stale };
827
861
  }
828
862
  let recorded: string[] = [];
829
863
  if (!req.dryRun) {
830
864
  const asked = await askForBuilds({ top, remote, green, forge, builds, requests, records, planned, warnings });
831
- recorded = canRecord ? await writeRecords({ top, green, planned, records, builds, requests: asked.live, dispatched: asked.dispatched, now, warnings, notified: marks }) : [];
865
+ recorded = canRecord
866
+ ? await writeRecords({ top, green, planned, records, builds, requests: asked.live, dispatched: asked.dispatched, now, warnings, notified: marks, branchRecord: branchAfter !== branchBefore ? branchAfter : undefined })
867
+ : [];
832
868
  }
833
869
  return {
834
870
  branch: green.branch,
@@ -909,6 +945,97 @@ export function tickEvents(input: {
909
945
  return out;
910
946
  }
911
947
 
948
+ /** A first-parent commit and when it was committed, ISO 8601. */
949
+ export interface StaleWalkCommit {
950
+ sha: string;
951
+ committed: string;
952
+ }
953
+
954
+ /** `ref`'s first-parent commits, newest first, `max` at most, with their commit times. */
955
+ function firstParents(top: string, ref: string, max: number): StaleWalkCommit[] {
956
+ return git(top, ["log", "--first-parent", `--max-count=${max}`, "--format=%H %ct", ref])
957
+ .split("\n")
958
+ .filter(Boolean)
959
+ .map((line) => line.split(" "))
960
+ .map(([sha, ct]) => ({ sha: sha!, committed: iso(new Date(Number(ct) * 1000)) }));
961
+ }
962
+
963
+ /**
964
+ * `ci.stale` and the `ci.green` that ends its stretch (#4678). The red
965
+ * stretch is the first-parent commits above the newest green one in `walk`;
966
+ * with no green one there, the commits down to the oldest the tick judged,
967
+ * so commits from before the tick ran don't count. When the stretch's
968
+ * oldest commit (`since`) was committed `staleAfter` hours ago or more and
969
+ * the branch's record has no open stretch, it sends `ci.stale` and opens
970
+ * one. An open stretch whose `since` is no longer above the newest green
971
+ * commit has ended: the `ci.green` the tick sends anyway (`answering`)
972
+ * names `since` and closes it (`endedBy`), or else this sends a `ci.green`
973
+ * for the newest green commit. Each event carries the branch record's
974
+ * `stale` as it is once the event is told. Pure.
975
+ */
976
+ export function staleEvents(input: {
977
+ green: CiGreen;
978
+ /** The branch's first-parent commits, newest first. */
979
+ walk: readonly StaleWalkCommit[];
980
+ /** A green tag, this tick's included, and no revoked one. */
981
+ isGreen: (sha: string) => boolean;
982
+ /** The tick judged it: it is in the window or has a record. */
983
+ judged: (sha: string) => boolean;
984
+ /** The branch record's `stale`. */
985
+ stale: CiBranchRecord["stale"];
986
+ /** The commit of the `ci.green` the tick sends anyway, if it does. */
987
+ answering?: string;
988
+ now: Date;
989
+ }): { events: { fields: NotifyFields; stale: NonNullable<CiBranchRecord["stale"]> }[]; endedBy?: NonNullable<CiBranchRecord["stale"]> } {
990
+ const { green, walk, now } = input;
991
+ const branch = green.branch;
992
+ const at = walk.findIndex((c) => input.isGreen(c.sha));
993
+ const lastGreen = at >= 0 ? walk[at]!.sha : null;
994
+ let end = at;
995
+ if (at < 0) for (let i = 0; i < walk.length; i++) if (input.judged(walk[i]!.sha)) end = i + 1;
996
+ const stretch = walk.slice(0, Math.max(end, 0));
997
+ const out: ReturnType<typeof staleEvents> = { events: [] };
998
+ const short = (sha: string) => sha.slice(0, 12);
999
+ let open = input.stale && !input.stale.ended ? input.stale : undefined;
1000
+ if (open && lastGreen && !stretch.some((c) => c.sha === open!.since)) {
1001
+ const ended = { ...open, ended: input.answering ?? lastGreen };
1002
+ if (input.answering) out.endedBy = ended;
1003
+ else {
1004
+ out.events.push({
1005
+ fields: {
1006
+ source: "chant",
1007
+ event: "ci.green",
1008
+ summary: `${branch} is green again at ${short(lastGreen)}, after no green commit since ${short(open.since)}`,
1009
+ targets: [],
1010
+ ci: { branch, commit: lastGreen, since: open.since },
1011
+ run: { commit: lastGreen },
1012
+ },
1013
+ stale: ended,
1014
+ });
1015
+ }
1016
+ open = undefined;
1017
+ }
1018
+ const staleAfter = green.notify?.staleAfter;
1019
+ const since = stretch.at(-1);
1020
+ if (open || staleAfter === undefined || !since) return out;
1021
+ const age = now.getTime() - Date.parse(since.committed);
1022
+ if (age < staleAfter * 3_600_000) return out;
1023
+ const hours = Math.floor(age / 3_600_000);
1024
+ const tip = walk[0]!.sha;
1025
+ out.events.push({
1026
+ fields: {
1027
+ source: "chant",
1028
+ event: "ci.stale",
1029
+ summary: `${branch} has had no green commit for ${hours} hours: ${stretch.length} commit${stretch.length === 1 ? "" : "s"} since ${short(since.sha)}${lastGreen ? `, above the green ${short(lastGreen)}` : ""}`,
1030
+ targets: [],
1031
+ ci: { branch, commit: tip, since: since.sha, ...(lastGreen ? { lastGreen } : {}), hours },
1032
+ run: { commit: tip },
1033
+ },
1034
+ stale: { since: since.sha, lastGreen, at: iso(now) },
1035
+ });
1036
+ return out;
1037
+ }
1038
+
912
1039
  /** The tick's environment for an event's run fields: its repository and forge, without the tick's own run link, which says nothing about the commit. */
913
1040
  function tickEventEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
914
1041
  const { GITHUB_RUN_ID: _r, CI_JOB_URL: _j, CI_PIPELINE_URL: _p, GITHUB_SHA: _s, CI_COMMIT_SHA: _c, ...rest } = env;
@@ -1015,6 +1142,8 @@ async function writeRecords(input: {
1015
1142
  warnings: string[];
1016
1143
  /** What the tick told people this time (#4645), merged into each commit's `notified`. */
1017
1144
  notified?: ReadonlyMap<string, NonNullable<CiRecord["notified"]>>;
1145
+ /** The branch's record, when what it told about a stretch changed (#4678). */
1146
+ branchRecord?: CiBranchRecord;
1018
1147
  }): Promise<string[]> {
1019
1148
  const { top, green, planned, records, builds, requests, now, warnings } = input;
1020
1149
  const writes: { path: string; content: string }[] = [];
@@ -1035,6 +1164,7 @@ async function writeRecords(input: {
1035
1164
  if (inWindow.has(sha) || r.state !== "pending") continue;
1036
1165
  writes.push({ path: recordPath(sha), content: `${JSON.stringify(agedOut(r, now), null, 2)}\n` });
1037
1166
  }
1167
+ if (input.branchRecord) writes.push({ path: branchRecordPath(input.branchRecord.branch), content: `${JSON.stringify(input.branchRecord, null, 2)}\n` });
1038
1168
  if (writes.length === 0) return [];
1039
1169
  for (let attempt = 0; attempt < 2; attempt++) {
1040
1170
  try {
@@ -1467,7 +1597,8 @@ export type CiBaseDocument =
1467
1597
  * job that failed. A commit with no record (outside the tick's window)
1468
1598
  * counts when it has a green tag and no revoked one, as `ci last-green`
1469
1599
  * reads them. Reads local refs only: the records on `chant/lifecycle`, or
1470
- * on `origin/chant/lifecycle` when there is no local branch, and the tags.
1600
+ * on `origin/chant/lifecycle` (or the remote `CHANT_LIFECYCLE_REMOTE`
1601
+ * names) when there is no local branch, and the tags.
1471
1602
  */
1472
1603
  export function ciBase(req: { cwd: string; from?: string; branch?: string; phase?: string; lane?: string; remote?: string }): CiBaseDocument {
1473
1604
  const head = { $schema: CI_LAST_GREEN_SCHEMA_ID, contract: CI_LAST_GREEN_CONTRACT_VERSION, chant: readerVersion() };
@@ -1487,7 +1618,7 @@ export function ciBase(req: { cwd: string; from?: string; branch?: string; phase
1487
1618
  }
1488
1619
  const branchRef = tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/remotes/${req.remote ?? "origin"}/${green.branch}^{commit}`]) ?? tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/heads/${green.branch}^{commit}`]);
1489
1620
  const tags = readCiTags(top, green, branchRef, lane?.name);
1490
- const ledger = tryGit(top, ["rev-parse", "--verify", "--quiet", CI_LEDGER_REF]) !== null ? CI_LEDGER_REF : `refs/remotes/${req.remote ?? "origin"}/chant/lifecycle`;
1621
+ const ledger = tryGit(top, ["rev-parse", "--verify", "--quiet", CI_LEDGER_REF]) !== null ? CI_LEDGER_REF : `refs/remotes/${lifecycleRemoteOverride() ?? req.remote ?? "origin"}/chant/lifecycle`;
1491
1622
  const records = readCiRecords(top, ledger);
1492
1623
  const phases = req.phase !== undefined ? [req.phase] : (lane?.require ?? green.require);
1493
1624
  const builtHere = (r: CiRecord) =>
@@ -0,0 +1,145 @@
1
+ /**
2
+ * #4677 — the quarantine's scheduled run: each quarantined test's outcome
3
+ * from JUnit XML, and ci.quarantine-passed for each one that passed.
4
+ */
5
+
6
+ import { describe, expect, test, vi } from "vitest";
7
+ import Ajv2020 from "ajv/dist/2020";
8
+ import notifySchema from "../notify.schema.json" with { type: "json" };
9
+ import { notifyHeadline, type NotifyEvent } from "../notify";
10
+ import { CI_QUARANTINE_NOTIFY_FLOOR, formatQuarantineReport, parseJUnit, quarantineReport } from "./ci-quarantine-report";
11
+ import { parseDeclaration, type CiGreen } from "./declaration";
12
+
13
+ const SHA = "0123456789abcdef0123456789abcdef01234567";
14
+
15
+ const NEXTEST = `<?xml version="1.0" encoding="UTF-8"?>
16
+ <testsuites name="nextest-run" tests="4" failures="1" errors="0">
17
+ <testsuite name="arugulad::integration" tests="3" disabled="0" errors="0" failures="1">
18
+ <testcase name="ssh::ssh_installs_runs" classname="arugulad::integration" timestamp="2026-11-01T07:47:00Z" time="12.1">
19
+ <system-out><![CDATA[ok <not a tag> </testcase> ]]></system-out>
20
+ </testcase>
21
+ <testcase name="reboot::comes_back" classname="arugulad::integration" time="3.0">
22
+ <flakyFailure message="code=101" type="test failure"><![CDATA[thread panicked]]></flakyFailure>
23
+ </testcase>
24
+ <testcase name="reboot::keeps_state" classname="arugulad::integration" time="3.0">
25
+ <failure message="code=101" type="test failure">assert &lt;left&gt; == right</failure>
26
+ <rerunFailure message="code=101" type="test failure"/>
27
+ </testcase>
28
+ </testsuite>
29
+ <testsuite name="arugula-platform" tests="1">
30
+ <testcase name="triggers::fires_once" classname="arugula-platform" time="0.2"/>
31
+ </testsuite>
32
+ </testsuites>`;
33
+
34
+ const PLAYWRIGHT = `<testsuites id="" name="" tests="3" failures="0" skipped="1">
35
+ <testsuite name="chat-control.spec.ts" timestamp="2026-11-01T07:50:00" hostname="chromium" tests="2" failures="0" skipped="1" time="4.2" errors="0">
36
+ <testcase name="composer › polish: edits the last message (and Esc cancels)" classname="chat-control.spec.ts" time="2.1">
37
+ </testcase>
38
+ <testcase name="opens the menu" classname="chat-control.spec.ts" time="0">
39
+ <skipped>
40
+ </skipped>
41
+ </testcase>
42
+ </testsuite>
43
+ <testsuite name="chat-control.spec.ts" hostname="webkit" tests="1">
44
+ <testcase name="composer › polish: edits the last message (and Esc cancels)" classname="chat-control.spec.ts" time="2.4"></testcase>
45
+ </testsuite>
46
+ </testsuites>`;
47
+
48
+ const entry = (test: string, extra: Record<string, string> = {}) => ({ test, issue: "1234", until: "2026-11-10", why: "Flaky.", ...extra });
49
+
50
+ function greenOf(notify?: unknown): CiGreen {
51
+ const ws = {
52
+ name: "acme",
53
+ schema: 1,
54
+ members: [],
55
+ ci: {
56
+ green: {
57
+ branch: "main",
58
+ phases: { test: ["test (*)"], e2e: ["e2e"] },
59
+ require: ["test", "e2e"],
60
+ ...(notify !== undefined ? { notify } : {}),
61
+ quarantine: {
62
+ phases: {
63
+ test: [entry("arugulad::integration ssh::ssh_installs_runs"), entry("arugulad::integration reboot::comes_back"), entry("reboot::keeps_state"), entry("triggers::fires_once"), entry("other::gone")],
64
+ e2e: [entry("polish: edits the last message (and Esc cancels)", { file: "chat-control.spec.ts", issue: "https://github.com/acme/app/issues/1235" }), entry("opens the menu", { file: "chat-control.spec.ts" })],
65
+ },
66
+ },
67
+ },
68
+ },
69
+ };
70
+ return parseDeclaration(JSON.stringify(ws), "chant.workspace.json").ci!.green!;
71
+ }
72
+
73
+ const NOTIFY = { webhook: "HOOK", key: "HOOK_KEY" };
74
+
75
+ describe("ci quarantine report (#4677)", () => {
76
+ test("its floor is the release it shipped in", () => {
77
+ expect(CI_QUARANTINE_NOTIFY_FLOOR).toBe("0.124.63");
78
+ });
79
+
80
+ test("reads nextest's and Playwright's JUnit, CDATA and entities included", () => {
81
+ expect(parseJUnit(NEXTEST).map((c) => [c.suite, c.name, c.outcome])).toEqual([
82
+ ["arugulad::integration", "ssh::ssh_installs_runs", "passed"],
83
+ ["arugulad::integration", "reboot::comes_back", "flaky"],
84
+ ["arugulad::integration", "reboot::keeps_state", "failed"],
85
+ ["arugula-platform", "triggers::fires_once", "passed"],
86
+ ]);
87
+ expect(parseJUnit(PLAYWRIGHT).map((c) => c.outcome)).toEqual(["passed", "skipped", "passed"]);
88
+ expect(() => parseJUnit("<html></html>")).toThrow(/not JUnit XML/);
89
+ });
90
+
91
+ test("each entry's outcome; a test that passed only on a retry is flaky, not passed", async () => {
92
+ const send = vi.fn(async () => [{ target: "webhook" as const, ok: true, detail: "delivered" }]);
93
+ const r = await quarantineReport({ green: greenOf(NOTIFY), phase: "test", junit: [NEXTEST], commit: SHA, env: { HOOK: "https://hooks.example/x", HOOK_KEY: "k" }, sendNotify: send });
94
+ expect(r.results.map((x) => [x.entry.test, x.outcome, x.cases])).toEqual([
95
+ ["arugulad::integration ssh::ssh_installs_runs", "passed", 1],
96
+ ["arugulad::integration reboot::comes_back", "flaky", 1],
97
+ ["reboot::keeps_state", "failed", 1],
98
+ ["triggers::fires_once", "passed", 1],
99
+ ["other::gone", "not-run", 0],
100
+ ]);
101
+ expect(r.told).toEqual([
102
+ { name: "arugulad::integration ssh::ssh_installs_runs", sent: true },
103
+ { name: "triggers::fires_once", sent: true },
104
+ ]);
105
+ expect(send).toHaveBeenCalledTimes(2);
106
+ const event = (send.mock.calls[0] as unknown as [unknown, NotifyEvent])[1];
107
+ expect(event).toMatchObject({
108
+ event: "ci.quarantine-passed",
109
+ source: "chant",
110
+ targets: ["arugulad::integration ssh::ssh_installs_runs"],
111
+ ci: { branch: "main", commit: SHA, phase: "test", quarantine: { test: "arugulad::integration ssh::ssh_installs_runs", issue: "1234", until: "2026-11-10" } },
112
+ run: { commit: SHA },
113
+ });
114
+ const second = (send.mock.calls[1] as unknown as [unknown, NotifyEvent])[1];
115
+ expect(second.id).not.toBe(event.id);
116
+ const ajv = new Ajv2020({ strict: false });
117
+ expect(ajv.validate(notifySchema, event)).toBe(true);
118
+ expect(notifyHeadline(event)).toContain("quarantined arugulad::integration ssh::ssh_installs_runs passed in phase test's scheduled run at 0123456789ab");
119
+ });
120
+
121
+ test("a Playwright test passes when every project's case passed, and its describes may be left out", async () => {
122
+ const r = await quarantineReport({ green: greenOf(), phase: "e2e", junit: [PLAYWRIGHT], commit: SHA });
123
+ expect(r.results.map((x) => [x.entry.test, x.outcome, x.cases])).toEqual([
124
+ ["polish: edits the last message (and Esc cancels)", "passed", 2],
125
+ ["opens the menu", "skipped", 1],
126
+ ]);
127
+ expect(r.told).toEqual([]);
128
+ expect(formatQuarantineReport(r, greenOf())).toBe(
129
+ [
130
+ `quarantine of phase e2e at 0123456789ab: 2 tests`,
131
+ ` passed chat-control.spec.ts › polish: edits the last message (and Esc cancels) (https://github.com/acme/app/issues/1235, until 2026-11-10): it may be fixed; take it out once the issue says so`,
132
+ ` skipped chat-control.spec.ts › opens the menu (1234, until 2026-11-10)`,
133
+ ` ci.green.notify is not set, so no ci.quarantine-passed was sent`,
134
+ ].join("\n"),
135
+ );
136
+ });
137
+
138
+ test("a dry run tells nothing, and events can be filtered out", async () => {
139
+ const send = vi.fn(async () => []);
140
+ const dry = await quarantineReport({ green: greenOf(NOTIFY), phase: "test", junit: [NEXTEST], commit: SHA, dryRun: true, sendNotify: send });
141
+ expect(send).not.toHaveBeenCalled();
142
+ expect(formatQuarantineReport(dry, greenOf(NOTIFY))).toContain("would tell ci.quarantine-passed: triggers::fires_once");
143
+ expect(() => parseDeclaration(JSON.stringify({ name: "a", schema: 1, members: [], ci: { green: { branch: "main", phases: { t: ["t"] }, require: ["t"], notify: { ...NOTIFY, events: ["ci.red", "ci.quarantine-passed"] } } } }), "chant.workspace.json")).not.toThrow();
144
+ });
145
+ });