* fix(#105): skip strategy branch auto-switch when use_worktrees is false When workflow.use_worktrees is false, the primary checkout is shared or pinned to a base branch. Auto-switching HEAD in that mode silently moves the shared checkout and allows concurrent commits to land on the wrong branch. ensureStrategyBranch now returns ok:true with an explicit skip reason instead of calling git checkout in this configuration. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(#105): replace source-grep tests with behavioral coverage Remove the root tests/bug-105-*.test.cjs file which used source-text structural assertions (reading commit.ts as a string) — tests that pass even when the runtime behavior is broken. Replace with a Vitest test at sdk/src/query/commit.bug-105.test.ts that invokes ensureStrategyBranch directly with use_worktrees:false and asserts the guard fires before any git invocation, and that the guard does NOT fire when use_worktrees is true or absent. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(#105): add changeset fragment Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(#105): address review — type WorkflowConfig.use_worktrees, accept "false" string, stub git in tests - Add `use_worktrees?: boolean | string` to WorkflowConfig interface with doc comment - Remove `(config.workflow as unknown as Record<string, unknown>)` double cast; use typed `config.workflow?.use_worktrees` - Accept string `"false"` alongside boolean `false` via `isExplicitlyFalse` guard (YAML/JSON parser resilience) - Add `vi.mock('node:child_process')` stub in commit.bug-105.test.ts; assert no-call on skip-path tests - Add new test case for string `"false"` coercion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -233,6 +233,22 @@ export async function ensureStrategyBranch(
|
||||
return { ok: true, reason: 'strategy-skipped: config load failed' };
|
||||
}
|
||||
|
||||
// Issue #105: when use_worktrees is false the primary checkout is shared or
|
||||
// pinned (concurrent sessions / deliberate base-branch lock). Auto-switching
|
||||
// HEAD in that mode silently moves the shared checkout and causes commits from
|
||||
// parallel sessions to land on the wrong branch. Skip the switch entirely;
|
||||
// the caller commits on whatever branch the primary is currently on.
|
||||
// String "false" is tolerated for resilience against YAML/JSON parsers that
|
||||
// leave boolean-like fields as strings.
|
||||
const useWorktrees = config.workflow?.use_worktrees;
|
||||
const isExplicitlyFalse = useWorktrees === false || useWorktrees === 'false';
|
||||
if (isExplicitlyFalse) {
|
||||
return {
|
||||
ok: true,
|
||||
reason: 'strategy-skipped: use_worktrees is false — shared/pinned primary checkout; branch auto-switch suppressed (#105)',
|
||||
};
|
||||
}
|
||||
|
||||
const strategy = config.git.branching_strategy;
|
||||
if (!strategy || strategy === 'none') return { ok: true };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user