@intentius/chant 0.124.61 → 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 (234) 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-workflow.d.ts +2 -0
  93. package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
  94. package/dist/workspace/ci-green-workflow.js +9 -0
  95. package/dist/workspace/ci-green.d.ts +45 -2
  96. package/dist/workspace/ci-green.d.ts.map +1 -1
  97. package/dist/workspace/ci-green.js +127 -9
  98. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  99. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine-report.js +205 -0
  101. package/dist/workspace/ci-quarantine.d.ts +73 -0
  102. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  103. package/dist/workspace/ci-quarantine.js +171 -0
  104. package/dist/workspace/ci-serve.d.ts.map +1 -1
  105. package/dist/workspace/ci-serve.js +7 -4
  106. package/dist/workspace/class-data.d.ts +3 -1
  107. package/dist/workspace/class-data.d.ts.map +1 -1
  108. package/dist/workspace/class-data.js +4 -1
  109. package/dist/workspace/declaration.d.ts +45 -2
  110. package/dist/workspace/declaration.d.ts.map +1 -1
  111. package/dist/workspace/declaration.js +45 -2
  112. package/dist/workspace/declaration.schema.json +51 -3
  113. package/dist/workspace/forge-work.d.ts +76 -0
  114. package/dist/workspace/forge-work.d.ts.map +1 -0
  115. package/dist/workspace/forge-work.js +160 -0
  116. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  117. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  118. package/dist/workspace/identity-gate-rule.js +5 -7
  119. package/dist/workspace/identity.d.ts +3 -2
  120. package/dist/workspace/identity.d.ts.map +1 -1
  121. package/dist/workspace/identity.js +6 -3
  122. package/dist/workspace/intent-cli.d.ts +3 -2
  123. package/dist/workspace/intent-cli.d.ts.map +1 -1
  124. package/dist/workspace/intent-cli.js +26 -5
  125. package/dist/workspace/intent-record.d.ts +3 -0
  126. package/dist/workspace/intent-record.d.ts.map +1 -1
  127. package/dist/workspace/intent-record.schema.json +32 -0
  128. package/dist/workspace/intent.d.ts +9 -0
  129. package/dist/workspace/intent.d.ts.map +1 -1
  130. package/dist/workspace/intent.js +3 -0
  131. package/dist/workspace/intent.schema.json +32 -0
  132. package/dist/workspace/kind-readers.d.ts.map +1 -1
  133. package/dist/workspace/kind-readers.js +2 -1
  134. package/dist/workspace/kinds.d.ts +6 -1
  135. package/dist/workspace/kinds.d.ts.map +1 -1
  136. package/dist/workspace/kinds.js +8 -3
  137. package/dist/workspace/plan-stale.schema.json +286 -0
  138. package/dist/workspace/release-candidates.d.ts +33 -6
  139. package/dist/workspace/release-candidates.d.ts.map +1 -1
  140. package/dist/workspace/release-candidates.js +49 -20
  141. package/dist/workspace/release-candidates.schema.json +48 -2
  142. package/dist/workspace/trust/policy.d.ts +10 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +19 -1
  145. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  146. package/dist/workspace/trust/run-commits.js +2 -1
  147. package/dist/workspace/trust/seal.d.ts.map +1 -1
  148. package/dist/workspace/trust/seal.js +34 -3
  149. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  150. package/dist/workspace/trust/trust-files.js +6 -1
  151. package/package.json +2 -1
  152. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  153. package/src/cli/handlers/approve.ts +174 -16
  154. package/src/cli/handlers/plan.ts +74 -0
  155. package/src/cli/handlers/release.ts +12 -7
  156. package/src/cli/main.ts +34 -5
  157. package/src/cli/mcp/workspace-tools.ts +2 -1
  158. package/src/cli/parse-args.ts +24 -0
  159. package/src/cli/registry.ts +13 -1
  160. package/src/gate-decision-bundle.test.ts +4 -2
  161. package/src/gate-decision.ts +11 -2
  162. package/src/gate-statement.schema.json +44 -0
  163. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  164. package/src/lifecycle/gate-ledger.ts +17 -3
  165. package/src/lifecycle/gate-seal.ts +62 -9
  166. package/src/lifecycle/gate-statement.ts +107 -0
  167. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  168. package/src/lifecycle/gate-webauthn.ts +133 -0
  169. package/src/lifecycle/git.ts +23 -19
  170. package/src/lifecycle/ledger-remote.test.ts +183 -0
  171. package/src/lifecycle/ledger-remote.ts +46 -0
  172. package/src/lifecycle/plan-stale.test.ts +150 -0
  173. package/src/lifecycle/plan-stale.ts +173 -0
  174. package/src/lifecycle/publish-credentials.ts +2 -0
  175. package/src/lifecycle/publish-declaration.ts +93 -1
  176. package/src/lifecycle/publish-forge.ts +15 -4
  177. package/src/lifecycle/publish-github.ts +174 -0
  178. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  179. package/src/lifecycle/publish-homebrew.ts +187 -0
  180. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  181. package/src/lifecycle/publish-marketplace.ts +259 -0
  182. package/src/lifecycle/publish-target-context.test.ts +2 -2
  183. package/src/lifecycle/publish-targets.test.ts +23 -0
  184. package/src/lifecycle/publish-targets.ts +15 -0
  185. package/src/lifecycle/publish-tauri.test.ts +163 -0
  186. package/src/lifecycle/publish-tauri.ts +199 -0
  187. package/src/lifecycle/release-publish.ts +5 -3
  188. package/src/lifecycle/snapshot-store.ts +16 -9
  189. package/src/lifecycle/test-passkey.ts +55 -0
  190. package/src/notify-bundle.test.ts +3 -1
  191. package/src/notify.schema.json +12 -3
  192. package/src/notify.ts +20 -3
  193. package/src/override-gate-bundle.test.ts +2 -0
  194. package/src/pr-forge-bundle.test.ts +2 -2
  195. package/src/pr-forge.test.ts +38 -0
  196. package/src/pr-forge.ts +68 -5
  197. package/src/release-floors.ts +1 -1
  198. package/src/stage-hooks-bundle.test.ts +2 -0
  199. package/src/wave-runtime-bundle.test.ts +3 -2
  200. package/src/workspace/ci-builds.ts +27 -0
  201. package/src/workspace/ci-green-stale.test.ts +193 -0
  202. package/src/workspace/ci-green-workflow.test.ts +9 -0
  203. package/src/workspace/ci-green-workflow.ts +9 -0
  204. package/src/workspace/ci-green.ts +141 -10
  205. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  206. package/src/workspace/ci-quarantine-report.ts +235 -0
  207. package/src/workspace/ci-quarantine.test.ts +161 -0
  208. package/src/workspace/ci-quarantine.ts +189 -0
  209. package/src/workspace/ci-serve.ts +7 -4
  210. package/src/workspace/class-data.ts +5 -1
  211. package/src/workspace/declaration.schema.json +51 -3
  212. package/src/workspace/declaration.test.ts +1 -0
  213. package/src/workspace/declaration.ts +88 -5
  214. package/src/workspace/forge-work.test.ts +143 -0
  215. package/src/workspace/forge-work.ts +195 -0
  216. package/src/workspace/identity-gate-rule.ts +6 -8
  217. package/src/workspace/identity.ts +6 -3
  218. package/src/workspace/intent-cli.ts +24 -5
  219. package/src/workspace/intent-record.schema.json +32 -0
  220. package/src/workspace/intent-record.ts +3 -0
  221. package/src/workspace/intent.schema.json +32 -0
  222. package/src/workspace/intent.ts +10 -0
  223. package/src/workspace/kind-readers.ts +2 -1
  224. package/src/workspace/kinds.test.ts +13 -0
  225. package/src/workspace/kinds.ts +12 -3
  226. package/src/workspace/plan-stale.schema.json +286 -0
  227. package/src/workspace/release-candidates.schema.json +48 -2
  228. package/src/workspace/release-candidates.test.ts +77 -4
  229. package/src/workspace/release-candidates.ts +62 -20
  230. package/src/workspace/trust/policy.ts +24 -1
  231. package/src/workspace/trust/run-commits.ts +2 -1
  232. package/src/workspace/trust/seal.ts +35 -3
  233. package/src/workspace/trust/trust-files.test.ts +5 -0
  234. package/src/workspace/trust/trust-files.ts +15 -1
