fix: 修复 CI 中 10 个测试的 Bun mock.module 跨文件污染

- 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 <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-05-11 09:38:13 +08:00
parent 4a39fd74b1
commit 27a01113e4
2 changed files with 43 additions and 4 deletions

View File

@@ -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,