@aviaratech/ai-delivery 0.3.35 → 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 (297) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -554
  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 +1651 -1590
  9. package/dist/boardReconcile.test.js.map +7 -1
  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 +402 -515
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -45
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +424 -369
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +288 -14
  22. package/dist/config/deliveryConfig.js +472 -390
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +773 -649
  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 -479
  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.js +649 -0
  53. package/dist/deliveryBoard.test.js.map +7 -0
  54. package/dist/deliveryHealth.test.js +179 -155
  55. package/dist/deliveryHealth.test.js.map +7 -1
  56. package/dist/dependencyCompatibility.test.js +154 -140
  57. package/dist/dependencyCompatibility.test.js.map +7 -1
  58. package/dist/directoryIndependent.test.js +417 -383
  59. package/dist/directoryIndependent.test.js.map +7 -1
  60. package/dist/dispatch.d.ts +16 -11
  61. package/dist/dispatch.js +329 -353
  62. package/dist/dispatch.js.map +7 -1
  63. package/dist/errors.d.ts +3 -3
  64. package/dist/errors.js +103 -96
  65. package/dist/errors.js.map +7 -1
  66. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  67. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  68. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  69. package/dist/fixtures/discovery.d.ts +59 -19
  70. package/dist/fixtures/discovery.js +96 -90
  71. package/dist/fixtures/discovery.js.map +7 -1
  72. package/dist/fixtures/inertEntrypointChild.js +57 -56
  73. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  74. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  75. package/dist/fixtures/inertEntrypoints.js +321 -276
  76. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  77. package/dist/fixtures/inertTarget.d.ts +78 -7
  78. package/dist/fixtures/inertTarget.js +769 -691
  79. package/dist/fixtures/inertTarget.js.map +7 -1
  80. package/dist/fixtures/issue63.d.ts +4 -3
  81. package/dist/fixtures/issue63.js +260 -274
  82. package/dist/fixtures/issue63.js.map +7 -1
  83. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  84. package/dist/fixtures/issueProjectItems.js +15 -0
  85. package/dist/fixtures/issueProjectItems.js.map +7 -0
  86. package/dist/fixtures/readView.d.ts +120 -0
  87. package/dist/fixtures/readView.js +172 -0
  88. package/dist/fixtures/readView.js.map +7 -0
  89. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  90. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  91. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  92. package/dist/genericCompatibility.test.js +64 -55
  93. package/dist/genericCompatibility.test.js.map +7 -1
  94. package/dist/git.js +73 -67
  95. package/dist/git.js.map +7 -1
  96. package/dist/gitProcess.d.ts +1 -1
  97. package/dist/gitProcess.js +58 -53
  98. package/dist/gitProcess.js.map +7 -1
  99. package/dist/github/client.d.ts +2 -2
  100. package/dist/github/client.js +484 -379
  101. package/dist/github/client.js.map +7 -1
  102. package/dist/github/commandIdentityPolicy.js +44 -52
  103. package/dist/github/commandIdentityPolicy.js.map +7 -1
  104. package/dist/github/discovery.d.ts +1 -0
  105. package/dist/github/discovery.js +197 -215
  106. package/dist/github/discovery.js.map +7 -1
  107. package/dist/github/discovery.test.js +223 -177
  108. package/dist/github/discovery.test.js.map +7 -1
  109. package/dist/github/issueHistory.d.ts +2 -2
  110. package/dist/github/issueHistory.js +117 -125
  111. package/dist/github/issueHistory.js.map +7 -1
  112. package/dist/github/machineAuth.d.ts +1 -1
  113. package/dist/github/machineAuth.js +126 -117
  114. package/dist/github/machineAuth.js.map +7 -1
  115. package/dist/github/machineAuth.test.js +755 -639
  116. package/dist/github/machineAuth.test.js.map +7 -1
  117. package/dist/github/nativeIssueMetadata.js +286 -273
  118. package/dist/github/nativeIssueMetadata.js.map +7 -1
  119. package/dist/github/projectDelivery.d.ts +18 -2
  120. package/dist/github/projectDelivery.js +615 -557
  121. package/dist/github/projectDelivery.js.map +7 -1
  122. package/dist/github/relationships.js +433 -389
  123. package/dist/github/relationships.js.map +7 -1
  124. package/dist/github/repo.d.ts +1 -0
  125. package/dist/github/repo.js +123 -96
  126. package/dist/github/repo.js.map +7 -1
  127. package/dist/index.js +3 -3
  128. package/dist/index.js.map +7 -1
  129. package/dist/issue.d.ts +40 -9
  130. package/dist/issue.js +2102 -1742
  131. package/dist/issue.js.map +7 -1
  132. package/dist/issue63History.test.js +40 -42
  133. package/dist/issue63History.test.js.map +7 -1
  134. package/dist/issue63Routes.test.js +154 -143
  135. package/dist/issue63Routes.test.js.map +7 -1
  136. package/dist/issueBatchUpdate.test.js +989 -885
  137. package/dist/issueBatchUpdate.test.js.map +7 -1
  138. package/dist/issueBlockerGuard.test.js +262 -226
  139. package/dist/issueBlockerGuard.test.js.map +7 -1
  140. package/dist/issueContract.d.ts +23 -4
  141. package/dist/issueContract.js +416 -395
  142. package/dist/issueContract.js.map +7 -1
  143. package/dist/issueContract.test.d.ts +4 -3
  144. package/dist/issueContract.test.js +358 -321
  145. package/dist/issueContract.test.js.map +7 -1
  146. package/dist/issueDates.test.js +235 -233
  147. package/dist/issueDates.test.js.map +7 -1
  148. package/dist/issueInfoReadback.test.js +304 -190
  149. package/dist/issueInfoReadback.test.js.map +7 -1
  150. package/dist/issueIntake.test.js +1945 -1732
  151. package/dist/issueIntake.test.js.map +7 -1
  152. package/dist/issueJournal.d.ts +40 -19
  153. package/dist/issueJournal.js +229 -138
  154. package/dist/issueJournal.js.map +7 -1
  155. package/dist/issueJournal.test.js +605 -422
  156. package/dist/issueJournal.test.js.map +7 -1
  157. package/dist/issueRollup.test.d.ts +1 -0
  158. package/dist/issueRollup.test.js +476 -0
  159. package/dist/issueRollup.test.js.map +7 -0
  160. package/dist/issueTracking.test.js +1059 -989
  161. package/dist/issueTracking.test.js.map +7 -1
  162. package/dist/issueWriteRecovery.test.d.ts +1 -0
  163. package/dist/issueWriteRecovery.test.js +260 -0
  164. package/dist/issueWriteRecovery.test.js.map +7 -0
  165. package/dist/lifecycle.test.js +112 -441
  166. package/dist/lifecycle.test.js.map +7 -1
  167. package/dist/logger.js +80 -74
  168. package/dist/logger.js.map +7 -1
  169. package/dist/mcp/index.js +116 -94
  170. package/dist/mcp/index.js.map +7 -1
  171. package/dist/mcp/tools.d.ts +264 -286
  172. package/dist/mcp/tools.js +267 -340
  173. package/dist/mcp/tools.js.map +7 -1
  174. package/dist/pluginAuthProbe.js +63 -52
  175. package/dist/pluginAuthProbe.js.map +7 -1
  176. package/dist/pluginAuthProbe.test.js +85 -62
  177. package/dist/pluginAuthProbe.test.js.map +7 -1
  178. package/dist/pluginCredentials.test.js +282 -259
  179. package/dist/pluginCredentials.test.js.map +7 -1
  180. package/dist/pluginDoctor.test.js +653 -588
  181. package/dist/pluginDoctor.test.js.map +7 -1
  182. package/dist/pluginInstaller.d.ts +7 -5
  183. package/dist/pluginInstaller.js +1173 -1229
  184. package/dist/pluginInstaller.js.map +7 -1
  185. package/dist/pluginInstaller.test.js +1842 -1423
  186. package/dist/pluginInstaller.test.js.map +7 -1
  187. package/dist/pluginPackaging.test.js +460 -409
  188. package/dist/pluginPackaging.test.js.map +7 -1
  189. package/dist/pr.d.ts +132 -94
  190. package/dist/pr.js +1521 -1323
  191. package/dist/pr.js.map +7 -1
  192. package/dist/pr.test.js +1678 -632
  193. package/dist/pr.test.js.map +7 -1
  194. package/dist/prAssociation.test.js +2419 -1788
  195. package/dist/prAssociation.test.js.map +7 -1
  196. package/dist/prDispatch.test.js +150 -89
  197. package/dist/prDispatch.test.js.map +7 -1
  198. package/dist/readView.d.ts +183 -0
  199. package/dist/readView.js +217 -0
  200. package/dist/readView.js.map +7 -0
  201. package/dist/readView.test.d.ts +1 -0
  202. package/dist/readView.test.js +119 -0
  203. package/dist/readView.test.js.map +7 -0
  204. package/dist/releaseReconciliation.test.js +267 -288
  205. package/dist/releaseReconciliation.test.js.map +7 -1
  206. package/dist/releaseWorkflow.test.js +2493 -422
  207. package/dist/releaseWorkflow.test.js.map +7 -1
  208. package/dist/review.d.ts +738 -2
  209. package/dist/review.js +601 -348
  210. package/dist/review.js.map +7 -1
  211. package/dist/review.test.js +1218 -812
  212. package/dist/review.test.js.map +7 -1
  213. package/dist/reviewSubmit.test.d.ts +1 -0
  214. package/dist/reviewSubmit.test.js +747 -0
  215. package/dist/reviewSubmit.test.js.map +7 -0
  216. package/dist/services/agentReadinessService.js +42 -37
  217. package/dist/services/agentReadinessService.js.map +7 -1
  218. package/dist/services/blockerGuardService.js +188 -188
  219. package/dist/services/blockerGuardService.js.map +7 -1
  220. package/dist/services/boardReconcileService.d.ts +125 -125
  221. package/dist/services/boardReconcileService.js +1295 -1421
  222. package/dist/services/boardReconcileService.js.map +7 -1
  223. package/dist/services/deliveryAdmission.js +131 -154
  224. package/dist/services/deliveryAdmission.js.map +7 -1
  225. package/dist/services/deliveryHealthService.js +197 -199
  226. package/dist/services/deliveryHealthService.js.map +7 -1
  227. package/dist/services/legacyIssueMigration.js +263 -277
  228. package/dist/services/legacyIssueMigration.js.map +7 -1
  229. package/dist/services/worktreeRegistry.d.ts +27 -119
  230. package/dist/services/worktreeRegistry.js +765 -1182
  231. package/dist/services/worktreeRegistry.js.map +7 -1
  232. package/dist/stagedChecks.test.js +396 -194
  233. package/dist/stagedChecks.test.js.map +7 -1
  234. package/dist/start.test.js +99 -95
  235. package/dist/start.test.js.map +7 -1
  236. package/dist/stdoutRegression.test.js +353 -352
  237. package/dist/stdoutRegression.test.js.map +7 -1
  238. package/dist/targetPolicyDiscovery.test.js +141 -143
  239. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  240. package/dist/targetPolicyEntrypoints.test.js +308 -269
  241. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  242. package/dist/targetPolicyLocal.test.js +580 -1051
  243. package/dist/targetPolicyLocal.test.js.map +7 -1
  244. package/dist/targetPolicyRoutes.test.js +305 -281
  245. package/dist/targetPolicyRoutes.test.js.map +7 -1
  246. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  247. package/dist/targetRepositoryExecution.test.js +463 -0
  248. package/dist/targetRepositoryExecution.test.js.map +7 -0
  249. package/dist/terminalMessages.js +41 -35
  250. package/dist/terminalMessages.js.map +7 -1
  251. package/dist/toolOutput.d.ts +2 -0
  252. package/dist/toolOutput.js +36 -0
  253. package/dist/toolOutput.js.map +7 -0
  254. package/dist/toolOutput.test.d.ts +1 -0
  255. package/dist/toolOutput.test.js +240 -0
  256. package/dist/toolOutput.test.js.map +7 -0
  257. package/dist/utils/atomicJson.js +84 -76
  258. package/dist/utils/atomicJson.js.map +7 -1
  259. package/dist/utils/filesystem.js +15 -18
  260. package/dist/utils/filesystem.js.map +7 -1
  261. package/dist/utils/lockfile.js +68 -71
  262. package/dist/utils/lockfile.js.map +7 -1
  263. package/dist/verification.d.ts +1 -19
  264. package/dist/verification.js +1020 -1939
  265. package/dist/verification.js.map +7 -1
  266. package/dist/verificationGate.test.js +127 -117
  267. package/dist/verificationGate.test.js.map +7 -1
  268. package/dist/version.js +23 -24
  269. package/dist/version.js.map +7 -1
  270. package/dist/worktree.d.ts +3 -15
  271. package/dist/worktree.js +97 -177
  272. package/dist/worktree.js.map +7 -1
  273. package/package.json +9 -8
  274. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  275. package/plugins/ai-delivery/README.md +47 -156
  276. package/plugins/ai-delivery/plugin.json +1 -1
  277. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
  278. package/plugins/ai-delivery/runtime/dist/cli.js +358 -115
  279. package/plugins/ai-delivery/runtime/package.json +1 -1
  280. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  281. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  282. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  283. package/dist/investigationCompletion.test.js +0 -728
  284. package/dist/investigationCompletion.test.js.map +0 -1
  285. package/dist/setup.d.ts +0 -60
  286. package/dist/setup.js +0 -585
  287. package/dist/setup.js.map +0 -1
  288. package/dist/setup.test.js +0 -3329
  289. package/dist/setup.test.js.map +0 -1
  290. package/dist/worktreeTransition.d.ts +0 -211
  291. package/dist/worktreeTransition.js +0 -1037
  292. package/dist/worktreeTransition.js.map +0 -1
  293. package/dist/worktreeTransition.test.js +0 -1191
  294. package/dist/worktreeTransition.test.js.map +0 -1
  295. /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
  296. /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
  297. /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
