fix: allow quick worktree parent plan base (#1347)

This commit is contained in:
Tom Boucher
2026-06-16 14:00:06 -04:00
committed by GitHub
parent 80014109c1
commit 6e242bd76a
9 changed files with 172 additions and 13 deletions

View File

@@ -99,4 +99,41 @@ describe('quick.md pre-dispatch PLAN.md commit (#2432)', () => {
'executor files_to_read must NOT contain hardcoded absolute paths'
);
});
test('#1265 records both parent base and plan commit for worktree dispatch', () => {
const step56Start = content.indexOf('Step 5.6');
const step6Start = content.indexOf('Step 6:', step56Start);
const step56Block = content.slice(step56Start, step6Start);
const step6Block = content.slice(step6Start, content.indexOf('After executor returns:', step6Start));
assert.ok(
step56Block.includes('QUICK_PLAN_PARENT'),
'quick worktree mode must record the pre-dispatch parent SHA before committing PLAN.md (#1265)'
);
assert.ok(
step56Block.includes('QUICK_PLAN_COMMIT'),
'quick worktree mode must record the PLAN.md commit SHA after the pre-dispatch commit (#1265)'
);
assert.ok(
step6Block.includes('EXPECTED_BASE_ALTERNATE'),
'executor guard embed must carry the alternate accepted base for parent-vs-plan worktree forks (#1265)'
);
});
test('#1265 executor materializes PLAN.md from the plan commit when worktree starts at parent', () => {
const executorTask = content.indexOf('subagent_type="gsd-executor"');
assert.ok(executorTask !== -1, 'executor Task() spawn must exist');
const promptStart = content.lastIndexOf('prompt="', executorTask);
const promptEnd = content.indexOf('subagent_type="gsd-executor"', promptStart);
const executorPrompt = content.slice(promptStart, promptEnd);
assert.ok(
executorPrompt.includes('git show') && executorPrompt.includes('QUICK_PLAN_COMMIT'),
'executor prompt must materialize PLAN.md from git show <plan-commit>:<plan-path> when absent (#1265)'
);
assert.ok(
executorPrompt.indexOf('git show') < executorPrompt.indexOf('<files_to_read>'),
'PLAN.md materialization must be a first action before files_to_read can prime paths (#1265)'
);
});
});

View File

@@ -57,7 +57,7 @@
"pr-branch.md": 9561,
"profile-user.md": 20650,
"progress.md": 29387,
"quick.md": 47251,
"quick.md": 48435,
"reapply-patches.md": 20393,
"remove-phase.md": 8469,
"remove-workspace.md": 7507,

View File

@@ -689,7 +689,7 @@ describe('bug #3384: worktree cleanup workflow contracts', () => {
assert.match(content, /WAVE_WORKTREE_MANIFEST|QUICK_WORKTREE_MANIFEST/);
assert.match(content, /worktree\.cleanup-wave/);
assert.match(content, /mktemp "\$\{TMPDIR:-\/tmp\}\/gsd-quick-worktree-/);
assert.match(content, /append its returned `\{agent_id, worktree_path, branch, expected_base\}`/);
assert.match(content, /append its returned `\{agent_id, worktree_path, branch, expected_base, allowed_bases\}`/);
// After #3797 architectural fix: quick.md delegates entirely to the SDK's cleanup-wave
// command (which handles manifest parsing internally). The shell fallback with manual
// QUICK_WORKTREE_MANIFEST node-e code is removed — the gsd_run call with || exit 1 is the

View File

@@ -518,6 +518,7 @@ describe('planWorktreeWaveCleanup', () => {
worktree_path: '/repo/.claude/worktrees/agent-a1',
branch: 'worktree-agent-a1',
expected_base: 'abc123',
allowed_bases: ['abc123', 'def456'],
},
],
});
@@ -527,11 +528,13 @@ describe('planWorktreeWaveCleanup', () => {
worktree_path: entry.worktree_path,
branch: entry.branch,
expected_base: entry.expected_base,
allowed_bases: entry.allowed_bases,
})), [{
agent_id: 'a1',
worktree_path: '/repo/.claude/worktrees/agent-a1',
branch: 'worktree-agent-a1',
expected_base: 'abc123',
allowed_bases: ['abc123', 'def456'],
}]);
assert.equal(plan.discovery, 'manifest');
});
@@ -562,6 +565,84 @@ describe('planWorktreeWaveCleanup', () => {
// ─── executeWorktreeWaveCleanupPlan ───────────────────────────────────────────
describe('executeWorktreeWaveCleanupPlan', () => {
test('#1265 accepts a merge-base listed in allowed_bases even when expected_base is the plan commit', () => {
const plan = {
ok: true,
repoRoot: '/repo/main',
action: 'cleanup_wave',
discovery: 'manifest',
entries: [{
agent_id: 'a1',
worktree_path: '/repo/.claude/worktrees/agent-a1',
branch: 'worktree-agent-a1',
expected_base: 'plancommit',
allowed_bases: ['plancommit', 'parentcommit'],
}],
};
const result = executeWorktreeWaveCleanupPlan(plan, {
execGit: (args) => {
const key = args.join(' ');
if (key === '-C /repo/.claude/worktrees/agent-a1 rev-parse --abbrev-ref HEAD') {
return { exitCode: 0, stdout: 'worktree-agent-a1', stderr: '' };
}
if (key === 'merge-base HEAD worktree-agent-a1') {
return { exitCode: 0, stdout: 'parentcommit', stderr: '' };
}
if (key === 'diff --diff-filter=D --name-only HEAD...worktree-agent-a1') {
return { exitCode: 0, stdout: '', stderr: '' };
}
if (key === '-C /repo/.claude/worktrees/agent-a1 status --porcelain --untracked-files=all') {
return { exitCode: 0, stdout: '', stderr: '' };
}
if (key.startsWith('merge worktree-agent-a1')) {
return { exitCode: 0, stdout: '', stderr: '' };
}
if (key === 'worktree remove /repo/.claude/worktrees/agent-a1 --force') {
return { exitCode: 0, stdout: '', stderr: '' };
}
if (key === 'branch -D worktree-agent-a1') {
return { exitCode: 0, stdout: '', stderr: '' };
}
return { exitCode: 0, stdout: '', stderr: '' };
},
});
assert.equal(result.ok, true);
assert.equal(result.entries[0].status, 'merged_removed');
});
test('#1265 still blocks a merge-base outside expected_base and allowed_bases', () => {
const plan = {
ok: true,
repoRoot: '/repo/main',
action: 'cleanup_wave',
discovery: 'manifest',
entries: [{
agent_id: 'a1',
worktree_path: '/repo/.claude/worktrees/agent-a1',
branch: 'worktree-agent-a1',
expected_base: 'plancommit',
allowed_bases: ['plancommit', 'parentcommit'],
}],
};
const result = executeWorktreeWaveCleanupPlan(plan, {
execGit: (args) => {
const key = args.join(' ');
if (key === '-C /repo/.claude/worktrees/agent-a1 rev-parse --abbrev-ref HEAD') {
return { exitCode: 0, stdout: 'worktree-agent-a1', stderr: '' };
}
if (key === 'merge-base HEAD worktree-agent-a1') {
return { exitCode: 0, stdout: 'unrelatedbase', stderr: '' };
}
throw new Error(`unexpected git call after rejected base: ${key}`);
},
});
assert.equal(result.ok, false);
assert.equal(result.entries[0].status, 'blocked');
assert.equal(result.entries[0].reason, 'base_mismatch');
});
test('does not delete a branch when worktree removal fails', () => {
const calls = [];
const plan = {

View File

@@ -176,8 +176,9 @@ describe('canonical worktree-branch-check fragment is the single source of truth
assert.ok(block.includes('update-ref'), 'fragment block must reference update-ref prohibition');
});
test('fragment block asserts exact base and fails closed with exit 42 (#48)', () => {
assert.ok(block.includes('git rev-parse HEAD') && block.includes('{EXPECTED_BASE}'), 'fragment must assert HEAD equals {EXPECTED_BASE} exactly (#48)');
test('fragment block asserts an allowed base set and fails closed with exit 42 (#48, #1265)', () => {
assert.ok(block.includes('git rev-parse HEAD') && block.includes('{EXPECTED_BASE}'), 'fragment must assert HEAD against {EXPECTED_BASE} (#48)');
assert.ok(block.includes('{EXPECTED_BASE_ALTERNATE}'), 'fragment must support one orchestrator-approved alternate base for quick parent/plan forks (#1265)');
assert.ok(/exit 42/.test(block), 'fragment must fail closed with exit 42 on mismatch (#48)');
});
});
@@ -848,4 +849,3 @@ done < <(${DISCOVERY_PIPELINE})
});
});
});