From 22908d474cf17b5f22fb6bd5ee8a036d9cc6f558 Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Mon, 9 Feb 2026 19:09:37 +0900 Subject: [PATCH] fix e2e --- e2e/helpers/test-repo.ts | 104 +++++++++++++++++++++++----------- e2e/specs/github-issue.e2e.ts | 2 +- e2e/specs/pipeline.e2e.ts | 2 +- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/e2e/helpers/test-repo.ts b/e2e/helpers/test-repo.ts index 6b07aa8..8c57f4e 100644 --- a/e2e/helpers/test-repo.ts +++ b/e2e/helpers/test-repo.ts @@ -11,6 +11,11 @@ export interface TestRepo { cleanup: () => void; } +export interface CreateTestRepoOptions { + /** Skip creating a test branch (stay on default branch). Use for pipeline tests. */ + skipBranch?: boolean; +} + function getGitHubUser(): string { const user = execFileSync('gh', ['api', 'user', '--jq', '.login'], { encoding: 'utf-8', @@ -33,7 +38,7 @@ function getGitHubUser(): string { * 2. Close any PRs created during the test * 3. Delete local directory */ -export function createTestRepo(): TestRepo { +export function createTestRepo(options?: CreateTestRepoOptions): TestRepo { const user = getGitHubUser(); const repoName = `${user}/takt-testing`; @@ -56,49 +61,80 @@ export function createTestRepo(): TestRepo { stdio: 'pipe', }); - // Create test branch - const testBranch = `e2e-test-${Date.now()}`; - execFileSync('git', ['checkout', '-b', testBranch], { - cwd: repoPath, - stdio: 'pipe', - }); + // Create test branch (unless skipped for pipeline tests) + const testBranch = options?.skipBranch + ? undefined + : `e2e-test-${Date.now()}`; + if (testBranch) { + execFileSync('git', ['checkout', '-b', testBranch], { + cwd: repoPath, + stdio: 'pipe', + }); + } + + const currentBranch = testBranch + ?? execFileSync('git', ['branch', '--show-current'], { + cwd: repoPath, + encoding: 'utf-8', + }).trim(); return { path: repoPath, repoName, - branch: testBranch, + branch: currentBranch, cleanup: () => { - // 1. Delete remote branch (best-effort) - try { - execFileSync( - 'git', - ['push', 'origin', '--delete', testBranch], - { cwd: repoPath, stdio: 'pipe' }, - ); - } catch { - // Branch may not have been pushed; ignore - } - - // 2. Close any PRs from this branch (best-effort) - try { - const prList = execFileSync( - 'gh', - ['pr', 'list', '--head', testBranch, '--repo', repoName, '--json', 'number', '--jq', '.[].number'], - { encoding: 'utf-8', stdio: 'pipe' }, - ).trim(); - - for (const prNumber of prList.split('\n').filter(Boolean)) { + if (testBranch) { + // 1. Delete remote branch (best-effort) + try { execFileSync( - 'gh', - ['pr', 'close', prNumber, '--repo', repoName, '--delete-branch'], - { stdio: 'pipe' }, + 'git', + ['push', 'origin', '--delete', testBranch], + { cwd: repoPath, stdio: 'pipe' }, ); + } catch { + // Branch may not have been pushed; ignore + } + + // 2. Close any PRs from this branch (best-effort) + try { + const prList = execFileSync( + 'gh', + ['pr', 'list', '--head', testBranch, '--repo', repoName, '--json', 'number', '--jq', '.[].number'], + { encoding: 'utf-8', stdio: 'pipe' }, + ).trim(); + + for (const prNumber of prList.split('\n').filter(Boolean)) { + execFileSync( + 'gh', + ['pr', 'close', prNumber, '--repo', repoName, '--delete-branch'], + { stdio: 'pipe' }, + ); + } + } catch { + // No PRs or already closed; ignore + } + } else { + // Pipeline mode: clean up takt-created PRs (best-effort) + try { + const prNumbers = execFileSync( + 'gh', + ['pr', 'list', '--state', 'open', '--repo', repoName, '--json', 'number', '--jq', '.[].number'], + { encoding: 'utf-8', stdio: 'pipe' }, + ).trim(); + + for (const prNumber of prNumbers.split('\n').filter(Boolean)) { + execFileSync( + 'gh', + ['pr', 'close', prNumber, '--repo', repoName, '--delete-branch'], + { stdio: 'pipe' }, + ); + } + } catch { + // ignore } - } catch { - // No PRs or already closed; ignore } - // 3. Delete local directory last + // Delete local directory last try { rmSync(repoPath, { recursive: true, force: true }); } catch { diff --git a/e2e/specs/github-issue.e2e.ts b/e2e/specs/github-issue.e2e.ts index 2ed1995..86ee439 100644 --- a/e2e/specs/github-issue.e2e.ts +++ b/e2e/specs/github-issue.e2e.ts @@ -17,7 +17,7 @@ describe('E2E: GitHub Issue processing', () => { beforeEach(() => { isolatedEnv = createIsolatedEnv(); - testRepo = createTestRepo(); + testRepo = createTestRepo({ skipBranch: true }); // Create a test issue const createOutput = execFileSync( diff --git a/e2e/specs/pipeline.e2e.ts b/e2e/specs/pipeline.e2e.ts index 1143953..3eb9b74 100644 --- a/e2e/specs/pipeline.e2e.ts +++ b/e2e/specs/pipeline.e2e.ts @@ -16,7 +16,7 @@ describe('E2E: Pipeline mode (--pipeline --auto-pr)', () => { beforeEach(() => { isolatedEnv = createIsolatedEnv(); - testRepo = createTestRepo(); + testRepo = createTestRepo({ skipBranch: true }); }); afterEach(() => {