*** Settings ***
Documentation     CONC3 - Cleanup commands integration smoke tests
Library           OperatingSystem
Library           Collections
Library           String
Resource          ${CURDIR}/common.resource

*** Variables ***
${SRC_DIR}        ${CURDIR}/../src/cleveragents

*** Test Cases ***
Cleanup Service Module Exists
    [Documentation]    Verify cleanup service module is present
    File Should Exist    ${SRC_DIR}/application/services/cleanup_service.py

Cleanup CLI Module Exists
    [Documentation]    Verify cleanup CLI command module is present
    File Should Exist    ${SRC_DIR}/cli/commands/cleanup.py

Cleanup Service Exports Expected Symbols
    [Documentation]    Verify cleanup_service.py exports the public API
    ${content}=    Get File    ${SRC_DIR}/application/services/cleanup_service.py
    Should Contain    ${content}    class CleanupService
    Should Contain    ${content}    def scan
    Should Contain    ${content}    def purge
    # F26 fix: CleanupReport, StaleItem, ResourceCleanupSummary were
    # extracted to cleanup_models.py (F8 fix).  Verify definitions live
    # there and that cleanup_service.py re-exports them via __all__.
    Should Contain    ${content}    CleanupReport
    Should Contain    ${content}    StaleItem
    Should Contain    ${content}    ResourceCleanupSummary

Cleanup Models Defines Data Classes
    [Documentation]    Verify cleanup_models.py contains the extracted data classes
    ${models}=    Get File    ${SRC_DIR}/application/services/cleanup_models.py
    Should Contain    ${models}    class CleanupReport
    Should Contain    ${models}    class StaleItem
    Should Contain    ${models}    class ResourceCleanupSummary

Cleanup CLI Has Scan Command
    [Documentation]    Verify cleanup CLI has scan subcommand
    ${content}=    Get File    ${SRC_DIR}/cli/commands/cleanup.py
    Should Contain    ${content}    def scan
    Should Contain    ${content}    dry-run

Cleanup CLI Has Purge Command
    [Documentation]    Verify cleanup CLI has purge subcommand
    ${content}=    Get File    ${SRC_DIR}/cli/commands/cleanup.py
    Should Contain    ${content}    def purge
    Should Contain    ${content}    --all
    Should Contain    ${content}    --dry-run
    Should Contain    ${content}    --yes

Cleanup CLI Has Status Command
    [Documentation]    Verify cleanup CLI has status subcommand
    ${content}=    Get File    ${SRC_DIR}/cli/commands/cleanup.py
    Should Contain    ${content}    def status
    Should Contain    ${content}    Retention Policies

Settings Has Retention Policy Fields
    [Documentation]    Verify settings includes cleanup config fields
    ${content}=    Get File    ${SRC_DIR}/config/settings.py
    Should Contain    ${content}    cleanup_sandbox_max_age_hours
    Should Contain    ${content}    cleanup_checkpoint_max_per_plan
    Should Contain    ${content}    cleanup_session_inactivity_days
    Should Contain    ${content}    cleanup_log_retention_days
    Should Contain    ${content}    cleanup_backup_retention_days
    Should Contain    ${content}    cleanup_schedule

Main CLI Registers Cleanup Command
    [Documentation]    Verify main.py registers the cleanup command group
    ${content}=    Get File    ${SRC_DIR}/cli/main.py
    Should Contain    ${content}    cleanup
    Should Contain    ${content}    Garbage collection

Cleanup Service Does Not Use Eval Or Exec
    [Documentation]    Security check: no eval/exec in cleanup service
    ${content}=    Get File    ${SRC_DIR}/application/services/cleanup_service.py
    Should Not Contain    ${content}    eval(
    Should Not Contain    ${content}    exec(
