mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 08:15:53 +00:00
chore: 添加 CI 配置、codecov 和测试 mock 基础设施
Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
This commit is contained in:
52
tests/mocks/toolContext.ts
Normal file
52
tests/mocks/toolContext.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Shared minimal ToolUseContext stub for tool unit tests.
|
||||
*
|
||||
* Provides only the fields tools actually access in tests:
|
||||
* - getAppState() returns a context with empty rule arrays for every source
|
||||
* - toolUseId / parentMessageId / assistantMessageId / turnId can be
|
||||
* overridden per test for budget tracking tests
|
||||
*
|
||||
* Usage:
|
||||
* import { mockToolContext } from 'tests/mocks/toolContext'
|
||||
* const ctx = mockToolContext({ toolUseId: 't1' })
|
||||
*
|
||||
* Per memory feedback "Mock dependency not subject" — this exists so each
|
||||
* tool test file does not redefine the same partial stub.
|
||||
*/
|
||||
|
||||
const emptyRules = {
|
||||
user: [],
|
||||
project: [],
|
||||
local: [],
|
||||
session: [],
|
||||
cliArg: [],
|
||||
}
|
||||
|
||||
export interface MockToolContextOptions {
|
||||
toolUseId?: string
|
||||
parentMessageId?: string
|
||||
assistantMessageId?: string
|
||||
turnId?: string
|
||||
/** Override toolPermissionContext fields (e.g. mode, alwaysAllowRules). */
|
||||
permissionOverrides?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export function mockToolContext(opts: MockToolContextOptions = {}): never {
|
||||
return {
|
||||
toolUseId: opts.toolUseId,
|
||||
parentMessageId: opts.parentMessageId,
|
||||
assistantMessageId: opts.assistantMessageId,
|
||||
turnId: opts.turnId,
|
||||
getAppState: () => ({
|
||||
toolPermissionContext: {
|
||||
mode: 'default',
|
||||
additionalWorkingDirectories: new Set(),
|
||||
alwaysAllowRules: { ...emptyRules },
|
||||
alwaysDenyRules: { ...emptyRules },
|
||||
alwaysAskRules: { ...emptyRules },
|
||||
isBypassPermissionsModeAvailable: false,
|
||||
...(opts.permissionOverrides ?? {}),
|
||||
},
|
||||
}),
|
||||
} as never
|
||||
}
|
||||
Reference in New Issue
Block a user