test(coverage): worker logsafe/migrations/root ≥95%#56
Merged
Conversation
Drive three coverage gaps to ≥95% (all hit 100%) via test seams, no waivers: - internal/logsafe (88.9% → 100%): cover itoa's n==0 and defensive n<0 branches with a direct unit test. - internal/migrations (93.9% → 100%): cover NewReader's ttl<=0 default-clamp branch and queryState's COUNT-query error path with sqlmock. - root package main.go (0% → 100%): introduce a run(ctx, deps) seam plus realMain/main wrapper indirection. Extract setupLogger, resolvePlansPath, loadPlanRegistry, newHealthzHandler, buildMux, serveLiveness/ startLivenessServer/shutdownLivenessServer, awaitShutdown, setupTelemetry/ telemetryCleanup, connectProvisioner, deployK8sInitOK, prodStartWorkers, newSignalContext. Inject infra constructors (deps struct + package vars osExit/signalCtxFn/realMainFn/newDeployK8sClients) so the full boot/shutdown path is exercised with sqlmock + miniredis + a fake workerSet and a cancelled context — no real Postgres/Redis/gRPC/River. - cmd/smoke-buildinfo (0% → 50%): extract render(io.Writer) seam + test; main() is the irreducible one-line wrapper. Full suite `go test ./...` builds; target packages pass under -race; go build ./... && go vet ./... clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes three code-coverage gaps in the worker repo, driving each target area to 100% (well above the 95% floor), using test seams not waivers.
Coverage block (before → after)
internal/logsafeinternal/migrationsinstant.dev/worker(main.go)cmd/smoke-buildinfo(bonus)Measured by full-suite
go test ./... -short. Full suite passes; all other packages unchanged.What changed
internal/logsafe(88.9 → 100): added a direct unit test for the unexporteditoahelper covering then==0and defensiven<0branches thatToken()can't reach via a reallen()argument.internal/migrations(93.9 → 100): added tests forNewReader'sttl<=0default-clamp branch (behavioural — verifies the cache TTL is positive) andqueryState's COUNT-query error path (sqlmock). No DB required — the package already uses go-sqlmock.root
main.go(0 → 100): the binary'smain()was one large untestable function. Refactored using the standard Go main-coverage seam:setupLogger,resolvePlansPath,loadPlanRegistry,newHealthzHandler,buildMux,serveLiveness/startLivenessServer/shutdownLivenessServer,awaitShutdown,setupTelemetry/telemetryCleanup,connectProvisioner,deployK8sInitOK,newSignalContext.run(ctx, deps) intseam where infra constructors are injectable (depsstruct) plus package-var indirection (osExit,signalCtxFn,realMainFn,newDeployK8sClients).main()is now a thinosExit(realMainFn(...))wrapper, itself covered by swapping its indirected collaborators.workerSet+ a cancelled context — no real Postgres / Redis / gRPC / River. A genericforceErr3wrapper exercises the fail-open k8s-init branch without naming the unexported provider types.cmd/smoke-buildinfo(bonus): extracted arender(io.Writer)seam (100% covered); the remainingmain()is the irreducible one-line wrapper.Verification
go build ./...cleango vet ./...clean-racego test ./... -shortgreen🤖 Generated with Claude Code