@intentius/chant 0.124.62 → 0.124.63

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 (229) hide show
  1. package/dist/cli/handlers/approve.d.ts +18 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +142 -16
  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/release.d.ts +6 -4
  8. package/dist/cli/handlers/release.d.ts.map +1 -1
  9. package/dist/cli/handlers/release.js +13 -7
  10. package/dist/cli/main.d.ts.map +1 -1
  11. package/dist/cli/main.js +34 -5
  12. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  13. package/dist/cli/mcp/workspace-tools.js +2 -1
  14. package/dist/cli/parse-args.d.ts.map +1 -1
  15. package/dist/cli/parse-args.js +31 -0
  16. package/dist/cli/registry.d.ts +13 -1
  17. package/dist/cli/registry.d.ts.map +1 -1
  18. package/dist/config.d.ts +32 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/gate-decision.d.ts +1 -1
  21. package/dist/gate-decision.d.ts.map +1 -1
  22. package/dist/gate-decision.js +4 -2
  23. package/dist/gate-statement.schema.json +44 -0
  24. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  25. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  26. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  27. package/dist/lifecycle/gate-ledger.d.ts +17 -3
  28. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  29. package/dist/lifecycle/gate-seal.d.ts +39 -3
  30. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  31. package/dist/lifecycle/gate-seal.js +50 -10
  32. package/dist/lifecycle/gate-statement.d.ts +70 -0
  33. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  34. package/dist/lifecycle/gate-statement.js +74 -0
  35. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  36. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  37. package/dist/lifecycle/gate-webauthn.js +105 -0
  38. package/dist/lifecycle/git.d.ts +1 -1
  39. package/dist/lifecycle/git.d.ts.map +1 -1
  40. package/dist/lifecycle/git.js +24 -19
  41. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  42. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  43. package/dist/lifecycle/ledger-remote.js +42 -0
  44. package/dist/lifecycle/plan-stale.d.ts +76 -0
  45. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  46. package/dist/lifecycle/plan-stale.js +121 -0
  47. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  48. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  49. package/dist/lifecycle/publish-credentials.js +2 -0
  50. package/dist/lifecycle/publish-declaration.d.ts +87 -0
  51. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  52. package/dist/lifecycle/publish-declaration.js +87 -1
  53. package/dist/lifecycle/publish-forge.d.ts +5 -1
  54. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  55. package/dist/lifecycle/publish-forge.js +14 -4
  56. package/dist/lifecycle/publish-github.d.ts +69 -0
  57. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  58. package/dist/lifecycle/publish-github.js +153 -0
  59. package/dist/lifecycle/publish-homebrew.d.ts +66 -0
  60. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  61. package/dist/lifecycle/publish-homebrew.js +173 -0
  62. package/dist/lifecycle/publish-marketplace.d.ts +51 -0
  63. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  64. package/dist/lifecycle/publish-marketplace.js +254 -0
  65. package/dist/lifecycle/publish-targets.d.ts +6 -0
  66. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  67. package/dist/lifecycle/publish-targets.js +15 -0
  68. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  69. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  70. package/dist/lifecycle/publish-tauri.js +182 -0
  71. package/dist/lifecycle/release-publish.d.ts +5 -2
  72. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  73. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  74. package/dist/lifecycle/snapshot-store.js +17 -9
  75. package/dist/lifecycle/test-passkey.d.ts +25 -0
  76. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  77. package/dist/lifecycle/test-passkey.js +39 -0
  78. package/dist/notify.d.ts +23 -3
  79. package/dist/notify.d.ts.map +1 -1
  80. package/dist/notify.js +8 -2
  81. package/dist/notify.schema.json +12 -3
  82. package/dist/op/activities/activity-contracts.d.ts +4 -4
  83. package/dist/pr-forge.d.ts +20 -0
  84. package/dist/pr-forge.d.ts.map +1 -1
  85. package/dist/pr-forge.js +61 -2
  86. package/dist/release-floors.d.ts +1 -1
  87. package/dist/release-floors.js +1 -1
  88. package/dist/wave-runtime.mjs +331 -330
  89. package/dist/workspace/ci-builds.d.ts +21 -0
  90. package/dist/workspace/ci-builds.d.ts.map +1 -1
  91. package/dist/workspace/ci-builds.js +14 -0
  92. package/dist/workspace/ci-green.d.ts +45 -2
  93. package/dist/workspace/ci-green.d.ts.map +1 -1
  94. package/dist/workspace/ci-green.js +124 -5
  95. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  96. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  97. package/dist/workspace/ci-quarantine-report.js +205 -0
  98. package/dist/workspace/ci-quarantine.d.ts +73 -0
  99. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine.js +171 -0
  101. package/dist/workspace/ci-serve.d.ts.map +1 -1
  102. package/dist/workspace/ci-serve.js +7 -4
  103. package/dist/workspace/class-data.d.ts +3 -1
  104. package/dist/workspace/class-data.d.ts.map +1 -1
  105. package/dist/workspace/class-data.js +4 -1
  106. package/dist/workspace/declaration.d.ts +45 -2
  107. package/dist/workspace/declaration.d.ts.map +1 -1
  108. package/dist/workspace/declaration.js +45 -2
  109. package/dist/workspace/declaration.schema.json +51 -3
  110. package/dist/workspace/forge-work.d.ts +76 -0
  111. package/dist/workspace/forge-work.d.ts.map +1 -0
  112. package/dist/workspace/forge-work.js +160 -0
  113. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  114. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  115. package/dist/workspace/identity-gate-rule.js +5 -7
  116. package/dist/workspace/identity.d.ts +3 -2
  117. package/dist/workspace/identity.d.ts.map +1 -1
  118. package/dist/workspace/identity.js +6 -3
  119. package/dist/workspace/intent-cli.d.ts +3 -2
  120. package/dist/workspace/intent-cli.d.ts.map +1 -1
  121. package/dist/workspace/intent-cli.js +26 -5
  122. package/dist/workspace/intent-record.d.ts +3 -0
  123. package/dist/workspace/intent-record.d.ts.map +1 -1
  124. package/dist/workspace/intent-record.schema.json +32 -0
  125. package/dist/workspace/intent.d.ts +9 -0
  126. package/dist/workspace/intent.d.ts.map +1 -1
  127. package/dist/workspace/intent.js +3 -0
  128. package/dist/workspace/intent.schema.json +32 -0
  129. package/dist/workspace/kind-readers.d.ts.map +1 -1
  130. package/dist/workspace/kind-readers.js +2 -1
  131. package/dist/workspace/kinds.d.ts +6 -1
  132. package/dist/workspace/kinds.d.ts.map +1 -1
  133. package/dist/workspace/kinds.js +8 -3
  134. package/dist/workspace/plan-stale.schema.json +286 -0
  135. package/dist/workspace/release-candidates.d.ts +33 -6
  136. package/dist/workspace/release-candidates.d.ts.map +1 -1
  137. package/dist/workspace/release-candidates.js +49 -20
  138. package/dist/workspace/release-candidates.schema.json +48 -2
  139. package/dist/workspace/trust/policy.d.ts +10 -0
  140. package/dist/workspace/trust/policy.d.ts.map +1 -1
  141. package/dist/workspace/trust/policy.js +19 -1
  142. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  143. package/dist/workspace/trust/run-commits.js +2 -1
  144. package/dist/workspace/trust/seal.d.ts.map +1 -1
  145. package/dist/workspace/trust/seal.js +34 -3
  146. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  147. package/dist/workspace/trust/trust-files.js +6 -1
  148. package/package.json +2 -1
  149. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  150. package/src/cli/handlers/approve.ts +174 -16
  151. package/src/cli/handlers/plan.ts +74 -0
  152. package/src/cli/handlers/release.ts +12 -7
  153. package/src/cli/main.ts +34 -5
  154. package/src/cli/mcp/workspace-tools.ts +2 -1
  155. package/src/cli/parse-args.ts +24 -0
  156. package/src/cli/registry.ts +13 -1
  157. package/src/gate-decision-bundle.test.ts +4 -2
  158. package/src/gate-decision.ts +11 -2
  159. package/src/gate-statement.schema.json +44 -0
  160. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  161. package/src/lifecycle/gate-ledger.ts +17 -3
  162. package/src/lifecycle/gate-seal.ts +62 -9
  163. package/src/lifecycle/gate-statement.ts +107 -0
  164. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  165. package/src/lifecycle/gate-webauthn.ts +133 -0
  166. package/src/lifecycle/git.ts +23 -19
  167. package/src/lifecycle/ledger-remote.test.ts +183 -0
  168. package/src/lifecycle/ledger-remote.ts +46 -0
  169. package/src/lifecycle/plan-stale.test.ts +150 -0
  170. package/src/lifecycle/plan-stale.ts +173 -0
  171. package/src/lifecycle/publish-credentials.ts +2 -0
  172. package/src/lifecycle/publish-declaration.ts +93 -1
  173. package/src/lifecycle/publish-forge.ts +15 -4
  174. package/src/lifecycle/publish-github.ts +174 -0
  175. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  176. package/src/lifecycle/publish-homebrew.ts +187 -0
  177. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  178. package/src/lifecycle/publish-marketplace.ts +259 -0
  179. package/src/lifecycle/publish-target-context.test.ts +2 -2
  180. package/src/lifecycle/publish-targets.test.ts +23 -0
  181. package/src/lifecycle/publish-targets.ts +15 -0
  182. package/src/lifecycle/publish-tauri.test.ts +163 -0
  183. package/src/lifecycle/publish-tauri.ts +199 -0
  184. package/src/lifecycle/release-publish.ts +5 -3
  185. package/src/lifecycle/snapshot-store.ts +16 -9
  186. package/src/lifecycle/test-passkey.ts +55 -0
  187. package/src/notify-bundle.test.ts +3 -1
  188. package/src/notify.schema.json +12 -3
  189. package/src/notify.ts +20 -3
  190. package/src/override-gate-bundle.test.ts +2 -0
  191. package/src/pr-forge-bundle.test.ts +2 -2
  192. package/src/pr-forge.test.ts +38 -0
  193. package/src/pr-forge.ts +68 -5
  194. package/src/release-floors.ts +1 -1
  195. package/src/stage-hooks-bundle.test.ts +2 -0
  196. package/src/wave-runtime-bundle.test.ts +3 -2
  197. package/src/workspace/ci-builds.ts +27 -0
  198. package/src/workspace/ci-green-stale.test.ts +193 -0
  199. package/src/workspace/ci-green.ts +138 -6
  200. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  201. package/src/workspace/ci-quarantine-report.ts +235 -0
  202. package/src/workspace/ci-quarantine.test.ts +161 -0
  203. package/src/workspace/ci-quarantine.ts +189 -0
  204. package/src/workspace/ci-serve.ts +7 -4
  205. package/src/workspace/class-data.ts +5 -1
  206. package/src/workspace/declaration.schema.json +51 -3
  207. package/src/workspace/declaration.test.ts +1 -0
  208. package/src/workspace/declaration.ts +88 -5
  209. package/src/workspace/forge-work.test.ts +143 -0
  210. package/src/workspace/forge-work.ts +195 -0
  211. package/src/workspace/identity-gate-rule.ts +6 -8
  212. package/src/workspace/identity.ts +6 -3
  213. package/src/workspace/intent-cli.ts +24 -5
  214. package/src/workspace/intent-record.schema.json +32 -0
  215. package/src/workspace/intent-record.ts +3 -0
  216. package/src/workspace/intent.schema.json +32 -0
  217. package/src/workspace/intent.ts +10 -0
  218. package/src/workspace/kind-readers.ts +2 -1
  219. package/src/workspace/kinds.test.ts +13 -0
  220. package/src/workspace/kinds.ts +12 -3
  221. package/src/workspace/plan-stale.schema.json +286 -0
  222. package/src/workspace/release-candidates.schema.json +48 -2
  223. package/src/workspace/release-candidates.test.ts +77 -4
  224. package/src/workspace/release-candidates.ts +62 -20
  225. package/src/workspace/trust/policy.ts +24 -1
  226. package/src/workspace/trust/run-commits.ts +2 -1
  227. package/src/workspace/trust/seal.ts +35 -3
  228. package/src/workspace/trust/trust-files.test.ts +5 -0
  229. package/src/workspace/trust/trust-files.ts +15 -1
