Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hitblast
Copy link
Collaborator

This PR focuses on creating AppContextManager and AppContext for the following causes:

  • Distributing config and snapshot loaders as reference for every Runnable command implementation, offering easy access to Loaded* variants of them.
  • Making path accessibility common across all parts of the codebase without requiring the get_*_path() variants of the same functionality - effectively reducing the mental overhead.

@hitblast
Copy link
Collaborator Author

@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 tempfile. Can you do the same while keeping existing functionality of the new codebase intact? You can also create new unit tests if you like to.

Copy link
Contributor

Copilot AI commented Dec 19, 2025

@hitblast I've opened a new pull request, #110, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a 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) and LoadedSnapshot (actual data)
  • Created AppContextManager for initialization and old snapshot migration
  • Updated all Runnable commands to accept AppContext instead of Config

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:?}"))?
Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
.with_context(|| format!("Failed to delete old snapshot at: {old_path:?}"))?
.with_context(|| format!("Failed to delete old snapshot at: {old_path:?}"))?;

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +33
Err(_) => {
log_err!("App context failed to initialize for cutler.");
Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
Err(_) => {
log_err!("App context failed to initialize for cutler.");
Err(err) => {
log_err!("App context failed to initialize for cutler: {err}");

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6
use std::path::Path;
use std::path::PathBuf;
Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
use std::path::Path;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

Copilot uses AI. Check for mistakes.
Comment on lines 99 to +100
Ok(mut snap) => {
snap.path = path.clone();
snap.path = self.path.to_owned();
Copy link

Copilot AI Dec 19, 2025

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.

Copilot uses AI. Check for mistakes.
Ok(())
}
}

Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
/// 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.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +11
pub struct AppContext {
pub config: Config,
pub snapshot: Snapshot,
}
Copy link

Copilot AI Dec 19, 2025

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.

Copilot uses AI. Check for mistakes.
pub config: Config,
pub snapshot: Snapshot,
}

Copy link

Copilot AI Dec 19, 2025

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.

Suggested change
/// 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.

Copilot uses AI. Check for mistakes.
@hitblast hitblast merged commit 2954084 into master Dec 20, 2025
7 checks passed
@hitblast hitblast deleted the tree branch December 20, 2025 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants