OverviewFilesCommitsIssuesDocsReleasesPeers

favela-web / test / reach.test.mjs

42 lines · javascript ref:
// Where a post went. Run: node test/reach.test.mjs
//
// The whole value of this module is the OBSERVED / ELIGIBLE distinction. Collapsing it would claim
// something we did not check — the habit that made #24 and #26 hard to diagnose.
import { reachFor, apKnown, TIER } from '../lib/reach.js'

let pass = 0
const ok = (c, m) => { if (!c) { console.error('FAIL:', m); process.exit(1) } console.log('  ok -', m); pass++ }
const tiers = (r) => r.map((x) => x.tier).join(',')
const state = (r, t) => (r.find((x) => x.tier === t) || {}).state

const PUB = 'app.bsky.feed.post'
const LOC = 'net.favela.local.post'

ok(tiers(reachFor({ collection: PUB, rkey: 'r1', apRkeys: new Set(['r1']) })) === 'favela,bsky,fediverse',
  'a public post in the outbox reached all three')
ok(state(reachFor({ collection: PUB, rkey: 'r1', apRkeys: new Set(['r1']) }), TIER.FEDIVERSE) === 'observed',
  'the fediverse claim is OBSERVED — the outbox names the rkey')
ok(state(reachFor({ collection: PUB, rkey: 'r1', apRkeys: new Set(['r1']) }), TIER.BSKY) === 'eligible',
  'the bsky claim is only ELIGIBLE — the lexicon is indexed, but we never checked it landed')
ok(state(reachFor({ collection: PUB, rkey: 'r1' }), TIER.FAVELA) === 'observed',
  'favela is observed — holding the record IS the evidence')

ok(tiers(reachFor({ collection: PUB, rkey: 'r2', apRkeys: new Set(['r1']) })) === 'favela,bsky',
  'a public post absent from the outbox claims no fediverse reach')
ok(tiers(reachFor({ collection: LOC, rkey: 'r3', apRkeys: new Set(['r3']) })) === 'favela',
  'a local-only post claims neither — even if an rkey collides in the outbox set')

// NULL IS UNKNOWN, NOT NO. One failed HTTP call must not render as "this did not federate".
ok(tiers(reachFor({ collection: PUB, rkey: 'r1', apRkeys: null })) === 'favela,bsky',
  'an unreachable AP side yields silence about the fediverse, never a denial')
ok(apKnown(null) === false && apKnown(new Set()) === true,
  'apKnown distinguishes "asked and got nothing" from "could not ask"')

// degenerate input must not throw on a render path
ok(tiers(reachFor({})) === 'favela', 'no collection still reports what we know')
ok(tiers(reachFor()) === 'favela', 'no argument at all does not throw')
ok(tiers(reachFor({ collection: 'com.example.unknown', rkey: 'r1' })) === 'favela',
  'an unknown lexicon claims no bsky reach — bsky indexes app.bsky.* only')

console.log(`\nREACH OK: ${pass} assertions`)