*** Settings ***
Documentation    Integration tests for entity sync (_cleveragents/sync/*)
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Sync Pull Via Facade
    [Documentation]    Verify sync/pull works through A2A facade with SyncService
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-pull    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-pull-ok

Sync Push Via Facade
    [Documentation]    Verify sync/push works through A2A facade with SyncService
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-push    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-push-ok

Sync Status Via Facade
    [Documentation]    Verify sync/status detects drift through A2A facade
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-status    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-status-ok

Sync Conflict Resolution
    [Documentation]    Verify conflict detection and resolution with vector clocks
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-conflict-resolution    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-conflict-resolution-ok

Sync Offline Queue
    [Documentation]    Verify offline queue enqueue and processing
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-offline-queue    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-offline-queue-ok

Sync Vector Clock Operations
    [Documentation]    Verify vector clock increment, merge, happens-before, concurrent
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-vector-clock    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-vector-clock-ok

Sync Facade Without Service Returns Stubs
    [Documentation]    Verify sync operations return stubs when no SyncService is registered
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-facade-no-service    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-facade-no-service-ok

Sync Incremental Pull
    [Documentation]    Verify incremental sync only pulls entities updated after since timestamp
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sync-incremental    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sync-incremental-ok
*** Keywords ***
