@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,1617 +1,2036 @@
1
- import assert from 'node:assert/strict';
2
- import { createHash } from 'node:crypto';
3
- import { EventEmitter } from 'node:events';
4
- import { existsSync, chmodSync, cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
5
- import { execFileSync, spawn, spawnSync } from 'node:child_process';
6
- import { tmpdir } from 'node:os';
7
- import { dirname, join } from 'node:path';
8
- import { fileURLToPath } from 'node:url';
9
- import * as atomicJson from './utils/atomicJson.js';
10
- import * as pluginTools from '@aviaratech/ai-plugin-tools';
11
- import { processSnapshot, retainedWorktreeTransitionProducerDigest, retainedWorktreeTransitionDependencyManifests, } from './verification.js';
12
- import { afterEach, beforeEach, test, vi } from 'vitest';
13
- import { PassThrough } from 'node:stream';
1
+ import assert from "node:assert/strict";
2
+ import { createHash } from "node:crypto";
3
+ import { EventEmitter } from "node:events";
4
+ import {
5
+ existsSync,
6
+ chmodSync,
7
+ cpSync,
8
+ lstatSync,
9
+ mkdirSync,
10
+ mkdtempSync,
11
+ readFileSync,
12
+ readdirSync,
13
+ rmSync,
14
+ symlinkSync,
15
+ writeFileSync
16
+ } from "node:fs";
17
+ import { execFileSync, spawn, spawnSync } from "node:child_process";
18
+ import { tmpdir } from "node:os";
19
+ import { dirname, join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import * as atomicJson from "./utils/atomicJson.js";
22
+ import * as pluginTools from "@aviaratech/ai-plugin-tools";
23
+ import {
24
+ processSnapshot,
25
+ retainedWorktreeTransitionProducerDigest,
26
+ retainedWorktreeTransitionDependencyManifests
27
+ } from "./verification.js";
28
+ import { afterEach, beforeEach, test, vi } from "vitest";
29
+ import { PassThrough } from "node:stream";
14
30
  const fixture = vi.hoisted(() => ({
15
- home: '',
16
- commands: [],
17
- commandArguments: [],
18
- realCommands: false,
19
- responses: [],
20
- respond: undefined,
21
- packArchive: '',
31
+ home: "",
32
+ commands: [],
33
+ commandArguments: [],
34
+ realCommands: false,
35
+ responses: [],
36
+ respond: void 0,
37
+ packArchive: ""
22
38
  }));
23
- vi.mock('@aviaratech/ai-plugin-tools', async (original) => {
24
- const actual = await original();
25
- return {
26
- ...actual,
27
- marketplaceDocuments: vi.fn(actual.marketplaceDocuments),
28
- nativePluginArgs: vi.fn(actual.nativePluginArgs),
29
- };
30
- });
31
- vi.mock('node:child_process', async (original) => {
32
- const actual = await original();
33
- return {
34
- ...actual,
35
- spawn: (...parameters) => {
36
- if (fixture.realCommands)
37
- return actual.spawn(...parameters);
38
- const [binary, args] = parameters;
39
- fixture.commands.push(binary === '/bin/sh' ? args[3] : binary);
40
- const commandArguments = binary === '/bin/sh' ? args.slice(3) : [binary, ...(args ?? [])];
41
- fixture.commandArguments.push(commandArguments);
42
- const child = Object.assign(new EventEmitter(), {
43
- stdin: new PassThrough(),
44
- stdout: new PassThrough(),
45
- stderr: new PassThrough(),
46
- kill: () => true,
47
- });
48
- const queued = fixture.responses.shift() ?? fixture.respond;
49
- let response = typeof queued === 'function' ? queued(commandArguments) : queued;
50
- if (binary === '/bin/sh' && args?.[3] === 'npm' && fixture.packArchive) {
51
- const destination = args[args.indexOf('--pack-destination') + 1];
52
- const filename = 'aviaratech-ai-delivery-0.3.22.tgz';
53
- writeFileSync(join(destination, filename), readFileSync(fixture.packArchive), { mode: 0o600 });
54
- response = JSON.stringify([{ filename }]);
55
- }
56
- queueMicrotask(() => {
57
- if (response === undefined) {
58
- child.emit('error', new Error('Native fixture intentionally unavailable.'));
59
- child.emit('close', 1, null);
60
- }
61
- else {
62
- child.stdout.emit('data', Buffer.from(response));
63
- child.emit('close', 0, null);
64
- }
65
- });
66
- return child;
67
- },
68
- };
39
+ vi.mock("@aviaratech/ai-plugin-tools", async (original) => {
40
+ const actual = await original();
41
+ return {
42
+ ...actual,
43
+ marketplaceDocuments: vi.fn(actual.marketplaceDocuments),
44
+ nativePluginArgs: vi.fn(actual.nativePluginArgs)
45
+ };
46
+ });
47
+ vi.mock("node:child_process", async (original) => {
48
+ const actual = await original();
49
+ return {
50
+ ...actual,
51
+ spawn: (...parameters) => {
52
+ if (fixture.realCommands) return actual.spawn(...parameters);
53
+ const [binary, args] = parameters;
54
+ fixture.commands.push(binary === "/bin/sh" ? args[3] : binary);
55
+ const commandArguments = binary === "/bin/sh" ? args.slice(3) : [binary, ...args ?? []];
56
+ fixture.commandArguments.push(commandArguments);
57
+ const child = Object.assign(new EventEmitter(), {
58
+ stdin: new PassThrough(),
59
+ stdout: new PassThrough(),
60
+ stderr: new PassThrough(),
61
+ kill: () => true
62
+ });
63
+ const queued = fixture.responses.shift() ?? fixture.respond;
64
+ let response = typeof queued === "function" ? queued(commandArguments) : queued;
65
+ if (binary === "/bin/sh" && args?.[3] === "npm" && fixture.packArchive) {
66
+ const destination = args[args.indexOf("--pack-destination") + 1];
67
+ const filename = "aviaratech-ai-delivery-0.3.22.tgz";
68
+ writeFileSync(join(destination, filename), readFileSync(fixture.packArchive), { mode: 384 });
69
+ response = JSON.stringify([{ filename }]);
70
+ }
71
+ queueMicrotask(() => {
72
+ if (response === void 0) {
73
+ child.emit("error", new Error("Native fixture intentionally unavailable."));
74
+ child.emit("close", 1, null);
75
+ } else {
76
+ child.stdout.emit("data", Buffer.from(response));
77
+ child.emit("close", 0, null);
78
+ }
79
+ });
80
+ return child;
81
+ }
82
+ };
69
83
  });
70
- vi.mock('node:os', async (original) => ({
71
- ...(await original()),
72
- homedir: () => fixture.home,
84
+ vi.mock("node:os", async (original) => ({
85
+ ...await original(),
86
+ homedir: () => fixture.home
73
87
  }));
74
- const { managePlugin } = await import('./pluginInstaller.js');
75
- test('preview observes a Codex registration candidate without executing or changing its settings', async () => {
76
- const profile = join(fixture.home, '.codex');
77
- mkdirSync(profile);
78
- const config = join(profile, 'config.toml');
79
- const bytes = '[mcp_servers."ai-delivery"]\ncommand = "unknown-launcher"\nsecret = "fictional-private-value"\n';
80
- writeFileSync(config, bytes);
81
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
82
- const report = Reflect.get(result, 'diagnostics');
83
- assert.ok(report);
84
- assert.equal(report.migration, 'refused');
85
- assert.equal(report.completeness, 'incomplete');
86
- assert.deepEqual(report.registrations, [
87
- { kind: 'standalone', scope: 'user', ownership: 'unknown', source: 'unknown', version: null, enabled: null },
88
- ]);
89
- assert.equal(JSON.stringify(result).includes('fictional-private-value'), false);
90
- assert.equal(JSON.stringify(result).includes('unknown-launcher'), false);
91
- assert.equal(readFileSync(config, 'utf8'), bytes);
92
- assert.deepEqual(fixture.commands, []);
93
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
94
- });
95
- test('preview preserves Claude local/project/user registrations and permission preferences', async () => {
96
- vi.stubEnv('CLAUDE_CONFIG_DIR', '');
97
- const user = join(fixture.home, '.claude.json');
98
- const project = join(fixture.home, '.mcp.json');
99
- const settings = join(fixture.home, '.claude', 'settings.json');
100
- mkdirSync(dirname(settings));
101
- writeFileSync(user, JSON.stringify({
102
- mcpServers: { 'ai-delivery': { command: 'unknown-user' } },
103
- projects: {
104
- [fixture.home]: { mcpServers: { 'ai-delivery': { command: 'unknown-local' } } },
105
- },
106
- }));
107
- writeFileSync(project, JSON.stringify({ mcpServers: { 'ai-delivery': { command: 'unknown-project' } } }));
108
- writeFileSync(settings, JSON.stringify({ permissions: { allow: ['mcp__ai-delivery__issue_info'] } }));
109
- const before = [user, project, settings].map((path) => readFileSync(path));
110
- const result = await managePlugin({ action: 'preview', host: 'claude-code', scope: 'user', repoRoot: fixture.home });
111
- assert.ok(result.diagnostics);
112
- assert.deepEqual(result.diagnostics.registrations.map((entry) => entry.scope), ['local', 'project', 'user']);
113
- assert.equal(result.diagnostics.migration, 'refused');
114
- assert.deepEqual([user, project, settings].map((path) => readFileSync(path)), before);
115
- assert.deepEqual(fixture.commands, []);
116
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
117
- });
118
- test('doctor reports an external native marketplace plugin without adopting or starting it', async () => {
119
- fixture.responses.push(JSON.stringify({
120
- installed: [
121
- {
122
- pluginId: 'ai-delivery@external-market',
123
- name: 'ai-delivery',
124
- marketplaceName: 'external-market',
125
- version: '0.3.24',
126
- enabled: true,
127
- source: { source: 'git', url: 'https://example.test/unknown' },
128
- },
129
- ],
130
- available: [],
131
- }));
132
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
133
- assert.equal(result.installed, false);
134
- assert.ok(result.diagnostics);
135
- assert.ok(result.activation);
136
- assert.deepEqual(result.diagnostics.registrations, [
137
- { kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
138
- ]);
139
- assert.equal(result.activation.loadedVersion, null);
140
- assert.equal(result.sourceIntegrity, undefined);
141
- assert.equal(result.mcp, undefined);
142
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
143
- });
144
- test('preview refuses incomplete oversized configuration without writes or native calls', async () => {
145
- const profile = join(fixture.home, '.codex');
146
- mkdirSync(profile);
147
- const config = join(profile, 'config.toml');
148
- const bytes = '#'.repeat(1024 * 1024 + 1);
149
- writeFileSync(config, bytes);
150
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
151
- assert.ok(result.diagnostics);
152
- assert.equal(result.diagnostics.migration, 'refused');
153
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
154
- assert.equal(readFileSync(config, 'utf8'), bytes);
155
- assert.deepEqual(fixture.commands, []);
156
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
157
- });
158
- test('doctor retains distinct external marketplace observations with identical reported versions', async () => {
159
- doctorFixture(false);
160
- const selected = JSON.parse(fixture.responses[0])
161
- .installed[0];
162
- fixture.responses.push(JSON.stringify({
163
- installed: [
164
- selected,
165
- { pluginId: 'ai-delivery@external-one', version: '0.3.24', enabled: true },
166
- { pluginId: 'ai-delivery@external-two', version: '0.3.24', enabled: true },
167
- ],
168
- available: [],
169
- }));
170
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
171
- assert.ok(result.diagnostics);
172
- assert.equal(result.diagnostics.registrations.filter((entry) => entry.ownership === 'external').length, 2);
173
- assert.equal(result.diagnostics.nativeInventory, 'observed');
174
- });
175
- test('doctor observes external installations after retained managed removal without adopting them', async () => {
176
- mkdirSync(join(fixture.home, '.codex'));
177
- const statePath = writeState({ ...pendingState('remove', null), pending: undefined });
178
- const before = readFileSync(statePath);
179
- fixture.responses.push(JSON.stringify({
180
- installed: [{ pluginId: 'ai-delivery@external-market', version: '0.3.24', enabled: true }],
181
- available: [],
182
- }));
183
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
184
- assert.ok(result.diagnostics);
185
- assert.deepEqual(result.diagnostics.registrations, [
186
- { kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
187
- ]);
188
- assert.equal(result.installed, false);
189
- assert.equal(result.sourceIntegrity, undefined);
190
- assert.equal(result.mcp, undefined);
191
- assert.deepEqual(result.activation, { installedVersion: null, startupVersion: null, loadedVersion: null });
192
- assert.deepEqual(readFileSync(statePath), before);
193
- assert.deepEqual(fixture.commandArguments, [['codex', 'plugin', 'list', '--json']]);
194
- });
195
- test('compiled preview never invokes native tools or creates installer state', () => {
196
- const profile = join(fixture.home, '.codex');
197
- const bin = join(fixture.home, 'bin');
198
- const marker = join(fixture.home, 'native-called');
199
- mkdirSync(profile);
200
- mkdirSync(bin);
201
- writeFileSync(join(bin, 'codex'), `#!/bin/sh\nprintf called > '${marker}'\n`, { mode: 0o755 });
202
- writeFileSync(join(profile, 'config.toml'), '[mcp_servers.ai-delivery]\ncommand="untrusted"\n');
203
- const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
204
- const stdout = execFileSync(process.execPath, [cli, 'plugin', 'preview', '--host', 'codex', '--json'], {
205
- cwd: fixture.home,
206
- env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile, PATH: bin },
207
- encoding: 'utf8',
88
+ const { managePlugin } = await import("./pluginInstaller.js");
89
+ test("preview observes a Codex registration candidate without executing or changing its settings", async () => {
90
+ const profile = join(fixture.home, ".codex");
91
+ mkdirSync(profile);
92
+ const config = join(profile, "config.toml");
93
+ const bytes = '[mcp_servers."ai-delivery"]\ncommand = "unknown-launcher"\nsecret = "fictional-private-value"\n';
94
+ writeFileSync(config, bytes);
95
+ const result = await managePlugin({ ...input(), action: "preview", version: void 0 });
96
+ const report = Reflect.get(result, "diagnostics");
97
+ assert.ok(report);
98
+ assert.equal(report.migration, "refused");
99
+ assert.equal(report.completeness, "incomplete");
100
+ assert.deepEqual(report.registrations, [
101
+ {
102
+ kind: "standalone",
103
+ scope: "user",
104
+ ownership: "unknown",
105
+ source: "unknown",
106
+ version: null,
107
+ behind: null,
108
+ enabled: null
109
+ }
110
+ ]);
111
+ assert.equal(JSON.stringify(result).includes("fictional-private-value"), false);
112
+ assert.equal(JSON.stringify(result).includes("unknown-launcher"), false);
113
+ assert.equal(readFileSync(config, "utf8"), bytes);
114
+ assert.deepEqual(fixture.commands, []);
115
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
116
+ });
117
+ test("preview preserves Claude local/project/user registrations and permission preferences", async () => {
118
+ vi.stubEnv("CLAUDE_CONFIG_DIR", "");
119
+ const user = join(fixture.home, ".claude.json");
120
+ const project = join(fixture.home, ".mcp.json");
121
+ const settings = join(fixture.home, ".claude", "settings.json");
122
+ mkdirSync(dirname(settings));
123
+ writeFileSync(
124
+ user,
125
+ JSON.stringify({
126
+ mcpServers: { "ai-delivery": { command: "unknown-user" } },
127
+ projects: {
128
+ [fixture.home]: { mcpServers: { "ai-delivery": { command: "unknown-local" } } }
129
+ }
130
+ })
131
+ );
132
+ writeFileSync(project, JSON.stringify({ mcpServers: { "ai-delivery": { command: "unknown-project" } } }));
133
+ writeFileSync(settings, JSON.stringify({ permissions: { allow: ["mcp__ai-delivery__issue_info"] } }));
134
+ const before = [user, project, settings].map((path) => readFileSync(path));
135
+ const result = await managePlugin({ action: "preview", host: "claude-code", scope: "user", repoRoot: fixture.home });
136
+ assert.ok(result.diagnostics);
137
+ assert.deepEqual(
138
+ result.diagnostics.registrations.map((entry) => entry.scope),
139
+ ["local", "project", "user"]
140
+ );
141
+ assert.equal(result.diagnostics.migration, "refused");
142
+ assert.deepEqual(
143
+ [user, project, settings].map((path) => readFileSync(path)),
144
+ before
145
+ );
146
+ assert.deepEqual(fixture.commands, []);
147
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
148
+ });
149
+ test("doctor reports an external native marketplace plugin without adopting or starting it", async () => {
150
+ fixture.responses.push(
151
+ JSON.stringify({
152
+ installed: [
153
+ {
154
+ pluginId: "ai-delivery@external-market",
155
+ name: "ai-delivery",
156
+ marketplaceName: "external-market",
157
+ version: "0.3.24",
158
+ enabled: true,
159
+ source: { source: "git", url: "https://example.test/unknown" }
160
+ }
161
+ ],
162
+ available: []
163
+ })
164
+ );
165
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
166
+ assert.equal(result.installed, false);
167
+ assert.ok(result.diagnostics);
168
+ assert.ok(result.activation);
169
+ assert.deepEqual(result.diagnostics.registrations, [
170
+ {
171
+ kind: "plugin",
172
+ scope: "user",
173
+ ownership: "external",
174
+ source: "unknown",
175
+ version: "0.3.24",
176
+ behind: true,
177
+ enabled: true
178
+ }
179
+ ]);
180
+ assert.equal(result.activation.loadedVersion, null);
181
+ assert.equal(result.sourceIntegrity, void 0);
182
+ assert.equal(result.mcp, void 0);
183
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
184
+ });
185
+ for (const host of ["codex", "claude-code"]) {
186
+ for (const [version, latest, behind] of [
187
+ ["0.3.29", "0.3.35", true],
188
+ ["0.3.35", "0.3.35", false],
189
+ ["0.3.36", "0.3.35", false],
190
+ ["0.3.9", "0.3.35", true],
191
+ ["0.3.35-beta.2", "0.3.35", true],
192
+ ["0.3.35+local", "0.3.35", false],
193
+ ["0.3.35-beta.2", "0.3.35-beta.10", true]
194
+ ]) {
195
+ test(`doctor compares ${host} installed ${version} against published ${latest}`, async () => {
196
+ vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(JSON.stringify({ latest }))));
197
+ const entry = { pluginId: "ai-delivery@external", version, scope: "user", enabled: true, installed: true };
198
+ fixture.responses.push(JSON.stringify(host === "codex" ? { installed: [entry], available: [] } : [entry]));
199
+ const result = await managePlugin({ action: "doctor", host, scope: "user", repoRoot: fixture.home });
200
+ assert.ok(result.diagnostics);
201
+ assert.equal(Reflect.get(result.diagnostics, "latestPublishedVersion"), latest);
202
+ assert.equal(result.diagnostics.registrations[0].version, version);
203
+ assert.equal(Reflect.get(result.diagnostics.registrations[0], "behind"), behind);
204
+ assert.equal(vi.mocked(fetch).mock.calls.length, 1);
205
+ assert.equal(
206
+ vi.mocked(fetch).mock.calls[0][0],
207
+ "https://registry.npmjs.org/-/package/@aviaratech%2fai-delivery/dist-tags"
208
+ );
209
+ assert.equal(result.changed, false);
210
+ assert.equal(result.sourceIntegrity, void 0);
211
+ assert.equal(result.mcp, void 0);
212
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
208
213
  });
209
- const result = JSON.parse(stdout);
210
- assert.ok(result.diagnostics);
211
- assert.equal(result.action, 'preview');
212
- assert.equal(result.diagnostics.migration, 'refused');
213
- assert.deepEqual(result.diagnostics.plannedChanges, []);
214
- assert.equal(existsSync(marker), false);
215
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
216
- });
217
- test('preview refuses a symlinked configuration without following its target', async () => {
218
- const profile = join(fixture.home, '.codex');
219
- const target = join(fixture.home, 'protected.pem');
220
- mkdirSync(profile);
221
- writeFileSync(target, '[mcp_servers.ai-delivery]\nsecret="fictional-sensitive-content"\n');
222
- symlinkSync(target, join(profile, 'config.toml'));
223
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
214
+ }
215
+ }
216
+ for (const failure of ["unavailable", "http-error", "malformed", "oversized"]) {
217
+ test(`doctor keeps published-version uncertainty explicit when registry is ${failure}`, async () => {
218
+ const response = new Response(
219
+ failure === "malformed" ? JSON.stringify({ latest: "fictional-private-version" }) : " ".repeat(8193),
220
+ { status: failure === "http-error" ? 503 : 200 }
221
+ );
222
+ vi.stubGlobal(
223
+ "fetch",
224
+ failure === "unavailable" ? vi.fn().mockRejectedValue(new Error("fictional-private-registry-error")) : vi.fn().mockResolvedValue(response)
225
+ );
226
+ fixture.responses.push(
227
+ JSON.stringify({
228
+ installed: [{ pluginId: "ai-delivery@external", version: "0.3.29", enabled: true }],
229
+ available: []
230
+ })
231
+ );
232
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
224
233
  assert.ok(result.diagnostics);
225
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
226
- assert.deepEqual(result.diagnostics.registrations, []);
227
- assert.equal(JSON.stringify(result).includes('fictional-sensitive-content'), false);
234
+ assert.equal(Reflect.get(result.diagnostics, "latestPublishedVersion"), null);
235
+ assert.equal(Reflect.get(result.diagnostics.registrations[0], "behind"), null);
236
+ assert.ok(result.diagnostics.findings.includes("latest_published_version_unavailable"));
237
+ assert.equal(JSON.stringify(result).includes("fictional-private"), false);
238
+ if (failure !== "unavailable") assert.equal(response.bodyUsed, true);
239
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
240
+ });
241
+ }
242
+ for (const value of [{ action: "preview" }, { action: "doctor", dryRun: true }]) {
243
+ test(`plugin ${value.action}${value.dryRun ? " dry-run" : ""} does not query the published version`, async () => {
244
+ await managePlugin({ ...input(), version: void 0, ...value });
245
+ assert.equal(vi.mocked(fetch).mock.calls.length, 0);
228
246
  assert.deepEqual(fixture.commands, []);
229
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
230
- });
231
- test.each(['codex', 'claude-code'])('preview refuses a FIFO configuration without blocking in %s', (host) => {
232
- const profile = join(fixture.home, '.codex');
247
+ assert.deepEqual(readdirSync(fixture.home), []);
248
+ });
249
+ }
250
+ test("preview refuses incomplete oversized configuration without writes or native calls", async () => {
251
+ const profile = join(fixture.home, ".codex");
252
+ mkdirSync(profile);
253
+ const config = join(profile, "config.toml");
254
+ const bytes = "#".repeat(1024 * 1024 + 1);
255
+ writeFileSync(config, bytes);
256
+ const result = await managePlugin({ ...input(), action: "preview", version: void 0 });
257
+ assert.ok(result.diagnostics);
258
+ assert.equal(result.diagnostics.migration, "refused");
259
+ assert.ok(result.diagnostics.findings.includes("configuration_unavailable"));
260
+ assert.equal(readFileSync(config, "utf8"), bytes);
261
+ assert.deepEqual(fixture.commands, []);
262
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
263
+ });
264
+ test("doctor retains distinct external marketplace observations with identical reported versions", async () => {
265
+ doctorFixture(false);
266
+ const selected = JSON.parse(fixture.responses[0]).installed[0];
267
+ fixture.responses.push(
268
+ JSON.stringify({
269
+ installed: [
270
+ selected,
271
+ { pluginId: "ai-delivery@external-one", version: "0.3.24", enabled: true },
272
+ { pluginId: "ai-delivery@external-two", version: "0.3.24", enabled: true }
273
+ ],
274
+ available: []
275
+ })
276
+ );
277
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
278
+ assert.ok(result.diagnostics);
279
+ assert.equal(result.diagnostics.registrations.filter((entry) => entry.ownership === "external").length, 2);
280
+ assert.equal(result.diagnostics.nativeInventory, "observed");
281
+ });
282
+ test("doctor observes external installations after retained managed removal without adopting them", async () => {
283
+ mkdirSync(join(fixture.home, ".codex"));
284
+ const statePath = writeState({ ...pendingState("remove", null), pending: void 0 });
285
+ const before = readFileSync(statePath);
286
+ fixture.responses.push(
287
+ JSON.stringify({
288
+ installed: [{ pluginId: "ai-delivery@external-market", version: "0.3.24", enabled: true }],
289
+ available: []
290
+ })
291
+ );
292
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
293
+ assert.ok(result.diagnostics);
294
+ assert.deepEqual(result.diagnostics.registrations, [
295
+ {
296
+ kind: "plugin",
297
+ scope: "user",
298
+ ownership: "external",
299
+ source: "unknown",
300
+ version: "0.3.24",
301
+ behind: true,
302
+ enabled: true
303
+ }
304
+ ]);
305
+ assert.equal(result.installed, false);
306
+ assert.equal(result.sourceIntegrity, void 0);
307
+ assert.equal(result.mcp, void 0);
308
+ assert.deepEqual(result.activation, { installedVersion: null, startupVersion: null, loadedVersion: null });
309
+ assert.deepEqual(readFileSync(statePath), before);
310
+ assert.deepEqual(fixture.commandArguments, [["codex", "plugin", "list", "--json"]]);
311
+ });
312
+ test("compiled preview never invokes native tools or creates installer state", { tags: ["release"] }, () => {
313
+ const profile = join(fixture.home, ".codex");
314
+ const bin = join(fixture.home, "bin");
315
+ const marker = join(fixture.home, "native-called");
316
+ mkdirSync(profile);
317
+ mkdirSync(bin);
318
+ writeFileSync(join(bin, "codex"), `#!/bin/sh
319
+ printf called > '${marker}'
320
+ `, { mode: 493 });
321
+ writeFileSync(join(profile, "config.toml"), '[mcp_servers.ai-delivery]\ncommand="untrusted"\n');
322
+ const cli = fileURLToPath(new URL("./cli.js", import.meta.url));
323
+ const stdout = execFileSync(process.execPath, [cli, "plugin", "preview", "--host", "codex", "--json"], {
324
+ cwd: fixture.home,
325
+ env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile, PATH: bin },
326
+ encoding: "utf8"
327
+ });
328
+ const result = JSON.parse(stdout);
329
+ assert.ok(result.diagnostics);
330
+ assert.equal(result.action, "preview");
331
+ assert.equal(result.diagnostics.migration, "refused");
332
+ assert.deepEqual(result.diagnostics.plannedChanges, []);
333
+ assert.equal(existsSync(marker), false);
334
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
335
+ });
336
+ test("preview refuses a symlinked configuration without following its target", async () => {
337
+ const profile = join(fixture.home, ".codex");
338
+ const target = join(fixture.home, "protected.pem");
339
+ mkdirSync(profile);
340
+ writeFileSync(target, '[mcp_servers.ai-delivery]\nsecret="fictional-sensitive-content"\n');
341
+ symlinkSync(target, join(profile, "config.toml"));
342
+ const result = await managePlugin({ ...input(), action: "preview", version: void 0 });
343
+ assert.ok(result.diagnostics);
344
+ assert.ok(result.diagnostics.findings.includes("configuration_unavailable"));
345
+ assert.deepEqual(result.diagnostics.registrations, []);
346
+ assert.equal(JSON.stringify(result).includes("fictional-sensitive-content"), false);
347
+ assert.deepEqual(fixture.commands, []);
348
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
349
+ });
350
+ test.each(["codex", "claude-code"])(
351
+ "preview refuses a FIFO configuration without blocking in %s",
352
+ { tags: ["release"] },
353
+ (host) => {
354
+ const profile = join(fixture.home, ".codex");
233
355
  mkdirSync(profile);
234
- const config = host === 'codex' ? join(profile, 'config.toml') : join(fixture.home, '.mcp.json');
235
- execFileSync('/usr/bin/mkfifo', [config]);
356
+ const config = host === "codex" ? join(profile, "config.toml") : join(fixture.home, ".mcp.json");
357
+ execFileSync("/usr/bin/mkfifo", [config]);
236
358
  const metadata = lstatSync(config);
237
- const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
238
- // Bound only the known FIFO-open stall and reap this test-owned child.
239
- const child = spawnSync(process.execPath, [cli, 'plugin', 'preview', '--host', host, '--json'], {
240
- cwd: fixture.home,
241
- env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile },
242
- encoding: 'utf8',
243
- timeout: 3000,
244
- killSignal: 'SIGKILL',
359
+ const cli = fileURLToPath(new URL("./cli.js", import.meta.url));
360
+ const child = spawnSync(process.execPath, [cli, "plugin", "preview", "--host", host, "--json"], {
361
+ cwd: fixture.home,
362
+ env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile },
363
+ encoding: "utf8",
364
+ timeout: 3e3,
365
+ killSignal: "SIGKILL"
245
366
  });
246
- assert.equal(child.error, undefined);
367
+ assert.equal(child.error, void 0);
247
368
  assert.equal(child.status, 0);
248
369
  const result = JSON.parse(child.stdout);
249
370
  assert.ok(result.diagnostics);
250
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
371
+ assert.ok(result.diagnostics.findings.includes("configuration_unavailable"));
251
372
  assert.deepEqual(result.diagnostics.registrations, []);
252
373
  assert.equal(lstatSync(config).ino, metadata.ino);
253
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
254
- });
255
- test.each(['migrate', 'apply', 'retire', 'restore-settings'])('unsupported %s never enables host mutation', async (action) => {
256
- await assert.rejects(managePlugin({ ...input(), action, version: undefined }));
374
+ assert.equal(existsSync(join(fixture.home, ".cache")), false);
375
+ }
376
+ );
377
+ test.each(["migrate", "apply", "retire", "restore-settings"])(
378
+ "unsupported %s never enables host mutation",
379
+ async (action) => {
380
+ await assert.rejects(managePlugin({ ...input(), action, version: void 0 }));
257
381
  assert.deepEqual(fixture.commands, []);
258
382
  assert.deepEqual(readdirSync(fixture.home), []);
259
- });
383
+ }
384
+ );
260
385
  beforeEach(() => {
261
- vi.clearAllMocks();
262
- fixture.home = mkdtempSync(join(tmpdir(), 'ai-delivery-installer-'));
263
- vi.stubEnv('CODEX_HOME', join(fixture.home, '.codex'));
264
- vi.stubEnv('CLAUDE_CONFIG_DIR', join(fixture.home, '.claude'));
265
- fixture.commands = [];
266
- fixture.commandArguments = [];
267
- fixture.realCommands = false;
268
- fixture.responses = [];
269
- fixture.respond = undefined;
270
- fixture.packArchive = '';
386
+ vi.clearAllMocks();
387
+ vi.stubGlobal(
388
+ "fetch",
389
+ vi.fn(() => Promise.resolve(new Response('{"latest":"0.3.35"}')))
390
+ );
391
+ fixture.home = mkdtempSync(join(tmpdir(), "ai-delivery-installer-"));
392
+ vi.stubEnv("CODEX_HOME", join(fixture.home, ".codex"));
393
+ vi.stubEnv("CLAUDE_CONFIG_DIR", join(fixture.home, ".claude"));
394
+ fixture.commands = [];
395
+ fixture.commandArguments = [];
396
+ fixture.realCommands = false;
397
+ fixture.responses = [];
398
+ fixture.respond = void 0;
399
+ fixture.packArchive = "";
271
400
  });
272
401
  afterEach(() => {
273
- vi.restoreAllMocks();
274
- vi.unstubAllEnvs();
275
- rmSync(fixture.home, { recursive: true, force: true });
276
- for (const args of fixture.commandArguments)
277
- if (args[1] === 'plugin' && args[2] === 'list')
278
- assert.deepEqual(args, args[0] === 'codex' && args.includes('--marketplace')
279
- ? ['codex', 'plugin', 'list', '--marketplace', 'ai-delivery-user', '--available', '--json']
280
- : args[0] === 'codex'
281
- ? ['codex', 'plugin', 'list', '--json']
282
- : ['claude', 'plugin', 'list', '--json']);
402
+ vi.restoreAllMocks();
403
+ vi.unstubAllGlobals();
404
+ vi.unstubAllEnvs();
405
+ rmSync(fixture.home, { recursive: true, force: true });
406
+ for (const args of fixture.commandArguments)
407
+ if (args[1] === "plugin" && args[2] === "list")
408
+ assert.deepEqual(
409
+ args,
410
+ args[0] === "codex" && args.includes("--marketplace") ? ["codex", "plugin", "list", "--marketplace", "ai-delivery-user", "--available", "--json"] : args[0] === "codex" ? ["codex", "plugin", "list", "--json"] : ["claude", "plugin", "list", "--json"]
411
+ );
283
412
  });
284
413
  function pendingState(action, version) {
285
- return {
286
- owner: '@aviaratech/ai-delivery.plugin@1',
287
- host: 'codex',
288
- scope: 'user',
289
- projectRoot: null,
290
- nativeHome: join(fixture.home, '.codex'),
291
- marketplace: 'ai-delivery-user',
292
- currentVersion: null,
293
- previousVersion: null,
294
- installedPath: null,
295
- pending: {
296
- action,
297
- targetVersion: version,
298
- producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
299
- owner: { pid: 2_000_000_000, birth: 'old owner' },
300
- command: { phase: 'idle' },
301
- },
302
- };
414
+ return {
415
+ owner: "@aviaratech/ai-delivery.plugin@1",
416
+ host: "codex",
417
+ scope: "user",
418
+ projectRoot: null,
419
+ nativeHome: join(fixture.home, ".codex"),
420
+ marketplace: "ai-delivery-user",
421
+ currentVersion: null,
422
+ previousVersion: null,
423
+ installedPath: null,
424
+ pending: {
425
+ action,
426
+ targetVersion: version,
427
+ producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
428
+ owner: { pid: 2e9, birth: "old owner" },
429
+ command: { phase: "idle" }
430
+ }
431
+ };
303
432
  }
304
- function writeState(value, host = 'codex') {
305
- const directory = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user');
306
- mkdirSync(directory, { recursive: true, mode: 0o700 });
307
- const path = join(directory, 'state.json');
308
- writeFileSync(path, JSON.stringify(value), { mode: 0o600 });
309
- return path;
433
+ function writeState(value, host = "codex") {
434
+ const directory = join(fixture.home, ".cache/ai-delivery/plugins", host, "user");
435
+ mkdirSync(directory, { recursive: true, mode: 448 });
436
+ const path = join(directory, "state.json");
437
+ writeFileSync(path, JSON.stringify(value), { mode: 384 });
438
+ return path;
310
439
  }
311
- function doctorFixture(enabled, host = 'codex') {
312
- const version = '0.3.21', catalog = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user/marketplace');
313
- const unit = join(catalog, 'versions', version), source = join(unit, 'plugins/ai-delivery');
314
- const nativeHome = join(fixture.home, host === 'codex' ? '.codex' : '.claude');
315
- const cache = join(nativeHome, 'plugins/cache/ai-delivery-user/ai-delivery', version);
316
- const files = { 'mcp.json': '{"ai-delivery":{"command":"node"}}', 'skills/intake/SKILL.md': 'owned skill bytes' };
317
- for (const root of [source, cache])
318
- for (const [name, bytes] of Object.entries(files)) {
319
- const path = join(root, name);
320
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
321
- writeFileSync(path, bytes, { mode: 0o600 });
322
- }
323
- const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
324
- writeFileSync(join(unit, 'archive.tgz'), 'captured archive', { mode: 0o600 });
325
- writeFileSync(join(unit, 'version.json'), JSON.stringify({
326
- owner: '@aviaratech/ai-delivery.plugin-version@1',
327
- version,
328
- archiveSha256: hash('captured archive'),
329
- files: Object.fromEntries(Object.entries(files).map(([name, bytes]) => [name, hash(bytes)])),
330
- }), { mode: 0o600 });
331
- writeState({
332
- ...pendingState('install', version),
333
- host,
334
- nativeHome,
335
- pending: undefined,
336
- currentVersion: version,
337
- installedPath: cache,
338
- }, host);
339
- for (const [relative, content] of [
340
- [
341
- '.agents/plugins/marketplace.json',
342
- {
343
- name: 'ai-delivery-user',
344
- interface: { displayName: 'ai-delivery' },
345
- plugins: [
346
- {
347
- name: 'ai-delivery',
348
- source: { source: 'local', path: `./versions/${version}/plugins/ai-delivery` },
349
- policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },
350
- category: 'Productivity',
351
- },
352
- ],
353
- },
354
- ],
355
- [
356
- '.claude-plugin/marketplace.json',
357
- {
358
- name: 'ai-delivery-user',
359
- owner: { name: 'AviaraTech' },
360
- plugins: [{ name: 'ai-delivery', source: `./versions/${version}/plugins/ai-delivery`, version }],
361
- },
362
- ],
363
- ]) {
364
- const path = join(catalog, relative);
365
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
366
- writeFileSync(path, JSON.stringify(content), { mode: 0o600 });
367
- }
368
- if (host === 'codex') {
369
- fixture.responses.push(JSON.stringify({
370
- installed: [
371
- {
372
- pluginId: 'ai-delivery@ai-delivery-user',
373
- marketplaceName: 'ai-delivery-user',
374
- version,
375
- enabled,
376
- source: { source: 'local', path: source },
377
- marketplaceSource: { sourceType: 'local', source: catalog },
378
- },
379
- ],
380
- available: [],
381
- }));
382
- }
383
- else {
384
- const path = join(nativeHome, 'plugins/known_marketplaces.json');
385
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
386
- writeFileSync(path, JSON.stringify({
387
- 'ai-delivery-user': { source: { source: 'directory', path: catalog }, installLocation: catalog },
388
- }), { mode: 0o600 });
389
- fixture.responses.push(JSON.stringify([
390
- {
391
- id: 'ai-delivery@ai-delivery-user',
392
- version,
393
- scope: 'user',
394
- enabled,
395
- installPath: cache,
396
- mcpServers: { 'ai-delivery': { command: 'node', args: ['${CLAUDE_PLUGIN_ROOT}/dist/mcp-launcher.js'] } },
397
- },
398
- ]));
440
+ function doctorFixture(enabled, host = "codex") {
441
+ const version = "0.3.21", catalog = join(fixture.home, ".cache/ai-delivery/plugins", host, "user/marketplace");
442
+ const unit = join(catalog, "versions", version), source = join(unit, "plugins/ai-delivery");
443
+ const nativeHome = join(fixture.home, host === "codex" ? ".codex" : ".claude");
444
+ const cache = join(nativeHome, "plugins/cache/ai-delivery-user/ai-delivery", version);
445
+ const files = { "mcp.json": '{"ai-delivery":{"command":"node"}}', "skills/intake/SKILL.md": "owned skill bytes" };
446
+ for (const root of [source, cache])
447
+ for (const [name, bytes] of Object.entries(files)) {
448
+ const path = join(root, name);
449
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
450
+ writeFileSync(path, bytes, { mode: 384 });
399
451
  }
400
- return cache;
452
+ const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
453
+ writeFileSync(join(unit, "archive.tgz"), "captured archive", { mode: 384 });
454
+ writeFileSync(
455
+ join(unit, "version.json"),
456
+ JSON.stringify({
457
+ owner: "@aviaratech/ai-delivery.plugin-version@1",
458
+ version,
459
+ archiveSha256: hash("captured archive"),
460
+ files: Object.fromEntries(Object.entries(files).map(([name, bytes]) => [name, hash(bytes)]))
461
+ }),
462
+ { mode: 384 }
463
+ );
464
+ writeState(
465
+ {
466
+ ...pendingState("install", version),
467
+ host,
468
+ nativeHome,
469
+ pending: void 0,
470
+ currentVersion: version,
471
+ installedPath: cache
472
+ },
473
+ host
474
+ );
475
+ for (const [relative, content] of [
476
+ [
477
+ ".agents/plugins/marketplace.json",
478
+ {
479
+ name: "ai-delivery-user",
480
+ interface: { displayName: "ai-delivery" },
481
+ plugins: [
482
+ {
483
+ name: "ai-delivery",
484
+ source: { source: "local", path: `./versions/${version}/plugins/ai-delivery` },
485
+ policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
486
+ category: "Productivity"
487
+ }
488
+ ]
489
+ }
490
+ ],
491
+ [
492
+ ".claude-plugin/marketplace.json",
493
+ {
494
+ name: "ai-delivery-user",
495
+ owner: { name: "AviaraTech" },
496
+ plugins: [{ name: "ai-delivery", source: `./versions/${version}/plugins/ai-delivery`, version }]
497
+ }
498
+ ]
499
+ ]) {
500
+ const path = join(catalog, relative);
501
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
502
+ writeFileSync(path, JSON.stringify(content), { mode: 384 });
503
+ }
504
+ if (host === "codex") {
505
+ fixture.responses.push(
506
+ JSON.stringify({
507
+ installed: [
508
+ {
509
+ pluginId: "ai-delivery@ai-delivery-user",
510
+ marketplaceName: "ai-delivery-user",
511
+ version,
512
+ enabled,
513
+ source: { source: "local", path: source },
514
+ marketplaceSource: { sourceType: "local", source: catalog }
515
+ }
516
+ ],
517
+ available: []
518
+ })
519
+ );
520
+ } else {
521
+ const path = join(nativeHome, "plugins/known_marketplaces.json");
522
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
523
+ writeFileSync(
524
+ path,
525
+ JSON.stringify({
526
+ "ai-delivery-user": { source: { source: "directory", path: catalog }, installLocation: catalog }
527
+ }),
528
+ { mode: 384 }
529
+ );
530
+ fixture.responses.push(
531
+ JSON.stringify([
532
+ {
533
+ id: "ai-delivery@ai-delivery-user",
534
+ version,
535
+ scope: "user",
536
+ enabled,
537
+ installPath: cache,
538
+ mcpServers: { "ai-delivery": { command: "node", args: ["${CLAUDE_PLUGIN_ROOT}/dist/mcp-launcher.js"] } }
539
+ }
540
+ ])
541
+ );
542
+ }
543
+ return cache;
401
544
  }
402
545
  function nativeArchiveFixture() {
403
- const root = join(fixture.home, 'synthetic-package'), version = '0.3.22';
404
- const files = {
405
- 'package.json': JSON.stringify({ name: '@aviaratech/ai-delivery', version }),
406
- 'plugins/ai-delivery/plugin.json': JSON.stringify({ name: 'ai-delivery', version }),
407
- 'plugins/ai-delivery/.claude-plugin/plugin.json': JSON.stringify({
408
- name: 'ai-delivery',
409
- version,
410
- packageVersion: version,
411
- deliveryCapabilityVersion: 2,
412
- }),
413
- 'plugins/ai-delivery/runtime/package.json': JSON.stringify({ name: '@aviaratech/ai-delivery', version }),
414
- 'plugins/ai-delivery/runtime/dist/cli.js': `process.stdout.write('${version}\\n');`,
415
- 'plugins/ai-delivery/skills/intake/SKILL.md': 'synthetic released skill bytes',
416
- };
417
- for (const [name, bytes] of Object.entries(files)) {
418
- const path = join(root, name);
419
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
420
- writeFileSync(path, bytes, { mode: 0o600 });
421
- }
422
- const configuration = join(fixture.home, 'empty.npmrc'), globalConfiguration = join(fixture.home, 'global.npmrc');
423
- writeFileSync(configuration, '', { mode: 0o600 });
424
- writeFileSync(globalConfiguration, '', { mode: 0o600 });
425
- const packed = JSON.parse(execFileSync('npm', [
426
- 'pack',
427
- '--ignore-scripts',
428
- '--json',
429
- '--logs-max',
430
- '0',
431
- '--cache',
432
- join(fixture.home, 'npm-cache'),
433
- '--userconfig',
546
+ const root = join(fixture.home, "synthetic-package"), version = "0.3.22";
547
+ const files = {
548
+ "package.json": JSON.stringify({ name: "@aviaratech/ai-delivery", version }),
549
+ "plugins/ai-delivery/plugin.json": JSON.stringify({ name: "ai-delivery", version }),
550
+ "plugins/ai-delivery/.claude-plugin/plugin.json": JSON.stringify({
551
+ name: "ai-delivery",
552
+ version,
553
+ packageVersion: version,
554
+ deliveryCapabilityVersion: 2
555
+ }),
556
+ "plugins/ai-delivery/runtime/package.json": JSON.stringify({ name: "@aviaratech/ai-delivery", version }),
557
+ "plugins/ai-delivery/runtime/dist/cli.js": `process.stdout.write('${version}\\n');`,
558
+ "plugins/ai-delivery/skills/intake/SKILL.md": "synthetic released skill bytes"
559
+ };
560
+ for (const [name, bytes] of Object.entries(files)) {
561
+ const path = join(root, name);
562
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
563
+ writeFileSync(path, bytes, { mode: 384 });
564
+ }
565
+ const configuration = join(fixture.home, "empty.npmrc"), globalConfiguration = join(fixture.home, "global.npmrc");
566
+ writeFileSync(configuration, "", { mode: 384 });
567
+ writeFileSync(globalConfiguration, "", { mode: 384 });
568
+ const packed = JSON.parse(
569
+ execFileSync(
570
+ "npm",
571
+ [
572
+ "pack",
573
+ "--ignore-scripts",
574
+ "--json",
575
+ "--logs-max",
576
+ "0",
577
+ "--cache",
578
+ join(fixture.home, "npm-cache"),
579
+ "--userconfig",
434
580
  configuration,
435
- '--globalconfig',
581
+ "--globalconfig",
436
582
  globalConfiguration,
437
- '--pack-destination',
438
- fixture.home,
439
- ], { cwd: root, encoding: 'utf8' }));
440
- fixture.packArchive = join(fixture.home, packed[0].filename);
583
+ "--pack-destination",
584
+ fixture.home
585
+ ],
586
+ { cwd: root, encoding: "utf8" }
587
+ )
588
+ );
589
+ fixture.packArchive = join(fixture.home, packed[0].filename);
441
590
  }
442
591
  function oversizedCatalogue(entries) {
443
- const filtered = JSON.stringify({ installed: entries, available: [] });
444
- const unfiltered = JSON.stringify({
445
- installed: entries,
446
- available: [{ pluginId: 'unrelated@remote', description: 'x'.repeat(1024 * 1024) }],
447
- });
448
- assert.ok(Buffer.byteLength(unfiltered) > 1024 * 1024);
449
- assert.ok(Buffer.byteLength(filtered) < 1024 * 1024);
450
- return (args) => (args[args.indexOf('--marketplace') + 1] === 'ai-delivery-user' ? filtered : unfiltered);
592
+ const filtered = JSON.stringify({ installed: entries, available: [] });
593
+ const unfiltered = JSON.stringify({
594
+ installed: entries,
595
+ available: [{ pluginId: "unrelated@remote", description: "x".repeat(1024 * 1024) }]
596
+ });
597
+ assert.ok(Buffer.byteLength(unfiltered) > 1024 * 1024);
598
+ assert.ok(Buffer.byteLength(filtered) < 1024 * 1024);
599
+ return (args) => args[args.indexOf("--marketplace") + 1] === "ai-delivery-user" ? filtered : unfiltered;
451
600
  }
452
601
  function installationFixture(action, readback = (entry) => [entry]) {
453
- let previous = [];
454
- if (action === 'update') {
455
- doctorFixture(true);
456
- const response = fixture.responses.shift();
457
- assert.ok(typeof response === 'string');
458
- previous = JSON.parse(response).installed;
459
- }
460
- nativeArchiveFixture();
461
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace'), source = join(catalog, 'versions/0.3.22/plugins/ai-delivery'), cache = join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.22');
462
- const entry = {
463
- pluginId: 'ai-delivery@ai-delivery-user',
464
- marketplaceName: 'ai-delivery-user',
465
- version: '0.3.22',
466
- enabled: true,
467
- source: { source: 'local', path: source },
468
- marketplaceSource: { sourceType: 'local', source: catalog },
469
- };
470
- fixture.responses.push('codex-cli 0.162.1', oversizedCatalogue(previous), '', '0.3.22', ...(action === 'install' ? ['{}'] : []), (args) => {
471
- assert.deepEqual(args, ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
472
- mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
473
- cpSync(source, cache, { recursive: true });
474
- return JSON.stringify({ installedPath: cache });
475
- }, oversizedCatalogue(readback(entry)));
476
- return { entry, cache, catalog, source };
602
+ let previous = [];
603
+ if (action === "update") {
604
+ doctorFixture(true);
605
+ const response = fixture.responses.shift();
606
+ assert.ok(typeof response === "string");
607
+ previous = JSON.parse(response).installed;
608
+ }
609
+ nativeArchiveFixture();
610
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/marketplace"), source = join(catalog, "versions/0.3.22/plugins/ai-delivery"), cache = join(fixture.home, ".codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.22");
611
+ const entry = {
612
+ pluginId: "ai-delivery@ai-delivery-user",
613
+ marketplaceName: "ai-delivery-user",
614
+ version: "0.3.22",
615
+ enabled: true,
616
+ source: { source: "local", path: source },
617
+ marketplaceSource: { sourceType: "local", source: catalog }
618
+ };
619
+ fixture.responses.push(
620
+ "codex-cli 0.162.1",
621
+ oversizedCatalogue(previous),
622
+ "",
623
+ "0.3.22",
624
+ ...action === "install" ? ["{}"] : [],
625
+ (args) => {
626
+ assert.deepEqual(args, ["codex", "plugin", "add", "ai-delivery@ai-delivery-user", "--json"]);
627
+ mkdirSync(dirname(cache), { recursive: true, mode: 448 });
628
+ cpSync(source, cache, { recursive: true });
629
+ return JSON.stringify({ installedPath: cache });
630
+ },
631
+ oversizedCatalogue(readback(entry))
632
+ );
633
+ return { entry, cache, catalog, source };
477
634
  }
478
- function replacementFixture(preferences = { issue_info: { approval: 'fictional-explicit-allow' } }) {
479
- const { entry, cache, catalog } = installationFixture('update');
480
- fixture.responses = [];
481
- const selector = 'ai-delivery@ai-delivery-user';
482
- const policy = {
483
- [selector]: { enabled: true, preferences },
484
- 'private-unrelated@other': { sentinel: 'fictional-private-value', enabled: false },
485
- };
486
- const before = structuredClone(policy);
487
- const native = {
488
- selected: [
489
- {
490
- ...entry,
491
- version: '0.3.21',
492
- source: { source: 'local', path: join(catalog, 'versions/0.3.21/plugins/ai-delivery') },
493
- },
494
- ],
495
- version: 'codex-cli 0.162.1',
496
- selectionCalls: 0,
497
- loseAck: false,
498
- failSelection: false,
499
- };
500
- fixture.respond = (args) => {
501
- if (args[0] === 'npm')
502
- return '';
503
- if (args[0] === process.execPath)
504
- return '0.3.22';
505
- if (args[1] === '--version')
506
- return native.version;
507
- if (args[2] === 'list') {
508
- let offeredPath;
509
- try {
510
- const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
511
- offeredPath = offered.plugins[0].source.path;
512
- }
513
- catch {
514
- return undefined;
515
- }
516
- // Pinned list takes installed version from cache and source from the current catalog.
517
- return JSON.stringify({
518
- installed: native.selected.map((plugin) => ({
519
- ...plugin,
520
- source: { source: 'local', path: join(catalog, offeredPath) },
521
- })),
522
- available: [],
523
- });
524
- }
525
- if (args[2] === 'marketplace')
526
- return '{}';
527
- if (args[2] === 'remove') {
528
- // Pinned Codex remove clears the complete qualified plugin table.
529
- delete policy[selector];
530
- native.selected = [];
531
- return '{}';
532
- }
533
- if (args[2] === 'add') {
534
- assert.deepEqual(args, ['codex', 'plugin', 'add', selector, '--json']);
535
- native.selectionCalls++;
536
- if (native.failSelection)
537
- return undefined;
538
- // Pinned add retains existing fields but can evict older native caches.
539
- policy[selector] = { ...policy[selector], enabled: true };
540
- const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
541
- const offeredPath = offered.plugins[0].source.path;
542
- const version = /^\.\/versions\/([^/]+)\/plugins\/ai-delivery$/u.exec(offeredPath)[1];
543
- const selectedCache = join(dirname(cache), version);
544
- mkdirSync(dirname(selectedCache), { recursive: true, mode: 0o700 });
545
- cpSync(join(catalog, offeredPath), selectedCache, { recursive: true });
546
- for (const old of readdirSync(dirname(cache)))
547
- if (old !== version)
548
- rmSync(join(dirname(cache), old), { recursive: true });
549
- native.selected = [{ ...entry, version, source: { source: 'local', path: join(catalog, offeredPath) } }];
550
- return native.loseAck ? undefined : JSON.stringify({ installedPath: selectedCache });
551
- }
552
- return undefined;
553
- };
554
- return { catalog, policy, before, native };
635
+ function replacementFixture(preferences = { issue_info: { approval: "fictional-explicit-allow" } }) {
636
+ const { entry, cache, catalog } = installationFixture("update");
637
+ fixture.responses = [];
638
+ const selector = "ai-delivery@ai-delivery-user";
639
+ const policy = {
640
+ [selector]: { enabled: true, preferences },
641
+ "private-unrelated@other": { sentinel: "fictional-private-value", enabled: false }
642
+ };
643
+ const before = structuredClone(policy);
644
+ const native = {
645
+ selected: [
646
+ {
647
+ ...entry,
648
+ version: "0.3.21",
649
+ source: { source: "local", path: join(catalog, "versions/0.3.21/plugins/ai-delivery") }
650
+ }
651
+ ],
652
+ version: "codex-cli 0.162.1",
653
+ selectionCalls: 0,
654
+ loseAck: false,
655
+ failSelection: false
656
+ };
657
+ fixture.respond = (args) => {
658
+ if (args[0] === "npm") return "";
659
+ if (args[0] === process.execPath) return "0.3.22";
660
+ if (args[1] === "--version") return native.version;
661
+ if (args[2] === "list") {
662
+ let offeredPath;
663
+ try {
664
+ const offered = JSON.parse(readFileSync(join(catalog, ".agents/plugins/marketplace.json"), "utf8"));
665
+ offeredPath = offered.plugins[0].source.path;
666
+ } catch {
667
+ return void 0;
668
+ }
669
+ return JSON.stringify({
670
+ installed: native.selected.map((plugin) => ({
671
+ ...plugin,
672
+ source: { source: "local", path: join(catalog, offeredPath) }
673
+ })),
674
+ available: []
675
+ });
676
+ }
677
+ if (args[2] === "marketplace") return "{}";
678
+ if (args[2] === "remove") {
679
+ delete policy[selector];
680
+ native.selected = [];
681
+ return "{}";
682
+ }
683
+ if (args[2] === "add") {
684
+ assert.deepEqual(args, ["codex", "plugin", "add", selector, "--json"]);
685
+ native.selectionCalls++;
686
+ if (native.failSelection) return void 0;
687
+ policy[selector] = { ...policy[selector], enabled: true };
688
+ const offered = JSON.parse(readFileSync(join(catalog, ".agents/plugins/marketplace.json"), "utf8"));
689
+ const offeredPath = offered.plugins[0].source.path;
690
+ const version = /^\.\/versions\/([^/]+)\/plugins\/ai-delivery$/u.exec(offeredPath)[1];
691
+ const selectedCache = join(dirname(cache), version);
692
+ mkdirSync(dirname(selectedCache), { recursive: true, mode: 448 });
693
+ cpSync(join(catalog, offeredPath), selectedCache, { recursive: true });
694
+ for (const old of readdirSync(dirname(cache)))
695
+ if (old !== version) rmSync(join(dirname(cache), old), { recursive: true });
696
+ native.selected = [{ ...entry, version, source: { source: "local", path: join(catalog, offeredPath) } }];
697
+ return native.loseAck ? void 0 : JSON.stringify({ installedPath: selectedCache });
698
+ }
699
+ return void 0;
700
+ };
701
+ return { catalog, policy, before, native };
555
702
  }
556
703
  test.each([
557
- { issue_info: { approval: 'fictional-explicit-allow' }, unknown: { nested: ['retain', null] } },
558
- { unknown: { nested: ['retain', null] } },
559
- { issue_info: null, unknown: { nested: ['retain', null] } },
560
- ])('managed replacement preserves fictional tool preferences %j without clearing the plugin entry', async (preferences) => {
704
+ { issue_info: { approval: "fictional-explicit-allow" }, unknown: { nested: ["retain", null] } },
705
+ { unknown: { nested: ["retain", null] } },
706
+ { issue_info: null, unknown: { nested: ["retain", null] } }
707
+ ])(
708
+ "managed replacement preserves fictional tool preferences %j without clearing the plugin entry",
709
+ async (preferences) => {
561
710
  const { policy, before } = replacementFixture(preferences);
562
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
563
- assert.equal(result.version, '0.3.22');
711
+ const result = await managePlugin({ ...input(), action: "update", version: "0.3.22" });
712
+ assert.equal(result.version, "0.3.22");
564
713
  assert.deepEqual(policy, before);
565
- assert.equal(fixture.commandArguments.some((args) => ['remove', 'uninstall'].includes(args[2] ?? '')), false);
566
- });
567
- test('installing a different owned version cannot bypass the preserving replacement path', async () => {
714
+ assert.equal(
715
+ fixture.commandArguments.some((args) => ["remove", "uninstall"].includes(args[2] ?? "")),
716
+ false
717
+ );
718
+ }
719
+ );
720
+ test(
721
+ "installing a different owned version cannot bypass the preserving replacement path",
722
+ { tags: ["release"] },
723
+ async () => {
568
724
  const { policy, before } = replacementFixture();
569
- await managePlugin({ ...input(), action: 'install', version: '0.3.22' });
725
+ await managePlugin({ ...input(), action: "install", version: "0.3.22" });
570
726
  assert.deepEqual(policy, before);
571
- assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
572
- });
573
- test('an exact same-version owned selection is reused without invoking native add', async () => {
574
- const { native } = replacementFixture();
575
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
576
- assert.equal(result.changed, false);
577
- assert.equal(native.selectionCalls, 0);
727
+ assert.equal(
728
+ fixture.commandArguments.some((args) => args[2] === "remove"),
729
+ false
730
+ );
731
+ }
732
+ );
733
+ test("an exact same-version owned selection is reused without invoking native add", { tags: ["release"] }, async () => {
734
+ const { native } = replacementFixture();
735
+ const result = await managePlugin({ ...input(), action: "update", version: "0.3.21" });
736
+ assert.equal(result.changed, false);
737
+ assert.equal(native.selectionCalls, 0);
578
738
  });
579
739
  test.each([
580
- 'disabled',
581
- 'missing selection',
582
- 'unregistered catalog',
583
- 'foreign source',
584
- 'changed cache',
585
- 'changed catalog',
586
- 'catalog symlink',
587
- 'read-only catalog',
588
- 'unqualified native',
589
- 'unqualified newer native',
590
- ])('replacement refuses %s before preparing a new version', async (fault) => {
591
- const { native, catalog, policy, before } = replacementFixture();
592
- if (fault === 'disabled')
593
- native.selected[0].enabled = false;
594
- if (fault === 'missing selection')
595
- native.selected = [];
596
- if (fault === 'unregistered catalog')
597
- native.selected[0].marketplaceSource.source = join(fixture.home, 'foreign-marketplace');
598
- if (fault === 'foreign source') {
599
- const respond = fixture.respond;
600
- fixture.respond = (args) => {
601
- const output = respond(args);
602
- if (args[2] !== 'list' || !output)
603
- return output;
604
- const listed = JSON.parse(output);
605
- listed.installed[0].source.path = join(fixture.home, 'unowned');
606
- return JSON.stringify(listed);
607
- };
608
- }
609
- if (fault === 'changed cache')
610
- writeFileSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21/skills/intake/SKILL.md'), 'changed');
611
- if (fault === 'changed catalog')
612
- writeFileSync(join(catalog, '.agents/plugins/marketplace.json'), '{}');
613
- const unrelatedCatalog = join(fixture.home, 'unrelated-catalog');
614
- if (fault === 'catalog symlink') {
615
- writeFileSync(unrelatedCatalog, 'unrelated catalog sentinel');
616
- rmSync(join(catalog, '.agents/plugins/marketplace.json'));
617
- symlinkSync(unrelatedCatalog, join(catalog, '.agents/plugins/marketplace.json'));
618
- }
619
- if (fault === 'read-only catalog')
620
- chmodSync(join(catalog, '.agents/plugins/marketplace.json'), 0o400);
621
- if (fault === 'unqualified native')
622
- native.version = 'codex-cli 0.153.0';
623
- if (fault === 'unqualified newer native')
624
- native.version = 'codex-cli 0.162.2';
625
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
626
- assert.equal(native.selectionCalls, 0);
627
- assert.equal(existsSync(join(catalog, 'versions/0.3.22')), false);
628
- assert.deepEqual(policy, before);
629
- if (fault === 'catalog symlink')
630
- assert.equal(readFileSync(unrelatedCatalog, 'utf8'), 'unrelated catalog sentinel');
631
- });
632
- test.each(['update', 'install', 'rollback'])('Claude owned %s refuses an unqualified native version before catalog or selection changes', async (action) => {
633
- doctorFixture(true, 'claude-code');
634
- fixture.responses.unshift('2.1.295 (Claude Code)', '--keep-data');
635
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
636
- if (action === 'rollback') {
637
- const path = join(dirname(catalog), 'state.json');
638
- const state = JSON.parse(readFileSync(path, 'utf8'));
639
- state.previousVersion = '0.3.20';
640
- writeState(state, 'claude-code');
740
+ "disabled",
741
+ "missing selection",
742
+ "unregistered catalog",
743
+ "foreign source",
744
+ "changed cache",
745
+ "changed catalog",
746
+ "catalog symlink",
747
+ "read-only catalog",
748
+ "unqualified native",
749
+ "unqualified newer native"
750
+ ])("replacement refuses %s before preparing a new version", async (fault) => {
751
+ const { native, catalog, policy, before } = replacementFixture();
752
+ if (fault === "disabled") native.selected[0].enabled = false;
753
+ if (fault === "missing selection") native.selected = [];
754
+ if (fault === "unregistered catalog")
755
+ native.selected[0].marketplaceSource.source = join(fixture.home, "foreign-marketplace");
756
+ if (fault === "foreign source") {
757
+ const respond = fixture.respond;
758
+ fixture.respond = (args) => {
759
+ const output = respond(args);
760
+ if (args[2] !== "list" || !output) return output;
761
+ const listed = JSON.parse(output);
762
+ listed.installed[0].source.path = join(fixture.home, "unowned");
763
+ return JSON.stringify(listed);
764
+ };
765
+ }
766
+ if (fault === "changed cache")
767
+ writeFileSync(
768
+ join(fixture.home, ".codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21/skills/intake/SKILL.md"),
769
+ "changed"
770
+ );
771
+ if (fault === "changed catalog") writeFileSync(join(catalog, ".agents/plugins/marketplace.json"), "{}");
772
+ const unrelatedCatalog = join(fixture.home, "unrelated-catalog");
773
+ if (fault === "catalog symlink") {
774
+ writeFileSync(unrelatedCatalog, "unrelated catalog sentinel");
775
+ rmSync(join(catalog, ".agents/plugins/marketplace.json"));
776
+ symlinkSync(unrelatedCatalog, join(catalog, ".agents/plugins/marketplace.json"));
777
+ }
778
+ if (fault === "read-only catalog") chmodSync(join(catalog, ".agents/plugins/marketplace.json"), 256);
779
+ if (fault === "unqualified native") native.version = "codex-cli 0.153.0";
780
+ if (fault === "unqualified newer native") native.version = "codex-cli 0.162.2";
781
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
782
+ assert.equal(native.selectionCalls, 0);
783
+ assert.equal(existsSync(join(catalog, "versions/0.3.22")), false);
784
+ assert.deepEqual(policy, before);
785
+ if (fault === "catalog symlink") assert.equal(readFileSync(unrelatedCatalog, "utf8"), "unrelated catalog sentinel");
786
+ });
787
+ test.each(["update", "install", "rollback"])(
788
+ "Claude owned %s refuses an unqualified native version before catalog or selection changes",
789
+ async (action) => {
790
+ doctorFixture(true, "claude-code");
791
+ fixture.responses.unshift("2.1.295 (Claude Code)", "--keep-data");
792
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins/claude-code/user/marketplace");
793
+ if (action === "rollback") {
794
+ const path = join(dirname(catalog), "state.json");
795
+ const state = JSON.parse(readFileSync(path, "utf8"));
796
+ state.previousVersion = "0.3.20";
797
+ writeState(state, "claude-code");
641
798
  }
642
- const paths = ['.agents/plugins/marketplace.json', '.claude-plugin/marketplace.json'].map((name) => join(catalog, name));
799
+ const paths = [".agents/plugins/marketplace.json", ".claude-plugin/marketplace.json"].map(
800
+ (name) => join(catalog, name)
801
+ );
643
802
  const before = paths.map((path) => readFileSync(path));
644
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action, version: action === 'rollback' ? undefined : '0.3.22' }), /preserv.*unqualified/iu);
645
- assert.deepEqual(paths.map((path) => readFileSync(path)), before);
646
- assert.equal(fixture.commandArguments.some((args) => ['update', 'install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
647
- });
803
+ await assert.rejects(
804
+ managePlugin({ ...input(), host: "claude-code", action, version: action === "rollback" ? void 0 : "0.3.22" }),
805
+ /preserv.*unqualified/iu
806
+ );
807
+ assert.deepEqual(
808
+ paths.map((path) => readFileSync(path)),
809
+ before
810
+ );
811
+ assert.equal(
812
+ fixture.commandArguments.some(
813
+ (args) => ["update", "install", "uninstall"].includes(args[2] ?? "") && !args.includes("--help")
814
+ ),
815
+ false
816
+ );
817
+ }
818
+ );
648
819
  function claudeReplacementFixture() {
649
- doctorFixture(true, 'claude-code');
650
- const initial = JSON.parse(fixture.responses.shift());
651
- nativeArchiveFixture();
652
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
653
- const settings = join(fixture.home, '.claude/settings.json');
654
- const preferences = {
655
- enabledPlugins: { 'ai-delivery@ai-delivery-user': true, 'unrelated@fictional': false },
656
- permissions: { allow: ['mcp__fictional__read'], deny: ['mcp__fictional__write'] },
657
- unknown: { nested: ['retain', null, { explicit: false }] },
658
- };
659
- writeFileSync(settings, JSON.stringify(preferences), { mode: 0o600 });
660
- const before = readFileSync(settings);
661
- const native = { selected: initial, updates: 0, loseAck: false, failSelection: false };
662
- fixture.respond = (args) => {
663
- if (args[0] === 'npm')
664
- return '';
665
- if (args[0] === process.execPath)
666
- return '0.3.22';
667
- if (args[1] === '--version')
668
- return '2.1.296 (Claude Code)';
669
- if (args[2] === 'uninstall' && args.includes('--help'))
670
- return '--keep-data';
671
- if (args[2] === 'list')
672
- return JSON.stringify(native.selected);
673
- if (args[2] === 'update') {
674
- assert.deepEqual(args, ['claude', 'plugin', 'update', 'ai-delivery@ai-delivery-user', '--scope', 'user']);
675
- native.updates++;
676
- if (native.failSelection)
677
- return undefined;
678
- const offered = JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8'));
679
- const { source, version } = offered.plugins[0];
680
- const cache = join(fixture.home, '.claude/plugins/cache/ai-delivery-user/ai-delivery', version);
681
- mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
682
- cpSync(join(catalog, source), cache, { recursive: true });
683
- native.selected = [{ ...initial[0], version, installPath: cache }];
684
- return native.loseAck ? undefined : '{}';
685
- }
686
- return undefined;
687
- };
688
- return { catalog, settings, before, native };
820
+ doctorFixture(true, "claude-code");
821
+ const initial = JSON.parse(fixture.responses.shift());
822
+ nativeArchiveFixture();
823
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins/claude-code/user/marketplace");
824
+ const settings = join(fixture.home, ".claude/settings.json");
825
+ const preferences = {
826
+ enabledPlugins: { "ai-delivery@ai-delivery-user": true, "unrelated@fictional": false },
827
+ permissions: { allow: ["mcp__fictional__read"], deny: ["mcp__fictional__write"] },
828
+ unknown: { nested: ["retain", null, { explicit: false }] }
829
+ };
830
+ writeFileSync(settings, JSON.stringify(preferences), { mode: 384 });
831
+ const before = readFileSync(settings);
832
+ const native = { selected: initial, updates: 0, loseAck: false, failSelection: false };
833
+ fixture.respond = (args) => {
834
+ if (args[0] === "npm") return "";
835
+ if (args[0] === process.execPath) return "0.3.22";
836
+ if (args[1] === "--version") return "2.1.296 (Claude Code)";
837
+ if (args[2] === "uninstall" && args.includes("--help")) return "--keep-data";
838
+ if (args[2] === "list") return JSON.stringify(native.selected);
839
+ if (args[2] === "update") {
840
+ assert.deepEqual(args, ["claude", "plugin", "update", "ai-delivery@ai-delivery-user", "--scope", "user"]);
841
+ native.updates++;
842
+ if (native.failSelection) return void 0;
843
+ const offered = JSON.parse(readFileSync(join(catalog, ".claude-plugin/marketplace.json"), "utf8"));
844
+ const { source, version } = offered.plugins[0];
845
+ const cache = join(fixture.home, ".claude/plugins/cache/ai-delivery-user/ai-delivery", version);
846
+ mkdirSync(dirname(cache), { recursive: true, mode: 448 });
847
+ cpSync(join(catalog, source), cache, { recursive: true });
848
+ native.selected = [{ ...initial[0], version, installPath: cache }];
849
+ return native.loseAck ? void 0 : "{}";
850
+ }
851
+ return void 0;
852
+ };
853
+ return { catalog, settings, before, native };
689
854
  }
690
- test.each(['update', 'install'])('Claude owned forward %s preserves preferences through native update', async (action) => {
855
+ test.each(["update", "install"])(
856
+ "Claude owned forward %s preserves preferences through native update",
857
+ async (action) => {
691
858
  const { settings, before, native } = claudeReplacementFixture();
692
- const result = await managePlugin({ ...input(), host: 'claude-code', action, version: '0.3.22' });
693
- assert.equal(result.version, '0.3.22');
694
- assert.equal(result.nativePluginRoot, join(fixture.home, '.claude/plugins/cache/ai-delivery-user/ai-delivery/0.3.22'));
859
+ const result = await managePlugin({ ...input(), host: "claude-code", action, version: "0.3.22" });
860
+ assert.equal(result.version, "0.3.22");
861
+ assert.equal(
862
+ result.nativePluginRoot,
863
+ join(fixture.home, ".claude/plugins/cache/ai-delivery-user/ai-delivery/0.3.22")
864
+ );
695
865
  assert.equal(native.updates, 1);
696
866
  assert.deepEqual(readFileSync(settings), before);
697
- assert.equal(fixture.commandArguments.some((args) => ['install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
698
- });
699
- test('Claude same-version replacement reuses its verified cache without a native update', async () => {
867
+ assert.equal(
868
+ fixture.commandArguments.some(
869
+ (args) => ["install", "uninstall"].includes(args[2] ?? "") && !args.includes("--help")
870
+ ),
871
+ false
872
+ );
873
+ }
874
+ );
875
+ test(
876
+ "Claude same-version replacement reuses its verified cache without a native update",
877
+ { tags: ["release"] },
878
+ async () => {
700
879
  const { settings, before, native } = claudeReplacementFixture();
701
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.21' });
880
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "update", version: "0.3.21" });
702
881
  assert.equal(result.changed, false);
703
882
  assert.equal(native.updates, 0);
704
883
  assert.deepEqual(readFileSync(settings), before);
705
- });
706
- test.each(['0.3.20', '0.3.22-beta.1', '0.3.22+fixture'])('Claude refuses unqualified replacement target %s before publication', async (version) => {
884
+ }
885
+ );
886
+ test.each(["0.3.20", "0.3.22-beta.1", "0.3.22+fixture"])(
887
+ "Claude refuses unqualified replacement target %s before publication",
888
+ async (version) => {
707
889
  const { catalog, native, settings, before } = claudeReplacementFixture();
708
- const paths = ['.agents/plugins/marketplace.json', '.claude-plugin/marketplace.json'].map((name) => join(catalog, name));
890
+ const paths = [".agents/plugins/marketplace.json", ".claude-plugin/marketplace.json"].map(
891
+ (name) => join(catalog, name)
892
+ );
709
893
  const catalogs = paths.map((path) => readFileSync(path));
710
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version }), /preserv.*unqualified/iu);
711
- assert.deepEqual(paths.map((path) => readFileSync(path)), catalogs);
894
+ await assert.rejects(
895
+ managePlugin({ ...input(), host: "claude-code", action: "update", version }),
896
+ /preserv.*unqualified/iu
897
+ );
898
+ assert.deepEqual(
899
+ paths.map((path) => readFileSync(path)),
900
+ catalogs
901
+ );
712
902
  assert.deepEqual(readFileSync(settings), before);
713
903
  assert.equal(native.updates, 0);
714
- assert.equal(existsSync(join(catalog, 'versions', version)), false);
715
- });
716
- test('Claude lost update acknowledgement resumes the exact target without selecting twice', async () => {
904
+ assert.equal(existsSync(join(catalog, "versions", version)), false);
905
+ }
906
+ );
907
+ test(
908
+ "Claude lost update acknowledgement resumes the exact target without selecting twice",
909
+ { tags: ["release"] },
910
+ async () => {
717
911
  const { native, settings, before, catalog } = claudeReplacementFixture();
718
912
  native.loseAck = true;
719
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
720
- const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
721
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
722
- writeState(interrupted, 'claude-code');
913
+ await assert.rejects(managePlugin({ ...input(), host: "claude-code", action: "update", version: "0.3.22" }));
914
+ const interrupted = JSON.parse(readFileSync(join(dirname(catalog), "state.json"), "utf8"));
915
+ interrupted.pending.owner = { pid: 2e9, birth: "old owner" };
916
+ writeState(interrupted, "claude-code");
723
917
  native.loseAck = false;
724
- await managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' });
918
+ await managePlugin({ ...input(), host: "claude-code", action: "update", version: "0.3.22" });
725
919
  assert.equal(native.updates, 1);
726
920
  assert.deepEqual(readFileSync(settings), before);
727
- });
728
- test('Claude prior selection with a published target catalog refuses an ambiguous retry', async () => {
921
+ }
922
+ );
923
+ test(
924
+ "Claude prior selection with a published target catalog refuses an ambiguous retry",
925
+ { tags: ["release"] },
926
+ async () => {
729
927
  const { native, settings, before, catalog } = claudeReplacementFixture();
730
928
  native.failSelection = true;
731
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
732
- const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
733
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
734
- writeState(interrupted, 'claude-code');
929
+ await assert.rejects(managePlugin({ ...input(), host: "claude-code", action: "update", version: "0.3.22" }));
930
+ const interrupted = JSON.parse(readFileSync(join(dirname(catalog), "state.json"), "utf8"));
931
+ interrupted.pending.owner = { pid: 2e9, birth: "old owner" };
932
+ writeState(interrupted, "claude-code");
735
933
  native.failSelection = false;
736
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }), /ambiguous/iu);
934
+ await assert.rejects(
935
+ managePlugin({ ...input(), host: "claude-code", action: "update", version: "0.3.22" }),
936
+ /ambiguous/iu
937
+ );
737
938
  assert.equal(native.updates, 1);
738
939
  assert.deepEqual(readFileSync(settings), before);
739
- });
740
- test('Claude doctor rejects changed native cache bytes before starting MCP', async () => {
741
- const cache = doctorFixture(true, 'claude-code');
742
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'foreign native cache bytes');
743
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
744
- assert.equal(result.sourceIntegrity, false);
745
- assert.equal(result.mcp?.startup, 'not_checked');
746
- });
747
- test('Claude doctor refuses a native cache path that differs from the owned selection', async () => {
748
- doctorFixture(true, 'claude-code');
749
- const entries = JSON.parse(fixture.responses[0]);
750
- entries[0].installPath = join(fixture.home, 'foreign-native-cache');
751
- fixture.responses[0] = JSON.stringify(entries);
752
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
753
- assert.equal(result.sourceIntegrity, false);
754
- assert.equal(result.mcp?.startup, 'not_checked');
755
- });
756
- test('lost native acknowledgement remains a failure, then exact target postimage resumes without selecting twice', async () => {
940
+ }
941
+ );
942
+ test("Claude doctor rejects changed native cache bytes before starting MCP", async () => {
943
+ const cache = doctorFixture(true, "claude-code");
944
+ writeFileSync(join(cache, "skills/intake/SKILL.md"), "foreign native cache bytes");
945
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "doctor", version: void 0 });
946
+ assert.equal(result.sourceIntegrity, false);
947
+ assert.equal(result.mcp?.startup, "not_checked");
948
+ });
949
+ test("Claude doctor refuses a native cache path that differs from the owned selection", async () => {
950
+ doctorFixture(true, "claude-code");
951
+ const entries = JSON.parse(fixture.responses[0]);
952
+ entries[0].installPath = join(fixture.home, "foreign-native-cache");
953
+ fixture.responses[0] = JSON.stringify(entries);
954
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "doctor", version: void 0 });
955
+ assert.equal(result.sourceIntegrity, false);
956
+ assert.equal(result.mcp?.startup, "not_checked");
957
+ });
958
+ test(
959
+ "lost native acknowledgement remains a failure, then exact target postimage resumes without selecting twice",
960
+ { tags: ["release"] },
961
+ async () => {
757
962
  const { native, policy, before, catalog } = replacementFixture();
758
963
  native.loseAck = true;
759
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
964
+ await assert.rejects(
965
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
966
+ /Native fixture intentionally unavailable/u
967
+ );
760
968
  assert.deepEqual(policy, before);
761
- const path = join(dirname(catalog), 'state.json');
762
- const interrupted = JSON.parse(readFileSync(path, 'utf8'));
763
- assert.equal(interrupted.currentVersion, '0.3.21');
764
- assert.equal(interrupted.pending.targetVersion, '0.3.22');
765
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
969
+ const path = join(dirname(catalog), "state.json");
970
+ const interrupted = JSON.parse(readFileSync(path, "utf8"));
971
+ assert.equal(interrupted.currentVersion, "0.3.21");
972
+ assert.equal(interrupted.pending.targetVersion, "0.3.22");
973
+ interrupted.pending.owner = { pid: 2e9, birth: "old owner" };
766
974
  writeState(interrupted);
767
975
  native.loseAck = false;
768
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
769
- assert.equal(result.version, '0.3.22');
976
+ const result = await managePlugin({ ...input(), action: "update", version: "0.3.22" });
977
+ assert.equal(result.version, "0.3.22");
770
978
  assert.equal(native.selectionCalls, 1);
771
979
  assert.deepEqual(policy, before);
772
- const finished = JSON.parse(readFileSync(path, 'utf8'));
773
- assert.equal(finished.currentVersion, '0.3.22');
774
- assert.equal(finished.previousVersion, '0.3.21');
775
- assert.equal(finished.pending, undefined);
776
- });
777
- test('a target catalog with prior native selection and an idle pending command refuses ambiguous replay', async () => {
980
+ const finished = JSON.parse(readFileSync(path, "utf8"));
981
+ assert.equal(finished.currentVersion, "0.3.22");
982
+ assert.equal(finished.previousVersion, "0.3.21");
983
+ assert.equal(finished.pending, void 0);
984
+ }
985
+ );
986
+ test(
987
+ "a target catalog with prior native selection and an idle pending command refuses ambiguous replay",
988
+ { tags: ["release"] },
989
+ async () => {
778
990
  const { native, catalog } = replacementFixture();
779
991
  native.failSelection = true;
780
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
781
- const path = join(dirname(catalog), 'state.json');
782
- const interrupted = JSON.parse(readFileSync(path, 'utf8'));
783
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
992
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
993
+ const path = join(dirname(catalog), "state.json");
994
+ const interrupted = JSON.parse(readFileSync(path, "utf8"));
995
+ interrupted.pending.owner = { pid: 2e9, birth: "old owner" };
784
996
  writeState(interrupted);
785
997
  native.failSelection = false;
786
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /ambiguous/u);
998
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }), /ambiguous/u);
787
999
  assert.equal(native.selectionCalls, 1);
788
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, '0.3.22');
789
- });
790
- test('recovery rejects a corrupted completed unit before reusing the selected target', async () => {
1000
+ assert.equal(
1001
+ JSON.parse(readFileSync(path, "utf8")).pending.targetVersion,
1002
+ "0.3.22"
1003
+ );
1004
+ }
1005
+ );
1006
+ test(
1007
+ "recovery rejects a corrupted completed unit before reusing the selected target",
1008
+ { tags: ["release"] },
1009
+ async () => {
791
1010
  const { native, catalog } = replacementFixture();
792
1011
  native.loseAck = true;
793
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
794
- const statePath = join(dirname(catalog), 'state.json');
795
- const pending = JSON.parse(readFileSync(statePath, 'utf8'));
796
- pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated selected owner' };
1012
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
1013
+ const statePath = join(dirname(catalog), "state.json");
1014
+ const pending = JSON.parse(readFileSync(statePath, "utf8"));
1015
+ pending.pending.owner = { pid: 2e9, birth: "terminated selected owner" };
797
1016
  writeState(pending);
798
- const archive = join(catalog, 'versions/0.3.22/archive.tgz');
799
- writeFileSync(archive, 'corrupted completed archive');
1017
+ const archive = join(catalog, "versions/0.3.22/archive.tgz");
1018
+ writeFileSync(archive, "corrupted completed archive");
800
1019
  native.loseAck = false;
801
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
1020
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
802
1021
  assert.equal(native.selectionCalls, 1);
803
- assert.equal(readFileSync(archive, 'utf8'), 'corrupted completed archive');
804
- assert.ok(JSON.parse(readFileSync(statePath, 'utf8')).pending);
805
- });
806
- test('qualified Codex rollback uses the retained immutable unit and preserves later unrelated edits', async () => {
1022
+ assert.equal(readFileSync(archive, "utf8"), "corrupted completed archive");
1023
+ assert.ok(JSON.parse(readFileSync(statePath, "utf8")).pending);
1024
+ }
1025
+ );
1026
+ test(
1027
+ "qualified Codex rollback uses the retained immutable unit and preserves later unrelated edits",
1028
+ { tags: ["release"] },
1029
+ async () => {
807
1030
  const { native, catalog, policy, before } = replacementFixture();
808
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
809
- assert.equal(existsSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21')), false);
810
- assert.equal(existsSync(join(catalog, 'versions/0.3.21/version.json')), true);
811
- policy.later = { sentinel: 'keep later edit' };
812
- const rolled = await managePlugin({ ...input(), action: 'rollback', version: undefined });
813
- assert.equal(rolled.version, '0.3.21');
1031
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
1032
+ assert.equal(existsSync(join(fixture.home, ".codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21")), false);
1033
+ assert.equal(existsSync(join(catalog, "versions/0.3.21/version.json")), true);
1034
+ policy.later = { sentinel: "keep later edit" };
1035
+ const rolled = await managePlugin({ ...input(), action: "rollback", version: void 0 });
1036
+ assert.equal(rolled.version, "0.3.21");
814
1037
  assert.equal(native.selectionCalls, 2);
815
- assert.deepEqual(policy, { ...before, later: { sentinel: 'keep later edit' } });
816
- });
817
- test('rollback of a removed managed selection refuses rather than reinstalling it', async () => {
818
- const { catalog, native, policy } = replacementFixture();
819
- const path = join(dirname(catalog), 'state.json');
820
- const state = JSON.parse(readFileSync(path, 'utf8'));
821
- state.currentVersion = null;
822
- state.previousVersion = '0.3.21';
823
- state.installedPath = null;
824
- writeState(state);
825
- native.selected = [];
826
- delete policy['ai-delivery@ai-delivery-user'];
827
- const before = structuredClone(policy);
828
- await assert.rejects(managePlugin({ ...input(), action: 'rollback', version: undefined }), /current managed selection/u);
829
- assert.deepEqual(fixture.commandArguments, []);
830
- assert.deepEqual(policy, before);
831
- });
832
- test('rollback refuses a target superseded by the managed writer ahead of its lock', async () => {
1038
+ assert.deepEqual(policy, { ...before, later: { sentinel: "keep later edit" } });
1039
+ }
1040
+ );
1041
+ test("rollback of a removed managed selection refuses rather than reinstalling it", { tags: ["release"] }, async () => {
1042
+ const { catalog, native, policy } = replacementFixture();
1043
+ const path = join(dirname(catalog), "state.json");
1044
+ const state = JSON.parse(readFileSync(path, "utf8"));
1045
+ state.currentVersion = null;
1046
+ state.previousVersion = "0.3.21";
1047
+ state.installedPath = null;
1048
+ writeState(state);
1049
+ native.selected = [];
1050
+ delete policy["ai-delivery@ai-delivery-user"];
1051
+ const before = structuredClone(policy);
1052
+ await assert.rejects(
1053
+ managePlugin({ ...input(), action: "rollback", version: void 0 }),
1054
+ /current managed selection/u
1055
+ );
1056
+ assert.deepEqual(fixture.commandArguments, []);
1057
+ assert.deepEqual(policy, before);
1058
+ });
1059
+ test(
1060
+ "rollback refuses a target superseded by the managed writer ahead of its lock",
1061
+ { tags: ["release"] },
1062
+ async () => {
833
1063
  const { catalog, native } = replacementFixture();
834
- const path = join(dirname(catalog), 'state.json');
835
- const initial = JSON.parse(readFileSync(path, 'utf8'));
836
- initial.previousVersion = '0.3.20';
1064
+ const path = join(dirname(catalog), "state.json");
1065
+ const initial = JSON.parse(readFileSync(path, "utf8"));
1066
+ initial.previousVersion = "0.3.20";
837
1067
  writeState(initial);
838
1068
  const respond = fixture.respond;
839
1069
  let queuedRollback;
840
1070
  fixture.respond = (args) => {
841
- const output = respond(args);
842
- if (args[2] === 'list' && native.selected[0]?.version === '0.3.22' && !queuedRollback)
843
- queuedRollback = managePlugin({ ...input(), action: 'rollback', version: undefined }).then(() => undefined, (error) => error);
844
- return output;
1071
+ const output = respond(args);
1072
+ if (args[2] === "list" && native.selected[0]?.version === "0.3.22" && !queuedRollback)
1073
+ queuedRollback = managePlugin({ ...input(), action: "rollback", version: void 0 }).then(
1074
+ () => void 0,
1075
+ (error2) => error2
1076
+ );
1077
+ return output;
845
1078
  };
846
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
1079
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
847
1080
  assert.ok(queuedRollback);
848
1081
  const error = await queuedRollback;
849
1082
  assert.ok(error instanceof Error);
850
1083
  assert.match(error.message, /rollback target changed before/u);
851
1084
  assert.equal(native.selectionCalls, 1);
852
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).currentVersion, '0.3.22');
853
- });
854
- test('a partial catalog publication resumes with reused units and matches an uninterrupted update', async () => {
1085
+ assert.equal(JSON.parse(readFileSync(path, "utf8")).currentVersion, "0.3.22");
1086
+ }
1087
+ );
1088
+ test(
1089
+ "a partial catalog publication resumes with reused units and matches an uninterrupted update",
1090
+ { tags: ["release"] },
1091
+ async () => {
855
1092
  const first = replacementFixture();
856
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
857
- const statePath = join(dirname(first.catalog), 'state.json');
858
- const uninterrupted = JSON.parse(readFileSync(statePath, 'utf8'));
1093
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
1094
+ const statePath = join(dirname(first.catalog), "state.json");
1095
+ const uninterrupted = JSON.parse(readFileSync(statePath, "utf8"));
859
1096
  const { catalog, native, policy, before } = replacementFixture();
860
- const immutableArchive = join(catalog, 'versions/0.3.22/archive.tgz');
1097
+ const immutableArchive = join(catalog, "versions/0.3.22/archive.tgz");
861
1098
  const archiveBefore = readFileSync(immutableArchive);
862
1099
  const actual = atomicJson.writePrivateJsonFileAtomically;
863
1100
  let interrupt = true;
864
- vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
865
- if (interrupt && path === join(catalog, '.claude-plugin/marketplace.json')) {
866
- interrupt = false;
867
- throw new Error('Synthetic catalog publication interruption');
868
- }
869
- actual(path, value);
1101
+ vi.spyOn(atomicJson, "writePrivateJsonFileAtomically").mockImplementation((path, value) => {
1102
+ if (interrupt && path === join(catalog, ".claude-plugin/marketplace.json")) {
1103
+ interrupt = false;
1104
+ throw new Error("Synthetic catalog publication interruption");
1105
+ }
1106
+ actual(path, value);
870
1107
  });
871
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /publication interruption/u);
1108
+ await assert.rejects(
1109
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
1110
+ /publication interruption/u
1111
+ );
872
1112
  assert.equal(native.selectionCalls, 0);
873
- assert.equal(JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8')).plugins[0].version, '0.3.21');
874
- assert.match(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'), /versions\/0\.3\.22/u);
875
- const pending = JSON.parse(readFileSync(statePath, 'utf8'));
876
- pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated publication owner' };
1113
+ assert.equal(
1114
+ JSON.parse(readFileSync(join(catalog, ".claude-plugin/marketplace.json"), "utf8")).plugins[0].version,
1115
+ "0.3.21"
1116
+ );
1117
+ assert.match(readFileSync(join(catalog, ".agents/plugins/marketplace.json"), "utf8"), /versions\/0\.3\.22/u);
1118
+ const pending = JSON.parse(readFileSync(statePath, "utf8"));
1119
+ pending.pending.owner = { pid: 2e9, birth: "terminated publication owner" };
877
1120
  writeState(pending);
878
1121
  fixture.commands = [];
879
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
880
- assert.deepEqual(JSON.parse(readFileSync(statePath, 'utf8')), uninterrupted);
1122
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
1123
+ assert.deepEqual(JSON.parse(readFileSync(statePath, "utf8")), uninterrupted);
881
1124
  assert.deepEqual(readFileSync(immutableArchive), archiveBefore);
882
- assert.equal(fixture.commands.includes('npm'), false);
1125
+ assert.equal(fixture.commands.includes("npm"), false);
883
1126
  assert.equal(native.selectionCalls, 1);
884
1127
  assert.deepEqual(policy, before);
885
- });
886
- test('a failed managed-state commit retains selection and resumes without selecting again', async () => {
1128
+ }
1129
+ );
1130
+ test(
1131
+ "a failed managed-state commit retains selection and resumes without selecting again",
1132
+ { tags: ["release"] },
1133
+ async () => {
887
1134
  const { native, catalog, policy, before } = replacementFixture();
888
1135
  const actual = atomicJson.writePrivateJsonFileAtomically;
889
- const fault = vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
890
- const state = value;
891
- if (path.endsWith('/state.json') && state.currentVersion === '0.3.22' && !state.pending)
892
- throw new Error('Synthetic final state commit failure');
893
- actual(path, value);
1136
+ const fault = vi.spyOn(atomicJson, "writePrivateJsonFileAtomically").mockImplementation((path2, value) => {
1137
+ const state = value;
1138
+ if (path2.endsWith("/state.json") && state.currentVersion === "0.3.22" && !state.pending)
1139
+ throw new Error("Synthetic final state commit failure");
1140
+ actual(path2, value);
894
1141
  });
895
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /final state commit failure/u);
1142
+ await assert.rejects(
1143
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
1144
+ /final state commit failure/u
1145
+ );
896
1146
  fault.mockRestore();
897
- const path = join(dirname(catalog), 'state.json');
898
- const pending = JSON.parse(readFileSync(path, 'utf8'));
899
- pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated commit owner' };
1147
+ const path = join(dirname(catalog), "state.json");
1148
+ const pending = JSON.parse(readFileSync(path, "utf8"));
1149
+ pending.pending.owner = { pid: 2e9, birth: "terminated commit owner" };
900
1150
  writeState(pending);
901
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
1151
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
902
1152
  assert.equal(native.selectionCalls, 1);
903
1153
  assert.deepEqual(policy, before);
904
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending, undefined);
905
- });
906
- test.each(['bytes', 'mode'])('managed state %s changed by another writer is not overwritten after native selection', async (change) => {
1154
+ assert.equal(JSON.parse(readFileSync(path, "utf8")).pending, void 0);
1155
+ }
1156
+ );
1157
+ test.each(["bytes", "mode"])(
1158
+ "managed state %s changed by another writer is not overwritten after native selection",
1159
+ async (change) => {
907
1160
  const { catalog, native } = replacementFixture();
908
1161
  const respond = fixture.respond;
909
- const path = join(dirname(catalog), 'state.json');
1162
+ const path = join(dirname(catalog), "state.json");
910
1163
  let changed;
911
1164
  fixture.respond = (args) => {
912
- const output = respond(args);
913
- if (args[2] === 'add') {
914
- if (change === 'mode')
915
- chmodSync(path, 0o400);
916
- else {
917
- const state = JSON.parse(readFileSync(path, 'utf8'));
918
- state.previousVersion = '0.3.19';
919
- writeFileSync(path, JSON.stringify(state), { mode: 0o600 });
920
- }
921
- changed = readFileSync(path);
1165
+ const output = respond(args);
1166
+ if (args[2] === "add") {
1167
+ if (change === "mode") chmodSync(path, 256);
1168
+ else {
1169
+ const state = JSON.parse(readFileSync(path, "utf8"));
1170
+ state.previousVersion = "0.3.19";
1171
+ writeFileSync(path, JSON.stringify(state), { mode: 384 });
922
1172
  }
923
- return output;
1173
+ changed = readFileSync(path);
1174
+ }
1175
+ return output;
924
1176
  };
925
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Managed state changed/u);
1177
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }), /Managed state changed/u);
926
1178
  assert.equal(native.selectionCalls, 1);
