From 288519474f2d77a3e605130c205249c403aff1b9 Mon Sep 17 00:00:00 2001 From: Bradley Hilton Date: Tue, 10 Nov 2026 15:05:51 -0600 Subject: [PATCH] fix: preserve installer command path in upgrade guidance --- README.md | 9 ++++++ atomic-cli/src/commands/update.rs | 48 ++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 190364d4..03dc366e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,15 @@ The old per-repository `atomic agent database-owner` command, its have been removed from the current CLI. Processes started by an older binary can still be running after an upgrade. Stop them using the steps below. +The official installer keeps complete native releases in separate versioned +directories and exposes `atomic` through a command symlink. Its installation +record keeps that command's absolute path in `install_path` and the complete +native release directory in `runtime_dir`. `atomic update` verifies that the +recorded command still resolves to the running executable, then preserves the +original command directory in its upgrade instructions instead of targeting the +immutable release directory. Restart editors to adopt a newly registered runtime; +do not remove an older release while a process still uses its library. + ### Upgrading from legacy database owners (0.19.1 and earlier) Replacing the executable does not stop existing processes. Before upgrading, diff --git a/atomic-cli/src/commands/update.rs b/atomic-cli/src/commands/update.rs index 7470a887..629f6638 100644 --- a/atomic-cli/src/commands/update.rs +++ b/atomic-cli/src/commands/update.rs @@ -181,7 +181,8 @@ fn manifest_path(env: &dyn EnvLookup) -> PathBuf { /// Determine the install source for a binary at `current_exe`. /// /// Manifest is consulted first under the trust gate (canonicalized path -/// must match current_exe). Path heuristics provide the fallback. +/// must match current_exe). Preserve its command path for upgrade guidance, +/// rather than installing into a versioned symlink target. pub fn detect_source(current_exe: &Path, env: &dyn EnvLookup) -> InstallSource { let canonical_exe = std::fs::canonicalize(current_exe).unwrap_or_else(|_| current_exe.to_path_buf()); @@ -193,11 +194,11 @@ pub fn detect_source(current_exe: &Path, env: &dyn EnvLookup) -> InstallSource { if let Ok(raw) = std::fs::read_to_string(&manifest_p) { if let Ok(m) = serde_json::from_str::(&raw) { if m.schema_version == 1 && m.source == "official-installer" { - let recorded = std::fs::canonicalize(&m.install_path).unwrap_or(m.install_path); - if recorded == canonical_exe { + let recorded = std::fs::canonicalize(&m.install_path); + if recorded.as_deref().unwrap_or(&m.install_path) == canonical_exe { return InstallSource::OfficialInstaller { manifest_path: manifest_p, - recorded_install_path: recorded, + recorded_install_path: m.install_path, recorded_version: m.version, }; } @@ -673,6 +674,45 @@ mod tests { } } + #[cfg(unix)] + #[test] + fn detect_source_preserves_command_symlink_for_versioned_install() { + let state = TempDir::new().unwrap(); + let root = TempDir::new().unwrap(); + let command_dir = root.path().join("commands with spaces"); + let release_dir = command_dir.join(".atomic-runtime/v0.21.0-test"); + fs::create_dir_all(&release_dir).unwrap(); + let executable = release_dir.join("atomic"); + let command = command_dir.join("atomic"); + fs::write(&executable, b"executable").unwrap(); + std::os::unix::fs::symlink(&executable, &command).unwrap(); + write_manifest(state.path(), &command, "0.21.0", 1); + let env = MockEnv::new().set("XDG_STATE_HOME", state.path().to_str().unwrap()); + + let source = detect_source(&executable, &env); + let InstallSource::OfficialInstaller { + recorded_install_path, + .. + } = &source + else { + panic!("expected official installer for a matching command symlink"); + }; + assert_eq!(recorded_install_path, &command); + let message = format_upgrade_message(&source, "0.21.0", "0.22.0", None, &env); + let upgrade = message + .lines() + .find(|line| line.trim_start().starts_with("curl ")) + .unwrap(); + assert!(upgrade.contains(&format!("ATOMIC_INSTALL='{}' sh", command_dir.display()))); + assert!(!upgrade.contains(".atomic-runtime")); + + let unrelated = root.path().join("unrelated-atomic"); + fs::write(&unrelated, b"other executable").unwrap(); + fs::remove_file(&command).unwrap(); + std::os::unix::fs::symlink(&unrelated, &command).unwrap(); + assert_eq!(detect_source(&executable, &env), InstallSource::Manual); + } + #[test] fn detect_source_manifest_path_mismatch_falls_through() { let state = TempDir::new().unwrap();