Something went wrong. Try again.
A collaborative coding-agent orchestrator for atproto radl.app
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279import assert from 'node:assert/strict'import { readFile } from 'node:fs/promises'import { describe, it } from 'node:test'import { resolve } from 'node:path'import { COLLECTIONS } from '../dist/generated/records.js'import { normalizeViewName } from '../dist/index.js'import { normalizeArtifactTitle } from '../dist/turn-protocol.js'import { validateRecord } from '../dist/validation.js'import { GOAL_SOURCE_GITHUB_ISSUE, GOAL_SOURCE_TANGLED_ISSUE } from '../dist/records.js'
const fixtures = resolve(import.meta.dirname, 'fixtures')
describe('saved view names', () => { it('uses the writer key after trimming and collapsing inner whitespace', () => { assert.equal(normalizeViewName(' Infra work\n queue '), 'Infra work queue') })})
describe('record validation', () => { it('accepts a valid fixture for every collection', async () => { const records = JSON.parse(await readFile(resolve(fixtures, 'valid-records.json'), 'utf8')) assert.deepEqual(Object.keys(records).sort(), Object.values(COLLECTIONS).sort()) for (const [collection, record] of Object.entries(records)) { assert.equal(validateRecord(collection, record).success, true, collection) } })
it('rejects an invalid fixture for every collection', async () => { const records = JSON.parse(await readFile(resolve(fixtures, 'invalid-records.json'), 'utf8')) assert.deepEqual(Object.keys(records).sort(), Object.values(COLLECTIONS).sort()) for (const [collection, record] of Object.entries(records)) { assert.equal(validateRecord(collection, record).success, false, collection) } })
it('ships valid goal-scoped and system registry seed records', async () => { const builtins = JSON.parse( await readFile(resolve(import.meta.dirname, '../../lexicons/fixtures/builtins.json'), 'utf8'), ) assert.deepEqual( builtins.map((record) => [record.name, record.scope, record.durability]), [ ['plan', 'goal', undefined], ['implementation', 'goal', undefined], ['architecture', 'project', 'living'], ['architecture-inventory', 'project', 'living'], ['glossary', 'project', 'living'], ['conventions', 'project', 'living'], ['adr', 'project', 'append-only'], ['fdr', 'project', 'append-only'], ], ) for (const record of builtins) { assert.equal(validateRecord(COLLECTIONS.artifactType, record).success, true) } })
it('enforces exact-one targets and anchors', async () => { const records = JSON.parse(await readFile(resolve(fixtures, 'valid-records.json'), 'utf8')) const request = records[COLLECTIONS.artifactRequest] assert.equal( validateRecord(COLLECTIONS.artifactRequest, { ...request, project: request.goal }).success, false, ) const message = { ...records[COLLECTIONS.message] } delete message.goal assert.equal(validateRecord(COLLECTIONS.message, message).success, false) })
it('rejects merge records field-by-field', async () => { const records = JSON.parse(await readFile(resolve(fixtures, 'valid-records.json'), 'utf8')) const base = records[COLLECTIONS.merge] assert.equal(validateRecord(COLLECTIONS.merge, base).success, true) const mutations = [ ['missing artifact', (r) => delete r.artifact], ['missing pr', (r) => delete r.pr], ['missing createdAt', (r) => delete r.createdAt], ['non-strongref artifact', (r) => (r.artifact = { uri: 'not-at', cid: '' })], ['non-URI pr', (r) => (r.pr = 'not a uri')], ['bad mergedAt datetime', (r) => (r.mergedAt = 'nope')], ] for (const [label, mutate] of mutations) { const record = structuredClone(base) mutate(record) assert.equal(validateRecord(COLLECTIONS.merge, record).success, false, label) } })
it('rejects impossible RFC 3339 calendar dates', async () => { const records = JSON.parse(await readFile(resolve(fixtures, 'valid-records.json'), 'utf8')) const space = { ...records[COLLECTIONS.space], createdAt: '2026-02-31T00:00:00Z', } assert.equal(validateRecord(COLLECTIONS.space, space).success, false) })})
it('accepts an at:// record URI where a lexicon says format: uri, and still rejects a non-URI', () => { // A pull request is not always a page: on a forge whose pulls are atproto records, `links.pr` // names the record. WHATWG `new URL` refuses an at-uri (the DID's colons parse as a port), so // this is checked explicitly rather than by parsing. const links = (pr) => ({ $type: COLLECTIONS.artifact, request: { uri: 'at://did:plc:human/com.disnetdev.radial.artifactRequest/r1', cid: 'c' }, goal: { uri: 'at://did:plc:human/com.disnetdev.radial.goal/g1', cid: 'c' }, type: 'implementation', body: 'x', links: { branch: 'radial/impl-1', commit: 'a'.repeat(40), pr }, createdAt: '2026-07-19T00:00:00.000Z', }) assert.equal(validateRecord(COLLECTIONS.artifact, links('at://did:plc:agent/sh.tangled.repo.pull/3ktid1')).success, true) assert.equal(validateRecord(COLLECTIONS.artifact, links('https://github.com/acme/widget/pull/7')).success, true) assert.equal(validateRecord(COLLECTIONS.artifact, links('at://did:plc:agent/sh.tangled.repo.pull/has a space')).success, false) assert.equal(validateRecord(COLLECTIONS.artifact, links('not a uri')).success, false)})
it('keeps an untitled artifact valid while bounding a title that is present', () => { // `title` is additive and OPTIONAL on the wire, and it has to stay that way: records signed before // the field existed cannot be rewritten, and requiring it would put every one of them in // `index.ignored` — where a materializer reads the request they answered as still open. Writers // require it instead (sidecar `artifact post`, the daemon's turn socket). const artifact = (extra) => ({ $type: COLLECTIONS.artifact, request: { uri: 'at://did:plc:human/com.disnetdev.radial.artifactRequest/r1', cid: 'c' }, project: { uri: 'at://did:plc:human/com.disnetdev.radial.project/p1', cid: 'c' }, type: 'adr', body: 'Status: accepted\n\n## Decision\n\nDo the thing.', links: {}, createdAt: '2026-07-19T00:00:00.000Z', ...extra, }) assert.equal(validateRecord(COLLECTIONS.artifact, artifact({})).success, true) assert.equal( validateRecord(COLLECTIONS.artifact, artifact({ title: '0008 · Jetstream first' })).success, true, ) assert.equal(validateRecord(COLLECTIONS.artifact, artifact({ title: 'x'.repeat(200) })).success, true) assert.equal(validateRecord(COLLECTIONS.artifact, artifact({ title: 'x'.repeat(201) })).success, false) assert.equal(validateRecord(COLLECTIONS.artifact, artifact({ title: 12 })).success, false)})
it('enforces item count and per-item bounds on a bounded string array', () => { // `labelGoal.labels` is the first record field that is a BOUNDED array of bounded strings, so this // pins the generic validator's two array rules — item count against `maxLength`, and each item // against the `items` schema — rather than trusting that they exist. A silent gap here would let // malformed label records into every store that ingests one. const labels = (value) => ({ $type: COLLECTIONS.labelGoal, goal: { uri: 'at://did:plc:human/com.disnetdev.radial.goal/g1', cid: 'c' }, labels: value, createdAt: '2026-07-19T00:00:00.000Z', }) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels([])).success, true) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels(['infra', 'ux'])).success, true) assert.equal( validateRecord(COLLECTIONS.labelGoal, labels(Array.from({ length: 20 }, (_, i) => `l${i}`))).success, true, ) assert.equal( validateRecord(COLLECTIONS.labelGoal, labels(Array.from({ length: 21 }, (_, i) => `l${i}`))).success, false, ) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels([''])).success, false) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels(['x'.repeat(100)])).success, true) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels(['x'.repeat(101)])).success, false) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels(['ok', 7])).success, false) assert.equal(validateRecord(COLLECTIONS.labelGoal, labels('infra')).success, false)})
it('bounds a saved view name and constrains its state to the known slice', () => { const view = (extra) => ({ $type: COLLECTIONS.savedView, space: { uri: 'at://did:plc:root/com.disnetdev.radial.space/s1', cid: 'c' }, name: 'Infra', createdAt: '2026-07-19T00:00:00.000Z', ...extra, }) assert.equal(validateRecord(COLLECTIONS.savedView, view({})).success, true) assert.equal(validateRecord(COLLECTIONS.savedView, view({ state: 'all' })).success, true) assert.equal(validateRecord(COLLECTIONS.savedView, view({ state: 'archived' })).success, false) assert.equal(validateRecord(COLLECTIONS.savedView, view({ name: '' })).success, false) assert.equal(validateRecord(COLLECTIONS.savedView, view({ name: 'x'.repeat(101) })).success, false) assert.equal(validateRecord(COLLECTIONS.savedView, view({ deleted: true })).success, true)})
it('normalizes an artifact title the same way for every writer', () => { // One rule, shared by the sidecar's direct write and the daemon's socket, so an artifact written // inside a turn and one written from a shell cannot disagree about what a title is. assert.equal(normalizeArtifactTitle(' Four moving parts \n'), 'Four moving parts') assert.equal(normalizeArtifactTitle('x'.repeat(200)).length, 200) assert.equal(normalizeArtifactTitle('x'.repeat(201)), undefined) assert.equal(normalizeArtifactTitle(' '), undefined) assert.equal(normalizeArtifactTitle(''), undefined) assert.equal(normalizeArtifactTitle(undefined), undefined) assert.equal(normalizeArtifactTitle(7), undefined)})
it('keeps a goal valid with and without a source, and pins the tangled kind this build mints', () => { // `source` is where an imported goal says its text came from. Optional on the wire like every // other addition (a goal signed before the field existed cannot be rewritten), and the kind is // free-form so a newer writer can name a forge this build has never heard of. What is checked is // each kind this build DOES mint: `tangled-issue` promises a record pointer, and a candidate list // that matched on anything else would offer the same issue for import forever. `github-issue` has // its own case below — a different pointer shape, the same reason for checking it. const goal = (source) => ({ $type: COLLECTIONS.goal, space: { uri: 'at://did:plc:root/com.disnetdev.radial.space/s1', cid: 'c' }, project: { uri: 'at://did:plc:root/com.disnetdev.radial.project/p1', cid: 'c' }, title: 'repo operations: archive repository', body: 'Freeze a repository without deleting it.', createdAt: '2026-07-31T00:00:00.000Z', ...(source === undefined ? {} : { source }), }) const issue = 'at://did:plc:stranger/sh.tangled.repo.issue/3mrxi5lzk2v22' assert.equal(validateRecord(COLLECTIONS.goal, goal()).success, true) assert.equal( validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_TANGLED_ISSUE, uri: issue, cid: 'bafy' })).success, true, ) assert.equal(validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_TANGLED_ISSUE, uri: issue })).success, true) // A kind this build does not know is somebody else's forge, not an error: it is carried, and the // candidate list simply does not match on it. The check is per-kind consistency, never an allowlist — // records signed today must survive a build that learns a third forge tomorrow. assert.equal( validateRecord(COLLECTIONS.goal, goal({ kind: 'gitlab-issue', uri: 'https://gitlab.com/acme/w/-/issues/7' })).success, true, ) assert.equal( validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_TANGLED_ISSUE, uri: 'at://did:plc:x/sh.tangled.repo.pull/1' })).success, false, ) assert.equal(validateRecord(COLLECTIONS.goal, goal({ uri: issue })).success, false) assert.equal(validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_TANGLED_ISSUE })).success, false) assert.equal(validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_TANGLED_ISSUE, uri: 'not a uri' })).success, false)})
it('checks a github-issue source against the URL shape GitHub actually serves', () => { // The GitHub twin of the case above, and a different kind of check for a different kind of pointer: // a tangled issue is a record, so what is checked is a collection; a GitHub issue is a page, so what // is checked is the page's canonical shape. Same reason, though — the candidate list joins goals to // issues on this string verbatim, so a pointer somebody constructed by hand would badge nothing and // keep offering an issue that was taken up. const goal = (source) => ({ $type: COLLECTIONS.goal, space: { uri: 'at://did:plc:root/com.disnetdev.radial.space/s1', cid: 'c' }, project: { uri: 'at://did:plc:root/com.disnetdev.radial.project/p1', cid: 'c' }, title: 'repo operations: archive repository', body: 'Freeze a repository without deleting it.', createdAt: '2026-07-31T00:00:00.000Z', source, }) const ok = (uri) => validateRecord(COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_GITHUB_ISSUE, uri })).success assert.equal(ok('https://github.com/acme/widget/issues/7'), true) assert.equal(ok('https://www.github.com/acme/widget/issues/7'), true) // No cid is the normal shape here: GitHub content is not content-addressed, so there is no version // to pin. One offered anyway is carried — `source` is an assertion, and the field is optional. assert.equal( validateRecord( COLLECTIONS.goal, goal({ kind: GOAL_SOURCE_GITHUB_ISSUE, uri: 'https://github.com/acme/widget/issues/7', cid: 'bafy' }), ).success, true, ) assert.equal(ok('at://did:plc:stranger/sh.tangled.repo.issue/3mrxi5lzk2v22'), false) assert.equal(ok('http://github.com/acme/widget/issues/7'), false) assert.equal(ok('https://github.com/acme/widget/issues/7?utm=1'), false) assert.equal(ok('https://github.com/acme/widget/issues/7#comment-1'), false) assert.equal(ok('https://github.com:8443/acme/widget/issues/7'), false) assert.equal(ok('https://user:pass@github.com/acme/widget/issues/7'), false) // A pull request is not an issue, even though GitHub's issues API answers for both. assert.equal(ok('https://github.com/acme/widget/pull/7'), false) assert.equal(ok('https://github.com/acme/widget/issues/0'), false) assert.equal(ok('https://github.com/acme/widget/issues/-1'), false) assert.equal(ok('https://github.com/acme/widget/issues'), false) assert.equal(ok('https://gitlab.com/acme/widget/issues/7'), false) assert.equal(ok('not a uri'), false)})