@aviaratech/ai-delivery 0.3.34 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,645 +1,710 @@
1
- import assert from 'node:assert/strict';
2
- import { createHash, generateKeyPairSync } from 'node:crypto';
3
- import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { dirname, join } from 'node:path';
6
- import { afterEach, beforeEach, test, vi } from 'vitest';
7
- import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from './fixtures/discovery.js';
8
- // Native selections, keys and HTTP responses below are fictional. This tests
9
- // the selected-process contract, not a GUI or an authenticated live service.
1
+ import assert from "node:assert/strict";
2
+ import { createHash, generateKeyPairSync } from "node:crypto";
3
+ import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { afterEach, beforeEach, test, vi } from "vitest";
7
+ import { syntheticDiscoveryClients, syntheticDiscoveryConfig } from "./fixtures/discovery.js";
10
8
  const fixture = vi.hoisted(() => ({
11
- home: '',
12
- config: '',
13
- root: '',
14
- host: 'codex',
15
- enabled: true,
16
- mode: 'success',
17
- authCalls: 0,
18
- machine: false,
19
- ghCalls: [],
20
- keyReads: 0,
21
- settingsReads: 0,
22
- requestErrorLogs: [],
23
- childStderrLines: [],
24
- commands: [],
25
- requests: [],
26
- startupEnvironments: [],
9
+ home: "",
10
+ config: "",
11
+ root: "",
12
+ host: "codex",
13
+ enabled: true,
14
+ mode: "success",
15
+ authCalls: 0,
16
+ machine: false,
17
+ ghCalls: [],
18
+ keyReads: 0,
19
+ settingsReads: 0,
20
+ requestErrorLogs: [],
21
+ childStderrLines: [],
22
+ commands: [],
23
+ requests: [],
24
+ startupEnvironments: []
27
25
  }));
