test(coverage): api handlers residual files + middleware → ≥95%#162
Merged
mastermanas805 merged 1 commit intoMay 23, 2026
Merged
Conversation
Raise the handler files the prior slice left below 95% (resource, webhook, onboarding, admin_customers, admin_impersonate, admin_promos_audit, admin_customer_notes, billing) plus internal/middleware to ≥95%. Seams added (production behavior unchanged — vars default to the real fn): - admin_impersonate.go: signImpersonationToken var (drives sign_failed 503). - webhook.go: cryptoEncrypt var (drives storeEncryptedURL encrypt-fail). Techniques: brokenDB closed-pool for db_failed arms; DATA-DOG/go-sqlmock for mid-sequence failures (mark-converted / team-create / user-create, soft-delete, List scan/rows-err, Detail per-query failures); bufconn fakeProvisioner for the Delete gRPC-deprovision arm; a dead MinIO endpoint for the storage-deprovision warn arm; dead-Redis clients for fail-open arms; real onboarding JWTs minted in-process for claim/preview/start branches; the cov2 webhook harness for the payment-failed + charged-receipt arms. All new test files carry a _residual suffix; new re-exports live in export_residual_test.go (no edits to the shared export_test.go / export_rbw_test.go / export_billing_test.go). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7f086d7 to
03dba73
Compare
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
Residual-coverage follow-up: raises every
internal/handlersfile the priorslice (#160) left below 95% to ≥95% where reachable, plus closes the tiny
internal/middlewaregap. Seams not waivers — two minimal package-varindirections were added (production behaviour unchanged) so the two
defensive crypto/JWT-sign error arms are deterministically reachable.
Targets a coverage integration branch (
coverage/api-integration), notmaster.Coverage block (before → after)
internal/handlers/admin_customers.gointernal/handlers/admin_impersonate.gointernal/handlers/admin_promos_audit.gointernal/handlers/admin_customer_notes.gointernal/handlers/billing.gointernal/handlers/onboarding.gointernal/handlers/resource.gointernal/handlers/webhook.gointernal/middleware(package)How
*sql.DBpool) drives thedb_failed/fetch_failed/lookup_failedarms.fakeProvisionerdrives the resourceDeletegRPC-deprovision arm.Backend()==MinIOAdminaudit branch./claim/claim/preview/startvalidation + single-use + 409 + transfer branches.payment.failedno-primary-user + charged-receipt arms.Seams added (production behaviour unchanged)
admin_impersonate.go:var signImpersonationToken = func(...)— the only deterministic way to hitsign_failed(HS256 sign with a[]bytekey never fails in prod).webhook.go:var cryptoEncrypt = crypto.Encrypt— the only deterministic way to hitstoreEncryptedURL's encrypt-failed arm (AES-256-GCM never fails with a valid key).Both default to the real function; only test code swaps them via
export_residual_test.go.Conflict-avoidance
All new test files carry a
_residualsuffix. New re-exports live in a NEWinternal/handlers/export_residual_test.go; the sharedexport_test.go/export_rbw_test.go/export_billing_test.goare untouched (verified noduplicate re-exports — a dup would be a compile error).
Verification
go build ./...+go vet ./internal/handlers/ ./internal/middleware/clean.Full hermetic suite
go test ./internal/handlers/... ./internal/middleware/... -short -p 1green (EXIT=0, 0 FAIL) against postgres:16 / redis:7 / mongo:6 service containers.🤖 Generated with Claude Code
Remaining under 95% — residual arms + seam attempted
Four files improved substantially but did not reach 95% on this slice. The
residual uncovered statements are concentrated in arms that need invasive
mid-flow failure injection (not reachable with the brokenDB/sqlmock/dead-Redis
seams used here without a deeper production rewrite). Documented per the
"no waiver without a seam attempt" rule:
webhook.go (90.3%) — uncovered: the anonymous-provision success error
arms (
finalizeProvision-fail,issueOnboardingJWT-fail,createOnboardingEvent-fail at the end ofNewWebhook), the auth-pathCreateResource-fail +finalizeProvision-fail arms, the Receive HMAC-secretlookup-error arm, and the Receive
json.Marshal-fail arm. Seam tried: sqlmockmid-provision — but
NewWebhookrunsparseProvisionBody → requireName → resolveEnv → checkProvisionLimit → CreateResource → finalizeProvision → issueOnboardingJWTagainst the same*sql.DB; mocking that exact orderedmulti-query sequence is brittle (every query string + arg must match) and a
single mismatch fails the whole flow, so I covered the reachable validation +
dedup + Receive + ListRequests + storeEncryptedURL arms instead.
billing.go (93.6%) — uncovered: deep
RazorpayWebhooksub-handler arms(
handleSubscriptionChargedunknown-tier / lower-tier-charge sub-id-updatefailures,
handleSubscriptionPausedgrace-start-fail,maybeRecoverPaymentGracegrace-recover-fail / race-not-flipped) and the
ListInvoicesAPI/UpdatePaymentMethodAPIcircuit-open + success arms. Seam tried: the cov2webhook harness covers many charged/failed paths, but the sub-id-update-fail and
grace-recover-fail arms need a DB that succeeds on the lookup then fails on the
immediately-following write within one handler — a partial-failure injection the
live test DB can't produce and full sqlmock of the webhook sequence is infeasibly
brittle. The portal circuit-open + invoice-list-success arms need a real Razorpay
client behind an open breaker (no seam to force the breaker open from a test).
resource.go (92.8%) — uncovered:
RotateCredentialsrand.Read-fail(unreachable — crypto/rand never fails on these platforms), url-parse-fail
(decrypt succeeds but yields a malformed URL — decrypt-fail fires first), and
encrypt-fail (would need the same
cryptoEncryptseam pattern but the rotatepath calls
crypto.Encryptdirectly); the mongo provider pause/resume +rotateMongoPasswordarms (need a live MongoDB admin connection with apre-seeded user). The redis provider arm IS now covered (via the live test
Redis ACL toggle).
onboarding.go (93.8%) — uncovered: a few
Claimresource-transfermicro-arms inside the JWT-listed-token loop that overlap with the
fingerprint loop, the
sendClaimVerificationEmailGenerateMagicLinkPlaintext-failarm (unreachable — never fails), and
StartLanding/ClaimPreviewredirectmicro-branches. The reachable validation, single-use 409, db-error, account-exists,
create-failure (sqlmock), and fingerprint-augmentation arms are covered.