Move daemon packages out of the standalone CLI installation (#45546)

## Why

The daemon shares the standalone CLI package, coupling daemon updates to the visible CLI installation. A dedicated package lets daemon updates preserve the CLI selection and shell profile.

## What changed

- Add dedicated daemon package selection and separate daemon and updater PID files, with diagnostics for the new files.
- Make `codex app-server daemon update` migrate eligible legacy stable latest-channel installations to a dedicated package. Prepare and validate the release and its package-ownership support before switching; preserve settings and whether the daemon was running. Scheduled updates keep legacy installations in place.
- Add daemon-only and deferred-selection modes to the shell and PowerShell installers, leaving the visible CLI installation unchanged.
- Coordinate migration with installer locks, refresh package selection after acquiring lifecycle locks, and reject package changes during update downloads.

## Testing

Add coverage for running and stopped migrations, incompatible installers and releases, package-selection races, daemon-only updates, and a capability probe that does not start an updater. Add a shell installer regression test verifying that daemon installation preserves the visible CLI and shell profile.

GitOrigin-RevId: 1ec0f358f8f6ebde7daddb74e880cc8d2235d647
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-14 23:43:59 +00:00
1 parent 2f1583b411
commit 923c6028b6
17 files changed
+1057 -106

No files matched your search

@@ -5,25 +5,70 @@ fn discovers_package_and_legacy_installs() {
let home = tempfile::TempDir::new().expect("home");
let current = home.path().join("packages/standalone/current");
let legacy = current.join(super::managed_codex_file_name());
let expected = if cfg!(windows) {
current.join("bin").join("codex.exe")
} else {
legacy.clone()
};
assert_eq!(super::managed_codex_bin(home.path()), expected);
assert_eq!(
super::managed_codex_bin(home.path()),
home.path()
.join("packages/app-server-daemon/current/bin")
.join(super::managed_codex_file_name())
);
std::fs::create_dir_all(&current).expect("current directory");
std::fs::write(&legacy, b"legacy").expect("legacy executable");
let state = home.path().join("app-server-daemon");
std::fs::create_dir(&state).unwrap();
for name in ["settings.json", "daemon.lock", "app-server.pid.lock"] {
std::fs::write(state.join(name), b"").unwrap();
}
// A CLI install and a previous stop/status operation do not establish ownership.
assert_eq!(
super::package_root(home.path()),
home.path().join("packages/standalone")
);
std::fs::write(state.join("app-server.stderr.log"), b"").unwrap();
assert_eq!(super::managed_codex_bin(home.path()), legacy);
let packaged = current.join("bin").join(super::managed_codex_file_name());
std::fs::create_dir(current.join("bin")).expect("bin directory");
std::fs::write(&packaged, b"packaged").expect("packaged executable");
assert_eq!(super::managed_codex_bin(home.path()), packaged);
std::fs::remove_dir_all(home.path().join("packages/standalone")).unwrap();
assert_eq!(
super::package_root(home.path()),
home.path().join("packages/standalone")
);
std::fs::remove_file(state.join("app-server.stderr.log")).unwrap();
std::fs::write(state.join("app-server.pid"), b"running daemon").unwrap();
assert_eq!(
super::package_root(home.path()),
home.path().join("packages/standalone")
);
std::fs::write(state.join("daemon.pid"), b"running dedicated daemon").unwrap();
assert_eq!(
super::package_root(home.path()),
home.path().join("packages/app-server-daemon")
);
std::fs::remove_file(state.join("daemon.pid")).unwrap();
std::fs::write(state.join("daemon.stderr.log"), b"").unwrap();
assert_eq!(
super::package_root(home.path()),
home.path().join("packages/app-server-daemon")
);
#[cfg(unix)]
{
let dedicated = home.path().join("packages/app-server-daemon");
std::fs::write(&dedicated, b"not a directory").expect("unreadable selection");
assert_eq!(super::package_root(home.path()), dedicated);
}
}
#[cfg(unix)]
#[test]
fn updater_only_runs_for_stable_installer_owned_releases() {
let home = tempfile::TempDir::new().expect("home");
let state = home.path().join("app-server-daemon");
std::fs::create_dir(&state).unwrap();
std::fs::write(state.join("app-server.stderr.log"), b"").unwrap();
let standalone = home.path().join("packages/standalone");
let current = standalone.join("current");
let release = standalone.join("releases/0.150.0-aarch64-apple-darwin");