test(coverage): api handlers resource/billing/webhooks slice + internal/db → ≥95%#160
Open
mastermanas805 wants to merge 10 commits into
Open
test(coverage): api handlers resource/billing/webhooks slice + internal/db → ≥95%#160mastermanas805 wants to merge 10 commits into
mastermanas805 wants to merge 10 commits into
Conversation
Adds package-var seams (readMigrationDir/readMigrationFile/sqlOpen in internal/db; readyzSQLOpen in handlers) to reach the genuinely-unreachable embed-read / lazy-driver-open error branches, plus a synchronous runExporterLoop split so the ctx.Done arm is recorded deterministically. - internal/db: 94.7% → 100.0% - handlers/readyz.go: customerDBCheck, redisFailedPing, statusToFloat, buildChecks upstream branches all ≥95% Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dev.go: NewSetTierHandler all arms (invalid body/team_id/tier/uuid, upgrade failure via closed pool, success via real team). openapi.go: SetOpenAPIEnvironment empty-guard, ServeOpenAPI dev+prod(cached) paths, stripInternalSetTierPath edge guards (no-colon/no-brace/unbalanced), escaped-string brace walker, middle-vs-last-entry comma trimming. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…udit emitters
- Provider helpers (revoke/grant Postgres/Mongo, setRedisACLEnabled,
rotate{Postgres,Redis,Mongo}Password): validation, open/connect (via
resourcePGOpen/resourceMongoConnect seams), exec/command-error, and
real-backend success arms.
- Handler methods (List/Get/Delete/GetCredentials/RotateCredentials/Pause/
Resume): unauthorized, invalid-uuid, not-found, cross-team-404, DB-error,
no_connection_url, aes_key_invalid, decrypt_failed arms via Locals-shim app.
- Audit emitters → 100% (user-actor arm + InsertAuditEvent warn arm).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds provider-no-op arms (redis/mongo/storage), provider-failed 503 arms, tier-gate, already-paused/invalid-state/not-paused conflicts, rotate provider-warn arms (postgres/redis/mongo non-fatal), and Pause/Resume/Delete success paths via a no-backend Locals-shim fixture. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…xStored/decrypt verifyWebhookHMAC, lookupIdempotentReceive, storeIdempotentReceive, decryptWebhookURL → 100%; webhookMaxStored → 100% (floor arm via custom 0-stored plans registry); storeEncryptedURL success+update-fail+key-parse arms. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
isValidEmail (all reachable rejection arms incl. angle-addr), maskEmailForLog → 100%, emitOnboardingClaimedAudit → 100% (success + Nil-user + warn arms), sendClaimVerificationEmail (nil-mailer, empty-email, send-success, send-fail, create-link-fail arms). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
adminParseTierFilter (all return cases), adminParseLimit/Offset (clamp arms), adminOrderClause (all sort keys + invalid), escapeLikePattern, computeMRR (nil-plans + priced), parsePromoAuditSince (RFC3339/date/empty/invalid). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Internal tests over the unexported rzp* webhook types: nil/bad-json/valid payment entity; receipt dedup key empty-sub / paid_count / payment-id-fallback / neither arms. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ateNote arms invalid-uuid, db_failed (list/delete), team_not_found, missing/empty/too-long body, note_not_found, success arms via Locals-shim notes app. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
invalid_team_id, team_not_found(404), db_failed(503), team_has_no_users(409), and the JWT-mint success path via Locals-shim app + real team/user rows. 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 the coverage gap on the resource-lifecycle / billing / webhooks / onboarding / admin / misc handler slice of
internal/handlers, plus bringsinternal/dbto 100%. Seams not waivers — every genuinely-unreachable branch (lazysql.Open/mongo.Connect, embedded-FS read failures, goroutine-recorded coverage) is reached via a package-var seam, not skipped.Disjoint from the concurrent provisioning-arm slice (db/cache/nosql/queue/storage/provision_helper/family_bulk_twin) — no shared files touched. All new test files use the
_rbwsuffix and a separateexport_rbw_test.goto avoid collisions.Coverage block (per-file, before → after, statement coverage)
internal/db(package)internal/handlers/readyz.gointernal/handlers/openapi.gointernal/handlers/dev.gointernal/handlers/resource.gointernal/handlers/webhook.gointernal/handlers/onboarding.gointernal/handlers/billing.gointernal/handlers/admin_customer_notes.gointernal/handlers/admin_impersonate.gointernal/handlers/admin_promos_audit.gointernal/handlers/admin_customers.gointernal/handlers/helpers.gointernal/handlers/brevo_webhook.go(Per-file numbers measured against a full
go test ./internal/handlers/... -p 1run with live Postgres/Redis/Mongo backends.internal/dbis independently 100%.)Functions brought to ≥95% (highlights)
RunMigrations,embeddedMigrationFilenames,ConnectPostgres,StartPoolStatsExporter— all 100% viareadMigrationDir/readMigrationFile/sqlOpenseams + a synchronousrunExporterLoopsplit (the ctx.Done arm is now recorded deterministically instead of racing the goroutine's exit).customerDBCheck,redisFailedPing,statusToFloat,buildChecksupstream branches,Getdrain path — all ≥95%.revoke/grantPostgresConnect,setRedisACLEnabled,revoke/grantMongoRoles,rotate{Postgres,Redis,Mongo}Password) viaresourcePGOpen/resourceMongoConnectseams + real-backend success arms; audit emitters → 100%; handler unauthorized/invalid-uuid/not-found/cross-team/DB-error/no_connection_url/aes_key_invalid/decrypt_failed/tier-gate/conflict/provider-failed arms.verifyWebhookHMAC, idempotency lookup/store,decryptWebhookURL→ 100%;webhookMaxStored→ 100% (floor arm via a custom 0-stored plans registry).isValidEmail,maskEmailForLog,emitOnboardingClaimedAudit→ 100%;sendClaimVerificationEmailarms.chargedPaymentMeta,receiptDedupKey→ 100%.adminParseTierFilter/Limit/Offset,adminOrderClause,computeMRR,parsePromoAuditSince,escapeLikePattern) → 100%; notesListNotes/DeleteNote→ 100%; impersonate + create-note error arms.Functions still < 95% (seam tried / why)
The remaining gaps are large request-flow handler methods that need full admin-auth + provisioning backends end-to-end, plus a handful of genuinely-unreachable defensive arms:
resource.go::Delete(73.7%) — storage-deprovision + provisioner-deprovision branches need astorageProvider/ gRPCprovisionermock; the soft-delete-fail arm needs a mid-call DB failure.resource.go::resumeProvider(77.8%),revokePostgresConnect/*MongoRoles(90–92%) — the pg_terminate_backend and mongo-disconnect warn arms are best-effort error logging unreachable after a successful primary op.webhook.go::{NewWebhook, newWebhookAuthenticated, Receive, ListRequests},onboarding.go::{Claim, ClaimPreview, StartLanding},admin_customers.go::{List, Detail, ChangeTier, IssuePromo}— full provisioning/auth request flows; partially covered by existing happy-path tests, the uncovered remainder is error/edge arms.webhook.go::storeEncryptedURL(88.9%) and several*_invalid/*_failed5xx arms — thecrypto.Encrypt-fail / partial-DB-fail arms need a crypto seam / mid-transaction failure injection.Notes
go build ./... && go vet ./internal/handlers/ ./internal/db/).TestStackDelete_AnonymousImmediate/TestStackLogs_AnonymousStackReadable(stack.go — not this slice) andTestAdminList_AdminUserSees200(passes on a fresh DB; failed only under accumulated test-data pollution from repeated local runs). No_rbwtest fails.🤖 Generated with Claude Code