Skip to content

Commit cd3bc87

Browse files
committed
fix: include snapshot diff in json output
1 parent 7954d02 commit cd3bc87

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/cortex-cli/src/debug_cmd/handlers/snapshot.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cortex_engine::rollout::get_rollout_path;
77
use cortex_protocol::ConversationId;
88

99
use crate::debug_cmd::commands::SnapshotArgs;
10-
use crate::debug_cmd::types::{SnapshotDebugOutput, SnapshotInfo};
10+
use crate::debug_cmd::types::{SnapshotDebugOutput, SnapshotDiffInfo, SnapshotInfo};
1111
use crate::debug_cmd::utils::{format_size, get_cortex_home};
1212

1313
/// Run the snapshot debug command.
@@ -196,6 +196,10 @@ pub async fn run_snapshot(args: SnapshotArgs) -> Result<()> {
196196
snapshot_count,
197197
session_snapshots,
198198
total_size_bytes,
199+
diff: args.diff.then(|| SnapshotDiffInfo {
200+
status: "not_implemented".to_string(),
201+
message: "Snapshot diff not yet implemented".to_string(),
202+
}),
199203
};
200204

201205
if args.json {

src/cortex-cli/src/debug_cmd/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ pub struct SnapshotDebugOutput {
215215
#[serde(skip_serializing_if = "Option::is_none")]
216216
pub session_snapshots: Option<Vec<SnapshotInfo>>,
217217
pub total_size_bytes: u64,
218+
#[serde(skip_serializing_if = "Option::is_none")]
219+
pub diff: Option<SnapshotDiffInfo>,
218220
}
219221

220222
/// Snapshot info.
@@ -225,6 +227,13 @@ pub struct SnapshotInfo {
225227
pub size_bytes: u64,
226228
}
227229

230+
/// Snapshot diff status.
231+
#[derive(Debug, Serialize)]
232+
pub struct SnapshotDiffInfo {
233+
pub status: String,
234+
pub message: String,
235+
}
236+
228237
// =============================================================================
229238
// Paths types
230239
// =============================================================================
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::process::Command;
2+
3+
#[test]
4+
fn debug_snapshot_json_includes_diff_when_requested() {
5+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
6+
.args(["debug", "snapshot", "--json", "--diff"])
7+
.env("NO_COLOR", "1")
8+
.output()
9+
.expect("run Cortex debug snapshot");
10+
11+
let stdout = String::from_utf8_lossy(&output.stdout);
12+
let stderr = String::from_utf8_lossy(&output.stderr);
13+
14+
assert!(
15+
output.status.success(),
16+
"debug snapshot failed\nstdout:\n{stdout}\nstderr:\n{stderr}"
17+
);
18+
19+
let json: serde_json::Value =
20+
serde_json::from_str(&stdout).expect("debug snapshot output should be JSON");
21+
assert_eq!(json["diff"]["status"], "not_implemented");
22+
assert!(
23+
json["diff"]["message"]
24+
.as_str()
25+
.is_some_and(|message| message.contains("not yet implemented")),
26+
"diff message should explain snapshot diff status\nstdout:\n{stdout}"
27+
);
28+
}

0 commit comments

Comments
 (0)