*** Settings ***
Documentation    Smoke tests for builtin/plan-subplan actor tool
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Serial Subplan Spawn
    [Documentation]    Emit a SUBPLAN_SPAWN decision for a serial subplan
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    serial    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    serial-spawn-ok

Parallel Subplan Spawn
    [Documentation]    Emit a SUBPLAN_PARALLEL_SPAWN decision for a parallel subplan
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    parallel    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-ok

Validation Error Without Scope
    [Documentation]    Tool returns error when no resource_scopes or project_ref provided
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    validation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    validation-error-ok

Default Values Applied
    [Documentation]    merge_strategy, max_parallel, and dependencies use sensible defaults
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    defaults    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    defaults-ok

Decision Service Injection
    [Documentation]    Injected DecisionService receives the emitted Decision object
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    service    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    service-injection-ok

Tool Registration In Registry
    [Documentation]    register_subplan_tool adds builtin/plan-subplan to ToolRegistry
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    registration    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    registration-ok

ToolRunner Execution
    [Documentation]    ToolRunner executes builtin/plan-subplan and returns success
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    runner    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runner-execution-ok

Rationale Text Contains Goal
    [Documentation]    Rationale text includes goal and execution mode
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    rationale    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    rationale-ok

SubplanPayload Model Direct Validation
    [Documentation]    SubplanPayload can be constructed directly for testing
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    payload    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    payload-model-ok
