coulomb-social/scripts/tests/bubble-resource-utils.test.mjs
tegwick 0ee31b596e
Some checks failed
Use-case regression gate / usecase-regressions (push) Failing after 6m36s
Capture bounded source resource evidence and expose navigation gap
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a18e2d-f513-7742-b8e7-12af0b744ff3
2026-10-31 15:37:08 +01:00

47 lines
2.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {ingestResourceBody, resourceParents} from '../bubble-resource-utils.mjs';
const id='1700000000000x1', other='1700000000000x2';
const output=()=>({records:{},empty:{}});
test('only explicit affected parents are visited; descriptors are not article targets',()=>{
assert.deepEqual(resourceParents({[id]:{_list_custom_scrap:'LOOKUP__'+other},
[other]:{hasattachments_boolean:true}, '1700000000000x3':{_list_custom_scrap:[]},
invalid:{hasattachments_boolean:true}}),[id,other]);
});
test('typed search and initialization resource observations preserve versions',()=>{
const result=output();
ingestResourceBody(JSON.stringify({responses:[{hits:{hits:[{_type:'custom.scrap',_id:id,
_source:{content_text:'Synthetic first'}}]}}]}),result);
const envelope={type:'custom.scrap',id,data:{_type:'custom.scrap',_id:id,
content_text:'Synthetic second'}};
ingestResourceBody(JSON.stringify(envelope),result);
ingestResourceBody(JSON.stringify(envelope),result);
assert.equal(result.records['custom.scrap:'+id].length,2);
assert.equal(result.records['custom.scrap:'+id][0].content_text,'Synthetic first');
});
test('empty envelopes remain unresolved; mixed ids/types and nested users are excluded',()=>{
const result=output();
const resource={_type:'custom.scrap',_id:id,_source:{content_text:'Synthetic'}};
ingestResourceBody(JSON.stringify([
{type:'custom.scrap',id,data:{}},
{type:'custom.scrap',id,data:{_type:'custom.scrap',_id:other}},
{type:'user',id,data:resource},
{_type:'user',_id:id,_source:resource},
{...resource,_source:{_type:'custom.article'}},
{...resource,_source:{_id:other}},
{_type:'custom.article',_id:id,_source:{content_text:'Synthetic article'}},
]),result);
assert.deepEqual(result.records,{});
assert.deepEqual(result.empty,{'custom.scrap:1700000000000x1':{type:'custom.scrap',id}});
});
test('NDJSON selects only content-resource types',()=>{
const result=output();
ingestResourceBody('unrelated\n'+JSON.stringify({_type:'custom.relattachment',_id:id,
_source:{url_text:'https://example.invalid/synthetic'}})+'\n'+
JSON.stringify({_type:'session',_id:other,_source:{cookie:'synthetic'}}),result);
assert.deepEqual(Object.keys(result.records),['custom.relattachment:'+id]);
});