Skip to content

fix: deep freeze in compaction middleware - #4396

Merged
koladilip merged 1 commit into
developfrom
fix.deep-freeze-in-compaction-middleware
Jun 16, 2025
Merged

koladilip merged 1 commit into
developfrom
fix.deep-freeze-in-compaction-middleware

Conversation

@koladilip

@koladilip koladilip commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

  • Enforces deep freezing of destination config in compaction middleware to prevent mutation and reference replacement in compacted payload flows.
  • Adds and updates tests to ensure mutation and replacement of config are properly handled and errors are thrown when attempted on frozen configs (both processor and router flows).
  • Removes unnecessary cloneDeep in router transform flow for efficiency.
  • Updates to use deepFreezeProperty instead of deepFreeze.
  • Bumps @rudderstack/integrations-lib to ^0.2.36.

What is the related Linear task?

Resolves INT-3634

Please explain the objectives of your changes below

  • Ensure immutability of destination config is strictly enforced in both processor and router compaction middleware flows.
  • Add comprehensive tests for error handling and status codes when mutation or replacement is attempted on frozen config.
  • No dependent changes.

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

  • Config mutation and replacement now throw errors if attempted on frozen configs in compacted payload flows, improving reliability and correctness.

Any new dependencies introduced with this change?

  • Bumps @rudderstack/integrations-lib to ^0.2.36.

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

  • Uses new deepFreezeProperty utility for targeted deep freezing.

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

  • Removes unnecessary deep cloning in router transform, which may improve performance.

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

@koladilip
koladilip requested review from a team and sivashanmukh as code owners June 10, 2025 14:43
@koladilip
koladilip requested review from a team, chandumlg and utsabc June 10, 2025 14:43
@coderabbitai

coderabbitai Bot commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added new test behavior controls to support mutation and replacement of destination configuration during testing.
    • Extended test configuration with a flag to indicate if configuration has been mutated by a test.
  • Refactor

    • Improved event processing logic for test destinations by introducing a dedicated processing function and consolidating validation and error handling.
    • Updated type definitions for greater flexibility and modularity in processing requests.
  • Style

    • Removed unused imports and redundant utility functions to streamline code.

Summary by CodeRabbit

  • New Features

    • Added new test behavior flags to enable mutation and replacement checks for destination configuration in testing scenarios.
    • Introduced an indicator to track if destination configuration has been mutated during tests.
  • Refactor

    • Streamlined transformation logic by extracting a reusable event processing function and simplifying router processing.
    • Enhanced flexibility of type definitions for transformation requests by making them generic.
  • Style

    • Removed unused imports and redundant utility functions for cleaner, more maintainable code.

Walkthrough

This update refactors how destination configuration objects are frozen, introduces new test behaviors for mutating or replacing configuration in the rudder_test destination, and generalizes the ProcessorTransformationRequest type for greater flexibility. The rudder_test transformation logic is modularized, and type definitions are extended to support new test scenarios.

Changes

File(s) Change Summary
src/middlewares/destTransformCompactedPayloadV1.ts
src/middlewares/routerTransformCompactedPayloadV1.ts
Replaced deepFreeze with deepFreezeProperty to freeze the Config property on the destination object.
src/services/destination/nativeIntegration.ts Removed deep cloning of destInputArray before processing; now passes the original array directly.
src/types/destinationTransformation.ts Made ProcessorTransformationRequest a generic type for flexible destination and connection typing.
src/v0/destinations/rudder_test/transform.ts Refactored to extract a process function; added mutation/replacement test behaviors; improved modularity.
src/v0/destinations/rudder_test/type.ts Added new flags to TestBehavior and RudderTestConfig; introduced RudderTestProcessorRequest type alias.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Middleware
    participant DestinationHandler

    Client->>Middleware: Send event with destination
    Middleware->>Middleware: deepFreezeProperty(destination, 'Config')
    Middleware->>DestinationHandler: Pass destination with frozen Config
    DestinationHandler->>DestinationHandler: Process event (may attempt mutation/replacement)
    DestinationHandler-->>Client: Return processed result or error
Loading

Suggestions for Improvement

  • Consider adding unit tests to explicitly verify that attempts to mutate or replace the frozen Config property throw the expected errors.
  • Review performance implications of removing deep cloning in nativeIntegration.ts, especially if downstream logic might mutate input arrays.
  • Document the new generic parameters in ProcessorTransformationRequest to guide future contributors on their intended usage.
  • Ensure that the new test behaviors in rudder_test are covered by comprehensive test cases to validate error handling and immutability enforcement.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 957dce8b220e783d81e40c039bd326a13d54cd30 and 71c33b2.

⛔ Files ignored due to path filters (4)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • package.json is excluded by !**/*.json
  • test/integrations/destinations/rudder_test/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/rudder_test/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (6)
  • src/middlewares/destTransformCompactedPayloadV1.ts (2 hunks)
  • src/middlewares/routerTransformCompactedPayloadV1.ts (2 hunks)
  • src/services/destination/nativeIntegration.ts (1 hunks)
  • src/types/destinationTransformation.ts (1 hunks)
  • src/v0/destinations/rudder_test/transform.ts (1 hunks)
  • src/v0/destinations/rudder_test/type.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/middlewares/routerTransformCompactedPayloadV1.ts
  • src/services/destination/nativeIntegration.ts
  • src/middlewares/destTransformCompactedPayloadV1.ts
  • src/v0/destinations/rudder_test/transform.ts
  • src/types/destinationTransformation.ts
  • src/v0/destinations/rudder_test/type.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

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

cursor[bot]

This comment was marked as outdated.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Jun 10, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.13%. Comparing base (4f48250) to head (71c33b2).
Report is 25 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4396      +/-   ##
===========================================
- Coverage    91.13%   91.13%   -0.01%     
===========================================
  Files          638      638              
  Lines        33476    33475       -1     
  Branches      7904     7904              
===========================================
- Hits         30509    30508       -1     
  Misses        2728     2728              
  Partials       239      239              

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

- Add test behaviors in rudder_test transform to mutate and replace destination config
- Add router and processor component tests for both property mutation and config
  reference replacement in compacted payload flow
- Assert correct error handling and status codes when mutation is attempted on frozen config
- Ensures immutability of config is enforced and covered in both flows
- Remove unneccessary clonedeep in router transform flow by fixing code
@koladilip
koladilip force-pushed the fix.deep-freeze-in-compaction-middleware branch from 957dce8 to 71c33b2 Compare June 11, 2025 08:32

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ BugBot reviewed your changes and found no bugs!


Was this report helpful? Give feedback by reacting with 👍 or 👎

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

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

It has unrelated rudder_test destination changes as well. Is this intended?
I reviewed it and approved it.

@koladilip

koladilip commented Jun 16, 2025 •

Copy link
Copy Markdown
Contributor Author

It has unrelated rudder_test destination changes as well. Is this intended? I reviewed it and approved it.

they are not unrelated, I had to modify rudder_test to test the exception thrown by deepFreeze

@koladilip
koladilip merged commit fdf0527 into develop Jun 16, 2025
@koladilip
koladilip deleted the fix.deep-freeze-in-compaction-middleware branch June 16, 2025 12:50
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.

4 participants