*** Settings ***
Documentation     Integration tests for routing prefix stripping functionality
Library           Process
Library           OperatingSystem
Library           String
Resource    ${CURDIR}/v2_paths.resource

*** Variables ***
${DISCOVERY_CONFIG}    ${V2_CONFIG_DIR}/routing_test_discovery_response.yaml
${BRAINSTORM_CONFIG}   ${V2_CONFIG_DIR}/routing_test_goto_brainstorming.yaml
${NO_PREFIX_CONFIG}    ${V2_CONFIG_DIR}/routing_test_no_prefix.yaml
${SET_TOPIC_CONFIG}    ${V2_CONFIG_DIR}/routing_test_set_topic.yaml
${RUN_CMD}             python -m cleveragents actor run

*** Test Cases ***
Routing Prefix Stripping In Application
    [Documentation]    Test that internal routing prefixes are stripped from output
    ...    SEC1: Requires code blocks for producing prefixed output — skipped.
    [Tags]    routing    prefix    integration    code_blocks

    # Run the application with DISCOVERY_RESPONSE prefix
    ${result}=    Run Process    ${PYTHON}    -m    cleveragents    actor    run
    ...    -c    ${DISCOVERY_CONFIG}
    ...    --unsafe
    ...    --allow-rxpy-in-run-mode
    ...    test-actor    test input
    ...    stderr=STDOUT
    ...    timeout=120s    on_timeout=kill

    # Check that the output does NOT contain the prefix
    Should Not Contain    ${result.stdout}    DISCOVERY_RESPONSE:
    Should Contain    ${result.stdout}    What topic would you like to write about?

Multiple Routing Prefixes Are Stripped
    [Documentation]    Test that various routing prefixes are all stripped correctly
    ...    SEC1: Requires code blocks for producing prefixed output — skipped.
    [Tags]    routing    prefix    integration    code_blocks

    # Test GOTO_BRAINSTORMING prefix
    ${result}=    Run Process    ${PYTHON}    -m    cleveragents    actor    run
    ...    -c    ${BRAINSTORM_CONFIG}
    ...    --unsafe
    ...    --allow-rxpy-in-run-mode
    ...    test-actor    test input
    ...    stderr=STDOUT
    ...    timeout=120s    on_timeout=kill

    Should Not Contain    ${result.stdout}    GOTO_BRAINSTORMING:
    Should Contain    ${result.stdout}    Let's brainstorm ideas

Content Without Prefix Remains Unchanged
    [Documentation]    Test that content without routing prefixes is not modified
    ...    SEC1: Requires code blocks for producing static output — skipped.
    [Tags]    routing    prefix    integration    code_blocks

    ${result}=    Run Process    ${PYTHON}    -m    cleveragents    actor    run
    ...    -c    ${NO_PREFIX_CONFIG}
    ...    --unsafe
    ...    --allow-rxpy-in-run-mode
    ...    test-actor    test input
    ...    stderr=STDOUT
    ...    timeout=120s    on_timeout=kill

    Should Contain    ${result.stdout}    This is normal text without any prefix

SET Prefix Family Stripped
    [Documentation]    Test that SET_* prefixes used for state updates are stripped
    ...    SEC1: Requires code blocks for producing prefixed output — skipped.
    [Tags]    routing    prefix    integration    code_blocks

    ${result}=    Run Process    ${PYTHON}    -m    cleveragents    actor    run
    ...    -c    ${SET_TOPIC_CONFIG}
    ...    --unsafe
    ...    --allow-rxpy-in-run-mode
    ...    test-actor    test input
    ...    stderr=STDOUT
    ...    timeout=120s    on_timeout=kill

    Should Not Contain    ${result.stdout}    SET_TOPIC:
    Should Contain    ${result.stdout}    Neural networks in cognitive science
