From 8ebb3ff0d4e2f8e4338ba09342921fd50a6c3672 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 17 Apr 2026 07:28:09 +0100 Subject: [PATCH] test: narrow message command mocks --- src/commands/message.test.ts | 45 +++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/commands/message.test.ts b/src/commands/message.test.ts index 45097c0fc48..27561583324 100644 --- a/src/commands/message.test.ts +++ b/src/commands/message.test.ts @@ -12,28 +12,46 @@ import { captureEnv } from "../test-utils/env.js"; let testConfig: Record = {}; const applyPluginAutoEnable = vi.hoisted(() => vi.fn(({ config }) => ({ config, changes: [] }))); -vi.mock("../config/config.js", async () => { - const actual = await vi.importActual("../config/config.js"); - return { - ...actual, - loadConfig: () => testConfig, - }; -}); +vi.mock("../config/config.js", () => ({ + loadConfig: () => testConfig, +})); vi.mock("../config/plugin-auto-enable.js", () => ({ applyPluginAutoEnable, })); -const { resolveCommandSecretRefsViaGateway, callGatewayMock } = vi.hoisted(() => ({ - resolveCommandSecretRefsViaGateway: vi.fn(async ({ config }: { config: unknown }) => ({ +const { resolveCommandConfigWithSecrets, callGatewayMock } = vi.hoisted(() => ({ + resolveCommandConfigWithSecrets: vi.fn(async ({ config }: { config: unknown }) => ({ resolvedConfig: config, + effectiveConfig: config, diagnostics: [] as string[], })), callGatewayMock: vi.fn(), })); -vi.mock("../cli/command-secret-gateway.js", () => ({ - resolveCommandSecretRefsViaGateway, +vi.mock("../cli/command-config-resolution.js", () => ({ + resolveCommandConfigWithSecrets: async (opts: { + autoEnable?: boolean; + config: unknown; + env?: NodeJS.ProcessEnv; + runtime?: { log: (message: string) => void }; + }) => { + const result = await resolveCommandConfigWithSecrets(opts); + for (const entry of result.diagnostics ?? []) { + opts.runtime?.log(`[secrets] ${entry}`); + } + const effectiveConfig = + opts.autoEnable === true + ? applyPluginAutoEnable({ + config: result.resolvedConfig, + env: opts.env ?? process.env, + }).config + : result.effectiveConfig; + return { + ...result, + effectiveConfig, + }; + }, })); vi.mock("../gateway/call.js", () => ({ @@ -68,7 +86,7 @@ beforeEach(() => { callGatewayMock.mockClear(); handleDiscordAction.mockClear(); handleTelegramAction.mockClear(); - resolveCommandSecretRefsViaGateway.mockClear(); + resolveCommandConfigWithSecrets.mockClear(); applyPluginAutoEnable.mockClear(); applyPluginAutoEnable.mockImplementation(({ config }) => ({ config, changes: [] })); }); @@ -203,8 +221,9 @@ function mockResolvedCommandConfig(params: { diagnostics?: string[]; }) { testConfig = params.rawConfig; - resolveCommandSecretRefsViaGateway.mockResolvedValueOnce({ + resolveCommandConfigWithSecrets.mockResolvedValueOnce({ resolvedConfig: params.resolvedConfig, + effectiveConfig: params.resolvedConfig, diagnostics: params.diagnostics ?? ["resolved channels.telegram.token"], }); }