From 205be5e78e18b63dd492813aea843eee973ae0c6 Mon Sep 17 00:00:00 2001 From: maplezzk <34745236+maplezzk@users.noreply.github.com> Date: Fri, 30 Oct 2026 21:43:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E6=97=B6=E7=A9=BA=E5=8F=82=E6=95=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/server.ts | 2 +- src/tests/integration/server-cli.test.ts | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/tests/integration/server-cli.test.ts diff --git a/src/commands/server.ts b/src/commands/server.ts index c1c2897..852e1c0 100644 --- a/src/commands/server.ts +++ b/src/commands/server.ts @@ -231,7 +231,7 @@ export const registerServerCommands = (program: Command) => { if (transport !== 'stdio' && (options.env || options.cwd !== undefined || options.args)) throw new Error('env, cwd and args require a stdio server'); if (transport === 'stdio' && (options.header || auth)) throw new Error('Headers and OAuth require an HTTP/SSE server'); if (options.command) updates.command = options.command; - if (options.args) updates.args = options.args; + if (options.args !== undefined) updates.args = options.args === true ? [] : options.args; if (options.url) updates.url = options.url; if (options.type) updates.type = options.type; if (options.cwd !== undefined) updates.cwd = options.cwd; diff --git a/src/tests/integration/server-cli.test.ts b/src/tests/integration/server-cli.test.ts new file mode 100644 index 0000000..f469b52 --- /dev/null +++ b/src/tests/integration/server-cli.test.ts @@ -0,0 +1,39 @@ +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import { mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { resolve, join } from 'node:path'; +import { spawnSync } from 'node:child_process'; + +describe('server update CLI', () => { + const directory = mkdtempSync(join(tmpdir(), 'mcps-update-')); + const config = join(directory, 'mcp.json'); + const original = { mcpServers: { fixture: { command: 'node', args: ['old'] } } }; + const run = (...args: string[]) => spawnSync(process.execPath, + [resolve('dist/index.js'), 'update', 'fixture', ...args], + { env: { ...process.env, MCPS_CONFIG_DIR: directory }, encoding: 'utf8', timeout: 5000 }); + const saved = () => JSON.parse(readFileSync(config, 'utf8')).mcpServers.fixture; + + beforeAll(() => writeFileSync(config, JSON.stringify(original))); + afterAll(() => rmSync(directory, { recursive: true, force: true })); + + it('keeps omitted arguments, clears bare --args, and preserves an explicit empty argument', () => { + expect(run('--command', 'node').status).toBe(0); + expect(saved().args).toEqual(['old']); + expect(run('--args').status).toBe(0); + expect(saved().args).toEqual([]); + expect(run('--args', '').status).toBe(0); + expect(saved().args).toEqual(['']); + expect(run('--args', 'new').status).toBe(0); + expect(saved().args).toEqual(['new']); + }); + + it('returns nonzero for an invalid update and preserves the previous configuration', () => { + writeFileSync(config, JSON.stringify(original)); + const before = readFileSync(config, 'utf8'); + const result = run('--url', 'not-a-url'); + expect(result.error).toBeUndefined(); + expect(result.status).toBeGreaterThan(0); + expect(result.stderr).toContain('Error updating server'); + expect(readFileSync(config, 'utf8')).toBe(before); + }); +});