Skip to content

test(workflow): the #533 label-shortcut tests take ~850 ms with every phase mocked — one hit 5785 ms on CI and turned main red at da9c4fd49 #1560

Closed

Description

@admarble

Problem

main went red at da9c4fd (run https://github.com/sequant-io/sequant/actions/runs/39328813306, attempt 1). The only failure was src/lib/workflow/batch-executor.test.ts > runIssueWithLogging — label-based phase shortcuts > #533: bug labels include spec by default > runs spec → exec → qa for 'bug' label, at 5785 ms against the unit project's 5 s default timeout. The commit under test (#1552) does not touch batch-executor.ts or its test. The failed job's re-run passed. The draft revert #1559 closed unmerged under the red-main rule.

Every phase is mocked in this test (mockExecutePhase.mockResolvedValue(successResult("exec"))), yet it takes about 850 ms locally (macOS, --reporter verbose: 857 ms for 'bug', 819 ms for 'fix'). So something un-mocked in runIssueWithLogging costs most of a second. A loaded CI runner stretched that roughly 7× past the timeout. The sibling #533 cases have the same shape, so they carry the same risk.

Acceptance Criteria

  • AC-1: The #533 label-shortcut tests run in well under the timeout. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts -t "#533" --reporter verbose 2>&1 | sed 's/\x1b\[[0-9;]*m//g' | grep -oE "label [0-9]+ms" | awk '{gsub("ms","",$2); if ($2+0 > 200) bad++} END {print bad+0}' → 0 (today: every case is over 800 ms)
  • AC-2: The PR body names what took the time (a real subprocess, a real filesystem walk, a retry backoff or a timer) and how the test now avoids it: a mock, an injected dependency or fake timers. Raising the timeout alone is not the fix. Evidence: gh pr view <pr> --json body --jq .body | grep -ciE 'took the time|un-mocked' → ≥ 1 (not runnable until the PR exists)
  • AC-3: The existing assertions are unchanged. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts → 0 failed

May touch

src/lib/workflow/batch-executor.test.ts, and, only if the slow call has no seam, a minimal injection point in src/lib/workflow/batch-executor.ts.

Non-Goals

  • Raising the unit project's default timeout.
  • Behaviour changes in runIssueWithLogging.
  • Anything under plugin/, .claude/skills/ or templates/skills/.

Activity

  1. added
    bug
    on Oct 19, 2026
  2. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Second occurrence, 2026-10-19 22:25Z: main went red at 755d475 (#1558, which touches neither file). The same test took 9402 ms: https://github.com/sequant-io/sequant/actions/runs/39334666470. A draft revert, #1562, is open under the red-main rule while the failed job re-runs. Two red mains in about an hour make this a merge-gate blocker, not an occasional flake.

  3. admarble commented on Oct 20, 2026

    @admarble
    ContributorAuthor

    Runner context, 2026-10-20, before launch (stop-at-PR; default tier). main = 755d475.

    Scope: prefer a test-only fix in batch-executor.test.ts, mocking whatever un-mocked call costs about 850 ms. Find it by timing, for example --reporter verbose with a temporary console.time around suspects. Don't guess.

    PR #1564 (#1504) is about to merge and edits batch-executor.ts. If the slow call has no seam and you must add one there, merge origin/main first.

    Do not raise any timeout (Non-Goal).

    For every phase, and the qa phase by name: run the full suite at most once, in the foreground, under timeout, after a WIP commit. Each MCP-dispatched phase has a 30-minute wall. Prefer the targeted npx vitest run <files> for the ACs.
    CHANGELOG: add [Unreleased] lines under the existing ### Added / ### Changed headings, not changelog.d/ fragments, and never add a second heading of the same name.
    Lint: #1503 made no-unused-vars, no-empty-object-type and prefer-const errors, and knip counts unused exports. Don't export what nothing imports.
    Health baseline: regenerate scripts/qa/health-baseline.json (npx tsx scripts/qa/health-report.ts --write-baseline) only to record a metric that went down. If npm run lint:health reports a rise, restructure so it holds. Otherwise leave the baseline alone and name the rise in the PR body. Owner ruling: a proseGate.lines rise caused by tests in files that mention SKILL.md only as a path may be absorbed, and must be said so.
    Freeze: nothing under plugin/, .claude/skills/ or templates/skills/.

  4. admarble commented on Oct 20, 2026

    @admarble
    ContributorAuthor

    Complexity: Simple (3 ACs, 1 directory)

    AC Quality Check

    • AC-1: Evidence is runnable and fails today (every case >800 ms). Note the label [0-9]+ms grep matches only the 7 ... label cases; the 3 other #533-matching cases (names without "label") are not gated by the awk. Acceptable, but the fix should cover them too (same root cause).
    • AC-2: PR-body check, not runnable until the PR exists. Fine.
    • AC-3: Passes today, so it gates only "no regression"; intended.
    • Non-Goals present.

    Root cause (measured, not guessed)

    runIssueWithLogging → resolveSpecRecommendation({chatOutput, issueNumber, labels}) (batch-executor.ts:1677) defaults its githubProvider to new GitHubProvider(). fetchIssueCommentBodiesSync (platforms/github.ts:150) does a real spawnSync("gh", ["issue","view",N,"--json","comments",...]). batch-executor.ts passes no provider, and the test file mocks no gh. So each spec-phase test makes a real GitHub API call for issue #42, #43, ... on the runner.

    Evidence: with a stub gh (exit 1) first on PATH, the same -t "#533" run drops from 715–1218 ms per case to 6–73 ms. No other un-mocked call matters for these cases.

    Acceptance Criteria

    AC-1: #533 tests run well under the timeout

    Verification: Integration Test (the Evidence command itself)
    Scenario: Given no real gh call is made → When -t "#533" runs → Then each case is <200 ms (expected ~10 ms).

    AC-2: PR body names the cause

    Verification: Manual Test
    Scenario: PR body says: "un-mocked gh issue view subprocess in resolveSpecRecommendation took the time; the test now stubs GitHubProvider.prototype.fetchIssueCommentBodiesSync."

    AC-3: Assertions unchanged

    Verification: Unit Test
    Scenario: Given only setup changed → When the full file runs → Then 0 failed, no expect lines touched.

    Implementation Plan

    1. In src/lib/workflow/batch-executor.test.ts, add vi.spyOn(GitHubProvider.prototype, "fetchIssueCommentBodiesSync").mockReturnValue([]) in the top-level beforeEach (after vi.clearAllMocks(); restoreAllMocks/mockRestore in afterEach if the file lacks one). [] is exactly what the real method returns when gh fails, so chain behaviour (fall to label-fallback) is unchanged. Import GitHubProvider from ./platforms/github.js (a spy, not a module mock, so the file's note about blanket mocks breaking other sites does not apply).
    2. Run the whole file; any test that relied on real fetch results (none expected, since CI has no matching comments for those issue numbers) overrides the spy locally.
    3. Re-run AC-1 Evidence; also check fetchIssueCommentsSync / other GitHubProvider sync methods are not hit by other slow tests (--reporter verbose, sort by duration) and report, don't expand scope.
    4. No change to batch-executor.ts: the seam already exists on the provider prototype, so no conflict with feat(#1504): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1564.

    Scope the spy file-wide vs. only the #533 describes: recommend file-wide. Any spec-phase test in the file has the same exposure (sibling-site scan), and it also stops tests from hitting the real GitHub API with fabricated issue numbers.

    Design Review

    1. Where does this belong? The test's setup; production code is correct.
    2. Simplest approach? Prototype spy returning []. Rejected: adding a githubProvider arg to runIssueWithLogging (production change, Non-Goal-adjacent); fake timers (nothing timed); raising timeout (Non-Goal).
    3. Pattern / re-patch count? Existing pattern: ctx.postComment injection for bug(run): orchestrated 'sequant run --phases qa' re-run computes a fresh verdict but never posts it, contradicting the stale comment left visible #964 and mocked phase executor. The same class (un-mocked gh in this file) was handled for postComment once (bug(run): orchestrated 'sequant run --phases qa' re-run computes a fresh verdict but never posts it, contradicting the stale comment left visible #964/bug(qa): a failing qa verdict (AC_NOT_MET) is never posted to the issue — posting is gated on phase success #1070); this is the second site, so I'm recording it as deliberately local, reason: test-setup spy; class (tests reaching real gh) tracked here in #1560. Two red mains (chore(#1528): revert #1552 — main red at da9c4fd49 #1559, chore(#1473): revert #1558 — main red at 755d47587 #1562) are the cost of leaving it.

    Open Questions

    1. File-wide vs. #533-only spy? Recommend file-wide (above). Impact if wrong: a test that wants real gh behaviour fails loudly and gets a local override.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: One test-file change, root cause measured. No testgen: the existing tests are the verification.

    Label Review

    Current: bug. Recommended: bug + planned. Quality loop won't auto-enable.

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

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/3 met

    Gaps:

    • Other test files that drive runIssueWithLogging may still spawn real gh via GitHubProvider sync calls and carry the same timeout risk

    Suggestions:

    • The spy is file-wide in the top-level beforeEach. A future test that needs real comment bodies has to override it locally. The PR body already notes this.
  7. admarble commented on Oct 20, 2026

    @admarble
    ContributorAuthor

    Execution Verification (runner, 2026-10-20), PR #1567 @ 22cfaaa

    Cause: resolveSpecRecommendation defaults to a real GitHubProvider, whose fetchIssueCommentBodiesSync spawned gh issue view from inside a unit test. The fix stubs it with vi.spyOn(GitHubProvider.prototype, "fetchIssueCommentBodiesSync").mockReturnValue([]).

    Results:

    • AC-1: 0. The seven #533 cases now take 0–3 ms, down from about 850 ms.
    • AC-3: batch-executor.test.ts 151 passed.

    QA's open point: other files that drive the same path. The runner timed them:

    • model-ladder.test.ts and batch-executor.model-ladder.test.ts have no slow cases.
    • run-orchestrator.test.ts has 2 cases over 400 ms (≈5.0 s in total).
    • skills-preflight.test.ts has 6 cases over 400 ms (≈4.9 s).

    Whether those are gh spawns is not yet confirmed; that is the owner's call to file or fold in.

  8. added a commit that references this issue on Oct 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