*** Settings ***
Documentation     Integration tests for plan diff --correction command.
...               Verifies that correction_diff() on PlanApplyService produces
...               the three-section structured output (Correction Diff summary,
...               Comparison, Patch Preview) defined in the specification.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Correction Diff Rich Format
    [Documentation]    Verify correction_diff() generates rich-format three-section output
    [Tags]    correction    plan    diff    rich
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-diff-rich    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-diff-rich-ok

Correction Diff Plain Format
    [Documentation]    Verify correction_diff() generates plain-format three-section output
    [Tags]    correction    plan    diff    plain
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-diff-plain    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-diff-plain-ok

Correction Diff JSON Format
    [Documentation]    Verify correction_diff() generates JSON output with all three sections
    [Tags]    correction    plan    diff    json
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-diff-json    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-diff-json-ok

Correction Diff YAML Format
    [Documentation]    Verify correction_diff() generates YAML output with all three sections
    [Tags]    correction    plan    diff    yaml
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-diff-yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-diff-yaml-ok

Correction Diff Raises When Correction Not Found
    [Documentation]    Verify correction_diff() raises PlanError on missing correction attempt
    [Tags]    correction    plan    diff    error
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-not-found    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-not-found-ok

Correction Diff Raises When Unit Of Work Is None
    [Documentation]    Verify correction_diff() raises ValidationError when unit_of_work is None
    [Tags]    correction    plan    diff    error    validation
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    correction-diff-uow-none    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-diff-uow-none-ok
