Skip to content

Commit dcbb3ff

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(nest): use buzz-dev symlink name for dev builds (#1587)
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 49391d8 commit dcbb3ff

3 files changed

Lines changed: 85 additions & 14 deletions

File tree

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ const overrides = new Map([
8282
// to split with the rest of this list.
8383
// dev-nest namespace: OnceLock<Option<PathBuf>> + init_nest_dir + constants
8484
// added to plumb the dev/prod discriminator. Load-bearing for the D2 nest fix.
85-
["src-tauri/src/managed_agents/nest.rs", 1501],
85+
// dev-build CLI symlink: cli_link_name helper + is_dev param on
86+
// ensure_cli_symlink + prod/dev test variants add ~68 lines. Load-bearing;
87+
// queued to split with the rest of this list.
88+
["src-tauri/src/managed_agents/nest.rs", 1569],
8689
// harness-persona-sync: persona-runtime resolution threaded into the spawn
8790
// path here. Load-bearing feature growth; queued to split in the resolver
8891
// unify refactor followup. +26 for resolve_effective_prompt_model_provider

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn run() {
323323
// bundled CLI binary. Non-fatal: agents find CLI via PATH.
324324
if let Ok(exe) = std::env::current_exe() {
325325
if let Some(parent) = exe.parent() {
326-
if let Err(error) = managed_agents::ensure_cli_symlink(parent) {
326+
if let Err(error) = managed_agents::ensure_cli_symlink(parent, is_dev_nest) {
327327
eprintln!("buzz-desktop: failed to create CLI symlink: {error}");
328328
}
329329
}

‎desktop/src-tauri/src/managed_agents/nest.rs‎

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,35 @@ fn ensure_skill_symlinks(_root: &Path) -> Result<(), String> {
306306
Ok(())
307307
}
308308

309-
/// Ensures `~/.local/bin/buzz` is a symlink to the bundled CLI binary.
309+
/// Returns the `~/.local/bin` link name for the bundled CLI.
310310
///
311-
/// On every boot: replaces any existing symlink unconditionally (the `buzz`
312-
/// name is our namespace), creates a new one if absent, and leaves regular
313-
/// files alone to avoid clobbering a user-compiled binary.
311+
/// Dev builds (`is_dev = true`) use `"buzz-dev"` so that a running DMG and a
312+
/// concurrent dev build each own a separate link and never clobber each other —
313+
/// the same isolation that separates `~/.buzz` (prod) from `~/.buzz-dev` (dev).
314+
pub fn cli_link_name(is_dev: bool) -> &'static str {
315+
if is_dev {
316+
"buzz-dev"
317+
} else {
318+
"buzz"
319+
}
320+
}
321+
322+
/// Ensures `~/.local/bin/buzz` (prod) or `~/.local/bin/buzz-dev` (dev) is a
323+
/// symlink to the bundled CLI binary.
324+
///
325+
/// The link name is split by `is_dev` so that an installed DMG and a
326+
/// concurrently running dev build each maintain their own symlink and never
327+
/// overwrite each other's target — the same isolation that separates the
328+
/// `~/.buzz` and `~/.buzz-dev` nests (see [`NEST_DIR_DEV`]).
329+
///
330+
/// On every boot: replaces any existing symlink unconditionally (the `buzz` /
331+
/// `buzz-dev` name is our namespace), creates a new one if absent, and leaves
332+
/// regular files alone to avoid clobbering a user-compiled binary.
314333
///
315334
/// Non-fatal: callers should ignore errors — the symlink is a convenience
316335
/// for human Terminal use; agents find the CLI via PATH augmentation.
317336
#[cfg(unix)]
318-
pub fn ensure_cli_symlink(exe_parent: &Path) -> Result<(), String> {
337+
pub fn ensure_cli_symlink(exe_parent: &Path, is_dev: bool) -> Result<(), String> {
319338
let buzz_bin = exe_parent.join("buzz");
320339
if !buzz_bin.exists() {
321340
return Ok(()); // CLI not bundled (e.g., dev builds without sidecars).
@@ -327,7 +346,7 @@ pub fn ensure_cli_symlink(exe_parent: &Path) -> Result<(), String> {
327346
.join("bin");
328347
fs::create_dir_all(&local_bin).map_err(|e| format!("create {}: {e}", local_bin.display()))?;
329348

330-
let link = local_bin.join("buzz");
349+
let link = local_bin.join(cli_link_name(is_dev));
331350
match link.symlink_metadata() {
332351
Ok(meta) if meta.file_type().is_symlink() => {
333352
let _ = fs::remove_file(&link);
@@ -351,7 +370,7 @@ pub fn ensure_cli_symlink(exe_parent: &Path) -> Result<(), String> {
351370

352371
/// No-op on non-Unix platforms — symlink management is macOS/Linux only.
353372
#[cfg(not(unix))]
354-
pub fn ensure_cli_symlink(_exe_parent: &Path) -> Result<(), String> {
373+
pub fn ensure_cli_symlink(_exe_parent: &Path, _is_dev: bool) -> Result<(), String> {
355374
Ok(())
356375
}
357376

@@ -983,38 +1002,87 @@ mod tests {
9831002
);
9841003
}
9851004

1005+
#[test]
1006+
fn cli_link_name_prod_is_buzz() {
1007+
assert_eq!(cli_link_name(false), "buzz");
1008+
}
1009+
1010+
#[test]
1011+
fn cli_link_name_dev_is_buzz_dev() {
1012+
assert_eq!(cli_link_name(true), "buzz-dev");
1013+
}
1014+
9861015
#[cfg(unix)]
9871016
#[test]
988-
fn ensure_cli_symlink_creates_symlink() {
1017+
fn ensure_cli_symlink_creates_symlink_prod() {
9891018
let tmp = tempfile::tempdir().unwrap();
9901019
let exe_parent = tmp.path().join("MacOS");
9911020
fs::create_dir(&exe_parent).unwrap();
9921021
fs::write(exe_parent.join("buzz"), "binary").unwrap();
9931022

994-
// Simulate the symlink creation path.
9951023
let local_bin = tmp.path().join("local_bin");
9961024
fs::create_dir_all(&local_bin).unwrap();
997-
let link = local_bin.join("buzz");
9981025

1026+
// Prod link name is "buzz"; simulate the symlink creation path.
1027+
let link = local_bin.join(cli_link_name(false));
9991028
std::os::unix::fs::symlink(exe_parent.join("buzz"), &link).unwrap();
10001029
assert!(link.symlink_metadata().unwrap().file_type().is_symlink());
10011030
assert_eq!(fs::read_link(&link).unwrap(), exe_parent.join("buzz"));
10021031
}
10031032

10041033
#[cfg(unix)]
10051034
#[test]
1006-
fn ensure_cli_symlink_does_not_clobber_regular_file() {
1035+
fn ensure_cli_symlink_creates_symlink_dev() {
10071036
let tmp = tempfile::tempdir().unwrap();
1037+
let exe_parent = tmp.path().join("MacOS");
1038+
fs::create_dir(&exe_parent).unwrap();
1039+
fs::write(exe_parent.join("buzz"), "binary").unwrap();
1040+
10081041
let local_bin = tmp.path().join("local_bin");
10091042
fs::create_dir_all(&local_bin).unwrap();
1010-
let link = local_bin.join("buzz");
1043+
1044+
// Dev link must be "buzz-dev", never "buzz".
1045+
assert_eq!(cli_link_name(true), "buzz-dev");
1046+
1047+
let link = local_bin.join(cli_link_name(true));
1048+
std::os::unix::fs::symlink(exe_parent.join("buzz"), &link).unwrap();
1049+
assert!(link.symlink_metadata().unwrap().file_type().is_symlink());
1050+
assert_eq!(fs::read_link(&link).unwrap(), exe_parent.join("buzz"));
1051+
// Prod link must not exist — the two builds don't touch each other.
1052+
assert!(!local_bin.join("buzz").exists());
1053+
}
1054+
1055+
#[cfg(unix)]
1056+
#[test]
1057+
fn ensure_cli_symlink_does_not_clobber_regular_file_prod() {
1058+
let tmp = tempfile::tempdir().unwrap();
1059+
let local_bin = tmp.path().join("local_bin");
1060+
fs::create_dir_all(&local_bin).unwrap();
1061+
let link = local_bin.join(cli_link_name(false));
10111062
fs::write(&link, "user-installed binary").unwrap();
10121063

10131064
// Regular files are preserved — the Ok(_) branch skips them.
10141065
assert!(link.symlink_metadata().unwrap().file_type().is_file());
10151066
assert_eq!(fs::read_to_string(&link).unwrap(), "user-installed binary");
10161067
}
10171068

1069+
#[cfg(unix)]
1070+
#[test]
1071+
fn ensure_cli_symlink_does_not_clobber_regular_file_dev() {
1072+
let tmp = tempfile::tempdir().unwrap();
1073+
let local_bin = tmp.path().join("local_bin");
1074+
fs::create_dir_all(&local_bin).unwrap();
1075+
let link = local_bin.join(cli_link_name(true));
1076+
fs::write(&link, "user-installed buzz-dev binary").unwrap();
1077+
1078+
// Regular files at the dev path are also preserved.
1079+
assert!(link.symlink_metadata().unwrap().file_type().is_file());
1080+
assert_eq!(
1081+
fs::read_to_string(&link).unwrap(),
1082+
"user-installed buzz-dev binary"
1083+
);
1084+
}
1085+
10181086
fn make_persona(id: &str, display_name: &str) -> PersonaRecord {
10191087
PersonaRecord {
10201088
id: id.to_string(),

0 commit comments

Comments
 (0)