Skip to content

test(jobs): close sub-95% residual branches via test seams - #54

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/worker-sub95-seams
May 22, 2026
Merged

test(jobs): close sub-95% residual branches via test seams#54
mastermanas805 merged 1 commit into
masterfrom
coverage/worker-sub95-seams

Conversation

@mastermanas805

Copy link
Copy Markdown
Member

Summary

New org policy forbids coverage waivers. Three job files landed below the >=95% mandate; this PR closes them using package-var test seams that make otherwise-unreachable defensive arms exercisable, with production defaults byte-for-byte identical.

File Before After
internal/jobs/quota_infra.go 93.5% 98.4%
internal/jobs/expire_imminent.go 90.4% 96.2%
internal/jobs/expiry_reminder_email.go 84.0% 100%

Seams

  • sqlOpen (quota_infra): drives the lib/pq lazy-open error fail-open arm — lib/pq's sql.Open never errors at Open time in prod (errors surface lazily on first use).
  • validateIdent (quota_infra): drives the usr_-identifier guard — db_<token>/usr_<token> share the same token, so the db check always short-circuits first for any failing token in prod.
  • jsonMarshal (expire_imminent): drives the primitive-only-map marshal-error skip branch.
  • template package vars (expiry_reminder_email): swap in templates whose Execute fails, driving both Sprintf fallback bodies guarded by template.Must at init.

All overrides restore the production binding in t.Cleanup.

Test plan

  • go build ./... && go vet ./... green
  • CI gate go test ./... -short -count=1 green (exit 0)
  • Full job suite green against Docker pg/redis/mongo
  • Per-file coverage recomputed from cover -func profile — all three >=95%

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

New org policy forbids coverage waivers, so the three job files that
landed below the >=95% mandate are closed using package-var test seams
that make otherwise-unreachable defensive arms exercisable while keeping
production defaults byte-for-byte identical:

- quota_infra.go (93.5% -> 98.4%): route sql.Open through `sqlOpen` and
  validateSuspendIdent through `validateIdent` package vars. The seams
  drive the lib/pq lazy-open error fail-open arm (Open never errors at
  Open time in prod) and the usr_-identifier guard (db_/usr_ share a
  token so the db check always short-circuits first in prod).
- expire_imminent.go (90.4% -> 96.2%): route json.Marshal through a
  `jsonMarshal` package var to drive the primitive-only-map marshal-error
  skip branch.
- expiry_reminder_email.go (84.0% -> 100%): swap the html/text template
  package vars for templates whose Execute fails, driving both Sprintf
  fallback bodies guarded by template.Must at init.

All seam overrides restore the production binding in t.Cleanup. CI gate
(go build + vet + go test ./... -short) green; full job suite green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805
mastermanas805 merged commit 92d7f8e into master May 22, 2026
9 of 10 checks passed
@mastermanas805
mastermanas805 deleted the coverage/worker-sub95-seams branch May 22, 2026 02:37
mastermanas805 added a commit that referenced this pull request Jun 5, 2026
Closes the 100%-patch gaps on deploy_idle_scaler.go: Kind(), the no-config
cluster-constructor error path (CI-only, gated like the status client),
list-query error, scan error, foreign provider_id skip, db-flip error,
gauge-sample error. Work() and the SQL helpers now 100%.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mastermanas805 added a commit that referenced this pull request Jun 5, 2026
…#94)

* feat(jobs): deploy_idle_scaler — scale-to-zero idle descheduler (Task #54)

Worker half of scale-to-zero. New periodic job (every 2 min) that patches
idle, healthy, not-pinned deployments to replicas=0 (~$0 compute) — reversible
via the api wake endpoint. Sibling to deployment_expirer (idle ≠ expired).

Flag-gated behind DEPLOY_SCALE_TO_ZERO_ENABLED (default OFF): Work()
short-circuits at DEBUG when off — no k8s patch, no DB write (proven by
TestDeployIdleScaler_FlagOffNoOp: zero SQL issued, zero scale calls). Fail-open
when k8s is unreachable (nil client → WARN per tick, other jobs unaffected).

Idle SIGNAL (stated honestly): deployments.last_activity_at (api migration 068)
— stamped at create, bumped on deploy/redeploy/wake. v1 idle = "no
deploy/redeploy/wake for N min" (default 30, floored at 5), NOT per-HTTP
traffic, because the api/worker are not in the request path and no
nginx-ingress request scrape is wired yet. Follow-up noted in the job header to
lift this to traffic-based idle.

CAS double-guard: candidate SELECT and the scaled_to_zero UPDATE share the
healthy + not-zeroed + not-always-on predicate, so a row that raced into a
woken/pinned/redeployed/expired state between SELECT and UPDATE is skipped
(0 rows), never wrongly slept. NotFound Deployment = skip (torn down), not fail.

Metric (rule 25): instant_deploy_scaled_to_zero_total{outcome} (scaled_down |
woke_up | wake_failed | scale_failed) + instant_deploy_idle_apps gauge, primed
in metrics_test.go. Alert+tile+catalog ship in the infra PR.

Tests: flag-off no-op, nil-k8s no-op, scale-down happy path (+counter+gauge),
CAS-race skip, NotFound skip, scale-error → scale_failed, idle-minutes floor,
provider_id→namespace derivation, real k8sDeployScaleClient vs fake clientset.
make gate GREEN.

Awaiting operator enable of DEPLOY_SCALE_TO_ZERO_ENABLED to verify real
scale-down in prod.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(jobs): idle-scaler error-branch + Kind/cluster-ctor coverage (#54)

Closes the 100%-patch gaps on deploy_idle_scaler.go: Kind(), the no-config
cluster-constructor error path (CI-only, gated like the status client),
list-query error, scan error, foreign provider_id skip, db-flip error,
gauge-sample error. Work() and the SQL helpers now 100%.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(scale-to-zero): cover idle-scaler cluster-ctor + config env-parse + AddWorker wiring

Closes the 6 uncovered changed lines flagged by the patch-coverage gate:

- config: DEPLOY_SCALE_TO_ZERO_IDLE_MINUTES parse branch (valid override +
  sub-5/non-numeric floor-to-30) now exercised directly.
- deploy_idle_scaler: introduce newDeployScaleClientset package-var seam so
  NewK8sDeployScaleClientFromCluster's success return is testable without a
  reachable cluster; add a success test alongside the NoConfig error test.
- workers: extract the idle-scaler k8s-client wiring (the AddWorker else-branch)
  into a unit-testable buildIdleScaleK8s helper; cover both the success and the
  fail-open (nil) branches via the seam.

Flag remains default-OFF; behaviour unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant