Skip to content

test: affiliate#220

Merged
kernelwhisperer merged 5 commits into
mainfrom
tests/affiliate
May 18, 2026
Merged

test: affiliate#220
kernelwhisperer merged 5 commits into
mainfrom
tests/affiliate

Conversation

@kernelwhisperer

@kernelwhisperer kernelwhisperer commented May 11, 2026

Copy link
Copy Markdown
Contributor

I snapshotted parts of the dune dashboards in my quest to debug https://www.notion.so/cownation/Orders-are-not-included-into-volume-when-protocol-fee-is-missing-3298da5f04ca800f94efe1f3a64a01f4?v=25a8da5f04ca81d1b904000c7c87b11c&source=copy_link

This will also be useful when we migrate to the new fac_trades dashboards from Matias, making sure nothing breaks. https://github.com/cowprotocol/cow-dagster/pull/608

Summary by CodeRabbit

  • Tests
    • Added end-to-end test coverage for affiliate partner overview, trader activity, and trader overview across production and staging; includes environment-specific test data and snapshot assertions.
    • Introduced a sanitization utility for stable snapshots.
  • Chores
    • Separated E2E from unit test targets and added a dedicated E2E test runner and npm script to run all E2E tests.

Review Change Stack

@kernelwhisperer kernelwhisperer requested a review from a team May 11, 2026 13:35
@kernelwhisperer kernelwhisperer self-assigned this May 11, 2026
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@kernelwhisperer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes and 8 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a489eb22-1e16-468c-af7a-2c44cd8a059b

📥 Commits

Reviewing files that changed from the base of the PR and between c840c33 and 2d8b466.

⛔ Files ignored due to path filters (3)
  • libs/services/e2e/affiliate/__snapshots__/AffiliatePartnerOverview.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderActivity.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderOverview.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • libs/services/e2e/affiliate/AffiliateTraderOverview.spec.ts
📝 Walkthrough

Walkthrough

Adds an affiliate e2e test suite: test constants and a mocked config, three snapshot specs (partner overview, trader overview, trader activity), a sanitize helper, and Nx/TypeScript changes to run e2e tests separately.

Changes

Affiliate E2E Test Suite

Layer / File(s) Summary
Test Constants and Mocking Setup
libs/services/e2e/affiliate/AffiliateTests.const.ts
Bootstraps dotenv, mocks getDuneQueryIds via jest.mock, exports PROD_QUERY_IDS/STAGING_QUERY_IDS, address lists (PROD_TRADERS, STAGING_TRADERS, PROD_PARTNERS, STAGING_PARTNERS, BUGGY_TRADERS), and getAffiliateStatsService(queryIds) to create service instances with controllable query IDs.
Build and CI configuration for e2e
libs/services/project.json, libs/services/tsconfig.spec.json, package.json
Excludes libs/services/e2e from the regular test target, adds test:e2e target with e2e-specific coverage output, extends spec TS types/includes to cover e2e files, and adds test:e2e npm script to run e2e across projects.
Snapshot sanitization utility
libs/services/e2e/affiliate/snapshot.utils.ts
Adds sanitize<T>(value:T) to recursively sanitize arrays/objects, remove lastUpdatedAt, filter undefined, and drop values with creation_date after 2026-05-10T00:00:00.000Z.
Partner Overview Snapshot Tests
libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts
Iterates partner addresses, calls service.getAffiliateStats(partnerAddress) per partner, sanitizes the aggregated map, and snapshots under 'prod' and 'staging'.
Trader Overview Snapshot Tests
libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts
Iterates trader addresses, calls per-trader stats via the service factory, sanitizes aggregated maps, and asserts 'prod'/'staging' snapshots.
Trader Activity Snapshot Tests
libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts
Queries activity for BUGGY_TRADERS plus environment traders, aggregates per-address results, sanitizes them, and snapshots for 'prod' and 'staging'.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In a burrow of code I quietly hop,
Fetching queries where Dune numbers drop,
Snapshots lined up — prod and staging in view,
Sanitized records all tidy and new,
A whiskered cheer for tests passing through!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "test: affiliate" is vague and generic. While it indicates the test domain, it lacks specificity about what tests are being added or what problem they address. Consider a more descriptive title that explains the specific purpose, such as "test: add e2e snapshot tests for affiliate stats" or "test: add affiliate partner and trader overview snapshots."
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tests/affiliate

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 and usage tips.

