*** Settings ***
Documentation    End-to-end output rendering framework verification
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Plain Format Renders Panel Without ANSI Codes
    [Documentation]    Verify plain format produces ASCII-only panel output
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plain-panel    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}    output-rendering-plain-panel-ok

JSON Format Produces Valid JSON With Elements
    [Documentation]    Verify JSON format serialises elements as valid JSON
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    json-output    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}    output-rendering-json-output-ok

YAML Format Produces Valid YAML With Elements
    [Documentation]    Verify YAML format serialises elements as valid YAML
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    yaml-output    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}    output-rendering-yaml-output-ok

Table Format Renders Box Drawing Characters
    [Documentation]    Verify table format uses Unicode box-drawing for tables (P2-5)
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    table-boxdraw    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}    output-rendering-table-boxdraw-ok

Color Format Includes ANSI Codes
    [Documentation]    Verify color format includes ANSI escape codes
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    color-ansi    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}    output-rendering-color-ansi-ok

Error Envelope In JSON Mode
    [Documentation]    Verify error envelope structure in JSON mode
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    json-error    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}    output-rendering-json-error-ok

Format Output Backward Compatibility
    [Documentation]    Verify format_output still works for all formats
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    backward-compat    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}    output-rendering-backward-compat-ok

Materializer Selection Fallback
    [Documentation]    Verify materializer selection with fallback logic
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    selection-fallback    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}    output-rendering-selection-fallback-ok

Tree Element Renders Across Formats
    [Documentation]    Verify tree element renders in plain and JSON formats
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    tree    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}    output-rendering-tree-ok

Code Element Renders With Line Numbers
    [Documentation]    Verify code block renders with line numbers in plain format
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    code    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}    output-rendering-code-ok

Diff Element Renders Unified Diff
    [Documentation]    Verify diff block renders unified diff format
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    diff    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}    output-rendering-diff-ok

Text Separator And Action Hint Render
    [Documentation]    Verify text, separator, and action hint elements render
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    text-sep-hint    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}    output-rendering-text-sep-hint-ok

JSON Serializes All Element Types
    [Documentation]    Verify JSON format serializes all element types (progress omitted per spec §26936)
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    json-all    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}    output-rendering-json-all-ok

YAML Serializes All Element Types
    [Documentation]    Verify YAML format serializes all element types (progress omitted per spec §26936)
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    yaml-all    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}    output-rendering-yaml-all-ok
