Repository navigation
Attach existing and new Spotify artists to organization rosters atomically - #969
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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 |
There was a problem hiding this comment.
1 issue found across 13 files
Confidence score: 3/5
resolveOrCreateArtist.tsremoves the explicit SPOTIFY social write and relies on an RPC side effect that the tests don't verify, so Spotify links may no longer be persisted. Confirm the RPC writes them and add an assertion for that behavior.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/artists/resolveOrCreateArtist.ts">
<violation number="1" location="lib/artists/resolveOrCreateArtist.ts:25">
P1: Custom agent: **Flag AI Slop and Fabricated Changes**
The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its `SPOTIFY` relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Client as HTTP Client
participant API as createArtistPostHandler
participant Validator as validateCreateArtistBody
participant Auth as Auth & Permission Validators
participant Resolver as resolveOrCreateArtist
participant Onboard as onboardSpotifyArtist
participant DB as PostgreSQL (RPC/Transactions)
participant Reader as selectAccountWithSocials
participant Creator as createArtistInDb
Client->>API: POST /api/artists (name, spotify_artist_id?, organization_id?)
API->>Validator: Validate request body
Validator->>Validator: CHANGED: spotify_artist_id must match /^[A-Za-z0-9]{22}$/
alt Invalid Spotify ID format
Validator-->>API: 400 Bad Request
API-->>Client: { status: "error" }
end
Validator-->>API: Validated body
API->>Auth: Verify account + organization membership
alt Revoked or non-member
Auth-->>API: 403 Forbidden
API-->>Client: { status: "error", error: "Access denied" }
end
Auth-->>API: Authorized (account_id, organization_id)
alt Spotify artist ID provided
API->>Resolver: resolveOrCreateArtist(name, accountId, orgId, spotifyId)
Resolver->>Onboard: NEW: onboardSpotifyArtist() - atomic resolve + attach
Onboard->>DB: RPC onboard_spotify_artist(p_account_id, p_org_id, p_name, p_spotify_id)
DB-->>Onboard: { artist_id, created } or Error
alt RPC error - fail closed (no fallback)
alt Permission denied (42501)
Onboard-->>Resolver: 403 ArtistOnboardingError
else Ambiguous identity (21000)
Onboard-->>Resolver: 409 ArtistOnboardingError
else Persistence unavailable (PGRST202/23514)
Onboard-->>Resolver: 503 ArtistOnboardingError
end
Resolver-->>API: Reject
API-->>Client: Status preserved (403/409/503)
end
Onboard-->>Resolver: { artist_id: "canonical", created }
Resolver->>Reader: selectAccountWithSocials(artist_id)
alt Readback failed
Reader-->>Resolver: null
Resolver-->>API: 503 retryable error
end
Reader-->>Resolver: Artist record
Resolver-->>API: { artist, created }
alt Artist already existed
API-->>Client: 200 OK (reused)
else New artist created
API-->>Client: 201 Created
end
else Name-only creation (no Spotify ID)
API->>Resolver: resolveOrCreateArtist(name, accountId, orgId)
Resolver->>Creator: createArtistInDb(name, accountId, orgId)
Creator->>DB: Insert account + artist + org relationship
DB-->>Creator: relationship_id or null
alt Organization attach returned no relationship
Creator-->>Resolver: null
Resolver-->>API: 500 error
API-->>Client: { status: "error" }
end
Creator-->>Resolver: Created artist
Resolver-->>API: { artist, created: true }
API-->>Client: 201 Created
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| created: false, | ||
| }; | ||
| } | ||
| const result = await onboardSpotifyArtist({ name, accountId, organizationId, spotifyArtistId }); |
There was a problem hiding this comment.
P1: Custom agent: Flag AI Slop and Fabricated Changes
The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its SPOTIFY relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/artists/resolveOrCreateArtist.ts, line 25:
<comment>The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its `SPOTIFY` relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.</comment>
<file context>
@@ -18,47 +16,16 @@ export interface ResolveOrCreateArtistResult {
- created: false,
- };
- }
+ const result = await onboardSpotifyArtist({ name, accountId, organizationId, spotifyArtistId });
+ const artist = await selectAccountWithSocials(result.artist_id);
+ if (!artist) throw new Error("Could not read artist after onboarding. Please retry.");
</file context>
There was a problem hiding this comment.
Validated by the companion database PR: the fixture now loads the actual social-normalization triggers and asserts the persisted Spotify social and artist relationship. All 15 PostgreSQL tests pass, including concurrent creation and rollback. Supabase Preview is also passing after the additive migration correction.
There was a problem hiding this comment.
All reported issues were addressed across 13 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
Adding an existing Spotify artist now uses the same atomic resolve-and-attach operation as adding a new one, so both return the canonical artist with the requested organization roster relationship committed. Lookup and attachment failures fail closed; ambiguous identities return 409, revoked membership returns 403, and unavailable persistence returns a retryable 503. Name-only creation uses a second transaction so attachment failures roll back the new profile. Post-commit profile-read failures return 503 without losing the committed artist identity.
Tracks recoupable/app#2166. Depends on recoupable/database#83: apply that migration before deploying this API change. The existing HTTP response shape and 200/reused versus 201/created distinction are retained. No production data patch or canonical merge is included.
Validation: the full API suite passes (5,982 tests; 12 skipped). Non-admin allow/deny tests run through the real request validators with synthetic credentials. Readback and valuation tests preserve committed identity; the name-only adapter preserves response timestamps. The database PR separately verifies 16 PostgreSQL cases with the actual normalization trigger, concurrency, and rollback. API lint passes. A final boundary check also rejects malformed RPC JSON with an exact sanitized error (four adapter cases passed). The unused legacy identity lookup was removed.
Limitations: repository-wide type checking reports 196 errors in unchanged files outside this repair. The default production build stalled without progress and was stopped. A webpack build compiled successfully, then stopped at page-data collection because this isolated checkout has no PRIVY_PROJECT_SECRET configuration. No isolated hosted configuration or test identity is available in this checkout, so authenticated UI → API → persisted membership verification remains pending. This is implemented and fixture-tested, not merged or production-verified. Automatic PR preview checks are separate from authenticated end-to-end verification.
Release evidence: recoupable/app#2166 (comment) (hosted preview checkpoint). Final production commit/deployment and verification boundaries are recorded in the latest release checkpoint on recoupable/app#2166 and #2167.