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(core): withdraw a recorded accept before landing [V2,V6,H16]

Corey Olson532065ee7fdc
diff --git a/test/reopen.test.js b/test/reopen.test.js
index 75997dc0..0446081f 100644
--- a/test/reopen.test.js
+++ b/test/reopen.test.js
@@ -709,3 +709,70 @@ test('retained main controls builder first refusal during detached review [B13,B
const claimed = box.run(other, 'claim', '1');
assert.equal(claimed.code, 0, claimed.err);
});
+
+
+/** Give an accepted private item a real reviewer and an enabled builder-return window. */
+function withdrawalFixture(t) {
+ const box = project();
+ const file = join(box.repo, 'pullboard.json');
+ const config = JSON.parse(readFileSync(file, 'utf8'));
+ config.claim = { reopenFirstRefusalMinutes: 30 };
+ writeFileSync(file, JSON.stringify(config));
+ box.git(box.repo, 'add', 'pullboard.json');
+ box.git(box.repo, 'commit', '-q', '-m', 'chore: enable private builder return window');
+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');
+ const submitted = submitFixture(box);
+ const reviewer = reserveFixtureReview(box);
+ box.git(reviewer, 'switch', '-q', '--detach', submitted.commit);
+ const accepted = box.run(reviewer, 'verify', '1', 'accept', '--note', 'the private frozen check passed', '--json');
+ assert.equal(accepted.code, 0, accepted.err + accepted.out);
+ const board = openFixtureBoard(t, box);
+ const original = board.db.prepare('SELECT * FROM verdict WHERE item_id = ?').get(1);
+ return { box, reviewer, board, original, submitted };
+}
+
+test('a reviewer withdraws its own accept before landing and the builder gets the item back [V2,V6,H16]', t => {
+ for (const coordinator of [false, true]) {
+ const { box, reviewer, board, original, submitted } = withdrawalFixture(t);
+ const initial = store.itemThread(board, 1).find(row => row.kind === 'accept');
+ if (coordinator) {
+ const stranger = box.run(box.web, 'reopen', '1', '--withdraw-verdict', '--note', 'not my verdict', '--json');
+ assert.equal(JSON.parse(stranger.out).error.code, 'VERDICT_WITHDRAW_FORBIDDEN');
+ const missing = box.run(box.repo, 'reopen', '1', '--withdraw-verdict', '--note', ' ', '--json');
+ assert.equal(JSON.parse(missing.out).error.code, 'NOTE_REQUIRED');
+ }
+ const result = box.run(coordinator ? box.repo : reviewer, 'reopen', '1', '--withdraw-verdict',
+ '--note', 'the accepted interpretation missed a recorded ruling', '--json');
+ assert.equal(result.code, 0, result.err + result.out);
+ const item = store.getItem(board, 1);
+ assert.equal(item.item_status, 'open');
+ assert.equal(item.item_built_by, 'web-1');
+ assert.equal(item.item_commit, submitted.commit);
+ assert.equal(item.item_verdict, null);
+ assert.equal(item.item_verified_by, null);
+ assert.deepEqual(board.db.prepare('SELECT * FROM verdict WHERE item_id = ?').get(1), original,
+ 'the original verdict row is immutable');
+ const verdict = store.verdictsFor(board, 1)[0];
+ assert.equal(verdict.withdrawn, true);
+ assert.match(verdict.withdrawal.note, /recorded ruling/u);
+ const thread = store.itemThread(board, 1);
+ const accept = thread.find(row => row.kind === 'accept');
+ assert.equal(accept.eventId, initial.eventId);
+ assert.deepEqual(accept.detail, initial.detail, 'the recorded acceptance detail is not rewritten');
+ assert.equal(accept.withdrawn, true, 'history marks the exact earlier accept withdrawn');
+ const move = thread.findLast(row => row.kind === 'reopen');
+ assert.equal(move.detail.withdrawnVerdict.verdictId, original.verdict_id);
+ assert.equal(move.detail.withdrawnVerdict.acceptEventId, initial.eventId);
+ assert.equal(move.detail.reopenFirstRefusal.builder, 'web-1');
+ assert.equal(Date.parse(move.detail.reopenFirstRefusal.until) - Date.parse(move.at), 30 * 60_000);
+ assert.equal(box.run(box.web, 'claim', '1').code, 0, 'the original builder can resume normally');
+ }
+ const { box, reviewer, submitted } = withdrawalFixture(t);
+ box.git(box.repo, 'merge', '-q', '--no-edit', submitted.commit);
+ const merged = box.run(box.repo, 'merged', '1', '--json');
+ assert.equal(merged.code, 0, merged.err + merged.out);
+ for (const caller of [box.repo, reviewer]) {
+ const refused = box.run(caller, 'reopen', '1', '--withdraw-verdict', '--note', 'too late', '--json');
+ assert.equal(JSON.parse(refused.out).error.code, 'ALREADY_MERGED');
+ }
+});