-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: AppContext and proper snapshot management #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@copilot Snapshot-related unit tests need to be updated. I had previously updated Config with the same architecture which required all unit tests to be converted to use |
… architecture Co-authored-by: hitblast <[email protected]>
Co-authored-by: hitblast <[email protected]>
Update snapshot tests to use tempfile and Snapshot/LoadedSnapshot architecture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces AppContext and AppContextManager to centralize configuration and snapshot management across the application. The refactoring eliminates the need for repeated get_*_path() calls and provides a unified context object passed to all commands.
Key changes:
- Refactored snapshot API by splitting into
Snapshot(path wrapper/loader) andLoadedSnapshot(actual data) - Created
AppContextManagerfor initialization and old snapshot migration - Updated all
Runnablecommands to acceptAppContextinstead ofConfig
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/context.rs | New module defining AppContext and AppContextManager for centralized config/snapshot access |
| src/lib.rs | Exports new context module |
| src/main.rs | Initializes AppContext via AppContextManager and passes it to commands |
| src/snapshot/core.rs | Splits Snapshot into Snapshot (loader) and LoadedSnapshot (data) structs |
| src/snapshot/path.rs | Simplifies get_snapshot_path to synchronous function, removes migration logic |
| src/commands/mod.rs | Updates Runnable trait to accept AppContext instead of Config |
| src/commands/*.rs | Updates all command implementations to use AppContext |
| tests/snapshot_test.rs | Updates tests to use new Snapshot/LoadedSnapshot API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if new_path.exists() { | ||
| fs::remove_file(&old_path) | ||
| .await | ||
| .with_context(|| format!("Failed to delete old snapshot at: {old_path:?}"))? |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon at the end of this statement. The error propagation operator ? should be followed by a semicolon to complete the statement properly.
| .with_context(|| format!("Failed to delete old snapshot at: {old_path:?}"))? | |
| .with_context(|| format!("Failed to delete old snapshot at: {old_path:?}"))?; |
| Err(_) => { | ||
| log_err!("App context failed to initialize for cutler."); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error in AppContextManager initialization is silently discarded. When sync() fails, the actual error message is lost and replaced with a generic message. Consider logging the actual error to help with debugging.
| Err(_) => { | |
| log_err!("App context failed to initialize for cutler."); | |
| Err(err) => { | |
| log_err!("App context failed to initialize for cutler: {err}"); |
| use std::path::Path; | ||
| use std::path::PathBuf; |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statements can be consolidated into a single line. Both Path and PathBuf are from std::path, so they should be combined as use std::path::{Path, PathBuf}; following Rust best practices.
| use std::path::Path; | |
| use std::path::PathBuf; | |
| use std::path::{Path, PathBuf}; |
| Ok(mut snap) => { | ||
| snap.path = path.clone(); | ||
| snap.path = self.path.to_owned(); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path field is being set twice unnecessarily. Line 100 sets snap.path = self.path.to_owned(), but the path was already correctly set during deserialization (since it has #[serde(skip)]). Since the path should always match self.path, this assignment is redundant and should be removed, or the deserialization should ensure it's set correctly initially.
| Ok(()) | ||
| } | ||
| } | ||
|
|
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Snapshot struct is missing documentation. It should have a doc comment explaining that it's a wrapper around a snapshot file path that provides methods to create, load, and check the existence of snapshot files, while LoadedSnapshot represents the actual in-memory snapshot data.
| /// A wrapper around a snapshot file path that provides methods to create, load, | |
| /// and check the existence of snapshot files, while [`LoadedSnapshot`] represents | |
| /// the actual in-memory snapshot data. |
| pub struct AppContext { | ||
| pub config: Config, | ||
| pub snapshot: Snapshot, | ||
| } |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AppContext struct is missing documentation. It should have a doc comment explaining its purpose as a container for application-wide configuration and snapshot references that are passed to command implementations.
| pub config: Config, | ||
| pub snapshot: Snapshot, | ||
| } | ||
|
|
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AppContextManager struct is missing documentation. It should have a doc comment explaining that it's responsible for initializing the application context, including handling migration of old snapshot files and setting up configuration and snapshot paths.
| /// Responsible for initializing the application context, including migrating any | |
| /// legacy snapshot files to the current snapshot location and setting up the | |
| /// configuration and snapshot paths used by the application. |
This PR focuses on creating
AppContextManagerandAppContextfor the following causes:Runnablecommand implementation, offering easy access toLoaded*variants of them.get_*_path()variants of the same functionality - effectively reducing the mental overhead.