OverviewFilesCommitsIssuesDocsReleasesPeers

favela-web / test / appview-blocks.test.mjs

43 lines · javascript ref:
// Remote-block awareness. Run: bare test/appview-blocks.test.mjs
//
// A BLOCK is a public record that federates (unlike a mute, which is private and node-local). Until
// INGEST_VERSION 6 the appview did not index app.bsky.graph.block at all, so a block made on ANOTHER
// device simply did not exist for this node: the account stayed visible, and an unblock here could not
// find a record it never knew about.
import '../lib/bare-globals.js'
import { storeDir } from './_store-dir.mjs'
import Corestore from 'corestore'
import { Appview, INGEST_VERSION } from '../lib/appview.js'

const assert = (c, m) => { if (!c) throw new Error('FAIL: ' + m); console.log('  ok -', m) }

const dir = storeDir('appview-blocks-test')
const av = await new Appview(new Corestore(dir)).ready()

const ME = 'did:plc:me'; const THEM = 'did:plc:them'; const OTHER = 'did:plc:other'
const BLOCK = 'app.bsky.graph.block'

assert(INGEST_VERSION >= 6, 'INGEST_VERSION is bumped, so every DID replays and picks up existing blocks')
assert((await av.blocking(ME)).size === 0, 'nothing blocked to begin with')

// A block arriving over the firehose — the case that did not work before: made elsewhere, seen here.
await av.applyCommit(ME, [{ action: 'create', collection: BLOCK, rkey: 'b1', record: { $type: BLOCK, subject: THEM, createdAt: '2026-08-01T00:00:00.000Z' } }])
const blocked = await av.blocking(ME)
assert(blocked.has(THEM), 'a block made on another device is now visible here')
assert(!blocked.has(OTHER), 'and only that subject is blocked')

// The rkey is what an unblock needs — without it, unblocking a remote block would no-op while the record
// stayed in the repo.
assert((await av.blockRkeyFor(ME, THEM)) === 'b1', 'the block record rkey is resolvable')
assert((await av.blockRkeyFor(ME, OTHER)) === null, 'a non-block resolves to null')

// DIRECTIONAL: me blocking them is not them blocking me.
assert((await av.blocking(THEM)).size === 0, 'blocks are directional')

// A delete op carries NO record, so the rkey->subject reverse entry is what makes removal possible.
await av.applyCommit(ME, [{ action: 'delete', collection: BLOCK, rkey: 'b1' }])
assert((await av.blocking(ME)).size === 0, 'an unblock made anywhere clears it here')
assert((await av.blockRkeyFor(ME, THEM)) === null, 'and the rkey lookup clears too')

console.log('\nall block-indexing assertions passed')