MCPcopy Create free account
hub / github.com/FastLED/FastLED / smart_select

Function smart_select

ci/util/smart_selector.py:397–550  ·  view source on GitHub ↗

Smart selector for unit tests and examples with fuzzy matching. Returns either: - A single TestMatch if there's a clear best match - A list of TestMatch objects if disambiguation is needed Args: query: Search query (e.g., "Animartrix", "string", "async", "tests/fl/async")

(
    query: str, project_dir: Optional[Path] = None, filter_type: Optional[str] = None
)

Source from the content-addressed store, hash-verified

395
396
397def smart_select(
398 query: str, project_dir: Optional[Path] = None, filter_type: Optional[str] = None
399) -> "TestMatch | list[TestMatch]":
400 """Smart selector for unit tests and examples with fuzzy matching.
401
402 Returns either:
403 - A single TestMatch if there's a clear best match
404 - A list of TestMatch objects if disambiguation is needed
405
406 Args:
407 query: Search query (e.g., "Animartrix", "string", "async", "tests/fl/async")
408 project_dir: Project root directory (defaults to current directory)
409 filter_type: Optional type filter ("unit_test" or "example")
410
411 Returns:
412 Single TestMatch for auto-selection, or list of TestMatch for disambiguation
413 """
414 if project_dir is None:
415 project_dir = Path.cwd()
416
417 # Handle explicit .hpp file queries (e.g., "tests/fl/audio/detectors/backbeat.hpp")
418 # Extract the .hpp filename for later filtering
419 hpp_filter = None
420 if query.endswith(".hpp"):
421 # Extract just the filename (e.g., "backbeat.hpp")
422 hpp_filter = query.split("/")[-1]
423 # For explicit .hpp file queries, find the aggregator that includes it
424 # and return it with the hpp_filter set
425 unit_tests = _find_unit_tests(project_dir)
426 examples = _find_examples(project_dir)
427 all_matches = unit_tests + examples
428
429 # Search for aggregators that include this .hpp file
430 # Search using the exact filename to avoid false matches (e.g., "beat.hpp" not "beat")
431 aggregator_matches = _find_aggregator_matches(
432 hpp_filter, all_matches, project_dir
433 )
434 if aggregator_matches:
435 # Return the first aggregator match with hpp_filter set
436 best_match = aggregator_matches[0]
437 best_match.hpp_filter = hpp_filter
438 return best_match
439
440 # Find all available tests and examples
441 unit_tests = _find_unit_tests(project_dir)
442 examples = _find_examples(project_dir)
443
444 # Combine all matches (optionally filter by type)
445 all_matches = unit_tests + examples
446 if filter_type:
447 all_matches = [m for m in all_matches if m.type == filter_type]
448
449 # Calculate scores for all matches using both name and path
450 scored_matches: list[TestMatch] = []
451 # Minimum score threshold to avoid showing irrelevant results
452 # Short queries (e.g., "gif") can get very low character-sequence
453 # matches against unrelated tests — filter those out.
454 min_score_threshold = 0.3

Callers 1

get_best_match_or_promptFunction · 0.85

Calls 8

_find_unit_testsFunction · 0.85
_find_examplesFunction · 0.85
_find_aggregator_matchesFunction · 0.85
_score_matchFunction · 0.85
_apply_hpp_filterFunction · 0.85
sortMethod · 0.80
absFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected