Files
makelore/tests/unit/session-transcript-view-model.test.ts
inman 01bee3188b
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled
feat: integrate learning module
2026-08-16 20:52:16 +08:00

70 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { buildSessionTranscriptViewModel } from '@/pages/Chat/session-transcript-view-model';
import { hydrateOpenCodeSession } from '@/lib/opencode-session-state';
describe('session transcript view model', () => {
it('keeps the final answer separate from execution narration and native branches', () => {
const nativeTranscript = hydrateOpenCodeSession('ses_1', [{
info: { id: 'msg_1', role: 'assistant', sessionID: 'ses_1' },
parts: [
{ id: 'native_reasoning', type: 'reasoning', text: 'Inspecting the change.' },
{ id: 'native_narration', type: 'text', text: 'Reading the files first.' },
{ id: 'native_subtask', type: 'subtask', parentID: 'root', sessionID: 'ses_child' },
{ id: 'native_retry', type: 'retry', message: 'retrying' },
{ id: 'native_final', type: 'text', text: 'The change is ready.' },
],
}], 'retry');
const model = buildSessionTranscriptViewModel({
messages: [{
id: 'msg_1',
role: 'assistant',
content: [
{ type: 'text', text: 'Reading the files first.' },
{ type: 'tool_use', id: 'call_1', name: 'read_file', input: { path: 'src/app.ts' } },
{ type: 'text', text: 'The change is ready.' },
{ type: 'thinking', thinking: 'Inspecting the change.' },
],
}],
nativeTranscript,
active: true,
attention: [{ id: 'question_1', kind: 'question', sessionID: 'ses_1' }],
});
expect(model.finalAnswer).toBe('The change is ready.');
expect(model.finalAnswerMessageId).toBe('msg_1');
expect(model.executionTrace.map((item) => item.kind)).toEqual(expect.arrayContaining([
'narration',
'tool',
'subtask',
'retry',
]));
expect(model.reasoningBlocks).toHaveLength(1);
expect(model.reasoningBlocks[0]).toMatchObject({ collapsed: true });
expect(model.activeExecution).toBe(true);
expect(model.status).toBe('retry');
expect(model.attention).toEqual([{ id: 'question_1', kind: 'question', sessionID: 'ses_1' }]);
expect(model.nestedSubtasks).toEqual([
expect.objectContaining({ id: 'native_subtask', childSessionID: 'ses_child' }),
]);
});
it('does not project the compaction summary into execution trace', () => {
const nativeTranscript = hydrateOpenCodeSession('ses_1', [{
info: { id: 'msg_compaction', role: 'assistant', sessionID: 'ses_1' },
parts: [{
id: 'part_compaction',
type: 'compaction',
text: 'PRIVATE COMPACTION SUMMARY',
}],
}]);
const model = buildSessionTranscriptViewModel({
messages: [],
nativeTranscript,
});
expect(model.executionTrace).toEqual([]);
expect(model.reasoningBlocks).toEqual([]);
});
});