🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(store): surface prospect metadata errors and revive the policy list assertion - #1778

Merged
AmanGIT07 merged 1 commit into
mainfrom
fix/empty-branches
Jul 22, 2026
Merged

fix(store): surface prospect metadata errors and revive the policy list assertion#1778
AmanGIT07 merged 1 commit into
mainfrom
fix/empty-branches

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

Two error checks existed but did nothing. The prospect transform caught the metadata unmarshal error and dropped it; the policy list test computed the content comparison and discarded the result.

Changes

  • internal/store/postgres/prospect.go: return the metadata unmarshal error, matching the organization and group transforms. A JSONB value of the wrong shape (for example a top-level array) now surfaces as an error instead of a prospect with silently empty metadata.
  • internal/store/postgres/prospect_repository_test.go: new TestGet case that stores a top-level JSON array as metadata and asserts Get returns an error.
  • internal/store/postgres/policy_repository_test.go: the list comparison now fails the test with a cmp.Diff output. The expected fixtures gain PrincipalType (the repository returns it, and the dead assertion had been hiding the gap), and the comparison sorts by resource type because the list query has no ORDER BY.

Test Plan

  • Policy and prospect suites pass
  • Both fixes verified red on the old code: the new prospect case fails without the transform fix; the revived assertion fails against the old expected fixtures with a PrincipalType diff

SQL Safety (if your PR touches *_repository.go or goqu.*)

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L (use make_interval(hours => ?)-style functions instead).
  • Any //nolint:forbidigo or // #nosec G20x annotation has a one-line justification on the same line that a reviewer can verify.

…st assertion

The prospect transform caught the metadata unmarshal error and did
nothing with it, and the policy list test computed its content
comparison without acting on the result. Return the error, fail the
test on mismatch, and correct the expected fixtures it had been hiding.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 20, 2026 10:41am

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when prospect metadata contains invalid or unexpected JSON.
    • Prospect retrieval now correctly reports parsing errors instead of returning incomplete data.
  • Tests

    • Added coverage for invalid prospect metadata.
    • Improved policy comparison tests to tolerate ordering differences and provide clearer mismatch details.

Walkthrough

Prospect metadata unmarshalling now propagates errors, with a repository test covering incompatible JSONB data. Policy list tests include PrincipalType and use sorted cmp.Diff comparisons that ignore generated fields.

Changes

Postgres store updates

Layer / File(s) Summary
Propagate prospect metadata errors
internal/store/postgres/prospect.go, internal/store/postgres/prospect_repository_test.go
Invalid metadata now returns an error, and TestGet verifies parsing failure for array-shaped JSONB metadata.
Improve policy list assertions
internal/store/postgres/policy_repository_test.go
Expected policies include PrincipalType; comparisons sort by ResourceType, ignore generated fields, and report diffs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ravisuhag

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2339445c-b75a-42dd-b328-ed078225fe32

📥 Commits

Reviewing files that changed from the base of the PR and between cfe2cf3 and 212f2a5.

📒 Files selected for processing (3)
  • internal/store/postgres/policy_repository_test.go
  • internal/store/postgres/prospect.go
  • internal/store/postgres/prospect_repository_test.go

Comment thread internal/store/postgres/policy_repository_test.go
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 29735903045

Coverage increased (+0.01%) to 46.12%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 38322
Covered Lines: 17674
Line Coverage: 46.12%
Coverage Strength: 13.32 hits per line

💛 - Coveralls

@AmanGIT07
AmanGIT07 requested a review from rohilsurana July 22, 2026 07:00
@AmanGIT07
AmanGIT07 merged commit 79ec099 into main Jul 22, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the fix/empty-branches branch July 22, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants