@aviaratech/ai-delivery 0.3.34 → 0.3.36

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 (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,144 +1,309 @@
1
- import assert from 'node:assert/strict';
2
- import { readFileSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
- import { execFileSync, spawnSync } from 'node:child_process';
4
- import { tmpdir } from 'node:os';
5
- import { join, resolve } from 'node:path';
6
- import { afterEach, test, vi } from 'vitest';
7
- import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
8
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
9
- import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
10
- import { z } from 'zod';
11
- import { createIssue, updateIssue, canonicalIssueBody, renderIssueHistory, readyCheck, issueInfo, listIssues, } from './issue.js';
12
- import { executeTool, startTrackedIssue } from './dispatch.js';
13
- import { digestValue } from './delivery/common.js';
14
- import { getAiDeliveryMcpTool } from './mcp/tools.js';
15
- import { IssueFields, ReadyIssue, renderIssueBody, parseIssueBody, ISSUE_BODY_MARKER } from './issueContract.js';
16
- import { syntheticDiscoveryConfig } from './fixtures/discovery.js';
1
+ import { quietReadViewResponse } from "./fixtures/readView.js";
2
+ import { issueProjectItemsResponse } from "./fixtures/issueProjectItems.js";
3
+ import assert from "node:assert/strict";
4
+ import { readFileSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
5
+ import { execFileSync, spawnSync } from "node:child_process";
6
+ import { tmpdir } from "node:os";
7
+ import { join, resolve } from "node:path";
8
+ import { afterEach, test, vi } from "vitest";
9
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
10
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
11
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
12
+ import { z } from "zod";
13
+ import {
14
+ createIssue,
15
+ updateIssue,
16
+ batchUpdateIssues,
17
+ getIncompleteIssueUpdate,
18
+ canonicalIssueBody,
19
+ renderIssueHistory,
20
+ readyCheck,
21
+ issueInfo,
22
+ listIssues
23
+ } from "./issue.js";
24
+ import { executeTool, startTrackedIssue } from "./dispatch.js";
25
+ import { digestValue } from "./delivery/common.js";
26
+ import { getAiDeliveryMcpTool } from "./mcp/tools.js";
27
+ import { IssueFields, ReadyIssue, renderIssueBody, parseIssueBody, ISSUE_BODY_MARKER } from "./issueContract.js";
28
+ import { syntheticDiscoveryConfig } from "./fixtures/discovery.js";
17
29
  afterEach(() => {
18
- vi.restoreAllMocks();
19
- vi.unstubAllEnvs();
30
+ vi.restoreAllMocks();
31
+ vi.unstubAllEnvs();
20
32
  });
21
- test('create renders all five status fields with a UTC timestamp and optional milestone', async () => {
22
- vi.spyOn(Date, 'now').mockReturnValue(Date.parse('2026-10-16T20:30:00Z'));
23
- for (const draft of [false, true]) {
24
- const f = fixture();
25
- const input = { ...ready(), draft, status: { nextMilestone: 'Run checks' } };
26
- const result = await createIssue(f.context, input);
27
- const status = result.body.split('## Status\n\n')[1].split('\n\n## Problem')[0];
28
- assert.equal(status, `- **State:** ${draft ? 'Draft' : 'Ready'}\n- **Last updated:** 2026-10-16T20:30:00.000Z UTC\n- **Next milestone:** Run checks\n- **Blockers:** None\n- **Latest journal:** None yet`);
29
- }
30
- const f = fixture();
31
- assert.match((await createIssue(f.context, ready())).body, /\*\*Next milestone:\*\* Not started/u);
33
+ test("create renders all five status fields with a UTC timestamp and optional milestone", async () => {
34
+ vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-10-16T20:30:00Z"));
35
+ for (const draft of [false, true]) {
36
+ const f2 = fixture();
37
+ const input = { ...ready(), draft, status: { nextMilestone: "Run checks" } };
38
+ const result = await createIssue(f2.context, input);
39
+ const status = result.body.split("## Status\n\n")[1].split("\n\n## Problem")[0];
40
+ assert.equal(
41
+ status,
42
+ `- **State:** ${draft ? "Draft" : "Ready"}
43
+ - **Last updated:** 2026-10-16T20:30:00.000Z UTC
44
+ - **Next milestone:** Run checks
45
+ - **Blockers:** None
46
+ - **Latest journal:** None yet`
47
+ );
48
+ }
49
+ const f = fixture();
50
+ assert.match((await createIssue(f.context, ready())).body, /\*\*Next milestone:\*\* Not started/u);
32
51
  });
33
- test('status-only patches preserve every outside-Status byte including canonical data and start markers', async () => {
34
- const f = fixture();
35
- const created = await createIssue(f.context, ready());
36
- f.live.body =
37
- created.body +
38
- '\n\n<!-- ai-delivery-start-intent: sha256:' +
39
- 'a'.repeat(64) +
40
- ' -->\n<!-- ai-delivery-start: sha256:' +
41
- 'b'.repeat(64) +
42
- ' -->';
43
- const before = f.live.body;
44
- const patch = { issueNumber: 17, status: { nextMilestone: 'Await review', blockers: 'None' } };
45
- const result = await updateIssue(f.context, patch);
46
- const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, '$1$2');
47
- assert.match(result.body, /\*\*Next milestone:\*\* Await review/u);
48
- assert.equal(outside(result.body), outside(before));
49
- assert.equal((await updateIssue(f.context, patch)).body, result.body);
50
- assert.equal(f.comments.length, 0);
52
+ test("status-only patches preserve every outside-Status byte including canonical data and start markers", async () => {
53
+ const f = fixture();
54
+ const created = await createIssue(f.context, ready());
55
+ f.live.body = created.body + "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
56
+ const before = f.live.body;
57
+ const patch = { issueNumber: 17, status: { nextMilestone: "Await review", blockers: "None" } };
58
+ const result = await updateIssue(f.context, patch);
59
+ const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, "$1$2");
60
+ assert.match(result.body, /\*\*Next milestone:\*\* Await review/u);
61
+ assert.equal(outside(result.body), outside(before));
62
+ assert.equal((await updateIssue(f.context, patch)).body, result.body);
63
+ assert.equal(f.comments.length, 0);
51
64
  });
52
- test('legacy rendering drops only by explicit retention choice or verified history and does not grow on repeat', async () => {
53
- const legacy = 'Retired criterion: accept every invalid identifier.\n';
54
- for (const preserveHistory of [undefined, false, true]) {
55
- const f = fixture();
56
- f.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
57
- const before = f.live.body;
58
- const result = await updateIssue(f.context, {
59
- issueNumber: 17,
60
- ...(preserveHistory === undefined ? {} : { preserveHistory }),
61
- });
62
- const readable = result.body.split('<!-- ai-delivery:issue-data@1 ')[0];
63
- assert.equal(readable.includes(legacy), preserveHistory === false);
64
- assert.equal(f.comments.length, preserveHistory === false ? 0 : 1);
65
- if (preserveHistory !== false) {
66
- const retained = f.comments[0].body.match(/Body:\n<pre>([\s\S]*)<\/pre>/u)[1]
67
- .replaceAll('&lt;', '<')
68
- .replaceAll('&gt;', '>')
69
- .replaceAll('&amp;', '&');
70
- assert.equal(retained, before);
71
- }
72
- const again = await updateIssue(f.context, {
73
- issueNumber: 17,
74
- ...(preserveHistory === undefined ? {} : { preserveHistory }),
75
- });
76
- assert.equal(again.body, result.body);
77
- assert.equal(f.comments.length, preserveHistory === false ? 0 : 1);
78
- }
79
- const f = fixture();
80
- f.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
81
- const drop = { issueNumber: 17, preserveHistory: false, retainLegacyBody: false };
82
- const result = await updateIssue(f.context, drop);
83
- assert.ok(!result.body.split('<!-- ai-delivery:issue-data@1 ')[0].includes(legacy));
84
- assert.equal(f.comments.length, 0);
65
+ test("explicit Project status records its reason without rewriting native issue fields", async () => {
66
+ const f = fixture();
67
+ const before = f.live.body;
68
+ const input = { issueNumber: 17, projectStatus: { status: "Blocked", reason: " Waiting for review. " } };
69
+ const result = await updateIssue(f.context, input);
70
+ assert.equal(result.projectStatus, "Blocked");
71
+ assert.equal(f.live.body, before);
72
+ assert.deepEqual(f.writes, []);
73
+ assert.equal(f.comments.length, 1);
74
+ assert.equal(f.comments[0].body, "Requested Project Status: Blocked.\n\nWaiting for review.");
75
+ await updateIssue(f.context, input);
76
+ assert.equal(f.comments.length, 1);
85
77
  });
86
- test('replacement legacy text remains visible until those incoming bytes have native history', async () => {
87
- const f = fixture();
88
- f.live.body = 'Original operator text.\n';
89
- const incoming = 'New operator text that was never in the previous body.\n';
90
- const result = await updateIssue(f.context, { issueNumber: 17, body: incoming, ...ready(), preserveHistory: true });
91
- assert.ok(result.body.split('<!-- ai-delivery:issue-data@1 ')[0].includes(incoming));
92
- assert.ok(!f.comments[0].body.includes(incoming));
78
+ test("explicit Project status validates public input and native truth before Project writes", async () => {
79
+ const schema = getAiDeliveryMcpTool("issue_update").inputSchema;
80
+ for (const projectStatus of [
81
+ { status: "Todo", reason: " " },
82
+ { status: "Queued", reason: "Review" },
83
+ { status: "Blocked", reason: "x".repeat(65536) },
84
+ { status: "Blocked", reason: "api_key=abcdefghijk12345" }
85
+ ]) {
86
+ assert.throws(() => schema.parse({ issueNumber: 17, projectStatus }));
87
+ const f2 = fixture();
88
+ await assert.rejects(updateIssue(f2.context, { issueNumber: 17, projectStatus }));
89
+ assert.equal(f2.comments.length + f2.statusWrites.length + f2.writes.length, 0);
90
+ }
91
+ for (const mode of ["openDone", "blockedTodo", "conflict", "missing"]) {
92
+ const f2 = fixture();
93
+ f2.controls.blockers = mode === "blockedTodo" || mode === "conflict";
94
+ f2.controls.blockerClosed = mode === "conflict";
95
+ f2.controls.blockerConflict = mode === "conflict";
96
+ f2.controls.missingNative = mode === "missing";
97
+ await assert.rejects(
98
+ updateIssue(f2.context, {
99
+ issueNumber: 17,
100
+ projectStatus: { status: mode === "openDone" ? "Done" : "Todo", reason: "Inspect native state." }
101
+ })
102
+ );
103
+ assert.equal(f2.statusWrites.length + f2.membershipWrites.length + f2.comments.length, 0);
104
+ }
105
+ const f = fixture();
106
+ f.controls.blockers = true;
107
+ f.controls.blockerClosed = true;
108
+ assert.equal(
109
+ (await updateIssue(f.context, {
110
+ issueNumber: 17,
111
+ projectStatus: { status: "Todo", reason: "Prerequisite closed." }
112
+ })).projectStatus,
113
+ "Todo"
114
+ );
93
115
  });
94
- test('default render omission reuses an existing exact authored history snapshot', async () => {
95
- const f = fixture();
96
- f.live.body = renderIssueBody({ ...ready(), legacyBody: 'Retired synthetic criterion.\n' });
97
- const before = f.live.body;
98
- const history = renderIssueHistory(f.live.title, before);
99
- f.comments.push({
100
- id: 91,
101
- body: history,
102
- html_url: 'https://github.com/example/widget/issues/17#issuecomment-91',
103
- user: { login: 'operator' },
104
- issue_url: 'https://api.github.com/repos/example/widget/issues/17',
105
- });
106
- const result = await updateIssue(f.context, { issueNumber: 17 });
107
- assert.equal(result.historyComment?.reused, true);
108
- assert.equal(f.comments.length, 1);
109
- assert.equal(f.comments[0].body, history);
110
- assert.ok(!result.body.split('<!-- ai-delivery:issue-data@1 ')[0].includes('Retired synthetic criterion.'));
116
+ test("explicit Project status rechecks native state after the reason and retains pending recovery", async () => {
117
+ const f = fixture();
118
+ const create = f.context.clients.rest.issues.createComment;
119
+ f.context.clients.rest.issues.createComment = (async (...args) => {
120
+ const result = await create(...args);
121
+ f.live.state = "closed";
122
+ return result;
123
+ });
124
+ await assert.rejects(
125
+ updateIssue(f.context, { issueNumber: 17, projectStatus: { status: "In Progress", reason: "Begin work." } })
126
+ );
127
+ assert.equal(f.comments.length, 1);
128
+ assert.equal(f.statusWrites.length, 0);
129
+ assert.equal(f.writes.length, 0);
111
130
  });
112
- test('normal-start recovery preserves legacy rendering across repeated exact retries', async () => {
113
- const f = fixture();
114
- f.controls.created = false;
115
- const request = getAiDeliveryMcpTool('issue_start').inputSchema.parse({
116
- title: ready().title,
117
- body: renderIssueBody({ ...ready(), legacyBody: 'Original operator context.\n' }),
118
- issueType: 'Task',
119
- points: 2,
120
- requestId: 'legacy-status-retry',
131
+ test("explicit Project partial recovery preserves reason and retries only pending work", async () => {
132
+ const f = fixture();
133
+ f.controls.projectFailure = "before";
134
+ const request = {
135
+ issueNumber: 17,
136
+ projectStatus: { status: "In Progress", reason: "Begin implementation." }
137
+ };
138
+ try {
139
+ await updateIssue(f.context, request);
140
+ assert.fail("Expected an incomplete Project update.");
141
+ } catch (error) {
142
+ const result = getIncompleteIssueUpdate(error);
143
+ assert.equal(result.native.status, "confirmed");
144
+ assert.equal(
145
+ result.native.projectStatusComment?.body,
146
+ "Requested Project Status: In Progress.\n\nBegin implementation."
147
+ );
148
+ }
149
+ assert.equal(f.comments.length, 1);
150
+ assert.equal(f.writes.length, 0);
151
+ f.controls.projectFailure = "";
152
+ const resumed = await batchUpdateIssues(f.context, { items: [request] });
153
+ assert.equal(resumed.results[0].status, "applied");
154
+ assert.deepEqual(Object.keys(resumed.results[0].changes), ["projectStatus"]);
155
+ assert.equal(f.comments.length, 1);
156
+ assert.equal(f.writes.length, 0);
157
+ assert.equal((await batchUpdateIssues(f.context, { items: [request] })).results[0].status, "unchanged");
158
+ f.controls.projectFailure = "readback";
159
+ assert.equal((await batchUpdateIssues(f.context, { items: [request] })).results[0].status, "failed");
160
+ assert.equal(f.comments.length, 1);
161
+ assert.equal(f.writes.length, 0);
162
+ });
163
+ test("explicit batch Project status waits for requested native closure", async () => {
164
+ const f = fixture();
165
+ const update = f.context.clients.rest.issues.update;
166
+ f.context.clients.rest.issues.update = (async (...args) => {
167
+ const result2 = await update(...args);
168
+ if (args[0]?.state === "closed") f.live.state = "closed";
169
+ return result2;
170
+ });
171
+ const result = await batchUpdateIssues(f.context, {
172
+ items: [
173
+ { issueNumber: 17, state: "closed", projectStatus: { status: "Done", reason: "Implementation complete." } }
174
+ ]
175
+ });
176
+ assert.equal(result.results[0].status, "applied");
177
+ assert.equal(result.results[0].relatedReadback.projectStatusReason, "Implementation complete.");
178
+ assert.equal(f.getStatus(), "Shipped");
179
+ });
180
+ test("explicit Project activation rechecks blockers after its capacity override comment", async () => {
181
+ const f = fixture();
182
+ f.controls.capacityMode = true;
183
+ f.live.labels = ["critical"];
184
+ f.context.config = {
185
+ ...f.context.config,
186
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
187
+ };
188
+ const create = f.context.clients.rest.issues.createComment;
189
+ f.context.clients.rest.issues.createComment = (async (...args) => {
190
+ const result = await create(...args);
191
+ if (args[0]?.body.startsWith("WIP capacity override.")) f.controls.blockers = true;
192
+ return result;
193
+ });
194
+ await assert.rejects(
195
+ updateIssue(f.context, {
196
+ issueNumber: 17,
197
+ overrideReason: "Admit capacity exception.",
198
+ projectStatus: { status: "In Progress", reason: "Begin work." }
199
+ })
200
+ );
201
+ assert.equal(f.statusWrites.length, 0);
202
+ assert.equal(f.getStatus(), "Queued");
203
+ });
204
+ test("explicit batch status refuses contradictory Project snapshots before unchanged success", async () => {
205
+ const f = fixture();
206
+ const request = { issueNumber: 17, projectStatus: { status: "Blocked", reason: "Await review." } };
207
+ await updateIssue(f.context, request);
208
+ const read = f.context.clients.rest.issues.getComment;
209
+ f.context.clients.rest.issues.getComment = (async (...args) => {
210
+ const result2 = await read(...args);
211
+ f.setStatus("Queued");
212
+ return result2;
213
+ });
214
+ const result = await batchUpdateIssues(f.context, { items: [request] });
215
+ assert.equal(result.results[0].status, "failed");
216
+ assert.equal(f.statusWrites.length, 1);
217
+ });
218
+ test("legacy rendering drops only by explicit retention choice or verified history and does not grow on repeat", async () => {
219
+ const legacy = "Retired criterion: accept every invalid identifier.\n";
220
+ for (const preserveHistory of [void 0, false, true]) {
221
+ const f2 = fixture();
222
+ f2.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
223
+ const before = f2.live.body;
224
+ const result2 = await updateIssue(f2.context, {
225
+ issueNumber: 17,
226
+ ...preserveHistory === void 0 ? {} : { preserveHistory }
121
227
  });
122
- await startTrackedIssue(f.context, request);
123
- const before = f.live.body;
124
- for (let retry = 0; retry < 2; retry++) {
125
- const result = await startTrackedIssue(f.context, request);
126
- assert.ok('reused' in result && result.reused);
127
- assert.equal(f.live.body, before);
228
+ const readable = result2.body.split("<!-- ai-delivery:issue-data@1 ")[0];
229
+ assert.equal(readable.includes(legacy), preserveHistory === false);
230
+ assert.equal(f2.comments.length, preserveHistory === false ? 0 : 1);
231
+ if (preserveHistory !== false) {
232
+ const retained = f2.comments[0].body.match(/Body:\n<pre>([\s\S]*)<\/pre>/u)[1].replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
233
+ assert.equal(retained, before);
128
234
  }
129
- assert.equal(f.writes.filter((input) => !('issue_number' in input)).length, 1);
130
- assert.equal(f.comments.length, 1);
235
+ const again = await updateIssue(f2.context, {
236
+ issueNumber: 17,
237
+ ...preserveHistory === void 0 ? {} : { preserveHistory }
238
+ });
239
+ assert.equal(again.body, result2.body);
240
+ assert.equal(f2.comments.length, preserveHistory === false ? 0 : 1);
241
+ }
242
+ const f = fixture();
243
+ f.live.body = renderIssueBody({ ...ready(), legacyBody: legacy });
244
+ const drop = { issueNumber: 17, preserveHistory: false, retainLegacyBody: false };
245
+ const result = await updateIssue(f.context, drop);
246
+ assert.ok(!result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes(legacy));
247
+ assert.equal(f.comments.length, 0);
248
+ });
249
+ test("replacement legacy text remains visible until those incoming bytes have native history", async () => {
250
+ const f = fixture();
251
+ f.live.body = "Original operator text.\n";
252
+ const incoming = "New operator text that was never in the previous body.\n";
253
+ const result = await updateIssue(f.context, { issueNumber: 17, body: incoming, ...ready(), preserveHistory: true });
254
+ assert.ok(result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes(incoming));
255
+ assert.ok(!f.comments[0].body.includes(incoming));
256
+ });
257
+ test("default render omission reuses an existing exact authored history snapshot", async () => {
258
+ const f = fixture();
259
+ f.live.body = renderIssueBody({ ...ready(), legacyBody: "Retired synthetic criterion.\n" });
260
+ const before = f.live.body;
261
+ const history = renderIssueHistory(f.live.title, before);
262
+ f.comments.push({
263
+ id: 91,
264
+ body: history,
265
+ html_url: "https://github.com/example/widget/issues/17#issuecomment-91",
266
+ user: { login: "operator" },
267
+ issue_url: "https://api.github.com/repos/example/widget/issues/17"
268
+ });
269
+ const result = await updateIssue(f.context, { issueNumber: 17 });
270
+ assert.equal(result.historyComment?.reused, true);
271
+ assert.equal(f.comments.length, 1);
272
+ assert.equal(f.comments[0].body, history);
273
+ assert.ok(!result.body.split("<!-- ai-delivery:issue-data@1 ")[0].includes("Retired synthetic criterion."));
274
+ });
275
+ test("normal-start recovery preserves legacy rendering across repeated exact retries", async () => {
276
+ const f = fixture();
277
+ f.controls.created = false;
278
+ const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
279
+ title: ready().title,
280
+ body: renderIssueBody({ ...ready(), legacyBody: "Original operator context.\n" }),
281
+ issueType: "Task",
282
+ points: 2,
283
+ requestId: "legacy-status-retry"
284
+ });
285
+ await startTrackedIssue(f.context, request);
286
+ const before = f.live.body;
287
+ for (let retry = 0; retry < 2; retry++) {
288
+ const result = await startTrackedIssue(f.context, request);
289
+ assert.ok("reused" in result && result.reused);
290
+ assert.equal(f.live.body, before);
291
+ }
292
+ assert.equal(f.writes.filter((input) => !("issue_number" in input)).length, 1);
293
+ assert.equal(f.comments.length, 1);
131
294
  });
132
- test.each([{ points: 4 }, { issueType: 'Feature' }])('normal-start retry refuses changed contract metadata %j before native writes', async (patch) => {
295
+ test.each([{ points: 4 }, { issueType: "Feature" }])(
296
+ "normal-start retry refuses changed contract metadata %j before native writes",
297
+ async (patch) => {
133
298
  const f = fixture();
134
299
  f.controls.created = false;
135
- f.context.config = { ...f.context.config, native: { ...f.context.config.native, issueTypes: ['Task', 'Feature'] } };
136
- const request = getAiDeliveryMcpTool('issue_start').inputSchema.parse({
137
- title: ready().title,
138
- body: renderIssueBody(ready()),
139
- issueType: 'Task',
140
- points: 2,
141
- requestId: 'contract-metadata-retry',
300
+ f.context.config = { ...f.context.config, native: { ...f.context.config.native, issueTypes: ["Task", "Feature"] } };
301
+ const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
302
+ title: ready().title,
303
+ body: renderIssueBody(ready()),
304
+ issueType: "Task",
305
+ points: 2,
306
+ requestId: "contract-metadata-retry"
142
307
  });
143
308
  await startTrackedIssue(f.context, request);
144
309
  await updateIssue(f.context, { issueNumber: 17, ...patch });
@@ -149,1814 +314,1862 @@ test.each([{ points: 4 }, { issueType: 'Feature' }])('normal-start retry refuses
149
314
  assert.equal(f.live.body, before);
150
315
  assert.equal(f.writes.length, writes);
151
316
  assert.equal(f.comments.length, comments);
317
+ }
318
+ );
319
+ test("default legacy omission refuses drift between preparation and the history snapshot", async () => {
320
+ const f = fixture();
321
+ f.live.body = renderIssueBody({ ...ready(), legacyBody: "Original unpreserved legacy bytes.\n" });
322
+ f.controls.driftBeforeUpdate = true;
323
+ await assert.rejects(updateIssue(f.context, { issueNumber: 17 }), /content changed/u);
324
+ assert.equal(f.live.body, "Concurrent operator edit");
325
+ assert.equal(f.comments.length, 0);
326
+ assert.equal(f.writes.length, 0);
152
327
  });
153
- test('default legacy omission refuses drift between preparation and the history snapshot', async () => {
154
- const f = fixture();
155
- f.live.body = renderIssueBody({ ...ready(), legacyBody: 'Original unpreserved legacy bytes.\n' });
156
- f.controls.driftBeforeUpdate = true;
157
- await assert.rejects(updateIssue(f.context, { issueNumber: 17 }), /content changed/u);
158
- assert.equal(f.live.body, 'Concurrent operator edit');
159
- assert.equal(f.comments.length, 0);
160
- assert.equal(f.writes.length, 0);
328
+ test("status-only updates preserve embedded metadata and old formatting despite different native metadata", async () => {
329
+ const f = fixture();
330
+ const data = {
331
+ ...ready(),
332
+ acceptanceCriteria: [{ behavior: "Reject malformed input:\n- Empty input", verifiedBy: "Regression test." }]
333
+ };
334
+ f.live.body = renderIssueBody(data).replace(" - Empty input\n\n Verified", "- Empty input\n Verified") + "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
335
+ f.controls.livePoints = 4;
336
+ f.live.type.name = "Feature";
337
+ const before = f.live.body;
338
+ const patch = { issueNumber: 17, status: { nextMilestone: "Await review" } };
339
+ const result = await updateIssue(f.context, patch);
340
+ const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, "$1$2");
341
+ assert.equal(outside(result.body), outside(before));
342
+ assert.equal(f.controls.livePoints, 4);
343
+ assert.equal(f.live.type.name, "Feature");
344
+ assert.equal(f.writes.length, 1);
345
+ assert.deepEqual(Object.keys(f.writes[0]).sort(), ["body", "issue_number", "owner", "repo"]);
161
346
  });
162
- test('status-only updates preserve embedded metadata and old formatting despite different native metadata', async () => {
347
+ test("status patches reject secrets, multiline and unknown fields without native writes", async () => {
348
+ for (const status of [
349
+ { nextMilestone: "password=" + "X".repeat(16) },
350
+ { nextMilestone: "Next\n## Problem" },
351
+ { unknown: "unexpected" }
352
+ ]) {
163
353
  const f = fixture();
164
- const data = {
165
- ...ready(),
166
- acceptanceCriteria: [{ behavior: 'Reject malformed input:\n- Empty input', verifiedBy: 'Regression test.' }],
167
- };
168
- f.live.body =
169
- renderIssueBody(data).replace(' - Empty input\n\n Verified', '- Empty input\n Verified') +
170
- '\n\n<!-- ai-delivery-start-intent: sha256:' +
171
- 'a'.repeat(64) +
172
- ' -->\n<!-- ai-delivery-start: sha256:' +
173
- 'b'.repeat(64) +
174
- ' -->';
175
- f.controls.livePoints = 4;
176
- f.live.type.name = 'Feature';
177
- const before = f.live.body;
178
- const patch = { issueNumber: 17, status: { nextMilestone: 'Await review' } };
179
- const result = await updateIssue(f.context, patch);
180
- const outside = (body) => body.replace(/(## Status\n\n)[\s\S]*?(\n\n## Problem)/u, '$1$2');
181
- assert.equal(outside(result.body), outside(before));
182
- assert.equal(f.controls.livePoints, 4);
183
- assert.equal(f.live.type.name, 'Feature');
184
- assert.equal(f.writes.length, 1);
185
- assert.deepEqual(Object.keys(f.writes[0]).sort(), ['body', 'issue_number', 'owner', 'repo']);
186
- });
187
- test('status patches reject secrets, multiline and unknown fields without native writes', async () => {
188
- for (const status of [
189
- { nextMilestone: 'password=' + 'X'.repeat(16) },
190
- { nextMilestone: 'Next\n## Problem' },
191
- { unknown: 'unexpected' },
192
- ]) {
193
- const f = fixture();
194
- const patch = { issueNumber: 17, status };
195
- await assert.rejects(updateIssue(f.context, patch));
196
- assert.equal(f.writes.length, 0);
197
- assert.equal(f.comments.length, 0);
198
- }
199
- });
200
- test('status-only patches refuse concurrent native body drift before overwriting it', async () => {
201
- const f = fixture();
202
- f.controls.driftBeforeUpdate = true;
203
- const patch = { issueNumber: 17, status: { nextMilestone: 'Await review' } };
204
- await assert.rejects(updateIssue(f.context, patch), /content changed/u);
205
- assert.equal(f.live.body, 'Concurrent operator edit');
354
+ const patch = { issueNumber: 17, status };
355
+ await assert.rejects(updateIssue(f.context, patch));
206
356
  assert.equal(f.writes.length, 0);
357
+ assert.equal(f.comments.length, 0);
358
+ }
207
359
  });
208
- test('CLI typed field files reach status privacy validation before configuration', () => {
209
- const root = mkdtempSync(join(tmpdir(), 'delivery130-status-'));
210
- try {
211
- const file = join(root, 'fields.json');
212
- writeFileSync(file, JSON.stringify({ ...ready(), status: { nextMilestone: 'password=' + 'X'.repeat(16) } }));
213
- const result = spawnSync(process.execPath, [resolve('dist/cli.js'), '--repo', 'example/widget', 'create', '--title', ready().title, '--fields-file', file], { encoding: 'utf8' });
214
- assert.notEqual(result.status, 0);
215
- assert.match(result.stderr, /Remove credentials and private keys from public status fields/u);
216
- assert.ok(!result.stderr.includes('X'.repeat(16)));
217
- }
218
- finally {
219
- rmSync(root, { recursive: true, force: true });
220
- }
360
+ test("status-only patches refuse concurrent native body drift before overwriting it", async () => {
361
+ const f = fixture();
362
+ f.controls.driftBeforeUpdate = true;
363
+ const patch = { issueNumber: 17, status: { nextMilestone: "Await review" } };
364
+ await assert.rejects(updateIssue(f.context, patch), /content changed/u);
365
+ assert.equal(f.live.body, "Concurrent operator edit");
366
+ assert.equal(f.writes.length, 0);
221
367
  });
222
- test('status updates retain old multiline canonical formatting and reject ambiguous status blocks', async () => {
223
- const f = fixture();
224
- const data = {
225
- ...ready(),
226
- acceptanceCriteria: [{ behavior: 'Reject malformed input:\n- Empty input', verifiedBy: 'Regression test.' }],
227
- };
228
- f.live.body = renderIssueBody(data).replace(' - Empty input\n\n Verified', '- Empty input\n Verified');
229
- const before = f.live.body.split('\n\n## Problem')[1];
230
- const patch = { issueNumber: 17, status: { nextMilestone: '<literal> *text* [link]' } };
231
- const result = await updateIssue(f.context, patch);
232
- assert.equal(result.body.split('\n\n## Problem')[1], before);
233
- assert.match(result.body, /&lt;literal&gt; \\\*text\\\* \\\[link\\\]/u);
234
- f.live.body = result.body.replace('- **Blockers:** None', '- **Blockers:** None\n- **Blockers:** Other');
235
- const writes = f.writes.length;
236
- await assert.rejects(updateIssue(f.context, patch), /unambiguous status/u);
237
- assert.equal(f.writes.length, writes);
368
+ test("CLI typed field files reach status privacy validation before configuration", { tags: ["release"] }, () => {
369
+ const root = mkdtempSync(join(tmpdir(), "delivery130-status-"));
370
+ try {
371
+ const file = join(root, "fields.json");
372
+ writeFileSync(file, JSON.stringify({ ...ready(), status: { nextMilestone: "password=" + "X".repeat(16) } }));
373
+ const result = spawnSync(
374
+ process.execPath,
375
+ [resolve("dist/cli.js"), "--repo", "example/widget", "create", "--title", ready().title, "--fields-file", file],
376
+ { encoding: "utf8" }
377
+ );
378
+ assert.notEqual(result.status, 0);
379
+ assert.match(result.stderr, /Remove credentials and private keys from public status fields/u);
380
+ assert.ok(!result.stderr.includes("X".repeat(16)));
381
+ } finally {
382
+ rmSync(root, { recursive: true, force: true });
383
+ }
384
+ });
385
+ test("status updates retain old multiline canonical formatting and reject ambiguous status blocks", async () => {
386
+ const f = fixture();
387
+ const data = {
388
+ ...ready(),
389
+ acceptanceCriteria: [{ behavior: "Reject malformed input:\n- Empty input", verifiedBy: "Regression test." }]
390
+ };
391
+ f.live.body = renderIssueBody(data).replace(" - Empty input\n\n Verified", "- Empty input\n Verified");
392
+ const before = f.live.body.split("\n\n## Problem")[1];
393
+ const patch = { issueNumber: 17, status: { nextMilestone: "<literal> *text* [link]" } };
394
+ const result = await updateIssue(f.context, patch);
395
+ assert.equal(result.body.split("\n\n## Problem")[1], before);
396
+ assert.match(result.body, /&lt;literal&gt; \\\*text\\\* \\\[link\\\]/u);
397
+ f.live.body = result.body.replace("- **Blockers:** None", "- **Blockers:** None\n- **Blockers:** Other");
398
+ const writes = f.writes.length;
399
+ await assert.rejects(updateIssue(f.context, patch), /unambiguous status/u);
400
+ assert.equal(f.writes.length, writes);
238
401
  });
239
402
  const ready = () => IssueFields.parse({
240
- title: 'Reject invalid widget identifiers before persistence',
241
- issueType: 'Task',
242
- points: 2,
243
- problem: 'Malformed identifiers reach persistence.',
244
- outcome: 'Reject malformed widget identifiers before persistence.',
245
- acceptanceCriteria: [
246
- {
247
- behavior: 'An invalid identifier returns an error with zero persistence calls.',
248
- verifiedBy: 'A portable mocked persistence regression test.',
249
- },
250
- ],
251
- outOfScope: ['Storage changes.'],
252
- context: { components: ['widget'], files: [], evidence: [] },
403
+ title: "Reject invalid widget identifiers before persistence",
404
+ issueType: "Task",
405
+ points: 2,
406
+ problem: "Malformed identifiers reach persistence.",
407
+ outcome: "Reject malformed widget identifiers before persistence.",
408
+ acceptanceCriteria: [
409
+ {
410
+ behavior: "An invalid identifier returns an error with zero persistence calls.",
411
+ verifiedBy: "A portable mocked persistence regression test."
412
+ }
413
+ ],
414
+ outOfScope: ["Storage changes."],
415
+ context: { components: ["widget"], files: [], evidence: [] }
253
416
  });
254
417
  function fixture() {
255
- const live = {
256
- number: 17,
257
- id: 117,
258
- node_id: 'ISSUE17',
259
- title: ready().title,
260
- body: renderIssueBody(ready()),
261
- state: 'open',
262
- created_at: '2026-01-01T00:00:00Z',
263
- updated_at: '2026-01-01T00:00:00Z',
264
- labels: [],
265
- type: { name: 'Task' },
266
- html_url: 'https://github.com/example/widget/issues/17',
267
- };
268
- const writes = [];
269
- const comments = [];
270
- const controls = {
271
- role: 'author',
272
- ignoreBody: false,
273
- wrongCreateRepo: false,
274
- driftAfterHistory: false,
275
- driftBeforeUpdate: false,
276
- created: true,
277
- blockers: false,
278
- trackingParent: false,
279
- livePoints: 2,
280
- projectMember: true,
281
- projectArchived: false,
282
- projectFailure: '',
283
- journalFailure: false,
284
- branchFailure: false,
285
- closeAfterBranch: false,
286
- blockAfterBranch: false,
287
- capacityMode: false,
288
- growAfterBranch: false,
289
- incompleteCapacity: false,
290
- corruptCapacityComment: false,
291
- capacityPageSize: 0,
292
- };
293
- const capacity = [];
294
- const branchWrites = [];
295
- const branches = [];
296
- let points = 2;
297
- let status = 'Queued';
298
- const statusWrites = [];
299
- const membershipWrites = [];
300
- let issueReads = 0;
301
- const optionId = () => ({ Queued: 'TODO', Active: 'ACTIVE', Waiting: 'BLOCKED', Shipped: 'DONE' })[status];
302
- const values = (number = 17) => [
303
- {
304
- issue_field_id: 101,
305
- issue_field_name: 'Estimate',
306
- data_type: 'single_select',
307
- value: String(controls.livePoints),
308
- single_select_option: { name: String(controls.livePoints) },
418
+ const live = {
419
+ number: 17,
420
+ id: 117,
421
+ node_id: "ISSUE17",
422
+ title: ready().title,
423
+ body: renderIssueBody(ready()),
424
+ state: "open",
425
+ created_at: "2026-01-01T00:00:00Z",
426
+ updated_at: "2026-01-01T00:00:00Z",
427
+ labels: [],
428
+ type: { name: "Task" },
429
+ html_url: "https://github.com/example/widget/issues/17"
430
+ };
431
+ const writes = [];
432
+ const comments = [];
433
+ const controls = {
434
+ role: "author",
435
+ ignoreBody: false,
436
+ wrongCreateRepo: false,
437
+ driftAfterHistory: false,
438
+ driftBeforeUpdate: false,
439
+ created: true,
440
+ blockers: false,
441
+ blockerClosed: false,
442
+ blockerConflict: false,
443
+ missingNative: false,
444
+ closeAfterReason: false,
445
+ trackingParent: false,
446
+ livePoints: 2,
447
+ projectMember: true,
448
+ projectArchived: false,
449
+ projectFailure: "",
450
+ journalFailure: false,
451
+ branchFailure: false,
452
+ closeAfterBranch: false,
453
+ blockAfterBranch: false,
454
+ capacityMode: false,
455
+ growAfterBranch: false,
456
+ incompleteCapacity: false,
457
+ corruptCapacityComment: false,
458
+ capacityPageSize: 0
459
+ };
460
+ const capacity = [];
461
+ const branchWrites = [];
462
+ const branches = [];
463
+ let points = 2;
464
+ let status = "Queued";
465
+ const statusWrites = [];
466
+ const membershipWrites = [];
467
+ let issueReads = 0;
468
+ const optionId = () => ({ Queued: "TODO", Active: "ACTIVE", Waiting: "BLOCKED", Shipped: "DONE" })[status];
469
+ const values = (number = 17) => [
470
+ {
471
+ issue_field_id: 101,
472
+ issue_field_name: "Estimate",
473
+ data_type: "single_select",
474
+ value: String(controls.livePoints),
475
+ single_select_option: { name: String(controls.livePoints) }
476
+ },
477
+ ...controls.capacityMode ? [
478
+ {
479
+ issue_field_id: 102,
480
+ issue_field_name: "Urgency",
481
+ data_type: "single_select",
482
+ single_select_option: {
483
+ name: number === 17 ? "High" : capacity.find((x) => x.number === number)?.value ?? "Low"
484
+ }
485
+ },
486
+ {
487
+ issue_field_id: 103,
488
+ issue_field_name: "Tags",
489
+ data_type: "multi_select",
490
+ multi_select_options: [{ name: "0" }]
491
+ }
492
+ ] : []
493
+ ];
494
+ const context = {
495
+ root: "/synthetic-non-git",
496
+ repo: { owner: "example", repo: "widget" },
497
+ config: syntheticDiscoveryConfig,
498
+ projectConfiguration: {
499
+ projectId: "PROJECT",
500
+ projectNumber: 1,
501
+ title: "Delivery",
502
+ writable: true,
503
+ pointsFieldId: "POINTS",
504
+ priorityFieldId: "PRIORITY",
505
+ statusFieldId: "STATUS",
506
+ statusOptionIds: { Todo: "TODO", "In Progress": "ACTIVE", Blocked: "BLOCKED", Done: "DONE" },
507
+ settings: {
508
+ number: 1,
509
+ title: "Delivery",
510
+ statusField: "Flow",
511
+ statuses: { Todo: "Queued", "In Progress": "Active", Blocked: "Waiting", Done: "Shipped" }
512
+ }
513
+ },
514
+ clients: {
515
+ get role() {
516
+ return controls.role;
517
+ },
518
+ authenticatedAuthor: async () => ({ actorLogin: "operator", credentialIdentity: "user:1" }),
519
+ rest: {
520
+ issues: {
521
+ listSubIssues: async () => ({
522
+ data: controls.trackingParent ? [
523
+ {
524
+ ...live,
525
+ number: 18,
526
+ id: 118,
527
+ node_id: "ISSUE18",
528
+ html_url: "https://github.com/example/widget/issues/18",
529
+ url: "https://api.github.com/repos/example/widget/issues/18",
530
+ repository_url: "https://api.github.com/repos/example/widget"
531
+ }
532
+ ] : []
533
+ }),
534
+ get: async (input) => {
535
+ if (controls.driftBeforeUpdate && ++issueReads > 1) live.body = "Concurrent operator edit";
536
+ if (input.issue_number === 18 && controls.blockers)
537
+ return {
538
+ data: {
539
+ ...live,
540
+ number: 18,
541
+ node_id: "ISSUE18",
542
+ state: controls.blockerClosed ? "closed" : "open",
543
+ html_url: "https://github.com/example/widget/issues/18"
544
+ }
545
+ };
546
+ if (controls.capacityMode && input.issue_number !== 17) {
547
+ const row = capacity.find((x) => x.number === input.issue_number);
548
+ return {
549
+ data: {
550
+ ...live,
551
+ number: row.number,
552
+ node_id: "ISSUE" + String(row.number),
553
+ labels: [row.label],
554
+ html_url: "https://github.com/example/widget/issues/" + String(row.number)
555
+ }
556
+ };
557
+ }
558
+ return { data: { ...live } };
559
+ },
560
+ listLabelsForRepo: async () => ({ data: [{ name: "critical" }, { name: "other" }] }),
561
+ listForRepo: async (input) => ({
562
+ headers: controls.capacityPageSize && (input.page ?? 1) === 1 ? { link: '<https://api.github.com/repos/example/widget/issues?page=2&per_page=100>; rel="next"' } : {},
563
+ data: controls.capacityMode ? (controls.incompleteCapacity ? [] : [
564
+ { ...live },
565
+ ...capacity.map((x) => ({
566
+ ...live,
567
+ number: x.number,
568
+ node_id: "ISSUE" + String(x.number),
569
+ labels: [x.label],
570
+ html_url: "https://github.com/example/widget/issues/" + String(x.number)
571
+ }))
572
+ ]).slice(
573
+ ((input.page ?? 1) - 1) * (controls.capacityPageSize || input.per_page || 100),
574
+ (input.page ?? 1) * (controls.capacityPageSize || input.per_page || 100)
575
+ ) : controls.created ? [{ ...live }] : []
576
+ }),
577
+ create: async (input) => {
578
+ writes.push(input);
579
+ controls.created = true;
580
+ live.title = String(input.title);
581
+ live.body = String(input.body);
582
+ live.type = { name: String(input.type) };
583
+ return {
584
+ data: {
585
+ ...live,
586
+ ...controls.wrongCreateRepo ? { html_url: "https://github.com/other/widget/issues/17" } : {}
587
+ }
588
+ };
589
+ },
590
+ update: async (input) => {
591
+ writes.push(input);
592
+ if (!controls.ignoreBody && typeof input.body === "string") live.body = input.body;
593
+ if (typeof input.title === "string") live.title = input.title;
594
+ if (typeof input.type === "string") live.type = { name: input.type };
595
+ return { data: { ...live } };
596
+ },
597
+ listComments: async () => ({ data: comments }),
598
+ createComment: async (input) => {
599
+ const comment = {
600
+ id: 91 + comments.length,
601
+ body: input.body,
602
+ html_url: "https://github.com/example/widget/issues/17#issuecomment-" + String(91 + comments.length),
603
+ user: { login: "operator" },
604
+ issue_url: "https://api.github.com/repos/example/widget/issues/17"
605
+ };
606
+ comments.push(comment);
607
+ if (controls.journalFailure) throw new Error("Lost journal response");
608
+ return { data: comment };
609
+ },
610
+ getComment: async (input) => {
611
+ if (controls.driftAfterHistory) live.body = "Concurrent owner content";
612
+ const found = comments.find((c) => c.id === input.comment_id);
613
+ return {
614
+ data: controls.corruptCapacityComment && found ? { ...found, user: { login: "foreign-writer" } } : found
615
+ };
616
+ }
309
617
  },
310
- ...(controls.capacityMode
311
- ? [
618
+ repos: { get: async () => ({ data: { default_branch: "main", node_id: "REPOSITORY" } }) },
619
+ git: { getRef: async () => ({ data: { object: { sha: "a".repeat(40) } } }) },
620
+ request: async (route, input) => {
621
+ if (route === "GET /orgs/{org}/issue-fields")
622
+ return {
623
+ data: [
312
624
  {
313
- issue_field_id: 102,
314
- issue_field_name: 'Urgency',
315
- data_type: 'single_select',
316
- single_select_option: {
317
- name: number === 17 ? 'High' : (capacity.find((x) => x.number === number)?.value ?? 'Low'),
318
- },
625
+ id: 101,
626
+ name: "Estimate",
627
+ data_type: "single_select",
628
+ options: ["1", "2", "4"].map((name) => ({ name }))
319
629
  },
320
630
  {
321
- issue_field_id: 103,
322
- issue_field_name: 'Tags',
323
- data_type: 'multi_select',
324
- multi_select_options: [{ name: '0' }],
325
- },
326
- ]
327
- : []),
328
- ];
329
- const context = {
330
- root: '/synthetic-non-git',
331
- repo: { owner: 'example', repo: 'widget' },
332
- config: syntheticDiscoveryConfig,
333
- projectConfiguration: {
334
- projectId: 'PROJECT',
335
- projectNumber: 1,
336
- title: 'Delivery',
337
- writable: true,
338
- pointsFieldId: 'POINTS',
339
- priorityFieldId: 'PRIORITY',
340
- statusFieldId: 'STATUS',
341
- statusOptionIds: { Todo: 'TODO', 'In Progress': 'ACTIVE', Blocked: 'BLOCKED', Done: 'DONE' },
342
- settings: {
343
- number: 1,
344
- title: 'Delivery',
345
- statusField: 'Flow',
346
- statuses: { Todo: 'Queued', 'In Progress': 'Active', Blocked: 'Waiting', Done: 'Shipped' },
347
- },
348
- },
349
- clients: {
350
- get role() {
351
- return controls.role;
352
- },
353
- authenticatedAuthor: async () => ({ actorLogin: 'operator', credentialIdentity: 'user:1' }),
354
- rest: {
355
- issues: {
356
- listSubIssues: async () => ({ data: controls.trackingParent ? [{ number: 18 }] : [] }),
357
- get: async (input) => {
358
- if (controls.driftBeforeUpdate && ++issueReads > 1)
359
- live.body = 'Concurrent operator edit';
360
- if (controls.capacityMode && input.issue_number !== 17) {
361
- const row = capacity.find((x) => x.number === input.issue_number);
362
- return {
363
- data: {
364
- ...live,
365
- number: row.number,
366
- node_id: 'ISSUE' + String(row.number),
367
- labels: [row.label],
368
- html_url: 'https://github.com/example/widget/issues/' + String(row.number),
369
- },
370
- };
371
- }
372
- return { data: { ...live } };
373
- },
374
- listLabelsForRepo: async () => ({ data: [{ name: 'critical' }, { name: 'other' }] }),
375
- listForRepo: async (input) => ({
376
- headers: controls.capacityPageSize && (input.page ?? 1) === 1
377
- ? { link: '<https://api.github.com/repos/example/widget/issues?page=2&per_page=100>; rel="next"' }
378
- : {},
379
- data: controls.capacityMode
380
- ? (controls.incompleteCapacity
381
- ? []
382
- : [
383
- { ...live },
384
- ...capacity.map((x) => ({
385
- ...live,
386
- number: x.number,
387
- node_id: 'ISSUE' + String(x.number),
388
- labels: [x.label],
389
- html_url: 'https://github.com/example/widget/issues/' + String(x.number),
390
- })),
391
- ]).slice(((input.page ?? 1) - 1) * (controls.capacityPageSize || input.per_page || 100), (input.page ?? 1) * (controls.capacityPageSize || input.per_page || 100))
392
- : controls.created
393
- ? [{ ...live }]
394
- : [],
395
- }),
396
- create: async (input) => {
397
- writes.push(input);
398
- controls.created = true;
399
- live.title = String(input.title);
400
- live.body = String(input.body);
401
- live.type = { name: String(input.type) };
402
- return {
403
- data: {
404
- ...live,
405
- ...(controls.wrongCreateRepo ? { html_url: 'https://github.com/other/widget/issues/17' } : {}),
406
- },
407
- };
408
- },
409
- update: async (input) => {
410
- writes.push(input);
411
- if (!controls.ignoreBody && typeof input.body === 'string')
412
- live.body = input.body;
413
- if (typeof input.title === 'string')
414
- live.title = input.title;
415
- if (typeof input.type === 'string')
416
- live.type = { name: input.type };
417
- return { data: { ...live } };
418
- },
419
- listComments: async () => ({ data: comments }),
420
- createComment: async (input) => {
421
- const comment = {
422
- id: 91 + comments.length,
423
- body: input.body,
424
- html_url: 'https://github.com/example/widget/issues/17#issuecomment-' + String(91 + comments.length),
425
- user: { login: 'operator' },
426
- issue_url: 'https://api.github.com/repos/example/widget/issues/17',
427
- };
428
- comments.push(comment);
429
- if (controls.journalFailure)
430
- throw new Error('Lost journal response');
431
- return { data: comment };
432
- },
433
- getComment: async (input) => {
434
- if (controls.driftAfterHistory)
435
- live.body = 'Concurrent owner content';
436
- const found = comments.find((c) => c.id === input.comment_id);
437
- return {
438
- data: controls.corruptCapacityComment && found ? { ...found, user: { login: 'foreign-writer' } } : found,
439
- };
440
- },
631
+ id: 102,
632
+ name: "Urgency",
633
+ data_type: "single_select",
634
+ options: ["High", "Low"].map((name) => ({ name }))
441
635
  },
442
- repos: { get: async () => ({ data: { default_branch: 'main', node_id: 'REPOSITORY' } }) },
443
- git: { getRef: async () => ({ data: { object: { sha: 'a'.repeat(40) } } }) },
444
- request: async (route, input) => {
445
- if (route === 'GET /orgs/{org}/issue-fields')
446
- return {
447
- data: [
448
- {
449
- id: 101,
450
- name: 'Estimate',
451
- data_type: 'single_select',
452
- options: ['1', '2', '4'].map((name) => ({ name })),
453
- },
454
- {
455
- id: 102,
456
- name: 'Urgency',
457
- data_type: 'single_select',
458
- options: ['High', 'Low'].map((name) => ({ name })),
459
- },
460
- ...(controls.capacityMode ? [{ id: 103, name: 'Tags', data_type: 'multi_select' }] : []),
461
- ],
462
- };
463
- if (route.startsWith('POST ')) {
464
- const fields = input.issue_field_values;
465
- points = Number(fields.find((f) => f.field_id === 101)?.value ?? points);
466
- controls.livePoints = points;
467
- return { data: values() };
636
+ ...controls.capacityMode ? [{ id: 103, name: "Tags", data_type: "multi_select" }] : []
637
+ ]
638
+ };
639
+ if (route.startsWith("POST ")) {
640
+ const fields = input.issue_field_values;
641
+ points = Number(fields.find((f) => f.field_id === 101)?.value ?? points);
642
+ controls.livePoints = points;
643
+ return { data: values() };
644
+ }
645
+ if (route.startsWith("GET ")) return { data: values(Number(input.issue_number ?? 17)) };
646
+ throw new Error("Unexpected native request " + route);
647
+ }
648
+ },
649
+ graphql: async (query, input) => {
650
+ if (query.includes("DeliveryIssueBranches"))
651
+ return {
652
+ repository: {
653
+ issue: {
654
+ linkedBranches: {
655
+ nodes: branches.map((branch) => ({
656
+ ref: {
657
+ name: branch.name,
658
+ target: { oid: branch.sha },
659
+ repository: { nameWithOwner: "example/widget" }
468
660
  }
469
- if (route.startsWith('GET '))
470
- return { data: values(Number(input.issue_number ?? 17)) };
471
- throw new Error('Unexpected native request ' + route);
472
- },
473
- },
474
- graphql: async (query, input) => {
475
- if (query.includes('DeliveryIssueBranches'))
476
- return {
477
- repository: {
478
- issue: {
479
- linkedBranches: {
480
- nodes: branches.map((branch) => ({
481
- ref: {
482
- name: branch.name,
483
- target: { oid: branch.sha },
484
- repository: { nameWithOwner: 'example/widget' },
485
- },
486
- })),
487
- pageInfo: { hasNextPage: false, endCursor: null },
488
- },
489
- },
490
- },
491
- };
492
- if (query.includes('DeliveryStartBranch')) {
493
- const fields = input.input;
494
- branchWrites.push(fields);
495
- branches.push({ name: String(fields.name), sha: String(fields.oid) });
496
- if (controls.closeAfterBranch)
497
- live.state = 'closed';
498
- if (controls.blockAfterBranch)
499
- controls.blockers = true;
500
- if (controls.growAfterBranch)
501
- capacity.push({ number: 99, label: 'critical', value: 'High', status: 'Active' });
502
- if (controls.branchFailure)
503
- throw new Error('Lost branch response');
504
- return { createLinkedBranch: { linkedBranch: { ref: { name: fields.name, target: { oid: fields.oid } } } } };
505
- }
506
- if (query.includes('blockedBy(first:'))
507
- return {
508
- repository: {
509
- issue: {
510
- parent: null,
511
- blockedBy: {
512
- nodes: controls.blockers
513
- ? [
514
- {
515
- id: 'ISSUE18',
516
- number: 18,
517
- title: 'Resolve prerequisite',
518
- state: 'OPEN',
519
- repository: { nameWithOwner: 'example/widget' },
520
- },
521
- ]
522
- : [],
523
- pageInfo: { hasNextPage: false, endCursor: null },
524
- },
525
- },
526
- },
527
- };
528
- if (query.includes('ProjectDeliveryItems'))
529
- return {
530
- organization: {
531
- projectV2: {
532
- id: 'PROJECT',
533
- number: 1,
534
- items: {
535
- nodes: [
536
- ...capacity.map((x) => ({
537
- id: 'ITEM' + String(x.number),
538
- isArchived: false,
539
- content: { id: 'ISSUE' + String(x.number) },
540
- fieldValueByName: x.status === 'Unset'
541
- ? null
542
- : x.status === 'Missing'
543
- ? undefined
544
- : { name: x.status, optionId: x.status === 'Active' ? 'ACTIVE' : 'TODO' },
545
- })),
546
- {
547
- id: 'OTHER',
548
- isArchived: false,
549
- content: { id: 'OTHER-ISSUE' },
550
- fieldValueByName: { name: 'Queued', optionId: 'TODO' },
551
- },
552
- ...(controls.projectMember
553
- ? [
554
- {
555
- id: 'ITEM17',
556
- isArchived: controls.projectArchived,
557
- content: { id: 'ISSUE17' },
558
- fieldValueByName: { name: status, optionId: optionId() },
559
- },
560
- ]
561
- : []),
562
- ],
563
- pageInfo: { hasNextPage: false, endCursor: null },
564
- },
565
- },
566
- },
567
- };
568
- if (query.includes('AddProjectDeliveryItem')) {
569
- membershipWrites.push(input);
570
- assert.equal(input.projectId, 'PROJECT');
571
- assert.equal(input.contentId, 'ISSUE17');
572
- controls.projectMember = true;
573
- return { addProjectV2ItemById: { item: { id: 'ITEM17' } } };
661
+ })),
662
+ pageInfo: { hasNextPage: false, endCursor: null }
574
663
  }
575
- if (query.includes('UpdateProjectDeliveryStatus')) {
576
- statusWrites.push(input);
577
- assert.equal(input.projectId, 'PROJECT');
578
- assert.equal(input.itemId, 'ITEM17');
579
- assert.equal(input.fieldId, 'STATUS');
580
- if (input.optionId === 'ACTIVE' && controls.projectFailure === 'before')
581
- throw new Error('Project write failed');
582
- status = input.optionId === 'TODO' ? 'Queued' : input.optionId === 'DONE' ? 'Shipped' : 'Active';
583
- if (input.optionId === 'ACTIVE' && controls.projectFailure === 'after')
584
- throw new Error('Lost Project response');
585
- return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'ITEM17' } } };
664
+ }
665
+ }
666
+ };
667
+ if (query.includes("DeliveryStartBranch")) {
668
+ const fields = input.input;
669
+ branchWrites.push(fields);
670
+ branches.push({ name: String(fields.name), sha: String(fields.oid) });
671
+ if (controls.closeAfterBranch) live.state = "closed";
672
+ if (controls.blockAfterBranch) controls.blockers = true;
673
+ if (controls.growAfterBranch)
674
+ capacity.push({ number: 99, label: "critical", value: "High", status: "Active" });
675
+ if (controls.branchFailure) throw new Error("Lost branch response");
676
+ return { createLinkedBranch: { linkedBranch: { ref: { name: fields.name, target: { oid: fields.oid } } } } };
677
+ }
678
+ if (query.includes("blockedBy(first:"))
679
+ return {
680
+ repository: {
681
+ issue: {
682
+ id: controls.missingNative ? void 0 : "ISSUE17",
683
+ number: 17,
684
+ repository: { nameWithOwner: "example/widget" },
685
+ parent: null,
686
+ blockedBy: {
687
+ nodes: controls.blockers ? [
688
+ {
689
+ id: "ISSUE18",
690
+ number: 18,
691
+ title: "Resolve prerequisite",
692
+ state: controls.blockerClosed && !controls.blockerConflict ? "CLOSED" : "OPEN",
693
+ repository: { nameWithOwner: "example/widget" }
694
+ }
695
+ ] : [],
696
+ pageInfo: { hasNextPage: false, endCursor: null }
586
697
  }
587
- if (query.includes('ProjectDeliveryItemReadback')) {
588
- const number = Number(String(input.itemId).replace('ITEM', ''));
589
- const selected = number === 17 ? status : capacity.find((x) => x.number === number)?.status;
590
- return {
591
- node: {
592
- id: input.itemId,
593
- isArchived: false,
594
- project: { id: 'PROJECT', number: 1 },
595
- content: {
596
- id: status === 'Active' && controls.projectFailure === 'readback'
597
- ? 'OTHER-ISSUE'
598
- : 'ISSUE' + String(number),
599
- },
600
- fieldValueByName: selected === 'Unset'
601
- ? null
602
- : selected === 'Missing'
603
- ? undefined
604
- : {
605
- name: selected,
606
- optionId: number === 17 ? optionId() : selected === 'Active' ? 'ACTIVE' : 'TODO',
607
- },
608
- },
609
- };
698
+ }
699
+ }
700
+ };
701
+ if (query.includes("ProjectDeliveryIssueItems"))
702
+ return issueProjectItemsResponse(
703
+ input,
704
+ [
705
+ ...capacity.map((x) => ({
706
+ id: "ITEM" + String(x.number),
707
+ isArchived: false,
708
+ content: { id: "ISSUE" + String(x.number) },
709
+ fieldValueByName: x.status === "Unset" ? null : x.status === "Missing" ? void 0 : { name: x.status, optionId: x.status === "Active" ? "ACTIVE" : "TODO" }
710
+ })),
711
+ {
712
+ id: "OTHER",
713
+ isArchived: false,
714
+ content: { id: "OTHER-ISSUE" },
715
+ fieldValueByName: { name: "Queued", optionId: "TODO" }
716
+ },
717
+ ...controls.projectMember ? [
718
+ {
719
+ id: "ITEM17",
720
+ isArchived: controls.projectArchived,
721
+ content: { id: "ISSUE17" },
722
+ fieldValueByName: { name: status, optionId: optionId() }
610
723
  }
611
- throw new Error('Unexpected native query ' + query);
612
- },
613
- },
614
- };
615
- return {
616
- context,
617
- capacity,
618
- live,
619
- writes,
620
- comments,
621
- controls,
622
- branches,
623
- branchWrites,
624
- statusWrites,
625
- membershipWrites,
626
- getStatus: () => status,
627
- setStatus: (value) => {
628
- status = value;
629
- },
630
- };
724
+ ] : []
725
+ ].filter((item) => item.content.id === input.issueNodeId)
726
+ );
727
+ if (query.includes("AddProjectDeliveryItem")) {
728
+ membershipWrites.push(input);
729
+ assert.equal(input.projectId, "PROJECT");
730
+ assert.equal(input.contentId, "ISSUE17");
731
+ controls.projectMember = true;
732
+ return { addProjectV2ItemById: { item: { id: "ITEM17" } } };
733
+ }
734
+ if (query.includes("UpdateProjectDeliveryStatus")) {
735
+ statusWrites.push(input);
736
+ assert.equal(input.projectId, "PROJECT");
737
+ assert.equal(input.itemId, "ITEM17");
738
+ assert.equal(input.fieldId, "STATUS");
739
+ if (input.optionId === "ACTIVE" && controls.projectFailure === "before")
740
+ throw new Error("Project write failed");
741
+ status = input.optionId === "TODO" ? "Queued" : input.optionId === "DONE" ? "Shipped" : input.optionId === "BLOCKED" ? "Waiting" : "Active";
742
+ if (input.optionId === "ACTIVE" && controls.projectFailure === "after")
743
+ throw new Error("Lost Project response");
744
+ return { updateProjectV2ItemFieldValue: { projectV2Item: { id: "ITEM17" } } };
745
+ }
746
+ if (query.includes("ProjectDeliveryItemReadback")) {
747
+ const number = Number(String(input.itemId).replace("ITEM", ""));
748
+ const selected = number === 17 ? status : capacity.find((x) => x.number === number)?.status;
749
+ return {
750
+ node: {
751
+ id: input.itemId,
752
+ isArchived: false,
753
+ project: { id: "PROJECT", number: 1 },
754
+ content: {
755
+ id: status === "Active" && controls.projectFailure === "readback" ? "OTHER-ISSUE" : "ISSUE" + String(number)
756
+ },
757
+ fieldValueByName: selected === "Unset" ? null : selected === "Missing" ? void 0 : {
758
+ name: selected,
759
+ optionId: number === 17 ? optionId() : selected === "Active" ? "ACTIVE" : "TODO"
760
+ }
761
+ }
762
+ };
763
+ }
764
+ const quiet = quietReadViewResponse(query, input);
765
+ if (quiet !== void 0) return quiet;
766
+ throw new Error("Unexpected native query " + query);
767
+ }
768
+ }
769
+ };
770
+ return {
771
+ context,
772
+ capacity,
773
+ live,
774
+ writes,
775
+ comments,
776
+ controls,
777
+ branches,
778
+ branchWrites,
779
+ statusWrites,
780
+ membershipWrites,
781
+ getStatus: () => status,
782
+ setStatus: (value) => {
783
+ status = value;
784
+ }
785
+ };
631
786
  }
632
- test('manual deferral survives other updates and past dates, appears in reads, and blocks all start writes', async () => {
633
- const f = fixture();
634
- const footer = '\n\n<!-- ai-delivery-start-intent: sha256:' +
635
- 'a'.repeat(64) +
636
- ' -->\n<!-- ai-delivery-start: sha256:' +
637
- 'b'.repeat(64) +
638
- ' -->';
639
- f.live.body += footer;
640
- const condition = { until: '2020-01-01', trigger: 'Upstream ships the prerequisite.' };
641
- const patch = getAiDeliveryMcpTool('issue_update').inputSchema.parse({ issueNumber: 17, defer: condition });
642
- const deferred = await updateIssue(f.context, patch);
643
- assert.deepEqual(Reflect.get(deferred, 'deferred'), condition);
644
- assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), 'deferred'), condition);
645
- assert.deepEqual(Reflect.get((await listIssues(f.context, {})).issues[0], 'deferred'), condition);
646
- const saved = parseIssueBody(deferred.body, { title: f.live.title }).issue;
647
- assert.ok(deferred.body.endsWith(footer));
648
- assert.deepEqual(Reflect.get(saved, 'deferral'), condition);
649
- assert.match(deferred.body, /Deferred/u);
650
- assert.equal((await readyCheck(f.context, 17)).ready, false);
651
- await updateIssue(f.context, { issueNumber: 17, status: { nextMilestone: 'Wait for upstream' } });
652
- assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), 'deferred'), condition);
653
- assert.ok(f.live.body.endsWith(footer));
654
- const writes = f.writes.length;
655
- const comments = f.comments.length;
656
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /deferred|undefer/iu);
657
- assert.equal(f.branchWrites.length, 0);
658
- assert.equal(f.statusWrites.filter((x) => x.optionId === 'ACTIVE').length, 0);
659
- assert.equal(f.writes.length, writes);
660
- assert.equal(f.comments.length, comments);
661
- const clear = { issueNumber: 17, undefer: true };
662
- const resumed = await updateIssue(f.context, clear);
663
- assert.equal(Reflect.get(resumed, 'deferred'), null);
664
- assert.ok(resumed.body.endsWith(footer));
665
- assert.deepEqual(parseIssueBody(resumed.body, { title: f.live.title }).issue.acceptanceCriteria, saved.acceptanceCriteria);
666
- assert.equal((await readyCheck(f.context, 17)).ready, true);
667
- await startTrackedIssue(f.context, { issueNumber: 17 });
668
- assert.equal(f.branchWrites.length, 1);
669
- assert.equal(f.getStatus(), 'Active');
787
+ test("manual deferral survives other updates and past dates, appears in reads, and blocks all start writes", async () => {
788
+ const f = fixture();
789
+ const footer = "\n\n<!-- ai-delivery-start-intent: sha256:" + "a".repeat(64) + " -->\n<!-- ai-delivery-start: sha256:" + "b".repeat(64) + " -->";
790
+ f.live.body += footer;
791
+ const condition = { until: "2020-01-01", trigger: "Upstream ships the prerequisite." };
792
+ const patch = getAiDeliveryMcpTool("issue_update").inputSchema.parse({ issueNumber: 17, defer: condition });
793
+ const deferred = await updateIssue(f.context, patch);
794
+ assert.deepEqual(Reflect.get(deferred, "deferred"), condition);
795
+ assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), "deferred"), condition);
796
+ assert.deepEqual(Reflect.get((await listIssues(f.context, {})).issues[0], "deferred"), condition);
797
+ const saved = parseIssueBody(deferred.body, { title: f.live.title }).issue;
798
+ assert.ok(deferred.body.endsWith(footer));
799
+ assert.deepEqual(Reflect.get(saved, "deferral"), condition);
800
+ assert.match(deferred.body, /Deferred/u);
801
+ assert.equal((await readyCheck(f.context, 17)).ready, false);
802
+ await updateIssue(f.context, { issueNumber: 17, status: { nextMilestone: "Wait for upstream" } });
803
+ assert.deepEqual(Reflect.get(await issueInfo(f.context, 17), "deferred"), condition);
804
+ assert.ok(f.live.body.endsWith(footer));
805
+ const writes = f.writes.length;
806
+ const comments = f.comments.length;
807
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /deferred|undefer/iu);
808
+ assert.equal(f.branchWrites.length, 0);
809
+ assert.equal(f.statusWrites.filter((x) => x.optionId === "ACTIVE").length, 0);
810
+ assert.equal(f.writes.length, writes);
811
+ assert.equal(f.comments.length, comments);
812
+ const clear = { issueNumber: 17, undefer: true };
813
+ const resumed = await updateIssue(f.context, clear);
814
+ assert.equal(Reflect.get(resumed, "deferred"), null);
815
+ assert.ok(resumed.body.endsWith(footer));
816
+ assert.deepEqual(
817
+ parseIssueBody(resumed.body, { title: f.live.title }).issue.acceptanceCriteria,
818
+ saved.acceptanceCriteria
819
+ );
820
+ assert.equal((await readyCheck(f.context, 17)).ready, true);
821
+ await startTrackedIssue(f.context, { issueNumber: 17 });
822
+ assert.equal(f.branchWrites.length, 1);
823
+ assert.equal(f.getStatus(), "Active");
670
824
  });
671
- test('canonical new-start intent preserves supplied deferral rather than silently resuming it', async () => {
672
- const deferred = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: 'Explicit undefer' } }));
673
- const canonical = canonicalIssueBody({ ...ready(), body: deferred });
674
- assert.deepEqual(Reflect.get(parseIssueBody(canonical, { title: ready().title }).issue, 'deferral'), {
675
- trigger: 'Explicit undefer',
676
- });
677
- const f = fixture();
678
- f.controls.created = false;
679
- const request = { ...ready(), body: deferred };
680
- const first = await startTrackedIssue(f.context, request);
681
- assert.equal(Reflect.get(first, 'status'), 'created-not-started');
682
- assert.deepEqual(Reflect.get(parseIssueBody(f.live.body, { title: f.live.title }).issue, 'deferral'), {
683
- trigger: 'Explicit undefer',
684
- });
685
- await startTrackedIssue(f.context, request);
686
- assert.equal(f.writes.filter((write) => !Object.hasOwn(write, 'issue_number')).length, 1);
687
- assert.equal(f.branchWrites.length, 0);
825
+ test("canonical new-start intent preserves supplied deferral rather than silently resuming it", async () => {
826
+ const deferred = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: "Explicit undefer" } }));
827
+ const canonical = canonicalIssueBody({ ...ready(), body: deferred });
828
+ assert.deepEqual(Reflect.get(parseIssueBody(canonical, { title: ready().title }).issue, "deferral"), {
829
+ trigger: "Explicit undefer"
830
+ });
831
+ const f = fixture();
832
+ f.controls.created = false;
833
+ const request = { ...ready(), body: deferred };
834
+ const first = await startTrackedIssue(f.context, request);
835
+ assert.equal(Reflect.get(first, "status"), "created-not-started");
836
+ assert.deepEqual(Reflect.get(parseIssueBody(f.live.body, { title: f.live.title }).issue, "deferral"), {
837
+ trigger: "Explicit undefer"
838
+ });
839
+ await startTrackedIssue(f.context, request);
840
+ assert.equal(f.writes.filter((write) => !Object.hasOwn(write, "issue_number")).length, 1);
841
+ assert.equal(f.branchWrites.length, 0);
842
+ });
843
+ test("WIP partial Project acknowledgment preserves the exact reason and reuses its authored comment", async () => {
844
+ const f = fixture();
845
+ f.controls.capacityMode = true;
846
+ f.live.labels = ["critical"];
847
+ f.context.config = {
848
+ ...f.context.config,
849
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
850
+ };
851
+ f.controls.projectFailure = "after";
852
+ const result = await startTrackedIssue(f.context, {
853
+ issueNumber: 17,
854
+ overrideReason: "Approved synthetic exception."
855
+ });
856
+ assert.equal(Reflect.get(result, "status"), "start-incomplete");
857
+ const recovery = result;
858
+ assert.ok(recovery.safeResume);
859
+ const resume = recovery.safeResume.arguments;
860
+ assert.equal(resume.overrideReason, "Approved synthetic exception.");
861
+ assert.equal(f.comments.length, 1);
862
+ f.controls.projectFailure = "";
863
+ await startTrackedIssue(f.context, resume);
864
+ assert.equal(f.branchWrites.length, 1);
865
+ assert.equal(f.statusWrites.length, 1);
866
+ assert.equal(f.comments.length, 2);
867
+ });
868
+ test("deferral remains orthogonal to park and only explicit undefer clears it", async () => {
869
+ const f = fixture();
870
+ const patch = { issueNumber: 17, defer: {} };
871
+ await updateIssue(f.context, patch);
872
+ const parked = await updateIssue(f.context, { issueNumber: 17, park: true });
873
+ assert.deepEqual(Reflect.get(parked, "deferred"), {});
874
+ assert.equal(parseIssueBody(parked.body, { title: parked.title }).issue.draft, true);
875
+ const clear = { issueNumber: 17, undefer: true };
876
+ const cleared = await updateIssue(f.context, clear);
877
+ assert.equal(Reflect.get(cleared, "deferred"), null);
878
+ assert.equal(parseIssueBody(cleared.body, { title: cleared.title }).issue.draft, true);
879
+ assert.equal((await readyCheck(f.context, 17)).ready, false);
688
880
  });
689
- test('WIP partial Project acknowledgment preserves the exact reason and reuses its authored comment', async () => {
881
+ test("deferral inputs reject invalid dates, empty reasons, conflicts and direct canonical bypass before writes", async () => {
882
+ const schema = getAiDeliveryMcpTool("issue_update").inputSchema;
883
+ assert.doesNotThrow(() => schema.parse({ issueNumber: 17, defer: { until: "2026-10-17" } }));
884
+ for (const input of [
885
+ { defer: { until: "2026-02-30" } },
886
+ { defer: { until: "tomorrow" } },
887
+ { defer: { trigger: " " } },
888
+ { defer: {}, undefer: true },
889
+ { deferral: {} },
890
+ { undefer: false }
891
+ ])
892
+ assert.throws(() => schema.parse({ issueNumber: 17, ...input }));
893
+ const f = fixture();
894
+ const conflicting = { issueNumber: 17, defer: {}, undefer: true };
895
+ await assert.rejects(updateIssue(f.context, conflicting));
896
+ assert.equal(f.writes.length, 0);
897
+ assert.equal(f.comments.length, 0);
898
+ });
899
+ test("WIP label and field lanes reject full capacity before creating a branch or journal", async () => {
900
+ for (const match of [{ label: "critical" }, { field: "Urgency", value: "High" }]) {
690
901
  const f = fixture();
691
902
  f.controls.capacityMode = true;
692
- f.live.labels = ['critical'];
903
+ f.live.labels = ["critical"];
693
904
  f.context.config = {
694
- ...f.context.config,
695
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
905
+ ...f.context.config,
906
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match, limit: 1 }]
696
907
  };
697
- f.controls.projectFailure = 'after';
698
- const result = await startTrackedIssue(f.context, {
699
- issueNumber: 17,
700
- overrideReason: 'Approved synthetic exception.',
701
- });
702
- assert.equal(Reflect.get(result, 'status'), 'start-incomplete');
703
- const recovery = result;
704
- assert.ok(recovery.safeResume);
705
- const resume = recovery.safeResume.arguments;
706
- assert.equal(resume.overrideReason, 'Approved synthetic exception.');
707
- assert.equal(f.comments.length, 1);
708
- f.controls.projectFailure = '';
709
- await startTrackedIssue(f.context, resume);
710
- assert.equal(f.branchWrites.length, 1);
711
- assert.equal(f.statusWrites.length, 1);
712
- assert.equal(f.comments.length, 2);
713
- });
714
- test('deferral remains orthogonal to park and only explicit undefer clears it', async () => {
715
- const f = fixture();
716
- const patch = { issueNumber: 17, defer: {} };
717
- await updateIssue(f.context, patch);
718
- const parked = await updateIssue(f.context, { issueNumber: 17, park: true });
719
- assert.deepEqual(Reflect.get(parked, 'deferred'), {});
720
- assert.equal(parseIssueBody(parked.body, { title: parked.title }).issue.draft, true);
721
- const clear = { issueNumber: 17, undefer: true };
722
- const cleared = await updateIssue(f.context, clear);
723
- assert.equal(Reflect.get(cleared, 'deferred'), null);
724
- assert.equal(parseIssueBody(cleared.body, { title: cleared.title }).issue.draft, true);
725
- assert.equal((await readyCheck(f.context, 17)).ready, false);
726
- });
727
- test('deferral inputs reject invalid dates, empty reasons, conflicts and direct canonical bypass before writes', async () => {
728
- const schema = getAiDeliveryMcpTool('issue_update').inputSchema;
729
- assert.doesNotThrow(() => schema.parse({ issueNumber: 17, defer: { until: '2026-10-17' } }));
730
- for (const input of [
731
- { defer: { until: '2026-02-30' } },
732
- { defer: { until: 'tomorrow' } },
733
- { defer: { trigger: ' ' } },
734
- { defer: {}, undefer: true },
735
- { deferral: {} },
736
- { undefer: false },
737
- ])
738
- assert.throws(() => schema.parse({ issueNumber: 17, ...input }));
739
- const f = fixture();
740
- const conflicting = { issueNumber: 17, defer: {}, undefer: true };
741
- await assert.rejects(updateIssue(f.context, conflicting));
742
- assert.equal(f.writes.length, 0);
908
+ f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
909
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity|limit/u);
910
+ assert.equal(f.branchWrites.length, 0);
911
+ assert.equal(f.statusWrites.length, 0);
743
912
  assert.equal(f.comments.length, 0);
913
+ }
744
914
  });
745
- test('WIP label and field lanes reject full capacity before creating a branch or journal', async () => {
746
- for (const match of [{ label: 'critical' }, { field: 'Urgency', value: 'High' }]) {
747
- const f = fixture();
748
- f.controls.capacityMode = true;
749
- f.live.labels = ['critical'];
750
- f.context.config = {
751
- ...f.context.config,
752
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match, limit: 1 }],
753
- };
754
- f.capacity.push({ number: 18, label: 'critical', value: 'High', status: 'Active' });
755
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity|limit/u);
756
- assert.equal(f.branchWrites.length, 0);
757
- assert.equal(f.statusWrites.length, 0);
758
- assert.equal(f.comments.length, 0);
759
- }
915
+ test("WIP rechecks after branch creation, retains that identity, and only admits a recorded capacity override", async () => {
916
+ const f = fixture();
917
+ f.controls.capacityMode = true;
918
+ f.controls.growAfterBranch = true;
919
+ f.live.labels = ["critical"];
920
+ f.context.config = {
921
+ ...f.context.config,
922
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
923
+ };
924
+ const refused = await startTrackedIssue(f.context, { issueNumber: 17 });
925
+ assert.equal(Reflect.get(refused, "status"), "start-incomplete");
926
+ assert.equal(f.branchWrites.length, 1);
927
+ assert.equal(f.statusWrites.length, 0);
928
+ assert.equal(f.comments.length, 0);
929
+ f.controls.growAfterBranch = false;
930
+ await startTrackedIssue(f.context, {
931
+ issueNumber: 17,
932
+ overrideReason: "Operator authorizes this synthetic capacity exception."
933
+ });
934
+ assert.equal(f.branchWrites.length, 1);
935
+ assert.equal(f.getStatus(), "Active");
936
+ assert.equal(f.comments.length, 2);
937
+ assert.match(f.comments[0].body, /Operator authorizes this synthetic capacity exception/u);
938
+ assert.match(f.comments[0].body, /"count": 1/u);
939
+ assert.match(f.comments[0].body, /"limit": 1/u);
940
+ await startTrackedIssue(f.context, { issueNumber: 17 });
941
+ assert.equal(f.comments.length, 2);
760
942
  });
761
- test('WIP rechecks after branch creation, retains that identity, and only admits a recorded capacity override', async () => {
943
+ test("WIP capacity override refuses a mismatched native comment author and reconciles lost comment responses", async () => {
944
+ for (const failure of ["author", "response"]) {
762
945
  const f = fixture();
763
946
  f.controls.capacityMode = true;
764
- f.controls.growAfterBranch = true;
765
- f.live.labels = ['critical'];
947
+ f.live.labels = ["critical"];
766
948
  f.context.config = {
767
- ...f.context.config,
768
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
949
+ ...f.context.config,
950
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
769
951
  };
770
- const refused = await startTrackedIssue(f.context, { issueNumber: 17 });
771
- assert.equal(Reflect.get(refused, 'status'), 'start-incomplete');
772
- assert.equal(f.branchWrites.length, 1);
952
+ f.controls.corruptCapacityComment = failure === "author";
953
+ f.controls.journalFailure = failure === "response";
954
+ const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity authorization." };
955
+ const refused = await startTrackedIssue(f.context, input);
956
+ assert.equal(Reflect.get(refused, "status"), "start-incomplete");
957
+ assert.equal(f.getStatus(), "Queued");
773
958
  assert.equal(f.statusWrites.length, 0);
774
- assert.equal(f.comments.length, 0);
775
- f.controls.growAfterBranch = false;
776
- await startTrackedIssue(f.context, {
777
- issueNumber: 17,
778
- overrideReason: 'Operator authorizes this synthetic capacity exception.',
779
- });
780
- assert.equal(f.branchWrites.length, 1);
781
- assert.equal(f.getStatus(), 'Active');
782
- assert.equal(f.comments.length, 2);
783
- assert.match(f.comments[0].body, /Operator authorizes this synthetic capacity exception/u);
784
- assert.match(f.comments[0].body, /"count": 1/u);
785
- assert.match(f.comments[0].body, /"limit": 1/u);
786
- await startTrackedIssue(f.context, { issueNumber: 17 });
959
+ assert.equal(f.comments.length, 1);
960
+ f.controls.corruptCapacityComment = false;
961
+ f.controls.journalFailure = false;
962
+ await startTrackedIssue(f.context, input);
963
+ assert.equal(f.getStatus(), "Active");
787
964
  assert.equal(f.comments.length, 2);
965
+ assert.equal(f.branchWrites.length, 1);
966
+ }
788
967
  });
789
- test('WIP capacity override refuses a mismatched native comment author and reconciles lost comment responses', async () => {
790
- for (const failure of ['author', 'response']) {
791
- const f = fixture();
792
- f.controls.capacityMode = true;
793
- f.live.labels = ['critical'];
794
- f.context.config = {
795
- ...f.context.config,
796
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
797
- };
798
- f.controls.corruptCapacityComment = failure === 'author';
799
- f.controls.journalFailure = failure === 'response';
800
- const input = { issueNumber: 17, overrideReason: 'Explicit synthetic capacity authorization.' };
801
- const refused = await startTrackedIssue(f.context, input);
802
- assert.equal(Reflect.get(refused, 'status'), 'start-incomplete');
803
- assert.equal(f.getStatus(), 'Queued');
804
- assert.equal(f.statusWrites.length, 0);
805
- assert.equal(f.comments.length, 1);
806
- f.controls.corruptCapacityComment = false;
807
- f.controls.journalFailure = false;
808
- await startTrackedIssue(f.context, input);
809
- assert.equal(f.getStatus(), 'Active');
810
- assert.equal(f.comments.length, 2);
811
- assert.equal(f.branchWrites.length, 1);
812
- }
813
- });
814
- test.each(['edited', 'exact-and-edited'])('WIP override retry refuses %s authored evidence with the same operation marker', async (mode) => {
968
+ test.each(["edited", "exact-and-edited"])(
969
+ "WIP override retry refuses %s authored evidence with the same operation marker",
970
+ async (mode) => {
815
971
  const f = fixture();
816
972
  f.controls.capacityMode = true;
817
- f.live.labels = ['critical'];
973
+ f.live.labels = ["critical"];
818
974
  f.context.config = {
819
- ...f.context.config,
820
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
975
+ ...f.context.config,
976
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
821
977
  };
822
978
  f.controls.journalFailure = true;
823
- const input = { issueNumber: 17, overrideReason: 'Explicit synthetic capacity authorization.' };
824
- assert.equal(Reflect.get(await startTrackedIssue(f.context, input), 'status'), 'start-incomplete');
979
+ const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity authorization." };
980
+ assert.equal(Reflect.get(await startTrackedIssue(f.context, input), "status"), "start-incomplete");
825
981
  assert.equal(f.comments.length, 1);
826
982
  const original = f.comments[0];
827
- const edited = original.body.replace('WIP capacity override.', 'Edited capacity override.');
828
- if (mode === 'edited')
829
- original.body = edited;
983
+ const edited = original.body.replace("WIP capacity override.", "Edited capacity override.");
984
+ if (mode === "edited") original.body = edited;
830
985
  else
831
- f.comments.push({
832
- ...original,
833
- id: 92,
834
- html_url: 'https://github.com/example/widget/issues/17#issuecomment-92',
835
- body: edited,
836
- });
986
+ f.comments.push({
987
+ ...original,
988
+ id: 92,
989
+ html_url: "https://github.com/example/widget/issues/17#issuecomment-92",
990
+ body: edited
991
+ });
837
992
  const before = structuredClone(f.comments);
838
993
  f.controls.journalFailure = false;
839
994
  const result = await startTrackedIssue(f.context, input);
840
- assert.equal(Reflect.get(result, 'status'), 'start-incomplete');
841
- assert.match(Reflect.get(result, 'failure').message, /conflict|duplicate|override/iu);
995
+ assert.equal(Reflect.get(result, "status"), "start-incomplete");
996
+ assert.match(Reflect.get(result, "failure").message, /conflict|duplicate|override/iu);
842
997
  assert.deepEqual(f.comments, before);
843
998
  assert.equal(f.branchWrites.length, 1);
844
999
  assert.equal(f.statusWrites.length, 0);
845
- assert.equal(f.getStatus(), 'Queued');
846
- });
847
- test.each(['text', 'number', 'date', 'single_select', 'multi_select'].flatMap((type) => [17, 18].map((number) => ({ type, number }))))('WIP refuses omitted $type payload on issue $number even with an override reason', async ({ type, number }) => {
848
- const f = fixture();
849
- f.controls.capacityMode = true;
850
- f.capacity.push({ number: 18, label: 'other', value: 'High', status: 'Active' });
851
- const value = type === 'number' ? 1 : type === 'date' ? '2026-10-17' : 'High';
852
- f.context.config = {
853
- ...f.context.config,
854
- wipLimits: [{ repository: 'example/widget', name: 'Urgent work', match: { field: 'Urgency', value }, limit: 1 }],
855
- };
856
- let capacityReadStarted = false;
857
- const list = f.context.clients.rest.issues.listForRepo;
858
- f.context.clients.rest.issues.listForRepo = (async (input) => {
859
- capacityReadStarted = true;
860
- return list(input);
861
- });
862
- const request = f.context.clients.rest.request;
863
- f.context.clients.rest.request = (async (route, input) => {
864
- const response = await request(route, input);
865
- if (!capacityReadStarted || typeof route !== 'string' || !route.startsWith('GET '))
866
- return response;
867
- const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
868
- const catalog = route === 'GET /orgs/{org}/issue-fields';
1000
+ assert.equal(f.getStatus(), "Queued");
1001
+ }
1002
+ );
1003
+ test.each(
1004
+ ["text", "number", "date", "single_select", "multi_select"].flatMap(
1005
+ (type) => [17, 18].map((number) => ({ type, number }))
1006
+ )
1007
+ )("WIP refuses omitted $type payload on issue $number even with an override reason", async ({ type, number }) => {
1008
+ const f = fixture();
1009
+ f.controls.capacityMode = true;
1010
+ f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
1011
+ const value = type === "number" ? 1 : type === "date" ? "2026-10-17" : "High";
1012
+ f.context.config = {
1013
+ ...f.context.config,
1014
+ wipLimits: [{ repository: "example/widget", name: "Urgent work", match: { field: "Urgency", value }, limit: 1 }]
1015
+ };
1016
+ let capacityReadStarted = false;
1017
+ const list = f.context.clients.rest.issues.listForRepo;
1018
+ f.context.clients.rest.issues.listForRepo = (async (input) => {
1019
+ capacityReadStarted = true;
1020
+ return list(input);
1021
+ });
1022
+ const request = f.context.clients.rest.request;
1023
+ f.context.clients.rest.request = (async (route, input) => {
1024
+ const response = await request(route, input);
1025
+ if (!capacityReadStarted || typeof route !== "string" || !route.startsWith("GET ")) return response;
1026
+ const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
1027
+ const catalog = route === "GET /orgs/{org}/issue-fields";
1028
+ return {
1029
+ ...response,
1030
+ data: rows.map((row) => {
1031
+ if ((catalog ? row.id : row.issue_field_id) !== 102) return row;
1032
+ if (catalog) return { ...row, data_type: type };
869
1033
  return {
870
- ...response,
871
- data: rows.map((row) => {
872
- if ((catalog ? row.id : row.issue_field_id) !== 102)
873
- return row;
874
- if (catalog)
875
- return { ...row, data_type: type };
876
- return {
877
- issue_field_id: 102,
878
- issue_field_name: 'Urgency',
879
- data_type: type,
880
- ...(input?.issue_number === number
881
- ? {}
882
- : type === 'single_select'
883
- ? { single_select_option: { name: value } }
884
- : type === 'multi_select'
885
- ? { multi_select_options: [{ name: value }] }
886
- : { value }),
887
- };
888
- }),
1034
+ issue_field_id: 102,
1035
+ issue_field_name: "Urgency",
1036
+ data_type: type,
1037
+ ...input?.issue_number === number ? {} : type === "single_select" ? { single_select_option: { name: value } } : type === "multi_select" ? { multi_select_options: [{ name: value }] } : { value }
889
1038
  };
890
- });
891
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Capacity cannot override missing evidence.' }), /capacity|payload|field/iu);
892
- assert.equal(f.branchWrites.length, 0);
893
- assert.equal(f.statusWrites.length, 0);
894
- assert.equal(f.membershipWrites.length, 0);
895
- assert.equal(f.comments.length, 0);
1039
+ })
1040
+ };
1041
+ });
1042
+ await assert.rejects(
1043
+ startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity cannot override missing evidence." }),
1044
+ /capacity|payload|field/iu
1045
+ );
1046
+ assert.equal(f.branchWrites.length, 0);
1047
+ assert.equal(f.statusWrites.length, 0);
1048
+ assert.equal(f.membershipWrites.length, 0);
1049
+ assert.equal(f.comments.length, 0);
896
1050
  });
897
- test.each(['absent', 'null', 'empty-multi'])('WIP accepts complete native %s peer values as nonmatching', async (mode) => {
1051
+ test.each(["absent", "null", "empty-multi"])(
1052
+ "WIP accepts complete native %s peer values as nonmatching",
1053
+ async (mode) => {
898
1054
  const f = fixture();
899
1055
  f.controls.capacityMode = true;
900
- f.capacity.push({ number: 18, label: 'other', value: 'High', status: 'Active' });
901
- const multi = mode === 'empty-multi';
1056
+ f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
1057
+ const multi = mode === "empty-multi";
902
1058
  f.context.config = {
903
- ...f.context.config,
904
- wipLimits: [
905
- {
906
- repository: 'example/widget',
907
- name: 'Urgent work',
908
- match: { field: multi ? 'Tags' : 'Urgency', value: multi ? '0' : 'High' },
909
- limit: 1,
910
- },
911
- ],
1059
+ ...f.context.config,
1060
+ wipLimits: [
1061
+ {
1062
+ repository: "example/widget",
1063
+ name: "Urgent work",
1064
+ match: { field: multi ? "Tags" : "Urgency", value: multi ? "0" : "High" },
1065
+ limit: 1
1066
+ }
1067
+ ]
912
1068
  };
913
1069
  const request = f.context.clients.rest.request;
914
1070
  f.context.clients.rest.request = (async (route, input) => {
915
- const response = await request(route, input);
916
- if (typeof route !== 'string' || !route.endsWith('/issue-field-values') || input?.issue_number !== 18)
917
- return response;
918
- const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
919
- return {
920
- ...response,
921
- data: rows.flatMap((row) => row.issue_field_id !== (multi ? 103 : 102)
922
- ? [row]
923
- : mode === 'absent'
924
- ? []
925
- : [
926
- {
927
- issue_field_id: row.issue_field_id,
928
- issue_field_name: row.issue_field_name,
929
- data_type: row.data_type,
930
- ...(multi ? { multi_select_options: [] } : { value: null }),
931
- },
932
- ]),
933
- };
1071
+ const response = await request(route, input);
1072
+ if (typeof route !== "string" || !route.endsWith("/issue-field-values") || input?.issue_number !== 18)
1073
+ return response;
1074
+ const rows = z.array(z.record(z.string(), z.unknown())).parse(response.data);
1075
+ return {
1076
+ ...response,
1077
+ data: rows.flatMap(
1078
+ (row) => row.issue_field_id !== (multi ? 103 : 102) ? [row] : mode === "absent" ? [] : [
1079
+ {
1080
+ issue_field_id: row.issue_field_id,
1081
+ issue_field_name: row.issue_field_name,
1082
+ data_type: row.data_type,
1083
+ ...multi ? { multi_select_options: [] } : { value: null }
1084
+ }
1085
+ ]
1086
+ )
1087
+ };
934
1088
  });
935
1089
  await startTrackedIssue(f.context, { issueNumber: 17 });
936
- assert.equal(f.getStatus(), 'Active');
1090
+ assert.equal(f.getStatus(), "Active");
937
1091
  assert.equal(f.branchWrites.length, 1);
938
1092
  assert.equal(f.comments.length, 1);
939
- });
940
- test('WIP missing target and unknown native field evidence refuse rather than counting zero', async () => {
941
- for (const failure of ['target', 'field']) {
942
- const f = fixture();
943
- f.controls.capacityMode = true;
944
- f.controls.incompleteCapacity = failure === 'target';
945
- f.context.config = {
946
- ...f.context.config,
947
- wipLimits: [
948
- {
949
- repository: 'example/widget',
950
- name: 'Urgent work',
951
- match: { field: failure === 'field' ? 'Nonexistent lane field' : 'Urgency', value: 'High' },
952
- limit: 2,
953
- },
954
- ],
955
- };
956
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Cannot authorize missing evidence.' }), /capacity|field|target|WIP/iu);
957
- assert.equal(f.branchWrites.length, 0);
958
- assert.equal(f.comments.length, 0);
959
- }
960
- });
961
- test('WIP follows native continuation evidence even when a page is short', async () => {
1093
+ }
1094
+ );
1095
+ test("WIP missing target and unknown native field evidence refuse rather than counting zero", async () => {
1096
+ for (const failure of ["target", "field"]) {
962
1097
  const f = fixture();
963
1098
  f.controls.capacityMode = true;
964
- f.controls.capacityPageSize = 1;
965
- f.live.labels = ['critical'];
1099
+ f.controls.incompleteCapacity = failure === "target";
966
1100
  f.context.config = {
967
- ...f.context.config,
968
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
1101
+ ...f.context.config,
1102
+ wipLimits: [
1103
+ {
1104
+ repository: "example/widget",
1105
+ name: "Urgent work",
1106
+ match: { field: failure === "field" ? "Nonexistent lane field" : "Urgency", value: "High" },
1107
+ limit: 2
1108
+ }
1109
+ ]
969
1110
  };
970
- f.capacity.push({ number: 18, label: 'critical', value: 'High', status: 'Active' });
971
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity limit/u);
1111
+ await assert.rejects(
1112
+ startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Cannot authorize missing evidence." }),
1113
+ /capacity|field|target|WIP/iu
1114
+ );
972
1115
  assert.equal(f.branchWrites.length, 0);
1116
+ assert.equal(f.comments.length, 0);
1117
+ }
973
1118
  });
974
- test('WIP rejects malformed continuation remnants instead of treating a short page as complete', async () => {
975
- const f = fixture();
976
- f.controls.capacityMode = true;
977
- f.controls.capacityPageSize = 1;
978
- f.live.labels = ['critical'];
979
- f.context.config = {
980
- ...f.context.config,
981
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
982
- };
983
- f.capacity.push({ number: 18, label: 'critical', value: 'High', status: 'Active' });
984
- const list = f.context.clients.rest.issues.listForRepo;
985
- f.context.clients.rest.issues.listForRepo = (async (input) => ({
986
- ...(await list(input)),
987
- headers: {
988
- link: '<https://api.github.com/repos/example/widget/issues?page=1&per_page=100>; rel="prev", broken next continuation',
989
- },
990
- }));
991
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /capacity.*pagination/iu);
992
- assert.equal(f.branchWrites.length, 0);
1119
+ test("WIP follows native continuation evidence even when a page is short", async () => {
1120
+ const f = fixture();
1121
+ f.controls.capacityMode = true;
1122
+ f.controls.capacityPageSize = 1;
1123
+ f.live.labels = ["critical"];
1124
+ f.context.config = {
1125
+ ...f.context.config,
1126
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
1127
+ };
1128
+ f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
1129
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity limit/u);
1130
+ assert.equal(f.branchWrites.length, 0);
993
1131
  });
994
- test('WIP rejects a native page larger than its requested window', async () => {
995
- const f = fixture();
996
- f.controls.capacityMode = true;
997
- f.live.labels = ['critical'];
998
- f.context.config = {
999
- ...f.context.config,
1000
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
1001
- };
1002
- const list = f.context.clients.rest.issues.listForRepo;
1003
- f.context.clients.rest.issues.listForRepo = (async (input) => ({
1004
- headers: {},
1005
- data: [
1006
- ...(await list(input)).data,
1007
- ...Array.from({ length: 100 }, (_, index) => ({ number: 1000 + index, pull_request: {} })),
1008
- ],
1009
- }));
1010
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity pagination/u);
1011
- assert.equal(f.branchWrites.length, 0);
1132
+ test("WIP rejects malformed continuation remnants instead of treating a short page as complete", async () => {
1133
+ const f = fixture();
1134
+ f.controls.capacityMode = true;
1135
+ f.controls.capacityPageSize = 1;
1136
+ f.live.labels = ["critical"];
1137
+ f.context.config = {
1138
+ ...f.context.config,
1139
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
1140
+ };
1141
+ f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
1142
+ const list = f.context.clients.rest.issues.listForRepo;
1143
+ f.context.clients.rest.issues.listForRepo = (async (input) => ({
1144
+ ...await list(input),
1145
+ headers: {
1146
+ link: '<https://api.github.com/repos/example/widget/issues?page=1&per_page=100>; rel="prev", broken next continuation'
1147
+ }
1148
+ }));
1149
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /capacity.*pagination/iu);
1150
+ assert.equal(f.branchWrites.length, 0);
1151
+ });
1152
+ test("WIP rejects a native page larger than its requested window", async () => {
1153
+ const f = fixture();
1154
+ f.controls.capacityMode = true;
1155
+ f.live.labels = ["critical"];
1156
+ f.context.config = {
1157
+ ...f.context.config,
1158
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
1159
+ };
1160
+ const list = f.context.clients.rest.issues.listForRepo;
1161
+ f.context.clients.rest.issues.listForRepo = (async (input) => ({
1162
+ headers: {},
1163
+ data: [
1164
+ ...(await list(input)).data,
1165
+ ...Array.from({ length: 100 }, (_, index) => ({ number: 1e3 + index, pull_request: {} }))
1166
+ ]
1167
+ }));
1168
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP capacity pagination/u);
1169
+ assert.equal(f.branchWrites.length, 0);
1170
+ });
1171
+ test("WIP evaluates every matching lane and capacity overrides cannot resume a deferred or blocked issue", async () => {
1172
+ const f = fixture();
1173
+ f.controls.capacityMode = true;
1174
+ f.live.labels = ["critical"];
1175
+ f.context.config = {
1176
+ ...f.context.config,
1177
+ wipLimits: [
1178
+ { repository: "example/widget", name: "Labels allow", match: { label: "critical" }, limit: 1 },
1179
+ { repository: "example/widget", name: "Field is full", match: { field: "Urgency", value: "High" }, limit: 1 }
1180
+ ]
1181
+ };
1182
+ f.capacity.push({ number: 18, label: "other", value: "High", status: "Active" });
1183
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Field is full/u);
1184
+ const deferred = { issueNumber: 17, defer: { trigger: "Manual approval" } };
1185
+ await updateIssue(f.context, deferred);
1186
+ await assert.rejects(
1187
+ startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }),
1188
+ /deferred/u
1189
+ );
1190
+ await updateIssue(f.context, { issueNumber: 17, undefer: true });
1191
+ f.controls.blockers = true;
1192
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }), /blocked/u);
1193
+ assert.equal(f.branchWrites.length, 0);
1194
+ assert.equal(f.comments.length, 0);
1012
1195
  });
1013
- test('WIP evaluates every matching lane and capacity overrides cannot resume a deferred or blocked issue', async () => {
1196
+ test("WIP distinguishes an explicitly unset native Status from omitted Status evidence", async () => {
1197
+ for (const status of ["Unset", "Missing"]) {
1014
1198
  const f = fixture();
1015
1199
  f.controls.capacityMode = true;
1016
- f.live.labels = ['critical'];
1200
+ f.live.labels = ["critical"];
1017
1201
  f.context.config = {
1018
- ...f.context.config,
1019
- wipLimits: [
1020
- { repository: 'example/widget', name: 'Labels allow', match: { label: 'critical' }, limit: 1 },
1021
- { repository: 'example/widget', name: 'Field is full', match: { field: 'Urgency', value: 'High' }, limit: 1 },
1022
- ],
1202
+ ...f.context.config,
1203
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
1023
1204
  };
1024
- f.capacity.push({ number: 18, label: 'other', value: 'High', status: 'Active' });
1025
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Field is full/u);
1026
- const deferred = { issueNumber: 17, defer: { trigger: 'Manual approval' } };
1027
- await updateIssue(f.context, deferred);
1028
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Capacity only.' }), /deferred/u);
1029
- await updateIssue(f.context, { issueNumber: 17, undefer: true });
1030
- f.controls.blockers = true;
1031
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Capacity only.' }), /blocked/u);
1032
- assert.equal(f.branchWrites.length, 0);
1033
- assert.equal(f.comments.length, 0);
1034
- });
1035
- test('WIP distinguishes an explicitly unset native Status from omitted Status evidence', async () => {
1036
- for (const status of ['Unset', 'Missing']) {
1037
- const f = fixture();
1038
- f.controls.capacityMode = true;
1039
- f.live.labels = ['critical'];
1040
- f.context.config = {
1041
- ...f.context.config,
1042
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
1043
- };
1044
- f.capacity.push({ number: 18, label: 'critical', value: 'High', status });
1045
- if (status === 'Unset') {
1046
- await startTrackedIssue(f.context, { issueNumber: 17 });
1047
- assert.equal(f.getStatus(), 'Active');
1048
- }
1049
- else {
1050
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity/u);
1051
- assert.equal(f.branchWrites.length, 0);
1052
- }
1205
+ f.capacity.push({ number: 18, label: "critical", value: "High", status });
1206
+ if (status === "Unset") {
1207
+ await startTrackedIssue(f.context, { issueNumber: 17 });
1208
+ assert.equal(f.getStatus(), "Active");
1209
+ } else {
1210
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /WIP|capacity/u);
1211
+ assert.equal(f.branchWrites.length, 0);
1053
1212
  }
1213
+ }
1214
+ });
1215
+ test("WIP evaluates distinct lanes using case aliases of the same native label", async () => {
1216
+ const f = fixture();
1217
+ f.controls.capacityMode = true;
1218
+ f.live.labels = ["critical"];
1219
+ f.context.config = {
1220
+ ...f.context.config,
1221
+ wipLimits: [
1222
+ { repository: "example/widget", name: "Available", match: { label: "critical" }, limit: 1 },
1223
+ { repository: "EXAMPLE/WIDGET", name: "Hold lane", match: { label: "CRITICAL" }, limit: 0 }
1224
+ ]
1225
+ };
1226
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Hold lane/u);
1227
+ assert.equal(f.branchWrites.length, 0);
1054
1228
  });
1055
- test('WIP evaluates distinct lanes using case aliases of the same native label', async () => {
1229
+ test("WIP field matching preserves value types for multi-select member names", async () => {
1230
+ for (const value of [0, " 0 ", "0"]) {
1056
1231
  const f = fixture();
1057
1232
  f.controls.capacityMode = true;
1058
- f.live.labels = ['critical'];
1059
1233
  f.context.config = {
1060
- ...f.context.config,
1061
- wipLimits: [
1062
- { repository: 'example/widget', name: 'Available', match: { label: 'critical' }, limit: 1 },
1063
- { repository: 'EXAMPLE/WIDGET', name: 'Hold lane', match: { label: 'CRITICAL' }, limit: 0 },
1064
- ],
1234
+ ...f.context.config,
1235
+ wipLimits: [{ repository: "example/widget", name: "Tagged work", match: { field: "Tags", value }, limit: 0 }]
1065
1236
  };
1066
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Hold lane/u);
1067
- assert.equal(f.branchWrites.length, 0);
1068
- });
1069
- test('WIP field matching preserves value types for multi-select member names', async () => {
1070
- for (const value of [0, ' 0 ', '0']) {
1071
- const f = fixture();
1072
- f.controls.capacityMode = true;
1073
- f.context.config = {
1074
- ...f.context.config,
1075
- wipLimits: [{ repository: 'example/widget', name: 'Tagged work', match: { field: 'Tags', value }, limit: 0 }],
1076
- };
1077
- if (typeof value === 'number' || value === ' 0 ') {
1078
- await startTrackedIssue(f.context, { issueNumber: 17 });
1079
- assert.equal(f.getStatus(), 'Active');
1080
- }
1081
- else {
1082
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Tagged work/u);
1083
- assert.equal(f.branchWrites.length, 0);
1084
- }
1237
+ if (typeof value === "number" || value === " 0 ") {
1238
+ await startTrackedIssue(f.context, { issueNumber: 17 });
1239
+ assert.equal(f.getStatus(), "Active");
1240
+ } else {
1241
+ await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), /Tagged work/u);
1242
+ assert.equal(f.branchWrites.length, 0);
1085
1243
  }
1244
+ }
1086
1245
  });
1087
- test.each(['project', 'pagination', 'status', 'archive', 'unreadable'])('WIP refuses changed or incomplete native %s evidence after healthy readiness', async (failure) => {
1246
+ test.each(["status", "archive", "unreadable"])(
1247
+ "WIP refuses changed or incomplete native %s evidence after healthy readiness",
1248
+ async (failure) => {
1088
1249
  const f = fixture();
1089
1250
  f.controls.capacityMode = true;
1090
- f.live.labels = ['critical'];
1251
+ f.live.labels = ["critical"];
1091
1252
  f.context.config = {
1092
- ...f.context.config,
1093
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 1 }],
1253
+ ...f.context.config,
1254
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 1 }]
1094
1255
  };
1095
1256
  const graphql = f.context.clients.graphql;
1096
1257
  let projectReads = 0;
1097
1258
  f.context.clients.graphql = (async (query, variables) => {
1098
- const value = await graphql(query, variables);
1099
- if (query.includes('ProjectDeliveryItems') && ++projectReads > 1) {
1100
- const project = value.organization.projectV2;
1101
- if (failure === 'project')
1102
- project.id = 'FOREIGN';
1103
- if (failure === 'pagination')
1104
- delete project.items.pageInfo.hasNextPage;
1105
- if (failure === 'status')
1106
- delete project.items.nodes[0].fieldValueByName;
1107
- if (failure === 'archive')
1108
- delete project.items.nodes[0].isArchived;
1109
- if (failure === 'unreadable')
1110
- project.items.nodes.push({ id: 'UNKNOWN', isArchived: false, content: null, fieldValueByName: null });
1111
- }
1112
- return value;
1259
+ const value = await graphql(query, variables);
1260
+ if (query.includes("ProjectDeliveryIssueItems") && ++projectReads > 1) {
1261
+ const nodes = value.node.projectItems.nodes;
1262
+ if (failure === "status") delete nodes[0].fieldValueByName;
1263
+ if (failure === "archive") delete nodes[0].isArchived;
1264
+ if (failure === "unreadable") nodes[0].content = null;
1265
+ }
1266
+ return value;
1113
1267
  });
1114
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17, overrideReason: 'Capacity only.' }), /WIP|capacity/u);
1268
+ await assert.rejects(
1269
+ startTrackedIssue(f.context, { issueNumber: 17, overrideReason: "Capacity only." }),
1270
+ /WIP|capacity/u
1271
+ );
1115
1272
  assert.equal(f.branchWrites.length, 0);
1116
1273
  assert.equal(f.comments.length, 0);
1274
+ }
1275
+ );
1276
+ test("WIP refuses observation drift after recording an override and preserves that attempt for reconciliation", async () => {
1277
+ const f = fixture();
1278
+ f.controls.capacityMode = true;
1279
+ f.live.labels = ["critical"];
1280
+ f.context.config = {
1281
+ ...f.context.config,
1282
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
1283
+ };
1284
+ const createComment = f.context.clients.rest.issues.createComment;
1285
+ let drift = true;
1286
+ f.context.clients.rest.issues.createComment = (async (input2) => {
1287
+ const result2 = await createComment(input2);
1288
+ if (drift) {
1289
+ drift = false;
1290
+ f.capacity.push({ number: 18, label: "critical", value: "High", status: "Active" });
1291
+ }
1292
+ return result2;
1293
+ });
1294
+ const input = { issueNumber: 17, overrideReason: "Explicit synthetic capacity exception." };
1295
+ const result = await startTrackedIssue(f.context, input);
1296
+ assert.match(Reflect.get(result, "failure").message, /capacity changed/u);
1297
+ assert.equal(f.getStatus(), "Queued");
1298
+ assert.equal(f.comments.length, 1);
1299
+ await startTrackedIssue(f.context, input);
1300
+ assert.equal(f.getStatus(), "Active");
1301
+ assert.equal(f.comments.length, 3, "two distinct native capacity observations and one start journal");
1302
+ assert.equal(f.branchWrites.length, 1);
1117
1303
  });
1118
- test('WIP refuses observation drift after recording an override and preserves that attempt for reconciliation', async () => {
1119
- const f = fixture();
1120
- f.controls.capacityMode = true;
1121
- f.live.labels = ['critical'];
1122
- f.context.config = {
1123
- ...f.context.config,
1124
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
1125
- };
1126
- const createComment = f.context.clients.rest.issues.createComment;
1127
- let drift = true;
1128
- f.context.clients.rest.issues.createComment = (async (input) => {
1129
- const result = await createComment(input);
1130
- if (drift) {
1131
- drift = false;
1132
- f.capacity.push({ number: 18, label: 'critical', value: 'High', status: 'Active' });
1133
- }
1134
- return result;
1135
- });
1136
- const input = { issueNumber: 17, overrideReason: 'Explicit synthetic capacity exception.' };
1137
- const result = await startTrackedIssue(f.context, input);
1138
- assert.match(Reflect.get(result, 'failure').message, /capacity changed/u);
1139
- assert.equal(f.getStatus(), 'Queued');
1140
- assert.equal(f.comments.length, 1);
1141
- await startTrackedIssue(f.context, input);
1142
- assert.equal(f.getStatus(), 'Active');
1143
- assert.equal(f.comments.length, 3, 'two distinct native capacity observations and one start journal');
1144
- assert.equal(f.branchWrites.length, 1);
1304
+ test("native create validates first, writes canonical fields, reads back metadata and returns warnings", async () => {
1305
+ const f = fixture();
1306
+ await assert.rejects(createIssue(f.context, { ...ready(), openQuestions: ["Select behavior."] }), /open-questions/u);
1307
+ assert.equal(f.writes.length, 0);
1308
+ const result = await createIssue(f.context, ready());
1309
+ assert.equal(f.writes.length, 1);
1310
+ assert.equal(canonicalIssueBody({ ...ready(), body: result.body }), renderIssueBody(ready()));
1311
+ assert.equal(parseIssueBody(result.body, { title: result.created.title }).issue.points, 2);
1312
+ assert.deepEqual(result.warnings, []);
1313
+ assert.equal(f.getStatus(), "Queued");
1145
1314
  });
1146
- test('native create validates first, writes canonical fields, reads back metadata and returns warnings', async () => {
1147
- const f = fixture();
1148
- await assert.rejects(createIssue(f.context, { ...ready(), openQuestions: ['Select behavior.'] }), /open-questions/u);
1149
- assert.equal(f.writes.length, 0);
1150
- const result = await createIssue(f.context, ready());
1151
- assert.equal(f.writes.length, 1);
1152
- assert.equal(canonicalIssueBody({ ...ready(), body: result.body }), renderIssueBody(ready()));
1153
- assert.equal(parseIssueBody(result.body, { title: result.created.title }).issue.points, 2);
1154
- assert.deepEqual(result.warnings, []);
1155
- assert.equal(f.getStatus(), 'Queued');
1315
+ test("incomplete drafts write parked; reviewer-role writes and wrong native repository readback are refused", async () => {
1316
+ const f = fixture();
1317
+ await createIssue(f.context, { title: "Investigate invalid widget identifiers", draft: true });
1318
+ assert.equal(f.getStatus(), "Queued");
1319
+ assert.match(f.live.body, /\*\*State:\*\* Draft/u);
1320
+ f.controls.role = "reviewer";
1321
+ await assert.rejects(createIssue(f.context, ready()), /author role/u);
1322
+ await assert.rejects(updateIssue(f.context, { issueNumber: 17, draft: true }), /author role/u);
1323
+ const bad = fixture();
1324
+ bad.controls.wrongCreateRepo = true;
1325
+ await assert.rejects(createIssue(bad.context, ready()), /created but native tracking did not complete/u);
1326
+ assert.equal(bad.writes.length, 1);
1156
1327
  });
1157
- test('incomplete drafts write parked; reviewer-role writes and wrong native repository readback are refused', async () => {
1158
- const f = fixture();
1159
- await createIssue(f.context, { title: 'Investigate invalid widget identifiers', draft: true });
1160
- assert.equal(f.getStatus(), 'Queued');
1161
- assert.match(f.live.body, /\*\*State:\*\* Draft/u);
1162
- f.controls.role = 'reviewer';
1163
- await assert.rejects(createIssue(f.context, ready()), /author role/u);
1164
- await assert.rejects(updateIssue(f.context, { issueNumber: 17, draft: true }), /author role/u);
1165
- const bad = fixture();
1166
- bad.controls.wrongCreateRepo = true;
1167
- await assert.rejects(createIssue(bad.context, ready()), /created but native tracking did not complete/u);
1168
- assert.equal(bad.writes.length, 1);
1328
+ test("first legacy update retains exact history and full diff, then typed patches preserve unspecified fields", async () => {
1329
+ const f = fixture();
1330
+ const legacy = "## Problem\nMalformed identifiers reach persistence.\n## Outcome\nReject malformed identifiers.\n## Acceptance Criteria\n- [ ] Invalid identifiers return an error without persistence.\n## Verification\nA portable regression asserts no write.\n## Out of scope\n- Storage changes.\n## Scope\nwidget component\n";
1331
+ f.live.body = legacy;
1332
+ const result = await updateIssue(f.context, { issueNumber: 17 });
1333
+ assert.equal(f.comments.length, 1);
1334
+ assert.equal(result.conversion?.priorBody, legacy);
1335
+ assert.match(result.conversion.diff, /^--- prior body\n\+\+\+ canonical body/u);
1336
+ assert.match(f.comments[0].body, /Malformed identifiers reach persistence/u);
1337
+ assert.equal(parseIssueBody(result.body, { title: result.title }).issue.legacyBody, legacy);
1338
+ const patched = await updateIssue(f.context, {
1339
+ issueNumber: 17,
1340
+ outcome: "Reject malformed identifiers with a typed error.",
1341
+ preserveHistory: true
1342
+ });
1343
+ assert.equal(parseIssueBody(patched.body, { title: patched.title }).issue.acceptanceCriteria.length, 1);
1344
+ assert.equal(patched.conversion, void 0);
1345
+ assert.equal(f.comments.length, 2);
1169
1346
  });
1170
- test('first legacy update retains exact history and full diff, then typed patches preserve unspecified fields', async () => {
1347
+ test("legacy replacement updates preserve the actual previous body and diff for canonical and handwritten input", async () => {
1348
+ const original = "Original native legacy bytes, including unclassified operator context.\n";
1349
+ for (const replacement of [renderIssueBody(ready()), "Replacement handwritten context.\n"]) {
1171
1350
  const f = fixture();
1172
- const legacy = '## Problem\nMalformed identifiers reach persistence.\n## Outcome\nReject malformed identifiers.\n## Acceptance Criteria\n- [ ] Invalid identifiers return an error without persistence.\n## Verification\nA portable regression asserts no write.\n## Out of scope\n- Storage changes.\n## Scope\nwidget component\n';
1173
- f.live.body = legacy;
1174
- const result = await updateIssue(f.context, { issueNumber: 17 });
1351
+ f.live.body = original;
1352
+ const result = await updateIssue(f.context, { issueNumber: 17, body: replacement, ...ready() });
1175
1353
  assert.equal(f.comments.length, 1);
1176
- assert.equal(result.conversion?.priorBody, legacy);
1177
- assert.match(result.conversion.diff, /^--- prior body\n\+\+\+ canonical body/u);
1178
- assert.match(f.comments[0].body, /Malformed identifiers reach persistence/u);
1179
- assert.equal(parseIssueBody(result.body, { title: result.title }).issue.legacyBody, legacy);
1180
- const patched = await updateIssue(f.context, {
1181
- issueNumber: 17,
1182
- outcome: 'Reject malformed identifiers with a typed error.',
1183
- preserveHistory: true,
1354
+ assert.ok(f.comments[0].body.includes(original));
1355
+ assert.equal(result.conversion?.priorBody, original);
1356
+ assert.ok(result.conversion.diff.includes("-" + original.trim()));
1357
+ const preserved = parseIssueBody(result.body, { title: result.title }).issue.legacyBody;
1358
+ assert.ok(preserved?.includes(original));
1359
+ if (!replacement.startsWith(ISSUE_BODY_MARKER)) assert.ok(preserved?.includes(replacement));
1360
+ assert.equal(result.conversion?.canonicalBody, result.body);
1361
+ const patch = await updateIssue(f.context, {
1362
+ issueNumber: 17,
1363
+ outcome: "Reject invalid input before persistence."
1184
1364
  });
1185
- assert.equal(parseIssueBody(patched.body, { title: patched.title }).issue.acceptanceCriteria.length, 1);
1186
- assert.equal(patched.conversion, undefined);
1187
- assert.equal(f.comments.length, 2);
1365
+ assert.equal(patch.conversion, void 0);
1366
+ assert.equal(f.comments.length, replacement.startsWith(ISSUE_BODY_MARKER) ? 1 : 2);
1367
+ assert.equal(parseIssueBody(patch.body, { title: patch.title }).issue.legacyBody, preserved);
1368
+ }
1188
1369
  });
1189
- test('legacy replacement updates preserve the actual previous body and diff for canonical and handwritten input', async () => {
1190
- const original = 'Original native legacy bytes, including unclassified operator context.\n';
1191
- for (const replacement of [renderIssueBody(ready()), 'Replacement handwritten context.\n']) {
1192
- const f = fixture();
1193
- f.live.body = original;
1194
- const result = await updateIssue(f.context, { issueNumber: 17, body: replacement, ...ready() });
1195
- assert.equal(f.comments.length, 1);
1196
- assert.ok(f.comments[0].body.includes(original));
1197
- assert.equal(result.conversion?.priorBody, original);
1198
- assert.ok(result.conversion.diff.includes('-' + original.trim()));
1199
- const preserved = parseIssueBody(result.body, { title: result.title }).issue.legacyBody;
1200
- assert.ok(preserved?.includes(original));
1201
- if (!replacement.startsWith(ISSUE_BODY_MARKER))
1202
- assert.ok(preserved?.includes(replacement));
1203
- assert.equal(result.conversion?.canonicalBody, result.body);
1204
- const patch = await updateIssue(f.context, {
1205
- issueNumber: 17,
1206
- outcome: 'Reject invalid input before persistence.',
1207
- });
1208
- assert.equal(patch.conversion, undefined);
1209
- assert.equal(f.comments.length, replacement.startsWith(ISSUE_BODY_MARKER) ? 1 : 2);
1210
- assert.equal(parseIssueBody(patch.body, { title: patch.title }).issue.legacyBody, preserved);
1211
- }
1370
+ test("validation, history drift and corrupted native update readback fail without a fabricated success", async () => {
1371
+ const f = fixture();
1372
+ await assert.rejects(
1373
+ updateIssue(f.context, { issueNumber: 17, openQuestions: ["Choose a policy."] }),
1374
+ /open-questions/u
1375
+ );
1376
+ assert.equal(f.writes.length, 0);
1377
+ assert.equal(f.comments.length, 0);
1378
+ f.controls.driftAfterHistory = true;
1379
+ await assert.rejects(
1380
+ updateIssue(f.context, {
1381
+ issueNumber: 17,
1382
+ outcome: "Reject malformed input before all writes.",
1383
+ preserveHistory: true
1384
+ }),
1385
+ /content changed/u
1386
+ );
1387
+ assert.equal(f.writes.length, 0);
1388
+ const bad = fixture();
1389
+ bad.controls.ignoreBody = true;
1390
+ await assert.rejects(
1391
+ updateIssue(bad.context, { issueNumber: 17, outcome: "Reject malformed input before all writes." }),
1392
+ /update readback disagrees/u
1393
+ );
1212
1394
  });
1213
- test('validation, history drift and corrupted native update readback fail without a fabricated success', async () => {
1214
- const f = fixture();
1215
- await assert.rejects(updateIssue(f.context, { issueNumber: 17, openQuestions: ['Choose a policy.'] }), /open-questions/u);
1216
- assert.equal(f.writes.length, 0);
1217
- assert.equal(f.comments.length, 0);
1218
- f.controls.driftAfterHistory = true;
1219
- await assert.rejects(updateIssue(f.context, {
1220
- issueNumber: 17,
1221
- outcome: 'Reject malformed input before all writes.',
1222
- preserveHistory: true,
1223
- }), /content changed/u);
1224
- assert.equal(f.writes.length, 0);
1225
- const bad = fixture();
1226
- bad.controls.ignoreBody = true;
1227
- await assert.rejects(updateIssue(bad.context, { issueNumber: 17, outcome: 'Reject malformed input before all writes.' }), /update readback disagrees/u);
1395
+ test("normal-start canonical retry body keeps exact intent markers through create/readiness", async () => {
1396
+ const issue = ready();
1397
+ const canonical = canonicalIssueBody(issue);
1398
+ const footer = "\n\n<!-- ai-delivery-start-intent: " + digestValue({ intent: "fixture" }) + " -->\n<!-- ai-delivery-start: " + digestValue({ request: "fixture" }) + " -->";
1399
+ const result = await createIssue(fixture().context, {
1400
+ title: issue.title,
1401
+ body: canonical + footer,
1402
+ points: 2,
1403
+ issueType: "Task"
1404
+ });
1405
+ assert.equal(canonicalIssueBody({ ...issue, body: result.body }), canonical + footer);
1406
+ assert.deepEqual(parseIssueBody(result.body, { title: issue.title }).issue, issue);
1228
1407
  });
1229
- test('normal-start canonical retry body keeps exact intent markers through create/readiness', async () => {
1230
- const issue = ready();
1231
- const canonical = canonicalIssueBody(issue);
1232
- const footer = '\n\n<!-- ai-delivery-start-intent: ' +
1233
- digestValue({ intent: 'fixture' }) +
1234
- ' -->\n<!-- ai-delivery-start: ' +
1235
- digestValue({ request: 'fixture' }) +
1236
- ' -->';
1237
- const result = await createIssue(fixture().context, {
1238
- title: issue.title,
1239
- body: canonical + footer,
1240
- points: 2,
1241
- issueType: 'Task',
1242
- });
1243
- assert.equal(canonicalIssueBody({ ...issue, body: result.body }), canonical + footer);
1244
- assert.deepEqual(parseIssueBody(result.body, { title: issue.title }).issue, issue);
1408
+ test("actual normal-start creation and retry reuse the exact canonical body, branch and authored journal", async () => {
1409
+ const clock = vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-10-16T20:30:00Z"));
1410
+ const f = fixture();
1411
+ f.controls.created = false;
1412
+ const request = getAiDeliveryMcpTool("issue_start").inputSchema.parse({
1413
+ title: ready().title,
1414
+ body: renderIssueBody(ready()),
1415
+ issueType: "Task",
1416
+ points: 2,
1417
+ requestId: "issue68-normal-start"
1418
+ });
1419
+ const first = await startTrackedIssue(f.context, request);
1420
+ assert.ok("issueNumber" in first);
1421
+ assert.equal(first.issueNumber, 17);
1422
+ assert.ok("reused" in first && first.reused === false);
1423
+ const body = f.live.body;
1424
+ assert.match(body, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
1425
+ assert.match(body, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
1426
+ assert.deepEqual(parseIssueBody(body, { title: f.live.title }).issue, ready());
1427
+ assert.equal(f.branchWrites.length, 1);
1428
+ assert.equal(
1429
+ f.branchWrites[0]?.clientMutationId,
1430
+ digestValue({ repository: "example/widget", issueNumber: 17, name: "issue/17", base: "a".repeat(40) })
1431
+ );
1432
+ assert.equal(f.comments.length, 1);
1433
+ clock.mockReturnValue(Date.parse("2026-10-17T20:30:00Z"));
1434
+ const retry = await startTrackedIssue(f.context, request);
1435
+ assert.ok("reused" in retry && retry.reused === true);
1436
+ assert.equal(retry.issueNumber, 17);
1437
+ assert.equal(f.writes.filter((input) => !("issue_number" in input)).length, 1);
1438
+ assert.equal(f.branchWrites.length, 1);
1439
+ assert.equal(f.comments.length, 1);
1440
+ assert.equal(f.live.body, body);
1441
+ await assert.rejects(
1442
+ startTrackedIssue(f.context, {
1443
+ ...request,
1444
+ body: renderIssueBody({ ...ready(), outcome: "A conflicting new outcome." })
1445
+ }),
1446
+ /conflicts/u
1447
+ );
1448
+ assert.equal(f.branchWrites.length, 1);
1245
1449
  });
1246
- test('actual normal-start creation and retry reuse the exact canonical body, branch and authored journal', async () => {
1247
- const clock = vi.spyOn(Date, 'now').mockReturnValue(Date.parse('2026-10-16T20:30:00Z'));
1248
- const f = fixture();
1249
- f.controls.created = false;
1250
- const request = getAiDeliveryMcpTool('issue_start').inputSchema.parse({
1251
- title: ready().title,
1252
- body: renderIssueBody(ready()),
1253
- issueType: 'Task',
1254
- points: 2,
1255
- requestId: 'issue68-normal-start',
1256
- });
1257
- const first = await startTrackedIssue(f.context, request);
1258
- assert.ok('issueNumber' in first);
1259
- assert.equal(first.issueNumber, 17);
1260
- assert.ok('reused' in first && first.reused === false);
1261
- const body = f.live.body;
1262
- assert.match(body, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
1263
- assert.match(body, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
1264
- assert.deepEqual(parseIssueBody(body, { title: f.live.title }).issue, ready());
1265
- assert.equal(f.branchWrites.length, 1);
1266
- assert.equal(f.branchWrites[0]?.clientMutationId, digestValue({ repository: 'example/widget', issueNumber: 17, name: 'issue/17', base: 'a'.repeat(40) }));
1267
- assert.equal(f.comments.length, 1);
1268
- clock.mockReturnValue(Date.parse('2026-10-17T20:30:00Z'));
1269
- const retry = await startTrackedIssue(f.context, request);
1270
- assert.ok('reused' in retry && retry.reused === true);
1271
- assert.equal(retry.issueNumber, 17);
1272
- assert.equal(f.writes.filter((input) => !('issue_number' in input)).length, 1);
1273
- assert.equal(f.branchWrites.length, 1);
1274
- assert.equal(f.comments.length, 1);
1275
- assert.equal(f.live.body, body);
1276
- await assert.rejects(startTrackedIssue(f.context, {
1277
- ...request,
1278
- body: renderIssueBody({ ...ready(), outcome: 'A conflicting new outcome.' }),
1279
- }), /conflicts/u);
1280
- assert.equal(f.branchWrites.length, 1);
1450
+ test("a history rewrite refuses to republish secret-bearing prior text", async () => {
1451
+ const f = fixture();
1452
+ f.live.body = "An accidental fixture " + ["gh", "p_"].join("") + "A".repeat(24);
1453
+ await assert.rejects(
1454
+ updateIssue(f.context, { issueNumber: 17, body: renderIssueBody(ready()), preserveHistory: true }),
1455
+ /secrets/u
1456
+ );
1457
+ assert.equal(f.comments.length, 0);
1458
+ assert.equal(f.writes.length, 0);
1281
1459
  });
1282
- test('a history rewrite refuses to republish secret-bearing prior text', async () => {
1283
- const f = fixture();
1284
- f.live.body = 'An accidental fixture ' + ['gh', 'p_'].join('') + 'A'.repeat(24);
1285
- await assert.rejects(updateIssue(f.context, { issueNumber: 17, body: renderIssueBody(ready()), preserveHistory: true }), /secrets/u);
1286
- assert.equal(f.comments.length, 0);
1287
- assert.equal(f.writes.length, 0);
1460
+ test("ordinary start checks typed Draft, Points and live eligibility before branch or journal mutation", async () => {
1461
+ for (const [expected, change] of [
1462
+ [
1463
+ "draft",
1464
+ (f2) => {
1465
+ f2.live.body = renderIssueBody({ ...ready(), draft: true });
1466
+ }
1467
+ ],
1468
+ [
1469
+ "points.sync",
1470
+ (f2) => {
1471
+ f2.controls.livePoints = 4;
1472
+ }
1473
+ ],
1474
+ [
1475
+ "blocked",
1476
+ (f2) => {
1477
+ f2.controls.blockers = true;
1478
+ }
1479
+ ],
1480
+ [
1481
+ "tracking-parent",
1482
+ (f2) => {
1483
+ f2.controls.trackingParent = true;
1484
+ }
1485
+ ]
1486
+ ]) {
1487
+ const f2 = fixture();
1488
+ change(f2);
1489
+ await assert.rejects(startTrackedIssue(f2.context, { issueNumber: 17 }), (error) => {
1490
+ assert.ok(error instanceof Error);
1491
+ const diagnostics = JSON.parse(error.message);
1492
+ assert(diagnostics.failures.some((failure) => failure.code === expected && failure.field && failure.fixHint));
1493
+ return true;
1494
+ });
1495
+ assert.equal(f2.branchWrites.length, 0);
1496
+ assert.equal(f2.comments.length, 0);
1497
+ assert.equal(f2.writes.length, 0);
1498
+ }
1499
+ const f = fixture();
1500
+ f.live.body = renderIssueBody({ ...ready(), outcome: "Retain the Todo label when validation passes." });
1501
+ const first = await startTrackedIssue(f.context, { issueNumber: 17 });
1502
+ assert.ok("reused" in first && first.reused === false);
1503
+ assert.ok("reused" in await startTrackedIssue(f.context, { issueNumber: 17 }));
1504
+ assert.equal(f.branchWrites.length, 1);
1505
+ assert.equal(f.comments.length, 1);
1288
1506
  });
1289
- test('ordinary start checks typed Draft, Points and live eligibility before branch or journal mutation', async () => {
1290
- for (const [expected, change] of [
1291
- [
1292
- 'draft',
1293
- (f) => {
1294
- f.live.body = renderIssueBody({ ...ready(), draft: true });
1295
- },
1296
- ],
1297
- [
1298
- 'points.sync',
1299
- (f) => {
1300
- f.controls.livePoints = 4;
1301
- },
1302
- ],
1303
- [
1304
- 'blocked',
1305
- (f) => {
1306
- f.controls.blockers = true;
1307
- },
1308
- ],
1309
- [
1310
- 'tracking-parent',
1311
- (f) => {
1312
- f.controls.trackingParent = true;
1313
- },
1314
- ],
1315
- ]) {
1316
- const f = fixture();
1317
- change(f);
1318
- await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), (error) => {
1319
- assert.ok(error instanceof Error);
1320
- const diagnostics = JSON.parse(error.message);
1321
- assert(diagnostics.failures.some((failure) => failure.code === expected && failure.field && failure.fixHint));
1322
- return true;
1323
- });
1324
- assert.equal(f.branchWrites.length, 0);
1325
- assert.equal(f.comments.length, 0);
1326
- assert.equal(f.writes.length, 0);
1507
+ test("joined MCP start modes preserve ordinary input and reject mixed investigation or foreign repository calls before configuration", async () => {
1508
+ const schema = getAiDeliveryMcpTool("issue_start").inputSchema;
1509
+ assert(schema.safeParse({ issueNumber: 17, repo: "example/widget" }).success);
1510
+ assert(
1511
+ schema.safeParse({ body: renderIssueBody(ready()), title: ready().title, points: 2, issueType: "Task" }).success
1512
+ );
1513
+ for (const arguments_ of [
1514
+ { issueNumber: 17, expectedHeadSha: "a".repeat(40) },
1515
+ {
1516
+ issueNumber: 17,
1517
+ investigationWorktree: "/fictional/issue-17",
1518
+ expectedHeadSha: "a".repeat(40),
1519
+ body: renderIssueBody(ready())
1327
1520
  }
1328
- const f = fixture();
1329
- f.live.body = renderIssueBody({ ...ready(), outcome: 'Retain the Todo label when validation passes.' });
1330
- const first = await startTrackedIssue(f.context, { issueNumber: 17 });
1331
- assert.ok('reused' in first && first.reused === false);
1332
- assert.ok('reused' in (await startTrackedIssue(f.context, { issueNumber: 17 })));
1333
- assert.equal(f.branchWrites.length, 1);
1334
- assert.equal(f.comments.length, 1);
1521
+ ])
1522
+ assert.equal(schema.safeParse(arguments_).success, false);
1523
+ await assert.rejects(
1524
+ executeTool(
1525
+ "issue_start",
1526
+ { repo: "foreign/widget", issueNumber: 17 },
1527
+ { repo: "example/widget", repoRoot: "/synthetic-non-git" }
1528
+ ),
1529
+ /selectors disagree/u
1530
+ );
1531
+ const finish = getAiDeliveryMcpTool("issue_finish").inputSchema;
1532
+ assert(finish.safeParse({ issueNumber: 17, prNumber: 23 }).success);
1533
+ assert.equal(finish.safeParse({ issueNumber: 17 }).success, false);
1534
+ assert.equal(
1535
+ finish.safeParse({ issueNumber: 17, investigation: true, resultPath: "/fictional/result", prNumber: 23 }).success,
1536
+ false
1537
+ );
1335
1538
  });
1336
- test('joined MCP start modes preserve ordinary input and reject mixed investigation or foreign repository calls before configuration', async () => {
1337
- const schema = getAiDeliveryMcpTool('issue_start').inputSchema;
1338
- assert(schema.safeParse({ issueNumber: 17, repo: 'example/widget' }).success);
1339
- assert(schema.safeParse({ body: renderIssueBody(ready()), title: ready().title, points: 2, issueType: 'Task' }).success);
1340
- for (const arguments_ of [
1341
- { issueNumber: 17, expectedHeadSha: 'a'.repeat(40) },
1342
- {
1343
- issueNumber: 17,
1344
- investigationWorktree: '/fictional/issue-17',
1345
- expectedHeadSha: 'a'.repeat(40),
1346
- body: renderIssueBody(ready()),
1347
- },
1348
- ])
1349
- assert.equal(schema.safeParse(arguments_).success, false);
1350
- await assert.rejects(executeTool('issue_start', { repo: 'foreign/widget', issueNumber: 17 }, { repo: 'example/widget', repoRoot: '/synthetic-non-git' }), /selectors disagree/u);
1351
- const finish = getAiDeliveryMcpTool('issue_finish').inputSchema;
1352
- assert(finish.safeParse({ issueNumber: 17, prNumber: 23 }).success);
1353
- assert.equal(finish.safeParse({ issueNumber: 17 }).success, false);
1354
- assert.equal(finish.safeParse({ issueNumber: 17, investigation: true, resultPath: '/fictional/result', prNumber: 23 }).success, false);
1355
- });
1356
- test('created readiness refusal returns exact retry markers through safe resume and original request retry', async () => {
1357
- const f = fixture();
1358
- f.controls.created = false;
1359
- f.controls.trackingParent = true;
1360
- const schema = getAiDeliveryMcpTool('issue_start').inputSchema;
1361
- const request = schema.parse({
1362
- title: ready().title,
1363
- body: renderIssueBody(ready()),
1364
- issueType: 'Task',
1365
- points: 2,
1366
- requestId: 'issue68-readiness-recovery',
1367
- });
1368
- const interrupted = await startTrackedIssue(f.context, request);
1369
- if (interrupted.status !== 'created-not-started')
1370
- assert.fail('Expected a known-created readiness refusal.');
1371
- assert.equal(interrupted.status, 'created-not-started');
1372
- const nativeBody = f.live.body;
1373
- assert.match(nativeBody, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
1374
- assert.match(nativeBody, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
1375
- assert.equal(interrupted.safeResume.arguments.resumeCreated, undefined);
1376
- assert.equal('body' in interrupted.safeResume.arguments, false);
1377
- assert.equal(f.branchWrites.length, 0);
1378
- assert.equal(f.comments.length, 0);
1379
- assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
1380
- f.controls.trackingParent = false;
1381
- const resumed = await startTrackedIssue(f.context, schema.parse(interrupted.safeResume.arguments));
1382
- assert.ok('reused' in resumed && resumed.reused === false);
1383
- assert.equal(f.live.body, nativeBody);
1384
- const retry = await startTrackedIssue(f.context, request);
1385
- assert.ok('reused' in retry && retry.reused === true);
1386
- assert.equal(f.live.body, nativeBody);
1387
- assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
1388
- assert.equal(f.branchWrites.length, 1);
1389
- assert.equal(f.comments.length, 1);
1539
+ test("created readiness refusal returns exact retry markers through safe resume and original request retry", async () => {
1540
+ const f = fixture();
1541
+ f.controls.created = false;
1542
+ f.controls.trackingParent = true;
1543
+ const schema = getAiDeliveryMcpTool("issue_start").inputSchema;
1544
+ const request = schema.parse({
1545
+ title: ready().title,
1546
+ body: renderIssueBody(ready()),
1547
+ issueType: "Task",
1548
+ points: 2,
1549
+ requestId: "issue68-readiness-recovery"
1550
+ });
1551
+ const interrupted = await startTrackedIssue(f.context, request);
1552
+ if (interrupted.status !== "created-not-started") assert.fail("Expected a known-created readiness refusal.");
1553
+ assert.equal(interrupted.status, "created-not-started");
1554
+ const nativeBody = f.live.body;
1555
+ assert.match(nativeBody, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
1556
+ assert.match(nativeBody, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
1557
+ assert.equal(interrupted.safeResume.arguments.resumeCreated, void 0);
1558
+ assert.equal("body" in interrupted.safeResume.arguments, false);
1559
+ assert.equal(f.branchWrites.length, 0);
1560
+ assert.equal(f.comments.length, 0);
1561
+ assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
1562
+ f.controls.trackingParent = false;
1563
+ const resumed = await startTrackedIssue(f.context, schema.parse(interrupted.safeResume.arguments));
1564
+ assert.ok("reused" in resumed && resumed.reused === false);
1565
+ assert.equal(f.live.body, nativeBody);
1566
+ const retry = await startTrackedIssue(f.context, request);
1567
+ assert.ok("reused" in retry && retry.reused === true);
1568
+ assert.equal(f.live.body, nativeBody);
1569
+ assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
1570
+ assert.equal(f.branchWrites.length, 1);
1571
+ assert.equal(f.comments.length, 1);
1390
1572
  });
1391
- test('actual compiled stdio MCP returns every Ready diagnostic before credentials and refuses a foreign caller repo', async () => {
1392
- const root = mkdtempSync(join(tmpdir(), 'issue-contract-stdio-'));
1573
+ test(
1574
+ "actual compiled stdio MCP returns every Ready diagnostic before credentials and refuses a foreign caller repo",
1575
+ { tags: ["release"] },
1576
+ async () => {
1577
+ const root = mkdtempSync(join(tmpdir(), "issue-contract-stdio-"));
1393
1578
  const transport = new StdioClientTransport({
1394
- command: process.execPath,
1395
- args: [resolve('dist/cli.js'), '--identity', 'host-author', '--repo', 'example/widget', 'mcp:serve'],
1396
- cwd: root,
1397
- stderr: 'pipe',
1398
- env: {
1399
- HOME: root,
1400
- PATH: process.env.PATH ?? '',
1401
- AI_DELIVERY_CONFIG: join(root, 'missing-config.json'),
1402
- LANG: 'en_US.UTF-8',
1403
- },
1579
+ command: process.execPath,
1580
+ args: [resolve("dist/cli.js"), "--identity", "host-author", "--repo", "example/widget", "mcp:serve"],
1581
+ cwd: root,
1582
+ stderr: "pipe",
1583
+ env: {
1584
+ HOME: root,
1585
+ PATH: process.env.PATH ?? "",
1586
+ AI_DELIVERY_CONFIG: join(root, "missing-config.json"),
1587
+ LANG: "en_US.UTF-8"
1588
+ }
1404
1589
  });
1405
- const client = new Client({ name: 'issue68-synthetic-client', version: '1.0.0' });
1590
+ const client = new Client({ name: "issue68-synthetic-client", version: "1.0.0" });
1406
1591
  let spawnedPid = null;
1407
1592
  let closeObserved = false;
1408
1593
  try {
1409
- await client.connect(transport);
1410
- spawnedPid = transport.pid;
1411
- assert.ok(spawnedPid);
1412
- const original = transport.onclose;
1413
- transport.onclose = () => {
1414
- closeObserved = true;
1415
- original?.();
1416
- };
1417
- const listing = await client.listTools();
1418
- assert.ok(listing.tools.find((t) => t.name === 'issue_create')?.inputSchema.properties?.acceptanceCriteria);
1419
- const result = await client.callTool({
1420
- name: 'issue_create',
1421
- arguments: { ...ready(), points: 13, openQuestions: ['Select behavior.'] },
1594
+ await client.connect(transport);
1595
+ spawnedPid = transport.pid;
1596
+ assert.ok(spawnedPid);
1597
+ const original = transport.onclose;
1598
+ transport.onclose = () => {
1599
+ closeObserved = true;
1600
+ original?.();
1601
+ };
1602
+ const listing = await client.listTools();
1603
+ assert.ok(listing.tools.find((t) => t.name === "issue_create")?.inputSchema.properties?.acceptanceCriteria);
1604
+ const result = await client.callTool({
1605
+ name: "issue_create",
1606
+ arguments: { ...ready(), points: 13, openQuestions: ["Select behavior."] }
1607
+ });
1608
+ assert.equal(result.isError, true);
1609
+ const content = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(result.content);
1610
+ const diagnostic = z.object({
1611
+ contract: z.literal("ai-delivery.issue@1"),
1612
+ failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() }))
1613
+ }).parse(JSON.parse(content[0].text));
1614
+ assert.deepEqual(diagnostic.failures.map((f) => f.code).sort(), ["open-questions", "points"]);
1615
+ assert.ok(diagnostic.failures.every((f) => f.field && f.fixHint));
1616
+ for (const name of ["issue_create", "issue_update"]) {
1617
+ const malformed = await client.callTool({
1618
+ name,
1619
+ arguments: {
1620
+ ...ready(),
1621
+ ...name === "issue_update" ? { issueNumber: 17 } : {},
1622
+ acceptanceCriteria: [{ behavior: ready().acceptanceCriteria[0].behavior }],
1623
+ context: { components: 9 }
1624
+ }
1625
+ });
1626
+ assert.equal(malformed.isError, true);
1627
+ const blocks = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(malformed.content);
1628
+ const failure = z.object({
1629
+ contract: z.literal("ai-delivery.issue@1"),
1630
+ failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() }))
1631
+ }).parse(JSON.parse(blocks[0].text));
1632
+ assert.deepEqual(failure.failures.map((f) => f.field).sort(), [
1633
+ "acceptanceCriteria.0.verifiedBy",
1634
+ "context.components"
1635
+ ]);
1636
+ assert.ok(failure.failures.every((f) => f.code && f.fixHint));
1637
+ assert.doesNotMatch(blocks[0].text, /missing-config/u);
1638
+ const unknown = await client.callTool({
1639
+ name,
1640
+ arguments: {
1641
+ ...ready(),
1642
+ ...name === "issue_update" ? { issueNumber: 17 } : {},
1643
+ unexpectedField: "Root field must be refused.",
1644
+ context: { ...ready().context, unexpectedField: "Nested field must be refused." },
1645
+ acceptanceCriteria: [{ ...ready().acceptanceCriteria[0], unexpectedField: "Unknown criterion field." }]
1646
+ }
1422
1647
  });
1423
- assert.equal(result.isError, true);
1424
- const content = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(result.content);
1425
- const diagnostic = z
1426
- .object({
1427
- contract: z.literal('ai-delivery.issue@1'),
1428
- failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() })),
1648
+ assert.equal(unknown.isError, true);
1649
+ const unknownBlocks = z.array(z.object({ type: z.literal("text"), text: z.string() })).parse(unknown.content);
1650
+ const unknownFailure = z.object({
1651
+ contract: z.literal("ai-delivery.issue@1"),
1652
+ failures: z.array(z.object({ code: z.literal("field.unknown"), field: z.string(), fixHint: z.string() }))
1653
+ }).parse(JSON.parse(unknownBlocks[0].text));
1654
+ assert.deepEqual(unknownFailure.failures.map((f) => f.field).sort(), [
1655
+ "acceptanceCriteria.0",
1656
+ "context",
1657
+ "issue"
1658
+ ]);
1659
+ assert.ok(unknownFailure.failures.every((f) => f.fixHint.length > 10));
1660
+ assert.doesNotMatch(
1661
+ unknownBlocks[0].text,
1662
+ /unexpectedField|Nested field|Unknown criterion/u,
1663
+ "Diagnostics do not echo untrusted keys or values."
1664
+ );
1665
+ }
1666
+ const foreign = await client.callTool({ name: "issue_create", arguments: { ...ready(), repo: "other/widget" } });
1667
+ assert.equal(foreign.isError, true);
1668
+ assert.match(JSON.stringify(foreign.content), /repository selectors disagree/u);
1669
+ } finally {
1670
+ await client.close();
1671
+ assert.equal(closeObserved, true, "SDK spawned-child close event was actually observed");
1672
+ rmSync(root, { recursive: true, force: true });
1673
+ console.info(
1674
+ JSON.stringify({
1675
+ fixture: "issue68-compiled-stdio",
1676
+ spawnedPid,
1677
+ childCloseObserved: closeObserved,
1678
+ syntheticRootRemoved: true
1429
1679
  })
1430
- .parse(JSON.parse(content[0].text));
1431
- assert.deepEqual(diagnostic.failures.map((f) => f.code).sort(), ['open-questions', 'points']);
1432
- assert.ok(diagnostic.failures.every((f) => f.field && f.fixHint));
1433
- for (const name of ['issue_create', 'issue_update']) {
1434
- const malformed = await client.callTool({
1435
- name,
1436
- arguments: {
1437
- ...ready(),
1438
- ...(name === 'issue_update' ? { issueNumber: 17 } : {}),
1439
- acceptanceCriteria: [{ behavior: ready().acceptanceCriteria[0].behavior }],
1440
- context: { components: 9 },
1441
- },
1442
- });
1443
- assert.equal(malformed.isError, true);
1444
- const blocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(malformed.content);
1445
- const failure = z
1446
- .object({
1447
- contract: z.literal('ai-delivery.issue@1'),
1448
- failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() })),
1449
- })
1450
- .parse(JSON.parse(blocks[0].text));
1451
- assert.deepEqual(failure.failures.map((f) => f.field).sort(), [
1452
- 'acceptanceCriteria.0.verifiedBy',
1453
- 'context.components',
1454
- ]);
1455
- assert.ok(failure.failures.every((f) => f.code && f.fixHint));
1456
- assert.doesNotMatch(blocks[0].text, /missing-config/u);
1457
- const unknown = await client.callTool({
1458
- name,
1459
- arguments: {
1460
- ...ready(),
1461
- ...(name === 'issue_update' ? { issueNumber: 17 } : {}),
1462
- unexpectedField: 'Root field must be refused.',
1463
- context: { ...ready().context, unexpectedField: 'Nested field must be refused.' },
1464
- acceptanceCriteria: [{ ...ready().acceptanceCriteria[0], unexpectedField: 'Unknown criterion field.' }],
1465
- },
1466
- });
1467
- assert.equal(unknown.isError, true);
1468
- const unknownBlocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(unknown.content);
1469
- const unknownFailure = z
1470
- .object({
1471
- contract: z.literal('ai-delivery.issue@1'),
1472
- failures: z.array(z.object({ code: z.literal('field.unknown'), field: z.string(), fixHint: z.string() })),
1473
- })
1474
- .parse(JSON.parse(unknownBlocks[0].text));
1475
- assert.deepEqual(unknownFailure.failures.map((f) => f.field).sort(), [
1476
- 'acceptanceCriteria.0',
1477
- 'context',
1478
- 'issue',
1479
- ]);
1480
- assert.ok(unknownFailure.failures.every((f) => f.fixHint.length > 10));
1481
- assert.doesNotMatch(unknownBlocks[0].text, /unexpectedField|Nested field|Unknown criterion/u, 'Diagnostics do not echo untrusted keys or values.');
1482
- }
1483
- const foreign = await client.callTool({ name: 'issue_create', arguments: { ...ready(), repo: 'other/widget' } });
1484
- assert.equal(foreign.isError, true);
1485
- assert.match(JSON.stringify(foreign.content), /repository selectors disagree/u);
1680
+ );
1486
1681
  }
1487
- finally {
1488
- await client.close();
1489
- assert.equal(closeObserved, true, 'SDK spawned-child close event was actually observed');
1490
- rmSync(root, { recursive: true, force: true });
1491
- console.info(JSON.stringify({
1492
- fixture: 'issue68-compiled-stdio',
1493
- spawnedPid,
1494
- childCloseObserved: closeObserved,
1495
- syntheticRootRemoved: true,
1496
- }));
1497
- }
1498
- });
1499
- test('intake skill example is Ready and every CLI line has actual required options and an explicit identity', () => {
1500
- const skill = readFileSync(resolve('plugins/ai-delivery/skills/intake-create/SKILL.md'), 'utf8');
1682
+ }
1683
+ );
1684
+ test(
1685
+ "intake skill example is Ready and every CLI line has actual required options and an explicit identity",
1686
+ { tags: ["release"] },
1687
+ () => {
1688
+ const skill = readFileSync(resolve("plugins/ai-delivery/skills/intake-create/SKILL.md"), "utf8");
1501
1689
  const examples = [...skill.matchAll(/```json\n([\s\S]*?)\n```/gu)].map((match) => {
1502
- const json = match[1] ?? '';
1503
- return { json, value: JSON.parse(json) };
1690
+ const json2 = match[1] ?? "";
1691
+ return { json: json2, value: JSON.parse(json2) };
1504
1692
  });
1505
- const readTool = getAiDeliveryMcpTool('issue_info');
1506
- assert.ok(readTool?.name === 'issue_info');
1693
+ const readTool = getAiDeliveryMcpTool("issue_info");
1694
+ assert.ok(readTool?.name === "issue_info");
1507
1695
  const readSchema = readTool.inputSchema;
1508
1696
  for (const example of examples) {
1509
- assert.ok(ReadyIssue.safeParse(example.value).success || readSchema.safeParse(example.value).success, 'each documented JSON example must satisfy its supported contract');
1697
+ assert.ok(
1698
+ ReadyIssue.safeParse(example.value).success || readSchema.safeParse(example.value).success,
1699
+ "each documented JSON example must satisfy its supported contract"
1700
+ );
1510
1701
  }
1511
1702
  const readExample = examples.find((example) => readSchema.safeParse(example.value).success);
1512
- assert.ok(readExample, 'the read-first example must use the actual MCP schema');
1703
+ assert.ok(readExample, "the read-first example must use the actual MCP schema");
1513
1704
  const readArguments = readSchema.parse(readExample.value);
1514
- assert.equal(readArguments.repo, 'example/widget');
1705
+ assert.equal(readArguments.repo, "example/widget");
1515
1706
  assert.equal(readArguments.issueNumber, 17);
1516
1707
  const createExample = examples.find((example) => ReadyIssue.safeParse(example.value).success);
1517
- assert.ok(createExample, 'the creation example must remain Ready');
1708
+ assert.ok(createExample, "the creation example must remain Ready");
1518
1709
  const json = createExample.json;
1519
- const root = mkdtempSync(join(tmpdir(), 'intake-cli-'));
1710
+ const root = mkdtempSync(join(tmpdir(), "intake-cli-"));
1520
1711
  try {
1521
- const fields = join(root, 'issue.json');
1522
- writeFileSync(fields, json);
1523
- for (const line of skill.split('\n').filter((line) => line.startsWith('ai-delivery '))) {
1524
- assert.match(line, /--identity host-author/u);
1525
- assert.match(line, /--repo example\/widget/u);
1526
- const argv = (line.match(/'[^']*'|[^\s]+/gu) ?? [])
1527
- .slice(1)
1528
- .map((token) => token.replace(/^'|'$/gu, ''))
1529
- .map((token) => token.replace('/owned/issue.json', fields));
1530
- const command = argv.find((token) => ['create', 'update', 'info', 'ready:check', 'start'].includes(token));
1531
- assert.ok(command);
1532
- assert.ok(argv.includes(command === 'create' ? '--title' : '--issue'));
1533
- const result = spawnSync(process.execPath, [resolve('dist/cli.js'), ...argv], {
1534
- cwd: root,
1535
- env: {
1536
- PATH: process.env.PATH ?? '',
1537
- HOME: root,
1538
- AI_DELIVERY_CONFIG: join(root, 'missing-config.json'),
1539
- LANG: 'en_US.UTF-8',
1540
- },
1541
- encoding: 'utf8',
1542
- });
1543
- assert.notEqual(result.status, 0);
1544
- assert.doesNotMatch(result.stderr, /unknown option|unknown command|required option/u);
1545
- assert.match(result.stderr, /missing-config|ENOENT|identity|configuration|config/iu);
1546
- }
1547
- const missing = spawnSync(process.execPath, [resolve('dist/cli.js'), '--identity', 'host-author', '--repo', 'example/widget', 'create'], { cwd: root, env: { HOME: root, PATH: process.env.PATH ?? '' }, encoding: 'utf8' });
1548
- assert.match(missing.stderr, /required option.*--title/u);
1549
- assert.ok(execFileSync(process.execPath, [resolve('dist/cli.js'), '--help'], {
1550
- env: { HOME: root, PATH: process.env.PATH ?? '' },
1551
- encoding: 'utf8',
1552
- }).includes('create'));
1553
- }
1554
- finally {
1555
- rmSync(root, { recursive: true, force: true });
1712
+ const fields = join(root, "issue.json");
1713
+ writeFileSync(fields, json);
1714
+ for (const line of skill.split("\n").filter((line2) => line2.startsWith("ai-delivery "))) {
1715
+ assert.match(line, /--identity host-author/u);
1716
+ assert.match(line, /--repo example\/widget/u);
1717
+ const argv = (line.match(/'[^']*'|[^\s]+/gu) ?? []).slice(1).map((token) => token.replace(/^'|'$/gu, "")).map((token) => token.replace("/owned/issue.json", fields));
1718
+ const command = argv.find((token) => ["create", "update", "info", "ready:check", "start"].includes(token));
1719
+ assert.ok(command);
1720
+ assert.ok(argv.includes(command === "create" ? "--title" : "--issue"));
1721
+ const result = spawnSync(process.execPath, [resolve("dist/cli.js"), ...argv], {
1722
+ cwd: root,
1723
+ env: {
1724
+ PATH: process.env.PATH ?? "",
1725
+ HOME: root,
1726
+ AI_DELIVERY_CONFIG: join(root, "missing-config.json"),
1727
+ LANG: "en_US.UTF-8"
1728
+ },
1729
+ encoding: "utf8"
1730
+ });
1731
+ assert.notEqual(result.status, 0);
1732
+ assert.doesNotMatch(result.stderr, /unknown option|unknown command|required option/u);
1733
+ assert.match(result.stderr, /missing-config|ENOENT|identity|configuration|config/iu);
1734
+ }
1735
+ const missing = spawnSync(
1736
+ process.execPath,
1737
+ [resolve("dist/cli.js"), "--identity", "host-author", "--repo", "example/widget", "create"],
1738
+ { cwd: root, env: { HOME: root, PATH: process.env.PATH ?? "" }, encoding: "utf8" }
1739
+ );
1740
+ assert.match(missing.stderr, /required option.*--title/u);
1741
+ assert.ok(
1742
+ execFileSync(process.execPath, [resolve("dist/cli.js"), "--help"], {
1743
+ env: { HOME: root, PATH: process.env.PATH ?? "" },
1744
+ encoding: "utf8"
1745
+ }).includes("create")
1746
+ );
1747
+ } finally {
1748
+ rmSync(root, { recursive: true, force: true });
1556
1749
  }
1557
1750
  assert.ok(skill.includes(ISSUE_BODY_MARKER));
1558
- assert.ok(!skill.includes('ai-delivery develop'));
1751
+ assert.ok(!skill.includes("ai-delivery develop"));
1752
+ }
1753
+ );
1754
+ test("explicit start changes Todo to the configured In Progress option and preserves unrelated items", async () => {
1755
+ const f = fixture();
1756
+ const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1757
+ assert.ok("branch" in result);
1758
+ assert.equal(f.getStatus(), "Active");
1759
+ assert.equal(f.statusWrites.length, 1);
1760
+ assert.deepEqual(f.statusWrites[0], {
1761
+ projectId: "PROJECT",
1762
+ itemId: "ITEM17",
1763
+ fieldId: "STATUS",
1764
+ optionId: "ACTIVE"
1765
+ });
1766
+ assert.equal(f.comments.length, 1);
1767
+ const retry = await startTrackedIssue(f.context, { issueNumber: 17 });
1768
+ assert.ok("reused" in retry && retry.reused);
1769
+ assert.equal(f.branchWrites.length, 1);
1770
+ assert.equal(f.statusWrites.length, 1);
1771
+ assert.equal(f.comments.length, 1);
1559
1772
  });
1560
- test('explicit start changes Todo to the configured In Progress option and preserves unrelated items', async () => {
1773
+ test("explicit start adds missing membership only for its exact issue and accepts already active status", async () => {
1774
+ for (const member of [true, false]) {
1561
1775
  const f = fixture();
1562
- const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1563
- assert.ok('branch' in result);
1564
- assert.equal(f.getStatus(), 'Active');
1565
- assert.equal(f.statusWrites.length, 1);
1566
- assert.deepEqual(f.statusWrites[0], {
1567
- projectId: 'PROJECT',
1568
- itemId: 'ITEM17',
1569
- fieldId: 'STATUS',
1570
- optionId: 'ACTIVE',
1571
- });
1572
- assert.equal(f.comments.length, 1);
1573
- const retry = await startTrackedIssue(f.context, { issueNumber: 17 });
1574
- assert.ok('reused' in retry && retry.reused);
1575
- assert.equal(f.branchWrites.length, 1);
1576
- assert.equal(f.statusWrites.length, 1);
1577
- assert.equal(f.comments.length, 1);
1578
- });
1579
- test('explicit start adds missing membership only for its exact issue and accepts already active status', async () => {
1580
- for (const member of [true, false]) {
1581
- const f = fixture();
1582
- f.controls.projectMember = member;
1583
- if (member)
1584
- f.setStatus('Active');
1585
- assert.ok('branch' in (await startTrackedIssue(f.context, { issueNumber: 17 })));
1586
- assert.equal(f.getStatus(), 'Active');
1587
- assert.equal(f.membershipWrites.length, member ? 0 : 1);
1588
- assert.equal(f.statusWrites.length, member ? 0 : 1);
1589
- }
1776
+ f.controls.projectMember = member;
1777
+ if (member) f.setStatus("Active");
1778
+ assert.ok("branch" in await startTrackedIssue(f.context, { issueNumber: 17 }));
1779
+ assert.equal(f.getStatus(), "Active");
1780
+ assert.equal(f.membershipWrites.length, member ? 0 : 1);
1781
+ assert.equal(f.statusWrites.length, member ? 0 : 1);
1782
+ }
1590
1783
  });
1591
- test.each(['before', 'after', 'readback'])('existing start returns known-issue recovery for Project %s failure', async (failure) => {
1784
+ test.each(["before", "after", "readback"])(
1785
+ "existing start returns known-issue recovery for Project %s failure",
1786
+ async (failure) => {
1592
1787
  const f = fixture();
1593
1788
  f.controls.projectFailure = failure;
1594
1789
  const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1595
- if (!('status' in result))
1596
- assert.fail('Project failure must not report successful start');
1597
- assert.equal(result.status, 'start-incomplete');
1598
- assert.equal(result.failure.phase, 'project-status');
1790
+ if (!("status" in result)) assert.fail("Project failure must not report successful start");
1791
+ assert.equal(result.status, "start-incomplete");
1792
+ assert.equal(result.failure.phase, "project-status");
1599
1793
  assert.equal(result.safeResume.arguments.issueNumber, 17);
1600
- assert.equal(result.safeResume.arguments.repo, 'example/widget');
1601
- assert.equal(result.safeResume.arguments.branch, 'issue/17');
1794
+ assert.equal(result.safeResume.arguments.repo, "example/widget");
1795
+ assert.equal(result.safeResume.arguments.branch, "issue/17");
1602
1796
  assert.equal(f.comments.length, 0);
1603
- f.controls.projectFailure = '';
1604
- const resumed = await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments));
1605
- assert.ok('reused' in resumed && resumed.reused);
1606
- assert.equal(f.getStatus(), 'Active');
1797
+ f.controls.projectFailure = "";
1798
+ const resumed = await startTrackedIssue(
1799
+ f.context,
1800
+ getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
1801
+ );
1802
+ assert.ok("reused" in resumed && resumed.reused);
1803
+ assert.equal(f.getStatus(), "Active");
1607
1804
  assert.equal(f.branchWrites.length, 1);
1608
1805
  assert.equal(f.comments.length, 1);
1609
1806
  assert.equal(f.writes.length, 0);
1610
- assert.equal(f.statusWrites.length, failure === 'before' ? 2 : 1);
1611
- });
1612
- test.each(['branch', 'journal'])('existing start reconciles a lost %s response without duplicate mutations', async (failure) => {
1807
+ assert.equal(f.statusWrites.length, failure === "before" ? 2 : 1);
1808
+ }
1809
+ );
1810
+ test.each(["branch", "journal"])(
1811
+ "existing start reconciles a lost %s response without duplicate mutations",
1812
+ async (failure) => {
1613
1813
  const f = fixture();
1614
- f.controls.branchFailure = failure === 'branch';
1615
- f.controls.journalFailure = failure === 'journal';
1814
+ f.controls.branchFailure = failure === "branch";
1815
+ f.controls.journalFailure = failure === "journal";
1616
1816
  const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1617
- if (!('status' in result))
1618
- assert.fail('An uncertain start must retain recovery');
1619
- assert.equal(result.status, 'start-incomplete');
1817
+ if (!("status" in result)) assert.fail("An uncertain start must retain recovery");
1818
+ assert.equal(result.status, "start-incomplete");
1620
1819
  f.controls.branchFailure = false;
1621
1820
  f.controls.journalFailure = false;
1622
- assert.ok('reused' in (await startTrackedIssue(f.context, result.safeResume.arguments)));
1821
+ assert.ok("reused" in await startTrackedIssue(f.context, result.safeResume.arguments));
1623
1822
  assert.equal(f.branchWrites.length, 1);
1624
1823
  assert.equal(f.comments.length, 1);
1625
- assert.equal(f.getStatus(), 'Active');
1626
- });
1627
- test('created start retains its exact issue recovery when Project synchronization fails', async () => {
1628
- const f = fixture();
1629
- f.controls.created = false;
1630
- f.controls.projectFailure = 'before';
1631
- const request = {
1632
- title: ready().title,
1633
- body: renderIssueBody(ready()),
1634
- issueType: 'Task',
1635
- points: 2,
1636
- requestId: 'project-recovery',
1637
- };
1638
- const result = await startTrackedIssue(f.context, request);
1639
- if (!('status' in result))
1640
- assert.fail('Expected created recovery');
1641
- assert.equal(result.status, 'created-not-started');
1642
- assert.equal(result.failure.phase, 'project-status');
1643
- f.controls.projectFailure = '';
1644
- assert.ok('reused' in (await startTrackedIssue(f.context, result.safeResume.arguments)));
1645
- assert.equal(f.branchWrites.length, 1);
1646
- assert.equal(f.comments.length, 1);
1647
- assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
1648
- assert.equal(f.getStatus(), 'Active');
1824
+ assert.equal(f.getStatus(), "Active");
1825
+ }
1826
+ );
1827
+ test("created start retains its exact issue recovery when Project synchronization fails", async () => {
1828
+ const f = fixture();
1829
+ f.controls.created = false;
1830
+ f.controls.projectFailure = "before";
1831
+ const request = {
1832
+ title: ready().title,
1833
+ body: renderIssueBody(ready()),
1834
+ issueType: "Task",
1835
+ points: 2,
1836
+ requestId: "project-recovery"
1837
+ };
1838
+ const result = await startTrackedIssue(f.context, request);
1839
+ if (!("status" in result)) assert.fail("Expected created recovery");
1840
+ assert.equal(result.status, "created-not-started");
1841
+ assert.equal(result.failure.phase, "project-status");
1842
+ f.controls.projectFailure = "";
1843
+ assert.ok("reused" in await startTrackedIssue(f.context, result.safeResume.arguments));
1844
+ assert.equal(f.branchWrites.length, 1);
1845
+ assert.equal(f.comments.length, 1);
1846
+ assert.equal(f.writes.filter((write) => !("issue_number" in write)).length, 1);
1847
+ assert.equal(f.getStatus(), "Active");
1649
1848
  });
1650
- test.each(['closed', 'blocked', 'parked', 'archived'])('start recovery refuses current %s truth before Project or journal writes', async (state) => {
1849
+ test.each(["closed", "blocked", "parked", "archived"])(
1850
+ "start recovery refuses current %s truth before Project or journal writes",
1851
+ async (state) => {
1651
1852
  const f = fixture();
1652
1853
  f.controls.branchFailure = true;
1653
1854
  const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1654
- if (result.status !== 'start-incomplete')
1655
- assert.fail('Expected recovery');
1855
+ if (result.status !== "start-incomplete") assert.fail("Expected recovery");
1656
1856
  f.controls.branchFailure = false;
1657
- if (state === 'closed')
1658
- f.live.state = 'closed';
1659
- if (state === 'blocked')
1660
- f.controls.blockers = true;
1661
- if (state === 'parked')
1662
- f.live.body = renderIssueBody({ ...ready(), draft: true });
1663
- if (state === 'archived')
1664
- f.controls.projectArchived = true;
1857
+ if (state === "closed") f.live.state = "closed";
1858
+ if (state === "blocked") f.controls.blockers = true;
1859
+ if (state === "parked") f.live.body = renderIssueBody({ ...ready(), draft: true });
1860
+ if (state === "archived") f.controls.projectArchived = true;
1665
1861
  const retry = await startTrackedIssue(f.context, result.safeResume.arguments).catch((error) => {
1666
- assert.ok(error instanceof Error);
1667
- return undefined;
1862
+ assert.ok(error instanceof Error);
1863
+ return void 0;
1668
1864
  });
1669
- assert.ok(retry === undefined || 'status' in retry, 'Current refusal must not report success');
1865
+ assert.ok(retry === void 0 || "status" in retry, "Current refusal must not report success");
1670
1866
  assert.equal(f.branchWrites.length, 1);
1671
1867
  assert.equal(f.statusWrites.length, 0);
1672
1868
  assert.equal(f.comments.length, 0);
1673
- });
1674
- test.each(['closeAfterBranch', 'blockAfterBranch'])('start rechecks live eligibility after %s before changing the board', async (control) => {
1869
+ }
1870
+ );
1871
+ test.each(["closeAfterBranch", "blockAfterBranch"])(
1872
+ "start rechecks live eligibility after %s before changing the board",
1873
+ async (control) => {
1675
1874
  const f = fixture();
1676
1875
  f.controls[control] = true;
1677
1876
  const result = await startTrackedIssue(f.context, { issueNumber: 17 });
1678
- assert.ok('status' in result);
1877
+ assert.ok("status" in result);
1679
1878
  assert.equal(f.statusWrites.length, 0);
1680
1879
  assert.equal(f.comments.length, 0);
1681
- });
1880
+ }
1881
+ );
1682
1882
  async function bindStartFixture(f) {
1683
- vi.stubEnv('AI_DELIVERY_CONFIG', '/synthetic-unconfigured-delivery-settings.json');
1684
- const settings = await import('./config/deliveryConfig.js');
1685
- const issues = await import('./issue.js');
1686
- vi.spyOn(settings, 'loadDeliverySettings').mockResolvedValue({
1687
- roles: { author: { identity: 'author', authSource: 'personal' }, reviewer: { identity: 'reviewer' } },
1688
- });
1689
- vi.spyOn(issues, 'loadDeliveryContext').mockResolvedValue(f.context);
1883
+ vi.stubEnv("AI_DELIVERY_CONFIG", "/synthetic-unconfigured-delivery-settings.json");
1884
+ const settings = await import("./config/deliveryConfig.js");
1885
+ const issues = await import("./issue.js");
1886
+ vi.spyOn(settings, "loadDeliverySettings").mockResolvedValue({
1887
+ roles: { author: { identity: "author", authSource: "personal" }, reviewer: { identity: "reviewer" } }
1888
+ });
1889
+ vi.spyOn(issues, "loadDeliveryContext").mockResolvedValue(f.context);
1690
1890
  }
1691
- test.each(['flags', 'file', 'undefer'])('CLI update %s changes explicit deferral through current dispatch', async (mode) => {
1891
+ test.each(["flags", "file", "undefer"])(
1892
+ "CLI update %s changes explicit deferral through current dispatch",
1893
+ async (mode) => {
1692
1894
  vi.resetModules();
1693
1895
  const f = fixture();
1694
- if (mode === 'undefer')
1695
- f.live.body = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: 'Prior condition' } }));
1896
+ if (mode === "undefer")
1897
+ f.live.body = renderIssueBody(IssueFields.parse({ ...ready(), deferral: { trigger: "Prior condition" } }));
1696
1898
  await bindStartFixture(f);
1697
- const root = mkdtempSync(join(tmpdir(), 'deferral-cli-'));
1698
- const fieldsFile = join(root, 'patch.json');
1699
- const condition = { until: '2020-01-01', trigger: 'CLI upstream condition' };
1899
+ const root = mkdtempSync(join(tmpdir(), "deferral-cli-"));
1900
+ const fieldsFile = join(root, "patch.json");
1901
+ const condition = { until: "2020-01-01", trigger: "CLI upstream condition" };
1700
1902
  writeFileSync(fieldsFile, JSON.stringify({ defer: condition }));
1701
1903
  const argv = process.argv;
1702
1904
  const exitCode = process.exitCode;
1703
- let stdout = '';
1704
- let complete = () => { };
1705
- const output = new Promise((resolve) => {
1706
- complete = resolve;
1905
+ let stdout = "";
1906
+ let complete = () => {
1907
+ };
1908
+ const output = new Promise((resolve2) => {
1909
+ complete = resolve2;
1707
1910
  });
1708
- vi.spyOn(process.stdout, 'write').mockImplementation((value) => {
1709
- stdout += String(value);
1710
- if (String(value).startsWith('{'))
1711
- complete();
1712
- return true;
1911
+ vi.spyOn(process.stdout, "write").mockImplementation((value) => {
1912
+ stdout += String(value);
1913
+ if (String(value).startsWith("{")) complete();
1914
+ return true;
1713
1915
  });
1714
1916
  try {
1715
- process.exitCode = undefined;
1716
- process.argv = [
1717
- process.execPath,
1718
- 'ai-delivery',
1719
- '--repo',
1720
- 'example/widget',
1721
- 'update',
1722
- '--issue',
1723
- '17',
1724
- ...(mode === 'undefer'
1725
- ? ['--undefer']
1726
- : mode === 'file'
1727
- ? ['--fields-file', fieldsFile]
1728
- : ['--defer-until', condition.until, '--defer-trigger', condition.trigger]),
1729
- ];
1730
- await import('./cli.js');
1731
- await output;
1732
- const result = z.object({ deferred: z.record(z.string(), z.string()).nullable() }).parse(JSON.parse(stdout));
1733
- assert.deepEqual(result.deferred, mode === 'undefer' ? null : condition);
1734
- assert.equal(f.writes.length, 1);
1735
- assert.equal(process.exitCode, undefined);
1736
- }
1737
- finally {
1738
- process.argv = argv;
1739
- process.exitCode = exitCode;
1740
- rmSync(root, { recursive: true, force: true });
1741
- }
1742
- });
1743
- test('MCP explicit start returns Project recovery and reuses the exact branch on retry', async () => {
1744
- const f = fixture();
1745
- await bindStartFixture(f);
1746
- f.controls.projectFailure = 'after';
1747
- const server = (await import('./mcp/index.js')).createAiDeliveryMcpServer({ repoRoot: '/unrelated' });
1748
- const client = new Client({ name: 'fictional-start-project', version: '1.0.0' });
1749
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1750
- try {
1751
- await server.connect(serverTransport);
1752
- await client.connect(clientTransport);
1753
- const call = async (arguments_) => {
1754
- const reply = await client.callTool({ name: 'issue_start', arguments: arguments_ });
1755
- assert.equal(reply.isError, undefined);
1756
- return JSON.parse(z.object({ content: z.array(z.object({ type: z.literal('text'), text: z.string() })) }).parse(reply).content[0]
1757
- .text);
1758
- };
1759
- const interrupted = await call({ repo: 'example/widget', issueNumber: 17 });
1760
- assert.equal(interrupted.status, 'start-incomplete');
1761
- assert.ok(interrupted.safeResume);
1762
- assert.equal(f.comments.length, 0);
1763
- f.controls.projectFailure = '';
1764
- const result = await call(interrupted.safeResume.arguments);
1765
- assert.equal(result.branch, 'issue/17');
1766
- assert.equal(result.issueNumber, 17);
1767
- assert.equal(f.getStatus(), 'Active');
1768
- assert.equal(f.statusWrites.length, 1);
1769
- assert.equal(f.branchWrites.length, 1);
1770
- assert.equal(f.comments.length, 1);
1771
- }
1772
- finally {
1773
- await client.close();
1774
- await server.close();
1917
+ process.exitCode = void 0;
1918
+ process.argv = [
1919
+ process.execPath,
1920
+ "ai-delivery",
1921
+ "--repo",
1922
+ "example/widget",
1923
+ "update",
1924
+ "--issue",
1925
+ "17",
1926
+ ...mode === "undefer" ? ["--undefer"] : mode === "file" ? ["--fields-file", fieldsFile] : ["--defer-until", condition.until, "--defer-trigger", condition.trigger]
1927
+ ];
1928
+ await import("./cli.js");
1929
+ await output;
1930
+ const result = z.object({ deferred: z.record(z.string(), z.string()).nullable() }).parse(JSON.parse(stdout));
1931
+ assert.deepEqual(result.deferred, mode === "undefer" ? null : condition);
1932
+ assert.equal(f.writes.length, 1);
1933
+ assert.equal(process.exitCode, void 0);
1934
+ } finally {
1935
+ process.argv = argv;
1936
+ process.exitCode = exitCode;
1937
+ rmSync(root, { recursive: true, force: true });
1775
1938
  }
1939
+ }
1940
+ );
1941
+ test("MCP explicit start returns Project recovery and reuses the exact branch on retry", async () => {
1942
+ const f = fixture();
1943
+ await bindStartFixture(f);
1944
+ f.controls.projectFailure = "after";
1945
+ const server = (await import("./mcp/index.js")).createAiDeliveryMcpServer({ repoRoot: "/unrelated" });
1946
+ const client = new Client({ name: "fictional-start-project", version: "1.0.0" });
1947
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1948
+ try {
1949
+ await server.connect(serverTransport);
1950
+ await client.connect(clientTransport);
1951
+ const call = async (arguments_) => {
1952
+ const reply = await client.callTool({ name: "issue_start", arguments: arguments_ });
1953
+ assert.equal(reply.isError, void 0);
1954
+ return JSON.parse(
1955
+ z.object({ content: z.array(z.object({ type: z.literal("text"), text: z.string() })) }).parse(reply).content[0].text
1956
+ );
1957
+ };
1958
+ const interrupted = await call({ repo: "example/widget", issueNumber: 17 });
1959
+ assert.equal(interrupted.status, "start-incomplete");
1960
+ assert.ok(interrupted.safeResume);
1961
+ assert.equal(f.comments.length, 0);
1962
+ f.controls.projectFailure = "";
1963
+ const result = await call(interrupted.safeResume.arguments);
1964
+ assert.equal(result.branch, "issue/17");
1965
+ assert.equal(result.issueNumber, 17);
1966
+ assert.equal(f.getStatus(), "Active");
1967
+ assert.equal(f.statusWrites.length, 1);
1968
+ assert.equal(f.branchWrites.length, 1);
1969
+ assert.equal(f.comments.length, 1);
1970
+ } finally {
1971
+ await client.close();
1972
+ await server.close();
1973
+ }
1776
1974
  });
1777
- test('current MCP update/read/list/start routes enforce deferral and recorded WIP capacity override', async () => {
1778
- const f = fixture();
1779
- await bindStartFixture(f);
1780
- const server = (await import('./mcp/index.js')).createAiDeliveryMcpServer({ repoRoot: '/unrelated' });
1781
- const client = new Client({ name: 'synthetic-deferral-wip', version: '1.0.0' });
1782
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1783
- const call = async (name, args, error = false) => {
1784
- const result = await client.callTool({ name, arguments: { repo: 'example/widget', ...args } });
1785
- assert.equal(Boolean(result.isError), error, JSON.stringify(result.content));
1786
- const content = result.content;
1787
- const value = error ? content[0].text : JSON.parse(content[0].text);
1788
- return value;
1975
+ test("current MCP update/read/list/start routes enforce deferral and recorded WIP capacity override", async () => {
1976
+ const f = fixture();
1977
+ await bindStartFixture(f);
1978
+ const server = (await import("./mcp/index.js")).createAiDeliveryMcpServer({ repoRoot: "/unrelated" });
1979
+ const client = new Client({ name: "synthetic-deferral-wip", version: "1.0.0" });
1980
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
1981
+ const call = async (name, args, error = false) => {
1982
+ const result = await client.callTool({ name, arguments: { repo: "example/widget", ...args } });
1983
+ assert.equal(Boolean(result.isError), error, JSON.stringify(result.content));
1984
+ const content = result.content;
1985
+ const value = error ? content[0].text : JSON.parse(content[0].text);
1986
+ return value;
1987
+ };
1988
+ try {
1989
+ await server.connect(serverTransport);
1990
+ await client.connect(clientTransport);
1991
+ const condition = { until: "2020-01-01", trigger: "Upstream ships" };
1992
+ const readback = z.object({ deferred: z.record(z.string(), z.string()).nullable() });
1993
+ assert.deepEqual(
1994
+ readback.parse(await call("issue_update", { issueNumber: 17, defer: condition })).deferred,
1995
+ condition
1996
+ );
1997
+ assert.deepEqual(readback.parse(await call("issue_info", { issueNumber: 17 })).deferred, condition);
1998
+ assert.deepEqual(
1999
+ z.object({ issues: z.array(readback) }).parse(await call("issue_list", {})).issues[0].deferred,
2000
+ condition
2001
+ );
2002
+ assert.match(
2003
+ z.string().parse(await call("issue_start", { issueNumber: 17, overrideReason: "Capacity only." }, true)),
2004
+ /deferred/u
2005
+ );
2006
+ await call("issue_update", { issueNumber: 17, undefer: true });
2007
+ f.controls.capacityMode = true;
2008
+ f.live.labels = ["critical"];
2009
+ f.context.config = {
2010
+ ...f.context.config,
2011
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
1789
2012
  };
1790
- try {
1791
- await server.connect(serverTransport);
1792
- await client.connect(clientTransport);
1793
- const condition = { until: '2020-01-01', trigger: 'Upstream ships' };
1794
- const readback = z.object({ deferred: z.record(z.string(), z.string()).nullable() });
1795
- assert.deepEqual(readback.parse(await call('issue_update', { issueNumber: 17, defer: condition })).deferred, condition);
1796
- assert.deepEqual(readback.parse(await call('issue_info', { issueNumber: 17 })).deferred, condition);
1797
- assert.deepEqual(z.object({ issues: z.array(readback) }).parse(await call('issue_list', {})).issues[0].deferred, condition);
1798
- assert.match(z.string().parse(await call('issue_start', { issueNumber: 17, overrideReason: 'Capacity only.' }, true)), /deferred/u);
1799
- await call('issue_update', { issueNumber: 17, undefer: true });
1800
- f.controls.capacityMode = true;
1801
- f.live.labels = ['critical'];
1802
- f.context.config = {
1803
- ...f.context.config,
1804
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
1805
- };
1806
- assert.match(z.string().parse(await call('issue_start', { issueNumber: 17 }, true)), /WIP/u);
1807
- assert.equal(f.branchWrites.length, 0);
1808
- await call('issue_start', { issueNumber: 17, overrideReason: 'Explicit synthetic capacity exception.' });
1809
- assert.equal(f.getStatus(), 'Active');
1810
- assert.equal(f.comments.length, 2);
1811
- await call('issue_start', { issueNumber: 17 });
1812
- assert.equal(f.comments.length, 2);
1813
- }
1814
- finally {
1815
- await client.close();
1816
- await server.close();
1817
- }
2013
+ assert.match(z.string().parse(await call("issue_start", { issueNumber: 17 }, true)), /WIP/u);
2014
+ assert.equal(f.branchWrites.length, 0);
2015
+ await call("issue_start", { issueNumber: 17, overrideReason: "Explicit synthetic capacity exception." });
2016
+ assert.equal(f.getStatus(), "Active");
2017
+ assert.equal(f.comments.length, 2);
2018
+ await call("issue_start", { issueNumber: 17 });
2019
+ assert.equal(f.comments.length, 2);
2020
+ } finally {
2021
+ await client.close();
2022
+ await server.close();
2023
+ }
1818
2024
  });
1819
- test.each(['success', 'failure', 'capacity', 'deferred', 'capacity-override'])('CLI explicit start shares Project transition and %s output', async (mode) => {
2025
+ test.each(["success", "failure", "capacity", "deferred", "capacity-override"])(
2026
+ "CLI explicit start shares Project transition and %s output",
2027
+ async (mode) => {
1820
2028
  vi.resetModules();
1821
2029
  const f = fixture();
1822
2030
  await bindStartFixture(f);
1823
- if (mode === 'failure')
1824
- f.controls.projectFailure = 'before';
1825
- if (mode === 'deferred')
1826
- await updateIssue(f.context, { issueNumber: 17, defer: {} });
1827
- if (mode === 'capacity' || mode === 'capacity-override') {
1828
- f.controls.capacityMode = true;
1829
- f.live.labels = ['critical'];
1830
- f.context.config = {
1831
- ...f.context.config,
1832
- wipLimits: [{ repository: 'example/widget', name: 'Critical work', match: { label: 'critical' }, limit: 0 }],
1833
- };
2031
+ if (mode === "failure") f.controls.projectFailure = "before";
2032
+ if (mode === "deferred") await updateIssue(f.context, { issueNumber: 17, defer: {} });
2033
+ if (mode === "capacity" || mode === "capacity-override") {
2034
+ f.controls.capacityMode = true;
2035
+ f.live.labels = ["critical"];
2036
+ f.context.config = {
2037
+ ...f.context.config,
2038
+ wipLimits: [{ repository: "example/widget", name: "Critical work", match: { label: "critical" }, limit: 0 }]
2039
+ };
1834
2040
  }
1835
2041
  const argv = process.argv;
1836
2042
  const exitCode = process.exitCode;
1837
- let stdout = '';
1838
- let stderr = '';
1839
- let completed = () => { };
1840
- const output = new Promise((resolve) => {
1841
- completed = resolve;
2043
+ let stdout = "";
2044
+ let stderr = "";
2045
+ let completed = () => {
2046
+ };
2047
+ const output = new Promise((resolve2) => {
2048
+ completed = resolve2;
1842
2049
  });
1843
- vi.spyOn(process.stdout, 'write').mockImplementation((value) => {
1844
- stdout += String(value);
1845
- if (String(value).startsWith('{'))
1846
- completed();
1847
- return true;
2050
+ vi.spyOn(process.stdout, "write").mockImplementation((value) => {
2051
+ stdout += String(value);
2052
+ if (String(value).startsWith("{")) completed();
2053
+ return true;
1848
2054
  });
1849
- vi.spyOn(process.stderr, 'write').mockImplementation((value) => {
1850
- stderr += String(value);
1851
- completed();
1852
- return true;
2055
+ vi.spyOn(process.stderr, "write").mockImplementation((value) => {
2056
+ stderr += String(value);
2057
+ completed();
2058
+ return true;
1853
2059
  });
1854
2060
  try {
1855
- process.exitCode = undefined;
1856
- process.argv = [process.execPath, 'ai-delivery', '--repo', 'example/widget', 'start', '--issue', '17'];
1857
- if (mode === 'capacity-override')
1858
- process.argv.push('--override-reason', 'Explicit synthetic capacity exception.');
1859
- await import('./cli.js');
1860
- await output;
1861
- if (mode === 'deferred' || mode === 'capacity') {
1862
- assert.match(stderr, mode === 'deferred' ? /deferred/u : /WIP/u);
1863
- assert.equal(process.exitCode, 1);
1864
- assert.equal(f.branchWrites.length, 0);
1865
- assert.equal(f.statusWrites.filter((x) => x.optionId === 'ACTIVE').length, 0);
1866
- return;
1867
- }
1868
- const result = JSON.parse(stdout);
1869
- if (mode === 'failure') {
1870
- assert.equal(result.status, 'start-incomplete');
1871
- assert.equal(result.safeResume?.arguments.issueNumber, 17);
1872
- assert.equal(process.exitCode, 1);
1873
- assert.equal(f.getStatus(), 'Queued');
1874
- assert.equal(f.comments.length, 0);
1875
- }
1876
- else {
1877
- assert.equal(result.branch, 'issue/17');
1878
- assert.equal(process.exitCode, undefined);
1879
- assert.equal(f.getStatus(), 'Active');
1880
- assert.equal(f.comments.length, mode === 'capacity-override' ? 2 : 1);
1881
- }
1882
- assert.equal(f.branchWrites.length, 1);
1883
- assert.equal(f.statusWrites.length, 1);
1884
- }
1885
- finally {
1886
- process.argv = argv;
1887
- process.exitCode = exitCode;
2061
+ process.exitCode = void 0;
2062
+ process.argv = [process.execPath, "ai-delivery", "--repo", "example/widget", "start", "--issue", "17"];
2063
+ if (mode === "capacity-override")
2064
+ process.argv.push("--override-reason", "Explicit synthetic capacity exception.");
2065
+ await import("./cli.js");
2066
+ await output;
2067
+ if (mode === "deferred" || mode === "capacity") {
2068
+ assert.match(stderr, mode === "deferred" ? /deferred/u : /WIP/u);
2069
+ assert.equal(process.exitCode, 1);
2070
+ assert.equal(f.branchWrites.length, 0);
2071
+ assert.equal(f.statusWrites.filter((x) => x.optionId === "ACTIVE").length, 0);
2072
+ return;
2073
+ }
2074
+ const result = JSON.parse(stdout);
2075
+ if (mode === "failure") {
2076
+ assert.equal(result.status, "start-incomplete");
2077
+ assert.equal(result.safeResume?.arguments.issueNumber, 17);
2078
+ assert.equal(process.exitCode, 1);
2079
+ assert.equal(f.getStatus(), "Queued");
2080
+ assert.equal(f.comments.length, 0);
2081
+ } else {
2082
+ assert.equal(result.branch, "issue/17");
2083
+ assert.equal(process.exitCode, void 0);
2084
+ assert.equal(f.getStatus(), "Active");
2085
+ assert.equal(f.comments.length, mode === "capacity-override" ? 2 : 1);
2086
+ }
2087
+ assert.equal(f.branchWrites.length, 1);
2088
+ assert.equal(f.statusWrites.length, 1);
2089
+ } finally {
2090
+ process.argv = argv;
2091
+ process.exitCode = exitCode;
1888
2092
  }
2093
+ }
2094
+ );
2095
+ test("info and unrelated body edits never imply explicit activation", async () => {
2096
+ const f = fixture();
2097
+ const { issueInfo: issueInfo2 } = await import("./issue.js");
2098
+ await issueInfo2(f.context, 17);
2099
+ await updateIssue(f.context, {
2100
+ issueNumber: 17,
2101
+ outcome: "Reject invalid widgets while retaining deferred execution."
2102
+ });
2103
+ assert.equal(f.getStatus(), "Queued");
2104
+ assert.equal(f.statusWrites.length, 0);
2105
+ assert.equal(f.branchWrites.length, 0);
2106
+ assert.equal(f.comments.length, 0);
1889
2107
  });
1890
- test('info and unrelated body edits never imply explicit activation', async () => {
1891
- const f = fixture();
1892
- const { issueInfo } = await import('./issue.js');
1893
- await issueInfo(f.context, 17);
1894
- await updateIssue(f.context, {
1895
- issueNumber: 17,
1896
- outcome: 'Reject invalid widgets while retaining deferred execution.',
1897
- });
1898
- assert.equal(f.getStatus(), 'Queued');
1899
- assert.equal(f.statusWrites.length, 0);
1900
- assert.equal(f.branchWrites.length, 0);
1901
- assert.equal(f.comments.length, 0);
1902
- });
1903
- test.each(['project-status', 'journal'])('created recovery after %s preserves a subsequent native park', async (phase) => {
2108
+ test.each(["project-status", "journal"])(
2109
+ "created recovery after %s preserves a subsequent native park",
2110
+ async (phase) => {
1904
2111
  const f = fixture();
1905
2112
  f.controls.created = false;
1906
- f.controls.projectFailure = phase === 'project-status' ? 'before' : '';
1907
- f.controls.journalFailure = phase === 'journal';
2113
+ f.controls.projectFailure = phase === "project-status" ? "before" : "";
2114
+ f.controls.journalFailure = phase === "journal";
1908
2115
  const result = await startTrackedIssue(f.context, {
1909
- title: ready().title,
1910
- body: renderIssueBody(ready()),
1911
- issueType: 'Task',
1912
- points: 2,
1913
- requestId: 'parked-created-' + phase,
2116
+ title: ready().title,
2117
+ body: renderIssueBody(ready()),
2118
+ issueType: "Task",
2119
+ points: 2,
2120
+ requestId: "parked-created-" + phase
1914
2121
  });
1915
- if (result.status !== 'created-not-started')
1916
- assert.fail('Expected known-created recovery');
2122
+ if (result.status !== "created-not-started") assert.fail("Expected known-created recovery");
1917
2123
  assert.equal(result.failure.phase, phase);
1918
- f.controls.projectFailure = '';
2124
+ f.controls.projectFailure = "";
1919
2125
  f.controls.journalFailure = false;
1920
2126
  await updateIssue(f.context, { issueNumber: 17, park: true });
1921
2127
  const parkedBody = f.live.body;
1922
2128
  const writesBeforeRetry = f.writes.length;
1923
2129
  const statusWritesBeforeRetry = f.statusWrites.length;
1924
2130
  const commentsBeforeRetry = f.comments.length;
1925
- const retry = await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments)).catch((error) => {
1926
- assert.ok(error instanceof Error);
1927
- return undefined;
2131
+ const retry = await startTrackedIssue(
2132
+ f.context,
2133
+ getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
2134
+ ).catch((error) => {
2135
+ assert.ok(error instanceof Error);
2136
+ return void 0;
1928
2137
  });
1929
2138
  assert.equal(f.live.body, parkedBody);
1930
2139
  assert.equal(parseIssueBody(f.live.body, { title: f.live.title }).issue.draft, true);
1931
- assert.equal(f.getStatus(), 'Queued');
1932
- assert.ok(retry === undefined || retry.status !== undefined, 'Parked recovery must not succeed');
2140
+ assert.equal(f.getStatus(), "Queued");
2141
+ assert.ok(retry === void 0 || retry.status !== void 0, "Parked recovery must not succeed");
1933
2142
  assert.equal(f.writes.length, writesBeforeRetry);
1934
2143
  assert.equal(f.statusWrites.length, statusWritesBeforeRetry);
1935
2144
  assert.equal(f.comments.length, commentsBeforeRetry);
1936
2145
  assert.equal(f.branchWrites.length, 1);
2146
+ }
2147
+ );
2148
+ test("created post-tracking recovery preserves later ready content without replaying tracking writes", async () => {
2149
+ const f = fixture();
2150
+ f.controls.created = false;
2151
+ f.controls.projectFailure = "before";
2152
+ const result = await startTrackedIssue(f.context, {
2153
+ title: ready().title,
2154
+ body: renderIssueBody(ready()),
2155
+ issueType: "Task",
2156
+ points: 2,
2157
+ requestId: "edited-created-recovery"
2158
+ });
2159
+ if (result.status !== "created-not-started") assert.fail("Expected known-created recovery");
2160
+ f.controls.projectFailure = "";
2161
+ await updateIssue(f.context, { issueNumber: 17, outcome: "Deliver the revised current acceptance evidence." });
2162
+ const revised = f.live.body;
2163
+ const writes = f.writes.length;
2164
+ assert.ok(
2165
+ "reused" in await startTrackedIssue(
2166
+ f.context,
2167
+ getAiDeliveryMcpTool("issue_start").inputSchema.parse(result.safeResume.arguments)
2168
+ )
2169
+ );
2170
+ assert.equal(f.live.body, revised);
2171
+ assert.equal(f.writes.length, writes);
2172
+ assert.equal(f.branchWrites.length, 1);
2173
+ assert.equal(f.getStatus(), "Active");
1937
2174
  });
1938
- test('created post-tracking recovery preserves later ready content without replaying tracking writes', async () => {
1939
- const f = fixture();
1940
- f.controls.created = false;
1941
- f.controls.projectFailure = 'before';
1942
- const result = await startTrackedIssue(f.context, {
1943
- title: ready().title,
1944
- body: renderIssueBody(ready()),
1945
- issueType: 'Task',
1946
- points: 2,
1947
- requestId: 'edited-created-recovery',
1948
- });
1949
- if (result.status !== 'created-not-started')
1950
- assert.fail('Expected known-created recovery');
1951
- f.controls.projectFailure = '';
1952
- await updateIssue(f.context, { issueNumber: 17, outcome: 'Deliver the revised current acceptance evidence.' });
1953
- const revised = f.live.body;
1954
- const writes = f.writes.length;
1955
- assert.ok('reused' in
1956
- (await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments))));
1957
- assert.equal(f.live.body, revised);
1958
- assert.equal(f.writes.length, writes);
1959
- assert.equal(f.branchWrites.length, 1);
1960
- assert.equal(f.getStatus(), 'Active');
1961
- });
1962
- //# sourceMappingURL=issueIntake.test.js.map
2175
+ //# sourceMappingURL=issueIntake.test.js.map