Files
claude-code/packages/agent-tools/src/__tests__/compat.test.ts
claude-code-best 1a4e9702c2 fix: 修复类型问题(#267) (#271)
* fix: 修复 Bun 的 polyfill 问题

* fix: 类型修复完成

* feat: 统一所有包的类型文件

* fix: 修复构建问题
2026-04-15 10:54:00 +08:00

35 lines
1.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import type { CoreTool, Tool, Tools, AnyObject, ToolResult, ValidationResult, PermissionResult } from '@claude-code-best/agent-tools'
import type { Tool as HostTool } from '../../../../src/Tool.js'
describe('agent-tools compatibility', () => {
test('CoreTool structural compatibility with host Tool', () => {
// The host's Tool should structurally satisfy CoreTool
// because it has all required fields (name, call, description, etc.)
// This test verifies the type-level compatibility at runtime
const mockHostTool: HostTool = {
name: 'test',
aliases: [],
searchHint: 'test tool',
inputSchema: {} as any,
async call() { return { data: 'ok' } as any },
async description() { return 'test' },
async prompt() { return 'test prompt' },
isConcurrencySafe: () => false,
isEnabled: () => true,
isReadOnly: () => false,
async checkPermissions() { return { behavior: 'allow' as const, updatedInput: {} } },
toAutoClassifierInput: () => '',
userFacingName: () => 'test',
maxResultSizeChars: 100000,
mapToolResultToToolResultBlockParam: () => ({ type: 'tool_result', tool_use_id: '1', content: 'ok' }),
renderToolUseMessage: () => null,
}
// This assignment should work if HostTool structurally extends CoreTool
const coreTool: CoreTool = mockHostTool as unknown as CoreTool
expect(coreTool.name).toBe('test')
expect(coreTool.isEnabled()).toBe(true)
})
})