feat: add sync operation that diffs and patches minimally#29
Merged
nathanjmcdougall merged 8 commits intoMay 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a sync operation to Document and Editor that diffs a desired Python value against the current document content at a given path and applies the minimal set of patches, preserving comments and formatting. Implements recursive mapping diffs and SequenceMatcher-based list diffs in a new yamltrip.sync module. Closes #25.
Changes:
- New
src/yamltrip/sync.pywith_compute_patchesand helpers for mapping/list/scalar diffing. Document.sync()andEditor.sync()methods, withKeyPartextracted to a new shared_typesmodule and import-linter layers updated accordingly.- 30 new tests in
tests/test_sync.pyand a design spec underdoc/specs/.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/yamltrip/sync.py | New module implementing recursive diff logic for mappings, lists (via SequenceMatcher with index-offset tracking), scalars, and type-mismatch fallback. |
| src/yamltrip/document.py | Adds Document.sync(); delegates to upsert when path missing, returns self on no-op; switches KeyPart to import from _types. |
| src/yamltrip/editor.py | Adds Editor.sync() thin wrapper; updates KeyPart import. |
| src/yamltrip/_types.py | New module exposing the shared KeyPart type alias. |
| .importlinter | Adds sync layer and _types ignore; allows yamltrip.sync -> yamltrip. |
| tests/test_sync.py | 30 tests covering mapping/list add/remove/change, nested cases, comment preservation, type mismatch, empty/null values, path creation, Editor integration, and a pre-commit-style scenario. |
| doc/specs/2026-05-20-sync-operation-design.md | Design document for the sync operation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
syncmethod toDocumentandEditorthat takes a desired Python value, diffs it against the current document content at a given path, and applies the minimal set of patches — preserving comments and formatting.Design
Documentprimitivesdifflib.SequenceMatchersrc/yamltrip/sync.pycontains the diff logicDocument.sync()returns a new Document;Editor.sync()mutates in placeselfon no-op (identity preservation)upsert; type mismatches handled viareplaceTest coverage
30 new tests covering:
Future work
keyparameter for identity-based list matching (deferred per YAGNI)Closes #25