import test from 'node:test'; import assert from 'node:assert/strict'; import { normalizeBubbleRef, assertSessionFresh, mergeCapturedRecord, selectTargetArticles } from '../bubble-corpus-utils.mjs'; test('typed lookup references normalize to the same space identifier', () => { const id = '1700000000000x1234567890'; assert.equal(normalizeBubbleRef(`LOOKUP__custom.space__${id}`), id); assert.equal(normalizeBubbleRef(`LOOKUP__${id}`), id); assert.equal(normalizeBubbleRef(id), id); }); test('expired signature blocks capture; an expired analytics cookie does not', () => { assert.throws(() => assertSessionFresh({cookies:[{name:'app.sig',expires:9}]},10), /bubble_session_expired/); assert.doesNotThrow(() => assertSessionFresh({cookies:[ {name:'analytics',expires:9},{name:'app.sig',expires:11}]},10)); }); test('partial network responses retain full notes captured in this run', () => { const first = mergeCapturedRecord(null,{content_text:'synthetic full notes'},'root'); assert.equal(mergeCapturedRecord(first,{nomer_text:'Synthetic call'},'root').content_text, 'synthetic full notes'); }); test('explicit target selection never substitutes the largest space', () => { const records = {root:{space_custom_space:'target',content_text:'synthetic index'}, call:{space_custom_space:'target',content_text:'synthetic protocol'}, a:{space_custom_space:'other'},b:{space_custom_space:'other'},c:{space_custom_space:'other'}}; const [id, selected] = selectTargetArticles(records,'root'); assert.equal(id,'target'); assert.equal(selected.length,2); delete records.call.content_text; assert.throws(() => selectTargetArticles(records,'root'), /target_protocol_bodies_incomplete/); records.call.content_text = 'synthetic protocol'; delete records.call; assert.throws(() => selectTargetArticles(records,'root'), /target_protocols_not_captured/); });