Repository navigation
fix(#537): respect custom base branch in exec zero-diff guard - #538
Merged
admarble merged 6 commits intoApr 19, 2026
Merged
Conversation
The #534 zero-diff guard hardcoded origin/main as the comparison ref. On worktrees created with `--base feature/<branch>`, HEAD is already ahead of origin/main from the moment the worktree exists (inheriting the parent branch's commits). The guard counted those commits, reported the exec as having changes, and silently passed zero-diff runs — the same failure mode #534 was written to prevent, but scoped to custom-base worktrees. - New `resolveBaseRef(cwd)` helper reads `branch.<current>.sequantBase` (written by new-feature.sh on worktree creation), prepending `origin/` when the recorded value does not already reference a remote. - Falls back to `origin/main` on missing config, detached HEAD, or any git error — preserves #534 behavior for pre-fix worktrees and non-sequant-managed ones. - `hasExecChanges` now consults `resolveBaseRef` instead of hardcoding. - `mapAgentSuccessToPhaseResult` signature unchanged (AC-5): base resolution lives inside the helper; callers stay base-agnostic. - `new-feature.sh` writes `branch.<name>.sequantBase <base>` after `git worktree add`. Existing worktrees are unaffected and fall through to the origin/main fallback (documented in CHANGELOG, no backfill). - Unit tests cover the AC-4 matrix and resolveBaseRef error paths. - Integration test reproduces the end-to-end #537 scenario with real git.
…ction The resolved base ref is interpolated into a shell-executed git command via execSync template string. The recorded value originates from the user-supplied --base CLI flag and is persisted in git config — so a value containing shell metacharacters would be spliced into the rev-list command and executed by /bin/sh. Threat model is limited (the user setting the flag is the one at risk — self-harm only, not cross-user), but hygiene matters and the validation is a one-liner. Both the current branch name and the recorded base are now matched against a conservative refname regex; anything outside the safe subset falls through to the origin/main fallback. Two new unit tests cover the injection cases (recorded value with shell metacharacters, branch name with shell metacharacters).
7 tasks
…zero-diff guard Root-cause fix for the shell-injection concern flagged in earlier QA. The previous commit added a SAFE_REF regex as defense in depth, but the actual problem was using execSync with template-string commands — that routes through /bin/sh and parses metacharacters. The regex worked but also rejected legal-but-unusual git refnames (feature+v1, tag=1, a,b). Switch resolveBaseRef and hasExecChanges to execFileSync, which passes argv directly to execve with no shell parse. Each arg is an opaque string to git — a value like "--version" would be treated as a revspec, not a flag, and fall through to the existing fail-open path. Drop SAFE_REF. Keep only a paranoid "no embedded newline" sanity check on rev-parse and config output, since git config --get is single-line by contract and multi-line output would indicate a corrupt config. Tests: - Mock now exposes both execSync and execFileSync from child_process - resolveBaseRef/hasExecChanges tests updated to use mockExecFileSync - New test verifies argv shape (call[0] === "git", call[1] is Array) - New test verifies legal-but-unusual refname chars (+, =, ,) now flow through instead of being rejected by the old regex - Shell-metachar-rejection tests replaced with an embedded-newline test (the only value that still trips the sanity guard) - Call-arg assertions updated from mock.calls[2][0] (command string) to mock.calls[2][1] (argv array)
Earlier integration tests used `git init` + `git checkout -b` to create the "worktree under test" scenario. That emulates the consumer semantics but does not exercise the worktree-specific config plumbing: branch- scoped config keys live in `$GIT_COMMON_DIR/config` and are shared across worktrees, and `new-feature.sh` writes the key from inside the newly created worktree. This test walks that actual shape: 1. main repo + bare origin 2. commit on main, push 3. feature/epic with E1 commit, push 4. `git worktree add <wt> -b feature/537-test feature/epic` 5. `git -C <wt> config branch.feature/537-test.sequantBase feature/epic` 6. verify resolveBaseRef(<wt>) reads origin/feature/epic 7. verify hasExecChanges(<wt>) returns false (zero-diff, primary #537 fix) 8. verify hasExecChanges(<wt>) returns true after a commit on top Teardown removes the worktree with --force before rmSync to avoid leaving stale metadata in the main repo. Pairs with the git-init-based tests (which remain as focused consumer-contract checks).
…lt suite The outer beforeEach only reset mockExecSync, so mockExecFileSync accumulated state from exec-phase tests into the other-phases "no subprocess calls" test. The existing assertion only checked execSync so it passed, but it was masking a real mock-state leak. Reset both mocks in the outer beforeEach, and extend the other-phases assertion to cover execFileSync too. Trivial in isolation, but removes a latent footgun for anyone adding a spec/testgen/verify/loop test block below.
The exec-qa-phase-guards troubleshooting doc shipped a "known gap" note pointing at this issue. Now that the fix has landed, rewrite the section to describe: - What was broken pre-#537 (for historical context and log-searchers) - How the fix works (sequantBase config key + resolveBaseRef) - The explicit fallback to origin/main for pre-fix worktrees - A manual recovery command for legacy worktrees that missed the config write Also corrects the script path from the gitignored scripts/dev/... copy to the tracked scripts/new-feature.sh.
admarble
deleted the
feature/537-fix-orchestrator-respect-custom-base-branch-in
branch
April 19, 2026 22:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--base feature/<branch>)resolveBaseRef(cwd)readsbranch.<current>.sequantBase(written bynew-feature.sh), prependsorigin/, falls back toorigin/mainon any error — preserves fix(orchestrator): treat null QA verdict and zero-diff exec as failure, not success #534 behavior for pre-fix and non-sequant-managed worktreesgit rev-listcommandAC Coverage
hasExecChangesresolves correct base viagit config branch.<name>.sequantBasetemplates/scripts/new-feature.sh(symlinked asscripts/new-feature.sh) writes the--basevalue to that config keyorigin/mainon missing config, detached HEAD, or git errormapAgentSuccessToPhaseResultsignature unchanged; still callshasExecChanges(cwd)phase-executor.integration.test.ts— real bare-origin + work repo,feature/epicpopulated,feature/537-testbranched from epic with recorded base; sanity-checks HEAD is ahead oforigin/mainbut zero againstorigin/feature/epic[Unreleased]/Fixed(sub-bullet of fix(orchestrator): treat null QA verdict and zero-diff exec as failure, not success #534)Test Plan
npm run build— cleannpm run lint— 0 errors, 0 warningsphase-executor.*,spec-retry,batch-executor) — 150/150 passing (111 in the two phase-executor files alone)bash -n templates/scripts/new-feature.sh— syntax OK--base feature/<branch>and confirmgit config --get branch.<name>.sequantBasereturns the expected valueNotes
docs/features/exec-qa-phase-guards.md(existing doc already flagged fix(orchestrator): respect custom base branch in exec zero-diff guard (#534 follow-up) #537 as the known gap; no further doc update needed)origin/mainfallback — no backfill script, no migrationCloses #537