coulomb-social/scripts/tests/bubble-corpus-utils.test.mjs
tegwick b897aa1ee6
Some checks failed
Use-case regression gate / usecase-regressions (push) Has been cancelled
feat: prepare isolated recovery and guarded fresh ReichelAg capture
Assistant: codex
Assistant-Model: gpt-6.1-sol
Assistant-Session: 01a10e2d-a5ef-7e92-b03d-b1694e915680
2026-10-06 22:11:42 +02:00

38 lines
1.9 KiB
JavaScript

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/);
});