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(api): retain evidence for missing events [A2,C7]

Corey Olsonc39774f824d3
diff --git a/test/api.test.js b/test/api.test.js
index 9b4960d1..372c1561 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -1222,61 +1222,81 @@ test('[A2] local HTTP v1 versions state and moves, authenticates, and preserves
test('[A2] moves run as the named worktree agent and requests stay visible until answered', async (t) => {
const box = project();
- const app = join(box.dir, 'app-1');
- box.git(box.repo, 'worktree', 'add', '-q', '-b', 'app/one', app);
- const joined = box.run(app, 'join', 'app');
- assert.equal(joined.status, 0, fixtureCommandEvidence('join worktree agent', joined, box.env));
- const api = await startApi(t, box);
- const boardsResponse = await apiStep('list registered boards', apiFetch(api, '/api/v1/boards'), box.env);
- const board = boardsResponse.document.boards.find((candidate) => candidate.root === box.repo);
- assert.ok(board, boardsResponse.evidence);
- const path = `/api/v1/boards/${board.id}`;
-
- const addedStep = await apiStep('add API move', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'add', args: { lane: 'app', title: 'Agent work' } }) }), box.env);
- const added = addedStep.document;
- const claimedStep = await apiStep('claim API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'next', args: {}, agent: 'app-1' }) }), box.env);
- const claimed = claimedStep.document;
- assert.equal(claimed.event.event_by, 'app-1', claimedStep.evidence);
- assert.equal(claimed.event.event_kind, 'claim', claimedStep.evidence);
- assert.equal(claimed.result.item.item_id, added.result.item.item_id, claimedStep.evidence);
-
- const renewedStep = await apiStep('renew API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'next', args: {}, agent: 'app-1' }) }), box.env);
- const renewed = renewedStep.document;
- assert.equal(renewed.result.held, true, renewedStep.evidence);
- assert.equal(renewed.event.event_kind, 'renew', renewedStep.evidence);
- assert.ok(renewed.event.event_id > claimed.event.event_id, renewedStep.evidence);
- assert.equal(renewed.result.item.item_id, claimed.result.item.item_id, renewedStep.evidence);
-
- const escalatedStep = await apiStep('escalate API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'escalate', item: added.result.item.item_id, args: { note: 'Two attempts failed' }, agent: 'app-1' }) }), box.env);
- const escalated = escalatedStep.document;
- assert.equal(escalated.event.event_kind, 'escalate', escalatedStep.evidence);
- const eventsStep = await apiStep('read events after escalation', apiFetch(api, `${path}/events?after=${renewed.event.event_id}`), box.env);
- const afterEscalation = eventsStep.document.events;
- assert.deepEqual(afterEscalation.map((event) => event.event_kind), ['escalate', 'shout'], eventsStep.evidence);
- assert.equal(afterEscalation[0].event_id, escalated.event.event_id, eventsStep.evidence);
-
- const requestStep = await apiStep('create person request', apiFetch(api, `${path}/requests`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text: 'Approve the API row' }) }), box.env);
- const requested = requestStep.document;
- assertRequiredShape(requested, JSON_SHAPES.http.request.required, `create person request\n${requestStep.evidence}`);
- const requestId = requested.result.id;
- assert.equal(requested.event.event_by, 'person', requestStep.evidence);
- const stateStep = await apiStep('read request state before answering', apiFetch(api, `${path}/state`), box.env);
- const state = stateStep.document.state;
- assert.deepEqual(state.requests.map((entry) => entry.shout_id), [requestId], stateStep.evidence);
- assert.ok(!state.decisions.some((entry) => entry.shout_id === requestId), `person requests are not open decisions\n${stateStep.evidence}`);
- const inboxStep = fixtureJsonStep(box, 'read coordinator inbox', box.repo, 'inbox');
- const inbox = inboxStep.document;
- assert.equal(inbox.shouts[0].shout_id, requestId, inboxStep.evidence);
- const resumeStep = fixtureJsonStep(box, 'read coordinator resume', box.repo, 'resume');
- const resumed = resumeStep.document;
- assert.equal(resumed.requests[0].shout_id, requestId, resumeStep.evidence);
-
- const answerStep = await apiStep('answer request through API move', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'answer', item: requestId, args: { text: 'done' } }) }), box.env);
- const answered = answerStep.document;
- assert.equal(answered.event.event_kind, 'answer', answerStep.evidence);
- assert.equal(answered.event.event_by, 'coordinator', answerStep.evidence);
- const finalStateStep = await apiStep('confirm request disappears after answer', apiFetch(api, `${path}/state`), box.env);
- assert.deepEqual(finalStateStep.document.state.requests, [], finalStateStep.evidence);
+ let lastStepEvidence = 'join worktree agent';
+ /** Retain the last completed HTTP step if its response fails during field access. */
+ async function observedApiStep(...args) {
+ const result = await apiStep(...args);
+ lastStepEvidence = result.evidence;
+ return result;
+ }
+ /** Retain CLI step evidence before downstream response fields are inspected. */
+ function observedFixtureStep(...args) {
+ const result = fixtureJsonStep(...args);
+ lastStepEvidence = result.evidence;
+ return result;
+ }
+ try {
+ const app = join(box.dir, 'app-1');
+ box.git(box.repo, 'worktree', 'add', '-q', '-b', 'app/one', app);
+ const joined = box.run(app, 'join', 'app');
+ lastStepEvidence = fixtureCommandEvidence('join worktree agent', joined, box.env);
+ assert.equal(joined.status, 0, lastStepEvidence);
+ const api = await startApi(t, box);
+ const boardsResponse = await observedApiStep('list registered boards', apiFetch(api, '/api/v1/boards'), box.env);
+ const board = boardsResponse.document.boards.find((candidate) => candidate.root === box.repo);
+ assert.ok(board, boardsResponse.evidence);
+ const path = `/api/v1/boards/${board.id}`;
+
+ const addedStep = await observedApiStep('add API move', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'add', args: { lane: 'app', title: 'Agent work' } }) }), box.env);
+ const added = addedStep.document;
+ const claimedStep = await observedApiStep('claim API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'next', args: {}, agent: 'app-1' }) }), box.env);
+ const claimed = claimedStep.document;
+ assert.ok(claimed?.event && typeof claimed.event === 'object', `claim response must contain an event\n${claimedStep.evidence}`);
+ assert.equal(claimed.event.event_by, 'app-1', claimedStep.evidence);
+ assert.equal(claimed.event.event_kind, 'claim', claimedStep.evidence);
+ assert.equal(claimed.result.item.item_id, added.result.item.item_id, claimedStep.evidence);
+
+ const renewedStep = await observedApiStep('renew API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'next', args: {}, agent: 'app-1' }) }), box.env);
+ const renewed = renewedStep.document;
+ assert.equal(renewed.result.held, true, renewedStep.evidence);
+ assert.equal(renewed.event.event_kind, 'renew', renewedStep.evidence);
+ assert.ok(renewed.event.event_id > claimed.event.event_id, renewedStep.evidence);
+ assert.equal(renewed.result.item.item_id, claimed.result.item.item_id, renewedStep.evidence);
+
+ const escalatedStep = await observedApiStep('escalate API move as app-1', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'escalate', item: added.result.item.item_id, args: { note: 'Two attempts failed' }, agent: 'app-1' }) }), box.env);
+ const escalated = escalatedStep.document;
+ assert.equal(escalated.event.event_kind, 'escalate', escalatedStep.evidence);
+ const eventsStep = await observedApiStep('read events after escalation', apiFetch(api, `${path}/events?after=${renewed.event.event_id}`), box.env);
+ const afterEscalation = eventsStep.document.events;
+ assert.deepEqual(afterEscalation.map((event) => event.event_kind), ['escalate', 'shout'], eventsStep.evidence);
+ assert.equal(afterEscalation[0].event_id, escalated.event.event_id, eventsStep.evidence);
+
+ const requestStep = await observedApiStep('create person request', apiFetch(api, `${path}/requests`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text: 'Approve the API row' }) }), box.env);
+ const requested = requestStep.document;
+ assertRequiredShape(requested, JSON_SHAPES.http.request.required, `create person request\n${requestStep.evidence}`);
+ const requestId = requested.result.id;
+ assert.equal(requested.event.event_by, 'person', requestStep.evidence);
+ const stateStep = await observedApiStep('read request state before answering', apiFetch(api, `${path}/state`), box.env);
+ const state = stateStep.document.state;
+ assert.deepEqual(state.requests.map((entry) => entry.shout_id), [requestId], stateStep.evidence);
+ assert.ok(!state.decisions.some((entry) => entry.shout_id === requestId), `person requests are not open decisions\n${stateStep.evidence}`);
+ const inboxStep = observedFixtureStep(box, 'read coordinator inbox', box.repo, 'inbox');
+ const inbox = inboxStep.document;
+ assert.equal(inbox.shouts[0].shout_id, requestId, inboxStep.evidence);
+ const resumeStep = observedFixtureStep(box, 'read coordinator resume', box.repo, 'resume');
+ const resumed = resumeStep.document;
+ assert.equal(resumed.requests[0].shout_id, requestId, resumeStep.evidence);
+
+ const answerStep = await observedApiStep('answer request through API move', apiFetch(api, `${path}/moves`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ verb: 'answer', item: requestId, args: { text: 'done' } }) }), box.env);
+ const answered = answerStep.document;
+ assert.equal(answered.event.event_kind, 'answer', answerStep.evidence);
+ assert.equal(answered.event.event_by, 'coordinator', answerStep.evidence);
+ const finalStateStep = await observedApiStep('confirm request disappears after answer', apiFetch(api, `${path}/state`), box.env);
+ assert.deepEqual(finalStateStep.document.state.requests, [], finalStateStep.evidence);
+ } catch (error) {
+ error.message = `${error.message}\n${lastStepEvidence}`;
+ throw error;
+ }
});
test('[A2,B25,B26,B27] HTTP decisions preserve routing, passing and explicit person answers', async (t) => {