@@ -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
+ });
@@ -0,0 +1,235 @@
1
+ /**
2
+ * The quarantine's scheduled run (#4677): what became of each quarantined
3
+ * test, read from the run's JUnit XML, and `ci.quarantine-passed` through
4
+ * `ci.green.notify` for each one that passed, so someone can take it out.
5
+ *
6
+ * ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]
7
+ *
8
+ * nextest (`[profile.<p>.junit]`), Playwright (`--reporter=junit`) and most
9
+ * other runners write JUnit XML. A test counts as passed only when every
10
+ * case of it passed on its first try: one nextest marks flaky (it failed,
11
+ * then passed on a retry) is still flaky. The report gates nothing: it exits
12
+ * 0 whatever the tests did, and 1 only when it can't read what it was given.
13
+ *
14
+ * The event is sent on every scheduled run the test passes in, with an id
15
+ * made from the test and the commit, so a re-run of the same commit sends
16
+ * the same id and a receiver can drop it.
17
+ */
18
+
19
+ import { createHash } from "node:crypto";
20
+ import { execFileSync } from "node:child_process";
21
+ import { readFileSync } from "node:fs";
22
+ import { resolve } from "node:path";
23
+ import { formatError } from "../cli/format";
24
+ import type { CommandContext } from "../cli/registry";
25
+ import { makeNotifyEvent, sendNotify as realSendNotify, type NotifyDelivery, type NotifyEvent } from "../notify";
26
+ import { NEXT_RELEASE } from "../release-floors";
27
+ import { quarantineName } from "./ci-quarantine";
28
+ import { locateWorkspace } from "./which-chant";
29
+ import { readDeclaration, WorkspaceReadError, type CiGreen, type CiQuarantineEntry } from "./declaration";
30
+
31
+ /** The first chant that sends `ci.quarantine-passed` (#4677). */
32
+ export const CI_QUARANTINE_NOTIFY_FLOOR = NEXT_RELEASE;
33
+
34
+ /** One `<testcase>`: its suite's name, its classname and name, and how it ended. */
35
+ export interface JUnitCase {
36
+ suite: string;
37
+ classname: string;
38
+ name: string;
39
+ outcome: "passed" | "flaky" | "failed" | "skipped";
40
+ }
41
+
42
+ const ENTITY: Record<string, string> = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
43
+ const decode = (s: string) => s.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-z]+);/g, (all, e: string) => (e[0] === "#" ? String.fromCodePoint(e[1] === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10)) : (ENTITY[e] ?? all)));
44
+
45
+ function attributes(text: string): Record<string, string> {
46
+ const out: Record<string, string> = {};
47
+ for (const m of text.matchAll(/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) out[m[1]!] = decode(m[2] ?? m[3] ?? "");
48
+ return out;
49
+ }
50
+
51
+ /**
52
+ * The test cases of a JUnit XML document. Only the elements a test's
53
+ * outcome needs are read: `testsuite`, `testcase` and its `failure`,
54
+ * `error`, `skipped`, and nextest's `flakyFailure` and `flakyError`.
55
+ */
56
+ export function parseJUnit(xml: string): JUnitCase[] {
57
+ // CDATA, comments and declarations can hold anything, `<` included.
58
+ const text = xml.replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, "").replace(/<!--[\s\S]*?-->/g, "").replace(/<[?!][\s\S]*?>/g, "");
59
+ if (!/<testsuites?[\s>/]/.test(text)) throw new Error("not JUnit XML: no <testsuites> or <testsuite>");
60
+ const out: JUnitCase[] = [];
61
+ const suites: string[] = [];
62
+ let open: (JUnitCase & { marks: Set<string> }) | null = null;
63
+ const close = () => {
64
+ if (!open) return;
65
+ const m = open.marks;
66
+ open.outcome = m.has("failure") || m.has("error") ? "failed" : m.has("flakyFailure") || m.has("flakyError") ? "flaky" : m.has("skipped") ? "skipped" : "passed";
67
+ const { marks: _m, ...c } = open;
68
+ out.push(c);
69
+ open = null;
70
+ };
71
+ for (const m of text.matchAll(/<(\/?)([A-Za-z][\w:.-]*)((?:\s+[^\s=>/]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>/g)) {
72
+ const [, end, tag, attrs, selfClosing] = m;
73
+ if (tag === "testsuite") {
74
+ if (end) suites.pop();
75
+ else if (!selfClosing) suites.push(attributes(attrs!).name ?? "");
76
+ } else if (tag === "testcase") {
77
+ if (end) close();
78
+ else {
79
+ close();
80
+ const a = attributes(attrs!);
81
+ open = { suite: suites.at(-1) ?? "", classname: a.classname ?? "", name: a.name ?? "", outcome: "passed", marks: new Set() };
82
+ if (selfClosing) close();
83
+ }
84
+ } else if (open && !end) open.marks.add(tag!);
85
+ }
86
+ close();
87
+ return out;
88
+ }
89
+
90
+ /** Whether a case is the entry's test. See {@link quarantineResults}. */
91
+ function matches(e: CiQuarantineEntry, c: JUnitCase): boolean {
92
+ // Playwright joins a case's describes and title with " › "; the entry, like its grep, may give them with spaces.
93
+ const name = c.name.replace(/ › /g, " ");
94
+ if (e.file !== undefined) return (c.classname === e.file || c.suite === e.file) && (name === e.test || name.endsWith(` ${e.test}`));
95
+ if (c.name === e.test) return true;
96
+ const at = e.test.indexOf(" ");
97
+ return at > 0 && (c.suite === e.test.slice(0, at) || c.classname === e.test.slice(0, at)) && c.name === e.test.slice(at + 1);
98
+ }
99
+
100
+ export type QuarantineOutcome = JUnitCase["outcome"] | "not-run";
101
+
102
+ export interface QuarantineResult {
103
+ entry: CiQuarantineEntry;
104
+ outcome: QuarantineOutcome;
105
+ /** How many cases matched: a Playwright test runs once per project. */
106
+ cases: number;
107
+ }
108
+
109
+ /**
110
+ * Each entry of `phase` with how its cases ended. An entry with a `file`
111
+ * matches a case whose classname or suite is the file and whose name (`›`
112
+ * read as a space) is its test or ends with it, as Playwright writes them.
113
+ * One without matches a case named its test, or, for `<binary> <name>` as
114
+ * nextest gives it, a case named `<name>` in the suite (or classname)
115
+ * `<binary>`. Any failed case makes the entry failed, then any flaky, then
116
+ * any passed; all skipped is skipped, and none is not run.
117
+ */
118
+ export function quarantineResults(green: CiGreen, phase: string, cases: readonly JUnitCase[]): QuarantineResult[] {
119
+ return (green.quarantine?.entries ?? [])
120
+ .filter((e) => e.phase === phase)
121
+ .map((entry) => {
122
+ const mine = cases.filter((c) => matches(entry, c));
123
+ const has = (o: JUnitCase["outcome"]) => mine.some((c) => c.outcome === o);
124
+ const outcome: QuarantineOutcome = mine.length === 0 ? "not-run" : has("failed") ? "failed" : has("flaky") ? "flaky" : has("passed") ? "passed" : "skipped";
125
+ return { entry, outcome, cases: mine.length };
126
+ });
127
+ }
128
+
129
+ /** `ci.quarantine-passed` for one entry that passed at `commit`. */
130
+ export function quarantinePassedEvent(green: CiGreen, entry: CiQuarantineEntry, commit: string, env: NodeJS.ProcessEnv = process.env): NotifyEvent {
131
+ const name = quarantineName(entry);
132
+ const run = { commit };
133
+ return makeNotifyEvent(
134
+ {
135
+ id: createHash("sha256").update(JSON.stringify(["chant", "ci.quarantine-passed", entry.phase, entry.file ?? null, entry.test, commit])).digest("hex"),
136
+ source: "chant",
137
+ event: "ci.quarantine-passed",
138
+ summary: `quarantined ${name} passed in phase ${entry.phase}'s scheduled run at ${commit.slice(0, 12)}: take it out of ci.green.quarantine if ${entry.issue} is fixed`,
139
+ targets: [name],
140
+ ci: { branch: green.branch, commit, phase: entry.phase, quarantine: { test: entry.test, ...(entry.file !== undefined ? { file: entry.file } : {}), issue: entry.issue, until: entry.until } },
141
+ run,
142
+ },
143
+ { env },
144
+ );
145
+ }
146
+
147
+ export interface QuarantineReport {
148
+ phase: string;
149
+ commit: string;
150
+ results: QuarantineResult[];
151
+ /** The tests told about, or that would be with `dryRun`; `sent` when a delivery went through. */
152
+ told: { name: string; sent: boolean }[];
153
+ dryRun: boolean;
154
+ }
155
+
156
+ /** Read the run's JUnit files, match them to `phase`'s entries, and send `ci.quarantine-passed` for each that passed. */
157
+ export async function quarantineReport(req: {
158
+ green: CiGreen;
159
+ phase: string;
160
+ junit: readonly string[];
161
+ commit: string;
162
+ dryRun?: boolean;
163
+ env?: NodeJS.ProcessEnv;
164
+ sendNotify?: typeof realSendNotify;
165
+ }): Promise<QuarantineReport> {
166
+ const { green, phase } = req;
167
+ if (!green.phases.some((p) => p.name === phase)) {
168
+ throw new WorkspaceReadError("declaration-invalid", `ci.green declares no phase ${JSON.stringify(phase)}; it declares ${green.phases.map((p) => p.name).join(", ")}`);
169
+ }
170
+ const cases = req.junit.flatMap((xml) => parseJUnit(xml));
171
+ const results = quarantineResults(green, phase, cases);
172
+ const dryRun = req.dryRun === true;
173
+ const send = req.sendNotify ?? realSendNotify;
174
+ const told: QuarantineReport["told"] = [];
175
+ for (const r of results.filter((x) => x.outcome === "passed")) {
176
+ const name = quarantineName(r.entry);
177
+ if (!green.notify) continue;
178
+ if (dryRun) {
179
+ told.push({ name, sent: false });
180
+ continue;
181
+ }
182
+ const deliveries: NotifyDelivery[] = await send(green.notify, quarantinePassedEvent(green, r.entry, req.commit, req.env ?? process.env), { env: req.env ?? process.env });
183
+ told.push({ name, sent: deliveries.some((d) => d.ok) });
184
+ }
185
+ return { phase, commit: req.commit, results, told, dryRun };
186
+ }
187
+
188
+ const LABEL: Record<QuarantineOutcome, string> = { passed: "passed", flaky: "flaky", failed: "failed", skipped: "skipped", "not-run": "not run" };
189
+
190
+ /** The report as text: a line per entry, then what was told. */
191
+ export function formatQuarantineReport(r: QuarantineReport, green: CiGreen): string {
192
+ const lines = [`quarantine of phase ${r.phase} at ${r.commit.slice(0, 12)}: ${r.results.length} test${r.results.length === 1 ? "" : "s"}`];
193
+ for (const x of r.results) {
194
+ const hint = x.outcome === "passed" ? ": it may be fixed; take it out once the issue says so" : "";
195
+ lines.push(` ${LABEL[x.outcome].padEnd(8)} ${quarantineName(x.entry)} (${x.entry.issue}, until ${x.entry.until})${hint}`);
196
+ }
197
+ const passed = r.results.filter((x) => x.outcome === "passed").length;
198
+ if (passed > 0 && !green.notify) lines.push(" ci.green.notify is not set, so no ci.quarantine-passed was sent");
199
+ for (const t of r.told) lines.push(` ${r.dryRun ? "would tell" : t.sent ? "told" : "noted (no notify variable set, or every delivery failed)"} ci.quarantine-passed: ${t.name}`);
200
+ return lines.join("\n");
201
+ }
202
+
203
+ const USAGE = "chant ci quarantine report --phase <name> --junit <file>... [--commit <sha>] [--dry-run] [--json]";
204
+
205
+ const describe = (err: unknown) => (err instanceof WorkspaceReadError ? err.describe() : err instanceof Error ? err.message : String(err));
206
+
207
+ /** `chant ci quarantine report` (#4677). */
208
+ export async function runCiQuarantineReport(ctx: CommandContext): Promise<number> {
209
+ const { args } = ctx;
210
+ try {
211
+ if (!args.phase) throw new Error("--phase names the ci.green phase whose quarantined tests the run ran");
212
+ const files = args.quarantineJunit ?? [];
213
+ if (files.length === 0) throw new Error("--junit names the JUnit XML the run wrote; repeat it for several");
214
+ const declaration = readDeclaration(locateWorkspace(process.cwd()).tree);
215
+ const green = declaration.ci?.green;
216
+ if (!green) throw new WorkspaceReadError("declaration-invalid", `${declaration.file} declares no ci.green, so it has no quarantine`);
217
+ const junit = files.map((f) => {
218
+ try {
219
+ return readFileSync(resolve(f), "utf8");
220
+ } catch (err) {
221
+ throw new Error(`could not read --junit ${f}: ${err instanceof Error ? err.message : String(err)}`);
222
+ }
223
+ });
224
+ const commit = args.commit ?? process.env.GITHUB_SHA ?? execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf-8" }).trim();
225
+ const report = await quarantineReport({ green, phase: args.phase, junit, commit, dryRun: args.dryRun === true });
226
+ if (args.json) {
227
+ const { results, ...rest } = report;
228
+ console.log(JSON.stringify({ ...rest, results: results.map((x) => ({ test: x.entry.test, ...(x.entry.file !== undefined ? { file: x.entry.file } : {}), issue: x.entry.issue, until: x.entry.until, outcome: x.outcome, cases: x.cases })) }, null, 2));
229
+ } else console.log(formatQuarantineReport(report, green));
230
+ return 0;
231
+ } catch (err) {
232
+ console.error(formatError({ message: `chant ci quarantine report: ${describe(err)}`, hint: USAGE }));
233
+ return 1;
234
+ }
235
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * #4677 — the quarantine: ci.green.quarantine read and checked, and each
3
+ * runner's filter from `chant ci quarantine filter`.
4
+ */
5
+
6
+ import { execFileSync } from "node:child_process";
7
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { afterAll, afterEach, describe, expect, test, vi } from "vitest";
11
+ import { parseArgs } from "../cli/parse-args";
12
+ import { NEXT_RELEASE } from "../release-floors";
13
+ import { CI_QUARANTINE_FLOOR, PLAYWRIGHT_NOTHING, quarantineFilter, quarantineProblems, runCiQuarantine, utcToday } from "./ci-quarantine";
14
+ import { parseDeclaration, WorkspaceReadError, type CiGreen } from "./declaration";
15
+
16
+ const TODAY = "2026-11-01";
17
+
18
+ const RUST = { test: "arugulad::integration ssh::ssh_installs_runs", issue: "1234", until: "2026-11-10", why: "Fails twice on unrelated commits." };
19
+ const BARE = { test: "triggers::fires_once", issue: "https://github.com/acme/app/issues/7", until: "2026-11-01", why: "Times out under load." };
20
+ const SPEC = { file: "chat-control.spec.ts", test: "polish: ↑ edits the last message (and Esc cancels) [1.2]?", issue: "#1235", until: "2026-11-15", why: "Races the composer." };
21
+
22
+ function ws(quarantine: unknown): Record<string, unknown> {
23
+ return { name: "acme", schema: 1, members: [], ci: { green: { branch: "main", phases: { test: ["test (*)"], e2e: ["e2e"], lint: ["lint"] }, require: ["test", "e2e", "lint"], ...(quarantine !== undefined ? { quarantine } : {}) } } };
24
+ }
25
+
26
+ const greenOf = (quarantine: unknown): CiGreen => parseDeclaration(JSON.stringify(ws(quarantine), null, 2), "chant.workspace.json").ci!.green!;
27
+
28
+ const invalid = (quarantine: unknown): WorkspaceReadError => {
29
+ try {
30
+ greenOf(quarantine);
31
+ } catch (err) {
32
+ return err as WorkspaceReadError;
33
+ }
34
+ throw new Error("read without an error");
35
+ };
36
+
37
+ describe("ci.green.quarantine (#4677)", () => {
38
+ test("is read phase by phase, with maxDays 14 by default and each entry located", () => {
39
+ const q = greenOf({ phases: { test: [RUST, BARE], e2e: [SPEC] } }).quarantine!;
40
+ expect(q.maxDays).toBe(14);
41
+ expect(q.entries.map((e) => [e.phase, e.test, e.file ?? null, e.pointer])).toEqual([
42
+ ["test", RUST.test, null, "/ci/green/quarantine/phases/test/0"],
43
+ ["test", BARE.test, null, "/ci/green/quarantine/phases/test/1"],
44
+ ["e2e", SPEC.test, SPEC.file, "/ci/green/quarantine/phases/e2e/0"],
45
+ ]);
46
+ expect(q.entries[0]!.location).toMatchObject({ file: "chant.workspace.json", line: expect.any(Number) });
47
+ expect(greenOf(undefined).quarantine).toBeUndefined();
48
+ });
49
+
50
+ test("refuses an undeclared phase, a day that isn't one, a test listed twice and an entry without an issue", () => {
51
+ expect(invalid({ phases: { unit: [RUST] } }).message).toContain('names the phase "unit", which ci.green.phases does not declare');
52
+ expect(invalid({ phases: { test: [{ ...RUST, until: "2026-02-30" }] } }).message).toContain("until is not a day");
53
+ expect(invalid({ phases: { test: [RUST, RUST] } }).message).toContain("lists");
54
+ const { issue: _issue, ...noIssue } = RUST;
55
+ expect(invalid({ phases: { test: [noIssue] } }).code).toBe("declaration-invalid");
56
+ expect(invalid({ maxDays: 0, phases: { test: [RUST] } }).code).toBe("declaration-invalid");
57
+ });
58
+
59
+ test("an entry past its until, or further out than maxDays, is a problem; the last day and the 14th day out are not", () => {
60
+ const green = greenOf({ phases: { test: [RUST, BARE, { ...RUST, test: "x::y", until: "2026-10-31" }, { ...RUST, test: "x::z", until: "2026-11-16" }] } });
61
+ expect(quarantineProblems(green, TODAY).map((p) => p.message)).toEqual([
62
+ "ci.green.quarantine: test: x::y (1234) expired on 2026-10-31: fix the test and delete the entry, or delete the test",
63
+ "ci.green.quarantine: test: x::z (1234) stays out until 2026-11-16, more than 14 days from 2026-11-01 (ci.green.quarantine.maxDays)",
64
+ ]);
65
+ expect(quarantineProblems(greenOf({ maxDays: 30, phases: { test: [{ ...RUST, until: "2026-11-16" }] } }), TODAY)).toEqual([]);
66
+ });
67
+ });
68
+
69
+ describe("ci quarantine filter (#4677)", () => {
70
+ const green = greenOf({ phases: { test: [RUST, BARE], e2e: [SPEC, { file: "nav/menu.spec.ts", test: "opens", issue: "9", until: "2026-11-02", why: "w" }] } });
71
+
72
+ test("nextest: a filterset leaving the phase's tests out, or with --only selecting them", () => {
73
+ const set = "(binary_id(=arugulad::integration) & test(=ssh::ssh_installs_runs)) | test(=triggers::fires_once)";
74
+ expect(quarantineFilter(green, { phase: "test", runner: "nextest", today: TODAY }).filter).toBe(`not (${set})`);
75
+ expect(quarantineFilter(green, { phase: "test", runner: "nextest", only: true, today: TODAY }).filter).toBe(set);
76
+ expect(quarantineFilter(green, { phase: "lint", runner: "nextest", today: TODAY }).filter).toBe("all()");
77
+ expect(quarantineFilter(green, { phase: "lint", runner: "nextest", only: true, today: TODAY }).filter).toBe("none()");
78
+ });
79
+
80
+ test("playwright: one pattern matching each quarantined test's title path and no other", () => {
81
+ const { filter, entries } = quarantineFilter(green, { phase: "e2e", runner: "playwright", today: TODAY });
82
+ expect(entries).toHaveLength(2);
83
+ // As Playwright's CLI builds a --grep-invert from a string.
84
+ const re = new RegExp(filter, "i");
85
+ expect(re.test(` chromium chat-control.spec.ts ${SPEC.test}`)).toBe(true);
86
+ expect(re.test(` chromium chat-control.spec.ts composer ${SPEC.test} @slow`)).toBe(true);
87
+ expect(re.test(` nav/menu.spec.ts opens`)).toBe(true);
88
+ expect(re.test(` chromium chat-control.spec.ts polish: x edits the last message (and Esc cancels) [1.2]?`)).toBe(false);
89
+ expect(re.test(` chromium chat-control.spec.ts ${SPEC.test} too`)).toBe(false);
90
+ expect(re.test(` chromium other.spec.ts ${SPEC.test}`)).toBe(false);
91
+ expect(re.test(` nav/menu.spec.ts opens later`)).toBe(false);
92
+ expect(quarantineFilter(green, { phase: "test", runner: "playwright", today: TODAY }).filter).toBe(PLAYWRIGHT_NOTHING);
93
+ expect(new RegExp(PLAYWRIGHT_NOTHING, "gi").test(" chromium a.spec.ts a")).toBe(false);
94
+ });
95
+
96
+ test("list: every entry of the phase, a line each, file and test split by a tab", () => {
97
+ expect(quarantineFilter(green, { phase: "e2e", runner: "list", today: TODAY }).filter).toBe(`chat-control.spec.ts\t${SPEC.test}\nnav/menu.spec.ts\topens`);
98
+ expect(quarantineFilter(green, { phase: "lint", runner: "list", today: TODAY }).filter).toBe("");
99
+ });
100
+
101
+ test("refuses the phase's expired entry, but --only and other phases don't", () => {
102
+ const later = "2026-11-03";
103
+ expect(() => quarantineFilter(green, { phase: "e2e", runner: "playwright", today: later })).toThrow(/nav\/menu.spec.ts › opens \(9\) expired on 2026-11-02/);
104
+ expect(quarantineFilter(green, { phase: "e2e", runner: "playwright", only: true, today: later }).entries).toHaveLength(2);
105
+ expect(() => quarantineFilter(green, { phase: "test", runner: "nextest", today: later })).toThrow(/expired on 2026-11-01/);
106
+ expect(quarantineFilter(green, { phase: "lint", runner: "nextest", today: later }).filter).toBe("all()");
107
+ });
108
+
109
+ test("refuses a nextest name its matchers can't hold, and an undeclared phase", () => {
110
+ const odd = greenOf({ phases: { test: [{ ...RUST, test: "a b c" }] } });
111
+ expect(() => quarantineFilter(odd, { phase: "test", runner: "nextest", today: TODAY })).toThrow(/isn't a nextest test/);
112
+ expect(() => quarantineFilter(green, { phase: "unit", runner: "nextest", today: TODAY })).toThrow(/declares no phase "unit"/);
113
+ });
114
+ });
115
+
116
+ describe("chant ci quarantine (#4677)", () => {
117
+ const scratch: string[] = [];
118
+ afterAll(() => {
119
+ for (const d of scratch) rmSync(d, { recursive: true, force: true });
120
+ });
121
+ afterEach(() => vi.restoreAllMocks());
122
+
123
+ function run(quarantine: unknown, args: Record<string, unknown>): Promise<{ code: number; out: string; err: string }> {
124
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-quarantine-")));
125
+ scratch.push(root);
126
+ execFileSync("git", ["init", "-q"], { cwd: root });
127
+ writeFileSync(join(root, "chant.workspace.json"), JSON.stringify(ws(quarantine), null, 2));
128
+ vi.spyOn(process, "cwd").mockReturnValue(root);
129
+ const out: string[] = [];
130
+ const err: string[] = [];
131
+ vi.spyOn(console, "log").mockImplementation((...m: unknown[]) => void out.push(m.map(String).join(" ")));
132
+ vi.spyOn(console, "error").mockImplementation((...m: unknown[]) => void err.push(m.map(String).join(" ")));
133
+ return runCiQuarantine({ args: { command: "ci", path: "quarantine", ...args }, plugins: [] } as never).then((code) => ({ code, out: out.join("\n"), err: err.join("\n") }));
134
+ }
135
+
136
+ const day = (offset: number) => utcToday(new Date(Date.now() + offset * 86_400_000));
137
+
138
+ test("check passes on current entries and fails at an expired one's line", async () => {
139
+ const ok = await run({ phases: { test: [{ ...RUST, until: day(3) }] } }, { extraPositional: "check" });
140
+ expect(ok).toMatchObject({ code: 0, out: expect.stringContaining("1 test quarantined, every one current") });
141
+ const expired = await run({ phases: { test: [{ ...RUST, until: day(-1) }] } }, { extraPositional: "check" });
142
+ expect(expired.code).toBe(1);
143
+ expect(expired.err).toMatch(/^chant\.workspace\.json:\d+:\d+: ci\.green\.quarantine: test: .* expired on /);
144
+ });
145
+
146
+ test("its floor is the next release", () => {
147
+ expect(CI_QUARANTINE_FLOOR).toBe(NEXT_RELEASE);
148
+ });
149
+
150
+ test("parses --phase, --runner and --only", () => {
151
+ expect(parseArgs(["ci", "quarantine", "filter", "--phase", "test", "--runner", "nextest", "--only"])).toMatchObject({ command: "ci", path: "quarantine", extraPositional: "filter", phase: "test", quarantineRunner: "nextest", quarantineOnly: true });
152
+ });
153
+
154
+ test("filter prints the runner's filter, and --runner is checked", async () => {
155
+ const q = { phases: { test: [{ ...RUST, until: day(3) }] } };
156
+ expect(await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "nextest" })).toMatchObject({ code: 0, out: "not ((binary_id(=arugulad::integration) & test(=ssh::ssh_installs_runs)))" });
157
+ const json = await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "list", json: true });
158
+ expect(JSON.parse(json.out)).toMatchObject({ phase: "test", runner: "list", only: false, filter: RUST.test, entries: [{ phase: "test", test: RUST.test, issue: "1234" }] });
159
+ expect(await run(q, { extraPositional: "filter", phase: "test", quarantineRunner: "jest" })).toMatchObject({ code: 1, err: expect.stringContaining('--runner takes nextest, playwright, list, not "jest"') });
160
+ });
161
+ });