Something went wrong. Try again.
A collaborative coding-agent orchestrator for atproto radl.app
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210import assert from 'node:assert/strict'import { describe, it } from 'node:test'import { buildTurnBundle } from '../dist/bundle.js'import { materialize } from '../dist/materializer.js'import { MemoryRecordStore } from '../dist/store.js'import { timeline, tally } from '../dist/timeline.js'import { goldenScenario } from '../dist/test/scenario.js'import { COLLECTIONS } from '../dist/generated/records.js'
const AS_OF = '2026-02-01T00:00:00Z'
const build = (records, spaceUri) => { const store = new MemoryRecordStore() records.forEach((record) => store.put(record)) return materialize(store, { spaceUri, asOf: AS_OF })}
const goalView = (index, uri) => index.goals.find((view) => view.target.uri === uri)const find = (records, suffix) => records.find((record) => record.uri.endsWith(suffix))const ref = (record) => ({ uri: record.uri, cid: record.cid })
/** The golden scenario with its answer exchange edited: `mutate` receives the record list. */function withScenario(mutate) { const scenario = goldenScenario() const records = mutate(scenario.records, scenario) ?? scenario.records return { scenario, index: build(records, scenario.spaceUri) }}
describe('answer requests', () => { it('materializes a request whose subject message resolves under its own goal', () => { const { scenario, index } = withScenario(() => undefined) const goal = goalView(index, scenario.secondGoalUri) const answer = goal.requests.find((request) => request.uri === scenario.answerRequestUri) assert.ok(answer, 'the answer request is filed under the goal it names') assert.equal(answer.value.type, 'answer') assert.equal(answer.value.subject.uri, scenario.answerQuestionUri) // Both the question and the reply are ordinary thread messages under the same goal. assert.deepEqual( goal.messages.map((message) => message.uri), [scenario.answerQuestionUri, scenario.answerReplyUri], ) })
it('does not materialize a request whose subject is pinned to a stale message cid', () => { const { scenario, index } = withScenario((records, current) => { const request = find(records, '/request-answer') request.value = { ...request.value, subject: { uri: current.answerQuestionUri, cid: 'cid-some-other-version' }, } }) const goal = goalView(index, scenario.secondGoalUri) assert.equal( goal.requests.some((request) => request.uri === scenario.answerRequestUri), false, ) assert.equal( index.ignored.some((entry) => entry.uri === scenario.answerRequestUri), true, 'an unresolvable answer request is reported, not silently dropped', ) })
it('does not materialize a request whose subject lives under a different goal', () => { const { scenario, index } = withScenario((records) => { // Repoint the request at the FIRST goal while its subject message stays on the second. const request = find(records, '/request-answer') const goalRecord = find(records, '/goal') request.value = { ...request.value, goal: ref(goalRecord) } }) assert.equal( index.goals.some((view) => view.requests.some((request) => request.uri === scenario.answerRequestUri), ), false, ) })
it('is fulfilled by the assignee reply, and by nobody else', () => { const { scenario, index } = withScenario(() => undefined) const goal = goalView(index, scenario.secondGoalUri) assert.equal( goal.openRequests.some((request) => request.uri === scenario.answerRequestUri), false, 'the assignee replied, so the request is closed', )
// The same reply from somebody who is not the assignee closes nothing. const other = withScenario((records) => { const reply = find(records, '/answer-reply') const moved = { ...reply, did: 'did:plc:agenta', uri: reply.uri.replace('did:plc:agentb', 'did:plc:agenta'), } records.splice(records.indexOf(reply), 1, moved) }) const otherGoal = goalView(other.index, other.scenario.secondGoalUri) assert.equal( otherGoal.openRequests.some((request) => request.uri === other.scenario.answerRequestUri), true, ) })
it('is NOT fulfilled by the assignee asking a question of its own', () => { // The two things an answer turn can write are both messages carrying `re`. Only the one threaded // under the subject is the reply; a bare question must leave the request open (and awaiting // input) rather than closing the request it was asked about. const { scenario, index } = withScenario((records) => { const reply = find(records, '/answer-reply') const { parent: _parent, root: _root, ...rest } = reply.value reply.value = { ...rest, body: 'Which SQLite path do you mean?' } }) const goal = goalView(index, scenario.secondGoalUri) assert.equal( goal.openRequests.some((request) => request.uri === scenario.answerRequestUri), true, ) assert.deepEqual(goal.awaitingInput, [scenario.answerRequestUri]) })
it('is fulfilled by the assignee declining, through the rule declines already had', () => { const { scenario, index } = withScenario((records) => { const reply = find(records, '/answer-reply') const { parent: _parent, root: _root, ...rest } = reply.value reply.value = { ...rest, declines: true, body: 'Not something I can speak to.' } }) const goal = goalView(index, scenario.secondGoalUri) assert.equal( goal.openRequests.some((request) => request.uri === scenario.answerRequestUri), false, ) })
it('is withdrawn by a retract tombstone from its author', () => { const { scenario, index } = withScenario((records) => { const request = find(records, '/request-answer') const reply = find(records, '/answer-reply') records.splice(records.indexOf(reply), 1) records.push({ did: 'did:plc:human', collection: COLLECTIONS.retractRequest, rkey: 'retract-answer', uri: `at://did:plc:human/${COLLECTIONS.retractRequest}/retract-answer`, cid: 'cid-retract-answer', rev: '0000000000099', value: { $type: COLLECTIONS.retractRequest, request: ref(request), createdAt: '2026-01-01T00:10:43Z', }, }) }) const goal = goalView(index, scenario.secondGoalUri) assert.equal( goal.retracted.some((request) => request.uri === scenario.answerRequestUri), true, ) assert.equal( goal.openRequests.some((request) => request.uri === scenario.answerRequestUri), false, ) })
it('never becomes a unit, open or retracted, and never moves the tally', () => { const { scenario, index } = withScenario(() => undefined) const units = timeline(index, scenario.secondGoalUri) assert.equal( units.some((unit) => unit.type === 'answer'), false, ) const before = tally(units)
// An OPEN answer request (the reply removed) must not add a row either — an unanswered question // is not a piece of work the goal's pie is missing. const open = withScenario((records) => { const reply = find(records, '/answer-reply') records.splice(records.indexOf(reply), 1) }) const openUnits = timeline(open.index, open.scenario.secondGoalUri) assert.equal( openUnits.some((unit) => unit.type === 'answer'), false, ) assert.deepEqual(tally(openUnits), before) })
it('gives the turn the exact message it was commissioned to answer', () => { const { scenario, index } = withScenario(() => undefined) const goal = goalView(index, scenario.secondGoalUri) const request = goal.requests.find((entry) => entry.uri === scenario.answerRequestUri) const bundle = buildTurnBundle(index, request.uri, request.cid) assert.deepEqual(bundle.answering, { uri: scenario.answerQuestionUri, cid: scenario.answerQuestionRef.cid, author: 'did:plc:human', body: 'Why did you drop the SQLite path?', createdAt: '2026-01-01T00:10:40Z', }) // The thread rides along as always, and now carries who each message addressed. const question = bundle.thread.find((message) => message.uri === scenario.answerQuestionUri) assert.deepEqual(question.mentions, ['did:plc:agentb']) const reply = bundle.thread.find((message) => message.uri === scenario.answerReplyUri) assert.equal(reply.parent.uri, scenario.answerQuestionUri) // The plan the exchange is about comes through `basedOn`, exactly as it does for any other turn. assert.equal(bundle.basedOn.some((artifact) => artifact.type === 'plan'), true) assert.equal(bundle.missingRefs.length, 0) })})