Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cortex-cli/src/debug_cmd/handlers/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cortex_engine::rollout::get_rollout_path;
use cortex_protocol::ConversationId;

use crate::debug_cmd::commands::SnapshotArgs;
use crate::debug_cmd::types::{SnapshotDebugOutput, SnapshotInfo};
use crate::debug_cmd::types::{SnapshotDebugOutput, SnapshotDiffInfo, SnapshotInfo};
use crate::debug_cmd::utils::{format_size, get_cortex_home};

/// Run the snapshot debug command.
Expand Down Expand Up @@ -196,6 +196,10 @@ pub async fn run_snapshot(args: SnapshotArgs) -> Result<()> {
snapshot_count,
session_snapshots,
total_size_bytes,
diff: args.diff.then(|| SnapshotDiffInfo {
status: "not_implemented".to_string(),
message: "Snapshot diff not yet implemented".to_string(),
}),
};

if args.json {
Expand Down
9 changes: 9 additions & 0 deletions src/cortex-cli/src/debug_cmd/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ pub struct SnapshotDebugOutput {
#[serde(skip_serializing_if = "Option::is_none")]
pub session_snapshots: Option<Vec<SnapshotInfo>>,
pub total_size_bytes: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub diff: Option<SnapshotDiffInfo>,
}

/// Snapshot info.
Expand All @@ -225,6 +227,13 @@ pub struct SnapshotInfo {
pub size_bytes: u64,
}

/// Snapshot diff status.
#[derive(Debug, Serialize)]
pub struct SnapshotDiffInfo {
pub status: String,
pub message: String,
}

// =============================================================================
// Paths types
// =============================================================================
Expand Down
28 changes: 28 additions & 0 deletions src/cortex-cli/tests/debug_snapshot_json_diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::process::Command;

#[test]
fn debug_snapshot_json_includes_diff_when_requested() {
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
.args(["debug", "snapshot", "--json", "--diff"])
.env("NO_COLOR", "1")
.output()
.expect("run Cortex debug snapshot");

let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);

assert!(
output.status.success(),
"debug snapshot failed\nstdout:\n{stdout}\nstderr:\n{stderr}"
);

let json: serde_json::Value =
serde_json::from_str(&stdout).expect("debug snapshot output should be JSON");
assert_eq!(json["diff"]["status"], "not_implemented");
assert!(
json["diff"]["message"]
.as_str()
.is_some_and(|message| message.contains("not yet implemented")),
"diff message should explain snapshot diff status\nstdout:\n{stdout}"
);
}