*** Settings ***
Library    Process
Library    String

*** Test Cases ***
TUI Search Fuzzy Matcher Initialization
    [Tags]    tdd_issue    tdd_issue_1928
    ${script}=    Catenate    SEPARATOR=\n
    ...    from cleveragents.tui.search.fuzzy import rank_candidates, FuzzyCandidate
    ...    assert callable(rank_candidates), "rank_candidates should be callable"
    ...    assert callable(FuzzyCandidate), "FuzzyCandidate should be a callable class"
    ...    print("fuzzy-matcher-ok")
    ${result}=    Run Process    ${PYTHON}    -c    ${script}    shell=False
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuzzy-matcher-ok

TUI Search Fuzzy Matching Functionality
    [Tags]    tdd_issue    tdd_issue_1928
    ${script}=    Catenate    SEPARATOR=\n
    ...    from cleveragents.tui.search.fuzzy import rank_candidates
    ...    items = ["hello", "world", "help"]
    ...    results = rank_candidates("hel", items)
    ...    assert results is not None, "rank_candidates should return results"
    ...    assert len(results) > 0, "rank_candidates should match at least one item"
    ...    assert results[0].value in ("hello", "help"), f"Top match should be hello or help, got {results[0].value}"
    ...    print("fuzzy-matching-ok")
    ${result}=    Run Process    ${PYTHON}    -c    ${script}    shell=False
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuzzy-matching-ok
