*** Settings ***
Documentation     Smoke tests for correction attempt persistence via CorrectionAttemptRepository
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER_SCRIPT}    robot/helper_correction_attempt_persistence.py

*** Test Cases ***
Create And Retrieve Correction Attempt
    [Documentation]    Create a revert correction attempt, persist, retrieve
    [Tags]    database    correction    persistence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    create-retrieve    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    create-retrieve-ok

List Correction Attempts By Plan
    [Documentation]    Create multiple correction attempts and list by plan
    [Tags]    database    correction    query    persistence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    list-by-plan    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    list-by-plan-ok

Update Correction Attempt State
    [Documentation]    Update state from pending to executing to complete
    [Tags]    database    correction    state    persistence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    update-state    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    update-state-ok

Delete Correction Attempt
    [Documentation]    Delete a correction attempt and verify it is gone
    [Tags]    database    correction    persistence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    delete    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    delete-ok

Domain Model Round-Trip
    [Documentation]    Verify all spec DDL columns survive domain-model round-trip
    [Tags]    database    correction    persistence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    domain-roundtrip    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    domain-roundtrip-ok
