Skip to content

improve(skills): phases run affected tests (vitest --changed) instead of the full suite; CI keeps the full run #1349

Closed

Description

@admarble

Summary

Phase agents (exec, qa) run the whole test suite inside one tool call. That call no longer fits the time limits it runs under. Use the test runner's affected-tests mode in phases and keep the full suite in CI.

Current State

Proposed Change

In the exec and qa skills, replace "run the full suite" with "run the tests affected by this branch", then a named-files pass:

  1. npx vitest run --changed origin/main (Vitest: "Run tests that are affected by the changed files"; it follows the static import graph).
  2. Plus any test file named in an AC's Evidence: command. Gate tests that read SKILL.md or fixtures through fs are not in the import graph, so --changed misses them (relates to feat(spec/qa): check that an AC's declared verify command selects that issue's own tests #1074).
  3. Plus every changed test file.

Make this stack-aware, because the skills ship to non-vitest repos. Keep the command in the stack config (src/lib/stack-config.ts): jest --changedSince=origin/main, vitest --changed origin/main. If a stack has no affected mode, use the current full-suite behaviour.

The full suite stays the merge gate in CI. Phases stop duplicating it.

Acceptance Criteria

  • AC-1: exec and qa SKILL.md tell the agent to run the stack's affected-tests command plus AC-named test files instead of the full suite — Evidence: grep -nE -- "--changed( |$)|changedSince" .claude/skills/exec/SKILL.md .claude/skills/qa/SKILL.md
  • AC-2: the stacks module (src/lib/stacks.ts, resolveAffectedTestCommand; amended by the owner 2026-10-07 per spec OQ-1 / ADR-0010 — stack-config.ts holds no commands) exposes an affected-tests command for at least the vitest and jest stacks, and falls back to the full-suite command when one is absent — Evidence: npx vitest run src/lib/stacks.test.ts -t affectedTest
  • AC-3: on a sample branch that changes one src/lib module, the affected run finishes in under 120 s and includes that module's test file — Evidence: timed run recorded in the PR body
  • AC-4: a gate test that reads a skill file through fs still runs when only that skill file changes (picked up as an AC-named or changed file) — Evidence: test in the diff, mutation-verified
  • AC-5: skill mirrors in sync — Evidence: npm run lint:skill-sync

Context

  • Location: .claude/skills/{exec,qa}/SKILL.md (+ templates/plugin mirrors), src/lib/stack-config.ts
  • Type: Tests / workflow
  • Effort: Medium
  • Tool: Vitest CLI --changed
  • Identified by: /improve analysis (tooling research, 2026-10-07)

Related

