25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { createContextManager } = require('../src/context');
|
|
|
|
test('context: long history is compressed into summary + recent', async () => {
|
|
const llm = { async chat() { return { content: 'Customer wants wholesale earrings.' }; } };
|
|
const cm = createContextManager();
|
|
const history = [];
|
|
for (let i = 0; i < 30; i += 1) history.push({ role: i % 2 ? 'assistant' : 'user', content: `message ${i}` });
|
|
const out = await cm.compressHistory('conv-1', history, llm);
|
|
assert.equal(out[0].role, 'system');
|
|
assert.match(out[0].content, /Earlier conversation summary/);
|
|
assert.equal(out.length, 17); // 1 summary + 16 recent
|
|
assert.equal(out[out.length - 1].content, 'message 29');
|
|
});
|
|
|
|
test('context: short history is unchanged', async () => {
|
|
const cm = createContextManager();
|
|
const history = [{ role: 'user', content: 'hi' }, { role: 'assistant', content: 'hello' }];
|
|
const out = await cm.compressHistory('c2', history, { async chat() { throw new Error('should not call'); } });
|
|
assert.equal(out.length, 2);
|
|
});
|