Repository navigation
test(config): real-DB test for GetPurchaseHistoryFiltered dual-column account filter - #994
Conversation
… account filter
Run the account predicate
cloud_account_id = ANY($uuids)
OR ((provider = '' OR LOWER(provider) = LOWER($p)) AND account_id = ANY($exts))
against a testcontainers Postgres. Until now the UUID half and the OR
between the two halves were checked only by pgxmock SQL-text tests.
The new table covers: both halves ORed (a NULL-cloud_account_id row
comes back next to UUID-only rows), UUID only, external only, a
provider mismatch on the same external number, the empty-provider row
(LeanerCloud#931 semantics), and the OR group inside a surrounding Provider clause.
Closes LeanerCloud#23
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 1 billable file and costs up to $0.25. Or wait 35 minutes for your next included review. View limit details
Comment |
cristim
left a comment
There was a problem hiding this comment.
Independent review of 0738071: draft: blocks ready
Findings: none actionable. Test-only, +127 lines in one file (three-dot diff vs main).
What I attacked
- Real DB:
setupTestContainerDB(store_postgres_db_test.go:35) starts a testcontainers Postgres. The test calls the realGetPurchaseHistoryFiltered(store_postgres.go:2535), which builds the predicate inappendAccountPredicate(store_postgres.go:2467-2491), so it runs the production SQL. Run at this SHA:go test -tags integration -run 'DualColumnAccount|AccountPredicate' ./internal/config/passes, and the integration package compiles (issue #23 part (a) is already satisfied on main). - Both columns: cases cover UUID-only match (
uuid-only, account_id deliberately unrelated), external-only match (ext-only, cloud_account_id NULL), both matching (both, returned once), UUID-only filter ignoring account_id, and provider-scoped external half (azure-same-extexcluded from aws filters). Cross-account exclusion:other-uuid/other-ext(account C) never appear in account A cases, andother-uuidappears only when C is the UUID filter. - Vacuous pass: every case asserts an exact non-empty sorted ID list, not "no error" or length, and the seeded rows are asserted by name.
- Mutation probes in a scratch worktree (each reverted; tree clean): UUID half set to FALSE -> 4 subtests fail; UUID half pointed at account_id -> 4 fail; external half set to FALSE -> 4 fail; drop
provider = ''-> 3 fail; provider gate neutralised -> 3 fail; OR joined with AND -> 3 fail; parentheses removed -> the compose-with-provider case fails. All 7 killed. - Consistency with #931: the new fixtures (
ext-empty-provider) reuse the same semantics as the existing TestAccountPredicate_ProviderCaseAndEmpty_Integration in the same file; no helper duplication beyondpurchaseIDs, which is reused. The expiry index from #942 is not touched. - Issue #23 (b): NULL cloud_account_id + populated account_id returned by UUID filter (via the resolved external pair), and same external number under another provider not returned: both covered.
NON-BLOCKING
- The doc comment names the raw predicate in the test header; it will drift if the SQL changes. Minor.
- The test relies on a resolved (provider, external) pair being passed alongside the UUID, as the API handler does; the resolver itself is not in scope.
Gate status
- Independent review: this comment, SHA above.
- CI: checks on this SHA are still pending (including Integration Tests and Lint); fork runs may need approval. Must be green before merge.
- Local verification: real-DB run on macOS plus mutation evidence above.
- Labels: priority/p2, severity/medium, urgency/this-sprint, impact/internal, type/chore, effort/m, triaged; they match the closing issue's triage set as reported by the PR (issue #23 labels not re-fetched by me beyond the closing reference).
- CodeRabbit: only a bot summary comment, no inline threads; not pinged.
Blocks ready
- CI green on this SHA (Integration Tests, Lint, pre-commit).
- Take the PR out of draft.
- Re-review if the head moves.
|
Gate record for 0738071 (origin/main CLAUDE.md "Review gate"):
Marking ready (owner-authorized) and merging at 0738071 with --match-head-commit. |
What
Adds
TestGetPurchaseHistoryFiltered_DualColumnAccount_Integration, a testcontainers (real Postgres) test for the dual-column account predicate inGetPurchaseHistoryFiltered:It goes in the existing
internal/config/store_postgres_history_account_provider_integration_test.go. No production code changes.Seed: two aws
cloud_accounts(A = 111122223333, C = 444455556666) and sevenpurchase_historyrows covering each combination of the two account columns (UUID-only, UUID+external, NULL-UUID external-only, NULL-UUID empty provider, azure row reusing A's external number, account C by UUID and by external number).AccountIDs=[A],aws:[111122223333]AccountIDs=[A]aws:[111122223333]AccountIDs=[A],azure:[111122223333]Provider=aws,AccountIDs=[C],aws:[111122223333]The empty-provider expectations follow the current semantics from #931 (an empty stored provider matches on
account_idalone).Why / status of the issue's two parts
PurchasePlanFilter{}withconfig.PurchasePlanFilter{}and removed thepf(...)helper usage ininternal/config/store_postgres_test.go. On current main,go vet -tags integration ./internal/config/passes and the full integration suite runs green. No change needed here.TestAccountPredicate_ProviderCaseAndEmpty_Integration, but that test only exercises the external-id half (every seeded row hascloud_account_id IS NULL). Until this PR, the UUID half, the OR between the two halves, and the parenthesisation of the OR inside the surroundingANDchain were checked only by pgxmock SQL-text tests. This PR adds that missing coverage.Verification
All tests ran with
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null.Fail-before evidence (mutations of
appendAccountPredicateininternal/config/store_postgres.go, each applied alone, then reverted)FALSEFALSEaccount_id = ANYfor any provider)ORbetween halves changed toANDAll five subtests pass with the predicate unchanged.
Out of scope
GetActivePurchaseHistorywithAccountIDs. It sharesappendAccountPredicate; its external-half variants are already covered by the fix(config): match purchase history with an empty or differently cased provider #931 test.Labels
Please mirror the issue's labels onto this PR (I have no label permission on the upstream repo):
priority/p2,severity/medium,urgency/this-sprint,impact/internal,type/chore,triaged,effort/m.Closes #23
🤖 Generated with Claude Code