Skip to content

🐛 No-op left transforms where the inserted objects are identical #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

alecgibson
Copy link
Collaborator

At the moment if you transform two identical oi ops by one another, you get a no-op in the right case, but the left case results in a "silly" op whose od value is identical to its oi value.

left vs right should simply determine which op wins in a tie. Since the two ops are identical, the right scenario and left scenario should also be identical.

This change updates the transform behaviour to check this case, and results in a no-op regardless of left or right if the two ops are performing identical oi.

@alecgibson alecgibson requested a review from a team October 3, 2024 11:31
@@ -669,7 +669,7 @@ json.transformComponent = function(dest, c, otherC, type) {
} else if (otherC.oi !== void 0) {
if (c.oi !== void 0 && c.p[common] === otherC.p[common]) {
// left wins if we try to insert at the same place
if (type === 'left') {
if (type === 'left' && !deepEqual(otherC.oi, c.oi)) {

Choose a reason for hiding this comment

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

They can differ with od though no?

Copy link
Collaborator Author

@alecgibson alecgibson Oct 4, 2024

Choose a reason for hiding this comment

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

Good prompt: I added a test case and realised that ops with no od are handled by different code to ops with an od 💀

However, apart from the quirks of this codebase, I don't think it matters if they have different od: they should still no-op. Ultimately, transform(a, b) is saying: "make a compatible with a document where b has already been applied." So if we've already applied b, its oi is the current value. Applying a — with the same oi — would result in no change, regardless of what its od is. Therefore, it should be a no-op.

@alecgibson alecgibson force-pushed the no-op-identical-oi-left branch from 5f3ca5b to d342559 Compare October 4, 2024 06:00
@alecgibson alecgibson requested a review from dawidreedsy October 4, 2024 06:09
Comment on lines 450 to 469
it 'An attempt to re-add a key with an identical string becomes a no-op', ->
assert.deepEqual [], type.transform [{p:['k'], oi:'x'}], [{p:['k'], oi:'x'}], 'left'
assert.deepEqual [], type.transform [{p:['k'], oi:'x'}], [{p:['k'], oi:'x'}], 'right'

it 'An attempt to re-replace a key with an identical string becomes a no-op', ->
assert.deepEqual [], type.transform [{p:['k'], oi:'x', od: 'a'}], [{p:['k'], oi:'x', od: 'a'}], 'left'
assert.deepEqual [], type.transform [{p:['k'], oi:'x', od: 'a'}], [{p:['k'], oi:'x', od: 'a'}], 'right'

it 'An attempt to re-add a key with an identical object becomes a no-op', ->
assert.deepEqual [], type.transform [{p:['k'], oi:{}}], [{p:['k'], oi:{}}], 'left'
assert.deepEqual [], type.transform [{p:['k'], oi:{}}], [{p:['k'], oi:{}}], 'right'

it 'An attempt to re-replace a key with an identical object becomes a no-op', ->
assert.deepEqual [], type.transform [{p:['k'], oi:{}, od: 'a'}], [{p:['k'], oi:{}, od: 'a'}], 'left'
assert.deepEqual [], type.transform [{p:['k'], oi:{}, od: 'a'}], [{p:['k'], oi:{}, od: 'a'}], 'right'

Choose a reason for hiding this comment

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

Let's add a test case for different od

At the moment if you transform two identical `oi` ops by one another,
you get a no-op in the `right` case, but the `left` case results in a
"silly" op whose `od` value is identical to its `oi` value.

`left` vs `right` should simply determine which op wins in a tie. Since
the two ops are identical, the `right` scenario and `left` scenario
should also be identical.

This change updates the transform behaviour to check this case, and
results in a no-op regardless of `left` or `right` if the two ops are
performing identical `oi`.
@alecgibson alecgibson force-pushed the no-op-identical-oi-left branch from d342559 to 5ed2ca1 Compare October 4, 2024 08:55
@alecgibson alecgibson requested a review from dawidreedsy October 4, 2024 08:55
@alecgibson alecgibson merged commit c366d81 into master Oct 4, 2024
1 check passed
@alecgibson alecgibson deleted the no-op-identical-oi-left branch October 4, 2024 09:11
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.

2 participants