@@ -64,7 +64,8 @@ describe("the wave-job runtime bundle (#3896)", () => {
64
64
  test("carries its version and stays small", () => {
65
65
  expect(built.text).toContain('"workspace points"');
66
66
  expect(built.text.startsWith("#!/usr/bin/env node\n")).toBe(true);
67
- // About 1.45 MB minified today (440 KB gzipped), zod's inlined schemas about 300 KB of it.
68
- expect(built.bytes).toBeLessThan(2 * 1024 * 1024);
67
+ // About 2.0 MB minified at #4678, which took it past 2 MiB; the declaration schema and zod's inlined
68
+ // schemas are a large part of it. The cap catches the 33 MB of the left-out packages, so 2.5 MiB keeps that.
69
+ expect(built.bytes).toBeLessThan(2.5 * 1024 * 1024);
69
70
  });
70
71
  });
@@ -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,14 @@ 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 { NEXT_RELEASE } from "../release-floors";
67
+ 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
68
  import { dispatchableWorkflows, MERGE_QUEUE_VERDICT_JOB, readWorkflowSources } from "./ci-green-workflow";
67
69
  import { signOpRunRecord, verifyOpRunStatement } from "./trust/op-run-statement";
68
70
  import type { ReasonCode } from "./reason-codes";
@@ -83,6 +85,10 @@ export const CI_REVOKED_TAG_PREFIX = "ci/revoked/";
83
85
  export const CI_GREEN_LANES_FLOOR = "0.124.61";
