Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export async function advanceLivingWorkday(store: CapacityGovernanceDatabase & {
const reports = nodeRows.filter((row) => row.kind === 'reporting');
const reservations = await store.all('SELECT state FROM capacity_reservations WHERE team_id=? AND work_day_id=?',
[run.teamId, run.id]);
if (reports.length > 0 && reports.every((row) => row.status === 'completed')
if (reports.length > 0 && reports.every((row) => terminalNodeStates.has(String(row.status)))
&& reservations.every((row) => terminalReservationStates.has(String(row.state)))) {
next = { ...next, state: 'ended', endedAt: next.endedAt ?? now };
status = 'completed'; completedAt = completedAt ?? now;
status = reports.every((row) => row.status === 'completed') ? 'completed' : 'failed';
completedAt = completedAt ?? now;
}
}
if (same(next, plan) && status === run.status) return { changed: false, plan: next, status };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ describe('living workday lifecycle', () => {
expect(sql).not.toMatch(/capacity_workday_demands|workday_capacity_envelopes/u);
});

it.each(['failed', 'cancelled', 'stale'])('settles a %s Reporter as a failed workday, not success or an endless drain', async status => {
const closingRun = { ...run, parameters: { appliedPlan: { ...plan, state: 'closing', closingAt: now } } } as never;
const store = { all: vi.fn(async (sql: string) => sql.includes('execution_nodes')
? [{ id: 'report', kind: 'reporting', status }] : [{ state: 'released' }]),
updateCapacityWorkdayRun: vi.fn(async () => closingRun) };
expect(await advanceLivingWorkday(store as never, closingRun, now)).toMatchObject({
status: 'failed', plan: { state: 'ended', endedAt: now } });
});
it('does not end a failed Reporter until reservations are settled', async () => {
const closingRun = { ...run, parameters: { appliedPlan: { ...plan, state: 'closing', closingAt: now } } } as never;
const store = { all: vi.fn(async (sql: string) => sql.includes('execution_nodes')
? [{ id: 'report', kind: 'reporting', status: 'failed' }] : [{ state: 'consuming' }]),
updateCapacityWorkdayRun: vi.fn(async () => closingRun) };
expect(await advanceLivingWorkday(store as never, closingRun, now)).toMatchObject({
status: 'running', plan: { state: 'closing' } });
});
it('ends only after Reporter completion and reservation settlement', async () => {
const closing = { ...plan, state: 'closing', closingAt: now } as const;
const closingRun = { ...run, parameters: { appliedPlan: closing } } as never;
Expand Down
Loading