@aviaratech/ai-delivery 0.3.34 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,1497 +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 { processSnapshot, retainedWorktreeTransitionProducerDigest } from './verification.js';
11
- import { afterEach, beforeEach, test, vi } from 'vitest';
12
- 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";
13
30
  const fixture = vi.hoisted(() => ({
14
- home: '',
15
- commands: [],
16
- commandArguments: [],
17
- realCommands: false,
18
- responses: [],
19
- respond: undefined,
20
- packArchive: '',
31
+ home: "",
32
+ commands: [],
33
+ commandArguments: [],
34
+ realCommands: false,
35
+ responses: [],
36
+ respond: void 0,
37
+ packArchive: ""
21
38
  }));
22
- vi.mock('node:child_process', async (original) => {
23
- const actual = await original();
24
- return {
25
- ...actual,
26
- spawn: (...parameters) => {
27
- if (fixture.realCommands)
28
- return actual.spawn(...parameters);
29
- const [binary, args] = parameters;
30
- fixture.commands.push(binary === '/bin/sh' ? args[3] : binary);
31
- const commandArguments = binary === '/bin/sh' ? args.slice(3) : [binary, ...(args ?? [])];
32
- fixture.commandArguments.push(commandArguments);
33
- const child = Object.assign(new EventEmitter(), {
34
- stdin: new PassThrough(),
35
- stdout: new PassThrough(),
36
- stderr: new PassThrough(),
37
- kill: () => true,
38
- });
39
- const queued = fixture.responses.shift() ?? fixture.respond;
40
- let response = typeof queued === 'function' ? queued(commandArguments) : queued;
41
- if (binary === '/bin/sh' && args?.[3] === 'npm' && fixture.packArchive) {
42
- const destination = args[args.indexOf('--pack-destination') + 1];
43
- const filename = 'aviaratech-ai-delivery-0.3.22.tgz';
44
- writeFileSync(join(destination, filename), readFileSync(fixture.packArchive), { mode: 0o600 });
45
- response = JSON.stringify([{ filename }]);
46
- }
47
- queueMicrotask(() => {
48
- if (response === undefined) {
49
- child.emit('error', new Error('Native fixture intentionally unavailable.'));
50
- child.emit('close', 1, null);
51
- }
52
- else {
53
- child.stdout.emit('data', Buffer.from(response));
54
- child.emit('close', 0, null);
55
- }
56
- });
57
- return child;
58
- },
59
- };
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
+ };
60
83
  });
61
- vi.mock('node:os', async (original) => ({
62
- ...(await original()),
63
- homedir: () => fixture.home,
84
+ vi.mock("node:os", async (original) => ({
85
+ ...await original(),
86
+ homedir: () => fixture.home
64
87
  }));
65
- const { managePlugin } = await import('./pluginInstaller.js');
66
- test('preview observes a Codex registration candidate without executing or changing its settings', async () => {
67
- const profile = join(fixture.home, '.codex');
68
- mkdirSync(profile);
69
- const config = join(profile, 'config.toml');
70
- const bytes = '[mcp_servers."ai-delivery"]\ncommand = "unknown-launcher"\nsecret = "fictional-private-value"\n';
71
- writeFileSync(config, bytes);
72
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
73
- const report = Reflect.get(result, 'diagnostics');
74
- assert.ok(report);
75
- assert.equal(report.migration, 'refused');
76
- assert.equal(report.completeness, 'incomplete');
77
- assert.deepEqual(report.registrations, [
78
- { kind: 'standalone', scope: 'user', ownership: 'unknown', source: 'unknown', version: null, enabled: null },
79
- ]);
80
- assert.equal(JSON.stringify(result).includes('fictional-private-value'), false);
81
- assert.equal(JSON.stringify(result).includes('unknown-launcher'), false);
82
- assert.equal(readFileSync(config, 'utf8'), bytes);
83
- assert.deepEqual(fixture.commands, []);
84
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
85
116
  });
86
- test('preview preserves Claude local/project/user registrations and permission preferences', async () => {
87
- vi.stubEnv('CLAUDE_CONFIG_DIR', '');
88
- const user = join(fixture.home, '.claude.json');
89
- const project = join(fixture.home, '.mcp.json');
90
- const settings = join(fixture.home, '.claude', 'settings.json');
91
- mkdirSync(dirname(settings));
92
- writeFileSync(user, JSON.stringify({
93
- mcpServers: { 'ai-delivery': { command: 'unknown-user' } },
94
- projects: {
95
- [fixture.home]: { mcpServers: { 'ai-delivery': { command: 'unknown-local' } } },
96
- },
97
- }));
98
- writeFileSync(project, JSON.stringify({ mcpServers: { 'ai-delivery': { command: 'unknown-project' } } }));
99
- writeFileSync(settings, JSON.stringify({ permissions: { allow: ['mcp__ai-delivery__issue_info'] } }));
100
- const before = [user, project, settings].map((path) => readFileSync(path));
101
- const result = await managePlugin({ action: 'preview', host: 'claude-code', scope: 'user', repoRoot: fixture.home });
102
- assert.ok(result.diagnostics);
103
- assert.deepEqual(result.diagnostics.registrations.map((entry) => entry.scope), ['local', 'project', 'user']);
104
- assert.equal(result.diagnostics.migration, 'refused');
105
- assert.deepEqual([user, project, settings].map((path) => readFileSync(path)), before);
106
- assert.deepEqual(fixture.commands, []);
107
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
108
148
  });
109
- test('doctor reports an external native marketplace plugin without adopting or starting it', async () => {
110
- fixture.responses.push(JSON.stringify({
111
- installed: [
112
- {
113
- pluginId: 'ai-delivery@external-market',
114
- name: 'ai-delivery',
115
- marketplaceName: 'external-market',
116
- version: '0.3.24',
117
- enabled: true,
118
- source: { source: 'git', url: 'https://example.test/unknown' },
119
- },
120
- ],
121
- available: [],
122
- }));
123
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
124
- assert.equal(result.installed, false);
125
- assert.ok(result.diagnostics);
126
- assert.ok(result.activation);
127
- assert.deepEqual(result.diagnostics.registrations, [
128
- { kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
129
- ]);
130
- assert.equal(result.activation.loadedVersion, null);
131
- assert.equal(result.sourceIntegrity, undefined);
132
- assert.equal(result.mcp, undefined);
133
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
134
184
  });
135
- test('preview refuses incomplete oversized configuration without writes or native calls', async () => {
136
- const profile = join(fixture.home, '.codex');
137
- mkdirSync(profile);
138
- const config = join(profile, 'config.toml');
139
- const bytes = '#'.repeat(1024 * 1024 + 1);
140
- writeFileSync(config, bytes);
141
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
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);
213
+ });
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 });
142
233
  assert.ok(result.diagnostics);
143
- assert.equal(result.diagnostics.migration, 'refused');
144
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
145
- assert.equal(readFileSync(config, 'utf8'), bytes);
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);
146
246
  assert.deepEqual(fixture.commands, []);
147
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
148
263
  });
149
- test('doctor retains distinct external marketplace observations with identical reported versions', async () => {
150
- doctorFixture(false);
151
- const selected = JSON.parse(fixture.responses[0])
152
- .installed[0];
153
- fixture.responses.push(JSON.stringify({
154
- installed: [
155
- selected,
156
- { pluginId: 'ai-delivery@external-one', version: '0.3.24', enabled: true },
157
- { pluginId: 'ai-delivery@external-two', version: '0.3.24', enabled: true },
158
- ],
159
- available: [],
160
- }));
161
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
162
- assert.ok(result.diagnostics);
163
- assert.equal(result.diagnostics.registrations.filter((entry) => entry.ownership === 'external').length, 2);
164
- assert.equal(result.diagnostics.nativeInventory, 'observed');
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");
165
281
  });
166
- test('doctor observes external installations after retained managed removal without adopting them', async () => {
167
- mkdirSync(join(fixture.home, '.codex'));
168
- const statePath = writeState({ ...pendingState('remove', null), pending: undefined });
169
- const before = readFileSync(statePath);
170
- fixture.responses.push(JSON.stringify({
171
- installed: [{ pluginId: 'ai-delivery@external-market', version: '0.3.24', enabled: true }],
172
- available: [],
173
- }));
174
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
175
- assert.ok(result.diagnostics);
176
- assert.deepEqual(result.diagnostics.registrations, [
177
- { kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
178
- ]);
179
- assert.equal(result.installed, false);
180
- assert.equal(result.sourceIntegrity, undefined);
181
- assert.equal(result.mcp, undefined);
182
- assert.deepEqual(result.activation, { installedVersion: null, startupVersion: null, loadedVersion: null });
183
- assert.deepEqual(readFileSync(statePath), before);
184
- assert.deepEqual(fixture.commandArguments, [['codex', 'plugin', 'list', '--json']]);
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"]]);
185
311
  });
186
- test('compiled preview never invokes native tools or creates installer state', () => {
187
- const profile = join(fixture.home, '.codex');
188
- const bin = join(fixture.home, 'bin');
189
- const marker = join(fixture.home, 'native-called');
190
- mkdirSync(profile);
191
- mkdirSync(bin);
192
- writeFileSync(join(bin, 'codex'), `#!/bin/sh\nprintf called > '${marker}'\n`, { mode: 0o755 });
193
- writeFileSync(join(profile, 'config.toml'), '[mcp_servers.ai-delivery]\ncommand="untrusted"\n');
194
- const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
195
- const stdout = execFileSync(process.execPath, [cli, 'plugin', 'preview', '--host', 'codex', '--json'], {
196
- cwd: fixture.home,
197
- env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile, PATH: bin },
198
- encoding: 'utf8',
199
- });
200
- const result = JSON.parse(stdout);
201
- assert.ok(result.diagnostics);
202
- assert.equal(result.action, 'preview');
203
- assert.equal(result.diagnostics.migration, 'refused');
204
- assert.deepEqual(result.diagnostics.plannedChanges, []);
205
- assert.equal(existsSync(marker), false);
206
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
207
335
  });