84
86
  /** The first chant whose tick sends `ci.red`, `ci.culprit` and `ci.green` through `ci.green.notify` (#4645). */
85
87
  export const CI_TICK_NOTIFY_FLOOR = "0.124.61";
88
+ /** The first chant whose tick sends `ci.stale` after `ci.green.notify.staleAfter` hours without a green commit (#4678). */
89
+ export const CI_STALE_NOTIFY_FLOOR = NEXT_RELEASE;
90
+ /** How many first-parent commits the tick reads back looking for the newest green one, for `ci.stale` (#4678). */
91
+ export const CI_STALE_WALK = 200;
86
92
  /** The first chant that writes a merge queue's trigger and verdict job, and reads `chant ci verdict` (#4644). */
87
93
  export const CI_MERGE_QUEUE_FLOOR = "0.124.61";
88
94
 
@@ -806,7 +812,35 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
806
812
  // #4645: what to tell people, decided from the records this tick writes. Without records a tick can't
807
813
  // remember what it sent, so it sends nothing rather than the same event every time.
808
814
  const canRecord = ledgerOk && !ledgerRecordingOff();
809
- const events = green.notify && canRecord ? tickEvents({ green, planned, records, builds, requests, now }) : [];
815
+ const events: { fields: NotifyFields; mark?: ReturnType<typeof tickEvents>[number]["mark"]; stale?: CiBranchRecord["stale"] }[] =
816
+ green.notify && canRecord ? tickEvents({ green, planned, records, builds, requests, now }) : [];
817
+ // #4678: ci.stale, from the tags as this tick leaves them, and the ci.green that ends its stretch.
818
+ const branchBefore = green.notify && canRecord ? readCiBranchRecord(top, green.branch) : undefined;
819
+ let branchAfter = branchBefore;
820
+ if (green.notify && canRecord && (green.notify.staleAfter !== undefined || (branchBefore?.stale && !branchBefore.stale.ended))) {
821
+ const greenNow = new Set(tags.green.keys());
822
+ const revokedNow = new Set(tags.revoked.keys());
823
+ for (const c of planned) {
824
+ if (c.made?.tag === `${CI_GREEN_TAG_PREFIX}${c.sha}`) greenNow.add(c.sha);
825
+ if (c.made?.tag === `${CI_REVOKED_TAG_PREFIX}${c.sha}`) revokedNow.add(c.sha);
826
+ }
827
+ const inWindow = new Set(planned.map((c) => c.sha));
828
+ const answering = events.find((e) => e.fields.event === "ci.green");
829
+ const stale = staleEvents({
830
+ green,
831
+ walk: firstParents(top, tracking, CI_STALE_WALK),
832
+ isGreen: (sha) => greenNow.has(sha) && !revokedNow.has(sha),
833
+ judged: (sha) => inWindow.has(sha) || records.has(sha),
834
+ stale: branchBefore?.stale,
835
+ answering: answering?.fields.ci!.commit,
836
+ now,
837
+ });
838
+ if (stale.endedBy && answering) {
839
+ answering.fields = { ...answering.fields, ci: { ...answering.fields.ci!, since: stale.endedBy.since } };
840
+ answering.stale = stale.endedBy;
841
+ }
842
+ events.push(...stale.events);
843
+ }
810
844
  const notified: TickResult["notified"] = [];
