Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(host-core): cover the Windows checks of the isolated-session E2E

renwangaaff369914c72
diff --git a/crates/host-core/src/rpc/worktree_rpc/tests.rs b/crates/host-core/src/rpc/worktree_rpc/tests.rs
index e641ab5c6..7f2df80b5 100644
--- a/crates/host-core/src/rpc/worktree_rpc/tests.rs
+++ b/crates/host-core/src/rpc/worktree_rpc/tests.rs
@@ -387,3 +387,118 @@ async fn behind(state: &Arc<Mutex<AppState>>, session_id: &str) -> Value {
.unwrap()["commits"]
.clone()
}
+
+/// A handshaken host on `data` with one isolated session of `project`;
+/// returns the state, the session id, and its tool root.
+async fn isolated_session_of(
+ project: &Path,
+ data: &Path,
+) -> (Arc<Mutex<AppState>>, String, PathBuf) {
+ fs::create_dir_all(data).unwrap();
+ let mut app = AppState::open(data).unwrap();
+ app.handshook = true;
+ let state = Arc::new(Mutex::new(app));
+ let created = call(
+ &state,
+ "session.create",
+ json!({ "projectPath": project.to_string_lossy(), "isolated": true, "title": "Windows" }),
+ )
+ .await
+ .unwrap();
+ let session_id = created["session"]["id"].as_str().unwrap().to_string();
+ let root = {
+ let st = state.lock().await;
+ PathBuf::from(resolve_tool_workspace(&st, &session_id).unwrap().unwrap())
+ };
+ (state, session_id, root)
+}
+
+fn session_branches(project: &Path) -> String {
+ git_cmd(project, &["branch", "--list", "pi-desktop/*"])
+}
+
+/// E2E-WORKTREE-isolated-session-lifecycle, Windows check: a path beyond 260
+/// characters is checked out into the worktree, written through the tools,
+/// and removed with the session. Git for Windows needs `core.longpaths` for
+/// such a project, which a project that already holds them has set.
+#[tokio::test]
+async fn a_path_beyond_260_characters_is_created_and_removed() {
+ let dir = tempfile::tempdir().unwrap();
+ let project = init_repo(&dir.path().join("project"));
+ git_cmd(&project, &["config", "core.longpaths", "true"]);
+ let deep: PathBuf = (0..12)
+ .map(|index| format!("segment-{index:02}-abcdefghijklmnop"))
+ .collect();
+ fs::create_dir_all(project.join(&deep)).unwrap();
+ fs::write(project.join(&deep).join("deep.txt"), "deep\n").unwrap();
+ git_cmd(&project, &["add", "-A"]);
+ git_cmd(&project, &["commit", "-q", "-m", "deep"]);
+
+ let (state, session_id, root) = isolated_session_of(&project, &dir.path().join("data")).await;
+ let checked_out = root.join(&deep).join("deep.txt");
+ assert!(checked_out.to_string_lossy().len() > 260, "{checked_out:?}");
+ assert_eq!(fs::read_to_string(&checked_out).unwrap(), "deep\n");
+ let written = crate::tools::execute_tool_with_path_access(
+ Some(&root),
+ None,
+ "Write",
+ &json!({ "path": deep.join("new.txt").to_string_lossy(), "content": "new\n" }),
+ tool_options(None),
+ )
+ .await;
+ assert!(written.ok, "{:?}", written.content);
+ assert_eq!(
+ fs::read_to_string(root.join(&deep).join("new.txt")).unwrap(),
+ "new\n"
+ );
+
+ call(&state, "session.delete", json!({ "id": session_id }))
+ .await
+ .unwrap();
+ assert!(!root.exists());
+ assert_eq!(session_branches(&project).trim(), "");
+ assert_eq!(
+ fs::read_to_string(project.join(&deep).join("deep.txt")).unwrap(),
+ "deep\n"
+ );
+}
+
+/// E2E-WORKTREE-isolated-session-lifecycle, Windows check: deleting while a
+/// file in the worktree is held open without delete sharing fails visibly
+/// (`WORKTREE_IO`), keeps the session and its worktree registration, and the
+/// same delete succeeds once the file is released.
+#[cfg(windows)]
+#[tokio::test]
+async fn deleting_with_a_locked_file_fails_visibly_and_can_be_retried() {
+ use std::os::windows::fs::OpenOptionsExt;
+ let dir = tempfile::tempdir().unwrap();
+ let project = init_repo(&dir.path().join("project"));
+ let (state, session_id, root) = isolated_session_of(&project, &dir.path().join("data")).await;
+ fs::write(root.join("locked.txt"), "x").unwrap();
+ let lock = fs::OpenOptions::new()
+ .read(true)
+ .share_mode(0)
+ .open(root.join("locked.txt"))
+ .unwrap();
+
+ let failed = call(&state, "session.delete", json!({ "id": session_id }))
+ .await
+ .unwrap_err();
+ assert_eq!(failed["code"], 1025);
+ assert_eq!(failed["errorCode"], "WORKTREE_IO");
+ let listed = call(&state, "session.list", json!({})).await.unwrap();
+ assert!(listed["sessions"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .any(|session| session["id"] == session_id.as_str()));
+ assert!(root.join("locked.txt").exists());
+ assert_ne!(session_branches(&project).trim(), "");
+
+ drop(lock);
+ call(&state, "session.delete", json!({ "id": session_id }))
+ .await
+ .unwrap();
+ assert!(!root.exists());
+ assert_eq!(session_branches(&project).trim(), "");
+}
diff --git a/docs/adr/0329-session-worktree-isolation.md b/docs/adr/0329-session-worktree-isolation.md
index 5bc65d11c..b2957eaf3 100644
--- a/docs/adr/0329-session-worktree-isolation.md
+++ b/docs/adr/0329-session-worktree-isolation.md
@@ -133,4 +133,7 @@ user-path tests cover the sidebar. `pnpm test:e2e:worktree-live` runs the
lifecycle against a real model. The hook-suppression, link-safe removal, and
`.worktreeinclude` link tests also run on Windows with directory junctions,
where Git for Windows runs hooks without an executable bit and lists files
-inside a junction. Long paths and locked-file removal require Windows E2E.
+inside a junction. On Windows, RPC user-path tests also create and delete a
+session with a path beyond 260 characters and show that a delete blocked by a
+locked file fails with `WORKTREE_IO`, keeps the session, and succeeds on
+retry; the renderer-level live-model run of the scenario is still manual.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index c0946c40b..915181bd7 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -409,7 +409,10 @@
- **Coverage:** host-core `session_worktrees` tests (create, merge, conflict,
removal, link safety, reconcile, delegates), worktree IPC contract tests,
renderer `worktree-ui` tests, and agent-runtime delegate tests. The Windows
- checks need a Windows host. `pnpm test:e2e:worktree-live`
+ checks run as host-core tests on a Windows host: junction removal
+ (`remove::tests`), the replaced-root link (`lifecycle::tests`), and the deep
+ path and locked-file delete through the RPC user path
+ (`rpc::worktree_rpc::tests`). `pnpm test:e2e:worktree-live`
(`scripts/e2e-worktree-live.mjs`) runs the steps above against a real model
at protocol level, without the renderer.
- **Status:** Partially automated
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index cb1bec3d0..88071b20f 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -9426,7 +9426,9 @@ Follow the [current S3 acceptance scenario](/spec/06-delivery/04-e2e-test-plan#e
`03-runtime/06-host-rpc-protocol.md`;`04-ux/01-ui-ia.md` §3.2;ADR 0329。
- **覆盖:** host-core `session_worktrees` 测试(创建、合并、冲突、删除、链接安全、启动
对账、子代理)、worktree IPC 契约测试、渲染层 `worktree-ui` 测试和 agent-runtime 子代理
- 测试。Windows 检查需要 Windows 主机。`pnpm test:e2e:worktree-live`
+ 测试。Windows 检查在 Windows 主机上以 host-core 测试运行:junction 删除(`remove::tests`)、
+ 根目录被替换为链接(`lifecycle::tests`),以及经 RPC 用户路径的深路径和文件占用时删除
+ (`rpc::worktree_rpc::tests`)。`pnpm test:e2e:worktree-live`
(`scripts/e2e-worktree-live.mjs`)在协议层用真实模型执行上述步骤,不经过渲染层。
- **状态:** Partially automated