Skip to content

Use exact label matching instead of substring includes() for phase detection #461

Closed

Description

@admarble

Problem

All label detection in phase-mapper.ts uses label.includes(targetLabel), which is a substring match. This means:

  • A label "docstring" matches "docs" → triggers docs pipeline
  • A label "endorsed" matches "doc" (if added) → false positive
  • A label "debugging" matches "bug" → triggers bug fix pipeline
  • A label "patchwork" matches "patch" → triggers bug fix pipeline

While no real incidents have occurred, "docstring" is a realistic label name that would incorrectly trigger the lighter docs pipeline.

Acceptance Criteria

  • AC-1: Replace label.includes(targetLabel) with exact equality (label === targetLabel) across all label arrays in phase-mapper.ts
  • AC-2: Update batch-executor.ts inline checks to use exact matching consistently
  • AC-3: Update existing tests to verify exact matching (no substring collisions)
  • AC-4: Add regression tests: "docstring" should NOT match docs, "debugging" should NOT match bug

Scope

All label arrays: BUG_LABELS, DOCS_LABELS, UI_LABELS, COMPLEX_LABELS, SECURITY_LABELS

References

Activity

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

    @admarble
    ContributorAuthor

    → PROCEED — Clear ACs, all referenced files exist, straightforward fix

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

  3. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Spec Plan — #461: Exact Label Matching

    AC Checklist with Verification Criteria

    AC Description Verification Method
    AC-1 Replace label.includes() with === in phase-mapper.ts detectPhasesFromLabels(["docstring"]) → standard phases Unit Test
    AC-2 Update batch-executor.ts inline checks 3 call sites at L469, L474, L694 Unit Test
    AC-3 Update existing tests for exact matching All existing tests pass unchanged Unit Test
    AC-4 Regression tests for substring non-matching "docstring" ≠ docs, "debugging" ≠ bug Unit Test
    AC-5 (derived) Fix hasUILabels() at L175 hasUILabels(["webinar"]) → false Unit Test

    Implementation Plan

    Phase 1: Fix phase-mapper.ts (AC-1, AC-5)

    • Replace 5 .includes() → === in detectPhasesFromLabels() (L62-84)
    • Replace 1 .includes() → === in hasUILabels() (L175)

    Phase 2: Fix batch-executor.ts (AC-2)

    • Replace 3 .includes() → === at L469, L474, L694

    Phase 3: Tests (AC-3, AC-4)

    • Verify existing tests pass (they use exact label names)
    • Add regression tests: "docstring", "debugging", "patchwork", "webinar" must NOT trigger any pipeline shortcut

    Conflict Note

    Issue #460 (batch-executor tests) has an open worktree but no changes yet. Recommend merging #461 first, then #460 adjusts tests to assert exact matching.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Mechanical find-and-replace fix, clear AC, no ambiguity.


    Total: 9 call sites across 2 files. All changes are label.includes(x) → label === x.

  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 Progress Update

    AC Coverage

    AC Description Status
    AC-1 Replace includes() with === in phase-mapper.ts ✅ Done (6 sites)
    AC-2 Update batch-executor.ts inline checks ✅ Done (3 sites)
    AC-3 Existing tests pass unchanged ✅ All 16 pass
    AC-4 Regression tests for substring non-matching ✅ 6 tests added
    AC-5 (derived) Fix hasUILabels() exact matching ✅ Done + 2 tests

    Key Files Changed

    • src/lib/workflow/phase-mapper.ts — 6 .includes() → ===
    • src/lib/workflow/batch-executor.ts — 3 .includes() → ===
    • src/lib/workflow/phase-mapper.test.ts — 6 regression tests + 2 hasUILabels tests

    Checks

    Check Result
    npm run build ✅ Pass
    npm run lint ✅ Pass
    npm test (phase-mapper) ✅ 22/22 pass

    PR

    Created: #463

    Quality Plan Alignment

    N/A — No quality plan in issue

  7. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #461

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Replace label.includes() with === in phase-mapper.ts MET 6 call sites converted: isBugFix, isDocs, isUI, isComplex, isSecurity, hasUILabels
    AC-2 Original Update batch-executor.ts inline checks MET 3 call sites converted: L469, L474, L694
    AC-3 Original Existing tests pass with exact matching MET All 16 pre-existing tests pass unchanged
    AC-4 Original Regression tests for substring non-matching MET 6 tests: docstring, debugging, patchwork, webinar, complexity, insecurity
    AC-5 Derived (Spec) Fix hasUILabels() exact matching MET Fixed + 2 tests (exact match true, substring collision false)

    Coverage: 5/5 AC items fully met


    CI Status

    Check Conclusion Impact
    build (20.x) SUCCESS ✅ MET
    build (22.x) SUCCESS ✅ MET
    typecheck SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET
    validate-plugin 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 3 OK
    Lines added +57 -
    Lines deleted -9 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/phase-mapper.ts Standard ✅ Yes phase-mapper.test.ts (22 tests)
    src/lib/workflow/batch-executor.ts Standard ✅ Yes Covered by phase-mapper tests (shared label arrays)
    src/lib/workflow/phase-mapper.test.ts Test file N/A —

    Coverage: 2/2 changed source files have corresponding tests


    Code Review

    Strengths:

    • Clean, mechanical replacement — every .includes() → === with no extraneous changes
    • Comprehensive regression tests covering all 5 label arrays (not just docs/bug)
    • Derived AC-5 caught the same bug in hasUILabels() which the original ACs missed

    Issues: None

    Suggestions: None — this is a minimal, focused fix


    Anti-Pattern Detection

    Code Patterns

    No anti-patterns detected. All changes are label.includes(x) → label === x.

    Zero remaining label.includes() calls in the workflow directory (verified via grep).


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Tests assert on output phases, not internals
    Coverage Depth ✅ OK All 5 label arrays have substring-collision regression tests
    Mock Hygiene ✅ OK No mocks — pure function tests
    Test Reliability ✅ OK Deterministic, no timing dependencies

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ⚠️ Borderline — fix affects label detection behavior
    [Unreleased] entry ❌ Missing

    Result: Add entry under ### Fixed before merging: "Fix substring label matching in phase detection — use exact equality (#461)"


    Self-Evaluation

    • Verified working: Yes — ran all 22 phase-mapper tests, all pass. Confirmed zero label.includes() remain.
    • Test efficacy: High — regression tests directly exercise the bug scenario (docstring ≠ docs, etc.)
    • Likely failure mode: None realistic. Only risk would be a label that is a legitimate exact match not in the arrays, but the arrays are unchanged.
    • Verdict confidence: High

    Verdict: READY_FOR_MERGE

    Clean, focused fix. All 5 ACs met. 22/22 tests pass. CI green. No remaining label.includes() calls.

    Documentation

    • N/A — No new features or flags
    • CHANGELOG entry needed under ### Fixed

    Next Steps

    1. Add CHANGELOG entry: Fix substring label matching in phase detection — use exact equality (#461) under ### Fixed in [Unreleased]
    2. Merge PR fix(#461): use exact label matching instead of substring includes() #463
  8. added
    ready-for-review
    on Mar 26, 2026
  9. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #461

    AC Coverage

    AC Description Status Notes
    AC-1 Replace .includes() with === in phase-mapper.ts MET All 6 sites updated: detectPhasesFromLabels (BUG, DOCS, UI, COMPLEX, SECURITY) + hasUILabels
    AC-2 Update batch-executor.ts inline checks MET All 3 inline .includes() → === (BUG_LABELS, DOCS_LABELS ×2)
    AC-3 Update tests to verify exact matching MET New phase-mapper.test.ts with 22 tests covering all label categories
    AC-4 Regression tests for substring collisions MET Tests for docstring, debugging, patchwork, webinar, complexity, insecurity

    Coverage: 4/4 AC items fully met


    CI Status

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

    CI Summary: 5/5 passed


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +57 -
    Lines deleted -9 -

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    phase-mapper.ts Standard ✅ Yes phase-mapper.test.ts (new, 22 tests)
    batch-executor.ts Standard ✅ Yes Existing test suite

    Coverage: 2/2 changed source files have corresponding tests


    Code Review

    Strengths:

    • Surgical fix — 9 substitutions of .includes() → ===, nothing else changed
    • Comprehensive regression tests covering all 5 label arrays plus hasUILabels
    • Tests verify both positive matches (exact labels) and negative matches (substring collisions)
    • Exports DOCS_LABELS and BUG_LABELS for test access — clean approach

    Issues: None

    Note: doctor.ts:87 retains .includes() for SKIP_ISSUE_LABELS — this is correctly out of scope (different feature, different matching semantics for user-defined skip labels).


    Anti-Pattern Detection

    No anti-patterns detected. Change is a simple equality substitution.


    Self-Evaluation

    • Verified working: Yes — tests execute and pass, build compiles, regression cases verified
    • Test efficacy: High — tests directly verify the fix by asserting substring labels DON'T match
    • Likely failure mode: A new label array added in future using .includes() by copy-paste from old pattern — mitigated by test precedent
    • Verdict confidence: High — mechanical fix, thorough tests, all CI green

    CHANGELOG Verification

    Result: Missing entry for bug fix. This is a correctness fix for label matching. Recommend adding:

    - Fix label matching to use exact equality instead of substring includes (#461)
    

    Verdict: READY_FOR_MERGE

    Clean, focused bug fix. All 4 ACs met. All 9 .includes() → === substitutions verified. 22 regression tests cover every label array. CI passes. Only recommendation is adding a CHANGELOG entry.

    Next Steps

    1. Add CHANGELOG entry under [Unreleased] > Fixed
    2. Merge PR fix(#461): use exact label matching instead of substring includes() #463
  10. added 2 commits that reference this issue on Mar 26, 2026
  11. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Documentation Generated

    File: docs/features/exact-label-matching.md

    Sections Included:

    • Quick Start — what changed and why
    • What Changed — before/after comparison with substring collision table
    • Affected Label Sets — all recognized labels and their pipeline effects
    • Usage — exact matching behavior with examples
    • Troubleshooting — common issues after the change

    Next Steps:

    1. Review generated documentation for accuracy
    2. Merge PR to deploy documentation

    Ready to merge!

  12. added 4 commits that reference this issue on Mar 26, 2026
  13. added 2 commits that reference this issue on Sep 9, 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