208
- test('preview refuses a symlinked configuration without following its target', async () => {
209
- const profile = join(fixture.home, '.codex');
210
- const target = join(fixture.home, 'protected.pem');
211
- mkdirSync(profile);
212
- writeFileSync(target, '[mcp_servers.ai-delivery]\nsecret="fictional-sensitive-content"\n');
213
- symlinkSync(target, join(profile, 'config.toml'));
214
- const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
215
- assert.ok(result.diagnostics);
216
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
217
- assert.deepEqual(result.diagnostics.registrations, []);
218
- assert.equal(JSON.stringify(result).includes('fictional-sensitive-content'), false);
219
- assert.deepEqual(fixture.commands, []);
220
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
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);
221
349
  });
222
- test.each(['codex', 'claude-code'])('preview refuses a FIFO configuration without blocking in %s', (host) => {
223
- const profile = join(fixture.home, '.codex');
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");
224
355
  mkdirSync(profile);
225
- const config = host === 'codex' ? join(profile, 'config.toml') : join(fixture.home, '.mcp.json');
226
- 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]);
227
358
  const metadata = lstatSync(config);
228
- const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
229
- // Bound only the known FIFO-open stall and reap this test-owned child.
230
- const child = spawnSync(process.execPath, [cli, 'plugin', 'preview', '--host', host, '--json'], {
231
- cwd: fixture.home,
232
- env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile },
233
- encoding: 'utf8',
234
- timeout: 3000,
235
- 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"
236
366
  });
237
- assert.equal(child.error, undefined);
367
+ assert.equal(child.error, void 0);
238
368
  assert.equal(child.status, 0);
239
369
  const result = JSON.parse(child.stdout);
240
370
  assert.ok(result.diagnostics);
241
- assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
371
+ assert.ok(result.diagnostics.findings.includes("configuration_unavailable"));
242
372
  assert.deepEqual(result.diagnostics.registrations, []);
243
373
  assert.equal(lstatSync(config).ino, metadata.ino);
244
- assert.equal(existsSync(join(fixture.home, '.cache')), false);
245
- });
246
- test.each(['migrate', 'apply', 'retire', 'restore-settings'])('unsupported %s never enables host mutation', async (action) => {
247
- 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 }));
248
381
  assert.deepEqual(fixture.commands, []);
249
382
  assert.deepEqual(readdirSync(fixture.home), []);
250
- });
383
+ }
384
+ );
251
385
  beforeEach(() => {
252
- fixture.home = mkdtempSync(join(tmpdir(), 'ai-delivery-installer-'));
253
- vi.stubEnv('CODEX_HOME', join(fixture.home, '.codex'));
254
- vi.stubEnv('CLAUDE_CONFIG_DIR', join(fixture.home, '.claude'));
255
- fixture.commands = [];
256
- fixture.commandArguments = [];
257
- fixture.realCommands = false;
258
- fixture.responses = [];
259
- fixture.respond = undefined;
260
- 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 = "";
261
400
  });
262
401
  afterEach(() => {
263
- vi.restoreAllMocks();
264
- vi.unstubAllEnvs();
265
- rmSync(fixture.home, { recursive: true, force: true });
266
- for (const args of fixture.commandArguments)
267
- if (args[1] === 'plugin' && args[2] === 'list')
268
- assert.deepEqual(args, args[0] === 'codex' && args.includes('--marketplace')
269
- ? ['codex', 'plugin', 'list', '--marketplace', 'ai-delivery-user', '--available', '--json']
270
- : args[0] === 'codex'
271
- ? ['codex', 'plugin', 'list', '--json']
272
- : ['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
+ );
273
412
  });
274
413
  function pendingState(action, version) {
275
- return {
276
- owner: '@aviaratech/ai-delivery.plugin@1',
277
- host: 'codex',
278
- scope: 'user',
279
- projectRoot: null,
280
- nativeHome: join(fixture.home, '.codex'),
281
- marketplace: 'ai-delivery-user',
282
- currentVersion: null,
283
- previousVersion: null,
284
- installedPath: null,
285
- pending: {
286
- action,
287
- targetVersion: version,
288
- producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
289
- owner: { pid: 2_000_000_000, birth: 'old owner' },
290
- command: { phase: 'idle' },
291
- },
292
- };
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
+ };
293
432
  }
294
- function writeState(value, host = 'codex') {
295
- const directory = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user');
296
- mkdirSync(directory, { recursive: true, mode: 0o700 });
297
- const path = join(directory, 'state.json');
298
- writeFileSync(path, JSON.stringify(value), { mode: 0o600 });
299
- 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;
300
439
  }
301
- function doctorFixture(enabled, host = 'codex') {
302
- const version = '0.3.21', catalog = join(fixture.home, '.cache/ai-delivery/plugins', host, 'user/marketplace');
303
- const unit = join(catalog, 'versions', version), source = join(unit, 'plugins/ai-delivery');
304
- const nativeHome = join(fixture.home, host === 'codex' ? '.codex' : '.claude');
305
- const cache = join(nativeHome, 'plugins/cache/ai-delivery-user/ai-delivery', version);
306
- const files = { 'mcp.json': '{"ai-delivery":{"command":"node"}}', 'skills/intake/SKILL.md': 'owned skill bytes' };
307
- for (const root of [source, cache])
308
- for (const [name, bytes] of Object.entries(files)) {
309
- const path = join(root, name);
310
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
311
- writeFileSync(path, bytes, { mode: 0o600 });
312
- }
313
- const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
314
- writeFileSync(join(unit, 'archive.tgz'), 'captured archive', { mode: 0o600 });
315
- writeFileSync(join(unit, 'version.json'), JSON.stringify({
316
- owner: '@aviaratech/ai-delivery.plugin-version@1',
317
- version,
318
- archiveSha256: hash('captured archive'),
319
- files: Object.fromEntries(Object.entries(files).map(([name, bytes]) => [name, hash(bytes)])),
320
- }), { mode: 0o600 });
321
- writeState({
322
- ...pendingState('install', version),
323
- host,
324
- nativeHome,
325
- pending: undefined,
326
- currentVersion: version,
327
- installedPath: cache,
328
- }, host);
329
- for (const [relative, content] of [
330
- [
331
- '.agents/plugins/marketplace.json',
332
- {
333
- name: 'ai-delivery-user',
334
- interface: { displayName: 'ai-delivery' },
335
- plugins: [
336
- {
337
- name: 'ai-delivery',
338
- source: { source: 'local', path: `./versions/${version}/plugins/ai-delivery` },
339
- policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },
340
- category: 'Productivity',
341
- },
342
- ],
343
- },
344
- ],
345
- [
346
- '.claude-plugin/marketplace.json',
347
- {
348
- name: 'ai-delivery-user',
349
- owner: { name: 'AviaraTech' },
350
- plugins: [{ name: 'ai-delivery', source: `./versions/${version}/plugins/ai-delivery`, version }],
351
- },
352
- ],
353
- ]) {
354
- const path = join(catalog, relative);
355
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
356
- writeFileSync(path, JSON.stringify(content), { mode: 0o600 });
357
- }
358
- if (host === 'codex') {
359
- fixture.responses.push(JSON.stringify({
360
- installed: [
361
- {
362
- pluginId: 'ai-delivery@ai-delivery-user',
363
- marketplaceName: 'ai-delivery-user',
364
- version,
365
- enabled,
366
- source: { source: 'local', path: source },
367
- marketplaceSource: { sourceType: 'local', source: catalog },
368
- },
369
- ],
370
- available: [],
371
- }));
372
- }
373
- else {
374
- const path = join(nativeHome, 'plugins/known_marketplaces.json');
375
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
376
- writeFileSync(path, JSON.stringify({
377
- 'ai-delivery-user': { source: { source: 'directory', path: catalog }, installLocation: catalog },
378
- }), { mode: 0o600 });
379
- fixture.responses.push(JSON.stringify([
380
- {
381
- id: 'ai-delivery@ai-delivery-user',
382
- version,
383
- scope: 'user',
384
- enabled,
385
- installPath: cache,
386
- mcpServers: { 'ai-delivery': { command: 'node', args: ['${CLAUDE_PLUGIN_ROOT}/dist/mcp-launcher.js'] } },
387
- },
388
- ]));
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 });
389
451
  }
390
- 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;
391
544
  }
