import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { validateSquadMcps, getConfiguredMcpIds } from '../validate.js';
import fs from 'fs';
import path from 'path';
import os from 'os';
let tmpDir;
beforeEach(() => {
    tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mcp-validate-test-'));
});
afterEach(() => {
    fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe('getConfiguredMcpIds', () => {
    it('returns MCP IDs from .mcp.json', () => {
        fs.writeFileSync(path.join(tmpDir, '.mcp.json'), JSON.stringify({
            mcpServers: { github: { command: 'x', args: [], env: {} }, slack: { command: 'x', args: [], env: {} } },
        }));
        expect(getConfiguredMcpIds(tmpDir)).toEqual(['github', 'slack']);
    });
    it('returns empty array when .mcp.json missing', () => {
        expect(getConfiguredMcpIds(tmpDir)).toEqual([]);
    });
});
describe('validateSquadMcps', () => {
    it('passes when squad has no mcps field', () => {
        expect(() => validateSquadMcps(undefined, ['github'])).not.toThrow();
    });
    it('passes when squad has empty mcps', () => {
        expect(() => validateSquadMcps([], ['github'])).not.toThrow();
    });
    it('passes when all required MCPs are configured', () => {
        expect(() => validateSquadMcps(['github', 'slack'], ['github', 'slack', 'sentry'])).not.toThrow();
    });
    it('throws when required MCP is not configured', () => {
        expect(() => validateSquadMcps(['github', 'linear'], ['github']))
            .toThrow(/linear/i);
    });
    it('includes setup command in error message', () => {
        expect(() => validateSquadMcps(['linear'], []))
            .toThrow(/expxagents mcp setup/i);
    });
});