927
1179
  assert.ok(changed);
928
1180
  assert.deepEqual(readFileSync(path), changed);
929
- if (change === 'mode')
930
- assert.equal(lstatSync(path).mode & 0o777, 0o400);
931
- });
932
- test('catalog custody changed during preparation refuses before selection without repairing it', async () => {
1181
+ if (change === "mode") assert.equal(lstatSync(path).mode & 511, 256);
1182
+ }
1183
+ );
1184
+ test(
1185
+ "catalog custody changed during preparation refuses before selection without repairing it",
1186
+ { tags: ["release"] },
1187
+ async () => {
933
1188
  const { catalog, native, policy, before } = replacementFixture();
934
1189
  const respond = fixture.respond;
935
- const path = join(catalog, '.agents/plugins/marketplace.json');
1190
+ const path = join(catalog, ".agents/plugins/marketplace.json");
936
1191
  fixture.respond = (args) => {
937
- const output = respond(args);
938
- if (args[0] === process.execPath)
939
- chmodSync(path, 0o644);
940
- return output;
1192
+ const output = respond(args);
1193
+ if (args[0] === process.execPath) chmodSync(path, 420);
1194
+ return output;
941
1195
  };
942
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /catalog.*changed/u);
1196
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }), /catalog.*changed/u);
943
1197
  assert.equal(native.selectionCalls, 0);
