From 399d7313c4f3084ae52e94d33105a57159586d79 Mon Sep 17 00:00:00 2001 From: Dudu-0223 Date: Mon, 7 Sep 2026 16:14:58 +0800 Subject: [PATCH] test(session): cover historical catalog comparison failures --- .../session-snapshot/tests/normalize.spec.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/test-support/session-snapshot/tests/normalize.spec.ts b/packages/test-support/session-snapshot/tests/normalize.spec.ts index cfc02aaeab..e6594ea603 100644 --- a/packages/test-support/session-snapshot/tests/normalize.spec.ts +++ b/packages/test-support/session-snapshot/tests/normalize.spec.ts @@ -684,6 +684,43 @@ describe('normalizeSessionSnapshot', () => { ].join('\n')) }) + it('rejects an empty historical comparison input', () => { + expect(() => omitSubagentCatalogForHistoricalComparison('\n')) + .toThrow('session snapshot must start with a session header') + }) + + it('preserves snapshots and source references when no catalog fact is present', () => { + const normalized = [ + { type: 'session', id: '{{session:1}}' }, + { type: 'tool/call', data: { callId: 'result' } }, + { type: 'tool/result', data: { callId: 'result' }, sourceEventSeqs: [0] }, + ].map(record => JSON.stringify(record)).join('\n') + '\n' + + expect(omitSubagentCatalogForHistoricalComparison(normalized)).toBe(normalized) + }) + + it.each(['0', 0.5, -1])('refuses malformed source references during historical comparison: %s', (source) => { + const normalized = [ + { type: 'session', id: '{{session:1}}' }, + { type: 'subagent/catalog', data: { childId: '{{session:2}}' } }, + { type: 'tool/result', data: { callId: 'result' }, sourceEventSeqs: [source] }, + ].map(record => JSON.stringify(record)).join('\n') + + expect(() => omitSubagentCatalogForHistoricalComparison(normalized)) + .toThrow('normalized sourceEventSeqs must contain non-negative safe integers') + }) + + it('refuses to remove a catalog fact cited by a retained event', () => { + const normalized = [ + { type: 'session', id: '{{session:1}}' }, + { type: 'subagent/catalog', data: { childId: '{{session:2}}' } }, + { type: 'tool/result', data: { callId: 'result' }, sourceEventSeqs: [0] }, + ].map(record => JSON.stringify(record)).join('\n') + + expect(() => omitSubagentCatalogForHistoricalComparison(normalized)) + .toThrow('historical comparison cannot omit cited catalog event 0') + }) + it('migrates and re-packs multi-session fixtures after relationship-preserving id redaction', () => { const raw = [ JSON.stringify({ type: 'session', version: 0, id: '{{session:1}}', createdAt: 0, delegationDepth: 0 }),