Skip to content

Add JSONPatch.difference producing RFC 6902 operations - #96

Merged
ThorFuchs merged 1 commit into
mainfrom
feature/1.10-patch-diff
Nov 14, 2026
Merged

ThorFuchs merged 1 commit into
mainfrom
feature/1.10-patch-diff

Conversation

@ThorFuchs

Copy link
Copy Markdown
Owner

Summary

1.10 exact interchange, part 2: JSONPatch.difference(from:to:options:) and differenceWithReport compute a structural RFC 6902 patch that turns source into target.

  • Exact model equality: equal decimals (1.0 / 1), decoded scalars and order-independent objects produce no operation.
  • Objects: source members in source order (removed or compared recursively), then target-only members added in target order.
  • Arrays: longest equal prefix and suffix kept; the middle compared pairwise; surplus removals from the highest index down, then additions in ascending order. No move, copy or test.
  • Root kind changes replace through the empty Pointer.
  • One invocation-owned JSONWorkMeter (domain .patch), with .operations and .pointerTokens limits and cancellation checks in loops.

Docs: Patch.md "Structural difference", DocC topics in JSONPatch.md, CHANGELOG under 1.10.0 (in progress). CLI identity regenerated. JSONPatchTests 16 → 22 in TestDiscovery.json.

Qualification (local)

Toolchain: Apple Swift 6.4.2 (swiftlang-6.4.2.1.9), macOS 27.3. Source: 24f6ada on b9040c2.

  • python3 Scripts/ci.py --lane docs: exit 0, 4/4 commands passed
  • python3 Scripts/ci.py --lane native: exit 0, 62/62 commands passed, 0 failed

Tests include a 600-pair deterministic generated corpus where every patch applies to the source and yields the target.

No tag, release or publication follows from this PR.

🤖 Generated with Claude Code

JSONPatch.difference(from:to:options:) and differenceWithReport compute a
deterministic structural patch that turns one exact value into another.
Equal values produce no operation; objects diff by exact key, arrays keep
their equal prefix and suffix and compare the remaining elements by position,
and other changes are replaced. No move, copy or test is generated, and the
result is not minimal. Both inputs, every comparison, Pointer and produced
operation share one cumulative patch ledger with cancellation checks.

Tests cover expected operations, Pointer escaping, scalar-distinct keys, root
replacement, a 600-pair generated corpus where applying the patch yields the
target, limits, reports and cancellation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThorFuchs
ThorFuchs merged commit 3ad1225 into main Nov 14, 2026
21 checks passed
@ThorFuchs
ThorFuchs deleted the feature/1.10-patch-diff branch November 14, 2026 15:16
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.

1 participant