fix: pull writes canonical model files and detects changes reliably - #243
fix: pull writes canonical model files and detects changes reliably#243angeloashmore wants to merge 15 commits into
Conversation
Model canonicalization sorted keys only one level deep, so structurally identical models with reordered keys inside nested config objects (e.g. an Image field's constraint) compared as different, causing pull to rewrite unchanged files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sync compared raw remote JSON against canonical local files, so any remote change re-synced every model whose key order differed. Sync now uses pull's comparison: the remote model's canonical form against the local file as parsed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pull now has a test that pulled files keep field order, a second pull changes nothing, and non-canonical files (types and slices) are rewritten in canonical form. The status reorder test also covers a slice and checks that push writes nothing. The scramble helper moves to test/it.ts and handles slice field maps. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…lize # Conflicts: # src/commands/sync.ts
Deep key sorting also sorted a Slices field's choices, which is the slice order shown in the editor, and the field maps inside legacy slices. Rebuild both from the unsorted input, like group fields. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Fixtures already hold their keys in a non-canonical order, so writing them to disk gives the same coverage as the scramble helper without restating which maps are position-significant. Cover a slice zone and a legacy slice too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The pulled file only proved that field order survives. Assert the sorted key order of the model, a field, a thumbnail, a slice, and a variation, and add a second tab and thumbnail so tab and array order are covered. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Write the unsorted fixture locally before the pull so one run covers both the rewrite and the canonical output. Compare the pulled models to the fixture for content, then assert key order at each kind of object, including the slice zone and a legacy slice. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Write the unsorted fixture locally instead of pulling first, so status and push run against a non-canonical file in two CLI runs. Move the Choices type next to the function that uses it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d592dae. Configure here.
| const customTypeOps = diffArrays(remoteCustomTypes, localCustomTypeModels, { | ||
| getKey: (m) => m.id, | ||
| equals: (remote, local) => | ||
| JSON.stringify(canonicalizeCustomType(remote)) === JSON.stringify(local), |
There was a problem hiding this comment.
Sync spurious change notifications
Medium Severity
prismic sync now treats models as unchanged when only remote JSON key order differs, but the watch loop still keys off a raw JSON.stringify hash. When that hash flips with no insert/update/delete work, it still runs generateTypes() and logs Changes detected in with an empty suffix.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit d592dae. Configure here.


Resolves:
Description
prismic pullrewrote model files that had no changes. It also did not rewrite files whose key order was different from the format that it writes.This PR corrects both faults. Model comparison now sorts keys at every depth before it compares. Field order stays the same. Pull rewrites local files that have a non-canonical key order.
prismic syncuses the same comparison as pull.pushandstatuscontinue to ignore key order. As a result, they push nothing and report nothing when only the key order is different.Checklist
Preview
How to QA 1
prismic pull. The command rewrites the files.prismic pullagain. The command prints "Already up to date." and leaves no dirty files.🤖 Generated with Claude Code
Note
Medium Risk
Changes core model diffing and canonicalization used by pull, sync, and disk writes—incorrect equality could cause missed updates or unnecessary rewrites, but scope is CLI sync logic with new integration tests.
Overview
Fixes pull rewriting model files on every run and missing non-canonical key order on disk. Comparison now canonicalizes the remote model and compares it to the local JSON (as read from files), so pull only updates when content differs and rewrites locals into the canonical on-disk shape.
prismic syncuses the same equality rules for slices and custom types.canonicalizeCustomType/canonicalizeSliceare tightened:sortKeysrecurses through nested objects and arrays; nested Group fields and Slices zone choices (including legacy Slicenon-repeat/repeat) are canonicalized explicitly without treating slice choice order as sortable metadata.Tests cover a forced pull that asserts sorted key layout (groups, thumbnails, legacy slice choices), a second pull reporting up to date, status/push staying quiet when only key order differs, and sync reporting slice-only changes.
Reviewed by Cursor Bugbot for commit d592dae. Bugbot is set up for automated code reviews on this repo. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