# Test Case: Structured invocation exhausts all retries and returns an error.
#
# This test validates that the SI retry mechanism correctly fails after
# exceeding the maximum number of validation retries (default: 2).
#
# 1. Workflow dispatches structured invocation to TestPeerAgentA (node "validate_order")
# 2. TestPeerAgentA outputs text WITHOUT the mandatory result embed (attempt 1)
# 3. Handler detects the missing embed and sends retry feedback (retry 1)
# 4. TestPeerAgentA again outputs text WITHOUT the result embed (attempt 2)
# 5. Handler sends retry feedback again (retry 2)
# 6. TestPeerAgentA still outputs text WITHOUT the result embed (attempt 3)
# 7. Handler detects max retries exceeded (2) and returns an error
# 8. Workflow fails because the node returned an error

test_case_id: "workflow_si_max_retries_exceeded_001"
description: "Tests that structured invocation fails with error after exhausting max validation retries."
tags: ["all", "workflows", "validation"]
skip_intermediate_events: true
expected_completion_timeout_seconds: 30

test_runner_config_overrides:
  agent_config:
    artifact_scope: "namespace"

gateway_input:
  target_agent_name: "StructuredTestWorkflow"
  user_identity: "max_retry_test@example.com"
  external_context:
    a2a_session_id: "max_retry_test_session"
  parts:
    - type: "data"
      data:
        customer_name: "Alice Retry"
        order_id: "ORD-00000"
        amount: 100

llm_interactions:
  # Turn 1 (Attempt 1): TestPeerAgentA receives the structured invocation
  # but outputs plain text without the mandatory result embed.
  - static_response:
      choices:
        - message:
            role: "assistant"
            content: "I have processed the order for Alice Retry."
    expected_request:
      tools_present: ["load_artifact"]

  # Turn 2 (Retry 1): Handler sends feedback about the missing result embed.
  # Agent again outputs text without the result embed.
  - static_response:
      choices:
        - message:
            role: "assistant"
            content: "The order ORD-00000 has been validated successfully."
    expected_request:
      messages_contain:
        - role: "user"
          content_contains: "You failed to provide the mandatory result embed"

  # Turn 3 (Retry 2 — final attempt): Handler sends feedback again.
  # Agent still outputs text without the result embed.
  # After this, max_validation_retries (2) is exceeded and the handler returns an error.
  - static_response:
      choices:
        - message:
            role: "assistant"
            content: "Order ORD-00000 for Alice Retry is complete."
    expected_request:
      messages_contain:
        - role: "user"
          content_contains: "You failed to provide the mandatory result embed"

expected_gateway_output:
  - type: "final_response"
    task_state: "failed"
