test: strengthen claude import coverage
This commit is contained in:
parent
54fdc85607
commit
b8687aec1d
@ -235,7 +235,9 @@ function resolveContainerDescriptor(
|
||||
// For claude-code, only allow root fallback for legacy root-style files (.claude.json, .claude/mcp.json).
|
||||
// Settings files like .claude/settings.json require proper mcpServers/servers/mcp containers.
|
||||
if (importKind === 'claude-code' && filePath) {
|
||||
const allowRootFallback = filePath.endsWith('.claude.json') || filePath.endsWith(`${path.sep}mcp.json`);
|
||||
const normalized = path.normalize(filePath);
|
||||
const allowRootFallback =
|
||||
normalized.endsWith('.claude.json') || normalized.endsWith(`${path.sep}.claude${path.sep}mcp.json`);
|
||||
return {
|
||||
allowMcpServers: true,
|
||||
allowServers: true,
|
||||
|
||||
@ -258,6 +258,61 @@ describe('config import helpers', () => {
|
||||
expect(entries?.has('folder-server')).toBe(true);
|
||||
});
|
||||
|
||||
it('disallows root fallback for mcp.json outside .claude', async () => {
|
||||
const nestedDir = path.join(TEMP_DIR, 'nested');
|
||||
await fs.mkdir(nestedDir, { recursive: true });
|
||||
const jsonPath = path.join(nestedDir, 'mcp.json');
|
||||
await fs.writeFile(
|
||||
jsonPath,
|
||||
JSON.stringify({
|
||||
stray: {
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
},
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
const entries = await readExternalEntries(jsonPath, { importKind: 'claude-code' });
|
||||
expect(entries?.size ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('ignores settings.local.json metadata without containers', async () => {
|
||||
const claudeDir = path.join(TEMP_DIR, '.claude');
|
||||
await fs.mkdir(claudeDir, { recursive: true });
|
||||
const jsonPath = path.join(claudeDir, 'settings.local.json');
|
||||
await fs.writeFile(
|
||||
jsonPath,
|
||||
JSON.stringify({
|
||||
statusLine: { type: 'command', command: 'bash script.sh' },
|
||||
tipsHistory: { shown: ['tip1', 'tip2'] },
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
const entries = await readExternalEntries(jsonPath, { importKind: 'claude-code' });
|
||||
expect(entries?.size ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('respects settings.local.json containers when present', async () => {
|
||||
const claudeDir = path.join(TEMP_DIR, '.claude');
|
||||
await fs.mkdir(claudeDir, { recursive: true });
|
||||
const jsonPath = path.join(claudeDir, 'settings.local.json');
|
||||
await fs.writeFile(
|
||||
jsonPath,
|
||||
JSON.stringify({
|
||||
mcpServers: {
|
||||
'local-server': {
|
||||
command: 'node',
|
||||
args: ['server.js'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
const entries = await readExternalEntries(jsonPath, { importKind: 'claude-code' });
|
||||
expect(entries?.size).toBe(1);
|
||||
expect(entries?.has('local-server')).toBe(true);
|
||||
});
|
||||
|
||||
it('uses mcpServers container in settings.json when present', async () => {
|
||||
await fs.mkdir(TEMP_DIR, { recursive: true });
|
||||
const jsonPath = path.join(TEMP_DIR, 'settings.json');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user