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
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 34 additions & 25 deletions crates/dim-agent-capabilities/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -29,15 +19,20 @@ static COMMIT: OnceLock<Option<&'static str>> = OnceLock::new();
/// than the source; `None` when the build left none.
static BUILD_ID: OnceLock<Option<String>> = 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<bool> = 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`
Expand All @@ -54,6 +49,27 @@ fn stamp(build_id: Option<&'static str>) -> Option<String> {
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 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)
}

/// 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> {
Expand All @@ -72,7 +88,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)]
Expand All @@ -97,11 +113,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));
}
}
3 changes: 3 additions & 0 deletions crates/dim-app-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-app-server/tests/mcp_http_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,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")),
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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). `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:

Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn default_plugins(executable: &Path) -> Option<PathBuf> {
/// `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()
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ async fn act(root: &rutis::Ctx, mut options: Options) -> Result<i32> {
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();
Expand Down
22 changes: 17 additions & 5 deletions crates/dim-cli/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -302,9 +314,9 @@ 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<Offer> {
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()) {
Expand Down Expand Up @@ -333,7 +345,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<Option<Offer>, 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)
Expand All @@ -347,7 +359,7 @@ pub async fn check(current: &str) -> Result<Option<Offer>, String> {
}

async fn channel_version(package: &str, tag: &str) -> crate::Result<String> {
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()
Expand Down Expand Up @@ -375,7 +387,7 @@ pub(crate) async fn recover_startup(
) -> crate::Result<i32> {
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()
Expand Down
9 changes: 7 additions & 2 deletions crates/dimcode/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
7 changes: 6 additions & 1 deletion crates/dimcode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
51 changes: 51 additions & 0 deletions crates/dimcode/tests/cli_flow/daemon_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
);
}
}
}
Loading