944
- assert.equal(lstatSync(path).mode & 0o777, 0o644);
1198
+ assert.equal(lstatSync(path).mode & 511, 420);
945
1199
  assert.deepEqual(policy, before);
946
- });
947
- for (const action of ['install', 'update'])
948
- test(`${action} reads back its managed version without capturing an unrelated catalogue over 1 MiB`, async () => {
949
- const { entry, cache, catalog } = installationFixture(action);
950
- const data = join(fixture.home, 'unrelated-native-data');
951
- writeFileSync(data, 'preserve native data');
952
- const result = await managePlugin({ ...input(), action, version: '0.3.22' });
953
- assert.equal(result.installed, true);
954
- assert.equal(result.changed, true);
955
- assert.equal(result.version, '0.3.22');
956
- assert.equal(result.nativePluginRoot, cache);
957
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'synthetic released skill bytes');
958
- const state = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
959
- assert.equal(state.pending, undefined);
960
- assert.equal(state.currentVersion, '0.3.22');
961
- assert.equal(state.previousVersion, action === 'update' ? '0.3.21' : null);
962
- const mutation = fixture.commandArguments.find((args) => args[2] === (action === 'install' ? 'marketplace' : 'add'));
963
- assert.deepEqual(mutation, action === 'install'
964
- ? ['codex', 'plugin', 'marketplace', 'add', catalog, '--json']
965
- : ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
966
- assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
967
- fixture.responses.push(oversizedCatalogue([{ ...entry, enabled: false }]));
968
- const doctor = await managePlugin({ ...input(), action: 'doctor', version: undefined });
969
- assert.equal(doctor.installed, true);
970
- assert.equal(doctor.sourceIntegrity, true);
971
- assert.deepEqual(doctor.mcp, { configuration: 'disabled', startup: 'not_checked' });
972
- assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
973
- assert.equal(fixture.commandArguments.filter((args) => args[2] === 'list').length, 4);
974
- });
975
- test('the filtered managed catalogue still enforces the 1 MiB capture ceiling', async () => {
976
- doctorFixture(false);
977
- fixture.responses[0] = JSON.stringify({ installed: [], available: [{ description: 'x'.repeat(1024 * 1024) }] });
978
- await assert.rejects(managePlugin({ ...input(), action: 'doctor', version: undefined }), /captured output exceeded 1048576 bytes/u);
1200
+ }
1201
+ );
1202
+ for (const action of ["install", "update"])
1203
+ test(
1204
+ `${action} reads back its managed version without capturing an unrelated catalogue over 1 MiB`,
1205
+ { tags: ["release"] },
1206
+ async () => {
1207
+ const { entry, cache, catalog } = installationFixture(action);
1208
+ const data = join(fixture.home, "unrelated-native-data");
1209
+ writeFileSync(data, "preserve native data");
1210
+ const result = await managePlugin({ ...input(), action, version: "0.3.22" });
1211
+ assert.equal(result.installed, true);
1212
+ assert.equal(result.changed, true);
1213
+ assert.equal(result.version, "0.3.22");
1214
+ assert.equal(result.nativePluginRoot, cache);
1215
+ assert.equal(readFileSync(join(cache, "skills/intake/SKILL.md"), "utf8"), "synthetic released skill bytes");
1216
+ const state = JSON.parse(readFileSync(join(dirname(catalog), "state.json"), "utf8"));
1217
+ assert.equal(state.pending, void 0);
1218
+ assert.equal(state.currentVersion, "0.3.22");
1219
+ assert.equal(state.previousVersion, action === "update" ? "0.3.21" : null);
1220
+ const mutation = fixture.commandArguments.find(
1221
+ (args) => args[2] === (action === "install" ? "marketplace" : "add")
1222
+ );
1223
+ assert.deepEqual(
1224
+ mutation,
1225
+ action === "install" ? ["codex", "plugin", "marketplace", "add", catalog, "--json"] : ["codex", "plugin", "add", "ai-delivery@ai-delivery-user", "--json"]
1226
+ );
1227
+ assert.equal(
1228
+ fixture.commandArguments.some((args) => args[2] === "remove"),
1229
+ false
1230
+ );
1231
+ fixture.responses.push(oversizedCatalogue([{ ...entry, enabled: false }]));
1232
+ const doctor = await managePlugin({ ...input(), action: "doctor", version: void 0 });
1233
+ assert.equal(doctor.installed, true);
1234
+ assert.equal(doctor.sourceIntegrity, true);
1235
+ assert.deepEqual(doctor.mcp, { configuration: "disabled", startup: "not_checked" });
1236
+ assert.equal(readFileSync(data, "utf8"), "preserve native data");
1237
+ assert.equal(fixture.commandArguments.filter((args) => args[2] === "list").length, 4);
1238
+ }
1239
+ );
1240
+ test("the filtered managed catalogue still enforces the 1 MiB capture ceiling", async () => {
1241
+ doctorFixture(false);
1242
+ fixture.responses[0] = JSON.stringify({ installed: [], available: [{ description: "x".repeat(1024 * 1024) }] });
1243
+ await assert.rejects(
1244
+ managePlugin({ ...input(), action: "doctor", version: void 0 }),
1245
+ /captured output exceeded 1048576 bytes/u
1246
+ );
979
1247
  });
