*** Settings ***
Documentation    M6 autonomy acceptance E2E smoke tests — A2A facade, guardrails, audit
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
M6 A2A Facade Session Lifecycle
    [Documentation]    Dispatch session.create and session.close via local facade
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    facade-session    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}    m6-facade-session-ok

M6 A2A Facade Plan Lifecycle
    [Documentation]    Dispatch plan create/execute/status/diff/apply operations
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    facade-plan    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}    m6-facade-plan-ok

M6 A2A Facade Unknown Operation Error
    [Documentation]    Verify unknown operations raise A2aOperationNotFoundError
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    facade-unknown-op    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}    m6-facade-unknown-op-ok

M6 A2A Event Queue Publish Subscribe
    [Documentation]    Publish events and verify local subscriber receives them
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    event-queue    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}    m6-event-queue-ok

M6 A2A Transport Stub Rejects All
    [Documentation]    Verify HTTP transport stub raises A2aNotAvailableError
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    transport-stub    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}    m6-transport-stub-ok

M6 A2A Version Negotiation
    [Documentation]    Negotiate supported and unsupported A2A versions
    [Tags]    tdd_issue    tdd_issue_4249    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    version-negotiation    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}    m6-version-negotiation-ok

M6 Guard Denylist Enforcement
    [Documentation]    Verify denylist guard blocks denied tools
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    guard-denylist    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}    m6-guard-denylist-ok

M6 Guard Budget Enforcement
    [Documentation]    Verify cost budget and call limit guards work
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    guard-budget    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}    m6-guard-budget-ok

M6 Profile Resolution Precedence
    [Documentation]    Verify plan > action > project > global resolution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    profile-resolution    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}    m6-profile-resolution-ok

M6 Fixture Loading
    [Documentation]    Load all M6 fixture files and verify structure
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fixture-loading    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}    m6-fixture-loading-ok

M6 Full Autonomy Acceptance Flow
    [Documentation]    End-to-end: facade dispatch + guard check + profile resolution
    [Tags]    tdd_issue    tdd_issue_4310    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-flow    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}    m6-full-flow-ok
