Files
claude-code/tests/mocks/toolContext.ts
unraid 8945f08708 feat: integrate fork work onto upstream main (squashed)
Squash-merge of feat/autofix-pr-test (69 commits) onto upstream/main
with -X ours strategy (upstream as authoritative for content conflicts).

Key features brought in from fork:
- LocalMemoryRecall + VaultHttpFetch tools (end-to-end wired)
- /local-memory, /local-vault, /memory-stores, /skill-store interactive panels
- /agents-platform, /schedule, /vault command scaffolding
- /login: switch / replace / remove of workspace API key
- statusline refactor (built-in status row, /statusline as info command)
- autofix-pr command + workflow

Conflict resolutions (upstream-wins):
- 10 .js command stubs kept from upstream (alongside fork's .ts implementations)
- src/components/BuiltinStatusLine.tsx accepted upstream's deletion
  (fork's wire-up references in StatusLine.tsx will be cleaned up next)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 14:58:26 +08:00

53 lines
1.5 KiB
TypeScript

/**
* 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
}