From 27a01113e427473caa094b234a90432bcc015b31 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Mon, 11 May 2026 09:38:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20CI=20=E4=B8=AD=2010?= =?UTF-8?q?=20=E4=B8=AA=E6=B5=8B=E8=AF=95=E7=9A=84=20Bun=20mock.module=20?= =?UTF-8?q?=E8=B7=A8=E6=96=87=E4=BB=B6=E6=B1=A1=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - thinking.test.ts: 补 envUtils.js 防御性 mock,提供 isEnvDefinedFalsy 和 isEnvTruthy 正确实现,覆盖 6 个其他测试文件不完整 mock 导致的污染 - launchLocalVault.test.ts: 补 keychain.js 防御性 mock,强制抛 KeychainUnavailableError 使 store 走文件回退路径,覆盖 store.test.ts 和 keychain.test.ts 的 mock 残留 Co-Authored-By: glm-5-turbo --- .../__tests__/launchLocalVault.test.ts | 27 ++++++++++++++++--- .../api/openai/__tests__/thinking.test.ts | 20 +++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/commands/local-vault/__tests__/launchLocalVault.test.ts b/src/commands/local-vault/__tests__/launchLocalVault.test.ts index 5d89b2f12..5f9482678 100644 --- a/src/commands/local-vault/__tests__/launchLocalVault.test.ts +++ b/src/commands/local-vault/__tests__/launchLocalVault.test.ts @@ -7,9 +7,30 @@ import { logMock } from '../../../../tests/mocks/log.js' mock.module('src/utils/log.ts', logMock) mock.module('bun:bundle', () => ({ feature: () => false })) -// No keychain mock here — the real store falls back to encrypted file when -// @napi-rs/keyring is not installed (which it is not in this environment). -// This exercises the full file-fallback path without cross-test module pollution. +// Re-register ../keychain.js to override pollution from store.test.ts (which +// mocks keychain as always-throwing) and keychain.test.ts (which mocks it with +// an in-memory MockEntry). Force KeychainUnavailableError so the store always +// uses the encrypted-file fallback path. +class KeychainUnavailableError extends Error { + override name = 'KeychainUnavailableError' +} + +const keychainUnavailable = async (): Promise => { + throw new KeychainUnavailableError('test: keychain mocked as unavailable') +} + +mock.module('../../../services/localVault/keychain.js', () => ({ + KeychainUnavailableError, + tryKeychain: { + set: keychainUnavailable, + get: keychainUnavailable, + delete: keychainUnavailable, + list: keychainUnavailable, + _addToIndex: keychainUnavailable, + _removeFromIndex: keychainUnavailable, + }, + _resetKeychainModuleCache: () => {}, +})) let callLocalVault: typeof import('../launchLocalVault.js').callLocalVault diff --git a/src/services/api/openai/__tests__/thinking.test.ts b/src/services/api/openai/__tests__/thinking.test.ts index a18dfb5d0..a1f477a18 100644 --- a/src/services/api/openai/__tests__/thinking.test.ts +++ b/src/services/api/openai/__tests__/thinking.test.ts @@ -1,9 +1,27 @@ -import { describe, expect, test, beforeEach, afterEach } from 'bun:test' +import { describe, expect, test, beforeEach, afterEach, mock } from 'bun:test' import { isOpenAIThinkingEnabled, buildOpenAIRequestBody, } from '../requestBody.js' +// Re-register envUtils.js with correct isEnvDefinedFalsy and isEnvTruthy to +// override pollution from other test files (debug-tool-call, issue, +// break-cache, MagicDocs/prompts, SessionMemory/prompts, cacheStats) that +// mock this module without exporting isEnvDefinedFalsy. +mock.module('src/utils/envUtils.js', () => ({ + isEnvTruthy: (v: string | boolean | undefined): boolean => { + if (!v) return false + if (typeof v === 'boolean') return v + return ['1', 'true', 'yes', 'on'].includes(v.toLowerCase().trim()) + }, + isEnvDefinedFalsy: (v: string | boolean | undefined): boolean => { + if (v === undefined) return false + if (typeof v === 'boolean') return !v + if (!v) return false + return ['0', 'false', 'no', 'off'].includes(v.toLowerCase().trim()) + }, +})) + describe('isOpenAIThinkingEnabled', () => { const originalEnv = { OPENAI_ENABLE_THINKING: process.env.OPENAI_ENABLE_THINKING,