*** Settings ***
Documentation     Integration tests for definition-of-done gating
Resource          common.resource
Library           Process
Library           OperatingSystem
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Test Cases ***
Parse DoD Text Into Criteria
    [Documentation]    Verify DoD text is parsed into individual criteria
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    parse    All tests pass\\nNo lint errors\\nCoverage above 90%
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dod-parse-ok: 3 criteria
    Should Contain    ${result.stdout}    All tests pass

Render DoD Template With Arguments
    [Documentation]    Verify DoD template rendering substitutes placeholders
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    render    Tests for {module} must pass    module    auth
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dod-render-ok: Tests for auth must pass

Evaluate DoD Criteria Against Context
    [Documentation]    Verify TextMatchEvaluator evaluates criteria correctly
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    evaluate    All tests pass    status    all tests pass
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dod-evaluate-ok: 1 passed, 0 failed

Build DoDSummary CLI Dict
    [Documentation]    Verify DoDSummary produces correct CLI dict output
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    summary    01PLANTEST0000000000001    test dod    2    1
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dod-summary-ok:
    Should Contain    ${result.stdout}    all_passed

Build DoDSummary Validation Summary
    [Documentation]    Verify DoDSummary produces compatible validation summary
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    validate-summary    01PLANTEST0000000000001    test dod    3    0
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dod-validate-summary-ok:
    Should Contain    ${result.stdout}    dod_evaluated

Helper Shows Usage On No Command
    [Documentation]    Verify helper prints usage when no command given
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Helper Rejects Unknown Command
    [Documentation]    Verify helper rejects an unknown sub-command
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    bogus    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Unknown command

Parse Shows Usage On No Args
    [Documentation]    Verify parse sub-command prints usage with no arguments
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    parse    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Render Shows Usage On Insufficient Args
    [Documentation]    Verify render sub-command prints usage with insufficient args
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    render    template_only    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Evaluate Shows Usage On Insufficient Args
    [Documentation]    Verify evaluate sub-command prints usage with insufficient args
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    evaluate    dod_only    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Summary Shows Usage On Insufficient Args
    [Documentation]    Verify summary sub-command prints usage with insufficient args
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    summary    plan_id_only    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Validate Summary Shows Usage On Insufficient Args
    [Documentation]    Verify validate-summary sub-command prints usage with insufficient args
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_definition_of_done.py
    ...    validate-summary    plan_id_only    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage
