Merge branch 'main' into chore/bump-1.3.1
This commit is contained in:
commit
b9b4a351b6
21 changed files with 425 additions and 24 deletions
|
|
@ -8,13 +8,24 @@ const {
|
|||
mockGetSession,
|
||||
mockFindFirstJob,
|
||||
mockUpdateJob,
|
||||
mockUpdateManyJob,
|
||||
mockUpdateManySprintTaskExecution,
|
||||
mockTransaction,
|
||||
mockExecuteRaw,
|
||||
} = vi.hoisted(() => ({
|
||||
mockGetSession: vi.fn(),
|
||||
mockFindFirstJob: vi.fn(),
|
||||
mockUpdateJob: vi.fn(),
|
||||
mockExecuteRaw: vi.fn().mockResolvedValue(undefined),
|
||||
}))
|
||||
} = vi.hoisted(() => {
|
||||
const mockUpdateManyJob = vi.fn()
|
||||
const mockUpdateManySprintTaskExecution = vi.fn()
|
||||
const mockTransaction = vi.fn()
|
||||
return {
|
||||
mockGetSession: vi.fn(),
|
||||
mockFindFirstJob: vi.fn(),
|
||||
mockUpdateJob: vi.fn(),
|
||||
mockUpdateManyJob,
|
||||
mockUpdateManySprintTaskExecution,
|
||||
mockTransaction,
|
||||
mockExecuteRaw: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
|
||||
vi.mock('@/lib/auth', () => ({ getSession: mockGetSession }))
|
||||
|
|
@ -23,7 +34,12 @@ vi.mock('@/lib/prisma', () => ({
|
|||
claudeJob: {
|
||||
findFirst: mockFindFirstJob,
|
||||
update: mockUpdateJob,
|
||||
updateMany: mockUpdateManyJob,
|
||||
},
|
||||
sprintTaskExecution: {
|
||||
updateMany: mockUpdateManySprintTaskExecution,
|
||||
},
|
||||
$transaction: mockTransaction,
|
||||
$executeRaw: mockExecuteRaw,
|
||||
},
|
||||
}))
|
||||
|
|
@ -32,6 +48,7 @@ import {
|
|||
enqueueClaudeJobAction,
|
||||
enqueueAllTodoJobsAction,
|
||||
cancelClaudeJobAction,
|
||||
restartClaudeJobAction,
|
||||
} from '@/actions/claude-jobs'
|
||||
|
||||
const SESSION_USER = { userId: 'user-1', isDemo: false }
|
||||
|
|
@ -39,6 +56,12 @@ const SESSION_USER = { userId: 'user-1', isDemo: false }
|
|||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockExecuteRaw.mockResolvedValue(undefined)
|
||||
mockTransaction.mockImplementation(async (fn: (tx: unknown) => Promise<unknown>) =>
|
||||
fn({
|
||||
claudeJob: { updateMany: mockUpdateManyJob },
|
||||
sprintTaskExecution: { updateMany: mockUpdateManySprintTaskExecution },
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
describe('enqueueClaudeJobAction (deprecated)', () => {
|
||||
|
|
@ -104,3 +127,115 @@ describe('cancelClaudeJobAction', () => {
|
|||
expect(result).toMatchObject({ error: expect.stringContaining('actieve') })
|
||||
})
|
||||
})
|
||||
|
||||
describe('restartClaudeJobAction', () => {
|
||||
const FAILED_JOB = {
|
||||
id: 'job-1',
|
||||
status: 'FAILED',
|
||||
kind: 'TASK_IMPLEMENTATION',
|
||||
task_id: 'task-1',
|
||||
idea_id: null,
|
||||
sprint_run_id: null,
|
||||
product_id: 'prod-1',
|
||||
}
|
||||
|
||||
it('reset een FAILED job naar QUEUED (happy path)', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 1 })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
|
||||
expect(result).toEqual({ success: true })
|
||||
expect(mockUpdateManyJob).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({ id: 'job-1', status: { in: ['FAILED', 'CANCELLED', 'SKIPPED'] } }),
|
||||
data: expect.objectContaining({ status: 'QUEUED' }),
|
||||
})
|
||||
)
|
||||
expect(mockExecuteRaw).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reset een CANCELLED job naar QUEUED', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'CANCELLED' })
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 1 })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toEqual({ success: true })
|
||||
})
|
||||
|
||||
it('reset een SKIPPED job naar QUEUED', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'SKIPPED' })
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 1 })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toEqual({ success: true })
|
||||
})
|
||||
|
||||
it('weigert demo-sessie', async () => {
|
||||
mockGetSession.mockResolvedValue({ userId: 'demo', isDemo: true })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toMatchObject({ error: expect.stringContaining('demo') })
|
||||
expect(mockUpdateManyJob).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('retourneert error als job niet gevonden', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue(null)
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toMatchObject({ error: expect.stringContaining('niet gevonden') })
|
||||
})
|
||||
|
||||
it('weigert wanneer job een niet-restartbare status heeft', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue({ ...FAILED_JOB, status: 'DONE' })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toMatchObject({ error: expect.stringContaining('mislukte') })
|
||||
expect(mockUpdateManyJob).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('retourneert error bij race-conditie (updateMany count === 0)', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 0 })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
expect(result).toMatchObject({ error: expect.stringContaining('gewijzigd') })
|
||||
})
|
||||
|
||||
it('reset ook SprintTaskExecution-rows bij SPRINT_IMPLEMENTATION', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue({
|
||||
...FAILED_JOB,
|
||||
kind: 'SPRINT_IMPLEMENTATION',
|
||||
sprint_run_id: 'run-1',
|
||||
})
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 1 })
|
||||
mockUpdateManySprintTaskExecution.mockResolvedValue({ count: 3 })
|
||||
|
||||
const result = await restartClaudeJobAction('job-1')
|
||||
|
||||
expect(result).toEqual({ success: true })
|
||||
expect(mockUpdateManySprintTaskExecution).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { sprint_job_id: 'job-1' },
|
||||
data: expect.objectContaining({ status: 'PENDING' }),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('reset geen SprintTaskExecution-rows bij TASK_IMPLEMENTATION', async () => {
|
||||
mockGetSession.mockResolvedValue(SESSION_USER)
|
||||
mockFindFirstJob.mockResolvedValue(FAILED_JOB)
|
||||
mockUpdateManyJob.mockResolvedValue({ count: 1 })
|
||||
|
||||
await restartClaudeJobAction('job-1')
|
||||
|
||||
expect(mockUpdateManySprintTaskExecution).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -110,13 +110,13 @@ describe('shouldEmit scope filter (via backlog-store reducer)', () => {
|
|||
|
||||
it('applyChange: story INSERT adds to storiesByPbi', () => {
|
||||
useBacklogStore.setState({ pbis: [], storiesByPbi: { 'pbi-1': [] }, tasksByStory: {} })
|
||||
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', created_at: new Date() }
|
||||
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', sprint_id: null, created_at: new Date() }
|
||||
useBacklogStore.getState().applyChange('story', 'I', story)
|
||||
expect(useBacklogStore.getState().storiesByPbi['pbi-1']).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('applyChange: story DELETE removes from correct pbi bucket', () => {
|
||||
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', created_at: new Date() }
|
||||
const story = { id: 'story-1', code: 'ST-1', title: 'S', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: 'pbi-1', sprint_id: null, created_at: new Date() }
|
||||
useBacklogStore.setState({ pbis: [], storiesByPbi: { 'pbi-1': [story] }, tasksByStory: {} })
|
||||
useBacklogStore.getState().applyChange('story', 'D', { id: 'story-1' })
|
||||
expect(useBacklogStore.getState().storiesByPbi['pbi-1']).toHaveLength(0)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ const ALT_PBI_ID = 'pbi-2'
|
|||
const STORY_ID = 'story-1'
|
||||
|
||||
const STORIES = [
|
||||
{ id: STORY_ID, code: 'ST-1', title: 'Eerste story', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: PBI_ID, created_at: new Date() },
|
||||
{ id: STORY_ID, code: 'ST-1', title: 'Eerste story', description: null, acceptance_criteria: null, priority: 2, status: 'OPEN', pbi_id: PBI_ID, sprint_id: null, created_at: new Date() },
|
||||
]
|
||||
const TASKS = [
|
||||
{ id: 'task-1', title: 'Eerste taak', description: null, priority: 2, status: 'TO_DO', sort_order: 1, story_id: STORY_ID, created_at: new Date() },
|
||||
|
|
|
|||
75
__tests__/components/jobs/job-detail-pane.test.tsx
Normal file
75
__tests__/components/jobs/job-detail-pane.test.tsx
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
// @vitest-environment jsdom
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import '@testing-library/jest-dom'
|
||||
import type { JobWithRelations } from '@/actions/jobs-page'
|
||||
|
||||
vi.mock('@/actions/claude-jobs', () => ({
|
||||
restartClaudeJobAction: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { error: vi.fn() } }))
|
||||
|
||||
import { restartClaudeJobAction } from '@/actions/claude-jobs'
|
||||
import JobDetailPane from '@/components/jobs/job-detail-pane'
|
||||
|
||||
const mockAction = restartClaudeJobAction as ReturnType<typeof vi.fn>
|
||||
|
||||
function makeJob(status: JobWithRelations['status']): JobWithRelations {
|
||||
return {
|
||||
id: 'job-1',
|
||||
kind: 'TASK_IMPLEMENTATION',
|
||||
status,
|
||||
taskCode: 'T-1',
|
||||
taskTitle: 'Test taak',
|
||||
ideaCode: null,
|
||||
ideaTitle: null,
|
||||
sprintGoal: null,
|
||||
sprintCode: null,
|
||||
productName: 'Scrum4Me',
|
||||
modelId: null,
|
||||
inputTokens: null,
|
||||
outputTokens: null,
|
||||
cacheReadTokens: null,
|
||||
cacheWriteTokens: null,
|
||||
costUsd: null,
|
||||
branch: null,
|
||||
prUrl: null,
|
||||
error: null,
|
||||
summary: null,
|
||||
description: null,
|
||||
verifyResult: null,
|
||||
startedAt: null,
|
||||
finishedAt: null,
|
||||
createdAt: new Date('2026-01-01'),
|
||||
sprintRunId: null,
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockAction.mockResolvedValue({ success: true })
|
||||
})
|
||||
|
||||
describe('JobDetailPane restart button', () => {
|
||||
it('toont de knop voor FAILED-jobs', () => {
|
||||
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
|
||||
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('toont de knop niet voor DONE-jobs', () => {
|
||||
render(<JobDetailPane job={makeJob('DONE')} isDemo={false} />)
|
||||
expect(screen.queryByRole('button', { name: /opnieuw starten/i })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('roept restartClaudeJobAction aan met het juiste id bij klik', () => {
|
||||
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: /opnieuw starten/i }))
|
||||
expect(mockAction).toHaveBeenCalledWith('job-1')
|
||||
})
|
||||
|
||||
it('knop is disabled in demo-modus', () => {
|
||||
render(<JobDetailPane job={makeJob('FAILED')} isDemo={true} />)
|
||||
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeDisabled()
|
||||
})
|
||||
})
|
||||
|
|
@ -21,6 +21,7 @@ const STORY: BacklogStory = {
|
|||
priority: 2,
|
||||
status: 'OPEN',
|
||||
pbi_id: 'pbi-1',
|
||||
sprint_id: null,
|
||||
created_at: new Date('2024-01-01T00:00:00Z'),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { type ClaudeJobStatus } from '@prisma/client'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { ACTIVE_JOB_STATUSES, jobStatusToApi } from '@/lib/job-status'
|
||||
|
|
@ -15,6 +16,9 @@ type EnqueueAllResult =
|
|||
|
||||
type CancelResult = { success: true } | { error: string }
|
||||
|
||||
type RestartResult = { success: true } | { error: string }
|
||||
const RESTARTABLE_STATUSES: ClaudeJobStatus[] = ['FAILED', 'CANCELLED', 'SKIPPED']
|
||||
|
||||
export type PreviewTask = {
|
||||
id: string
|
||||
title: string
|
||||
|
|
@ -109,3 +113,76 @@ export async function cancelClaudeJobAction(jobId: string): Promise<CancelResult
|
|||
revalidatePath(`/products/${job.product_id}/solo`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function restartClaudeJobAction(jobId: string): Promise<RestartResult> {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
if (!jobId) return { error: 'job_id is verplicht' }
|
||||
|
||||
const job = await prisma.claudeJob.findFirst({
|
||||
where: { id: jobId, user_id: session.userId },
|
||||
select: { id: true, status: true, kind: true, task_id: true, idea_id: true, sprint_run_id: true, product_id: true },
|
||||
})
|
||||
if (!job) return { error: 'Job niet gevonden' }
|
||||
if (!RESTARTABLE_STATUSES.includes(job.status)) {
|
||||
return { error: 'Alleen mislukte, geannuleerde of overgeslagen jobs kunnen opnieuw gestart worden' }
|
||||
}
|
||||
|
||||
const updated = await prisma.$transaction(async (tx) => {
|
||||
const result = await tx.claudeJob.updateMany({
|
||||
where: { id: jobId, status: { in: RESTARTABLE_STATUSES } },
|
||||
data: {
|
||||
status: 'QUEUED',
|
||||
retry_count: { increment: 1 },
|
||||
claimed_by_token_id: null,
|
||||
claimed_at: null,
|
||||
started_at: null,
|
||||
finished_at: null,
|
||||
pushed_at: null,
|
||||
verify_result: null,
|
||||
error: null,
|
||||
summary: null,
|
||||
branch: null,
|
||||
head_sha: null,
|
||||
lease_until: null,
|
||||
},
|
||||
})
|
||||
if (result.count === 0) return 0
|
||||
if (job.kind === 'SPRINT_IMPLEMENTATION') {
|
||||
await tx.sprintTaskExecution.updateMany({
|
||||
where: { sprint_job_id: jobId },
|
||||
data: {
|
||||
status: 'PENDING',
|
||||
verify_result: null,
|
||||
verify_summary: null,
|
||||
skip_reason: null,
|
||||
head_sha: null,
|
||||
started_at: null,
|
||||
finished_at: null,
|
||||
},
|
||||
})
|
||||
}
|
||||
return result.count
|
||||
})
|
||||
if (updated === 0) {
|
||||
return { error: 'Job-status is gewijzigd; herlaad en probeer opnieuw' }
|
||||
}
|
||||
|
||||
await prisma.$executeRaw`
|
||||
SELECT pg_notify('scrum4me_changes', ${JSON.stringify({
|
||||
type: 'claude_job_status',
|
||||
job_id: jobId,
|
||||
kind: job.kind,
|
||||
task_id: job.task_id,
|
||||
idea_id: job.idea_id,
|
||||
sprint_run_id: job.sprint_run_id,
|
||||
user_id: session.userId,
|
||||
product_id: job.product_id,
|
||||
status: jobStatusToApi('QUEUED'),
|
||||
})}::text)
|
||||
`
|
||||
|
||||
revalidatePath('/jobs')
|
||||
return { success: true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ export async function createSprintAction(_prevState: unknown, formData: FormData
|
|||
}
|
||||
|
||||
await setActiveSprintCookie(parsed.data.productId, sprint.id)
|
||||
revalidatePath(`/products/${parsed.data.productId}`)
|
||||
revalidatePath(`/products/${parsed.data.productId}`, 'layout')
|
||||
return { success: true, sprintId: sprint.id }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default async function JobsPage() {
|
|||
<h1 className="text-lg font-semibold">Jobs</h1>
|
||||
</div>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<JobsBoard initialActiveJobs={data.activeJobs} initialDoneJobs={data.doneJobs} />
|
||||
<JobsBoard initialActiveJobs={data.activeJobs} initialDoneJobs={data.doneJobs} isDemo={session.isDemo ?? false} />
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ export default async function ProductBacklogPage({ params, searchParams }: Props
|
|||
priority: true,
|
||||
status: true,
|
||||
pbi_id: true,
|
||||
sprint_id: true,
|
||||
created_at: true,
|
||||
},
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { notFound, redirect } from 'next/navigation'
|
|||
import { getSession } from '@/lib/auth'
|
||||
import { getAccessibleProduct } from '@/lib/product-access'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { resolveActiveSprint } from '@/lib/active-sprint'
|
||||
import { getSprintSwitcherData } from '@/lib/sprint-switcher-data'
|
||||
import { SoloBoard } from '@/components/solo/solo-board'
|
||||
import { NoActiveSprint } from '@/components/solo/no-active-sprint'
|
||||
|
|
@ -21,9 +22,10 @@ export default async function SoloProductPage({ params }: Props) {
|
|||
const product = await getAccessibleProduct(id, session.userId)
|
||||
if (!product) notFound()
|
||||
|
||||
const sprint = await prisma.sprint.findFirst({
|
||||
where: { product_id: id, status: 'OPEN' },
|
||||
})
|
||||
const active = await resolveActiveSprint(id)
|
||||
const sprint = active
|
||||
? await prisma.sprint.findFirst({ where: { id: active.id, product_id: id } })
|
||||
: null
|
||||
|
||||
const switcherData = await getSprintSwitcherData(id, { activeSprintId: sprint?.id ?? null })
|
||||
|
||||
|
|
@ -126,6 +128,7 @@ export default async function SoloProductPage({ params }: Props) {
|
|||
{switcherBar}
|
||||
<div className="flex-1 min-h-0">
|
||||
<SoloBoard
|
||||
key={sprint.id}
|
||||
productId={id}
|
||||
sprintGoal={sprint.sprint_goal}
|
||||
tasks={tasks}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ export default async function SprintBoardPage({ params, searchParams }: Props) {
|
|||
description: s.description,
|
||||
acceptance_criteria: s.acceptance_criteria,
|
||||
pbi_id: s.pbi_id,
|
||||
sprint_id: s.sprint_id,
|
||||
created_at: s.created_at,
|
||||
priority: s.priority,
|
||||
status: s.status,
|
||||
|
|
@ -144,6 +145,7 @@ export default async function SprintBoardPage({ params, searchParams }: Props) {
|
|||
description: s.description,
|
||||
acceptance_criteria: s.acceptance_criteria,
|
||||
pbi_id: s.pbi_id,
|
||||
sprint_id: s.sprint_id,
|
||||
created_at: s.created_at,
|
||||
priority: s.priority,
|
||||
status: s.status,
|
||||
|
|
@ -191,6 +193,7 @@ export default async function SprintBoardPage({ params, searchParams }: Props) {
|
|||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<SprintBoardClient
|
||||
key={sprint.id}
|
||||
productId={id}
|
||||
sprintId={sprint.id}
|
||||
stories={sprintStoryItems}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ export default async function MobileProductBacklogPage({ params, searchParams }:
|
|||
priority: true,
|
||||
status: true,
|
||||
pbi_id: true,
|
||||
sprint_id: true,
|
||||
created_at: true,
|
||||
},
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { notFound } from 'next/navigation'
|
|||
import { getAccessibleProduct } from '@/lib/product-access'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { requireSession } from '@/lib/auth-guard'
|
||||
import { resolveActiveSprint } from '@/lib/active-sprint'
|
||||
import { SoloBoard } from '@/components/solo/solo-board'
|
||||
import { NoActiveSprint } from '@/components/solo/no-active-sprint'
|
||||
import type { SoloTask } from '@/components/solo/solo-board'
|
||||
|
|
@ -24,9 +25,10 @@ export default async function MobileSoloProductPage({ params }: Props) {
|
|||
const product = await getAccessibleProduct(id, session.userId)
|
||||
if (!product) notFound()
|
||||
|
||||
const sprint = await prisma.sprint.findFirst({
|
||||
where: { product_id: id, status: 'OPEN' },
|
||||
})
|
||||
const active = await resolveActiveSprint(id)
|
||||
const sprint = active
|
||||
? await prisma.sprint.findFirst({ where: { id: active.id, product_id: id } })
|
||||
: null
|
||||
|
||||
if (!sprint) {
|
||||
return (
|
||||
|
|
@ -112,6 +114,7 @@ export default async function MobileSoloProductPage({ params }: Props) {
|
|||
|
||||
return (
|
||||
<SoloBoard
|
||||
key={sprint.id}
|
||||
productId={id}
|
||||
sprintGoal={sprint.sprint_goal}
|
||||
tasks={tasks}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useBacklogStore, type BacklogPbi, type BacklogStory, type BacklogTask } from '@/stores/backlog-store'
|
||||
import { useBacklogRealtime } from '@/lib/realtime/use-backlog-realtime'
|
||||
|
||||
|
|
@ -16,13 +16,28 @@ interface BacklogHydrationWrapperProps {
|
|||
children: React.ReactNode
|
||||
}
|
||||
|
||||
function fingerprint(data: InitialData): string {
|
||||
const pbiPart = data.pbis.map((p) => `${p.id}:${p.status}:${p.priority}`).join(',')
|
||||
const storyPart = Object.entries(data.storiesByPbi)
|
||||
.flatMap(([, list]) => list.map((s) => `${s.id}:${s.status}:${s.sprint_id ?? 'null'}`))
|
||||
.join(',')
|
||||
const taskPart = Object.entries(data.tasksByStory)
|
||||
.flatMap(([, list]) => list.map((t) => `${t.id}:${t.status}`))
|
||||
.join(',')
|
||||
return `${pbiPart}|${storyPart}|${taskPart}`
|
||||
}
|
||||
|
||||
export function BacklogHydrationWrapper({ initialData, productId, children }: BacklogHydrationWrapperProps) {
|
||||
const setInitialData = useBacklogStore((s) => s.setInitialData)
|
||||
const lastFingerprint = useRef<string>('')
|
||||
|
||||
useEffect(() => {
|
||||
setInitialData(initialData)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
const fp = fingerprint(initialData)
|
||||
if (fp !== lastFingerprint.current) {
|
||||
lastFingerprint.current = fp
|
||||
setInitialData(initialData)
|
||||
}
|
||||
}, [initialData, setInitialData])
|
||||
|
||||
useBacklogRealtime(productId)
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ export interface Story {
|
|||
priority: number
|
||||
status: string
|
||||
pbi_id: string
|
||||
sprint_id: string | null
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
'use client'
|
||||
|
||||
import { useTransition } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { JOB_STATUS_LABELS, JOB_STATUS_COLORS } from '@/components/shared/job-status'
|
||||
import { jobStatusToApi } from '@/lib/job-status'
|
||||
import type { JobWithRelations } from '@/actions/jobs-page'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DemoTooltip } from '@/components/shared/demo-tooltip'
|
||||
import { restartClaudeJobAction } from '@/actions/claude-jobs'
|
||||
|
||||
const RESTARTABLE_API_STATUSES = new Set(['failed', 'cancelled', 'skipped'])
|
||||
|
||||
interface FieldRowProps {
|
||||
label: string
|
||||
|
|
@ -42,9 +49,12 @@ function subjectLabel(job: JobWithRelations): { label: string; value: string } |
|
|||
|
||||
interface JobDetailPaneProps {
|
||||
job: JobWithRelations | null
|
||||
isDemo: boolean
|
||||
}
|
||||
|
||||
export default function JobDetailPane({ job }: JobDetailPaneProps) {
|
||||
export default function JobDetailPane({ job, isDemo }: JobDetailPaneProps) {
|
||||
const [isPending, startTransition] = useTransition()
|
||||
|
||||
if (!job) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-sm text-muted-foreground">
|
||||
|
|
@ -55,6 +65,14 @@ export default function JobDetailPane({ job }: JobDetailPaneProps) {
|
|||
|
||||
const apiStatus = jobStatusToApi(job.status)
|
||||
const subject = subjectLabel(job)
|
||||
const canRestart = RESTARTABLE_API_STATUSES.has(apiStatus)
|
||||
|
||||
function handleRestart() {
|
||||
startTransition(async () => {
|
||||
const result = await restartClaudeJobAction(job!.id)
|
||||
if ('error' in result) toast.error(result.error)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-y-auto h-full p-4">
|
||||
|
|
@ -110,6 +128,19 @@ export default function JobDetailPane({ job }: JobDetailPaneProps) {
|
|||
<p className="text-xs text-muted-foreground italic">Geen beschrijving.</p>
|
||||
)}
|
||||
</div>
|
||||
{canRestart && (
|
||||
<div className="pt-3 mt-3 border-t border-border/50">
|
||||
<DemoTooltip show={isDemo}>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleRestart}
|
||||
disabled={isPending || isDemo}
|
||||
>
|
||||
{isPending ? 'Opnieuw starten…' : 'Opnieuw starten'}
|
||||
</Button>
|
||||
</DemoTooltip>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import type { JobWithRelations } from '@/actions/jobs-page'
|
|||
interface JobsBoardProps {
|
||||
initialActiveJobs: JobWithRelations[]
|
||||
initialDoneJobs: JobWithRelations[]
|
||||
isDemo: boolean
|
||||
}
|
||||
|
||||
type View = 'detail' | 'usage'
|
||||
|
|
@ -32,7 +33,7 @@ const DONE_STATUS_OPTIONS: Array<{ value: ClaudeJobStatusApi; label: string }> =
|
|||
{ value: 'skipped', label: 'Overgeslagen' },
|
||||
]
|
||||
|
||||
export default function JobsBoard({ initialActiveJobs, initialDoneJobs }: JobsBoardProps) {
|
||||
export default function JobsBoard({ initialActiveJobs, initialDoneJobs, isDemo }: JobsBoardProps) {
|
||||
const { activeJobs, doneJobs, selectedJobId, initJobs, setSelectedJobId } = useJobsStore()
|
||||
const [view, setView] = useState<View>('detail')
|
||||
useJobsRealtime()
|
||||
|
|
@ -77,7 +78,7 @@ export default function JobsBoard({ initialActiveJobs, initialDoneJobs }: JobsBo
|
|||
</Button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{view === 'detail' ? <JobDetailPane job={selectedJob} /> : <JobUsagePane job={selectedJob} />}
|
||||
{view === 'detail' ? <JobDetailPane job={selectedJob} isDemo={isDemo} /> : <JobUsagePane job={selectedJob} />}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ export interface SprintStory {
|
|||
description: string | null
|
||||
acceptance_criteria: string | null
|
||||
pbi_id: string
|
||||
sprint_id: string | null
|
||||
created_at: Date
|
||||
priority: number
|
||||
status: string
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from '@/components/shared/entity-dialog-layout'
|
||||
import { createSprintAction } from '@/actions/sprints'
|
||||
import { useSelectionStore } from '@/stores/selection-store'
|
||||
import { useBacklogStore } from '@/stores/backlog-store'
|
||||
|
||||
interface StartSprintButtonProps {
|
||||
productId: string
|
||||
|
|
@ -46,6 +47,13 @@ export function StartSprintButton({ productId, isDemo = false }: StartSprintButt
|
|||
const formRef = useRef<HTMLFormElement>(null)
|
||||
const router = useRouter()
|
||||
const selectedPbiId = useSelectionStore((s) => s.selectedPbiId)
|
||||
const selectedPbi = useBacklogStore((s) =>
|
||||
selectedPbiId ? s.pbis.find((p) => p.id === selectedPbiId) ?? null : null,
|
||||
)
|
||||
const freeStoryCount = useBacklogStore((s) => {
|
||||
if (!selectedPbiId) return 0
|
||||
return (s.storiesByPbi[selectedPbiId] ?? []).filter((story) => story.sprint_id === null).length
|
||||
})
|
||||
|
||||
const [state, formAction, pending] = useActionState<ActionResult | undefined, FormData>(
|
||||
async (_prev, fd) => {
|
||||
|
|
@ -96,6 +104,26 @@ export function StartSprintButton({ productId, isDemo = false }: StartSprintButt
|
|||
<input type="hidden" name="productId" value={productId} />
|
||||
{selectedPbiId && <input type="hidden" name="pbi_id" value={selectedPbiId} />}
|
||||
|
||||
{!selectedPbi ? (
|
||||
<div className="bg-warning-container text-warning-container-foreground rounded-lg px-3 py-2 text-sm border-l-4 border-warning">
|
||||
Geen PBI geselecteerd — de sprint wordt leeg aangemaakt. Je kunt later stories
|
||||
toevoegen via slepen.
|
||||
</div>
|
||||
) : freeStoryCount === 0 ? (
|
||||
<div className="bg-warning-container text-warning-container-foreground rounded-lg px-3 py-2 text-sm border-l-4 border-warning">
|
||||
PBI <strong>{selectedPbi.code ?? selectedPbi.id.slice(0, 8)}</strong> heeft geen
|
||||
vrije stories (alle stories zitten al in een andere sprint of zijn afgerond) — de
|
||||
sprint wordt leeg aangemaakt.
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-primary-container text-primary-container-foreground rounded-lg px-3 py-2 text-sm border-l-4 border-primary">
|
||||
<strong>{freeStoryCount}</strong> {freeStoryCount === 1 ? 'story' : 'stories'} van
|
||||
PBI <strong>{selectedPbi.code ?? selectedPbi.id.slice(0, 8)}</strong>
|
||||
{selectedPbi.title ? ` (${selectedPbi.title})` : ''} worden toegevoegd aan deze
|
||||
sprint.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium text-foreground">
|
||||
Sprint Goal <span className="text-error">*</span>
|
||||
|
|
|
|||
|
|
@ -522,6 +522,30 @@ De app is deployable op Vercel + Neon PostgreSQL en lokaal draaibaar met een Neo
|
|||
|
||||
---
|
||||
|
||||
### F-14: Job-queue inzicht en beheer (`/jobs`)
|
||||
|
||||
**Prioriteit:** v1 — Operationele controle
|
||||
**Persona:** Lars
|
||||
|
||||
**Omschrijving:**
|
||||
De `/jobs`-pagina geeft een overzicht van alle `ClaudeJob`-records voor het actieve product. Vanuit de `JobDetailPane` kan de gebruiker een mislukte, geannuleerde of overgeslagen job opnieuw in de wachtrij zetten.
|
||||
|
||||
**Acceptatiecriteria:**
|
||||
|
||||
#### Mislukte job opnieuw starten
|
||||
|
||||
- [ ] Een `ClaudeJob` in status `FAILED`, `CANCELLED` of `SKIPPED` toont een "Opnieuw starten"-knop in de `JobDetailPane`.
|
||||
- [ ] De knop reset de bestaande job (geen nieuwe job aanmaken): `status → QUEUED`, `retry_count + 1`, alle run-velden gecleared.
|
||||
- [ ] Bij `SPRINT_IMPLEMENTATION`-jobs worden alle bijbehorende `SprintTaskExecution`-rows in dezelfde transactie teruggezet naar `PENDING`.
|
||||
- [ ] Tijdens de server-action is de knop disabled (loading-state). De UI updatet via SSE zonder handmatige refresh.
|
||||
- [ ] Demo-sessies zien een `DemoTooltip` op de knop en kunnen niet restarten (drie-laagse policy: knop disabled + server action `session.isDemo`-check + HTTP 403).
|
||||
|
||||
**Randgevallen:**
|
||||
- Job is ondertussen al door een andere actie opnieuw gestart (race condition) → server-action controleert de huidige status vóór de update; als de status niet meer `FAILED/CANCELLED/SKIPPED` is, retourneert de action een foutmelding.
|
||||
- Demo-token probeert via directe API-aanroep te restarten → 403 Forbidden.
|
||||
|
||||
---
|
||||
|
||||
## Navigatiestructuur
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export interface BacklogStory {
|
|||
priority: number
|
||||
status: string
|
||||
pbi_id: string
|
||||
sprint_id: string | null
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue