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.

fix(gate): select trunk changes from claim head [V4,C7]

Corey Olson1d02332e2f53
diff --git a/src/affected-tests.js b/src/affected-tests.js
index 5ad4f514..fef72f7c 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -95,7 +95,10 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change
if (!base) return { full: true, reason: 'no claim head recorded; the change cannot be selected', files };
// The merge base includes topic parents and merge resolutions that receipt history omits.
if (trunk) {
- base = selectionGit(root, ['merge-base', trunk, commit]).trim();
+ const mergeBase = selectionGit(root, ['merge-base', trunk, commit]).trim();
+ const submitted = selectionGit(root, ['rev-parse', '--verify', `${commit}^{commit}`]).trim();
+ // A trunk submission has no distinct branch base; its claim bounds the submitted work.
+ if (mergeBase !== submitted) base = mergeBase;
changed = undefined;
}
changed ??= selectionGit(root, ['diff', '--no-renames', '--name-only', '-z', base, commit]).split('\0').filter(Boolean);
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index 93d51bae..613b36fd 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -403,3 +403,54 @@ test('affected submit includes branch changes made before the item claim [V4,C7,
assert.match(refused.err, /affected tests:.*test\/a\.test\.js/u);
assert.match(refused.err, /ERR_ASSERTION/u);
});
+
+
+for (const mode of ['deleted source', 'topic parent', 'merge commit']) {
+ test(`affected submit on main includes a ${mode} since its claim [V4,C7,V16]`, (t) => {
+ const box = privateRepo(t);
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', lanes: { core: { owns: ['src/', 'test/'], specs: ['G'] } } }));
+ seedGraph(box);
+ put(box.root, 'test/a.test.js', [
+ "import assert from 'node:assert/strict';",
+ "import { appendFileSync } from 'node:fs';",
+ "import { value } from '../src/middle.js';",
+ "appendFileSync(process.env.AFFECTED_MARKER, 'ran\\n');",
+ 'assert.equal(value, 1);',
+ ].join('\n'));
+ commitAll(box);
+ const added = box.run('add', 'coordinator', 'Main checkout source', '--check', 'true');
+ assert.equal(added.code, 0, added.err);
+ const claimed = box.run('claim', '1');
+ assert.equal(claimed.code, 0, claimed.err);
+ if (mode === 'deleted source') {
+ box.git('rm', 'src/a.js');
+ commitAll(box, 'refactor(core): delete source on main [G1]');
+ } else {
+ box.git('checkout', '-q', '-b', 'topic');
+ put(box.root, mode === 'topic parent' ? 'src/a.js' : 'src/notes.js', 'export const value = 2;\n');
+ commitAll(box, 'feat(core): topic source [G1]');
+ box.git('checkout', '-q', 'main');
+ if (mode === 'merge commit') {
+ put(box.root, 'src/other.js', 'export const other = false;\n');
+ commitAll(box, 'feat(core): unrelated main source [G1]');
+ box.git('merge', '--no-ff', '--no-commit', 'topic');
+ put(box.root, 'src/a.js', 'export const value = 2;\n');
+ commitAll(box, 'feat(core): resolve main merge [G1]');
+ } else box.git('merge', '--no-ff', '-q', 'topic', '-m', 'feat(core): merge topic into main [G1]');
+ assert.equal(box.git('rev-list', '--parents', '-n', '1', 'HEAD').split(' ').length, 3);
+ }
+ assert.equal(box.git('branch', '--show-current'), 'main', 'submit runs in the actual main checkout');
+ const marker = join(box.dir, 'main-importer-ran.log');
+ box.env.AFFECTED_MARKER = marker;
+ const standalone = spawnSync(process.execPath, ['--test', 'test/a.test.js'], { cwd: box.root, env: box.env, encoding: 'utf8' });
+ assert.equal(standalone.status, 1, 'the unchanged importer detects the source regression');
+ assert.match(standalone.stdout, mode === 'deleted source' ? /ERR_MODULE_NOT_FOUND/u : /ERR_ASSERTION/u);
+ rmSync(marker, { force: true });
+ const refused = box.run('submit', '1');
+ assert.equal(refused.code, 1, refused.out || refused.err);
+ assert.match(refused.err, /GATE_RED/u);
+ assert.match(refused.err, /affected tests:.*test\/a\.test\.js/u);
+ assert.match(refused.err, mode === 'deleted source' ? /ERR_MODULE_NOT_FOUND/u : /ERR_ASSERTION/u);
+ if (mode !== 'deleted source') assert.equal(readFileSync(marker, 'utf8'), 'ran\n', 'submit executed the unchanged transitive importer');
+ });
+}