811
845
  const marks = new Map<string, NonNullable<CiRecord["notified"]>>();
812
846
  for (const e of events) {
@@ -823,12 +857,15 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
823
857
  continue;
824
858
  }
825
859
  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 });
860
+ if (e.mark) marks.set(e.mark.sha, { ...(marks.get(e.mark.sha) ?? {}), ...e.mark.notified });
861
+ if (e.stale) branchAfter = { schema: 1, branch: green.branch, stale: e.stale };
827
862
  }
828
863
  let recorded: string[] = [];
829
864
  if (!req.dryRun) {
830
865
  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 }) : [];
866
+ recorded = canRecord
867
+ ? await writeRecords({ top, green, planned, records, builds, requests: asked.live, dispatched: asked.dispatched, now, warnings, notified: marks, branchRecord: branchAfter !== branchBefore ? branchAfter : undefined })
868
+ : [];
832
869
  }
833
870
  return {
834
871
  branch: green.branch,
@@ -909,6 +946,97 @@ export function tickEvents(input: {
909
946
  return out;
910
947
  }
911
948
 
949
+ /** A first-parent commit and when it was committed, ISO 8601. */
950
+ export interface StaleWalkCommit {
951
+ sha: string;
952
+ committed: string;
953
+ }
954
+
955
+ /** `ref`'s first-parent commits, newest first, `max` at most, with their commit times. */
956
+ function firstParents(top: string, ref: string, max: number): StaleWalkCommit[] {
957
+ return git(top, ["log", "--first-parent", `--max-count=${max}`, "--format=%H %ct", ref])
958
+ .split("\n")
959
+ .filter(Boolean)
960
+ .map((line) => line.split(" "))
961
+ .map(([sha, ct]) => ({ sha: sha!, committed: iso(new Date(Number(ct) * 1000)) }));
962
+ }
963
+
964
+ /**
965
+ * `ci.stale` and the `ci.green` that ends its stretch (#4678). The red
966
+ * stretch is the first-parent commits above the newest green one in `walk`;
967
+ * with no green one there, the commits down to the oldest the tick judged,
968
+ * so commits from before the tick ran don't count. When the stretch's
969
+ * oldest commit (`since`) was committed `staleAfter` hours ago or more and
970
+ * the branch's record has no open stretch, it sends `ci.stale` and opens
971
+ * one. An open stretch whose `since` is no longer above the newest green
972
+ * commit has ended: the `ci.green` the tick sends anyway (`answering`)
973
+ * names `since` and closes it (`endedBy`), or else this sends a `ci.green`
974
+ * for the newest green commit. Each event carries the branch record's
975
+ * `stale` as it is once the event is told. Pure.
976
+ */
977
+ export function staleEvents(input: {
978
+ green: CiGreen;
979
+ /** The branch's first-parent commits, newest first. */
980
+ walk: readonly StaleWalkCommit[];
981
+ /** A green tag, this tick's included, and no revoked one. */
982
+ isGreen: (sha: string) => boolean;
983
+ /** The tick judged it: it is in the window or has a record. */
984
+ judged: (sha: string) => boolean;
985
+ /** The branch record's `stale`. */
986
+ stale: CiBranchRecord["stale"];
987
+ /** The commit of the `ci.green` the tick sends anyway, if it does. */
988
+ answering?: string;
989
+ now: Date;
990
+ }): { events: { fields: NotifyFields; stale: NonNullable<CiBranchRecord["stale"]> }[]; endedBy?: NonNullable<CiBranchRecord["stale"]> } {
991
+ const { green, walk, now } = input;
992
+ const branch = green.branch;
993
+ const at = walk.findIndex((c) => input.isGreen(c.sha));
994
+ const lastGreen = at >= 0 ? walk[at]!.sha : null;
995
+ let end = at;
996
+ if (at < 0) for (let i = 0; i < walk.length; i++) if (input.judged(walk[i]!.sha)) end = i + 1;
997
+ const stretch = walk.slice(0, Math.max(end, 0));
998
+ const out: ReturnType<typeof staleEvents> = { events: [] };
999
+ const short = (sha: string) => sha.slice(0, 12);
1000
+ let open = input.stale && !input.stale.ended ? input.stale : undefined;
1001
+ if (open && lastGreen && !stretch.some((c) => c.sha === open!.since)) {
1002
+ const ended = { ...open, ended: input.answering ?? lastGreen };
1003
+ if (input.answering) out.endedBy = ended;
1004
+ else {
1005
+ out.events.push({
1006
+ fields: {
1007
+ source: "chant",
1008
+ event: "ci.green",
1009
+ summary: `${branch} is green again at ${short(lastGreen)}, after no green commit since ${short(open.since)}`,
1010
+ targets: [],
1011
+ ci: { branch, commit: lastGreen, since: open.since },
1012
+ run: { commit: lastGreen },
1013
+ },
1014
+ stale: ended,
1015
+ });
1016
+ }
1017
+ open = undefined;
1018
+ }
1019
+ const staleAfter = green.notify?.staleAfter;
1020
+ const since = stretch.at(-1);
1021
+ if (open || staleAfter === undefined || !since) return out;
1022
+ const age = now.getTime() - Date.parse(since.committed);
1023
+ if (age < staleAfter * 3_600_000) return out;
1024
+ const hours = Math.floor(age / 3_600_000);
1025
+ const tip = walk[0]!.sha;
1026
+ out.events.push({
1027
+ fields: {
1028
+ source: "chant",
1029
+ event: "ci.stale",
1030
+ 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)}` : ""}`,
1031
+ targets: [],
1032
+ ci: { branch, commit: tip, since: since.sha, ...(lastGreen ? { lastGreen } : {}), hours },
1033
+ run: { commit: tip },
1034
+ },
1035
+ stale: { since: since.sha, lastGreen, at: iso(now) },
1036
+ });
1037
+ return out;
1038
+ }
1039
+
912
1040
  /** 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
1041
  function tickEventEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
914
1042
  const { GITHUB_RUN_ID: _r, CI_JOB_URL: _j, CI_PIPELINE_URL: _p, GITHUB_SHA: _s, CI_COMMIT_SHA: _c, ...rest } = env;
@@ -1015,6 +1143,8 @@ async function writeRecords(input: {
1015
1143
  warnings: string[];
1016
1144
  /** What the tick told people this time (#4645), merged into each commit's `notified`. */
