architecture-harness 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/package.json +3 -22
  2. package/src/cli/ask.mjs +42 -0
  3. package/src/cli/ask.test.mjs +40 -0
  4. package/src/cli/branch-sync.mjs +126 -0
  5. package/src/cli/branch-sync.test.mjs +428 -0
  6. package/src/cli/budget-guard.mjs +74 -5
  7. package/src/cli/budget-guard.test.mjs +185 -2
  8. package/src/cli/budget-report.mjs +85 -0
  9. package/src/cli/budget-report.test.mjs +173 -0
  10. package/src/cli/budget.mjs +8 -5
  11. package/src/cli/check-commands.mjs +123 -11
  12. package/src/cli/check-commands.test.mjs +360 -6
  13. package/src/cli/check-feature-switches.test.mjs +110 -0
  14. package/src/cli/check-full.test.mjs +152 -0
  15. package/src/cli/check-verdict.mjs +46 -0
  16. package/src/cli/check-verdict.test.mjs +32 -0
  17. package/src/cli/check.mjs +137 -4
  18. package/src/cli/check.test.mjs +45 -0
  19. package/src/cli/checkpoint.mjs +143 -0
  20. package/src/cli/checkpoint.test.mjs +146 -0
  21. package/src/cli/child-run.mjs +7 -2
  22. package/src/cli/child-run.test.mjs +17 -2
  23. package/src/cli/ci-failures.mjs +304 -0
  24. package/src/cli/ci-failures.test.mjs +615 -0
  25. package/src/cli/ci-preview.mjs +62 -0
  26. package/src/cli/ci-preview.test.mjs +85 -0
  27. package/src/cli/ci-state.mjs +25 -29
  28. package/src/cli/ci-state.test.mjs +174 -2
  29. package/src/cli/ci-template.test.mjs +86 -0
  30. package/src/cli/claude-core.test.mjs +37 -0
  31. package/src/cli/codex-implement.mjs +580 -47
  32. package/src/cli/codex-implement.test.mjs +1946 -29
  33. package/src/cli/codex-limit.mjs +85 -0
  34. package/src/cli/codex-limit.test.mjs +179 -0
  35. package/src/cli/codex-reset.mjs +78 -0
  36. package/src/cli/codex-reset.test.mjs +192 -0
  37. package/src/cli/codex-verify.mjs +230 -0
  38. package/src/cli/codex-verify.test.mjs +402 -0
  39. package/src/cli/comment-watch.mjs +391 -0
  40. package/src/cli/comment-watch.test.mjs +392 -0
  41. package/src/cli/commit-guard.mjs +219 -0
  42. package/src/cli/commit-guard.test.mjs +809 -0
  43. package/src/cli/context-budgets.mjs +47 -0
  44. package/src/cli/context-budgets.test.mjs +96 -0
  45. package/src/cli/context-watch.mjs +116 -0
  46. package/src/cli/context-watch.test.mjs +395 -0
  47. package/src/cli/contract-history.mjs +1 -1
  48. package/src/cli/controller-guard.mjs +38 -0
  49. package/src/cli/controller-guard.test.mjs +66 -2
  50. package/src/cli/cost-stop.mjs +5 -1
  51. package/src/cli/cost-stop.test.mjs +26 -0
  52. package/src/cli/diff-shape.mjs +162 -0
  53. package/src/cli/diff-shape.test.mjs +200 -0
  54. package/src/cli/direct-lane.mjs +32 -19
  55. package/src/cli/direct-lane.test.mjs +21 -3
  56. package/src/cli/dispatch-guard.mjs +11 -0
  57. package/src/cli/dispatch-guard.test.mjs +145 -10
  58. package/src/cli/dispatch-reminder.mjs +23 -10
  59. package/src/cli/dispatch-reminder.test.mjs +63 -11
  60. package/src/cli/dispatch-route.mjs +54 -0
  61. package/src/cli/dispatch-route.test.mjs +101 -0
  62. package/src/cli/dispatch-slot.mjs +2 -2
  63. package/src/cli/dispatch-slot.test.mjs +18 -19
  64. package/src/cli/dispatch.test.mjs +3 -3
  65. package/src/cli/e2e-affected.mjs +15 -0
  66. package/src/cli/e2e-affected.test.mjs +73 -0
  67. package/src/cli/fleet.mjs +180 -0
  68. package/src/cli/fleet.test.mjs +213 -0
  69. package/src/cli/gate-slot.mjs +2 -1
  70. package/src/cli/gh-merge-command.mjs +96 -31
  71. package/src/cli/gh-merge-command.test.mjs +74 -0
  72. package/src/cli/gh-run.mjs +64 -3
  73. package/src/cli/gh-run.test.mjs +66 -1
  74. package/src/cli/git-hooks.test.mjs +25 -3
  75. package/src/cli/git-read.mjs +2 -1
  76. package/src/cli/integrate-tree.mjs +47 -0
  77. package/src/cli/integrate.mjs +143 -40
  78. package/src/cli/integrate.test.mjs +347 -1
  79. package/src/cli/integration-lane.mjs +62 -0
  80. package/src/cli/integration-lane.test.mjs +213 -0
  81. package/src/cli/ledger.mjs +4 -2
  82. package/src/cli/ledger.test.mjs +12 -3
  83. package/src/cli/legs.mjs +53 -0
  84. package/src/cli/legs.test.mjs +70 -0
  85. package/src/cli/lint-changed.mjs +59 -10
  86. package/src/cli/lint-changed.test.mjs +112 -1
  87. package/src/cli/locked-tests.mjs +134 -0
  88. package/src/cli/locked-tests.test.mjs +188 -0
  89. package/src/cli/merge-guard.mjs +234 -62
  90. package/src/cli/merge-guard.test.mjs +768 -39
  91. package/src/cli/metrics.mjs +53 -0
  92. package/src/cli/metrics.test.mjs +73 -0
  93. package/src/cli/milestone.mjs +297 -0
  94. package/src/cli/milestone.test.mjs +294 -0
  95. package/src/cli/mutate.mjs +203 -0
  96. package/src/cli/mutate.test.mjs +134 -0
  97. package/src/cli/output-redaction.mjs +26 -0
  98. package/src/cli/output-redaction.test.mjs +117 -0
  99. package/src/cli/overview.mjs +131 -0
  100. package/src/cli/overview.test.mjs +137 -0
  101. package/src/cli/pause.mjs +93 -0
  102. package/src/cli/pause.test.mjs +109 -0
  103. package/src/cli/plan-check.mjs +84 -12
  104. package/src/cli/plan-check.test.mjs +152 -2
  105. package/src/cli/plan-stop.mjs +7 -4
  106. package/src/cli/plan-stop.test.mjs +87 -0
  107. package/src/cli/platform-risk.mjs +46 -0
  108. package/src/cli/platform-risk.test.mjs +38 -0
  109. package/src/cli/plugin-skills.test.mjs +25 -0
  110. package/src/cli/pr-guard.mjs +128 -0
  111. package/src/cli/pr-guard.test.mjs +154 -0
  112. package/src/cli/promotion-branch.mjs +2 -0
  113. package/src/cli/qc.mjs +160 -27
  114. package/src/cli/qc.test.mjs +93 -0
  115. package/src/cli/report-stop.mjs +5 -0
  116. package/src/cli/report-stop.test.mjs +23 -1
  117. package/src/cli/retry-failed.mjs +3 -1
  118. package/src/cli/review-gate.mjs +24 -6
  119. package/src/cli/review-gate.test.mjs +116 -0
  120. package/src/cli/review-promotion.mjs +107 -0
  121. package/src/cli/review-promotion.test.mjs +251 -0
  122. package/src/cli/role-budget.mjs +50 -0
  123. package/src/cli/role-budget.test.mjs +91 -0
  124. package/src/cli/run-log.mjs +73 -0
  125. package/src/cli/run-log.test.mjs +121 -0
  126. package/src/cli/secret-patterns.mjs +16 -0
  127. package/src/cli/secret-patterns.test.mjs +73 -0
  128. package/src/cli/setup-block.mjs +24 -0
  129. package/src/cli/setup-block.test.mjs +96 -0
  130. package/src/cli/setup-checks.mjs +65 -0
  131. package/src/cli/setup-checks.test.mjs +158 -0
  132. package/src/cli/setup-compaction.mjs +55 -0
  133. package/src/cli/setup-compaction.test.mjs +115 -0
  134. package/src/cli/setup-skills.mjs +65 -0
  135. package/src/cli/setup-skills.test.mjs +171 -0
  136. package/src/cli/setup.mjs +107 -0
  137. package/src/cli/setup.test.mjs +275 -0
  138. package/src/cli/skill-length.test.mjs +8 -0
  139. package/src/cli/spawn-command.mjs +47 -0
  140. package/src/cli/spawn-command.test.mjs +64 -0
  141. package/src/cli/task-gate-review.test.mjs +21 -2
  142. package/src/cli/task-gate.mjs +25 -12
  143. package/src/cli/task-gate.test.mjs +43 -5
  144. package/src/cli/tokens.mjs +46 -3
  145. package/src/cli/tokens.test.mjs +103 -3
  146. package/src/cli/tools.mjs +49 -0
  147. package/src/cli/tools.test.mjs +89 -0
  148. package/src/cli/transcript-usage.mjs +27 -0
  149. package/src/cli/transcript-usage.test.mjs +34 -0
  150. package/src/cli/user-config-package.mjs +1 -1
  151. package/src/cli/user-config-toml.mjs +63 -7
  152. package/src/cli/user-config.mjs +39 -7
  153. package/src/cli/user-config.test.mjs +238 -5
  154. package/src/cli/watch-arm.mjs +39 -0
  155. package/src/cli/watch-arm.test.mjs +87 -0
  156. package/src/cli/watch.mjs +80 -35
  157. package/src/cli/watch.test.mjs +233 -27
  158. package/src/cli/work-order-guard.mjs +2 -1
  159. package/src/cli/workflow-hooks.test.mjs +18 -4
  160. package/src/cli/workflow-settings.mjs +44 -8
  161. package/src/cli/workflow-settings.test.mjs +124 -1
  162. package/src/cli/worktree.mjs +14 -1
  163. package/src/cli/worktree.test.mjs +20 -1
  164. package/src/config.mjs +174 -7
  165. package/src/config.test.mjs +327 -5
  166. package/src/consumer-package.mjs +31 -0
  167. package/src/consumer-package.test.mjs +54 -0
  168. package/src/descriptions.mjs +2 -0
  169. package/src/eslint/index.mjs +12 -0
  170. package/src/eslint/jsx.mjs +20 -0
  171. package/src/eslint/preset.mjs +26 -2
  172. package/src/eslint/preset.test.mjs +104 -2
  173. package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
  174. package/src/eslint/rules/no-literal-color.mjs +94 -0
  175. package/src/eslint/rules/no-static-inline-style.mjs +41 -0
  176. package/src/eslint/rules/one-component-per-file.mjs +70 -0
  177. package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
  178. package/src/eslint/rules/timeless-comment.mjs +92 -0
  179. package/src/eslint/rules.test.mjs +189 -0
  180. package/src/eslint/ui-regressions.test.mjs +39 -0
  181. package/src/gates/contract-operations.mjs +3 -3
  182. package/src/gates/contract-operations.test.mjs +28 -0
  183. package/src/gates/feature-switches.mjs +19 -0
  184. package/src/gates/feature-switches.test.mjs +55 -0
  185. package/src/gates/plain-language.mjs +396 -0
  186. package/src/gates/plain-language.test.mjs +210 -0
  187. package/src/gates/runtime-imports.test.mjs +114 -0
  188. package/src/gates/saga-key.test.mjs +1 -1
  189. package/src/global-skills.mjs +9 -0
  190. package/src/global-skills.test.mjs +53 -0
  191. package/src/plugin.test.mjs +3 -2
  192. package/src/ui/class-sites.mjs +38 -6
  193. package/src/ui/codemod.mjs +4 -1
  194. package/src/ui/codemod.test.mjs +52 -0
  195. package/src/ui/components.mjs +5 -3
  196. package/src/ui/components.test.mjs +8 -0
  197. package/src/ui/dupes.test.mjs +18 -0
  198. package/templates/docs/enforcement.md +12 -2
  199. package/templates/docs/ui.md +33 -0
  200. package/templates/githooks/pre-commit +1 -0
  201. package/templates/githooks/pre-push +11 -2
  202. package/templates/github/workflows/ci.yml +57 -3
  203. package/user-config/claude/CLAUDE.core.md +28 -0
  204. package/user-config/claude/settings.shared.json +41 -1
  205. package/src/cli/screens-discovery.mjs +0 -60
  206. package/src/cli/screens.mjs +0 -84
  207. package/src/cli/stack.mjs +0 -14
  208. package/src/cli/throwaway-db.mjs +0 -127
  209. package/src/cli/throwaway-db.test.mjs +0 -83
  210. package/src/screens/auth-context.test.mjs +0 -41
  211. package/src/screens/auth-run.test.mjs +0 -147
  212. package/src/screens/auth.mjs +0 -223
  213. package/src/screens/auth.test.mjs +0 -76
  214. package/src/screens/capture-idle.test.mjs +0 -27
  215. package/src/screens/capture.browser-test.mjs +0 -73
  216. package/src/screens/capture.mjs +0 -175
  217. package/src/screens/capture.test.mjs +0 -28
  218. package/src/screens/catalog.browser-test.mjs +0 -32
  219. package/src/screens/catalog.mjs +0 -72
  220. package/src/screens/catalog.test.mjs +0 -36
  221. package/src/screens/chrome.mjs +0 -21
  222. package/src/screens/compare.mjs +0 -40
  223. package/src/screens/compare.test.mjs +0 -30
  224. package/src/screens/discovery.browser-test.mjs +0 -29
  225. package/src/screens/discovery.mjs +0 -158
  226. package/src/screens/discovery.test.mjs +0 -27
  227. package/src/screens/inventory.mjs +0 -69
  228. package/src/screens/inventory.test.mjs +0 -10
  229. package/src/screens/map.mjs +0 -63
  230. package/src/screens/map.test.mjs +0 -35
  231. package/src/screens/open.browser-test.mjs +0 -50
  232. package/src/screens/regions.mjs +0 -137
  233. package/src/screens/regions.test.mjs +0 -38
  234. package/src/screens/session-files.mjs +0 -39
  235. package/src/screens/session-files.test.mjs +0 -39
  236. package/src/screens/setup.browser-test.mjs +0 -49
  237. package/src/screens/setup.mjs +0 -78
  238. package/src/screens/stack-auth.browser-test.mjs +0 -30
  239. package/src/screens/stack-auth.mjs +0 -106
  240. package/src/screens/stack-auth.test.mjs +0 -65
  241. package/src/screens/write-guard.mjs +0 -26
  242. package/src/stack/stack.mjs +0 -131
  243. package/src/stack/stack.test.mjs +0 -40
  244. package/src/stack/supervisor.mjs +0 -30