392
545
  function nativeArchiveFixture() {
393
- const root = join(fixture.home, 'synthetic-package'), version = '0.3.22';
394
- const files = {
395
- 'package.json': JSON.stringify({ name: '@aviaratech/ai-delivery', version }),
396
- 'plugins/ai-delivery/plugin.json': JSON.stringify({ name: 'ai-delivery', version }),
397
- 'plugins/ai-delivery/.claude-plugin/plugin.json': JSON.stringify({
398
- name: 'ai-delivery',
399
- version,
400
- packageVersion: version,
401
- deliveryCapabilityVersion: 2,
402
- }),
403
- 'plugins/ai-delivery/runtime/package.json': JSON.stringify({ name: '@aviaratech/ai-delivery', version }),
404
- 'plugins/ai-delivery/runtime/dist/cli.js': `process.stdout.write('${version}\\n');`,
405
- 'plugins/ai-delivery/skills/intake/SKILL.md': 'synthetic released skill bytes',
406
- };
407
- for (const [name, bytes] of Object.entries(files)) {
408
- const path = join(root, name);
409
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
410
- writeFileSync(path, bytes, { mode: 0o600 });
411
- }
412
- const configuration = join(fixture.home, 'empty.npmrc'), globalConfiguration = join(fixture.home, 'global.npmrc');
413
- writeFileSync(configuration, '', { mode: 0o600 });
414
- writeFileSync(globalConfiguration, '', { mode: 0o600 });
415
- const packed = JSON.parse(execFileSync('npm', [
416
- 'pack',
417
- '--ignore-scripts',
418
- '--json',
419
- '--logs-max',
420
- '0',
421
- '--cache',
422
- join(fixture.home, 'npm-cache'),
423
- '--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",
424
580
  configuration,
425
- '--globalconfig',
581
+ "--globalconfig",
426
582
  globalConfiguration,
427
- '--pack-destination',
428
- fixture.home,
429
- ], { cwd: root, encoding: 'utf8' }));
430
- 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);
431
590
  }
432
591
  function oversizedCatalogue(entries) {
433
- const filtered = JSON.stringify({ installed: entries, available: [] });
434
- const unfiltered = JSON.stringify({
435
- installed: entries,
436
- available: [{ pluginId: 'unrelated@remote', description: 'x'.repeat(1024 * 1024) }],
437
- });
438
- assert.ok(Buffer.byteLength(unfiltered) > 1024 * 1024);
439
- assert.ok(Buffer.byteLength(filtered) < 1024 * 1024);
440
- 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;
441
600
  }
442
601
  function installationFixture(action, readback = (entry) => [entry]) {
443
- let previous = [];
444
- if (action === 'update') {
445
- doctorFixture(true);
446
- const response = fixture.responses.shift();
447
- assert.ok(typeof response === 'string');
448
- previous = JSON.parse(response).installed;
449
- }
450
- nativeArchiveFixture();
451
- 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');
452
- const entry = {
453
- pluginId: 'ai-delivery@ai-delivery-user',
454
- marketplaceName: 'ai-delivery-user',
455
- version: '0.3.22',
456
- enabled: true,
457
- source: { source: 'local', path: source },
458
- marketplaceSource: { sourceType: 'local', source: catalog },
459
- };
460
- fixture.responses.push('codex-cli 0.162.1', oversizedCatalogue(previous), '', '0.3.22', ...(action === 'install' ? ['{}'] : []), (args) => {
461
- assert.deepEqual(args, ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
462
- mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
463
- cpSync(source, cache, { recursive: true });
464
- return JSON.stringify({ installedPath: cache });
465
- }, oversizedCatalogue(readback(entry)));
466
- 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 };
467
634
  }
468
- function replacementFixture(preferences = { issue_info: { approval: 'fictional-explicit-allow' } }) {
469
- const { entry, cache, catalog } = installationFixture('update');
470
- fixture.responses = [];
471
- const selector = 'ai-delivery@ai-delivery-user';
472
- const policy = {
473
- [selector]: { enabled: true, preferences },
474
- 'private-unrelated@other': { sentinel: 'fictional-private-value', enabled: false },
475
- };
476
- const before = structuredClone(policy);
477
- const native = {
478
- selected: [
479
- {
480
- ...entry,
481
- version: '0.3.21',
482
- source: { source: 'local', path: join(catalog, 'versions/0.3.21/plugins/ai-delivery') },
483
- },
484
- ],
485
- version: 'codex-cli 0.162.1',
486
- selectionCalls: 0,
487
- loseAck: false,
488
- failSelection: false,
489
- };
490
- fixture.respond = (args) => {
491
- if (args[0] === 'npm')
492
- return '';
493
- if (args[0] === process.execPath)
494
- return '0.3.22';
495
- if (args[1] === '--version')
496
- return native.version;
497
- if (args[2] === 'list') {
498
- let offeredPath;
499
- try {
500
- const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
501
- offeredPath = offered.plugins[0].source.path;
502
- }
503
- catch {
504
- return undefined;
505
- }
506
- // Pinned list takes installed version from cache and source from the current catalog.
507
- return JSON.stringify({
508
- installed: native.selected.map((plugin) => ({
509
- ...plugin,
510
- source: { source: 'local', path: join(catalog, offeredPath) },
511
- })),
512
- available: [],
513
- });
514
- }
515
- if (args[2] === 'marketplace')
516
- return '{}';
517
- if (args[2] === 'remove') {
518
- // Pinned Codex remove clears the complete qualified plugin table.
519
- delete policy[selector];
520
- native.selected = [];
521
- return '{}';
522
- }
523
- if (args[2] === 'add') {
524
- assert.deepEqual(args, ['codex', 'plugin', 'add', selector, '--json']);
525
- native.selectionCalls++;
526
- if (native.failSelection)
527
- return undefined;
528
- // Pinned add retains existing fields but can evict older native caches.
529
- policy[selector] = { ...policy[selector], enabled: true };
530
- const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
531
- const offeredPath = offered.plugins[0].source.path;
532
- const version = /^\.\/versions\/([^/]+)\/plugins\/ai-delivery$/u.exec(offeredPath)[1];
533
- const selectedCache = join(dirname(cache), version);
534
- mkdirSync(dirname(selectedCache), { recursive: true, mode: 0o700 });
535
- cpSync(join(catalog, offeredPath), selectedCache, { recursive: true });
536
- for (const old of readdirSync(dirname(cache)))
537
- if (old !== version)
538
- rmSync(join(dirname(cache), old), { recursive: true });
539
- native.selected = [{ ...entry, version, source: { source: 'local', path: join(catalog, offeredPath) } }];
540
- return native.loseAck ? undefined : JSON.stringify({ installedPath: selectedCache });
541
- }
542
- return undefined;
543
- };
544
- 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 };
545
702
  }
546
703
  test.each([
547
- { issue_info: { approval: 'fictional-explicit-allow' }, unknown: { nested: ['retain', null] } },
548
- { unknown: { nested: ['retain', null] } },
549
- { issue_info: null, unknown: { nested: ['retain', null] } },
550
- ])('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) => {
551
710
  const { policy, before } = replacementFixture(preferences);
552
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
553
- 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");
554
713
  assert.deepEqual(policy, before);
555
- assert.equal(fixture.commandArguments.some((args) => ['remove', 'uninstall'].includes(args[2] ?? '')), false);
556
- });
557
- 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 () => {
558
724
  const { policy, before } = replacementFixture();
559
- await managePlugin({ ...input(), action: 'install', version: '0.3.22' });
725
+ await managePlugin({ ...input(), action: "install", version: "0.3.22" });
560
726
  assert.deepEqual(policy, before);
561
- assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
562
- });
563
- test('an exact same-version owned selection is reused without invoking native add', async () => {
564
- const { native } = replacementFixture();
565
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
566
- assert.equal(result.changed, false);
567
- 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);
568
738
  });
569
739
  test.each([
570
- 'disabled',
571
- 'missing selection',
572
- 'unregistered catalog',
573
- 'foreign source',
574
- 'changed cache',
575
- 'changed catalog',
576
- 'catalog symlink',
577
- 'read-only catalog',
578
- 'unqualified native',
579
- 'unqualified newer native',
580
- ])('replacement refuses %s before preparing a new version', async (fault) => {
581
- const { native, catalog, policy, before } = replacementFixture();
582
- if (fault === 'disabled')
583
- native.selected[0].enabled = false;
584
- if (fault === 'missing selection')
585
- native.selected = [];
586
- if (fault === 'unregistered catalog')
587
- native.selected[0].marketplaceSource.source = join(fixture.home, 'foreign-marketplace');
588
- if (fault === 'foreign source') {
589
- const respond = fixture.respond;
590
- fixture.respond = (args) => {
591
- const output = respond(args);
592
- if (args[2] !== 'list' || !output)
593
- return output;
594
- const listed = JSON.parse(output);
595
- listed.installed[0].source.path = join(fixture.home, 'unowned');
596
- return JSON.stringify(listed);
597
- };
598
- }
599
- if (fault === 'changed cache')
600
- writeFileSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21/skills/intake/SKILL.md'), 'changed');
601
- if (fault === 'changed catalog')
602
- writeFileSync(join(catalog, '.agents/plugins/marketplace.json'), '{}');
603
- const unrelatedCatalog = join(fixture.home, 'unrelated-catalog');
604
- if (fault === 'catalog symlink') {
605
- writeFileSync(unrelatedCatalog, 'unrelated catalog sentinel');
606
- rmSync(join(catalog, '.agents/plugins/marketplace.json'));
607
- symlinkSync(unrelatedCatalog, join(catalog, '.agents/plugins/marketplace.json'));
608
- }
609
- if (fault === 'read-only catalog')
610
- chmodSync(join(catalog, '.agents/plugins/marketplace.json'), 0o400);
611
- if (fault === 'unqualified native')
612
- native.version = 'codex-cli 0.153.0';
613
- if (fault === 'unqualified newer native')
614
- native.version = 'codex-cli 0.162.2';
615
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
616
- assert.equal(native.selectionCalls, 0);
617
- assert.equal(existsSync(join(catalog, 'versions/0.3.22')), false);
618
- assert.deepEqual(policy, before);
619
- if (fault === 'catalog symlink')
620
- assert.equal(readFileSync(unrelatedCatalog, 'utf8'), 'unrelated catalog sentinel');
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");
621
786
  });
