Adds two interlocking PBIs:
PBI-9 — Worktree foundation + persistent product-worktrees for idea-jobs
- src/git/worktree-paths.ts: centralised root + skip-set + lock-path helpers
- src/git/file-lock.ts: proper-lockfile wrapper, deadlock-safe ordered acquire
- src/git/product-worktree.ts: detached-HEAD worktree per product, .scratch/
excluded via git rev-parse --git-path (handles linked .git file)
- src/git/job-locks.ts: setupProductWorktrees + releaseLocksOnTerminal
- wait-for-job.ts: idea-branch wires product-worktrees for IDEA_GRILL/MAKE_PLAN
- update-job-status.ts + pbi-cascade.ts + stale-reset: release on all four
server-side terminal transitions (DONE/FAILED/CANCELLED/stale)
- cleanup-my-worktrees: skip _products/ + *.lock
- README: worktrees section with single-host invariant + advisory-lock path
PBI-47 — Sprint-flow P0 corrections + PAUSED flow with rich pause_context
- prisma schema: ClaudeJob.{base_sha,head_sha} + SprintRun.pause_context
- tryClaimJob captures base_sha; prepareDoneUpdate captures head_sha
- verify-task-against-plan diffs vs base_sha (no more origin/main fallback);
rejects with MISSING_BASE_SHA when null — fixes per-task verify-scope P0
- pr.ts: createPullRequest enableAutoMerge default false; new
enableAutoMergeOnPr with --match-head-commit guard + 5-category typed
EnableAutoMergeResult — fixes STORY auto-merge timing P0
- src/flow/{effects,worktree-lease,pr-flow,sprint-run}.ts: pure transition
modules + idempotent declarative effects executor
- update-job-status: STORY auto-merge fires only on the last task of the
story (story.status === DONE), with head_sha as merge guard; MERGE_CONFLICT
routes to sprint-run flow which produces CREATE_CLAUDE_QUESTION +
SET_SPRINT_RUN_STATUS effects with rich pause_context
Tests: 31 test files, 242 passing. Pure-transition tests cover STORY 3-tasks
auto-merge timing, SPRINT draft→ready, MERGE_CONFLICT pause/resume, file-lock
deadlock prevention, worktree-lease lifecycle, delete-only verify (ALIGNED),
per-job verify scope (base_sha isolation), 5-category auto-merge errors.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
// Mock node:child_process before importing the module under test
|
|
vi.mock('node:child_process', () => ({
|
|
execFile: vi.fn(),
|
|
}))
|
|
|
|
import { execFile } from 'node:child_process'
|
|
import { enableAutoMergeOnPr } from '../../src/git/pr.js'
|
|
|
|
const mockExecFile = vi.mocked(execFile) as unknown as ReturnType<typeof vi.fn>
|
|
|
|
function mockGhFailure(stderr: string) {
|
|
mockExecFile.mockImplementation(((_cmd: string, _args: string[], _opts: unknown, cb: any) => {
|
|
cb(Object.assign(new Error('gh exit'), { stderr }))
|
|
}) as never)
|
|
}
|
|
|
|
function mockGhSuccess() {
|
|
mockExecFile.mockImplementation(((_cmd: string, _args: string[], _opts: unknown, cb: any) => {
|
|
cb(null, { stdout: '', stderr: '' })
|
|
}) as never)
|
|
}
|
|
|
|
describe('enableAutoMergeOnPr — typed errors (PBI-47 C2 layer 1)', () => {
|
|
beforeEach(() => {
|
|
mockExecFile.mockReset()
|
|
})
|
|
|
|
it('returns ok:true on green merge', async () => {
|
|
mockGhSuccess()
|
|
const result = await enableAutoMergeOnPr({ prUrl: 'x', expectedHeadSha: 'sha1' })
|
|
expect(result.ok).toBe(true)
|
|
})
|
|
|
|
it('classifies GH_AUTH_ERROR for 401/403 / permission strings', async () => {
|
|
mockGhFailure('gh: HTTP 403: permission denied')
|
|
const result = await enableAutoMergeOnPr({ prUrl: 'x', expectedHeadSha: 'sha1' })
|
|
expect(result.ok).toBe(false)
|
|
if (!result.ok) expect(result.reason).toBe('GH_AUTH_ERROR')
|
|
})
|
|
|
|
it('classifies AUTO_MERGE_NOT_ALLOWED for repo-setting refusal', async () => {
|
|
mockGhFailure('auto-merge is not allowed for this repository')
|
|
const result = await enableAutoMergeOnPr({ prUrl: 'x', expectedHeadSha: 'sha1' })
|
|
expect(result.ok).toBe(false)
|
|
if (!result.ok) expect(result.reason).toBe('AUTO_MERGE_NOT_ALLOWED')
|
|
})
|
|
|
|
it('classifies MERGE_CONFLICT for dirty merge state', async () => {
|
|
mockGhFailure('pull request is not in a mergeable state (dirty)')
|
|
const result = await enableAutoMergeOnPr({ prUrl: 'x', expectedHeadSha: 'sha1' })
|
|
expect(result.ok).toBe(false)
|
|
if (!result.ok) expect(result.reason).toBe('MERGE_CONFLICT')
|
|
})
|
|
|
|
it('classifies UNKNOWN for unrecognised stderr', async () => {
|
|
mockGhFailure('unexpected gh error')
|
|
const result = await enableAutoMergeOnPr({ prUrl: 'x', expectedHeadSha: 'sha1' })
|
|
expect(result.ok).toBe(false)
|
|
if (!result.ok) expect(result.reason).toBe('UNKNOWN')
|
|
})
|
|
|
|
it('passes --match-head-commit when expectedHeadSha provided', async () => {
|
|
mockGhSuccess()
|
|
await enableAutoMergeOnPr({ prUrl: 'pr-url', expectedHeadSha: 'abc123' })
|
|
const callArgs = mockExecFile.mock.calls[0]
|
|
expect(callArgs[0]).toBe('gh')
|
|
const args = callArgs[1] as string[]
|
|
expect(args).toContain('--match-head-commit')
|
|
expect(args).toContain('abc123')
|
|
expect(args).toContain('--auto')
|
|
expect(args).toContain('--squash')
|
|
})
|
|
})
|