test(team): stabilize mcp builder workspace entry checks

This commit is contained in:
777genius 2026-04-12 00:07:31 +03:00
parent fb21b982c6
commit 08b7e53e77

View file

@ -88,6 +88,24 @@ describe('TeamMcpConfigBuilder', () => {
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(() => {
originalResourcesPath = (process as NodeJS.Process & { resourcesPath?: string }).resourcesPath;
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 () => {
const builtEntry = mockBuiltWorkspaceEntryAvailable();
const builder = new TeamMcpConfigBuilder();
const configPath = await builder.writeConfigFile();
@ -171,7 +190,7 @@ describe('TeamMcpConfigBuilder', () => {
};
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 () => {
@ -254,6 +273,7 @@ describe('TeamMcpConfigBuilder', () => {
});
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-'));
createdDirs.push(homeDir);
mockHomeDir = homeDir;
@ -279,7 +299,7 @@ describe('TeamMcpConfigBuilder', () => {
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 () => {
@ -485,6 +505,7 @@ describe('TeamMcpConfigBuilder', () => {
});
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');
const resourcesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'team-mcp-resources-'));
createdDirs.push(resourcesDir);
@ -494,6 +515,6 @@ describe('TeamMcpConfigBuilder', () => {
const configPath = await builder.writeConfigFile();
createdPaths.push(configPath);
expectNodeEntry(readGeneratedServer(configPath), path.join(process.cwd(), 'mcp-server', 'dist', 'index.js'));
expectNodeEntry(readGeneratedServer(configPath), builtEntry);
});
});