Skip to content

fix: factorization dropping operations when paths share a string prefix - #46

Merged
wI2L merged 1 commit into
wI2L:masterfrom
fnoopv:fix_factorize_error
Apr 1, 2026
Merged

fix: factorization dropping operations when paths share a string prefix#46
wI2L merged 1 commit into
wI2L:masterfrom
fnoopv:fix_factorize_error

Conversation

@fnoopv

@fnoopv fnoopv commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

fix #45

This fixes issue #45, where enabling Factorize() could produce an incomplete patch.

Root cause:
the move validation logic used a plain string prefix check to determine whether the source path was a proper prefix of the destination path. This was too broad for JSON Pointers and incorrectly treated sibling paths such as /key/b and /key/bb as a parent/child relationship.

As a result, a valid factorization candidate could be rejected and the add operation was dropped, leaving an incomplete patch.

Changes:

  • replace the plain strings.HasPrefix check with a JSON Pointer-aware proper prefix check that requires a segment boundary
  • add a fixture regression case for the reported scenario
  • add a direct Go regression test covering both non-factorized and factorized behavior

With this change:

  • without Factorize(), the diff remains remove + add
  • with Factorize(), the diff is correctly reduced to a move from /key/b to /key/bb

@wI2L
wI2L force-pushed the fix_factorize_error branch from b68d9c8 to 15c7d1c Compare April 1, 2026 15:02
@codecov-commenter

codecov-commenter commented Apr 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.93%. Comparing base (65fb3ba) to head (31743f2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #46      +/-   ##
==========================================
+ Coverage   94.89%   94.93%   +0.04%     
==========================================
  Files          12       12              
  Lines         979      987       +8     
==========================================
+ Hits          929      937       +8     
  Misses         30       30              
  Partials       20       20              
Flag Coverage Δ
unittests 94.93% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wI2L
wI2L force-pushed the fix_factorize_error branch from 15c7d1c to 32b52b1 Compare April 1, 2026 15:15
@wI2L
wI2L force-pushed the fix_factorize_error branch from 32b52b1 to 31743f2 Compare April 1, 2026 15:17
@wI2L
wI2L self-requested a review April 1, 2026 15:18
@wI2L
wI2L merged commit 8b8ba7c into wI2L:master Apr 1, 2026
7 checks passed
@wI2L

wI2L commented Apr 1, 2026

Copy link
Copy Markdown
Owner

@fnoopv Thank you for your contribution.

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.

Factorize() causes dropped operations in Patch

3 participants