@cleocode/adapters 2026.11.4 → 2026.11.5-rc.ci.721
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/dist/.source-stamp.json +1 -1
- package/dist/index.js +268 -14
- package/dist/index.js.map +2 -2
- package/dist/orca-execution.d.ts +7 -0
- package/dist/orca-execution.d.ts.map +1 -1
- package/dist/orca-execution.js +33 -4
- package/dist/orca-execution.js.map +1 -1
- package/dist/providers/claude-code/index.js +268 -13
- package/dist/providers/claude-code/index.js.map +2 -2
- package/dist/providers/claude-code/lead-mcp.d.ts +27 -0
- package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +6 -2
- package/dist/providers/claude-sdk/index.js.map +1 -1
- package/dist/providers/codex/index.js +6 -2
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/gemini-cli/index.js +6 -2
- package/dist/providers/gemini-cli/index.js.map +1 -1
- package/dist/providers/kimi/index.js +6 -2
- package/dist/providers/kimi/index.js.map +1 -1
- package/dist/providers/openai-sdk/index.js +6 -2
- package/dist/providers/openai-sdk/index.js.map +1 -1
- package/dist/providers/opencode/index.js +6 -2
- package/dist/providers/opencode/index.js.map +1 -1
- package/dist/providers/pi/index.js +6 -2
- package/dist/providers/pi/index.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/orca-execution-fixture.ts +39 -1
- package/src/__tests__/orca-execution.test.ts +58 -0
- package/src/orca-execution.ts +39 -4
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +154 -1
- package/src/providers/claude-code/lead-mcp.ts +403 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/adapters",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.5-rc.ci.721",
|
|
4
4
|
"description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@ai-sdk/anthropic": "^3.0.69",
|
|
36
36
|
"@ai-sdk/openai": "^2.0.53",
|
|
37
37
|
"ai": "^6.0.168",
|
|
38
|
-
"@cleocode/caamp": "2026.11.
|
|
39
|
-
"@cleocode/contracts": "2026.11.
|
|
40
|
-
"@cleocode/paths": "2026.11.
|
|
38
|
+
"@cleocode/caamp": "2026.11.5-rc.ci.721",
|
|
39
|
+
"@cleocode/contracts": "2026.11.5-rc.ci.721",
|
|
40
|
+
"@cleocode/paths": "2026.11.5-rc.ci.721"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"engines": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^24.3.0",
|
|
52
52
|
"vitest": "^4.1.4",
|
|
53
|
-
"@cleocode/
|
|
54
|
-
"@cleocode/
|
|
53
|
+
"@cleocode/playbooks": "2026.11.5-rc.ci.721",
|
|
54
|
+
"@cleocode/core": "2026.11.5-rc.ci.721"
|
|
55
55
|
},
|
|
56
56
|
"repository": {
|
|
57
57
|
"type": "git",
|
|
@@ -14,8 +14,46 @@ import { vi } from 'vitest';
|
|
|
14
14
|
/** Fake durable provider mailbox; retained while a fresh client simulates CLI restart. */
|
|
15
15
|
export const fixtureMail = { bodies: new Map<string, string>(), failBefore: false, loseAck: false };
|
|
16
16
|
|
|
17
|
-
/** AgentMBX
|
|
17
|
+
/** AgentMBX held-identity reads and idempotent sends, with no real mailbox access. */
|
|
18
18
|
export const runMbxFixture: MbxRunner = async (args) => {
|
|
19
|
+
if (args[0] === 'identity' && args[1] === 'list') {
|
|
20
|
+
if (!args.includes('--project')) throw new Error('Mailbox inventory needs a project');
|
|
21
|
+
return {
|
|
22
|
+
missing: false,
|
|
23
|
+
exitCode: 0,
|
|
24
|
+
stderr: '',
|
|
25
|
+
stdout: JSON.stringify({
|
|
26
|
+
identities: [
|
|
27
|
+
{
|
|
28
|
+
name: 'fixture-lead',
|
|
29
|
+
registered: true,
|
|
30
|
+
retired: false,
|
|
31
|
+
state: 'held',
|
|
32
|
+
holder: { cli: 'codex', session_id: 'ses_fixture_lead' },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (args[0] === 'status' || (args[0] === 'identity' && args[1] === 'release')) {
|
|
39
|
+
const held =
|
|
40
|
+
args[0] === 'status' &&
|
|
41
|
+
args[args.indexOf('--cli') + 1] === 'codex' &&
|
|
42
|
+
args[args.indexOf('--session') + 1] === 'ses_fixture_lead';
|
|
43
|
+
return {
|
|
44
|
+
missing: false,
|
|
45
|
+
exitCode: 0,
|
|
46
|
+
stderr: '',
|
|
47
|
+
stdout: JSON.stringify({
|
|
48
|
+
identity: {
|
|
49
|
+
name: held ? 'fixture-lead' : null,
|
|
50
|
+
role: held ? 'lead' : null,
|
|
51
|
+
state: held ? 'bound' : 'unbound',
|
|
52
|
+
},
|
|
53
|
+
unread: 0,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
19
57
|
if (args[0] !== 'send') throw new Error(`Unexpected mailbox fixture command: ${args[0]}`);
|
|
20
58
|
const key = args[args.indexOf('--idempotency-key') + 1];
|
|
21
59
|
const body = args[args.indexOf('-m') + 1];
|
|
@@ -223,6 +223,34 @@ describe('Orca execution process boundary', () => {
|
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
+
it('records a first start that failed before worker-start as not launched (T14486)', async () => {
|
|
227
|
+
fixtureRunner.mockImplementation(async (...args) =>
|
|
228
|
+
args[1][0] === 'status'
|
|
229
|
+
? { stdout: '', stderr: 'runtime went away', exitCode: 1 }
|
|
230
|
+
: runOrcaFixture(...args),
|
|
231
|
+
);
|
|
232
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
233
|
+
expect(await backend.start(fixtureAttempt())).toMatchObject({
|
|
234
|
+
state: 'failed',
|
|
235
|
+
resourceState: 'stopped',
|
|
236
|
+
startRefusal: 'not_launched',
|
|
237
|
+
startRequestId: null,
|
|
238
|
+
dispatchId: null,
|
|
239
|
+
});
|
|
240
|
+
// A retry keeps its reserved key replayable under the original Task's breaker.
|
|
241
|
+
const retry = await backend.start(
|
|
242
|
+
fixtureAttempt({
|
|
243
|
+
runId: 'run_fixture',
|
|
244
|
+
orcaTaskId: 'task_fixture',
|
|
245
|
+
retryOf: 'ctx_previous',
|
|
246
|
+
startBinding: { runId: 'run_fixture', orcaTaskId: 'task_fixture', retryOf: 'ctx_previous' },
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
expect(retry).toMatchObject({ state: 'outcome_unknown' });
|
|
250
|
+
expect(retry.startRefusal).toBeUndefined();
|
|
251
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
|
|
226
254
|
it('refuses ambiguous workspace resolution with an exact-selector fix before launch', async () => {
|
|
227
255
|
fixtureRunner.mockImplementation(async (...args) =>
|
|
228
256
|
args[1][0] === 'worktree'
|
|
@@ -751,6 +779,36 @@ else {
|
|
|
751
779
|
}
|
|
752
780
|
});
|
|
753
781
|
|
|
782
|
+
it.each([
|
|
783
|
+
['nonzero exit', { stdout: '', stderr: 'unavailable fixture CLI', exitCode: 2 }, 'exited 2'],
|
|
784
|
+
['malformed registry', { stdout: '{not json', stderr: '', exitCode: 0 }, 'no valid command'],
|
|
785
|
+
] as const)('refuses a lead on a %s from agent-context with a typed fix (T14486)', async (_case, registry, message) => {
|
|
786
|
+
vi.stubEnv('ORCA_TERMINAL_HANDLE', fixtureContext.coordinatorHandle);
|
|
787
|
+
fixtureRunner.mockImplementation(async (...args) =>
|
|
788
|
+
args[1][0] === 'agent-context' ? registry : runOrcaFixture(...args),
|
|
789
|
+
);
|
|
790
|
+
const admitted = vi.fn<(pid: number) => void>();
|
|
791
|
+
await expect(
|
|
792
|
+
new OrcaExecutionBackend(fixtureRunner).startLead(
|
|
793
|
+
{
|
|
794
|
+
command: '/fixture/claude',
|
|
795
|
+
args: [],
|
|
796
|
+
cwd: '/fixture/project',
|
|
797
|
+
tempDir: '/fixture/spawn',
|
|
798
|
+
env: { CLEO_SESSION_ID: 'ses_own', CLEO_AGENT_ID: 'agent-own', CLEO_AGENT_ROLE: 'lead' },
|
|
799
|
+
},
|
|
800
|
+
admitted,
|
|
801
|
+
),
|
|
802
|
+
).rejects.toMatchObject({
|
|
803
|
+
name: 'OrcaExecutionError',
|
|
804
|
+
code: 'E_LEAD_TOOLS_UNSTRIPPED',
|
|
805
|
+
message: expect.stringContaining(message),
|
|
806
|
+
fix: expect.stringContaining('update the CLI and runtime together'),
|
|
807
|
+
});
|
|
808
|
+
expect(admitted).not.toHaveBeenCalled();
|
|
809
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'create')).toBe(false);
|
|
810
|
+
});
|
|
811
|
+
|
|
754
812
|
it('refuses a changed runtime and an incomplete command registry before launch', async () => {
|
|
755
813
|
fixtureRunner.mockImplementation(async (...args) =>
|
|
756
814
|
args[1][0] === 'status'
|
package/src/orca-execution.ts
CHANGED
|
@@ -312,13 +312,22 @@ export class OrcaExecutionBackend implements OrcaRoutingAdapter {
|
|
|
312
312
|
['agent-context', '--json'],
|
|
313
313
|
launch.cwd,
|
|
314
314
|
);
|
|
315
|
-
|
|
315
|
+
if (registryResult.exitCode !== 0) {
|
|
316
|
+
throw refuse(
|
|
317
|
+
`The selected Orca CLI is unavailable: agent-context exited ${registryResult.exitCode ?? 'without a status'}.`,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
let registry: ReturnType<typeof orcaCommandRegistrySchema.parse>;
|
|
321
|
+
try {
|
|
322
|
+
registry = orcaCommandRegistrySchema.parse(JSON.parse(registryResult.stdout));
|
|
323
|
+
} catch {
|
|
324
|
+
throw refuse('The selected Orca CLI returned no valid command registry.');
|
|
325
|
+
}
|
|
316
326
|
const create = registry.commands.find((entry) => entry.command === 'terminal create');
|
|
317
327
|
const show = registry.commands.find((entry) => entry.command === 'terminal show');
|
|
318
328
|
const close = registry.commands.find((entry) => entry.command === 'terminal close');
|
|
319
329
|
const focus = registry.commands.find((entry) => entry.command === 'terminal switch');
|
|
320
330
|
if (
|
|
321
|
-
registryResult.exitCode !== 0 ||
|
|
322
331
|
!create ||
|
|
323
332
|
!['command', 'worktree', 'title', 'environment'].every((flag) =>
|
|
324
333
|
create.flags.includes(flag),
|
|
@@ -785,7 +794,7 @@ export class OrcaExecutionBackend implements OrcaRoutingAdapter {
|
|
|
785
794
|
'Inspect the stored exact Dispatch; recover an uncertain request by its issued id.',
|
|
786
795
|
);
|
|
787
796
|
}
|
|
788
|
-
return this.startCommand(attempt, attempt.startRequestKey);
|
|
797
|
+
return this.startCommand(attempt, attempt.startRequestKey, true);
|
|
789
798
|
}
|
|
790
799
|
|
|
791
800
|
/** Replay an issued or pre-reserved launch key on the same runtime and caller. */
|
|
@@ -1123,7 +1132,18 @@ export class OrcaExecutionBackend implements OrcaRoutingAdapter {
|
|
|
1123
1132
|
}
|
|
1124
1133
|
}
|
|
1125
1134
|
|
|
1126
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* Send, or replay, one keyed worker-start.
|
|
1137
|
+
* @param attempt - Durable attempt the receipt is recorded on.
|
|
1138
|
+
* @param requestId - Reserved or issued start key.
|
|
1139
|
+
* @param firstSend - True only for {@link start}: no earlier send of this key can exist,
|
|
1140
|
+
* so a failure before worker-start is sent proves nothing was launched.
|
|
1141
|
+
*/
|
|
1142
|
+
private async startCommand(
|
|
1143
|
+
attempt: OrcaAttempt,
|
|
1144
|
+
requestId?: string,
|
|
1145
|
+
firstSend = false,
|
|
1146
|
+
): Promise<OrcaAttempt> {
|
|
1127
1147
|
const launch = attempt.launch;
|
|
1128
1148
|
this.validateLaunch(launch, attempt.context);
|
|
1129
1149
|
if (launch.harness === 'kimi') {
|
|
@@ -1173,8 +1193,10 @@ export class OrcaExecutionBackend implements OrcaRoutingAdapter {
|
|
|
1173
1193
|
...(launch.effort ? ['--effort', launch.effort] : []),
|
|
1174
1194
|
...(requestId ? ['--retry-request', requestId] : []),
|
|
1175
1195
|
];
|
|
1196
|
+
let sent = false;
|
|
1176
1197
|
try {
|
|
1177
1198
|
await this.verifyRuntime(launch.projectRoot, attempt.context, launch.model !== undefined);
|
|
1199
|
+
sent = true;
|
|
1178
1200
|
const reply = await this.invoke(
|
|
1179
1201
|
args,
|
|
1180
1202
|
launch.projectRoot,
|
|
@@ -1296,6 +1318,19 @@ export class OrcaExecutionBackend implements OrcaRoutingAdapter {
|
|
|
1296
1318
|
} catch (error) {
|
|
1297
1319
|
if (error instanceof OrcaExecutionError && error.code === 'E_ORCA_REQUEST_MISMATCH')
|
|
1298
1320
|
throw error;
|
|
1321
|
+
// A first launch that failed before worker-start was sent created nothing in
|
|
1322
|
+
// Orca, so it records a resource-free refusal instead of uncertain custody.
|
|
1323
|
+
// A retry keeps its reserved key replayable under the original Task's breaker.
|
|
1324
|
+
if (firstSend && !sent && binding.retryOf === null) {
|
|
1325
|
+
return {
|
|
1326
|
+
...attempt,
|
|
1327
|
+
state: 'failed',
|
|
1328
|
+
resourceState: 'stopped',
|
|
1329
|
+
startRefusal: 'not_launched',
|
|
1330
|
+
lastError: String(error).slice(0, MAX_DIAGNOSTIC_LENGTH),
|
|
1331
|
+
observedAt: new Date().toISOString(),
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1299
1334
|
return {
|
|
1300
1335
|
...attempt,
|
|
1301
1336
|
state: 'outcome_unknown',
|
|
@@ -23,13 +23,14 @@ import {
|
|
|
23
23
|
mkdtempSync,
|
|
24
24
|
readFileSync,
|
|
25
25
|
realpathSync,
|
|
26
|
+
renameSync,
|
|
26
27
|
rmSync,
|
|
27
28
|
statSync,
|
|
28
29
|
symlinkSync,
|
|
29
30
|
writeFileSync,
|
|
30
31
|
} from 'node:fs';
|
|
31
32
|
import { tmpdir } from 'node:os';
|
|
32
|
-
import { join } from 'node:path';
|
|
33
|
+
import { dirname, join } from 'node:path';
|
|
33
34
|
import type { SpawnContext } from '@cleocode/contracts';
|
|
34
35
|
import { E_LEAD_NO_OWNER_CHANNEL, LEAD_DENIED_TOOLS, LEAD_RUNNER_TOOL } from '@cleocode/contracts';
|
|
35
36
|
import type { OrcaLeadTerminalLauncher } from '@cleocode/contracts/orca-execution.js';
|
|
@@ -37,6 +38,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
37
38
|
import { OrcaExecutionError } from '../../../orca-execution.js';
|
|
38
39
|
import * as leadMcpModule from '../lead-mcp.js';
|
|
39
40
|
import {
|
|
41
|
+
claudeUnsafePath,
|
|
40
42
|
LEAD_MCP_FILE,
|
|
41
43
|
prepareLeadMcp,
|
|
42
44
|
requireLeadProjectTrust,
|
|
@@ -233,6 +235,157 @@ describe('lead isolation on claude-code (T14363, T14423)', () => {
|
|
|
233
235
|
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
234
236
|
});
|
|
235
237
|
|
|
238
|
+
/** Write a config trusting exactly `folders`. */
|
|
239
|
+
function trustOnly(...folders: string[]): void {
|
|
240
|
+
const projects = Object.fromEntries(
|
|
241
|
+
folders.map((folder) => [folder, { hasTrustDialogAccepted: true }]),
|
|
242
|
+
);
|
|
243
|
+
writeFileSync(claudeJson, JSON.stringify({ projects }));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
it('refuses a linked worktree whose main checkout root is the home directory', () => {
|
|
247
|
+
// HOME (root) is the main checkout; Claude never persists home-folder trust.
|
|
248
|
+
project = root;
|
|
249
|
+
const worktree = linkedWorktree();
|
|
250
|
+
trustOnly(realpathSync(root));
|
|
251
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow('the lead was not launched');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('resolves gitdir and commondir lexically, as Claude does, never realpath-following them (T14520)', () => {
|
|
255
|
+
if (process.platform === 'win32') return;
|
|
256
|
+
const worktree = linkedWorktree();
|
|
257
|
+
const alias = join(realpathSync(root), 'alias');
|
|
258
|
+
symlinkSync(realpathSync(project), alias);
|
|
259
|
+
const gitDir = readFileSync(join(worktree, '.git'), 'utf8').trim().slice(7).trim();
|
|
260
|
+
trustOnly(realpathSync(project));
|
|
261
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
262
|
+
|
|
263
|
+
// An absolute commondir spelled through the alias no longer names the entry's parent.
|
|
264
|
+
const commondir = readFileSync(join(gitDir, 'commondir'), 'utf8');
|
|
265
|
+
writeFileSync(join(gitDir, 'commondir'), join(alias, '.git'));
|
|
266
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
267
|
+
writeFileSync(join(gitDir, 'commondir'), commondir);
|
|
268
|
+
|
|
269
|
+
// A gitdir spelled through the alias makes Claude key trust by the alias, not the target.
|
|
270
|
+
const aliasGitDir = join(alias, '.git', 'worktrees', gitDir.split('/').at(-1) ?? '');
|
|
271
|
+
writeFileSync(join(worktree, '.git'), `gitdir: ${aliasGitDir}\n`);
|
|
272
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
273
|
+
trustOnly(alias);
|
|
274
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it.each([
|
|
278
|
+
'commondir',
|
|
279
|
+
'gitdir',
|
|
280
|
+
])('refuses a symlinked worktree %s file and an unsafe gitdir path', (file) => {
|
|
281
|
+
if (process.platform === 'win32') return;
|
|
282
|
+
const worktree = linkedWorktree();
|
|
283
|
+
const gitDir = readFileSync(join(worktree, '.git'), 'utf8').trim().slice(7).trim();
|
|
284
|
+
trustOnly(realpathSync(project));
|
|
285
|
+
const copy = join(root, `${file}-copy`);
|
|
286
|
+
writeFileSync(copy, readFileSync(join(gitDir, file)));
|
|
287
|
+
rmSync(join(gitDir, file));
|
|
288
|
+
symlinkSync(copy, join(gitDir, file));
|
|
289
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
290
|
+
rmSync(join(gitDir, file));
|
|
291
|
+
writeFileSync(join(gitDir, file), readFileSync(copy));
|
|
292
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
293
|
+
// An existing target spelled with a leading `//`: only the unsafe-path rule refuses it.
|
|
294
|
+
expect(existsSync(`/${gitDir}`)).toBe(true);
|
|
295
|
+
writeFileSync(join(worktree, '.git'), `gitdir: /${gitDir}\n`);
|
|
296
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('refuses a worktrees entry whose raw symlink target is a UNC spelling (T14520)', () => {
|
|
300
|
+
if (process.platform === 'win32') return;
|
|
301
|
+
const worktree = linkedWorktree();
|
|
302
|
+
const gitDir = readFileSync(join(worktree, '.git'), 'utf8').trim().slice(7).trim();
|
|
303
|
+
trustOnly(realpathSync(project));
|
|
304
|
+
// A local directory literally named \\server\share, reached through the entry's symlink.
|
|
305
|
+
const unc = '\\\\server\\share';
|
|
306
|
+
renameSync(gitDir, join(dirname(gitDir), unc));
|
|
307
|
+
symlinkSync(unc, gitDir);
|
|
308
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('follows a symlink to / with remaining components, as Claude does (T14520)', () => {
|
|
312
|
+
if (process.platform === 'win32') return;
|
|
313
|
+
const worktree = linkedWorktree();
|
|
314
|
+
const gitDir = readFileSync(join(worktree, '.git'), 'utf8').trim().slice(7).trim();
|
|
315
|
+
const rootLink = join(realpathSync(root), 'rootlink');
|
|
316
|
+
symlinkSync('/', rootLink);
|
|
317
|
+
writeFileSync(join(worktree, '.git'), `gitdir: ${rootLink}${gitDir}\n`);
|
|
318
|
+
trustOnly(`${rootLink}${realpathSync(project)}`);
|
|
319
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("ports Claude's unsafe-path rule: same-host /net, other hosts, /home automounts (T14520)", () => {
|
|
323
|
+
const linux = { darwin: false, homeAutomount: false, home: '/home/me' };
|
|
324
|
+
const mac = { darwin: true, homeAutomount: true, home: '/Users/me' };
|
|
325
|
+
// Same /net host as the base is allowed; another host, or a base off /net, is not.
|
|
326
|
+
expect(claudeUnsafePath('/net/host/repo/.git', '/net/host/repo/.git/worktrees/w', linux)).toBe(
|
|
327
|
+
false,
|
|
328
|
+
);
|
|
329
|
+
expect(
|
|
330
|
+
claudeUnsafePath('../../../../../other/repo', '/net/host/repo/.git/worktrees/w', linux),
|
|
331
|
+
).toBe(true);
|
|
332
|
+
expect(claudeUnsafePath('/net/host/repo/.git', '/srv/repo', linux)).toBe(true);
|
|
333
|
+
expect(claudeUnsafePath('/net', '/srv', linux)).toBe(true);
|
|
334
|
+
// macOS with /home automounted: another user's /home is refused, your own is not.
|
|
335
|
+
expect(claudeUnsafePath('/home/other/repo/.git', '/Users/me/repo', mac)).toBe(true);
|
|
336
|
+
expect(
|
|
337
|
+
claudeUnsafePath('/home/other/repo/.git', '/Users/me/repo', { ...mac, homeAutomount: false }),
|
|
338
|
+
).toBe(false);
|
|
339
|
+
expect(
|
|
340
|
+
claudeUnsafePath('/home/me/repo/.git', '/home/me/repo/.git/worktrees/w', {
|
|
341
|
+
...mac,
|
|
342
|
+
home: '/home/me',
|
|
343
|
+
}),
|
|
344
|
+
).toBe(false);
|
|
345
|
+
expect(claudeUnsafePath('/home/other/repo/.git', '/Users/me/repo', linux)).toBe(false);
|
|
346
|
+
// UNC spellings on another server, device paths and volfs roots.
|
|
347
|
+
expect(claudeUnsafePath('\\\\server\\share', '/srv/repo', linux)).toBe(true);
|
|
348
|
+
expect(claudeUnsafePath('//server/share/repo', '/srv/repo', linux)).toBe(true);
|
|
349
|
+
expect(claudeUnsafePath('/??/C:/repo', '/srv/repo', linux)).toBe(true);
|
|
350
|
+
expect(claudeUnsafePath('/.vol/1/2', '/srv/repo', mac)).toBe(true);
|
|
351
|
+
expect(claudeUnsafePath('/Network/Servers/h/repo', '/srv/repo', mac)).toBe(true);
|
|
352
|
+
expect(claudeUnsafePath('../..', '/srv/repo/.git/worktrees/w', mac)).toBe(false);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("judges /home automounts by the lead's HOME, not the parent's (T14520)", () => {
|
|
356
|
+
if (process.platform !== 'darwin') return;
|
|
357
|
+
const worktree = linkedWorktree();
|
|
358
|
+
const gitDir = readFileSync(join(worktree, '.git'), 'utf8').trim().slice(7).trim();
|
|
359
|
+
trustOnly(realpathSync(project));
|
|
360
|
+
// The parent's HOME owns /home/me; the lead Claude's HOME (root) does not.
|
|
361
|
+
vi.stubEnv('HOME', '/home/me');
|
|
362
|
+
const leadEnv = { HOME: root };
|
|
363
|
+
expect(requireLeadProjectTrust(worktree, leadEnv)).toBe(claudeJson);
|
|
364
|
+
writeFileSync(join(worktree, '.git'), `gitdir: /home/me/../..${gitDir}\n`);
|
|
365
|
+
expect(() => requireLeadProjectTrust(worktree, leadEnv)).toThrow(OrcaExecutionError);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('ignores a dangling .git link in a bare common directory, as Claude does (T14520)', () => {
|
|
369
|
+
if (process.platform === 'win32') return;
|
|
370
|
+
linkedWorktree();
|
|
371
|
+
const bare = join(realpathSync(root), 'bare.git');
|
|
372
|
+
const git = (...args: string[]): string =>
|
|
373
|
+
execFileSync('git', ['-c', 'core.hooksPath=', ...args], {
|
|
374
|
+
encoding: 'utf8',
|
|
375
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
376
|
+
});
|
|
377
|
+
git('clone', '--quiet', '--bare', '--template=', project, bare);
|
|
378
|
+
const worktree = join(realpathSync(root), 'bare-linked');
|
|
379
|
+
git('-C', bare, 'worktree', 'add', '--quiet', '--detach', worktree);
|
|
380
|
+
trustOnly(bare);
|
|
381
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
382
|
+
symlinkSync(join(root, 'missing'), join(bare, '.git'));
|
|
383
|
+
expect(requireLeadProjectTrust(worktree)).toBe(claudeJson);
|
|
384
|
+
rmSync(join(bare, '.git'));
|
|
385
|
+
mkdirSync(join(bare, '.git'));
|
|
386
|
+
expect(() => requireLeadProjectTrust(worktree)).toThrow(OrcaExecutionError);
|
|
387
|
+
});
|
|
388
|
+
|
|
236
389
|
it('does not inherit trust across a repository boundary or from a similarly named folder', () => {
|
|
237
390
|
mkdirSync(join(project, '.git'));
|
|
238
391
|
writeFileSync(
|