|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect } from 'vitest'; |
|
|
import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; |
|
|
|
|
|
describe('todo_write', () => { |
|
|
it('should be able to create and manage a todo list', async () => { |
|
|
const rig = new TestRig(); |
|
|
await rig.setup('should be able to create and manage a todo list'); |
|
|
|
|
|
const prompt = `I want to implement a new feature to track user preferences. Here are the tasks: |
|
|
1. Create a user preferences model |
|
|
2. Add API endpoints for preferences |
|
|
3. Implement frontend components |
|
|
4. Write tests for the new functionality |
|
|
|
|
|
Please create a todo list for these tasks.`; |
|
|
|
|
|
const result = await rig.run(prompt); |
|
|
|
|
|
const foundToolCall = await rig.waitForToolCall('todo_write'); |
|
|
|
|
|
|
|
|
if (!foundToolCall) { |
|
|
printDebugInfo(rig, result); |
|
|
} |
|
|
|
|
|
expect( |
|
|
foundToolCall, |
|
|
'Expected to find a todo_write tool call', |
|
|
).toBeTruthy(); |
|
|
|
|
|
|
|
|
validateModelOutput(result, null, 'Todo write test'); |
|
|
|
|
|
|
|
|
const toolLogs = rig.readToolLogs(); |
|
|
const todoWriteCalls = toolLogs.filter( |
|
|
(t) => t.toolRequest.name === 'todo_write', |
|
|
); |
|
|
|
|
|
expect(todoWriteCalls.length).toBeGreaterThan(0); |
|
|
|
|
|
|
|
|
const todoArgs = JSON.parse(todoWriteCalls[0].toolRequest.args); |
|
|
|
|
|
expect(todoArgs.todos).toBeDefined(); |
|
|
expect(Array.isArray(todoArgs.todos)).toBe(true); |
|
|
expect(todoArgs.todos.length).toBe(4); |
|
|
|
|
|
|
|
|
for (const todo of todoArgs.todos) { |
|
|
expect(todo.id).toBeDefined(); |
|
|
expect(todo.content).toBeDefined(); |
|
|
expect(['pending', 'in_progress', 'completed']).toContain(todo.status); |
|
|
} |
|
|
|
|
|
|
|
|
if (process.env['VERBOSE'] === 'true') { |
|
|
console.log('Todo list created successfully'); |
|
|
} |
|
|
}); |
|
|
|
|
|
it('should be able to update todo status', async () => { |
|
|
const rig = new TestRig(); |
|
|
await rig.setup('should be able to update todo status'); |
|
|
|
|
|
|
|
|
const initialPrompt = `Create a todo list with these tasks: |
|
|
1. Set up project structure |
|
|
2. Implement authentication |
|
|
3. Add database migrations`; |
|
|
|
|
|
await rig.run(initialPrompt); |
|
|
await rig.waitForToolCall('todo_write'); |
|
|
|
|
|
|
|
|
const updatePrompt = `I've started working on implementing authentication. Please update the todo list to reflect that.`; |
|
|
|
|
|
const result = await rig.run(updatePrompt); |
|
|
|
|
|
const foundToolCall = await rig.waitForToolCall('todo_write'); |
|
|
|
|
|
|
|
|
if (!foundToolCall) { |
|
|
printDebugInfo(rig, result); |
|
|
} |
|
|
|
|
|
expect( |
|
|
foundToolCall, |
|
|
'Expected to find a todo_write tool call', |
|
|
).toBeTruthy(); |
|
|
|
|
|
|
|
|
validateModelOutput(result, null, 'Todo update test'); |
|
|
|
|
|
|
|
|
const toolLogs = rig.readToolLogs(); |
|
|
const todoWriteCalls = toolLogs.filter( |
|
|
(t) => t.toolRequest.name === 'todo_write', |
|
|
); |
|
|
|
|
|
expect(todoWriteCalls.length).toBeGreaterThan(0); |
|
|
|
|
|
|
|
|
const todoArgs = JSON.parse( |
|
|
todoWriteCalls[todoWriteCalls.length - 1].toolRequest.args, |
|
|
); |
|
|
|
|
|
expect(todoArgs.todos).toBeDefined(); |
|
|
expect(Array.isArray(todoArgs.todos)).toBe(true); |
|
|
|
|
|
|
|
|
expect(todoArgs.todos.length).toBeGreaterThanOrEqual(1); |
|
|
|
|
|
|
|
|
for (const todo of todoArgs.todos) { |
|
|
expect(todo.id).toBeDefined(); |
|
|
expect(todo.content).toBeDefined(); |
|
|
expect(['pending', 'in_progress', 'completed']).toContain(todo.status); |
|
|
} |
|
|
|
|
|
|
|
|
if (process.env['VERBOSE'] === 'true') { |
|
|
console.log('Todo list updated successfully'); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|