@aviaratech/ai-delivery 0.3.29 → 0.3.31
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/README.md +43 -4
- package/dist/cli.js +11 -6
- package/dist/cli.js.map +1 -1
- package/dist/cliResult.d.ts +1 -0
- package/dist/cliResult.js +8 -0
- package/dist/cliResult.js.map +1 -1
- package/dist/cliResult.test.js +176 -0
- package/dist/cliResult.test.js.map +1 -1
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +52 -0
- package/dist/errors.js.map +1 -1
- package/dist/github/client.d.ts +5 -0
- package/dist/github/client.js +142 -6
- package/dist/github/client.js.map +1 -1
- package/dist/github/machineAuth.test.js +284 -1
- package/dist/github/machineAuth.test.js.map +1 -1
- package/dist/issue.d.ts +2 -0
- package/dist/issue.js +2 -0
- package/dist/issue.js.map +1 -1
- package/dist/issueInfoReadback.test.d.ts +1 -0
- package/dist/issueInfoReadback.test.js +203 -0
- package/dist/issueInfoReadback.test.js.map +1 -0
- package/dist/lifecycle.test.js +72 -6
- package/dist/lifecycle.test.js.map +1 -1
- package/dist/pluginAuthProbe.test.js +25 -0
- package/dist/pluginAuthProbe.test.js.map +1 -1
- package/dist/pluginDoctor.test.js +21 -3
- package/dist/pluginDoctor.test.js.map +1 -1
- package/dist/pluginInstaller.d.ts +22 -0
- package/dist/pluginInstaller.js +378 -57
- package/dist/pluginInstaller.js.map +1 -1
- package/dist/pluginInstaller.test.js +745 -31
- package/dist/pluginInstaller.test.js.map +1 -1
- package/dist/pr.d.ts +1 -1
- package/dist/pr.js +85 -27
- package/dist/pr.js.map +1 -1
- package/dist/pr.test.js +223 -5
- package/dist/pr.test.js.map +1 -1
- package/dist/prAssociation.test.js +509 -2
- package/dist/prAssociation.test.js.map +1 -1
- package/dist/review.js +11 -0
- package/dist/review.js.map +1 -1
- package/dist/review.test.js +38 -0
- package/dist/review.test.js.map +1 -1
- package/dist/setup.test.js +489 -4
- package/dist/setup.test.js.map +1 -1
- package/dist/targetPolicyLocal.test.js +574 -167
- package/dist/targetPolicyLocal.test.js.map +1 -1
- package/package.json +1 -1
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +7 -1
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/cli.js +57 -57
- package/plugins/ai-delivery/runtime/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
|
-
import { existsSync, cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
4
|
+
import { existsSync, chmodSync, cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
5
5
|
import { execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
6
6
|
import { tmpdir } from 'node:os';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
@@ -16,6 +16,7 @@ const fixture = vi.hoisted(() => ({
|
|
|
16
16
|
commandArguments: [],
|
|
17
17
|
realCommands: false,
|
|
18
18
|
responses: [],
|
|
19
|
+
respond: undefined,
|
|
19
20
|
packArchive: '',
|
|
20
21
|
}));
|
|
21
22
|
vi.mock('node:child_process', async (original) => {
|
|
@@ -35,7 +36,7 @@ vi.mock('node:child_process', async (original) => {
|
|
|
35
36
|
stderr: new PassThrough(),
|
|
36
37
|
kill: () => true,
|
|
37
38
|
});
|
|
38
|
-
const queued = fixture.responses.shift();
|
|
39
|
+
const queued = fixture.responses.shift() ?? fixture.respond;
|
|
39
40
|
let response = typeof queued === 'function' ? queued(commandArguments) : queued;
|
|
40
41
|
if (binary === '/bin/sh' && args?.[3] === 'npm' && fixture.packArchive) {
|
|
41
42
|
const destination = args[args.indexOf('--pack-destination') + 1];
|
|
@@ -62,6 +63,191 @@ vi.mock('node:os', async (original) => ({
|
|
|
62
63
|
homedir: () => fixture.home,
|
|
63
64
|
}));
|
|
64
65
|
const { managePlugin } = await import('./pluginInstaller.js');
|
|
66
|
+
test('preview observes a Codex registration candidate without executing or changing its settings', async () => {
|
|
67
|
+
const profile = join(fixture.home, '.codex');
|
|
68
|
+
mkdirSync(profile);
|
|
69
|
+
const config = join(profile, 'config.toml');
|
|
70
|
+
const bytes = '[mcp_servers."ai-delivery"]\ncommand = "unknown-launcher"\nsecret = "fictional-private-value"\n';
|
|
71
|
+
writeFileSync(config, bytes);
|
|
72
|
+
const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
|
|
73
|
+
const report = Reflect.get(result, 'diagnostics');
|
|
74
|
+
assert.ok(report);
|
|
75
|
+
assert.equal(report.migration, 'refused');
|
|
76
|
+
assert.equal(report.completeness, 'incomplete');
|
|
77
|
+
assert.deepEqual(report.registrations, [
|
|
78
|
+
{ kind: 'standalone', scope: 'user', ownership: 'unknown', source: 'unknown', version: null, enabled: null },
|
|
79
|
+
]);
|
|
80
|
+
assert.equal(JSON.stringify(result).includes('fictional-private-value'), false);
|
|
81
|
+
assert.equal(JSON.stringify(result).includes('unknown-launcher'), false);
|
|
82
|
+
assert.equal(readFileSync(config, 'utf8'), bytes);
|
|
83
|
+
assert.deepEqual(fixture.commands, []);
|
|
84
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
85
|
+
});
|
|
86
|
+
test('preview preserves Claude local/project/user registrations and permission preferences', async () => {
|
|
87
|
+
vi.stubEnv('CLAUDE_CONFIG_DIR', '');
|
|
88
|
+
const user = join(fixture.home, '.claude.json');
|
|
89
|
+
const project = join(fixture.home, '.mcp.json');
|
|
90
|
+
const settings = join(fixture.home, '.claude', 'settings.json');
|
|
91
|
+
mkdirSync(dirname(settings));
|
|
92
|
+
writeFileSync(user, JSON.stringify({
|
|
93
|
+
mcpServers: { 'ai-delivery': { command: 'unknown-user' } },
|
|
94
|
+
projects: {
|
|
95
|
+
[fixture.home]: { mcpServers: { 'ai-delivery': { command: 'unknown-local' } } },
|
|
96
|
+
},
|
|
97
|
+
}));
|
|
98
|
+
writeFileSync(project, JSON.stringify({ mcpServers: { 'ai-delivery': { command: 'unknown-project' } } }));
|
|
99
|
+
writeFileSync(settings, JSON.stringify({ permissions: { allow: ['mcp__ai-delivery__issue_info'] } }));
|
|
100
|
+
const before = [user, project, settings].map((path) => readFileSync(path));
|
|
101
|
+
const result = await managePlugin({ action: 'preview', host: 'claude-code', scope: 'user', repoRoot: fixture.home });
|
|
102
|
+
assert.ok(result.diagnostics);
|
|
103
|
+
assert.deepEqual(result.diagnostics.registrations.map((entry) => entry.scope), ['local', 'project', 'user']);
|
|
104
|
+
assert.equal(result.diagnostics.migration, 'refused');
|
|
105
|
+
assert.deepEqual([user, project, settings].map((path) => readFileSync(path)), before);
|
|
106
|
+
assert.deepEqual(fixture.commands, []);
|
|
107
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
108
|
+
});
|
|
109
|
+
test('doctor reports an external native marketplace plugin without adopting or starting it', async () => {
|
|
110
|
+
fixture.responses.push(JSON.stringify({
|
|
111
|
+
installed: [
|
|
112
|
+
{
|
|
113
|
+
pluginId: 'ai-delivery@external-market',
|
|
114
|
+
name: 'ai-delivery',
|
|
115
|
+
marketplaceName: 'external-market',
|
|
116
|
+
version: '0.3.24',
|
|
117
|
+
enabled: true,
|
|
118
|
+
source: { source: 'git', url: 'https://example.test/unknown' },
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
available: [],
|
|
122
|
+
}));
|
|
123
|
+
const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
|
|
124
|
+
assert.equal(result.installed, false);
|
|
125
|
+
assert.ok(result.diagnostics);
|
|
126
|
+
assert.ok(result.activation);
|
|
127
|
+
assert.deepEqual(result.diagnostics.registrations, [
|
|
128
|
+
{ kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
|
|
129
|
+
]);
|
|
130
|
+
assert.equal(result.activation.loadedVersion, null);
|
|
131
|
+
assert.equal(result.sourceIntegrity, undefined);
|
|
132
|
+
assert.equal(result.mcp, undefined);
|
|
133
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
134
|
+
});
|
|
135
|
+
test('preview refuses incomplete oversized configuration without writes or native calls', async () => {
|
|
136
|
+
const profile = join(fixture.home, '.codex');
|
|
137
|
+
mkdirSync(profile);
|
|
138
|
+
const config = join(profile, 'config.toml');
|
|
139
|
+
const bytes = '#'.repeat(1024 * 1024 + 1);
|
|
140
|
+
writeFileSync(config, bytes);
|
|
141
|
+
const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
|
|
142
|
+
assert.ok(result.diagnostics);
|
|
143
|
+
assert.equal(result.diagnostics.migration, 'refused');
|
|
144
|
+
assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
|
|
145
|
+
assert.equal(readFileSync(config, 'utf8'), bytes);
|
|
146
|
+
assert.deepEqual(fixture.commands, []);
|
|
147
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
148
|
+
});
|
|
149
|
+
test('doctor retains distinct external marketplace observations with identical reported versions', async () => {
|
|
150
|
+
doctorFixture(false);
|
|
151
|
+
const selected = JSON.parse(fixture.responses[0])
|
|
152
|
+
.installed[0];
|
|
153
|
+
fixture.responses.push(JSON.stringify({
|
|
154
|
+
installed: [
|
|
155
|
+
selected,
|
|
156
|
+
{ pluginId: 'ai-delivery@external-one', version: '0.3.24', enabled: true },
|
|
157
|
+
{ pluginId: 'ai-delivery@external-two', version: '0.3.24', enabled: true },
|
|
158
|
+
],
|
|
159
|
+
available: [],
|
|
160
|
+
}));
|
|
161
|
+
const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
|
|
162
|
+
assert.ok(result.diagnostics);
|
|
163
|
+
assert.equal(result.diagnostics.registrations.filter((entry) => entry.ownership === 'external').length, 2);
|
|
164
|
+
assert.equal(result.diagnostics.nativeInventory, 'observed');
|
|
165
|
+
});
|
|
166
|
+
test('doctor observes external installations after retained managed removal without adopting them', async () => {
|
|
167
|
+
mkdirSync(join(fixture.home, '.codex'));
|
|
168
|
+
const statePath = writeState({ ...pendingState('remove', null), pending: undefined });
|
|
169
|
+
const before = readFileSync(statePath);
|
|
170
|
+
fixture.responses.push(JSON.stringify({
|
|
171
|
+
installed: [{ pluginId: 'ai-delivery@external-market', version: '0.3.24', enabled: true }],
|
|
172
|
+
available: [],
|
|
173
|
+
}));
|
|
174
|
+
const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
|
|
175
|
+
assert.ok(result.diagnostics);
|
|
176
|
+
assert.deepEqual(result.diagnostics.registrations, [
|
|
177
|
+
{ kind: 'plugin', scope: 'user', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: true },
|
|
178
|
+
]);
|
|
179
|
+
assert.equal(result.installed, false);
|
|
180
|
+
assert.equal(result.sourceIntegrity, undefined);
|
|
181
|
+
assert.equal(result.mcp, undefined);
|
|
182
|
+
assert.deepEqual(result.activation, { installedVersion: null, startupVersion: null, loadedVersion: null });
|
|
183
|
+
assert.deepEqual(readFileSync(statePath), before);
|
|
184
|
+
assert.deepEqual(fixture.commandArguments, [['codex', 'plugin', 'list', '--json']]);
|
|
185
|
+
});
|
|
186
|
+
test('compiled preview never invokes native tools or creates installer state', () => {
|
|
187
|
+
const profile = join(fixture.home, '.codex');
|
|
188
|
+
const bin = join(fixture.home, 'bin');
|
|
189
|
+
const marker = join(fixture.home, 'native-called');
|
|
190
|
+
mkdirSync(profile);
|
|
191
|
+
mkdirSync(bin);
|
|
192
|
+
writeFileSync(join(bin, 'codex'), `#!/bin/sh\nprintf called > '${marker}'\n`, { mode: 0o755 });
|
|
193
|
+
writeFileSync(join(profile, 'config.toml'), '[mcp_servers.ai-delivery]\ncommand="untrusted"\n');
|
|
194
|
+
const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
195
|
+
const stdout = execFileSync(process.execPath, [cli, 'plugin', 'preview', '--host', 'codex', '--json'], {
|
|
196
|
+
cwd: fixture.home,
|
|
197
|
+
env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile, PATH: bin },
|
|
198
|
+
encoding: 'utf8',
|
|
199
|
+
});
|
|
200
|
+
const result = JSON.parse(stdout);
|
|
201
|
+
assert.ok(result.diagnostics);
|
|
202
|
+
assert.equal(result.action, 'preview');
|
|
203
|
+
assert.equal(result.diagnostics.migration, 'refused');
|
|
204
|
+
assert.deepEqual(result.diagnostics.plannedChanges, []);
|
|
205
|
+
assert.equal(existsSync(marker), false);
|
|
206
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
207
|
+
});
|
|
208
|
+
test('preview refuses a symlinked configuration without following its target', async () => {
|
|
209
|
+
const profile = join(fixture.home, '.codex');
|
|
210
|
+
const target = join(fixture.home, 'protected.pem');
|
|
211
|
+
mkdirSync(profile);
|
|
212
|
+
writeFileSync(target, '[mcp_servers.ai-delivery]\nsecret="fictional-sensitive-content"\n');
|
|
213
|
+
symlinkSync(target, join(profile, 'config.toml'));
|
|
214
|
+
const result = await managePlugin({ ...input(), action: 'preview', version: undefined });
|
|
215
|
+
assert.ok(result.diagnostics);
|
|
216
|
+
assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
|
|
217
|
+
assert.deepEqual(result.diagnostics.registrations, []);
|
|
218
|
+
assert.equal(JSON.stringify(result).includes('fictional-sensitive-content'), false);
|
|
219
|
+
assert.deepEqual(fixture.commands, []);
|
|
220
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
221
|
+
});
|
|
222
|
+
test.each(['codex', 'claude-code'])('preview refuses a FIFO configuration without blocking in %s', (host) => {
|
|
223
|
+
const profile = join(fixture.home, '.codex');
|
|
224
|
+
mkdirSync(profile);
|
|
225
|
+
const config = host === 'codex' ? join(profile, 'config.toml') : join(fixture.home, '.mcp.json');
|
|
226
|
+
execFileSync('/usr/bin/mkfifo', [config]);
|
|
227
|
+
const metadata = lstatSync(config);
|
|
228
|
+
const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
|
|
229
|
+
// Bound only the known FIFO-open stall and reap this test-owned child.
|
|
230
|
+
const child = spawnSync(process.execPath, [cli, 'plugin', 'preview', '--host', host, '--json'], {
|
|
231
|
+
cwd: fixture.home,
|
|
232
|
+
env: { ...process.env, HOME: fixture.home, CODEX_HOME: profile },
|
|
233
|
+
encoding: 'utf8',
|
|
234
|
+
timeout: 3000,
|
|
235
|
+
killSignal: 'SIGKILL',
|
|
236
|
+
});
|
|
237
|
+
assert.equal(child.error, undefined);
|
|
238
|
+
assert.equal(child.status, 0);
|
|
239
|
+
const result = JSON.parse(child.stdout);
|
|
240
|
+
assert.ok(result.diagnostics);
|
|
241
|
+
assert.ok(result.diagnostics.findings.includes('configuration_unavailable'));
|
|
242
|
+
assert.deepEqual(result.diagnostics.registrations, []);
|
|
243
|
+
assert.equal(lstatSync(config).ino, metadata.ino);
|
|
244
|
+
assert.equal(existsSync(join(fixture.home, '.cache')), false);
|
|
245
|
+
});
|
|
246
|
+
test.each(['migrate', 'apply', 'retire', 'restore-settings'])('unsupported %s never enables host mutation', async (action) => {
|
|
247
|
+
await assert.rejects(managePlugin({ ...input(), action, version: undefined }));
|
|
248
|
+
assert.deepEqual(fixture.commands, []);
|
|
249
|
+
assert.deepEqual(readdirSync(fixture.home), []);
|
|
250
|
+
});
|
|
65
251
|
beforeEach(() => {
|
|
66
252
|
fixture.home = mkdtempSync(join(tmpdir(), 'ai-delivery-installer-'));
|
|
67
253
|
vi.stubEnv('CODEX_HOME', join(fixture.home, '.codex'));
|
|
@@ -70,6 +256,7 @@ beforeEach(() => {
|
|
|
70
256
|
fixture.commandArguments = [];
|
|
71
257
|
fixture.realCommands = false;
|
|
72
258
|
fixture.responses = [];
|
|
259
|
+
fixture.respond = undefined;
|
|
73
260
|
fixture.packArchive = '';
|
|
74
261
|
});
|
|
75
262
|
afterEach(() => {
|
|
@@ -78,9 +265,11 @@ afterEach(() => {
|
|
|
78
265
|
rmSync(fixture.home, { recursive: true, force: true });
|
|
79
266
|
for (const args of fixture.commandArguments)
|
|
80
267
|
if (args[1] === 'plugin' && args[2] === 'list')
|
|
81
|
-
assert.deepEqual(args, args[0] === 'codex'
|
|
268
|
+
assert.deepEqual(args, args[0] === 'codex' && args.includes('--marketplace')
|
|
82
269
|
? ['codex', 'plugin', 'list', '--marketplace', 'ai-delivery-user', '--available', '--json']
|
|
83
|
-
: [
|
|
270
|
+
: args[0] === 'codex'
|
|
271
|
+
? ['codex', 'plugin', 'list', '--json']
|
|
272
|
+
: ['claude', 'plugin', 'list', '--json']);
|
|
84
273
|
});
|
|
85
274
|
function pendingState(action, version) {
|
|
86
275
|
return {
|
|
@@ -137,6 +326,35 @@ function doctorFixture(enabled, host = 'codex') {
|
|
|
137
326
|
currentVersion: version,
|
|
138
327
|
installedPath: cache,
|
|
139
328
|
}, host);
|
|
329
|
+
for (const [relative, content] of [
|
|
330
|
+
[
|
|
331
|
+
'.agents/plugins/marketplace.json',
|
|
332
|
+
{
|
|
333
|
+
name: 'ai-delivery-user',
|
|
334
|
+
interface: { displayName: 'ai-delivery' },
|
|
335
|
+
plugins: [
|
|
336
|
+
{
|
|
337
|
+
name: 'ai-delivery',
|
|
338
|
+
source: { source: 'local', path: `./versions/${version}/plugins/ai-delivery` },
|
|
339
|
+
policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' },
|
|
340
|
+
category: 'Productivity',
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
[
|
|
346
|
+
'.claude-plugin/marketplace.json',
|
|
347
|
+
{
|
|
348
|
+
name: 'ai-delivery-user',
|
|
349
|
+
owner: { name: 'AviaraTech' },
|
|
350
|
+
plugins: [{ name: 'ai-delivery', source: `./versions/${version}/plugins/ai-delivery`, version }],
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
]) {
|
|
354
|
+
const path = join(catalog, relative);
|
|
355
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
356
|
+
writeFileSync(path, JSON.stringify(content), { mode: 0o600 });
|
|
357
|
+
}
|
|
140
358
|
if (host === 'codex') {
|
|
141
359
|
fixture.responses.push(JSON.stringify({
|
|
142
360
|
installed: [
|
|
@@ -158,12 +376,6 @@ function doctorFixture(enabled, host = 'codex') {
|
|
|
158
376
|
writeFileSync(path, JSON.stringify({
|
|
159
377
|
'ai-delivery-user': { source: { source: 'directory', path: catalog }, installLocation: catalog },
|
|
160
378
|
}), { mode: 0o600 });
|
|
161
|
-
const published = join(catalog, '.claude-plugin/marketplace.json');
|
|
162
|
-
mkdirSync(dirname(published), { recursive: true, mode: 0o700 });
|
|
163
|
-
writeFileSync(published, JSON.stringify({
|
|
164
|
-
name: 'ai-delivery-user',
|
|
165
|
-
plugins: [{ name: 'ai-delivery', version, source: `./versions/${version}/plugins/ai-delivery` }],
|
|
166
|
-
}), { mode: 0o600 });
|
|
167
379
|
fixture.responses.push(JSON.stringify([
|
|
168
380
|
{
|
|
169
381
|
id: 'ai-delivery@ai-delivery-user',
|
|
@@ -245,7 +457,7 @@ function installationFixture(action, readback = (entry) => [entry]) {
|
|
|
245
457
|
source: { source: 'local', path: source },
|
|
246
458
|
marketplaceSource: { sourceType: 'local', source: catalog },
|
|
247
459
|
};
|
|
248
|
-
fixture.responses.push('codex-cli 0.
|
|
460
|
+
fixture.responses.push('codex-cli 0.162.1', oversizedCatalogue(previous), '', '0.3.22', ...(action === 'install' ? ['{}'] : []), (args) => {
|
|
249
461
|
assert.deepEqual(args, ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
|
|
250
462
|
mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
|
|
251
463
|
cpSync(source, cache, { recursive: true });
|
|
@@ -253,6 +465,475 @@ function installationFixture(action, readback = (entry) => [entry]) {
|
|
|
253
465
|
}, oversizedCatalogue(readback(entry)));
|
|
254
466
|
return { entry, cache, catalog, source };
|
|
255
467
|
}
|
|
468
|
+
function replacementFixture(preferences = { issue_info: { approval: 'fictional-explicit-allow' } }) {
|
|
469
|
+
const { entry, cache, catalog } = installationFixture('update');
|
|
470
|
+
fixture.responses = [];
|
|
471
|
+
const selector = 'ai-delivery@ai-delivery-user';
|
|
472
|
+
const policy = {
|
|
473
|
+
[selector]: { enabled: true, preferences },
|
|
474
|
+
'private-unrelated@other': { sentinel: 'fictional-private-value', enabled: false },
|
|
475
|
+
};
|
|
476
|
+
const before = structuredClone(policy);
|
|
477
|
+
const native = {
|
|
478
|
+
selected: [
|
|
479
|
+
{
|
|
480
|
+
...entry,
|
|
481
|
+
version: '0.3.21',
|
|
482
|
+
source: { source: 'local', path: join(catalog, 'versions/0.3.21/plugins/ai-delivery') },
|
|
483
|
+
},
|
|
484
|
+
],
|
|
485
|
+
version: 'codex-cli 0.162.1',
|
|
486
|
+
selectionCalls: 0,
|
|
487
|
+
loseAck: false,
|
|
488
|
+
failSelection: false,
|
|
489
|
+
};
|
|
490
|
+
fixture.respond = (args) => {
|
|
491
|
+
if (args[0] === 'npm')
|
|
492
|
+
return '';
|
|
493
|
+
if (args[0] === process.execPath)
|
|
494
|
+
return '0.3.22';
|
|
495
|
+
if (args[1] === '--version')
|
|
496
|
+
return native.version;
|
|
497
|
+
if (args[2] === 'list') {
|
|
498
|
+
let offeredPath;
|
|
499
|
+
try {
|
|
500
|
+
const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
|
|
501
|
+
offeredPath = offered.plugins[0].source.path;
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
return undefined;
|
|
505
|
+
}
|
|
506
|
+
// Pinned list takes installed version from cache and source from the current catalog.
|
|
507
|
+
return JSON.stringify({
|
|
508
|
+
installed: native.selected.map((plugin) => ({
|
|
509
|
+
...plugin,
|
|
510
|
+
source: { source: 'local', path: join(catalog, offeredPath) },
|
|
511
|
+
})),
|
|
512
|
+
available: [],
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (args[2] === 'marketplace')
|
|
516
|
+
return '{}';
|
|
517
|
+
if (args[2] === 'remove') {
|
|
518
|
+
// Pinned Codex remove clears the complete qualified plugin table.
|
|
519
|
+
delete policy[selector];
|
|
520
|
+
native.selected = [];
|
|
521
|
+
return '{}';
|
|
522
|
+
}
|
|
523
|
+
if (args[2] === 'add') {
|
|
524
|
+
assert.deepEqual(args, ['codex', 'plugin', 'add', selector, '--json']);
|
|
525
|
+
native.selectionCalls++;
|
|
526
|
+
if (native.failSelection)
|
|
527
|
+
return undefined;
|
|
528
|
+
// Pinned add retains existing fields but can evict older native caches.
|
|
529
|
+
policy[selector] = { ...policy[selector], enabled: true };
|
|
530
|
+
const offered = JSON.parse(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'));
|
|
531
|
+
const offeredPath = offered.plugins[0].source.path;
|
|
532
|
+
const version = /^\.\/versions\/([^/]+)\/plugins\/ai-delivery$/u.exec(offeredPath)[1];
|
|
533
|
+
const selectedCache = join(dirname(cache), version);
|
|
534
|
+
mkdirSync(dirname(selectedCache), { recursive: true, mode: 0o700 });
|
|
535
|
+
cpSync(join(catalog, offeredPath), selectedCache, { recursive: true });
|
|
536
|
+
for (const old of readdirSync(dirname(cache)))
|
|
537
|
+
if (old !== version)
|
|
538
|
+
rmSync(join(dirname(cache), old), { recursive: true });
|
|
539
|
+
native.selected = [{ ...entry, version, source: { source: 'local', path: join(catalog, offeredPath) } }];
|
|
540
|
+
return native.loseAck ? undefined : JSON.stringify({ installedPath: selectedCache });
|
|
541
|
+
}
|
|
542
|
+
return undefined;
|
|
543
|
+
};
|
|
544
|
+
return { catalog, policy, before, native };
|
|
545
|
+
}
|
|
546
|
+
test.each([
|
|
547
|
+
{ issue_info: { approval: 'fictional-explicit-allow' }, unknown: { nested: ['retain', null] } },
|
|
548
|
+
{ unknown: { nested: ['retain', null] } },
|
|
549
|
+
{ issue_info: null, unknown: { nested: ['retain', null] } },
|
|
550
|
+
])('managed replacement preserves fictional tool preferences %j without clearing the plugin entry', async (preferences) => {
|
|
551
|
+
const { policy, before } = replacementFixture(preferences);
|
|
552
|
+
const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
553
|
+
assert.equal(result.version, '0.3.22');
|
|
554
|
+
assert.deepEqual(policy, before);
|
|
555
|
+
assert.equal(fixture.commandArguments.some((args) => ['remove', 'uninstall'].includes(args[2] ?? '')), false);
|
|
556
|
+
});
|
|
557
|
+
test('installing a different owned version cannot bypass the preserving replacement path', async () => {
|
|
558
|
+
const { policy, before } = replacementFixture();
|
|
559
|
+
await managePlugin({ ...input(), action: 'install', version: '0.3.22' });
|
|
560
|
+
assert.deepEqual(policy, before);
|
|
561
|
+
assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
|
|
562
|
+
});
|
|
563
|
+
test('an exact same-version owned selection is reused without invoking native add', async () => {
|
|
564
|
+
const { native } = replacementFixture();
|
|
565
|
+
const result = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
|
|
566
|
+
assert.equal(result.changed, false);
|
|
567
|
+
assert.equal(native.selectionCalls, 0);
|
|
568
|
+
});
|
|
569
|
+
test.each([
|
|
570
|
+
'disabled',
|
|
571
|
+
'missing selection',
|
|
572
|
+
'unregistered catalog',
|
|
573
|
+
'foreign source',
|
|
574
|
+
'changed cache',
|
|
575
|
+
'changed catalog',
|
|
576
|
+
'catalog symlink',
|
|
577
|
+
'read-only catalog',
|
|
578
|
+
'unqualified native',
|
|
579
|
+
'unqualified newer native',
|
|
580
|
+
])('replacement refuses %s before preparing a new version', async (fault) => {
|
|
581
|
+
const { native, catalog, policy, before } = replacementFixture();
|
|
582
|
+
if (fault === 'disabled')
|
|
583
|
+
native.selected[0].enabled = false;
|
|
584
|
+
if (fault === 'missing selection')
|
|
585
|
+
native.selected = [];
|
|
586
|
+
if (fault === 'unregistered catalog')
|
|
587
|
+
native.selected[0].marketplaceSource.source = join(fixture.home, 'foreign-marketplace');
|
|
588
|
+
if (fault === 'foreign source') {
|
|
589
|
+
const respond = fixture.respond;
|
|
590
|
+
fixture.respond = (args) => {
|
|
591
|
+
const output = respond(args);
|
|
592
|
+
if (args[2] !== 'list' || !output)
|
|
593
|
+
return output;
|
|
594
|
+
const listed = JSON.parse(output);
|
|
595
|
+
listed.installed[0].source.path = join(fixture.home, 'unowned');
|
|
596
|
+
return JSON.stringify(listed);
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
if (fault === 'changed cache')
|
|
600
|
+
writeFileSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21/skills/intake/SKILL.md'), 'changed');
|
|
601
|
+
if (fault === 'changed catalog')
|
|
602
|
+
writeFileSync(join(catalog, '.agents/plugins/marketplace.json'), '{}');
|
|
603
|
+
const unrelatedCatalog = join(fixture.home, 'unrelated-catalog');
|
|
604
|
+
if (fault === 'catalog symlink') {
|
|
605
|
+
writeFileSync(unrelatedCatalog, 'unrelated catalog sentinel');
|
|
606
|
+
rmSync(join(catalog, '.agents/plugins/marketplace.json'));
|
|
607
|
+
symlinkSync(unrelatedCatalog, join(catalog, '.agents/plugins/marketplace.json'));
|
|
608
|
+
}
|
|
609
|
+
if (fault === 'read-only catalog')
|
|
610
|
+
chmodSync(join(catalog, '.agents/plugins/marketplace.json'), 0o400);
|
|
611
|
+
if (fault === 'unqualified native')
|
|
612
|
+
native.version = 'codex-cli 0.153.0';
|
|
613
|
+
if (fault === 'unqualified newer native')
|
|
614
|
+
native.version = 'codex-cli 0.162.2';
|
|
615
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
|
|
616
|
+
assert.equal(native.selectionCalls, 0);
|
|
617
|
+
assert.equal(existsSync(join(catalog, 'versions/0.3.22')), false);
|
|
618
|
+
assert.deepEqual(policy, before);
|
|
619
|
+
if (fault === 'catalog symlink')
|
|
620
|
+
assert.equal(readFileSync(unrelatedCatalog, 'utf8'), 'unrelated catalog sentinel');
|
|
621
|
+
});
|
|
622
|
+
test.each(['update', 'install', 'rollback'])('Claude owned %s refuses an unqualified native version before catalog or selection changes', async (action) => {
|
|
623
|
+
doctorFixture(true, 'claude-code');
|
|
624
|
+
fixture.responses.unshift('2.1.295 (Claude Code)', '--keep-data');
|
|
625
|
+
const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
|
|
626
|
+
if (action === 'rollback') {
|
|
627
|
+
const path = join(dirname(catalog), 'state.json');
|
|
628
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
629
|
+
state.previousVersion = '0.3.20';
|
|
630
|
+
writeState(state, 'claude-code');
|
|
631
|
+
}
|
|
632
|
+
const paths = ['.agents/plugins/marketplace.json', '.claude-plugin/marketplace.json'].map((name) => join(catalog, name));
|
|
633
|
+
const before = paths.map((path) => readFileSync(path));
|
|
634
|
+
await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action, version: action === 'rollback' ? undefined : '0.3.22' }), /preserv.*unqualified/iu);
|
|
635
|
+
assert.deepEqual(paths.map((path) => readFileSync(path)), before);
|
|
636
|
+
assert.equal(fixture.commandArguments.some((args) => ['update', 'install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
|
|
637
|
+
});
|
|
638
|
+
function claudeReplacementFixture() {
|
|
639
|
+
doctorFixture(true, 'claude-code');
|
|
640
|
+
const initial = JSON.parse(fixture.responses.shift());
|
|
641
|
+
nativeArchiveFixture();
|
|
642
|
+
const catalog = join(fixture.home, '.cache/ai-delivery/plugins/claude-code/user/marketplace');
|
|
643
|
+
const settings = join(fixture.home, '.claude/settings.json');
|
|
644
|
+
const preferences = {
|
|
645
|
+
enabledPlugins: { 'ai-delivery@ai-delivery-user': true, 'unrelated@fictional': false },
|
|
646
|
+
permissions: { allow: ['mcp__fictional__read'], deny: ['mcp__fictional__write'] },
|
|
647
|
+
unknown: { nested: ['retain', null, { explicit: false }] },
|
|
648
|
+
};
|
|
649
|
+
writeFileSync(settings, JSON.stringify(preferences), { mode: 0o600 });
|
|
650
|
+
const before = readFileSync(settings);
|
|
651
|
+
const native = { selected: initial, updates: 0, loseAck: false, failSelection: false };
|
|
652
|
+
fixture.respond = (args) => {
|
|
653
|
+
if (args[0] === 'npm')
|
|
654
|
+
return '';
|
|
655
|
+
if (args[0] === process.execPath)
|
|
656
|
+
return '0.3.22';
|
|
657
|
+
if (args[1] === '--version')
|
|
658
|
+
return '2.1.296 (Claude Code)';
|
|
659
|
+
if (args[2] === 'uninstall' && args.includes('--help'))
|
|
660
|
+
return '--keep-data';
|
|
661
|
+
if (args[2] === 'list')
|
|
662
|
+
return JSON.stringify(native.selected);
|
|
663
|
+
if (args[2] === 'update') {
|
|
664
|
+
assert.deepEqual(args, ['claude', 'plugin', 'update', 'ai-delivery@ai-delivery-user', '--scope', 'user']);
|
|
665
|
+
native.updates++;
|
|
666
|
+
if (native.failSelection)
|
|
667
|
+
return undefined;
|
|
668
|
+
const offered = JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8'));
|
|
669
|
+
const { source, version } = offered.plugins[0];
|
|
670
|
+
const cache = join(fixture.home, '.claude/plugins/cache/ai-delivery-user/ai-delivery', version);
|
|
671
|
+
mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
|
|
672
|
+
cpSync(join(catalog, source), cache, { recursive: true });
|
|
673
|
+
native.selected = [{ ...initial[0], version, installPath: cache }];
|
|
674
|
+
return native.loseAck ? undefined : '{}';
|
|
675
|
+
}
|
|
676
|
+
return undefined;
|
|
677
|
+
};
|
|
678
|
+
return { catalog, settings, before, native };
|
|
679
|
+
}
|
|
680
|
+
test.each(['update', 'install'])('Claude owned forward %s preserves preferences through native update', async (action) => {
|
|
681
|
+
const { settings, before, native } = claudeReplacementFixture();
|
|
682
|
+
const result = await managePlugin({ ...input(), host: 'claude-code', action, version: '0.3.22' });
|
|
683
|
+
assert.equal(result.version, '0.3.22');
|
|
684
|
+
assert.equal(result.nativePluginRoot, join(fixture.home, '.claude/plugins/cache/ai-delivery-user/ai-delivery/0.3.22'));
|
|
685
|
+
assert.equal(native.updates, 1);
|
|
686
|
+
assert.deepEqual(readFileSync(settings), before);
|
|
687
|
+
assert.equal(fixture.commandArguments.some((args) => ['install', 'uninstall'].includes(args[2] ?? '') && !args.includes('--help')), false);
|
|
688
|
+
});
|
|
689
|
+
test('Claude same-version replacement reuses its verified cache without a native update', async () => {
|
|
690
|
+
const { settings, before, native } = claudeReplacementFixture();
|
|
691
|
+
const result = await managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.21' });
|
|
692
|
+
assert.equal(result.changed, false);
|
|
693
|
+
assert.equal(native.updates, 0);
|
|
694
|
+
assert.deepEqual(readFileSync(settings), before);
|
|
695
|
+
});
|
|
696
|
+
test.each(['0.3.20', '0.3.22-beta.1', '0.3.22+fixture'])('Claude refuses unqualified replacement target %s before publication', async (version) => {
|
|
697
|
+
const { catalog, native, settings, before } = claudeReplacementFixture();
|
|
698
|
+
const paths = ['.agents/plugins/marketplace.json', '.claude-plugin/marketplace.json'].map((name) => join(catalog, name));
|
|
699
|
+
const catalogs = paths.map((path) => readFileSync(path));
|
|
700
|
+
await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version }), /preserv.*unqualified/iu);
|
|
701
|
+
assert.deepEqual(paths.map((path) => readFileSync(path)), catalogs);
|
|
702
|
+
assert.deepEqual(readFileSync(settings), before);
|
|
703
|
+
assert.equal(native.updates, 0);
|
|
704
|
+
assert.equal(existsSync(join(catalog, 'versions', version)), false);
|
|
705
|
+
});
|
|
706
|
+
test('Claude lost update acknowledgement resumes the exact target without selecting twice', async () => {
|
|
707
|
+
const { native, settings, before, catalog } = claudeReplacementFixture();
|
|
708
|
+
native.loseAck = true;
|
|
709
|
+
await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
|
|
710
|
+
const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
|
|
711
|
+
interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
|
|
712
|
+
writeState(interrupted, 'claude-code');
|
|
713
|
+
native.loseAck = false;
|
|
714
|
+
await managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' });
|
|
715
|
+
assert.equal(native.updates, 1);
|
|
716
|
+
assert.deepEqual(readFileSync(settings), before);
|
|
717
|
+
});
|
|
718
|
+
test('Claude prior selection with a published target catalog refuses an ambiguous retry', async () => {
|
|
719
|
+
const { native, settings, before, catalog } = claudeReplacementFixture();
|
|
720
|
+
native.failSelection = true;
|
|
721
|
+
await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }));
|
|
722
|
+
const interrupted = JSON.parse(readFileSync(join(dirname(catalog), 'state.json'), 'utf8'));
|
|
723
|
+
interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
|
|
724
|
+
writeState(interrupted, 'claude-code');
|
|
725
|
+
native.failSelection = false;
|
|
726
|
+
await assert.rejects(managePlugin({ ...input(), host: 'claude-code', action: 'update', version: '0.3.22' }), /ambiguous/iu);
|
|
727
|
+
assert.equal(native.updates, 1);
|
|
728
|
+
assert.deepEqual(readFileSync(settings), before);
|
|
729
|
+
});
|
|
730
|
+
test('Claude doctor rejects changed native cache bytes before starting MCP', async () => {
|
|
731
|
+
const cache = doctorFixture(true, 'claude-code');
|
|
732
|
+
writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'foreign native cache bytes');
|
|
733
|
+
const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
|
|
734
|
+
assert.equal(result.sourceIntegrity, false);
|
|
735
|
+
assert.equal(result.mcp?.startup, 'not_checked');
|
|
736
|
+
});
|
|
737
|
+
test('Claude doctor refuses a native cache path that differs from the owned selection', async () => {
|
|
738
|
+
doctorFixture(true, 'claude-code');
|
|
739
|
+
const entries = JSON.parse(fixture.responses[0]);
|
|
740
|
+
entries[0].installPath = join(fixture.home, 'foreign-native-cache');
|
|
741
|
+
fixture.responses[0] = JSON.stringify(entries);
|
|
742
|
+
const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
|
|
743
|
+
assert.equal(result.sourceIntegrity, false);
|
|
744
|
+
assert.equal(result.mcp?.startup, 'not_checked');
|
|
745
|
+
});
|
|
746
|
+
test('lost native acknowledgement remains a failure, then exact target postimage resumes without selecting twice', async () => {
|
|
747
|
+
const { native, policy, before, catalog } = replacementFixture();
|
|
748
|
+
native.loseAck = true;
|
|
749
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
|
|
750
|
+
assert.deepEqual(policy, before);
|
|
751
|
+
const path = join(dirname(catalog), 'state.json');
|
|
752
|
+
const interrupted = JSON.parse(readFileSync(path, 'utf8'));
|
|
753
|
+
assert.equal(interrupted.currentVersion, '0.3.21');
|
|
754
|
+
assert.equal(interrupted.pending.targetVersion, '0.3.22');
|
|
755
|
+
interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
|
|
756
|
+
writeState(interrupted);
|
|
757
|
+
native.loseAck = false;
|
|
758
|
+
const result = await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
759
|
+
assert.equal(result.version, '0.3.22');
|
|
760
|
+
assert.equal(native.selectionCalls, 1);
|
|
761
|
+
assert.deepEqual(policy, before);
|
|
762
|
+
const finished = JSON.parse(readFileSync(path, 'utf8'));
|
|
763
|
+
assert.equal(finished.currentVersion, '0.3.22');
|
|
764
|
+
assert.equal(finished.previousVersion, '0.3.21');
|
|
765
|
+
assert.equal(finished.pending, undefined);
|
|
766
|
+
});
|
|
767
|
+
test('a target catalog with prior native selection and an idle pending command refuses ambiguous replay', async () => {
|
|
768
|
+
const { native, catalog } = replacementFixture();
|
|
769
|
+
native.failSelection = true;
|
|
770
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
|
|
771
|
+
const path = join(dirname(catalog), 'state.json');
|
|
772
|
+
const interrupted = JSON.parse(readFileSync(path, 'utf8'));
|
|
773
|
+
interrupted.pending.owner = { pid: 2_000_000_000, birth: 'old owner' };
|
|
774
|
+
writeState(interrupted);
|
|
775
|
+
native.failSelection = false;
|
|
776
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /ambiguous/u);
|
|
777
|
+
assert.equal(native.selectionCalls, 1);
|
|
778
|
+
assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending.targetVersion, '0.3.22');
|
|
779
|
+
});
|
|
780
|
+
test('recovery rejects a corrupted completed unit before reusing the selected target', async () => {
|
|
781
|
+
const { native, catalog } = replacementFixture();
|
|
782
|
+
native.loseAck = true;
|
|
783
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
|
|
784
|
+
const statePath = join(dirname(catalog), 'state.json');
|
|
785
|
+
const pending = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
786
|
+
pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated selected owner' };
|
|
787
|
+
writeState(pending);
|
|
788
|
+
const archive = join(catalog, 'versions/0.3.22/archive.tgz');
|
|
789
|
+
writeFileSync(archive, 'corrupted completed archive');
|
|
790
|
+
native.loseAck = false;
|
|
791
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }));
|
|
792
|
+
assert.equal(native.selectionCalls, 1);
|
|
793
|
+
assert.equal(readFileSync(archive, 'utf8'), 'corrupted completed archive');
|
|
794
|
+
assert.ok(JSON.parse(readFileSync(statePath, 'utf8')).pending);
|
|
795
|
+
});
|
|
796
|
+
test('qualified Codex rollback uses the retained immutable unit and preserves later unrelated edits', async () => {
|
|
797
|
+
const { native, catalog, policy, before } = replacementFixture();
|
|
798
|
+
await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
799
|
+
assert.equal(existsSync(join(fixture.home, '.codex/plugins/cache/ai-delivery-user/ai-delivery/0.3.21')), false);
|
|
800
|
+
assert.equal(existsSync(join(catalog, 'versions/0.3.21/version.json')), true);
|
|
801
|
+
policy.later = { sentinel: 'keep later edit' };
|
|
802
|
+
const rolled = await managePlugin({ ...input(), action: 'rollback', version: undefined });
|
|
803
|
+
assert.equal(rolled.version, '0.3.21');
|
|
804
|
+
assert.equal(native.selectionCalls, 2);
|
|
805
|
+
assert.deepEqual(policy, { ...before, later: { sentinel: 'keep later edit' } });
|
|
806
|
+
});
|
|
807
|
+
test('rollback of a removed managed selection refuses rather than reinstalling it', async () => {
|
|
808
|
+
const { catalog, native, policy } = replacementFixture();
|
|
809
|
+
const path = join(dirname(catalog), 'state.json');
|
|
810
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
811
|
+
state.currentVersion = null;
|
|
812
|
+
state.previousVersion = '0.3.21';
|
|
813
|
+
state.installedPath = null;
|
|
814
|
+
writeState(state);
|
|
815
|
+
native.selected = [];
|
|
816
|
+
delete policy['ai-delivery@ai-delivery-user'];
|
|
817
|
+
const before = structuredClone(policy);
|
|
818
|
+
await assert.rejects(managePlugin({ ...input(), action: 'rollback', version: undefined }), /current managed selection/u);
|
|
819
|
+
assert.deepEqual(fixture.commandArguments, []);
|
|
820
|
+
assert.deepEqual(policy, before);
|
|
821
|
+
});
|
|
822
|
+
test('rollback refuses a target superseded by the managed writer ahead of its lock', async () => {
|
|
823
|
+
const { catalog, native } = replacementFixture();
|
|
824
|
+
const path = join(dirname(catalog), 'state.json');
|
|
825
|
+
const initial = JSON.parse(readFileSync(path, 'utf8'));
|
|
826
|
+
initial.previousVersion = '0.3.20';
|
|
827
|
+
writeState(initial);
|
|
828
|
+
const respond = fixture.respond;
|
|
829
|
+
let queuedRollback;
|
|
830
|
+
fixture.respond = (args) => {
|
|
831
|
+
const output = respond(args);
|
|
832
|
+
if (args[2] === 'list' && native.selected[0]?.version === '0.3.22' && !queuedRollback)
|
|
833
|
+
queuedRollback = managePlugin({ ...input(), action: 'rollback', version: undefined }).then(() => undefined, (error) => error);
|
|
834
|
+
return output;
|
|
835
|
+
};
|
|
836
|
+
await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
837
|
+
assert.ok(queuedRollback);
|
|
838
|
+
const error = await queuedRollback;
|
|
839
|
+
assert.ok(error instanceof Error);
|
|
840
|
+
assert.match(error.message, /rollback target changed before/u);
|
|
841
|
+
assert.equal(native.selectionCalls, 1);
|
|
842
|
+
assert.equal(JSON.parse(readFileSync(path, 'utf8')).currentVersion, '0.3.22');
|
|
843
|
+
});
|
|
844
|
+
test('a partial catalog publication resumes with reused units and matches an uninterrupted update', async () => {
|
|
845
|
+
const first = replacementFixture();
|
|
846
|
+
await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
847
|
+
const statePath = join(dirname(first.catalog), 'state.json');
|
|
848
|
+
const uninterrupted = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
849
|
+
const { catalog, native, policy, before } = replacementFixture();
|
|
850
|
+
const immutableArchive = join(catalog, 'versions/0.3.22/archive.tgz');
|
|
851
|
+
const archiveBefore = readFileSync(immutableArchive);
|
|
852
|
+
const actual = atomicJson.writePrivateJsonFileAtomically;
|
|
853
|
+
let interrupt = true;
|
|
854
|
+
vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
|
|
855
|
+
if (interrupt && path === join(catalog, '.claude-plugin/marketplace.json')) {
|
|
856
|
+
interrupt = false;
|
|
857
|
+
throw new Error('Synthetic catalog publication interruption');
|
|
858
|
+
}
|
|
859
|
+
actual(path, value);
|
|
860
|
+
});
|
|
861
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /publication interruption/u);
|
|
862
|
+
assert.equal(native.selectionCalls, 0);
|
|
863
|
+
assert.equal(JSON.parse(readFileSync(join(catalog, '.claude-plugin/marketplace.json'), 'utf8')).plugins[0].version, '0.3.21');
|
|
864
|
+
assert.match(readFileSync(join(catalog, '.agents/plugins/marketplace.json'), 'utf8'), /versions\/0\.3\.22/u);
|
|
865
|
+
const pending = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
866
|
+
pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated publication owner' };
|
|
867
|
+
writeState(pending);
|
|
868
|
+
fixture.commands = [];
|
|
869
|
+
await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
870
|
+
assert.deepEqual(JSON.parse(readFileSync(statePath, 'utf8')), uninterrupted);
|
|
871
|
+
assert.deepEqual(readFileSync(immutableArchive), archiveBefore);
|
|
872
|
+
assert.equal(fixture.commands.includes('npm'), false);
|
|
873
|
+
assert.equal(native.selectionCalls, 1);
|
|
874
|
+
assert.deepEqual(policy, before);
|
|
875
|
+
});
|
|
876
|
+
test('a failed managed-state commit retains selection and resumes without selecting again', async () => {
|
|
877
|
+
const { native, catalog, policy, before } = replacementFixture();
|
|
878
|
+
const actual = atomicJson.writePrivateJsonFileAtomically;
|
|
879
|
+
const fault = vi.spyOn(atomicJson, 'writePrivateJsonFileAtomically').mockImplementation((path, value) => {
|
|
880
|
+
const state = value;
|
|
881
|
+
if (path.endsWith('/state.json') && state.currentVersion === '0.3.22' && !state.pending)
|
|
882
|
+
throw new Error('Synthetic final state commit failure');
|
|
883
|
+
actual(path, value);
|
|
884
|
+
});
|
|
885
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /final state commit failure/u);
|
|
886
|
+
fault.mockRestore();
|
|
887
|
+
const path = join(dirname(catalog), 'state.json');
|
|
888
|
+
const pending = JSON.parse(readFileSync(path, 'utf8'));
|
|
889
|
+
pending.pending.owner = { pid: 2_000_000_000, birth: 'terminated commit owner' };
|
|
890
|
+
writeState(pending);
|
|
891
|
+
await managePlugin({ ...input(), action: 'update', version: '0.3.22' });
|
|
892
|
+
assert.equal(native.selectionCalls, 1);
|
|
893
|
+
assert.deepEqual(policy, before);
|
|
894
|
+
assert.equal(JSON.parse(readFileSync(path, 'utf8')).pending, undefined);
|
|
895
|
+
});
|
|
896
|
+
test.each(['bytes', 'mode'])('managed state %s changed by another writer is not overwritten after native selection', async (change) => {
|
|
897
|
+
const { catalog, native } = replacementFixture();
|
|
898
|
+
const respond = fixture.respond;
|
|
899
|
+
const path = join(dirname(catalog), 'state.json');
|
|
900
|
+
let changed;
|
|
901
|
+
fixture.respond = (args) => {
|
|
902
|
+
const output = respond(args);
|
|
903
|
+
if (args[2] === 'add') {
|
|
904
|
+
if (change === 'mode')
|
|
905
|
+
chmodSync(path, 0o400);
|
|
906
|
+
else {
|
|
907
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
908
|
+
state.previousVersion = '0.3.19';
|
|
909
|
+
writeFileSync(path, JSON.stringify(state), { mode: 0o600 });
|
|
910
|
+
}
|
|
911
|
+
changed = readFileSync(path);
|
|
912
|
+
}
|
|
913
|
+
return output;
|
|
914
|
+
};
|
|
915
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Managed state changed/u);
|
|
916
|
+
assert.equal(native.selectionCalls, 1);
|
|
917
|
+
assert.ok(changed);
|
|
918
|
+
assert.deepEqual(readFileSync(path), changed);
|
|
919
|
+
if (change === 'mode')
|
|
920
|
+
assert.equal(lstatSync(path).mode & 0o777, 0o400);
|
|
921
|
+
});
|
|
922
|
+
test('catalog custody changed during preparation refuses before selection without repairing it', async () => {
|
|
923
|
+
const { catalog, native, policy, before } = replacementFixture();
|
|
924
|
+
const respond = fixture.respond;
|
|
925
|
+
const path = join(catalog, '.agents/plugins/marketplace.json');
|
|
926
|
+
fixture.respond = (args) => {
|
|
927
|
+
const output = respond(args);
|
|
928
|
+
if (args[0] === process.execPath)
|
|
929
|
+
chmodSync(path, 0o644);
|
|
930
|
+
return output;
|
|
931
|
+
};
|
|
932
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /catalog.*changed/u);
|
|
933
|
+
assert.equal(native.selectionCalls, 0);
|
|
934
|
+
assert.equal(lstatSync(path).mode & 0o777, 0o644);
|
|
935
|
+
assert.deepEqual(policy, before);
|
|
936
|
+
});
|
|
256
937
|
for (const action of ['install', 'update'])
|
|
257
938
|
test(`${action} reads back its managed version without capturing an unrelated catalogue over 1 MiB`, async () => {
|
|
258
939
|
const { entry, cache, catalog } = installationFixture(action);
|
|
@@ -268,17 +949,18 @@ for (const action of ['install', 'update'])
|
|
|
268
949
|
assert.equal(state.pending, undefined);
|
|
269
950
|
assert.equal(state.currentVersion, '0.3.22');
|
|
270
951
|
assert.equal(state.previousVersion, action === 'update' ? '0.3.21' : null);
|
|
271
|
-
const mutation = fixture.commandArguments.find((args) => args[2] === (action === 'install' ? 'marketplace' : '
|
|
952
|
+
const mutation = fixture.commandArguments.find((args) => args[2] === (action === 'install' ? 'marketplace' : 'add'));
|
|
272
953
|
assert.deepEqual(mutation, action === 'install'
|
|
273
954
|
? ['codex', 'plugin', 'marketplace', 'add', catalog, '--json']
|
|
274
|
-
: ['codex', 'plugin', '
|
|
955
|
+
: ['codex', 'plugin', 'add', 'ai-delivery@ai-delivery-user', '--json']);
|
|
956
|
+
assert.equal(fixture.commandArguments.some((args) => args[2] === 'remove'), false);
|
|
275
957
|
fixture.responses.push(oversizedCatalogue([{ ...entry, enabled: false }]));
|
|
276
958
|
const doctor = await managePlugin({ ...input(), action: 'doctor', version: undefined });
|
|
277
959
|
assert.equal(doctor.installed, true);
|
|
278
960
|
assert.equal(doctor.sourceIntegrity, true);
|
|
279
961
|
assert.deepEqual(doctor.mcp, { configuration: 'disabled', startup: 'not_checked' });
|
|
280
962
|
assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
|
|
281
|
-
assert.equal(fixture.commandArguments.filter((args) => args[2] === 'list').length,
|
|
963
|
+
assert.equal(fixture.commandArguments.filter((args) => args[2] === 'list').length, 4);
|
|
282
964
|
});
|
|
283
965
|
test('the filtered managed catalogue still enforces the 1 MiB capture ceiling', async () => {
|
|
284
966
|
doctorFixture(false);
|
|
@@ -343,7 +1025,7 @@ test('interrupted filtered readback resumes the original install without fetchin
|
|
|
343
1025
|
state.pending.owner = { pid: 2_000_000_000, birth: 'terminated fixture owner' };
|
|
344
1026
|
writeFileSync(statePath, JSON.stringify(state), { mode: 0o600 });
|
|
345
1027
|
const before = readFileSync(join(cache, 'skills/intake/SKILL.md'));
|
|
346
|
-
fixture.responses.push('codex-cli 0.153.0', oversizedCatalogue([entry]),
|
|
1028
|
+
fixture.responses.push('codex-cli 0.153.0', oversizedCatalogue([entry]), oversizedCatalogue([entry]));
|
|
347
1029
|
const result = await managePlugin({ ...input(), version: '0.3.22' });
|
|
348
1030
|
assert.equal(result.installed, true);
|
|
349
1031
|
assert.equal(result.version, '0.3.22');
|
|
@@ -376,6 +1058,31 @@ test('Claude doctor retains its unfiltered native inventory and disabled selecti
|
|
|
376
1058
|
assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
|
|
377
1059
|
assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
|
|
378
1060
|
});
|
|
1061
|
+
test('Claude doctor binds managed provenance to the verified scope and source, excluding other projects', async () => {
|
|
1062
|
+
doctorFixture(false, 'claude-code');
|
|
1063
|
+
const entries = JSON.parse(fixture.responses[0]);
|
|
1064
|
+
const selected = entries[0];
|
|
1065
|
+
entries.push({ ...selected, scope: 'project', projectPath: fixture.home, version: '0.3.24', installPath: '/unverified' }, { ...selected, scope: 'local', projectPath: fixture.home, installPath: '/unverified' }, { ...selected, scope: 'project', projectPath: join(fixture.home, 'other-project') }, { ...selected, scope: 'local' });
|
|
1066
|
+
fixture.responses[0] = JSON.stringify(entries);
|
|
1067
|
+
const result = await managePlugin({ ...input(), host: 'claude-code', action: 'doctor', version: undefined });
|
|
1068
|
+
assert.equal(result.sourceIntegrity, true);
|
|
1069
|
+
assert.ok(result.diagnostics);
|
|
1070
|
+
assert.deepEqual(result.diagnostics.registrations, [
|
|
1071
|
+
{
|
|
1072
|
+
kind: 'plugin',
|
|
1073
|
+
scope: 'user',
|
|
1074
|
+
ownership: 'managed',
|
|
1075
|
+
source: 'managed_archive',
|
|
1076
|
+
version: '0.3.21',
|
|
1077
|
+
enabled: false,
|
|
1078
|
+
},
|
|
1079
|
+
{ kind: 'plugin', scope: 'project', ownership: 'external', source: 'unknown', version: '0.3.24', enabled: false },
|
|
1080
|
+
{ kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
|
|
1081
|
+
{ kind: 'plugin', scope: 'local', ownership: 'external', source: 'unknown', version: '0.3.21', enabled: false },
|
|
1082
|
+
]);
|
|
1083
|
+
assert.ok(result.diagnostics.findings.includes('native_registration_project_unverified'));
|
|
1084
|
+
assert.deepEqual(fixture.commandArguments, [['claude', 'plugin', 'list', '--json']]);
|
|
1085
|
+
});
|
|
379
1086
|
test('doctor refuses a same-version native cache with changed skill bytes before starting MCP', async () => {
|
|
380
1087
|
const cache = doctorFixture(true);
|
|
381
1088
|
writeFileSync(join(cache, 'skills/intake/SKILL.md'), 'unexpected native bytes');
|
|
@@ -385,7 +1092,7 @@ test('doctor refuses a same-version native cache with changed skill bytes before
|
|
|
385
1092
|
assert.equal(result.sourceIntegrity, false);
|
|
386
1093
|
assert.equal(result.mcp?.startup, 'not_checked');
|
|
387
1094
|
assert.match(result.mcp?.error ?? '', /native plugin bytes/u);
|
|
388
|
-
assert.deepEqual(fixture.commands, ['codex']);
|
|
1095
|
+
assert.deepEqual(fixture.commands, ['codex', 'codex']);
|
|
389
1096
|
assert.deepEqual(readFileSync(join(cache, 'skills/intake/SKILL.md')), before);
|
|
390
1097
|
});
|
|
391
1098
|
test('doctor reports a disabled native plugin separately and does not start its MCP server', async () => {
|
|
@@ -395,7 +1102,7 @@ test('doctor reports a disabled native plugin separately and does not start its
|
|
|
395
1102
|
assert.equal(result.enabled, false);
|
|
396
1103
|
assert.equal(result.sourceIntegrity, true);
|
|
397
1104
|
assert.deepEqual(result.mcp, { configuration: 'disabled', startup: 'not_checked' });
|
|
398
|
-
assert.deepEqual(fixture.commands, ['codex']);
|
|
1105
|
+
assert.deepEqual(fixture.commands, ['codex', 'codex']);
|
|
399
1106
|
});
|
|
400
1107
|
test('doctor refuses a Claude catalog pointing at a different same-version source before startup', async () => {
|
|
401
1108
|
doctorFixture(true, 'claude-code');
|
|
@@ -445,15 +1152,16 @@ test('an absent native profile beneath a symlink keeps its identity after creati
|
|
|
445
1152
|
const result = await managePlugin({ ...input(), action: 'doctor', version: undefined });
|
|
446
1153
|
assert.equal(result.recoveryRequired, false);
|
|
447
1154
|
assert.deepEqual(readFileSync(statePath), before);
|
|
448
|
-
assert.
|
|
1155
|
+
assert.equal(result.diagnostics?.nativeInventory, 'unavailable');
|
|
1156
|
+
assert.deepEqual(fixture.commands, ['codex', 'codex']);
|
|
449
1157
|
});
|
|
450
1158
|
test('a definitive version preparation failure preserves selection and permits a different valid request', async () => {
|
|
451
1159
|
const cache = doctorFixture(true);
|
|
452
|
-
fixture.responses
|
|
1160
|
+
const response = fixture.responses[0];
|
|
1161
|
+
fixture.responses.unshift('codex-cli 0.162.1');
|
|
453
1162
|
const catalog = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace');
|
|
454
1163
|
const catalogPath = join(catalog, '.agents/plugins/marketplace.json');
|
|
455
1164
|
mkdirSync(dirname(catalogPath), { recursive: true, mode: 0o700 });
|
|
456
|
-
writeFileSync(catalogPath, 'unchanged selected catalog', { mode: 0o600 });
|
|
457
1165
|
const before = readFileSync(catalogPath);
|
|
458
1166
|
const data = join(fixture.home, 'native-data');
|
|
459
1167
|
writeFileSync(data, 'preserve native data');
|
|
@@ -466,18 +1174,21 @@ test('a definitive version preparation failure preserves selection and permits a
|
|
|
466
1174
|
assert.deepEqual(readFileSync(catalogPath), before);
|
|
467
1175
|
assert.equal(readFileSync(data, 'utf8'), 'preserve native data');
|
|
468
1176
|
assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
|
|
469
|
-
|
|
470
|
-
|
|
1177
|
+
fixture.responses.push('codex-cli 0.162.1', response, response);
|
|
1178
|
+
const reused = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
|
|
1179
|
+
assert.equal(reused.changed, false);
|
|
1180
|
+
assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
|
|
471
1181
|
});
|
|
472
1182
|
test('failure after catalog selection retains pending recovery before another version', async () => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
await assert.rejects(managePlugin({ ...input(), action: 'update' }), /Native fixture intentionally unavailable/u);
|
|
1183
|
+
const { native } = replacementFixture();
|
|
1184
|
+
native.failSelection = true;
|
|
1185
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.22' }), /Native fixture intentionally unavailable/u);
|
|
476
1186
|
const statePath = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/state.json');
|
|
477
1187
|
const state = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
478
|
-
assert.equal(state.pending?.targetVersion, '0.3.
|
|
479
|
-
|
|
480
|
-
assert.
|
|
1188
|
+
assert.equal(state.pending?.targetVersion, '0.3.22');
|
|
1189
|
+
const before = [...fixture.commandArguments];
|
|
1190
|
+
await assert.rejects(managePlugin({ ...input(), action: 'update', version: '0.3.23' }), /A live plugin installer still owns this target|Resume the interrupted original plugin command/u);
|
|
1191
|
+
assert.deepEqual(fixture.commandArguments, before);
|
|
481
1192
|
});
|
|
482
1193
|
test('definitive preparation reports pending-state cleanup failure and preserves its recovery intent', async () => {
|
|
483
1194
|
const actual = atomicJson.writePrivateJsonFileAtomically;
|
|
@@ -497,7 +1208,8 @@ test('definitive preparation reports pending-state cleanup failure and preserves
|
|
|
497
1208
|
});
|
|
498
1209
|
test('an unsupported version archive leaves selection intact and permits a valid version request', async () => {
|
|
499
1210
|
const cache = doctorFixture(true);
|
|
500
|
-
fixture.responses
|
|
1211
|
+
const response = fixture.responses[0];
|
|
1212
|
+
fixture.responses.unshift('codex-cli 0.162.1');
|
|
501
1213
|
const root = join(fixture.home, 'unsupported/package');
|
|
502
1214
|
const files = {
|
|
503
1215
|
'package.json': { name: '@aviaratech/ai-delivery', version: '0.3.22' },
|
|
@@ -544,8 +1256,10 @@ test('an unsupported version archive leaves selection intact and permits a valid
|
|
|
544
1256
|
assert.equal(readFileSync(join(cache, 'skills/intake/SKILL.md'), 'utf8'), 'owned skill bytes');
|
|
545
1257
|
assert.equal(existsSync(join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions/0.3.22')), false);
|
|
546
1258
|
fixture.packArchive = '';
|
|
547
|
-
|
|
548
|
-
|
|
1259
|
+
fixture.responses.push('codex-cli 0.162.1', response, response);
|
|
1260
|
+
const reused = await managePlugin({ ...input(), action: 'update', version: '0.3.21' });
|
|
1261
|
+
assert.equal(reused.changed, false);
|
|
1262
|
+
assert.equal(fixture.commands.filter((command) => command === 'npm').length, 1);
|
|
549
1263
|
});
|
|
550
1264
|
test('recovery removes only its recorded incomplete staging directory', async () => {
|
|
551
1265
|
const version = '0.3.21', directory = join(fixture.home, '.cache/ai-delivery/plugins/codex/user/marketplace/versions');
|