622
- test.each(['update', 'install', 'rollback'])('Claude owned %s refuses an unqualified native version before catalog or selection changes', async (action) => {
623
- doctorFixture(true, 'claude-code');
624
- fixture.responses.unshift('2.1.295 (Claude Code)', '--keep-data');
625
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
626
- if (action === 'rollback') {
627
- const path = join(dirname(catalog), 'state.json');
628
- const state = JSON.parse(readFileSync(path, 'utf8'));
629
- state.previousVersion = '0.3.20';
630
- writeState(state, 'claude-code');
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");
631
798
  }
632
- 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
+ );
633
802
  const before = paths.map((path) => readFileSync(path));
634
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action, version: action === 'rollback' ? undefined : '0.3.22' }), /preserv.*unqualified/iu);
635
- assert.deepEqual(paths.map((path) => readFileSync(path)), before);
636
- assert.equal(fixture.commandArguments.some((args) => ['update', 'install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
637
- });
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
+ );
638
819
  function claudeReplacementFixture() {
639
- doctorFixture(true, 'claude-code');
640
- const initial = JSON.parse(fixture.responses.shift());
641
- nativeArchiveFixture();
642
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
643
- const settings = join(fixture.home, '.claude/settings.json');
644
- const preferences = {
645
- enabledPlugins: { 'ai-delivery@ai-delivery-user': true, 'unrelated@fictional': false },
646
- permissions: { allow: ['mcp__fictional__read'], deny: ['mcp__fictional__write'] },
647
- unknown: { nested: ['retain', null, { explicit: false }] },
648
- };
649
- writeFileSync(settings, JSON.stringify(preferences), { mode: 0o600 });
650
- const before = readFileSync(settings);
651
- const native = { selected: initial, updates: 0, loseAck: false, failSelection: false };
652
- fixture.respond = (args) => {
653
- if (args[0] === 'npm')
654
- return '';
655
- if (args[0] === process.execPath)
656
- return '0.3.22';
657
- if (args[1] === '--version')
658
- return '2.1.296 (Claude Code)';
659
- if (args[2] === 'uninstall' && args.includes('--help'))
660
- return '--keep-data';
661
- if (args[2] === 'list')
662
- return JSON.stringify(native.selected);
663
- if (args[2] === 'update') {
664
- assert.deepEqual(args, ['claude', 'plugin', 'update', 'ai-delivery@ai-delivery-user', '--scope', 'user']);
665
- native.updates++;
666
- if (native.failSelection)
667
- return undefined;
668
- const offered = JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8'));
669
- const { source, version } = offered.plugins[0];
670
- const cache = join(fixture.home, '.claude/plugins/cache/ai-delivery-user/ai-delivery', version);
671
- mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
672
- cpSync(join(catalog, source), cache, { recursive: true });
673
- native.selected = [{ ...initial[0], version, installPath: cache }];
674
- return native.loseAck ? undefined : '{}';
675
- }
676
- return undefined;
677
- };
678
- 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 };
679
854
  }
680
- 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) => {
681
858
  const { settings, before, native } = claudeReplacementFixture();
682
- const result = await managePlugin({ ...input(), host: 'claude-code', action, version: '0.3.22' });
683
- assert.equal(result.version, '0.3.22');
684
- 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
+ );
685
865
  assert.equal(native.updates, 1);
686
866
  assert.deepEqual(readFileSync(settings), before);
687
- assert.equal(fixture.commandArguments.some((args) => ['install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
688
- });
689
- 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 () => {
690
879
  const { settings, before, native } = claudeReplacementFixture();
691
- 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" });
692
881
  assert.equal(result.changed, false);
693
882
  assert.equal(native.updates, 0);
694
883
  assert.deepEqual(readFileSync(settings), before);
695
- });
696
- 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) => {
697
889
  const { catalog, native, settings, before } = claudeReplacementFixture();
698
- 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
+ );
699
893
  const catalogs = paths.map((path) => readFileSync(path));
700
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version }), /preserv.*unqualified/iu);
701
- 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
+ );
702
902
  assert.deepEqual(readFileSync(settings), before);
703
903
  assert.equal(native.updates, 0);
704
- assert.equal(existsSync(join(catalog, 'versions', version)), false);
705
- });
706
- 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 () => {
707
911
  const { native, settings, before, catalog } = claudeReplacementFixture();
708
912
  native.loseAck = true;
709
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
710
- const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
711
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
712
- 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");
713
917
  native.loseAck = false;
714
- 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" });
715
919
  assert.equal(native.updates, 1);
716
920
  assert.deepEqual(readFileSync(settings), before);
717
- });
718
- 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 () => {
719
927
  const { native, settings, before, catalog } = claudeReplacementFixture();
720
928
  native.failSelection = true;
721
- await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
722
- const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
723
- interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
724
- 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");
725
933
  native.failSelection = false;
726
- 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
+ );
727
938
  assert.equal(native.updates, 1);
728
939
  assert.deepEqual(readFileSync(settings), before);
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");
729
948
  });
730
- test('Claude doctor rejects changed native cache bytes before starting MCP', async () => {
731
- const cache = doctorFixture(true, 'claude-code');
732
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'foreign native cache bytes');
733
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
734
- assert.equal(result.sourceIntegrity, false);
735
- assert.equal(result.mcp?.startup, 'not_checked');
736
- });
737
- test('Claude doctor refuses a native cache path that differs from the owned selection', async () => {
738
- doctorFixture(true, 'claude-code');
739
- const entries = JSON.parse(fixture.responses[0]);
740
- entries[0].installPath = join(fixture.home, 'foreign-native-cache');
741
- fixture.responses[0] = JSON.stringify(entries);
742
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
743
- assert.equal(result.sourceIntegrity, false);
744
- assert.equal(result.mcp?.startup, 'not_checked');
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");
745
957
  });
746
- test('lost native acknowledgement remains a failure, then exact target postimage resumes without selecting twice', async () => {
958
+ test(
959
+ "lost native acknowledgement remains a failure, then exact target postimage resumes without selecting twice",
960
+ { tags: ["release"] },
961
+ async () => {
747
962
  const { native, policy, before, catalog } = replacementFixture();
748
963
  native.loseAck = true;
749
- 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
+ );
750
968
  assert.deepEqual(policy, before);
751
- const path = join(dirname(catalog), 'state.json');
752
- const interrupted = JSON.parse(readFileSync(path, 'utf8'));
753
- assert.equal(interrupted.currentVersion, '0.3.21');
754
- assert.equal(interrupted.pending.targetVersion, '0.3.22');
755
- 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" };
756
974
  writeState(interrupted);
757
975
  native.loseAck = false;
758
- const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
759
- 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");
760
978
  assert.equal(native.selectionCalls, 1);
761
979
  assert.deepEqual(policy, before);
762
- const finished = JSON.parse(readFileSync(path, 'utf8'));
763
- assert.equal(finished.currentVersion, '0.3.22');
764
- assert.equal(finished.previousVersion, '0.3.21');
765
- assert.equal(finished.pending, undefined);
766
- });
767
- 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 () => {
768
990
  const { native, catalog } = replacementFixture();
769
991
  native.failSelection = true;
770
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
771
- const path = join(dirname(catalog), 'state.json');
772
- const interrupted = JSON.parse(readFileSync(path, 'utf8'));
773
- 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" };
774
996
  writeState(interrupted);
775
997
  native.failSelection = false;
776
- 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);
777
999
  assert.equal(native.selectionCalls, 1);
778
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, '0.3.22');
779
- });
780
- 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 () => {
781
1010
  const { native, catalog } = replacementFixture();
782
1011
  native.loseAck = true;
783
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
784
- const statePath = join(dirname(catalog), 'state.json');
785
- const pending = JSON.parse(readFileSync(statePath, 'utf8'));
786
- 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" };
787
1016
  writeState(pending);
788
- const archive = join(catalog, 'versions/0.3.22/archive.tgz');
789
- writeFileSync(archive, 'corrupted completed archive');
1017
+ const archive = join(catalog, "versions/0.3.22/archive.tgz");
1018
+ writeFileSync(archive, "corrupted completed archive");
790
1019
  native.loseAck = false;
791
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
1020
+ await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
792
1021
  assert.equal(native.selectionCalls, 1);
793
- assert.equal(readFileSync(archive, 'utf8'), 'corrupted completed archive');
794
- assert.ok(JSON.parse(readFileSync(statePath, 'utf8')).pending);
795
- });
796
- 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 () => {
797
1030
  const { native, catalog, policy, before } = replacementFixture();
798
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
799
- assert.equal(existsSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21')), false);
800
- assert.equal(existsSync(join(catalog, 'versions/0.3.21/version.json')), true);
801
- policy.later = { sentinel: 'keep later edit' };
802
- const rolled = await managePlugin({ ...input(), action: 'rollback', version: undefined });
803
- 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");
804
1037
  assert.equal(native.selectionCalls, 2);
805
- assert.deepEqual(policy, { ...before, later: { sentinel: 'keep later edit' } });
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);
806
1058
  });
