@@ -307,6 +307,74 @@ it.layer(
307307 } ) ,
308308 ) ;
309309
310+ it . effect . each ( [
311+ { output : "codex-cli 2.0.0" , exitCode : 0 , expected : "2.0.0" } ,
312+ { output : "2.0.0 (Claude Code)" , exitCode : 0 , expected : "2.0.0" } ,
313+ { output : "unavailable" , exitCode : 0 , expected : null } ,
314+ { output : "codex-cli 2.0.0" , exitCode : 1 , expected : null } ,
315+ { output : "missing executable" , exitCode : 0 , expected : null , missing : true } ,
316+ ] ) (
317+ "uses the selected CLI version only for advisories ($output, exit $exitCode)" ,
318+ ( fixture ) =>
319+ Effect . gen ( function * ( ) {
320+ const tempDir = yield * makeTempDir ( "t3-maintenance-advisory" ) ;
321+ const maintenancePath = NodePath . join ( tempDir , ".local" , "bin" , "native-package-tool" ) ;
322+ if ( ! fixture . missing ) writeExecutable ( maintenancePath ) ;
323+ let probes = 0 ;
324+ const capabilities = {
325+ ...( yield * resolveProviderMaintenanceCapabilitiesEffect ( nativePackageToolUpdate , {
326+ binaryPath : NodePath . join ( tempDir , "runtime-launcher" ) ,
327+ maintenanceBinaryPath : maintenancePath ,
328+ env : { PATH : "" , SELECTED_INSTALL : "fixture" } ,
329+ } ) . pipe (
330+ Effect . provideService (
331+ ChildProcessSpawner . ChildProcessSpawner ,
332+ stdoutSpawner (
333+ ( command , args ) => {
334+ expect ( command ) . toBe ( maintenancePath ) ;
335+ expect ( args ) . toEqual ( [ "--version" ] ) ;
336+ probes ++ ;
337+ return fixture . output ;
338+ } ,
339+ ( ) => fixture . exitCode ,
340+ ) ,
341+ ) ,
342+ ) ) ,
343+ latestVersion : "3.0.0" ,
344+ } ;
345+ const snapshot = {
346+ ...installedPackageToolProvider ,
347+ version : "3.0.0" ,
348+ installedVersion : "3.0.0" ,
349+ } ;
350+ const enrich = ( useMaintenanceVersion : boolean , enableProviderUpdateChecks = true ) =>
351+ enrichProviderSnapshotWithVersionAdvisory ( snapshot , capabilities , {
352+ enableProviderUpdateChecks,
353+ useMaintenanceVersion,
354+ } ) ;
355+ yield * enrich ( true , false ) ;
356+ expect ( probes ) . toBe ( 0 ) ;
357+ const verification = yield * enrich ( false ) ;
358+ expect ( verification . versionAdvisory ?. currentVersion ) . toBe ( "3.0.0" ) ;
359+ expect ( probes ) . toBe ( 0 ) ;
360+ const advisory = yield * enrich ( true ) ;
361+ expect ( advisory . version ) . toBe ( "3.0.0" ) ;
362+ expect ( advisory . installedVersion ) . toBe ( "3.0.0" ) ;
363+ expect ( advisory . versionAdvisory ) . toMatchObject ( {
364+ currentVersion : fixture . expected ,
365+ status : fixture . expected ? "behind_latest" : "unknown" ,
366+ } ) ;
367+ expect ( probes ) . toBe ( fixture . missing ? 0 : 1 ) ;
368+ } ) . pipe (
369+ Effect . provide ( ProviderLatestVersions . layer ) ,
370+ Effect . provideService (
371+ HttpClient . HttpClient ,
372+ HttpClient . make ( ( ) => Effect . die ( "fixture latest version must not make an HTTP request" ) ) ,
373+ ) ,
374+ ) ,
375+ { skip : windowsHost } ,
376+ ) ;
377+
310378 it . effect ( "does not fetch latest provider versions when update checks are disabled" , ( ) =>
311379 enrichProviderSnapshotWithVersionAdvisory (
312380 { ...installedPackageToolProvider , installedVersion : "1.1.0" } ,
@@ -1159,29 +1227,100 @@ it.layer(
11591227 { skip : ! symlinksSupported || windowsHost } ,
11601228 ) ;
11611229
1162- it . effect . skipIf ( windowsHost ) (
1163- "switches to bun updates when the resolved binary lives in bun's global bin " ,
1230+ it . effect . skipIf ( windowsHost || ! symlinksSupported ) (
1231+ "binds bun updates to the selected global installation and rejects unproven ownership " ,
11641232 ( ) =>
11651233 Effect . gen ( function * ( ) {
11661234 const tempDir = yield * makeTempDir ( "t3-bun-capabilities" ) ;
1167- const bunBinDir = NodePath . join ( tempDir , ".bun" , "bin" ) ;
1168- writeExecutable ( NodePath . join ( bunBinDir , "package-tool" ) ) ;
1169-
1170- const capabilities = yield * resolveProviderMaintenanceCapabilitiesEffect (
1171- packageToolUpdate ,
1172- {
1173- binaryPath : "package-tool" ,
1174- env : { PATH : bunBinDir } ,
1175- } ,
1176- ) . pipe (
1177- Effect . provideService ( HostProcess . Platform , "darwin" ) ,
1178- Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
1235+ const bunBinDir = NodePath . join ( tempDir , "selected" , ".bun" , "bin" ) ;
1236+ const globalDir = NodePath . join ( tempDir , "selected" , ".bun" , "install" , "global" ) ;
1237+ const packagePath = NodePath . join (
1238+ globalDir ,
1239+ "node_modules" ,
1240+ "@example" ,
1241+ "package-tool" ,
1242+ "bin" ,
1243+ "package-tool.js" ,
11791244 ) ;
1245+ writeExecutable ( packagePath ) ;
1246+ const maintenancePath = NodePath . join ( bunBinDir , "package-tool" ) ;
1247+ NodeFS . mkdirSync ( bunBinDir , { recursive : true } ) ;
1248+ NodeFS . symlinkSync ( packagePath , maintenancePath ) ;
1249+ const runtimePath = NodePath . join ( tempDir , "default" , ".bun" , "bin" , "package-tool" ) ;
1250+ writeExecutable ( runtimePath ) ;
1251+ const env = {
1252+ PATH : NodePath . dirname ( runtimePath ) ,
1253+ BUN_INSTALL_GLOBAL_DIR : NodePath . join ( tempDir , "default" , ".bun" , "install" , "global" ) ,
1254+ BUN_INSTALL_BIN : NodePath . dirname ( runtimePath ) ,
1255+ } ;
1256+
1257+ const resolve = ( ) =>
1258+ resolveProviderMaintenanceCapabilitiesEffect ( packageToolUpdate , {
1259+ binaryPath : runtimePath ,
1260+ maintenanceBinaryPath : maintenancePath ,
1261+ env,
1262+ } ) . pipe (
1263+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
1264+ Effect . provideService ( HostProcess . Environment , env ) ,
1265+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
1266+ ) ;
11801267
1268+ const capabilities = yield * resolve ( ) ;
11811269 expect ( capabilities . update ) . toMatchObject ( {
11821270 command : "bun i -g @example/package-tool@latest" ,
1183- lockKey : "bun-global" ,
1271+ lockKey : `bun-global:${ normalizeCommandPath ( globalDir ) } ` ,
1272+ env : { ...env , BUN_INSTALL_GLOBAL_DIR : globalDir , BUN_INSTALL_BIN : bunBinDir } ,
1273+ } ) ;
1274+ expect ( makeTargetedProviderUpdateAction ( capabilities , "2.0.0" ) ) . toMatchObject ( {
1275+ args :
[ "i" , "-g" , "@example/[email protected] " ] , 1276+ env : capabilities . update ?. env ,
1277+ } ) ;
1278+
1279+ for ( const target of [
1280+ NodePath . join ( globalDir , "node_modules" , "@example" , "other-package" , "bin" , "tool" ) ,
1281+ NodePath . join (
1282+ tempDir ,
1283+ "project" ,
1284+ "node_modules" ,
1285+ "@example" ,
1286+ "package-tool" ,
1287+ "bin" ,
1288+ "tool" ,
1289+ ) ,
1290+ maintenancePath ,
1291+ ] ) {
1292+ NodeFS . unlinkSync ( maintenancePath ) ;
1293+ writeExecutable ( target ) ;
1294+ if ( target !== maintenancePath ) NodeFS . symlinkSync ( target , maintenancePath ) ;
1295+ expect ( yield * resolve ( ) ) . toMatchObject ( { update : null , installPath : target } ) ;
1296+ }
1297+ } ) ,
1298+ ) ;
1299+
1300+ it . effect . skipIf ( windowsHost ) (
1301+ "updates the explicit maintenance installation while keeping the runtime wrapper separate" ,
1302+ ( ) =>
1303+ Effect . gen ( function * ( ) {
1304+ const tempDir = yield * makeTempDir ( "t3-wrapper-maintenance" ) ;
1305+ const wrapper = NodePath . join ( tempDir , "agentfleet-launcher" ) ;
1306+ const nativePath = NodePath . join ( tempDir , ".local" , "bin" , "native-package-tool" ) ;
1307+ writeExecutable ( wrapper ) ;
1308+ writeExecutable ( nativePath ) ;
1309+ const resolve = ( maintenanceBinaryPath : string ) =>
1310+ resolveProviderMaintenanceCapabilitiesEffect ( nativePackageToolUpdate , {
1311+ binaryPath : wrapper ,
1312+ maintenanceBinaryPath,
1313+ env : { PATH : "" } ,
1314+ } ) . pipe (
1315+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
1316+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , noSpawn ) ,
1317+ ) ;
1318+ expect ( ( yield * resolve ( nativePath ) ) . update ) . toMatchObject ( {
1319+ executable : nativePath ,
1320+ args : [ "update" ] ,
11841321 } ) ;
1322+ expect ( ( yield * resolve ( NodePath . join ( tempDir , "missing" ) ) ) . update ) . toBeNull ( ) ;
1323+ expect ( ( yield * resolve ( " " ) ) . update ?. executable ) . toBe ( wrapper ) ;
11851324 } ) ,
11861325 ) ;
11871326
0 commit comments