From b691380914685b3904bb161ba798b57b3ce61dd2 Mon Sep 17 00:00:00 2001 From: zm2231 Date: Fri, 20 Mar 2026 23:24:03 -0400 Subject: [PATCH] test: cover cli managed runtime wiring --- tests/cli-managed-runtime.test.ts | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/cli-managed-runtime.test.ts diff --git a/tests/cli-managed-runtime.test.ts b/tests/cli-managed-runtime.test.ts new file mode 100644 index 0000000..6db8681 --- /dev/null +++ b/tests/cli-managed-runtime.test.ts @@ -0,0 +1,43 @@ +import { describe, expect, it, vi } from 'vitest'; + +process.env.MCPORTER_DISABLE_AUTORUN = '1'; +process.env.MCPORTER_NO_FORCE_EXIT = '1'; + +const runtime = { + getDefinitions: vi.fn(() => []), + close: vi.fn(async () => undefined), +}; + +const createManagedRuntimeMock = vi.fn(async () => runtime); +const createRuntimeMock = vi.fn(async () => runtime); +const handleListMock = vi.fn(async () => undefined); + +vi.mock('../src/runtime.js', async () => { + const actual = await vi.importActual('../src/runtime.js'); + return { + ...actual, + createManagedRuntime: createManagedRuntimeMock, + createRuntime: createRuntimeMock, + }; +}); + +vi.mock('../src/cli/list-command.js', async () => { + const actual = await vi.importActual('../src/cli/list-command.js'); + return { + ...actual, + handleList: handleListMock, + }; +}); + +describe('mcporter CLI managed runtime wiring', () => { + it('uses createManagedRuntime for normal CLI commands', async () => { + const { runCli } = await import('../src/cli.js'); + + await runCli(['list']); + + expect(createManagedRuntimeMock).toHaveBeenCalledTimes(1); + expect(createRuntimeMock).not.toHaveBeenCalled(); + expect(handleListMock).toHaveBeenCalledWith(runtime, []); + expect(runtime.close).toHaveBeenCalledTimes(1); + }); +});