---
id: w8/m1/t008
title: Test coverage — rollup correctness, idempotency, catch-up
worker: worker8
status: done
estimate: 45m
depends_on: [w8/m1/t006]
---

## Objective

Add meaningful tests for the behavior this milestone shipped, asserting real behavior and failure modes: window-bounded rollup math, upsert idempotency, restart catch-up bounds, the store-or-prom-unset ⇒ loop-never-starts gate, and month-boundary aggregation. No tautological or snapshot-everything tests.

## Context

- Standing closing task (`.claude/commands/pm.md`); patterns: `internal/metrics/*_test.go` (fake prom), `internal/store/fake_test.go` + `store_pg_test.go`.

## Steps

1. Sweep t001–t005 for asserted-but-untested claims (each task's acceptance criteria are the checklist).
2. Fill gaps: catch-up double-run, Prometheus-unavailable tick (skip + retry next tick, no partial rows), unknown-workspace attribution.
3. `cd lego/backend && go test ./...` and `make lint-backend` (from `lego/operator/`) green.

## Files

- `lego/backend/internal/usage/*_test.go`, `lego/backend/internal/store/*_test.go`

## Acceptance criteria

- [ ] Failure modes are tested (prom down mid-tick, restart catch-up, month boundary), not just happy paths.
- [ ] `go test ./...` + `make lint-backend` pass.

## Out of scope

- m2 adapter tests.