1017
1145
  notified?: ReadonlyMap<string, NonNullable<CiRecord["notified"]>>;
1146
+ /** The branch's record, when what it told about a stretch changed (#4678). */
1147
+ branchRecord?: CiBranchRecord;
1018
1148
  }): Promise<string[]> {
1019
1149
  const { top, green, planned, records, builds, requests, now, warnings } = input;
1020
1150
  const writes: { path: string; content: string }[] = [];
@@ -1035,6 +1165,7 @@ async function writeRecords(input: {
1035
1165
  if (inWindow.has(sha) || r.state !== "pending") continue;
1036
1166
  writes.push({ path: recordPath(sha), content: `${JSON.stringify(agedOut(r, now), null, 2)}\n` });
1037
1167
  }
1168
+ if (input.branchRecord) writes.push({ path: branchRecordPath(input.branchRecord.branch), content: `${JSON.stringify(input.branchRecord, null, 2)}\n` });
1038
1169
  if (writes.length === 0) return [];
1039
1170
  for (let attempt = 0; attempt < 2; attempt++) {
1040
1171
  try {
@@ -1467,7 +1598,8 @@ export type CiBaseDocument =
1467
1598
  * job that failed. A commit with no record (outside the tick's window)
1468
1599
  * counts when it has a green tag and no revoked one, as `ci last-green`
1469
1600
  * 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.
1601
+ * on `origin/chant/lifecycle` (or the remote `CHANT_LIFECYCLE_REMOTE`
1602
+ * names) when there is no local branch, and the tags.
1471
1603
  */
1472
1604
  export function ciBase(req: { cwd: string; from?: string; branch?: string; phase?: string; lane?: string; remote?: string }): CiBaseDocument {
1473
1605
  const head = { $schema: CI_LAST_GREEN_SCHEMA_ID, contract: CI_LAST_GREEN_CONTRACT_VERSION, chant: readerVersion() };
@@ -1487,7 +1619,7 @@ export function ciBase(req: { cwd: string; from?: string; branch?: string; phase
1487
1619
  }
1488
1620
  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
1621
  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`;
1622
+ const ledger = tryGit(top, ["rev-parse", "--verify", "--quiet", CI_LEDGER_REF]) !== null ? CI_LEDGER_REF : `refs/remotes/${lifecycleRemoteOverride() ?? req.remote ?? "origin"}/chant/lifecycle`;
1491
1623
  const records = readCiRecords(top, ledger);
1492
1624
  const phases = req.phase !== undefined ? [req.phase] : (lane?.require ?? green.require);
1493
1625
  const builtHere = (r: CiRecord) =>
@@ -0,0 +1,146 @@
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 { NEXT_RELEASE } from "../release-floors";
11
+ import { CI_QUARANTINE_NOTIFY_FLOOR, formatQuarantineReport, parseJUnit, quarantineReport } from "./ci-quarantine-report";
12
+ import { parseDeclaration, type CiGreen } from "./declaration";
13
+
14
+ const SHA = "0123456789abcdef0123456789abcdef01234567";
15
+
16
+ const NEXTEST = `<?xml version="1.0" encoding="UTF-8"?>
17
+ <testsuites name="nextest-run" tests="4" failures="1" errors="0">
18
+ <testsuite name="arugulad::integration" tests="3" disabled="0" errors="0" failures="1">
19
+ <testcase name="ssh::ssh_installs_runs" classname="arugulad::integration" timestamp="2026-11-01T07:47:00Z" time="12.1">
20
+ <system-out><![CDATA[ok <not a tag> </testcase> ]]></system-out>
21
+ </testcase>
22
+ <testcase name="reboot::comes_back" classname="arugulad::integration" time="3.0">
23
+ <flakyFailure message="code=101" type="test failure"><![CDATA[thread panicked]]></flakyFailure>
24
+ </testcase>
25
+ <testcase name="reboot::keeps_state" classname="arugulad::integration" time="3.0">
26
+ <failure message="code=101" type="test failure">assert &lt;left&gt; == right</failure>
27
+ <rerunFailure message="code=101" type="test failure"/>
28
+ </testcase>
29
+ </testsuite>
30
+ <testsuite name="arugula-platform" tests="1">
31
+ <testcase name="triggers::fires_once" classname="arugula-platform" time="0.2"/>
32
+ </testsuite>
33
+ </testsuites>`;
34
+
35
+ const PLAYWRIGHT = `<testsuites id="" name="" tests="3" failures="0" skipped="1">
36
+ <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">
37
+ <testcase name="composer › polish: edits the last message (and Esc cancels)" classname="chat-control.spec.ts" time="2.1">
38
+ </testcase>
39
+ <testcase name="opens the menu" classname="chat-control.spec.ts" time="0">
40
+ <skipped>
41
+ </skipped>
42
+ </testcase>
43
+ </testsuite>
44
+ <testsuite name="chat-control.spec.ts" hostname="webkit" tests="1">
45
+ <testcase name="composer › polish: edits the last message (and Esc cancels)" classname="chat-control.spec.ts" time="2.4"></testcase>
46
+ </testsuite>
47
+ </testsuites>`;
48
+
49
+ const entry = (test: string, extra: Record<string, string> = {}) => ({ test, issue: "1234", until: "2026-11-10", why: "Flaky.", ...extra });
50
+
51
+ function greenOf(notify?: unknown): CiGreen {
52
+ const ws = {
53
+ name: "acme",
54
+ schema: 1,
55
+ members: [],
56
+ ci: {
57
+ green: {
58
+ branch: "main",
59
+ phases: { test: ["test (*)"], e2e: ["e2e"] },
60
+ require: ["test", "e2e"],
61
+ ...(notify !== undefined ? { notify } : {}),
62
+ quarantine: {
63
+ phases: {
64
+ 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")],
65
+ 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" })],
66
+ },
67
+ },
68
+ },
69
+ },
70
+ };
71
+ return parseDeclaration(JSON.stringify(ws), "chant.workspace.json").ci!.green!;
72
+ }
73
+
74
+ const NOTIFY = { webhook: "HOOK", key: "HOOK_KEY" };
75
+
76
+ describe("ci quarantine report (#4677)", () => {
77
+ test("its floor is the next release", () => {
78
+ expect(CI_QUARANTINE_NOTIFY_FLOOR).toBe(NEXT_RELEASE);
79
+ });
80
+
81
+ test("reads nextest's and Playwright's JUnit, CDATA and entities included", () => {
82
+ expect(parseJUnit(NEXTEST).map((c) => [c.suite, c.name, c.outcome])).toEqual([
83
+ ["arugulad::integration", "ssh::ssh_installs_runs", "passed"],
84
+ ["arugulad::integration", "reboot::comes_back", "flaky"],
85
+ ["arugulad::integration", "reboot::keeps_state", "failed"],
86
+ ["arugula-platform", "triggers::fires_once", "passed"],
87
+ ]);
88
+ expect(parseJUnit(PLAYWRIGHT).map((c) => c.outcome)).toEqual(["passed", "skipped", "passed"]);
89
+ expect(() => parseJUnit("<html></html>")).toThrow(/not JUnit XML/);
90
+ });
91
+
92
+ test("each entry's outcome; a test that passed only on a retry is flaky, not passed", async () => {
93
+ const send = vi.fn(async () => [{ target: "webhook" as const, ok: true, detail: "delivered" }]);
94
+ const r = await quarantineReport({ green: greenOf(NOTIFY), phase: "test", junit: [NEXTEST], commit: SHA, env: { HOOK: "https://hooks.example/x", HOOK_KEY: "k" }, sendNotify: send });
95
+ expect(r.results.map((x) => [x.entry.test, x.outcome, x.cases])).toEqual([
96
+ ["arugulad::integration ssh::ssh_installs_runs", "passed", 1],
97
+ ["arugulad::integration reboot::comes_back", "flaky", 1],
98
+ ["reboot::keeps_state", "failed", 1],
99
+ ["triggers::fires_once", "passed", 1],
100
+ ["other::gone", "not-run", 0],
101
+ ]);
102
+ expect(r.told).toEqual([
103
+ { name: "arugulad::integration ssh::ssh_installs_runs", sent: true },
104
+ { name: "triggers::fires_once", sent: true },
105
+ ]);
106
+ expect(send).toHaveBeenCalledTimes(2);
107
+ const event = (send.mock.calls[0] as unknown as [unknown, NotifyEvent])[1];
108
+ expect(event).toMatchObject({
109
+ event: "ci.quarantine-passed",
110
+ source: "chant",
111
+ targets: ["arugulad::integration ssh::ssh_installs_runs"],
112
+ ci: { branch: "main", commit: SHA, phase: "test", quarantine: { test: "arugulad::integration ssh::ssh_installs_runs", issue: "1234", until: "2026-11-10" } },
113
+ run: { commit: SHA },
114
+ });
115
+ const second = (send.mock.calls[1] as unknown as [unknown, NotifyEvent])[1];
116
+ expect(second.id).not.toBe(event.id);
117
+ const ajv = new Ajv2020({ strict: false });
118
+ expect(ajv.validate(notifySchema, event)).toBe(true);
119
+ expect(notifyHeadline(event)).toContain("quarantined arugulad::integration ssh::ssh_installs_runs passed in phase test's scheduled run at 0123456789ab");
120
+ });
121
+
122
+ test("a Playwright test passes when every project's case passed, and its describes may be left out", async () => {
123
+ const r = await quarantineReport({ green: greenOf(), phase: "e2e", junit: [PLAYWRIGHT], commit: SHA });
124
+ expect(r.results.map((x) => [x.entry.test, x.outcome, x.cases])).toEqual([
125
+ ["polish: edits the last message (and Esc cancels)", "passed", 2],
126
+ ["opens the menu", "skipped", 1],
127
+ ]);
128
+ expect(r.told).toEqual([]);
129
+ expect(formatQuarantineReport(r, greenOf())).toBe(
130
+ [
131
+ `quarantine of phase e2e at 0123456789ab: 2 tests`,
132
+ ` 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`,
133
+ ` skipped chat-control.spec.ts › opens the menu (1234, until 2026-11-10)`,
134
+ ` ci.green.notify is not set, so no ci.quarantine-passed was sent`,
135
+ ].join("\n"),
136
+ );
137
+ });
138
+
139
+ test("a dry run tells nothing, and events can be filtered out", async () => {
140
+ const send = vi.fn(async () => []);
141
+ const dry = await quarantineReport({ green: greenOf(NOTIFY), phase: "test", junit: [NEXTEST], commit: SHA, dryRun: true, sendNotify: send });
142
+ expect(send).not.toHaveBeenCalled();
143
+ expect(formatQuarantineReport(dry, greenOf(NOTIFY))).toContain("would tell ci.quarantine-passed: triggers::fires_once");
144
+ 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();
145
+ });
146
+ });