fix(shared): fix deepMerge data-corruption bugs and add tests
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
deepMergeinStruct.tsnow recurses only when both sides are plain objects (Object.prototype), soDate,Map, class instances, arrays, and functions are replaced wholesale instead of being walked like nested records (which brokeDateprototypes and similar values).Invalid top-level patches throw instead of silently returning a primitive and dropping the base object;
nullat the top level is still allowed.New
Struct.test.tsandStruct.edgeCases.test.tslock in normal merge behavior and document remaining quirks (array overwrite,nullnot skipped, shallow copy of nested refs).Reviewed by Cursor Bugbot for commit 3405a012d347f52cc7cf79dc7d9489c16c6bee3c. Bugbot is set up for automated code reviews on this repo. Configure here.
[!NOTE]
Fix data-corruption bugs in
deepMergeand add test coverage
- Introduces
isPlainObjectin Struct.ts to restrict recursion to plain objects; dates, maps, and class instances are now overwritten rather than recursively merged.deepMergenow 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.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
2fc415e1-ed28-47a1-afd7-c60d09002e8fYou can disable this status message by setting the
reviews.review_statustofalsein 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.
Comment @coderabbitai help to get the list of available commands.
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.