Repository navigation
fix: fix up map objects comparison - #10990
Conversation
9d0f161 to
c7b5ba2
Compare
gioboa
left a comment
There was a problem hiding this comment.
Thanks for the PR, can you solve the conflicts please?
WalkthroughAdds Map and Set normalization to the deep comparison in OrmUtils, converting Maps to objects and Sets to arrays before recursive checks. Updates internal comparisons to use normalized iterables. Extends unit tests to cover Map and Set scenarios for deepCompare. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant DC as OrmUtils.deepCompare
participant N as Normalizer
participant R as Recursive Check
Caller->>DC: deepCompare(x, y)
DC->>N: Determine types of x, y
alt x is Map
N-->>DC: iterableX = Object.fromEntries(x)\niterableY = Object.fromEntries(y)
note over DC,N: Normalize Maps to plain objects
else x is Set
N-->>DC: iterableX = Array.from(x)\niterableY = Array.from(y)
note over DC,N: Normalize Sets to arrays
else
N-->>DC: iterableX = x, iterableY = y
end
DC->>R: Compare keys/indices in iterableX vs iterableY
loop for each property p
R->>DC: recursive deepCompare(iterableX[p], iterableY[p])
DC-->>R: boolean
end
DC-->>Caller: true/false
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate 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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/util/OrmUtils.ts (1)
470-495: Index using symbol-safe access once to reduce casts and fix TS typing.Keep logic, but read props into locals to handle string|symbol keys.
- switch (typeof iterableX[p]) { + const xProp = (iterableX as any)[p] + const yProp = (iterableY as any)[p] + switch (typeof xProp) { case "object": case "function": leftChain.push(x) rightChain.push(y) if ( !OrmUtils.compare2Objects( leftChain, rightChain, - iterableX[p], - iterableY[p], + xProp, + yProp, ) ) { return false } leftChain.pop() rightChain.pop() break default: - if (iterableX[p] !== iterableY[p]) { + if (xProp !== yProp) { return false } break }test/github-issues/10989/issue-10989.ts (1)
4-29: Add coverage for Map numeric/symbol/object keys and Set order-insensitivity.Current tests miss the lossy cases; these would have caught the regressions.
it("should compare two Map.", () => { expect(OrmUtils.deepCompare(new Map(), new Map())).to.equal(true) expect( OrmUtils.deepCompare( new Map(Object.entries({ prop1: "value1", prop2: "value2" })), new Map(Object.entries({ prop1: "value1", prop2: "value2" })), ), ).to.equal(true) expect( OrmUtils.deepCompare( new Map(Object.entries({ prop1: "value1" })), new Map(Object.entries({ prop1: "value1", prop2: "value2" })), ), ).to.equal(false) + // numeric vs string keys must differ + expect(OrmUtils.deepCompare(new Map([[1, "a"]]), new Map([["1", "a"]]))).to.equal(false) + // symbol keys must be compared + const s = Symbol("k") + expect(OrmUtils.deepCompare(new Map([[s, 1]]), new Map([[s, 1]]))).to.equal(true) + // object key by identity + const key = { a: 1 } + expect(OrmUtils.deepCompare(new Map([[key, 1]]), new Map([[key, 1]]))).to.equal(true) }) it("should compare two Set.", () => { expect(OrmUtils.deepCompare(new Set(), new Set())).to.equal(true) expect( OrmUtils.deepCompare(new Set([1, 2, 3]), new Set([1, 2, 3])), ).to.equal(true) expect( OrmUtils.deepCompare(new Set([1, 2]), new Set([1, 2, 3])), ).to.equal(false) + // order-insensitive semantics + expect( + OrmUtils.deepCompare(new Set([3, 2, 1]), new Set([1, 2, 3])), + ).to.equal(true) })Questions to confirm:
- Should Maps with deep-equal but different object keys be considered equal, or must key identity match? Same for Sets of objects. Please confirm desired semantics.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/util/OrmUtils.ts(3 hunks)test/github-issues/10989/issue-10989.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/github-issues/10989/issue-10989.ts (1)
src/util/OrmUtils.ts (1)
OrmUtils(8-599)
|
Conflicts resolved ;) |
af53333 to
c5535f7
Compare
|
The test |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
test/unit/util/orm-utils.ts (2)
206-206: Name the suite after the public API being exercised.You’re testing
deepCompare, not the internalcompare2Objects. Rename for clarity.- describe("compare2Objects", () => { + describe("deepCompare (Map/Set)", () => {
207-207: Tiny wording nit in test titles.Pluralize for consistency.
- it("should compare two Map.", () => { + it("should compare two Maps.", () => { ... - it("should compare two Set.", () => { + it("should compare two Sets.", () => {Also applies to: 229-229
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/util/OrmUtils.ts(3 hunks)test/unit/util/orm-utils.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/util/OrmUtils.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/unit/util/orm-utils.ts (1)
src/util/OrmUtils.ts (1)
OrmUtils(8-599)
🔇 Additional comments (1)
test/unit/util/orm-utils.ts (1)
206-238: Solid new coverage for Map and Set equality paths.These assertions exercise the happy paths and basic negatives for both Map and Set. Good placement and readable expectations.
|
@sgarner is there anything else I have to do ? |
gioboa
left a comment
There was a problem hiding this comment.
May I ask you to solve the conflicts please?
|
Hi @gioboa, I asked a question #10990 (comment) and never got an answer, it was to fix failing tests. I'm sad to see my PR closed, I did put efforts in it |
|
Can you solve the conflicts please? We can review it without an aligned codebase. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 236f3bc
Previous suggestionsSuggestions up to commit 44b676a
Suggestions up to commit 657133d
Suggestions up to commit dc42540
Suggestions up to commit b727efd
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit dc42540 |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
|
Persistent review updated to latest commit 657133d |
1 similar comment
|
Persistent review updated to latest commit 657133d |
|
Persistent review updated to latest commit 44b676a |
|
@gioboa it's done, I got stuck 15 min with the PR title semantic ... a real pain >< |
|
Thanks for the feedback, I'm struggling with it too 😅 |
|
Persistent review updated to latest commit 236f3bc |
Co-authored-by: Maelig <[email protected]>
Description of change
Fixes #10989
Pull-Request Checklist
masterbranchnpm run formatto apply prettier formattingnpm run testpasses with this changeFixes #0000Summary by CodeRabbit
New Features
Tests