Files
brain/tools/secretary-transcript.test.mjs
T
Дмитрий 4253cd7114 fix(secretary): разбор хвоста пропускает tool_result (ловит промпт+действия), провенанс по реальному ходу, кириллица в имени дела
Корень бага: в формате Anthropic tool_result — сообщения role:user; parseLastExchange
брал их вместо настоящего промпта, теряя текст юзера и действия. + хук форсит реальный
turn (Хайку его не знает) + work-slug принимает кириллицу.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 07:21:09 +03:00

42 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import { parseLastExchange } from './secretary-transcript.mjs';
describe('parseLastExchange', () => {
it('тащит последний user + assistant + действия', () => {
const t = [
JSON.stringify({ message: { role: 'user', content: 'старое' } }),
JSON.stringify({ message: { role: 'user', content: 'привет' } }),
JSON.stringify({ message: { role: 'assistant', content: [
{ type: 'text', text: 'ответ' },
{ type: 'tool_use', name: 'Read', input: { f: 'x' } },
] } }),
].join('\n');
const ex = parseLastExchange(t);
expect(ex.user).toBe('привет');
expect(ex.assistant).toBe('ответ');
expect(ex.actions).toEqual([{ tool: 'Read', input: '{"f":"x"}' }]);
});
it('строковый content тоже понимает; битые строки пропускает', () => {
const t = ['не-json', JSON.stringify({ message: { role: 'user', content: 'у' } }),
JSON.stringify({ message: { role: 'assistant', content: 'а' } })].join('\n');
const ex = parseLastExchange(t);
expect(ex.user).toBe('у');
expect(ex.assistant).toBe('а');
expect(ex.actions).toEqual([]);
});
it('пропускает tool_result (role:user) — берёт настоящий промпт + все действия', () => {
const t = [
JSON.stringify({ message: { role: 'user', content: 'настоящий вопрос' } }),
JSON.stringify({ message: { role: 'assistant', content: [
{ type: 'text', text: 'думаю' }, { type: 'tool_use', name: 'Read', input: { f: 'a' } }] } }),
JSON.stringify({ message: { role: 'user', content: [{ type: 'tool_result', content: 'результат' }] } }),
JSON.stringify({ message: { role: 'assistant', content: [{ type: 'text', text: 'готово' }] } }),
].join('\n');
const ex = parseLastExchange(t);
expect(ex.user).toBe('настоящий вопрос');
expect(ex.assistant).toContain('думаю');
expect(ex.assistant).toContain('готово');
expect(ex.actions).toEqual([{ tool: 'Read', input: '{"f":"a"}' }]);
});
});