refactor(e2e): extract infrastructure into tests/e2e/infra/ module
- Move fixtures.ts, llm-judge.ts, results-db.ts to tests/e2e/infra/ - Deduplicate wdio.conf.js: use createTestFixture() instead of inline copy - Replace __dirname paths with projectRoot-anchored paths - Create test-mode-constants.ts (typed env var names, flag registry) - Create scripts/preflight-check.sh (validates tauri-driver, display, Claude CLI) - Create scripts/check-test-flags.sh (CI lint for AGOR_TEST flag drift) - Rewrite tests/e2e/README.md with full documentation - Update spec imports for moved infra files
This commit is contained in:
parent
538a31f85c
commit
e76bc341f2
10 changed files with 235 additions and 191 deletions
142
tests/e2e/infra/fixtures.ts
Normal file
142
tests/e2e/infra/fixtures.ts
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
// Test fixture generator — creates isolated test environments
|
||||
// Used by E2E tests to set up temp data/config dirs with valid groups.json
|
||||
|
||||
import { mkdirSync, writeFileSync, rmSync, existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
export interface TestFixture {
|
||||
/** Root temp directory for this test run */
|
||||
rootDir: string;
|
||||
/** AGOR_TEST_DATA_DIR — isolated data dir */
|
||||
dataDir: string;
|
||||
/** AGOR_TEST_CONFIG_DIR — isolated config dir */
|
||||
configDir: string;
|
||||
/** Path to a minimal git repo for agent testing */
|
||||
projectDir: string;
|
||||
/** Environment variables to pass to the app */
|
||||
env: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an isolated test fixture with:
|
||||
* - Temp data dir (sessions.db, btmsg.db created at runtime)
|
||||
* - Temp config dir with a minimal groups.json
|
||||
* - A simple git repo with one file for agent testing
|
||||
*/
|
||||
export function createTestFixture(name = 'agor-e2e'): TestFixture {
|
||||
const rootDir = join(tmpdir(), `${name}-${Date.now()}`);
|
||||
const dataDir = join(rootDir, 'data');
|
||||
const configDir = join(rootDir, 'config');
|
||||
const projectDir = join(rootDir, 'test-project');
|
||||
|
||||
// Create directory structure
|
||||
mkdirSync(dataDir, { recursive: true });
|
||||
mkdirSync(configDir, { recursive: true });
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
// Create a minimal git repo for agent testing
|
||||
execSync('git init', { cwd: projectDir, stdio: 'ignore' });
|
||||
execSync('git config user.email "test@agor.dev"', { cwd: projectDir, stdio: 'ignore' });
|
||||
execSync('git config user.name "Agor Test"', { cwd: projectDir, stdio: 'ignore' });
|
||||
writeFileSync(join(projectDir, 'README.md'), '# Test Project\n\nA simple test project for Agor E2E tests.\n');
|
||||
writeFileSync(join(projectDir, 'hello.py'), 'def greet(name: str) -> str:\n return f"Hello, {name}!"\n');
|
||||
execSync('git add -A && git commit -m "initial commit"', { cwd: projectDir, stdio: 'ignore' });
|
||||
|
||||
// Write groups.json with one group containing the test project
|
||||
const groupsJson = {
|
||||
version: 1,
|
||||
groups: [
|
||||
{
|
||||
id: 'test-group',
|
||||
name: 'Test Group',
|
||||
projects: [
|
||||
{
|
||||
id: 'test-project',
|
||||
name: 'Test Project',
|
||||
identifier: 'test-project',
|
||||
description: 'E2E test project',
|
||||
icon: '\uf120',
|
||||
cwd: projectDir,
|
||||
profile: 'default',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
agents: [],
|
||||
},
|
||||
],
|
||||
activeGroupId: 'test-group',
|
||||
};
|
||||
|
||||
writeFileSync(
|
||||
join(configDir, 'groups.json'),
|
||||
JSON.stringify(groupsJson, null, 2),
|
||||
);
|
||||
|
||||
const env: Record<string, string> = {
|
||||
AGOR_TEST: '1',
|
||||
AGOR_TEST_DATA_DIR: dataDir,
|
||||
AGOR_TEST_CONFIG_DIR: configDir,
|
||||
};
|
||||
|
||||
return { rootDir, dataDir, configDir, projectDir, env };
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up a test fixture's temporary directories.
|
||||
*/
|
||||
export function destroyTestFixture(fixture: TestFixture): void {
|
||||
if (existsSync(fixture.rootDir)) {
|
||||
rmSync(fixture.rootDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a groups.json with multiple projects for multi-project testing.
|
||||
*/
|
||||
export function createMultiProjectFixture(projectCount = 3): TestFixture {
|
||||
const fixture = createTestFixture('agor-multi');
|
||||
|
||||
const projects = [];
|
||||
for (let i = 0; i < projectCount; i++) {
|
||||
const projDir = join(fixture.rootDir, `project-${i}`);
|
||||
mkdirSync(projDir, { recursive: true });
|
||||
execSync('git init', { cwd: projDir, stdio: 'ignore' });
|
||||
execSync('git config user.email "test@agor.dev"', { cwd: projDir, stdio: 'ignore' });
|
||||
execSync('git config user.name "Agor Test"', { cwd: projDir, stdio: 'ignore' });
|
||||
writeFileSync(join(projDir, 'README.md'), `# Project ${i}\n`);
|
||||
execSync('git add -A && git commit -m "init"', { cwd: projDir, stdio: 'ignore' });
|
||||
|
||||
projects.push({
|
||||
id: `project-${i}`,
|
||||
name: `Project ${i}`,
|
||||
identifier: `project-${i}`,
|
||||
description: `Test project ${i}`,
|
||||
icon: '\uf120',
|
||||
cwd: projDir,
|
||||
profile: 'default',
|
||||
enabled: true,
|
||||
});
|
||||
}
|
||||
|
||||
const groupsJson = {
|
||||
version: 1,
|
||||
groups: [
|
||||
{
|
||||
id: 'multi-group',
|
||||
name: 'Multi Project Group',
|
||||
projects,
|
||||
agents: [],
|
||||
},
|
||||
],
|
||||
activeGroupId: 'multi-group',
|
||||
};
|
||||
|
||||
writeFileSync(
|
||||
join(fixture.configDir, 'groups.json'),
|
||||
JSON.stringify(groupsJson, null, 2),
|
||||
);
|
||||
|
||||
return fixture;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue