@@ -141,6 +141,54 @@ test("loads config with defaults when no files exist", async () => {
141141 } )
142142} )
143143
144+ test ( "creates global jsonc config with schema when no global configs exist" , async ( ) => {
145+ await using tmp = await tmpdir ( )
146+ const prev = Global . Path . config
147+ ; ( Global . Path as { config : string } ) . config = tmp . path
148+ await clear ( true )
149+
150+ try {
151+ await WithInstance . provide ( {
152+ directory : tmp . path ,
153+ fn : async ( ) => {
154+ await load ( )
155+ } ,
156+ } )
157+
158+ const content = await Filesystem . readText ( path . join ( tmp . path , "opencode.jsonc" ) )
159+ expect ( content ) . toContain ( '"$schema": "https://opencode.ai/config.json"' )
160+ } finally {
161+ ; ( Global . Path as { config : string } ) . config = prev
162+ await clear ( true )
163+ }
164+ } )
165+
166+ test ( "does not create global config when OPENCODE_CONFIG_DIR is set" , async ( ) => {
167+ await using tmp = await tmpdir ( )
168+ await using custom = await tmpdir ( )
169+ const prevConfig = Global . Path . config
170+ const prevEnv = process . env . OPENCODE_CONFIG_DIR
171+ ; ( Global . Path as { config : string } ) . config = tmp . path
172+ process . env . OPENCODE_CONFIG_DIR = custom . path
173+ await clear ( true )
174+
175+ try {
176+ await WithInstance . provide ( {
177+ directory : tmp . path ,
178+ fn : async ( ) => {
179+ await load ( )
180+ } ,
181+ } )
182+
183+ expect ( await Filesystem . exists ( path . join ( tmp . path , "opencode.jsonc" ) ) ) . toBe ( false )
184+ } finally {
185+ ; ( Global . Path as { config : string } ) . config = prevConfig
186+ if ( prevEnv === undefined ) delete process . env . OPENCODE_CONFIG_DIR
187+ else process . env . OPENCODE_CONFIG_DIR = prevEnv
188+ await clear ( true )
189+ }
190+ } )
191+
144192test ( "loads JSON config file" , async ( ) => {
145193 await using tmp = await tmpdir ( {
146194 init : async ( dir ) => {
0 commit comments