Files
tiny-worlds/test/check-reminder.mjs
T

52 lines
2.3 KiB
JavaScript
Raw Normal View History

// 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, listSessions } from '../server/session.mjs';
const runId = process.argv[2];
if (!runId) {
console.error('usage: node test/check-reminder.mjs <runId>');
process.exit(1);
}
// the newest session that has a log (a dormant latest has none)
let s = null;
for (const n of [...listSessions(runId)].reverse()) {
try {
s = loadSession(runId, n);
break;
} catch {}
}
if (!s) {
console.error(`no session log under runs/${runId}/sessions/*/log.jsonl`);
process.exit(1);
}
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 >= 1, `${logged}`);
2026-11-17 22:35:44 +00:00
// the sheet chunk (when the run keeps a ledger) is its own live
// system surface at the freshest end -- the reminder policy tolerates
// exactly one of them
const sheetChunks = sys.filter((m) => /^<sheet>/.test(String(m.content ?? '').trim()));
ok('view carries exactly two system chunks (the trio + the newest reminder)',
sys.length === 2 + sheetChunks.length && sheetChunks.length <= 1, `${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
2026-11-17 22:35:44 +00:00
// GM turn at the freshest end of the context. Only her latest reply
// and the sheet chunk may follow it
const ri = view.findIndex((m) => m.role === 'system' && /How to compose your turn/i.test(m.content));
2026-11-17 22:35:44 +00:00
const after = view.slice(ri + 1);
const tail = view.slice(-3).map((m) => m.role).join(',');
2026-11-17 22:35:44 +00:00
ok('the reminder rides at the freshest end',
after.every((m) => m.role === 'assistant' || (m.role === 'system' && /^<sheet>/.test(String(m.content ?? '').trim()))) && after.length <= 2, tail);
console.log(fails ? `\n${fails} FAILURES` : '\nALL PASS');
process.exit(fails ? 1 : 0);