Skip to content

improve(run): add unit tests for exported utility functions #317

Closed

Description

@admarble

Summary

src/commands/run.ts is the core workflow execution engine (3,459 lines) with many exported utility functions that have minimal test coverage. Add focused unit tests for the testable utility functions.

Current State

run.test.ts exists but has limited meaningful coverage. The following exported functions lack tests:

  • parseQaVerdict() — parses QA verdict strings into structured results
  • listWorktrees() — lists git worktrees with metadata
  • getWorktreeChangedFiles() — detects changed files in a worktree
  • detectPhasesFromLabels() — maps issue labels to workflow phases
  • parseRecommendedWorkflow() — parses workflow recommendations from issue comments
  • determinePhasesForIssue() — determines which phases to run for an issue

These are critical path functions with complex branching logic.

Proposed Change

Expand src/commands/run.test.ts (or create focused test files) with unit tests for each exported utility function. Focus on:

  • Happy path and edge cases
  • Error conditions and fallback behavior
  • Various input formats (especially for parsing functions)

Acceptance Criteria

  • parseQaVerdict tested with pass/fail/partial verdicts and malformed input
  • detectPhasesFromLabels tested with various label combinations
  • parseRecommendedWorkflow tested with various workflow formats
  • Worktree utility functions tested (may need git mocking)
  • All new tests pass with npx vitest run
  • No regressions in existing tests

Context

  • Location: src/commands/run.ts
  • Type: Tests
  • Effort: Medium (2-3 hours)
  • Identified by: /improve analysis

Activity

  1. added
    enhancement
    auto-ready
    on Feb 21, 2026
  2. admarble commented on Mar 10, 2026

    @admarble
    ContributorAuthor

    Spec Plan — #317

    Current Coverage Analysis

    Most functions listed in this issue already have test coverage in run.test.ts:

    Function Test Status Tests
    parseQaVerdict ✅ Covered 15+ cases
    listWorktrees ✅ Covered 3 cases
    getWorktreeChangedFiles ✅ Covered 3 cases
    detectPhasesFromLabels ✅ Covered 7 cases
    parseRecommendedWorkflow ✅ Covered 12 cases
    determinePhasesForIssue ❌ Not exported, untested 0

    Remaining Gaps (Exported Functions Without Tests)

    Function Type Testability
    getWorktreeDiffStats Pure parsing Easy — mock spawnSync
    filterResumedPhases Logic + state Medium — mock getResumablePhasesForIssue
    determinePhasesForIssue Phase logic Needs export first

    Implementation Plan

    1. Export determinePhasesForIssue so it can be unit tested
    2. Add tests for getWorktreeDiffStats (parsing git diff stat output)
    3. Add tests for filterResumedPhases (resume logic)
    4. Add tests for determinePhasesForIssue (phase determination with options)
    5. Verify all tests pass with no regressions

    AC Coverage

    • AC-1 (parseQaVerdict): ✅ Already met
    • AC-2 (detectPhasesFromLabels): ✅ Already met
    • AC-3 (parseRecommendedWorkflow): ✅ Already met
    • AC-4 (worktree utilities): ✅ Partially met, adding getWorktreeDiffStats tests
    • AC-5 (all tests pass): Will verify
    • AC-6 (no regressions): Will verify

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Test-only issue, most work already done, small remaining gap

  3. added a commit that references this issue on Mar 10, 2026
  4. added
    ai-in-progress
    on Mar 11, 2026
  5. added a commit that references this issue on Mar 11, 2026
  6. admarble commented on Mar 11, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #317
    Status: READY_FOR_MERGE

    Summary

    • AC: 6/6 met
    • Tests: 116/116 passed (111 existing + 5 new filterResumedPhases tests)
    • Build: Clean
    • QA: All checks passed

    Changes Made

    1. Exported determinePhasesForIssue for testability (+1 line in run.ts)
    2. Added 6 tests for getWorktreeDiffStats (parsing git diff stat output, error handling)
    3. Added 9 tests for determinePhasesForIssue (testgen insertion, UI label handling, immutability)
    4. Added 5 tests for filterResumedPhases (resume=true/false, all-completed, none-completed, immutability)

    Coverage

    Most functions listed in the issue already had tests. The remaining gaps (getWorktreeDiffStats, determinePhasesForIssue, filterResumedPhases) are now covered.

    PR: #346

  7. added
    ai-in-progress
    and removed
    ai-in-progress
    on Mar 11, 2026
  8. added a commit that references this issue on Mar 11, 2026
  9. removed
    ai-in-progress
    on Mar 11, 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

    auto-readyenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions