Skip to content

bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086

Closed

Description

@admarble

Problem

The test suite is not hermetic against the environment sequant's own phases run under. phase-executor.ts:1458 injects SEQUANT_ORCHESTRATOR, SEQUANT_WORKTREE (and SEQUANT_PHASE/SEQUANT_ISSUE) into every phase, for every driver. An exec phase that runs npm test inherits them, and two tests change outcome:

Env var Test Result
SEQUANT_ORCHESTRATOR=sequant-run src/commands/__tests__/prompt-wait.test.ts › returns 0 and prints the reply when one arrives within the window expected 1 to be +0
SEQUANT_WORKTREE=<path> src/lib/workflow/batch-executor.test.ts › returns the input config unchanged when onProgress is undefined config gains 2 keys (13 vs 11)

SEQUANT_PHASE and SEQUANT_ISSUE alone do not reproduce.

Why it matters

An exec phase that sees red tests in files its diff never touched cannot tell pre-existing breakage from its own, and the exec skill's pre-PR gate correctly refuses to open a PR. That is what stopped #1060's gate run 3: exec (Codex driver) reported 7 failures in unchanged files and opened no PR, so QA returned AC_NOT_MET on a correct implementation. Driver-agnostic — a Claude Code phase gets the same env.

Reproduce ($0)

SEQUANT_ORCHESTRATOR=sequant-run npx vitest run src/commands/__tests__/prompt-wait.test.ts
SEQUANT_WORKTREE=$PWD npx vitest run src/lib/workflow/batch-executor.test.ts -t "onProgress is undefined"

Both pass with the vars unset.

Not attributed

Run 3's other 5 failures (2 cli-ui.test.ts minimal-mode cases, 3 batch-executor.test.ts cases at 7–10s) did not reproduce in isolation, including under codex sandbox with the driver's exact workspace-write config. Exec had several vitest runs and lint in flight at once; contention fits the timeouts. Out of scope unless they reproduce.

Acceptance criteria

  • AC-1: SEQUANT_ORCHESTRATOR=sequant-run SEQUANT_WORKTREE=$PWD SEQUANT_PHASE=exec SEQUANT_ISSUE=1 SEQUANT_RELAY=true SEQUANT_RELAY_FRAME=1 npx vitest run src/commands/__tests__/prompt-wait.test.ts src/lib/workflow/batch-executor.test.ts __tests__/integration/relay-hook.integration.test.ts passes
  • AC-2: the fix scrubs every variable matching ^SEQUANT_ by prefix at the suite level (vitest config env or a setup file that runs in every worker), not from a list and not per test, so a new phase var or a new test cannot reintroduce the leak — Verify: grep -n 'SEQUANT_' vitest.config.ts vitest.global-setup.ts vitest.setup.ts 2>/dev/null shows one prefix match, no per-name list
  • AC-3: a test that deliberately reads one of the scrubbed vars still controls it explicitly (vi.stubEnv) and passes
  • AC-4: gate test — mutation-verified per CLAUDE.md §Testing: remove the scrub, confirm the AC-1 command fails, restore, record the marker in the PR body
  • AC-5: the PR body records whether SEQUANT_ORCHESTRATOR=sequant-run alone and SEQUANT_WORKTREE=$PWD alone reproduce under the AC-1 test files in the worktree (Phase 0 on 09-18 and 09-20 got 1 passed for each; only SEQUANT_RELAY=true reproduced alone — PLAN OQ-1)

Release-graph plan — guard-2026-09 (2026-09-20)

Graph: guard-2026-09 Tier: mechanical Wave: 1
May touch: vitest.config.ts, vitest.global-setup.ts or a new vitest.setup.ts, and the three AC-1 test files only if AC-3 needs an explicit vi.stubEnv example

The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). Root node: until this merges the runner's suite shows these failures under the orchestrator, so its PR is merged first when the owner consents.

Related

#1060 (gate run 3 record) · #497

