*** Settings ***
Documentation    Integration tests for decision persistence via serialization round-trips
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Root Decision Round-Trip
    [Documentation]    Root prompt_definition decision survives model_dump round-trip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    roundtrip_root    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-roundtrip-root-ok

Child Decision Round-Trip
    [Documentation]    Child strategy_choice with all fields survives model_dump round-trip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    roundtrip_child    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-roundtrip-child-ok

Context Snapshot Persistence
    [Documentation]    Context snapshot with resources survives round-trip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    snapshot    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-snapshot-ok

JSON Serialization Round-Trip
    [Documentation]    Decision survives JSON serialization round-trip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    json_roundtrip    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-json-roundtrip-ok

Correction Chain Persistence
    [Documentation]    Correction chain of 3 decisions persists and reconstructs
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction_chain    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-correction-chain-ok

Decision Tree Reconstruction
    [Documentation]    3-level tree of 7 nodes reconstructs from serialized data
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    tree_reconstruction    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-tree-reconstruction-ok

All Decision Types Round-Trip
    [Documentation]    All decision types survive model_dump round-trip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    all_types    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-persist-all-types-ok