807
- test('rollback of a removed managed selection refuses rather than reinstalling it', async () => {
808
- const { catalog, native, policy } = replacementFixture();
809
- const path = join(dirname(catalog), 'state.json');
810
- const state = JSON.parse(readFileSync(path, 'utf8'));
811
- state.currentVersion = null;
812
- state.previousVersion = '0.3.21';
813
- state.installedPath = null;
814
- writeState(state);
815
- native.selected = [];
816
- delete policy['ai-delivery@ai-delivery-user'];
817
- const before = structuredClone(policy);
818
- await assert.rejects(managePlugin({ ...input(), action: 'rollback', version: undefined }), /current managed selection/u);
819
- assert.deepEqual(fixture.commandArguments, []);
820
- assert.deepEqual(policy, before);
821
- });
822
- test('rollback refuses a target superseded by the managed writer ahead of its lock', async () => {
1059
+ test(
1060
+ "rollback refuses a target superseded by the managed writer ahead of its lock",
1061
+ { tags: ["release"] },
1062
+ async () => {
823
1063
  const { catalog, native } = replacementFixture();
824
- const path = join(dirname(catalog), 'state.json');
825
- const initial = JSON.parse(readFileSync(path, 'utf8'));
826
- 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";
827
1067
  writeState(initial);
828
1068
  const respond = fixture.respond;
829
1069
  let queuedRollback;
830
1070
  fixture.respond = (args) => {
831
- const output = respond(args);
832
- if (args[2] === 'list' && native.selected[0]?.version === '0.3.22' && !queuedRollback)
833
- queuedRollback = managePlugin({ ...input(), action: 'rollback', version: undefined }).then(() => undefined, (error) => error);
834
- 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;
835
1078
  };
836
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
1079
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
837
1080
  assert.ok(queuedRollback);
838
1081
  const error = await queuedRollback;
839
1082
  assert.ok(error instanceof Error);
840
1083
  assert.match(error.message, /rollback target changed before/u);
841
1084
  assert.equal(native.selectionCalls, 1);
842
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).currentVersion, '0.3.22');
843
- });
844
- 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 () => {
845
1092
  const first = replacementFixture();
846
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
847
- const statePath = join(dirname(first.catalog), 'state.json');
848
- 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"));
849
1096
  const { catalog, native, policy, before } = replacementFixture();
850
- const immutableArchive = join(catalog, 'versions/0.3.22/archive.tgz');
1097
+ const immutableArchive = join(catalog, "versions/0.3.22/archive.tgz");
851
1098
  const archiveBefore = readFileSync(immutableArchive);
852
1099
  const actual = atomicJson.writePrivateJsonFileAtomically;
853
1100
  let interrupt = true;
854
- vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
855
- if (interrupt && path === join(catalog, '.claude-plugin/marketplace.json')) {
856
- interrupt = false;
857
- throw new Error('Synthetic catalog publication interruption');
858
- }
859
- 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);
860
1107
  });
861
- 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
+ );
862
1112
  assert.equal(native.selectionCalls, 0);
863
- assert.equal(JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8')).plugins[0].version, '0.3.21');
864
- assert.match(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'), /versions\/0\.3\.22/u);
865
- const pending = JSON.parse(readFileSync(statePath, 'utf8'));
866
- 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" };
867
1120
  writeState(pending);
868
1121
  fixture.commands = [];
869
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
870
- 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);
871
1124
  assert.deepEqual(readFileSync(immutableArchive), archiveBefore);
872
- assert.equal(fixture.commands.includes('npm'), false);
1125
+ assert.equal(fixture.commands.includes("npm"), false);
873
1126
  assert.equal(native.selectionCalls, 1);
874
1127
  assert.deepEqual(policy, before);
875
- });
876
- 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 () => {
877
1134
  const { native, catalog, policy, before } = replacementFixture();
878
1135
  const actual = atomicJson.writePrivateJsonFileAtomically;
879
- const fault = vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
880
- const state = value;
881
- if (path.endsWith('/state.json') && state.currentVersion === '0.3.22' && !state.pending)
882
- throw new Error('Synthetic final state commit failure');
883
- 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);
884
1141
  });
885
- 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
+ );
886
1146
  fault.mockRestore();
887
- const path = join(dirname(catalog), 'state.json');
888
- const pending = JSON.parse(readFileSync(path, 'utf8'));
889
- 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" };
890
1150
  writeState(pending);
891
- await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
1151
+ await managePlugin({ ...input(), action: "update", version: "0.3.22" });
892
1152
  assert.equal(native.selectionCalls, 1);
893
1153
  assert.deepEqual(policy, before);
894
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending, undefined);
895
- });
896
- 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) => {
897
1160
  const { catalog, native } = replacementFixture();
898
1161
  const respond = fixture.respond;
899
- const path = join(dirname(catalog), 'state.json');
1162
+ const path = join(dirname(catalog), "state.json");
900
1163
  let changed;
901
1164
  fixture.respond = (args) => {
902
- const output = respond(args);
903
- if (args[2] === 'add') {
904
- if (change === 'mode')
905
- chmodSync(path, 0o400);
906
- else {
907
- const state = JSON.parse(readFileSync(path, 'utf8'));
908
- state.previousVersion = '0.3.19';
909
- writeFileSync(path, JSON.stringify(state), { mode: 0o600 });
910
- }
911
- 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 });
912
1172
  }
913
- return output;
1173
+ changed = readFileSync(path);
1174
+ }
1175
+ return output;
914
1176
  };
915
- 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);
916
1178
  assert.equal(native.selectionCalls, 1);
917
1179
  assert.ok(changed);
918
1180
  assert.deepEqual(readFileSync(path), changed);
919
- if (change === 'mode')
920
- assert.equal(lstatSync(path).mode & 0o777, 0o400);
921
- });
922
- 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 () => {
923
1188
  const { catalog, native, policy, before } = replacementFixture();
924
1189
  const respond = fixture.respond;
925
- const path = join(catalog, '.agents/plugins/marketplace.json');
1190
+ const path = join(catalog, ".agents/plugins/marketplace.json");
926
1191
  fixture.respond = (args) => {
927
- const output = respond(args);
928
- if (args[0] === process.execPath)
929
- chmodSync(path, 0o644);
930
- return output;
1192
+ const output = respond(args);
1193
+ if (args[0] === process.execPath) chmodSync(path, 420);
1194
+ return output;
931
1195
  };
932
- 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);
933
1197
  assert.equal(native.selectionCalls, 0);
934
- assert.equal(lstatSync(path).mode & 0o777, 0o644);
1198
+ assert.equal(lstatSync(path).mode & 511, 420);
935
1199
  assert.deepEqual(policy, before);
936
- });
937
- for (const action of ['install', 'update'])
938
- test(`${action} reads back its managed version without capturing an unrelated catalogue over 1 MiB`, async () => {
939
- const { entry, cache, catalog } = installationFixture(action);
940
- const data = join(fixture.home, 'unrelated-native-data');
941
- writeFileSync(data, 'preserve native data');
942
- const result = await managePlugin({ ...input(), action, version: '0.3.22' });
943
- assert.equal(result.installed, true);
944
- assert.equal(result.changed, true);
945
- assert.equal(result.version, '0.3.22');
946
- assert.equal(result.nativePluginRoot, cache);
947
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'synthetic released skill bytes');
948
- const state = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
949
- assert.equal(state.pending, undefined);
950
- assert.equal(state.currentVersion, '0.3.22');
951
- assert.equal(state.previousVersion, action === 'update' ? '0.3.21' : null);
952
- const mutation = fixture.commandArguments.find((args) => args[2] === (action === 'install' ? 'marketplace' : 'add'));
953
- assert.deepEqual(mutation, action === 'install'
954
- ? ['codex', 'plugin', 'marketplace', 'add', catalog, '--json']
955
- : ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
956
- assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
957
- fixture.responses.push(oversizedCatalogue([{ ...entry, enabled: false }]));
958
- const doctor = await managePlugin({ ...input(), action: 'doctor', version: undefined });
959
- assert.equal(doctor.installed, true);
960
- assert.equal(doctor.sourceIntegrity, true);
961
- assert.deepEqual(doctor.mcp, { configuration: 'disabled', startup: 'not_checked' });
962
- assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
963
- assert.equal(fixture.commandArguments.filter((args) => args[2] === 'list').length, 4);
964
- });
965
- test('the filtered managed catalogue still enforces the 1 MiB capture ceiling', async () => {
966
- doctorFixture(false);
967
- fixture.responses[0] = JSON.stringify({ installed: [], available: [{ description: 'x'.repeat(1024 * 1024) }] });
968
- 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
+ );
969
1247
  });
970
1248
  for (const [name, readback, error] of [
971
- [
972
- 'missing registration',
973
- (entry) => [{ ...entry, marketplaceName: 'unrelated' }],
974
- /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") } }
975
1258
  ],
976
- [
977
- 'wrong marketplace source',
978
- (entry) => [
979
- { ...entry, marketplaceSource: { sourceType: 'local', source: join(fixture.home, 'unmanaged') } },
980
- ],
981
- /unmanaged source/u,
982
- ],
983
- [
984
- 'wrong version source',
985
- (entry) => [
986
- { ...entry, source: { source: 'local', path: join(fixture.home, 'unmanaged') } },
987
- ],
988
- /source differs/u,
989
- ],
990
- ['duplicate native selection', (entry) => [entry, entry], /ambiguous/u],
991
- [
992
- 'disabled native selection',
993
- (entry) => [{ ...entry, enabled: false }],
994
- /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") } }
995
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
+ ]
996
1274
  ])
997
- test(`filtered installation refuses ${name} and retains its interrupted intent`, async () => {
998
- const { catalog } = installationFixture('install', readback);
999
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), error);
1000
- const state = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
1001
- assert.equal(state.currentVersion, null);
1002
- assert.equal(state.pending.targetVersion, '0.3.22');
1003
- });
1004
- test('filtered readback refuses changed native bytes without adopting the selected version', async () => {
1005
- 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");
1006
1287
  const add = fixture.responses[5];
1007
- assert.ok(typeof add === 'function');
1288
+ assert.ok(typeof add === "function");
1008
1289
  fixture.responses[5] = (args) => {
1009
- const result = add(args);
1010
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'unexpected native bytes');
1011
- return result;
1290
+ const result = add(args);
1291
+ writeFileSync(join(cache, "skills/intake/SKILL.md"), "unexpected native bytes");
1292
+ return result;
1012
1293
  };
1013
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), /native plugin bytes/u);
1014
- 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"));
1015
1296
  assert.equal(state.currentVersion, null);
1016
1297
  assert.ok(state.pending);
1017
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'unexpected native bytes');
1018
- });
1019
- test('interrupted filtered readback resumes the original install without fetching or losing native data', async () => {
1020
- 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");
1021
1306
  fixture.responses.pop();
1022
- await assert.rejects(managePlugin({ ...input(), version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1023
- const statePath = join(dirname(catalog), 'state.json');
1024
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1025
- state.pending.owner = { pid: 2_000_000_000, birth: 'terminated fixture owner' };
1026
- writeFileSync(statePath, JSON.stringify(state), { mode: 0o600 });
1027
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1028
- fixture.responses.push('codex-cli 0.153.0', oversizedCatalogue([entry]), oversizedCatalogue([entry]));
1029
- const result = await managePlugin({ ...input(), version: '0.3.22' });
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" });
1030
1315
  assert.equal(result.installed, true);
1031
- assert.equal(result.version, '0.3.22');
1032
- assert.equal(JSON.parse(readFileSync(statePath, 'utf8')).pending, undefined);
1033
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
1034
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
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);
1035
1337
  });
1036
- test('filtered inventory does not adopt a manual install even when its marketplace source matches', async () => {
1037
- const cache = doctorFixture(true);
1038
- const response = fixture.responses.shift();
1039
- assert.ok(typeof response === 'string');
1040
- const directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user');
1041
- rmSync(directory, { recursive: true });
1042
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1043
- fixture.responses.push('codex-cli 0.153.0', response);
1044
- await assert.rejects(managePlugin(input()), /not owned by managed state/u);
1045
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1046
- const state = JSON.parse(readFileSync(join(directory, 'state.json'), 'utf8'));
1047
- assert.equal(state.currentVersion, null);
1048
- assert.equal(state.installedPath, null);
1049
- assert.equal(state.pending, undefined);
1050
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
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"]]);
1051
1346
  });
1052
- test('Claude doctor retains its unfiltered native inventory and disabled selection readback', async () => {
1053
- doctorFixture(false, 'claude-code');
1054
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1055
- assert.equal(result.installed, true);
1056
- assert.equal(result.enabled, false);
1057
- assert.equal(result.sourceIntegrity, true);
1058
- assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
1059
- assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
1060
- });
1061
- test('Claude doctor binds managed provenance to the verified scope and source, excluding other projects', async () => {
1062
- doctorFixture(false, 'claude-code');
1063
- const entries = JSON.parse(fixture.responses[0]);
1064
- const selected = entries[0];
1065
- 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' });
1066
- fixture.responses[0] = JSON.stringify(entries);
1067
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1068
- assert.equal(result.sourceIntegrity, true);
1069
- assert.ok(result.diagnostics);
1070
- assert.deepEqual(result.diagnostics.registrations, [
1071
- {
1072
- kind: 'plugin',
1073
- scope: 'user',
1074
- ownership: 'managed',
1075
- source: 'managed_archive',
1076
- version: '0.3.21',
1077
- enabled: false,
1078
- },
1079
- { kind: 'plugin', scope: 'project', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: false },
1080
- { kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
1081
- { kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
1082
- ]);
1083
- assert.ok(result.diagnostics.findings.includes('native_registration_project_unverified'));
1084
- assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
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"]]);
1085
1401
  });
1086
- test('doctor refuses a same-version native cache with changed skill bytes before starting MCP', async () => {
1087
- const cache = doctorFixture(true);
1088
- writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'unexpected native bytes');
1089
- const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
1090
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1091
- assert.equal(result.installed, true);
1092
- assert.equal(result.sourceIntegrity, false);
1093
- assert.equal(result.mcp?.startup, 'not_checked');
1094
- assert.match(result.mcp?.error ?? '', /native plugin bytes/u);
1095
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1096
- assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
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);
1097
1413
  });
1098
- test('doctor reports a disabled native plugin separately and does not start its MCP server', async () => {
1099
- doctorFixture(false);
1100
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1101
- assert.equal(result.installed, true);
1102
- assert.equal(result.enabled, false);
1103
- assert.equal(result.sourceIntegrity, true);
1104
- assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
1105
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
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"]);
1106
1422
  });
1107
- test('doctor refuses a Claude catalog pointing at a different same-version source before startup', async () => {
1108
- doctorFixture(true, 'claude-code');
1109
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
1110
- const other = join(catalog, 'unexpected-source');
1111
- mkdirSync(other, { mode: 0o700 });
1112
- writeFileSync(join(other, 'plugin.json'), JSON.stringify({ name: 'ai-delivery', version: '0.3.21' }));
1113
- const path = join(catalog, '.claude-plugin/marketplace.json');
1114
- writeFileSync(path, JSON.stringify({
1115
- name: 'ai-delivery-user',
1116
- plugins: [{ name: 'ai-delivery', version: '0.3.21', source: './unexpected-source' }],
1117
- }));
1118
- const before = readFileSync(path);
1119
- const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
1120
- assert.equal(result.sourceIntegrity, false);
1121
- assert.equal(result.mcp?.startup, 'not_checked');
1122
- assert.match(result.mcp?.error ?? '', /catalog source/u);
1123
- assert.deepEqual(fixture.commands, ['claude']);
1124
- assert.deepEqual(readFileSync(path), before);
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);
1125
1444
  });
1126
- test('a different native profile cannot reconcile or overwrite the original ownership record', async () => {
1127
- const profileA = join(fixture.home, 'profile-a'), profileB = join(fixture.home, 'profile-b');
1128
- mkdirSync(profileA, { mode: 0o700 });
1129
- const marker = join(profileA, 'plugin-selection');
1130
- writeFileSync(marker, 'profile A stays installed');
1131
- const value = pendingState('install', '0.3.21');
1132
- const statePath = writeState({ ...value, pending: undefined, currentVersion: '0.3.21', nativeHome: profileA });
1133
- const before = readFileSync(statePath);
1134
- vi.stubEnv('CODEX_HOME', profileB);
1135
- await assert.rejects(managePlugin({ ...input(), action: 'remove', version: undefined }), /different native profile/u);
1136
- assert.deepEqual(fixture.commands, []);
1137
- assert.deepEqual(readFileSync(statePath), before);
1138
- assert.equal(readFileSync(marker, 'utf8'), 'profile A stays installed');
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");
1139
1458
  });
1140
- test('an absent native profile beneath a symlink keeps its identity after creation', async () => {
1141
- const parent = join(fixture.home, 'native-profiles'), alias = join(fixture.home, 'native-profile-alias');
1142
- mkdirSync(parent, { mode: 0o700 });
1143
- symlinkSync(parent, alias);
1144
- const profile = join(alias, 'new-profile');
1145
- vi.stubEnv('CODEX_HOME', profile);
1146
- await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1147
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1148
- const before = readFileSync(statePath);
1149
- const state = JSON.parse(before.toString());
1150
- assert.equal(state.nativeHome, join(parent, 'new-profile'));
1151
- mkdirSync(profile, { mode: 0o700 });
1152
- const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
1153
- assert.equal(result.recoveryRequired, false);
1154
- assert.deepEqual(readFileSync(statePath), before);
1155
- assert.equal(result.diagnostics?.nativeInventory, 'unavailable');
1156
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
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"]);
1157
1476
  });
1158
- test('a definitive version preparation failure preserves selection and permits a different valid request', async () => {
1159
- const cache = doctorFixture(true);
1160
- const response = fixture.responses[0];
1161
- fixture.responses.unshift('codex-cli 0.162.1');
1162
- const catalog = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace');
1163
- const catalogPath = join(catalog, '.agents/plugins/marketplace.json');
1164
- mkdirSync(dirname(catalogPath), { recursive: true, mode: 0o700 });
1165
- const before = readFileSync(catalogPath);
1166
- const data = join(fixture.home, 'native-data');
1167
- writeFileSync(data, 'preserve native data');
1168
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1169
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1170
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1171
- assert.equal(state.pending, undefined);
1172
- assert.equal(state.currentVersion, '0.3.21');
1173
- assert.equal(state.installedPath, cache);
1174
- assert.deepEqual(readFileSync(catalogPath), before);
1175
- assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
1176
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
1177
- fixture.responses.push('codex-cli 0.162.1', response, response);
1178
- const reused = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
1179
- assert.equal(reused.changed, false);
1180
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
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);
1181
1503
  });
