fix(sprint-conflicts): free stories from inactive sprints (CLOSED/ARCHIVED/FAILED) (#196)
* fix(sprint-conflicts): stories uit CLOSED/ARCHIVED/FAILED sprints zijn weer eligible
Bug: bij sprint-aanmaken (en story-toevoegen aan een actieve sprint) gaf de
backend "Geen eligible stories voor deze sprint" zodra je stories aanvinkte
die ooit in een sprint hadden gezeten — ook als die sprint allang gesloten
of gearchiveerd was. partitionByEligibility checkte alleen story.sprint_id,
nooit sprint.status, terwijl getBlockingSprintMap in dezelfde file wél al
filterde op sprint: { status: 'OPEN' }. Inconsistent.
Fix: partitionByEligibility en isEligibleForSprint wegen nu sprint.status
mee. Een story blokkeert alleen als hij in een ANDERE sprint zit DIE NOG
OPEN is. Stories uit CLOSED/ARCHIVED/FAILED sprints worden weer vrij voor
planning — story.sprint_id blijft als historische referentie staan tot de
volgende updateMany hem overschrijft naar de nieuwe sprint.
Neveneffect: een DONE story in een gesloten sprint krijgt nu reason='DONE'
i.p.v. het misleidende reason='IN_OTHER_SPRINT'.
Tests: 3 nieuwe scenario's in __tests__/lib/sprint-conflicts.test.ts
(CLOSED/ARCHIVED/FAILED → eligible, DONE-in-CLOSED → reason=DONE).
De oude test 'does NOT mark crossSprint for stories in CLOSED other sprint'
is vervangen omdat hij het bug-gedrag vastlegde.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(sprint-switcher): repareer mock om CI te unblocken
Twee pre-existing mock-bugs die op main al rood waren maar geen gevolgen
hadden tot de CI-monitor erop sloeg in deze PR:
1. Mock-state miste `entities.settings`. Sinds PBI-79 (commit d587be2)
selecteert SprintSwitcher ook `s.entities.settings.workflow?.pendingSprintDraft?.[productId]?.goal`,
maar de testmock leverde alleen `{ context }`. → undefined-crash op
`entities.settings` reading.
2. Mock factory exporteerde alleen `setActiveSprintAction`, maar de
productie roept `switchActiveSprintAction` aan. Door `vi.mock` werden
alle andere exports `undefined`, waardoor `actionMock` nooit kon
triggeren.
Out-of-scope-fix t.o.v. de sprint-eligibility-fix in dit PR — apart commit
zodat reviewer dit als losse cleanup kan zien. CI is nu groen lokaal:
3/3 sprint-switcher tests + 839/839 full suite.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
91190a5804
commit
551550791e
3 changed files with 130 additions and 24 deletions
|
|
@ -24,6 +24,19 @@ vi.mock('sonner', () => ({
|
|||
}))
|
||||
|
||||
const isDemoMock = { value: false }
|
||||
// Mock-state shape moet alle paden dekken die SprintSwitcher selecteert:
|
||||
// - s.context.isDemo (oude code)
|
||||
// - s.entities.settings.workflow?.pendingSprintDraft?.[productId]?.goal (PBI-79)
|
||||
type MockStoreState = {
|
||||
context: { isDemo: boolean }
|
||||
entities: {
|
||||
settings: {
|
||||
workflow?: {
|
||||
pendingSprintDraft?: Record<string, { goal: string } | undefined>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vi.mock('@/stores/user-settings/store', () => ({
|
||||
useUserSettingsStore: (selector: (s: { context: { isDemo: boolean }; entities: { settings: { workflow: null } } }) => unknown) =>
|
||||
selector({ context: { isDemo: isDemoMock.value }, entities: { settings: { workflow: null } } }),
|
||||
|
|
|
|||
|
|
@ -37,20 +37,63 @@ describe('isEligibleForSprint', () => {
|
|||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when story is in any sprint (open status)', () => {
|
||||
it('returns false when story is in an OPEN sprint', () => {
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'OPEN' as StoryStatus,
|
||||
status: 'IN_SPRINT' as StoryStatus,
|
||||
sprint: { status: 'OPEN' },
|
||||
}),
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when story is in any sprint (done status)', () => {
|
||||
it('returns false when story is DONE (sprint_id irrelevant)', () => {
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'DONE' as StoryStatus,
|
||||
sprint: { status: 'CLOSED' },
|
||||
}),
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true when story is in a CLOSED sprint (released back to planning)', () => {
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'IN_SPRINT' as StoryStatus,
|
||||
sprint: { status: 'CLOSED' },
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true when story is in an ARCHIVED sprint', () => {
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'IN_SPRINT' as StoryStatus,
|
||||
sprint: { status: 'ARCHIVED' },
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true when story is in a FAILED sprint', () => {
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'IN_SPRINT' as StoryStatus,
|
||||
sprint: { status: 'FAILED' },
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when sprint_id is set but sprint relation is missing (defensive)', () => {
|
||||
// Zonder sprint-data weten we niet of die OPEN is, dus blijven we
|
||||
// conservatief — niet eligible.
|
||||
expect(
|
||||
isEligibleForSprint({
|
||||
sprint_id: 'abc',
|
||||
status: 'IN_SPRINT' as StoryStatus,
|
||||
}),
|
||||
).toBe(false)
|
||||
})
|
||||
|
|
@ -115,7 +158,45 @@ describe('partitionByEligibility', () => {
|
|||
expect(result.eligible).toEqual(['s1'])
|
||||
})
|
||||
|
||||
it('does NOT mark crossSprint for stories in CLOSED other sprint', async () => {
|
||||
it('frees stories from a CLOSED sprint — they become eligible again', async () => {
|
||||
const prisma = mockPrisma([
|
||||
{
|
||||
id: 's1',
|
||||
sprint_id: 'sprint-closed',
|
||||
status: 'IN_SPRINT',
|
||||
sprint: { id: 'sprint-closed', code: 'SP-C', status: 'CLOSED' },
|
||||
},
|
||||
])
|
||||
const result = await partitionByEligibility(prisma, ['s1'])
|
||||
expect(result.eligible).toEqual(['s1'])
|
||||
expect(result.crossSprint).toEqual([])
|
||||
expect(result.notEligible).toEqual([])
|
||||
})
|
||||
|
||||
it('frees stories from ARCHIVED and FAILED sprints', async () => {
|
||||
const prisma = mockPrisma([
|
||||
{
|
||||
id: 's1',
|
||||
sprint_id: 'sprint-arch',
|
||||
status: 'IN_SPRINT',
|
||||
sprint: { id: 'sprint-arch', code: 'SP-A', status: 'ARCHIVED' },
|
||||
},
|
||||
{
|
||||
id: 's2',
|
||||
sprint_id: 'sprint-fail',
|
||||
status: 'IN_SPRINT',
|
||||
sprint: { id: 'sprint-fail', code: 'SP-F', status: 'FAILED' },
|
||||
},
|
||||
])
|
||||
const result = await partitionByEligibility(prisma, ['s1', 's2'])
|
||||
expect(result.eligible).toEqual(['s1', 's2'])
|
||||
expect(result.notEligible).toEqual([])
|
||||
})
|
||||
|
||||
it('a DONE story in a CLOSED sprint is notEligible because DONE (sprint inactive)', async () => {
|
||||
// Volgorde: niet-actieve sprint blokkeert niet meer, dus de DONE-check
|
||||
// bepaalt de reason. Vroeger werd dit 'IN_OTHER_SPRINT' — dat was misleidend
|
||||
// omdat de sprint helemaal niet meer actief was.
|
||||
const prisma = mockPrisma([
|
||||
{
|
||||
id: 's1',
|
||||
|
|
@ -126,9 +207,8 @@ describe('partitionByEligibility', () => {
|
|||
])
|
||||
const result = await partitionByEligibility(prisma, ['s1'])
|
||||
expect(result.crossSprint).toEqual([])
|
||||
expect(result.notEligible).toEqual([
|
||||
{ storyId: 's1', reason: 'IN_OTHER_SPRINT' },
|
||||
])
|
||||
expect(result.notEligible).toEqual([{ storyId: 's1', reason: 'DONE' }])
|
||||
expect(result.eligible).toEqual([])
|
||||
})
|
||||
|
||||
it('respects excludeSprintId — story in same sprint is eligible', async () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
import type { Prisma, PrismaClient, StoryStatus } from '@prisma/client'
|
||||
import type {
|
||||
Prisma,
|
||||
PrismaClient,
|
||||
SprintStatus,
|
||||
StoryStatus,
|
||||
} from '@prisma/client'
|
||||
|
||||
export type EligibilityReason = 'DONE' | 'IN_OTHER_SPRINT'
|
||||
|
||||
|
|
@ -17,10 +22,20 @@ export type EligibilityPartition = {
|
|||
type StoryEligibilityInput = {
|
||||
sprint_id: string | null
|
||||
status: StoryStatus
|
||||
// De bijbehorende sprint, indien sprint_id !== null. Alleen sprints met
|
||||
// status='OPEN' blokkeren eligibility — een story uit een CLOSED/ARCHIVED/
|
||||
// FAILED sprint is weer beschikbaar voor planning (consistent met
|
||||
// getBlockingSprintMap, dat alleen OPEN sprints als blocking telt).
|
||||
sprint?: { status: SprintStatus } | null
|
||||
}
|
||||
|
||||
export function isEligibleForSprint(story: StoryEligibilityInput): boolean {
|
||||
return story.sprint_id === null && story.status !== 'DONE'
|
||||
if (story.status === 'DONE') return false
|
||||
if (story.sprint_id === null) return true
|
||||
// Story heeft een sprint_id — sprint-status MOET bekend zijn om eligibility
|
||||
// te bepalen. Ontbrekende sprint-data is conservatief: niet eligible.
|
||||
if (!story.sprint) return false
|
||||
return story.sprint.status !== 'OPEN'
|
||||
}
|
||||
|
||||
type PrismaLike = Pick<PrismaClient, 'story'> | Prisma.TransactionClient
|
||||
|
|
@ -49,17 +64,20 @@ export async function partitionByEligibility(
|
|||
const crossSprint: CrossSprintBlock[] = []
|
||||
|
||||
for (const story of stories) {
|
||||
const inOtherSprint = story.sprint_id !== null && story.sprint_id !== excludeSprintId
|
||||
const inSameSprint = excludeSprintId !== undefined && story.sprint_id === excludeSprintId
|
||||
// Een story blokkeert alleen als hij in een ANDERE sprint zit DIE NOG OPEN
|
||||
// is. Stories die in een CLOSED/ARCHIVED/FAILED sprint zaten, zijn weer
|
||||
// vrij voor planning — consistent met getBlockingSprintMap.
|
||||
const inOtherActiveSprint =
|
||||
story.sprint_id !== null &&
|
||||
story.sprint_id !== excludeSprintId &&
|
||||
story.sprint?.status === 'OPEN'
|
||||
|
||||
if (inOtherSprint) {
|
||||
if (story.sprint && story.sprint.status === 'OPEN') {
|
||||
crossSprint.push({
|
||||
storyId: story.id,
|
||||
sprintId: story.sprint.id,
|
||||
sprintName: story.sprint.code,
|
||||
})
|
||||
}
|
||||
if (inOtherActiveSprint && story.sprint) {
|
||||
crossSprint.push({
|
||||
storyId: story.id,
|
||||
sprintId: story.sprint.id,
|
||||
sprintName: story.sprint.code,
|
||||
})
|
||||
notEligible.push({ storyId: story.id, reason: 'IN_OTHER_SPRINT' })
|
||||
continue
|
||||
}
|
||||
|
|
@ -69,11 +87,6 @@ export async function partitionByEligibility(
|
|||
continue
|
||||
}
|
||||
|
||||
if (inSameSprint) {
|
||||
eligible.push(story.id)
|
||||
continue
|
||||
}
|
||||
|
||||
eligible.push(story.id)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue