Skip to content

Add batch-executor unit tests for label-based phase shortcuts #460

Closed

Description

@admarble

Problem

batch-executor.ts has no test file. The isDocs shortcut (from #451) and isSimpleBugFix shortcut both have inline label detection at L465-473 and issueConfig construction at L679-686 that are untested.

The detectPhasesFromLabels function in phase-mapper.ts is well-tested (14 tests), but the batch-executor's consumption of those labels — specifically that issueConfig.issueType gets set to "docs" and passed to executePhaseWithRetry — has no test coverage. If someone refactors batch-executor and breaks the wiring, phase-mapper tests still pass.

Acceptance Criteria

  • AC-1: batch-executor.test.ts exists with tests for label-based phase shortcuts (isSimpleBugFix, isDocs)
  • AC-2: Test verifies issueConfig.issueType is set to "docs" when docs labels are present
  • AC-3: Test verifies issueConfig has no issueType when non-docs labels are present (no state leak)
  • AC-4: Test verifies bug labels take precedence over docs labels in phase selection

Context

References

  • src/lib/workflow/batch-executor.ts L460-486 (phase shortcuts), L679-686 (issueConfig)
  • src/lib/workflow/phase-mapper.test.ts (existing pattern to follow)

Activity

  1. added
    enhancement
    cli
    on Mar 26, 2026
  2. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Clear ACs, test-only issue, follows phase-mapper.test.ts pattern

    exec → qa · 4 ACs · -q · --skip-spec

  3. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Spec Plan — #460: Add batch-executor unit tests for label-based phase shortcuts


    AC Quality Check

    ✅ All 4 acceptance criteria are clear and testable.


    Scope Assessment

    Non-Goals (Required)

    ⚠️ Non-Goals section not found. Recommended scope boundaries:

    Scope Metrics

    Metric Value Status
    Feature count 1 ✅
    AC items 4 ✅
    Directory spread 1 ✅

    Scope Verdict

    ✅ SCOPE_OK — Single test file, focused on wiring verification.


    Acceptance Criteria

    AC-1: batch-executor.test.ts exists with tests for label-based phase shortcuts (isSimpleBugFix, isDocs)

    Verification Method: Unit Test

    Test Scenario:

    • Given: runIssueWithLogging is called with options.autoDetectPhases = true and labels ["bug"]
    • When: The function executes
    • Then: executePhaseWithRetry is called with phases ["exec", "qa"] (spec skipped)

    Integration Points: phase-mapper.ts (BUG_LABELS, DOCS_LABELS constants)

    AC-2: Test verifies issueConfig.issueType is set to "docs" when docs labels are present

    Verification Method: Unit Test

    Test Scenario:

    • Given: runIssueWithLogging called with labels ["docs"]
    • When: executePhaseWithRetry is invoked
    • Then: The config argument passed to executePhaseWithRetry has issueType: "docs"

    Integration Points: issueConfig construction at L691-698

    AC-3: Test verifies issueConfig has no issueType when non-docs labels are present (no state leak)

    Verification Method: Unit Test

    Test Scenario:

    • Given: runIssueWithLogging called with labels ["enhancement"]
    • When: executePhaseWithRetry is invoked
    • Then: The config argument does NOT have issueType property (or it's undefined)

    AC-4: Test verifies bug labels take precedence over docs labels in phase selection

    Verification Method: Unit Test

    Test Scenario:

    • Given: runIssueWithLogging called with labels ["bug", "docs"] and autoDetectPhases = true
    • When: The function executes
    • Then: The bug-fix shortcut fires (phases = ["exec", "qa"]) AND issueConfig.issueType is still "docs" (because issueConfig checks docs labels independently at L691-698)

    Note: The current code checks isSimpleBugFix before isDocs in the if/else chain (L477-484), so bug labels win for phase selection. However, issueConfig.issueType is set independently at L691-698, so a ["bug", "docs"] issue gets bug phases but docs issueType. The test should verify this specific behavior.


    Implementation Plan

    Phase 1: Create test file with mocks

    1. Create src/lib/workflow/batch-executor.test.ts
    2. Mock dependencies using vi.mock():
      • ./phase-executor.js → mock executePhaseWithRetry to return success PhaseResult
      • ./worktree-manager.js → mock createCheckpointCommit, rebaseBeforePR, createPR
      • ../log-writer.js → mock LogWriter
      • ./state-manager.js → mock StateManager methods
      • ./phase-spinner.js → mock PhaseSpinner
      • ./shutdown-manager.js → mock ShutdownManager
    3. Create helper function to build minimal valid ExecutionConfig and RunOptions

    Phase 2: Write test cases

    1. Bug label shortcut tests (AC-1 partial):

      • ["bug"] → phases ["exec", "qa"]
      • ["fix"], ["hotfix"], ["patch"] → same result
      • Case insensitive: ["BUG"] → same
    2. Docs label shortcut tests (AC-1 partial, AC-2):

      • ["docs"] → phases ["exec", "qa"] AND issueConfig.issueType === "docs"
      • ["documentation"], ["readme"] → same
    3. No state leak test (AC-3):

      • ["enhancement"] → issueConfig.issueType is undefined
    4. Precedence test (AC-4):

      • ["bug", "docs"] → bug shortcut fires for phases, issueType still "docs"

    Phase 3: Verify

    1. Run npm test -- src/lib/workflow/batch-executor.test.ts to confirm all tests pass

    Design Review

    1. Where does this logic belong? src/lib/workflow/batch-executor.test.ts — co-located test file following the existing *.test.ts convention in the workflow/ directory.

    2. What's the simplest correct approach? Mock executePhaseWithRetry and inspect the arguments it receives (phases via the config, and issueType). This avoids needing to run actual phases or set up worktrees. The function under test (runIssueWithLogging) is large but the label-detection logic is early and deterministic.

    3. What existing pattern does this follow? Same pattern as phase-executor.test.ts — vi.mock() at top level, vi.mocked() for typed access, beforeEach for vi.clearAllMocks(), inspect mock call arguments.

    4. What would a senior reviewer challenge? (1) "Why not extract the label logic into a testable pure function?" — That's what phase-mapper.ts already is; this tests the wiring in batch-executor. (2) "Will these tests break when Use exact label matching instead of substring includes() for phase detection #461 changes includes() to exact match?" — Yes, intentionally. These tests document current behavior; Use exact label matching instead of substring includes() for phase detection #461 should update them.


    Feature Quality Planning

    Completeness Check

    • All AC items have corresponding implementation steps
    • Integration points: phase-mapper constants, executePhaseWithRetry, issueConfig construction
    • No partial implementations planned

    Error Handling

    • N/A — test-only issue, no runtime error paths

    Code Quality

    • Types: reuse existing ExecutionConfig, RunOptions, PhaseResult
    • Follows phase-mapper.test.ts and phase-executor.test.ts patterns
    • No magic strings — use BUG_LABELS and DOCS_LABELS constants where appropriate

    Test Coverage Plan

    • Unit tests: all 4 AC items covered
    • Edge cases: case insensitivity, mixed labels, both bug+docs labels
    • Mocking: mock phase-executor and worktree-manager, not label detection

    Best Practices

    Derived ACs

    Source Derived AC Priority
    Test Coverage AC-5: Test case-insensitive label matching (e.g., ["BUG"]) Medium
    Completeness AC-6: Test autoDetectPhases = false skips label shortcuts entirely Medium

    Open Questions

    1. How to capture phases passed to executePhaseWithRetry?

      • Recommendation: Inspect executePhaseWithRetry.mock.calls[n] — the config argument contains phases (or phases are determined before the call and passed as the phase string argument)
      • Impact: Need to verify exact argument position in the function signature
    2. Should Add batch-executor unit tests for label-based phase shortcuts #460 tests cover autoDetectPhases = false?

      • Recommendation: Yes, include one test to verify shortcuts are skipped when auto-detect is off (AC-6 derived)
      • Impact: Low — adds one test case for completeness

    Conflict Risk Analysis

    In-flight work detected: Issue #461 (feature/461-use-exact-label-matching-instead-of-substring-incl)
    Status: No changes committed yet
    Overlapping area: Both touch label matching in batch-executor.ts

    Recommended approach:


    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Test-only issue with clear ACs, well-understood patterns, and no runtime changes. Assess already recommended exec → qa with skip-spec. Spec was explicitly invoked so completed here.


    Label Review

    Current: enhancement, cli
    Recommended: enhancement, cli (no changes needed)
    Reason: Test-only issue within CLI workflow module; current labels are appropriate
    Quality Loop: Won't auto-enable — scope is green, labels don't trigger it


  4. added
    planned
    on Mar 26, 2026
  5. added a commit that references this issue on Mar 26, 2026
  6. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Exec Phase — Progress Update

    AC Coverage

    AC Description Status
    AC-1 Tests for isSimpleBugFix and isDocs shortcuts ✅ Implemented
    AC-2 issueConfig.issueType set to "docs" for docs labels ✅ Implemented
    AC-3 No issueType for non-docs labels (no state leak) ✅ Implemented
    AC-4 Bug labels take precedence over docs in phase selection ✅ Implemented
    AC-5 Case-insensitive label matching (derived) ✅ Implemented
    AC-6 autoDetectPhases=false skips shortcuts (derived) ✅ Implemented

    Files Changed

    • src/lib/workflow/batch-executor.test.ts (new — 418 LOC, 18 tests)

    Quality Gates

    Check Status
    npm run build ✅ Clean
    npm run lint ✅ Clean
    npm test (target file) ✅ 18/18 passed

    Quality Plan Alignment

    N/A — Test-only issue, no runtime error paths or code quality changes.

    PR

    ✅ Created: #464

  7. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #460

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original batch-executor.test.ts exists with tests for isSimpleBugFix, isDocs MET 18 tests covering bug/fix/hotfix/docs/documentation labels
    AC-2 Original issueConfig.issueType set to "docs" for docs labels MET Verified for docs, documentation, readme labels
    AC-3 Original No issueType for non-docs labels (no state leak) MET Verified for enhancement, bug, and empty labels
    AC-4 Original Bug labels take precedence over docs in phase selection MET Test verifies bug phases fire AND issueType still set to docs
    Derived ACs
    AC-5 Derived (Test Coverage) Case-insensitive label matching MET BUG, DOCS, Documentation all tested
    AC-6 Derived (Completeness) autoDetectPhases=false skips label shortcuts MET Two tests verify explicit phases used when auto-detect disabled

    Coverage: 6/6 AC items fully met
    Original ACs: 4/4 met
    Derived ACs: 2/2 met


    Quality Plan Verification

    Dimension Items Planned Items Addressed Status
    Completeness 3 3 ✅ Complete
    Error Handling N/A N/A - (test-only issue)
    Code Quality 3 3 ✅ Complete
    Test Coverage 3 3 ✅ Complete
    Best Practices 2 2 ✅ Complete

    Derived ACs: 2/2 addressed
    Quality Plan Status: Complete


    CI Status

    Check State Conclusion Impact
    build (20.x) COMPLETED SUCCESS ✅ MET
    build (22.x) COMPLETED SUCCESS ✅ MET
    typecheck COMPLETED SUCCESS ✅ MET
    validate-skills COMPLETED SUCCESS ✅ MET
    validate-plugin COMPLETED SUCCESS ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 1 OK
    Lines added +418 -
    Lines deleted -0 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/batch-executor.test.ts N/A (is a test) N/A Self

    Coverage: N/A - the only changed file IS the test file. Tests target existing batch-executor.ts label detection logic (L465-484, L691-698).


    Code Review

    Strengths:

    • Clean mock setup covering all heavy dependencies (phase-executor, worktree-manager, state-manager, etc.)
    • Helper functions (makeConfig, makeOptions, successResult) keep test bodies concise and readable
    • Good describe/it structure mirrors AC items directly - easy to trace AC to test
    • Tests verify BOTH phase selection (via mock.calls.map(c => c[1])) AND config propagation (via call[2].issueType) - these are independent code paths at different line numbers
    • No any types, no snapshot abuse, no flaky timing dependencies

    Issues: None found

    Suggestions: None - test file is focused and well-structured for its scope


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on outputs (called phases, config values), not internals
    Coverage Depth ✅ OK Bug, docs, and non-matching labels all covered; edge cases (case, empty, mixed) included
    Mock Hygiene ✅ OK Only external dependencies mocked; label detection logic runs for real
    Test Reliability ✅ OK Deterministic - no timing, no network, no filesystem

    Issues Found: None


    Anti-Pattern Detection

    No anti-patterns detected. The test file has no production code, no error handling concerns, no security surface.


    Self-Evaluation

    • Verified working: Yes - ran npm test locally, 18/18 pass in 9ms
    • Test efficacy: High - tests exercise the actual label-matching code path in runIssueWithLogging via mocks that isolate the unit under test; a refactor that breaks label-to-phase wiring WILL fail these tests
    • Likely failure mode: If runIssueWithLogging signature changes (argument order/count), all tests break at once - but that is appropriate for API change detection
    • Verdict confidence: High - test-only change, all CI green, no runtime risk

    Verdict: READY_FOR_MERGE

    All 6 ACs (4 original + 2 derived) are met. Test file is well-structured, build and CI pass, no code quality issues. A+ implementation.

    Documentation

    • N/A - No documentation needed (test-only change, internal coverage improvement)

    CHANGELOG Verification

    Result: N/A - test-only change, not user-facing

    Next Steps

    1. Merge PR test(#460): add batch-executor unit tests for label-based phase shortcuts #464
    2. After merge, Use exact label matching instead of substring includes() for phase detection #461 (exact label matching) should update these tests when changing includes() to exact match
  8. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor
    No description provided.
  9. added
    ready-for-review
    on Mar 26, 2026
  10. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #460

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original batch-executor.test.ts with tests for isSimpleBugFix, isDocs MET 18 tests covering bug/fix/hotfix/docs/documentation labels
    AC-2 Original issueConfig.issueType set to "docs" for docs labels MET Verified for docs, documentation, readme labels via call[2].issueType
    AC-3 Original No issueType for non-docs labels (no state leak) MET Verified for enhancement, bug, and empty labels — issueType undefined
    AC-4 Original Bug labels take precedence over docs in phase selection MET Test verifies bug phases fire AND issueType still set to docs
    Derived ACs
    AC-5 Derived (Test Coverage) Case-insensitive label matching MET BUG, DOCS, Documentation all tested
    AC-6 Derived (Completeness) autoDetectPhases=false skips label shortcuts MET Two tests verify explicit phases used when auto-detect disabled

    Coverage: 6/6 AC items fully met
    Original ACs: 4/4 met
    Derived ACs: 2/2 met


    Quality Plan Verification

    Dimension Items Planned Items Addressed Status
    Completeness 3 3 ✅ Complete
    Error Handling N/A N/A - (test-only issue)
    Code Quality 3 3 ✅ Complete
    Test Coverage 3 3 ✅ Complete
    Best Practices 2 2 ✅ Complete

    Derived ACs: 2/2 addressed
    Quality Plan Status: Complete


    CI Status

    Check State Conclusion Impact
    build (20.x) COMPLETED SUCCESS ✅ MET
    build (22.x) COMPLETED SUCCESS ✅ MET
    typecheck COMPLETED SUCCESS ✅ MET
    validate-skills COMPLETED SUCCESS ✅ MET
    validate-plugin COMPLETED SUCCESS ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 1 OK
    Lines added +418 -
    Lines deleted -0 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/batch-executor.test.ts N/A (is a test) N/A Self

    Coverage: N/A — the only changed file IS the test file. Tests target existing batch-executor.ts label detection (L465-484, L691-698).


    Code Review

    Strengths:

    • Mock setup covers all heavy dependencies while leaving phase-mapper.ts unmocked — label detection runs for real, testing actual wiring
    • Helper functions (makeConfig, makeOptions, successResult) keep test bodies concise
    • Argument position verification is correct: call[1] = phase, call[2] = config — confirmed against executePhaseWithRetry signature
    • Tests verify BOTH independent code paths: phase selection (L465-484) AND config propagation (L691-698)
    • AC-4 (precedence) correctly tests that isSimpleBugFix fires first in if/else chain while issueIsDocs at L693 sets issueType independently
    • No any types, no snapshot abuse, no flaky timing dependencies

    Issues: None

    Suggestions: None — focused test file appropriate for scope


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on outputs (called phases, config values), not internals
    Coverage Depth ✅ OK Bug, docs, non-matching, empty, mixed, and case variants all covered
    Mock Hygiene ✅ OK Only external deps mocked; detectPhasesFromLabels runs for real
    Test Reliability ✅ OK Deterministic — no timing, network, or filesystem deps

    Anti-Pattern Detection

    No anti-patterns detected. Test-only file with no production code, no error handling concerns, no security surface.


    Self-Evaluation

    • Verified working: Yes — ran npm test, 18/18 pass in 14ms; traced function signatures to confirm call[1]/call[2] map to phase/config
    • Test efficacy: High — a refactor that breaks label→phase or label→issueType wiring WILL fail these tests
    • Likely failure mode: If runIssueWithLogging argument order changes, all tests break at once — appropriate for API change detection
    • Verdict confidence: High — test-only change, all CI green, no runtime risk

    Verdict: READY_FOR_MERGE

    All 6 ACs (4 original + 2 derived) are met. Tests are well-structured with correct mock boundaries. Build and CI pass. A+ implementation.

    Documentation

    • N/A — No documentation needed (test-only change, internal coverage improvement)

    CHANGELOG Verification

    Result: N/A — test-only change, not user-facing

    Next Steps

    1. Merge PR test(#460): add batch-executor unit tests for label-based phase shortcuts #464
    2. After merge, Use exact label matching instead of substring includes() for phase detection #461 (exact label matching) should update these tests when changing includes() to exact match
  11. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor
    No description provided.
  12. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Documentation Review Complete

    This issue contains test-only changes (batch-executor.test.ts). No user-facing functionality was added or modified — no documentation generation required.

    Files Modified:

    • src/lib/workflow/batch-executor.test.ts (new — unit tests for label-based phase shortcuts)

    Status:

    ✅ No documentation needed. Ready to merge.

  13. added 2 commits that reference this issue on Mar 26, 2026
  14. added a commit that references this issue on Mar 26, 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

    clienhancementplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions