@aviaratech/ai-delivery 0.3.35 → 0.3.37

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 +56 -554
  3. package/dist/agent.d.ts +1 -3
  4. package/dist/agent.js +74 -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 +91 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +389 -517
  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 +316 -354
  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 +63 -23
  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.d.ts +0 -3
  95. package/dist/git.js +59 -76
  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 +42 -52
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +1 -0
  106. package/dist/github/discovery.js +197 -215
  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 +18 -2
  121. package/dist/github/projectDelivery.js +615 -557
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.js +433 -389
  124. package/dist/github/relationships.js.map +7 -1
  125. package/dist/github/repo.d.ts +1 -0
  126. package/dist/github/repo.js +123 -96
  127. package/dist/github/repo.js.map +7 -1
  128. package/dist/index.js +3 -3
  129. package/dist/index.js.map +7 -1
  130. package/dist/issue.d.ts +40 -9
  131. package/dist/issue.js +2102 -1742
  132. package/dist/issue.js.map +7 -1
  133. package/dist/issue63History.test.js +40 -42
  134. package/dist/issue63History.test.js.map +7 -1
  135. package/dist/issue63Routes.test.js +154 -143
  136. package/dist/issue63Routes.test.js.map +7 -1
  137. package/dist/issueBatchUpdate.test.js +989 -885
  138. package/dist/issueBatchUpdate.test.js.map +7 -1
  139. package/dist/issueBlockerGuard.test.js +262 -226
  140. package/dist/issueBlockerGuard.test.js.map +7 -1
  141. package/dist/issueContract.d.ts +23 -4
  142. package/dist/issueContract.js +416 -395
  143. package/dist/issueContract.js.map +7 -1
  144. package/dist/issueContract.test.d.ts +4 -3
  145. package/dist/issueContract.test.js +358 -321
  146. package/dist/issueContract.test.js.map +7 -1
  147. package/dist/issueDates.test.js +235 -233
  148. package/dist/issueDates.test.js.map +7 -1
  149. package/dist/issueInfoReadback.test.js +304 -190
  150. package/dist/issueInfoReadback.test.js.map +7 -1
  151. package/dist/issueIntake.test.js +1938 -1732
  152. package/dist/issueIntake.test.js.map +7 -1
  153. package/dist/issueJournal.d.ts +40 -19
  154. package/dist/issueJournal.js +229 -138
  155. package/dist/issueJournal.js.map +7 -1
  156. package/dist/issueJournal.test.js +605 -422
  157. package/dist/issueJournal.test.js.map +7 -1
  158. package/dist/issueRollup.test.d.ts +1 -0
  159. package/dist/issueRollup.test.js +476 -0
  160. package/dist/issueRollup.test.js.map +7 -0
  161. package/dist/issueTracking.test.js +1059 -989
  162. package/dist/issueTracking.test.js.map +7 -1
  163. package/dist/issueWriteRecovery.test.d.ts +1 -0
  164. package/dist/issueWriteRecovery.test.js +260 -0
  165. package/dist/issueWriteRecovery.test.js.map +7 -0
  166. package/dist/lifecycle.test.js +112 -441
  167. package/dist/lifecycle.test.js.map +7 -1
  168. package/dist/logger.js +80 -74
  169. package/dist/logger.js.map +7 -1
  170. package/dist/mcp/index.js +116 -94
  171. package/dist/mcp/index.js.map +7 -1
  172. package/dist/mcp/tools.d.ts +252 -310
  173. package/dist/mcp/tools.js +235 -342
  174. package/dist/mcp/tools.js.map +7 -1
  175. package/dist/pluginAuthProbe.js +63 -52
  176. package/dist/pluginAuthProbe.js.map +7 -1
  177. package/dist/pluginAuthProbe.test.js +85 -62
  178. package/dist/pluginAuthProbe.test.js.map +7 -1
  179. package/dist/pluginCredentials.test.js +282 -259
  180. package/dist/pluginCredentials.test.js.map +7 -1
  181. package/dist/pluginDoctor.test.js +653 -588
  182. package/dist/pluginDoctor.test.js.map +7 -1
  183. package/dist/pluginInstaller.d.ts +7 -5
  184. package/dist/pluginInstaller.js +1173 -1229
  185. package/dist/pluginInstaller.js.map +7 -1
  186. package/dist/pluginInstaller.test.js +1842 -1423
  187. package/dist/pluginInstaller.test.js.map +7 -1
  188. package/dist/pluginPackaging.test.js +417 -413
  189. package/dist/pluginPackaging.test.js.map +7 -1
  190. package/dist/pr.d.ts +114 -131
  191. package/dist/pr.js +1314 -1327
  192. package/dist/pr.js.map +7 -1
  193. package/dist/pr.test.js +967 -653
  194. package/dist/pr.test.js.map +7 -1
  195. package/dist/prAssociation.test.js +2419 -1788
  196. package/dist/prAssociation.test.js.map +7 -1
  197. package/dist/prDispatch.test.js +123 -89
  198. package/dist/prDispatch.test.js.map +7 -1
  199. package/dist/readView.d.ts +184 -0
  200. package/dist/readView.js +218 -0
  201. package/dist/readView.js.map +7 -0
  202. package/dist/readView.test.d.ts +1 -0
  203. package/dist/readView.test.js +146 -0
  204. package/dist/readView.test.js.map +7 -0
  205. package/dist/releaseReconciliation.test.js +267 -288
  206. package/dist/releaseReconciliation.test.js.map +7 -1
  207. package/dist/releaseWorkflow.test.js +2493 -422
  208. package/dist/releaseWorkflow.test.js.map +7 -1
  209. package/dist/review.d.ts +738 -2
  210. package/dist/review.js +601 -348
  211. package/dist/review.js.map +7 -1
  212. package/dist/review.test.js +1218 -812
  213. package/dist/review.test.js.map +7 -1
  214. package/dist/reviewSubmit.test.d.ts +1 -0
  215. package/dist/reviewSubmit.test.js +747 -0
  216. package/dist/reviewSubmit.test.js.map +7 -0
  217. package/dist/services/agentReadinessService.js +42 -37
  218. package/dist/services/agentReadinessService.js.map +7 -1
  219. package/dist/services/blockerGuardService.js +188 -188
  220. package/dist/services/blockerGuardService.js.map +7 -1
  221. package/dist/services/boardReconcileService.d.ts +125 -125
  222. package/dist/services/boardReconcileService.js +1295 -1421
  223. package/dist/services/boardReconcileService.js.map +7 -1
  224. package/dist/services/deliveryHealthService.js +197 -199
  225. package/dist/services/deliveryHealthService.js.map +7 -1
  226. package/dist/services/legacyIssueMigration.js +263 -277
  227. package/dist/services/legacyIssueMigration.js.map +7 -1
  228. package/dist/stagedChecks.test.js +396 -194
  229. package/dist/stagedChecks.test.js.map +7 -1
  230. package/dist/start.test.js +99 -95
  231. package/dist/start.test.js.map +7 -1
  232. package/dist/stdoutRegression.test.js +321 -358
  233. package/dist/stdoutRegression.test.js.map +7 -1
  234. package/dist/targetPolicyDiscovery.test.js +141 -143
  235. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  236. package/dist/targetPolicyEntrypoints.test.js +308 -269
  237. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  238. package/dist/targetPolicyLocal.test.js +580 -1051
  239. package/dist/targetPolicyLocal.test.js.map +7 -1
  240. package/dist/targetPolicyRoutes.test.js +274 -281
  241. package/dist/targetPolicyRoutes.test.js.map +7 -1
  242. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  243. package/dist/targetRepositoryExecution.test.js +451 -0
  244. package/dist/targetRepositoryExecution.test.js.map +7 -0
  245. package/dist/terminalMessages.js +41 -35
  246. package/dist/terminalMessages.js.map +7 -1
  247. package/dist/toolOutput.d.ts +2 -0
  248. package/dist/toolOutput.js +36 -0
  249. package/dist/toolOutput.js.map +7 -0
  250. package/dist/toolOutput.test.d.ts +1 -0
  251. package/dist/toolOutput.test.js +240 -0
  252. package/dist/toolOutput.test.js.map +7 -0
  253. package/dist/utils/atomicJson.d.ts +0 -2
  254. package/dist/utils/atomicJson.js +81 -77
  255. package/dist/utils/atomicJson.js.map +7 -1
  256. package/dist/utils/filesystem.d.ts +0 -8
  257. package/dist/utils/filesystem.js +5 -19
  258. package/dist/utils/filesystem.js.map +7 -1
  259. package/dist/utils/lockfile.js +68 -71
  260. package/dist/utils/lockfile.js.map +7 -1
  261. package/dist/verification.d.ts +1 -54
  262. package/dist/verification.js +976 -1941
  263. package/dist/verification.js.map +7 -1
  264. package/dist/verificationGate.test.js +127 -117
  265. package/dist/verificationGate.test.js.map +7 -1
  266. package/dist/version.js +45 -24
  267. package/dist/version.js.map +7 -1
  268. package/package.json +9 -8
  269. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  270. package/plugins/ai-delivery/README.md +47 -156
  271. package/plugins/ai-delivery/plugin.json +1 -1
  272. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
  273. package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
  274. package/plugins/ai-delivery/runtime/package.json +1 -1
  275. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  276. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  277. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  278. package/dist/investigationCompletion.test.js +0 -728
  279. package/dist/investigationCompletion.test.js.map +0 -1
  280. package/dist/services/deliveryAdmission.d.ts +0 -49
  281. package/dist/services/deliveryAdmission.js +0 -165
  282. package/dist/services/deliveryAdmission.js.map +0 -1
  283. package/dist/services/worktreeRegistry.d.ts +0 -434
  284. package/dist/services/worktreeRegistry.js +0 -1248
  285. package/dist/services/worktreeRegistry.js.map +0 -1
  286. package/dist/setup.d.ts +0 -60
  287. package/dist/setup.js +0 -585
  288. package/dist/setup.js.map +0 -1
  289. package/dist/setup.test.js +0 -3329
  290. package/dist/setup.test.js.map +0 -1
  291. package/dist/worktree.d.ts +0 -28
  292. package/dist/worktree.js +0 -188
  293. package/dist/worktree.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 → build.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
