35 lines
1.8 KiB
JavaScript
35 lines
1.8 KiB
JavaScript
|
|
// test/check-reminder.mjs — unit-verifies the reminder elision
|
||
|
|
// policy: the live context carries exactly one reminder (the newest),
|
||
|
|
// sitting at the freshest end, next to the one system trio from the
|
||
|
|
// bundle. Run against a run id that has GM turns:
|
||
|
|
// node test/check-reminder.mjs <runId>
|
||
|
|
|
||
|
|
import { loadSession, renderView } from '../server/session.mjs';
|
||
|
|
import { readdirSync } from 'node:fs';
|
||
|
|
import { fileURLToPath } from 'node:url';
|
||
|
|
import { join, dirname } from 'node:path';
|
||
|
|
|
||
|
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||
|
|
const runId = process.argv[2];
|
||
|
|
const dir = join(ROOT, 'runs', runId, 'sessions');
|
||
|
|
const latest = readdirSync(dir).filter((f) => f.endsWith('.jsonl')).sort().pop().replace(/\.jsonl$/, '');
|
||
|
|
const s = loadSession(runId, latest);
|
||
|
|
const view = renderView(s);
|
||
|
|
const sys = view.filter((m) => m.role === 'system');
|
||
|
|
let fails = 0;
|
||
|
|
const ok = (name, cond, extra = '') => {
|
||
|
|
console.log(`${cond ? 'PASS' : 'FAIL'} ${name}${extra ? ` — ${extra}` : ''}`);
|
||
|
|
if (!cond) fails++;
|
||
|
|
};
|
||
|
|
const logged = s.lines.filter((e) => e.reminder).length;
|
||
|
|
ok(`log keeps every copy (${logged})`, logged >= 5, `${logged}`);
|
||
|
|
ok('view carries exactly two system chunks (the trio + the newest reminder)', sys.length === 2, `${sys.length}`);
|
||
|
|
// mid-call the reminder is the last message; after the model's reply it
|
||
|
|
// sits immediately before that reply — either way it follows the newest
|
||
|
|
// GM turn at the freshest end of the context
|
||
|
|
const ri = view.findIndex((m) => m.role === 'system' && /How to compose your turn/i.test(m.content));
|
||
|
|
const tail = view.slice(-3).map((m) => m.role).join(',');
|
||
|
|
ok('the reminder rides at the freshest end', (ri === view.length - 1) || (ri === view.length - 2 && view[view.length - 1].role === 'assistant'), tail);
|
||
|
|
console.log(fails ? `\n${fails} FAILURES` : '\nALL PASS');
|
||
|
|
process.exit(fails ? 1 : 0);
|