@@ -0,0 +1,62 @@
1
+ // A pipeline reserves platform previews, dispatches CI, and records passing legs.
2
+ import { execFileSync } from "node:child_process";
3
+ import { closeSync, mkdirSync, openSync, unlinkSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { appendLeg, gitText, legRecords } from "./legs.mjs";
6
+ import { ledgerFileOf } from "./ledger.mjs";
7
+
8
+ const ghCommand = (root, args) => execFileSync("gh", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 16 * 1024 * 1024 });
9
+ const platforms = (value) => value === "both" ? ["linux", "windows"] : [value];
10
+ const jobOS = (name) => /windows/i.test(name) ? "windows" : /linux|ubuntu/i.test(name) ? "linux" : null;
11
+
12
+ export async function runCiPreview(root, args = [], options = {}) {
13
+ const write = options.write ?? console.error;
14
+ const os = args.length === 0 ? "both" : args.length === 2 && args[0] === "--os" ? args[1] : null;
15
+ if (!["linux", "windows", "both"].includes(os)) { write("ci-preview: use --os linux, windows, or both"); return 1; }
16
+ const git = options.git ?? ((...words) => gitText(root, ...words));
17
+ const gh = options.gh ?? ((words) => ghCommand(root, words));
18
+ const records = options.records ?? (() => legRecords(root));
19
+ const record = options.record ?? appendLeg;
20
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
21
+ let lock;
22
+ let fd;
23
+ try {
24
+ const head = git("rev-parse", "HEAD");
25
+ const branch = git("branch", "--show-current");
26
+ if (!branch) throw new Error("a preview needs a branch");
27
+ const file = ledgerFileOf(root);
28
+ if (!file) throw new Error("a preview needs a git worktree");
29
+ mkdirSync(path.dirname(file), { recursive: true });
30
+ lock = `${file}.preview-lock`;
31
+ fd = openSync(lock, "wx");
32
+ const wanted = platforms(os);
33
+ const previous = records();
34
+ if (wanted.some((leg) => previous.some((r) => r.head === head && r.os === leg && r.source === "preview"))) throw new Error("a preview already exists for this head and platform");
35
+ const listArgs = ["run", "list", "--workflow", "ci.yml", "--event", "workflow_dispatch", "--branch", branch, "--commit", head, "--limit", "100", "--json", "databaseId,headSha"];
36
+ const before = new Set(JSON.parse(gh(listArgs)).map((run) => run.databaseId));
37
+ for (const leg of wanted) record(root, { type: "leg-preview", os: leg, head, source: "preview" });
38
+ gh(["workflow", "run", "ci.yml", "--ref", branch, "-f", `os=${os}`]);
39
+ let run;
40
+ for (let attempt = 0; attempt < (options.attempts ?? 30); attempt += 1) {
41
+ const candidates = JSON.parse(gh(listArgs)).filter((r) => r.headSha === head && !before.has(r.databaseId));
42
+ if (candidates.length > 1) throw new Error("multiple new preview runs match this head");
43
+ if (candidates.length === 1) { run = candidates[0]; break; }
44
+ await sleep(2000);
45
+ }
46
+ if (!run) throw new Error("the dispatched preview run did not appear");
47
+ gh(["run", "watch", String(run.databaseId)]);
48
+ const result = JSON.parse(gh(["run", "view", String(run.databaseId), "--json", "headSha,jobs"]));
49
+ if (result.headSha !== head) throw new Error("preview run head differs from the requested head");
50
+ let passed = 0;
51
+ for (const leg of wanted) {
52
+ const jobs = result.jobs.filter((job) => jobOS(job.name) === leg);
53
+ if (jobs.length > 0 && jobs.every((job) => job.conclusion === "success")) {
54
+ record(root, { type: "leg", os: leg, head, source: "preview" });
55
+ passed += 1;
56
+ }
57
+ }
58
+ if (passed !== wanted.length) { write("ci-preview: one or more requested platform legs failed or are missing"); return 1; }
59
+ return 0;
60
+ } catch (error) { write(`ci-preview: ${error.message.split("\n")[0]}`); return 1; }
61
+ finally { if (fd !== undefined) { closeSync(fd); unlinkSync(lock); } }
62
+ }
@@ -0,0 +1,85 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+ import { runCiPreview } from "./ci-preview.mjs";
7
+
8
+ function fixture(t, jobs = [{ name: 'test (ubuntu-latest)', conclusion: 'success' }, { name: 'test (windows-latest)', conclusion: 'success' }]) {
9
+ const root = mkdtempSync(path.join(tmpdir(), 'qc-preview-'));
10
+ mkdirSync(path.join(root, '.git'));
11
+ t.after(() => rmSync(root, { recursive: true, force: true }));
12
+ const calls = [], records = [];
13
+ let lists = 0;
14
+ const options = {
15
+ git: (...args) => args[0] === 'branch' ? 'feat/test' : 'abc123',
16
+ gh: (args) => {
17
+ calls.push(args);
18
+ if (args[0] === 'workflow') return '';
19
+ if (args[1] === 'list') return lists++ === 0 ? '[]' : JSON.stringify([{ databaseId: 7, headSha: 'abc123' }]);
20
+ if (args[1] === 'view') return JSON.stringify({ headSha: 'abc123', jobs });
21
+ return '';
22
+ },
23
+ records: () => records,
24
+ record: (_root, record) => records.push(record),
25
+ sleep: async () => {}, attempts: 2, write: () => {},
26
+ };
27
+ return { root, options, calls, records };
28
+ }
29
+ test('dispatches both, waits, and records each passing leg once', async (t) => {
30
+ const { root, options, calls, records } = fixture(t);
31
+ assert.equal(await runCiPreview(root, ['--os', 'both'], options), 0);
32
+ assert.deepEqual(calls[1], ['workflow', 'run', 'ci.yml', '--ref', 'feat/test', '-f', 'os=both']);
33
+ assert.ok(calls.some((args) => args[1] === 'watch' && args.includes('7')));
34
+ assert.deepEqual(records.filter((r) => r.type === 'leg').map((r) => r.os), ['linux', 'windows']);
35
+ assert.equal(await runCiPreview(root, ['--os', 'windows'], options), 1);
36
+ assert.equal(calls.filter((args) => args[0] === 'workflow').length, 1);
37
+ });
38
+ test('records only the successful platform when another fails', async (t) => {
39
+ const { root, options, records } = fixture(t, [{ name: 'linux', conclusion: 'success' }, { name: 'windows', conclusion: 'failure' }]);
40
+ assert.equal(await runCiPreview(root, ['--os', 'both'], options), 1);
41
+ assert.deepEqual(records.filter((r) => r.type === 'leg').map((r) => r.os), ['linux']);
42
+ });
43
+ test('refuses invalid input and detached heads before dispatch', async (t) => {
44
+ const { root, options, calls } = fixture(t);
45
+ assert.equal(await runCiPreview(root, ['--os', 'mac'], options), 1);
46
+ options.git = (...args) => args[0] === 'branch' ? '' : 'head';
47
+ assert.equal(await runCiPreview(root, [], options), 1);
48
+ assert.deepEqual(calls, []);
49
+ });
50
+ test('does not credit a stale run or missing platform jobs', async (t) => {
51
+ const { root, options, records } = fixture(t, []);
52
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
53
+ assert.equal(records.filter((r) => r.type === 'leg').length, 0);
54
+ });
55
+ test('a lookup failure dispatches nothing and reserves nothing', async (t) => {
56
+ const { root, options, records } = fixture(t);
57
+ options.gh = () => { throw new Error('offline'); };
58
+ assert.equal(await runCiPreview(root, [], options), 1);
59
+ assert.deepEqual(records, []);
60
+ });
61
+ test('dispatch failure retains the reservation and prevents a second preview', async (t) => {
62
+ const { root, options, records } = fixture(t);
63
+ const original = options.gh;
64
+ options.gh = (args) => { if (args[0] === 'workflow') throw new Error('offline'); return original(args); };
65
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
66
+ assert.equal(records[0].type, 'leg-preview');
67
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
68
+ assert.equal(records.length, 1);
69
+ });
70
+ test('rejects stale head results and times out when no new run appears', async (t) => {
71
+ const { root, options, records } = fixture(t);
72
+ const original = options.gh;
73
+ options.gh = (args) => args[1] === 'view' ? JSON.stringify({ headSha: 'stale', jobs: [] }) : original(args);
74
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
75
+ assert.equal(records.filter((r) => r.type === 'leg').length, 0);
76
+ options.git = (...args) => args[0] === 'branch' ? 'feat/test' : 'new-head';
77
+ options.gh = () => '[]';
78
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
79
+ assert.equal(records.filter((r) => r.type === 'leg').length, 0);
80
+ });
81
+ test('a failed job prevents credit even when another job for that platform passes', async (t) => {
82
+ const { root, options, records } = fixture(t, [{ name: 'linux unit', conclusion: 'success' }, { name: 'linux integration', conclusion: 'failure' }]);
83
+ assert.equal(await runCiPreview(root, ['--os', 'linux'], options), 1);
84
+ assert.equal(records.filter((r) => r.type === 'leg').length, 0);
85
+ });
@@ -1,50 +1,46 @@
1
- // The CI state of a commit, read from its GitHub check runs. The task gate asks it before a review: a
2
- // head whose CI is not green changes before it is reviewed, so the review waits.
1
+ // The CI state of a commit, read from its GitHub check runs. The task gate uses this state before a review.
3
2
 
