diff --git a/tests/e2e/global-setup.ts b/tests/e2e/global-setup.ts index 24474fc8657..05de880d5f8 100644 --- a/tests/e2e/global-setup.ts +++ b/tests/e2e/global-setup.ts @@ -90,6 +90,13 @@ export default function globalSetup(): void { prepareDockerSshHostImage(root) } + const testRepoDir = seedTestRepository() + writeFileSync(TEST_REPO_PATH_FILE, testRepoDir) + console.error(`[e2e] Test repo created at ${testRepoDir}`) +} + +// Shared by global setup and worker fallbacks so both seed paths stay identical. +export function seedTestRepository(): string { // Resolve macOS /var symlinks like git does when registering repo.path. const testRepoDir = realpathSync(mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-repo-'))) @@ -112,16 +119,18 @@ export default function globalSetup(): void { writeFileSync(path.join(testRepoDir, 'src', 'diff-note-layout.ts'), 'export const seed = true\n') execSync('git add -A', { cwd: testRepoDir, stdio: 'pipe' }) - execSync('git commit -m "Initial commit for E2E tests"', { cwd: testRepoDir, stdio: 'pipe' }) - - // Seed a second worktree so retention/switching specs run instead of skipping. - const worktreeDir = path.join(testRepoDir, '..', `orca-e2e-worktree-${randomUUID()}`) - execSync(`git worktree add "${worktreeDir}" -b e2e-secondary`, { + // Why: per-command -c so contributor global hooks/signing can't fail the seed without persisting into repo config. + const isolatedGit = 'git -c core.hooksPath=/dev/null -c commit.gpgsign=false' + execSync(`${isolatedGit} commit -m "Initial commit for E2E tests"`, { cwd: testRepoDir, stdio: 'pipe' }) - console.error(`[e2e] Secondary worktree created at ${worktreeDir}`) - writeFileSync(TEST_REPO_PATH_FILE, testRepoDir) - console.error(`[e2e] Test repo created at ${testRepoDir}`) + // Seed a second worktree so retention/switching specs run; UUIDs keep concurrent workers apart. + const worktreeDir = path.join(testRepoDir, '..', `orca-e2e-worktree-${randomUUID()}`) + execSync(`${isolatedGit} worktree add "${worktreeDir}" -b e2e-secondary`, { + cwd: testRepoDir, + stdio: 'pipe' + }) + return testRepoDir } diff --git a/tests/e2e/helpers/seeded-test-repo.ts b/tests/e2e/helpers/seeded-test-repo.ts index 1334ce32003..5c02c6e7357 100644 --- a/tests/e2e/helpers/seeded-test-repo.ts +++ b/tests/e2e/helpers/seeded-test-repo.ts @@ -1,17 +1,6 @@ -import { - existsSync, - mkdirSync, - mkdtempSync, - readFileSync, - realpathSync, - rmSync, - writeFileSync -} from 'node:fs' +import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { execSync } from 'node:child_process' -import { randomUUID } from 'node:crypto' -import os from 'node:os' -import path from 'node:path' -import { TEST_REPO_PATH_FILE } from '../global-setup' +import { seedTestRepository, TEST_REPO_PATH_FILE } from '../global-setup' import { cleanupTestRepository } from '../global-teardown' export async function provideWorkerTestRepository( @@ -50,37 +39,7 @@ export function isValidGitRepo(repoPath: string): boolean { } export function createSeededTestRepo(options: { publishPath?: boolean } = {}): string { - // Canonicalize macOS /var symlinks to match Git’s repo.path after add. - const testRepoDir = realpathSync(mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-repo-'))) - - execSync('git init', { cwd: testRepoDir, stdio: 'pipe' }) - execSync('git config user.email "e2e@test.local"', { cwd: testRepoDir, stdio: 'pipe' }) - execSync('git config user.name "E2E Test"', { cwd: testRepoDir, stdio: 'pipe' }) - - writeFileSync( - path.join(testRepoDir, 'README.md'), - '# Orca E2E Test Repo\n\nThis repo was created automatically for Playwright tests.\n' - ) - writeFileSync(path.join(testRepoDir, 'CLAUDE.md'), '# CLAUDE.md\n\nTest instructions for E2E.\n') - writeFileSync( - path.join(testRepoDir, 'package.json'), - `${JSON.stringify({ name: 'orca-e2e-test', version: '0.0.0', private: true }, null, 2)}\n` - ) - writeFileSync(path.join(testRepoDir, '.gitignore'), 'node_modules/\n') - mkdirSync(path.join(testRepoDir, 'src'), { recursive: true }) - writeFileSync(path.join(testRepoDir, 'src', 'index.ts'), 'export const hello = "world"\n') - writeFileSync(path.join(testRepoDir, 'src', 'diff-note-layout.ts'), 'export const seed = true\n') - - execSync('git add -A', { cwd: testRepoDir, stdio: 'pipe' }) - execSync('git commit -m "Initial commit for E2E tests"', { cwd: testRepoDir, stdio: 'pipe' }) - - // Worker-scoped fallbacks can run together; UUIDs prevent temp worktree collisions. - const worktreeDir = path.join(testRepoDir, '..', `orca-e2e-worktree-${randomUUID()}`) - execSync(`git worktree add "${worktreeDir}" -b e2e-secondary`, { - cwd: testRepoDir, - stdio: 'pipe' - }) - + const testRepoDir = seedTestRepository() if (options.publishPath !== false) { writeFileSync(TEST_REPO_PATH_FILE, testRepoDir) }