@@ -1151,6 +1151,73 @@ fn launch_path_puts_bundled_tools_before_platform_tools() {
11511151 assert_eq ! ( std:: env:: split_paths( path) . collect:: <Vec <_>>( ) , expected) ;
11521152}
11531153
1154+ #[ test]
1155+ #[ cfg( unix) ]
1156+ fn claude_launch_uses_its_node_and_preserves_harness_defaults ( ) {
1157+ let dir = tempfile:: Builder :: new ( )
1158+ . prefix ( "Claude tools " )
1159+ . tempdir ( )
1160+ . unwrap ( ) ;
1161+ let runtime = bundle ( dir. path ( ) ) ;
1162+ let key = Secret :: parse ( KEY , PUB ) . unwrap ( ) ;
1163+ let mut saved = agent ( dir. path ( ) ) ;
1164+ saved. harness . model . clear ( ) ;
1165+ saved. harness . provider . clear ( ) ;
1166+ let bin = dir. path ( ) . join ( "claude-tools/bin" ) ;
1167+ fs:: create_dir_all ( & bin) . unwrap ( ) ;
1168+ let adapter = bin. join ( "claude-agent-acp" ) ;
1169+ let cli = bin. join ( "claude" ) ;
1170+ for path in [ & adapter, & cli] {
1171+ fs:: copy ( dir. path ( ) . join ( "buzz-agent" ) , path) . unwrap ( ) ;
1172+ }
1173+ let node = dir. path ( ) . join ( "runtimes/node/v24.18.0" ) . join (
1174+ match ( std:: env:: consts:: OS , std:: env:: consts:: ARCH ) {
1175+ ( "macos" , "aarch64" ) => "darwin-arm64/bin/node" ,
1176+ ( "macos" , _) => "darwin-x64/bin/node" ,
1177+ ( "linux" , "aarch64" ) => "linux-arm64/bin/node" ,
1178+ _ => "linux-x64/bin/node" ,
1179+ } ,
1180+ ) ;
1181+ fs:: create_dir_all ( node. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
1182+ fs:: copy ( dir. path ( ) . join ( "buzz-agent" ) , & node) . unwrap ( ) ;
1183+ saved. harness . command = adapter. to_string_lossy ( ) . into_owned ( ) ;
1184+ let command = runtime
1185+ . command_with_defaults ( & saved, & key, & deployment_defaults ( ) )
1186+ . unwrap ( ) ;
1187+ let environment: BTreeMap < _ , _ > = command. get_envs ( ) . collect ( ) ;
1188+ let env = |name| environment[ std:: ffi:: OsStr :: new ( name) ] . unwrap ( ) ;
1189+ assert_eq ! ( env( "BUZZ_ACP_AGENT_COMMAND" ) , adapter. as_os_str( ) ) ;
1190+ assert_eq ! ( env( "BUZZ_ACP_AGENT_ARGS" ) , "" ) ;
1191+ let path: Vec < _ > = std:: env:: split_paths ( env ( "PATH" ) ) . collect ( ) ;
1192+ assert_eq ! (
1193+ & path[ ..3 ] ,
1194+ & [ dir. path( ) , node. parent( ) . unwrap( ) , bin. as_path( ) ]
1195+ ) ;
1196+ assert ! ( !environment. contains_key( std:: ffi:: OsStr :: new( "BUZZ_ACP_MODEL" ) ) ) ;
1197+ assert_eq ! ( env( "CLAUDE_CODE_EXECUTABLE" ) , cli. as_os_str( ) ) ;
1198+ saved
1199+ . environment
1200+ . insert ( "CLAUDE_CODE_EXECUTABLE" . into ( ) , "/custom/claude" . into ( ) ) ;
1201+ let override_command = runtime. command ( & saved, & key) . unwrap ( ) ;
1202+ assert ! ( override_command
1203+ . get_envs( )
1204+ . any( |( name, value) | name == "CLAUDE_CODE_EXECUTABLE"
1205+ && value == Some ( std:: ffi:: OsStr :: new( "/custom/claude" ) ) ) ) ;
1206+ saved. harness . model = "old-model" . into ( ) ;
1207+ assert ! ( runtime
1208+ . command( & saved, & key)
1209+ . unwrap_err( )
1210+ . contains( "Use Claude Code defaults" ) ) ;
1211+ saved. harness . model . clear ( ) ;
1212+ fs:: remove_file ( & cli) . unwrap ( ) ;
1213+ // The managed Node remains required even when another installation is on PATH.
1214+ fs:: remove_file ( node) . unwrap ( ) ;
1215+ assert ! ( runtime
1216+ . command( & saved, & key)
1217+ . unwrap_err( )
1218+ . contains( "Install Node.js for Claude Code" ) ) ;
1219+ }
1220+
11541221#[ test]
11551222#[ cfg( unix) ]
11561223fn start_and_restart_reject_missing_saved_identities ( ) {
@@ -1168,6 +1235,90 @@ fn start_and_restart_reject_missing_saved_identities() {
11681235 assert ! ( controller. running. is_empty( ) ) ;
11691236}
11701237
1238+ #[ test]
1239+ fn external_claude_launch_resolves_node_and_avoids_windows_batch_cli_overrides ( ) {
1240+ const FIXTURE : & str = "BUZZ_CLAUDE_LAUNCH_FIXTURE" ;
1241+ let Some ( root) = std:: env:: var_os ( FIXTURE ) else {
1242+ let dir = tempfile:: Builder :: new ( )
1243+ . prefix ( "External Claude " )
1244+ . tempdir ( )
1245+ . unwrap ( ) ;
1246+ let output = Command :: new ( std:: env:: current_exe ( ) . unwrap ( ) )
1247+ . args ( [ "--exact" , "runtime::tests::external_claude_launch_resolves_node_and_avoids_windows_batch_cli_overrides" , "--nocapture" ] )
1248+ . env ( FIXTURE , dir. path ( ) )
1249+ . env ( "HOME" , dir. path ( ) . join ( "home" ) )
1250+ . env ( "PATH" , dir. path ( ) . join ( "tools" ) )
1251+ . output ( ) . unwrap ( ) ;
1252+ assert ! (
1253+ output. status. success( ) ,
1254+ "{}{}" ,
1255+ String :: from_utf8_lossy( & output. stdout) ,
1256+ String :: from_utf8_lossy( & output. stderr)
1257+ ) ;
1258+ return ;
1259+ } ;
1260+ let root = PathBuf :: from ( root) ;
1261+ let runtime = bundle ( & root) ;
1262+ let bin = root. join ( "tools" ) ;
1263+ fs:: create_dir_all ( & bin) . unwrap ( ) ;
1264+ let adapter = bin. join ( if cfg ! ( windows) {
1265+ "claude-agent-acp.cmd"
1266+ } else {
1267+ "claude-agent-acp"
1268+ } ) ;
1269+ let cli = bin. join ( if cfg ! ( windows) {
1270+ "claude.cmd"
1271+ } else {
1272+ "claude"
1273+ } ) ;
1274+ let node = bin. join ( if cfg ! ( windows) { "node.exe" } else { "node" } ) ;
1275+ let fixture = root. join ( format ! ( "buzz-agent{}" , std:: env:: consts:: EXE_SUFFIX ) ) ;
1276+ for path in [ & adapter, & cli, & node] {
1277+ fs:: copy ( & fixture, path) . unwrap ( ) ;
1278+ }
1279+ let mut saved = agent ( & root) ;
1280+ saved. harness . command = adapter. to_string_lossy ( ) . into_owned ( ) ;
1281+ saved. harness . model . clear ( ) ;
1282+ saved. harness . provider . clear ( ) ;
1283+ let key = Secret :: parse ( KEY , PUB ) . unwrap ( ) ;
1284+ let command = runtime. command ( & saved, & key) . unwrap ( ) ;
1285+ let env: BTreeMap < _ , _ > = command. get_envs ( ) . collect ( ) ;
1286+ assert_eq ! (
1287+ env[ std:: ffi:: OsStr :: new( "BUZZ_ACP_AGENT_COMMAND" ) ] ,
1288+ Some ( adapter. as_os_str( ) )
1289+ ) ;
1290+ let path: Vec < _ > = std:: env:: split_paths ( env[ std:: ffi:: OsStr :: new ( "PATH" ) ] . unwrap ( ) ) . collect ( ) ;
1291+ assert_eq ! ( path[ 1 ] , bin) ;
1292+ if cfg ! ( windows) {
1293+ assert ! ( !env. contains_key( std:: ffi:: OsStr :: new( "CLAUDE_CODE_EXECUTABLE" ) ) ) ;
1294+ let native = bin. join ( "claude.exe" ) ;
1295+ fs:: copy ( & fixture, & native) . unwrap ( ) ;
1296+ let command = runtime. command ( & saved, & key) . unwrap ( ) ;
1297+ assert ! ( command. get_envs( ) . any(
1298+ |( key, value) | key == "CLAUDE_CODE_EXECUTABLE" && value == Some ( native. as_os_str( ) )
1299+ ) ) ;
1300+ } else {
1301+ assert_eq ! (
1302+ env[ std:: ffi:: OsStr :: new( "CLAUDE_CODE_EXECUTABLE" ) ] ,
1303+ Some ( cli. as_os_str( ) )
1304+ ) ;
1305+ }
1306+ fs:: remove_file ( & cli) . unwrap ( ) ;
1307+ if cfg ! ( windows) {
1308+ fs:: remove_file ( bin. join ( "claude.exe" ) ) . unwrap ( ) ;
1309+ }
1310+ let custom_cli = root. join ( format ! ( "custom-claude{}" , std:: env:: consts:: EXE_SUFFIX ) ) ;
1311+ fs:: copy ( & fixture, & custom_cli) . unwrap ( ) ;
1312+ saved. environment . insert (
1313+ "CLAUDE_CODE_EXECUTABLE" . into ( ) ,
1314+ custom_cli. to_string_lossy ( ) . into_owned ( ) ,
1315+ ) ;
1316+ let command = runtime. command ( & saved, & key) . unwrap ( ) ;
1317+ assert ! ( command. get_envs( ) . any( |( name, value) | {
1318+ name == "CLAUDE_CODE_EXECUTABLE" && value == Some ( custom_cli. as_os_str( ) )
1319+ } ) ) ;
1320+ }
1321+
11711322#[ test]
11721323#[ cfg( unix) ]
11731324fn shared_cache_spawn_capture_disconnect_snapshot_and_private_temp_cleanup ( ) {
0 commit comments