4
- import { runGh } from "./gh-run.mjs";
3
+ import { parseApiList, runGh } from "./gh-run.mjs";
5
4
  import { originOf } from "./git-read.mjs";
5
+ import { checkRunsState } from "./check-verdict.mjs";
6
6
 
7
- // The hook that asks has a 10 second limit, and a hook that the limit kills lets the call through. The two reads
8
- // together stay well under it, so a slow gh leaves the head unknown and the review refusal stands.
7
+ // The hook has a 10 second limit. The origin read and both gh calls fit within it, so a timeout leaves CI unknown.
9
8
  const GH_TIMEOUT_MS = 3_000;
10
9
  const ORIGIN_TIMEOUT_MS = 1_000;
11
- const FAILED = new Set(["failure", "cancelled", "timed_out", "action_required"]);
12
10
  const short = (sha) => sha.slice(0, 7);
13
11
 
14
- /**
15
- * @param runs the `check_runs` array of the GitHub API
16
- * @returns why the head is not green, naming the run, or null when every run completed without a failure
17
- * or when there are no runs, because a head with no CI is unknown.
18
- */
19
- export function notGreenReason(runs) {
20
- const failed = runs.find((entry) => entry.status === "completed" && FAILED.has(entry.conclusion));
21
- if (failed) return `${failed.name} ended ${failed.conclusion}`;
22
- const open = runs.find((entry) => entry.status !== "completed");
23
- return open ? `${open.name} is ${open.status}` : null;
24
- }
12
+ /** The reason the newest check runs are not green, or null when they pass or are absent. */
13
+ export const notGreenReason = (runs) => checkRunsState(runs).reason;
25
14
 
