*** Settings ***
Documentation    Integration test for Workflow Example 2: automated test generation
...              for a module using the trusted automation profile.
...
...              Validates trusted-profile lifecycle behavior, mocked LLM-based
...              deterministic test generation, coverage validation enforcement,
...              and invariant-safe artifacts (test-only file changes).
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment With Database Isolation
Suite Teardown   Cleanup Test Environment
Force Tags       wf02    integration    trusted    workflow2    test-generation

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

*** Test Cases ***
WF02 Trusted Profile Auto Runs Strategize And Execute
    [Documentation]    Verify trusted profile auto-runs strategize and execute
    ...                while not auto-applying (human approval gate retained).
    [Tags]    tdd_issue    tdd_issue_4296    lifecycle    automation-profile    trusted
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    trusted-lifecycle    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}    wf02-trusted-lifecycle-ok

WF02 Mocked Generation Produces Test Artifacts Only
    [Documentation]    Verify mocked LLM responses generate deterministic test
    ...                files, assert user-facing plan artifacts command path,
    ...                and artifacts list only test paths (no prod edits).
    [Tags]    tdd_issue    tdd_issue_4296    mocking    artifacts    invariants
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    mocked-generation-artifacts    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}    wf02-mocked-generation-artifacts-ok

WF02 Coverage Validation Enforced For Target Threshold
    [Documentation]    Verify required coverage validation blocks below-threshold
    ...                runs and passes after deterministic generated tests.
    [Tags]    tdd_issue    tdd_issue_4296    validation    coverage
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    coverage-validation    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}    wf02-coverage-validation-ok

WF02 Path Safety Guardrails Reject Unsafe Destinations
    [Documentation]    Verify generated-file path guardrails reject absolute,
    ...                traversal, and non-tests destinations.
    [Tags]    tdd_issue    tdd_issue_4296    guardrails    path-safety
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    path-safety-guardrails    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}    wf02-path-safety-guardrails-ok
