import { INITIAL_PROTOCOL_MISMATCH_SNAPSHOT, newestProtocolMismatchSnapshot, type ProtocolMismatchSnapshot, } from "../src/lib/protocolMismatch.ts"; const assertEquals = (actual: T, expected: T, message: string) => { if (JSON.stringify(actual) !== JSON.stringify(expected)) { throw new Error( `${message}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`, ); } }; Deno.test("delayed bootstrap snapshot cannot overwrite a newer mismatch event", () => { const delayedQuery = INITIAL_PROTOCOL_MISMATCH_SNAPSHOT; const event: ProtocolMismatchSnapshot = { revision: 1, mismatch: { observed: 7, expected: 8 }, }; const afterEvent = newestProtocolMismatchSnapshot( INITIAL_PROTOCOL_MISMATCH_SNAPSHOT, event, ); assertEquals( newestProtocolMismatchSnapshot(afterEvent, delayedQuery), event, "delayed query must lose to event", ); }); Deno.test("new runtime generation clears an older mismatch", () => { const mismatch: ProtocolMismatchSnapshot = { revision: 4, mismatch: { observed: null, expected: 8 }, }; const cleared: ProtocolMismatchSnapshot = { revision: 5, mismatch: null }; assertEquals( newestProtocolMismatchSnapshot(mismatch, cleared), cleared, "new generation clear must win", ); });