26
15
  /**
27
16
  * What CI says about `sha`: `reason` names a run that failed or still runs, as `CI on <short sha>: <why>`.
17
+ * `pending: true` marks an unfinished check or workflow, or a missing required check, when completed checks pass.
28
18
  * `unknown` says why nothing is known: no sha, no `origin`, a gh that fails or times out, a reply that does not parse, or no check runs.
29
19
  * `gh` and `origin` replace the real reads, for a test.
30
20
  */
31
- export function ciState(sha, cwd, { gh = runGh, origin = originOf } = {}) {
21
+ export function ciState(sha, cwd, { gh = runGh, origin = originOf, requiredChecks = [] } = {}) {
32
22
  const unknown = (why) => ({ reason: null, unknown: why });
33
23
  if (typeof sha !== "string" || sha === "") return unknown("there is no commit to ask about");
34
24
  const repo = origin(cwd, ORIGIN_TIMEOUT_MS);
35
25
  if (repo === null) return unknown("the checkout has no readable origin");
36
- const out = gh(["api", `repos/${repo}/commits/${sha}/check-runs?per_page=100`], { cwd, timeoutMs: GH_TIMEOUT_MS });
26
+ const out = gh(["api", `repos/${repo}/commits/${sha}/check-runs?per_page=100&filter=all`, "--paginate"], { cwd, timeoutMs: GH_TIMEOUT_MS });
37
27
  if (out === null) return unknown("gh failed or timed out");
38
- let runs;
39
- try {
40
- runs = JSON.parse(out)?.check_runs;
41
- } catch {
42
- return unknown("gh answered with text that is not JSON");
43
- }
44
- if (!Array.isArray(runs)) return unknown("gh answered with no check_runs list");
45
- if (runs.length === 0) return unknown(`${short(sha)} has no check runs`);
46
- const why = notGreenReason(runs);
47
- return { reason: why === null ? null : `CI on ${short(sha)}: ${why}`, unknown: null };
28
+ const runs = parseApiList(out, "check_runs");
29
+ if (runs === null) return unknown("gh answered with no readable check_runs list");
30
+ let state = checkRunsState(runs, { requiredChecks });
31
+ const workflows = gh(["api", `repos/${repo}/actions/runs?head_sha=${encodeURIComponent(sha)}&per_page=100`, "--paginate"], { cwd, timeoutMs: GH_TIMEOUT_MS });
32
+ const workflowRuns = parseApiList(workflows, "workflow_runs");
33
+ if (workflowRuns === null && state.reason === null) return unknown("gh answered with no readable workflow_runs list");
34
+ if (workflowRuns !== null) state = checkRunsState(runs, {
35
+ workflowRuns: workflowRuns.filter((run) => run.head_sha === sha),
36
+ requiredChecks,
37
+ });
38
+ if (runs.length === 0 && state.reason === null) return unknown(`${short(sha)} has no check runs`);
39
+ return {
40
+ reason: state.reason === null ? null : `CI on ${short(sha)}: ${state.reason}`,
41
+ unknown: null,
42
+ ...(state.pending ? { pending: true } : {}),
43
+ };
48
44
  }
49
45
 
50
46
  /**
@@ -1,21 +1,173 @@
1
1
  import { strict as assert } from "node:assert";
2
2
  import { test } from "node:test";
3
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
3
6
  import { ciNotGreen, ciState, notGreenReason } from "./ci-state.mjs";
4
7
 
5
8
  const SHA = "a".repeat(40);
6
9
  const run = (name, status, conclusion = null) => ({ name, status, conclusion });
7
- const reply = (...runs) => JSON.stringify({ total_count: runs.length, check_runs: runs });
10
+ const reply = (...runs) => JSON.stringify({ total_count: runs.length, check_runs: runs, workflow_runs: [] });
11
+
12
+ const ciGh = (checks, workflows) => (args) => args[1].includes("/actions/runs") ? (Array.isArray(workflows) ? workflows : [workflows]).map(page => JSON.stringify(page)).join("\n") : reply(...checks);
13
+
14
+ test("unfinished workflows on the head are pending before checks exist and after checks pass", () => {
15
+ for (const status of ["queued", "in_progress", "waiting", "pending", "requested"]) {
16
+ for (const checks of [[], [run("lint", "completed", "success")]]) {
17
+ const calls = [];
18
+ const read = ciGh(checks, [{ workflow_runs: [] }, { workflow_runs: [{ name: "CI", head_sha: SHA, status }] }]);
19
+ const gh = (args, options) => (calls.push({ args, options }), read(args));
20
+ const state = ciState(SHA, "/c", { gh, origin: () => "o/r" });
21
+ assert.equal(state.pending, true);
22
+ assert.equal(state.unknown, null);
23
+ assert.equal(state.reason, `CI on aaaaaaa: CI is ${status}`);
24
+ assert.ok(calls[1].args.includes("--paginate"));
25
+ assert.ok(!calls[1].args.includes("--slurp"));
26
+ assert.equal(calls[1].args[1], `repos/o/r/actions/runs?head_sha=${SHA}&per_page=100`);
27
+ assert.ok(calls[0].options.timeoutMs + calls[1].options.timeoutMs + 1000 < 10000);
28
+ }
29
+ }
30
+ });
31
+
32
+ test("completed workflows and workflows on other heads add no pending state", () => {
33
+ const gh = ciGh([run("lint", "completed", "success")], [{ workflow_runs: [
34
+ { name: "CI", head_sha: "b".repeat(40), status: "queued" },
35
+ { name: "CI", head_sha: SHA, status: "completed" },
36
+ ] }]);
37
+ assert.deepEqual(ciState(SHA, "/c", { gh, origin: () => "o/r" }), { reason: null, unknown: null });
38
+ });
39
+
40
+ test("a failed check wins over queued workflows and missing required checks", () => {
41
+ const gh = ciGh([run("build", "completed", "failure")], [{ workflow_runs: [{ name: "CI", head_sha: SHA, status: "queued" }] }]);
42
+ const state = ciState(SHA, "/c", { gh, origin: () => "o/r", requiredChecks: ["lint"] });
43
+ assert.equal(state.reason, "CI on aaaaaaa: build ended failure");
44
+ assert.equal(state.pending, undefined);
45
+ });
46
+
47
+ test("unreadable workflow lists keep a green-looking head unknown", () => {
48
+ for (const answer of [null, "not JSON", "{}", '{"workflow_runs":[]}\n{}']) {
49
+ const gh = (args) => args[1].includes("/actions/runs") ? answer : reply(run("lint", "completed", "success"));
50
+ assert.match(ciState(SHA, "/c", { gh, origin: () => "o/r" }).unknown ?? "", /gh/);
51
+ }
52
+ });
53
+
54
+ test("unreadable workflows preserve pending and failed checks", () => {
55
+ for (const answer of [null, "not JSON", "{}", '{"workflow_runs":[]}\n{}']) {
56
+ for (const [status, conclusion] of [["in_progress", null], ["completed", "failure"]]) {
57
+ const gh = (args) => args[1].includes("/actions/runs") ? answer : reply(run("build", status, conclusion));
58
+ assert.deepEqual(ciState(SHA, "/c", { gh, origin: () => "o/r" }), {
59
+ reason: `CI on aaaaaaa: build ${status === "completed" ? "ended failure" : "is in_progress"}`,
60
+ unknown: null,
61
+ ...(status === "completed" ? {} : { pending: true }),
62
+ });
63
+ }
64
+ }
65
+ });
66
+
67
+ test("workflow paths let a newer suite supersede a cancelled suite", () => {
68
+ const checks = [
69
+ { ...run("build", "completed", "cancelled"), check_suite: { id: 1 }, id: 1 },
70
+ { ...run("build", "completed", "success"), check_suite: { id: 2 }, id: 2 },
71
+ ];
72
+ const workflows = checks.map((check) => ({ check_suite_id: check.check_suite.id, path: ".github/workflows/ci.yml", head_sha: SHA, status: "completed" }));
73
+ assert.deepEqual(ciState(SHA, "/c", { gh: ciGh(checks, { workflow_runs: workflows }), origin: () => "o/r" }), { reason: null, unknown: null });
74
+ });
75
+
76
+ test("ciState uses caller-required checks and ignores invalid checkout configuration", (t) => {
77
+ const cwd = mkdtempSync(path.join(os.tmpdir(), "qc-ci-required-"));
78
+ t.after(() => rmSync(cwd, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }));
79
+ writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ ci: null }));
80
+ for (const checks of [[], [run("lint", "completed", "success")]]) {
81
+ const state = ciState(SHA, cwd, { gh: ciGh(checks, [{ workflow_runs: [] }]), origin: () => "o/r", requiredChecks: ["build"] });
82
+ assert.equal(state.pending, true);
83
+ assert.equal(state.reason, "CI on aaaaaaa: build is missing");
84
+ }
85
+ assert.deepEqual(ciState(SHA, cwd, { gh: ciGh([run("build", "completed", "success")], [{ workflow_runs: [] }]), origin: () => "o/r" }), { reason: null, unknown: null });
86
+ assert.deepEqual(ciState(SHA, cwd, { gh: ciGh([run("lint", "completed", "success")], [{ workflow_runs: [] }]), origin: () => "o/r" }), { reason: null, unknown: null });
87
+ });
88
+
89
+ test("checks with the same name in different suites remain separate", () => {
90
+ const failed = { ...run("build", "completed", "failure"), check_suite: { id: 1 }, started_at: "2026-01-01", id: 1 };
91
+ const passed = { ...run("build", "completed", "success"), check_suite: { id: 2 }, started_at: "2026-01-02", id: 2 };
92
+ for (const runs of [[failed, passed], [passed, failed]]) assert.equal(notGreenReason(runs), "build ended failure");
93
+ });
94
+
95
+ test("ciState reads every check-run page", () => {
96
+ const calls = [];
97
+ const gh = (args) => {
98
+ calls.push(args);
99
+ return [
100
+ { check_runs: [run("lint", "completed", "success")] },
101
+ { check_runs: [run("build", "completed", "failure")] },
102
+ ].map(page => JSON.stringify(page)).join("\n");
103
+ };
104
+ assert.equal(ciState(SHA, "/c", { gh, origin: () => "o/r" }).reason, "CI on aaaaaaa: build ended failure");
105
+ assert.ok(calls[0].includes("--paginate"));
106
+ assert.ok(!calls[0].includes("--slurp"));
107
+ assert.match(calls[0][1], /[?&]filter=all(?:&|$)/);
108
+ });
109
+
110
+ test("a queued rerun without a start time supersedes an older completed check", () => {
111
+ const older = { ...run("build", "completed", "success"), check_suite: { id: 1 }, started_at: "2026-01-01", id: 1 };
112
+ const newer = { ...run("build", "queued"), check_suite: { id: 1 }, started_at: null, id: 2 };
113
+ for (const runs of [[older, newer], [newer, older]]) assert.equal(notGreenReason(runs), "build is queued");
114
+ });
8
115
 
9
116
  test("a head whose check runs all completed green is green", () => {
10
117
  assert.equal(notGreenReason([run("lint", "completed", "success"), run("docs", "completed", "skipped"), run("x", "completed", "neutral")]), null);
11
118
  });
12
119
 
120
+ test("a newer success supersedes an older failure of the same check", () => {
121
+ const older = { ...run("build", "completed", "failure"), started_at: "2026-01-01T00:00:00Z", id: 20 };
122
+ const newer = { ...run("build", "completed", "success"), started_at: "2026-01-02T00:00:00Z", id: 10 };
123
+ for (const runs of [[older, newer], [newer, older]]) {
124
+ assert.equal(notGreenReason(runs), null);
125
+ assert.deepEqual(ciState(SHA, "/c", { gh: () => reply(...runs), origin: () => "o/r" }), { reason: null, unknown: null });
126
+ }
127
+ });
128
+
129
+ test("a newer failure supersedes an older success of the same check", () => {
130
+ const older = { ...run("build", "completed", "success"), started_at: "2026-01-01T00:00:00Z", id: 20 };
131
+ const newer = { ...run("build", "completed", "failure"), started_at: "2026-01-02T00:00:00Z", id: 10 };
132
+ for (const runs of [[older, newer], [newer, older]]) assert.equal(notGreenReason(runs), "build ended failure");
133
+ });
134
+
135
+ test("the higher run id breaks a tie in start times", () => {
136
+ for (const conclusion of ["success", "failure"]) {
137
+ const older = { ...run("build", "completed", conclusion === "success" ? "failure" : "success"), started_at: "2026-01-01T00:00:00Z", id: 9 };
138
+ const newer = { ...run("build", "completed", conclusion), started_at: older.started_at, id: 10 };
139
+ for (const runs of [[older, newer], [newer, older]]) {
140
+ assert.equal(notGreenReason(runs), conclusion === "success" ? null : "build ended failure");
141
+ }
142
+ }
143
+ });
144
+
145
+ test("the newest run counts while it is in progress", () => {
146
+ for (const conclusion of ["success", "failure"]) {
147
+ const older = { ...run("build", "completed", conclusion), started_at: "2026-01-01T00:00:00Z", id: 20 };
148
+ const newer = { ...run("build", "in_progress"), started_at: "2026-01-02T00:00:00Z", id: 10 };
149
+ for (const runs of [[older, newer], [newer, older]]) assert.equal(notGreenReason(runs), "build is in_progress");
150
+ }
151
+ });
152
+
153
+ test("a newer success for another check preserves a failure", () => {
154
+ const failed = { ...run("build", "completed", "failure"), started_at: "2026-01-01T00:00:00Z", id: 9 };
155
+ const passed = { ...run("lint", "completed", "success"), started_at: "2026-01-02T00:00:00Z", id: 10 };
156
+ assert.equal(notGreenReason([failed, passed]), "build ended failure");
157
+ });
158
+
13
159
  test("each failing conclusion makes the head not green, and the reason names the run", () => {
14
160
  for (const conclusion of ["failure", "cancelled", "timed_out", "action_required"]) {
15
161
  assert.match(notGreenReason([run("ok", "completed", "success"), run("build", "completed", conclusion)]) ?? "", new RegExp(`build.*${conclusion}`));
16
162
  }
17
163
  });
18
164
 
165
+ test("every completed conclusion outside the green allowlist fails", () => {
166
+ for (const conclusion of ["stale", "startup_failure", "future_conclusion", "", null, undefined]) {
167
+ assert.equal(notGreenReason([{ name: "build", status: "completed", conclusion }]), `build ended ${conclusion}`);
168
+ }
169
+ });
170
+
19
171
  test("a run that has not completed makes the head not green", () => {
20
172
  for (const status of ["queued", "in_progress", "waiting", "pending"]) {
21
173
  assert.match(notGreenReason([run("build", status)]) ?? "", new RegExp(`build.*${status}`));
@@ -34,7 +186,8 @@ test("ciNotGreen reads the check runs of the sha from the repository of origin",
34
186
  };
35
187
  const reason = ciNotGreen(SHA, "/checkout", { gh, origin: () => "o/r" });
36
188
  assert.match(reason ?? "", /^CI on aaaaaaa:.*build.*failure/);
37
- assert.equal(calls.length, 1);
189
+ assert.equal(calls.length, 2);
190
+ assert.match(calls[1].args[1], /actions\/runs\?head_sha=/);
38
191
  assert.equal(calls[0].args[0], "api");
39
192
  assert.ok(calls[0].args[1].startsWith(`repos/o/r/commits/${SHA}/check-runs`));
40
193
  assert.equal(calls[0].options.cwd, "/checkout");
@@ -74,3 +227,22 @@ test("ciState separates a head that is not green, a green head, and a head it ca
74
227
  assert.match(ciState("", "/c", { gh: () => null, origin }).unknown, /no commit/);
75
228
  for (const answer of [state(() => null), state(() => reply())]) assert.equal(answer.reason, null);
76
229
  });
230
+
231
+ test("ciState marks unfinished checks so a review policy can allow them", () => {
232
+ for (const status of ["queued", "in_progress", "waiting", "pending"]) {
233
+ const state = ciState(SHA, "/c", { gh: () => reply(run("build", status)), origin: () => "o/r" });
234
+ assert.equal(state.pending, true);
235
+ assert.equal(state.reason, `CI on aaaaaaa: build is ${status}`);
236
+ }
237
+ });
238
+
239
+ test("ciState gives a failure priority over an unfinished check", () => {
240
+ for (const conclusion of ["failure", "cancelled", "timed_out", "action_required"]) {
241
+ const state = ciState(SHA, "/c", {
242
+ gh: () => reply(run("lint", "in_progress"), run("build", "completed", conclusion)),
243
+ origin: () => "o/r",
244
+ });
245
+ assert.equal(state.pending, undefined);
246
+ assert.equal(state.reason, `CI on aaaaaaa: build ended ${conclusion}`);
247
+ }
248
+ });
@@ -7,6 +7,50 @@ import { parse } from "yaml";
7
7
  const WORKFLOW = fileURLToPath(new URL("../../templates/github/workflows/ci.yml", import.meta.url));
8
8
  const runs = () => parse(readFileSync(WORKFLOW, "utf8")).jobs.gates.steps.map((step) => step.run ?? "").join("\n");
9
9
 
10
+ test("the template runs on pull requests and trunk pushes, and cancels stale pull request runs", () => {
11
+ const workflow = parse(readFileSync(WORKFLOW, "utf8"));
12
+ assert.ok(Object.hasOwn(workflow.on, "pull_request"));
13
+ assert.deepEqual(workflow.on.push.branches, ["main", "master"]);
14
+ assert.ok(workflow.concurrency.group.includes("github.event.pull_request.number"));
15
+ assert.equal(workflow.concurrency["cancel-in-progress"], "${{ github.event_name != 'merge_group' }}");
16
+ });
17
+
18
+ const KIT_WORKFLOW = fileURLToPath(new URL("../../../../.github/workflows/ci.yml", import.meta.url));
19
+
20
+ for (const [name, file] of [["template", WORKFLOW], ["kit", KIT_WORKFLOW]]) {
21
+ test(`${name} skips drafts and starts CI when a draft becomes ready`, () => {
22
+ const workflow = parse(readFileSync(file, "utf8"));
23
+ assert.deepEqual(workflow.on.push.branches, name === "template" ? ["main", "master"] : ["main"]);
24
+ assert.deepEqual(workflow.on.pull_request.types, ["opened", "synchronize", "reopened", "ready_for_review"]);
25
+ assert.equal(workflow.jobs.gates.if, "${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}");
26
+ assert.ok(workflow.concurrency.group.includes("github.event.pull_request.number"));
27
+ assert.ok(workflow.concurrency.group.includes("github.event_name"));
28
+ assert.equal(workflow.concurrency["cancel-in-progress"], "${{ github.event_name != 'merge_group' }}");
29
+ assert.ok(Object.hasOwn(workflow.on, "merge_group"));
30
+ });
31
+
32
+ test(`${name} dispatch chooses Linux, Windows, or both matrix legs`, () => {
33
+ const workflow = parse(readFileSync(file, "utf8"));
34
+ const input = workflow.on.workflow_dispatch.inputs.os;
35
+ assert.equal(input.type, "choice");
36
+ assert.equal(input.required, true);
37
+ assert.equal(input.default, "both");
38
+ assert.deepEqual(input.options, ["linux", "windows", "both"]);
39
+ assert.equal(workflow.jobs.gates["runs-on"], "${{ matrix.os }}");
40
+ assert.equal(workflow.jobs.gates.defaults.run.shell, "bash");
41
+ const matrix = workflow.jobs.gates.strategy.matrix.os;
42
+ const expression = matrix.slice(3, -2).trim().replace(/fromJSON/g, "JSON.parse");
43
+ const evaluate = (event, os) => Function("github", "inputs", `return (${expression})`)({ event_name: event }, { os });
44
+ assert.deepEqual(evaluate("workflow_dispatch", "linux"), ["ubuntu-latest"]);
45
+ assert.deepEqual(evaluate("workflow_dispatch", "windows"), ["windows-latest"]);
46
+ assert.deepEqual(evaluate("workflow_dispatch", "both"), ["ubuntu-latest", "windows-latest"]);
47
+ const normal = ["ubuntu-latest", "windows-latest"];
48
+ assert.deepEqual(evaluate("pull_request", ""), normal);
49
+ assert.deepEqual(evaluate("push", ""), normal);
50
+ assert.deepEqual(evaluate("merge_group", ""), normal);
51
+ });
52
+ }
53
+
10
54
  test("the template installs with the package manager of the lockfile, so no one tool is assumed", () => {
11
55
  const text = runs();
12
56
  assert.match(text, /pnpm-lock\.yaml.*pnpm install --frozen-lockfile/);
@@ -28,3 +72,45 @@ test("the policy checks of a pull request are opt-in, not steps of the template"
28
72
  assert.doesNotMatch(text, /qc pr-check|qc prose/);
29
73
  assert.doesNotMatch(readFileSync(WORKFLOW, "utf8"), /^\s*# - run:/m);
30
74
  });
75
+
76
+
77
+ test("the CI template runs --affected on pull_request and pnpm test on push to main and on schedule", async () => {
78
+ for (const file of [WORKFLOW, KIT_WORKFLOW]) {
79
+ const workflow = parse(readFileSync(file, "utf8"));
80
+ assert.deepEqual(workflow.on.schedule, [{ cron: "0 2 * * *" }]);
81
+ assert.deepEqual(workflow.permissions, { contents: "read" });
82
+ const steps = workflow.jobs.gates.steps;
83
+ if (file === KIT_WORKFLOW) {
84
+ assert.doesNotMatch(readFileSync(file, "utf8"), /\bnpx\s+qc\b/);
85
+ }
86
+ const affected = steps.find((step) => /check --affected --base origin\/main/.test(step.run ?? ""));
87
+ assert.equal(affected.if, "github.event_name == 'pull_request'");
88
+ const full = steps.find((step) => /pnpm test|run test/.test(step.run ?? ""));
89
+ assert.equal(full.if, "github.event_name != 'pull_request'");
90
+ const job = workflow.jobs['report-failure'];
91
+ assert.equal(job.needs, 'gates');
92
+ assert.deepEqual(job.concurrency, { group: 'ci-red-${{ github.sha }}', 'cancel-in-progress': false });
93
+ assert.equal(job.if, "${{ always() && needs.gates.result == 'failure' && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'schedule') }}");
94
+ assert.equal(job.permissions.issues, 'write');
95
+ assert.equal(workflow.jobs.gates.permissions?.issues, undefined);
96
+ const script = job.steps.find((step) => step.uses?.startsWith('actions/github-script@')).with.script;
97
+ const calls = [], issues = [];
98
+ const github = { rest: { issues: {
99
+ async createLabel(args) { calls.push(args); },
100
+ async listForRepo() { return { data: issues }; },
101
+ async create(args) { calls.push(args); issues.push({ title: args.title }); },
102
+ } }, async paginate(fn, args) { return (await fn(args)).data; } };
103
+ const context = { repo: { owner: 'owner', repo: 'repo' }, sha: 'abc123', serverUrl: 'https://github.com', runId: 42 };
104
+ const run = new (Object.getPrototypeOf(async function() {}).constructor)('github', 'context', script);
105
+ await run(github, context); await run(github, context);
106
+ const created = calls.filter((args) => args.body);
107
+ assert.equal(created.length, 1);
108
+ assert.deepEqual(created[0].labels, ['ci-red', 'priority']);
109
+ assert.match(created[0].body, /abc123/);
110
+ assert.match(created[0].body, /https:\/\/github.com\/owner\/repo\/actions\/runs\/42/);
111
+ github.rest.issues.createLabel = async () => { throw Object.assign(Error('exists'), { status: 422 }); };
112
+ await run(github, context); assert.equal(calls.filter((args) => args.body).length, 1);
113
+ github.rest.issues.createLabel = async () => { throw Object.assign(Error('denied'), { status: 403 }); };
114
+ await assert.rejects(run(github, context), /denied/);
115
+ }
116
+ });
@@ -0,0 +1,37 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFileSync } from "node:fs";
3
+ import { test } from "node:test";
4
+ import { GLOBAL_SKILLS } from "../global-skills.mjs";
5
+
6
+ const core = readFileSync(new URL("../../../../user-config/claude/CLAUDE.core.md", import.meta.url), "utf8");
7
+
8
+ test("the core template requires review before merge", () => {
9
+ assert.doesNotMatch(core, /suspend/i);
10
+ assert.ok(core.includes("**Review before merge.** Every pull request gets a review before it merges. `architecture:reviewing-before-merge` has the details."));
11
+ });
12
+
13
+ test("the review skill supplies a route when the guard denies code-review", () => {
14
+ const skill = readFileSync(new URL("../../../../skills/reviewing-before-merge/SKILL.md", import.meta.url), "utf8");
15
+ assert.match(skill, /guard.*denies.*`\/code-review`.*`architecture:sdd-branch-reviewer`.*user.*`\/code-review`/);
16
+ });
17
+
18
+ test("the core template excludes personal instructions and paths", () => {
19
+ for (const text of ["Grammar", "Global Claude Rules", "~/.claude", ".Codex"]) {
20
+ assert.ok(!core.includes(text), `The core template contains ${text}`);
21
+ }
22
+ });
23
+
24
+ test("the core template starts with the skills heading", () => {
25
+ assert.ok(core.startsWith("## Rules that live in skills"));
26
+ });
27
+
28
+ test("the core template excludes setup markers", () => {
29
+ assert.doesNotMatch(core, /^.*architecture-kit:(?:begin|end).*$/m);
30
+ });
31
+
32
+ for (const name of GLOBAL_SKILLS) {
33
+ test(`the core template qualifies every reference to ${name}`, () => {
34
+ assert.ok(core.includes(`architecture:${name}`));
35
+ assert.doesNotMatch(core, new RegExp("(?<!architecture:)\\b" + name + "\\b"));
36
+ });
37
+ }