@@ -217,10 +217,18 @@ mod tests {
217217 assert ! ( !is_potential_package_binary( "another-fake-tool" ) ) ;
218218 }
219219
220+ /// Clear both shim env vars to isolate tests.
221+ /// SAFETY: caller must be `#[serial]` since this mutates process-global state.
222+ unsafe fn clear_shim_env_vars ( ) {
223+ unsafe {
224+ std:: env:: remove_var ( SHIM_TOOL_ENV_VAR ) ;
225+ std:: env:: remove_var ( LEGACY_SHIM_TOOL_ENV_VAR ) ;
226+ }
227+ }
228+
220229 #[ test]
221230 #[ serial]
222231 fn test_detect_shim_tool_from_env_var ( ) {
223- // SAFETY: We're in a test at startup, no other threads
224232 unsafe {
225233 std:: env:: set_var ( SHIM_TOOL_ENV_VAR , "node" ) ;
226234 std:: env:: remove_var ( LEGACY_SHIM_TOOL_ENV_VAR ) ;
@@ -236,7 +244,6 @@ mod tests {
236244 fn test_detect_shim_tool_from_legacy_env_var ( ) {
237245 // When only VITE_PLUS_SHIM_TOOL is set (older trampoline), it should
238246 // fall back to reading the legacy env var.
239- // SAFETY: We're in a test at startup, no other threads
240247 unsafe {
241248 std:: env:: remove_var ( SHIM_TOOL_ENV_VAR ) ;
242249 std:: env:: set_var ( LEGACY_SHIM_TOOL_ENV_VAR , "npm" ) ;
@@ -247,46 +254,28 @@ mod tests {
247254 assert ! ( std:: env:: var( LEGACY_SHIM_TOOL_ENV_VAR ) . is_err( ) ) ;
248255 }
249256
257+ /// Tests that argv0-based tool detection works for a given tool name,
258+ /// including full path and .exe extension variants.
259+ fn assert_detect_shim_tool_from_argv0 ( tool : & str ) {
260+ unsafe { clear_shim_env_vars ( ) } ;
261+
262+ assert_eq ! ( detect_shim_tool( tool) , Some ( tool. to_string( ) ) ) ;
263+ assert_eq ! (
264+ detect_shim_tool( & format!( "/home/user/.vite-plus/bin/{tool}" ) ) ,
265+ Some ( tool. to_string( ) ) ,
266+ ) ;
267+ assert_eq ! ( detect_shim_tool( & format!( "{tool}.exe" ) ) , Some ( tool. to_string( ) ) , ) ;
268+ }
269+
250270 #[ test]
251271 #[ serial]
252272 fn test_detect_shim_tool_vpx ( ) {
253- // vpx should be detected via the argv0 check, before the env var check
254- // and before is_shim_tool (which would incorrectly match it as a package binary)
255- // SAFETY: We're in a test
256- unsafe {
257- std:: env:: remove_var ( SHIM_TOOL_ENV_VAR ) ;
258- std:: env:: remove_var ( LEGACY_SHIM_TOOL_ENV_VAR ) ;
259- }
260- let result = detect_shim_tool ( "vpx" ) ;
261- assert_eq ! ( result, Some ( "vpx" . to_string( ) ) ) ;
262-
263- // Also works with full path
264- let result = detect_shim_tool ( "/home/user/.vite-plus/bin/vpx" ) ;
265- assert_eq ! ( result, Some ( "vpx" . to_string( ) ) ) ;
266-
267- // Also works with .exe extension (Windows)
268- let result = detect_shim_tool ( "vpx.exe" ) ;
269- assert_eq ! ( result, Some ( "vpx" . to_string( ) ) ) ;
273+ assert_detect_shim_tool_from_argv0 ( "vpx" ) ;
270274 }
271275
272276 #[ test]
273277 #[ serial]
274278 fn test_detect_shim_tool_vpr ( ) {
275- // vpr should be detected via the argv0 check, same pattern as vpx
276- // SAFETY: We're in a test
277- unsafe {
278- std:: env:: remove_var ( SHIM_TOOL_ENV_VAR ) ;
279- std:: env:: remove_var ( LEGACY_SHIM_TOOL_ENV_VAR ) ;
280- }
281- let result = detect_shim_tool ( "vpr" ) ;
282- assert_eq ! ( result, Some ( "vpr" . to_string( ) ) ) ;
283-
284- // Also works with full path
285- let result = detect_shim_tool ( "/home/user/.vite-plus/bin/vpr" ) ;
286- assert_eq ! ( result, Some ( "vpr" . to_string( ) ) ) ;
287-
288- // Also works with .exe extension (Windows)
289- let result = detect_shim_tool ( "vpr.exe" ) ;
290- assert_eq ! ( result, Some ( "vpr" . to_string( ) ) ) ;
279+ assert_detect_shim_tool_from_argv0 ( "vpr" ) ;
291280 }
292281}
0 commit comments