@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.
- package/CONTRIBUTING.md +12 -206
- package/README.md +57 -506
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +76 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1746 -0
- package/dist/boardReconcile.test.js.map +7 -0
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +105 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +406 -485
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -25
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +434 -297
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +320 -14
- package/dist/config/deliveryConfig.js +472 -385
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +775 -584
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -477
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.d.ts +1 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +17 -12
- package/dist/dispatch.js +330 -322
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +16 -3
- package/dist/errors.js +104 -82
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +59 -19
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.js +73 -67
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +44 -51
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +3 -0
- package/dist/github/discovery.js +197 -201
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +53 -1
- package/dist/github/projectDelivery.js +623 -460
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.d.ts +5 -2
- package/dist/github/relationships.js +434 -333
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +103 -7
- package/dist/issue.js +2104 -1547
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +1004 -683
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1945 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1088 -593
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -90
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +790 -220
- package/dist/mcp/tools.js +267 -333
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1231
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1822 -1283
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +485 -305
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +132 -94
- package/dist/pr.js +1521 -1323
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +1678 -632
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +150 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +183 -0
- package/dist/readView.js +217 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +119 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +1204 -0
- package/dist/services/boardReconcileService.js +1445 -0
- package/dist/services/boardReconcileService.js.map +7 -0
- package/dist/services/deliveryAdmission.d.ts +2 -0
- package/dist/services/deliveryAdmission.js +129 -152
- package/dist/services/deliveryAdmission.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/services/worktreeRegistry.d.ts +27 -119
- package/dist/services/worktreeRegistry.js +765 -1182
- package/dist/services/worktreeRegistry.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +354 -350
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +305 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +463 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.js +84 -76
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.js +15 -18
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -19
- package/dist/verification.js +1020 -1929
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.js +24 -10
- package/dist/version.js.map +7 -1
- package/dist/worktree.d.ts +3 -15
- package/dist/worktree.js +97 -177
- package/dist/worktree.js.map +7 -1
- package/package.json +10 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
- package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3058
- package/dist/setup.test.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
|
@@ -1,1497 +1,2036 @@
|
|
|
1
|
-
import assert from
|
|
2
|
-
import { createHash } from
|
|
3
|
-
import { EventEmitter } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
home: "",
|
|
32
|
+
commands: [],
|
|
33
|
+
commandArguments: [],
|
|
34
|
+
realCommands: false,
|
|
35
|
+
responses: [],
|
|
36
|
+
respond: void 0,
|
|
37
|
+
packArchive: ""
|
|
21
38
|
}));
|
|
22
|
-
vi.mock(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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(
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
vi.mock("node:os", async (original) => ({
|
|
85
|
+
...await original(),
|
|
86
|
+
homedir: () => fixture.home
|
|
64
87
|
}));
|
|
65
|
-
const { managePlugin } = await import(
|
|
66
|
-
test(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
144
|
-
assert.
|
|
145
|
-
assert.
|
|
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.
|
|
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(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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([
|
|
223
|
-
|
|
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 ===
|
|
226
|
-
execFileSync(
|
|
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(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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,
|
|
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(
|
|
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,
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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 =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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 =
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
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
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
581
|
+
"--globalconfig",
|
|
426
582
|
globalConfiguration,
|
|
427
|
-
|
|
428
|
-
fixture.home
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
},
|
|
466
|
-
|
|
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:
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
])(
|
|
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:
|
|
553
|
-
assert.equal(result.version,
|
|
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(
|
|
556
|
-
|
|
557
|
-
|
|
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:
|
|
725
|
+
await managePlugin({ ...input(), action: "install", version: "0.3.22" });
|
|
560
726
|
assert.deepEqual(policy, before);
|
|
561
|
-
assert.equal(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
])(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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([
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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 = [
|
|
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(
|
|
635
|
-
|
|
636
|
-
|
|
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
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
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([
|
|
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:
|
|
683
|
-
assert.equal(result.version,
|
|
684
|
-
assert.equal(
|
|
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(
|
|
688
|
-
|
|
689
|
-
|
|
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:
|
|
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
|
-
|
|
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 = [
|
|
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(
|
|
701
|
-
|
|
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,
|
|
705
|
-
}
|
|
706
|
-
|
|
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:
|
|
710
|
-
const interrupted = JSON.parse(readFileSync(join(dirname(catalog),
|
|
711
|
-
interrupted.pending.owner = { pid:
|
|
712
|
-
writeState(interrupted,
|
|
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:
|
|
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
|
-
|
|
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:
|
|
722
|
-
const interrupted = JSON.parse(readFileSync(join(dirname(catalog),
|
|
723
|
-
interrupted.pending.owner = { pid:
|
|
724
|
-
writeState(interrupted,
|
|
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(
|
|
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(
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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(
|
|
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(
|
|
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),
|
|
752
|
-
const interrupted = JSON.parse(readFileSync(path,
|
|
753
|
-
assert.equal(interrupted.currentVersion,
|
|
754
|
-
assert.equal(interrupted.pending.targetVersion,
|
|
755
|
-
interrupted.pending.owner = { pid:
|
|
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:
|
|
759
|
-
assert.equal(result.version,
|
|
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,
|
|
763
|
-
assert.equal(finished.currentVersion,
|
|
764
|
-
assert.equal(finished.previousVersion,
|
|
765
|
-
assert.equal(finished.pending,
|
|
766
|
-
}
|
|
767
|
-
|
|
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:
|
|
771
|
-
const path = join(dirname(catalog),
|
|
772
|
-
const interrupted = JSON.parse(readFileSync(path,
|
|
773
|
-
interrupted.pending.owner = { pid:
|
|
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:
|
|
998
|
+
await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }), /ambiguous/u);
|
|
777
999
|
assert.equal(native.selectionCalls, 1);
|
|
778
|
-
assert.equal(
|
|
779
|
-
|
|
780
|
-
|
|
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:
|
|
784
|
-
const statePath = join(dirname(catalog),
|
|
785
|
-
const pending = JSON.parse(readFileSync(statePath,
|
|
786
|
-
pending.pending.owner = { pid:
|
|
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,
|
|
789
|
-
writeFileSync(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:
|
|
1020
|
+
await assert.rejects(managePlugin({ ...input(), action: "update", version: "0.3.22" }));
|
|
792
1021
|
assert.equal(native.selectionCalls, 1);
|
|
793
|
-
assert.equal(readFileSync(archive,
|
|
794
|
-
assert.ok(JSON.parse(readFileSync(statePath,
|
|
795
|
-
}
|
|
796
|
-
|
|
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:
|
|
799
|
-
assert.equal(existsSync(join(fixture.home,
|
|
800
|
-
assert.equal(existsSync(join(catalog,
|
|
801
|
-
policy.later = { sentinel:
|
|
802
|
-
const rolled = await managePlugin({ ...input(), action:
|
|
803
|
-
assert.equal(rolled.version,
|
|
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:
|
|
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(
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
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),
|
|
825
|
-
const initial = JSON.parse(readFileSync(path,
|
|
826
|
-
initial.previousVersion =
|
|
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
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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:
|
|
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,
|
|
843
|
-
}
|
|
844
|
-
|
|
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:
|
|
847
|
-
const statePath = join(dirname(first.catalog),
|
|
848
|
-
const uninterrupted = JSON.parse(readFileSync(statePath,
|
|
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,
|
|
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,
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
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(
|
|
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(
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
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:
|
|
870
|
-
assert.deepEqual(JSON.parse(readFileSync(statePath,
|
|
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(
|
|
1125
|
+
assert.equal(fixture.commands.includes("npm"), false);
|
|
873
1126
|
assert.equal(native.selectionCalls, 1);
|
|
874
1127
|
assert.deepEqual(policy, before);
|
|
875
|
-
}
|
|
876
|
-
|
|
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,
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
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(
|
|
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),
|
|
888
|
-
const pending = JSON.parse(readFileSync(path,
|
|
889
|
-
pending.pending.owner = { pid:
|
|
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:
|
|
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,
|
|
895
|
-
}
|
|
896
|
-
|
|
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),
|
|
1162
|
+
const path = join(dirname(catalog), "state.json");
|
|
900
1163
|
let changed;
|
|
901
1164
|
fixture.respond = (args) => {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
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
|
-
|
|
1173
|
+
changed = readFileSync(path);
|
|
1174
|
+
}
|
|
1175
|
+
return output;
|
|
914
1176
|
};
|
|
915
|
-
await assert.rejects(managePlugin({ ...input(), action:
|
|
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 ===
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
test(
|
|
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,
|
|
1190
|
+
const path = join(catalog, ".agents/plugins/marketplace.json");
|
|
926
1191
|
fixture.respond = (args) => {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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:
|
|
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 &
|
|
1198
|
+
assert.equal(lstatSync(path).mode & 511, 420);
|
|
935
1199
|
assert.deepEqual(policy, before);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
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
|
-
|
|
973
|
-
|
|
974
|
-
|
|
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
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
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
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
test(
|
|
1005
|
-
|
|
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 ===
|
|
1288
|
+
assert.ok(typeof add === "function");
|
|
1008
1289
|
fixture.responses[5] = (args) => {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
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:
|
|
1014
|
-
const state = JSON.parse(readFileSync(join(dirname(catalog),
|
|
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,
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
|
|
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:
|
|
1023
|
-
const statePath = join(dirname(catalog),
|
|
1024
|
-
const state = JSON.parse(readFileSync(statePath,
|
|
1025
|
-
state.pending.owner = { pid:
|
|
1026
|
-
writeFileSync(statePath, JSON.stringify(state), { mode:
|
|
1027
|
-
const before = readFileSync(join(cache,
|
|
1028
|
-
fixture.responses.push(
|
|
1029
|
-
const result = await managePlugin({ ...input(), version:
|
|
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,
|
|
1032
|
-
assert.equal(JSON.parse(readFileSync(statePath,
|
|
1033
|
-
assert.deepEqual(readFileSync(join(cache,
|
|
1034
|
-
assert.equal(fixture.commands.filter((command) => command ===
|
|
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(
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
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(
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
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(
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
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(
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
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(
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
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(
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
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(
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
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(
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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(
|
|
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(
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
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(
|
|
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(
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
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(
|
|
1213
|
-
const root = join(fixture.home,
|
|
1550
|
+
fixture.responses.unshift("codex-cli 0.162.1");
|
|
1551
|
+
const root = join(fixture.home, "unsupported/package");
|
|
1214
1552
|
const files = {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
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
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
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,
|
|
1231
|
-
const globalConfiguration = join(fixture.home,
|
|
1232
|
-
writeFileSync(configuration,
|
|
1233
|
-
writeFileSync(globalConfiguration,
|
|
1234
|
-
const packed = JSON.parse(
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
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(
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
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,
|
|
1257
|
-
assert.equal(
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
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 ===
|
|
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(
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
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(
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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,
|
|
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(
|
|
1292
|
-
|
|
1293
|
-
|
|
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(
|
|
1296
|
-
|
|
1655
|
+
const cli = spawn(
|
|
1656
|
+
process.execPath,
|
|
1657
|
+
[
|
|
1658
|
+
"--import",
|
|
1297
1659
|
preload,
|
|
1298
|
-
join(dirname(fileURLToPath(import.meta.url)),
|
|
1299
|
-
|
|
1660
|
+
join(dirname(fileURLToPath(import.meta.url)), "cli.js"),
|
|
1661
|
+
"--repo-root",
|
|
1300
1662
|
fixture.home,
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
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
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
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
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
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
|
-
|
|
1723
|
+
}
|
|
1724
|
+
);
|
|
1725
|
+
const input = () => ({ action: "install", host: "codex", scope: "user", version: "0.3.21", repoRoot: fixture.home });
|
|
1357
1726
|
function fixturePreload() {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
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(
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
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
|
-
|
|
1745
|
+
"--repo-root",
|
|
1369
1746
|
fixture.home,
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
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,
|
|
1382
|
-
assert.equal(value.version,
|
|
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,
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
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
|
-
|
|
1777
|
+
"--repo-root",
|
|
1393
1778
|
fixture.home,
|
|
1394
1779
|
...prefix,
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
...suffix
|
|
1400
|
-
|
|
1401
|
-
|
|
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([
|
|
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,
|
|
1408
|
-
assert.equal(value.authProbe.reason,
|
|
1409
|
-
assert.equal(value.authProbe.repositoryAccess.repository,
|
|
1410
|
-
const defaultDoctor = invoke([], [
|
|
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,
|
|
1413
|
-
assert.ok(!existsSync(join(fixture.home,
|
|
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(
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
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(
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
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(
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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(
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
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(
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
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(
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
},
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
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
|