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.

feat(gate): defer a large affected selection to landing [C7]

Corey Olson7297c754840d
diff --git a/docs/api.md b/docs/api.md
index 3c6b1a64..fb1cd263 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -193,7 +193,7 @@ Each checkout is bound to the first agent session that writes there. The local G
`status.reviewQueue` contains `pending`, `reviewing` (distinct agents with live review leases), `reserved`, `oldestSubmittedAt` and `ageMs`. Age starts at each outstanding item's latest submit event; reserving or renewing its review does not reset it. An empty queue has `oldestSubmittedAt: null` and `ageMs: 0`. Among unreserved submissions, `awaitingFirstReview` counts items with no release since their latest submission; `releasedWithoutVerdict` counts those released without a verdict. `releasedItems` lists `{item, releases, reason}` with the cumulative release count and latest reason for that submission. Historical releases without a reason show `reason not recorded`.
-With `submitGate: "landing"`, `status.submitInvariantProposals` lists files that failed outside a recorded submit selection. Each proposal carries `file`, `escapes` (distinct tested merge commits), `runtimeMs`, `budgetMs: 60000`, `withinBudget`, `commits` and the participating `submissions`. Repeated escapes below budget come first. Unmeasured whole-file runtime is `null`, not a sum of test-case durations. A later whole-file diagnostic or full gate passing at the identical commit suppresses that escape; another commit or merely an equal Git tree does not. Submission events record versioned `submissionProof: { version: 1, files, full, deferred, reason }`, including the actual full-fallback reason. A deferred full fallback records only invariants actually selected to run, rather than its possible full selection. Historical submissions without this receipt remain unknown. Landing batches append versioned `invariantEvidence` with actual tested commits, participants and whole-file diagnostics; earlier evidence cannot be replaced. Status reads those canonical events and changes no configuration. Edit `submitInvariants` on main to accept a proposal. Outside the landing submit policy the proposal list is empty.
+With `submitGate: "landing"`, `status.submitInvariantProposals` lists files that failed outside a recorded submit selection. Each proposal carries `file`, `escapes` (distinct tested merge commits), `runtimeMs`, `budgetMs: 60000`, `withinBudget`, `commits` and the participating `submissions`. Repeated escapes below budget come first. Unmeasured whole-file runtime is `null`, not a sum of test-case durations. A later whole-file diagnostic or full gate passing at the identical commit suppresses that escape; another commit or merely an equal Git tree does not. Submission events record versioned `submissionProof: { version: 1, files, full, deferred, reason }`, including the actual full-fallback reason, plus `deferredFiles` when `submitDeferAbove` moved the affected selection to landing. A deferred full fallback records only invariants actually selected to run, rather than its possible full selection. Historical submissions without this receipt remain unknown. Landing batches append versioned `invariantEvidence` with actual tested commits, participants and whole-file diagnostics; earlier evidence cannot be replaced. Status reads those canonical events and changes no configuration. Edit `submitInvariants` on main to accept a proposal. Outside the landing submit policy the proposal list is empty.
Releasing a reserved review requires a nonempty one-line `--note` (or `--note-file`); the authenticated release action accepts the same `note` field. A refusal keeps the reservation and records no release. The same reviewer is not offered that submission again until it is resubmitted or an hour passes, while other reviewers remain eligible. Releasing a build claim keeps its existing behavior and does not require a reason.
diff --git a/docs/formats.md b/docs/formats.md
index 172ff6cd..c9520633 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -463,6 +463,8 @@ Migration preserves event rows and adds only schema objects that are missing.
A project with `"submitGate": "landing"` can also set `"submitInvariants": ["test/guard.test.js"]` to run a small set of project guard files on every submit, even when uncertain selection defers the full suite. The list defaults to empty and requires the project's explicit `affectedTests` runner; no framework or test files are added by default. Submit reads the list and its runner from accepted main, so a candidate cannot remove or replace its required files. Named affected tests and invariants run once per file, with their paths and results in the receipt. Missing invariant files refuse the submit, and subset passes never stamp the full gate. The coordinator still runs the configured full suite at landing.
+With `"submitGate": "landing"`, `"submitDeferAbove": N` (a whole number, 1 or more; absent by default) moves an affected selection of more than N test files from submit to landing. Such a submit runs its frozen check, the static checks and `submitInvariants` only, records the selection as `submissionProof.deferredFiles`, and notes `<count> affected test files deferred to the landing gate` on the submission, where `show` prints it. A full-gate landing already runs every file. A landing with `"landing": { "publish": "separate" }` runs the recorded files on the merged tree before anything lands; a red sends back each item whose own deferred files failed, and nothing in that batch lands.
+
<!-- pass-rule:start -->
The `pass` event is emitted by `passDecision` only for the coordinator; another agent receives `COORDINATOR_ONLY`. Its event actor is the coordinator. The person receives the passed decision, while the event table records who performed the pass.
<!-- pass-rule:end -->
diff --git a/src/commands/submit.js b/src/commands/submit.js
index 4d2e4cb9..06362df2 100644
--- a/src/commands/submit.js
+++ b/src/commands/submit.js
@@ -16,6 +16,7 @@ import {
gateWaitReporter,
} from '../gate-wait.js';
import {
+ deferredSelectionNote,
runSubmitGate,
submitGateReport,
withGateSlot,
@@ -163,7 +164,7 @@ export async function submitHere(ctx, id, infra) {
// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).
// Empty frozen gates adopt accepted main setup; only a full fallback may stamp its tree.
const submitConfig = { ...ctx.config, gate: ctx.config.gate.trim() ? ctx.config.gate : acceptedMain.config.gate, submitGate: acceptedMain.config.submitGate, staticChecks: acceptedMain.config.staticChecks,
- submitInvariants: acceptedMain.config.submitInvariants,
+ submitInvariants: acceptedMain.config.submitInvariants, submitDeferAbove: acceptedMain.config.submitDeferAbove,
// The accepted project runner interprets its current invariant files; candidate config cannot replace it.
...(acceptedMain.config.submitInvariants.length ? { affectedTests: acceptedMain.config.affectedTests } : {}) };
const gate = await runSubmitGate(root, submitConfig, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: queuedItemLease(ctx, held, me.id, 'build'), onBrowserFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson),
@@ -193,13 +194,13 @@ export async function submitHere(ctx, id, infra) {
// The waived run is written to the item's thread before the submission, so no waived proof reads as green.
if (waived) await ordered(ctx, board, 'appendFact', [id, { agentId: me.id, kind: 'measurement', text: `submission proof at ${commit.slice(0, 12)} was red and is recorded as waived, not green; every failure is covered by a live person waiver:\n${waivedLines.join('\n')}` }]);
return await ordered(ctx, board, 'submit', [id, { agentId: me.id, commit, tree: headTree(root) ?? '', files: filesSince(root, id, claimHead, commit), policyCommit: acceptedMain.commit, ...(infraRecord ? { infra: infraRecord } : {}),
- submissionProof: { version: 1, files: gate.files, full: gate.full, deferred: gate.deferred, reason: gate.reason },
- ...(gate.deferred ? { note: 'full suite deferred to the landing gate' } : {}) }]);
+ submissionProof: { version: 1, files: gate.files, full: gate.full, deferred: gate.deferred, reason: gate.reason, ...(gate.deferredFiles ? { deferredFiles: gate.deferredFiles } : {}) },
+ ...(gate.deferred ? { note: gate.deferredFiles ? deferredSelectionNote(gate.deferredFiles) : 'full suite deferred to the landing gate' } : {}) }]);
});
const report = waived
? `submission proof waived, not green: ${waived.length} failure(s), each covered by a live person waiver; the whole output is in ${gate.log}\n${waivedLines.join('\n')}`
: submitGateReport(gate);
- return reportSubmission(ctx, id, commit, { green: gate.isGreen, report, files: gate.files, full: gate.full, deferred: gate.deferred, deferFullFallback: gate.deferFullFallback, reason: gate.reason, check: gate.check,
+ return reportSubmission(ctx, id, commit, { green: gate.isGreen, report, files: gate.files, full: gate.full, deferred: gate.deferred, deferFullFallback: gate.deferFullFallback, ...(gate.deferredFiles ? { deferredFiles: gate.deferredFiles } : {}), reason: gate.reason, check: gate.check,
log: gate.log, profile: gate.profile, profilePath: gate.profilePath, proofLog: gate.proofLog, proofProfilePath: gate.proofProfilePath,
...(waived ? { waived: waived.map(({ file, name, waiver }) => ({ file, name, waiver: waiver.id, reason: waiver.reason, until: waiver.until })) } : {}) }, doctrine);
}
diff --git a/src/config.js b/src/config.js
index 3251d974..44febc63 100644
--- a/src/config.js
+++ b/src/config.js
@@ -196,6 +196,9 @@ export function configProblems(config) {
if (config.submitGate !== undefined && config.submitGate !== 'landing') {
problems.push('"submitGate" is "landing" when the full suite should be deferred until landing');
}
+ if (config.submitDeferAbove !== undefined && (!Number.isSafeInteger(config.submitDeferAbove) || config.submitDeferAbove < 1 || config.submitGate !== 'landing')) {
+ problems.push('"submitDeferAbove" is a whole number, 1 or more, with "submitGate": "landing": a submit whose affected selection names more test files runs only its check, static checks and submitInvariants, and the landing gate runs the selection; leave it out to run every selected file at submit');
+ }
if (config.landingShards !== undefined && (!Number.isSafeInteger(config.landingShards) || config.landingShards < 1 || config.landingShards > 64)) {
problems.push('"landingShards" is a whole number from 1 to 64: how many shards the landing gate splits its test files into');
}
diff --git a/src/gate.js b/src/gate.js
index ead1127d..fbc38a36 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -723,6 +723,8 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
: { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };
const deferred = config.submitGate === 'landing';
const deferFullFallback = deferred && selection.full;
+ // A selection over submitDeferAbove files moves to the landing gate, which runs every recorded file before the item lands.
+ const deferSelection = deferred && !selection.full && Number.isSafeInteger(config.submitDeferAbove) && selection.files.length > config.submitDeferAbove;
const invariants = deferred ? [...new Set(config.submitInvariants ?? [])].sort() : [];
if (invariants.length && !config.affectedTests?.trim()) {
throw new Refused('BAD_CONFIG', 'submitInvariants requires the project affectedTests runner');
@@ -732,10 +734,10 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
try { file = statSync(join(root, path)).isFile(); } catch { /* Missing or unreadable invariants refuse rather than silently disappearing. */ }
if (!file) throw new Refused('BAD_CONFIG', `submitInvariants file ${path} is missing or unreadable; restore it or update the list on accepted main`);
}
- const proofFiles = [...new Set([...(deferFullFallback ? [] : selection.files), ...invariants])].sort();
+ const proofFiles = [...new Set([...(deferFullFallback || deferSelection ? [] : selection.files), ...invariants])].sort();
const allowBrowserFreeChecks = browserFreeChecksEnabled();
const checkUsesBrowser = check ? (!allowBrowserFreeChecks || await checkNeedsBrowser(root, check, { onFallback: onBrowserFallback })) : false;
- const proofUsesBrowser = deferFullFallback
+ const proofUsesBrowser = deferFullFallback || deferSelection
? (proofFiles.length > 0 && (!allowBrowserFreeChecks || await testsNeedBrowser(root, proofFiles, { onFallback: onBrowserFallback })))
: (selection.full || !allowBrowserFreeChecks || await testsNeedBrowser(root, proofFiles, { onFallback: onBrowserFallback }));
const browser = checkUsesBrowser || proofUsesBrowser;
@@ -765,7 +767,8 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
executionSource: profiles.find(value => value.executionSource)?.executionSource } : {}),
});
refuseSandboxBlocked(proof);
- return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, ...(deferred ? { files: proofFiles, submitInvariants: invariants } : {}), deferred, deferFullFallback, check: receipt,
+ return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, ...(deferred ? { files: proofFiles, submitInvariants: invariants } : {}),
+ ...(deferSelection ? { deferredFiles: selection.files, deferAbove: config.submitDeferAbove } : {}), deferred, deferFullFallback, check: receipt,
profile, profilePath, proofProfilePath: proof.profilePath, proofLog: proof.log };
};
if (!criterion.isGreen) {
@@ -784,7 +787,9 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
proof = { ...runProfiledShell(root, command, { waitMs: proofWait, profileFile: `${proofLog}.profile.json`, gateLease: lease, stages: true }), isCached: false, log: proofLog };
writeFileSync(proofLog, proof.output);
}
- const phase = deferFullFallback ? `submit invariants: ${invariants.length ? invariants.join(', ') : 'none'}; full suite deferred to the landing gate` : selection.full ? 'full gate' : 'affected tests';
+ const phase = deferFullFallback || deferSelection
+ ? `submit invariants: ${invariants.length ? invariants.join(', ') : 'none'}; ${deferSelection ? `${selection.files.length} affected test files` : 'full suite'} deferred to the landing gate`
+ : selection.full ? 'full gate' : 'affected tests';
writeFileSync(log, `item check:\n${criterion.output}\n${phase}:\n${proof.output}`);
if (!proof.isGreen && onFailure) await onFailure(proof, { root,
command: !deferFullFallback && selection.full ? config.gate : `${config.affectedTests.trimEnd()} ${proofFiles.map(path => commandWord('./' + path)).join(' ')}`, lease });
@@ -793,6 +798,11 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
}, { browser, agent, item, kind, itemCheck: true, onWait });
}
+/** The durable words a submission and its reviewers read for an affected selection moved to the landing gate. */
+export function deferredSelectionNote(files) {
+ return `${files.length} affected test files deferred to the landing gate`;
+}
+
/** Describe precisely which submission proof ran, including absent checks and full fallbacks. */
export function submitGateReport(gate) {
const check = gate.check.checked ? `item check ${gate.check.green ? 'green' : 'red'} in ${gate.check.seconds}s` : 'no item check';
@@ -800,10 +810,14 @@ export function submitGateReport(gate) {
const reason = gate.reason ? `: ${gate.reason}` : '';
const timings = timingDigest(gate.profile);
const detail = timings ? `\n${timings}\ntiming profile: ${gate.profilePath}` : '';
+ const invariantsOnly = gate.deferFullFallback || Boolean(gate.deferredFiles);
+ const invariants = gate.submitInvariants?.length ? 'submit invariants: ' + gate.submitInvariants.join(', ') + '; ' : '';
const proof = gate.deferFullFallback
- ? `${gate.submitInvariants?.length ? 'submit invariants: ' + gate.submitInvariants.join(', ') + '; ' : ''}full suite deferred to the landing gate${reason}`
- : `affected tests: ${gate.files.length ? gate.files.join(', ') : 'none'}; full suite deferred to the landing gate${gate.submitInvariants?.length ? '; submit invariants: ' + gate.submitInvariants.join(', ') : ''}`;
- const result = gate.deferFullFallback && !gate.submitInvariants?.length ? '' : `; ${gate.isGreen ? `${gate.deferFullFallback ? 'submit invariants' : 'affected tests'} green in ${gate.seconds}s` : gateReport(gate)}`;
+ ? `${invariants}full suite deferred to the landing gate${reason}`
+ : gate.deferredFiles
+ ? `${invariants}${deferredSelectionNote(gate.deferredFiles)} (over submitDeferAbove ${gate.deferAbove}): ${gate.deferredFiles.join(', ')}`
+ : `affected tests: ${gate.files.length ? gate.files.join(', ') : 'none'}; full suite deferred to the landing gate${gate.submitInvariants?.length ? '; submit invariants: ' + gate.submitInvariants.join(', ') : ''}`;
+ const result = invariantsOnly && !gate.submitInvariants?.length ? '' : `; ${gate.isGreen ? `${invariantsOnly ? 'submit invariants' : 'affected tests'} green in ${gate.seconds}s` : gateReport(gate)}`;
return `${check}; ${proof}${result}${detail}`;
}
const selection = gate.full ? `full gate: ${gate.reason}` : `affected tests: ${gate.files.length ? gate.files.join(', ') : 'none'}`;
diff --git a/src/land.js b/src/land.js
index 5140a842..d514ccc0 100644
--- a/src/land.js
+++ b/src/land.js
@@ -39,8 +39,10 @@ import {
readGateReceipt,
receiptStore,
} from './gate-run-receipt.js';
+import { testsNeedBrowser } from './browser-admission.js';
import { laneOf } from './lanes.js';
import { Refused } from './refused.js';
+import { browserFreeChecksEnabled } from './settings.js';
import { landingFileTimes } from './submit-invariants.js';
import {
flakeSource,
@@ -615,13 +617,49 @@ async function quickGuards(state) {
if (!run.isGreen) throw new Refused('GATE_RED', `the submit invariants are red on the merged tree: ${invariants.join(', ')}`);
}
+/** The affected test files each batch item's submission moved to the landing gate, read from its exact submit. */
+function deferredSelections(state) {
+ return state.batch.items.flatMap((entry) => {
+ const event = store.events(state.board, { itemId: entry.id }).findLast((row) => row.event_kind === 'submit');
+ const detail = event ? JSON.parse(event.event_detail) : null;
+ const files = detail?.commit === entry.commit ? detail.submissionProof?.deferredFiles ?? [] : [];
+ return files.length ? [{ entry, files }] : [];
+ });
+}
+
+/**
+ * Run every affected test file a submit deferred over submitDeferAbove on the merged tree, before anything lands.
+ * A red sends back each item whose own deferred selection holds a failing file, the way a red submit would.
+ */
+async function deferredGuards(state) {
+ const root = state.batch.root;
+ const deferred = deferredSelections(state);
+ if (!deferred.length) return;
+ const files = [...new Set(deferred.flatMap((row) => row.files))].sort();
+ const browser = !browserFreeChecksEnabled() || await testsNeedBrowser(root, files);
+ const run = await withGateSlot(root, lease => runProfiledShell(root, `${state.config.affectedTests} ${files.map(quote).join(' ')}`, { waitMs: lease.waitMs, gateLease: lease, stages: true }),
+ { agent: 'coordinator', kind: 'gate', landing: true, browser, onWait: state.onWait });
+ state.say(`deferred affected tests: ${files.length} file(s) ${run.isGreen ? 'green' : 'red'} on the merged tree`);
+ if (run.isGreen) return;
+ const failures = landingFailures(run.output, root);
+ const failed = new Set(failures.map((failure) => failure.file).filter(Boolean));
+ for (const { entry, files: own } of deferred) {
+ if (!own.some((file) => failed.has(file)) || state.culprits.some((culprit) => culprit.id === entry.id)) continue;
+ state.culprits.push({ id: entry.id, commit: entry.commit, ...(entry.reviewedCommit ? { reviewedCommit: entry.reviewedCommit } : {}),
+ mergeCommit: state.batch.tip, tests: failures.filter((failure) => own.includes(failure.file)) });
+ }
+ await save(state, { culprits: state.culprits });
+ await returnCulprits(state);
+ throw new Refused('GATE_RED', `the deferred affected tests are red on the merged tree: ${[...failed].join(', ') || 'no failing file was named; inspect the merged tree'}`);
+}
+
/**
* Tier 1 (#801): after a clean merge and its quick guards, the batch lands on the local trunk in seconds, with each
* item's merged receipt; nothing is pushed. pullboard publish runs the whole suite on the trunk head and pushes it.
*/
async function landOnTrunk(state) {
await save(state, { state: 'gating', tip: headCommit(state.batch.root) });
- try { await quickGuards(state); } catch (error) {
+ try { await quickGuards(state); await deferredGuards(state); } catch (error) {
if (!(error instanceof Refused)) throw error;
await save(state, { state: 'blocked' });
state.say(`nothing landed: ${error.message}`);
diff --git a/src/settings-inventory.js b/src/settings-inventory.js
index bf6f6b68..35e888a1 100644
--- a/src/settings-inventory.js
+++ b/src/settings-inventory.js
@@ -33,7 +33,7 @@ const MACHINE_DEFAULTS = {
const OPTIONAL_REPO_DEFAULTS = {
project: null, name: null, 'checks.provesNothing': 'warn', 'verify.unrelatedTrunkMoves': false, 'verify.composeAtAdmission': false,
'flakes.rerun': false, 'flakes.quarantine': false, 'rigor.budget': 400, 'relay.outbox': false,
- submitGate: null, landingShards: 1, 'landing.publish': null, positiveControl: null, affectedTests: null,
+ submitGate: null, submitDeferAbove: null, landingShards: 1, 'landing.publish': null, positiveControl: null, affectedTests: null,
'health.sentinel': true, 'testConcurrency.browser': 2, approvers: null,
};
diff --git a/src/submit-invariants.js b/src/submit-invariants.js
index 5a999c00..fa72dcf0 100644
--- a/src/submit-invariants.js
+++ b/src/submit-invariants.js
@@ -18,11 +18,12 @@ function projectFile(value) {
export function submissionProof(value) {
if (!value || value.version !== 1 || typeof value.full !== 'boolean'
|| typeof value.deferred !== 'boolean' || typeof value.reason !== 'string'
- || value.reason.length > 8192 || !Array.isArray(value.files) || value.files.some(file => !projectFile(file))) {
+ || value.reason.length > 8192 || !Array.isArray(value.files) || value.files.some(file => !projectFile(file))
+ || value.deferredFiles !== undefined && (!value.deferred || !Array.isArray(value.deferredFiles) || value.deferredFiles.some(file => !projectFile(file)))) {
throw new Refused('SUBMISSION_PROOF', 'a submission proof needs its version, selected project files, full-fallback reason and deferred flag; rerun submit with the current CLI');
}
return { version: 1, files: [...new Set(value.files)].sort(), full: value.full,
- deferred: value.deferred, reason: value.reason };
+ deferred: value.deferred, reason: value.reason, ...(value.deferredFiles ? { deferredFiles: [...new Set(value.deferredFiles)].sort() } : {}) };
}
/** Accept only measured finite nonnegative durations; unavailable is always null. */
diff --git a/test/gate.test.js b/test/gate.test.js
index 7259db62..f2909cb6 100644
--- a/test/gate.test.js
+++ b/test/gate.test.js
@@ -22,8 +22,12 @@ import { prepareEngineMove } from '../src/engine.js';
import { mainPolicy } from '../src/trusted-policy.js';
import { ENGINE_VERSION } from '../src/machine.js';
import { submitFixture } from './board-submit-fixture.js';
+import { createE2eHelpers } from './e2e-helpers.js';
import { BROWSER_SLOT_HELD_ENV, GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV } from '../src/resources.js';
+const e2e = createE2eHelpers();
+after(e2e.cleanup);
+
const PRIVATE_WORKER = resolve(import.meta.dirname, '../src/private-check-worker.js');
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
@@ -774,3 +778,88 @@ test('a hand-recorded run never quarantines a test [C7,D1]', async (t) => {
assert.equal(store.listItems(reopened, { all: true }).length, 0, 'one real red and no green proves nothing');
assert.equal(waivedFailures(reopened, [FLAKY]), null, 'no landing block is removed');
});
+
+/** A web project whose one source file is imported by thirty test files, each recording its own run. */
+function largeSelectionProject(deferAbove) {
+ const box = e2e.project('true');
+ const config = JSON.parse(readFileSync(join(box.repo, 'pullboard.json'), 'utf8'));
+ writeFileSync(join(box.repo, 'pullboard.json'), JSON.stringify({ ...config, submitGate: 'landing', affectedTests: 'node --test',
+ submitInvariants: ['web/guard.test.js'], landing: { publish: 'separate' }, ...(deferAbove ? { submitDeferAbove: deferAbove } : {}) }, null, 2));
+ writeFileSync(join(box.repo, 'package.json'), '{"type":"module"}\n');
+ mkdirSync(join(box.repo, 'web'), { recursive: true });
+ writeFileSync(join(box.repo, 'web/core.js'), 'export const value = 1;\n');
+ const record = () => `import { appendFileSync } from 'node:fs';\nimport { test } from 'node:test';\nimport assert from 'node:assert/strict';\n`;
+ writeFileSync(join(box.repo, 'web/guard.test.js'), `${record()}test('guard [G1]', () => { appendFileSync(process.env.DEFER_MARKER, 'guard\\n'); });\n`);
+ for (let index = 0; index < 30; index += 1) {
+ writeFileSync(join(box.repo, `web/selected-${String(index).padStart(2, '0')}.test.js`), `${record()}import { value } from './core.js';\n`
+ + `test('selected ${index} [G1]', () => { appendFileSync(process.env.DEFER_MARKER, '${index}\\n'); assert.notEqual(value, 'red'); });\n`);
+ }
+ box.git(box.repo, 'add', '-A');
+ box.git(box.repo, 'commit', '-q', '-m', 'chore: thirty tests import one source');
+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');
+ box.env.DEFER_MARKER = join(box.dir, 'ran.log');
+ delete box.env.NODE_TEST_CONTEXT;
+ const ran = () => existsSync(box.env.DEFER_MARKER) ? readFileSync(box.env.DEFER_MARKER, 'utf8').trim().split('\n').filter(Boolean) : [];
+ /** Add, claim, change the shared source and submit one item, returning its receipt and what ran. */
+ const submitChange = (value) => {
+ const added = box.run(box.repo, 'add', 'web', `Set the value to ${value}`, '--specs', 'G1', '--criterion', 'The source exists.', '--check', 'test -f web/core.js', '--wait', '--json');
+ assert.equal(added.code, 0, added.err);
+ const id = JSON.parse(added.out).item.item_id;
+ assert.equal(box.run(box.web, 'claim', String(id)).code, 0);
+ assert.equal(e2e.commitFile(box, box.web, 'web/core.js', `export const value = ${JSON.stringify(value)};\n`, `feat(web): set the value [G1]`).status, 0);
+ rmSync(box.env.DEFER_MARKER, { force: true });
+ const submitted = box.run(box.web, 'submit', String(id), '--json');
+ assert.equal(submitted.code, 0, submitted.err + submitted.out);
+ const receipt = JSON.parse(submitted.out);
+ const proof = onLocalBoard(box, board => JSON.parse(store.events(board, { itemId: id }).findLast(row => row.event_kind === 'submit').event_detail));
+ return { id, receipt, proof, ran: ran() };
+ };
+ /** Accept one submitted item as the coordinator, at its exact commit. */
+ const accept = (id, commit) => {
+ box.git(box.repo, 'switch', '-q', '--detach', commit);
+ try { assert.equal(box.run(box.repo, 'verify', String(id), 'accept', '--as', 'coordinator', '--note', 'The source exists.').code, 0); }
+ finally { box.git(box.repo, 'switch', '-q', 'main'); }
+ };
+ return { box, ran, submitChange, accept };
+}
+
+/** Read a fixture's real board through its public interface. */
+function onLocalBoard(box, action) {
+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));
+ try { return action(board); } finally { store.closeBoard(board); }
+}
+
+test('a large affected selection is deferred to landing at submit [C7]', () => {
+ const selected = Array.from({ length: 30 }, (_, index) => `web/selected-${String(index).padStart(2, '0')}.test.js`);
+ const all = [...Array.from({ length: 30 }, (_, index) => String(index)), 'guard'].sort();
+ const on = largeSelectionProject(20);
+ const green = on.submitChange(2);
+ assert.equal(green.receipt.gate.full, false);
+ assert.equal(green.receipt.gate.deferred, true);
+ assert.deepEqual(green.ran, ['guard'], 'submit ran the frozen check, static checks and the invariant file only');
+ assert.deepEqual(green.proof.submissionProof.files, ['web/guard.test.js'], 'the receipt names what actually ran');
+ assert.deepEqual(green.proof.submissionProof.deferredFiles, selected, 'the submission records the thirty deferred files');
+ assert.match(green.proof.note, /30 affected test files deferred to the landing gate/u, 'reviewers see the deferral');
+ assert.match(green.receipt.gate.report, /30 affected test files deferred to the landing gate/u);
+ on.accept(green.id, green.receipt.commit);
+ rmSync(on.box.env.DEFER_MARKER, { force: true });
+ const landed = on.box.run(on.box.repo, 'land', '--json');
+ assert.equal(landed.code, 0, landed.err + landed.out);
+ assert.deepEqual(JSON.parse(landed.out).landed, [green.id]);
+ assert.deepEqual(on.ran().sort(), all, 'landing ran every deferred file before the item landed');
+
+ const red = on.submitChange('red');
+ assert.deepEqual(red.ran, ['guard'], 'a red deferred file is not run at submit');
+ on.accept(red.id, red.receipt.commit);
+ const blocked = on.box.run(on.box.repo, 'land', '--json');
+ assert.equal(blocked.code, 0, blocked.err + blocked.out);
+ assert.deepEqual(JSON.parse(blocked.out).landed, [], 'a red deferred selection lands nothing');
+ const reopened = JSON.parse(on.box.run(on.box.repo, 'show', String(red.id), '--json').out);
+ assert.notEqual(reopened.item_status, 'verified', 'the red item is sent back like a red submit');
+ assert.equal(reopened.item_merged_commit, null);
+ assert.ok(reopened.thread.some(entry => entry.kind === 'reopen' && /web\/selected-00\.test\.js/u.test(entry.detail.note)), 'the reopen names the failing deferred file');
+
+ const off = largeSelectionProject(null).submitChange(2);
+ assert.equal(off.proof.submissionProof.deferredFiles, undefined);
+ assert.deepEqual(off.ran.sort(), all, 'with the setting off, submit runs all thirty as today');
+});