Files
msd-core/tests/quick-branching.test.cjs
Tom Boucher 294564b951 fix(#2916): branch new phases off origin/HEAD instead of current HEAD
handle_branching in execute-phase.md (and the equivalent step in quick.md)
created the per-phase branch from whatever branch happened to be checked
out — typically the previous phase's still-unmerged feature branch — so
consecutive phases compounded on top of each other and stayed unpushed.

Detect the default branch via git symbolic-ref refs/remotes/origin/HEAD,
fast-forward it from origin, and fork the new phase branch off that tip.
Existing branches are still reused as-is. Dirty working trees fall back
to current HEAD with a loud warning, and a post-creation guard reports
any inherited commits.

Regression test extracts the bash from the <step name="handle_branching">
block structurally and runs it against a fixture repo where HEAD sits on
a previous-phase branch with extra commits.
2026-04-30 17:30:52 -04:00

53 lines
2.1 KiB
JavaScript

/**
* Quick task branching tests
*
* Validates that /gsd-quick exposes branch_name from init and that the
* workflow checks out a dedicated quick-task branch when configured.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
describe('quick workflow: branching support', () => {
const workflowPath = path.join(__dirname, '..', 'get-shit-done', 'workflows', 'quick.md');
let content;
test('workflow file exists', () => {
assert.ok(fs.existsSync(workflowPath), 'workflows/quick.md should exist');
});
test('init parse list includes branch_name', () => {
content = fs.readFileSync(workflowPath, 'utf-8');
assert.ok(content.includes('branch_name'), 'quick workflow should parse branch_name from init JSON');
});
test('workflow includes quick-task branching step', () => {
content = fs.readFileSync(workflowPath, 'utf-8');
assert.ok(content.includes('Step 2.5: Handle quick-task branching'));
// Branching block must (a) honour the existing branch if present and
// (b) create new branches off origin/HEAD, not current HEAD (#2916).
assert.ok(
content.includes('git switch "$branch_name"'),
'should reuse existing branch via git switch'
);
assert.ok(
content.includes('refs/remotes/origin/HEAD'),
'should detect default branch from origin/HEAD instead of branching off current HEAD'
);
assert.ok(
content.includes('git checkout -b "$branch_name"'),
'should create new branch via git checkout -b after switching to default'
);
});
test('branching step runs before task directory creation', () => {
content = fs.readFileSync(workflowPath, 'utf-8');
const branchingIndex = content.indexOf('Step 2.5: Handle quick-task branching');
const createDirIndex = content.indexOf('Step 3: Create task directory');
assert.ok(branchingIndex !== -1 && createDirIndex !== -1, 'workflow should contain both branching and directory steps');
assert.ok(branchingIndex < createDirIndex, 'branching should happen before quick task directories and commits');
});
});