---
id: w1/m20/t007
title: Test coverage — reconciler unit + envtest, surface tests
worker: worker1
status: done
estimate: 40m
depends_on: [w1/m20/t005]
---

## Objective

Add meaningful tests for the behavior this milestone shipped: the scale-up/scale-down decision logic, the clamping to [min,max], the no-op-when-unchanged guard, and the API surface round-trip. Assert real behavior and failure modes — no tautological or snapshot-everything tests.

## Context

- Operator tests: unit for the desired-replicas math + envtest for the reconcile loop with an injected metrics source.
- Backend tests: `PUT`/`DELETE …/autoscaling` round-trip + error shapes.

## Steps

1. Unit-test the utilization→replicas computation (up, down, clamp, hysteresis boundary).
2. Envtest the reconciler: above target → scales up ≤ max; idle → scales down ≥ min; never writes when unchanged.
3. Backend surface tests for the REST/GraphQL/MCP verbs.

## Files

- `lego/operator/internal/controller/…_test.go`, `lego/backend/…_test.go`

## Acceptance criteria

- [ ] Tests fail if the clamp or no-op guard regresses.
- [ ] `make test` + backend `go test ./...` green.

## Out of scope

- Non-autoscaling behavior.
