Skip to content

fix: remove channel from eventSource evaluation for tiktok_ads - #4583

Merged
krishna2020 merged 2 commits into
hotfix/21.AUG.2025from
fix/removeChannel
Aug 21, 2025
Merged

krishna2020 merged 2 commits into
hotfix/21.AUG.2025from
fix/removeChannel

Conversation

@ItsSudip

Copy link
Copy Markdown
Member

What are the changes introduced in this PR?

Remove channel from evaluation of event_source for tiktok_ads

What is the related Linear task?

Resolves INT-XXX

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@ItsSudip
ItsSudip requested review from a team and sivashanmukh as code owners August 21, 2025 16:01
@ItsSudip
ItsSudip requested review from a team, koladilip and manish339k August 21, 2025 16:01
@coderabbitai

coderabbitai Bot commented Aug 21, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Standardized TikTok Ads event source handling: only accepts web, app, offline, crm.
    • Defaults to web when event source is missing or unrecognized.
  • Refactor

    • Removed reliance on channel and legacy implicit mappings (e.g., mobile → app) for source resolution.
  • Tests

    • Updated test expectations to align with the new source resolution rules.

Walkthrough

getEventSource for TikTok Ads was simplified: it now accepts only { properties }, removes channel-based and legacy mappings, restricts recognized values to ['web','app','offline','crm'], and falls back to properties.eventSource/event_source or 'web'. Tests were updated to match the new behavior.

Changes

Cohort / File(s) Summary
TikTok Ads util refactor
src/v0/destinations/tiktok_ads/util.js
Removed channel param and legacy sourceMapping; changed signature to getEventSource({ properties }); accepted sources limited to ['web','app','offline','crm']; fallback uses eventSource/event_source, then 'web'.
TikTok Ads util tests update
src/v0/destinations/tiktok_ads/util.test.js
Updated expectations for tests that previously relied on channel- or mobile-based fallbacks to reflect new defaulting to 'web'.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Util as getEventSource
  Caller->>Util: getEventSource({ properties })
  Note over Util: read properties.eventSource or event_source
  alt value in [web, app, offline, crm]
    Util-->>Caller: return recognized value
  else missing or unrecognized
    Util-->>Caller: return "web"
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • koladilip
  • manish339k

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/removeChannel

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (2)
src/v0/destinations/tiktok_ads/util.js (1)

72-77: Update JSDoc to remove "channel" and reflect the new API.

The docstring still mentions "channel" and an old param shape. Please align it with the current behavior and return contract.

 /**
- * Get event source from message properties or channel. We have considered the following doc
+ * Resolve TikTok Ads event_source from message.properties only (channel is intentionally ignored).
+ * Reference:
  * https://business-api.tiktok.com/portal/docs?id=1771100779668482
- * @param {*} message
- * @returns (string): The resolved, valid event source — one of 'web', 'app', 'offline', or 'crm'. Defaults to 'web' if none are valid.
+ * @param {{ properties?: { eventSource?: string, event_source?: string } }} message
+ * @returns {string} One of 'web' | 'app' | 'offline' | 'crm'. Defaults to 'web' if not provided or invalid.
  */
src/v0/destinations/tiktok_ads/util.test.js (1)

209-221: Clarify test names to reflect that channel is ignored now.

The assertions are correct, but the test titles still talk about "channel". Reword to avoid confusion and reflect the new contract.

