Skip to content

feat(#817): --ready-gate — run the post-QA ready gate inside sequant run - #832

Merged
admarble merged 3 commits into
mainfrom
feature/817-feat-run-ready-gate-run-the-post-qa-ready-gate-ins
Jul 28, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/817-feat-run-ready-gate-run-the-post-qa-ready-gate-ins

Conversation

@admarble

@admarble admarble commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds an opt-in --ready-gate flag to sequant run that invokes the existing runReadyGate engine (the sequant ready qa → loop → qa gate) after an issue's standard phases succeed, before the PR is created — so the gate's auto-fix commits land in the PR.
  • The gate drives the issue to the configured settings.ready.policy threshold, then stops at the human merge gate — it never merges. The run terminates with the issue waiting_for_human_merge (threshold reached) or blocked (guard halt).
  • Reuses ready's policy, iteration cap, stagnation guard, and Non-Goals handling — no new settings. Off by default; without the flag the run path is byte-identical (the fix(run): AC_MET_BUT_NOT_A_PLUS QA verdict misrouted into quality loop → fails with no PR (should break to PR) #749 break-to-PR behavior is unchanged).

Pre-PR AC Verification

AC Description Status Evidence
AC-1 Gate invoked post-phases; PR open; ready-terminal status; never merges ✅ batch-executor.ts seam runs runReadyGateForIssue before rebase/PR; persists readyGateResult.issueStatus, never ready_for_merge. Test: ready-gate-run.test.ts "AC-3/AC-1"
AC-2 With flag, AC_MET_BUT_NOT_A_PLUS escalates through the gate; without flag, #749 preserved ✅ Gate runs iff config.readyGate; flag-off path untouched. Tests: ready-gate-run.test.ts (flag-on/off), worktree-manager.build-pr-body.test.ts (#749 note preserved when no gate)
AC-3 Flag wired end-to-end; a test fails if it stops reaching the engine ✅ bin/cli.ts .option → RunOptions → ExecutionConfig → config-resolver → batch-executor → runReadyGate. Tests: run-options-dead-surface.test.ts live-surface guard + ready-gate-run.test.ts behavioral wiring
AC-4 Policy/cap/budget/stagnation/Non-Goals from ready; no new flags/settings ✅ runReadyGateForIssue sources policy ← settings.ready.policy, maxIterations ← config, tokenBudget ← undefined, Non-Goals parsed from body. Test: ready-gate-run.test.ts "AC-4"
AC-5 Without the flag, run behavior byte-identical; existing tests pass unmodified ✅ Gate block gated behind config.readyGate; existing batch-executor.test.ts passes unchanged. Test: ready-gate-run.test.ts "AC-5"
AC-6 Run summary + PR body surface the gate outcome as ready does ✅ buildAutomatedPRBody embeds the gate report; run-display.ts renders the per-issue outcome. Tests: worktree-manager.build-pr-body.test.ts, run-display.test.ts (#817)
AC-7 Docs in main README, marketplace README, and docs/ ✅ README.md, scripts/prepare-marketplace.ts (marketplace README source), docs/reference/run-command.md, docs/features/run-ready-gate.md

Test plan

  • npm run build — clean
  • npm run lint — clean
  • npx tsx bin/cli.ts run --help shows --ready-gate
  • New/affected suites green: ready-gate-run.test.ts, run-options-dead-surface.test.ts, worktree-manager.build-pr-body.test.ts, batch-executor.test.ts (unmodified — AC-5), run-display.test.ts, config-resolver.test.ts

Notes

  • Chain/-Q interaction: the gate fires per-issue at the runIssueWithLogging seam (naturally per-issue). Chain-level coordination is out of scope per the issue's Non-Goals. The concrete consequence — --chain --ready-gate resume re-executes already-gated links, because chain-resume.ts's COMPLETED_STATUSES doesn't include the gate's terminal statuses — is tracked in fix(chain): --chain --ready-gate resume re-executes already-gated links (COMPLETED_STATUSES misses waiting_for_human_merge/blocked) #837.
  • A gate failure mid-run is non-fatal: the standard-phase work is already committed, so the run logs a warning and continues to PR with the standard status. It is reported, not silent — see below.

AC-3 mutation record (6725cc8)

QA's second look mutation-tested AC-3's guard rather than reading it, and the guard did not hold. AC-3's contract is literal — "a test fails if the flag stops reaching the engine (the #795 inert-flag class)" — and it didn't: mutating the resolver mapping to mergedOptions.readyGate && false left --ready-gate permanently inert with 145 tests green. The pre-existing guard asserted only the substring readyGate: mergedOptions.readyGate, which that mutation preserves verbatim.

6725cc8 closes all three links behaviorally, following the pattern --auto-wait (#804) already established in auto-wait.test.ts. Mutation-verified per the repo's gate-test rule — each mutation applied to the four touched suites, then reverted and re-confirmed green:

Mutation Result
(baseline — no mutation) 0 failed / 63 passed
M1 · delete .option("--ready-gate") from bin/cli.ts 1 failed — new scoped CLI-registration guard
M2 · resolver mapping → && false (source shape preserved) 4 failed — new binding assertions
M3 · executor reads config.fullQa instead of config.readyGate 6 failed — behavioral wiring suite
M4 · drop readyGateError from IssueResult 1 failed — new crash-path guard

Before 6725cc8, M1 and M2 both left the entire suite green. M1 is self-detecting at runtime (Commander rejects the unknown option); M2 was the silent #795 class and is the defect this commit exists to close.

Gate-failure visibility

The same pass surfaced a second gap: a gate that threw returned undefined, so the issue disappeared from the summary's ready-gate section entirely. A run whose gate crashed was byte-identical in the summary to one that gated cleanly — the user opted into a second look and would believe it happened when it never did.

The helper now returns { result?, error? }, IssueResult carries readyGateError, and the summary renders:

  Ready gate (#817) — never merged:
     #42: ✗ gate did not run · <error> · PR opened ungated — re-run `sequant ready 42`

Status deliberately stays ready_for_merge on that path: the run degraded to a standard run and nothing about the work is blocked. The fix is visibility, not a status flip.

Closes #817

Opt-in --ready-gate flag on `sequant run` invokes the existing
`runReadyGate` engine after an issue's standard phases succeed, driving
it to the configured ready.policy before the PR opens (so the gate's
auto-fix commits land in the PR), then stops at the human merge gate —
it never merges.

- Wire the flag end-to-end: bin/cli.ts .option → RunOptions →
  ExecutionConfig → config-resolver → batch-executor → runReadyGate.
- Invoke the gate at the post-success/pre-PR seam in
  runIssueWithLogging; persist the gate's terminal status
  (waiting_for_human_merge / blocked) instead of ready_for_merge.
- Reuse ready's policy, iteration cap, stagnation guard, and Non-Goals
  handling — no new settings. Token budget stays disabled on the run
  path (the iteration cap bounds cost).
- Surface the gate outcome in the PR body and end-of-run summary the
  same way sequant ready reports it.
- Without the flag the run path is byte-identical (#749 break-to-PR
  unchanged); with it, AC_MET_BUT_NOT_A_PLUS escalates through the gate.
- Guard the #795 inert-flag class with a source-level live-surface test
  and a behavioral wiring test that fails if the flag stops reaching the
  engine.
- Docs: main README, marketplace README source, run-command reference,
  and a docs/features entry.

Entire-Checkpoint: 3617e402a67b
…from passing silently

QA second look mutation-tested AC-3's guard instead of reading it, and the
guard did not hold. AC-3's contract is literal: "a test fails if the flag stops
reaching the engine (the #795 inert-flag class)". It did not.

Mutating the resolver mapping to `mergedOptions.readyGate && false` left
`--ready-gate` permanently inert while 145 tests stayed green. The existing
guard asserts only the substring `readyGate: mergedOptions.readyGate`, which
that mutation preserves verbatim - the unscoped file-read class CLAUDE.md now
calls out, landing on the one link whose own comment calls it "the load-bearing
wire the #795 inert-flag class guards against".

Closes all three links of AC-3's chain behaviorally, following the pattern
--auto-wait (#804) already established in auto-wait.test.ts:

- __tests__/config-resolver.test.ts: four binding assertions - the flag reaches
  ExecutionConfig, defaults to false without it (AC-5), survives the
  resolveRunOptions hop (Commander key -> config), and cannot be switched on by
  any settings key (AC-4 opt-in only).
- run-options-dead-surface.test.ts: asserts `--ready-gate` is registered on the
  `run` command in bin/cli.ts, scoped to that command's own section so a
  comment or another command's help text cannot satisfy it. The pre-existing
  resolver source-grep is kept and documented as a shape-only tripwire that is
  explicitly not sufficient alone.

Also fixes a gap the same pass surfaced: a gate that threw returned undefined,
so the issue vanished from the summary's ready-gate section entirely. A run
whose gate crashed was byte-identical to one that gated cleanly - the user
opted into a second look and would believe it happened when it never did. The
helper now returns { result?, error? }, IssueResult carries readyGateError, and
the summary renders an explicit "gate did not run" line with the cause and the
`sequant ready <n>` remediation. Status deliberately stays ready_for_merge: the
run degraded to a standard run and nothing about the work is blocked; the fix
is visibility, not a status flip.

Mutation-verified (per CLAUDE.md gate-test rule), each against the four
touched suites, restored and re-confirmed green between runs:

  baseline                                            0 failed / 63 passed
  M1 delete .option("--ready-gate") from bin/cli.ts   1 failed (new cli guard)
  M2 resolver mapping -> `&& false` (shape preserved) 4 failed (new bindings)
  M3 executor reads config.fullQa instead             6 failed (behavioral)
  M4 drop readyGateError from IssueResult             1 failed (new crash-path)

M1 was previously undetected but is self-detecting at runtime (commander
rejects the unknown option); M2 was the silent #795 class and is the defect
this commit exists to close.

Regression: 1607 tests across src/lib/workflow + src/commands pass, with
batch-executor.test.ts untouched (AC-5 byte-identical-without-the-flag holds).
Resolves two additive conflicts, both "keep both" — main and this branch each
appended a new section at the same insertion point:

- CHANGELOG.md: #818 (merge --watch) and #817 (--ready-gate) both prepended an
  entry to [Unreleased] > Added. Kept both, #818 first.
- scripts/prepare-marketplace.ts: both added a marketplace README section after
  the rate-limit-window one. Kept both, "Wait for CI, then verify" then
  "Running the ready gate inside run".

No semantic overlap between the two changes. Post-merge: tsc clean, build
clean, 1639 tests pass across src/lib/workflow + src/commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(run): --ready-gate — run the post-QA ready gate inside sequant run (automates the any-gaps/fix-gaps second look, stops at human merge)

1 participant