@@ -179,6 +179,74 @@ it.layer(
179179 } ) ,
180180 ) ;
181181
182+ it . effect . each ( [
183+ { output : "codex-cli 2.0.0" , exitCode : 0 , expected : "2.0.0" } ,
184+ { output : "2.0.0 (Claude Code)" , exitCode : 0 , expected : "2.0.0" } ,
185+ { output : "unavailable" , exitCode : 0 , expected : null } ,
186+ { output : "codex-cli 2.0.0" , exitCode : 1 , expected : null } ,
187+ { output : "missing executable" , exitCode : 0 , expected : null , missing : true } ,
188+ ] ) (
189+ "uses the selected CLI version only for advisories ($output, exit $exitCode)" ,
190+ ( fixture ) =>
191+ Effect . gen ( function * ( ) {
192+ const tempDir = yield * makeTempDir ( "t3-maintenance-advisory" ) ;
193+ const maintenancePath = NodePath . join ( tempDir , ".local" , "bin" , "native-package-tool" ) ;
194+ if ( ! fixture . missing ) writeExecutable ( maintenancePath ) ;
195+ let probes = 0 ;
196+ const capabilities = {
197+ ...( yield * resolveProviderMaintenanceCapabilitiesEffect ( nativePackageToolUpdate , {
198+ binaryPath : NodePath . join ( tempDir , "runtime-launcher" ) ,
199+ maintenanceBinaryPath : maintenancePath ,
200+ env : { PATH : "" , SELECTED_INSTALL : "fixture" } ,
201+ } ) . pipe (
202+ Effect . provideService (
203+ ChildProcessSpawner . ChildProcessSpawner ,
204+ stdoutSpawner (
205+ ( command , args ) => {
206+ expect ( command ) . toBe ( maintenancePath ) ;
207+ expect ( args ) . toEqual ( [ "--version" ] ) ;
208+ probes ++ ;
209+ return fixture . output ;
210+ } ,
211+ ( ) => fixture . exitCode ,
212+ ) ,
213+ ) ,
214+ ) ) ,
215+ latestVersion : "3.0.0" ,
216+ } ;
217+ const snapshot = {
218+ ...installedPackageToolProvider ,
219+ version : "3.0.0" ,
220+ installedVersion : "3.0.0" ,
221+ } ;
222+ const enrich = ( useMaintenanceVersion : boolean , enableProviderUpdateChecks = true ) =>
223+ enrichProviderSnapshotWithVersionAdvisory ( snapshot , capabilities , {
224+ enableProviderUpdateChecks,
225+ useMaintenanceVersion,
226+ } ) ;
227+ yield * enrich ( true , false ) ;
228+ expect ( probes ) . toBe ( 0 ) ;
229+ const verification = yield * enrich ( false ) ;
230+ expect ( verification . versionAdvisory ?. currentVersion ) . toBe ( "3.0.0" ) ;
231+ expect ( probes ) . toBe ( 0 ) ;
232+ const advisory = yield * enrich ( true ) ;
233+ expect ( advisory . version ) . toBe ( "3.0.0" ) ;
234+ expect ( advisory . installedVersion ) . toBe ( "3.0.0" ) ;
235+ expect ( advisory . versionAdvisory ) . toMatchObject ( {
236+ currentVersion : fixture . expected ,
237+ status : fixture . expected ? "behind_latest" : "unknown" ,
238+ } ) ;
239+ expect ( probes ) . toBe ( fixture . missing ? 0 : 1 ) ;
240+ } ) . pipe (
241+ Effect . provide ( ProviderLatestVersions . layer ) ,
242+ Effect . provideService (
243+ HttpClient . HttpClient ,
244+ HttpClient . make ( ( ) => Effect . die ( "fixture latest version must not make an HTTP request" ) ) ,
245+ ) ,
246+ ) ,
247+ { skip : windowsHost } ,
248+ ) ;
249+
182250 it . effect ( "does not fetch latest provider versions when update checks are disabled" , ( ) =>
183251 enrichProviderSnapshotWithVersionAdvisory (
184252 { ...installedPackageToolProvider , installedVersion : "1.1.0" } ,
@@ -869,29 +937,100 @@ it.layer(
869937 { skip : ! symlinksSupported || windowsHost } ,
870938 ) ;
871939
872- it . effect . skipIf ( windowsHost ) (
873- "switches to bun updates when the resolved binary lives in bun's global bin " ,
940+ it . effect . skipIf ( windowsHost || ! symlinksSupported ) (
941+ "binds bun updates to the selected global installation and rejects unproven ownership " ,
874942 ( ) =>
875943 Effect . gen ( function * ( ) {
876944 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 ) ,
945+ const bunBinDir = NodePath . join ( tempDir , "selected" , ".bun" , "bin" ) ;
946+ const globalDir = NodePath . join ( tempDir , "selected" , ".bun" , "install" , "global" ) ;
947+ const packagePath = NodePath . join (
948+ globalDir ,
949+ "node_modules" ,
950+ "@example" ,
951+ "package-tool" ,
952+ "bin" ,
953+ "package-tool.js" ,
889954 ) ;
955+ writeExecutable ( packagePath ) ;
956+ const maintenancePath = NodePath . join ( bunBinDir , "package-tool" ) ;
957+ NodeFS . mkdirSync ( bunBinDir , { recursive : true } ) ;
958+ NodeFS . symlinkSync ( packagePath , maintenancePath ) ;
959+ const runtimePath = NodePath . join ( tempDir , "default" , ".bun" , "bin" , "package-tool" ) ;
960+ writeExecutable ( runtimePath ) ;
961+ const env = {
962+ PATH : NodePath . dirname ( runtimePath ) ,
963+ BUN_INSTALL_GLOBAL_DIR : NodePath . join ( tempDir , "default" , ".bun" , "install" , "global" ) ,
964+ BUN_INSTALL_BIN : NodePath . dirname ( runtimePath ) ,
965+ } ;
966+
967+ const resolve = ( ) =>
968+ resolveProviderMaintenanceCapabilitiesEffect ( packageToolUpdate , {
969+ binaryPath : runtimePath ,
970+ maintenanceBinaryPath : maintenancePath ,
971+ env,
972+ } ) . pipe (
973+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
974+ Effect . provideService ( HostProcess . Environment , env ) ,
975+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
976+ ) ;
890977
978+ const capabilities = yield * resolve ( ) ;
891979 expect ( capabilities . update ) . toMatchObject ( {
892980 command : "bun i -g @example/package-tool@latest" ,
893- lockKey : "bun-global" ,
981+ lockKey : `bun-global:${ normalizeCommandPath ( globalDir ) } ` ,
982+ env : { BUN_INSTALL_GLOBAL_DIR : globalDir , BUN_INSTALL_BIN : bunBinDir } ,
983+ } ) ;
984+ expect ( makeTargetedProviderUpdateAction ( capabilities , "2.0.0" ) ) . toMatchObject ( {
985+ args :
[ "i" , "-g" , "@example/[email protected] " ] , 986+ env : capabilities . update ?. env ,
987+ } ) ;
988+
989+ for ( const target of [
990+ NodePath . join ( globalDir , "node_modules" , "@example" , "other-package" , "bin" , "tool" ) ,
991+ NodePath . join (
992+ tempDir ,
993+ "project" ,
994+ "node_modules" ,
995+ "@example" ,
996+ "package-tool" ,
997+ "bin" ,
998+ "tool" ,
999+ ) ,
1000+ maintenancePath ,
1001+ ] ) {
1002+ NodeFS . unlinkSync ( maintenancePath ) ;
1003+ writeExecutable ( target ) ;
1004+ if ( target !== maintenancePath ) NodeFS . symlinkSync ( target , maintenancePath ) ;
1005+ expect ( yield * resolve ( ) ) . toMatchObject ( { update : null , installPath : target } ) ;
1006+ }
1007+ } ) ,
1008+ ) ;
1009+
1010+ it . effect . skipIf ( windowsHost ) (
1011+ "updates the explicit maintenance installation while keeping the runtime wrapper separate" ,
1012+ ( ) =>
1013+ Effect . gen ( function * ( ) {
1014+ const tempDir = yield * makeTempDir ( "t3-wrapper-maintenance" ) ;
1015+ const wrapper = NodePath . join ( tempDir , "agentfleet-launcher" ) ;
1016+ const nativePath = NodePath . join ( tempDir , ".local" , "bin" , "native-package-tool" ) ;
1017+ writeExecutable ( wrapper ) ;
1018+ writeExecutable ( nativePath ) ;
1019+ const resolve = ( maintenanceBinaryPath : string ) =>
1020+ resolveProviderMaintenanceCapabilitiesEffect ( nativePackageToolUpdate , {
1021+ binaryPath : wrapper ,
1022+ maintenanceBinaryPath,
1023+ env : { PATH : "" } ,
1024+ } ) . pipe (
1025+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
1026+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
1027+ ) ;
1028+ expect ( ( yield * resolve ( nativePath ) ) . update ) . toMatchObject ( {
1029+ executable : nativePath ,
1030+ args : [ "update" ] ,
8941031 } ) ;
1032+ expect ( ( yield * resolve ( NodePath . join ( tempDir , "missing" ) ) ) . update ) . toBeNull ( ) ;
1033+ expect ( ( yield * resolve ( " " ) ) . update ?. executable ) . toBe ( wrapper ) ;
8951034 } ) ,
8961035 ) ;
8971036
0 commit comments