// packages/core/src/tools/my-tool.test.ts
import { describe, it, expect, beforeEach } from 'vitest';
import { MyTool } from './my-tool.js';
import type { Config } from '../config/config.js';
describe('MyTool', () => {
let tool: MyTool;
let mockConfig: Config;
beforeEach(() => {
mockConfig = createMockConfig();
tool = new MyTool(mockConfig);
});
describe('parameter validation', () => {
it('should reject empty parameters', () => {
const params = { required: '' };
const error = tool.validateParams(params);
expect(error).toBeTruthy();
expect(error).toContain('must not be empty');
});
it('should accept valid parameters', () => {
const params = { required: 'value' };
const error = tool.validateParams(params);
expect(error).toBeNull();
});
});
describe('execution', () => {
it('should execute successfully with valid params', async () => {
const params = { required: 'value' };
const invocation = tool.invoke(params);
const result = await invocation.execute(
new AbortController().signal,
);
expect(result.error).toBeUndefined();
expect(result.llmContent).toContain('Success');
});
it('should handle errors gracefully', async () => {
const params = { required: 'invalid' };
const invocation = tool.invoke(params);
const result = await invocation.execute(
new AbortController().signal,
);
expect(result.error).toBeDefined();
expect(result.error.type).toBe('EXECUTION_ERROR');
});
});
});