Skip to content

Phase Executor Unit Tests

Unit test coverage for src/lib/workflow/phase-executor.ts, a core orchestration module that handles phase execution, cold-start retry logic, MCP fallback, and QA verdict parsing.

Parses QA verdict strings from agent output. Covers all four verdict types across multiple formats:

FormatExample
Markdown header### Verdict: READY_FOR_MERGE
Bold label**Verdict:** AC_NOT_MET
Bold-wrapped value**Verdict:** **AC_MET_BUT_NOT_A_PLUS**
Plain textVerdict: NEEDS_VERIFICATION

Also tests case insensitivity, multi-line extraction, and null returns for empty/invalid input.

Formats elapsed seconds into human-readable strings:

InputOutput
00.0s
30.530.5s
901m 30s
366161m 1s

Generates phase-specific prompts with issue number substitution. Tests:

  • {issue} placeholder substitution in all positions
  • AGENTS.md content inclusion when the file exists
  • Graceful handling when AGENTS.md is absent
  • Prompt selection for Claude vs non-Claude agents (aider uses direct CLI instructions)

Tests the cold-start retry and MCP fallback logic using an injected executePhaseFn:

ScenarioExpected Behavior
First-attempt successReturns immediately, 1 call
Cold-start failures (< 60s)Retries up to 2 times before fallback
MCP fallbackDisables MCP after retry exhaustion, tries once more
retry: falseNo retries, returns on first failure
Genuine failure (>= 60s)No retry — treated as real failure, not cold-start
MCP already disabledSkips MCP fallback step
MCP fallback also failsReturns original error, not fallback error
Terminal window
npx vitest run src/lib/workflow/phase-executor.test.ts

Tests fail after modifying phase-executor.ts

Section titled “Tests fail after modifying phase-executor.ts”

Symptoms: getPhasePrompt tests fail with unexpected content.

Solution: The tests check for specific prompt content like /spec 42 or /exec 10. If you change the prompt templates in PHASE_PROMPTS or AIDER_PHASE_PROMPTS, update the test assertions to match.

Symptoms: readAgentsMd is not a function or mock not working.

Solution: The test file mocks ../agents-md.js at the module level with vi.mock(). Ensure the import path hasn’t changed if you’ve restructured the module.


Generated for Issue #378 on 2026-03-25