*** Settings ***
Documentation    E2E workflow tests for context configuration and plan execution
...
...    Tests the context management workflow including:
...    - Context listing and status
...    - Context show operations
...    - Output format validation against specification
...
...    These tests run against the real CLI without mocking.
Resource         common_e2e.resource
Suite Setup      E2E Suite Setup
Suite Teardown   E2E Suite Teardown

*** Test Cases ***
Context List Command Succeeds
    [Documentation]    Verify context list command succeeds
    ...
    ...    This test validates that:
    ...    - Context list command executes without error
    ...    - Output is produced
    [Tags]    E2E    Context    Workflow
    ${result}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${result.rc}    0

Context Show Command Succeeds
    [Documentation]    Verify context show command succeeds
    ...
    ...    This test validates that:
    ...    - Context show command executes without error
    ...    - Output is produced
    [Tags]    E2E    Context    Loading
    ${result}=    Run CleverAgents Command    context    show
    Should Be Equal As Integers    ${result.rc}    0

Context List Produces Output
    [Documentation]    Verify context list produces output
    ...
    ...    This test validates that:
    ...    - Context list produces output
    ...    - Output is not empty
    [Tags]    E2E    Context    Tiers
    ${result}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Be Empty    ${result.stdout}

Plan List After Context Operations
    [Documentation]    Verify plan list works after context operations
    ...
    ...    This test validates that:
    ...    - Plan list succeeds after context operations
    ...    - Output format is correct
    [Tags]    E2E    Context    ACMS
    ${result}=    Run CleverAgents Command    plan    list    --format    json
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Be Empty    ${result.stdout}

Context List Multiple Times
    [Documentation]    Verify context list can be called multiple times
    ...
    ...    This test validates that:
    ...    - Context list is idempotent
    ...    - Multiple calls produce consistent results
    [Tags]    E2E    Context    Strategy
    ${result1}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${result1.rc}    0
    ${result2}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${result2.rc}    0

Session And Context Integration
    [Documentation]    Verify session and context commands work together
    ...
    ...    This test validates that:
    ...    - Session creation succeeds
    ...    - Context list succeeds in same workspace
    ...    - Both commands use the same workspace state
    [Tags]    E2E    Context    Constraints
    ${session_result}=    Run CleverAgents Command    session    create    --format    json
    Should Be Equal As Integers    ${session_result.rc}    0
    ${context_result}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${context_result.rc}    0

Context List Before And After Session Create
    [Documentation]    Verify context list works before and after session creation
    ...
    ...    This test validates that:
    ...    - Context list works before session creation
    ...    - Context list works after session creation
    ...    - Context state is consistent
    [Tags]    E2E    Context    Export
    ${before}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${before.rc}    0
    Run CleverAgents Command    session    create    --format    plain
    ${after}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${after.rc}    0

Context And Plan List Integration
    [Documentation]    Verify context and plan list commands work together
    ...
    ...    This test validates that:
    ...    - Context list and plan list both succeed
    ...    - Both commands use the same workspace state
    [Tags]    E2E    Context    Multi
    ${context_result}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${context_result.rc}    0
    ${plan_result}=    Run CleverAgents Command    plan    list    --format    json
    Should Be Equal As Integers    ${plan_result.rc}    0

Context Show After Session Create
    [Documentation]    Verify context show works after session creation
    ...
    ...    This test validates that:
    ...    - Context show works after session creation
    ...    - Context state is accessible
    [Tags]    E2E    Context    Validation
    Run CleverAgents Command    session    create    --format    plain
    ${result}=    Run CleverAgents Command    context    show
    Should Be Equal As Integers    ${result.rc}    0

Context And Session Lifecycle
    [Documentation]    Verify context and session lifecycle commands work together
    ...
    ...    This test validates that:
    ...    - Session creation and context list work in sequence
    ...    - Session deletion and context list work in sequence
    [Tags]    E2E    Context    Lifecycle
    ${create_result}=    Run CleverAgents Command    session    create    --format    json
    Should Be Equal As Integers    ${create_result.rc}    0
    ${context_result}=    Run CleverAgents Command    context    list
    Should Be Equal As Integers    ${context_result.rc}    0
    ${session_id}=    Safe Parse Json Field    ${create_result.stdout}    session_id
    Should Not Be Empty    ${session_id}
    ${delete_result}=    Run CleverAgents Command    session    delete    ${session_id}    --yes
    Should Be Equal As Integers    ${delete_result.rc}    0

*** Keywords ***
Output Should Contain
    [Documentation]    Verify output contains expected text
    [Arguments]    ${result}    ${expected_text}
    Should Contain    ${result.stdout}    ${expected_text}
