From 93eb11619b42dbf08ce290e3446bf84e179f6e96 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 31 Jul 2026 03:18:41 +0000 Subject: [PATCH] fix: supply the ninth format argument in build_guest_script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This crate does not compile on main: error: 9 positional arguments in format string, but there are 8 arguments --> src/script.rs:72:19 The guest script's format string has nine placeholders; the argument list supplied eight. The missing one is the third bootstrap_path, at the fallback warning "bootstrap flake not found at {}". The mapping is determined by the surrounding text, not guessed. The else branch reads: report that the local flake was missing, then retry via GitHub. So the warning takes the PATH and the `nix develop` that follows takes the URL — which is exactly where the argument list skipped from bootstrap_path straight to bootstrap_github. Also adds the tests that would have caught it. Nothing exercised build_guest_script at all — it is called only from lima.rs at runtime — which is why an outright compile error survived on main. The second test earns its place: an arity mismatch is caught by the compiler, but SWAPPING the path and URL arguments still compiles and produces a script that names the GitHub URL in the "not found at" message and then runs the local path as a flake reference. Verified the test has teeth by making that swap and watching it fail, then reverting. cargo build: clean cargo test: 18 passed, 0 failed (16 pre-existing + 2 new) Unrelated to the dependency work in the merged osv-scan PR, though that is how it surfaced: the broken build made it impossible to confirm the git2 0.21 bump compiled, so the advisory fix went in with weaker evidence than it should have. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LF9Cu8u4dkCEM8MXC1QeDL --- src/script.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/script.rs b/src/script.rs index bc3b194..72f5c69 100644 --- a/src/script.rs +++ b/src/script.rs @@ -126,6 +126,61 @@ fi GUEST_WORKTREE_ROOT, bootstrap_path, bootstrap_path, + bootstrap_path, bootstrap_github ) } + +#[cfg(test)] +mod tests { + use super::*; + use std::path::PathBuf; + + fn ctx() -> AppContext { + AppContext { + target_dir_host: PathBuf::from("/host/worktrees/demo"), + guest_cwd: "/worktrees/demo".to_string(), + path_segments: vec!["demo".to_string()], + lima_instance: "devshell".to_string(), + bare_repo_path: PathBuf::from("/host/bare.git"), + bare_repo_mount_name: "bare".to_string(), + } + } + + /// The format string carries nine placeholders. Nothing exercised this + /// function, so an arity mismatch sat on main as a hard compile error. + #[test] + fn guest_script_substitutes_every_placeholder() { + let script = build_guest_script(&ctx()); + assert!( + !script.contains("{}"), + "unsubstituted placeholder left in generated script" + ); + assert!(script.contains("TARGET_DIR=\"${1:-/worktrees/demo}\"")); + assert!(script.contains(" /worktrees/*)")); + } + + /// The two branches are not interchangeable: the failure message reports the + /// local flake PATH that was missing, while the command that follows falls + /// back to the GitHub URL. Swapping them still compiles. + #[test] + fn bootstrap_fallback_reports_path_and_runs_github_url() { + let script = build_guest_script(&ctx()); + let github = get_bootstrap_github_url(); + let path = get_bootstrap_flake_path(); + + let warning = script + .lines() + .find(|l| l.contains("bootstrap flake not found at")) + .expect("fallback warning line present"); + assert!( + warning.contains(&path), + "warning should name the flake path, got: {warning}" + ); + + assert!( + script.contains(&format!("nix develop {github} --command")), + "fallback should invoke the GitHub URL" + ); + } +}