*** Settings ***
Documentation    TDD Issue #1024 — SQLite DB URL resolves to CWD instead of CLEVERAGENTS_HOME
...              Integration tests verifying that the database URL resolves
...              inside CLEVERAGENTS_HOME rather than the current working
...              directory.  The default ``database_url`` in Settings is
...              ``sqlite:///cleveragents.db`` — a relative path that resolves
...              against CWD, breaking test isolation when CLEVERAGENTS_HOME
...              points to a different directory.
...
...              Bug: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/1024
...              TDD: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/1034
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD SQLite DB URL Resolves Inside CLEVERAGENTS_HOME
    [Documentation]    Verify that ``get_database_url()`` resolves the database
    ...                path inside CLEVERAGENTS_HOME when no explicit database URL
    ...                is provided via environment variable.

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-db-url-resolution    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-sqlite-url-cwd-resolution-ok

TDD CLI Command Creates DB Inside CLEVERAGENTS_HOME
    [Documentation]    Verify that a CLI command (session list) creates the
    ...                database file inside CLEVERAGENTS_HOME, not in CWD.

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-cli-db-location    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-sqlite-url-cwd-cli-ok
