Merge pull request #43 from madhura68/fix/prepare-done-uses-db-branch
fix(update_job_status): gebruik DB-branch ipv legacy feat/job-<8> fallback
This commit is contained in:
commit
ed94d5b7e1
2 changed files with 48 additions and 2 deletions
|
|
@ -5,13 +5,26 @@ vi.mock('../src/git/push.js', () => ({
|
|||
pushBranchForJob: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('../src/prisma.js', () => ({
|
||||
prisma: {
|
||||
claudeJob: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
import { pushBranchForJob } from '../src/git/push.js'
|
||||
import { prisma } from '../src/prisma.js'
|
||||
import { prepareDoneUpdate } from '../src/tools/update-job-status.js'
|
||||
|
||||
const mockPush = pushBranchForJob as ReturnType<typeof vi.fn>
|
||||
const mockFindUnique = (prisma as unknown as {
|
||||
claudeJob: { findUnique: ReturnType<typeof vi.fn> }
|
||||
}).claudeJob.findUnique
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockFindUnique.mockResolvedValue(null)
|
||||
})
|
||||
|
||||
describe('prepareDoneUpdate', () => {
|
||||
|
|
@ -39,8 +52,25 @@ describe('prepareDoneUpdate', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('derives branchName from jobId when branch is undefined', async () => {
|
||||
it('reads branchName from DB (claudeJob.branch) when branch arg is undefined', async () => {
|
||||
process.env.SCRUM4ME_AGENT_WORKTREE_DIR = '/wt'
|
||||
mockFindUnique.mockResolvedValue({ branch: 'feat/sprint-fvy30lvv' })
|
||||
mockPush.mockResolvedValue({ pushed: true, remoteRef: 'refs/heads/feat/sprint-fvy30lvv' })
|
||||
|
||||
await prepareDoneUpdate('job-abc12345', undefined)
|
||||
|
||||
expect(mockFindUnique).toHaveBeenCalledWith({
|
||||
where: { id: 'job-abc12345' },
|
||||
select: { branch: true },
|
||||
})
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ branchName: 'feat/sprint-fvy30lvv' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to feat/job-<8> when neither branch arg nor DB.branch is set', async () => {
|
||||
process.env.SCRUM4ME_AGENT_WORKTREE_DIR = '/wt'
|
||||
mockFindUnique.mockResolvedValue({ branch: null })
|
||||
mockPush.mockResolvedValue({ pushed: true, remoteRef: 'refs/heads/feat/job-abc12345' })
|
||||
|
||||
await prepareDoneUpdate('job-abc12345', undefined)
|
||||
|
|
|
|||
|
|
@ -119,9 +119,25 @@ export async function prepareDoneUpdate(
|
|||
jobId: string,
|
||||
branch: string | undefined,
|
||||
): Promise<DoneUpdatePlan> {
|
||||
// Resolve branch in deze volgorde:
|
||||
// 1. Expliciete `branch`-arg van Claude (meestal niet meegegeven).
|
||||
// 2. ClaudeJob.branch uit de DB — gezet door attachWorktreeToJob met de
|
||||
// juiste pr_strategy: feat/sprint-<id> voor SPRINT, feat/story-<id>
|
||||
// voor STORY met sibling-reuse.
|
||||
// 3. Legacy fallback feat/job-<8> — alleen voor jobs zonder DB-branch
|
||||
// (zou niet moeten voorkomen na PBI-50).
|
||||
let resolvedBranch = branch
|
||||
if (!resolvedBranch) {
|
||||
const dbJob = await prisma.claudeJob.findUnique({
|
||||
where: { id: jobId },
|
||||
select: { branch: true },
|
||||
})
|
||||
resolvedBranch = dbJob?.branch ?? undefined
|
||||
}
|
||||
const branchName = resolvedBranch ?? `feat/job-${jobId.slice(-8)}`
|
||||
|
||||
const worktreeDir = getWorktreeRoot()
|
||||
const worktreePath = path.join(worktreeDir, jobId)
|
||||
const branchName = branch ?? `feat/job-${jobId.slice(-8)}`
|
||||
|
||||
const pushResult = await pushBranchForJob({ worktreePath, branchName })
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue