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>
211 lines
8.0 KiB
TypeScript
211 lines
8.0 KiB
TypeScript
/**
|
|
* Test: CodexInstaller
|
|
* Tests OpenAI Codex CLI TOML MCP config and AGENTS.md 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('CodexInstaller', () => {
|
|
const projectRoot = '/test/project';
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('install() - fresh project', () => {
|
|
beforeEach(() => {
|
|
mockExistsSync.mockReturnValue(false);
|
|
});
|
|
|
|
it('creates .codex/config.toml with TOML MCP config', async () => {
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('config.toml')
|
|
);
|
|
expect(configCall).toBeDefined();
|
|
const content = configCall![1] as string;
|
|
expect(content).toContain('[mcp_servers.agentic-qe]');
|
|
expect(content).toContain('type = "stdio"');
|
|
expect(content).toContain('command = "npx"');
|
|
expect(content).toContain('AQE_V3_MODE');
|
|
});
|
|
|
|
it('creates AGENTS.md behavioral rules', async () => {
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
const rulesCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('AGENTS.md')
|
|
);
|
|
expect(rulesCall).toBeDefined();
|
|
expect(rulesCall![1]).toContain('Quality Engineering Standards');
|
|
expect(rulesCall![1]).toContain('fleet_init');
|
|
});
|
|
|
|
it('creates .codex/ directory', async () => {
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
expect(mockMkdirSync).toHaveBeenCalledWith(
|
|
join(projectRoot, '.codex'),
|
|
{ recursive: true }
|
|
);
|
|
});
|
|
|
|
it('returns success with correct result shape', async () => {
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
const result = await installer.install();
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(result.mcpConfigured).toBe(true);
|
|
expect(result.agentsMdInstalled).toBe(true);
|
|
expect(result.errors).toEqual([]);
|
|
expect(result.configPath).toBe(join(projectRoot, '.codex/config.toml'));
|
|
expect(result.agentsMdPath).toBe(join(projectRoot, 'AGENTS.md'));
|
|
});
|
|
|
|
it('generates valid TOML syntax', async () => {
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('config.toml')
|
|
);
|
|
const content = configCall![1] as string;
|
|
// Verify TOML key-value pairs
|
|
expect(content).toMatch(/^\[mcp_servers\.agentic-qe\]$/m);
|
|
expect(content).toMatch(/^command = "npx"$/m);
|
|
expect(content).toMatch(/^args = \["-y", "agentic-qe@latest", "mcp"\]$/m);
|
|
expect(content).toMatch(/^\[mcp_servers\.agentic-qe\.env\]$/m);
|
|
});
|
|
});
|
|
|
|
describe('install() - existing files', () => {
|
|
it('skips when files exist and overwrite is false', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot, overwrite: false });
|
|
const result = await installer.install();
|
|
|
|
expect(result.mcpConfigured).toBe(false);
|
|
expect(result.agentsMdInstalled).toBe(false);
|
|
expect(mockWriteFileSync).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('appends to existing TOML when overwrite is true', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
const existingToml = `[model]
|
|
default = "gpt-4"
|
|
`;
|
|
mockReadFileSync.mockReturnValue(existingToml);
|
|
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot, overwrite: true });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('config.toml')
|
|
);
|
|
expect(configCall).toBeDefined();
|
|
const content = configCall![1] as string;
|
|
// Should contain both original and new content
|
|
expect(content).toContain('[model]');
|
|
expect(content).toContain('[mcp_servers.agentic-qe]');
|
|
});
|
|
|
|
it('skips TOML merge if agentic-qe already present', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
const existingToml = `[mcp_servers.agentic-qe]
|
|
type = "stdio"
|
|
command = "npx"
|
|
`;
|
|
mockReadFileSync.mockReturnValue(existingToml);
|
|
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot, overwrite: true });
|
|
await installer.install();
|
|
|
|
const configCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('config.toml')
|
|
);
|
|
const content = configCall![1] as string;
|
|
// Should return existing content unchanged
|
|
expect(content).toBe(existingToml);
|
|
});
|
|
|
|
it('appends to existing AGENTS.md when overwrite is true', async () => {
|
|
mockExistsSync.mockReturnValue(true);
|
|
const existingAgentsMd = '# My Project Agents\n\nCustom instructions here.';
|
|
mockReadFileSync.mockReturnValue(existingAgentsMd);
|
|
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot, overwrite: true });
|
|
await installer.install();
|
|
|
|
const rulesCall = mockWriteFileSync.mock.calls.find(
|
|
(c: unknown[]) => (c[0] as string).endsWith('AGENTS.md')
|
|
);
|
|
expect(rulesCall).toBeDefined();
|
|
const content = rulesCall![1] as string;
|
|
expect(content).toContain('My Project Agents');
|
|
expect(content).toContain('Quality Engineering Standards');
|
|
});
|
|
});
|
|
|
|
describe('install() - error handling', () => {
|
|
it('catches fs errors and returns success: false', async () => {
|
|
mockExistsSync.mockReturnValue(false);
|
|
mockMkdirSync.mockImplementation(() => {
|
|
throw new Error('Permission denied');
|
|
});
|
|
|
|
const { createCodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
const result = await installer.install();
|
|
|
|
expect(result.success).toBe(false);
|
|
expect(result.errors.length).toBeGreaterThan(0);
|
|
expect(result.errors[0]).toContain('Codex installation failed');
|
|
});
|
|
});
|
|
|
|
describe('createCodexInstaller()', () => {
|
|
it('returns a CodexInstaller instance', async () => {
|
|
const { createCodexInstaller, CodexInstaller } = await import('../../../src/init/codex-installer.js');
|
|
const installer = createCodexInstaller({ projectRoot });
|
|
expect(installer).toBeInstanceOf(CodexInstaller);
|
|
});
|
|
});
|
|
});
|