@socket-security

socket-security Bot commented May 11, 2026

Copy link
Copy Markdown

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

@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.

🧹 Nitpick comments (3)
libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts (1)

11-13: ⚡ Quick win

Parallelize the API calls for better performance.

Both test loops fetch partner data sequentially, which could be slow with 28 total calls. Consider using Promise.all to fetch all partners concurrently, similar to the refactor suggested in AffiliateTraderActivity.spec.ts.

Also applies to: 22-24

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts` around lines 11
- 13, The loops calling service.getAffiliateStats for each PROD_PARTNERS member
are sequential and should be parallelized: replace the for-loops that populate
partnerOverview (keyed by partnerAddress) with a Promise.all over
PROD_PARTNERS.map(...) to concurrently call service.getAffiliateStats for each
partnerAddress, then assign results back into partnerOverview (or build an
object from the array of [partnerAddress, stats] pairs); apply the same refactor
to both occurrences mentioned so PROD_PARTNERS, partnerOverview, and
service.getAffiliateStats are used with Promise.all for concurrent fetching.
libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts (1)

18-20: ⚡ Quick win

Consider parallelizing API calls for better test performance.

The sequential for loop processes ~24 trader addresses one-by-one. With network latency, this could approach the 30s timeout. Parallelizing with Promise.all would significantly improve execution speed.

⚡ Proposed refactor to parallelize calls
-    for (const traderAddress of [...BUGGY_TRADERS, ...PROD_TRADERS]) {
-      traderActivity[traderAddress] = await service.getTraderActivity(traderAddress)
-    }
+    const traders = [...BUGGY_TRADERS, ...PROD_TRADERS]
+    const results = await Promise.all(
+      traders.map(async (traderAddress) => ({
+        address: traderAddress,
+        activity: await service.getTraderActivity(traderAddress)
+      }))
+    )
+    results.forEach(({ address, activity }) => {
+      traderActivity[address] = activity
+    })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts` around lines 18
- 20, The test currently awaits service.getTraderActivity sequentially in the
for loop over [...BUGGY_TRADERS, ...PROD_TRADERS], causing slow execution;
replace the loop with a parallel fetch using Promise.all over the combined
address array (map each traderAddress to service.getTraderActivity) and then
populate traderActivity with the resolved results (preserve keys from
traderAddress), ensuring any per-request errors are handled or allowed to fail
the test as appropriate; references: traderActivity, service.getTraderActivity,
BUGGY_TRADERS, PROD_TRADERS.
libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts (1)

11-13: ⚡ Quick win

Parallelize the API calls for better performance.

With 37 sequential API calls across both tests, execution time could approach the 30s timeout. Refactor to use Promise.all for concurrent fetching, as suggested in the other e2e test files.

Also applies to: 22-24

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts` around
lines 11 - 13, The loop that fills traderOverview by awaiting
service.getTraderStats sequentially for each address (using PROD_TRADERS and
traderOverview) should be refactored to run concurrently with Promise.all: map
PROD_TRADERS to an array of service.getTraderStats(traderAddress) promises,
await Promise.all to get results, and then assign results back into
traderOverview (preserving traderAddress keys). Apply the same Promise.all
refactor to the other similar block that populates traderOverview (the second
occurrence using PROD_TRADERS and service.getTraderStats).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts`:
- Around line 11-13: The loops calling service.getAffiliateStats for each
PROD_PARTNERS member are sequential and should be parallelized: replace the
for-loops that populate partnerOverview (keyed by partnerAddress) with a
Promise.all over PROD_PARTNERS.map(...) to concurrently call
service.getAffiliateStats for each partnerAddress, then assign results back into
partnerOverview (or build an object from the array of [partnerAddress, stats]
pairs); apply the same refactor to both occurrences mentioned so PROD_PARTNERS,
partnerOverview, and service.getAffiliateStats are used with Promise.all for
concurrent fetching.

