*** Settings ***
Documentation    Integration tests verifying that ``agents actor add`` routes through
...              ActorRegistry.upsert_actor() with yaml_text threaded through, preserving
...              the original YAML text in the database while honouring all CLI flags.
Library    OperatingSystem
Library    Collections
Library    Process

*** Variables ***
${PYTHON}              python
${HELPER}    ${CURDIR}/helper_actor_add_yaml_first_path.py

*** Test Cases ***
Actor Add Preserves yaml_text Via Registry upsert_actor
    [Documentation]    Verify that ``actor add`` calls ActorRegistry.upsert_actor() with
    ...                yaml_text so the original YAML text is preserved in the database.
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    yaml_text_preserved
    ...    stdout=PIPE    stderr=PIPE
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    yaml-text-preserved-ok

Actor Add With set-default Flag Passes set_default=True To Registry
    [Documentation]    Verify that ``actor add --set-default`` passes set_default=True
    ...                to ActorRegistry.upsert_actor() so the actor is set as default.
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    set_default_flag
    ...    stdout=PIPE    stderr=PIPE
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    set-default-flag-ok

Actor Add With option Flag Passes option_overrides To Registry
    [Documentation]    Verify that ``actor add --option key=value`` passes option_overrides
    ...                to ActorRegistry.upsert_actor() so the override is applied.
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    option_override_flag
    ...    stdout=PIPE    stderr=PIPE
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    option-override-flag-ok

Actor Add With Update Flag Calls Registry upsert_actor
    [Documentation]    Verify that ``actor add --update`` calls registry.upsert_actor()
    ...                (upsert semantics handle the update case).
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    update_flag
    ...    stdout=PIPE    stderr=PIPE
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    update-flag-ok
