@@ -23,19 +23,22 @@ function fixture(
2323 failCleanup = false ,
2424 releasePackage = name ,
2525 formula ?: string ,
26+ executableOverride ?: ( root : string , home : string ) => Effect . Effect < string , PlatformError . PlatformError , FileSystem . FileSystem > ,
2627) {
2728 return Effect . gen ( function * ( ) {
2829 const fs = yield * FileSystem . FileSystem
2930 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner
3031 const root = yield * fs . makeTempDirectoryScoped ( { prefix : "opencode-updater-" } )
3132 const execPath = process . execPath
3233 const modules = path . join ( root , "node_modules" )
33- const executable = formula
34- ? path . join ( root , "Cellar" , formula , "2.0.20" , "bin" , "opencode" )
35- : path . join ( modules , "@opencode" , "cli" , "bin" , "opencode" )
34+ const executable = executableOverride
35+ ? yield * executableOverride ( root , path . join ( root , "home" ) )
36+ : formula
37+ ? path . join ( root , "Cellar" , formula , "2.0.20" , "bin" , "opencode" )
38+ : path . join ( modules , "@opencode" , "cli" , "bin" , "opencode" )
3639 yield * fs . makeDirectory ( path . dirname ( executable ) , { recursive : true } )
3740 yield * fs . writeFileString ( executable , "binary" )
38- if ( ! formula )
41+ if ( ! formula && ! executableOverride )
3942 yield * fs . writeFileString (
4043 path . join ( modules , "@opencode" , "cli" , "package.json" ) ,
4144 JSON . stringify ( { name, bin : { opencode : "bin/opencode" } } ) ,
@@ -98,7 +101,7 @@ function fixture(
98101 } ) ,
99102 )
100103 : fs . remove ( target , options ) ,
101- realPath : ( input ) => ( input === execPath ? Effect . succeed ( executable ) : fs . realPath ( input ) ) ,
104+ realPath : ( input ) => ( input === execPath ? fs . realPath ( executable ) : fs . realPath ( input ) ) ,
102105 } ) ,
103106 Effect . provideService (
104107 AppProcess . Service ,
@@ -403,17 +406,22 @@ windows("windows keeps the uninstall link in the temporary directory, not the re
403406windows ( "windows links the curl binary before the installer replaces it" , ( ) =>
404407 Effect . gen ( function * ( ) {
405408 const layout = { executable : "" , cache : "" }
406- const test = yield * fixture ( ( command ) => {
407- if ( path . basename ( command . command , ".exe" ) === "bash" ) {
408- expect ( readFileSync ( layout . executable , "utf8" ) ) . toBe ( "binary" )
409- expect ( upgradeLinks ( layout . cache ) ) . toHaveLength ( 1 )
410- }
411- return { }
412- } )
413- layout . executable = path . join ( test . global . home , ".opencode" , "bin" , "opencode.exe" )
409+ const test = yield * fixture (
410+ ( command ) => {
411+ if ( path . basename ( command . command , ".exe" ) === "bash" ) {
412+ expect ( readFileSync ( layout . executable , "utf8" ) ) . toBe ( "binary" )
413+ expect ( upgradeLinks ( layout . cache ) ) . toHaveLength ( 1 )
414+ }
415+ return { }
416+ } ,
417+ "@opencode/cli" ,
418+ false ,
419+ "@opencode/cli" ,
420+ undefined ,
421+ ( _root , home ) => Effect . succeed ( path . join ( home , ".opencode" , "bin" , "opencode.exe" ) ) ,
422+ )
423+ layout . executable = test . executable
414424 layout . cache = test . global . cache
415- yield * test . fs . makeDirectory ( path . dirname ( layout . executable ) , { recursive : true } )
416- yield * test . fs . writeFileString ( layout . executable , "binary" )
417425 const original = process . execPath
418426 process . execPath = layout . executable
419427 yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => ( process . execPath = original ) ) )
@@ -425,6 +433,29 @@ windows("windows links the curl binary before the installer replaces it", () =>
425433 } ) ,
426434)
427435
436+ unix ( "curl method detection resolves symlinked home directories" , ( ) =>
437+ Effect . gen ( function * ( ) {
438+ const test = yield * fixture (
439+ ( ) => ( { } ) ,
440+ "@opencode/cli" ,
441+ false ,
442+ "@opencode/cli" ,
443+ undefined ,
444+ ( root , home ) =>
445+ Effect . gen ( function * ( ) {
446+ const fs = yield * FileSystem . FileSystem
447+ const realHome = path . join ( root , "real-home" )
448+ const bin = path . join ( realHome , ".opencode" , "bin" , "opencode" )
449+ yield * fs . makeDirectory ( path . dirname ( bin ) , { recursive : true } )
450+ yield * fs . symlink ( realHome , home )
451+ return bin
452+ } ) ,
453+ )
454+ expect ( yield * test . updater . method ( ) ) . toBe ( "curl" )
455+ expect ( test . commands ) . toEqual ( [ ] )
456+ } ) ,
457+ )
458+
428459windows ( "windows leaves a source checkout's runtime alone" , ( ) =>
429460 Effect . gen ( function * ( ) {
430461 const layout = { cache : "" }
0 commit comments