openpencil/tests/engine/tools/registry.test.ts
Danila Poyarkov 4a9bad5cec refactor(tools)!: centralize schemas and execution contracts
Define native Valibot inputs and execution/exposure metadata on each tool. Derive effects and default capabilities, consume upstream Standard Schema conversion, and validate finite numeric inputs consistently across adapters.

Move atomic execution to Core and restore failures from Scene Graph checkpoints without relying on a property diff. Preserve topology, collections, indexes and surviving object identities during rollback.

BREAKING CHANGE: custom tools use input schemas and execution metadata instead of params, ParamDef and independently declared mutation flags. Direct tool execution validates inputs before invoking the handler.
2026-09-15 10:55:27 +03:00

35 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
// eslint-disable-next-line open-pencil/no-mixed-case-acronym-identifiers -- Upstream export spelling.
import { toJsonSchema as toJSONSchema } from '@valibot/to-json-schema'
import { isAtomicTool } from '@open-pencil/core/tools'
import { ALL_TOOLS } from '#tests/helpers/tools'
describe('tool definitions', () => {
test('all tools have unique names and native input schemas', () => {
const names = ALL_TOOLS.map((tool) => tool.name)
expect(new Set(names).size).toBe(names.length)
for (const tool of ALL_TOOLS) {
expect(tool.name).toBeTruthy()
expect(tool.description).toBeTruthy()
expect(typeof tool.execute).toBe('function')
expect(toJSONSchema(tool.input, { typeMode: 'input' }).type).toBe('object')
}
})
test('browser exposure is explicit and restricted to inspection or atomic property edits', () => {
for (const tool of ALL_TOOLS) {
expect(tool.mutates).toBe(tool.execution.mutation !== 'none')
if (!tool.exposure.webmcp) continue
expect(tool.execution.mutation === 'none' || isAtomicTool(tool)).toBe(true)
expect(
tool.capabilities.every(
(capability) => capability === 'document:read' || capability === 'document:write'
)
).toBe(true)
}
})
})