@@ -403,3 +403,101 @@ test("resolves scoped npm plugins in config", async () => {
403403 } ,
404404 } )
405405} )
406+
407+ test ( "merges plugin arrays from global and local configs" , async ( ) => {
408+ await using tmp = await tmpdir ( {
409+ init : async ( dir ) => {
410+ // Create a nested project structure with local .opencode config
411+ const projectDir = path . join ( dir , "project" )
412+ const opencodeDir = path . join ( projectDir , ".opencode" )
413+ await fs . mkdir ( opencodeDir , { recursive : true } )
414+
415+ // Global config with plugins
416+ await Bun . write (
417+ path . join ( dir , "opencode.json" ) ,
418+ JSON . stringify ( {
419+ $schema : "https://opencode.ai/config.json" ,
420+ plugin : [ "global-plugin-1" , "global-plugin-2" ] ,
421+ } ) ,
422+ )
423+
424+ // Local .opencode config with different plugins
425+ await Bun . write (
426+ path . join ( opencodeDir , "opencode.json" ) ,
427+ JSON . stringify ( {
428+ $schema : "https://opencode.ai/config.json" ,
429+ plugin : [ "local-plugin-1" ] ,
430+ } ) ,
431+ )
432+ } ,
433+ } )
434+
435+ await Instance . provide ( {
436+ directory : path . join ( tmp . path , "project" ) ,
437+ fn : async ( ) => {
438+ const config = await Config . get ( )
439+ const plugins = config . plugin ?? [ ]
440+
441+ // Should contain both global and local plugins
442+ expect ( plugins . some ( ( p ) => p . includes ( "global-plugin-1" ) ) ) . toBe ( true )
443+ expect ( plugins . some ( ( p ) => p . includes ( "global-plugin-2" ) ) ) . toBe ( true )
444+ expect ( plugins . some ( ( p ) => p . includes ( "local-plugin-1" ) ) ) . toBe ( true )
445+
446+ // Should have all 3 plugins (not replaced, but merged)
447+ const pluginNames = plugins . filter ( ( p ) => p . includes ( "global-plugin" ) || p . includes ( "local-plugin" ) )
448+ expect ( pluginNames . length ) . toBeGreaterThanOrEqual ( 3 )
449+ } ,
450+ } )
451+ } )
452+
453+ test ( "deduplicates duplicate plugins from global and local configs" , async ( ) => {
454+ await using tmp = await tmpdir ( {
455+ init : async ( dir ) => {
456+ // Create a nested project structure with local .opencode config
457+ const projectDir = path . join ( dir , "project" )
458+ const opencodeDir = path . join ( projectDir , ".opencode" )
459+ await fs . mkdir ( opencodeDir , { recursive : true } )
460+
461+ // Global config with plugins
462+ await Bun . write (
463+ path . join ( dir , "opencode.json" ) ,
464+ JSON . stringify ( {
465+ $schema : "https://opencode.ai/config.json" ,
466+ plugin : [ "duplicate-plugin" , "global-plugin-1" ] ,
467+ } ) ,
468+ )
469+
470+ // Local .opencode config with some overlapping plugins
471+ await Bun . write (
472+ path . join ( opencodeDir , "opencode.json" ) ,
473+ JSON . stringify ( {
474+ $schema : "https://opencode.ai/config.json" ,
475+ plugin : [ "duplicate-plugin" , "local-plugin-1" ] ,
476+ } ) ,
477+ )
478+ } ,
479+ } )
480+
481+ await Instance . provide ( {
482+ directory : path . join ( tmp . path , "project" ) ,
483+ fn : async ( ) => {
484+ const config = await Config . get ( )
485+ const plugins = config . plugin ?? [ ]
486+
487+ // Should contain all unique plugins
488+ expect ( plugins . some ( ( p ) => p . includes ( "global-plugin-1" ) ) ) . toBe ( true )
489+ expect ( plugins . some ( ( p ) => p . includes ( "local-plugin-1" ) ) ) . toBe ( true )
490+ expect ( plugins . some ( ( p ) => p . includes ( "duplicate-plugin" ) ) ) . toBe ( true )
491+
492+ // Should deduplicate the duplicate plugin
493+ const duplicatePlugins = plugins . filter ( ( p ) => p . includes ( "duplicate-plugin" ) )
494+ expect ( duplicatePlugins . length ) . toBe ( 1 )
495+
496+ // Should have exactly 3 unique plugins
497+ const pluginNames = plugins . filter (
498+ ( p ) => p . includes ( "global-plugin" ) || p . includes ( "local-plugin" ) || p . includes ( "duplicate-plugin" ) ,
499+ )
500+ expect ( pluginNames . length ) . toBe ( 3 )
501+ } ,
502+ } )
503+ } )
0 commit comments