test(tui): add Behave coverage for tui/search/fuzzy.py score_match and rank_candidates #10708

Open
opened 2026-04-19 07:17:48 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • File: src/cleveragents/tui/search/fuzzy.py
  • Commit message: test(tui): add Behave unit tests for tui/search/fuzzy score_match and rank_candidates
  • Branch name: test/tui-fuzzy-search-coverage

Background and Context

The tui/search/fuzzy.py module implements the weighted fuzzy search algorithm used by the TUI reference picker and slash command overlay (ADR-046). It contains two public functions and one dataclass:

  • FuzzyCandidate -- frozen dataclass with value, score, and reason fields
  • score_match(query, value) -- scores a query against a value using six distinct code paths:
    1. Empty query returns FuzzyCandidate with score 0.0 and reason "empty"
    2. Prefix match: score 1.0, reason "prefix"
    3. Substring match: score 0.7, reason "substring"
    4. Path-component match (all /-split parts present): score 0.8, reason "path-component"
    5. Fuzzy match via difflib.SequenceMatcher (ratio >= 0.4): score 0.4 * ratio, reason "fuzzy"
    6. No match: returns None
  • rank_candidates(query, values, *, recency, limit) -- ranks candidates with deterministic tie-breaking by score (descending), recency (descending), then value (ascending); respects limit

There is currently no Behave feature file for this module. The only existing issue about this module is #5969 (a bug report about the fuzzy score weighting), which is a separate concern from coverage.

Without dedicated unit tests, the following code paths are not exercised by the Behave suite:

  • Empty query path in score_match
  • Path-component match path (multi-part /-separated query)
  • Fuzzy match path (difflib ratio >= 0.4 but not prefix/substring)
  • No-match path (returns None)
  • rank_candidates with recency weighting
  • rank_candidates with limit enforcement
  • rank_candidates tie-breaking (same score, different recency/alphabetical)

Acceptance Criteria

  • A new Behave feature file features/tui_fuzzy_search_coverage.feature exists
  • Feature covers all six score_match code paths (empty, prefix, substring, path-component, fuzzy, no-match)
  • Feature covers rank_candidates with recency weighting, limit enforcement, and tie-breaking
  • Feature covers FuzzyCandidate dataclass fields (value, score, reason)
  • All new scenarios pass nox -s unit_tests
  • Coverage remains >= 97% (nox -s coverage_report)
  • No regressions in any other nox session

Subtasks

  • Create features/tui_fuzzy_search_coverage.feature with scenarios for all score_match paths
  • Add scenarios for rank_candidates with recency, limit, and tie-breaking
  • Add step definitions in features/steps/tui_fuzzy_search_coverage_steps.py
  • Run nox -s unit_tests and fix any failures
  • Run nox -s coverage_report and verify >= 97%
  • Run full nox suite and confirm no regressions

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage >= 97%.

Duplicate Check

  • 2026-04-19: GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=fuzzy found #5969 (bug about score weighting), #5305 (TUI Reference Epic) -- neither is a coverage issue for tui/search/fuzzy.py
  • 2026-04-19: GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=rank_candidates only found build session issue #3775 -- no coverage issue exists
  • 2026-04-19: GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=tui+fuzzy+coverage no dedicated coverage issue found
  • 2026-04-19: GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=score_match no coverage issue found
  • No existing Behave feature file for tui/search/fuzzy.py found in features/ directory

Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-worker

## Metadata - **File:** `src/cleveragents/tui/search/fuzzy.py` - **Commit message:** `test(tui): add Behave unit tests for tui/search/fuzzy score_match and rank_candidates` - **Branch name:** `test/tui-fuzzy-search-coverage` ## Background and Context The `tui/search/fuzzy.py` module implements the weighted fuzzy search algorithm used by the TUI reference picker and slash command overlay (ADR-046). It contains two public functions and one dataclass: - `FuzzyCandidate` -- frozen dataclass with `value`, `score`, and `reason` fields - `score_match(query, value)` -- scores a query against a value using six distinct code paths: 1. Empty query returns `FuzzyCandidate` with score 0.0 and reason "empty" 2. Prefix match: score 1.0, reason "prefix" 3. Substring match: score 0.7, reason "substring" 4. Path-component match (all `/`-split parts present): score 0.8, reason "path-component" 5. Fuzzy match via `difflib.SequenceMatcher` (ratio >= 0.4): score `0.4 * ratio`, reason "fuzzy" 6. No match: returns `None` - `rank_candidates(query, values, *, recency, limit)` -- ranks candidates with deterministic tie-breaking by score (descending), recency (descending), then value (ascending); respects `limit` There is currently **no Behave feature file** for this module. The only existing issue about this module is #5969 (a bug report about the fuzzy score weighting), which is a separate concern from coverage. Without dedicated unit tests, the following code paths are not exercised by the Behave suite: - Empty query path in `score_match` - Path-component match path (multi-part `/`-separated query) - Fuzzy match path (difflib ratio >= 0.4 but not prefix/substring) - No-match path (returns `None`) - `rank_candidates` with recency weighting - `rank_candidates` with limit enforcement - `rank_candidates` tie-breaking (same score, different recency/alphabetical) ## Acceptance Criteria - [ ] A new Behave feature file `features/tui_fuzzy_search_coverage.feature` exists - [ ] Feature covers all six `score_match` code paths (empty, prefix, substring, path-component, fuzzy, no-match) - [ ] Feature covers `rank_candidates` with recency weighting, limit enforcement, and tie-breaking - [ ] Feature covers `FuzzyCandidate` dataclass fields (value, score, reason) - [ ] All new scenarios pass `nox -s unit_tests` - [ ] Coverage remains >= 97% (`nox -s coverage_report`) - [ ] No regressions in any other nox session ## Subtasks - [ ] Create `features/tui_fuzzy_search_coverage.feature` with scenarios for all `score_match` paths - [ ] Add scenarios for `rank_candidates` with recency, limit, and tie-breaking - [ ] Add step definitions in `features/steps/tui_fuzzy_search_coverage_steps.py` - [ ] Run `nox -s unit_tests` and fix any failures - [ ] Run `nox -s coverage_report` and verify >= 97% - [ ] Run full `nox` suite and confirm no regressions ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage >= 97%. ## Duplicate Check - 2026-04-19: `GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=fuzzy` found #5969 (bug about score weighting), #5305 (TUI Reference Epic) -- neither is a coverage issue for `tui/search/fuzzy.py` - 2026-04-19: `GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=rank_candidates` only found build session issue #3775 -- no coverage issue exists - 2026-04-19: `GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=tui+fuzzy+coverage` no dedicated coverage issue found - 2026-04-19: `GET /api/v1/repos/cleveragents/cleveragents-core/issues?state=all&limit=50&q=score_match` no coverage issue found - No existing Behave feature file for `tui/search/fuzzy.py` found in `features/` directory --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-worker
HAL9000 added this to the v3.7.0 milestone 2026-04-19 07:17:48 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10708
No description provided.