test(coverage): db/cache/nosql local providers to >=95% via source seams#151
Merged
Merged
Conversation
…rce seams Closes the coverage gap on the three local-backend providers to the >=95% mandate using deterministic source seams (org policy: seams, not waivers). Production defaults are identical — every seam defaults to the real fn/value. Coverage (per-package, real pg16/redis7/mongo6 on 127.0.0.1): - internal/providers/db: 2.2% -> 97.8% (local.go fully covered) - internal/providers/cache: 64.8% -> 98.2% - internal/providers/nosql: 70.3% -> 100.0% Seams added (all package vars / interfaces, real default): - db/local.go: randInt (crypto/rand.Int), pgConn interface + pgxConnect factory — drives the RNG failure, conn.Close defer-error logs, and the non-fatal REVOKE/GRANT/DROP USER exec-error logs via an in-memory fake. - cache/redis.go: randRead (crypto/rand.Read); storageBytesScanCap (test-lowerable truncation ceiling, default storageMaxKeys=200k); redisScanner interface behind storageBytes — drives the mid-scan vanished-key skip deterministically (fake returns a SCAN key that MEMORY USAGE reports missing) and the truncation branch with a handful of keys (no 200k write, no timing). - nosql/mongo.go: randRead (crypto/rand.Read); mongoDisconnect seam for the Disconnect defer-error logs; storageSizeToInt64 extracted so every numeric BSON arm is unit-testable. Replaces the flaky timing-based MEMORY-USAGE-skip test from the prior attempt with a deterministic interface fake. Aligns the db test env var to TEST_POSTGRES_CUSTOMERS_URL (what CI's coverage.yml provides; the prior attempt used TEST_CUSTOMERS_URL and silently skipped in CI). Hardens uniqueToken with a per-run random seed so same-second runs against a shared Postgres can't collide. Tests are CI-safe (skip cleanly with no env) and stable across 3 consecutive full runs. Supersedes PR #148. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
3 tasks
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 the coverage gap on the three local-backend providers to the >=95% mandate using deterministic source seams (org policy now requires seams, not waivers). Production defaults are unchanged — every seam defaults to the real fn/value.
internal/providers/dbinternal/providers/cacheinternal/providers/nosqlSeams added (package vars / interfaces, real default)
randInt(crypto/rand.Int),pgConninterface +pgxConnectfactory. An in-memory fakepgConndrives the RNG failure, theconn.Closedefer-error logs, and the non-fatal REVOKE / GRANT / DROP USER exec-error logs.randRead(crypto/rand.Read);storageBytesScanCap(test-lowerable truncation ceiling, defaultstorageMaxKeys=200k);redisScannerinterface behind astorageByteshelper. The mid-scan vanished-key skip is now deterministic (a fake returns a SCAN key that MEMORY USAGE reports missing); the truncation branch fires with a handful of keys (no 200k write, no timing).randRead(crypto/rand.Read);mongoDisconnectseam for the Disconnect defer-error logs;storageSizeToInt64extracted so every numeric BSON arm is unit-testable.Notable fixes over the prior attempt (supersedes #148)
TEST_POSTGRES_CUSTOMERS_URL(what CI'scoverage.ymlprovides). The prior attempt usedTEST_CUSTOMERS_URLand silently skipped in CI, contributing zero coverage.uniqueTokenwith a per-run random seed so same-second runs against a shared Postgres can't collide with orphan databases.Test plan
go test ./internal/providers/{db,cache,nosql} -count=1 -p 1green against local docker pg16 / redis7 / mongo6 on 127.0.0.1go build ./...+go vet ./...clean;gofmt -lclean🤖 Generated with Claude Code