1182
- test('failure after catalog selection retains pending recovery before another version', async () => {
1504
+ test(
1505
+ "failure after catalog selection retains pending recovery before another version",
1506
+ { tags: ["release"] },
1507
+ async () => {
1183
1508
  const { native } = replacementFixture();
1184
1509
  native.failSelection = true;
1185
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
1186
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1187
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1188
- 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");
1189
1517
  const before = [...fixture.commandArguments];
1190
- 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
+ );
1191
1522
  assert.deepEqual(fixture.commandArguments, before);
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
+ );
1192
1543
  });
1193
- test('definitive preparation reports pending-state cleanup failure and preserves its recovery intent', async () => {
1194
- const actual = atomicJson.writePrivateJsonFileAtomically;
1195
- vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
1196
- if (path.endsWith('/state.json') && !value.pending)
1197
- throw new Error('Synthetic pending-state durability failure');
1198
- actual(path, value);
1199
- });
1200
- await assert.rejects(managePlugin(input()), (error) => {
1201
- assert.ok(error instanceof AggregateError);
1202
- assert.match(error.message, /pending-state cleanup also failed/u);
1203
- assert.equal(error.errors.length, 2);
1204
- return true;
1205
- });
1206
- const path = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1207
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, '0.3.21');
1208
- });
1209
- test('an unsupported version archive leaves selection intact and permits a valid version request', async () => {
1544
+ test(
1545
+ "an unsupported version archive leaves selection intact and permits a valid version request",
1546
+ { tags: ["release"] },
1547
+ async () => {
1210
1548
  const cache = doctorFixture(true);
1211
1549
  const response = fixture.responses[0];
1212
- fixture.responses.unshift('codex-cli 0.162.1');
1213
- const root = join(fixture.home, 'unsupported/package');
1550
+ fixture.responses.unshift("codex-cli 0.162.1");
1551
+ const root = join(fixture.home, "unsupported/package");
1214
1552
  const files = {
1215
- 'package.json': { name: '@aviaratech/ai-delivery', version: '0.3.22' },
1216
- 'plugins/ai-delivery/plugin.json': { name: 'ai-delivery', version: '0.3.22' },
1217
- 'plugins/ai-delivery/.claude-plugin/plugin.json': {
1218
- name: 'ai-delivery',
1219
- version: '0.3.22',
1220
- packageVersion: '0.3.22',
1221
- deliveryCapabilityVersion: 1,
1222
- },
1223
- '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" }
1224
1562
  };
1225
1563
  for (const [name, value] of Object.entries(files)) {
1226
- const path = join(root, name);
1227
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
1228
- 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 });
1229
1567
  }
1230
- const configuration = join(fixture.home, 'empty.npmrc');
1231
- const globalConfiguration = join(fixture.home, 'global.npmrc');
1232
- writeFileSync(configuration, '', { mode: 0o600 });
1233
- writeFileSync(globalConfiguration, '', { mode: 0o600 });
1234
- const packed = JSON.parse(execFileSync('npm', [
1235
- 'pack',
1236
- '--ignore-scripts',
1237
- '--json',
1238
- '--logs-max',
1239
- '0',
1240
- '--cache',
1241
- join(fixture.home, 'npm-cache'),
1242
- '--userconfig',
1243
- configuration,
1244
- '--globalconfig',
1245
- globalConfiguration,
1246
- '--pack-destination',
1247
- fixture.home,
1248
- ], { 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
+ );
1249
1593
  fixture.packArchive = join(fixture.home, packed[0].filename);
1250
- await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /coherent self-contained native plugin/u);
1251
- const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1252
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
1253
- assert.equal(state.pending, undefined);
1254
- 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");
1255
1602
  assert.equal(state.installedPath, cache);
1256
- assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
1257
- assert.equal(existsSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions/0.3.22')), false);
1258
- fixture.packArchive = '';
1259
- fixture.responses.push('codex-cli 0.162.1', response, response);
1260
- 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" });
1261
1611
  assert.equal(reused.changed, false);
1262
- assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
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");
1263
1630
  });
1264
- test('recovery removes only its recorded incomplete staging directory', async () => {
1265
- const version = '0.3.21', directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions');
1266
- const owned = join(directory, '.stage-11111111-1111-1111-1111-111111111111'), peer = join(directory, '.stage-peer');
1267
- for (const path of [owned, peer]) {
1268
- mkdirSync(path, { recursive: true, mode: 0o700 });
1269
- writeFileSync(join(path, 'partial'), 'preserve-or-recover');
1270
- }
1271
- const metadata = lstatSync(owned), value = pendingState('install', version);
1272
- writeState({
1273
- ...value,
1274
- pending: { ...value.pending, staging: { path: owned, device: metadata.dev, inode: metadata.ino } },
1275
- });
1276
- await assert.rejects(managePlugin(input()), /Native fixture intentionally unavailable/u);
1277
- assert.equal(existsSync(owned), false);
1278
- assert.equal(readFileSync(join(peer, 'partial'), 'utf8'), 'preserve-or-recover');
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, []);
1279
1636
  });
1280
- test('recovery rejects incompatible controllers without starting native commands', async () => {
1281
- const value = pendingState('install', '0.3.21');
1282
- writeState({ ...value, pending: { ...value.pending, producerDigest: `sha256:${'0'.repeat(64)}` } });
1283
- await assert.rejects(managePlugin(input()), /different controller/u);
1284
- assert.deepEqual(fixture.commands, []);
1285
- });
1286
- test('cancellation kills recorded detached descendants and preserves an unrelated process', async () => {
1637
+ test(
1638
+ "cancellation kills recorded detached descendants and preserves an unrelated process",
1639
+ { tags: ["release"] },
1640
+ async () => {
1287
1641
  fixture.realCommands = true;
1288
- const bin = join(fixture.home, 'bin'), marker = join(fixture.home, 'descendant');
1642
+ const bin = join(fixture.home, "bin"), marker = join(fixture.home, "descendant");
1289
1643
  mkdirSync(bin);
1290
1644
  const childScript = "require('fs').writeFileSync(process.argv[1],String(process.pid));process.on('SIGTERM',()=>{});setInterval(()=>{},1000)";
1291
- 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 });
1292
- vi.stubEnv('PATH', `${bin}:${process.env.PATH ?? ''}`);
1293
- 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" });
1294
1654
  const preload = fixturePreload();
1295
- const cli = spawn(process.execPath, [
1296
- '--import',
1655
+ const cli = spawn(
1656
+ process.execPath,
1657
+ [
1658
+ "--import",
1297
1659
  preload,
1298
- join(dirname(fileURLToPath(import.meta.url)), 'cli.js'),
1299
- '--repo-root',
1660
+ join(dirname(fileURLToPath(import.meta.url)), "cli.js"),
1661
+ "--repo-root",
1300
1662
  fixture.home,
1301
- 'plugin',
1302
- 'install',
1303
- '--host',
1304
- 'codex',
1305
- '--scope',
1306
- 'user',
1307
- '--version',
1308
- '0.3.21',
1309
- '--json',
1310
- ], { stdio: ['ignore', 'pipe', 'pipe'] });
1311
- 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 = "";
1312
1676
  for (const stream of [cli.stdout, cli.stderr])
1313
- stream.on('data', (bytes) => {
1314
- if (Buffer.byteLength(output) + bytes.length <= 1024 * 1024)
1315
- output += bytes.toString();
1316
- });
1317
- 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)));
1318
1681
  let descendant;
1319
1682
  try {
1320
- for (let attempt = 0; attempt < 1000; attempt++) {
1321
- if (cli.exitCode !== null || cli.signalCode !== null)
1322
- break;
1323
- if (existsSync(marker)) {
1324
- descendant = Number(readFileSync(marker, 'utf8'));
1325
- const path = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
1326
- const pending = JSON.parse(readFileSync(path, 'utf8')).pending;
1327
- if (pending.command.phase === 'running' &&
1328
- pending.command.tracked.some((entry) => entry.pid === descendant))
1329
- break;
1330
- }
1331
- 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;
1332
1691
  }
1333
- assert.ok(descendant, `native fixture started its detached child: ${output}`);
1334
- const state = JSON.parse(readFileSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json'), 'utf8'));
1335
- assert.ok(state.pending.command.tracked.some((entry) => entry.pid === descendant), 'durable receipt captured child identity');
1336
- cli.kill('SIGTERM');
1337
- assert.equal(await closed, 1);
1338
- assert.match(output, /cancelled/u);
1339
- const observed = processSnapshot().get(descendant);
1340
- assert.ok(!observed || observed.status.startsWith('Z'));
1341
- assert.ok(processSnapshot().has(peer.pid));
1342
- assert.equal(JSON.parse(readFileSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json'), 'utf8')).pending.command.phase, 'idle');
1343
- }
1344
- finally {
1345
- cli.kill('SIGTERM');
1346
- await closed;
1347
- peer.kill('SIGKILL');
1348
- await new Promise((done) => {
1349
- if (peer.exitCode !== null || peer.signalCode !== null)
1350
- done();
1351
- else
1352
- peer.once('close', () => done());
1353
- });
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
+ });
1354
1722
  }
1355
- });
1356
- 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 });
1357
1726
  function fixturePreload() {
1358
- const path = join(fixture.home, 'home.mjs');
1359
- writeFileSync(path, `import os from 'node:os';import {syncBuiltinESMExports} from 'node:module';os.homedir=()=>${JSON.stringify(fixture.home)};syncBuiltinESMExports();`);
1360
- 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;
1361
1733
  }
