*** Settings ***
Documentation    AutoDebugAgent prompt injection mitigation — integration smoke tests
Library          OperatingSystem
Library          Process
Resource         ${CURDIR}/common.resource

Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

*** Variables ***
${HELPER_SCRIPT}    robot/helper_auto_debug_agent_prompt_injection.py
${SRC_DIR}          ${CURDIR}/../src

*** Test Cases ***
AutoDebugAgent Wraps Error Message With Boundary Markers
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-error-boundary-markers
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS

AutoDebugAgent Wraps Code Context With Boundary Markers
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-code-context-boundary-markers
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS

AutoDebugAgent Handles Injection In Error Message Gracefully
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-injection-in-error-graceful
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS

AutoDebugAgent Handles Injection In Code Context Gracefully
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-injection-in-code-graceful
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS

AutoDebugAgent System Prompt Includes Boundary Instruction
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-system-prompt-boundary-instruction
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS

AutoDebugAgent Does Not Sanitize Internal LLM Output
    [Tags]    security  prompt-injection  auto-debug-agent
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    test-internal-output-not-sanitized
    ...    cwd=${WORKSPACE}    env:PYTHONPATH=${SRC_DIR}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    PASS
