open-design/apps/web/tests/runtime/todos.test.ts
marco 5dd70b5016
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
github-metrics / Generate repository metrics SVG (push) Failing after 2m3s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 11s
Initial import: open-design source for helix-mind.ai distribution
This repository contains the open-design daemon CLI source code, built
and packaged at https://helix-mind.ai/cli/open-design/latest.tgz for use
by the HelixMind /design slash command.

Licenses: Apache-2.0 (root) + MIT (skills/*)
2026-05-06 20:50:24 +02:00

85 lines
2.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
latestTodosFromEvents,
parseTodoWriteInput,
unfinishedTodosFromEvents,
} from '../../src/runtime/todos';
import type { AgentEvent } from '../../src/types';
const firstTodoInput = {
todos: [
{ content: 'Draft layout', status: 'completed' },
{ content: 'Build components', status: 'in_progress', activeForm: 'Building components' },
{ content: 'Run QA', status: 'pending' },
{ content: '', status: 'pending' },
{ content: 'Unknown status defaults pending', status: 'blocked' },
null,
],
};
describe('todo event helpers', () => {
it('normalizes TodoWrite input and ignores malformed items', () => {
expect(parseTodoWriteInput(firstTodoInput)).toEqual([
{ content: 'Draft layout', status: 'completed', activeForm: undefined },
{
content: 'Build components',
status: 'in_progress',
activeForm: 'Building components',
},
{ content: 'Run QA', status: 'pending', activeForm: undefined },
{
content: 'Unknown status defaults pending',
status: 'pending',
activeForm: undefined,
},
]);
});
it('uses the latest TodoWrite event as the current todo truth', () => {
const events: AgentEvent[] = [
{ kind: 'tool_use', id: 'todo-1', name: 'TodoWrite', input: firstTodoInput },
{ kind: 'text', text: 'Working...' },
{ kind: 'tool_use', id: 'todo-empty', name: 'TodoWrite', input: { todos: [] } },
{
kind: 'tool_use',
id: 'todo-2',
name: 'TodoWrite',
input: { todos: [{ content: 'Final polish', status: 'pending' }] },
},
];
expect(latestTodosFromEvents(events)).toEqual([
{ content: 'Final polish', status: 'pending', activeForm: undefined },
]);
});
it('treats an empty latest TodoWrite event as authoritative', () => {
const events: AgentEvent[] = [
{ kind: 'tool_use', id: 'todo-1', name: 'TodoWrite', input: firstTodoInput },
{ kind: 'text', text: 'All done.' },
{ kind: 'tool_use', id: 'todo-empty', name: 'TodoWrite', input: { todos: [] } },
];
expect(latestTodosFromEvents(events)).toEqual([]);
expect(unfinishedTodosFromEvents(events)).toEqual([]);
});
it('returns only pending and in-progress todos as unfinished', () => {
expect(unfinishedTodosFromEvents([
{ kind: 'tool_use', id: 'todo-1', name: 'TodoWrite', input: firstTodoInput },
])).toEqual([
{
content: 'Build components',
status: 'in_progress',
activeForm: 'Building components',
},
{ content: 'Run QA', status: 'pending', activeForm: undefined },
{
content: 'Unknown status defaults pending',
status: 'pending',
activeForm: undefined,
},
]);
});
});