-  it('returns "web" if both eventSource and channel are missing', () => {
+  it('returns "web" if eventSource is missing (channel is ignored)', () => {
     const message = { properties: {} };
     expect(getEventSource(message)).toBe('web');
   });
-  it('returns "web" if both eventSource and channel are invalid', () => {
+  it('returns "web" if eventSource is invalid (channel is ignored)', () => {
     const message = { properties: { eventSource: 'foo' }, channel: 'bar' };
     expect(getEventSource(message)).toBe('web');
   });
-  it('returns eventSource if both eventSource and channel are valid', () => {
+  it('returns eventSource when valid (channel is ignored)', () => {
     const message = { properties: { eventSource: 'crm' }, channel: 'app' };
     expect(getEventSource(message)).toBe('crm');
   });

If you adopt the normalization in util.js, consider adding these tests to lock the behavior:

it('normalizes case and whitespace for eventSource', () => {
  expect(getEventSource({ properties: { eventSource: ' Web ' } })).toBe('web');
  expect(getEventSource({ properties: { eventSource: 'CRM' } })).toBe('crm');
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ef4f64f and 8f85d05.

⛔ Files ignored due to path filters (1)
  • test/integrations/destinations/tiktok_ads/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (2)
  • src/v0/destinations/tiktok_ads/util.js (2 hunks)
  • src/v0/destinations/tiktok_ads/util.test.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/tiktok_ads/util.test.js
  • src/v0/destinations/tiktok_ads/util.js
🧠 Learnings (2)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
📚 Learning: 2025-07-15T06:27:07.528Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.

Applied to files:

  • src/v0/destinations/tiktok_ads/util.test.js
  • src/v0/destinations/tiktok_ads/util.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/tiktok_ads/util.js (1)

78-96: Normalize eventSource with trimming/lowercasing & switch to Set – refactor confirmed safe

I’ve scanned all usages of getEventSource, checked for any upstream reliance on channel fallback, and found no code paths outside of tests and the V2 transformer that would break under the proposed change. Switching to a Set and normalizing input only widens accepted values (e.g. 'CRM', ' Web ' → 'crm', 'web') without altering existing behavior for lowercase, exact matches.

• Call-site summary
– src/v0/destinations/tiktok_ads/util.test.js – only covers exact lowercase inputs and default fallback
– src/v0/destinations/tiktok_ads/transformV2.js – uses getEventSource(message) to set event_source
– No production code inspects the channel field for event source determination

• Optional improvement
– Add unit tests in util.test.js for uppercase and whitespace-padded inputs to verify normalization

• Proposed diff (no changes since last suggestion):

-const getEventSource = ({ properties }) => {
-  const supportedSources = ['web', 'app', 'offline', 'crm'];
+const getEventSource = ({ properties }) => {
+  // Use a Set for explicit, O(1) membership checks
+  const supportedSources = new Set(['web', 'app', 'offline', 'crm']);

   const { eventSource, event_source: eventSourceV2 } = properties || {};

   // Helper function to resolve source
   const resolveSource = (source) => {
-    if (!source) return null;
+    if (!source || typeof source !== 'string') return null;
+    const normalized = source.trim().toLowerCase();
+    if (supportedSources.has(normalized)) return normalized;
     return null;
   };

   return resolveSource(eventSource) || resolveSource(eventSourceV2) || 'web';
 };

This refactor is non-breaking and can be safely merged.

@codecov

codecov Bot commented Aug 21, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.81%. Comparing base (99c3e78) to head (90f4f9f).
⚠️ Report is 1 commits behind head on hotfix/21.AUG.2025.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           hotfix/21.AUG.2025    #4583      +/-   ##
======================================================
- Coverage               91.81%   91.81%   -0.01%     
======================================================
  Files                     642      642              
  Lines                   33930    33926       -4     
  Branches                 8041     8031      -10     
======================================================
- Hits                    31152    31148       -4     
- Misses                   2526     2548      +22     
+ Partials                  252      230      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ItsSudip
ItsSudip changed the base branch from develop to hotfix/21.AUG.2025 August 21, 2025 16:19

@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: 0

🧹 Nitpick comments (4)
src/v0/destinations/tiktok_ads/util.test.js (4)

208-211: Rename test to reflect channel is ignored now.

Test name still says it uses channel, but the assertion expects ‘web’ (correct). Rename for clarity.

-it('returns channel if eventSource is missing and channel is valid', () => {
+it('returns "web" when eventSource is missing (channel ignored)', () => {

212-215: Rename test: remove “channel” semantics from the title.

Channel no longer participates in resolution; the expectation to ‘web’ is right. Adjust the title accordingly.

-it('returns channel if eventSource is invalid and channel is valid', () => {
+it('returns "web" when eventSource is invalid (channel ignored)', () => {

240-243: Fix misleading test title (“mobile” no longer maps to app).

The implementation treats “mobile” as unrecognized and falls back to event_source=web. Update the title to match the new behavior.

-it('if mobile is present, it should return app', () => {
-  const message = { properties: { eventSource: 'mobile', event_source: 'web' } };
-  expect(getEventSource(message)).toBe('web');
+it('falls back to event_source when eventSource is "mobile" (unrecognized)', () => {
+  const message = { properties: { eventSource: 'mobile', event_source: 'web' } };
+  expect(getEventSource(message)).toBe('web');

216-227: Optional: Normalize other titles to remove references to channel.

These tests are valid, but titles still mention channel, which can confuse future readers now that channel is ignored.

-it('returns "web" if both eventSource and channel are missing', () => {
+it('returns "web" if eventSource is missing', () => {
   const message = { properties: {} };
   expect(getEventSource(message)).toBe('web');
 });

-it('returns "web" if both eventSource and channel are invalid', () => {
+it('returns "web" if eventSource is invalid', () => {
   const message = { properties: { eventSource: 'foo' }, channel: 'bar' };
   expect(getEventSource(message)).toBe('web');
 });

-it('returns eventSource if both eventSource and channel are valid', () => {
+it('returns eventSource when it is valid (channel ignored)', () => {
   const message = { properties: { eventSource: 'crm' }, channel: 'app' };
   expect(getEventSource(message)).toBe('crm');
 });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8f85d05 and 90f4f9f.

📒 Files selected for processing (1)
  • src/v0/destinations/tiktok_ads/util.test.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/tiktok_ads/util.test.js
🧠 Learnings (2)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
📚 Learning: 2025-07-15T06:27:07.528Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.

Applied to files:

  • src/v0/destinations/tiktok_ads/util.test.js
🧬 Code graph analysis (1)
src/v0/destinations/tiktok_ads/util.test.js (1)
src/v0/destinations/tiktok_ads/util.js (2)
  • getEventSource (78-96)
  • message (11-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/tiktok_ads/util.test.js (1)

199-244: All getEventSource call sites now use the single-argument signature

I ran the AST-grep and ripgrep searches as suggested and confirmed there are no two- or three-argument invocations of getEventSource anywhere in the repository. All existing call sites correctly use the updated single-argument form, for example:

  • src/v0/destinations/tiktok_ads/util.test.js: all tests call getEventSource(message) only
  • src/v0/destinations/tiktok_ads/transformV2.js (line 166): event_source: getEventSource(message)

No further action is needed here—this completes the sanity check.

@krishna2020
krishna2020 merged commit 8fff71a into hotfix/21.AUG.2025 Aug 21, 2025
@krishna2020
krishna2020 deleted the fix/removeChannel branch August 21, 2025 16:29
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

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