Skip to content

fix(shared): fix deepMerge data-corruption bugs and add tests - #4136

Closed
kridaydave wants to merge 2 commits into
pingdotgg:mainfrom
kridaydave:fix/shared-deepmerge-bugs
Closed

kridaydave wants to merge 2 commits into
pingdotgg:mainfrom
kridaydave:fix/shared-deepmerge-bugs

Conversation

@kridaydave

@kridaydave kridaydave commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes two deepMerge bugs: it destroyed Date/Map/class-instance values (prototype loss) and silently discarded the entire base on a primitive patch.

  • Only recurse into plain objects now; Date/Map/instances are overwritten whole.
  • Throw on a primitive patch instead of dropping the base (null still allowed).
  • Added regression tests in Struct.test.ts and Struct.edgeCases.test.ts.

All gates green (typecheck, check, test).


Note

Medium Risk
Shared utility behavior change: callers that passed a non-null primitive or array as the top-level patch will now throw instead of getting a silent wrong result; merge semantics for non-plain nested values also change.

Overview
deepMerge in Struct.ts now recurses only when both sides are plain objects (Object.prototype), so Date, Map, class instances, arrays, and functions are replaced wholesale instead of being walked like nested records (which broke Date prototypes and similar values).

Invalid top-level patches throw instead of silently returning a primitive and dropping the base object; null at the top level is still allowed.

New Struct.test.ts and Struct.edgeCases.test.ts lock in normal merge behavior and document remaining quirks (array overwrite, null not skipped, shallow copy of nested refs).

Reviewed by Cursor Bugbot for commit 3405a01. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix data-corruption bugs in deepMerge and add test coverage

  • Introduces isPlainObject in Struct.ts to restrict recursion to plain objects; dates, maps, and class instances are now overwritten rather than recursively merged.
  • deepMerge now throws when the top-level patch is a non-null primitive (e.g. number, array, function) instead of silently returning it.
  • Adds primary tests in Struct.test.ts and edge-case tests in Struct.edgeCases.test.ts documenting both corrected and remaining lossy behaviors.
  • Behavioral Change: callers passing a primitive or array as the top-level patch will now receive a thrown error instead of a silent no-op overwrite.

Macroscope summarized 3405a01.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2fc415e1-ed28-47a1-afd7-c60d09002e8f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jul 18, 2026
@kridaydave
kridaydave force-pushed the fix/shared-deepmerge-bugs branch from 250dfdc to 966cd6b Compare July 18, 2026 19:06
@macroscopeapp

macroscopeapp Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This bug fix introduces meaningful runtime behavior changes to a shared deepMerge utility: new exception pathways for primitive patches and changed merge semantics for Date/Map/class instances. These changes to shared infrastructure warrant human review to ensure callers aren't affected.

You can customize Macroscope's approvability policy. Learn more.

@t3dotgg t3dotgg added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. and removed vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Aug 24, 2026
@t3dotgg

t3dotgg commented Sep 4, 2026

Copy link
Copy Markdown
Member

Note

🤖 GPT-6 Astra (preview) responding on behalf of Theo

This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.

Closing because this change does not address a demonstrated settings failure. Current callers merge schema-validated settings objects, not class instances or primitive patches. The new shared throw changes behavior for inputs outside that settings path. A failing case through a supported settings path would justify a focused fix.

@t3dotgg t3dotgg closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants