import { describe, it, expect } from 'vitest';
import { parseXmlToolCalls } from '../src/parsers/xml-toolcall';
describe('XML ToolCall Parser', () => {
it('parses basic XML tool call correctly', () => {
const content = `
/tmp/test.txt
`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(1);
expect(result[0].name).toBe('read');
expect(result[0].args).toEqual({ path: '/tmp/test.txt' });
});
it('parses multiple parameters correctly', () => {
const content = `
/tmp/a.txt
hello
`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(1);
expect(result[0].name).toBe('write');
expect(result[0].args).toEqual({
path: '/tmp/a.txt',
content: 'hello'
});
});
it('ignores normal text', () => {
const content = `I will read the file. Let me check the system.`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(0);
});
it('parses JSON tool calls wrapped in tool_call tags', () => {
const content = `
{"name":"read","arguments":{"path":"/tmp/test.txt"}}
`;
const result = parseXmlToolCalls(content);
expect(result).toHaveLength(1);
expect(result[0].name).toBe('read');
expect(result[0].args).toEqual({ path: '/tmp/test.txt' });
});
});