test(token-meter): narrow optional projection state before checkpoint checks

The session projection API can return undefined when a unit is not registered. Assert the registered test fixture produced state before inspecting compact entries, rather than assuming a value that the current master type does not guarantee. This preserves the retained-state regression and adds no production fallback.

Validation: the aggregate build identified three TS2532 errors in this test; all context-breakdown projection cases pass after narrowing. Full build is rerun separately.
This commit is contained in:
Tianyi Cui committed 2026-09-07 11:09:40 +08:00
1 parent 1721a9c566
commit 84e94d8394
1 file changed
+5 -1
@@ -363,7 +363,11 @@ describe('contextBreakdown session projection', () => {
const first = appendUser(session, 'the first of many messages')
for (let index = 0; index < 24; index += 1) appendUser(session, `message number ${index} with some text`)
const last = appendUser(session, 'the last message before compaction')
const state = () => ctx.sessionProjections.stateOf(session, 'contextBreakdown')
const state = () => {
const current = ctx.sessionProjections.stateOf(session, 'contextBreakdown')
if (current === undefined) throw new Error('registered context breakdown has no state')
return current
}
expect(state().nodes).toHaveLength(26)
expect(Object.keys(state().nodes[0]!).sort()).toEqual(['heuristicTokens', 'seq', 'system'])
const shadowed = [...session.surface.nodes]