Add write strategy policy - #3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a5e884640
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR introduces a write_strategy policy to control how snapshot files are written, defaulting to Windows-friendly in-place writes while allowing callers to opt into atomic temp-file replacement. It threads the new option through stash/model configuration, runtime helpers, and updates documentation and tests accordingly.
Changes:
- Add
write_strategypropagation viaStash,snapclass/create_model/sync,Model.Meta, andSnapshotconfiguration. - Implement strategy-aware writing (
in_placevsatomic) and default toin_place. - Expand test coverage for strategy scoping/precedence and document tradeoffs; bump version to
0.1.4.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_sync.py | Adds a regression test ensuring sync(..., write_strategy=...) is accepted and used. |
| tests/test_stash_binding_and_api.py | Extends stash option plumbing tests to cover write_strategy. |
| tests/test_snapshot_magic_and_serializers.py | Ensures atomic writes are used in a concurrent conflict test scenario. |
| tests/test_snapshot_locking.py | Updates locking/symlink test coverage for atomic writes. |
| tests/test_sessions_and_frozen.py | Adds tests for default in-place behavior, atomic opt-in, and policy precedence. |
| tests/test_model_meta.py | Adds tests for Model.Meta.snapshot_write_strategy precedence and create_model(..., write_strategy=...). |
| tests/test_conversion_and_writes.py | Updates atomic-replace failure test to explicitly opt into atomic strategy. |
| src/snapclass/stash.py | Adds stash-level write_strategy policy, normalization, and inheritance resolution. |
| src/snapclass/schemas.py | Wires write_strategy through public APIs/config and implements strategy-aware _write_text. |
| README.md | Documents the new default and how/when to opt into atomic replacement. |
| pyproject.toml | Bumps project version to 0.1.4. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
write_strategypolicy within_placeas the default andatomicas an opt-in strategy.Model.Meta,create_model,sync, and directSnapshotconstruction.Why
Atomic temp-file replacement is better for file visibility and failure preservation, but it can fail on Windows when active apps or readers hold the destination file open. The default now matches datafiles-style in-place writes while preserving atomic replacement for callers that choose it.
Validation
python.exe -m compileall src\snapclass testspython.exe -m pytest tests\test_sessions_and_frozen.py tests\test_conversion_and_writes.py tests\test_stash_binding_and_api.py tests\test_model_meta.py tests\test_sync.py tests\test_snapshot_locking.py tests\test_snapshot_magic_and_serializers.pypython.exe -m pytest