// import { describe, it, expect } from '@jest/globals'
import {
toolDefinitions,
tools,
getToolsMetadata,
isValidToolName,
runPipeline
} from '../../src/pipeline'
describe('Tool Definitions', () => {
it('should have correct structure for all tools', () => {
expect(toolDefinitions.compare_texts).toBeDefined()
expect(toolDefinitions.get_detailed_diff).toBeDefined()
expect(toolDefinitions.compare_texts.pipeline).toBeInstanceOf(Array)
expect(typeof toolDefinitions.compare_texts.description).toBe('string')
expect(typeof toolDefinitions.compare_texts.inputSchema).toBe('object')
expect(toolDefinitions.get_detailed_diff.pipeline).toBeInstanceOf(Array)
expect(typeof toolDefinitions.get_detailed_diff.description).toBe('string')
expect(typeof toolDefinitions.get_detailed_diff.inputSchema).toBe('object')
})
it('should have valid input schemas', () => {
const compareSchema = toolDefinitions.compare_texts.inputSchema
expect(compareSchema.type).toBe('object')
expect(compareSchema.properties.text1).toBeDefined()
expect(compareSchema.properties.text2).toBeDefined()
expect(compareSchema.required).toContain('text1')
expect(compareSchema.required).toContain('text2')
const diffSchema = toolDefinitions.get_detailed_diff.inputSchema
expect(diffSchema.type).toBe('object')
expect(diffSchema.properties.text1).toBeDefined()
expect(diffSchema.properties.text2).toBeDefined()
expect(diffSchema.required).toContain('text1')
expect(diffSchema.required).toContain('text2')
})
})
describe('Tool Name Validation', () => {
it('should validate known tool names', () => {
expect(isValidToolName('compare_texts')).toBe(true)
expect(isValidToolName('get_detailed_diff')).toBe(true)
})
it('should reject unknown tool names', () => {
expect(isValidToolName('unknown_tool')).toBe(false)
expect(isValidToolName('')).toBe(false)
expect(isValidToolName('compare-texts')).toBe(false) // wrong format
})
it('should be case sensitive', () => {
expect(isValidToolName('Compare_Texts')).toBe(false)
expect(isValidToolName('COMPARE_TEXTS')).toBe(false)
})
})
describe('Tool Execution', () => {
it('should execute compare_texts pipeline', () => {
const args = {
text1: 'Hello World',
text2: 'Hello World'
}
const result = tools.compare_texts(args)
expect(result.identical).toBe(true)
})
it('should execute get_detailed_diff pipeline', () => {
const args = {
text1: 'Hello World',
text2: 'Hello World!',
includeFormattedOutput: true
}
const result = tools.get_detailed_diff(args)
expect(result.identical).toBe(false)
expect(result.differences).toBeDefined()
expect(result.formattedDiff).toBeDefined()
})
it('should reject unknown tools', () => {
const args = {
text1: 'Hello',
text2: 'World'
}
expect(() => (tools as any).unknown_tool(args)).toThrow()
})
})
describe('Pipeline Composition', () => {
it('should compose compare_texts pipeline correctly', () => {
const pipeline = toolDefinitions.compare_texts.pipeline
expect(pipeline).toHaveLength(3) // validate, normalize, compare
const result = runPipeline(pipeline)({ text1: 'Hello', text2: 'Hello' })
expect(result.identical).toBe(true)
})
it('should compose get_detailed_diff pipeline correctly', () => {
const pipeline = toolDefinitions.get_detailed_diff.pipeline
expect(pipeline).toHaveLength(4) // validate, normalize, calculate, format
const result = runPipeline(pipeline)({
text1: 'Hello',
text2: 'Hello!',
includeFormattedOutput: true
})
expect(result.identical).toBe(false)
expect(result.formattedDiff).toBeDefined()
})
it('should handle pipeline stage errors', () => {
const invalidArgs = { text1: 'Hello' } // missing text2
expect(() => runPipeline(toolDefinitions.compare_texts.pipeline)(invalidArgs))
.toThrow()
})
})
describe('Tool Metadata', () => {
it('should generate correct tool metadata', () => {
const metadata = getToolsMetadata()
expect(metadata.tools).toHaveLength(2)
expect(metadata.tools[0].name).toBe('compare_texts')
expect(metadata.tools[1].name).toBe('get_detailed_diff')
metadata.tools.forEach(tool => {
expect(typeof tool.name).toBe('string')
expect(typeof tool.description).toBe('string')
expect(typeof tool.inputSchema).toBe('object')
})
})
it('should have consistent metadata with tool definitions', () => {
const metadata = getToolsMetadata()
metadata.tools.forEach(tool => {
const definition = toolDefinitions[tool.name as keyof typeof toolDefinitions]
expect(definition).toBeDefined()
expect(tool.description).toBe(definition.description)
expect(tool.inputSchema).toEqual(definition.inputSchema)
})
})
})