@@ -566,6 +566,67 @@ test("gets config directories", async () => {
566566 } )
567567} )
568568
569+ test ( "does not try to install dependencies in read-only OPENCODE_CONFIG_DIR" , async ( ) => {
570+ if ( process . platform === "win32" ) return
571+
572+ await using tmp = await tmpdir < string > ( {
573+ init : async ( dir ) => {
574+ const ro = path . join ( dir , "readonly" )
575+ await fs . mkdir ( ro , { recursive : true } )
576+ await fs . chmod ( ro , 0o555 )
577+ return ro
578+ } ,
579+ dispose : async ( dir ) => {
580+ const ro = path . join ( dir , "readonly" )
581+ await fs . chmod ( ro , 0o755 ) . catch ( ( ) => { } )
582+ return ro
583+ } ,
584+ } )
585+
586+ const prev = process . env . OPENCODE_CONFIG_DIR
587+ process . env . OPENCODE_CONFIG_DIR = tmp . extra
588+
589+ try {
590+ await Instance . provide ( {
591+ directory : tmp . path ,
592+ fn : async ( ) => {
593+ await Config . get ( )
594+ } ,
595+ } )
596+ } finally {
597+ if ( prev === undefined ) delete process . env . OPENCODE_CONFIG_DIR
598+ else process . env . OPENCODE_CONFIG_DIR = prev
599+ }
600+ } )
601+
602+ test ( "installs dependencies in writable OPENCODE_CONFIG_DIR" , async ( ) => {
603+ await using tmp = await tmpdir < string > ( {
604+ init : async ( dir ) => {
605+ const cfg = path . join ( dir , "configdir" )
606+ await fs . mkdir ( cfg , { recursive : true } )
607+ return cfg
608+ } ,
609+ } )
610+
611+ const prev = process . env . OPENCODE_CONFIG_DIR
612+ process . env . OPENCODE_CONFIG_DIR = tmp . extra
613+
614+ try {
615+ await Instance . provide ( {
616+ directory : tmp . path ,
617+ fn : async ( ) => {
618+ await Config . get ( )
619+ } ,
620+ } )
621+
622+ expect ( await Bun . file ( path . join ( tmp . extra , "package.json" ) ) . exists ( ) ) . toBe ( true )
623+ expect ( await Bun . file ( path . join ( tmp . extra , ".gitignore" ) ) . exists ( ) ) . toBe ( true )
624+ } finally {
625+ if ( prev === undefined ) delete process . env . OPENCODE_CONFIG_DIR
626+ else process . env . OPENCODE_CONFIG_DIR = prev
627+ }
628+ } )
629+
569630test ( "resolves scoped npm plugins in config" , async ( ) => {
570631 await using tmp = await tmpdir ( {
571632 init : async ( dir ) => {
0 commit comments