~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/atlibs-socialweb-computer-app

app.socialweb.computer: socialweb.computer in one page, one atlibs composition

0
0
main
57 lines · 3.2 KB Raw History
// node --test test/app.test.mjs: the page's logic and its atirc client, no network
import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'

import { createHash } from 'node:crypto'

import { bidderDids, channelOf, groupBidders, guestOf, liveness } from '../app.js'

test('compose.ts writes the committed composition.json', () => {
	const built = execFileSync('node', ['compose.ts'], { cwd: new URL('..', import.meta.url), encoding: 'utf8' })
	assert.equal(built, readFileSync(new URL('../composition.json', import.meta.url), 'utf8'))
	const c = JSON.parse(built)
	assert.deepEqual(c.instances.map((i) => i.name), ['vm', 'machine', 'user_data', 'iroh_user_data', 'vouch', 'payload', 'process', 'agent', 'vouches', 'status'])
	assert.ok(c.edges.some((e) => e.from === 'agent' && e.nsid === 'computer.socialweb.cicd.process.exec' && e.to === 'process'))
})

test('channels are atirc\'s', () => {
	assert.equal(channelOf('aliceoa.bsky.social'), '#aliceoa_bsky_social')
	assert.equal(channelOf('scout.aliceoa.bsky.social'), '#scout_aliceoa_bsky_social')
})

test('liveness: a heartbeat within 5 minutes is live', () => {
	const now = Date.parse('2026-11-10T12:00:00Z')
	assert.deepEqual(liveness('2026-11-10T11:59:30Z', now), { live: true, age: '30s ago' })
	assert.deepEqual(liveness('2026-11-10T11:50:00Z', now), { live: false, age: '10m ago' })
	assert.deepEqual(liveness(undefined, now), { live: false, age: 'no heartbeat' })
})

test('bidders: yours by confirmed operator, vouched by bidder or operator, none without records', () => {
	const rows = [
		{ did: 'did:plc:b1', operator: 'did:plc:me', heartbeat: {} },
		{ did: 'did:plc:b2', operator: 'did:plc:friend', offering: {} },
		{ did: 'did:plc:friend2', operator: null, offering: {} },
		{ did: 'did:plc:b3', operator: 'did:plc:stranger', offering: {} },
		{ did: 'did:plc:b4', operator: 'did:plc:me' },
	]
	const g = groupBidders(rows, 'did:plc:me', new Set(['did:plc:friend', 'did:plc:friend2']))
	assert.deepEqual(g.mine.map((r) => r.did), ['did:plc:b1'])
	assert.deepEqual(g.vouched.map((r) => r.did), ['did:plc:b2', 'did:plc:friend2'])
	assert.deepEqual(bidderDids(['did:plc:a'], ['did:plc:a', 'did:plc:b'], 'did:plc:me', ['x', 'did:plc:v']), ['did:plc:a', 'did:plc:b', 'did:plc:me', 'did:plc:v'])
})

test('atlibs-atirc is v0.1.0 (5d2f1dc js/index.js), vendored', () => {
	const sha = createHash('sha256').update(readFileSync(new URL('../vendor/atlibs-atirc.js', import.meta.url))).digest('hex')
	assert.equal(sha, '14fe09a435ae5f274f3eaaaa2782be12d4679b8dfb06b234e58a338b47fb01f5')
})

test('guestOf: the receipt a shell URL names, with the requester\'s signals', () => {
	const ref = Buffer.from(JSON.stringify({ receipt: { uri: 'at://did:plc:b/com.publicdomainrelay.temp.market.receipt/r', cid: 'c' }, bidder: 'did:plc:b' })).toString('base64url')
	const events = () => []
	const g = guestOf(`webrtc:///${ref}/shell/mcp`, { events, signal: events })
	assert.deepEqual(g.receipt, { uri: 'at://did:plc:b/com.publicdomainrelay.temp.market.receipt/r', cid: 'c', bidder: 'did:plc:b' })
	assert.equal(g.events, events)
	assert.throws(() => guestOf(`webrtc:///${Buffer.from('{}').toString('base64url')}/shell/mcp`, {}), /no receipt/)
})