Skip to content
Merged
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
24 changes: 2 additions & 22 deletions crates/dim-app-server/src/worktrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,10 @@ fn parse_duration(text: &str) -> Result<Duration, RpcError> {

#[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()));
Expand Down Expand Up @@ -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());
}
}
2 changes: 2 additions & 0 deletions crates/dim-app-server/tests/app_server_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mod storage_flow;
mod storage_session_flow;
#[cfg(unix)]
mod transport_limits;
#[cfg(not(unix))]
mod worktree_removal_flow;
98 changes: 98 additions & 0 deletions crates/dim-app-server/tests/worktree_removal_flow.rs
Original file line number Diff line number Diff line change
@@ -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<NamedPipeClient>,
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);
}
2 changes: 1 addition & 1 deletion docs/architecture/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions docs/architecture/tui-e2e.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 run the lightweight `static-checks` job (`xtask-check`) on Linux x64 without compiling business runtime crates. Plugin pages select 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 run the lightweight `static-checks` job (`xtask-check`) on Linux x64 without compiling business runtime crates. Plugin pages select 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.

Expand Down
8 changes: 5 additions & 3 deletions scripts/ci-changes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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$/,
];

Expand Down
2 changes: 2 additions & 0 deletions scripts/ci-changes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,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 [
Expand Down
1 change: 1 addition & 0 deletions scripts/test-windows-native.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]},
];

Expand Down