Skip to content

fix: no mutation for caller owned payloads#996

Merged
ferhatelmas merged 1 commit intomasterfrom
ferhat/event-mutation
Apr 9, 2026
Merged

fix: no mutation for caller owned payloads#996
ferhatelmas merged 1 commit intomasterfrom
ferhat/event-mutation

Conversation

@ferhatelmas
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Event payloads are mutated to add version but they are owned by their callers.

What is the new behavior?

Do a shallow copy to add version to prevent nasty bugs.

Additional context

Related to any type changes (#922), extracted due to behavior changes.

@ferhatelmas ferhatelmas requested a review from a team as a code owner April 9, 2026 11:56
Copilot AI review requested due to automatic review settings April 9, 2026 11:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents mutation of caller-owned event payload objects when adding $version, reducing surprising side effects for event callers across sync/async queue paths.

Changes:

  • Introduces a withPayloadVersion() helper to add $version via a shallow copy instead of mutating inputs.
  • Updates Event.send, Event.invoke, Event.invokeOrSend, and Event.batchSend to use the copied payload.
  • Adds Jest coverage ensuring payload objects passed into these APIs are not mutated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/internal/queue/event.ts Avoids mutating caller payloads by generating a shallow-copied payload with $version for static send/invoke APIs and batch inserts.
src/test/event.test.ts Adds regression tests asserting caller payloads are not mutated and that queued batch payloads still include $version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 9, 2026

Coverage Report for CI Build 24196948700

Coverage increased (+0.02%) to 80.846%

Details

  • Coverage increased (+0.02%) from the base build.
  • Patch coverage: 21 of 21 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 37225
Covered Lines: 30271
Line Coverage: 81.32%
Relevant Branches: 4139
Covered Branches: 3170
Branch Coverage: 76.59%
Branches in Coverage %: Yes
Coverage Strength: 320.18 hits per line

💛 - Coveralls

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas ferhatelmas force-pushed the ferhat/event-mutation branch from b79bdad to d28fea1 Compare April 9, 2026 14:54
@ferhatelmas ferhatelmas merged commit 41cfe75 into master Apr 9, 2026
5 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/event-mutation branch April 9, 2026 15:14
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