feat: integrate learning module
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { applyStreamingPartDeltaToMessage, normalizeOpencodeSessionMessages } from '@/lib/opencode-message';
|
||||
import {
|
||||
applyStreamingPartDeltaToMessage,
|
||||
applyStreamingPartToMessage,
|
||||
normalizeOpencodeSessionMessages,
|
||||
} from '@/lib/opencode-message';
|
||||
|
||||
describe('opencode message normalization', () => {
|
||||
it('keeps reasoning deltas as thinking content when the full part has not arrived yet', () => {
|
||||
@@ -77,6 +81,71 @@ describe('opencode message normalization', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps compaction-only messages out of the visible transcript', () => {
|
||||
const messages = normalizeOpencodeSessionMessages([
|
||||
{
|
||||
info: {
|
||||
id: 'msg_compaction',
|
||||
role: 'assistant',
|
||||
sessionID: 'ses_1',
|
||||
time: { created: 1747040000000, completed: 1747040001000 },
|
||||
},
|
||||
parts: [
|
||||
{
|
||||
id: 'part_compaction',
|
||||
type: 'compaction',
|
||||
auto: true,
|
||||
summary: 'PRIVATE COMPACTION SUMMARY',
|
||||
},
|
||||
{ id: 'step_finish', type: 'step-finish' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'legacy_compaction',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'compaction', text: 'PRIVATE LEGACY SUMMARY' }],
|
||||
},
|
||||
]);
|
||||
|
||||
expect(messages).toEqual([]);
|
||||
expect(JSON.stringify(messages)).not.toContain('PRIVATE COMPACTION SUMMARY');
|
||||
expect(JSON.stringify(messages)).not.toContain('PRIVATE LEGACY SUMMARY');
|
||||
});
|
||||
|
||||
it('does not leak compaction text through streaming message projections', () => {
|
||||
const input = {
|
||||
sessionID: 'ses_1',
|
||||
messageID: 'msg_compaction',
|
||||
partID: 'part_compaction',
|
||||
delta: 'PRIVATE COMPACTION SUMMARY',
|
||||
part: {
|
||||
id: 'part_compaction',
|
||||
type: 'compaction',
|
||||
},
|
||||
};
|
||||
|
||||
expect(applyStreamingPartToMessage(null, input)).toBeNull();
|
||||
expect(applyStreamingPartDeltaToMessage(null, input)).toBeNull();
|
||||
expect(applyStreamingPartDeltaToMessage({
|
||||
id: 'msg_compaction',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'text', text: 'Visible text' }],
|
||||
}, input)).toEqual({
|
||||
id: 'msg_compaction',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'text', text: 'Visible text' }],
|
||||
});
|
||||
expect(applyStreamingPartToMessage({
|
||||
id: 'msg_compaction',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'text', id: 'part_compaction', text: 'PRIVATE COMPACTION SUMMARY' }],
|
||||
}, input)).toEqual({
|
||||
id: 'msg_compaction',
|
||||
role: 'assistant',
|
||||
content: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('retains bounded runtime tool evidence without exposing raw tool state', () => {
|
||||
const messages = normalizeOpencodeSessionMessages([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user