Skip to content

fix(affiliate): require an active affiliate to attribute a swap - #56

Merged
kaladinlight merged 5 commits into
developfrom
fix/require-active-affiliate-attribution
Aug 27, 2026
Merged

fix(affiliate): require an active affiliate to attribute a swap#56
kaladinlight merged 5 commits into
developfrom
fix/require-active-affiliate-attribution

Conversation

@kaladinlight

@kaladinlight kaladinlight commented Aug 27, 2026

Copy link
Copy Markdown
Member

Description

isActive on the affiliate registry was settable through the API but no query ever read it, so deactivating an affiliate had no effect — it could still be attributed on new swaps indefinitely.

resolvePartner now requires an active affiliate on both resolution paths: the partner-code lookup checks the flag, and the partner-address lookup filters on it, so a deactivated affiliate can't be reattached via its own wallet or receive address either. An attempted attribution to a deactivated code logs a warning and falls through to unattributed.

Testing

  • yarn test in apps/swap-service — 67/67 pass, including 5 new resolvePartner cases covering the active path, the deactivated code path, address fallback, and the no-partner default.
  • Confirmed the tests are meaningful: reverting the guard turns 3 of the 5 red.

Summary by CodeRabbit

  • Bug Fixes

    • Swap partner attribution now applies only to active affiliate partners.
    • Deactivated partners are excluded from attribution, including address-based fallback matching.
    • Swaps without valid partner information remain unattributed.
  • Tests

    • Added coverage for active, inactive, and missing partner attribution scenarios.

`isActive` was settable through the registry API but no query read it, so deactivating
an affiliate did nothing to stop it being attributed on new swaps. `resolvePartner` now
requires it on both the partner-code and the partner-address path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 52 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cdd9799c-0c9e-4a28-8184-7c82e8e6e97f

📥 Commits

Reviewing files that changed from the base of the PR and between ea08673 and db5a96b.

📒 Files selected for processing (1)
  • apps/swap-service/src/swaps/__tests__/create-swap-attribution.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ca4fcc1-ff44-4fcc-84fc-ffe82d51abdd

📥 Commits

Reviewing files that changed from the base of the PR and between 279f89a and ea08673.

📒 Files selected for processing (1)
  • apps/swap-service/src/swaps/__tests__/resolve-partner.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

resolvePartner now attributes swaps only to active affiliates. Partner-code and partner-address resolution include active-status checks. Tests verify query arguments, inactive affiliate handling, address fallback, and missing partner data.

Changes

Partner resolution

Layer / File(s) Summary
Active affiliate filtering and validation
apps/swap-service/src/swaps/swaps.service.ts, apps/swap-service/src/swaps/__tests__/resolve-partner.test.ts
resolvePartner selects and checks isActive for partner codes. Address lookups require active affiliates. Tests record Prisma arguments and verify active attribution, inactive affiliate handling, address fallback, and zero-call cases.

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

Merge Risk: 🟡 Moderate · up to ea086

The change blocks inactive affiliate codes, but an address-only request can still persist the supplied partner address without a unique active-affiliate match, so deactivated affiliates may remain attributable through that path. This should be corrected or explicitly accepted before merging.

Poem

A rabbit checks each partner code,
Active paths receive the load.
Dormant affiliates stay unseen,
Address matches must also be clean.
Tests hop through every mode.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely states the main change: swaps require an active affiliate for attribution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/require-active-affiliate-attribution

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.

kaladinlight and others added 4 commits August 27, 2026 14:52
Replaces the jest.fn() prisma mocks with typed stubs and a call recorder, clearing
13 no-unsafe-* lint errors.

Also fixes a test that did not test what it claimed: "does not let a deactivated
partner slip back in via its own address" passed with the address-path isActive
filter removed, because it was really re-asserting the partner-code guard. It now
asserts the fall-through it actually covers, and a new assertion pins the findUnique
lookup to the supplied partner code, which nothing checked before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…vate resolver

Moves the tests up to createSwap so they assert what is actually written to the
swaps table, and renames the file to match.

The previous tests drove the private resolvePartner and so could only observe its
return value. That left the regressions that matter uncovered: passing the caller's
partnerCode or partnerAddress straight through to the row instead of the registry-
resolved value. Both now fail a test.

Verified by mutation — each of the four tests catches exactly one regression:
  drop the partner-code isActive guard      -> deactivated partner is attributed
  drop the address-path isActive filter     -> filter no longer requested
  persist caller-supplied partnerAddress    -> address not resolved from registry
  persist caller-supplied partnerCode       -> resolution bypassed entirely

Dropped two tests that earned nothing: one asserted a fall-through with no
behavioural consequence, the other duplicated the partner-code guard while its name
promised address-path coverage.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kaladinlight
kaladinlight enabled auto-merge (squash) August 27, 2026 21:00
@kaladinlight
kaladinlight merged commit 8436eb9 into develop Aug 27, 2026
2 checks passed
@kaladinlight
kaladinlight deleted the fix/require-active-affiliate-attribution branch August 27, 2026 21:02
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.

1 participant