Activity

  1. added
    bug
    on Sep 18, 2026
  2. admarble commented on Sep 19, 2026

    @admarble
    ContributorAuthor

    Third leaked var, verified 2026-09-18: SEQUANT_RELAY=true (set at phase-executor.ts:1516 when relay is on) breaks __tests__/integration/relay-hook.integration.test.ts › AC-7 "does NOT render when SEQUANT_RELAY is unset".

    SEQUANT_RELAY=true npx vitest run __tests__/integration/relay-hook.integration.test.ts -t "SEQUANT_RELAY is unset"
      → Tests  1 failed | 8 skipped (9)
    npx vitest run __tests__/integration/relay-hook.integration.test.ts -t "SEQUANT_RELAY is unset"
      → Tests  1 passed | 8 skipped (9)
    

    Worth adding SEQUANT_RELAY (and SEQUANT_RELAY_FRAME, :1521) to the AC-2 scrub list. With it, the fix covers all three of the failures that PRs #1036, #1042 and #1048 (2026-09-10/11) each reported as "3 pre-existing failures in batch-executor.test.ts, prompt-wait.test.ts, relay-hook.integration.test.ts, unrelated to this diff" — those three were this bug, a week before it was filed.

    Null result, for the record: in a clean interactive shell here, SEQUANT_ORCHESTRATOR=sequant-run alone did not fail prompt-wait.test.ts (3 passed) and SEQUANT_WORKTREE=$PWD alone did not fail the batch-executor onProgress is undefined case (1 passed). Not disputing the repro above; those two may need the combined env or relay state under .sequant/.

  3. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Runner context — guard-2026-09 launch, 2026-09-20. Base: origin/main at da9ed6e8 (2.16.0 plus the plan docs). These rules override the exec skill's defaults for this run:

    • No full npm test in the worktree. Run only the test files this issue's ACs name. The runner runs the full suite once per PR from a clean shell. Under sequant run the suite is not hermetic against SEQUANT_* (bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086), so a full run shows red files you did not cause.
    • A named test file red before your change: re-run it as env -u SEQUANT_ORCHESTRATOR -u SEQUANT_WORKTREE -u SEQUANT_PHASE -u SEQUANT_ISSUE -u SEQUANT_RELAY -u SEQUANT_RELAY_FRAME npx vitest run <file>. If it is still red, the PR body names the issue number and the base-vs-head result for that test.
    • Mutation marker (gate-test ACs): <!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} --> in the PR body. failedTest MUST start with the test file path, or the qa classifier reports it Failed. Commit before mutating.
    • 30-minute no-progress wall per phase. Commit a WIP checkpoint before any long command; every command foreground, with timeout.
    • Commits: single-line git commit -m "...", no Co-Authored-By. Never rebase or force-push after pushing. One AC per line in the PR body, ids AC-N only.
    • Stop at the PR. Do not merge.

    Issue-specific: Root node for suite hygiene. AC-5 is a PR-body record: run the AC-1 files with SEQUANT_ORCHESTRATOR=sequant-run alone and SEQUANT_WORKTREE=$PWD alone and write both results. Do not edit any test file beyond the three AC-1 names, and only if AC-3 needs a vi.stubEnv example.

  4. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, 1 directory)

    AC Quality Check

    • AC-1: measurable, runnable command. OK.
    • AC-2: precise, with a grep verify. Its scope is to be settled by OQ-2 — the SEQUANT_TEMPLATES_DIR/SEQUANT_LOCKS_DIR-style vars the suite deliberately sets are also caught by a prefix scrub.
    • AC-3: "a test that deliberately reads one of the scrubbed vars" is satisfied today by existing tests (see Design Review Q3) — no new test needed.
    • AC-4/AC-5: process ACs recorded in the PR body, not in code.
    • Note: the issue table attributes the batch-executor failure to SEQUANT_WORKTREE, but withActivityHook (src/lib/workflow/batch-executor.ts:150-151) branches on SEQUANT_ORCHESTRATOR only; SEQUANT_WORKTREE is not read there. That fits both null results in the comments (each var alone passes). AC-5 records this, so the PR should report it as measured, not asserted.

    Scope Assessment

    Non-Goals: ⚠️ No Non-Goals section, but "Not attributed" (cli-ui and batch-executor timeouts) and the runner's "may touch" list bound scope: vitest.config.ts, vitest.global-setup.ts / new vitest.setup.ts, and the three AC-1 files only for an vi.stubEnv example.

    Metric Value Status
    Feature count 1 ✅
    AC items 5 ✅
    Directory spread 1 (repo root) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: Combined-env run of the three named files passes

    Verification: Integration Test (the command itself)
    Scenario: Given all six SEQUANT_* vars exported → When the AC-1 npx vitest run command runs → Then exit 0, all three files green.
    Assumptions: globalSetup env mutations reach forked workers (existing GIT_CONFIG_GLOBAL scrub relies on the same inheritance) — confirm with the AC-1 run itself, not by reading vitest docs.

    AC-2: Prefix scrub at suite level

    Verification: Manual Test (grep) plus AC-1/AC-4 as behavioral proof
    Scenario: Given vitest.global-setup.ts → When grep -n 'SEQUANT_' vitest.config.ts vitest.global-setup.ts vitest.setup.ts → Then exactly one prefix match (^SEQUANT_ / startsWith("SEQUANT_")), no per-name list.
    Assumptions: Comment lines also match the grep — keep the word SEQUANT_ out of explanatory comments (write "the SEQUANT_ prefix" once, in the code line only, or phrase the comment without it) so "one match" stays literal.

    AC-3: A test that reads a scrubbed var still controls it explicitly

    Verification: Unit Test (existing)
    Scenario: Given the scrub → When templates.test.ts (sets SEQUANT_TEMPLATES_DIR) and batch-executor.test.ts:1495-1516 (sets/restores SEQUANT_ORCHESTRATOR) run → Then they pass; saved-original is now undefined and is restored via delete.
    Assumptions: Both already handle an unset original. Run them post-change. Only add a vi.stubEnv example to an AC-1 file if a reviewer wants it — the "may touch" list allows it but does not require it.

    AC-4: Gate test mutation-verified

    Verification: Manual Test (procedure)
    Scenario: Given the fix committed → When the scrub block is deleted and the AC-1 command is re-run → Then it fails; restore; record <!-- SEQUANT_MUTATION: {"ac":"AC-4","mutation":"deleted the SEQUANT_ prefix scrub loop in vitest.global-setup.ts","failedTest":"src/commands/__tests__/prompt-wait.test.ts > ..."} --> in the PR body.
    Assumptions: failedTest must start with the test file path (#1104). Commit before mutating. Use the test name actually printed by the failing run, and check which of the three files fail (the marker names one).

    AC-5: PR body records single-var reproduction results

    Verification: Manual Test
    Scenario: Given the worktree → When the AC-1 files run with SEQUANT_ORCHESTRATOR=sequant-run alone, then SEQUANT_WORKTREE=$PWD alone, on the unfixed base (or with the scrub temporarily removed) → Then the PR body records pass/fail for each.
    Assumptions: Measure with the scrub removed — with it in place both trivially pass and the record is meaningless. Run these during the AC-4 mutation step to save a cycle.


    Implementation Plan

    Phase 1: Scrub

    1. In vitest.global-setup.ts, before execSync("npm run build"), add a loop: for (const k of Object.keys(process.env)) if (k.startsWith("SEQUANT_")) delete process.env[k]; with a comment stating intent (phases inject these; bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086). Follows the existing hermetic-git block directly above it.
    2. Run the AC-1 command. If workers still see the vars (globalSetup did not propagate), fall back to a new vitest.setup.ts listed under setupFiles in both projects (setupFiles is per-project in projects: [...], not inherited from the root test).

    Phase 2: Verify

    1. Run AC-1 command; run templates.test.ts, batch-executor.test.ts, prompt-wait.test.ts and the relay-hook file with the vars unset (regression check on AC-3).
    2. Commit. Perform AC-4 mutation (delete loop, re-run AC-1, capture failing test names) and AC-5 single-var runs in the same pass; restore.
    3. Open the PR with the marker and AC-5 record, one AC per line, ids AC-N only. Stop at the PR.

    Per the runner context: no full npm test in the worktree; run only the named files.


    Design Review

    1. Where does this logic belong? vitest.global-setup.ts — it already owns the hermetic-git env scrub and runs for every project. A per-file beforeEach would be the per-test approach AC-2 forbids.
    2. Simplest correct approach? Delete-by-prefix in globalSetup, ~3 lines. Rejected: vitest config test.env (can only set values; "" leaves the var defined, and Boolean(process.env.X) sites differ from === undefined sites); an explicit name list (the reason for AC-2).
    3. Existing pattern? The GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM block in the same file, relying on fork inheritance. Tests that need a var already set it in-process (process.env.X = ... with save/restore), so a startup scrub does not disturb them.
    4. What would a senior reviewer challenge? "Why not fix each production reader so tests don't depend on ambient env?" — the tests' subjects legitimately read the env; the harness is what's non-hermetic. And: "does a prefix scrub hide a var a developer wants to pass into the suite?" — see OQ-2.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Vitest-side scrub does not affect a developer's non-test shell or the orchestrator's own env: it only mutates the vitest main process. Verify sequant run itself is unaffected (it is not run under vitest).
    • Sibling scan: no other suite-level env leak class was searched. SEQUANT_TEMPLATES_DIR (38 refs), SEQUANT_LOCKS_DIR and SEQUANT_SKILL_LOCK_TTL_MS are read by production code and could also leak from a developer shell; the prefix scrub covers them at no extra cost. Non-SEQUANT_ leaks (e.g. CLAUDE_*) are out of scope — not proposed here.
    • Not fixed here: the 5 unattributed failures (cli-ui, batch-executor timeouts). Per the issue, out of scope unless reproducible.

    Derived ACs

    None.


    Open Questions

    1. Does globalSetup mutation reach the forked workers under Vitest 4 projects? — Recommendation: try it first (matches existing precedent); AC-1 is the arbiter; fallback in Plan step 2. Impact if wrong: AC-1 fails and we add vitest.setup.ts.
    2. Should the scrub keep any opt-in SEQUANT_* var (e.g. SEQUANT_TEMPLATES_DIR used by CI smoke workflows)? — Recommendation: no. Only .github/workflows/opencode-smoke.yml sets it, and that job does not invoke vitest (checked by grep, no vitest/npm test there). AC-2 requires pure prefix, no exceptions. Impact if wrong: a CI job that passed a var into vitest would silently lose it.
    3. The issue's WORKTREE attribution — see AC Quality Check; AC-5 measures it. No decision needed.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Small mechanical bug fix in one config file; testgen skipped (bug label, and AC-1's command is itself the test). No UI, no security surface.


    Label Review

    Current: bug
    Recommended: bug, planned
    Reason: Plan posted; no additional labels warranted.
    Quality Loop: Won't auto-enable (SCOPE_OK, single file).

  5. added
    planned
    on Sep 20, 2026
  6. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 0/1 met

    Gaps:

    • The scrub has no automated regression gate — deleting it leaves CI green, so the fix can silently regress
    • Missing CHANGELOG [Unreleased] entry for a commit that trips the §10a user-facing detection regex
    • /qa §6i cannot classify a gate-test AC as Verified when the gating test is pre-existing and deliberately unmodified, producing a false AC_NOT_MET floor for harness fixes
    • A future opt-in or live test gated on a SEQUANT_-prefixed env var would be silently disabled by the scrub with no warning in the code comment
    • No automated regression gate. Nothing asserts the scrub exists. Delete it and CI stays green, because CI has no SEQUANT_* vars to leak — the only thing that catches the regression is someone manually re-running the AC-1 command under an orchestrator. AC-4 asked for a mutation record, which was delivered, so this is not an AC gap; it is the durability gap left behind.

    Suggestions:

    • A ~10-line vitest.global-setup.test.ts that sets process.env.SEQUANT_FAKE, calls the exported setup(), and asserts the key is gone would convert this into a real gate. It would also have made §6i classify naturally (see below). The execSync("npm run build") line would need extracting or stubbing first.
    • The code comment could warn that a future opt-in/live test gate must not use a SEQUANT_ prefix, or the scrub will silently disable it.
  7. added 2 commits that reference this issue on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions