fix: create strategy branch before first commit, not at execute-phase (#1278)
When branching_strategy is "phase" or "milestone", the branch was only created during execute-phase — but discuss-phase, plan-phase, and new-milestone all commit artifacts before that, landing them on main. Move branch creation into cmdCommit() so the strategy branch is created at the first commit point in any workflow. execute-phase's existing handle_branching step becomes a harmless no-op (checkout existing branch). Also fixes websearch test mocks broken by #1276 (fs.writeSync change). Closes #1278 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1185,6 +1185,71 @@ describe('commit command', () => {
|
||||
const logCount = execSync('git log --oneline', { cwd: tmpDir, encoding: 'utf-8' }).trim().split('\n').length;
|
||||
assert.strictEqual(logCount, 2, 'should have 2 commits (initial + amended)');
|
||||
});
|
||||
test('creates strategy branch before first commit when branching_strategy is milestone', () => {
|
||||
// Configure milestone branching strategy
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'config.json'),
|
||||
JSON.stringify({
|
||||
commit_docs: true,
|
||||
branching_strategy: 'milestone',
|
||||
milestone_branch_template: 'gsd/{milestone}-{slug}',
|
||||
})
|
||||
);
|
||||
// getMilestoneInfo reads ROADMAP.md for milestone version/name
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'## v1.0: Initial Release\n\n### Phase 1: Setup\n'
|
||||
);
|
||||
|
||||
// Create a file to commit
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'test-context.md'), '# Context\n');
|
||||
|
||||
const result = runGsdTools('commit "docs: add context" --files .planning/test-context.md', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.committed, true, 'should have committed');
|
||||
|
||||
// Verify we're on the strategy branch
|
||||
const { execFileSync } = require('child_process');
|
||||
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||||
assert.strictEqual(branch, 'gsd/v1.0-initial-release', 'should be on milestone branch');
|
||||
});
|
||||
|
||||
test('creates strategy branch before first commit when branching_strategy is phase', () => {
|
||||
// Configure phase branching strategy
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'config.json'),
|
||||
JSON.stringify({
|
||||
commit_docs: true,
|
||||
branching_strategy: 'phase',
|
||||
phase_branch_template: 'gsd/phase-{phase}-{slug}',
|
||||
})
|
||||
);
|
||||
// Create ROADMAP.md with a phase
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '01-setup'), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap\n\n## Phase 1: Setup\nGoal: Initial setup\n'
|
||||
);
|
||||
|
||||
// Create a context file for phase 1
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'phases', '01-setup', '01-CONTEXT.md'), '# Context\n');
|
||||
|
||||
const result = runGsdTools(
|
||||
'commit "docs(01): add context" --files .planning/phases/01-setup/01-CONTEXT.md',
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.committed, true, 'should have committed');
|
||||
|
||||
// Verify we're on the strategy branch
|
||||
const { execFileSync } = require('child_process');
|
||||
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: tmpDir, encoding: 'utf-8' }).trim();
|
||||
assert.strictEqual(branch, 'gsd/phase-01-setup', 'should be on phase branch');
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user