28
- vi.mock('node:os', async (original) => ({
29
- ...(await original()),
30
- homedir: () => fixture.home,
26
+ vi.mock("node:os", async (original) => ({
27
+ ...await original(),
28
+ homedir: () => fixture.home
31
29
  }));
32
- vi.mock('node:fs', async (original) => {
33
- const actual = await original();
34
- return {
35
- ...actual,
36
- readFileSync: (...args) => {
37
- if (String(args[0]) === fixture.config)
38
- fixture.settingsReads++;
39
- if (String(args[0]).endsWith('.pem'))
40
- fixture.keyReads++;
41
- return actual.readFileSync(...args);
42
- },
43
- };
44
- });
45
- // Octokit binds console.error at module import. Capture its real request-log
46
- // hook through a logger sink instead of a later console spy, as subprocess
47
- // stderr would do. Requests, authentication and error owners remain real.
48
- vi.mock('@octokit/rest', async (original) => {
49
- const actual = await original();
50
- return {
51
- ...actual,
52
- Octokit: actual.Octokit.defaults({
53
- log: {
54
- debug: () => { },
55
- info: () => { },
56
- warn: () => { },
57
- error: (...values) => {
58
- const line = values.filter((value) => typeof value === 'string').join(' ');
59
- fixture.childStderrLines.push(line);
60
- fixture.requestErrorLogs.push(line);
61
- },
62
- },
63
- }),
64
- };
30
+ vi.mock("node:fs", async (original) => {
31
+ const actual = await original();
32
+ return {
33
+ ...actual,
34
+ readFileSync: (...args) => {
35
+ if (String(args[0]) === fixture.config) fixture.settingsReads++;
36
+ if (String(args[0]).endsWith(".pem")) fixture.keyReads++;
37
+ return actual.readFileSync(...args);
38
+ }
39
+ };
65
40
  });
66
- vi.mock('@modelcontextprotocol/sdk/client/stdio.js', async (original) => ({
67
- ...(await original()),
68
- StdioClientTransport: class {
69
- constructor(options) {
70
- fixture.startupEnvironments.push(options.env);
71
- }
72
- close() { }
73
- },
74
- }));
75
- vi.mock('@modelcontextprotocol/sdk/client/index.js', () => ({
76
- Client: class {
77
- connect() {
78
- if (fixture.mode === 'startup_failed')
79
- throw new Error('fictional-upstream-secret');
80
- }
81
- getServerVersion() {
82
- return { version: '0.3.24' };
83
- }
84
- listTools() {
85
- return { tools: [] };
41
+ vi.mock("@octokit/rest", async (original) => {
42
+ const actual = await original();
43
+ return {
44
+ ...actual,
45
+ Octokit: actual.Octokit.defaults({
46
+ log: {
47
+ debug: () => {
48
+ },
49
+ info: () => {
50
+ },
51
+ warn: () => {
52
+ },
53
+ error: (...values) => {
54
+ const line = values.filter((value) => typeof value === "string").join(" ");
55
+ fixture.childStderrLines.push(line);
56
+ fixture.requestErrorLogs.push(line);
86
57
  }
87
- close() { }
88
- },
58
+ }
59
+ })
60
+ };
61
+ });
62
+ vi.mock("@modelcontextprotocol/sdk/client/stdio.js", async (original) => ({
63
+ ...await original(),
64
+ StdioClientTransport: class {
65
+ constructor(options) {
66
+ fixture.startupEnvironments.push(options.env);
67
+ }
68
+ close() {
69
+ }
70
+ }
89
71
  }));
90
- vi.mock('./verification.js', async (original) => ({
91
- ...(await original()),
92
- runStageCommand: async (_root, args, _signal, _a, _b, _c, _d, writer, options) => {
93
- if (args[0] === process.execPath) {
94
- const { execFile } = await import('node:child_process');
95
- return new Promise((resolve, reject) => {
96
- execFile(process.execPath, args.slice(1), {
97
- env: options.environment,
98
- cwd: options.cwd ?? _root,
99
- maxBuffer: options.maxCapturedOutputBytes ?? 1024 * 1024,
100
- encoding: 'utf8',
101
- }, (error, stdout, stderr) => {
102
- writer?.idle();
103
- if (error) {
104
- options.failedOutput?.(Buffer.from(stdout + stderr));
105
- reject(new Error('Synthetic selected CLI failed; output withheld.'));
106
- }
107
- else
108
- resolve(Buffer.from(stdout));
109
- });
110
- });
111
- }
112
- fixture.commands.push({ args, environment: options.environment });
113
- assert.deepEqual(args, fixture.host === 'codex' && args.includes('--marketplace')
114
- ? ['codex', 'plugin', 'list', '--marketplace', 'ai-delivery-user', '--available', '--json']
115
- : fixture.host === 'codex'
116
- ? ['codex', 'plugin', 'list', '--json']
117
- : ['claude', 'plugin', 'list', '--json']);
118
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins', fixture.host, 'user/marketplace');
119
- const entry = { version: '0.3.24', enabled: fixture.enabled };
120
- return Buffer.from(JSON.stringify(fixture.host === 'codex'
121
- ? {
122
- installed: [
123
- {
124
- ...entry,
125
- pluginId: 'ai-delivery@ai-delivery-user',
126
- marketplaceName: 'ai-delivery-user',
127
- source: { source: 'local', path: join(catalog, 'versions/0.3.24/plugins/ai-delivery') },
128
- marketplaceSource: { sourceType: 'local', source: catalog },
129
- },
130
- ],
131
- available: [],
132
- }
133
- : [
134
- {
135
- ...entry,
136
- id: 'ai-delivery@ai-delivery-user',
137
- scope: 'user',
138
- installPath: fixture.root,
139
- mcpServers: {
140
- 'ai-delivery': { command: 'node', args: ['${CLAUDE_PLUGIN_ROOT}/dist/mcp-launcher.js'] },
141
- },
142
- },
143
- ]));
144
- },
72
+ vi.mock("@modelcontextprotocol/sdk/client/index.js", () => ({
73
+ Client: class {
74
+ connect() {
75
+ if (fixture.mode === "startup_failed") throw new Error("fictional-upstream-secret");
76
+ }
77
+ getServerVersion() {
78
+ return { version: "0.3.24" };
79
+ }
80
+ listTools() {
81
+ return { tools: [] };
82
+ }
83
+ close() {
84
+ }
85
+ }
145
86
  }));
146
- vi.mock('node:child_process', async (original) => ({
147
- ...(await original()),
148
- execFile: (binary, args, options, callback) => {
149
- if (args[0] === 'auth') {
150
- assert.equal(fixture.machine, true);
151
- assert.equal(binary, realpathSync(join(fixture.home, 'bin', 'gh')));
152
- assert.equal(options.maxBuffer, 64 * 1024);
153
- for (const name of [
154
- 'GH_TOKEN',
155
- 'GITHUB_TOKEN',
156
- 'DELIVERY_REVIEW_APP_ID',
157
- 'DELIVERY_REVIEW_INSTALLATION_ID',
158
- 'DELIVERY_REVIEW_KEY_PATH',
159
- 'NODE_OPTIONS',
160
- 'GH_DEBUG',
161
- 'UNRELATED_SERVICE_TOKEN',
162
- ])
163
- assert.equal(options.env[name], undefined);
164
- fixture.ghCalls.push(args);
165
- if (args[1] === 'status')
166
- callback(null, JSON.stringify({
167
- hosts: {
168
- 'github.com': [{ active: true, host: 'github.com', login: 'fixture-author-login', state: 'success' }],
169
- },
170
- }), 'fictional-opaque-stderr');
171
- else {
172
- assert.deepEqual(args, ['auth', 'token', '--hostname', 'github.com', '--user', 'fixture-author-login']);
173
- callback(null, 'fictional_machine_author_value', 'fictional-opaque-stderr');
174
- }
175
- return;
176
- }
177
- assert.equal(binary, process.execPath);
178
- assert.deepEqual(args, [join(fixture.root, 'runtime/dist/cli.js'), '--repo', args[2], 'config:resolve']);
179
- assert.equal(options.timeout, undefined);
180
- assert.equal(options.maxBuffer, 1024 * 1024);
181
- const forwarded = Object.keys(options.env).sort();
182
- assert.deepEqual(forwarded, (fixture.machine
183
- ? [
184
- 'AI_DELIVERY_CONFIG',
185
- 'DELIVERY_REVIEW_APP_ID',
186
- 'DELIVERY_REVIEW_INSTALLATION_ID',
187
- 'DELIVERY_REVIEW_KEY_PATH',
188
- 'DISABLE_AUTOUPDATER',
189
- 'HOME',
190
- 'LANG',
191
- 'LC_ALL',
192
- 'NODE_OPTIONS',
193
- 'PATH',
194
- ]
195
- : [
196
- 'AI_DELIVERY_CONFIG',
197
- 'DELIVERY_AUTHOR_TOKEN',
198
- 'DELIVERY_REVIEW_APP_ID',
199
- 'DELIVERY_REVIEW_INSTALLATION_ID',
200
- 'DELIVERY_REVIEW_KEY_PATH',
201
- 'DISABLE_AUTOUPDATER',
202
- 'NODE_OPTIONS',
203
- 'PATH',
204
- ]).sort());
205
- fixture.authCalls++;
206
- const run = async () => {
207
- if (fixture.mode === 'raw_failure') {
208
- callback(new Error('fictional-value-header'), 'fictional-value-body', 'fictional-value-key-path');
209
- return;
210
- }
211
- const ambient = process.env;
212
- process.env = { ...options.env };
213
- fixture.childStderrLines = [];
214
- try {
215
- const { contextFor } = await import('./dispatch.js');
216
- const { preflightReviewRoute } = await import('./pr.js');
217
- const context = await contextFor({ repoRoot: options.cwd, repo: args[2] }, 'config:resolve');
218
- const data = {
219
- routing: context.configuration.routing,
220
- reviewRoute: await preflightReviewRoute(context, undefined, undefined, 'development'),
221
- };
222
- if (fixture.mode === 'wrong_repo')
223
- data.routing.repository = 'example/unselected';
224
- if (fixture.mode === 'same_actor')
225
- data.reviewRoute.reviewer.actorLogin = data.reviewRoute.author.actorLogin;
226
- if (fixture.mode === 'secret_actor')
227
- data.reviewRoute.author.actorLogin = options.env.DELIVERY_AUTHOR_TOKEN;
228
- callback(null, JSON.stringify({
229
- ...data,
230
- untrustedBody: 'fictional-value-body',
231
- untrustedHeaders: 'fictional-value-header',
232
- }), 'fictional-value-key-path');
87
+ vi.mock("./verification.js", async (original) => ({
88
+ ...await original(),
89
+ runStageCommand: async (_root, args, _signal, _a, _b, _c, _d, writer, options) => {
90
+ if (args[0] === process.execPath) {
91
+ const { execFile } = await import("node:child_process");
92
+ return new Promise((resolve, reject) => {
93
+ execFile(
94
+ process.execPath,
95
+ args.slice(1),
96
+ {
97
+ env: options.environment,
98
+ cwd: options.cwd ?? _root,
99
+ maxBuffer: options.maxCapturedOutputBytes ?? 1024 * 1024,
100
+ encoding: "utf8"
101
+ },
102
+ (error, stdout, stderr) => {
103
+ writer?.idle();
104
+ if (error) {
105
+ options.failedOutput?.(Buffer.from(stdout + stderr));
106
+ reject(new Error("Synthetic selected CLI failed; output withheld."));
107
+ } else resolve(Buffer.from(stdout));
108
+ }
109
+ );
110
+ });
111
+ }
112
+ fixture.commands.push({ args, environment: options.environment });
113
+ assert.deepEqual(
114
+ args,
115
+ fixture.host === "codex" && args.includes("--marketplace") ? ["codex", "plugin", "list", "--marketplace", "ai-delivery-user", "--available", "--json"] : fixture.host === "codex" ? ["codex", "plugin", "list", "--json"] : ["claude", "plugin", "list", "--json"]
116
+ );
117
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins", fixture.host, "user/marketplace");
118
+ const entry = { version: "0.3.24", enabled: fixture.enabled };
119
+ return Buffer.from(
120
+ JSON.stringify(
121
+ fixture.host === "codex" ? {
122
+ installed: [
123
+ {
124
+ ...entry,
125
+ pluginId: "ai-delivery@ai-delivery-user",
126
+ marketplaceName: "ai-delivery-user",
127
+ source: { source: "local", path: join(catalog, "versions/0.3.24/plugins/ai-delivery") },
128
+ marketplaceSource: { sourceType: "local", source: catalog }
233
129
  }
234
- catch (error) {
235
- callback(new Error('Selected CLI failed'), '', [...fixture.childStderrLines, `ai-delivery: ${error instanceof Error ? error.message : 'unknown'}`].join('\n') + '\n');
130
+ ],
131
+ available: []
132
+ } : [
133
+ {
134
+ ...entry,
135
+ id: "ai-delivery@ai-delivery-user",
136
+ scope: "user",
137
+ installPath: fixture.root,
138
+ mcpServers: {
139
+ "ai-delivery": { command: "node", args: ["${CLAUDE_PLUGIN_ROOT}/dist/mcp-launcher.js"] }
236
140
  }
237
- finally {
238
- process.env = ambient;
141
+ }
142
+ ]
143
+ )
144
+ );
145
+ }
146
+ }));
147
+ vi.mock("node:child_process", async (original) => ({
148
+ ...await original(),
149
+ execFile: (binary, args, options, callback) => {
150
+ if (args[0] === "auth") {
151
+ assert.equal(fixture.machine, true);
152
+ assert.equal(binary, realpathSync(join(fixture.home, "bin", "gh")));
153
+ assert.equal(options.maxBuffer, 64 * 1024);
154
+ for (const name of [
155
+ "GH_TOKEN",
156
+ "GITHUB_TOKEN",
157
+ "DELIVERY_REVIEW_APP_ID",
158
+ "DELIVERY_REVIEW_INSTALLATION_ID",
159
+ "DELIVERY_REVIEW_KEY_PATH",
160
+ "NODE_OPTIONS",
161
+ "GH_DEBUG",
162
+ "UNRELATED_SERVICE_TOKEN"
163
+ ])
164
+ assert.equal(options.env[name], void 0);
165
+ fixture.ghCalls.push(args);
166
+ if (args[1] === "status")
167
+ callback(
168
+ null,
169
+ JSON.stringify({
170
+ hosts: {
171
+ "github.com": [{ active: true, host: "github.com", login: "fixture-author-login", state: "success" }]
239
172
  }
173
+ }),
174
+ "fictional-opaque-stderr"
175
+ );
176
+ else {
177
+ assert.deepEqual(args, ["auth", "token", "--hostname", "github.com", "--user", "fixture-author-login"]);
178
+ callback(null, "fictional_machine_author_value", "fictional-opaque-stderr");
179
+ }
180
+ return;
181
+ }
182
+ assert.equal(binary, process.execPath);
183
+ assert.deepEqual(args, [join(fixture.root, "runtime/dist/cli.js"), "--repo", args[2], "config:resolve"]);
184
+ assert.equal(options.timeout, void 0);
185
+ assert.equal(options.maxBuffer, 1024 * 1024);
186
+ const forwarded = Object.keys(options.env).sort();
187
+ assert.deepEqual(
188
+ forwarded,
189
+ (fixture.machine ? [
190
+ "AI_DELIVERY_CONFIG",
191
+ "DELIVERY_REVIEW_APP_ID",
192
+ "DELIVERY_REVIEW_INSTALLATION_ID",
193
+ "DELIVERY_REVIEW_KEY_PATH",
194
+ "DISABLE_AUTOUPDATER",
195
+ "HOME",
196
+ "LANG",
197
+ "LC_ALL",
198
+ "NODE_OPTIONS",
199
+ "PATH"
200
+ ] : [
201
+ "AI_DELIVERY_CONFIG",
202
+ "DELIVERY_AUTHOR_TOKEN",
203
+ "DELIVERY_REVIEW_APP_ID",
204
+ "DELIVERY_REVIEW_INSTALLATION_ID",
205
+ "DELIVERY_REVIEW_KEY_PATH",
206
+ "DISABLE_AUTOUPDATER",
207
+ "NODE_OPTIONS",
208
+ "PATH"
209
+ ]).sort()
210
+ );
211
+ fixture.authCalls++;
212
+ const run = async () => {
213
+ if (fixture.mode === "raw_failure") {
214
+ callback(new Error("fictional-value-header"), "fictional-value-body", "fictional-value-key-path");
215
+ return;
216
+ }
217
+ const ambient = process.env;
218
+ process.env = { ...options.env };
219
+ fixture.childStderrLines = [];
220
+ try {
221
+ const { contextFor } = await import("./dispatch.js");
222
+ const { preflightReviewRoute } = await import("./pr.js");
223
+ const context = await contextFor({ repoRoot: options.cwd, repo: args[2] }, "config:resolve");
224
+ const data = {
225
+ routing: context.configuration.routing,
226
+ reviewRoute: await preflightReviewRoute(context, void 0, void 0, "development")
240
227
  };
241
- void run();
242
- },
228
+ if (fixture.mode === "wrong_repo") data.routing.repository = "example/unselected";
229
+ if (fixture.mode === "same_actor") data.reviewRoute.reviewer.actorLogin = data.reviewRoute.author.actorLogin;
230
+ if (fixture.mode === "secret_actor") data.reviewRoute.author.actorLogin = options.env.DELIVERY_AUTHOR_TOKEN;
231
+ callback(
232
+ null,
233
+ JSON.stringify({
234
+ ...data,
235
+ untrustedBody: "fictional-value-body",
236
+ untrustedHeaders: "fictional-value-header"
237
+ }),
238
+ "fictional-value-key-path"
239
+ );
240
+ } catch (error) {
241
+ callback(
242
+ new Error("Selected CLI failed"),
243
+ "",
244
+ [...fixture.childStderrLines, `ai-delivery: ${error instanceof Error ? error.message : "unknown"}`].join(
245
+ "\n"
246
+ ) + "\n"
247
+ );
248
+ } finally {
249
+ process.env = ambient;
250
+ }
251
+ };
252
+ void run();
253
+ }
243
254
  }));
244
- const { managePlugin } = await import('./pluginInstaller.js');
255
+ const { managePlugin } = await import("./pluginInstaller.js");
245
256
  let settings;
246
257
  function file(path, bytes) {
247
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
248
- writeFileSync(path, bytes, { mode: 0o600 });
258
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
259
+ writeFileSync(path, bytes, { mode: 384 });
249
260
  }
250
- function native(host = 'codex') {
251
- fixture.host = host;
252
- const directory = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user');
253
- const catalog = join(directory, 'marketplace');
254
- const unit = join(catalog, 'versions/0.3.24');
255
- const source = join(unit, 'plugins/ai-delivery');
256
- const nativeHome = join(fixture.home, host === 'codex' ? '.codex' : '.claude');
257
- const cache = join(nativeHome, 'plugins/cache/ai-delivery-user/ai-delivery/0.3.24');
258
- fixture.root = cache;
259
- const files = {
260
- 'runtime/dist/cli.js': 'fictional selected CLI; execution simulated',
261
- 'dist/mcp-launcher.js': 'fictional launcher',
262
- 'skills/intake/SKILL.md': 'fictional skill',
263
- };
264
- for (const root of [source, cache])
265
- for (const [name, bytes] of Object.entries(files))
266
- file(join(root, name), bytes);
267
- const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
268
- file(join(unit, 'archive.tgz'), 'fictional archive');
269
- file(join(unit, 'version.json'), JSON.stringify({
270
- owner: '@aviaratech/ai-delivery.plugin-version@1',
271
- version: '0.3.24',
272
- archiveSha256: hash('fictional archive'),
273
- files: Object.fromEntries(Object.entries(files)
274
- .sort(([a], [b]) => a.localeCompare(b))
275
- .map(([name, bytes]) => [name, hash(bytes)])),
276
- }));
277
- file(join(directory, 'state.json'), JSON.stringify({
278
- owner: '@aviaratech/ai-delivery.plugin@1',
279
- host,
280
- scope: 'user',
281
- projectRoot: null,
282
- nativeHome,
283
- marketplace: 'ai-delivery-user',
284
- currentVersion: '0.3.24',
285
- previousVersion: null,
286
- installedPath: cache,
287
- }));
288
- if (host === 'claude-code') {
289
- file(join(nativeHome, 'plugins/known_marketplaces.json'), JSON.stringify({
290
- 'ai-delivery-user': { source: { source: 'directory', path: catalog }, installLocation: catalog },
291
- }));
292
- file(join(catalog, '.claude-plugin/marketplace.json'), JSON.stringify({
293
- name: 'ai-delivery-user',
294
- plugins: [{ name: 'ai-delivery', version: '0.3.24', source: './versions/0.3.24/plugins/ai-delivery' }],
295
- }));
296
- }
261
+ function native(host = "codex") {
262
+ fixture.host = host;
263
+ const directory = join(fixture.home, ".cache/ai-delivery/plugins", host, "user");
264
+ const catalog = join(directory, "marketplace");
265
+ const unit = join(catalog, "versions/0.3.24");
266
+ const source = join(unit, "plugins/ai-delivery");
267
+ const nativeHome = join(fixture.home, host === "codex" ? ".codex" : ".claude");
268
+ const cache = join(nativeHome, "plugins/cache/ai-delivery-user/ai-delivery/0.3.24");
269
+ fixture.root = cache;
270
+ const files = {
271
+ "runtime/dist/cli.js": "fictional selected CLI; execution simulated",
272
+ "dist/mcp-launcher.js": "fictional launcher",
273
+ "skills/intake/SKILL.md": "fictional skill"
274
+ };
275
+ for (const root of [source, cache]) for (const [name, bytes] of Object.entries(files)) file(join(root, name), bytes);
276
+ const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
277
+ file(join(unit, "archive.tgz"), "fictional archive");
278
+ file(
279
+ join(unit, "version.json"),
280
+ JSON.stringify({
281
+ owner: "@aviaratech/ai-delivery.plugin-version@1",
282
+ version: "0.3.24",
283
+ archiveSha256: hash("fictional archive"),
284
+ files: Object.fromEntries(
285
+ Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([name, bytes]) => [name, hash(bytes)])
286
+ )
287
+ })
288
+ );
289
+ file(
290
+ join(directory, "state.json"),
291
+ JSON.stringify({
292
+ owner: "@aviaratech/ai-delivery.plugin@1",
293
+ host,
294
+ scope: "user",
295
+ projectRoot: null,
296
+ nativeHome,
297
+ marketplace: "ai-delivery-user",
298
+ currentVersion: "0.3.24",
299
+ previousVersion: null,
300
+ installedPath: cache
301
+ })
302
+ );
303
+ if (host === "claude-code") {
304
+ file(
305
+ join(nativeHome, "plugins/known_marketplaces.json"),
306
+ JSON.stringify({
307
+ "ai-delivery-user": { source: { source: "directory", path: catalog }, installLocation: catalog }
308
+ })
309
+ );
310
+ file(
311
+ join(catalog, ".claude-plugin/marketplace.json"),
312
+ JSON.stringify({
313
+ name: "ai-delivery-user",
314
+ plugins: [{ name: "ai-delivery", version: "0.3.24", source: "./versions/0.3.24/plugins/ai-delivery" }]
315
+ })
316
+ );
317
+ }
297
318
  }
298
319
  beforeEach(() => {
299
- fixture.home = mkdtempSync(join(tmpdir(), 'ai-delivery-doctor-'));
300
- fixture.config = join(fixture.home, 'settings.json');
301
- fixture.enabled = true;
302
- fixture.mode = 'success';
303
- fixture.authCalls = 0;
304
- fixture.machine = false;
305
- fixture.ghCalls = [];
306
- fixture.keyReads = 0;
307
- fixture.settingsReads = 0;
308
- fixture.requestErrorLogs = [];
309
- fixture.childStderrLines = [];
310
- fixture.commands = [];
311
- fixture.requests = [];
312
- fixture.startupEnvironments = [];
313
- vi.stubEnv('CODEX_HOME', join(fixture.home, '.codex'));
314
- vi.stubEnv('CLAUDE_CONFIG_DIR', join(fixture.home, '.claude'));
315
- vi.stubEnv('AI_DELIVERY_CONFIG', fixture.config);
316
- settings = {
317
- schemaVersion: 'ai-delivery.user@1',
318
- roles: {
319
- author: { authSource: 'personal', identity: 'fixture-author', credentialEnv: { token: 'DELIVERY_AUTHOR_TOKEN' } },
320
- reviewer: {
321
- identity: 'fixture-reviewer',
322
- credentialEnv: {
323
- appId: 'DELIVERY_REVIEW_APP_ID',
324
- installationId: 'DELIVERY_REVIEW_INSTALLATION_ID',
325
- privateKeyPath: 'DELIVERY_REVIEW_KEY_PATH',
326
- },
327
- },
328
- },
329
- project: 1,
330
- checkoutRoots: [],
331
- pointsField: 'Estimate',
332
- priorityField: 'Urgency',
333
- statusField: 'Flow',
334
- statuses: syntheticDiscoveryConfig.native.project.statuses,
335
- };
336
- file(fixture.config, JSON.stringify(settings));
337
- vi.stubEnv('DELIVERY_AUTHOR_TOKEN', 'fictional-author-value');
338
- vi.stubEnv('DELIVERY_REVIEW_APP_ID', '654321');
339
- vi.stubEnv('DELIVERY_REVIEW_INSTALLATION_ID', '765432');
340
- const key = join(fixture.home, 'fictional-reviewer.pem');
341
- file(key, generateKeyPairSync('rsa', {
342
- modulusLength: 2048,
343
- privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
344
- publicKeyEncoding: { type: 'spki', format: 'pem' },
345
- }).privateKey);
346
- vi.stubEnv('DELIVERY_REVIEW_KEY_PATH', key);
347
- for (const name of ['GH_TOKEN', 'GITHUB_TOKEN', 'UNRELATED_SERVICE_TOKEN', 'AI_DELIVERY_IDENTITY'])
348
- vi.stubEnv(name, 'fictional-unrelated-value');
349
- vi.stubGlobal('fetch', () => {
350
- throw new Error('Unexpected HTTP in a synthetic doctor fixture');
351
- });
352
- native();
320
+ fixture.home = mkdtempSync(join(tmpdir(), "ai-delivery-doctor-"));
321
+ fixture.config = join(fixture.home, "settings.json");
322
+ fixture.enabled = true;
323
+ fixture.mode = "success";
324
+ fixture.authCalls = 0;
325
+ fixture.machine = false;
326
+ fixture.ghCalls = [];
327
+ fixture.keyReads = 0;
328
+ fixture.settingsReads = 0;
329
+ fixture.requestErrorLogs = [];
330
+ fixture.childStderrLines = [];
331
+ fixture.commands = [];
332
+ fixture.requests = [];
333
+ fixture.startupEnvironments = [];
334
+ vi.stubEnv("CODEX_HOME", join(fixture.home, ".codex"));
335
+ vi.stubEnv("CLAUDE_CONFIG_DIR", join(fixture.home, ".claude"));
336
+ vi.stubEnv("AI_DELIVERY_CONFIG", fixture.config);
337
+ settings = {
338
+ schemaVersion: "ai-delivery.user@1",
339
+ roles: {
340
+ author: { authSource: "personal", identity: "fixture-author", credentialEnv: { token: "DELIVERY_AUTHOR_TOKEN" } },
341
+ reviewer: {
342
+ identity: "fixture-reviewer",
343
+ credentialEnv: {
344
+ appId: "DELIVERY_REVIEW_APP_ID",
345
+ installationId: "DELIVERY_REVIEW_INSTALLATION_ID",
346
+ privateKeyPath: "DELIVERY_REVIEW_KEY_PATH"
347
+ }
348
+ }
349
+ },
350
+ project: 1,
351
+ checkoutRoots: [],
352
+ pointsField: "Estimate",
353
+ priorityField: "Urgency",
354
+ statusField: "Flow",
355
+ statuses: syntheticDiscoveryConfig.native.project.statuses
356
+ };
357
+ file(fixture.config, JSON.stringify(settings));
358
+ vi.stubEnv("DELIVERY_AUTHOR_TOKEN", "fictional-author-value");
359
+ vi.stubEnv("DELIVERY_REVIEW_APP_ID", "654321");
360
+ vi.stubEnv("DELIVERY_REVIEW_INSTALLATION_ID", "765432");
361
+ const key = join(fixture.home, "fictional-reviewer.pem");
362
+ file(
363
+ key,
364
+ generateKeyPairSync("rsa", {
365
+ modulusLength: 2048,
366
+ privateKeyEncoding: { type: "pkcs8", format: "pem" },
367
+ publicKeyEncoding: { type: "spki", format: "pem" }
368
+ }).privateKey
369
+ );
370
+ vi.stubEnv("DELIVERY_REVIEW_KEY_PATH", key);
371
+ for (const name of ["GH_TOKEN", "GITHUB_TOKEN", "UNRELATED_SERVICE_TOKEN", "AI_DELIVERY_IDENTITY"])
372
+ vi.stubEnv(name, "fictional-unrelated-value");
373
+ vi.stubGlobal("fetch", () => {
374
+ throw new Error("Unexpected HTTP in a synthetic doctor fixture");
375
+ });
376
+ native();
353
377
  });
354
378
  afterEach(() => {
355
- vi.unstubAllEnvs();
356
- vi.unstubAllGlobals();
357
- vi.restoreAllMocks();
358
- rmSync(fixture.home, { recursive: true, force: true });
379
+ vi.unstubAllEnvs();
380
+ vi.unstubAllGlobals();
381
+ vi.restoreAllMocks();
382
+ rmSync(fixture.home, { recursive: true, force: true });
359
383
  });
360
384
  function http() {
361
- vi.stubGlobal('fetch', async (input, init) => {
362
- const url = input instanceof Request ? input.url : String(input);
363
- const path = new URL(url).pathname;
364
- const method = init?.method ?? 'GET';
365
- fixture.requests.push(`${method} ${path}`);
366
- const json = (data, status = 200) => new Response(JSON.stringify(data), {
367
- status,
368
- headers: { 'content-type': 'application/json', 'x-fixture-secret': 'fictional-value-header' },
369
- });
370
- if (path === '/graphql' && method === 'POST') {
371
- assert.equal(typeof init?.body, 'string');
372
- const body = JSON.parse(init.body);
373
- assert.ok(!body.query.includes('mutation'));
374
- const config = { ...syntheticDiscoveryConfig, repository: `${body.variables.owner}/${body.variables.repo}` };
375
- return json({ data: await syntheticDiscoveryClients(config).graphql(body.query) });
376
- }
377
- if (method === 'POST' && path === '/app/installations/765432/access_tokens')
378
- return json({
379
- token: 'ghs_fictional_installation',
380
- expires_at: '2099-01-01T00:00:00Z',
381
- permissions: { contents: 'read', pull_requests: 'write' },
382
- });
383
- assert.equal(method, 'GET');
384
- if (path === '/user')
385
- return fixture.mode === 'expired'
386
- ? json({ message: 'fictional-author-value' }, 401)
387
- : json({ id: 42, login: 'fixture-author-login', type: 'User' });
388
- if (path === '/app')
389
- return json({ id: 654321, slug: 'fixture-reviewer' });
390
- if (/^\/repos\/example\/(widget|service)$/u.test(path)) {
391
- if (fixture.mode === 'denied' && new Headers(init?.headers).get('authorization')?.includes('ghs_'))
392
- return json({ message: 'fictional-value-body' }, 403);
393
- return json({ full_name: path.slice(7), default_branch: 'main' });
394
- }
395
- if (path.endsWith('/rules/branches/main'))
396
- return fixture.mode === 'unknown_rules' ? json({ message: 'fictional-value-body' }, 403) : json([]);
397
- if (path.endsWith('/branches/main/protection'))
398
- return fixture.mode === 'unknown_rules' ? json({ message: 'fictional-value-body' }, 403) : json({});
399
- throw new Error('Unapproved endpoint in simulated doctor readback');
400
- });
401
- }
402
- function doctor(repo = 'example/widget', checkAuth = true) {
403
- return managePlugin({
404
- action: 'doctor',
405
- host: fixture.host,
406
- scope: 'user',
407
- repoRoot: fixture.home,
408
- ...(checkAuth ? { checkAuth, repo } : {}),
409
- });
410
- }
411
- test('default doctor has no settings, reference, key or authentication access; native inventory/startup exclude credentials', async () => {
412
- file(fixture.config, '{invalid fictional settings');
413
- const result = await doctor('example/widget', false);
414
- assert.equal(result.mcp?.startup, 'ready');
415
- assert.equal(result.authProbe, undefined);
416
- assert.equal(fixture.settingsReads, 0);
417
- assert.equal(fixture.keyReads, 0);
418
- assert.equal(fixture.authCalls, 0);
419
- assert.deepEqual(fixture.requests, []);
420
- for (const env of [...fixture.commands.map((c) => c.environment), ...fixture.startupEnvironments]) {
421
- assert.equal(env.GH_TOKEN, undefined);
422
- assert.equal(env.DELIVERY_AUTHOR_TOKEN, undefined);
423
- assert.equal(env.AI_DELIVERY_IDENTITY, undefined);
424
- }
425
- });
426
- test('the actual SDK startup subprocess receives no inherited-name credential sentinels', async () => {
427
- const sdk = await vi.importActual('@modelcontextprotocol/sdk/client/stdio.js');
428
- settings.roles.author.credentialEnv = { token: 'LOGNAME' };
429
- file(fixture.config, JSON.stringify(settings));
430
- for (const name of sdk.DEFAULT_INHERITED_ENV_VARS)
431
- vi.stubEnv(name, `fictional-inherited-${name}`);
432
- await doctor('example/widget', false);
433
- const transport = new sdk.StdioClientTransport({
434
- command: process.execPath,
435
- args: [
436
- '--input-type=module',
437
- '-e',
438
- "process.stdout.write(JSON.stringify({jsonrpc:'2.0',method:'fixture.environment',params:Object.fromEntries(['HOME','LOGNAME','PATH','SHELL','TERM','USER'].map(name=>[name,process.env[name]]))})+'\\n');process.stdin.resume();",
439
- ],
440
- cwd: fixture.home,
441
- env: fixture.startupEnvironments[0],
442
- stderr: 'pipe',
385
+ vi.stubGlobal("fetch", async (input, init) => {
386
+ const url = input instanceof Request ? input.url : String(input);
387
+ const path = new URL(url).pathname;
388
+ const method = init?.method ?? "GET";
389
+ fixture.requests.push(`${method} ${path}`);
390
+ const json = (data, status = 200) => new Response(JSON.stringify(data), {
391
+ status,
392
+ headers: { "content-type": "application/json", "x-fixture-secret": "fictional-value-header" }
443
393
  });
444
- try {
445
- const readback = new Promise((resolve, reject) => {
446
- transport.onmessage = resolve;
447
- transport.onerror = reject;
448
- });
449
- await transport.start();
450
- const message = (await readback);
451
- assert.deepEqual(message.params, Object.fromEntries(sdk.DEFAULT_INHERITED_ENV_VARS.map((name) => [name, ''])));
452
- assert.equal(fixture.settingsReads, 0);
453
- assert.equal(fixture.authCalls, 0);
454
- assert.equal(fixture.keyReads, 0);
394
+ if (path === "/graphql" && method === "POST") {
395
+ assert.equal(typeof init?.body, "string");
396
+ const body = JSON.parse(init.body);
397
+ assert.ok(!body.query.includes("mutation"));
398
+ const config = { ...syntheticDiscoveryConfig, repository: `${body.variables.owner}/${body.variables.repo}` };
399
+ return json({ data: await syntheticDiscoveryClients(config).graphql(body.query) });
455
400
  }
456
- finally {
457
- await transport.close();
401
+ if (method === "POST" && path === "/app/installations/765432/access_tokens")
402
+ return json({
403
+ token: "ghs_fictional_installation",
404
+ expires_at: "2099-01-01T00:00:00Z",
405
+ permissions: { contents: "read", pull_requests: "write" }
406
+ });
407
+ assert.equal(method, "GET");
408
+ if (path === "/user")
409
+ return fixture.mode === "expired" ? json({ message: "fictional-author-value" }, 401) : json({ id: 42, login: "fixture-author-login", type: "User" });
410
+ if (path === "/app") return json({ id: 654321, slug: "fixture-reviewer" });
411
+ if (/^\/repos\/example\/(widget|service)$/u.test(path)) {
412
+ if (fixture.mode === "denied" && new Headers(init?.headers).get("authorization")?.includes("ghs_"))
413
+ return json({ message: "fictional-value-body" }, 403);
414
+ return json({ full_name: path.slice(7), default_branch: "main" });
458
415
  }
416
+ if (path.endsWith("/rules/branches/main"))
417
+ return fixture.mode === "unknown_rules" ? json({ message: "fictional-value-body" }, 403) : json([]);
418
+ if (path.endsWith("/branches/main/protection"))
419
+ return fixture.mode === "unknown_rules" ? json({ message: "fictional-value-body" }, 403) : json({});
420
+ throw new Error("Unapproved endpoint in simulated doctor readback");
421
+ });
422
+ }
423
+ function doctor(repo = "example/widget", checkAuth = true) {
424
+ return managePlugin({
425
+ action: "doctor",
426
+ host: fixture.host,
427
+ scope: "user",
428
+ repoRoot: fixture.home,
429
+ ...checkAuth ? { checkAuth, repo } : {}
430
+ });
431
+ }
432
+ test("default doctor has no settings, reference, key or authentication access; native inventory/startup exclude credentials", async () => {
433
+ file(fixture.config, "{invalid fictional settings");
434
+ const result = await doctor("example/widget", false);
435
+ assert.equal(result.mcp?.startup, "ready");
436
+ assert.equal(result.authProbe, void 0);
437
+ assert.equal(fixture.settingsReads, 0);
438
+ assert.equal(fixture.keyReads, 0);
439
+ assert.equal(fixture.authCalls, 0);
440
+ assert.deepEqual(fixture.requests, []);
441
+ for (const env of [...fixture.commands.map((c) => c.environment), ...fixture.startupEnvironments]) {
442
+ assert.equal(env.GH_TOKEN, void 0);
443
+ assert.equal(env.DELIVERY_AUTHOR_TOKEN, void 0);
444
+ assert.equal(env.AI_DELIVERY_IDENTITY, void 0);
445
+ }
459
446
  });
460
- test('auth opt-in requires an explicit valid repository, even outside Git or in dry-run', async () => {
461
- await assert.rejects(managePlugin({ action: 'doctor', host: 'codex', scope: 'user', repoRoot: fixture.home, checkAuth: true }), /requires explicit --repo/u);
462
- await assert.rejects(doctor('invalid'), /Invalid string/u);
463
- assert.equal(fixture.commands.length, 0);
464
- const result = await managePlugin({
465
- action: 'doctor',
466
- host: 'codex',
467
- scope: 'user',
468
- repoRoot: fixture.home,
469
- checkAuth: true,
470
- repo: 'example/widget',
471
- dryRun: true,
447
+ test("the actual SDK startup subprocess receives no inherited-name credential sentinels", async () => {
448
+ const sdk = await vi.importActual(
449
+ "@modelcontextprotocol/sdk/client/stdio.js"
450
+ );
451
+ settings.roles.author = {
452
+ authSource: "personal",
453
+ identity: settings.roles.author.identity,
454
+ credentialEnv: { token: "LOGNAME" }
455
+ };
456
+ file(fixture.config, JSON.stringify(settings));
457
+ for (const name of sdk.DEFAULT_INHERITED_ENV_VARS) vi.stubEnv(name, `fictional-inherited-${name}`);
458
+ await doctor("example/widget", false);
459
+ const transport = new sdk.StdioClientTransport({
460
+ command: process.execPath,
461
+ args: [
462
+ "--input-type=module",
463
+ "-e",
464
+ "process.stdout.write(JSON.stringify({jsonrpc:'2.0',method:'fixture.environment',params:Object.fromEntries(['HOME','LOGNAME','PATH','SHELL','TERM','USER'].map(name=>[name,process.env[name]]))})+'\\n');process.stdin.resume();"
465
+ ],
466
+ cwd: fixture.home,
467
+ env: fixture.startupEnvironments[0],
468
+ stderr: "pipe"
469
+ });
470
+ try {
471
+ const readback = new Promise((resolve, reject) => {
472
+ transport.onmessage = resolve;
473
+ transport.onerror = reject;
472
474
  });
473
- assert.equal(result.authProbe?.reason, 'dry_run');
475
+ await transport.start();
476
+ const message = await readback;
477
+ assert.deepEqual(message.params, Object.fromEntries(sdk.DEFAULT_INHERITED_ENV_VARS.map((name) => [name, ""])));
474
478
  assert.equal(fixture.settingsReads, 0);
475
- });
476
- test('invalid settings stop before reading a key or executing the authenticated child', async () => {
477
- file(fixture.config, JSON.stringify({
478
- ...settings,
479
- roles: { ...settings.roles, reviewer: { ...settings.roles.reviewer, identity: settings.roles.author.identity } },
480
- }));
481
- const result = await doctor();
482
- assert.equal(result.authProbe?.settings, 'unavailable_or_invalid');
483
- assert.equal(fixture.keyReads, 0);
484
479
  assert.equal(fixture.authCalls, 0);
485
- assert.ok(!JSON.stringify(result.authProbe).includes(fixture.config));
486
- });
487
- test('all missing selected references gate both roles; unrelated legacy credentials cannot satisfy them', async () => {
488
- vi.stubEnv('DELIVERY_AUTHOR_TOKEN', '');
489
- vi.stubEnv('DELIVERY_REVIEW_APP_ID', '');
490
- const result = await doctor();
491
- assert.deepEqual(result.authProbe?.processReferences.missingNames, [
492
- 'DELIVERY_AUTHOR_TOKEN',
493
- 'DELIVERY_REVIEW_APP_ID',
494
- ]);
495
- assert.equal(result.authProbe?.authentication.status, 'not_checked');
496
480
  assert.equal(fixture.keyReads, 0);
497
- assert.equal(fixture.authCalls, 0);
498
- assert.ok(!JSON.stringify(result.authProbe).includes('fictional-unrelated-value'));
481
+ } finally {
482
+ await transport.close();
483
+ }
484
+ });
485
+ test("auth opt-in requires an explicit valid repository, even outside Git or in dry-run", async () => {
486
+ await assert.rejects(
487
+ managePlugin({ action: "doctor", host: "codex", scope: "user", repoRoot: fixture.home, checkAuth: true }),
488
+ /requires explicit --repo/u
489
+ );
490
+ await assert.rejects(doctor("invalid"), /Invalid string/u);
491
+ assert.equal(fixture.commands.length, 0);
492
+ const result = await managePlugin({
493
+ action: "doctor",
494
+ host: "codex",
495
+ scope: "user",
496
+ repoRoot: fixture.home,
497
+ checkAuth: true,
498
+ repo: "example/widget",
499
+ dryRun: true
500
+ });
501
+ assert.equal(result.authProbe?.reason, "dry_run");
502
+ assert.equal(fixture.settingsReads, 0);
503
+ });
504
+ test("invalid settings stop before reading a key or executing the authenticated child", async () => {
505
+ file(
506
+ fixture.config,
507
+ JSON.stringify({
508
+ ...settings,
509
+ roles: { ...settings.roles, reviewer: { ...settings.roles.reviewer, identity: settings.roles.author.identity } }
510
+ })
511
+ );
512
+ const result = await doctor();
513
+ assert.equal(result.authProbe?.settings, "unavailable_or_invalid");
514
+ assert.equal(fixture.keyReads, 0);
515
+ assert.equal(fixture.authCalls, 0);
516
+ assert.ok(!JSON.stringify(result.authProbe).includes(fixture.config));
499
517
  });
500
- test.each(['codex', 'claude-code'])('%s doctor may explicitly resolve an absent default reference through the selected machine session', async (host) => {
518
+ test("all missing selected references gate both roles; unrelated legacy credentials cannot satisfy them", async () => {
519
+ vi.stubEnv("DELIVERY_AUTHOR_TOKEN", "");
520
+ vi.stubEnv("DELIVERY_REVIEW_APP_ID", "");
521
+ const result = await doctor();
522
+ assert.deepEqual(result.authProbe?.processReferences.missingNames, [
523
+ "DELIVERY_AUTHOR_TOKEN",
524
+ "DELIVERY_REVIEW_APP_ID"
525
+ ]);
526
+ assert.equal(result.authProbe?.authentication.status, "not_checked");
527
+ assert.equal(fixture.keyReads, 0);
528
+ assert.equal(fixture.authCalls, 0);
529
+ assert.ok(!JSON.stringify(result.authProbe).includes("fictional-unrelated-value"));
530
+ });
531
+ test.each(["codex", "claude-code"])(
532
+ "%s doctor may explicitly resolve an absent default reference through the selected machine session",
533
+ async (host) => {
501
534
  native(host);
502
535
  fixture.machine = true;
503
- settings.roles.author.credentialEnv = { token: 'GH_TOKEN' };
536
+ settings.roles.author = {
537
+ authSource: "personal",
538
+ identity: settings.roles.author.identity,
539
+ credentialEnv: { token: "GH_TOKEN" }
540
+ };
504
541
  file(fixture.config, JSON.stringify(settings));
505
- vi.stubEnv('GH_TOKEN', undefined);
506
- vi.stubEnv('HOME', fixture.home);
507
- // Own optional language selectors instead of assuming the verification wrapper supplies them.
508
- vi.stubEnv('LANG', 'C');
509
- vi.stubEnv('LC_ALL', 'C');
510
- vi.stubEnv('USER', undefined);
511
- vi.stubEnv('LOGNAME', undefined);
512
- const bin = join(fixture.home, 'bin');
542
+ vi.stubEnv("GH_TOKEN", void 0);
543
+ vi.stubEnv("HOME", fixture.home);
544
+ vi.stubEnv("LANG", "C");
545
+ vi.stubEnv("LC_ALL", "C");
546
+ vi.stubEnv("USER", void 0);
547
+ vi.stubEnv("LOGNAME", void 0);
548
+ const bin = join(fixture.home, "bin");
513
549
  mkdirSync(bin);
514
- file(join(bin, 'gh'), 'fictional CLI; execution simulated');
515
- chmodSync(join(bin, 'gh'), 0o755);
516
- vi.stubEnv('PATH', bin);
550
+ file(join(bin, "gh"), "fictional CLI; execution simulated");
551
+ chmodSync(join(bin, "gh"), 493);
552
+ vi.stubEnv("PATH", bin);
517
553
  http();
518
- for (const repo of ['example/widget', 'example/service', 'example/widget']) {
519
- const result = await doctor(repo);
520
- assert.equal(result.authProbe?.outcome, 'readback_complete');
521
- assert.equal(result.authProbe?.processReferences.status, 'complete');
522
- assert.ok(!result.authProbe?.processReferences.requiredNames.includes('GH_TOKEN'));
523
- assert.equal(result.authProbe?.authentication.author?.credentialSource, `gh:github.com:${realpathSync(join(bin, 'gh'))}`);
524
- assert.equal(result.authProbe?.nativeGuiPropagation, 'unverified');
525
- assert.ok(!JSON.stringify(result).includes('fictional_machine_author_value'));
554
+ for (const repo of ["example/widget", "example/service", "example/widget"]) {
555
+ const result = await doctor(repo);
556
+ assert.equal(result.authProbe?.outcome, "readback_complete");
557
+ assert.equal(result.authProbe?.processReferences.status, "complete");
558
+ assert.ok(!result.authProbe?.processReferences.requiredNames.includes("GH_TOKEN"));
559
+ assert.equal(
560
+ result.authProbe?.authentication.author?.credentialSource,
561
+ `gh:github.com:${realpathSync(join(bin, "gh"))}`
562
+ );
563
+ assert.equal(result.authProbe?.nativeGuiPropagation, "unverified");
564
+ assert.ok(!JSON.stringify(result).includes("fictional_machine_author_value"));
526
565
  }
527
- assert.equal(fixture.ghCalls.length, 6, 'One status/token selection per command, retained across routing and operation');
528
- });
529
- test('absent default author input still gates missing reviewer references before machine/session/key access', async () => {
530
- settings.roles.author.credentialEnv = { token: 'GH_TOKEN' };
531
- file(fixture.config, JSON.stringify(settings));
532
- vi.stubEnv('GH_TOKEN', undefined);
533
- vi.stubEnv('DELIVERY_REVIEW_APP_ID', undefined);
534
- const result = await doctor();
535
- assert.deepEqual(result.authProbe?.processReferences.missingNames, ['DELIVERY_REVIEW_APP_ID']);
536
- assert.equal(fixture.authCalls, 0);
537
- assert.equal(fixture.ghCalls.length, 0);
538
- assert.equal(fixture.keyReads, 0);
566
+ assert.equal(
567
+ fixture.ghCalls.length,
568
+ 6,
569
+ "One status/token selection per command, retained across routing and operation"
570
+ );
571
+ }
572
+ );
573
+ test("absent default author input still gates missing reviewer references before machine/session/key access", async () => {
574
+ settings.roles.author = {
575
+ authSource: "personal",
576
+ identity: settings.roles.author.identity,
577
+ credentialEnv: { token: "GH_TOKEN" }
578
+ };
579
+ file(fixture.config, JSON.stringify(settings));
580
+ vi.stubEnv("GH_TOKEN", void 0);
581
+ vi.stubEnv("DELIVERY_REVIEW_APP_ID", void 0);
582
+ const result = await doctor();
583
+ assert.deepEqual(result.authProbe?.processReferences.missingNames, ["DELIVERY_REVIEW_APP_ID"]);
584
+ assert.equal(fixture.authCalls, 0);
585
+ assert.equal(fixture.ghCalls.length, 0);
586
+ assert.equal(fixture.keyReads, 0);
539
587
  });
540
- test('invalid App references and reserved runtime credential names stop before key/network access', async () => {
541
- vi.stubEnv('DELIVERY_REVIEW_INSTALLATION_ID', 'not-an-id');
542
- assert.equal((await doctor()).authProbe?.reason, 'invalid_references');
543
- vi.stubEnv('DELIVERY_REVIEW_INSTALLATION_ID', '765432');
544
- settings.roles.author.credentialEnv = { token: 'NODE_OPTIONS' };
545
- file(fixture.config, JSON.stringify(settings));
546
- vi.stubEnv('NODE_OPTIONS', 'fictional-runtime-value');
547
- assert.equal((await doctor()).authProbe?.reason, 'invalid_references');
548
- assert.equal(fixture.keyReads, 0);
549
- assert.equal(fixture.authCalls, 0);
588
+ test("invalid App references and reserved runtime credential names stop before key/network access", async () => {
589
+ vi.stubEnv("DELIVERY_REVIEW_INSTALLATION_ID", "not-an-id");
590
+ assert.equal((await doctor()).authProbe?.reason, "invalid_references");
591
+ vi.stubEnv("DELIVERY_REVIEW_INSTALLATION_ID", "765432");
592
+ settings.roles.author = {
593
+ authSource: "personal",
594
+ identity: settings.roles.author.identity,
595
+ credentialEnv: { token: "NODE_OPTIONS" }
596
+ };
597
+ file(fixture.config, JSON.stringify(settings));
598
+ vi.stubEnv("NODE_OPTIONS", "fictional-runtime-value");
599
+ assert.equal((await doctor()).authProbe?.reason, "invalid_references");
600
+ assert.equal(fixture.keyReads, 0);
601
+ assert.equal(fixture.authCalls, 0);
550
602
  });
551
- test.each(['codex', 'claude-code'])('%s synthetic selection outside Git probes A → B → A through existing read-only auth owners', async (host) => {
603
+ test.each(["codex", "claude-code"])(
604
+ "%s synthetic selection outside Git probes A \u2192 B \u2192 A through existing read-only auth owners",
605
+ async (host) => {
552
606
  native(host);
553
607
  http();
554
- for (const repo of ['example/widget', 'example/service', 'example/widget']) {
555
- const result = await doctor(repo);
556
- assert.equal(result.authProbe?.outcome, 'readback_complete');
557
- assert.deepEqual(result.authProbe?.authentication, {
558
- status: 'verified',
559
- author: { actorLogin: 'fixture-author-login', authSource: 'personal' },
560
- reviewer: { actorLogin: 'fixture-reviewer[bot]', authSource: 'app' },
561
- });
562
- assert.deepEqual(result.authProbe?.repositoryAccess, { repository: repo, status: 'verified' });
563
- assert.equal(result.authProbe?.nativeGuiPropagation, 'unverified');
564
- assert.equal(result.authProbe?.reviewRules?.approvalEligibility, 'unknown');
565
- assert.ok(!JSON.stringify(result).includes('fictional-author-value'));
566
- assert.ok(!JSON.stringify(result.authProbe).includes('fictional-reviewer.pem'));
608
+ for (const repo of ["example/widget", "example/service", "example/widget"]) {
609
+ const result = await doctor(repo);
610
+ assert.equal(result.authProbe?.outcome, "readback_complete");
611
+ assert.deepEqual(result.authProbe?.authentication, {
612
+ status: "verified",
613
+ author: { actorLogin: "fixture-author-login", authSource: "personal" },
614
+ reviewer: { actorLogin: "fixture-reviewer[bot]", authSource: "app" }
615
+ });
616
+ assert.deepEqual(result.authProbe?.repositoryAccess, { repository: repo, status: "verified" });
617
+ assert.equal(result.authProbe?.nativeGuiPropagation, "unverified");
618
+ assert.equal(result.authProbe?.reviewRules?.approvalEligibility, "unknown");
619
+ assert.ok(!JSON.stringify(result).includes("fictional-author-value"));
620
+ assert.ok(!JSON.stringify(result.authProbe).includes("fictional-reviewer.pem"));
567
621
  }
568
622
  assert.equal(fixture.authCalls, 3);
569
- assert.ok(fixture.requests.includes('POST /app/installations/765432/access_tokens'));
570
- });
571
- test.each(['changed', 'disabled', 'startup_failed'])('auth probe refuses %s selected native bytes/startup', async (mode) => {
572
- if (mode === 'changed')
573
- file(join(fixture.root, 'skills/intake/SKILL.md'), 'modified skill');
574
- if (mode === 'disabled')
575
- fixture.enabled = false;
576
- if (mode === 'startup_failed')
577
- fixture.mode = mode;
623
+ assert.ok(fixture.requests.includes("POST /app/installations/765432/access_tokens"));
624
+ }
625
+ );
626
+ test.each(["changed", "disabled", "startup_failed"])(
627
+ "auth probe refuses %s selected native bytes/startup",
628
+ async (mode) => {
629
+ if (mode === "changed") file(join(fixture.root, "skills/intake/SKILL.md"), "modified skill");
630
+ if (mode === "disabled") fixture.enabled = false;
631
+ if (mode === "startup_failed") fixture.mode = mode;
578
632
  const result = await doctor();
579
- assert.equal(result.authProbe?.reason, 'native_plugin_not_ready');
633
+ assert.equal(result.authProbe?.reason, "native_plugin_not_ready");
580
634
  assert.equal(fixture.authCalls, 0);
581
635
  assert.equal(fixture.keyReads, 0);
582
636
  assert.equal(fixture.settingsReads, 0);
583
- assert.ok(!JSON.stringify(result).includes('fictional-upstream-secret'));
584
- });
585
- test.each(['expired', 'denied', 'raw_failure'])('safe labelled %s failure does not reveal body/header/key-path sentinels or claim verified access', async (mode) => {
637
+ assert.ok(!JSON.stringify(result).includes("fictional-upstream-secret"));
638
+ }
639
+ );
640
+ test.each(["expired", "denied", "raw_failure"])(
641
+ "safe labelled %s failure does not reveal body/header/key-path sentinels or claim verified access",
642
+ async (mode) => {
586
643
  fixture.mode = mode;
587
644
  http();
588
645
  const result = await doctor();
589
- assert.equal(result.authProbe?.outcome, 'failed');
590
- assert.equal(result.authProbe?.reason, mode === 'expired' ? 'authentication_failed' : mode === 'denied' ? 'repository_denied' : 'probe_failed');
591
- if (mode !== 'raw_failure')
592
- assert.ok(fixture.requestErrorLogs.some((line) => line.startsWith('GET ')), 'Installed Octokit REST logger must precede the final diagnostic');
593
- assert.notEqual(result.authProbe?.authentication.status, 'verified');
594
- assert.notEqual(result.authProbe?.repositoryAccess.status, 'verified');
646
+ assert.equal(result.authProbe?.outcome, "failed");
647
+ assert.equal(
648
+ result.authProbe?.reason,
649
+ mode === "expired" ? "authentication_failed" : mode === "denied" ? "repository_denied" : "probe_failed"
650
+ );
651
+ if (mode !== "raw_failure")
652
+ assert.ok(
653
+ fixture.requestErrorLogs.some((line) => line.startsWith("GET ")),
654
+ "Installed Octokit REST logger must precede the final diagnostic"
655
+ );
656
+ assert.notEqual(result.authProbe?.authentication.status, "verified");
657
+ assert.notEqual(result.authProbe?.repositoryAccess.status, "verified");
595
658
  for (const sentinel of [
596
- 'fictional-author-value',
597
- 'fictional-value-body',
598
- 'fictional-value-header',
599
- 'fictional-value-key-path',
659
+ "fictional-author-value",
660
+ "fictional-value-body",
661
+ "fictional-value-header",
662
+ "fictional-value-key-path"
600
663
  ])
601
- assert.ok(!JSON.stringify(result).includes(sentinel));
602
- });
603
- test('hidden rules remain unknown after authenticated identity/repository reads; no counted approval is inferred', async () => {
604
- fixture.mode = 'unknown_rules';
605
- http();
606
- const result = await doctor();
607
- assert.equal(result.authProbe?.outcome, 'readback_complete');
608
- assert.deepEqual(result.authProbe?.reviewRules, {
609
- visibility: 'unknown',
610
- observedRequiredApprovals: null,
611
- approvalEligibility: 'unknown',
612
- });
664
+ assert.ok(!JSON.stringify(result).includes(sentinel));
665
+ }
666
+ );
667
+ test("hidden rules remain unknown after authenticated identity/repository reads; no counted approval is inferred", async () => {
668
+ fixture.mode = "unknown_rules";
669
+ http();
670
+ const result = await doctor();
671
+ assert.equal(result.authProbe?.outcome, "readback_complete");
672
+ assert.deepEqual(result.authProbe?.reviewRules, {
673
+ visibility: "unknown",
674
+ observedRequiredApprovals: null,
675
+ approvalEligibility: "unknown"
676
+ });
613
677
  });
614
- test.each(['wrong_repo', 'same_actor', 'secret_actor'])('rejects %s readback without reflecting unsafe identity data', async (mode) => {
678
+ test.each(["wrong_repo", "same_actor", "secret_actor"])(
679
+ "rejects %s readback without reflecting unsafe identity data",
680
+ async (mode) => {
615
681
  fixture.mode = mode;
616
682
  http();
617
683
  const result = await doctor();
618
- assert.equal(result.authProbe?.reason, 'invalid_readback');
619
- assert.equal(result.authProbe?.authentication.status, 'unverified');
620
- assert.ok(!JSON.stringify(result).includes('fictional-author-value'));
621
- });
622
- test('synthetic doctor reads never change managed state or settings', async () => {
623
- http();
624
- const state = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
625
- const before = [readFileSync(state), readFileSync(fixture.config)];
626
- await doctor();
627
- assert.deepEqual([readFileSync(state), readFileSync(fixture.config)], before);
684
+ assert.equal(result.authProbe?.reason, "invalid_readback");
685
+ assert.equal(result.authProbe?.authentication.status, "unverified");
686
+ assert.ok(!JSON.stringify(result).includes("fictional-author-value"));
687
+ }
688
+ );
689
+ test("synthetic doctor reads never change managed state or settings", async () => {
690
+ http();
691
+ const state = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
692
+ const before = [readFileSync(state), readFileSync(fixture.config)];
693
+ await doctor();
694
+ assert.deepEqual([readFileSync(state), readFileSync(fixture.config)], before);
628
695
  });
629
- test.each([true, false])('doctor preserves a present or absent native tool preference (%s)', async (present) => {
630
- const nativeConfig = join(fixture.home, '.codex', 'config.toml');
631
- const bytes = present
632
- ? '[plugins."ai-delivery".mcp_servers.ai-delivery.tools.issue_info]\napproval_mode="approve"\n'
633
- : '# no explicit issue_info approval preference\n';
634
- file(nativeConfig, bytes);
635
- const result = await doctor('example/widget', false);
636
- assert.equal(result.mcp?.startup, 'ready');
637
- assert.equal(result.activation?.installedVersion, '0.3.24');
638
- assert.equal(result.activation?.startupVersion, '0.3.24');
639
- assert.equal(result.activation?.loadedVersion, null);
640
- assert.equal(result.diagnostics?.migration, 'refused');
641
- assert.equal(readFileSync(nativeConfig, 'utf8'), bytes);
642
- assert.equal(fixture.authCalls, 0);
643
- assert.equal(fixture.keyReads, 0);
696
+ test.each([true, false])("doctor preserves a present or absent native tool preference (%s)", async (present) => {
697
+ const nativeConfig = join(fixture.home, ".codex", "config.toml");
698
+ const bytes = present ? '[plugins."ai-delivery".mcp_servers.ai-delivery.tools.issue_info]\napproval_mode="approve"\n' : "# no explicit issue_info approval preference\n";
699
+ file(nativeConfig, bytes);
700
+ const result = await doctor("example/widget", false);
701
+ assert.equal(result.mcp?.startup, "ready");
702
+ assert.equal(result.activation?.installedVersion, "0.3.24");
703
+ assert.equal(result.activation?.startupVersion, "0.3.24");
704
+ assert.equal(result.activation?.loadedVersion, null);
705
+ assert.equal(result.diagnostics?.migration, "refused");
706
+ assert.equal(readFileSync(nativeConfig, "utf8"), bytes);
707
+ assert.equal(fixture.authCalls, 0);
708
+ assert.equal(fixture.keyReads, 0);
644
709
  });
645
- //# sourceMappingURL=pluginDoctor.test.js.map
710
+ //# sourceMappingURL=pluginDoctor.test.js.map