refactor: 统一 log.ts/debug.ts 的测试 mock 为共享定义

- 新增 tests/mocks/log.ts 和 tests/mocks/debug.ts,覆盖源文件全部实际导出
- 移除旧 mock 中不存在的导出(logToFile、logEvent、getLogFilePath)
- 13 个测试文件改为使用共享 mock,避免定义分散和不一致

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-22 23:35:59 +08:00
parent 7ea69ca279
commit 1173a62301
16 changed files with 87 additions and 134 deletions

25
tests/mocks/debug.ts Normal file
View File

@@ -0,0 +1,25 @@
/**
* Shared mock for src/utils/debug.ts
*
* Cuts the bootstrap/state.ts dependency chain (module-level realpathSync + randomUUID).
* Must be called via mock.module("src/utils/debug.ts", debugMock) BEFORE any import that
* transitively depends on debug.ts.
*
* Exported as a factory so each call produces a fresh object (mock.module requirement).
*/
export function debugMock() {
return {
getMinDebugLogLevel: () => "debug" as const,
isDebugMode: () => false,
enableDebugLogging: () => false,
getDebugFilter: () => null,
isDebugToStdErr: () => false,
getDebugFilePath: () => null as string | null,
setHasFormattedOutput: () => {},
getHasFormattedOutput: () => false,
flushDebugLogs: async () => {},
logForDebugging: () => {},
getDebugLogPath: () => "/tmp/mock-debug.log",
logAntError: () => {},
}
}

24
tests/mocks/log.ts Normal file
View File

@@ -0,0 +1,24 @@
/**
* Shared mock for src/utils/log.ts
*
* Cuts the bootstrap/state.ts dependency chain (module-level realpathSync + randomUUID).
* Must be called via mock.module("src/utils/log.ts", logMock) BEFORE any import that
* transitively depends on log.ts.
*
* Exported as a factory so each call produces a fresh object (mock.module requirement).
*/
export function logMock() {
return {
logError: () => {},
getLogDisplayTitle: () => "",
dateToFilename: (d: Date) => d.toISOString().replace(/[:.]/g, "-"),
attachErrorLogSink: () => {},
getInMemoryErrors: () => [] as Array<{ error: string; timestamp: string }>,
loadErrorLogs: async () => [],
getErrorLogByIndex: async () => null,
logMCPError: () => {},
logMCPDebug: () => {},
captureAPIRequest: () => {},
_resetErrorLogForTesting: () => {},
}
}