@@ -869,29 +869,73 @@ it.layer(
869869 { skip : ! symlinksSupported || windowsHost } ,
870870 ) ;
871871
872- it . effect . skipIf ( windowsHost ) (
873- "switches to bun updates when the resolved binary lives in bun's global bin " ,
872+ it . effect . skipIf ( windowsHost || ! symlinksSupported ) (
873+ "binds bun updates to the selected global installation and rejects unproven ownership " ,
874874 ( ) =>
875875 Effect . gen ( function * ( ) {
876876 const tempDir = yield * makeTempDir ( "t3-bun-capabilities" ) ;
877- const bunBinDir = NodePath . join ( tempDir , ".bun" , "bin" ) ;
878- writeExecutable ( NodePath . join ( bunBinDir , "package-tool" ) ) ;
879-
880- const capabilities = yield * resolveProviderMaintenanceCapabilitiesEffect (
881- packageToolUpdate ,
882- {
883- binaryPath : "package-tool" ,
884- env : { PATH : bunBinDir } ,
885- } ,
886- ) . pipe (
887- Effect . provideService ( HostProcess . Platform , "darwin" ) ,
888- Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
877+ const bunBinDir = NodePath . join ( tempDir , "selected" , ".bun" , "bin" ) ;
878+ const globalDir = NodePath . join ( tempDir , "selected" , ".bun" , "install" , "global" ) ;
879+ const packagePath = NodePath . join (
880+ globalDir ,
881+ "node_modules" ,
882+ "@example" ,
883+ "package-tool" ,
884+ "bin" ,
885+ "package-tool.js" ,
889886 ) ;
887+ writeExecutable ( packagePath ) ;
888+ const maintenancePath = NodePath . join ( bunBinDir , "package-tool" ) ;
889+ NodeFS . mkdirSync ( bunBinDir , { recursive : true } ) ;
890+ NodeFS . symlinkSync ( packagePath , maintenancePath ) ;
891+ const runtimePath = NodePath . join ( tempDir , "default" , ".bun" , "bin" , "package-tool" ) ;
892+ writeExecutable ( runtimePath ) ;
893+ const env = {
894+ PATH : NodePath . dirname ( runtimePath ) ,
895+ BUN_INSTALL_GLOBAL_DIR : NodePath . join ( tempDir , "default" , ".bun" , "install" , "global" ) ,
896+ BUN_INSTALL_BIN : NodePath . dirname ( runtimePath ) ,
897+ } ;
898+
899+ const resolve = ( ) =>
900+ resolveProviderMaintenanceCapabilitiesEffect ( packageToolUpdate , {
901+ binaryPath : runtimePath ,
902+ maintenanceBinaryPath : maintenancePath ,
903+ env,
904+ } ) . pipe (
905+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
906+ Effect . provideService ( HostProcess . Environment , env ) ,
907+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
908+ ) ;
890909
910+ const capabilities = yield * resolve ( ) ;
891911 expect ( capabilities . update ) . toMatchObject ( {
892912 command : "bun i -g @example/package-tool@latest" ,
893- lockKey : "bun-global" ,
913+ lockKey : `bun-global:${ normalizeCommandPath ( globalDir ) } ` ,
914+ env : { BUN_INSTALL_GLOBAL_DIR : globalDir , BUN_INSTALL_BIN : bunBinDir } ,
894915 } ) ;
916+ expect ( makeTargetedProviderUpdateAction ( capabilities , "2.0.0" ) ) . toMatchObject ( {
917+ args :
[ "i" , "-g" , "@example/[email protected] " ] , 918+ env : capabilities . update ?. env ,
919+ } ) ;
920+
921+ for ( const target of [
922+ NodePath . join ( globalDir , "node_modules" , "@example" , "other-package" , "bin" , "tool" ) ,
923+ NodePath . join (
924+ tempDir ,
925+ "project" ,
926+ "node_modules" ,
927+ "@example" ,
928+ "package-tool" ,
929+ "bin" ,
930+ "tool" ,
931+ ) ,
932+ maintenancePath ,
933+ ] ) {
934+ NodeFS . unlinkSync ( maintenancePath ) ;
935+ writeExecutable ( target ) ;
936+ if ( target !== maintenancePath ) NodeFS . symlinkSync ( target , maintenancePath ) ;
937+ expect ( yield * resolve ( ) ) . toMatchObject ( { update : null , installPath : target } ) ;
938+ }
895939 } ) ,
896940 ) ;
897941
0 commit comments