Plan: Fix MetricsSummary successRate and add inProgressCount#
Summary#
The computeSummary method in MetricsService already uses a terminal-only denominator (complete + failed + stopped + stuck), but the MetricsSummary interface lacks an inProgressCount field for in-flight tasks (blocked + gated). This plan adds that field, adds the required code comment at the zero-denominator guard, and extends tests to cover the corrected formula and edge cases.
Files#
| File | Action | Description |
|---|---|---|
src/metrics/metrics.types.ts | modify | Add inProgressCount: number to MetricsSummary interface |
src/metrics/metrics.service.ts | modify | Compute inProgressCount from blocked + gated, add code comment at zero-denominator guard |
src/metrics/metrics.service.spec.ts | modify | Add tests for inProgressCount, zero-terminal edge case, and the issue's exact scenario (27/45 ≈ 0.60) |
Steps#
- Add
inProgressCount: numberfield to theMetricsSummaryinterface inmetrics.types.ts. - In
metrics.service.tscomputeSummary(), computeinProgressCountas(byStatus['blocked'] ?? 0) + (byStatus['gated'] ?? 0)and include it in the return object. - Add inline comment
// successRate is 0.0 when no terminal tasks existat the zero-denominator guard (line 89). - In
metrics.service.spec.ts, add test: given 27 complete, 10 failed, 5 stopped, 3 stuck, 23 blocked, 15 gated →successRate ≈ 0.60andinProgressCount === 38. - Add test: when all tasks are blocked/gated (zero terminal),
successRate === 0.0andinProgressCountequals total task count. - Update the existing zero-tasks test to assert
inProgressCount === 0.
Verification#
npm run testpasses with all new and existing tests green.npm run lintpasses with zero warnings.npm run buildcompiles without errors.
Risks#
- Status string mismatch: The code uses
byStatus['complete'](not'completed'). The acceptance criteria says "completed" — need to verify the actual DB status string iscomplete. The existing test on line 91 confirms'complete'is correct.