@@ -1,381 +1,344 @@
1
- import assert from 'node:assert/strict';
2
- import { execFileSync } from 'node:child_process';
3
- import { Console } from 'node:console';
4
- import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
5
- import { tmpdir } from 'node:os';
6
- import { join } from 'node:path';
7
- import { Octokit } from '@octokit/rest';
8
- import { afterEach, test, vi } from 'vitest';
9
- import { parseDeliveryConfig } from './config/deliveryConfig.js';
10
- import { syntheticDiscoveryConfig } from './fixtures/discovery.js';
11
- import { replaceParentIssue } from './github/relationships.js';
12
- import { IssueFields, renderIssueBody } from './issueContract.js';
13
- import { CLIError, handleCommandError, logDebug, logError, logInfo, logProgress, logSuccess, logWarn, setLogsSuppressed, } from './logger.js';
14
- import { addWorktreeEntry, removeWorktreeEntry } from './services/worktreeRegistry.js';
15
- // Project/field metadata is unrelated to stream routing. Keep these provider
16
- // adapters local while exercising real parent linking, issue start and dispatch.
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { Console } from "node:console";
4
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { Octokit } from "@octokit/rest";
8
+ import { afterEach, test, vi } from "vitest";
9
+ import { parseDeliveryConfig } from "./config/deliveryConfig.js";
10
+ import { syntheticDiscoveryConfig } from "./fixtures/discovery.js";
11
+ import { replaceParentIssue } from "./github/relationships.js";
12
+ import { IssueFields, renderIssueBody } from "./issueContract.js";
13
+ import {
14
+ CLIError,
15
+ handleCommandError,
16
+ logDebug,
17
+ logError,
18
+ logInfo,
19
+ logProgress,
20
+ logSuccess,
21
+ logWarn,
22
+ setLogsSuppressed
23
+ } from "./logger.js";
17
24
  const projectReadback = vi.hoisted(() => ({ value: null }));
