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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(check): accept reverts a named guard, needs the check red [C7,V4]
Corey Olson2237a01404b9
diff --git a/docs/lifecycle.md b/docs/lifecycle.mdindex 3f16b16d..a344dc8d 100644--- a/docs/lifecycle.md+++ b/docs/lifecycle.md@@ -58,7 +58,7 @@ Each move checks its guards in this order and refuses with the first one that do| lapse | claimed | open | clock, when its lease runs out | none || submit | claimed | submitted | agent, coordinator | joined (NOT_JOINED or SESSION_LEDGER), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), correctionRefrozen (PENDING_REFREEZE), checkProvesSomething (CRITERION_PROVES_NOTHING), criterionUnchanged (CRITERIA_CHANGED), treeClean (DIRTY), nothingUntracked (UNTRACKED), hasCommit (NO_COMMIT), withinLane (OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), doctrineHolds (RATCHET_ROSE or RATCHET_UNCOUNTED), gateConfigured (NO_GATE), queuedItemLease (ITEM_LEASE_LOST or A5_GRAMMAR_VERSION or SPEC_BEHIND_MAIN or NOT_A_REPO or NO_CONFIG), gateGreen (GATE_RED or PIPEFAIL_UNAVAILABLE), treeStillDuringGate (MOVED_DURING_GATE), submissionProofValid (SUBMISSION_PROOF), childrenDone (CHILDREN_OPEN), headIsNew (HEAD_NOT_NEW) || reserve | submitted | submitted | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED or SESSION_LEDGER), roadmapReadable (MILESTONES_CORRUPT), itemExists (NO_ITEM), inState (NOT_SUBMITTED), reviewCooldownElapsed (REVIEW_COOLDOWN), notBuilder (SELF_VERIFY or VERIFIER_STANDING or SELF_SESSION_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD) |-| accept | submitted, verified | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED or SESSION_LEDGER), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notMerged (ALREADY_MERGED), verdictReviewRecorded (BAD_VERDICT_REVIEW), reviewTreeCurrent (STALE_VERDICT or DIRTY or UNTRACKED or VERDICT_TRUNK_MOVED), notBuilder (SELF_VERIFY or VERIFIER_STANDING or SELF_SESSION_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), queuedItemLease (ITEM_LEASE_LOST or A5_GRAMMAR_VERSION or SPEC_BEHIND_MAIN or NOT_A_REPO or NO_CONFIG), itemCheckGreen (CHECK_RED or CHECK_UNVERIFIED), proofNoted (PROOF_REQUIRED), result (LAND_HEADER), result (ENGINE_VERSION) |+| accept | submitted, verified | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED or SESSION_LEDGER), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notMerged (ALREADY_MERGED), verdictReviewRecorded (BAD_VERDICT_REVIEW), reviewTreeCurrent (STALE_VERDICT or DIRTY or UNTRACKED or VERDICT_TRUNK_MOVED), notBuilder (SELF_VERIFY or VERIFIER_STANDING or SELF_SESSION_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), queuedItemLease (ITEM_LEASE_LOST or A5_GRAMMAR_VERSION or SPEC_BEHIND_MAIN or NOT_A_REPO or NO_CONFIG), itemCheckGreen (CHECK_RED or CHECK_UNVERIFIED or GUARD_CANNOT_FAIL or GUARD_NOT_FOUND), proofNoted (PROOF_REQUIRED), result (LAND_HEADER), result (ENGINE_VERSION) || reject | submitted, verified | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED or SESSION_LEDGER), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notMerged (ALREADY_MERGED), verdictReviewRecorded (BAD_VERDICT_REVIEW), reviewTreeCurrent (STALE_VERDICT or DIRTY or UNTRACKED or VERDICT_TRUNK_MOVED), notBuilder (SELF_VERIFY or VERIFIER_STANDING or SELF_SESSION_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED), causeWellFormed (BAD_CAUSE), result (LAND_HEADER), result (ENGINE_VERSION), result (NOT_YOURS), result (CLOSED) || reopen | submitted, verified | open | coordinator | joined (NOT_JOINED or SESSION_LEDGER), itemExists (NO_ITEM), inState (NOT_SUBMITTED), coordinatorOnly (COORDINATOR_ONLY), noteGiven (NOTE_REQUIRED), causeWellFormed (BAD_CAUSE), notMerged (ALREADY_MERGED), landingFailureRecorded (LANDING_FAILURE_REQUIRED), trunkConflicts (NOT_CONFLICTING or CONFLICT_FILES or NO_TRUNK or MERGE_CHECK_FAILED), conflictAccepted (NOT_ACCEPTED or BAD_CONFLICT or ENGINE_VERSION) || escalate | open, claimed | open | agent, coordinator | joined (NOT_JOINED or SESSION_LEDGER), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), holderOrCoordinator (NOT_YOURS), inState (CLOSED) |@@ -127,6 +127,8 @@ Each move checks its guards in this order and refuses with the first one that do| RATCHET_UNCOUNTED | every touched doctrine check counts (exit 0 or 1), none rises above its committed count and no changed file gains a problem; watch-mode rules only count, only when accepted main has an approved doctrine rule with gate: check | fix the check so it exits 0 or 1 within its timeout, then submit again || CHECK_RED | the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance | reject the failing behavior; the builder fixes and resubmits || CHECK_UNVERIFIED | the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance | restore the frozen install or check environment and retry |+| GUARD_CANNOT_FAIL | the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance | reject: the check stays green with the named guard reverted |+| GUARD_NOT_FOUND | the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance | the named guard is not in the submitted commit; ask the coordinator to fix it || CRITERION_PROVES_NOTHING | the item's check does not already pass on main, or the person accepted that exact check, only when accepted main sets checks.provesNothing to "hold" | set a check that fails before the work, or the person runs pullboard check accept <id> || GATE_RED | the gate, which submit runs itself every time, is green at HEAD | fix what the digest names, commit, submit again || PIPEFAIL_UNAVAILABLE | the gate, which submit runs itself every time, is green at HEAD | rewrite the gate without a pipe |diff --git a/src/cli.js b/src/cli.jsindex b125ce99..63eba4d6 100644--- a/src/cli.js+++ b/src/cli.js@@ -113,6 +113,7 @@ import {timingDigest,withGateSlot,} from './gate.js';+import { guardRevertNote } from './guard-revert.js';import { draftRow } from './spec-draft.js';import {clashingRowDrafts,@@ -3028,7 +3029,7 @@ async function verifyHere(ctx, id, { second, values }) {const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(root, frozenCheck(item), { commit: checkedCommit, onFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });// A private checked composition needs this machine's live local gate markers [C7,V4].const shortEligible = Boolean(await explicitCheckFiles(root, frozenCheck(item), { commit: checkedCommit }));- check = await withGateSlot(root, async (lease) => { if (admitted) ({ trunk, review } = composeNow()); return nativeFlakes.verify(ctx, checkedItem, frozenCheck(item), { board, main: trunk.commit, commit: checkedCommit }, { ordered, withBoard, resourceAgent })(lease); }, { browser, remote: false, agent: me.id, item: String(id), kind: 'review', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, me.id, 'review') });+ check = await withGateSlot(root, async (lease) => { if (admitted) ({ trunk, review } = composeNow()); const ran = await nativeFlakes.verify(ctx, checkedItem, frozenCheck(item), { board, main: trunk.commit, commit: checkedCommit }, { ordered, withBoard, resourceAgent })(lease); return ran.state === 'pass' ? { ...ran, guardNote: guardRevertNote(root, checkedItem, lease) } : ran; }, { browser, remote: false, agent: me.id, item: String(id), kind: 'review', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, me.id, 'review') });} else {check = checkAtCommit(root, checkedItem);}@@ -3061,7 +3062,7 @@ async function verifyHere(ctx, id, { second, values }) {agentId: me.id,decision,reason: values.reason,- note: (textArg(ctx.io, values, 'note') ?? '') + unaffectedMove,+ note: (textArg(ctx.io, values, 'note') ?? '') + unaffectedMove + (check?.guardNote ?? ''),...(decision === 'REJECT' && values.cause !== undefined ? { cause: values.cause } : {}),head,digest,diff --git a/src/guard-revert.js b/src/guard-revert.jsnew file mode 100644index 00000000..5eee3fe1--- /dev/null+++ b/src/guard-revert.js@@ -0,0 +1,80 @@+/**+ * A guard whose check passes when the guard is deleted is not a guard. An item can name its guard in+ * its criterion, and accept then reverts exactly that guard in a scratch tree and needs the frozen+ * check to fail there [C7,V4].+ *+ * Two forms: `guard: <path>:<from>-<to>` (lines of the submitted file, removed in the scratch tree) and+ * `guard: patch <path>` (a patch file in the submitted commit, applied in reverse).+ */+import { spawnSync } from 'node:child_process';+import {+ existsSync,+ readFileSync,+ writeFileSync,+} from 'node:fs';+import { join } from 'node:path';+import { Refused } from './refused.js';+import { checkAtCommit } from './trusted-policy.js';++const GUARD = /\bguard:\s+(?:patch\s+(\S+)|(\S+?):(\d+)-(\d+))/u;++/**+ * Read the guard an item's criterion names, or null when it names none.+ *+ * @param {{ item_criterion?: string|null }} item+ * @returns {{ text: string, patch?: string, path?: string, from?: number, to?: number } | null}+ */+export function guardOf(item) {+ const found = GUARD.exec(item?.item_criterion ?? '');+ if (!found) return null;+ if (found[1]) {+ const patch = found[1].replace(/[.,;]+$/u, '');+ return { text: `patch ${patch}`, patch };+ }+ return { text: `${found[2]}:${found[3]}-${found[4]}`, path: found[2], from: Number(found[3]), to: Number(found[4]) };+}++/**+ * Revert one guard inside a scratch checkout.+ *+ * @param {string} directory+ * @param {NonNullable<ReturnType<typeof guardOf>>} guard+ * @returns {string} empty when reverted, else why it could not be+ */+function revert(directory, guard) {+ if (guard.patch) {+ if (!existsSync(join(directory, guard.patch))) return `${guard.patch} is not in the submitted commit`;+ const applied = spawnSync('git', ['apply', '-R', '--whitespace=nowarn', guard.patch], { cwd: directory, encoding: 'utf8' });+ return applied.status === 0 ? '' : `${guard.patch} does not reverse cleanly: ${String(applied.stderr).trim().split('\n')[0]}`;+ }+ const file = join(directory, guard.path);+ if (guard.path.startsWith('/') || guard.path.split('/').includes('..') || !existsSync(file)) return `${guard.path} is not in the submitted commit`;+ const lines = readFileSync(file, 'utf8').split('\n');+ if (guard.from < 1 || guard.to < guard.from || guard.to > lines.length) return `${guard.path} has no lines ${guard.from}-${guard.to}`;+ lines.splice(guard.from - 1, guard.to - guard.from + 1);+ writeFileSync(file, lines.join('\n'));+ return '';+}++/**+ * Run the frozen check with the item's named guard reverted, in a scratch tree at the submitted commit.+ * The caller's own run of the check at the commit is the restored run, so a green there plus a red here+ * proves the guard can fail. An item that names no guard returns an empty note.+ *+ * @param {string} root+ * @param {any} item - with item_commit and the frozen check+ * @param {object} [lease] - the held gate slot, shared with the restored run+ * @returns {string} the line the verdict note carries, or '' when no guard is named+ */+export function guardRevertNote(root, item, lease) {+ const guard = guardOf(item);+ if (!guard) return '';+ let problem = '';+ const run = checkAtCommit(root, item, { gateLease: lease, mutate: (directory) => { problem = revert(directory, guard); return problem; } });+ if (problem) throw new Refused('GUARD_NOT_FOUND', `#${item.item_id}'s guard ${guard.text} cannot be reverted: ${problem}`);+ if (run.state === 'pass') {+ throw new Refused('GUARD_CANNOT_FAIL', `#${item.item_id}'s check stays green with its guard ${guard.text} reverted, so the check does not test the guard`);+ }+ if (run.state !== 'red') throw new Refused('CHECK_UNVERIFIED', `the frozen check could not be verified with guard ${guard.text} reverted (${run.stage}); retry verification`);+ return `\nguard ${guard.text} reverted: check red; restored: check green`;+}diff --git a/src/machine.js b/src/machine.jsindex d4398e02..6fd7189e 100644--- a/src/machine.js+++ b/src/machine.js@@ -170,7 +170,7 @@ export const GUARDS = [{ id: 'trunkMergeClean', refuse: 'MERGE_CONFLICT', alsoRefuses: [{ code: 'MERGE_CHECK_FAILED', next: 'use Git 2.38 or newer, restore its objects and retry' }, { code: 'NO_POLICY', next: 'restore the primary repository metadata' }, { code: 'NO_TRUNK', next: 'check out the trunk branch in the main checkout once and run pullboard inbox' }], rule: 'the candidate merges cleanly into the current primary branch without changing an index or worktree', next: 'merge the trunk into your branch, resolve conflicts, commit and resubmit', source: 'cli' },{ id: 'noUnverifiedStack', refuse: 'STACKED_ON_UNVERIFIED', rule: "the candidate range contains no other item's unverified submitted commit", next: 'wait for that item to be accepted, or rebuild without its commits', source: 'cli' },{ id: 'doctrineHolds', refuse: 'RATCHET_ROSE', alsoRefuses: [{ code: 'RATCHET_UNCOUNTED', next: 'fix the check so it exits 0 or 1 within its timeout, then submit again' }], rule: "every touched doctrine check counts (exit 0 or 1), none rises above its committed count and no changed file gains a problem; watch-mode rules only count", next: "fix the new problems, commit, submit again; only the person's signature raises count:", source: 'cli', when: 'only when accepted main has an approved doctrine rule with gate: check' },- { id: 'itemCheckGreen', refuse: 'CHECK_RED', alsoRefuses: [{ code: 'CHECK_UNVERIFIED', next: 'restore the frozen install or check environment and retry' }], rule: 'the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance', next: 'reject the failing behavior; the builder fixes and resubmits', source: 'cli' },+ { id: 'itemCheckGreen', refuse: 'CHECK_RED', alsoRefuses: [{ code: 'CHECK_UNVERIFIED', next: 'restore the frozen install or check environment and retry' }, { code: 'GUARD_CANNOT_FAIL', next: 'reject: the check stays green with the named guard reverted' }, { code: 'GUARD_NOT_FOUND', next: 'the named guard is not in the submitted commit; ask the coordinator to fix it' }], rule: 'the frozen item check passes at the submitted commit, or its clean reviewed composition for a stale acceptance', next: 'reject the failing behavior; the builder fixes and resubmits', source: 'cli' },{ id: 'checkProvesSomething', refuse: 'CRITERION_PROVES_NOTHING', rule: "the item's check does not already pass on main, or the person accepted that exact check", next: 'set a check that fails before the work, or the person runs pullboard check accept <id>', source: 'cli', when: 'only when accepted main sets checks.provesNothing to "hold"' },{ id: 'gateGreen', refuse: 'GATE_RED', alsoRefuses: [{ code: 'PIPEFAIL_UNAVAILABLE', next: 'rewrite the gate without a pipe' }], rule: 'the gate, which submit runs itself every time, is green at HEAD', next: 'fix what the digest names, commit, submit again', source: 'cli' },diff --git a/src/next-steps.js b/src/next-steps.jsindex 0dc58ab7..e55110f5 100644--- a/src/next-steps.js+++ b/src/next-steps.js@@ -217,6 +217,8 @@ export const NEXT_STEPS = Object.freeze({CHECK_ACCEPT_STALE: 'read the current check with pullboard show <id>, then the person accepts it again: pullboard check accept <id>',CHECK_CANNOT_FAIL: 'write a check that exits nonzero on the problem, then add the item again',CHECK_CONFIRM: 'read the check command, then run pullboard check <id> --yes',+ GUARD_CANNOT_FAIL: 'reject: the check does not test the guard; ask for one that fails with the guard reverted: pullboard verify <id> reject --reason TEST_FAILURE --note "<what the check missed>"',+ GUARD_NOT_FOUND: 'reject: the named guard is not in the submitted commit; fix the guard line in the criterion with the coordinator: pullboard shout coordinator --decision "<id> guard does not match the commit"',CHECK_RED: 'reject with what failed: pullboard verify <id> reject --reason TEST_FAILURE --note "<what failed>"',CHECK_UNVERIFIED: 'restore the install or check environment, then run pullboard verify <id> again',CHILDREN_OPEN: 'finish the child items (pullboard list --all), or ask the coordinator to withdraw them',diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex c63bd3ed..5fc1da6c 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -186,9 +186,10 @@ export function frozenCheck(item) {/** Run the frozen check at the exact submitted commit in a private clone, leaving live worktrees untouched.* @param {string} root* @param {object} item- * @param {{ waitMs?: number, gateSlotHeld?: boolean, gateLease?: object }} [options] - Queue wait before the private check started.+ * @param {{ waitMs?: number, gateSlotHeld?: boolean, gateLease?: object, mutate?: (directory: string) => string }} [options] - Queue wait before the private check started;+ * mutate changes the scratch tree after checkout (a guard revert) and returns a reason when it cannot [C7,V4].*/-export function checkAtCommit(root, item, { waitMs = 0, gateSlotHeld = false, gateLease } = {}) {+export function checkAtCommit(root, item, { waitMs = 0, gateSlotHeld = false, gateLease, mutate } = {}) {const command = frozenCheck(item);if (!command) return { state: 'pass', green: true, checked: false, report: '' };let config;@@ -246,7 +247,11 @@ export function checkAtCommit(root, item, { waitMs = 0, gateSlotHeld = false, ga}const checkout = clone.status === 0 && spawnSync('git', ['checkout', '--quiet', '--detach', item.item_commit], { cwd: copy, env, stdio: 'ignore' });if (!checkout || checkout.status !== 0) return finish('unverified', 'clone or checkout could not start');- checkedSourceReady = true;+ if (mutate) {+ const reason = mutate(copy);+ if (reason) return finish('unverified', reason);+ }+ checkedSourceReady = !mutate;const deadline = Date.now() + timeout;if (install) {installLogPath = join(scratch, 'install.log');diff --git a/test/check-accept.test.js b/test/check-accept.test.jsnew file mode 100644index 00000000..6aff4db2--- /dev/null+++ b/test/check-accept.test.js@@ -0,0 +1,108 @@+/** Accept reverts a named guard in a scratch tree and needs the frozen check red there, green restored [C7,V4]. */+import assert from 'node:assert/strict';+import { runFixtureChild, runFixtureGit, safeFixtureDiagnostic } from './fixture-child.js';+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join, resolve } from 'node:path';+import { test } from 'node:test';++const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+const SPEC = '# Fixture\n\n## G · Goals\n- G1 [approved, must] The fixture item is complete. | gate: none\n';+const SOURCE = 'export const answer = 42;\n// kept\n';++/** Create a private CLI environment with isolated Git, home and board state. */+function sandbox() {+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-guard-'));+ const shimDir = join(dir, 'bin');+ mkdirSync(shimDir);+ writeFileSync(join(shimDir, 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${BIN}" "$@"\n`);+ chmodSync(join(shimDir, 'pullboard'), 0o755);+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_')));+ Object.assign(env, {+ PATH: `${shimDir}:${process.env.PATH}`,+ HOME: join(dir, 'home'),+ GIT_CONFIG_GLOBAL: '/dev/null',+ GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'Fixture agent',+ GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'Fixture agent',+ GIT_COMMITTER_EMAIL: '[email protected]',+ PULLBOARD_HOME: join(dir, 'pullboard-home'),+ PULLBOARD_MACHINE_HOME: join(dir, 'machine-home'),+ });+ delete env.NODE_TEST_CONTEXT;+ mkdirSync(env.HOME);+ /** Run isolated Git commands for this fixture. */+ const git = (cwd, ...args) => runFixtureGit(args, { cwd, env, encoding: 'utf8', stdio: 'pipe' });+ /** Run the checked-out CLI without invoking any shared board. */+ const run = (cwd, ...args) => {+ const result = runFixtureChild(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8' });+ return { code: result.status, out: result.stdout, err: result.failure ?? result.stderr };+ };+ return { dir, env, git, run };+}++/** Initialize a real board repository and one joined builder worktree. */+function project(box) {+ const repo = join(box.dir, 'repo');+ const web = join(box.dir, 'web-1');+ mkdirSync(repo);+ box.git(repo, 'init', '-q', '-b', 'main');+ assert.equal(box.run(repo, 'init').code, 0);+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({+ gate: 'test ! -f RED', spec: 'SPEC.md', verify: { policy: 'any', family: 'off' },+ lease: '2h', lanes: { web: { owns: ['web/'], specs: ['G'] }, review: { owns: [], specs: [] } }, shared: [],+ }, null, 2) + '\n');+ writeFileSync(join(repo, 'SPEC.md'), SPEC);+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: initialize fixture');+ box.git(repo, 'worktree', 'add', '-q', web, '-b', 'web/one');+ assert.match(box.run(web, 'join', 'web').out, /joined as web-1/);+ return { repo, web };+}++/** Run a fixture command and fail with its captured diagnostics if it refuses. */+function succeeds(box, cwd, ...args) {+ const result = box.run(cwd, ...args);+ assert.equal(result.code, 0, safeFixtureDiagnostic(`${result.out}\n${result.err}`, box.env));+ return result.out;+}++/** Add, claim, commit and submit an item whose criterion names a guard, then check out its commit. */+function submittedWithGuard(box, repo, web, check) {+ const criterion = 'The fixture item is complete. guard: web/guard.js:1-1';+ const added = succeeds(box, repo, 'add', 'web', 'Guarded fix', '--specs', 'G1', '--criterion', criterion, '--check', check);+ const id = Number(/#(\d+)/.exec(added)?.[1]);+ succeeds(box, web, 'claim', String(id));+ mkdirSync(join(web, 'web'), { recursive: true });+ writeFileSync(join(web, 'web', 'guard.js'), SOURCE);+ box.git(web, 'add', '-A');+ box.git(web, 'commit', '-q', '-m', `fix(web): guarded fix [G1]`);+ succeeds(box, web, 'submit', String(id));+ box.git(repo, 'switch', '--detach', 'web/one');+ return id;+}++test('accept refuses a fix whose guard revert stays green [C7,V4]', () => {+ const box = sandbox();+ try {+ const { repo, web } = project(box);+ const id = submittedWithGuard(box, repo, web, 'test -f web/guard.js');+ const refused = box.run(repo, 'verify', String(id), 'accept', '--as', 'coordinator', '--note', 'the check passed');+ assert.notEqual(refused.code, 0, refused.out);+ assert.match(`${refused.out}\n${refused.err}`, /GUARD_CANNOT_FAIL/u);+ assert.match(`${refused.out}\n${refused.err}`, /web\/guard\.js:1-1/u, 'the refusal names the guard');+ } finally { rmSync(box.dir, { recursive: true, force: true }); }+});++test('a named guard that turns the check red is accepted [C7,V4]', () => {+ const box = sandbox();+ try {+ const { repo, web } = project(box);+ const id = submittedWithGuard(box, repo, web, 'grep -q "answer = 42" web/guard.js');+ const accepted = succeeds(box, repo, 'verify', String(id), 'accept', '--as', 'coordinator', '--note', 'the check passed');+ assert.match(accepted, /verified #/u);+ const shown = succeeds(box, repo, 'show', String(id));+ assert.match(shown, /guard web\/guard\.js:1-1 reverted: check red; restored: check green/u);+ } finally { rmSync(box.dir, { recursive: true, force: true }); }+});