In `@libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts`:
- Around line 18-20: The test currently awaits service.getTraderActivity
sequentially in the for loop over [...BUGGY_TRADERS, ...PROD_TRADERS], causing
slow execution; replace the loop with a parallel fetch using Promise.all over
the combined address array (map each traderAddress to service.getTraderActivity)
and then populate traderActivity with the resolved results (preserve keys from
traderAddress), ensuring any per-request errors are handled or allowed to fail
the test as appropriate; references: traderActivity, service.getTraderActivity,
BUGGY_TRADERS, PROD_TRADERS.

In `@libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts`:
- Around line 11-13: The loop that fills traderOverview by awaiting
service.getTraderStats sequentially for each address (using PROD_TRADERS and
traderOverview) should be refactored to run concurrently with Promise.all: map
PROD_TRADERS to an array of service.getTraderStats(traderAddress) promises,
await Promise.all to get results, and then assign results back into
traderOverview (preserving traderAddress keys). Apply the same Promise.all
refactor to the other similar block that populates traderOverview (the second
occurrence using PROD_TRADERS and service.getTraderStats).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3e10419-7880-44bd-91a0-1c83f4360388

📥 Commits

Reviewing files that changed from the base of the PR and between e461c57 and 2e1aa3d.

⛔ Files ignored due to path filters (3)
  • libs/services/e2e/affiliate/__snapshots__/AffiliatePartnerOverview.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderActivity.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderOverview.staging.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts
  • libs/services/e2e/affiliate/AffiliateTests.const.ts
  • libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts
  • libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts
  • libs/services/project.json
  • libs/services/tsconfig.spec.json
  • package.json

@shoom3301 shoom3301 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.

There are lint issues to address

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/services/e2e/affiliate/snapshot.utils.ts`:
- Around line 3-22: The sanitize function's signature incorrectly claims to
always return T while it can return undefined (e.g., when
isAfterMaxSnapshotDate(...) is true); update the return type of sanitize from T
to T | undefined and adjust internal handling: ensure the Array branch returns
(value.map(sanitize).filter((e) => e !== undefined) as unknown) as (T |
undefined)[] or equivalent to preserve types, and keep the object branch
returning Object.fromEntries(...) as T | undefined; update any callers that
assume a guaranteed T to handle the undefined case. Reference: function
sanitize, predicate isAfterMaxSnapshotDate, and filtered key 'lastUpdatedAt'.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69a866fd-66f9-4c7b-8442-65b3b046c513

📥 Commits

Reviewing files that changed from the base of the PR and between 2e1aa3d and c840c33.

⛔ Files ignored due to path filters (3)
  • libs/services/e2e/affiliate/__snapshots__/AffiliatePartnerOverview.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderActivity.spec.ts.snap is excluded by !**/*.snap
  • libs/services/e2e/affiliate/__snapshots__/AffiliateTraderOverview.staging.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts
  • libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts
  • libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts
  • libs/services/e2e/affiliate/snapshot.utils.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • libs/services/e2e/affiliate/AffiliateTraderActivity.spec.ts
  • libs/services/e2e/affiliate/AffiliateTraderOverview.staging.spec.ts
  • libs/services/e2e/affiliate/AffiliatePartnerOverview.spec.ts

Comment thread libs/services/e2e/affiliate/snapshot.utils.ts
@kernelwhisperer kernelwhisperer enabled auto-merge (squash) May 14, 2026 08:05
@kernelwhisperer kernelwhisperer disabled auto-merge May 14, 2026 08:05
@kernelwhisperer

Copy link
Copy Markdown
Contributor Author

There are lint issues to address

I'm not sure but they should be fixed in the newest commits. lint:fix returns no changes.

Which lint issues do you mean specifically?

@kernelwhisperer kernelwhisperer requested a review from a team May 14, 2026 10:29
@kernelwhisperer kernelwhisperer merged commit a160920 into main May 18, 2026
9 checks passed
@kernelwhisperer kernelwhisperer deleted the tests/affiliate branch May 18, 2026 11:28
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