*** Settings ***
Documentation     Integration tests for the full A2A session and plan lifecycle.
...               Covers: session create/list/show/close/delete, plan create/execute/
...               status/cancel, event queue publish/subscribe, guard enforcement
...               (budget cap, tool call limit, denylist), and plan rollback with
...               session state consistency.
...
...               All tests use real service instances (no mocks) wired via the
...               full DI-compatible fixture in helper_a2a_session_plan_lifecycle_integration.py.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
A2A Full Session Lifecycle Create List Show Close Delete
    [Documentation]    Verify full session lifecycle: create via A2A facade,
    ...                list via session service, show (get) by ID, close via
    ...                facade (which deletes), and verify deletion.
    [Tags]    a2a    session    lifecycle    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    session-full-lifecycle
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    session-full-lifecycle-ok

A2A Full Plan Lifecycle Create Execute Status Cancel
    [Documentation]    Verify full plan lifecycle within a session: create plan via
    ...                A2A facade, get status, advance through strategize, execute,
    ...                verify execute phase, cancel, and verify cancellation.
    [Tags]    a2a    plan    lifecycle    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-full-lifecycle
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-full-lifecycle-ok

A2A Event Queue Receives Published Events During Lifecycle
    [Documentation]    Verify that the A2A event queue receives published events
    ...                during plan lifecycle transitions, subscriber callbacks are
    ...                invoked, and unsubscribe stops delivery.
    [Tags]    a2a    events    queue    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    event-queue-receives-events
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    event-queue-receives-events-ok

A2A Guard Enforcement Budget Cap Exceeded Halts Execution
    [Documentation]    Verify that the autonomy guardrail service blocks plan
    ...                execution when the budget cap is exceeded, records the
    ...                denial in the audit trail, and maintains consistent state.
    [Tags]    a2a    guard    budget    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    guard-budget-cap
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    guard-budget-cap-ok

A2A Guard Enforcement Tool Call Limit Exceeded Halts Execution
    [Documentation]    Verify that the autonomy guardrail service blocks plan
    ...                execution when the per-actor tool call limit is exceeded,
    ...                and records the denial in the audit trail.
    [Tags]    a2a    guard    tool_limit    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    guard-tool-call-limit
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    guard-tool-call-limit-ok

A2A Guard Enforcement Denylist Violation Blocks Tool Invocation
    [Documentation]    Verify that the automation profile denylist blocks tool
    ...                invocations for denied tools and allows permitted tools,
    ...                both via direct profile check and via AutomationProfileService.
    [Tags]    a2a    guard    denylist    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    guard-denylist
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    guard-denylist-ok

A2A Plan Rollback After Failed Execution Session State Consistent
    [Documentation]    Verify that after a plan execution failure, the plan is in
    ...                ERRORED state, the session remains accessible and consistent,
    ...                and the plan list is not corrupted. Session can be deleted
    ...                cleanly after the failure.
    [Tags]    a2a    plan    rollback    session    integration    issue_10032
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-rollback-session-consistent
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-rollback-session-consistent-ok
