*** Settings ***
Documentation    TDD Issue #680 — session list with missing database
...              Integration smoke tests verifying that the session list command
...              handles a missing database gracefully.  The database URL points
...              to a non-existent file; the command should auto-create the DB
...              and return an empty list rather than crashing.
...              Bug #680 is now fixed; these tests serve as regression tests.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

*** Variables ***
${HELPER}    ${CURDIR}/helper_tdd_session_list_missing_db.py

*** Test Cases ***
TDD Session List Missing DB Via CLI
    [Documentation]    Verify that ``session list`` succeeds when no database file exists
    [Tags]  tdd_issue    tdd_issue_680    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-missing-db    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-session-list-missing-db-ok

TDD Session List Missing DB JSON Output
    [Documentation]    Verify that ``session list --format json`` succeeds when no database file exists
    [Tags]  tdd_issue    tdd_issue_680    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-missing-db-json    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-session-list-missing-db-json-ok
