Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

test(relay): bind offline hand-off after renumber [B3,B26,H16,H17]

Corey Olson7f1ef2b923db
diff --git a/test/relay-outbox.test.js b/test/relay-outbox.test.js
index 58c0d72a..6e675637 100644
--- a/test/relay-outbox.test.js
+++ b/test/relay-outbox.test.js
@@ -140,6 +140,51 @@ test('an item added while the relay is down keeps its queued moves when another
}
});
+test('an offline hand-off keeps its own item number after another machine adds [B3,B26,H16,H17]', async (t) => {
+ const { box, other } = await twoMachines(t, 'Before the offline hand-off');
+ /** Join a real local worktree before the outage so both hand-off actors have authenticated seats. */
+ async function seat(name) {
+ const path = join(dirname(box.root), name);
+ runFixtureGit(['worktree', 'add', '-q', '-b', `agent/${name}`, path], { cwd: box.root, env: box.env });
+ const joined = await box.cliAt(path, 'join', box.lane, '--model', 'fixture-model');
+ assert.equal(joined.code, 0, joined.failure);
+ return { path, id: joined.document.agent };
+ }
+ const outgoing = await seat('outgoing');
+ const incoming = await seat('incoming');
+ await box.stopRelay();
+ const opened = await box.cliAt(outgoing.path, 'handoff');
+ assert.equal(opened.code, 0, opened.failure);
+ const local = opened.document.handoff.item;
+ const fact = await box.cliAt(outgoing.path, 'fact', String(local), 'note', 'Keep this note on its own hand-off');
+ assert.equal(fact.code, 0, fact.failure);
+ const taken = await box.cliAt(incoming.path, 'handoff', '--take', String(local));
+ assert.equal(taken.code, 0, taken.failure);
+ assert.equal(taken.document.handoff.item, local);
+
+ await box.restartRelay();
+ const remote = await (await otherAgent(box, other))('add', box.lane, 'Remote item takes the offline number');
+ assert.equal(remote.code, 0, remote.failure);
+ assert.equal(remote.document.item.item_id, local);
+ const replayed = await box.cli('status');
+ assert.equal(replayed.code, 0, replayed.failure);
+ assert.equal(replayed.document.relay.outboxRefusals, undefined, 'the fact and take follow their own hand-off instead of the remote item');
+ assert.deepEqual(replayed.document.relay.outboxRenumbered, [{ was: local, is: local + 1 }]);
+ for (const machine of [box, other]) {
+ const exported = await machine.cli('export');
+ const tables = exported.document.tables;
+ assert.equal(tables.item.find(row => row.item_id === local).item_title, 'Remote item takes the offline number');
+ const thread = await machine.cli('show', String(local + 1));
+ assert.equal(thread.code, 0, thread.failure);
+ const notes = tables.event.filter(row => row.event_kind === 'fact' && JSON.parse(row.event_detail).text === 'Keep this note on its own hand-off');
+ assert.equal(notes.length, 1, 'the original fact is recorded once');
+ assert.equal(notes[0].item_id, local + 1, 'the fact is bound to the hand-off');
+ const takes = tables.event.filter(row => row.event_kind === 'handoff-take');
+ assert.equal(takes.length, 1, 'the incoming seat takes over once');
+ assert.equal(takes[0].item_id, local + 1, 'the take is bound to the hand-off');
+ }
+});
+
test('an offline item stays bound to its queued moves through a replay that stops part way and new work after it [B26,H16,H17]', async (t) => {
const { box, other } = await twoMachines(t, 'Added before the outage');
await box.stopRelay();