test(team): stabilize mcp builder workspace entry checks
This commit is contained in:
parent
fb21b982c6
commit
08b7e53e77
1 changed files with 24 additions and 3 deletions
|
|
@ -88,6 +88,24 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
expect(server?.command).toMatch(/(^node$|[\\/]node(?:\.exe)?$)/);
|
expect(server?.command).toMatch(/(^node$|[\\/]node(?:\.exe)?$)/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mockPathExists(existingPaths: string[]): void {
|
||||||
|
const originalAccess = fs.promises.access.bind(fs.promises);
|
||||||
|
vi.spyOn(fs.promises, 'access').mockImplementation(async (targetPath, mode) => {
|
||||||
|
const normalizedPath =
|
||||||
|
typeof targetPath === 'string' ? targetPath : Buffer.isBuffer(targetPath) ? targetPath.toString() : `${targetPath}`;
|
||||||
|
if (existingPaths.includes(normalizedPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await originalAccess(targetPath, mode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockBuiltWorkspaceEntryAvailable(): string {
|
||||||
|
const builtEntry = path.join(process.cwd(), 'mcp-server', 'dist', 'index.js');
|
||||||
|
mockPathExists([builtEntry]);
|
||||||
|
return builtEntry;
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
originalResourcesPath = (process as NodeJS.Process & { resourcesPath?: string }).resourcesPath;
|
originalResourcesPath = (process as NodeJS.Process & { resourcesPath?: string }).resourcesPath;
|
||||||
tempAppData = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-appdata-'));
|
tempAppData = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-appdata-'));
|
||||||
|
|
@ -160,6 +178,7 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prefers the built workspace MCP entry when available', async () => {
|
it('prefers the built workspace MCP entry when available', async () => {
|
||||||
|
const builtEntry = mockBuiltWorkspaceEntryAvailable();
|
||||||
const builder = new TeamMcpConfigBuilder();
|
const builder = new TeamMcpConfigBuilder();
|
||||||
|
|
||||||
const configPath = await builder.writeConfigFile();
|
const configPath = await builder.writeConfigFile();
|
||||||
|
|
@ -171,7 +190,7 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = parsed.mcpServers?.['agent-teams'];
|
const server = parsed.mcpServers?.['agent-teams'];
|
||||||
expectNodeEntry(server, path.join(process.cwd(), 'mcp-server', 'dist', 'index.js'));
|
expectNodeEntry(server, builtEntry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps generated team MCP config minimal and does not inline top-level user MCP', async () => {
|
it('keeps generated team MCP config minimal and does not inline top-level user MCP', async () => {
|
||||||
|
|
@ -254,6 +273,7 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generated agent-teams server ignores same-named user MCP entry', async () => {
|
it('generated agent-teams server ignores same-named user MCP entry', async () => {
|
||||||
|
const builtEntry = mockBuiltWorkspaceEntryAvailable();
|
||||||
const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-home-'));
|
const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-home-'));
|
||||||
createdDirs.push(homeDir);
|
createdDirs.push(homeDir);
|
||||||
mockHomeDir = homeDir;
|
mockHomeDir = homeDir;
|
||||||
|
|
@ -279,7 +299,7 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
mcpServers: Record<string, { command?: string; args?: string[] }>;
|
mcpServers: Record<string, { command?: string; args?: string[] }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
expectNodeEntry(parsed.mcpServers['agent-teams'], path.join(process.cwd(), 'mcp-server', 'dist', 'index.js'));
|
expectNodeEntry(parsed.mcpServers['agent-teams'], builtEntry);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores malformed user MCP file', async () => {
|
it('ignores malformed user MCP file', async () => {
|
||||||
|
|
@ -485,6 +505,7 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('packaged mode falls back to the built workspace MCP entry when resourcesPath bundle is missing', async () => {
|
it('packaged mode falls back to the built workspace MCP entry when resourcesPath bundle is missing', async () => {
|
||||||
|
const builtEntry = mockBuiltWorkspaceEntryAvailable();
|
||||||
setPackagedMode(true, '6.0.0');
|
setPackagedMode(true, '6.0.0');
|
||||||
const resourcesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-resources-'));
|
const resourcesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-resources-'));
|
||||||
createdDirs.push(resourcesDir);
|
createdDirs.push(resourcesDir);
|
||||||
|
|
@ -494,6 +515,6 @@ describe('TeamMcpConfigBuilder', () => {
|
||||||
const configPath = await builder.writeConfigFile();
|
const configPath = await builder.writeConfigFile();
|
||||||
createdPaths.push(configPath);
|
createdPaths.push(configPath);
|
||||||
|
|
||||||
expectNodeEntry(readGeneratedServer(configPath), path.join(process.cwd(), 'mcp-server', 'dist', 'index.js'));
|
expectNodeEntry(readGeneratedServer(configPath), builtEntry);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue