Repository navigation
test(mocks): route the last five mistyped-.Return panics through testReporter and guard against new ones; assert the 5xx rejection directly - #1561
Conversation
…Reporter GetMarketplaceListingAttempt, ListMarketplaceListingsToPoll, ListStoredRecommendationsChunk, ListHistoryExecutionsPage and ListPurchaseHistoryPage still did a bare panic on a mistyped .Return, which ends the whole test binary instead of failing the registered test under the method's name. They now call m.reporter.wrongReturnType like the other sites, so TestMocks_EveryWrongReturnTypeSiteReportsItsOwnMethod picks them up. TestMocks_NoBarePanicOutsideTestReporter parses the package's non-test files and fails on any panic( outside testReporter.fail, so a new mock method cannot reintroduce the pattern. Refs LeanerCloud#353 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ejecting
'includes status code in error' asserted inside a catch block, so if
apiRequest resolved on a 500 instead of rejecting, no assertion ran and
Jest reported a pass. Assert the rejection itself with
rejects.toMatchObject({ status: 500 }).
Refs LeanerCloud#353
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
govulncheck in the Docker image build now fails on these two advisories, both fixed in x/net v0.62.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent review (IAmJSD's agent, fresh context, given only the diff, the issue and the PR text): VERDICT: APPROVE Head moved from Blocking:
Non-blocking:
Attacked:
Body-stale:
Reviewer: rG2. Bar while the maintainers are away (set by IAmJSD as acting owner): one approving independent review on the head, two for money, auth and security paths. |
|
Local verification at |
|
Merged by IAmJSD's agent at IAmJSD's request (IAmJSD is acting owner while the maintainers are away), under the bar IAmJSD set: 1 approving independent review(s) on |
… through testReporter Main's bare-panic guard (LeanerCloud#1561) rejects the two bare panics in MockAuthStore.CreateMFALoginToken and ClaimMFALoginTokenAttempt; report them through m.reporter.wrongReturnType like the other mocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he password (#1571) * feat(auth): issue a single-use MFA login token instead of resending the password A correct password for an MFA-enrolled user answered only mfa_required, so the browser kept the plaintext password in memory until the user typed the code and sent password + code again. That answer now also carries mfa_token: a random token whose SHA-256 is stored in mfa_login_tokens (migration 000152), bound to the user and to the password version the password step verified, valid for 5 minutes and for 3 code attempts. The code step can send {email, mfa_token, mfa_code} with no password. Each attempt is claimed in one UPDATE before the code is checked, so concurrent guesses cannot exceed the cap; only the request that deletes the token gets a session. Wrong codes still count toward the account lockout and the per-account login_mfa bucket, and the password + code form keeps working until the frontend switches. Refs #134 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(mocks): route the MFA login token mocks' mistyped-.Return errors through testReporter Main's bare-panic guard (#1561) rejects the two bare panics in MockAuthStore.CreateMFALoginToken and ClaimMFALoginTokenAttempt; report them through m.reporter.wrongReturnType like the other mocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(server): rename the round-trip password constant so git-secrets doesn't flag it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Two remaining test-integrity items from #353. Other parts of that issue stay open.
1. The last five bare
panic(...)sites ininternal/mocksRoot cause. #1270 moved 82 of the mocks' type-assertion sites onto
testReporter. Mock methods added since then went back to the old pattern:panic(fmt.Sprintf("mock: expected ..."))on a mistyped.Return(...). A panic like that ends the whole test binary. The remaining tests in the package don't run,TestMainteardown (such as a shared Postgres container) is skipped, and the output is a stack trace instead of a failure filed under the test's name. On main (7b86e38), five sites ininternal/mocks/stores.gostill do this:GetMarketplaceListingAttemptListMarketplaceListingsToPollListStoredRecommendationsChunkListHistoryExecutionsPageListPurchaseHistoryPageFix. Each site now calls
m.reporter.wrongReturnType(<method>, <want type>, <got>), the same as the other 82. A mock with a registered test fails that test under the method's name. Without a registered test,testReporter.failstill panics, now naming the method. Behavior for correctly typed returns is unchanged.Guard. The new
internal/mocks/bare_panic_guard_test.go(TestMocks_NoBarePanicOutsideTestReporter) parses the package's non-test files. It fails on any call topanic(outsidetestReporter.fail, the one allowed site, and reports each offender asfile:line:col in Recv.Method(orpackage scope). It also checks itself: it fails if it can no longer find the allowed panic, so a broken scan can't pass vacuously. Because the five methods now callwrongReturnType, the existingTestMocks_EveryWrongReturnTypeSiteReportsItsOwnMethoddiscovers them automatically. It checks that each one fails the registered test under its own name instead of panicking or returning.2.
frontend/src/__tests__/api.test.ts'includes status code in error'The assertion sat inside a
catchwith noexpect.assertions. IfapiRequestresolved on a 500 instead of rejecting, no assertion ran and Jest reported a pass. It is nowawait expect(apiRequest('/test')).rejects.toMatchObject({ status: 500 }). This is the only frontend file touched, as allowed for this task.Refs #353
Verification
All evidence below is unit, mock or fixture evidence. Nothing here touches a database or a real service.
Fail-before / pass-after (mocks).
TestMocks_NoBarePanicOutsideTestReporterfails, listing exactlystores.go:962,:1013,:1816,:2097and:2128in the five methods above. After the fix it passes.TestMocks_EveryWrongReturnTypeSiteReportsItsOwnMethod/MockConfigStore.<method>subtests pass. They did not exist before, because the scan only findswrongReturnTypecallers.Mutation probes (each applied alone, then reverted) all fail the named test:
panic("probe")added insideMockSESClient.SendEmailses.go:21:3 in MockSESClient.SendEmailvar _ = func() int { panic("probe") }in package scopeGetMarketplaceListingAttemptpassing a neighbor's method name towrongReturnTypeGetMarketplaceListingAttemptsubtestFail-before / pass-after (frontend). I temporarily changed
apiRequesttoreturn nullinstead ofthrow erroron a non-OK response (the regression the issue describes), then reverted it.rejects.toMatchObjecttest fails against it.Combined-tree verification. This branch was tested together with the other queued branches on a local, never-pushed tree:
queue/platform@400d256b= origin/main7b86e386plus these heads, merged in this order:Linux, Go 1.26.9,
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null AWS_EC2_METADATA_DISABLED=true; Docker Postgres via testcontainers. The full suite ran onf7c48020, which differs from this tree only by test-only commits on fix/issue-30, fix/issue-713 and fix/issue-263 that replace placeholder account-number literals with named constants:go build ./...,go vet ./...,go vet -tags integration ./...and the fullgo test -race -short -count=1 ./....--build-tags integration.gocyclo -over 10is silent on the changed non-test files.-tags integration -count=1):internal/analytics,internal/api,internal/auth,internal/config,internal/database/postgres/migrations,internal/purchase,internal/schedulerandinternal/serverall pass. Migrations 000149, 000150 and 000151 apply in order on this tree.approval-details,settings-accounts,api) pass (221 tests).accountkey); fixed with named constants. Re-run on this tree: git-secrets, using the repo'sscripts/setup-git-secrets.shpatterns in a fresh repo with an isolated HOME, found nothing in the changed files, and a planted fake key was flagged.scripts/test-git-secrets-allowlist.sh: 183 PASS, 0 FAIL..tftest.hclfiles were not run locally (CI runs them). Nothing was applied to any cloud.Out of scope (deliberately left for later)
tat the roughly 1,140MockConfigStoreconstructions, and making theisExpecteddefaults opt-in. The owner question on chore(test): medium/low findings from the 2026-07-28 full review [platform part] #353 is still pending.Labels
Maintainer: please mirror the issue's triage labels onto this PR:
impact/internal,type/chore,triaged,priority/p3,severity/low,urgency/eventually,effort/m.🤖 Generated with Claude Code