Activity

  1. added
    enhancement
    qa
    on Oct 7, 2026
  2. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Runner note for the phase agents (sequant run, 2026-10-07):

    • Do not run the full npm test suite in exec or qa. CI runs it on the PR and it is a required check. Run the test files you add or change, plus each AC's own Evidence command, in the foreground with timeout 590.
    • Never start tests with run_in_background or Monitor: the phase ends when your turn ends and the result never arrives.
    • Commit every ~10 minutes of work. The MCP watchdog kills a phase after 30 minutes without progress events, and uncommitted work can be lost.
    • Put the SEQUANT_MUTATION markers and AC table in exec's final ## Summary. The runner checks the PR body after exec.
    • This issue edits the exec and qa skills. Edit .claude/skills/ then run npm run sync:skills so templates/ and plugin/ stay in sync, and keep npm run lint:skill-sync green.
  3. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, 3 directories)

    AC Quality Check

    • AC-1 Evidence fails on base today (grep rc=1), so it gates the work. OK.
    • AC-2 Evidence is vacuous: npx vitest run src/lib/stack-config.test.ts passes on unchanged code. Tighten it to a named new test, e.g. npx vitest run src/lib/stacks.test.ts -t "affectedTest". Also, stack-config.ts is only the .sequant/stack.json persistence layer. It holds no commands (see Open Question 1).
    • AC-3 Timed run in the PR body is a manual artifact. Acceptable, but record the command and wall time.
    • AC-4 "Picked up as an AC-named or changed file" is satisfied by rule 2/3 in the skill text alone. The test must prove it mechanically (see plan step 4).
    • AC-5 Passes on base today. It only guards the mirrors once the skills are edited. Fine as a final check, not as a gate on the behaviour.

    Scope Assessment

    Non-Goals: ⚠️ Not found. Suggested: no change to CI test job; no change to npm test script; no new --changed handling in sequant run TypeScript.

    Metric Value Status
    Feature count 1 ✅
    AC items 5 ✅
    Directory spread 3 (.claude/skills, src/lib, mirrors) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: exec and qa tell the agent to run the affected-tests command + AC-named files

    Verification: Manual Test (grep), backed by a skill-gate test
    Scenario: Given the edited SKILL.md files → When the Evidence: grep runs → Then both files match --changed / changedSince
    Assumptions: Exactly the passages at exec/SKILL.md:57,1339,1371-1390 and qa/SKILL.md:479-483 carry the "full suite" instruction.

    AC-2: stack config exposes an affected-tests command (vitest, jest), falls back to full suite

    Verification: Unit Test
    Scenario: Given a runner of vitest / jest / unknown → When the resolver is called → Then vitest run --changed origin/main / jest --changedSince=origin/main / the stack's full commands.test
    Assumptions: The location is decided in Open Question 1.

    AC-3: affected run on a one-module branch finishes <120 s and includes that module's test

    Verification: Manual Test (timed run in PR body)
    Scenario: Given a branch touching one src/lib module → When npx vitest run --changed origin/main runs → Then wall time <120 s and the module's test file is listed

    AC-4: fs-reading gate test still runs when only its skill file changes

    Verification: Unit Test, mutation-verified
    Scenario: Given only .claude/skills/exec/SKILL.md changed → When the affected-set builder runs → Then the gate test that reads that file is in the set
    Assumptions: --changed misses fs-read files, so the set is --changed output ∪ AC Evidence: test files ∪ changed *.test.ts. A changed SKILL.md is not itself a test file, so rule 3 alone does NOT cover it. The test must define how a changed non-test file maps to its fs-reading gate test (see Open Question 2).

    AC-5: skill mirrors in sync

    Verification: npm run lint:skill-sync

    Implementation Plan

    Phase 1: Command resolution (src)

    1. Add an optional affectedTest field per test runner, next to the existing commands.test in src/lib/stacks.ts (StackConfig.commands). Add resolveAffectedTestCommand(stack, runner) that returns the affected command, or commands.test when none exists.
    2. Detect the runner (vitest vs jest) from package.json devDependencies / config file presence. The JS stacks all use npm test, so the stack name alone cannot pick the flag.
    3. If Open Question 1 is answered "stack-config.ts", re-export the accessor there.

    Phase 2: Skills

    1. Edit .claude/skills/exec/SKILL.md (~L57, L1339, L1371-1390) and .claude/skills/qa/SKILL.md (~L479-483, L1965): replace "full suite" with the affected command, plus AC-Evidence: test files, plus changed test files. Keep timeout 600, the foreground-only rule and the WIP-commit step. State that the full suite is the CI merge gate. Keep the "no affected mode → full suite" fallback.
    2. npm run sync:skills to refresh templates/ and plugin/; then npm run lint:skill-sync, npm run lint:skill-gates.

    Phase 3: Tests

    1. Unit tests for the resolver (vitest, jest, unknown → fallback). Gate test for the skill text, scoped to the delimited test-run region only. Gate test for AC-4. Record Mutation-verified: markers with the <test file path> > … form.

    Design Review

    1. Where does this logic belong? Command table in src/lib/stacks.ts (it owns commands.test); the skill prose tells the agent which command to run.
    2. Simplest correct approach? Skill prose + a small pure resolver. Rejected: wrapping the affected-set computation in a new CLI command (more surface, the agent can compose three commands itself). Rejected: dropping the full suite everywhere (CI-only is the issue's own stated scope).
    3. Existing pattern / re-patch count? Stack command table (STACKS[*].commands). The "don't run the full suite" rule has been patched in prose several times: fix(exec): phase agent that backgrounds the test suite and waits for a notification strands uncommitted work — block Monitor/run_in_background under the orchestrator, WIP-commit on the no-commit guard #1032 (foreground only), feat(mcp): configurable per-phase no-progress wall for sequant_run — judgment-tier exec phases die at the hard-coded 30 minutes #1049 (watchdog), the 2026-09-20 qa cap at qa/SKILL.md:479. Each time it was prose-only, plus a manual runner note. This change moves the default rather than adding another exception, so it addresses the class. No deliberately local needed.
    4. Senior reviewer challenge? "--changed misses fs-read gate tests, so a green affected run can hide a red gate test." Mitigation: AC-named + changed test files, and CI keeps the full run. Also: "doesn't a stale origin/main make the set wrong?" The skill should git fetch origin main first.
    5. Producers/consumers of test-command config: src/lib/stacks.ts (commands.test, variables.TEST_COMMAND), consumers agents-md.ts:175, init.ts:1204, sync.ts:784, merge-check/combined-branch-test.ts:402 (separate ${pm.run} test, correctly stays full-suite). Skill consumers: exec, qa (and solve/loop text mention npm test: grep before finishing). Only one producer for the new field. The merge-check path must NOT adopt the affected mode.

    ADR: The plan chooses between designs (resolver in stacks.ts vs stack-config.ts; skill prose vs CLI wrapper). The exec PR must include an ADR in docs/adr/ (next NNNN, shape per docs/adr/README.md).

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Python/Rust/Go stacks: pytest/cargo/go have no built-in affected mode, so they fall back to the full suite. The skill must say so.
    • Fresh worktrees may lack origin/main locally; fetch first.
    • The existing Bash(npm test:*) allowed-tools grant does not cover npx vitest run --changed …; check each skill's allowed-tools frontmatter and add a narrow Bash(npx vitest:*) grant if absent (cf. fix(skills): narrow broad allowed-tools grants — bare Bash, Bash(*), and runner wildcards hold the directory listing for review #1287).
    • Sibling scan: other skills that still say "run npm test" (loop, fullsolve, test) are outside this issue. Recommend a follow-up rather than silent widening.

    Open Questions

    1. Where should the resolver live? The issue says src/lib/stack-config.ts, but that file only persists .sequant/stack.json; all test commands live in StackConfig.commands in src/lib/stacks.ts. Recommendation: stacks.ts, and amend AC-2's location. Impact if wrong: the AC-2 Evidence points at a file with no test of the new behaviour.
    2. How does a changed non-test file (a SKILL.md) pull in the gate test that reads it? Recommendation: the skill tells the agent to grep -l the changed path across **/*.test.ts and add those hits to the run. Impact: without it AC-4 is only met for changed test files.
    3. Tighten AC-2 Evidence to a test that fails on base (e.g. -t "affectedTest"). Recommendation: yes.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Skill-prose edits plus one small resolver. AC-2 and AC-4 declare unit-test evidence, but exec writes the tests alongside the code; testgen adds little. The new affectedTest field is skill-facing, so no browser test.

    Label Review

    Current: enhancement, qa
    Recommended: enhancement, qa, planned
    Quality Loop: Won't auto-enable (SCOPE_OK).

  4. added
    planned
    on Oct 7, 2026
  5. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 4/5 met

    Gaps:

    • exec still tells the agent to run the full npm test, contradicting the new affected-tests rule (AC-1 partially met)
    • AC-4 gate test has no recorded mutation marker in exec's Summary or the PR body
    • AC-3 timed run is not recorded in the PR body as the AC asks
    • Dangling reference to a non-existent block for other runners
    • Sibling skills still instruct the full suite; follow-up not filed — unresolved
  6. added 3 commits that reference this issue on Oct 7, 2026
  7. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    Runner note for QA round 2 (2026-10-07): the runner fixed the round-1 findings and the first CI failures on the PR branch (commits and reasons are in the PR body's "QA round 1 fixes" and "CI round fix" sections). CI is green on the current head, full suite included, so don't re-run npm test: verify each AC with its own Evidence command and the named test files, foreground, timeout 590.

  8. admarble commented on Oct 7, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 5/5 met

    Gaps:

    • Two deferred follow-ups have no terminal state (filed or dropped) — unresolved
    • New resolver exports have no production caller; skills hardcode the strings and a test keeps them in sync — unresolved
    • AC-2 text and evidence still name stack-config.ts; the owner should amend the AC to match the stacks.ts decision
    • qa's affected set can miss whole-tree skill gate tests such as skill-allowed-tools-gate; CI's full run still catches them — unresolved
  9. added 2 commits that reference this issue on Oct 7, 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

    enhancementplannedqa

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions