Skip to content
Draft
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: 6 additions & 0 deletions crates/sandbox-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Fixes

- Send empty sandbox diff snapshots after the final change is removed, clearing stale diff views.



## v0.1.0 (2026-09-03)
Expand Down
20 changes: 9 additions & 11 deletions crates/sandbox-core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ async fn push_diff_view<B: SandboxBackend, M: MetadataStore, C: CallbackClient>(
};

let files: Vec<serde_json::Value> = match &repo_state.mode {
SandboxMode::Direct => Vec::new(),
SandboxMode::Direct => return,
_ => {
let Ok(changed) = state.backend.diff_files(sandbox_dir, &repo_state).await else {
return;
Expand All @@ -1807,16 +1807,14 @@ async fn push_diff_view<B: SandboxBackend, M: MetadataStore, C: CallbackClient>(
}
};

if !files.is_empty() {
rap_protocol::send_view_update(
&state.callback_client,
&invocation.callback_url,
invocation.group_id.clone(),
"diff",
serde_json::json!({ "files": files }),
)
.await;
}
rap_protocol::send_view_update(
&state.callback_client,
&invocation.callback_url,
invocation.group_id.clone(),
"diff",
serde_json::json!({ "files": files }),
)
.await;
}

/// Build a pretty-printed unified diff for display in the CLI.
Expand Down
47 changes: 47 additions & 0 deletions crates/sandbox-local/tests/execute_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,50 @@ async fn sandboxed_command_can_write_sccache_cache_dir() {
std::env::remove_var("SCCACHE_DIR");
}
}

#[tokio::test]
async fn deleting_last_added_file_clears_diff_view() {
let repo = jj_init_with_file("README.md", "hello\n");
let metadata = tempfile::tempdir().expect("create metadata directory");
let server_url = start_test_server(metadata.path()).await;
let (callback_url, mut rx) = start_callback_channel()
.await
.expect("start callback channel");
let group = "empty-diff-test";
let result = invoke(
&server_url,
&callback_url,
group,
"clone_repo",
serde_json::json!({ "repo": repo.path().to_str().expect("repository path") }),
&mut rx,
None,
)
.await;
assert!(result.contains("Repository initialized"), "{result}");

let (_, created_views) = invoke_collecting_views(
&server_url,
&callback_url,
group,
"create_file",
serde_json::json!({ "path": "added.txt", "content": "new content\n" }),
&mut rx,
1,
)
.await;
assert_eq!(created_views[0].content["files"][0]["path"], "added.txt");

let (_, deleted_views) = invoke_collecting_views(
&server_url,
&callback_url,
group,
"execute_command",
serde_json::json!({ "command": "rm added.txt" }),
&mut rx,
1,
)
.await;
assert_eq!(deleted_views[0].view_type, "diff");
assert_eq!(deleted_views[0].content["files"], serde_json::json!([]));
}