@@ -1,492 +1,512 @@
1
- import assert from 'node:assert/strict';
2
- import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
- import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
7
- import { test, vi } from 'vitest';
8
- import * as githubClients from './github/client.js';
9
- import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from './fixtures/discovery.js';
10
- import { createAiDeliveryMcpServer } from './mcp/index.js';
11
- import { canonicalIssueBody } from './issue.js';
12
- // Only the external GitHub/auth port is replaced. Reads reflect stored writes;
13
- // unexpected endpoints and foreign targets fail instead of returning canned success.
1
+ import { issueProjectItemsResponse } from "./fixtures/issueProjectItems.js";
2
+ import assert from "node:assert/strict";
3
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
7
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
8
+ import { test, vi } from "vitest";
9
+ import * as githubClients from "./github/client.js";
10
+ import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from "./fixtures/discovery.js";
11
+ import { createAiDeliveryMcpServer } from "./mcp/index.js";
12
+ import { canonicalIssueBody } from "./issue.js";
14
13
  function trackingRepository() {
15
- const issues = new Map();
16
- const comments = [];
17
- const events = [];
18
- let writes = 0;
19
- const add = (number, title, body, parent) => {
20
- const value = {
21
- number,
22
- id: 100 + number,
23
- node_id: `ISSUE${String(number)}`,
24
- title,
25
- body,
26
- state: 'open',
27
- type: { name: 'Task' },
28
- labels: [],
29
- html_url: `https://github.com/example/widget/issues/${String(number)}`,
30
- updated_at: '2026-10-07T00:00:00Z',
31
- parent,
32
- status: parent === null ? null : 'Active',
33
- reason: null,
34
- ...(parent === null ? {} : { points: 2, priority: 'High' }),
35
- };
36
- issues.set(number, value);
37
- return value;
38
- };
39
- add(10, 'Original tracking parent', 'Original unsized parent', null);
40
- add(20, 'Replacement tracking parent', 'Replacement unsized parent', null);
41
- add(17, ' Legacy <tracking> & title\r\n', '\nLegacy & backlog <tag>\t \r\n', 10);
42
- add(18, 'Second tracking issue', canonicalIssueBody({
43
- title: 'Second tracking issue',
44
- issueType: 'Task',
45
- points: 2,
46
- problem: 'A second executable issue needs a new parent.',
47
- outcome: 'The issue retains its contract when reparented.',
48
- acceptanceCriteria: [
49
- {
50
- behavior: 'A parent update returns the new native parent.',
51
- verifiedBy: 'The scenario checks persisted parent membership.',
52
- },
53
- ],
54
- outOfScope: ['Changing the executable work.'],
55
- openQuestions: [],
56
- draft: false,
57
- }), 10);
58
- const get = (number) => {
59
- assert.equal(typeof number, 'number');
60
- const issue = issues.get(number);
61
- assert.ok(issue, `Unknown synthetic issue ${String(number)}`);
62
- return issue;
14
+ const issues = /* @__PURE__ */ new Map();
15
+ const comments = [];
16
+ const events = [];
17
+ let writes = 0;
18
+ const add = (number, title, body, parent) => {
19
+ const value = {
20
+ number,
21
+ id: 100 + number,
22
+ node_id: `ISSUE${String(number)}`,
23
+ title,
24
+ body,
25
+ state: "open",
26
+ type: { name: "Task" },
27
+ labels: [],
28
+ html_url: `https://github.com/example/widget/issues/${String(number)}`,
29
+ url: `https://api.github.com/repos/example/widget/issues/${String(number)}`,
30
+ repository_url: "https://api.github.com/repos/example/widget",
31
+ updated_at: "2026-10-07T00:00:00Z",
32
+ parent,
33
+ status: parent === null ? null : "Active",
34
+ reason: null,
35
+ ...parent === null ? {} : { points: 2, priority: "High" }
63
36
  };
64
- const target = (input) => {
65
- if ('owner' in input)
66
- assert.equal(input.owner, 'example');
67
- if ('repo' in input)
68
- assert.equal(input.repo, 'widget');
69
- if ('name' in input)
70
- assert.equal(input.name, 'widget');
71
- if ('org' in input)
72
- assert.equal(input.org, 'example');
73
- };
74
- const mutation = (event) => {
75
- writes += 1;
76
- events.push(event);
77
- };
78
- const values = (issue) => [
79
- ...(issue.points === undefined
80
- ? []
81
- : [
82
- {
83
- issue_field_id: 101,
84
- issue_field_name: 'Estimate',
85
- data_type: 'single_select',
86
- value: String(issue.points),
87
- single_select_option: { name: String(issue.points) },
88
- },
89
- ]),
90
- ...(issue.priority === undefined
91
- ? []
92
- : [
93
- {
94
- issue_field_id: 102,
95
- issue_field_name: 'Urgency',
96
- data_type: 'single_select',
97
- value: issue.priority,
98
- single_select_option: { name: issue.priority },
99
- },
100
- ]),
101
- ];
102
- const listSubIssues = async (input) => {
37
+ issues.set(number, value);
38
+ return value;
39
+ };
40
+ add(10, "Original tracking parent", "Original unsized parent", null);
41
+ add(20, "Replacement tracking parent", "Replacement unsized parent", null);
42
+ add(17, " Legacy <tracking> & title\r\n", "\nLegacy & backlog <tag> \r\n", 10);
43
+ add(
44
+ 18,
45
+ "Second tracking issue",
46
+ canonicalIssueBody({
47
+ title: "Second tracking issue",
48
+ issueType: "Task",
49
+ points: 2,
50
+ problem: "A second executable issue needs a new parent.",
51
+ outcome: "The issue retains its contract when reparented.",
52
+ acceptanceCriteria: [
53
+ {
54
+ behavior: "A parent update returns the new native parent.",
55
+ verifiedBy: "The scenario checks persisted parent membership."
56
+ }
57
+ ],
58
+ outOfScope: ["Changing the executable work."],
59
+ openQuestions: [],
60
+ draft: false
61
+ }),
62
+ 10
63
+ );
64
+ const get = (number) => {
65
+ assert.equal(typeof number, "number");
66
+ const issue = issues.get(number);
67
+ assert.ok(issue, `Unknown synthetic issue ${String(number)}`);
68
+ return issue;
69
+ };
70
+ const target = (input) => {
71
+ if ("owner" in input) assert.equal(input.owner, "example");
72
+ if ("repo" in input) assert.equal(input.repo, "widget");
73
+ if ("name" in input) assert.equal(input.name, "widget");
74
+ if ("org" in input) assert.equal(input.org, "example");
75
+ };
76
+ const mutation = (event) => {
77
+ writes += 1;
78
+ events.push(event);
79
+ };
80
+ const values = (issue) => [
81
+ ...issue.points === void 0 ? [] : [
82
+ {
83
+ issue_field_id: 101,
84
+ issue_field_name: "Estimate",
85
+ data_type: "single_select",
86
+ value: String(issue.points),
87
+ single_select_option: { name: String(issue.points) }
88
+ }
89
+ ],
90
+ ...issue.priority === void 0 ? [] : [
91
+ {
92
+ issue_field_id: 102,
93
+ issue_field_name: "Urgency",
94
+ data_type: "single_select",
95
+ value: issue.priority,
96
+ single_select_option: { name: issue.priority }
97
+ }
98
+ ]
99
+ ];
100
+ const listSubIssues = async (input) => {
101
+ target(input);
102
+ get(input.issue_number);
103
+ return { data: structuredClone([...issues.values()].filter((issue) => issue.parent === input.issue_number)) };
104
+ };
105
+ const rest = {
106
+ issues: {
107
+ get: async (input) => {
103
108
  target(input);
104
- get(input.issue_number);
105
- return { data: structuredClone([...issues.values()].filter((issue) => issue.parent === input.issue_number)) };
106
- };
107
- const rest = {
108
- issues: {
109
- get: async (input) => {
110
- target(input);
111
- return { data: structuredClone(get(input.issue_number)) };
112
- },
113
- listForRepo: async (input) => {
114
- target(input);
115
- assert.equal(input.page, 1);
116
- return {
117
- data: structuredClone([...issues.values()].filter((issue) => input.state === 'all' || issue.state === input.state)),
118
- };
119
- },
120
- listSubIssues,
121
- create: async (input) => {
122
- target(input);
123
- assert.equal(issues.has(31), false, 'the scenario creates exactly one child');
124
- assert.equal(input.type, 'Task');
125
- const issue = add(31, input.title, input.body, null);
126
- mutation('issue:create:31');
127
- return { data: structuredClone(issue) };
128
- },
129
- update: async (input) => {
130
- target(input);
131
- const issue = get(input.issue_number);
132
- for (const key of ['title', 'body', 'state'])
133
- if (typeof input[key] === 'string')
134
- issue[key] = input[key];
135
- if (typeof input.type === 'string')
136
- issue.type = { name: input.type };
137
- if (typeof input.state_reason === 'string')
138
- issue.reason = input.state_reason.toUpperCase();
139
- mutation(`issue:update:${String(issue.number)}`);
140
- return { data: structuredClone(issue) };
141
- },
142
- addSubIssue: async (input) => {
143
- target(input);
144
- const parent = get(input.issue_number);
145
- const child = [...issues.values()].find((issue) => issue.id === input.sub_issue_id);
146
- assert.ok(child);
147
- assert.equal(child.parent, null);
148
- child.parent = parent.number;
149
- mutation(`parent:add:${String(child.number)}:${String(parent.number)}`);
150
- return { data: structuredClone(child) };
151
- },
152
- removeSubIssue: async (input) => {
153
- target(input);
154
- const child = [...issues.values()].find((issue) => issue.id === input.sub_issue_id);
155
- assert.ok(child);
156
- assert.equal(child.parent, input.issue_number);
157
- child.parent = null;
158
- mutation(`parent:remove:${String(child.number)}`);
159
- return { data: structuredClone(child) };
160
- },
161
- listComments: async (input) => {
162
- target(input);
163
- const issue = get(input.issue_number);
164
- return {
165
- data: structuredClone(comments.filter((comment) => comment.issue_url.endsWith(`/issues/${String(issue.number)}`))),
166
- };
167
- },
168
- createComment: async (input) => {
169
- target(input);
170
- const issue = get(input.issue_number);
171
- const id = 101 + comments.length;
172
- const comment = {
173
- id,
174
- body: input.body,
175
- html_url: `${issue.html_url}#issuecomment-${String(id)}`,
176
- issue_url: `https://api.github.com/repos/example/widget/issues/${String(issue.number)}`,
177
- user: { login: 'operator' },
178
- };
179
- comments.push(comment);
180
- mutation(`comment:create:${String(id)}`);
181
- return { data: structuredClone(comment) };
182
- },
183
- getComment: async (input) => {
184
- target(input);
185
- const comment = comments.find((value) => value.id === input.comment_id);
186
- assert.ok(comment);
187
- events.push(`comment:read:${String(comment.id)}`);
188
- return { data: structuredClone(comment) };
189
- },
190
- },
191
- search: {
192
- issuesAndPullRequests: async (input) => {
193
- assert.equal(input.page, 1);
194
- assert.equal(typeof input.q, 'string');
195
- const match = /^repo:example\/widget is:issue "(Legacy|Replacement)"$/u.exec(input.q);
196
- assert.ok(match, 'search must retain repository and literal text boundaries');
197
- const items = [...issues.values()].filter((issue) => `${issue.title}\n${issue.body}`.includes(match[1]));
198
- return { data: { total_count: items.length, incomplete_results: false, items: structuredClone(items) } };
199
- },
200
- },
201
- paginate: async (method, input) => {
202
- assert.equal(method, listSubIssues);
203
- return (await method(input)).data;
204
- },
205
- request: async (route, input) => {
206
- target(input);
207
- if (route === 'GET /orgs/{org}/issue-fields')
208
- return {
209
- data: [
210
- {
211
- id: 101,
212
- name: 'Estimate',
213
- data_type: 'single_select',
214
- options: [{ name: '1' }, { name: '2' }, { name: '4' }],
215
- },
216
- { id: 102, name: 'Urgency', data_type: 'single_select', options: [{ name: 'High' }, { name: 'Low' }] },
217
- ],
218
- };
219
- const issue = get(input.issue_number);
220
- if (route === 'POST /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values') {
221
- for (const field of input.issue_field_values) {
222
- if (field.field_id === 101)
223
- issue.points = Number(field.value);
224
- else {
225
- assert.equal(field.field_id, 102);
226
- issue.priority = field.value;
227
- }
228
- }
229
- mutation(`fields:${String(issue.number)}`);
230
- }
231
- else
232
- assert.equal(route, 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values');
233
- return { data: values(issue) };
234
- },
235
- };
236
- const discovery = syntheticDiscoveryClients();
237
- const page = (nodes) => ({ nodes, pageInfo: { hasNextPage: false, endCursor: null } });
238
- const projectItem = (issue) => ({
239
- id: `ITEM${String(issue.number)}`,
240
- isArchived: false,
241
- content: { id: issue.node_id },
242
- fieldValueByName: issue.status === null
243
- ? null
244
- : {
245
- name: issue.status,
246
- optionId: `STATUS-${String(['Queued', 'Active', 'Waiting', 'Shipped'].indexOf(issue.status))}`,
247
- },
248
- });
249
- const graphql = async (query, input) => {
109
+ return { data: structuredClone(get(input.issue_number)) };
110
+ },
111
+ listForRepo: async (input) => {
250
112
  target(input);
251
- if (query.includes('blockedBy(first:')) {
252
- const issue = get(input.number);
253
- return {
254
- repository: {
255
- issue: {
256
- parent: issue.parent === null
257
- ? null
258
- : {
259
- id: get(issue.parent).node_id,
260
- number: issue.parent,
261
- repository: { nameWithOwner: 'example/widget' },
262
- },
263
- blockedBy: page([]),
264
- },
265
- },
266
- };
267
- }
268
- if (query.includes('IssueClosureReadback')) {
269
- const issue = get(input.number);
270
- return {
271
- repository: {
272
- issue: {
273
- number: issue.number,
274
- repository: { nameWithOwner: 'example/widget' },
275
- state: issue.state.toUpperCase(),
276
- stateReason: issue.reason,
277
- duplicateOf: null,
278
- },
279
- },
280
- };
281
- }
282
- if (query.includes('ProjectDeliveryItems'))
283
- return {
284
- organization: {
285
- projectV2: { items: page([...issues.values()].filter((issue) => issue.status !== null).map(projectItem)) },
286
- },
287
- };
288
- if (query.includes('AddProjectDeliveryItem')) {
289
- const issue = [...issues.values()].find((value) => value.node_id === input.contentId);
290
- assert.ok(issue);
291
- assert.equal(input.projectId, 'PROJECT-1');
292
- mutation(`project:add:${String(issue.number)}`);
293
- return { addProjectV2ItemById: { item: { id: `ITEM${String(issue.number)}` } } };
294
- }
295
- if (query.includes('UpdateProjectDeliveryStatus')) {
296
- const issue = get(Number(String(input.itemId).slice(4)));
297
- assert.equal(input.projectId, 'PROJECT-1');
298
- assert.equal(input.fieldId, 'STATUS-FIELD');
299
- const status = ['Queued', 'Active', 'Waiting', 'Shipped'][Number(String(input.optionId).slice(7))];
300
- assert.ok(status);
301
- issue.status = status;
302
- mutation(`project:status:${String(issue.number)}:${status}`);
303
- return { updateProjectV2ItemFieldValue: { projectV2Item: { id: input.itemId } } };
304
- }
305
- if (query.includes('ProjectDeliveryItemReadback')) {
306
- const issue = get(Number(String(input.itemId).slice(4)));
307
- return { node: { ...projectItem(issue), project: { id: 'PROJECT-1', number: 1 } } };
308
- }
309
- return discovery.graphql(query, input);
310
- };
311
- return {
312
- issues,
313
- comments,
314
- events,
315
- rest,
316
- graphql,
317
- snapshot: () => structuredClone({ issues: [...issues.values()], comments, writes }),
318
- writes: () => writes,
319
- };
320
- }
321
- test('composes shipped tracking through one non-Git MCP session with persisted readbacks and inert refusals', async () => {
322
- const root = mkdtempSync(join(tmpdir(), 'delivery-tracking-scenario-'));
323
- const fixture = trackingRepository();
324
- vi.stubEnv('AI_DELIVERY_CONFIG', join(root, 'operator.json'));
325
- writeFileSync(join(root, 'operator.json'), JSON.stringify({
326
- schemaVersion: 'ai-delivery.user@1',
327
- roles: {
328
- author: { authSource: 'personal', identity: 'host-author', credentialEnv: { token: 'SYNTHETIC_TOKEN' } },
329
- reviewer: {
330
- identity: 'app-reviewer',
331
- credentialEnv: { appId: 'APP_ID', installationId: 'INSTALLATION_ID', privateKeyPath: 'KEY_PATH' },
332
- },
333
- },
334
- project: 1,
335
- checkoutRoots: [],
336
- pointsField: 'Estimate',
337
- priorityField: 'Urgency',
338
- statusField: 'Flow',
339
- statuses: syntheticDiscoveryConfig.native.project.statuses,
340
- }));
341
- vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockImplementation(async (input) => {
342
- assert.equal(input.role, 'author');
113
+ assert.equal(input.page, 1);
343
114
  return {
344
- role: 'author',
345
- authSource: 'personal',
346
- authenticatedAuthor: async () => ({ actorLogin: 'operator', credentialIdentity: 'user:1' }),
347
- rest: fixture.rest,
348
- graphql: fixture.graphql,
115
+ data: structuredClone(
116
+ [...issues.values()].filter((issue) => input.state === "all" || issue.state === input.state)
117
+ )
349
118
  };
350
- });
351
- const server = createAiDeliveryMcpServer({ repoRoot: root });
352
- const client = new Client({ name: 'tracking-scenario', version: '1' });
353
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
354
- async function call(name, args) {
355
- const result = await client.callTool({ name, arguments: { repo: 'example/widget', ...args } });
356
- assert.equal(result.isError, undefined, JSON.stringify(result));
357
- return JSON.parse(result.content[0].text);
119
+ },
120
+ listSubIssues,
121
+ create: async (input) => {
122
+ target(input);
123
+ assert.equal(issues.has(31), false, "the scenario creates exactly one child");
124
+ assert.equal(input.type, "Task");
125
+ const issue = add(31, input.title, input.body, null);
126
+ mutation("issue:create:31");
127
+ return { data: structuredClone(issue) };
128
+ },
129
+ update: async (input) => {
130
+ target(input);
131
+ const issue = get(input.issue_number);
132
+ for (const key of ["title", "body", "state"])
133
+ if (typeof input[key] === "string") issue[key] = input[key];
134
+ if (typeof input.type === "string") issue.type = { name: input.type };
135
+ if (typeof input.state_reason === "string") issue.reason = input.state_reason.toUpperCase();
136
+ mutation(`issue:update:${String(issue.number)}`);
137
+ return { data: structuredClone(issue) };
138
+ },
139
+ addSubIssue: async (input) => {
140
+ target(input);
141
+ const parent = get(input.issue_number);
142
+ const child = [...issues.values()].find((issue) => issue.id === input.sub_issue_id);
143
+ assert.ok(child);
144
+ assert.equal(child.parent, null);
145
+ child.parent = parent.number;
146
+ mutation(`parent:add:${String(child.number)}:${String(parent.number)}`);
147
+ return { data: structuredClone(child) };
148
+ },
149
+ removeSubIssue: async (input) => {
150
+ target(input);
151
+ const child = [...issues.values()].find((issue) => issue.id === input.sub_issue_id);
152
+ assert.ok(child);
153
+ assert.equal(child.parent, input.issue_number);
154
+ child.parent = null;
155
+ mutation(`parent:remove:${String(child.number)}`);
156
+ return { data: structuredClone(child) };
157
+ },
158
+ listComments: async (input) => {
159
+ target(input);
160
+ const issue = get(input.issue_number);
161
+ return {
162
+ data: structuredClone(
163
+ comments.filter((comment) => comment.issue_url.endsWith(`/issues/${String(issue.number)}`))
164
+ )
165
+ };
166
+ },
167
+ createComment: async (input) => {
168
+ target(input);
169
+ const issue = get(input.issue_number);
170
+ const id = 101 + comments.length;
171
+ const comment = {
172
+ id,
173
+ body: input.body,
174
+ html_url: `${issue.html_url}#issuecomment-${String(id)}`,
175
+ issue_url: `https://api.github.com/repos/example/widget/issues/${String(issue.number)}`,
176
+ user: { login: "operator" }
177
+ };
178
+ comments.push(comment);
179
+ mutation(`comment:create:${String(id)}`);
180
+ return { data: structuredClone(comment) };
181
+ },
182
+ getComment: async (input) => {
183
+ target(input);
184
+ const comment = comments.find((value) => value.id === input.comment_id);
185
+ assert.ok(comment);
186
+ events.push(`comment:read:${String(comment.id)}`);
187
+ return { data: structuredClone(comment) };
188
+ }
189
+ },
190
+ search: {
191
+ issuesAndPullRequests: async (input) => {
192
+ assert.equal(input.page, 1);
193
+ assert.equal(typeof input.q, "string");
194
+ const match = /^repo:example\/widget is:issue "(Legacy|Replacement)"$/u.exec(input.q);
195
+ assert.ok(match, "search must retain repository and literal text boundaries");
196
+ const items = [...issues.values()].filter((issue) => `${issue.title}
197
+ ${issue.body}`.includes(match[1]));
198
+ return { data: { total_count: items.length, incomplete_results: false, items: structuredClone(items) } };
199
+ }
200
+ },
201
+ paginate: async (method, input) => {
202
+ assert.equal(method, listSubIssues);
203
+ return (await method(input)).data;
204
+ },
205
+ request: async (route, input) => {
206
+ target(input);
207
+ if (route === "GET /orgs/{org}/issue-fields")
208
+ return {
209
+ data: [
210
+ {
211
+ id: 101,
212
+ name: "Estimate",
213
+ data_type: "single_select",
214
+ options: [{ name: "1" }, { name: "2" }, { name: "4" }]
215
+ },
216
+ { id: 102, name: "Urgency", data_type: "single_select", options: [{ name: "High" }, { name: "Low" }] }
217
+ ]
218
+ };
219
+ const issue = get(input.issue_number);
220
+ if (route === "POST /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values") {
221
+ for (const field of input.issue_field_values) {
222
+ if (field.field_id === 101) issue.points = Number(field.value);
223
+ else {
224
+ assert.equal(field.field_id, 102);
225
+ issue.priority = field.value;
226
+ }
227
+ }
228
+ mutation(`fields:${String(issue.number)}`);
229
+ } else assert.equal(route, "GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values");
230
+ return { data: values(issue) };
358
231
  }
359
- async function refuse(name, args) {
360
- const before = fixture.snapshot();
361
- const refused = await client.callTool({ name, arguments: { repo: 'example/widget', ...args } }).then((result) => result.isError === true, () => true);
362
- assert.equal(refused, true, name);
363
- assert.deepEqual(fixture.snapshot(), before, `${name} must not mutate stored native state or write count`);
232
+ };
233
+ const discovery = syntheticDiscoveryClients();
234
+ const page = (nodes) => ({ nodes, pageInfo: { hasNextPage: false, endCursor: null } });
235
+ const projectItem = (issue) => ({
236
+ id: `ITEM${String(issue.number)}`,
237
+ isArchived: false,
238
+ content: { id: issue.node_id },
239
+ fieldValueByName: issue.status === null ? null : {
240
+ name: issue.status,
241
+ optionId: `STATUS-${String(["Queued", "Active", "Waiting", "Shipped"].indexOf(issue.status))}`
364
242
  }
365
- const fields = {
366
- issueType: 'Task',
367
- points: 2,
368
- problem: 'Legacy tracking needs a portable replacement.',
369
- outcome: 'Replacement tracking has an explicit native readback.',
370
- acceptanceCriteria: [
371
- {
372
- behavior: 'Invalid tracking requests leave native state unchanged.',
373
- verifiedBy: 'The synthetic MCP scenario compares stored state and writes.',
243
+ });
244
+ const graphql = async (query, input) => {
245
+ target(input);
246
+ if (query.includes("blockedBy(first:")) {
247
+ const issue = get(input.number);
248
+ return {
249
+ repository: {
250
+ issue: {
251
+ parent: issue.parent === null ? null : {
252
+ id: get(issue.parent).node_id,
253
+ number: issue.parent,
254
+ repository: { nameWithOwner: "example/widget" }
374
255
  },
375
- ],
376
- outOfScope: ['Implementing batch or deferral.'],
377
- openQuestions: [],
378
- context: {
379
- files: ['src/currentTrackingScenario.test.ts'],
380
- evidence: ['https://github.com/example/widget/issues/17'],
381
- },
382
- draft: false,
383
- };
384
- try {
385
- await server.connect(serverTransport);
386
- await client.connect(clientTransport);
387
- assert.equal(existsSync(join(root, '.git')), false);
388
- const tools = (await client.listTools()).tools.map((tool) => tool.name);
389
- for (const name of ['issue_list', 'issue_search', 'issue_update', 'issue_create', 'issue_comment', 'issue_info'])
390
- assert.ok(tools.includes(name));
391
- const original = await call('issue_list', {
392
- parentIssueNumber: 10,
393
- state: 'all',
394
- });
395
- assert.deepEqual(original.issues.map((issue) => issue.number), [17, 18]);
396
- const found = await call('issue_search', { query: 'Legacy', state: 'all' });
397
- assert.deepEqual(found.issues.map((issue) => issue.number), [17]);
398
- await refuse('issue_update', { issueNumber: 17, points: 'two' });
399
- const rewritten = await call('issue_update', {
400
- ...fields,
401
- issueNumber: 17,
402
- title: 'Replacement tracking issue',
403
- preserveHistory: true,
404
- });
405
- const expectedHistory = '<details>\n<summary>Previous issue title and body</summary>\n\nTitle:\n<pre> Legacy &lt;tracking&gt; &amp; title\r\n</pre>\n\nBody:\n<pre>\nLegacy &amp; backlog &lt;tag&gt;\t \r\n</pre>\n\n</details>';
406
- assert.equal(rewritten.historyComment.body, expectedHistory);
407
- assert.equal(fixture.comments[0].body, expectedHistory);
408
- assert.equal(fixture.comments[0].user.login, 'operator');
409
- const historyRead = fixture.events.indexOf('comment:read:101');
410
- assert.ok(historyRead >= 0 && historyRead < fixture.events.indexOf('issue:update:17'));
411
- assert.equal(rewritten.title, fixture.issues.get(17).title);
412
- assert.equal(rewritten.body, fixture.issues.get(17).body);
413
- const created = await call('issue_create', {
414
- ...fields,
415
- title: 'Replacement sized child',
416
- priority: 'High',
417
- parentIssueNumber: 20,
418
- });
419
- assert.equal(created.created.number, 31);
420
- const child = await call('issue_info', { issueNumber: created.created.number });
421
- assert.equal(child.points, 2);
422
- assert.equal(child.priority, 'High');
423
- assert.equal(child.issueType, 'Task');
424
- assert.equal(child.parentIssueNumber, 20);
425
- assert.equal(child.projectStatus, 'Todo');
426
- assert.equal(fixture.issues.get(31).parent, 20);
427
- await refuse('issue_batch', { issues: [17, 18], parentIssueNumber: 20 });
428
- for (const issueNumber of [17, 18]) {
429
- const moved = await call('issue_update', { issueNumber, parentIssueNumber: 20 });
430
- assert.equal(moved.parentIssueNumber, 20);
431
- assert.equal(fixture.issues.get(issueNumber).parent, 20);
256
+ blockedBy: page([])
257
+ }
258
+ }
259
+ };
260
+ }
261
+ if (query.includes("IssueClosureReadback")) {
262
+ const issue = get(input.number);
263
+ return {
264
+ repository: {
265
+ issue: {
266
+ number: issue.number,
267
+ repository: { nameWithOwner: "example/widget" },
268
+ state: issue.state.toUpperCase(),
269
+ stateReason: issue.reason,
270
+ duplicateOf: null
271
+ }
432
272
  }
433
- assert.deepEqual((await call('issue_list', { parentIssueNumber: 10, state: 'all' })).issues, []);
434
- assert.deepEqual((await call('issue_list', { parentIssueNumber: 20, state: 'all' })).issues.map((issue) => issue.number), [17, 18, 31]);
435
- for (const number of [10, 20])
436
- assert.equal((await call('issue_info', { issueNumber: number })).points, undefined);
437
- const journal = await call('issue_comment', {
438
- issueNumber: 31,
439
- kind: 'progress',
440
- summary: 'Tracking replay is verified.',
441
- status: 'In progress',
442
- done: ['Reparented two issues individually.'],
443
- decisionNeeded: 'None',
444
- keyNumbers: [],
445
- evidence: [created.created.url],
446
- nextStep: 'Review',
447
- nextDate: '2026-10-09',
448
- });
449
- const storedJournal = fixture.comments.find((comment) => comment.id === journal.commentId);
450
- assert.equal(storedJournal.body, journal.body);
451
- assert.equal(storedJournal.html_url, journal.url);
452
- assert.equal(storedJournal.user.login, 'operator');
453
- assert.match(journal.body, /Tracking replay is verified/u);
454
- await refuse('issue_defer', { issueNumber: 17, trigger: 'After review' });
455
- const deferred = await call('issue_update', { issueNumber: 17, defer: { trigger: 'After review' } });
456
- assert.deepEqual(deferred.deferred, { trigger: 'After review' });
457
- assert.deepEqual((await call('issue_info', { issueNumber: 17 })).deferred, { trigger: 'After review' });
458
- const undeferred = await call('issue_update', { issueNumber: 17, undefer: true });
459
- assert.equal(undeferred.deferred, null);
460
- const closed = await call('issue_update', { issueNumber: 17, state: 'closed', closeReason: 'not_planned', supersededBy: 31 });
461
- assert.equal(closed.closure.state, 'closed');
462
- assert.equal(closed.closure.closeReason, 'not_planned');
463
- assert.equal(closed.closure.supersededBy, 31);
464
- assert.equal(closed.projectStatus, 'Done');
465
- assert.equal(fixture.issues.get(17).reason, 'NOT_PLANNED');
466
- assert.equal(fixture.issues.get(17).status, 'Shipped');
467
- assert.equal(fixture.comments.find((comment) => comment.id === closed.closure.comment.commentId).body, 'Requested closure reason: not_planned.\nSuperseded by example/widget#31.');
468
- const final = await call('issue_info', { issueNumber: 17 });
469
- assert.equal(final.state, 'closed');
470
- assert.equal(final.parentIssueNumber, 20);
471
- assert.equal(final.projectStatus, 'Done');
472
- const finalSearch = await call('issue_search', {
473
- query: 'Replacement',
474
- state: 'all',
475
- });
476
- assert.deepEqual(finalSearch.issues.map(({ number, state }) => ({ number, state })), [
477
- { number: 20, state: 'open' },
478
- { number: 17, state: 'closed' },
479
- { number: 31, state: 'open' },
480
- ]);
481
- assert.ok(fixture.writes() > 0);
482
- assert.equal(existsSync(join(root, '.git')), false);
273
+ };
274
+ }
275
+ if (query.includes("ProjectDeliveryIssueItems"))
276
+ return issueProjectItemsResponse(
277
+ input,
278
+ [...issues.values()].filter((issue) => issue.status !== null && issue.node_id === input.issueNodeId).map(projectItem),
279
+ { id: "PROJECT-1", number: 1 }
280
+ );
281
+ if (query.includes("AddProjectDeliveryItem")) {
282
+ const issue = [...issues.values()].find((value) => value.node_id === input.contentId);
283
+ assert.ok(issue);
284
+ assert.equal(input.projectId, "PROJECT-1");
285
+ mutation(`project:add:${String(issue.number)}`);
286
+ return { addProjectV2ItemById: { item: { id: `ITEM${String(issue.number)}` } } };
483
287
  }
484
- finally {
485
- await client.close();
486
- await server.close();
487
- vi.restoreAllMocks();
488
- vi.unstubAllEnvs();
489
- rmSync(root, { recursive: true, force: true });
288
+ if (query.includes("UpdateProjectDeliveryStatus")) {
289
+ const issue = get(Number(String(input.itemId).slice(4)));
290
+ assert.equal(input.projectId, "PROJECT-1");
291
+ assert.equal(input.fieldId, "STATUS-FIELD");
292
+ const status = ["Queued", "Active", "Waiting", "Shipped"][Number(String(input.optionId).slice(7))];
293
+ assert.ok(status);
294
+ issue.status = status;
295
+ mutation(`project:status:${String(issue.number)}:${status}`);
296
+ return { updateProjectV2ItemFieldValue: { projectV2Item: { id: input.itemId } } };
490
297
  }
298
+ if (query.includes("ProjectDeliveryItemReadback")) {
299
+ const issue = get(Number(String(input.itemId).slice(4)));
300
+ return { node: { ...projectItem(issue), project: { id: "PROJECT-1", number: 1 } } };
301
+ }
302
+ return discovery.graphql(query, input);
303
+ };
304
+ return {
305
+ issues,
306
+ comments,
307
+ events,
308
+ rest,
309
+ graphql,
310
+ snapshot: () => structuredClone({ issues: [...issues.values()], comments, writes }),
311
+ writes: () => writes
312
+ };
313
+ }
314
+ test("composes shipped tracking through one non-Git MCP session with persisted readbacks and inert refusals", async () => {
315
+ const root = mkdtempSync(join(tmpdir(), "delivery-tracking-scenario-"));
316
+ const fixture = trackingRepository();
317
+ vi.stubEnv("AI_DELIVERY_CONFIG", join(root, "operator.json"));
318
+ writeFileSync(
319
+ join(root, "operator.json"),
320
+ JSON.stringify({
321
+ schemaVersion: "ai-delivery.user@1",
322
+ roles: {
323
+ author: { authSource: "personal", identity: "host-author", credentialEnv: { token: "SYNTHETIC_TOKEN" } },
324
+ reviewer: {
325
+ identity: "app-reviewer",
326
+ credentialEnv: { appId: "APP_ID", installationId: "INSTALLATION_ID", privateKeyPath: "KEY_PATH" }
327
+ }
328
+ },
329
+ project: 1,
330
+ checkoutRoots: [],
331
+ pointsField: "Estimate",
332
+ priorityField: "Urgency",
333
+ statusField: "Flow",
334
+ statuses: syntheticDiscoveryConfig.native.project.statuses
335
+ })
336
+ );
337
+ vi.spyOn(githubClients, "createDeliveryGitHubClients").mockImplementation(async (input) => {
338
+ assert.equal(input.role, "author");
339
+ return {
340
+ role: "author",
341
+ authSource: "personal",
342
+ authenticatedAuthor: async () => ({ actorLogin: "operator", credentialIdentity: "user:1" }),
343
+ rest: fixture.rest,
344
+ graphql: fixture.graphql
345
+ };
346
+ });
347
+ const server = createAiDeliveryMcpServer({ repoRoot: root });
348
+ const client = new Client({ name: "tracking-scenario", version: "1" });
349
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
350
+ async function call(name, args) {
351
+ const result = await client.callTool({ name, arguments: { repo: "example/widget", ...args } });
352
+ assert.equal(result.isError, void 0, JSON.stringify(result));
353
+ return JSON.parse(result.content[0].text);
354
+ }
355
+ async function refuse(name, args) {
356
+ const before = fixture.snapshot();
357
+ const refused = await client.callTool({ name, arguments: { repo: "example/widget", ...args } }).then(
358
+ (result) => result.isError === true,
359
+ () => true
360
+ );
361
+ assert.equal(refused, true, name);
362
+ assert.deepEqual(fixture.snapshot(), before, `${name} must not mutate stored native state or write count`);
363
+ }
364
+ const fields = {
365
+ issueType: "Task",
366
+ points: 2,
367
+ problem: "Legacy tracking needs a portable replacement.",
368
+ outcome: "Replacement tracking has an explicit native readback.",
369
+ acceptanceCriteria: [
370
+ {
371
+ behavior: "Invalid tracking requests leave native state unchanged.",
372
+ verifiedBy: "The synthetic MCP scenario compares stored state and writes."
373
+ }
374
+ ],
375
+ outOfScope: ["Implementing batch or deferral."],
376
+ openQuestions: [],
377
+ context: {
378
+ files: ["src/currentTrackingScenario.test.ts"],
379
+ evidence: ["https://github.com/example/widget/issues/17"]
380
+ },
381
+ draft: false
382
+ };
383
+ try {
384
+ await server.connect(serverTransport);
385
+ await client.connect(clientTransport);
386
+ assert.equal(existsSync(join(root, ".git")), false);
387
+ const tools = (await client.listTools()).tools.map((tool) => tool.name);
388
+ for (const name of ["issue_list", "issue_search", "issue_update", "issue_create", "issue_comment", "issue_info"])
389
+ assert.ok(tools.includes(name));
390
+ const original = await call("issue_list", {
391
+ parentIssueNumber: 10,
392
+ state: "all"
393
+ });
394
+ assert.deepEqual(
395
+ original.issues.map((issue) => issue.number),
396
+ [17, 18]
397
+ );
398
+ const found = await call("issue_search", { query: "Legacy", state: "all" });
399
+ assert.deepEqual(
400
+ found.issues.map((issue) => issue.number),
401
+ [17]
402
+ );
403
+ await refuse("issue_update", { issueNumber: 17, points: "two" });
404
+ const rewritten = await call("issue_update", {
405
+ ...fields,
406
+ issueNumber: 17,
407
+ title: "Replacement tracking issue",
408
+ preserveHistory: true,
409
+ verbose: true
410
+ });
411
+ const expectedHistory = "<details>\n<summary>Previous issue title and body</summary>\n\nTitle:\n<pre> Legacy &lt;tracking&gt; &amp; title\r\n</pre>\n\nBody:\n<pre>\nLegacy &amp; backlog &lt;tag&gt; \r\n</pre>\n\n</details>";
412
+ assert.equal(rewritten.historyComment.body, expectedHistory);
413
+ assert.equal(fixture.comments[0].body, expectedHistory);
414
+ assert.equal(fixture.comments[0].user.login, "operator");
415
+ const historyRead = fixture.events.indexOf("comment:read:101");
416
+ assert.ok(historyRead >= 0 && historyRead < fixture.events.indexOf("issue:update:17"));
417
+ assert.equal(rewritten.title, fixture.issues.get(17).title);
418
+ assert.equal(rewritten.body, fixture.issues.get(17).body);
419
+ const created = await call("issue_create", {
420
+ ...fields,
421
+ title: "Replacement sized child",
422
+ priority: "High",
423
+ parentIssueNumber: 20
424
+ });
425
+ assert.equal(created.created.number, 31);
426
+ const child = await call("issue_info", { issueNumber: created.created.number });
427
+ assert.equal(child.points, 2);
428
+ assert.equal(child.priority, "High");
429
+ assert.equal(child.issueType, "Task");
430
+ assert.equal(child.parentIssueNumber, 20);
431
+ assert.equal(child.projectStatus, "Todo");
432
+ assert.equal(fixture.issues.get(31).parent, 20);
433
+ await refuse("issue_batch", { issues: [17, 18], parentIssueNumber: 20 });
434
+ for (const issueNumber of [17, 18]) {
435
+ const moved = await call("issue_update", { issueNumber, parentIssueNumber: 20 });
436
+ assert.equal(moved.parentIssueNumber, 20);
437
+ assert.equal(fixture.issues.get(issueNumber).parent, 20);
438
+ }
439
+ assert.deepEqual(
440
+ (await call("issue_list", { parentIssueNumber: 10, state: "all" })).issues,
441
+ []
442
+ );
443
+ assert.deepEqual(
444
+ (await call("issue_list", { parentIssueNumber: 20, state: "all" })).issues.map(
445
+ (issue) => issue.number
446
+ ),
447
+ [17, 18, 31]
448
+ );
449
+ for (const number of [10, 20])
450
+ assert.equal((await call("issue_info", { issueNumber: number })).points, void 0);
451
+ const journal = await call("issue_comment", {
452
+ verbose: true,
453
+ issueNumber: 31,
454
+ kind: "progress",
455
+ summary: "Tracking replay is verified.",
456
+ status: "In progress",
457
+ done: ["Reparented two issues individually."],
458
+ decisionNeeded: "None",
459
+ keyNumbers: [],
460
+ evidence: [created.created.url],
461
+ nextStep: "Review",
462
+ nextDate: "2026-10-09"
463
+ });
464
+ const storedJournal = fixture.comments.find((comment) => comment.id === journal.commentId);
465
+ assert.equal(storedJournal.body, journal.body);
466
+ assert.equal(storedJournal.html_url, journal.url);
467
+ assert.equal(storedJournal.user.login, "operator");
468
+ assert.match(journal.body, /Tracking replay is verified/u);
469
+ await refuse("issue_defer", { issueNumber: 17, trigger: "After review" });
470
+ const deferred = await call("issue_update", { issueNumber: 17, defer: { trigger: "After review" } });
471
+ assert.deepEqual(deferred.deferred, { trigger: "After review" });
472
+ assert.deepEqual((await call("issue_info", { issueNumber: 17 })).deferred, { trigger: "After review" });
473
+ const undeferred = await call("issue_update", { issueNumber: 17, undefer: true });
474
+ assert.equal(undeferred.deferred, null);
475
+ const closed = await call("issue_update", { issueNumber: 17, state: "closed", closeReason: "not_planned", supersededBy: 31 });
476
+ assert.equal(closed.closure.state, "closed");
477
+ assert.equal(closed.closure.closeReason, "not_planned");
478
+ assert.equal(closed.closure.supersededBy, 31);
479
+ assert.equal(closed.projectStatus, "Done");
480
+ assert.equal(fixture.issues.get(17).reason, "NOT_PLANNED");
481
+ assert.equal(fixture.issues.get(17).status, "Shipped");
482
+ assert.equal(
483
+ fixture.comments.find((comment) => comment.id === closed.closure.comment.commentId).body,
484
+ "Requested closure reason: not_planned.\nSuperseded by example/widget#31."
485
+ );
486
+ const final = await call("issue_info", { issueNumber: 17 });
487
+ assert.equal(final.state, "closed");
488
+ assert.equal(final.parentIssueNumber, 20);
489
+ assert.equal(final.projectStatus, "Done");
490
+ const finalSearch = await call("issue_search", {
491
+ query: "Replacement",
492
+ state: "all"
493
+ });
494
+ assert.deepEqual(
495
+ finalSearch.issues.map(({ number, state }) => ({ number, state })),
496
+ [
497
+ { number: 20, state: "open" },
498
+ { number: 17, state: "closed" },
499
+ { number: 31, state: "open" }
500
+ ]
501
+ );
502
+ assert.ok(fixture.writes() > 0);
503
+ assert.equal(existsSync(join(root, ".git")), false);
504
+ } finally {
505
+ await client.close();
506
+ await server.close();
507
+ vi.restoreAllMocks();
508
+ vi.unstubAllEnvs();
509
+ rmSync(root, { recursive: true, force: true });
510
+ }
491
511
  });
492
- //# sourceMappingURL=currentTrackingScenario.test.js.map
512
+ //# sourceMappingURL=currentTrackingScenario.test.js.map