feat: dashboard reads the sprint, the risks, aging and bottlenecks
A new projectInsights reading (GraphQL Project.insights, REST
/projects/{project}/insights, MCP get_project_insights), computed by pure
functions over the read model and the timeline:
- the sprint under way: days left, points done, pace against what is
needed and whether it gets there;
- tickets at risk: overdue, due within a week, blocked by an open ticket
and stuck (7 days or more in an in-progress or QA status);
- aging of the work under way against the p85 cycle time;
- average days in each in-progress and QA status, with WIP limits.
The dashboard shows them in four new panels, reloaded on every change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
177
libs/api/tracker/application/src/lib/analytics/insights.spec.ts
Normal file
177
libs/api/tracker/application/src/lib/analytics/insights.spec.ts
Normal file
@@ -0,0 +1,177 @@
|
||||
import {
|
||||
defaultProjectSettings,
|
||||
IssueLinkType,
|
||||
IssueReadModel,
|
||||
IssueTimelineEntry,
|
||||
SprintReadModel,
|
||||
SprintStatus,
|
||||
StatusCategory as C,
|
||||
} from '@task-stream/api/tracker/domain';
|
||||
import { computeInsights, STUCK_DAYS } from './insights';
|
||||
|
||||
const NOW = new Date('2026-10-15T12:00:00Z');
|
||||
const bob = { id: 'bob', name: 'Bob' };
|
||||
|
||||
const issue = (
|
||||
id: string,
|
||||
status: string,
|
||||
category: C,
|
||||
extra: Partial<IssueReadModel> = {},
|
||||
): IssueReadModel =>
|
||||
({
|
||||
id,
|
||||
key: id,
|
||||
title: `Ticket ${id}`,
|
||||
status,
|
||||
statusCategory: category,
|
||||
assignee: bob,
|
||||
reporter: bob,
|
||||
sprint: null,
|
||||
storyPoints: null,
|
||||
dueDate: null,
|
||||
links: [],
|
||||
trashedAt: null,
|
||||
createdAt: '2026-09-01T09:00:00Z',
|
||||
updatedAt: '2026-10-14T09:00:00Z',
|
||||
...extra,
|
||||
}) as IssueReadModel;
|
||||
|
||||
let seq = 0;
|
||||
const step = (
|
||||
issueId: string,
|
||||
at: string,
|
||||
status: string,
|
||||
category: C,
|
||||
): IssueTimelineEntry => ({
|
||||
id: `${issueId}:${++seq}`,
|
||||
issueId,
|
||||
projectId: 'p',
|
||||
at,
|
||||
kind: 'status',
|
||||
status,
|
||||
category,
|
||||
assigneeId: 'bob',
|
||||
});
|
||||
|
||||
const sprint: SprintReadModel = {
|
||||
id: 's',
|
||||
projectId: 'p',
|
||||
name: 'Sprint 7',
|
||||
goal: null,
|
||||
startDate: '2026-10-12',
|
||||
endDate: '2026-10-25',
|
||||
status: SprintStatus.ACTIVE,
|
||||
startedAt: '2026-10-12T08:00:00Z',
|
||||
closedAt: null,
|
||||
createdAt: '2026-10-01T08:00:00Z',
|
||||
version: 2,
|
||||
};
|
||||
const inSprint = { sprint: { id: 's', name: 'Sprint 7' } };
|
||||
|
||||
describe('computeInsights', () => {
|
||||
it('names what is late, due soon, blocked and stuck', () => {
|
||||
const issues = [
|
||||
issue('LATE', 'TODO', C.TODO, { dueDate: '2026-10-10' }),
|
||||
issue('SOON', 'TODO', C.TODO, { dueDate: '2026-10-20' }),
|
||||
issue('LATER', 'TODO', C.TODO, { dueDate: '2026-11-30' }),
|
||||
issue('DONE_LATE', 'DONE', C.DONE, { dueDate: '2026-10-01' }),
|
||||
issue('WAITS', 'TODO', C.TODO, {
|
||||
links: [
|
||||
{
|
||||
type: IssueLinkType.BLOCKS,
|
||||
direction: 'INWARD',
|
||||
issueId: 'SLOW',
|
||||
issueKey: 'SLOW',
|
||||
},
|
||||
],
|
||||
}),
|
||||
issue('SLOW', 'IN_PROGRESS', C.IN_PROGRESS),
|
||||
issue('FRESH', 'IN_QA', C.QA),
|
||||
];
|
||||
const timeline = [
|
||||
step('SLOW', '2026-10-01T10:00:00Z', 'IN_PROGRESS', C.IN_PROGRESS),
|
||||
step('FRESH', '2026-10-14T10:00:00Z', 'IN_QA', C.QA),
|
||||
];
|
||||
const { risks, aging } = computeInsights({
|
||||
issues,
|
||||
timeline,
|
||||
settings: defaultProjectSettings(),
|
||||
activeSprint: null,
|
||||
now: NOW,
|
||||
});
|
||||
expect(risks.overdue.map((i) => [i.key, i.days])).toEqual([['LATE', 5]]);
|
||||
expect(risks.dueSoon.map((i) => [i.key, i.days])).toEqual([['SOON', 5]]);
|
||||
expect(risks.blocked.map((i) => i.key)).toEqual(['WAITS']);
|
||||
expect(risks.stuck.map((i) => [i.key, i.days])).toEqual([['SLOW', 14]]);
|
||||
expect(risks.stuckDays).toBe(STUCK_DAYS);
|
||||
// Everything under way, the longest first.
|
||||
expect(aging.issues.map((i) => [i.key, i.days])).toEqual([
|
||||
['SLOW', 14],
|
||||
['FRESH', 1],
|
||||
]);
|
||||
});
|
||||
|
||||
it('measures the sprint under way against the calendar', () => {
|
||||
const issues = [
|
||||
issue('A', 'DONE', C.DONE, { ...inSprint, storyPoints: 3 }),
|
||||
issue('B', 'IN_PROGRESS', C.IN_PROGRESS, { ...inSprint, storyPoints: 8 }),
|
||||
issue('C', 'TODO', C.TODO, { ...inSprint, storyPoints: 5 }),
|
||||
issue('X', 'CANCELLED', C.CANCELLED, { ...inSprint, storyPoints: 13 }),
|
||||
];
|
||||
const { sprint: pulse } = computeInsights({
|
||||
issues,
|
||||
timeline: [],
|
||||
settings: defaultProjectSettings(),
|
||||
activeSprint: sprint,
|
||||
now: NOW,
|
||||
});
|
||||
expect(pulse).toMatchObject({
|
||||
totalDays: 14,
|
||||
daysLeft: 10,
|
||||
tickets: 3,
|
||||
doneTickets: 1,
|
||||
points: 16,
|
||||
donePoints: 3,
|
||||
// 3 points in 3 days; 13 left for 11 days.
|
||||
pacePerDay: 1,
|
||||
neededPerDay: 1.2,
|
||||
behind: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('finds where tickets wait, and columns over their limit', () => {
|
||||
const settings = defaultProjectSettings();
|
||||
settings.statuses.find((s) => s.id === 'IN_REVIEW')!.wipLimit = 1;
|
||||
const issues = [
|
||||
issue('A', 'DONE', C.DONE),
|
||||
issue('B', 'IN_REVIEW', C.IN_PROGRESS),
|
||||
issue('C', 'IN_REVIEW', C.IN_PROGRESS),
|
||||
];
|
||||
const timeline = [
|
||||
step('A', '2026-10-01T10:00:00Z', 'IN_PROGRESS', C.IN_PROGRESS),
|
||||
step('A', '2026-10-03T10:00:00Z', 'IN_REVIEW', C.IN_PROGRESS),
|
||||
step('A', '2026-10-07T10:00:00Z', 'DONE', C.DONE),
|
||||
];
|
||||
const rows = computeInsights({
|
||||
issues,
|
||||
timeline,
|
||||
settings,
|
||||
activeSprint: null,
|
||||
now: NOW,
|
||||
}).bottlenecks;
|
||||
expect(rows.map((r) => r.status)).toEqual([
|
||||
'IN_PROGRESS',
|
||||
'IN_REVIEW',
|
||||
'READY_FOR_QA',
|
||||
'IN_QA',
|
||||
'QA_FAILED',
|
||||
]);
|
||||
expect(rows[0]).toMatchObject({ averageDays: 2, samples: 1, open: 0 });
|
||||
expect(rows[1]).toMatchObject({
|
||||
averageDays: 4,
|
||||
open: 2,
|
||||
wipLimit: 1,
|
||||
overLimit: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user