From 29a26c47879576ce925d862b2452e24209b3e7fd Mon Sep 17 00:00:00 2001 From: huihui Date: Wed, 25 Nov 2026 19:37:07 +0800 Subject: [PATCH 1/2] test(worktrees): run the non-Unix removal refusal in the Windows flow The Windows job does not build the dim-app-server lib test target, so the non-Unix refusal branch had no test that CI executed. Move the assertion into app_server_flow, which the windows-cli job runs, and drive it through worktree.remove over the local transport: an unregistered directory under the managed root must be refused without --force and removed with it. Name the test in scripts/test-windows-native.mjs and add its file and worktrees.rs to the windows_native paths, so the Windows step runs when either changes. --- crates/dim-app-server/src/worktrees.rs | 24 +---- .../dim-app-server/tests/app_server_flow.rs | 2 + .../tests/worktree_removal_flow.rs | 98 +++++++++++++++++++ scripts/ci-changes.mjs | 8 +- scripts/ci-changes.test.mjs | 2 + scripts/test-windows-native.mjs | 1 + 6 files changed, 110 insertions(+), 25 deletions(-) create mode 100644 crates/dim-app-server/tests/worktree_removal_flow.rs diff --git a/crates/dim-app-server/src/worktrees.rs b/crates/dim-app-server/src/worktrees.rs index b49deacb22..ec24fb93a2 100644 --- a/crates/dim-app-server/src/worktrees.rs +++ b/crates/dim-app-server/src/worktrees.rs @@ -1760,8 +1760,10 @@ fn parse_duration(text: &str) -> Result { #[cfg(test)] mod tests { + #[cfg(unix)] use super::*; + #[cfg(unix)] fn scratch(name: &str) -> PathBuf { let path = std::env::temp_dir().join(format!("dim-worktrees-{name}-{}", uuid::Uuid::new_v4())); @@ -1858,26 +1860,4 @@ mod tests { assert!(child.is_dir()); std::fs::remove_dir_all(&entry).unwrap(); } - - /// A non-Unix target deletes a directory by path, so a reparse point - /// swapped in after the check could redirect the non-force removal; this - /// path refuses and `--force` removes the tree instead. - #[cfg(not(unix))] - #[tokio::test] - async fn a_path_based_removal_refuses_an_unregistered_directory() { - let entry = scratch("path-based-removal"); - let child = entry.join("repo"); - std::fs::create_dir_all(&child).unwrap(); - let error = remove_checked_entry(&entry, std::slice::from_ref(&child), false) - .await - .expect_err("a path-based removal must refuse the non-force removal"); - assert_eq!(error.code(), "worktree_in_use"); - assert!( - matches!(&error, WorktreeError::InUse(message) if message.contains("--force")), - "{error:?}" - ); - assert!(child.is_dir()); - remove_checked_entry(&entry, &[], true).await.unwrap(); - assert!(!entry.exists()); - } } diff --git a/crates/dim-app-server/tests/app_server_flow.rs b/crates/dim-app-server/tests/app_server_flow.rs index c798db4e71..812c768a67 100644 --- a/crates/dim-app-server/tests/app_server_flow.rs +++ b/crates/dim-app-server/tests/app_server_flow.rs @@ -32,3 +32,5 @@ mod storage_flow; mod storage_session_flow; #[cfg(unix)] mod transport_limits; +#[cfg(not(unix))] +mod worktree_removal_flow; diff --git a/crates/dim-app-server/tests/worktree_removal_flow.rs b/crates/dim-app-server/tests/worktree_removal_flow.rs new file mode 100644 index 0000000000..9a6ff3a374 --- /dev/null +++ b/crates/dim-app-server/tests/worktree_removal_flow.rs @@ -0,0 +1,98 @@ +//! The non-force removal of an unregistered directory, over the local +//! transport the product uses. A platform without handle-relative deletion +//! refuses it, and `--force` remains the way to remove the tree. +use dim_agent_capabilities::defaults; +use dim_agent_runtime::{AgentBuilder, AgentConfig}; +use dim_app_server::{ServerConfig, serve}; +use serde_json::{Value, json}; +use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; +use tokio::net::windows::named_pipe::{ClientOptions, NamedPipeClient}; + +fn builder() -> AgentBuilder { + let mut builder = AgentBuilder::new(AgentConfig::default()); + defaults::mock_hosts(&mut builder); + defaults::install(&mut builder); + builder +} + +async fn reply( + client: &mut BufReader, + id: u32, + method: &str, + params: Value, +) -> Value { + let mut frame = serde_json::to_vec(&json!({ + "jsonrpc":"2.0", "id":id, "method":method, "params":params, + })) + .unwrap(); + frame.push(b'\n'); + client.get_mut().write_all(&frame).await.unwrap(); + loop { + let mut line = String::new(); + assert_ne!(client.read_line(&mut line).await.unwrap(), 0); + let reply: Value = serde_json::from_str(&line).unwrap(); + if reply["id"] == id { + return reply; + } + } +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn a_non_force_removal_refuses_an_unregistered_directory() { + let home = std::env::temp_dir().join(format!("dim-worktree-removal-{}", uuid::Uuid::new_v4())); + std::fs::create_dir_all(&home).unwrap(); + let home = home.canonicalize().unwrap(); + let pipe = format!(r"\\.\pipe\dim-worktree-removal-{}", uuid::Uuid::new_v4()); + let server = serve( + builder(), + ServerConfig { + pipe_name: Some(pipe.clone()), + websocket_address: None, + product_home: Some(home.clone()), + target_home: Some(home.join("native")), + platform_home: Some(home.join("user")), + ..Default::default() + }, + ) + .await + .unwrap(); + let entry = home.join("worktrees").join("aaaaaa"); + std::fs::create_dir_all(entry.join("repo")).unwrap(); + let mut client = BufReader::new(ClientOptions::new().open(&pipe).unwrap()); + let hello = reply( + &mut client, + 1, + "hello", + json!({"protocolVersion":3,"clientKind":"cli"}), + ) + .await; + assert_eq!(hello["result"]["protocolVersion"], 3); + let refused = reply( + &mut client, + 2, + "worktree.remove", + json!({"taskId":"aaaaaa"}), + ) + .await; + assert_eq!(refused["error"]["data"]["appError"], "worktree_in_use"); + assert!( + refused["error"]["message"] + .as_str() + .unwrap() + .contains("--force"), + "{refused}" + ); + assert!(entry.join("repo").is_dir()); + let removed = reply( + &mut client, + 3, + "worktree.remove", + json!({"taskId":"aaaaaa","force":true}), + ) + .await; + assert_eq!(removed["result"]["removed"], true); + assert!(!entry.exists()); + server.shutdown(); + server.join().await.unwrap(); + let _ = std::fs::remove_dir_all(&home); +} diff --git a/scripts/ci-changes.mjs b/scripts/ci-changes.mjs index e20530bf77..cc47415a89 100644 --- a/scripts/ci-changes.mjs +++ b/scripts/ci-changes.mjs @@ -8,7 +8,9 @@ const cargoManifest=/(?:^|\/)Cargo\.toml$/; // The Windows-only boundary flows no other platform compiles (#2065): the // product files behind crates/dim-agent-capabilities/tests/file_storage_flow.rs, // tests/host_platform_windows_flow.rs and crates/dim-app-server/tests/named_pipe_flow.rs, -// the test targets that include them, and the runner that selects them. A file +// the worktree removal refusal in crates/dim-app-server/src/worktrees.rs and its +// flow in crates/dim-app-server/tests/worktree_removal_flow.rs, the test targets +// that include them, and the runner that selects them. A file // missing here still reaches the Windows step on the daily sweep, so add it when // a Windows branch of those flows moves or gains another file. // The same tests are named in scripts/test-windows-native.mjs's `flows`, which @@ -19,8 +21,8 @@ const cargoManifest=/(?:^|\/)Cargo\.toml$/; const windowsNative=[ /^crates\/dim-agent-capabilities\/src\/(?:file_storage\.rs|file_storage\/|host_platform\.rs|host_platform\/)/, /^crates\/dim-agent-capabilities\/tests\/(?:capabilities_flow|file_storage_flow|host_platform_windows_flow)\.rs$/, - /^crates\/dim-app-server\/src\/(?:lib|transport|pipe_client|cli)\.rs$/, - /^crates\/dim-app-server\/tests\/(?:app_server_flow|named_pipe_flow)\.rs$/, + /^crates\/dim-app-server\/src\/(?:lib|transport|pipe_client|cli|worktrees)\.rs$/, + /^crates\/dim-app-server\/tests\/(?:app_server_flow|named_pipe_flow|worktree_removal_flow)\.rs$/, /^scripts\/test-windows-native\.mjs$/, ]; diff --git a/scripts/ci-changes.test.mjs b/scripts/ci-changes.test.mjs index 43405b981c..1f7d523d1b 100644 --- a/scripts/ci-changes.test.mjs +++ b/scripts/ci-changes.test.mjs @@ -90,8 +90,10 @@ test('Windows-native flows follow their storage, host and named pipe paths',()=> 'crates/dim-app-server/src/transport.rs', 'crates/dim-app-server/src/pipe_client.rs', 'crates/dim-app-server/src/cli.rs', + 'crates/dim-app-server/src/worktrees.rs', 'crates/dim-app-server/tests/app_server_flow.rs', 'crates/dim-app-server/tests/named_pipe_flow.rs', + 'crates/dim-app-server/tests/worktree_removal_flow.rs', 'scripts/test-windows-native.mjs', ]) assert.equal(classify([file]).windows_native,true,file); for (const file of [ diff --git a/scripts/test-windows-native.mjs b/scripts/test-windows-native.mjs index fced5bab2e..469e601fff 100644 --- a/scripts/test-windows-native.mjs +++ b/scripts/test-windows-native.mjs @@ -22,6 +22,7 @@ export const flows = [ {package: 'dim-app-server', target: 'app_server_flow', tests: [ 'named_pipe_flow::native_client_authenticates_before_rpc_and_exits_without_stdin_eof', 'named_pipe_flow::named_pipe_is_private_exclusive_and_shares_session_cleanup', + 'worktree_removal_flow::a_non_force_removal_refuses_an_unregistered_directory', ]}, ]; From 41f4ffac098781b226af8faae94731447944a84a Mon Sep 17 00:00:00 2001 From: huihui Date: Wed, 25 Nov 2026 20:09:46 +0800 Subject: [PATCH 2/2] docs(ci): record the worktree-removal Windows-native flow The Windows-native selection covers the worktree removal refusal in `crates/dim-app-server/src/worktrees.rs` and its flow in `crates/dim-app-server/tests/worktree_removal_flow.rs`. Add the worktree-removal paths and `worktree_removal_flow` to the CI descriptions so a change to that path is documented as selecting the `windows-cli` job. --- docs/architecture/build.md | 2 +- docs/architecture/tui-e2e.md | 4 ++-- docs/release/README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/architecture/build.md b/docs/architecture/build.md index f1dfbeaa91..aecd0e4985 100644 --- a/docs/architecture/build.md +++ b/docs/architecture/build.md @@ -349,7 +349,7 @@ The root `./dev` entry performs incremental CLI/App Server builds without disabl The [Web workspace](../design/web-workspace.md) frontend in `web/` is a separate artifact (`scripts/stage-web.mjs` builds it; the CLI finds the installed `dimcode-web` package or a `web/` directory beside the executable or in the product home, or `DIMCODE_WEB_ASSETS` names one), so building `dim-app-server` and `dimcode` needs neither Node nor npm. Only `cargo build --features embedded-web` compiles the frontend in; then `build.rs` runs `npm ci` and `npm run build` when that frontend changed, and a host without npm fails the build. Otherwise Node is only needed for packaging, packaging checks and TypeScript plugin execution/development. `.node-version` pins the Node version bundled into account-enabled releases. The `runtime/package-lock.json` fixes the rutis Node runtime and its transitive dependencies; `npm ci --ignore-scripts --prefix runtime` installs them for local bridge testing. -Pull requests run workspace verification on self-hosted Linux x64 runners labelled `dim-verify`, with eight Cargo build jobs. The job checks that bubblewrap can create the sandbox the confined tests use (a user namespace with a private `/proc`) before running them. The macOS ARM64 runners use four Cargo jobs for the native Rust checks on pull requests and for full workspace verification on `main`. Use `node scripts/test-macos-native.mjs --list` to inspect the Rust selection from the current Cargo targets, Rust platform guards and host-specific test fixtures. On an Apple Silicon Mac, run `node scripts/test-macos-native.mjs` to build those targets and check each selected name against its compiled test binary before execution. Tests marked for manual execution keep their normal ignore status. The [workflow guide](../release/README.md#github-workflows) describes path selection, native packaging checks and manual dispatch. The separate `windows-cli` job runs the `dim-cli` library tests on a self-hosted Windows x64 runner, where its fixture writes to the clipboard. When a pull request changes Windows storage, host-platform or named-pipe paths, when a push to `main` changes a path that selects the job, and on scheduled sweeps and manual dispatch, the same job also builds and runs the Windows-only boundary flows (`file_storage_flow`'s Windows checks, `host_platform_windows_flow` and `named_pipe_flow`) in that directory; `node scripts/test-windows-native.mjs --list` prints the selection and a run checks every selected name against its compiled test binary. The job keeps its fifteen-minute hard timeout, and the first cold compile of the `dim-app-server` graph that the step adds may not fit it; no run has measured that yet and it cannot be reproduced locally. The layout workflow uses hosted `windows-2022` and `windows-11-arm` runners, with Python 3.13 and the pinned native MSVC Rust host toolchain provisioned explicitly. Release builds use GitHub-hosted VMs matching each target OS and CPU. See the [runner setup and release matrix](../release/README.md#runner-setup). +Pull requests run workspace verification on self-hosted Linux x64 runners labelled `dim-verify`, with eight Cargo build jobs. The job checks that bubblewrap can create the sandbox the confined tests use (a user namespace with a private `/proc`) before running them. The macOS ARM64 runners use four Cargo jobs for the native Rust checks on pull requests and for full workspace verification on `main`. Use `node scripts/test-macos-native.mjs --list` to inspect the Rust selection from the current Cargo targets, Rust platform guards and host-specific test fixtures. On an Apple Silicon Mac, run `node scripts/test-macos-native.mjs` to build those targets and check each selected name against its compiled test binary before execution. Tests marked for manual execution keep their normal ignore status. The [workflow guide](../release/README.md#github-workflows) describes path selection, native packaging checks and manual dispatch. The separate `windows-cli` job runs the `dim-cli` library tests on a self-hosted Windows x64 runner, where its fixture writes to the clipboard. When a pull request changes Windows storage, host-platform, named-pipe or worktree-removal paths, when a push to `main` changes a path that selects the job, and on scheduled sweeps and manual dispatch, the same job also builds and runs the Windows-only boundary flows (`file_storage_flow`'s Windows checks, `host_platform_windows_flow`, `named_pipe_flow` and `worktree_removal_flow`) in that directory; `node scripts/test-windows-native.mjs --list` prints the selection and a run checks every selected name against its compiled test binary. The job keeps its fifteen-minute hard timeout, and the first cold compile of the `dim-app-server` graph that the step adds may not fit it; no run has measured that yet and it cannot be reproduced locally. The layout workflow uses hosted `windows-2022` and `windows-11-arm` runners, with Python 3.13 and the pinned native MSVC Rust host toolchain provisioned explicitly. Release builds use GitHub-hosted VMs matching each target OS and CPU. See the [runner setup and release matrix](../release/README.md#runner-setup). The macOS clipboard flows use private pasteboards and serialize access to the shared pasteboard server; other tests remain parallel. diff --git a/docs/architecture/tui-e2e.md b/docs/architecture/tui-e2e.md index d08ad0ab2b..715007eecd 100644 --- a/docs/architecture/tui-e2e.md +++ b/docs/architecture/tui-e2e.md @@ -43,8 +43,8 @@ Prerequisites: The suite is Unix-only because tmux is. Windows keeps its native boundary checks in the `windows-cli` job: `cargo test --locked -p dim-cli --lib`, and the Windows-only boundary flows that the same job runs for Windows storage, -host-platform and named-pipe paths and on full sweeps. The component-level -terminal tests that do not need tmux also run there. +host-platform, named-pipe and worktree-removal paths and on full sweeps. The +component-level terminal tests that do not need tmux also run there. ## What a case runs diff --git a/docs/release/README.md b/docs/release/README.md index bfbaad09ef..d735e3fec8 100644 --- a/docs/release/README.md +++ b/docs/release/README.md @@ -223,7 +223,7 @@ release packages use the ordinary Cargo executable. `ci.yml` runs on pull requests, pushes to `main`, a daily scheduled full sweep (`0 19 * * *` UTC), and manual dispatch. A pull request runs the groups its changed paths need, as decided by `scripts/ci-changes.mjs`. A push to `main` runs only `changes` and `ci-ok` when its entire push range changes only paths that select no check group (documentation and non-code repository metadata); pushes touching any checked path or whose base cannot be compared keep the full `main` run while the daily scheduled sweep is established (ADR 026 D5). Scheduled sweeps and manual dispatch select every group across both Linux and macOS: if a scheduled sweep fails on a cross-group regression, the maintainers triage it and bisect the `main` commit range since the previous passing sweep back to the regressing merge. Every push to `main` runs its selected jobs to completion: a later push does not cancel them, so each merge has its own result and the `main CI` badge in the [README](../../README.md) reports the latest finished one. -CI builds the workspace, checks formatting and Clippy, runs workspace tests and boundary checks, runs the packaging/development script tests in a dedicated Linux x64 `scripts` job, and exercises the ignored actual CLI profile and public Node-backed flows. `ci-ok` passes when every selected gating job passes, so it is the check to require. CI builds without debug info (`CARGO_PROFILE_DEV_DEBUG=0`). The [build environment](../architecture/build.md) describes test artifact reuse, concurrency limits, and target deadlines. Cargo runs documentation tests with the same features, and ignored CLI and Node flows reuse the recorded binaries without package-scoped recompilation. Web source changes, plugin pages and static generated graphs run the lightweight `static-checks` job (`xtask-check`) on Linux x64 without compiling business runtime crates, while `catalog.md` changes retain the runtime-assembled `xtask` check; from `scripts/`, `scripts/stage-web.mjs` and `scripts/run-rust-test.mjs` select the `web` job (the latter deliberately selects every group), while Rust files read directly by packaging scripts (`crates/dim-app-server/src/protocol.rs`, `crates/dim-app-server/src/storage/sqlite.rs`, and `crates/dim-app-server/resources/`) retain their owning packaging checks. Node-backed checks run for runtime, binding and service-contract paths, and CLI-only changes retain their ordinary and actual-profile flows. Windows client transport and CLI terminal crates (`crates/dim-cli/`, `crates/dim-client/`, `crates/dim-agent-types/`, `vendor/grok-build/`) trigger `windows-cli`. Windows storage, host-platform and named-pipe paths (`crates/dim-agent-capabilities/src/file_storage*`, `crates/dim-agent-capabilities/src/host_platform*`, `crates/dim-app-server/src/lib.rs`, `transport.rs`, `pipe_client.rs`, `cli.rs` and the test files that hold those flows) also run its Windows-native boundary step, which `main` pushes that select the job, scheduled sweeps and manual dispatch execute as well. Evaluation tests use `xtask/eval-tests` for `xtask/` changes, and the wall-clock handoff runs for execution-related changes. PRs run `verify (linux)` for the selected Rust/`xtask` groups. Rust PRs also run `macos-native` on Apple Silicon, and changes affecting native packaging or code layout select its macOS script checks on PRs, `main` pushes, scheduled sweeps and manual runs. All selected jobs feed `ci-ok`. Full `main` pushes run `verify (macos)`, and scheduled sweeps and manual dispatch run full verification on both Linux and macOS. The `web` job runs on self-hosted Windows x64. It stages the frontend package, verifies generated declarations and bundled dependency notices, and runs the Web tests. +CI builds the workspace, checks formatting and Clippy, runs workspace tests and boundary checks, runs the packaging/development script tests in a dedicated Linux x64 `scripts` job, and exercises the ignored actual CLI profile and public Node-backed flows. `ci-ok` passes when every selected gating job passes, so it is the check to require. CI builds without debug info (`CARGO_PROFILE_DEV_DEBUG=0`). The [build environment](../architecture/build.md) describes test artifact reuse, concurrency limits, and target deadlines. Cargo runs documentation tests with the same features, and ignored CLI and Node flows reuse the recorded binaries without package-scoped recompilation. Web source changes, plugin pages and static generated graphs run the lightweight `static-checks` job (`xtask-check`) on Linux x64 without compiling business runtime crates, while `catalog.md` changes retain the runtime-assembled `xtask` check; from `scripts/`, `scripts/stage-web.mjs` and `scripts/run-rust-test.mjs` select the `web` job (the latter deliberately selects every group), while Rust files read directly by packaging scripts (`crates/dim-app-server/src/protocol.rs`, `crates/dim-app-server/src/storage/sqlite.rs`, and `crates/dim-app-server/resources/`) retain their owning packaging checks. Node-backed checks run for runtime, binding and service-contract paths, and CLI-only changes retain their ordinary and actual-profile flows. Windows client transport and CLI terminal crates (`crates/dim-cli/`, `crates/dim-client/`, `crates/dim-agent-types/`, `vendor/grok-build/`) trigger `windows-cli`. Windows storage, host-platform, named-pipe and worktree-removal paths (`crates/dim-agent-capabilities/src/file_storage*`, `crates/dim-agent-capabilities/src/host_platform*`, `crates/dim-app-server/src/lib.rs`, `transport.rs`, `pipe_client.rs`, `cli.rs`, `worktrees.rs` and the test files that hold those flows, including `worktree_removal_flow.rs`) also run its Windows-native boundary step, which `main` pushes that select the job, scheduled sweeps and manual dispatch execute as well. Evaluation tests use `xtask/eval-tests` for `xtask/` changes, and the wall-clock handoff runs for execution-related changes. PRs run `verify (linux)` for the selected Rust/`xtask` groups. Rust PRs also run `macos-native` on Apple Silicon, and changes affecting native packaging or code layout select its macOS script checks on PRs, `main` pushes, scheduled sweeps and manual runs. All selected jobs feed `ci-ok`. Full `main` pushes run `verify (macos)`, and scheduled sweeps and manual dispatch run full verification on both Linux and macOS. The `web` job runs on self-hosted Windows x64. It stages the frontend package, verifies generated declarations and bundled dependency notices, and runs the Web tests. The `Verify Python plugins` step is off by default. When a Python plugin ships, set the repository Actions variable `DIM_CI_PYTHON_PLUGINS` to `true` to run it whenever the Node check group is selected. It prepares CPython for the `python_plugin_` flows and reuses the App Server test binary from the workspace build. See the [App Server verification commands](../../crates/dim-app-server/README.md#verification) to run the suites locally.