980
1248
  for (const [name, readback, error] of [
981
- [
982
- 'missing registration',
983
- (entry) => [{ ...entry, marketplaceName: 'unrelated' }],
984
- /registration is missing/u,
1249
+ [
1250
+ "missing registration",
1251
+ (entry) => [{ ...entry, marketplaceName: "unrelated" }],
1252
+ /registration is missing/u
1253
+ ],
1254
+ [
1255
+ "wrong marketplace source",
1256
+ (entry) => [
1257
+ { ...entry, marketplaceSource: { sourceType: "local", source: join(fixture.home, "unmanaged") } }
985
1258
  ],
986
- [
987
- 'wrong marketplace source',
988
- (entry) => [
989
- { ...entry, marketplaceSource: { sourceType: 'local', source: join(fixture.home, 'unmanaged') } },
990
- ],
991
- /unmanaged source/u,
992
- ],
993
- [
994
- 'wrong version source',
995
- (entry) => [
996
- { ...entry, source: { source: 'local', path: join(fixture.home, 'unmanaged') } },
997
- ],
998
- /source differs/u,
999
- ],
1000
- ['duplicate native selection', (entry) => [entry, entry], /ambiguous/u],
1001
- [
1002
- 'disabled native selection',
1003
- (entry) => [{ ...entry, enabled: false }],
1004
- /selection is disabled/u,
1259
+ /unmanaged source/u
1260
+ ],
1261
+ [
1262
+ "wrong version source",
1263
+ (entry) => [
1264
+ { ...entry, source: { source: "local", path: join(fixture.home, "unmanaged") } }
1005
1265
  ],
1266
+ /source differs/u
1267
+ ],
1268
+ ["duplicate native selection", (entry) => [entry, entry], /ambiguous/u],
1269
+ [
1270
+ "disabled native selection",
1271
+ (entry) => [{ ...entry, enabled: false }],
1272
+ /selection is disabled/u
1273
+ ]
1006
1274
  ])
1007
- test(`filtered installation refuses ${name} and retains its interrupted intent`, async () => {
1008
- const { catalog } = installationFixture('install', readback);
1009
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), error);
1010
- const state = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
1011
- assert.equal(state.currentVersion, null);
1012
- assert.equal(state.pending.targetVersion, '0.3.22');
1013
- });
1014
- test('filtered readback refuses changed native bytes without adopting the selected version', async () => {
1015
- const { cache, catalog } = installationFixture('install');
1275
+ test(`filtered installation refuses ${name} and retains its interrupted intent`, { tags: ["release"] }, async () => {
1276
+ const { catalog } = installationFixture("install", readback);
1277
+ await assert.rejects(managePlugin({ ...input(), version: "0.3.22" }), error);
1278
+ const state = JSON.parse(readFileSync(join(dirname(catalog), "state.json"), "utf8"));
1279
+ assert.equal(state.currentVersion, null);
1280
+ assert.equal(state.pending.targetVersion, "0.3.22");
1281
+ });
1282
+ test(
1283
+ "filtered readback refuses changed native bytes without adopting the selected version",
1284
+ { tags: ["release"] },
1285
+ async () => {
1286
+ const { cache, catalog } = installationFixture("install");
1016
1287
  const add = fixture.responses[5];
1017
- assert.ok(typeof add === 'function');
1288
+ assert.ok(typeof add === "function");
1018
1289
  fixture.responses[5] = (args) => {
1019
- const result = add(args);
1020
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'unexpected native bytes');
1021
- return result;
1290
+ const result = add(args);
1291
+ writeFileSync(join(cache, "skills/intake/SKILL.md"), "unexpected native bytes");
1292
+ return result;
1022
1293
  };
1023
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), /native plugin bytes/u);
1024
- const state = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
1294
+ await assert.rejects(managePlugin({ ...input(), version: "0.3.22" }), /native plugin bytes/u);
1295
+ const state = JSON.parse(readFileSync(join(dirname(catalog), "state.json"), "utf8"));
1025
1296
  assert.equal(state.currentVersion, null);
1026
1297
  assert.ok(state.pending);
1027
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'unexpected native bytes');
1028
- });
1029
- test('interrupted filtered readback resumes the original install without fetching or losing native data', async () => {
1030
- const { entry, cache, catalog } = installationFixture('install');
1298
+ assert.equal(readFileSync(join(cache, "skills/intake/SKILL.md"), "utf8"), "unexpected native bytes");
1299
+ }
1300
+ );
1301
+ test(
1302
+ "interrupted filtered readback resumes the original install without fetching or losing native data",
1303
+ { tags: ["release"] },
1304
+ async () => {
1305
+ const { entry, cache, catalog } = installationFixture("install");
1031
1306
  fixture.responses.pop();
1032
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1033
- const statePath = join(dirname(catalog), 'state.json');
1034
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1035
- state.pending.owner = { pid: 2_000_000_000, birth: 'terminated fixture owner' };
1036
- writeFileSync(statePath, JSON.stringify(state), { mode: 0o600 });
1037
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1038
- fixture.responses.push('codex-cli 0.153.0', oversizedCatalogue([entry]), oversizedCatalogue([entry]));
1039
- const result = await managePlugin({ ...input(), version: '0.3.22' });
1040
- assert.equal(result.installed, true);
1041
- assert.equal(result.version, '0.3.22');
1042
- assert.equal(JSON.parse(readFileSync(statePath, 'utf8')).pending, undefined);
1043
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
1044
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
1045
- });
1046
- test('filtered inventory does not adopt a manual install even when its marketplace source matches', async () => {
1047
- const cache = doctorFixture(true);
1048
- const response = fixture.responses.shift();
1049
- assert.ok(typeof response === 'string');
1050
- const directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user');
1051
- rmSync(directory, { recursive: true });
1052
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1053
- fixture.responses.push('codex-cli 0.153.0', response);
1054
- await assert.rejects(managePlugin(input()), /not owned by managed state/u);
1055
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1056
- const state = JSON.parse(readFileSync(join(directory, 'state.json'), 'utf8'));
1057
- assert.equal(state.currentVersion, null);
1058
- assert.equal(state.installedPath, null);
1059
- assert.equal(state.pending, undefined);
1060
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
1061
- });
1062
- test('Claude doctor retains its unfiltered native inventory and disabled selection readback', async () => {
1063
- doctorFixture(false, 'claude-code');
1064
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1065
- assert.equal(result.installed, true);
1066
- assert.equal(result.enabled, false);
1067
- assert.equal(result.sourceIntegrity, true);
1068
- assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
1069
- assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
1070
- });
1071
- test('Claude doctor binds managed provenance to the verified scope and source, excluding other projects', async () => {
1072
- doctorFixture(false, 'claude-code');
1073
- const entries = JSON.parse(fixture.responses[0]);
1074
- const selected = entries[0];
1075
- entries.push({ ...selected, scope: 'project', projectPath: fixture.home, version: '0.3.24', installPath: '/unverified' }, { ...selected, scope: 'local', projectPath: fixture.home, installPath: '/unverified' }, { ...selected, scope: 'project', projectPath: join(fixture.home, 'other-project') }, { ...selected, scope: 'local' });
1076
- fixture.responses[0] = JSON.stringify(entries);
1077
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1078
- assert.equal(result.sourceIntegrity, true);
1079
- assert.ok(result.diagnostics);
1080
- assert.deepEqual(result.diagnostics.registrations, [
1081
- {
1082
- kind: 'plugin',
1083
- scope: 'user',
1084
- ownership: 'managed',
1085
- source: 'managed_archive',
1086
- version: '0.3.21',
1087
- enabled: false,
1088
- },
1089
- { kind: 'plugin', scope: 'project', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: false },
1090
- { kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
1091
- { kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
1092
- ]);
1093
- assert.ok(result.diagnostics.findings.includes('native_registration_project_unverified'));
1094
- assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
1095
- });
1096
- test('doctor refuses a same-version native cache with changed skill bytes before starting MCP', async () => {
1097
- const cache = doctorFixture(true);
1098
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'unexpected native bytes');
1099
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1100
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1307
+ await assert.rejects(managePlugin({ ...input(), version: "0.3.22" }), /Native fixture intentionally unavailable/u);
1308
+ const statePath = join(dirname(catalog), "state.json");
1309
+ const state = JSON.parse(readFileSync(statePath, "utf8"));
1310
+ state.pending.owner = { pid: 2e9, birth: "terminated fixture owner" };
1311
+ writeFileSync(statePath, JSON.stringify(state), { mode: 384 });
1312
+ const before = readFileSync(join(cache, "skills/intake/SKILL.md"));
1313
+ fixture.responses.push("codex-cli 0.153.0", oversizedCatalogue([entry]), oversizedCatalogue([entry]));
1314
+ const result = await managePlugin({ ...input(), version: "0.3.22" });
1101
1315
  assert.equal(result.installed, true);
1102
- assert.equal(result.sourceIntegrity, false);
1103
- assert.equal(result.mcp?.startup, 'not_checked');
1104
- assert.match(result.mcp?.error ?? '', /native plugin bytes/u);
1105
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1106
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
1107
- });
1108
- test('doctor reports a disabled native plugin separately and does not start its MCP server', async () => {
1109
- doctorFixture(false);
1110
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1111
- assert.equal(result.installed, true);
1112
- assert.equal(result.enabled, false);
1113
- assert.equal(result.sourceIntegrity, true);
1114
- assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
1115
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1116
- });
1117
- test('doctor refuses a Claude catalog pointing at a different same-version source before startup', async () => {
1118
- doctorFixture(true, 'claude-code');
1119
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
1120
- const other = join(catalog, 'unexpected-source');
1121
- mkdirSync(other, { mode: 0o700 });
1122
- writeFileSync(join(other, 'plugin.json'), JSON.stringify({ name: 'ai-delivery', version: '0.3.21' }));
1123
- const path = join(catalog, '.claude-plugin/marketplace.json');
1124
- writeFileSync(path, JSON.stringify({
1125
- name: 'ai-delivery-user',
1126
- plugins: [{ name: 'ai-delivery', version: '0.3.21', source: './unexpected-source' }],
1127
- }));
1128
- const before = readFileSync(path);
1129
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1130
- assert.equal(result.sourceIntegrity, false);
1131
- assert.equal(result.mcp?.startup, 'not_checked');
1132
- assert.match(result.mcp?.error ?? '', /catalog source/u);
1133
- assert.deepEqual(fixture.commands, ['claude']);
1134
- assert.deepEqual(readFileSync(path), before);
1135
- });
1136
- test('a different native profile cannot reconcile or overwrite the original ownership record', async () => {
1137
- const profileA = join(fixture.home, 'profile-a'), profileB = join(fixture.home, 'profile-b');
1138
- mkdirSync(profileA, { mode: 0o700 });
1139
- const marker = join(profileA, 'plugin-selection');
1140
- writeFileSync(marker, 'profile A stays installed');
1141
- const value = pendingState('install', '0.3.21');
1142
- const statePath = writeState({ ...value, pending: undefined, currentVersion: '0.3.21', nativeHome: profileA });
1143
- const before = readFileSync(statePath);
1144
- vi.stubEnv('CODEX_HOME', profileB);
1145
- await assert.rejects(managePlugin({ ...input(), action: 'remove', version: undefined }), /different native profile/u);
1146
- assert.deepEqual(fixture.commands, []);
1147
- assert.deepEqual(readFileSync(statePath), before);
1148
- assert.equal(readFileSync(marker, 'utf8'), 'profile A stays installed');
1149
- });
1150
- test('an absent native profile beneath a symlink keeps its identity after creation', async () => {
1151
- const parent = join(fixture.home, 'native-profiles'), alias = join(fixture.home, 'native-profile-alias');
1152
- mkdirSync(parent, { mode: 0o700 });
1153
- symlinkSync(parent, alias);
1154
- const profile = join(alias, 'new-profile');
1155
- vi.stubEnv('CODEX_HOME', profile);
1156
- await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1157
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1158
- const before = readFileSync(statePath);
1159
- const state = JSON.parse(before.toString());
1160
- assert.equal(state.nativeHome, join(parent, 'new-profile'));
1161
- mkdirSync(profile, { mode: 0o700 });
1162
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1163
- assert.equal(result.recoveryRequired, false);
1164
- assert.deepEqual(readFileSync(statePath), before);
1165
- assert.equal(result.diagnostics?.nativeInventory, 'unavailable');
1166
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1167
- });
1168
- test('a definitive version preparation failure preserves selection and permits a different valid request', async () => {
1169
- const cache = doctorFixture(true);
1170
- const response = fixture.responses[0];
1171
- fixture.responses.unshift('codex-cli 0.162.1');
1172
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace');
1173
- const catalogPath = join(catalog, '.agents/plugins/marketplace.json');
1174
- mkdirSync(dirname(catalogPath), { recursive: true, mode: 0o700 });
1175
- const before = readFileSync(catalogPath);
1176
- const data = join(fixture.home, 'native-data');
1177
- writeFileSync(data, 'preserve native data');
1178
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1179
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1180
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1181
- assert.equal(state.pending, undefined);
1182
- assert.equal(state.currentVersion, '0.3.21');
1183
- assert.equal(state.installedPath, cache);
1184
- assert.deepEqual(readFileSync(catalogPath), before);
1185
- assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
1186
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
1187
- fixture.responses.push('codex-cli 0.162.1', response, response);
1188
- const reused = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
1189
- assert.equal(reused.changed, false);
1190
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
1191
- });
1192
- test('failure after catalog selection retains pending recovery before another version', async () => {
1316
+ assert.equal(result.version, "0.3.22");
1317
+ assert.equal(JSON.parse(readFileSync(statePath, "utf8")).pending, void 0);
1318
+ assert.deepEqual(readFileSync(join(cache, "skills/intake/SKILL.md")), before);
1319
+ assert.equal(fixture.commands.filter((command) => command === "npm").length, 1);
1320
+ }
1321
+ );
1322
+ test("filtered inventory does not adopt a manual install even when its marketplace source matches", async () => {
1323
+ const cache = doctorFixture(true);
1324
+ const response = fixture.responses.shift();
1325
+ assert.ok(typeof response === "string");
1326
+ const directory = join(fixture.home, ".cache/ai-delivery/plugins/codex/user");
1327
+ rmSync(directory, { recursive: true });
1328
+ const before = readFileSync(join(cache, "skills/intake/SKILL.md"));
1329
+ fixture.responses.push("codex-cli 0.153.0", response);
1330
+ await assert.rejects(managePlugin(input()), /not owned by managed state/u);
1331
+ assert.deepEqual(fixture.commands, ["codex", "codex"]);
1332
+ const state = JSON.parse(readFileSync(join(directory, "state.json"), "utf8"));
1333
+ assert.equal(state.currentVersion, null);
1334
+ assert.equal(state.installedPath, null);
1335
+ assert.equal(state.pending, void 0);
1336
+ assert.deepEqual(readFileSync(join(cache, "skills/intake/SKILL.md")), before);
1337
+ });
1338
+ test("Claude doctor retains its unfiltered native inventory and disabled selection readback", async () => {
1339
+ doctorFixture(false, "claude-code");
1340
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "doctor", version: void 0 });
1341
+ assert.equal(result.installed, true);
1342
+ assert.equal(result.enabled, false);
1343
+ assert.equal(result.sourceIntegrity, true);
1344
+ assert.deepEqual(result.mcp, { configuration: "disabled", startup: "not_checked" });
1345
+ assert.deepEqual(fixture.commandArguments, [["claude", "plugin", "list", "--json"]]);
1346
+ });
1347
+ test("Claude doctor binds managed provenance to the verified scope and source, excluding other projects", async () => {
1348
+ doctorFixture(false, "claude-code");
1349
+ const entries = JSON.parse(fixture.responses[0]);
1350
+ const selected = entries[0];
1351
+ entries.push(
1352
+ { ...selected, scope: "project", projectPath: fixture.home, version: "0.3.24", installPath: "/unverified" },
1353
+ { ...selected, scope: "local", projectPath: fixture.home, installPath: "/unverified" },
1354
+ { ...selected, scope: "project", projectPath: join(fixture.home, "other-project") },
1355
+ { ...selected, scope: "local" }
1356
+ );
1357
+ fixture.responses[0] = JSON.stringify(entries);
1358
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "doctor", version: void 0 });
1359
+ assert.equal(result.sourceIntegrity, true);
1360
+ assert.ok(result.diagnostics);
1361
+ assert.deepEqual(result.diagnostics.registrations, [
1362
+ {
1363
+ kind: "plugin",
1364
+ scope: "user",
1365
+ ownership: "managed",
1366
+ source: "managed_archive",
1367
+ version: "0.3.21",
1368
+ behind: true,
1369
+ enabled: false
1370
+ },
1371
+ {
1372
+ kind: "plugin",
1373
+ scope: "project",
1374
+ ownership: "external",
1375
+ source: "unknown",
1376
+ version: "0.3.24",
1377
+ behind: true,
1378
+ enabled: false
1379
+ },
1380
+ {
1381
+ kind: "plugin",
1382
+ scope: "local",
1383
+ ownership: "external",
1384
+ source: "unknown",
1385
+ version: "0.3.21",
1386
+ behind: true,
1387
+ enabled: false
1388
+ },
1389
+ {
1390
+ kind: "plugin",
1391
+ scope: "local",
1392
+ ownership: "external",
1393
+ source: "unknown",
1394
+ version: "0.3.21",
1395
+ behind: true,
1396
+ enabled: false
1397
+ }
1398
+ ]);
1399
+ assert.ok(result.diagnostics.findings.includes("native_registration_project_unverified"));
1400
+ assert.deepEqual(fixture.commandArguments, [["claude", "plugin", "list", "--json"]]);
1401
+ });
1402
+ test("doctor refuses a same-version native cache with changed skill bytes before starting MCP", async () => {
1403
+ const cache = doctorFixture(true);
1404
+ writeFileSync(join(cache, "skills/intake/SKILL.md"), "unexpected native bytes");
1405
+ const before = readFileSync(join(cache, "skills/intake/SKILL.md"));
1406
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
1407
+ assert.equal(result.installed, true);
1408
+ assert.equal(result.sourceIntegrity, false);
1409
+ assert.equal(result.mcp?.startup, "not_checked");
1410
+ assert.match(result.mcp?.error ?? "", /native plugin bytes/u);
1411
+ assert.deepEqual(fixture.commands, ["codex", "codex"]);
1412
+ assert.deepEqual(readFileSync(join(cache, "skills/intake/SKILL.md")), before);
1413
+ });
1414
+ test("doctor reports a disabled native plugin separately and does not start its MCP server", async () => {
1415
+ doctorFixture(false);
1416
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
1417
+ assert.equal(result.installed, true);
1418
+ assert.equal(result.enabled, false);
1419
+ assert.equal(result.sourceIntegrity, true);
1420
+ assert.deepEqual(result.mcp, { configuration: "disabled", startup: "not_checked" });
1421
+ assert.deepEqual(fixture.commands, ["codex", "codex"]);
1422
+ });
1423
+ test("doctor refuses a Claude catalog pointing at a different same-version source before startup", async () => {
1424
+ doctorFixture(true, "claude-code");
1425
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins/claude-code/user/marketplace");
1426
+ const other = join(catalog, "unexpected-source");
1427
+ mkdirSync(other, { mode: 448 });
1428
+ writeFileSync(join(other, "plugin.json"), JSON.stringify({ name: "ai-delivery", version: "0.3.21" }));
1429
+ const path = join(catalog, ".claude-plugin/marketplace.json");
1430
+ writeFileSync(
1431
+ path,
1432
+ JSON.stringify({
1433
+ name: "ai-delivery-user",
1434
+ plugins: [{ name: "ai-delivery", version: "0.3.21", source: "./unexpected-source" }]
1435
+ })
1436
+ );
1437
+ const before = readFileSync(path);
1438
+ const result = await managePlugin({ ...input(), host: "claude-code", action: "doctor", version: void 0 });
1439
+ assert.equal(result.sourceIntegrity, false);
1440
+ assert.equal(result.mcp?.startup, "not_checked");
1441
+ assert.match(result.mcp?.error ?? "", /catalog source/u);
1442
+ assert.deepEqual(fixture.commands, ["claude"]);
1443
+ assert.deepEqual(readFileSync(path), before);
1444
+ });
1445
+ test("a different native profile cannot reconcile or overwrite the original ownership record", async () => {
1446
+ const profileA = join(fixture.home, "profile-a"), profileB = join(fixture.home, "profile-b");
1447
+ mkdirSync(profileA, { mode: 448 });
1448
+ const marker = join(profileA, "plugin-selection");
1449
+ writeFileSync(marker, "profile A stays installed");
1450
+ const value = pendingState("install", "0.3.21");
1451
+ const statePath = writeState({ ...value, pending: void 0, currentVersion: "0.3.21", nativeHome: profileA });
1452
+ const before = readFileSync(statePath);
1453
+ vi.stubEnv("CODEX_HOME", profileB);
1454
+ await assert.rejects(managePlugin({ ...input(), action: "remove", version: void 0 }), /different native profile/u);
1455
+ assert.deepEqual(fixture.commands, []);
1456
+ assert.deepEqual(readFileSync(statePath), before);
1457
+ assert.equal(readFileSync(marker, "utf8"), "profile A stays installed");
1458
+ });
1459
+ test("an absent native profile beneath a symlink keeps its identity after creation", async () => {
1460
+ const parent = join(fixture.home, "native-profiles"), alias = join(fixture.home, "native-profile-alias");
1461
+ mkdirSync(parent, { mode: 448 });
1462
+ symlinkSync(parent, alias);
1463
+ const profile = join(alias, "new-profile");
1464
+ vi.stubEnv("CODEX_HOME", profile);
1465
+ await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1466
+ const statePath = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1467
+ const before = readFileSync(statePath);
1468
+ const state = JSON.parse(before.toString());
1469
+ assert.equal(state.nativeHome, join(parent, "new-profile"));
1470
+ mkdirSync(profile, { mode: 448 });
1471
+ const result = await managePlugin({ ...input(), action: "doctor", version: void 0 });
1472
+ assert.equal(result.recoveryRequired, false);
1473
+ assert.deepEqual(readFileSync(statePath), before);
1474
+ assert.equal(result.diagnostics?.nativeInventory, "unavailable");
1475
+ assert.deepEqual(fixture.commands, ["codex", "codex"]);
1476
+ });
1477
+ test("a definitive version preparation failure preserves selection and permits a different valid request", async () => {
1478
+ const cache = doctorFixture(true);
1479
+ const response = fixture.responses[0];
1480
+ fixture.responses.unshift("codex-cli 0.162.1");
1481
+ const catalog = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/marketplace");
1482
+ const catalogPath = join(catalog, ".agents/plugins/marketplace.json");
1483
+ mkdirSync(dirname(catalogPath), { recursive: true, mode: 448 });
1484
+ const before = readFileSync(catalogPath);
1485
+ const data = join(fixture.home, "native-data");
1486
+ writeFileSync(data, "preserve native data");
1487
+ await assert.rejects(
1488
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
1489
+ /Native fixture intentionally unavailable/u
1490
+ );
1491
+ const statePath = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1492
+ const state = JSON.parse(readFileSync(statePath, "utf8"));
1493
+ assert.equal(state.pending, void 0);
1494
+ assert.equal(state.currentVersion, "0.3.21");
1495
+ assert.equal(state.installedPath, cache);
1496
+ assert.deepEqual(readFileSync(catalogPath), before);
1497
+ assert.equal(readFileSync(data, "utf8"), "preserve native data");
1498
+ assert.equal(readFileSync(join(cache, "skills/intake/SKILL.md"), "utf8"), "owned skill bytes");
1499
+ fixture.responses.push("codex-cli 0.162.1", response, response);
1500
+ const reused = await managePlugin({ ...input(), action: "update", version: "0.3.21" });
1501
+ assert.equal(reused.changed, false);
1502
+ assert.equal(fixture.commands.filter((command) => command === "npm").length, 1);
1503
+ });
1504
+ test(
1505
+ "failure after catalog selection retains pending recovery before another version",
1506
+ { tags: ["release"] },
1507
+ async () => {
1193
1508
  const { native } = replacementFixture();
1194
1509
  native.failSelection = true;
1195
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1196
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1197
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1198
- assert.equal(state.pending?.targetVersion, '0.3.22');
1510
+ await assert.rejects(
1511
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
1512
+ /Native fixture intentionally unavailable/u
1513
+ );
1514
+ const statePath = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1515
+ const state = JSON.parse(readFileSync(statePath, "utf8"));
1516
+ assert.equal(state.pending?.targetVersion, "0.3.22");
1199
1517
  const before = [...fixture.commandArguments];
1200
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.23' }), /A live plugin installer still owns this target|Resume the interrupted original plugin command/u);
1518
+ await assert.rejects(
1519
+ managePlugin({ ...input(), action: "update", version: "0.3.23" }),
1520
+ /A live plugin installer still owns this target|Resume the interrupted original plugin command/u
1521
+ );
1201
1522
  assert.deepEqual(fixture.commandArguments, before);
1202
- });
1203
- test('definitive preparation reports pending-state cleanup failure and preserves its recovery intent', async () => {
1204
- const actual = atomicJson.writePrivateJsonFileAtomically;
1205
- vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
1206
- if (path.endsWith('/state.json') && !value.pending)
1207
- throw new Error('Synthetic pending-state durability failure');
1208
- actual(path, value);
1209
- });
1210
- await assert.rejects(managePlugin(input()), (error) => {
1211
- assert.ok(error instanceof AggregateError);
1212
- assert.match(error.message, /pending-state cleanup also failed/u);
1213
- assert.equal(error.errors.length, 2);
1214
- return true;
1215
- });
1216
- const path = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1217
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, '0.3.21');
1218
- });
1219
- test('an unsupported version archive leaves selection intact and permits a valid version request', async () => {
1523
+ }
1524
+ );
1525
+ test("definitive preparation reports pending-state cleanup failure and preserves its recovery intent", async () => {
1526
+ const actual = atomicJson.writePrivateJsonFileAtomically;
1527
+ vi.spyOn(atomicJson, "writePrivateJsonFileAtomically").mockImplementation((path2, value) => {
1528
+ if (path2.endsWith("/state.json") && !value.pending)
1529
+ throw new Error("Synthetic pending-state durability failure");
1530
+ actual(path2, value);
1531
+ });
1532
+ await assert.rejects(managePlugin(input()), (error) => {
1533
+ assert.ok(error instanceof AggregateError);
1534
+ assert.match(error.message, /pending-state cleanup also failed/u);
1535
+ assert.equal(error.errors.length, 2);
1536
+ return true;
1537
+ });
1538
+ const path = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1539
+ assert.equal(
1540
+ JSON.parse(readFileSync(path, "utf8")).pending.targetVersion,
1541
+ "0.3.21"
1542
+ );
1543
+ });
1544
+ test(
1545
+ "an unsupported version archive leaves selection intact and permits a valid version request",
1546
+ { tags: ["release"] },
1547
+ async () => {
1220
1548
  const cache = doctorFixture(true);
1221
1549
  const response = fixture.responses[0];
1222
- fixture.responses.unshift('codex-cli 0.162.1');
1223
- const root = join(fixture.home, 'unsupported/package');
1550
+ fixture.responses.unshift("codex-cli 0.162.1");
1551
+ const root = join(fixture.home, "unsupported/package");
1224
1552
  const files = {
1225
- 'package.json': { name: '@aviaratech/ai-delivery', version: '0.3.22' },
1226
- 'plugins/ai-delivery/plugin.json': { name: 'ai-delivery', version: '0.3.22' },
1227
- 'plugins/ai-delivery/.claude-plugin/plugin.json': {
1228
- name: 'ai-delivery',
1229
- version: '0.3.22',
1230
- packageVersion: '0.3.22',
1231
- deliveryCapabilityVersion: 1,
1232
- },
1233
- 'plugins/ai-delivery/runtime/package.json': { name: '@aviaratech/ai-delivery', version: '0.3.22' },
1553
+ "package.json": { name: "@aviaratech/ai-delivery", version: "0.3.22" },
1554
+ "plugins/ai-delivery/plugin.json": { name: "ai-delivery", version: "0.3.22" },
1555
+ "plugins/ai-delivery/.claude-plugin/plugin.json": {
1556
+ name: "ai-delivery",
1557
+ version: "0.3.22",
1558
+ packageVersion: "0.3.22",
1559
+ deliveryCapabilityVersion: 1
1560
+ },
1561
+ "plugins/ai-delivery/runtime/package.json": { name: "@aviaratech/ai-delivery", version: "0.3.22" }
1234
1562
  };
1235
1563
  for (const [name, value] of Object.entries(files)) {
1236
- const path = join(root, name);
1237
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
1238
- writeFileSync(path, JSON.stringify(value), { mode: 0o600 });
1564
+ const path = join(root, name);
1565
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
1566
+ writeFileSync(path, JSON.stringify(value), { mode: 384 });
1239
1567
  }
1240
- const configuration = join(fixture.home, 'empty.npmrc');
1241
- const globalConfiguration = join(fixture.home, 'global.npmrc');
1242
- writeFileSync(configuration, '', { mode: 0o600 });
1243
- writeFileSync(globalConfiguration, '', { mode: 0o600 });
1244
- const packed = JSON.parse(execFileSync('npm', [
1245
- 'pack',
1246
- '--ignore-scripts',
1247
- '--json',
1248
- '--logs-max',
1249
- '0',
1250
- '--cache',
1251
- join(fixture.home, 'npm-cache'),
1252
- '--userconfig',
1253
- configuration,
1254
- '--globalconfig',
1255
- globalConfiguration,
1256
- '--pack-destination',
1257
- fixture.home,
1258
- ], { cwd: root, encoding: 'utf8' }));
1568
+ const configuration = join(fixture.home, "empty.npmrc");
1569
+ const globalConfiguration = join(fixture.home, "global.npmrc");
1570
+ writeFileSync(configuration, "", { mode: 384 });
1571
+ writeFileSync(globalConfiguration, "", { mode: 384 });
1572
+ const packed = JSON.parse(
1573
+ execFileSync(
1574
+ "npm",
1575
+ [
1576
+ "pack",
1577
+ "--ignore-scripts",
1578
+ "--json",
1579
+ "--logs-max",
1580
+ "0",
1581
+ "--cache",
1582
+ join(fixture.home, "npm-cache"),
1583
+ "--userconfig",
1584
+ configuration,
1585
+ "--globalconfig",
1586
+ globalConfiguration,
1587
+ "--pack-destination",
1588
+ fixture.home
1589
+ ],
1590
+ { cwd: root, encoding: "utf8" }
1591
+ )
1592
+ );
1259
1593
  fixture.packArchive = join(fixture.home, packed[0].filename);
1260
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /coherent self-contained native plugin/u);
1261
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1262
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1263
- assert.equal(state.pending, undefined);
1264
- assert.equal(state.currentVersion, '0.3.21');
1594
+ await assert.rejects(
1595
+ managePlugin({ ...input(), action: "update", version: "0.3.22" }),
1596
+ /coherent self-contained native plugin/u
1597
+ );
1598
+ const statePath = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1599
+ const state = JSON.parse(readFileSync(statePath, "utf8"));
1600
+ assert.equal(state.pending, void 0);
1601
+ assert.equal(state.currentVersion, "0.3.21");
1265
1602
  assert.equal(state.installedPath, cache);
1266
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
1267
- assert.equal(existsSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions/0.3.22')), false);
1268
- fixture.packArchive = '';
1269
- fixture.responses.push('codex-cli 0.162.1', response, response);
1270
- const reused = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
1603
+ assert.equal(readFileSync(join(cache, "skills/intake/SKILL.md"), "utf8"), "owned skill bytes");
1604
+ assert.equal(
1605
+ existsSync(join(fixture.home, ".cache/ai-delivery/plugins/codex/user/marketplace/versions/0.3.22")),
1606
+ false
1607
+ );
1608
+ fixture.packArchive = "";
1609
+ fixture.responses.push("codex-cli 0.162.1", response, response);
1610
+ const reused = await managePlugin({ ...input(), action: "update", version: "0.3.21" });
1271
1611
  assert.equal(reused.changed, false);
1272
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
1273
- });
1274
- test('recovery removes only its recorded incomplete staging directory', async () => {
1275
- const version = '0.3.21', directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions');
1276
- const owned = join(directory, '.stage-11111111-1111-1111-1111-111111111111'), peer = join(directory, '.stage-peer');
1277
- for (const path of [owned, peer]) {
1278
- mkdirSync(path, { recursive: true, mode: 0o700 });
1279
- writeFileSync(join(path, 'partial'), 'preserve-or-recover');
1280
- }
1281
- const metadata = lstatSync(owned), value = pendingState('install', version);
1282
- writeState({
1283
- ...value,
1284
- pending: { ...value.pending, staging: { path: owned, device: metadata.dev, inode: metadata.ino } },
1285
- });
1286
- await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1287
- assert.equal(existsSync(owned), false);
1288
- assert.equal(readFileSync(join(peer, 'partial'), 'utf8'), 'preserve-or-recover');
1289
- });
1290
- test('recovery rejects incompatible controllers without starting native commands', async () => {
1291
- const value = pendingState('install', '0.3.21');
1292
- writeState({ ...value, pending: { ...value.pending, producerDigest: `sha256:${'0'.repeat(64)}` } });
1293
- await assert.rejects(managePlugin(input()), /different controller/u);
1294
- assert.deepEqual(fixture.commands, []);
1295
- });
1296
- test('cancellation kills recorded detached descendants and preserves an unrelated process', async () => {
1612
+ assert.equal(fixture.commands.filter((command) => command === "npm").length, 1);
1613
+ }
1614
+ );
1615
+ test("recovery removes only its recorded incomplete staging directory", async () => {
1616
+ const version = "0.3.21", directory = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/marketplace/versions");
1617
+ const owned = join(directory, ".stage-11111111-1111-1111-1111-111111111111"), peer = join(directory, ".stage-peer");
1618
+ for (const path of [owned, peer]) {
1619
+ mkdirSync(path, { recursive: true, mode: 448 });
1620
+ writeFileSync(join(path, "partial"), "preserve-or-recover");
1621
+ }
1622
+ const metadata = lstatSync(owned), value = pendingState("install", version);
1623
+ writeState({
1624
+ ...value,
1625
+ pending: { ...value.pending, staging: { path: owned, device: metadata.dev, inode: metadata.ino } }
1626
+ });
1627
+ await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1628
+ assert.equal(existsSync(owned), false);
1629
+ assert.equal(readFileSync(join(peer, "partial"), "utf8"), "preserve-or-recover");
1630
+ });
1631
+ test("recovery rejects incompatible controllers without starting native commands", async () => {
1632
+ const value = pendingState("install", "0.3.21");
1633
+ writeState({ ...value, pending: { ...value.pending, producerDigest: `sha256:${"0".repeat(64)}` } });
1634
+ await assert.rejects(managePlugin(input()), /different controller/u);
1635
+ assert.deepEqual(fixture.commands, []);
1636
+ });
1637
+ test(
1638
+ "cancellation kills recorded detached descendants and preserves an unrelated process",
1639
+ { tags: ["release"] },
1640
+ async () => {
1297
1641
  fixture.realCommands = true;
1298
- const bin = join(fixture.home, 'bin'), marker = join(fixture.home, 'descendant');
1642
+ const bin = join(fixture.home, "bin"), marker = join(fixture.home, "descendant");
1299
1643
  mkdirSync(bin);
1300
1644
  const childScript = "require('fs').writeFileSync(process.argv[1],String(process.pid));process.on('SIGTERM',()=>{});setInterval(()=>{},1000)";
1301
- writeFileSync(join(bin, 'codex'), `#!${process.execPath}\nconst {spawn}=require('child_process');spawn(process.execPath,['-e',${JSON.stringify(childScript)},${JSON.stringify(marker)}],{detached:true,stdio:'ignore'});setInterval(()=>{},1000);\n`, { mode: 0o700 });
1302
- vi.stubEnv('PATH', `${bin}:${process.env.PATH ?? ''}`);
1303
- const peer = spawn(process.execPath, ['-e', 'setInterval(()=>{},1000)'], { stdio: 'ignore' });
1645
+ writeFileSync(
1646
+ join(bin, "codex"),
1647
+ `#!${process.execPath}
1648
+ const {spawn}=require('child_process');spawn(process.execPath,['-e',${JSON.stringify(childScript)},${JSON.stringify(marker)}],{detached:true,stdio:'ignore'});setInterval(()=>{},1000);
1649
+ `,
1650
+ { mode: 448 }
1651
+ );
1652
+ vi.stubEnv("PATH", `${bin}:${process.env.PATH ?? ""}`);
1653
+ const peer = spawn(process.execPath, ["-e", "setInterval(()=>{},1000)"], { stdio: "ignore" });
1304
1654
  const preload = fixturePreload();
1305
- const cli = spawn(process.execPath, [
1306
- '--import',
1655
+ const cli = spawn(
1656
+ process.execPath,
1657
+ [
1658
+ "--import",
1307
1659
  preload,
1308
- join(dirname(fileURLToPath(import.meta.url)), 'cli.js'),
1309
- '--repo-root',
1660
+ join(dirname(fileURLToPath(import.meta.url)), "cli.js"),
1661
+ "--repo-root",
1310
1662
  fixture.home,
1311
- 'plugin',
1312
- 'install',
1313
- '--host',
1314
- 'codex',
1315
- '--scope',
1316
- 'user',
1317
- '--version',
1318
- '0.3.21',
1319
- '--json',
1320
- ], { stdio: ['ignore', 'pipe', 'pipe'] });
1321
- let output = '';
1663
+ "plugin",
1664
+ "install",
1665
+ "--host",
1666
+ "codex",
1667
+ "--scope",
1668
+ "user",
1669
+ "--version",
1670
+ "0.3.21",
1671
+ "--json"
1672
+ ],
1673
+ { stdio: ["ignore", "pipe", "pipe"] }
1674
+ );
1675
+ let output = "";
1322
1676
  for (const stream of [cli.stdout, cli.stderr])
1323
- stream.on('data', (bytes) => {
1324
- if (Buffer.byteLength(output) + bytes.length <= 1024 * 1024)
1325
- output += bytes.toString();
1326
- });
1327
- const closed = new Promise((done) => cli.once('close', (code) => done(code)));
1677
+ stream.on("data", (bytes) => {
1678
+ if (Buffer.byteLength(output) + bytes.length <= 1024 * 1024) output += bytes.toString();
1679
+ });
1680
+ const closed = new Promise((done) => cli.once("close", (code) => done(code)));
1328
1681
  let descendant;
1329
1682
  try {
1330
- for (let attempt = 0; attempt < 1000; attempt++) {
1331
- if (cli.exitCode !== null || cli.signalCode !== null)
1332
- break;
1333
- if (existsSync(marker)) {
1334
- descendant = Number(readFileSync(marker, 'utf8'));
1335
- const path = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1336
- const pending = JSON.parse(readFileSync(path, 'utf8')).pending;
1337
- if (pending.command.phase === 'running' &&
1338
- pending.command.tracked.some((entry) => entry.pid === descendant))
1339
- break;
1340
- }
1341
- await new Promise((done) => setTimeout(done, 20));
1683
+ for (let attempt = 0; attempt < 1e3; attempt++) {
1684
+ if (cli.exitCode !== null || cli.signalCode !== null) break;
1685
+ if (existsSync(marker)) {
1686
+ descendant = Number(readFileSync(marker, "utf8"));
1687
+ const path = join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json");
1688
+ const pending = JSON.parse(readFileSync(path, "utf8")).pending;
1689
+ if (pending.command.phase === "running" && pending.command.tracked.some((entry) => entry.pid === descendant))
1690
+ break;
1342
1691
  }
1343
- assert.ok(descendant, `native fixture started its detached child: ${output}`);
1344
- const state = JSON.parse(readFileSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json'), 'utf8'));
1345
- assert.ok(state.pending.command.tracked.some((entry) => entry.pid === descendant), 'durable receipt captured child identity');
1346
- cli.kill('SIGTERM');
1347
- assert.equal(await closed, 1);
1348
- assert.match(output, /cancelled/u);
1349
- const observed = processSnapshot().get(descendant);
1350
- assert.ok(!observed || observed.status.startsWith('Z'));
1351
- assert.ok(processSnapshot().has(peer.pid));
1352
- assert.equal(JSON.parse(readFileSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json'), 'utf8')).pending.command.phase, 'idle');
1353
- }
1354
- finally {
1355
- cli.kill('SIGTERM');
1356
- await closed;
1357
- peer.kill('SIGKILL');
1358
- await new Promise((done) => {
1359
- if (peer.exitCode !== null || peer.signalCode !== null)
1360
- done();
1361
- else
1362
- peer.once('close', () => done());
1363
- });
1692
+ await new Promise((done) => setTimeout(done, 20));
1693
+ }
1694
+ assert.ok(descendant, `native fixture started its detached child: ${output}`);
1695
+ const state = JSON.parse(
1696
+ readFileSync(join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json"), "utf8")
1697
+ );
1698
+ assert.ok(
1699
+ state.pending.command.tracked.some((entry) => entry.pid === descendant),
1700
+ "durable receipt captured child identity"
1701
+ );
1702
+ cli.kill("SIGTERM");
1703
+ assert.equal(await closed, 1);
1704
+ assert.match(output, /cancelled/u);
1705
+ const observed = processSnapshot().get(descendant);
1706
+ assert.ok(!observed || observed.status.startsWith("Z"));
1707
+ assert.ok(processSnapshot().has(peer.pid));
1708
+ assert.equal(
1709
+ JSON.parse(
1710
+ readFileSync(join(fixture.home, ".cache/ai-delivery/plugins/codex/user/state.json"), "utf8")
1711
+ ).pending.command.phase,
1712
+ "idle"
1713
+ );
1714
+ } finally {
1715
+ cli.kill("SIGTERM");
1716
+ await closed;
1717
+ peer.kill("SIGKILL");
1718
+ await new Promise((done) => {
1719
+ if (peer.exitCode !== null || peer.signalCode !== null) done();
1720
+ else peer.once("close", () => done());
1721
+ });
1364
1722
  }
1365
- });
1366
- const input = () => ({ action: 'install', host: 'codex', scope: 'user', version: '0.3.21', repoRoot: fixture.home });
1723
+ }
1724
+ );
1725
+ const input = () => ({ action: "install", host: "codex", scope: "user", version: "0.3.21", repoRoot: fixture.home });
1367
1726
  function fixturePreload() {
1368
- const path = join(fixture.home, 'home.mjs');
1369
- writeFileSync(path, `import os from 'node:os';import {syncBuiltinESMExports} from 'node:module';os.homedir=()=>${JSON.stringify(fixture.home)};syncBuiltinESMExports();`);
1370
- return path;
1727
+ const path = join(fixture.home, "home.mjs");
1728
+ writeFileSync(
1729
+ path,
1730
+ `import os from 'node:os';import {syncBuiltinESMExports} from 'node:module';os.homedir=()=>${JSON.stringify(fixture.home)};syncBuiltinESMExports();`
1731
+ );
1732
+ return path;
1371
1733
  }
1372
- test('compiled plugin CLI consumes its local version and emits the promised JSON dry-run', () => {
1373
- const cli = join(dirname(fileURLToPath(import.meta.url)), 'cli.js');
1374
- const result = spawnSync(process.execPath, [
1375
- '--import',
1734
+ test(
1735
+ "compiled plugin CLI consumes its local version and emits the promised JSON dry-run",
1736
+ { tags: ["release"] },
1737
+ () => {
1738
+ const cli = join(dirname(fileURLToPath(import.meta.url)), "cli.js");
1739
+ const result = spawnSync(
1740
+ process.execPath,
1741
+ [
1742
+ "--import",
1376
1743
  fixturePreload(),
1377
1744
  cli,
1378
- '--repo-root',
1745
+ "--repo-root",
1379
1746
  fixture.home,
1380
- 'plugin',
1381
- 'install',
1382
- '--host',
1383
- 'codex',
1384
- '--version',
1385
- '0.3.21',
1386
- '--dry-run',
1387
- '--json',
1388
- ], { encoding: 'utf8', maxBuffer: 1024 * 1024 });
1747
+ "plugin",
1748
+ "install",
1749
+ "--host",
1750
+ "codex",
1751
+ "--version",
1752
+ "0.3.21",
1753
+ "--dry-run",
1754
+ "--json"
1755
+ ],
1756
+ { encoding: "utf8", maxBuffer: 1024 * 1024 }
1757
+ );
1389
1758
  assert.equal(result.status, 0, result.stderr);
1390
1759
  const value = JSON.parse(result.stdout);
1391
- assert.equal(value.action, 'install');
1392
- assert.equal(value.version, '0.3.21');
1760
+ assert.equal(value.action, "install");
1761
+ assert.equal(value.version, "0.3.21");
1393
1762
  assert.equal(value.dryRun, true);
1394
- assert.ok(!existsSync(join(fixture.home, '.cache')));
1395
- });
1396
- test('compiled doctor CLI requires explicit repository for auth and keeps dry-run credential-free', () => {
1397
- const cli = join(dirname(fileURLToPath(import.meta.url)), 'cli.js');
1398
- const invoke = (prefix, suffix) => spawnSync(process.execPath, [
1399
- '--import',
1763
+ assert.ok(!existsSync(join(fixture.home, ".cache")));
1764
+ }
1765
+ );
1766
+ test(
1767
+ "compiled doctor CLI requires explicit repository for auth and keeps dry-run credential-free",
1768
+ { tags: ["release"] },
1769
+ () => {
1770
+ const cli = join(dirname(fileURLToPath(import.meta.url)), "cli.js");
1771
+ const invoke = (prefix, suffix) => spawnSync(
1772
+ process.execPath,
1773
+ [
1774
+ "--import",
1400
1775
  fixturePreload(),
1401
1776
  cli,
1402
- '--repo-root',
1777
+ "--repo-root",
1403
1778
  fixture.home,
1404
1779
  ...prefix,
1405
- 'plugin',
1406
- 'doctor',
1407
- '--host',
1408
- 'codex',
1409
- ...suffix,
1410
- ], { encoding: 'utf8', maxBuffer: 1024 * 1024 });
1411
- const missing = invoke([], ['--check-auth', '--dry-run', '--json']);
1780
+ "plugin",
1781
+ "doctor",
1782
+ "--host",
1783
+ "codex",
1784
+ ...suffix
1785
+ ],
1786
+ { encoding: "utf8", maxBuffer: 1024 * 1024 }
1787
+ );
1788
+ const missing = invoke([], ["--check-auth", "--dry-run", "--json"]);
1412
1789
  assert.equal(missing.status, 1);
1413
1790
  assert.match(missing.stderr, /requires explicit --repo owner\/name/u);
1414
- const selected = invoke(['--repo', 'example/widget'], ['--check-auth', '--dry-run', '--json']);
1791
+ const selected = invoke(["--repo", "example/widget"], ["--check-auth", "--dry-run", "--json"]);
1415
1792
  assert.equal(selected.status, 0, selected.stderr);
1416
1793
  const value = JSON.parse(selected.stdout);
1417
- assert.equal(value.authProbe.settings, 'not_checked');
1418
- assert.equal(value.authProbe.reason, 'dry_run');
1419
- assert.equal(value.authProbe.repositoryAccess.repository, 'example/widget');
1420
- const defaultDoctor = invoke([], ['--dry-run', '--json']);
1794
+ assert.equal(value.authProbe.settings, "not_checked");
1795
+ assert.equal(value.authProbe.reason, "dry_run");
1796
+ assert.equal(value.authProbe.repositoryAccess.repository, "example/widget");
1797
+ const defaultDoctor = invoke([], ["--dry-run", "--json"]);
1421
1798
  assert.equal(defaultDoctor.status, 0, defaultDoctor.stderr);
1422
- assert.equal(JSON.parse(defaultDoctor.stdout).authProbe, undefined);
1423
- assert.ok(!existsSync(join(fixture.home, '.cache')));
1424
- });
1799
+ assert.equal(JSON.parse(defaultDoctor.stdout).authProbe, void 0);
1800
+ assert.ok(!existsSync(join(fixture.home, ".cache")));
1801
+ }
1802
+ );
1425
1803
  function producerDependencyFixture(esm = true) {
1426
- const root = join(fixture.home, 'producer');
1427
- const manifests = new Map([
1428
- ['package.json', { name: 'synthetic-producer', dependencies: { 'synthetic-dependency': '1' } }],
1429
- [
1430
- 'node_modules/synthetic-dependency/package.json',
1431
- {
1432
- name: 'synthetic-dependency',
1433
- type: 'module',
1434
- exports: esm ? { '.': { import: './entry.js' } } : { '.': './entry.js' },
1435
- dependencies: { 'synthetic-leaf': '1' },
1436
- },
1437
- ],
1438
- ['node_modules/synthetic-dependency/node_modules/synthetic-leaf/package.json', { name: 'synthetic-leaf' }],
1439
- ]);
1440
- for (const [path, value] of manifests) {
1441
- mkdirSync(dirname(join(root, path)), { recursive: true });
1442
- writeFileSync(join(root, path), JSON.stringify(value));
1443
- }
1444
- const entry = join(root, 'node_modules/synthetic-dependency/entry.js');
1445
- writeFileSync(entry, 'throw new Error("Dependency discovery must not evaluate this entry.");');
1446
- mkdirSync(join(root, 'dist'));
1447
- writeFileSync(join(root, 'dist/index.js'), 'export const synthetic = true;');
1448
- return { root, dist: join(root, 'dist'), paths: [...manifests.keys()].map((path) => join(root, path)) };
1804
+ const root = join(fixture.home, "producer");
1805
+ const manifests = /* @__PURE__ */ new Map([
1806
+ ["package.json", { name: "synthetic-producer", dependencies: { "synthetic-dependency": "1" } }],
1807
+ [
1808
+ "node_modules/synthetic-dependency/package.json",
1809
+ {
1810
+ name: "synthetic-dependency",
1811
+ type: "module",
1812
+ exports: esm ? { ".": { import: "./entry.js" } } : { ".": "./entry.js" },
1813
+ dependencies: { "synthetic-leaf": "1" }
1814
+ }
1815
+ ],
1816
+ ["node_modules/synthetic-dependency/node_modules/synthetic-leaf/package.json", { name: "synthetic-leaf" }]
1817
+ ]);
1818
+ for (const [path, value] of manifests) {
1819
+ mkdirSync(dirname(join(root, path)), { recursive: true });
1820
+ writeFileSync(join(root, path), JSON.stringify(value));
1821
+ }
1822
+ const entry = join(root, "node_modules/synthetic-dependency/entry.js");
1823
+ writeFileSync(entry, 'throw new Error("Dependency discovery must not evaluate this entry.");');
1824
+ mkdirSync(join(root, "dist"));
1825
+ writeFileSync(join(root, "dist/index.js"), "export const synthetic = true;");
1826
+ return { root, dist: join(root, "dist"), paths: [...manifests.keys()].map((path) => join(root, path)) };
1449
1827
  }
1450
- test.each([true, false])('producer discovery preserves inert full-byte transitive manifests (ESM-only=%s)', (esm) => {
1451
- const { dist, paths } = producerDependencyFixture(esm);
1452
- const expected = paths
1453
- .map((source) => ({
1454
- source,
1455
- digest: `sha256:${createHash('sha256').update(readFileSync(source)).digest('hex')}`,
1456
- }))
1457
- .sort((a, b) => a.source.localeCompare(b.source));
1458
- assert.deepEqual(retainedWorktreeTransitionDependencyManifests(dist), expected);
1459
- const before = retainedWorktreeTransitionProducerDigest(dist);
1460
- writeFileSync(paths[2], `${readFileSync(paths[2], 'utf8')}\n`);
1461
- assert.notEqual(retainedWorktreeTransitionProducerDigest(dist), before);
1462
- assert.equal(retainedWorktreeTransitionDependencyManifests(dist).find(({ source }) => source === paths[2]).digest, `sha256:${createHash('sha256').update(readFileSync(paths[2])).digest('hex')}`);
1463
- });
1464
- test('producer discovery refuses missing transitive dependencies and mismatched ESM identity', () => {
1465
- const { dist, paths } = producerDependencyFixture();
1466
- rmSync(dirname(paths[2]), { recursive: true });
1467
- assert.throws(() => retainedWorktreeTransitionDependencyManifests(dist), { code: 'MODULE_NOT_FOUND' });
1468
- writeFileSync(paths[1], JSON.stringify({ name: 'different-identity', exports: { '.': { import: './entry.js' } } }));
1469
- assert.throws(() => retainedWorktreeTransitionDependencyManifests(dist), /Producer dependency identity is unavailable/u);
1470
- });
1471
- // Independent golden bytes captured from a4808e1 catalogDocuments before toolkit substitution.
1472
- test.each(['codex', 'claude-code'])('toolkit adoption preserves catalog bytes and publication order for %s', async (host) => {
1473
- const { catalog } = host === 'codex' ? replacementFixture() : claudeReplacementFixture();
1474
- const paths = ['.agents/plugins/marketplace.json', '.claude-plugin/marketplace.json'].map((path) => join(catalog, path));
1828
+ test.each([true, false])("producer discovery preserves inert full-byte transitive manifests (ESM-only=%s)", (esm) => {
1829
+ const { dist, paths } = producerDependencyFixture(esm);
1830
+ const expected = paths.map((source) => ({
1831
+ source,
1832
+ digest: `sha256:${createHash("sha256").update(readFileSync(source)).digest("hex")}`
1833
+ })).sort((a, b) => a.source.localeCompare(b.source));
1834
+ assert.deepEqual(retainedWorktreeTransitionDependencyManifests(dist), expected);
1835
+ const before = retainedWorktreeTransitionProducerDigest(dist);
1836
+ writeFileSync(paths[2], `${readFileSync(paths[2], "utf8")}
1837
+ `);
1838
+ assert.notEqual(retainedWorktreeTransitionProducerDigest(dist), before);
1839
+ assert.equal(
1840
+ retainedWorktreeTransitionDependencyManifests(dist).find(({ source }) => source === paths[2]).digest,
1841
+ `sha256:${createHash("sha256").update(readFileSync(paths[2])).digest("hex")}`
1842
+ );
1843
+ });
1844
+ test("producer discovery refuses missing transitive dependencies and mismatched ESM identity", () => {
1845
+ const { dist, paths } = producerDependencyFixture();
1846
+ rmSync(dirname(paths[2]), { recursive: true });
1847
+ assert.throws(() => retainedWorktreeTransitionDependencyManifests(dist), { code: "MODULE_NOT_FOUND" });
1848
+ writeFileSync(paths[1], JSON.stringify({ name: "different-identity", exports: { ".": { import: "./entry.js" } } }));
1849
+ assert.throws(
1850
+ () => retainedWorktreeTransitionDependencyManifests(dist),
1851
+ /Producer dependency identity is unavailable/u
1852
+ );
1853
+ });
1854
+ test.each(["codex", "claude-code"])(
1855
+ "toolkit adoption preserves catalog bytes and publication order for %s",
1856
+ async (host) => {
1857
+ const { catalog } = host === "codex" ? replacementFixture() : claudeReplacementFixture();
1858
+ const paths = [".agents/plugins/marketplace.json", ".claude-plugin/marketplace.json"].map(
1859
+ (path) => join(catalog, path)
1860
+ );
1475
1861
  const published = [];
1476
1862
  const actual = atomicJson.writePrivateJsonFileAtomically;
1477
- vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
1478
- if (paths.includes(path))
1479
- published.push(path);
1480
- actual(path, value);
1863
+ vi.spyOn(atomicJson, "writePrivateJsonFileAtomically").mockImplementation((path, value) => {
1864
+ if (paths.includes(path)) published.push(path);
1865
+ actual(path, value);
1481
1866
  });
1482
- await managePlugin({ ...input(), host, action: 'update', version: '0.3.22' });
1867
+ await managePlugin({ ...input(), host, action: "update", version: "0.3.22" });
1483
1868
  assert.deepEqual(published, paths);
1484
- assert.ok(vi.mocked(pluginTools.marketplaceDocuments).mock.calls.some(([spec]) => JSON.stringify(spec) ===
1485
- JSON.stringify({
1486
- marketplaceName: 'ai-delivery-user',
1487
- pluginName: 'ai-delivery',
1488
- relativeSource: './versions/0.3.22/plugins/ai-delivery',
1489
- version: '0.3.22',
1490
- ownerName: 'AviaraTech',
1491
- metadata: {
1492
- kind: 'interface-policy',
1493
- displayName: 'ai-delivery',
1494
- policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },
1495
- category: 'Productivity',
1496
- },
1497
- })), 'installer calls real marketplaceDocuments with its existing interface-policy inputs');
1498
- assert.deepEqual(vi.mocked(pluginTools.nativePluginArgs).mock.calls.map(([spec]) => spec), [
1499
- { host, action: 'remove', pluginId: 'ai-delivery@ai-delivery-user', scope: 'user' },
1500
- { host, action: 'update', pluginId: 'ai-delivery@ai-delivery-user', scope: 'user' },
1501
- ]);
1502
- for (const args of fixture.commandArguments.filter((args) => args[1] === 'plugin' &&
1503
- ['add', 'remove', 'install', 'update', 'uninstall'].includes(args[2] ?? '') &&
1504
- !args.includes('--help'))) {
1505
- assert.ok(vi
1506
- .mocked(pluginTools.nativePluginArgs)
1507
- .mock.results.some((result) => result.type === 'return' && JSON.stringify(result.value) === JSON.stringify(args.slice(1))), 'native dispatch uses the real helper result unchanged');
1869
+ assert.ok(
1870
+ vi.mocked(pluginTools.marketplaceDocuments).mock.calls.some(
1871
+ ([spec]) => JSON.stringify(spec) === JSON.stringify({
1872
+ marketplaceName: "ai-delivery-user",
1873
+ pluginName: "ai-delivery",
1874
+ relativeSource: "./versions/0.3.22/plugins/ai-delivery",
1875
+ version: "0.3.22",
1876
+ ownerName: "AviaraTech",
1877
+ metadata: {
1878
+ kind: "interface-policy",
1879
+ displayName: "ai-delivery",
1880
+ policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
1881
+ category: "Productivity"
1882
+ }
1883
+ })
1884
+ ),
1885
+ "installer calls real marketplaceDocuments with its existing interface-policy inputs"
1886
+ );
1887
+ assert.deepEqual(
1888
+ vi.mocked(pluginTools.nativePluginArgs).mock.calls.map(([spec]) => spec),
1889
+ [
1890
+ { host, action: "remove", pluginId: "ai-delivery@ai-delivery-user", scope: "user" },
1891
+ { host, action: "update", pluginId: "ai-delivery@ai-delivery-user", scope: "user" }
1892
+ ]
1893
+ );
1894
+ for (const args of fixture.commandArguments.filter(
1895
+ (args2) => args2[1] === "plugin" && ["add", "remove", "install", "update", "uninstall"].includes(args2[2] ?? "") && !args2.includes("--help")
1896
+ )) {
1897
+ assert.ok(
1898
+ vi.mocked(pluginTools.nativePluginArgs).mock.results.some(
1899
+ (result) => result.type === "return" && JSON.stringify(result.value) === JSON.stringify(args.slice(1))
1900
+ ),
1901
+ "native dispatch uses the real helper result unchanged"
1902
+ );
1508
1903
  }
1509
- for (const [index, name] of ['codex', 'claude'].entries()) {
1510
- const golden = join(dirname(fileURLToPath(import.meta.url)), '../fixtures/plugin-installer-toolkit', `interface-policy.${name}.json`);
1511
- assert.deepEqual(readFileSync(paths[index]), readFileSync(golden));
1904
+ for (const [index, name] of ["codex", "claude"].entries()) {
1905
+ const golden = join(
1906
+ dirname(fileURLToPath(import.meta.url)),
1907
+ "../fixtures/plugin-installer-toolkit",
1908
+ `interface-policy.${name}.json`
1909
+ );
1910
+ assert.deepEqual(readFileSync(paths[index]), readFileSync(golden));
1512
1911
  }
1513
- });
1514
- test.each(['codex', 'claude-code'])('toolkit adoption loads compatible completed state unchanged for %s', async (host) => {
1912
+ }
1913
+ );
1914
+ test.each(["codex", "claude-code"])(
1915
+ "toolkit adoption loads compatible completed state unchanged for %s",
1916
+ async (host) => {
1515
1917
  doctorFixture(true, host);
1516
- const directory = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user');
1517
- const paths = [join(directory, 'state.json'), join(directory, 'marketplace/versions/0.3.21/version.json')];
1918
+ const directory = join(fixture.home, ".cache/ai-delivery/plugins", host, "user");
1919
+ const paths = [join(directory, "state.json"), join(directory, "marketplace/versions/0.3.21/version.json")];
1518
1920
  const before = paths.map((path) => readFileSync(path));
1519
- const digests = before.map((bytes) => createHash('sha256').update(bytes).digest('hex'));
1520
- const result = await managePlugin({ ...input(), host, action: 'doctor', version: undefined });
1521
- assert.equal(result.version, '0.3.21');
1522
- assert.deepEqual(paths.map((path) => readFileSync(path)), before);
1523
- assert.deepEqual(paths.map((path) => createHash('sha256').update(readFileSync(path)).digest('hex')), digests);
1524
- });
1525
- test.each(['project', 'local'])('toolkit adoption preserves early scope refusal for %s', async (scope) => {
1526
- await assert.rejects(managePlugin({ ...input(), scope }), {
1527
- name: 'Error',
1528
- message: 'Codex currently supports user plugin installation; select --scope user.',
1529
- });
1530
- assert.deepEqual(fixture.commandArguments, []);
1531
- assert.deepEqual(vi.mocked(pluginTools.nativePluginArgs).mock.calls, []);
1532
- assert.deepEqual(vi.mocked(pluginTools.marketplaceDocuments).mock.calls, []);
1533
- assert.deepEqual(readdirSync(fixture.home), []);
1534
- });
1535
- test('plugin management rejects unsupported native scopes and nonliteral versions before writing', async () => {
1536
- for (const value of [
1537
- { ...input(), scope: 'project' },
1538
- { ...input(), host: 'claude-code', scope: 'managed' },
1539
- { ...input(), version: 'latest' },
1540
- { ...input(), version: undefined },
1541
- { ...input(), version: '0.3.21 --ignore-scripts=false' },
1542
- ])
1543
- await assert.rejects(managePlugin(value));
1544
- assert.deepEqual(readdirSync(fixture.home), []);
1545
- });
1546
- test('plugin dry-run describes the exact selected native target without creating a profile or fetching', async () => {
1547
- const result = await managePlugin({ ...input(), dryRun: true });
1548
- assert.equal(result.action, 'install');
1549
- assert.equal(result.host, 'codex');
1550
- assert.equal(result.scope, 'user');
1551
- assert.equal(result.version, '0.3.21');
1552
- assert.equal(result.changed, false);
1553
- assert.equal(result.dryRun, true);
1554
- assert.deepEqual(readdirSync(fixture.home), []);
1555
- });
1556
- test('doctor of an unconfigured host is read-only and does not claim installation or admission', async () => {
1557
- const result = await managePlugin({ action: 'doctor', host: 'claude-code', scope: 'local', repoRoot: fixture.home });
1558
- assert.equal(result.changed, false);
1559
- assert.equal(result.installed, false);
1560
- assert.equal(result.repositoryAdmission, 'explicit_stage_and_admit_required');
1561
- assert.deepEqual(readdirSync(fixture.home), []);
1562
- });
1563
- test('remove never touches an unmanaged native selector or creates managed state', async () => {
1564
- const result = await managePlugin({ action: 'remove', host: 'codex', scope: 'user', repoRoot: fixture.home });
1565
- assert.equal(result.changed, false);
1566
- assert.deepEqual(fixture.commands, []);
1567
- assert.deepEqual(readdirSync(fixture.home), []);
1568
- });
1569
- test('initial install refuses a marketplace-name collision before fetching or changing native selection', async () => {
1570
- const unowned = join(fixture.home, 'unowned-marketplace');
1571
- mkdirSync(unowned);
1572
- const marker = join(unowned, 'configuration');
1573
- writeFileSync(marker, 'unrelated native source');
1574
- fixture.responses.push('codex-cli 0.153.0', JSON.stringify({
1575
- installed: [
1576
- {
1577
- pluginId: 'ai-delivery@ai-delivery-user',
1578
- marketplaceName: 'ai-delivery-user',
1579
- version: '0.3.21',
1580
- enabled: true,
1581
- source: { source: 'local', path: unowned },
1582
- marketplaceSource: { sourceType: 'local', source: unowned },
1583
- },
1584
- ],
1585
- available: [],
1586
- }));
1587
- await assert.rejects(managePlugin(input()), /unmanaged source/u);
1588
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1589
- assert.equal(readFileSync(marker, 'utf8'), 'unrelated native source');
1590
- });
1591
- test('an interrupted managed removal resumes its null target before invoking native commands', async () => {
1592
- const directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user');
1593
- mkdirSync(directory, { recursive: true, mode: 0o700 });
1594
- const path = join(directory, 'state.json');
1595
- writeFileSync(path, JSON.stringify({
1596
- owner: '@aviaratech/ai-delivery.plugin@1',
1597
- host: 'codex',
1598
- scope: 'user',
1599
- projectRoot: null,
1600
- nativeHome: join(fixture.home, '.codex'),
1601
- marketplace: 'ai-delivery-user',
1602
- currentVersion: '0.3.21',
1603
- previousVersion: null,
1604
- installedPath: null,
1605
- pending: {
1606
- action: 'remove',
1607
- targetVersion: null,
1608
- producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
1609
- owner: { pid: 2_000_000_000, birth: 'old owner' },
1610
- command: { phase: 'idle' },
1611
- },
1612
- }), { mode: 0o600 });
1613
- await assert.rejects(managePlugin({ action: 'remove', host: 'codex', scope: 'user', repoRoot: fixture.home }), /Native fixture intentionally unavailable/u);
1614
- assert.deepEqual(fixture.commands, ['codex']);
1615
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, null);
1616
- });
1617
- //# sourceMappingURL=pluginInstaller.test.js.map
1921
+ const digests = before.map((bytes) => createHash("sha256").update(bytes).digest("hex"));
1922
+ const result = await managePlugin({ ...input(), host, action: "doctor", version: void 0 });
1923
+ assert.equal(result.version, "0.3.21");
1924
+ assert.deepEqual(
1925
+ paths.map((path) => readFileSync(path)),
1926
+ before
1927
+ );
1928
+ assert.deepEqual(
1929
+ paths.map((path) => createHash("sha256").update(readFileSync(path)).digest("hex")),
1930
+ digests
1931
+ );
1932
+ }
1933
+ );
1934
+ test.each(["project", "local"])("toolkit adoption preserves early scope refusal for %s", async (scope) => {
1935
+ await assert.rejects(managePlugin({ ...input(), scope }), {
1936
+ name: "Error",
1937
+ message: "Codex currently supports user plugin installation; select --scope user."
1938
+ });
1939
+ assert.deepEqual(fixture.commandArguments, []);
1940
+ assert.deepEqual(vi.mocked(pluginTools.nativePluginArgs).mock.calls, []);
1941
+ assert.deepEqual(vi.mocked(pluginTools.marketplaceDocuments).mock.calls, []);
1942
+ assert.deepEqual(readdirSync(fixture.home), []);
1943
+ });
1944
+ test("plugin management rejects unsupported native scopes and nonliteral versions before writing", async () => {
1945
+ for (const value of [
1946
+ { ...input(), scope: "project" },
1947
+ { ...input(), host: "claude-code", scope: "managed" },
1948
+ { ...input(), version: "latest" },
1949
+ { ...input(), version: void 0 },
1950
+ { ...input(), version: "0.3.21 --ignore-scripts=false" }
1951
+ ])
1952
+ await assert.rejects(managePlugin(value));
1953
+ assert.deepEqual(readdirSync(fixture.home), []);
1954
+ });
1955
+ test("plugin dry-run describes the exact selected native target without creating a profile or fetching", async () => {
1956
+ const result = await managePlugin({ ...input(), dryRun: true });
1957
+ assert.equal(result.action, "install");
1958
+ assert.equal(result.host, "codex");
1959
+ assert.equal(result.scope, "user");
1960
+ assert.equal(result.version, "0.3.21");
1961
+ assert.equal(result.changed, false);
1962
+ assert.equal(result.dryRun, true);
1963
+ assert.deepEqual(readdirSync(fixture.home), []);
1964
+ });
1965
+ test("doctor of an unconfigured host is read-only and does not claim installation or admission", async () => {
1966
+ const result = await managePlugin({ action: "doctor", host: "claude-code", scope: "local", repoRoot: fixture.home });
1967
+ assert.equal(result.changed, false);
1968
+ assert.equal(result.installed, false);
1969
+ assert.equal(result.repositoryAdmission, "explicit_stage_and_admit_required");
1970
+ assert.deepEqual(readdirSync(fixture.home), []);
1971
+ });
1972
+ test("remove never touches an unmanaged native selector or creates managed state", async () => {
1973
+ const result = await managePlugin({ action: "remove", host: "codex", scope: "user", repoRoot: fixture.home });
1974
+ assert.equal(result.changed, false);
1975
+ assert.deepEqual(fixture.commands, []);
1976
+ assert.deepEqual(readdirSync(fixture.home), []);
1977
+ });
1978
+ test("initial install refuses a marketplace-name collision before fetching or changing native selection", async () => {
1979
+ const unowned = join(fixture.home, "unowned-marketplace");
1980
+ mkdirSync(unowned);
1981
+ const marker = join(unowned, "configuration");
1982
+ writeFileSync(marker, "unrelated native source");
1983
+ fixture.responses.push(
1984
+ "codex-cli 0.153.0",
1985
+ JSON.stringify({
1986
+ installed: [
1987
+ {
1988
+ pluginId: "ai-delivery@ai-delivery-user",
1989
+ marketplaceName: "ai-delivery-user",
1990
+ version: "0.3.21",
1991
+ enabled: true,
1992
+ source: { source: "local", path: unowned },
1993
+ marketplaceSource: { sourceType: "local", source: unowned }
1994
+ }
1995
+ ],
1996
+ available: []
1997
+ })
1998
+ );
1999
+ await assert.rejects(managePlugin(input()), /unmanaged source/u);
2000
+ assert.deepEqual(fixture.commands, ["codex", "codex"]);
2001
+ assert.equal(readFileSync(marker, "utf8"), "unrelated native source");
2002
+ });
2003
+ test("an interrupted managed removal resumes its null target before invoking native commands", async () => {
2004
+ const directory = join(fixture.home, ".cache/ai-delivery/plugins/codex/user");
2005
+ mkdirSync(directory, { recursive: true, mode: 448 });
2006
+ const path = join(directory, "state.json");
2007
+ writeFileSync(
2008
+ path,
2009
+ JSON.stringify({
2010
+ owner: "@aviaratech/ai-delivery.plugin@1",
2011
+ host: "codex",
2012
+ scope: "user",
2013
+ projectRoot: null,
2014
+ nativeHome: join(fixture.home, ".codex"),
2015
+ marketplace: "ai-delivery-user",
2016
+ currentVersion: "0.3.21",
2017
+ previousVersion: null,
2018
+ installedPath: null,
2019
+ pending: {
2020
+ action: "remove",
2021
+ targetVersion: null,
2022
+ producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
2023
+ owner: { pid: 2e9, birth: "old owner" },
2024
+ command: { phase: "idle" }
2025
+ }
2026
+ }),
2027
+ { mode: 384 }
2028
+ );
2029
+ await assert.rejects(
2030
+ managePlugin({ action: "remove", host: "codex", scope: "user", repoRoot: fixture.home }),
2031
+ /Native fixture intentionally unavailable/u
2032
+ );
2033
+ assert.deepEqual(fixture.commands, ["codex"]);
2034
+ assert.equal(JSON.parse(readFileSync(path, "utf8")).pending.targetVersion, null);
2035
+ });
2036
+ //# sourceMappingURL=pluginInstaller.test.js.map