fix e2e
This commit is contained in:
parent
fdcce2e425
commit
22908d474c
@ -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,18 +61,29 @@ export function createTestRepo(): TestRepo {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
|
||||
// Create test branch
|
||||
const testBranch = `e2e-test-${Date.now()}`;
|
||||
// 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: () => {
|
||||
if (testBranch) {
|
||||
// 1. Delete remote branch (best-effort)
|
||||
try {
|
||||
execFileSync(
|
||||
@ -97,8 +113,28 @@ export function createTestRepo(): TestRepo {
|
||||
} 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();
|
||||
|
||||
// 3. Delete local directory last
|
||||
for (const prNumber of prNumbers.split('\n').filter(Boolean)) {
|
||||
execFileSync(
|
||||
'gh',
|
||||
['pr', 'close', prNumber, '--repo', repoName, '--delete-branch'],
|
||||
{ stdio: 'pipe' },
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Delete local directory last
|
||||
try {
|
||||
rmSync(repoPath, { recursive: true, force: true });
|
||||
} catch {
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -16,7 +16,7 @@ describe('E2E: Pipeline mode (--pipeline --auto-pr)', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
isolatedEnv = createIsolatedEnv();
|
||||
testRepo = createTestRepo();
|
||||
testRepo = createTestRepo({ skipBranch: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user