From 576957f0316fe373ce5ce30c40ac943b36fdabfa Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 17:35:39 +0800 Subject: [PATCH 1/4] build(ci): replace DIM_RELEASE_BUILD recompile loop with release-safe runtime injection Stop reading `option_env!("DIM_RELEASE_BUILD")` in the foundational `dim-agent-capabilities` crate and move release-flag wiring to the final `dimcode` binary crate, matching `GIT_COMMIT` and `BUILD_ID` (ADR 026 D3): - `crates/dim-agent-capabilities/src/build.rs`: replace `pub const RELEASE` with a `OnceLock` installed via `build::install(commit, build_id, release)` and read through `build::release()`. Support a `#[cfg(debug_assertions)]`-only `DIM_TEST_RELEASE_BUILD` runtime override (unreachable in release builds). - `crates/dimcode/build.rs` & `crates/dimcode/src/main.rs`: forward `DIM_RELEASE_BUILD` into `dimcode` alone and install it at startup, so toggling `DIM_RELEASE_BUILD` recompiles only `dimcode` (~2s) instead of 56 upstream crates. - `crates/dim-cli` & `crates/dim-app-server`: switch `build::RELEASE` reads to `build::release()` and document `DIM_TEST_RELEASE_BUILD` in `crates/dim-cli/README.md`. - `crates/dimcode/tests/cli_flow/{staged_update,daemon_replace}.rs`: drive `staged_update::recovery::*` and `staged_update::tui_update::*` via `DIM_TEST_RELEASE_BUILD=1` in debug builds, split the sequential multi-case loops into parallel tests, and verify `--version` override behavior. - `.github/workflows/ci.yml`: drop the redundant `DIM_RELEASE_BUILD=1` `cargo test -p dimcode` step that recompiled 56 crates (~2.1-2.4 min and ~1.7 GiB of `mbx` cache writes) on every Rust PR, since those tests now run directly inside `Run compiled workspace tests`. Fixes #1932 Refs #1919 --- .github/workflows/ci.yml | 7 - crates/dim-agent-capabilities/src/build.rs | 57 +- crates/dim-app-server/tests/mcp_http_flow.rs | 2 +- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/client.rs | 2 +- crates/dim-cli/src/lib.rs | 2 +- crates/dim-cli/src/update.rs | 6 +- crates/dimcode/build.rs | 9 +- crates/dimcode/src/main.rs | 7 +- .../dimcode/tests/cli_flow/daemon_replace.rs | 51 + .../dimcode/tests/cli_flow/staged_update.rs | 928 +++++++++--------- 11 files changed, 581 insertions(+), 492 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3501a8b6b1..dec42233bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -243,13 +243,6 @@ jobs: real_daemon_profile_conflicts_preserve_the_running_daemon_and_endpoint \ workflow::workflow_commands_write_and_enable_against_the_real_owner \ --ignored --test-threads=2 - - name: Verify startup recovery and Update now in a release-stamped CLI - if: needs.changes.outputs.rust == 'true' - env: - DIM_RELEASE_BUILD: '1' - run: | - cargo test --locked -p dimcode --test cli_flow "staged_update::recovery::" - cargo test --locked -p dimcode --test cli_flow "staged_update::tui_update::" - name: Verify public Node bindings if: needs.changes.outputs.node == 'true' shell: bash diff --git a/crates/dim-agent-capabilities/src/build.rs b/crates/dim-agent-capabilities/src/build.rs index fd2926492d..b801522e37 100644 --- a/crates/dim-agent-capabilities/src/build.rs +++ b/crates/dim-agent-capabilities/src/build.rs @@ -8,16 +8,6 @@ use std::sync::OnceLock; /// The workspace version; the release flow sets it for the builds it produces. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -/// Whether the release flow produced this build, which it marks with -/// `DIM_RELEASE_BUILD`. CI exports an unset variable as empty, so an empty -/// mark is no mark. -pub const RELEASE: bool = stamped(option_env!("DIM_RELEASE_BUILD")); - -/// Whether `value` marks the build: an empty value is no mark. -const fn stamped(value: Option<&'static str>) -> bool { - matches!(value, Some(value) if !value.is_empty()) -} - /// The marker of a build the release flow did not produce. const SOURCE: &str = "-source"; @@ -29,15 +19,20 @@ static COMMIT: OnceLock> = OnceLock::new(); /// than the source; `None` when the build left none. static BUILD_ID: OnceLock> = OnceLock::new(); -/// Hands this build the commit and the artifact stamp the final binary crate -/// read at build time. The binary calls this once before it serves either -/// role, so every label in the process — the client's, the daemon's reports -/// and its MCP identity — names the commit it runs. Nothing in this crate reads -/// git or a build environment, so a new commit never recompiles it. The first -/// call wins. -pub fn install(commit: Option<&'static str>, build_id: Option<&'static str>) { +/// Whether the release flow produced this build, installed by the final binary +/// crate. +static RELEASE: OnceLock = OnceLock::new(); + +/// Hands this build the commit, artifact stamp and release mark the final +/// binary crate read at build time. The binary calls this once before it serves +/// either role, so every label in the process — the client's, the daemon's +/// reports and its MCP identity — names one build. Nothing in this crate reads +/// git or a build environment, so a new commit or release flag never recompiles +/// it. The first call wins. +pub fn install(commit: Option<&'static str>, build_id: Option<&'static str>, release: bool) { let _ = COMMIT.set(commit); let _ = BUILD_ID.set(stamp(build_id)); + let _ = RELEASE.set(release_flag(release)); } /// The stamp this build carries. A debug build takes `DIM_TEST_BUILD_ID` @@ -54,6 +49,25 @@ fn stamp(build_id: Option<&'static str>) -> Option { build_id.map(str::to_owned) } +/// Whether this build behaves as a released build. A debug build takes +/// `DIM_TEST_RELEASE_BUILD` instead, so a flow can exercise release-gated +/// behavior without recompiling with `DIM_RELEASE_BUILD=1`; an empty value or +/// `"0"` means a source build. A release build ignores the variable. +fn release_flag(release: bool) -> bool { + #[cfg(debug_assertions)] + if let Some(value) = std::env::var_os("DIM_TEST_RELEASE_BUILD") { + return value + .to_str() + .is_some_and(|value| !value.is_empty() && value != "0"); + } + release +} + +/// Whether the release flow produced this build. +pub fn release() -> bool { + RELEASE.get().copied().unwrap_or(false) +} + /// The artifact stamp this build reported, or `None` when its build left /// none: an unstamped build names its source but not its artifact. pub fn build_id() -> Option<&'static str> { @@ -72,7 +86,7 @@ pub fn label(version: &str, release: bool, commit: Option<&str>) -> String { /// What this build reports. pub fn current() -> String { - label(VERSION, RELEASE, COMMIT.get().copied().flatten()) + label(VERSION, release(), COMMIT.get().copied().flatten()) } #[cfg(test)] @@ -97,11 +111,4 @@ mod tests { ); assert_eq!(label("0.1.0-alpha.8", false, None), "0.1.0-alpha.8-source"); } - - #[test] - fn an_empty_release_mark_is_no_mark() { - assert!(stamped(Some("1"))); - assert!(!stamped(Some(""))); - assert!(!stamped(None)); - } } diff --git a/crates/dim-app-server/tests/mcp_http_flow.rs b/crates/dim-app-server/tests/mcp_http_flow.rs index 6010f956ff..238e3eadf8 100644 --- a/crates/dim-app-server/tests/mcp_http_flow.rs +++ b/crates/dim-app-server/tests/mcp_http_flow.rs @@ -1975,7 +1975,7 @@ async fn the_mcp_client_declares_the_build_the_process_reports() { json!(dim_agent_capabilities::build::current()), "the MCP client declares the label its own process reports" ); - if !dim_agent_capabilities::build::RELEASE { + if !dim_agent_capabilities::build::release() { assert_ne!( received[0]["version"], json!(env!("CARGO_PKG_VERSION")), diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index 46c524a69d..5a2670f960 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1769,7 +1769,7 @@ cargo test --locked -p dimcode --test cli_flow cargo clippy --locked -p dim-cli --all-targets -- -D warnings ``` -Two debug-only variables shorten the daemon startup waits for the flow tests: `DIM_TEST_DAEMON_START_TIMEOUT_MS` replaces the 10 s bound of the wait before spawning and of the spawn wait and `DIM_TEST_START_LOCK_TIMEOUT_MS` the start-lock wait's derived bound, so a test reaches an inactivity bound without waiting the production time. A third, `DIM_TEST_BUILD_ID`, replaces this build's artifact stamp, so a flow or a tmux scenario can stand a client and a daemon of different builds beside each other; an empty value means no stamp. Only a debug build reads them, a release build ignores them, and the tests that set them compile only in debug builds. +Two debug-only variables shorten the daemon startup waits for the flow tests: `DIM_TEST_DAEMON_START_TIMEOUT_MS` replaces the 10 s bound of the wait before spawning and of the spawn wait and `DIM_TEST_START_LOCK_TIMEOUT_MS` the start-lock wait's derived bound, so a test reaches an inactivity bound without waiting the production time. Two more inject build identity without recompiling: `DIM_TEST_BUILD_ID` replaces this build's artifact stamp (so a flow or a tmux scenario can stand a client and a daemon of different builds beside each other; an empty value means no stamp), and `DIM_TEST_RELEASE_BUILD` overrides the release mark (so flows can test release-gated startup recovery and `Update now` against the already-compiled debug binary; an empty value or `"0"` means a source build). Only a debug build reads them, a release build ignores them, and the tests that set them compile only in debug builds. The production-model flow uses the actual App Server, an API-key environment reference and a local OpenAI-compatible HTTP stream fixture. It checks the production tool list, a real file read reaching the model, and continued input on the same persisted session: diff --git a/crates/dim-cli/src/client.rs b/crates/dim-cli/src/client.rs index 6cd67ca13a..a0ed65895d 100644 --- a/crates/dim-cli/src/client.rs +++ b/crates/dim-cli/src/client.rs @@ -127,7 +127,7 @@ fn default_plugins(executable: &Path) -> Option { /// `dimcode web install`, while a build from source, which has none /// published, is pointed at `DIMCODE_WEB_ASSETS` or the embedded-web build. pub fn web_hint(error: &crate::Error, executable: &Path, home: &Path) -> Option<(String, String)> { - let install = if dim_agent_capabilities::build::RELEASE { + let install = if dim_agent_capabilities::build::release() { "Install it with `dimcode web install`".to_owned() } else { "Set DIMCODE_WEB_ASSETS to a frontend built from this source, or build the App Server with the embedded-web feature".to_owned() diff --git a/crates/dim-cli/src/lib.rs b/crates/dim-cli/src/lib.rs index ddb403615c..f19c33f93e 100644 --- a/crates/dim-cli/src/lib.rs +++ b/crates/dim-cli/src/lib.rs @@ -862,7 +862,7 @@ async fn act(root: &rutis::Ctx, mut options: Options) -> Result { return open_tui(root, &options, initial, locale).await; } if matches!(options.action, Action::WebInstall) { - if !dim_agent_capabilities::build::RELEASE { + if !dim_agent_capabilities::build::release() { return Err("A build from source has no published Web workspace; set DIMCODE_WEB_ASSETS to a frontend built from this source, or build the App Server with the embedded-web feature".into()); } let executable = std::env::current_exe().unwrap_or_default(); diff --git a/crates/dim-cli/src/update.rs b/crates/dim-cli/src/update.rs index cd24d99579..d4da17097e 100644 --- a/crates/dim-cli/src/update.rs +++ b/crates/dim-cli/src/update.rs @@ -304,7 +304,7 @@ fn upgrade_tag(version: &str, release: bool) -> Option<&str> { /// A newer version on the channel of `current` the user has not skipped, or /// `None` when there is none or the registry did not answer in time. pub async fn available(home: &Path, current: &str) -> Option { - let tag = upgrade_tag(current, dim_agent_capabilities::build::RELEASE)?; + let tag = upgrade_tag(current, dim_agent_capabilities::build::release())?; let package = package().ok()?; let version = channel_version(&package, tag).await.ok()?; if !newer(current, &version) || skipped(home).as_deref() == Some(version.as_str()) { @@ -333,7 +333,7 @@ fn offer(exe: &Path, package: &str, current: &str, version: String) -> Offer { /// be offered: a source build, or a registry that did not answer. pub async fn check(current: &str) -> Result, String> { let package = package()?; - let Some(tag) = upgrade_tag(current, dim_agent_capabilities::build::RELEASE) else { + let Some(tag) = upgrade_tag(current, dim_agent_capabilities::build::release()) else { return Err(not_installable(&package, current)); }; let version = channel_version(&package, tag) @@ -375,7 +375,7 @@ pub(crate) async fn recover_startup( ) -> crate::Result { use std::os::unix::process::CommandExt; - if !dim_agent_capabilities::build::RELEASE + if !dim_agent_capabilities::build::release() || !enabled() || !std::io::stderr().is_terminal() || std::env::var_os(crate::client::STARTUP_RETRY).is_some() diff --git a/crates/dimcode/build.rs b/crates/dimcode/build.rs index 1ca7431cbf..40c44bf900 100644 --- a/crates/dimcode/build.rs +++ b/crates/dimcode/build.rs @@ -23,18 +23,23 @@ const BUILD_ID: &str = "DIM_BUILD_ID"; /// named a commit or when this is a release build, whose output must not change. const COMMIT: &str = "DIM_GIT_COMMIT"; +/// Whether the release flow produced this build, forwarded into the final +/// binary crate so a build cache replays it alongside the stamp. +const RELEASE: &str = "DIM_RELEASE_BUILD"; + fn main() { - println!("cargo:rerun-if-env-changed=DIM_RELEASE_BUILD"); + println!("cargo:rerun-if-env-changed={RELEASE}"); println!("cargo:rerun-if-env-changed={FROM_CALLER}"); println!("cargo:rerun-if-env-changed={BUILD_ID}"); let stamp = std::env::var(BUILD_ID) .ok() .map(|stamp| stamp.trim().to_owned()) .filter(|stamp| !stamp.is_empty()); - if std::env::var_os("DIM_RELEASE_BUILD").is_some_and(|value| !value.is_empty()) { + if std::env::var_os(RELEASE).is_some_and(|value| !value.is_empty()) { // A released build carries no source identity, but the artifact stamp a // packaging caller resolved still distinguishes two builds of one // version. + println!("cargo:rustc-env={RELEASE}=1"); if let Some(stamp) = stamp { println!("cargo:rustc-env={BUILD_ID}={stamp}"); } diff --git a/crates/dimcode/src/main.rs b/crates/dimcode/src/main.rs index 8e945ccd85..addb811e02 100644 --- a/crates/dimcode/src/main.rs +++ b/crates/dimcode/src/main.rs @@ -63,13 +63,18 @@ const BUILD_ID: Option<&str> = match option_env!("DIM_BUILD_ID") { _ => None, }; +/// Whether the release flow produced this build, which `build.rs` forwards from +/// `DIM_RELEASE_BUILD`. Keeping it in the final binary crate means toggling +/// `DIM_RELEASE_BUILD` never recompiles upstream crates. +const RELEASE: bool = present(option_env!("DIM_RELEASE_BUILD")).is_some(); + fn main() { // Both roles this executable serves read one installed identity: the CLI's // `--version`, the daemon's report `Dim` line and its MCP client // declaration, so a log, a report and a screenshot name one commit. The // client and the daemon also compare their stamps, so a client that meets a // daemon of another build of the same version can say so. - dim_agent_capabilities::build::install(GIT_COMMIT, BUILD_ID); + dim_agent_capabilities::build::install(GIT_COMMIT, BUILD_ID, RELEASE); #[cfg(target_os = "linux")] unsafe { unsafe extern "C" { diff --git a/crates/dimcode/tests/cli_flow/daemon_replace.rs b/crates/dimcode/tests/cli_flow/daemon_replace.rs index acf824f678..e56866729e 100644 --- a/crates/dimcode/tests/cli_flow/daemon_replace.rs +++ b/crates/dimcode/tests/cli_flow/daemon_replace.rs @@ -644,4 +644,55 @@ mod build_identity { "an explicit server gets no embedded-build notice: {stderr}" ); } + + #[test] + fn release_override_controls_version_identity_in_debug_builds() { + let version = env!("CARGO_PKG_VERSION"); + let released = Command::new(env!("CARGO_BIN_EXE_dimcode")) + .env("DIM_TEST_RELEASE_BUILD", "1") + .arg("--version") + .output() + .unwrap(); + assert!(released.status.success()); + assert_eq!( + String::from_utf8_lossy(&released.stdout).trim(), + format!("dimcode {version}"), + "DIM_TEST_RELEASE_BUILD=1 must report the bare release version" + ); + + for disabled in ["0", ""] { + let output = Command::new(env!("CARGO_BIN_EXE_dimcode")) + .env("DIM_TEST_RELEASE_BUILD", disabled) + .arg("--version") + .output() + .unwrap(); + assert!(output.status.success()); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!( + stdout + .trim() + .starts_with(&format!("dimcode {version}-source")), + "DIM_TEST_RELEASE_BUILD={disabled:?} must report a source build: {stdout}" + ); + } + + let default_build = Command::new(env!("CARGO_BIN_EXE_dimcode")) + .env_remove("DIM_TEST_RELEASE_BUILD") + .arg("--version") + .output() + .unwrap(); + assert!(default_build.status.success()); + let stdout = String::from_utf8_lossy(&default_build.stdout); + let compiled_release = option_env!("DIM_RELEASE_BUILD").is_some_and(|v| !v.is_empty()); + if compiled_release { + assert_eq!(stdout.trim(), format!("dimcode {version}")); + } else { + assert!( + stdout + .trim() + .starts_with(&format!("dimcode {version}-source")), + "default source build must carry -source: {stdout}" + ); + } + } } diff --git a/crates/dimcode/tests/cli_flow/staged_update.rs b/crates/dimcode/tests/cli_flow/staged_update.rs index 942e66845c..acbae9ff20 100644 --- a/crates/dimcode/tests/cli_flow/staged_update.rs +++ b/crates/dimcode/tests/cli_flow/staged_update.rs @@ -864,184 +864,206 @@ fn an_interrupted_check_ends_every_process_it_started() { ); } -/// These pass trivially unless the build is release-stamped; the CI step runs them. +#[cfg(all(debug_assertions, any(target_os = "macos", target_os = "linux")))] +fn target_platform() -> Option<&'static str> { + match (std::env::consts::OS, std::env::consts::ARCH) { + ("macos", "aarch64") => Some("darwin-arm64"), + ("macos", "x86_64") => Some("darwin-x64"), + ("linux", "aarch64") => Some("linux-arm64"), + ("linux", "x86_64") => Some("linux-x64"), + _ => None, + } +} + +/// Startup recovery when the store format is newer than this daemon. Uses the +/// debug-only `DIM_TEST_RELEASE_BUILD=1` override so these flows run against +/// the already-compiled debug binary without recompiling the workspace. +#[cfg(all(debug_assertions, any(target_os = "macos", target_os = "linux")))] mod recovery { use super::*; - #[cfg(any(target_os = "macos", target_os = "linux"))] - #[test] - fn a_newer_store_recovers_only_with_a_compatible_staged_release() { - if !option_env!("DIM_RELEASE_BUILD").is_some_and(|mark| !mark.is_empty()) { + fn assert_newer_store_recovery(declared: Option, retry: bool, second_failure: bool) { + let Some(platform) = target_platform() else { return; - } - let platform = match (std::env::consts::OS, std::env::consts::ARCH) { - ("macos", "aarch64") => "darwin-arm64", - ("macos", "x86_64") => "darwin-x64", - ("linux", "aarch64") => "linux-arm64", - ("linux", "x86_64") => "linux-x64", - _ => return, }; let version = next_version(); - let format = dim_app_server::storage::STORE_FORMAT; - let future = format + 1; - for (declared, retry, second_failure) in [ - (Some(future), false, false), - (Some(format), false, false), - (None, false, false), - (Some(future), true, false), - (Some(future), false, true), - ] { - let installed = Installed::new(CURRENT, &["dima"]); - installed.mock_npm(); - installed.release(); - let home = Home::new(); - let database = home.0.join("rust/dimcode.sqlite"); - rusqlite::Connection::open(&database) - .unwrap() - .execute_batch(&format!( - "CREATE TABLE agent_store_format (version INTEGER NOT NULL PRIMARY KEY CHECK (version = {future})); - INSERT INTO agent_store_format VALUES ({future});" - )) + let future = dim_app_server::storage::STORE_FORMAT + 1; + let installed = Installed::new(CURRENT, &["dima"]); + installed.mock_npm(); + installed.release(); + let home = Home::new(); + let database = home.0.join("rust/dimcode.sqlite"); + rusqlite::Connection::open(&database) + .unwrap() + .execute_batch(&format!( + "CREATE TABLE agent_store_format (version INTEGER NOT NULL PRIMARY KEY CHECK (version = {future})); + INSERT INTO agent_store_format VALUES ({future});" + )) + .unwrap(); + let original = fs::read(&database).unwrap(); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let registry = format!("http://{}", listener.local_addr().unwrap()); + let reply = json!({ "alpha": version }).to_string(); + let registry = if retry { + drop(listener); + registry + } else { + thread::spawn(move || { + let (mut stream, _) = listener.accept().unwrap(); + stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); + let mut request = String::new(); + BufReader::new(&stream).read_line(&mut request).unwrap(); + assert!(request.starts_with("GET /-/package/dimcode-alpha/dist-tags ")); + write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", + reply.len() + ) .unwrap(); - let original = fs::read(&database).unwrap(); - let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - let registry = format!("http://{}", listener.local_addr().unwrap()); - let reply = json!({ "alpha": version }).to_string(); - let registry = if retry { - drop(listener); - registry - } else { - thread::spawn(move || { - let (mut stream, _) = listener.accept().unwrap(); - stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); - let mut request = String::new(); - BufReader::new(&stream).read_line(&mut request).unwrap(); - assert!(request.starts_with("GET /-/package/dimcode-alpha/dist-tags ")); - write!( - stream, - "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", - reply.len() - ) - .unwrap(); - }); - registry - }; - let cwd = home.0.join("workspace with spaces"); - fs::create_dir(&cwd).unwrap(); - let launcher = r#"#!/bin/sh + }); + registry + }; + let cwd = home.0.join("workspace with spaces"); + fs::create_dir(&cwd).unwrap(); + let launcher = r#"#!/bin/sh if [ "$1" = "--version" ]; then printf 'dimcode %s\n' "$UPDATE_VERSION"; exit 0; fi printf '%s\n' "$DIMCODE_STARTUP_RETRY" "$PWD" "$@" > "$RECOVERY_RESTART" if [ "$RECOVERY_SECOND_FAILURE" = 1 ]; then exec "$RECOVERY_UPDATER" "$@"; fi printf 'Replacement launcher started\n' "#; - let marker = home.0.join("restart"); - let mut command = Command::new(&installed.updater); - command - .current_dir(&cwd) - .arg("--home") - .arg(&home.0) - .args(["tui", "-p", "original message"]) - .env_remove("DIMCODE_DISABLE_AUTOUPDATE") - .env_remove("DIMCODE_AUTOUPDATE") - .env_remove("DIMCODE_UPDATE_CHECK") - .env_remove("DIMCODE_STARTUP_RETRY") - .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") - .env("DIMCODE_NPM_REGISTRY", registry) - .env("NO_PROXY", "127.0.0.1") - .env("RECOVERY_RESTART", &marker) - .env( - "RECOVERY_SECOND_FAILURE", - if second_failure { "1" } else { "0" }, - ) - .env("RECOVERY_UPDATER", &installed.updater) - .env("UPDATE_NATIVE", "") - .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) - .env("UPDATE_VERSION", &version) - .env("UPDATE_ARGS", installed.home.0.join("install-args")) - .env("UPDATE_GATE", installed.home.0.join("gate")) - .env("UPDATE_WAITING", installed.home.0.join("waiting")) - .env( - "UPDATE_PACKAGE_JSON", - package_json(&version, &[("dima", "bin/dimcode.mjs")]), - ) - .env("UPDATE_BINS", "dima=bin/dimcode.mjs") - .env("UPDATE_COMMAND", launcher) - .env( - "UPDATE_RELEASE_MANIFEST", - declared.map_or_else(String::new, |declared| { - json!({ - "schemaVersion": 1, "platform": platform, "version": version, - "storeFormats": [declared] - }) - .to_string() - }), - ); - if retry { - command.env("DIMCODE_STARTUP_RETRY", "1"); - } - if second_failure { - command.env("UPDATE_NATIVE", &installed.updater); - } - let mut terminal = Terminal::launch_tui(command); - let status = terminal.wait(); - let output = strip_ansi(&terminal.transcript); - assert!( - output.contains(&format!("Store format: v{future}")), + let marker = home.0.join("restart"); + let mut command = Command::new(&installed.updater); + command + .current_dir(&cwd) + .arg("--home") + .arg(&home.0) + .args(["tui", "-p", "original message"]) + .env_remove("DIMCODE_DISABLE_AUTOUPDATE") + .env_remove("DIMCODE_AUTOUPDATE") + .env_remove("DIMCODE_UPDATE_CHECK") + .env_remove("DIMCODE_STARTUP_RETRY") + .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") + .env("DIMCODE_NPM_REGISTRY", registry) + .env("NO_PROXY", "127.0.0.1") + .env("RECOVERY_RESTART", &marker) + .env( + "RECOVERY_SECOND_FAILURE", + if second_failure { "1" } else { "0" }, + ) + .env("RECOVERY_UPDATER", &installed.updater) + .env("UPDATE_NATIVE", "") + .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) + .env("UPDATE_VERSION", &version) + .env("UPDATE_ARGS", installed.home.0.join("install-args")) + .env("UPDATE_GATE", installed.home.0.join("gate")) + .env("UPDATE_WAITING", installed.home.0.join("waiting")) + .env( + "UPDATE_PACKAGE_JSON", + package_json(&version, &[("dima", "bin/dimcode.mjs")]), + ) + .env("UPDATE_BINS", "dima=bin/dimcode.mjs") + .env("UPDATE_COMMAND", launcher) + .env( + "UPDATE_RELEASE_MANIFEST", + declared.map_or_else(String::new, |declared| { + json!({ + "schemaVersion": 1, "platform": platform, "version": version, + "storeFormats": [declared] + }) + .to_string() + }), + ); + if retry { + command.env("DIMCODE_STARTUP_RETRY", "1"); + } + if second_failure { + command.env("UPDATE_NATIVE", &installed.updater); + } + let mut terminal = Terminal::launch_tui(command); + let status = terminal.wait(); + let output = strip_ansi(&terminal.transcript); + assert!( + output.contains(&format!("Store format: v{future}")), + "{output}" + ); + assert!(!output.contains("store-newer"), "{output}"); + assert_eq!(fs::read(&database).unwrap(), original); + assert!(!installed.staging().exists()); + let switched = declared == Some(future) && !retry; + assert_eq!(status.success(), switched && !second_failure, "{output}"); + if switched { + assert_eq!(installed.recorded().last().unwrap(), "dimcode-alpha@alpha"); + assert_eq!( + output.matches("Checking dimcode-alpha").count(), + 1, "{output}" ); - assert!(!output.contains("store-newer"), "{output}"); - assert_eq!(fs::read(&database).unwrap(), original); - assert!(!installed.staging().exists()); - let switched = declared == Some(future) && !retry; - assert_eq!(status.success(), switched && !second_failure, "{output}"); - if switched { - assert_eq!(installed.recorded().last().unwrap(), "dimcode-alpha@alpha"); - assert_eq!( - output.matches("Checking dimcode-alpha").count(), - 1, + if !second_failure { + assert!(output.contains("Replacement launcher started"), "{output}"); + } + assert_eq!( + fs::read_to_string(marker).unwrap(), + format!( + "1\n{}\n--home\n{}\ntui\n-p\noriginal message\n", + fs::canonicalize(cwd).unwrap().display(), + home.0.display() + ) + ); + } else { + assert_eq!(installed.installed(), CURRENT); + assert!(!marker.exists()); + if retry { + assert!(!output.contains("Checking dimcode-alpha"), "{output}"); + } else if declared.is_some() { + assert!( + output.contains(&format!( + "{version} does not support native store v{future}" + )), "{output}" ); - if !second_failure { - assert!(output.contains("Replacement launcher started"), "{output}"); - } - assert_eq!( - fs::read_to_string(marker).unwrap(), - format!( - "1\n{}\n--home\n{}\ntui\n-p\noriginal message\n", - fs::canonicalize(cwd).unwrap().display(), - home.0.display() - ) - ); } else { - assert_eq!(installed.installed(), CURRENT); - assert!(!marker.exists()); - if retry { - assert!(!output.contains("Checking dimcode-alpha"), "{output}"); - } else if declared.is_some() { - assert!( - output.contains(&format!( - "{version} does not support native store v{future}" - )), - "{output}" - ); - } else { - assert!( - output.contains(&format!( - "{version} does not declare support for native store v{future}" - )), - "{output}" - ); - } + assert!( + output.contains(&format!( + "{version} does not declare support for native store v{future}" + )), + "{output}" + ); } } } - #[cfg(any(target_os = "macos", target_os = "linux"))] + #[test] + fn a_newer_store_recovers_with_a_compatible_staged_release() { + assert_newer_store_recovery( + Some(dim_app_server::storage::STORE_FORMAT + 1), + false, + false, + ); + } + + #[test] + fn a_newer_store_refuses_a_staged_release_for_an_older_store_format() { + assert_newer_store_recovery(Some(dim_app_server::storage::STORE_FORMAT), false, false); + } + + #[test] + fn a_newer_store_refuses_a_staged_release_without_declared_store_formats() { + assert_newer_store_recovery(None, false, false); + } + + #[test] + fn a_newer_store_does_not_retry_recovery_when_already_restarted() { + assert_newer_store_recovery(Some(dim_app_server::storage::STORE_FORMAT + 1), true, false); + } + + #[test] + fn a_newer_store_stops_if_replacement_launcher_fails_again() { + assert_newer_store_recovery(Some(dim_app_server::storage::STORE_FORMAT + 1), false, true); + } + #[test] fn a_store_this_build_cannot_read_never_recovers() { - if !option_env!("DIM_RELEASE_BUILD").is_some_and(|mark| !mark.is_empty()) { - return; - } let installed = Installed::new(CURRENT, &["dima"]); installed.mock_npm(); installed.release(); @@ -1064,6 +1086,7 @@ mod recovery { .env_remove("DIMCODE_AUTOUPDATE") .env_remove("DIMCODE_UPDATE_CHECK") .env_remove("DIMCODE_STARTUP_RETRY") + .env("DIM_TEST_RELEASE_BUILD", "1") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", "http://127.0.0.1:1") .env("UPDATE_ARGS", installed.home.0.join("install-args")) @@ -1091,18 +1114,10 @@ mod recovery { assert!(!installed.staging().exists()); } - #[cfg(any(target_os = "macos", target_os = "linux"))] #[test] fn a_recovery_never_installs_the_skipped_release() { - if !option_env!("DIM_RELEASE_BUILD").is_some_and(|mark| !mark.is_empty()) { + let Some(platform) = target_platform() else { return; - } - let platform = match (std::env::consts::OS, std::env::consts::ARCH) { - ("macos", "aarch64") => "darwin-arm64", - ("macos", "x86_64") => "darwin-x64", - ("linux", "aarch64") => "linux-arm64", - ("linux", "x86_64") => "linux-x64", - _ => return, }; // The lookup registry answers a version above the skipped one, and the // manager's own registry resolves the channel tag to the skipped one. @@ -1159,6 +1174,7 @@ mod recovery { .env_remove("DIMCODE_AUTOUPDATE") .env_remove("DIMCODE_UPDATE_CHECK") .env_remove("DIMCODE_STARTUP_RETRY") + .env("DIM_TEST_RELEASE_BUILD", "1") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", registry) .env("NO_PROXY", "127.0.0.1") @@ -1209,8 +1225,10 @@ mod recovery { } } -/// `Update now` in the terminal UI. These pass trivially unless the build is -/// release-stamped; the CI step runs them. +/// `Update now` in the terminal UI. Uses the debug-only +/// `DIM_TEST_RELEASE_BUILD=1` override so these flows run against the +/// already-compiled debug binary without recompiling the workspace. +#[cfg(all(debug_assertions, any(target_os = "macos", target_os = "linux")))] mod tui_update { use super::*; @@ -1221,318 +1239,328 @@ mod tui_update { /// while the daemon is asked installs nothing, and every command the CLI /// prints to finish keeps the selected home. A daemon that cannot decide /// whether it is idle gets the manual command instead of `Update now`. - #[cfg(any(target_os = "macos", target_os = "linux"))] - #[test] - fn update_now_stops_an_idle_daemon_and_restarts_or_refuses_a_busy_or_old_one() { - if !option_env!("DIM_RELEASE_BUILD").is_some_and(|mark| !mark.is_empty()) { + fn assert_tui_update_case(case: &'static str) { + let Some(platform) = target_platform() else { return; - } - let platform = match (std::env::consts::OS, std::env::consts::ARCH) { - ("macos", "aarch64") => "darwin-arm64", - ("macos", "x86_64") => "darwin-x64", - ("linux", "aarch64") => "linux-arm64", - ("linux", "x86_64") => "linux-x64", - _ => return, }; let version = next_version(); - for case in ["idle", "busy", "old", "cancelled"] { - let installed = Installed::new(CURRENT, &["dima"]); - installed.mock_npm(); - installed.release(); - let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - let registry = format!("http://{}", listener.local_addr().unwrap()); - let reply = json!({ "alpha": version }).to_string(); - thread::spawn(move || { - for stream in listener.incoming() { - let mut stream = stream.unwrap(); - let mut request = String::new(); - BufReader::new(&stream).read_line(&mut request).unwrap(); - let _ = write!( - stream, - "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", - reply.len() - ); - } - }); - let home = Home::new(); - let socket = home.0.join("rust/daemon.sock"); - let listener = UnixListener::bind(&socket).unwrap(); - fs::set_permissions(&socket, fs::Permissions::from_mode(0o600)).unwrap(); - let (asked, shutdown_asked) = std::sync::mpsc::channel(); - let daemon = thread::spawn(move || { - let (stream, _) = listener.accept().unwrap(); - stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); - let mut wire = Wire::new(stream); - let shutdown = ["daemon.shutdown.completed", "daemon.shutdown.ifIdle"]; - wire.hello(if case == "old" { - &shutdown[..1] - } else { - &shutdown - }); - let attach = wire.read("session.attach"); - wire.reply(&attach, attach_record(&attach)); - let history = wire.read("session.history"); - wire.reply( - &history, - json!({"events":[],"through":8,"nextAfter":8,"done":true}), + let installed = Installed::new(CURRENT, &["dima"]); + installed.mock_npm(); + installed.release(); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let registry = format!("http://{}", listener.local_addr().unwrap()); + let reply = json!({ "alpha": version }).to_string(); + thread::spawn(move || { + for stream in listener.incoming() { + let mut stream = stream.unwrap(); + let mut request = String::new(); + BufReader::new(&stream).read_line(&mut request).unwrap(); + let _ = write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", + reply.len() ); - wire.no_context(); - let providers = wire.read("account.providers"); - wire.reply(&providers, json!([])); - while let Some(request) = wire.trailing_request() { - let request: Value = serde_json::from_str(&request).unwrap(); - assert_ne!(request["method"], "daemon.shutdown", "{request}"); - wire.reply(&request, json!({})); - } - if case == "old" { - return; - } - let (stream, _) = listener.accept().unwrap(); - stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); - let mut wire = Wire::new(stream); - wire.hello(&shutdown); - while let Some(shutdown) = wire.trailing_request() { - let shutdown: Value = serde_json::from_str(&shutdown).unwrap(); - assert_eq!(shutdown["method"], "daemon.shutdown"); - assert_eq!(shutdown["params"], json!({"ifIdle": true})); - match case { - "idle" => { - wire.reply(&shutdown, json!({})); - return; - } - "cancelled" => { - asked.send(()).unwrap(); - continue; - } - _ => {} - } - wire.send(json!({"jsonrpc":"2.0","id":shutdown["id"],"error":{ - "code":-32000,"message":"The App Server is in use", - "data":{"appError":"daemon_busy","connections":1,"attachedSessions":1,"running":0}}})); - } + } + }); + let home = Home::new(); + let socket = home.0.join("rust/daemon.sock"); + let listener = UnixListener::bind(&socket).unwrap(); + fs::set_permissions(&socket, fs::Permissions::from_mode(0o600)).unwrap(); + let (asked, shutdown_asked) = std::sync::mpsc::channel(); + let daemon = thread::spawn(move || { + let (stream, _) = listener.accept().unwrap(); + stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); + let mut wire = Wire::new(stream); + let shutdown = ["daemon.shutdown.completed", "daemon.shutdown.ifIdle"]; + wire.hello(if case == "old" { + &shutdown[..1] + } else { + &shutdown }); - let launcher = format!( - r#"#!/bin/sh -if [ "$1" = "--version" ]; then printf 'dimcode {version}\n'; exit 0; fi -printf '%s\n' "$@" > "$UPDATE_RESTART" -printf 'Updated launcher started\n' -"# + let attach = wire.read("session.attach"); + wire.reply(&attach, attach_record(&attach)); + let history = wire.read("session.history"); + wire.reply( + &history, + json!({"events":[],"through":8,"nextAfter":8,"done":true}), ); - let marker = home.0.join("restart"); - let shot = home.0.join("shot.png"); - fs::write(&shot, noise_png(4, 4)).unwrap(); - let mut command = Command::new(&installed.updater); - command - .args([ - "--home", - home.0.to_str().unwrap(), - "tui", - "--resume", - "session", - ]) - .env_remove("DIMCODE_DISABLE_AUTOUPDATE") - .env_remove("DIMCODE_AUTOUPDATE") - .env_remove("DIMCODE_UPDATE_CHECK") - .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") - .env("DIMCODE_NPM_REGISTRY", ®istry) - .env("NO_PROXY", "127.0.0.1") - .env("UPDATE_RESTART", &marker) - .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) - .env("UPDATE_VERSION", &version) - .env("UPDATE_ARGS", installed.home.0.join("install-args")) - .env("UPDATE_GATE", installed.home.0.join("gate")) - .env("UPDATE_WAITING", installed.home.0.join("waiting")) - .env( - "UPDATE_PACKAGE_JSON", - package_json(&version, &[("dima", "bin/dimcode.mjs")]), - ) - .env("UPDATE_BINS", "dima=bin/dimcode.mjs") - .env("UPDATE_COMMAND", &launcher); - if case == "idle" { - command.args(["-p", "first message", "--image", shot.to_str().unwrap()]); + wire.no_context(); + let providers = wire.read("account.providers"); + wire.reply(&providers, json!([])); + while let Some(request) = wire.trailing_request() { + let request: Value = serde_json::from_str(&request).unwrap(); + assert_ne!(request["method"], "daemon.shutdown", "{request}"); + wire.reply(&request, json!({})); } - sized(&mut command, 100, 30); - let mut terminal = Terminal::launch_tui(command); if case == "old" { - terminal.until_plain("To update, exit DimCode and run: dima update"); - assert!(!strip_ansi(&terminal.transcript).contains("Update now")); - terminal.write(b"\t\r"); - terminal.write(b"/exit\r"); - assert!(terminal.wait().success(), "{}", terminal.transcript); - daemon.join().unwrap(); - assert!(!installed.home.0.join("install-args").exists()); - continue; + return; } - terminal.until_plain("Update now"); - terminal.write(b"\r"); - if case == "cancelled" { - shutdown_asked.recv_timeout(HANG_GUARD).unwrap(); - terminal.signal(libc::SIGINT); + let (stream, _) = listener.accept().unwrap(); + stream.set_read_timeout(Some(HANG_GUARD)).unwrap(); + let mut wire = Wire::new(stream); + wire.hello(&shutdown); + while let Some(shutdown) = wire.trailing_request() { + let shutdown: Value = serde_json::from_str(&shutdown).unwrap(); + assert_eq!(shutdown["method"], "daemon.shutdown"); + assert_eq!(shutdown["params"], json!({"ifIdle": true})); + match case { + "idle" => { + wire.reply(&shutdown, json!({})); + return; + } + "cancelled" => { + asked.send(()).unwrap(); + continue; + } + _ => {} + } + wire.send(json!({"jsonrpc":"2.0","id":shutdown["id"],"error":{ + "code":-32000,"message":"The App Server is in use", + "data":{"appError":"daemon_busy","connections":1,"attachedSessions":1,"running":0}}})); } - let status = terminal.wait(); + }); + let launcher = format!( + r#"#!/bin/sh +if [ "$1" = "--version" ]; then printf 'dimcode {version}\n'; exit 0; fi +printf '%s\n' "$@" > "$UPDATE_RESTART" +printf 'Updated launcher started\n' +"# + ); + let marker = home.0.join("restart"); + let shot = home.0.join("shot.png"); + fs::write(&shot, noise_png(4, 4)).unwrap(); + let mut command = Command::new(&installed.updater); + command + .args([ + "--home", + home.0.to_str().unwrap(), + "tui", + "--resume", + "session", + ]) + .env_remove("DIMCODE_DISABLE_AUTOUPDATE") + .env_remove("DIMCODE_AUTOUPDATE") + .env_remove("DIMCODE_UPDATE_CHECK") + .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") + .env("DIMCODE_NPM_REGISTRY", ®istry) + .env("NO_PROXY", "127.0.0.1") + .env("UPDATE_RESTART", &marker) + .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) + .env("UPDATE_VERSION", &version) + .env("UPDATE_ARGS", installed.home.0.join("install-args")) + .env("UPDATE_GATE", installed.home.0.join("gate")) + .env("UPDATE_WAITING", installed.home.0.join("waiting")) + .env( + "UPDATE_PACKAGE_JSON", + package_json(&version, &[("dima", "bin/dimcode.mjs")]), + ) + .env("UPDATE_BINS", "dima=bin/dimcode.mjs") + .env("UPDATE_COMMAND", &launcher); + if case == "idle" { + command.args(["-p", "first message", "--image", shot.to_str().unwrap()]); + } + sized(&mut command, 100, 30); + let mut terminal = Terminal::launch_tui(command); + if case == "old" { + terminal.until_plain("To update, exit DimCode and run: dima update"); + assert!(!strip_ansi(&terminal.transcript).contains("Update now")); + terminal.write(b"\t\r"); + terminal.write(b"/exit\r"); + assert!(terminal.wait().success(), "{}", terminal.transcript); daemon.join().unwrap(); - let output = strip_ansi(&terminal.transcript); - let selected = format!("dima --home {}", home.0.display()); - if case != "idle" { - assert!(!status.success(), "{output}"); - let blocker = if case == "busy" { - "Other DimCode windows or tasks are using the server" - } else { - "Update cancelled." - }; - assert!(output.contains(blocker), "{output}"); - assert!(output.contains(&format!("{selected} update")), "{output}"); - assert!( - output.contains(&format!( - "Resume this session with: {selected} --resume session" - )), - "{output}" - ); - assert!(!installed.home.0.join("install-args").exists()); - assert!(!marker.exists()); - assert_eq!(installed.installed(), CURRENT); + assert!(!installed.home.0.join("install-args").exists()); + return; + } + terminal.until_plain("Update now"); + terminal.write(b"\r"); + if case == "cancelled" { + shutdown_asked.recv_timeout(HANG_GUARD).unwrap(); + terminal.signal(libc::SIGINT); + } + let status = terminal.wait(); + daemon.join().unwrap(); + let output = strip_ansi(&terminal.transcript); + let selected = format!("dima --home {}", home.0.display()); + if case != "idle" { + assert!(!status.success(), "{output}"); + let blocker = if case == "busy" { + "Other DimCode windows or tasks are using the server" } else { - assert!(status.success(), "{output}"); - assert!(output.contains("Updated launcher started"), "{output}"); - assert_eq!(installed.installed(), version); - assert_eq!( - fs::read_to_string(&marker).unwrap(), - format!( - "--home\n{}\ntui\n--scrollback\n--resume\nsession\n", - home.0.display() - ) - ); - } + "Update cancelled." + }; + assert!(output.contains(blocker), "{output}"); + assert!(output.contains(&format!("{selected} update")), "{output}"); + assert!( + output.contains(&format!( + "Resume this session with: {selected} --resume session" + )), + "{output}" + ); + assert!(!installed.home.0.join("install-args").exists()); + assert!(!marker.exists()); + assert_eq!(installed.installed(), CURRENT); + } else { + assert!(status.success(), "{output}"); + assert!(output.contains("Updated launcher started"), "{output}"); + assert_eq!(installed.installed(), version); + assert_eq!( + fs::read_to_string(&marker).unwrap(), + format!( + "--home\n{}\ntui\n--scrollback\n--resume\nsession\n", + home.0.display() + ) + ); } } + #[test] + fn update_now_stops_an_idle_daemon_and_restarts_on_the_same_session() { + assert_tui_update_case("idle"); + } + + #[test] + fn update_now_refuses_a_busy_daemon_and_prints_manual_command() { + assert_tui_update_case("busy"); + } + + #[test] + fn update_now_falls_back_to_manual_command_for_an_old_daemon() { + assert_tui_update_case("old"); + } + + #[test] + fn update_now_cancels_cleanly_on_sigint_while_stopping_daemon() { + assert_tui_update_case("cancelled"); + } + /// With the real App Server, the interface's own leave ends its UI leaf /// while the input history is still being written. A history lock held /// by another process keeps that write waiting well past the exit budget: /// `Update now` still installs and starts the new version once, after the /// write lands, or, when the lock is never released, after a bounded wait /// that says the entry may not be saved. - #[cfg(any(target_os = "macos", target_os = "linux"))] - #[test] - fn update_now_survives_a_history_write_that_waits_for_its_lock() { - if !option_env!("DIM_RELEASE_BUILD").is_some_and(|mark| !mark.is_empty()) { + fn assert_history_lock_update(released: bool) { + let Some(platform) = target_platform() else { return; - } - let platform = match (std::env::consts::OS, std::env::consts::ARCH) { - ("macos", "aarch64") => "darwin-arm64", - ("macos", "x86_64") => "darwin-x64", - ("linux", "aarch64") => "linux-arm64", - ("linux", "x86_64") => "linux-x64", - _ => return, }; - for released in [true, false] { - let version = next_version(); - let installed = Installed::new(CURRENT, &["dima"]); - installed.mock_npm(); - installed.release(); - let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); - let registry = format!("http://{}", listener.local_addr().unwrap()); - let reply = json!({ "alpha": version }).to_string(); - thread::spawn(move || { - for stream in listener.incoming() { - let mut stream = stream.unwrap(); - let mut request = String::new(); - BufReader::new(&stream).read_line(&mut request).unwrap(); - let _ = write!( - stream, - "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", - reply.len() - ); - } - }); - let home = Home::new(); - let config = home.0.join("model.json"); - fs::write( - &config, - include_str!("../../../dim-agent-aimux/examples/offline.json"), - ) + let version = next_version(); + let installed = Installed::new(CURRENT, &["dima"]); + installed.mock_npm(); + installed.release(); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let registry = format!("http://{}", listener.local_addr().unwrap()); + let reply = json!({ "alpha": version }).to_string(); + thread::spawn(move || { + for stream in listener.incoming() { + let mut stream = stream.unwrap(); + let mut request = String::new(); + BufReader::new(&stream).read_line(&mut request).unwrap(); + let _ = write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", + reply.len() + ); + } + }); + let home = Home::new(); + let config = home.0.join("model.json"); + fs::write( + &config, + include_str!("../../../dim-agent-aimux/examples/offline.json"), + ) + .unwrap(); + let history_lock = fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(false) + .open(home.0.join("input-history.json.lock")) .unwrap(); - let history_lock = fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(home.0.join("input-history.json.lock")) - .unwrap(); - history_lock.lock().unwrap(); - let launcher = format!( - r#"#!/bin/sh + history_lock.lock().unwrap(); + let launcher = format!( + r#"#!/bin/sh if [ "$1" = "--version" ]; then printf 'dimcode {version}\n'; exit 0; fi printf '%s\n' "$@" >> "$UPDATE_RESTART" printf 'Updated launcher started\n' "# - ); - let marker = home.0.join("restart"); - let mut command = Command::new(&installed.updater); - command - .args(["--home", home.0.to_str().unwrap(), "--model-config"]) - .arg(&config) - .arg("tui") - .env_remove("DIMCODE_DISABLE_AUTOUPDATE") - .env_remove("DIMCODE_AUTOUPDATE") - .env_remove("DIMCODE_UPDATE_CHECK") - .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") - .env("DIMCODE_NPM_REGISTRY", ®istry) - .env("NO_PROXY", "127.0.0.1") - .env("UPDATE_RESTART", &marker) - .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) - .env("UPDATE_VERSION", &version) - .env("UPDATE_ARGS", installed.home.0.join("install-args")) - .env("UPDATE_GATE", installed.home.0.join("gate")) - .env("UPDATE_WAITING", installed.home.0.join("waiting")) - .env( - "UPDATE_PACKAGE_JSON", - package_json(&version, &[("dima", "bin/dimcode.mjs")]), - ) - .env("UPDATE_BINS", "dima=bin/dimcode.mjs") - .env("UPDATE_COMMAND", &launcher); - sized(&mut command, 100, 30); - let mut terminal = Terminal::launch_tui(command); - terminal.until_plain("Update now"); - terminal.write(b"\t\t\r"); - terminal.until_plain("Ask anything"); - terminal.write(b"hello"); - terminal.until_plain("hello"); - terminal.write(b"\r"); - terminal.until_plain("Retrying"); - terminal.write(b"\x1b"); - terminal.until_plain("stopped"); - terminal.write(b"/update\r"); - terminal.until_plain("Update now"); - terminal.write(b"\r"); - terminal.until_plain("Updated dimcode-alpha on the alpha channel."); - thread::sleep(Duration::from_secs(2)); - assert!( - !marker.exists(), - "the new version must not start before the history write lands" - ); - if released { - drop(history_lock); - } - let status = terminal.wait(); - let history = fs::read_to_string(home.0.join("input-history.json")).unwrap_or_default(); - let output = strip_ansi(&terminal.transcript); - let unsaved = "Input history is still waiting for its lock"; - if released { - assert!(history.contains("\"hello\""), "{history}"); - assert!(!output.contains(unsaved), "{output}"); - } else { - assert!(!history.contains("\"hello\""), "{history}"); - assert!(output.contains(unsaved), "{output}"); - } - assert!(status.success(), "{output}"); - assert_eq!( - output.matches("Updated launcher started").count(), - 1, - "{output}" - ); - assert_eq!(installed.installed(), version); - let restarted = fs::read_to_string(&marker).unwrap(); - assert!(restarted.contains("--resume\n"), "{restarted}"); + ); + let marker = home.0.join("restart"); + let mut command = Command::new(&installed.updater); + command + .args(["--home", home.0.to_str().unwrap(), "--model-config"]) + .arg(&config) + .arg("tui") + .env_remove("DIMCODE_DISABLE_AUTOUPDATE") + .env_remove("DIMCODE_AUTOUPDATE") + .env_remove("DIMCODE_UPDATE_CHECK") + .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") + .env("DIMCODE_NPM_REGISTRY", ®istry) + .env("NO_PROXY", "127.0.0.1") + .env("UPDATE_RESTART", &marker) + .env("UPDATE_PLATFORM_PACKAGE", format!("dimcode-{platform}")) + .env("UPDATE_VERSION", &version) + .env("UPDATE_ARGS", installed.home.0.join("install-args")) + .env("UPDATE_GATE", installed.home.0.join("gate")) + .env("UPDATE_WAITING", installed.home.0.join("waiting")) + .env( + "UPDATE_PACKAGE_JSON", + package_json(&version, &[("dima", "bin/dimcode.mjs")]), + ) + .env("UPDATE_BINS", "dima=bin/dimcode.mjs") + .env("UPDATE_COMMAND", &launcher); + sized(&mut command, 100, 30); + let mut terminal = Terminal::launch_tui(command); + terminal.until_plain("Update now"); + terminal.write(b"\t\t\r"); + terminal.until_plain("Ask anything"); + terminal.write(b"hello"); + terminal.until_plain("hello"); + terminal.write(b"\r"); + terminal.until_plain("Retrying"); + terminal.write(b"\x1b"); + terminal.until_plain("stopped"); + terminal.write(b"/update\r"); + terminal.until_plain("Update now"); + terminal.write(b"\r"); + terminal.until_plain("Updated dimcode-alpha on the alpha channel."); + thread::sleep(Duration::from_secs(2)); + assert!( + !marker.exists(), + "the new version must not start before the history write lands" + ); + if released { + drop(history_lock); } + let status = terminal.wait(); + let history = fs::read_to_string(home.0.join("input-history.json")).unwrap_or_default(); + let output = strip_ansi(&terminal.transcript); + let unsaved = "Input history is still waiting for its lock"; + if released { + assert!(history.contains("\"hello\""), "{history}"); + assert!(!output.contains(unsaved), "{output}"); + } else { + assert!(!history.contains("\"hello\""), "{history}"); + assert!(output.contains(unsaved), "{output}"); + } + assert!(status.success(), "{output}"); + assert_eq!( + output.matches("Updated launcher started").count(), + 1, + "{output}" + ); + assert_eq!(installed.installed(), version); + let restarted = fs::read_to_string(&marker).unwrap(); + assert!(restarted.contains("--resume\n"), "{restarted}"); + } + + #[test] + fn update_now_waits_for_a_released_history_lock_before_restarting() { + assert_history_lock_update(true); + } + + #[test] + fn update_now_restarts_after_a_bounded_wait_when_history_lock_stays_held() { + assert_history_lock_update(false); } } From 6b0c4d42a9b90270f0bfd9357cf992f12dc8fec7 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 18:31:14 +0800 Subject: [PATCH 2/4] docs(ci): update tui-e2e inventory and address PR #1949 review notes - Update `docs/architecture/tui-e2e.md` with the six split `staged_update::tui_update::update_now_*` names, updated case counts (305 TUI / 287 `cli_flow` + 4 `ui_leaf` = 291; 417 non-TUI / 405 default), and removal of the obsolete release-stamped CI step bullet. - Clarify `dim_agent_capabilities::build::release()` doc comment to mention the debug-only `DIM_TEST_RELEASE_BUILD` override. - Install `RELEASE` in standalone `crates/dim-app-server/src/main.rs` so release-stamped standalone `dim-app-server` builds retain their release identity without recompiling `dim-app-server`'s library or upstream crates. Refs #1932 --- crates/dim-agent-capabilities/src/build.rs | 4 ++- crates/dim-app-server/src/main.rs | 3 +++ docs/architecture/tui-e2e.md | 31 +++++++++++----------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/crates/dim-agent-capabilities/src/build.rs b/crates/dim-agent-capabilities/src/build.rs index b801522e37..00653fa64a 100644 --- a/crates/dim-agent-capabilities/src/build.rs +++ b/crates/dim-agent-capabilities/src/build.rs @@ -63,7 +63,9 @@ fn release_flag(release: bool) -> bool { release } -/// Whether the release flow produced this build. +/// Whether this process behaves as a released build: the compiled release mark +/// installed by the binary crate, or in debug builds the `DIM_TEST_RELEASE_BUILD` +/// override read during [`install`]. A release build ignores the override. pub fn release() -> bool { RELEASE.get().copied().unwrap_or(false) } diff --git a/crates/dim-app-server/src/main.rs b/crates/dim-app-server/src/main.rs index 70ff8b7dc2..a03d30bd9f 100644 --- a/crates/dim-app-server/src/main.rs +++ b/crates/dim-app-server/src/main.rs @@ -1,4 +1,7 @@ +const RELEASE: bool = matches!(option_env!("DIM_RELEASE_BUILD"), Some(value) if !value.is_empty()); + fn main() { + dim_agent_capabilities::build::install(None, None, RELEASE); #[cfg(target_os = "linux")] unsafe { unsafe extern "C" { diff --git a/docs/architecture/tui-e2e.md b/docs/architecture/tui-e2e.md index 830d1eca49..ff2ed5fbfe 100644 --- a/docs/architecture/tui-e2e.md +++ b/docs/architecture/tui-e2e.md @@ -223,13 +223,13 @@ does the resumed `resumed session · N messages` count a follow-up is skipped by ## Existing terminal E2E cases -`crates/dimcode/tests/cli_flow*.rs` holds 299 cases that drive the TUI (or the +`crates/dimcode/tests/cli_flow*.rs` holds 305 cases that drive the TUI (or the launcher that passes through to it) through a PTY, spread over 26 modules; the inventory below lists each one with the disposition #1802 gave it. #1805 is merged, so the five cases it merged are gone and its no-session survivor is in -their place. Of those 299, 10 are now `#[ignore]`d with the reason "TUI E2E runs +their place. Of those 305, 10 are now `#[ignore]`d with the reason "TUI E2E runs in the local tmux suite" because a tmux scenario proves their behavior; 8 were -already ignored for production (4 of them now have a scenario); the other 281 +already ignored for production (4 of them now have a scenario); the other 287 stay selected by CI until #1810 replaces them. `tests/ui_leaf.rs` adds 4 UI leaf cases, all still selected by CI. @@ -314,9 +314,9 @@ States (the #1802 disposition, not the current routing): - unreviewed (#1802), CI — `skill_discovery_reports_failures_and_a_failed_reload_keeps_the_palette`, `tui_skills_panel_reads_again_after_a_failed_read`, `tui_skills_panel_lists_toggles_and_reloads`, `tui_skills_panel_reloads_an_empty_catalog`, `tui_skills_panel_says_when_the_daemon_cannot_manage_them` -**`staged_update`** — 2 cases +**`staged_update`** — 6 cases -- unreviewed (#1802), CI (release-stamped step) — `tui_update::update_now_stops_an_idle_daemon_and_restarts_or_refuses_a_busy_or_old_one`, `tui_update::update_now_survives_a_history_write_that_waits_for_its_lock` +- unreviewed (#1802), CI — `tui_update::update_now_stops_an_idle_daemon_and_restarts_on_the_same_session`, `tui_update::update_now_refuses_a_busy_daemon_and_prints_manual_command`, `tui_update::update_now_falls_back_to_manual_command_for_an_old_daemon`, `tui_update::update_now_cancels_cleanly_on_sigint_while_stopping_daemon`, `tui_update::update_now_waits_for_a_released_history_lock_before_restarting`, `tui_update::update_now_restarts_after_a_bounded_wait_when_history_lock_stays_held` The interrupted-check case is line mode and stays in CI with the other `update` flows. @@ -367,16 +367,16 @@ flows. - rewrite (#1802), CI — `tui_queue_shows_held_messages_and_steers_or_withdraws_them` - unreviewed (#1802), CI — `explicit_model_selection_uses_protocol_field_names_from_tui_and_line_client`, `fullscreen_session_attached_before_the_first_frame_shows_one_banner`, `the_model_label_shows_the_adopted_reasoning_effort_in_both_modes`, `a_new_session_shows_the_effort_its_creation_adopted`, `the_model_label_shows_a_configured_profile_effort` (ignored, production), `home_after_new_drops_the_previous_sessions_effort`, `repicking_the_current_model_keeps_the_effort`, `a_resumed_session_draws_the_adopted_model_and_effort`, `another_clients_adoption_redraws_the_model_label`, `a_narrow_composer_drops_the_effort_before_the_model`, `tui_escape_sends_the_reason_that_records_the_interruption`, `tui_shell_mode_runs_through_session_methods_and_shows_the_recorded_run`, `tui_effort_dialog_selects_the_current_models_effort_and_cancels_without_writing`, `tui_mcp_and_configuration_commands_use_session_methods`, `tui_pasted_images_and_long_text_submit_as_user_content`, `tui_skill_rows_come_from_the_catalog_and_complete_without_sending`, `reloading_skills_changes_the_palette_rows`, `a_daemon_without_skill_catalog_keeps_a_working_command_palette`, `tui_palette_tab_only_completes_and_enter_still_runs`, `tui_sends_dropped_files_as_links_and_images_by_model_capability`, `fullscreen_login_releases_mouse_for_the_link_and_restores_the_preference_on_close`, `tui_mcp_says_when_no_server_is_configured`, `tui_mcp_shows_failure_reasons_rejections_and_the_catalog_error`, `tui_mcp_enables_and_disables_a_project_server`, `tui_web_toggles_the_daemon_switch_without_leaving`, `tui_registers_with_the_ui_registry_and_leaves_when_asked`, `tui_export_dialog_matches_the_subcommand_and_cancel_sends_nothing`, `tui_ctrl_enter_interrupts_the_run_and_starts_a_new_one_with_the_draft`, `tui_ctrl_s_steers_the_draft_while_a_run_is_in_progress`, `tui_escape_withdraws_the_queue_before_the_run_stops`, `tui_command_output_refreshes_one_read_and_preserves_its_branch_and_terminal_result`, `tui_command_output_errors_stop_refresh_and_reopening_retries`, `tui_permissions_keep_pending_file_and_member_questions_and_save_command_rules`, `tui_approval_alias_selects_presets_and_remembers_them`, `tui_shift_tab_cycles_permissions_and_preserves_the_draft_in_both_modes`, `tui_yields_the_title_and_the_bar_to_a_terminal_that_keeps_the_record`, `cold_hosted_tui_opens_without_reading_the_session_catalog`, `resume_by_id_takes_its_model_from_the_attach_record`, `resume_by_id_finds_the_model_in_the_catalog_when_the_attach_reply_is_empty`, `tui_provider_create_recovery_preserves_changed_draft_until_confirmation`, `tui_models_picker_edits_only_the_subagent_model_policy`, `tui_models_picker_cycles_reasoning_effort`, `tui_models_picker_writes_the_default_the_launch_workspace_reads`, `member_tool_approval_requires_trusted_details_in_both_terminal_modes`, `member_approval_without_the_detail_method_offers_only_rejection`, `tui_default_theme_respects_background_and_saved_choice` -Modules: 26; cases: 301; already ignored before this PR: 8 (4 now covered by a +Modules: 26; cases: 305; already ignored before this PR: 8 (4 now covered by a tmux scenario: `unix_npm_wrapper_…`, `tui_provider_management_…`, `native_tui_question_answer_…`, `tasks::native_tui_stop_all_…`); newly ignored for the tmux suite: 10; moved to the tmux suite: 14; still ignored with no scenario: `a_cold_ui_leaf_…`, `a_resumed_session_of_an_older_protocol_opens`, `managed_worktree_tui_…`, `the_model_label_shows_a_configured_profile_effort`; -selected by CI: 283 in `cli_flow` plus the 4 `ui_leaf` cases (287). +selected by CI: 287 in `cli_flow` plus the 4 `ui_leaf` cases (291). The `cli_flow` target also holds the line-mode, ACP, daemon and production flows -that CI keeps: 412 cases, of which 400 run by default and 12 are `--ignored` +that CI keeps: 417 cases, of which 405 run by default and 12 are `--ignored` production flows that the CI selection names one by one. The five cases #1805 merged, and the one case #1805 added, are recorded in the dispositions above rather than listed here. @@ -407,7 +407,7 @@ No CI job runs a **migrated** TUI flow. The 10 cases whose behavior a tmux scenario proves are `#[ignore]`d with the reason "TUI E2E runs in the local tmux suite", so the ordinary `cargo test --workspace` selection compiles them and runs none of them; the production `--ignored` step names only the flows CI -keeps. The other 283 `cli_flow` TUI cases and the 4 `ui_leaf` cases have no +keeps. The other 287 `cli_flow` TUI cases and the 4 `ui_leaf` cases have no replacement yet and stay selected by CI, because dropping them would remove runtime coverage that only they assert (#1810). Terminal E2E coverage that has moved is a local verification step: a display-less runner and the suite's @@ -419,17 +419,16 @@ component and protocol tests do not already cover. CI keeps: - Ordinary workspace tests: the `dim-cli` component render and keyboard tests, - `dim-app-server` protocol and transport flows, the 400 non-TUI `cli_flow` - cases (`--no-tui`, `exec`, piped prompts, ACP and the scripted daemon flows), - and the 287 TUI cases #1810 still tracks. + `dim-app-server` protocol and transport flows, the 405 non-TUI `cli_flow` + cases (`--no-tui`, `exec`, piped prompts, ACP, `staged_update::recovery::`, + and the scripted daemon flows), and the 291 TUI cases #1810 still tracks + (including the 6 `staged_update::tui_update::` cases, which use the debug-only + `DIM_TEST_RELEASE_BUILD=1` override instead of a separate release-stamped + build step). - The explicit `cli_flow` step that names the 12 `--ignored` production and line-mode flows one by one: the production App Server, the account and permission presets, the real-owner MCP/hooks/workflow writes, and the line-mode startup case below. -- The release-stamped step, which runs `staged_update::recovery::` and the TUI - cases `staged_update::tui_update::`: they pass trivially in an unstamped build, - so only that step exercises them. The recovery cases and `local_execution` do - not drive the UI. ### Line-mode routing exception From be92c36dce0e511a60c123b0fc17da3f338f656a Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sat, 21 Nov 2026 09:25:22 +0800 Subject: [PATCH 3/4] fix(update): retry the startup check once A loaded runner can miss the four-second registry deadline, which used to hide the update dialog for the whole session; retry once on the background startup path so a transient miss still offers the update. --- crates/dim-cli/src/update.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/dim-cli/src/update.rs b/crates/dim-cli/src/update.rs index d4da17097e..06476ebe45 100644 --- a/crates/dim-cli/src/update.rs +++ b/crates/dim-cli/src/update.rs @@ -302,11 +302,14 @@ fn upgrade_tag(version: &str, release: bool) -> Option<&str> { } /// A newer version on the channel of `current` the user has not skipped, or -/// `None` when there is none or the registry did not answer in time. +/// `None` when there is none or the registry did not answer. pub async fn available(home: &Path, current: &str) -> Option { let tag = upgrade_tag(current, dim_agent_capabilities::build::release())?; let package = package().ok()?; - let version = channel_version(&package, tag).await.ok()?; + let version = match channel_version(&package, tag).await { + Ok(version) => version, + Err(_) => channel_version(&package, tag).await.ok()?, + }; if !newer(current, &version) || skipped(home).as_deref() == Some(version.as_str()) { return None; } From c1bb5258281b4c7a1565d4b178af03da6d8bc6d5 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sat, 21 Nov 2026 11:18:13 +0800 Subject: [PATCH 4/4] test(update): give the startup check a test-only deadline Replace the one-shot retry with a debug-only DIM_TEST_UPDATE_TIMEOUT_MS override and set it in the update flows, so a loaded runner's scheduling delay cannot hide the offer, and correct the cli_flow counts in the terminal E2E inventory. --- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/update.rs | 19 ++++++++++++++----- .../dimcode/tests/cli_flow/staged_update.rs | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index 54b09e6895..5b7c1d77b2 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1769,7 +1769,7 @@ cargo test --locked -p dimcode --test cli_flow --test cli_tui_flow --test cli_se cargo clippy --locked -p dim-cli --all-targets -- -D warnings ``` -Two debug-only variables shorten the daemon startup waits for the flow tests: `DIM_TEST_DAEMON_START_TIMEOUT_MS` replaces the 10 s bound of the wait before spawning and of the spawn wait and `DIM_TEST_START_LOCK_TIMEOUT_MS` the start-lock wait's derived bound, so a test reaches an inactivity bound without waiting the production time. Two more inject build identity without recompiling: `DIM_TEST_BUILD_ID` replaces this build's artifact stamp (so a flow or a tmux scenario can stand a client and a daemon of different builds beside each other; an empty value means no stamp), and `DIM_TEST_RELEASE_BUILD` overrides the release mark (so flows can test release-gated startup recovery and `Update now` against the already-compiled debug binary; an empty value or `"0"` means a source build). Only a debug build reads them, a release build ignores them, and the tests that set them compile only in debug builds. +Two debug-only variables shorten the daemon startup waits for the flow tests: `DIM_TEST_DAEMON_START_TIMEOUT_MS` replaces the 10 s bound of the wait before spawning and of the spawn wait and `DIM_TEST_START_LOCK_TIMEOUT_MS` the start-lock wait's derived bound, so a test reaches an inactivity bound without waiting the production time. Two more inject build identity without recompiling: `DIM_TEST_BUILD_ID` replaces this build's artifact stamp (so a flow or a tmux scenario can stand a client and a daemon of different builds beside each other; an empty value means no stamp), and `DIM_TEST_RELEASE_BUILD` overrides the release mark (so flows can test release-gated startup recovery and `Update now` against the already-compiled debug binary; an empty value or `"0"` means a source build). `DIM_TEST_UPDATE_TIMEOUT_MS` replaces the update check's 4 s registry deadline, so a flow on a loaded runner still sees the offer. Only a debug build reads them, a release build ignores them, and the tests that set them compile only in debug builds. The production-model flow uses the actual App Server, an API-key environment reference and a local OpenAI-compatible HTTP stream fixture. It checks the production tool list, a real file read reaching the model, and continued input on the same persisted session: diff --git a/crates/dim-cli/src/update.rs b/crates/dim-cli/src/update.rs index 06476ebe45..6a77b8cc5c 100644 --- a/crates/dim-cli/src/update.rs +++ b/crates/dim-cli/src/update.rs @@ -20,6 +20,18 @@ const ALPHA_PACKAGE: &str = "dimcode-alpha"; const ALPHA_COMMAND: &str = "dima"; const REGISTRY: &str = "https://registry.npmjs.org"; const TIMEOUT: Duration = Duration::from_secs(4); + +/// The registry deadline; a debug build takes `DIM_TEST_UPDATE_TIMEOUT_MS` so +/// a flow can keep it past a loaded runner's scheduling delay. +fn timeout() -> Duration { + #[cfg(debug_assertions)] + if let Some(millis) = std::env::var_os("DIM_TEST_UPDATE_TIMEOUT_MS") + .and_then(|value| value.to_str().and_then(|value| value.parse().ok())) + { + return Duration::from_millis(millis); + } + TIMEOUT +} /// The version the user chose to skip, shared with the TypeScript CLI. const SKIP_FILE: &str = "upgrade-skip.json"; @@ -306,10 +318,7 @@ fn upgrade_tag(version: &str, release: bool) -> Option<&str> { pub async fn available(home: &Path, current: &str) -> Option { let tag = upgrade_tag(current, dim_agent_capabilities::build::release())?; let package = package().ok()?; - let version = match channel_version(&package, tag).await { - Ok(version) => version, - Err(_) => channel_version(&package, tag).await.ok()?, - }; + let version = channel_version(&package, tag).await.ok()?; if !newer(current, &version) || skipped(home).as_deref() == Some(version.as_str()) { return None; } @@ -350,7 +359,7 @@ pub async fn check(current: &str) -> Result, String> { } async fn channel_version(package: &str, tag: &str) -> crate::Result { - let client = reqwest::Client::builder().timeout(TIMEOUT).build()?; + let client = reqwest::Client::builder().timeout(timeout()).build()?; let tags: serde_json::Value = client .get(format!("{}/-/package/{package}/dist-tags", registry())) .send() diff --git a/crates/dimcode/tests/cli_flow/staged_update.rs b/crates/dimcode/tests/cli_flow/staged_update.rs index acbae9ff20..b5d07152ff 100644 --- a/crates/dimcode/tests/cli_flow/staged_update.rs +++ b/crates/dimcode/tests/cli_flow/staged_update.rs @@ -943,6 +943,7 @@ mod recovery { .env_remove("DIMCODE_UPDATE_CHECK") .env_remove("DIMCODE_STARTUP_RETRY") .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIM_TEST_UPDATE_TIMEOUT_MS", "60000") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", registry) .env("NO_PROXY", "127.0.0.1") @@ -1087,6 +1088,7 @@ mod recovery { .env_remove("DIMCODE_UPDATE_CHECK") .env_remove("DIMCODE_STARTUP_RETRY") .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIM_TEST_UPDATE_TIMEOUT_MS", "60000") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", "http://127.0.0.1:1") .env("UPDATE_ARGS", installed.home.0.join("install-args")) @@ -1175,6 +1177,7 @@ mod recovery { .env_remove("DIMCODE_UPDATE_CHECK") .env_remove("DIMCODE_STARTUP_RETRY") .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIM_TEST_UPDATE_TIMEOUT_MS", "60000") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", registry) .env("NO_PROXY", "127.0.0.1") @@ -1342,6 +1345,7 @@ printf 'Updated launcher started\n' .env_remove("DIMCODE_AUTOUPDATE") .env_remove("DIMCODE_UPDATE_CHECK") .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIM_TEST_UPDATE_TIMEOUT_MS", "60000") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", ®istry) .env("NO_PROXY", "127.0.0.1") @@ -1494,6 +1498,7 @@ printf 'Updated launcher started\n' .env_remove("DIMCODE_AUTOUPDATE") .env_remove("DIMCODE_UPDATE_CHECK") .env("DIM_TEST_RELEASE_BUILD", "1") + .env("DIM_TEST_UPDATE_TIMEOUT_MS", "60000") .env("DIMCODE_NPM_PACKAGE", "dimcode-alpha") .env("DIMCODE_NPM_REGISTRY", ®istry) .env("NO_PROXY", "127.0.0.1")