18
- vi.mock('./github/nativeIssueMetadata.js', async (importOriginal) => ({
19
- ...(await importOriginal()),
20
- getConfiguredNativeIssueMetadata: async () => ({ points: 2 }),
21
- setConfiguredNativeIssueMetadata: async () => ({ points: 2 }),
22
- clearConfiguredNativeIssuePoints: async () => { },
25
+ vi.mock("./github/nativeIssueMetadata.js", async (importOriginal) => ({
26
+ ...await importOriginal(),
27
+ getConfiguredNativeIssueMetadata: async () => ({ points: 2 }),
28
+ setConfiguredNativeIssueMetadata: async () => ({ points: 2 }),
29
+ clearConfiguredNativeIssuePoints: async () => {
30
+ }
23
31
  }));
24
- vi.mock('./github/projectDelivery.js', async (importOriginal) => ({
25
- ...(await importOriginal()),
26
- assertIssueProjectWritable: async () => { },
27
- getIssueProjectStatus: async () => projectReadback.value,
28
- syncIssueProjectStatus: async ({ status }) => (projectReadback.value = { itemId: 'SYNTHETIC-PROJECT-ITEM', status }),
32
+ vi.mock("./github/projectDelivery.js", async (importOriginal) => ({
33
+ ...await importOriginal(),
34
+ assertIssueProjectWritable: async () => {
35
+ },
36
+ getIssueProjectStatus: async () => projectReadback.value,
37
+ syncIssueProjectStatus: async ({ status }) => projectReadback.value = { itemId: "SYNTHETIC-PROJECT-ITEM", status }
29
38
  }));
30
39
  afterEach(() => {
31
- projectReadback.value = null;
32
- vi.restoreAllMocks();
33
- vi.unstubAllEnvs();
34
- setLogsSuppressed(false);
40
+ projectReadback.value = null;
41
+ vi.restoreAllMocks();
42
+ vi.unstubAllEnvs();
43
+ setLogsSuppressed(false);
35
44
  });
36
- const readyBody = renderIssueBody(IssueFields.parse({
37
- title: 'Synthetic change',
38
- issueType: 'Task',
45
+ const readyBody = renderIssueBody(
46
+ IssueFields.parse({
47
+ title: "Synthetic change",
48
+ issueType: "Task",
39
49
  points: 2,
40
- problem: 'Parent-link diagnostics can corrupt the CLI JSON result.',
41
- outcome: 'Return one parseable JSON result after parent linking or branch failure.',
50
+ problem: "Parent-link diagnostics can corrupt the CLI JSON result.",
51
+ outcome: "Return one parseable JSON result after parent linking or branch failure.",
42
52
  acceptanceCriteria: [
43
- {
44
- behavior: 'Parent linking leaves stdout as one JSON result and diagnostics on stderr.',
45
- verifiedBy: 'Byte-level CLI stream assertions.',
46
- },
53
+ {
54
+ behavior: "Parent linking leaves stdout as one JSON result and diagnostics on stderr.",
55
+ verifiedBy: "Byte-level CLI stream assertions."
56
+ }
47
57
  ],
48
- outOfScope: ['Live GitHub access and host configuration.'],
49
- context: { files: ['artifact.txt'] },
50
- }));
58
+ outOfScope: ["Live GitHub access and host configuration."],
59
+ context: { files: ["artifact.txt"] }
60
+ })
61
+ );
51
62
  function fixture(developmentFails = false) {
52
- const root = realpathSync(mkdtempSync(join(tmpdir(), 'ai-delivery-stdout-')));
53
- const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();
54
- git('init', '-q', '-b', 'main');
55
- git('config', 'user.name', 'Synthetic Delivery');
56
- git('config', 'user.email', 'delivery@example.test');
57
- writeFileSync(join(root, 'artifact.txt'), 'synthetic\n');
58
- git('add', 'artifact.txt');
59
- git('commit', '-qm', 'synthetic base');
60
- git('remote', 'add', 'origin', 'https://github.com/example/widget.git');
61
- git('update-ref', 'refs/remotes/origin/main', git('rev-parse', 'HEAD'));
62
- git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/main');
63
- let parent = null;
64
- const issue = {
65
- id: 170,
66
- number: 17,
67
- node_id: 'ISSUE-17',
68
- title: 'Synthetic change',
69
- body: readyBody,
70
- state: 'open',
71
- html_url: 'https://github.com/example/widget/issues/17',
72
- labels: [],
73
- type: { name: 'Task' },
74
- };
75
- const rest = new Octokit();
76
- rest.request = (async (route) => {
77
- if (route === 'GET /orgs/{org}/issue-fields')
78
- return {
79
- data: [
80
- { id: 101, name: 'Estimate', data_type: 'single_select' },
81
- { id: 102, name: 'Urgency', data_type: 'single_select' },
82
- ],
83
- };
84
- if (route === 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values')
85
- return {
86
- data: [
87
- {
88
- issue_field_id: 101,
89
- issue_field_name: 'Estimate',
90
- data_type: 'single_select',
91
- value: '2',
92
- single_select_option: { name: '2' },
93
- },
94
- ],
95
- };
96
- throw new Error(`Unexpected synthetic stdout REST operation: ${route}`);
97
- });
98
- Object.assign(rest.issues, {
99
- get: async ({ issue_number }) => ({
100
- data: issue_number === 17
101
- ? { ...issue, state: developmentFails ? 'closed' : 'open' }
102
- : { ...issue, number: issue_number, id: issue_number * 10, node_id: `ISSUE-${String(issue_number)}` },
103
- }),
104
- create: async (input) => {
105
- issue.title = input.title;
106
- issue.body = input.body;
107
- return { data: issue };
108
- },
109
- listForRepo: async () => ({ data: [] }),
110
- update: async (input) => {
111
- if (input.title !== undefined)
112
- issue.title = input.title;
113
- if (input.body !== undefined)
114
- issue.body = input.body;
115
- return { data: issue };
116
- },
117
- listSubIssues: async ({ issue_number }) => ({
118
- data: parent === issue_number ? [issue] : [],
119
- }),
120
- addSubIssue: async ({ issue_number }) => {
121
- parent = issue_number;
122
- return { data: issue };
123
- },
124
- });
125
- Object.assign(rest, {
126
- paginate: async (_route, { issue_number }) => parent === issue_number ? [issue] : [],
127
- });
128
- const clients = {
129
- authSource: 'personal',
130
- role: 'author',
131
- rest,
132
- graphql: (async (query) => {
133
- const page = { nodes: [], pageInfo: { endCursor: null, hasNextPage: false } };
134
- if (query.includes('blockedBy(')) {
135
- return {
136
- repository: {
137
- issue: {
138
- blockedBy: page,
139
- parent: parent === null
140
- ? null
141
- : { id: 'ISSUE-5', number: parent, repository: { nameWithOwner: 'example/widget' } },
142
- },
143
- },
144
- };
145
- }
146
- if (query.includes('blocking('))
147
- return { repository: { issue: { blocking: page } } };
148
- if (query.includes('subIssues('))
149
- return { repository: { issue: { subIssues: page } } };
150
- throw new Error('Unexpected synthetic stdout query.');
151
- }),
152
- };
153
- const config = parseDeliveryConfig({
154
- ...syntheticDiscoveryConfig,
155
- schemaVersion: 'ai-delivery.config@2',
156
- policy: { contract: 'RepositoryDeliveryPolicy@1', module: './policy.mjs' },
157
- roles: {
158
- author: { identity: 'host-author', authSource: 'personal', credentialEnv: { token: 'AUTHOR_TOKEN' } },
159
- reviewer: {
160
- identity: 'synthetic-reviewer',
161
- credentialEnv: {
162
- appId: 'REVIEWER_APP_ID',
163
- installationId: 'REVIEWER_INSTALLATION_ID',
164
- privateKeyPath: 'REVIEWER_KEY_PATH',
165
- },
166
- },
167
- },
168
- commandPolicy: {
169
- checks: { format: 'REQUIRED', gitClean: 'REQUIRED', lint: 'REQUIRED', test: 'REQUIRED', typecheck: 'REQUIRED' },
170
- timeoutsMs: { lint: 60000, test: 60000, typecheck: 60000 },
171
- },
172
- });
173
- return {
174
- context: { root, repo: { owner: 'example', repo: 'widget' }, clients, config },
175
- cleanup: () => rmSync(root, { recursive: true, force: true }),
176
- };
177
- }
178
- function captureStreams() {
179
- const output = { stdout: '', stderr: '' };
180
- const previousConsole = globalThis.console;
181
- // Vitest intercepts console calls before they reach process streams. Use a
182
- // native console so the byte-level capture matches an actual CLI process.
183
- globalThis.console = new Console(process.stdout, process.stderr);
184
- const out = vi.spyOn(process.stdout, 'write').mockImplementation((value) => {
185
- output.stdout += String(value);
186
- return true;
187
- });
188
- const err = vi.spyOn(process.stderr, 'write').mockImplementation((value) => {
189
- output.stderr += String(value);
190
- return true;
191
- });
192
- return {
193
- output,
194
- restore: () => {
195
- out.mockRestore();
196
- err.mockRestore();
197
- globalThis.console = previousConsole;
198
- },
199
- };
200
- }
201
- test('parent replacement emits its diagnostic on stderr without writing any stdout bytes', async () => {
202
- const f = fixture();
203
- const capture = captureStreams();
204
- try {
205
- await replaceParentIssue({ ...f.context.clients, repo: f.context.repo, issueNumber: 17, parentIssueNumber: 5 });
206
- assert.equal(capture.output.stdout, '');
207
- assert.match(capture.output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
208
- }
209
- finally {
210
- capture.restore();
211
- f.cleanup();
63
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "ai-delivery-stdout-")));
64
+ const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
65
+ git("init", "-q", "-b", "main");
66
+ git("config", "user.name", "Synthetic Delivery");
67
+ git("config", "user.email", "delivery@example.test");
68
+ writeFileSync(join(root, "artifact.txt"), "synthetic\n");
69
+ git("add", "artifact.txt");
70
+ git("commit", "-qm", "synthetic base");
71
+ git("remote", "add", "origin", "https://github.com/example/widget.git");
72
+ git("update-ref", "refs/remotes/origin/main", git("rev-parse", "HEAD"));
73
+ git("symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main");
74
+ let parent = null;
75
+ const issue = {
76
+ id: 170,
77
+ number: 17,
78
+ node_id: "ISSUE-17",
79
+ title: "Synthetic change",
80
+ body: readyBody,
81
+ state: "open",
82
+ html_url: "https://github.com/example/widget/issues/17",
83
+ labels: [],
84
+ type: { name: "Task" }
85
+ };
86
+ const rest = new Octokit();
87
+ rest.request = (async (route) => {
88
+ if (route === "GET /orgs/{org}/issue-fields")
89
+ return {
90
+ data: [
91
+ { id: 101, name: "Estimate", data_type: "single_select" },
92
+ { id: 102, name: "Urgency", data_type: "single_select" }
93
+ ]
94
+ };
95
+ if (route === "GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values")
96
+ return {
97
+ data: [
98
+ {
99
+ issue_field_id: 101,
100
+ issue_field_name: "Estimate",
101
+ data_type: "single_select",
102
+ value: "2",
103
+ single_select_option: { name: "2" }
104
+ }
105
+ ]
106
+ };
107
+ throw new Error(`Unexpected synthetic stdout REST operation: ${route}`);
108
+ });
109
+ Object.assign(rest.issues, {
110
+ get: async ({ issue_number }) => ({
111
+ data: issue_number === 17 ? { ...issue, state: developmentFails ? "closed" : "open" } : { ...issue, number: issue_number, id: issue_number * 10, node_id: `ISSUE-${String(issue_number)}` }
112
+ }),
113
+ create: async (input) => {
114
+ issue.title = input.title;
115
+ issue.body = input.body;
116
+ return { data: issue };
117
+ },
118
+ listForRepo: async () => ({ data: [] }),
119
+ update: async (input) => {
120
+ if (input.title !== void 0) issue.title = input.title;
121
+ if (input.body !== void 0) issue.body = input.body;
122
+ return { data: issue };
123
+ },
124
+ listSubIssues: async ({ issue_number }) => ({
125
+ data: parent === issue_number ? [issue] : []
126
+ }),
127
+ addSubIssue: async ({ issue_number }) => {
128
+ parent = issue_number;
129
+ return { data: issue };
212
130
  }
213
- });
214
- test.each(['add', 'remove'])('registry %s emits its diagnostic without writing any stdout bytes', async (operation) => {
215
- const f = fixture();
216
- const row = {
217
- path: join(f.context.root, '.worktrees', 'synthetic'),
218
- branch: 'issue/17',
219
- type: 'issue',
220
- issueNumber: 17,
221
- identity: 'host-author',
222
- status: 'active',
223
- createdAt: '2026-10-08T00:00:00Z',
224
- updatedAt: '2026-10-08T00:00:00Z',
225
- };
226
- const capture = captureStreams();
227
- try {
228
- await addWorktreeEntry(row, f.context.root);
229
- if (operation === 'remove') {
230
- capture.output.stdout = '';
231
- capture.output.stderr = '';
232
- assert.equal(await removeWorktreeEntry(row.path, f.context.root), true);
131
+ });
132
+ Object.assign(rest, {
133
+ paginate: async (_route, { issue_number }) => parent === issue_number ? [issue] : []
134
+ });
135
+ const clients = {
136
+ authSource: "personal",
137
+ role: "author",
138
+ rest,
139
+ graphql: (async (query) => {
140
+ const page = { nodes: [], pageInfo: { endCursor: null, hasNextPage: false } };
141
+ if (query.includes("blockedBy(")) {
142
+ return {
143
+ repository: {
144
+ issue: {
145
+ blockedBy: page,
146
+ parent: parent === null ? null : { id: "ISSUE-5", number: parent, repository: { nameWithOwner: "example/widget" } }
147
+ }
148
+ }
149
+ };
150
+ }
151
+ if (query.includes("blocking(")) return { repository: { issue: { blocking: page } } };
152
+ if (query.includes("subIssues(")) return { repository: { issue: { subIssues: page } } };
153
+ throw new Error("Unexpected synthetic stdout query.");
154
+ })
155
+ };
156
+ const config = parseDeliveryConfig({
157
+ ...syntheticDiscoveryConfig,
158
+ schemaVersion: "ai-delivery.config@2",
159
+ policy: { contract: "RepositoryDeliveryPolicy@1", module: "./policy.mjs" },
160
+ roles: {
161
+ author: { identity: "host-author", authSource: "personal", credentialEnv: { token: "AUTHOR_TOKEN" } },
162
+ reviewer: {
163
+ identity: "synthetic-reviewer",
164
+ credentialEnv: {
165
+ appId: "REVIEWER_APP_ID",
166
+ installationId: "REVIEWER_INSTALLATION_ID",
167
+ privateKeyPath: "REVIEWER_KEY_PATH"
233
168
  }
234
- assert.equal(capture.output.stdout, '');
235
- assert.match(capture.output.stderr, operation === 'add' ? /Added to worktree registry:/u : /Removed from worktree registry:/u);
169
+ }
170
+ },
171
+ commandPolicy: {
172
+ checks: { format: "REQUIRED", gitClean: "REQUIRED", lint: "REQUIRED", test: "REQUIRED", typecheck: "REQUIRED" },
173
+ timeoutsMs: { lint: 6e4, test: 6e4, typecheck: 6e4 }
236
174
  }
237
- finally {
238
- capture.restore();
239
- f.cleanup();
175
+ });
176
+ return {
177
+ context: { root, repo: { owner: "example", repo: "widget" }, clients, config },
178
+ cleanup: () => rmSync(root, { recursive: true, force: true })
179
+ };
180
+ }
181
+ function captureStreams() {
182
+ const output = { stdout: "", stderr: "" };
183
+ const previousConsole = globalThis.console;
184
+ globalThis.console = new Console(process.stdout, process.stderr);
185
+ const out = vi.spyOn(process.stdout, "write").mockImplementation((value) => {
186
+ output.stdout += String(value);
187
+ return true;
188
+ });
189
+ const err = vi.spyOn(process.stderr, "write").mockImplementation((value) => {
190
+ output.stderr += String(value);
191
+ return true;
192
+ });
193
+ return {
194
+ output,
195
+ restore: () => {
196
+ out.mockRestore();
197
+ err.mockRestore();
198
+ globalThis.console = previousConsole;
240
199
  }
200
+ };
201
+ }
202
+ test("parent replacement emits its diagnostic on stderr without writing any stdout bytes", async () => {
203
+ const f = fixture();
204
+ const capture = captureStreams();
205
+ try {
206
+ await replaceParentIssue({ ...f.context.clients, repo: f.context.repo, issueNumber: 17, parentIssueNumber: 5 });
207
+ assert.equal(capture.output.stdout, "");
208
+ assert.match(capture.output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
209
+ } finally {
210
+ capture.restore();
211
+ f.cleanup();
212
+ }
241
213
  });
242
214
  async function runCli(context, args) {
243
- vi.resetModules();
244
- const configuration = await import('./config/deliveryConfig.js');
245
- const issues = await import('./issue.js');
246
- const admission = await import('./services/deliveryAdmission.js');
247
- const prs = await import('./pr.js');
248
- const dispatch = await import('./dispatch.js');
249
- vi.spyOn(configuration, 'loadDeliverySettings').mockResolvedValue({
250
- ...context.config,
251
- configPath: 'synthetic-user.json',
252
- checkoutRoots: [],
253
- overrides: { schemaVersion: 'ai-delivery.config@2' },
254
- sourceDigest: 'synthetic',
255
- });
256
- vi.spyOn(issues, 'loadDeliveryContext').mockResolvedValue(context);
257
- // Synthetic authorization seams: these tests exercise streams, not live access.
258
- vi.spyOn(admission, 'assertDeliveryRuntimeAdmitted').mockResolvedValue({});
259
- vi.spyOn(prs, 'preflightReviewRoute').mockResolvedValue({});
260
- const argv = process.argv;
261
- const exitCode = process.exitCode;
262
- const capture = captureStreams();
263
- let completed = () => { };
264
- let failed = () => { };
265
- const resultWritten = new Promise((resolve, reject) => {
266
- completed = resolve;
267
- failed = reject;
268
- });
269
- const execute = dispatch.executeTool;
270
- vi.spyOn(dispatch, 'executeTool').mockImplementation(async (...input) => {
271
- try {
272
- return await execute(...input);
273
- }
274
- catch (error) {
275
- failed(error);
276
- throw error;
277
- }
278
- });
279
- vi.spyOn(process.stdout, 'write').mockImplementation((value) => {
280
- capture.output.stdout += String(value);
281
- // Wait for the result, not the earlier diagnostic chunk that reproduces #74.
282
- if (String(value).startsWith('{'))
283
- completed();
284
- return true;
285
- });
215
+ vi.resetModules();
216
+ const configuration = await import("./config/deliveryConfig.js");
217
+ const issues = await import("./issue.js");
218
+ const prs = await import("./pr.js");
219
+ const dispatch = await import("./dispatch.js");
220
+ vi.spyOn(configuration, "loadDeliverySettings").mockResolvedValue({
221
+ ...context.config,
222
+ configPath: "synthetic-user.json",
223
+ checkoutRoots: [],
224
+ overrides: { schemaVersion: "ai-delivery.config@2" },
225
+ sourceDigest: "synthetic"
226
+ });
227
+ vi.spyOn(issues, "loadDeliveryContext").mockResolvedValue(context);
228
+ vi.spyOn(prs, "preflightReviewRoute").mockResolvedValue({});
229
+ const argv = process.argv;
230
+ const exitCode = process.exitCode;
231
+ const capture = captureStreams();
232
+ let completed = () => {
233
+ };
234
+ let failed = () => {
235
+ };
236
+ const resultWritten = new Promise((resolve, reject) => {
237
+ completed = resolve;
238
+ failed = reject;
239
+ });
240
+ const execute = dispatch.executeTool;
241
+ vi.spyOn(dispatch, "executeTool").mockImplementation(async (...input) => {
286
242
  try {
287
- process.exitCode = undefined;
288
- process.argv = [process.execPath, 'ai-delivery', '--repo-root', context.root, '--identity', 'host-author', ...args];
289
- await import('./cli.js');
290
- await resultWritten;
291
- return { ...capture.output, exitCode: process.exitCode };
292
- }
293
- finally {
294
- capture.restore();
295
- vi.restoreAllMocks();
296
- process.argv = argv;
297
- process.exitCode = exitCode;
243
+ return await execute(...input);
244
+ } catch (error) {
245
+ failed(error);
246
+ throw error;
298
247
  }
248
+ });
249
+ vi.spyOn(process.stdout, "write").mockImplementation((value) => {
250
+ capture.output.stdout += String(value);
251
+ if (String(value).startsWith("{")) completed();
252
+ return true;
253
+ });
254
+ try {
255
+ process.exitCode = void 0;
256
+ process.argv = [process.execPath, "ai-delivery", "--repo-root", context.root, "--identity", "host-author", ...args];
257
+ await import("./cli.js");
258
+ await resultWritten;
259
+ return { ...capture.output, exitCode: process.exitCode };
260
+ } finally {
261
+ capture.restore();
262
+ vi.restoreAllMocks();
263
+ process.argv = argv;
264
+ process.exitCode = exitCode;
265
+ }
299
266
  }
300
- test('parent update through the CLI entry produces one parseable JSON result', async () => {
301
- const f = fixture();
302
- try {
303
- const output = await runCli(f.context, ['update', '--issue', '17', '--parent', '5']);
304
- const result = JSON.parse(output.stdout);
305
- assert.equal(result.issueNumber, 17);
306
- assert.equal(result.parentIssueNumber, 5);
307
- assert.equal(output.exitCode, undefined);
308
- assert.match(output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
309
- }
310
- finally {
311
- f.cleanup();
312
- }
267
+ test("parent update through the CLI entry produces one parseable JSON result", async () => {
268
+ const f = fixture();
269
+ try {
270
+ const output = await runCli(f.context, ["update", "--issue", "17", "--parent", "5"]);
271
+ const result = JSON.parse(output.stdout);
272
+ assert.equal(result.issueNumber, 17);
273
+ assert.equal(result.parentIssueNumber, 5);
274
+ assert.equal(output.exitCode, void 0);
275
+ assert.match(output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
276
+ } finally {
277
+ f.cleanup();
278
+ }
313
279
  });
314
- test('failed remote branch start after parent linking preserves parseable CLI recovery JSON and nonzero exit', async () => {
315
- const f = fixture(true);
316
- try {
317
- const output = await runCli(f.context, [
318
- 'start',
319
- '--title',
320
- 'Synthetic change',
321
- '--body',
322
- readyBody,
323
- '--parent',
324
- '5',
325
- ]);
326
- const result = JSON.parse(output.stdout);
327
- assert.equal(result.status, 'created-not-started');
328
- assert.equal(result.createdIssue.number, 17);
329
- assert.equal(result.failure.phase, 'branch-or-journal');
330
- assert.match(result.failure.message, /open GitHub issue/u);
331
- assert.equal(result.safeResume.arguments.issueNumber, 17);
332
- assert.equal('parentIssueNumber' in result.safeResume.arguments, false);
333
- assert.equal('resumeCreated' in result.safeResume.arguments, false);
334
- assert.equal(output.exitCode, 1);
335
- assert.match(output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
336
- }
337
- finally {
338
- f.cleanup();
339
- }
280
+ test("failed remote branch start after parent linking preserves parseable CLI recovery JSON and nonzero exit", async () => {
281
+ const f = fixture(true);
282
+ try {
283
+ const output = await runCli(f.context, [
284
+ "start",
285
+ "--title",
286
+ "Synthetic change",
287
+ "--body",
288
+ readyBody,
289
+ "--parent",
290
+ "5"
291
+ ]);
292
+ const result = JSON.parse(output.stdout);
293
+ assert.equal(result.status, "created-not-started");
294
+ assert.equal(result.createdIssue.number, 17);
295
+ assert.equal(result.failure.phase, "branch-or-journal");
296
+ assert.match(result.failure.message, /open GitHub issue/u);
297
+ assert.equal(result.safeResume.arguments.issueNumber, 17);
298
+ assert.equal("parentIssueNumber" in result.safeResume.arguments, false);
299
+ assert.equal("resumeCreated" in result.safeResume.arguments, false);
300
+ assert.equal(output.exitCode, 1);
301
+ assert.match(output.stderr, /Linked issue #17 as sub-issue of issue #5\./u);
302
+ } finally {
303
+ f.cleanup();
304
+ }
340
305
  });
341
- test('all enabled diagnostics preserve their content on stderr', () => {
342
- vi.stubEnv('DEBUG', '1');
343
- const capture = captureStreams();
344
- try {
345
- logDebug('debug proof');
346
- logInfo('info proof');
347
- logSuccess('success proof');
348
- logWarn('warning proof');
349
- logError('error proof');
350
- logProgress('progress proof');
351
- handleCommandError(new CLIError('failure proof', { hint: 'retry proof' }));
352
- assert.equal(capture.output.stdout, '');
353
- for (const message of ['debug', 'info', 'success', 'warning', 'error', 'progress', 'failure', 'retry']) {
354
- assert.match(capture.output.stderr, new RegExp(`${message} proof`, 'u'));
355
- }
356
- }
357
- finally {
358
- capture.restore();
306
+ test("all enabled diagnostics preserve their content on stderr", () => {
307
+ vi.stubEnv("DEBUG", "1");
308
+ const capture = captureStreams();
309
+ try {
310
+ logDebug("debug proof");
311
+ logInfo("info proof");
312
+ logSuccess("success proof");
313
+ logWarn("warning proof");
314
+ logError("error proof");
315
+ logProgress("progress proof");
316
+ handleCommandError(new CLIError("failure proof", { hint: "retry proof" }));
317
+ assert.equal(capture.output.stdout, "");
318
+ for (const message of ["debug", "info", "success", "warning", "error", "progress", "failure", "retry"]) {
319
+ assert.match(capture.output.stderr, new RegExp(`${message} proof`, "u"));
359
320
  }
321
+ } finally {
322
+ capture.restore();
323
+ }
360
324
  });
361
- test('MCP suppression still silences diagnostics while retaining errors and recovery hints on stderr', () => {
362
- vi.stubEnv('DEBUG', 'true');
363
- setLogsSuppressed(true);
364
- const capture = captureStreams();
365
- try {
366
- logDebug('hidden');
367
- logInfo('hidden');
368
- logSuccess('hidden');
369
- logWarn('hidden');
370
- logProgress('hidden');
371
- handleCommandError(new CLIError('visible error', { hint: 'visible recovery' }));
372
- assert.equal(capture.output.stdout, '');
373
- assert.doesNotMatch(capture.output.stderr, /hidden/u);
374
- assert.match(capture.output.stderr, /visible error/u);
375
- assert.match(capture.output.stderr, /visible recovery/u);
376
- }
377
- finally {
378
- capture.restore();
379
- }
325
+ test("MCP suppression still silences diagnostics while retaining errors and recovery hints on stderr", () => {
326
+ vi.stubEnv("DEBUG", "true");
327
+ setLogsSuppressed(true);
328
+ const capture = captureStreams();
329
+ try {
330
+ logDebug("hidden");
331
+ logInfo("hidden");
332
+ logSuccess("hidden");
333
+ logWarn("hidden");
334
+ logProgress("hidden");
335
+ handleCommandError(new CLIError("visible error", { hint: "visible recovery" }));
336
+ assert.equal(capture.output.stdout, "");
337
+ assert.doesNotMatch(capture.output.stderr, /hidden/u);
338
+ assert.match(capture.output.stderr, /visible error/u);
339
+ assert.match(capture.output.stderr, /visible recovery/u);
340
+ } finally {
341
+ capture.restore();
342
+ }
380
343
  });
381
- //# sourceMappingURL=stdoutRegression.test.js.map
344
+ //# sourceMappingURL=stdoutRegression.test.js.map