1362
- test('compiled plugin CLI consumes its local version and emits the promised JSON dry-run', () => {
1363
- const cli = join(dirname(fileURLToPath(import.meta.url)), 'cli.js');
1364
- const result = spawnSync(process.execPath, [
1365
- '--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",
1366
1743
  fixturePreload(),
1367
1744
  cli,
1368
- '--repo-root',
1745
+ "--repo-root",
1369
1746
  fixture.home,
1370
- 'plugin',
1371
- 'install',
1372
- '--host',
1373
- 'codex',
1374
- '--version',
1375
- '0.3.21',
1376
- '--dry-run',
1377
- '--json',
1378
- ], { 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
+ );
1379
1758
  assert.equal(result.status, 0, result.stderr);
1380
1759
  const value = JSON.parse(result.stdout);
1381
- assert.equal(value.action, 'install');
1382
- assert.equal(value.version, '0.3.21');
1760
+ assert.equal(value.action, "install");
1761
+ assert.equal(value.version, "0.3.21");
1383
1762
  assert.equal(value.dryRun, true);
1384
- assert.ok(!existsSync(join(fixture.home, '.cache')));
1385
- });
1386
- test('compiled doctor CLI requires explicit repository for auth and keeps dry-run credential-free', () => {
1387
- const cli = join(dirname(fileURLToPath(import.meta.url)), 'cli.js');
1388
- const invoke = (prefix, suffix) => spawnSync(process.execPath, [
1389
- '--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",
1390
1775
  fixturePreload(),
1391
1776
  cli,
1392
- '--repo-root',
1777
+ "--repo-root",
1393
1778
  fixture.home,
1394
1779
  ...prefix,
1395
- 'plugin',
1396
- 'doctor',
1397
- '--host',
1398
- 'codex',
1399
- ...suffix,
1400
- ], { encoding: 'utf8', maxBuffer: 1024 * 1024 });
1401
- 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"]);
1402
1789
  assert.equal(missing.status, 1);
1403
1790
  assert.match(missing.stderr, /requires explicit --repo owner\/name/u);
1404
- const selected = invoke(['--repo', 'example/widget'], ['--check-auth', '--dry-run', '--json']);
1791
+ const selected = invoke(["--repo", "example/widget"], ["--check-auth", "--dry-run", "--json"]);
1405
1792
  assert.equal(selected.status, 0, selected.stderr);
1406
1793
  const value = JSON.parse(selected.stdout);
1407
- assert.equal(value.authProbe.settings, 'not_checked');
1408
- assert.equal(value.authProbe.reason, 'dry_run');
1409
- assert.equal(value.authProbe.repositoryAccess.repository, 'example/widget');
1410
- 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"]);
1411
1798
  assert.equal(defaultDoctor.status, 0, defaultDoctor.stderr);
1412
- assert.equal(JSON.parse(defaultDoctor.stdout).authProbe, undefined);
1413
- assert.ok(!existsSync(join(fixture.home, '.cache')));
1799
+ assert.equal(JSON.parse(defaultDoctor.stdout).authProbe, void 0);
1800
+ assert.ok(!existsSync(join(fixture.home, ".cache")));
1801
+ }
1802
+ );
1803
+ function producerDependencyFixture(esm = true) {
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)) };
1827
+ }
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
+ );
1414
1843
  });
1415
- test('plugin management rejects unsupported native scopes and nonliteral versions before writing', async () => {
1416
- for (const value of [
1417
- { ...input(), scope: 'project' },
1418
- { ...input(), host: 'claude-code', scope: 'managed' },
1419
- { ...input(), version: 'latest' },
1420
- { ...input(), version: undefined },
1421
- { ...input(), version: '0.3.21 --ignore-scripts=false' },
1422
- ])
1423
- await assert.rejects(managePlugin(value));
1424
- assert.deepEqual(readdirSync(fixture.home), []);
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
+ );
1425
1853
  });
1426
- test('plugin dry-run describes the exact selected native target without creating a profile or fetching', async () => {
1427
- const result = await managePlugin({ ...input(), dryRun: true });
1428
- assert.equal(result.action, 'install');
1429
- assert.equal(result.host, 'codex');
1430
- assert.equal(result.scope, 'user');
1431
- assert.equal(result.version, '0.3.21');
1432
- assert.equal(result.changed, false);
1433
- assert.equal(result.dryRun, true);
1434
- assert.deepEqual(readdirSync(fixture.home), []);
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
+ );
1861
+ const published = [];
1862
+ const actual = atomicJson.writePrivateJsonFileAtomically;
1863
+ vi.spyOn(atomicJson, "writePrivateJsonFileAtomically").mockImplementation((path, value) => {
1864
+ if (paths.includes(path)) published.push(path);
1865
+ actual(path, value);
1866
+ });
1867
+ await managePlugin({ ...input(), host, action: "update", version: "0.3.22" });
1868
+ assert.deepEqual(published, paths);
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
+ );
1903
+ }
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));
1911
+ }
1912
+ }
1913
+ );
1914
+ test.each(["codex", "claude-code"])(
1915
+ "toolkit adoption loads compatible completed state unchanged for %s",
1916
+ async (host) => {
1917
+ doctorFixture(true, host);
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")];
1920
+ const before = paths.map((path) => readFileSync(path));
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), []);
1435
1943
  });
1436
- test('doctor of an unconfigured host is read-only and does not claim installation or admission', async () => {
1437
- const result = await managePlugin({ action: 'doctor', host: 'claude-code', scope: 'local', repoRoot: fixture.home });
1438
- assert.equal(result.changed, false);
1439
- assert.equal(result.installed, false);
1440
- assert.equal(result.repositoryAdmission, 'explicit_stage_and_admit_required');
1441
- assert.deepEqual(readdirSync(fixture.home), []);
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), []);
1442
1954
  });
1443
- test('remove never touches an unmanaged native selector or creates managed state', async () => {
1444
- const result = await managePlugin({ action: 'remove', host: 'codex', scope: 'user', repoRoot: fixture.home });
1445
- assert.equal(result.changed, false);
1446
- assert.deepEqual(fixture.commands, []);
1447
- assert.deepEqual(readdirSync(fixture.home), []);
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), []);
1448
1964
  });
1449
- test('initial install refuses a marketplace-name collision before fetching or changing native selection', async () => {
1450
- const unowned = join(fixture.home, 'unowned-marketplace');
1451
- mkdirSync(unowned);
1452
- const marker = join(unowned, 'configuration');
1453
- writeFileSync(marker, 'unrelated native source');
1454
- fixture.responses.push('codex-cli 0.153.0', JSON.stringify({
1455
- installed: [
1456
- {
1457
- pluginId: 'ai-delivery@ai-delivery-user',
1458
- marketplaceName: 'ai-delivery-user',
1459
- version: '0.3.21',
1460
- enabled: true,
1461
- source: { source: 'local', path: unowned },
1462
- marketplaceSource: { sourceType: 'local', source: unowned },
1463
- },
1464
- ],
1465
- available: [],
1466
- }));
1467
- await assert.rejects(managePlugin(input()), /unmanaged source/u);
1468
- assert.deepEqual(fixture.commands, ['codex', 'codex']);
1469
- assert.equal(readFileSync(marker, 'utf8'), 'unrelated native source');
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");
1470
2002
  });
1471
- test('an interrupted managed removal resumes its null target before invoking native commands', async () => {
1472
- const directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user');
1473
- mkdirSync(directory, { recursive: true, mode: 0o700 });
1474
- const path = join(directory, 'state.json');
1475
- writeFileSync(path, JSON.stringify({
1476
- owner: '@aviaratech/ai-delivery.plugin@1',
1477
- host: 'codex',
1478
- scope: 'user',
1479
- projectRoot: null,
1480
- nativeHome: join(fixture.home, '.codex'),
1481
- marketplace: 'ai-delivery-user',
1482
- currentVersion: '0.3.21',
1483
- previousVersion: null,
1484
- installedPath: null,
1485
- pending: {
1486
- action: 'remove',
1487
- targetVersion: null,
1488
- producerDigest: retainedWorktreeTransitionProducerDigest(dirname(fileURLToPath(import.meta.url))),
1489
- owner: { pid: 2_000_000_000, birth: 'old owner' },
1490
- command: { phase: 'idle' },
1491
- },
1492
- }), { mode: 0o600 });
1493
- await assert.rejects(managePlugin({ action: 'remove', host: 'codex', scope: 'user', repoRoot: fixture.home }), /Native fixture intentionally unavailable/u);
1494
- assert.deepEqual(fixture.commands, ['codex']);
1495
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, null);
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);
1496
2035
  });
1497
- //# sourceMappingURL=pluginInstaller.test.js.map
2036
+ //# sourceMappingURL=pluginInstaller.test.js.map