mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
2253d05618
Remove the nested v3/ subdirectory by moving all active source code, tests, configs, and assets directly to the project root. Archive v2/ (dead code, 847MB) to v2-archive.tar.gz. Key changes: - Move v3/src/ → src/, v3/tests/ → tests/, v3/packages/ → packages/ - Move v3/tsconfig.json, v3/vitest.config.ts to root - Merge v3/package.json into root package.json (ESM, scripts, deps, exports) - Merge v3/scripts/ into scripts/, v3/implementation/ into docs/implementation/ - Update all CI workflows to remove "cd v3 &&" and v3/ path prefixes - Fix all init installer path resolution (3-level-up → 2-level-up) - Fix hooks to use "node ./dist/cli/bundle.js" instead of bare "aqe" - Update settings.json ADR/DDD directories to docs/implementation/ - Fix helper scripts (statusline, adr-compliance, ddd-tracker, guidance-hooks) - Update 58 agent definitions: aqe/v3/ → aqe/ memory namespaces - Update 15 guidance shards: v3/src/ → src/ path references - Fix sync interfaces: remove v3/ and v2/ path references - Fix test path calculations (process.cwd() + '..' no longer needed) - Fix flaky perf test threshold (500ms → 1000ms for CI environments) - Fix complexity-analyzer test to match ADR-051 keyword-based eligibility Build passes, 17,901 tests pass, CLI and MCP bundles verified. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
178 lines
6.6 KiB
TypeScript
178 lines
6.6 KiB
TypeScript
/**
|
|
* Test: CopilotInstaller
|
|
* Tests GitHub Copilot MCP config and behavioral rules installation.
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { join } from 'path';
|
|
|
|
vi.mock('fs', async () => {
|
|
const actual = await vi.importActual<typeof import('fs')>('fs');
|
|
return {
|
|
...actual,
|
|
existsSync: vi.fn(),
|
|
mkdirSync: vi.fn(),
|
|
writeFileSync: vi.fn(),
|
|
readFileSync: vi.fn(),
|
|
};
|
|
});
|
|
|
|
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
|
|
const mockExistsSync = existsSync as ReturnType<typeof vi.fn>;
|
|
const mockMkdirSync = mkdirSync as ReturnType<typeof vi.fn>;
|
|
const mockWriteFileSync = writeFileSync as ReturnType<typeof vi.fn>;
|
|
const mockReadFileSync = readFileSync as ReturnType<typeof vi.fn>;
|
|
|
|
describe('CopilotInstaller', () => {
|
|
const projectRoot = '/test/project';
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('install() - fresh project', () => {
|
|
beforeEach(() => {
|
|
// Nothing exists yet
|
|
mockExistsSync.mockReturnValue(false);
|
|
});
|
|
|
|
it('creates .vscode/mcp.json with servers key', async () => {
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('mcp.json')
|
|
);
|
|
expect(configCall).toBeDefined();
|
|
const parsed = JSON.parse(configCall![1] as string);
|
|
expect(parsed).toHaveProperty('servers');
|
|
expect(parsed.servers).toHaveProperty('agentic-qe');
|
|
});
|
|
|
|
it('creates .github/copilot-instructions.md', async () => {
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
const rulesCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('copilot-instructions.md')
|
|
);
|
|
expect(rulesCall).toBeDefined();
|
|
expect(rulesCall![1]).toContain('Quality Engineering Standards');
|
|
});
|
|
|
|
it('creates .vscode/ and .github/ directories', async () => {
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
expect(mockMkdirSync).toHaveBeenCalledWith(
|
|
join(projectRoot, '.vscode'),
|
|
{ recursive: true }
|
|
);
|
|
expect(mockMkdirSync).toHaveBeenCalledWith(
|
|
join(projectRoot, '.github'),
|
|
{ recursive: true }
|
|
);
|
|
});
|
|
|
|
it('returns success with correct result shape', async () => {
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
const result = await installer.install();
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.mcpConfigured).toBe(true);
|
|
expect(result.rulesInstalled).toBe(true);
|
|
expect(result.errors).toEqual([]);
|
|
expect(result.configPath).toBe(join(projectRoot, '.vscode/mcp.json'));
|
|
expect(result.rulesPath).toBe(join(projectRoot, '.github/copilot-instructions.md'));
|
|
});
|
|
});
|
|
|
|
describe('install() - existing files', () => {
|
|
it('skips when files exist and overwrite is false', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot, overwrite: false });
|
|
const result = await installer.install();
|
|
|
|
expect(result.mcpConfigured).toBe(false);
|
|
expect(result.rulesInstalled).toBe(false);
|
|
expect(mockWriteFileSync).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('merges when overwrite is true and config exists', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
const existingConfig = JSON.stringify({
|
|
servers: { 'other-server': { command: 'other' } },
|
|
});
|
|
mockReadFileSync.mockReturnValue(existingConfig);
|
|
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot, overwrite: true });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('mcp.json')
|
|
);
|
|
expect(configCall).toBeDefined();
|
|
const parsed = JSON.parse(configCall![1] as string);
|
|
expect(parsed.servers).toHaveProperty('other-server');
|
|
expect(parsed.servers).toHaveProperty('agentic-qe');
|
|
});
|
|
|
|
it('preserves existing servers entries during merge', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
const existingConfig = JSON.stringify({
|
|
servers: { 'custom-tool': { command: 'npx', args: ['custom'] } },
|
|
extraField: true,
|
|
});
|
|
mockReadFileSync.mockReturnValue(existingConfig);
|
|
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot, overwrite: true });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('mcp.json')
|
|
);
|
|
const parsed = JSON.parse(configCall![1] as string);
|
|
expect(parsed.servers['custom-tool']).toEqual({ command: 'npx', args: ['custom'] });
|
|
expect(parsed.extraField).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('install() - error handling', () => {
|
|
it('catches fs errors and returns success: false', async () => {
|
|
mockExistsSync.mockReturnValue(false);
|
|
mockMkdirSync.mockImplementation(() => {
|
|
throw new Error('Permission denied');
|
|
});
|
|
|
|
const { createCopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
const result = await installer.install();
|
|
|
|
expect(result.success).toBe(false);
|
|
expect(result.errors.length).toBeGreaterThan(0);
|
|
expect(result.errors[0]).toContain('Copilot installation failed');
|
|
});
|
|
});
|
|
|
|
describe('createCopilotInstaller()', () => {
|
|
it('returns a CopilotInstaller instance', async () => {
|
|
const { createCopilotInstaller, CopilotInstaller } = await import('../../../src/init/copilot-installer.js');
|
|
const installer = createCopilotInstaller({ projectRoot });
|
|
expect(installer).toBeInstanceOf(CopilotInstaller);
|
|
});
|
|
});
|
|
});
|