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