createPullRequest の全呼び出し箇所で base が未指定だったため、 PR が常にリポジトリデフォルトブランチ(main)向けに作成されていた。 ブランチ作成/clone作成の直前に getCurrentBranch() で元ブランチを 取得し、PR作成時に base として渡すように修正。
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
/**
|
|
* Tests for getCurrentBranch
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { execFileSync } from 'node:child_process';
|
|
|
|
vi.mock('node:child_process', () => ({
|
|
execFileSync: vi.fn(),
|
|
}));
|
|
|
|
const mockExecFileSync = vi.mocked(execFileSync);
|
|
|
|
import { getCurrentBranch } from '../infra/task/git.js';
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('getCurrentBranch', () => {
|
|
it('should return the current branch name', () => {
|
|
// Given
|
|
mockExecFileSync.mockReturnValue('feature/my-branch\n');
|
|
|
|
// When
|
|
const result = getCurrentBranch('/project');
|
|
|
|
// Then
|
|
expect(result).toBe('feature/my-branch');
|
|
expect(mockExecFileSync).toHaveBeenCalledWith(
|
|
'git',
|
|
['rev-parse', '--abbrev-ref', 'HEAD'],
|
|
{ cwd: '/project', encoding: 'utf-8', stdio: 'pipe' },
|
|
);
|
|
});
|
|
|
|
it('should trim whitespace from output', () => {
|
|
// Given
|
|
mockExecFileSync.mockReturnValue(' main \n');
|
|
|
|
// When
|
|
const result = getCurrentBranch('/project');
|
|
|
|
// Then
|
|
expect(result).toBe('main');
|
|
});
|
|
|
|
it('should propagate errors from git', () => {
|
|
// Given
|
|
mockExecFileSync.mockImplementation(() => {
|
|
throw new Error('not a git repository');
|
|
});
|
|
|
|
// When / Then
|
|
expect(() => getCurrentBranch('/not-a-repo')).toThrow('not a git repository');
|
|
});
|
|
});
|