11import { expect , test } from "bun:test"
22import path from "node:path"
3- import { mkdir } from "node:fs/promises"
3+ import { mkdir , realpath } from "node:fs/promises"
44import { parse , type ParseError } from "jsonc-parser"
55import { configuredServers , removeServer } from "../src/commands/handlers/mcp/remove"
6- import { tmpdir } from "../../core/test /fixture/tmpdir"
6+ import { tmpdir } from "./fixture/tmpdir"
77import { isolatedEnv } from "./fixture/environment"
88
99test ( "removes only the selected local non-OAuth server, preserving JSONC and unrelated settings" , async ( ) => {
@@ -37,8 +37,9 @@ test("removes only the selected local non-OAuth server, preserving JSONC and unr
3737
3838test ( "enumerates native and legacy entries by source, including reserved legacy server names" , async ( ) => {
3939 await using tmp = await tmpdir ( )
40- const global = path . join ( tmp . path , "global" )
41- const project = path . join ( tmp . path , "project" )
40+ const root = await realpath ( tmp . path )
41+ const global = path . join ( root , "global" )
42+ const project = path . join ( root , "project" )
4243 const directory = path . join ( project , "nested" )
4344 await mkdir ( directory , { recursive : true } )
4445 const files = [
@@ -115,7 +116,7 @@ test("warns and skips malformed files during discovery, but refuses a malformed
115116 expect ( await Bun . file ( file ) . text ( ) ) . toBe ( broken )
116117} )
117118
118- test ( "CLI rejects ambiguous names without edits and removes one global legacy entry with --yes " , async ( ) => {
119+ test ( "CLI rejects unknown or ambiguous names without edits and removes one scoped legacy entry" , async ( ) => {
119120 await using tmp = await tmpdir ( )
120121 const global = path . join ( tmp . path , "config" )
121122 const directory = path . join ( tmp . path , "project" )
@@ -124,7 +125,7 @@ test("CLI rejects ambiguous names without edits and removes one global legacy en
124125 const globalFile = path . join ( global , "opencode.json" )
125126 await Bun . write ( projectFile , JSON . stringify ( config ) )
126127 await Bun . write ( globalFile , JSON . stringify ( config ) )
127- const cli = async ( args : string [ ] ) => {
128+ const cli = async ( args : string [ ] , name = "paper" ) => {
128129 const child = Bun . spawn (
129130 [
130131 process . execPath ,
@@ -134,7 +135,7 @@ test("CLI rejects ambiguous names without edits and removes one global legacy en
134135 path . join ( import . meta. dir , "../src/index.ts" ) ,
135136 "mcp" ,
136137 "remove" ,
137- "paper" ,
138+ name ,
138139 "--yes" ,
139140 ...args ,
140141 ] ,
@@ -152,8 +153,13 @@ test("CLI rejects ambiguous names without edits and removes one global legacy en
152153 expect ( ambiguous . code ) . toBe ( 1 )
153154 expect ( await Bun . file ( projectFile ) . json ( ) ) . toEqual ( config )
154155 expect ( await Bun . file ( globalFile ) . json ( ) ) . toEqual ( config )
156+ const unknown = await cli ( [ "--global" ] , "missing" )
157+ expect ( unknown . stderr ) . toBe ( "" )
158+ expect ( unknown . stdout ) . toContain ( 'MCP server "missing" is not configured in the selected scope' )
159+ expect ( unknown . code ) . toBe ( 1 )
160+ expect ( await Bun . file ( globalFile ) . json ( ) ) . toEqual ( config )
155161 const removed = await cli ( [ "--global" ] )
156- expect ( removed . stdout ) . toContain ( `removed from ${ globalFile } ` )
162+ expect ( removed . stdout ) . toContain ( `removed from ${ await realpath ( globalFile ) } ` )
157163 expect ( removed . stderr ) . toBe ( "" )
158164 expect ( removed . code ) . toBe ( 0 )
159165 expect ( await Bun . file ( globalFile ) . json ( ) ) . toEqual ( { mcp : { } } )
0 commit comments