test_case_id: "builtin_load_artifact_invalid_version_error_001"
description: |
  Tests the 'load_artifact' tool's error handling when an invalid
  (e.g., negative) version number is specified.
tags: ["all","agent","tools","builtin_artifact_tools"]
skip_intermediate_events: true

setup_artifacts:
  - filename: "doc_for_invalid_version.txt"
    content: "Some content."
    mime_type: "text/plain"
    metadata:
      description: "Document for invalid version test"
      mime_type: "text/plain"
      size_bytes: 13

gateway_input:
  target_agent_name: "TestAgent"
  user_identity: "declarative_load_invalid_version_tester@example.com"
  a2a_parts:
    - type: "text"
      text: "Please try to load version -1 of 'doc_for_invalid_version.txt'."
  external_context:
    a2a_session_id: "session_load_invalid_version_artifact_001"

llm_interactions:
  # Step 1: LLM calls load_artifact with a negative version
  - step_id: "llm_calls_load_invalid_version"
    static_response:
      id: "chatcmpl-load-invalid-version-1"
      object: "chat.completion"
      model: "test-llm-model"
      choices:
        - message:
            role: "assistant"
            tool_calls:
              - id: "tool_call_load_invalid_version"
                type: "function"
                function:
                  name: "load_artifact"
                  arguments: '{"filename": "doc_for_invalid_version.txt", "version": -1}'
          finish_reason: "tool_calls"

  # Step 2: LLM receives tool error result and formulates final response
  - step_id: "llm_final_response_after_load_invalid_version"
    expected_request: # After load_artifact tool call
      expected_tool_responses_in_llm_messages:
        - tool_call_id_matches_prior_request_index: 0
          response_json_matches:
            status: "error"
            message: "Version number must be a positive integer. Got: -1"
    static_response:
      id: "chatcmpl-load-invalid-version-2"
      object: "chat.completion"
      model: "test-llm-model"
      choices:
        - message:
            role: "assistant"
            content: "I couldn't load version -1 of 'doc_for_invalid_version.txt' as the version number is invalid."
          finish_reason: "stop"

expected_gateway_output:
  - type: "final_response"
    kind: "task"
    id: "*"
    contextId: "session_load_invalid_version_artifact_001"
    status:
      state: "completed"
      message:
        kind: "message"
        messageId: "*"
        role: "agent"
        parts:
          - kind: "text"
            text_exact: "I couldn't load version -1 of 'doc_for_invalid_version.txt' as the version number is invalid."
