fix: snapshot() returns deep copies to prevent internal store mutation#153
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/CyberSecDef/NovelForge/sessions/c1d734a6-6751-497f-aa1d-83a76d319ffd Co-authored-by: CyberSecDef <17597068+CyberSecDef@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix snapshot() method to return deep copies
fix: snapshot() returns deep copies to prevent internal store mutation
Apr 8, 2026
CyberSecDef
approved these changes
Apr 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns ProgressManager.snapshot() with get() by returning deep copies, preventing callers from mutating nested structures and corrupting the internal in-memory progress store.
Changes:
- Update
ProgressManager.snapshot()to returncopy.deepcopy(...)entries instead of shallowdict(...)copies. - Update the
snapshot()docstring to reflect deep-copy semantics and safe caller mutation. - Strengthen the snapshot test to assert nested mutations don’t affect stored state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
novelforge/progress.py |
Make snapshot() return deep copies and update documentation to match the intended immutability boundary. |
tests/test_progress_manager.py |
Rename and extend the snapshot test to cover nested-mutation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
191
to
+192
| with self._lock: | ||
| return {k: dict(v) for k, v in self._store.items()} # type: ignore[misc] | ||
| return {k: copy.deepcopy(v) for k, v in self._store.items()} # type: ignore[misc] |
There was a problem hiding this comment.
snapshot() now uses copy.deepcopy, which should generally preserve the ProgressState type. Consider removing the broad # type: ignore[misc] (or replacing it with a narrower cast(...) / correct ignore code) so mypy can validate the return type instead of suppressing it.
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.
snapshot()returned shallowdict(v)copies, meaning callers could mutate nested structures (e.g.chapters_done,consistency) and corrupt the internal store — inconsistent with the deep-copy guarantee already provided byget().Changes
novelforge/progress.py: Replacedict(v)withcopy.deepcopy(v)insnapshot(); update docstring to reflect deep-copy semantics.tests/test_progress_manager.py: Renametest_snapshot_returns_shallow_copies→test_snapshot_returns_deep_copiesand add a nested-mutation assertion that directly exercises the fixed behaviour.