@phase2 @a2a @agent_card
Feature: A2A Agent Card Discovery
  As an A2A-compatible client
  I want to discover the agent's capabilities via an Agent Card
  So that I can determine which operations the CleverAgents server supports

  # -----------------------------------------------------------------------
  # Agent Card model construction
  # -----------------------------------------------------------------------

  Scenario: Build an Agent Card with a facade
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card name should be "CleverAgents"
    And the agent card version should be "1.0"
    And the agent card should have a non-empty url
    And the agent card should have at least 1 skill
    And the agent card should have at least 1 extension

  Scenario: Build an Agent Card without a facade
    When I build an agent card without a facade
    Then the agent card name should be "CleverAgents"
    And the agent card version should be "1.0"
    And the agent card should have 0 skills

  Scenario: Agent Card includes supported versions
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card supported versions should contain "1.0"

  Scenario: Agent Card includes supported operations
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card should list extension operations

  Scenario: Agent Card includes security schemes
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card should have at least 1 security scheme

  Scenario: Agent Card includes protocol interfaces
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card should have at least 1 interface
    And the first interface protocol should be "jsonrpc"

  Scenario: Agent Card includes default input and output modes
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card default input modes should contain "text"
    And the agent card default output modes should contain "text"

  Scenario: Agent Card capabilities reflect current state
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card streaming capability should be false
    And the agent card push notifications capability should be false

  # -----------------------------------------------------------------------
  # Agent Card validation
  # -----------------------------------------------------------------------

  Scenario: Build rejects invalid host
    When I try to build an agent card with an empty host
    Then a ValueError should be raised for agent card

  Scenario: Build rejects invalid port zero
    When I try to build an agent card with port 0
    Then a ValueError should be raised for agent card

  Scenario: Build rejects port above 65535
    When I try to build an agent card with port 70000
    Then a ValueError should be raised for agent card

  # -----------------------------------------------------------------------
  # Agent Card model validation
  # -----------------------------------------------------------------------

  Scenario: AgentCard rejects empty name
    When I try to create an AgentCard with empty name
    Then a validation error should be raised for agent card

  Scenario: AgentCard rejects empty version
    When I try to create an AgentCard with empty version
    Then a validation error should be raised for agent card

  Scenario: AgentCardSkill rejects empty id
    When I try to create an AgentCardSkill with empty id
    Then a validation error should be raised for agent card

  Scenario: AgentCardSkill rejects empty name
    When I try to create an AgentCardSkill with empty skill name
    Then a validation error should be raised for agent card

  Scenario: AgentCardExtension rejects empty uri
    When I try to create an AgentCardExtension with empty uri
    Then a validation error should be raised for agent card

  Scenario: AgentCardSecurityScheme rejects empty type
    When I try to create an AgentCardSecurityScheme with empty type
    Then a validation error should be raised for agent card

  Scenario: AgentCardInterface rejects empty protocol
    When I try to create an AgentCardInterface with empty protocol
    Then a validation error should be raised for agent card

  # -----------------------------------------------------------------------
  # A2A conformance validation
  # -----------------------------------------------------------------------

  Scenario: Valid Agent Card passes conformance validation
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    And I validate the agent card conformance
    Then the conformance violations should be empty

  Scenario: Agent Card with empty url fails conformance
    Given an agent card with empty url
    When I validate the agent card conformance
    Then the conformance violations should include "url is required"

  Scenario: Agent Card with unsupported version fails conformance
    Given an agent card with version "99.0"
    When I validate the agent card conformance
    Then the conformance violations should include "not in supported versions"

  Scenario: Agent Card with empty supportedVersions fails conformance
    Given an agent card with empty supported versions
    When I validate the agent card conformance
    Then the conformance violations should include "supportedVersions must not be empty"

  Scenario: Conformance validation rejects non-AgentCard argument
    When I try to validate conformance of a non-AgentCard object
    Then a TypeError should be raised for conformance validation

  # -----------------------------------------------------------------------
  # Serialization
  # -----------------------------------------------------------------------

  Scenario: Agent Card serializes to dict
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    And I serialize the agent card to dict
    Then the serialized dict should have key "name"
    And the serialized dict should have key "version"
    And the serialized dict should have key "capabilities"
    And the serialized dict should have key "skills"
    And the serialized dict should have key "supportedVersions"
    And the serialized dict should have key "supportedOperations"

  Scenario: agent_card_to_dict rejects non-AgentCard argument
    When I try to serialize a non-AgentCard object
    Then a TypeError should be raised for serialization

  # -----------------------------------------------------------------------
  # Discovery endpoint (ASGI)
  # -----------------------------------------------------------------------

  Scenario: Discovery endpoint returns Agent Card with skills
    Given a running ASGI test client with facade
    When I request GET /.well-known/agent.json
    Then the response status code should be 200
    And the response body should contain "CleverAgents"
    And the response body should contain "skills"
    And the response body should contain "supportedVersions"
    And the response body should contain "supportedOperations"

  Scenario: Discovery endpoint Agent Card has correct structure
    Given a running ASGI test client with facade
    When I request GET /.well-known/agent.json and parse JSON
    Then the agent card JSON should have key "name" with value "CleverAgents"
    And the agent card JSON should have key "version" with value "1.0"
    And the agent card JSON "capabilities" should be a dict
    And the agent card JSON "skills" should be a non-empty list
    And the agent card JSON "supportedVersions" should be a non-empty list

  Scenario: Discovery endpoint Agent Card lists extension operations
    Given a running ASGI test client with facade
    When I request GET /.well-known/agent.json and parse JSON
    Then the agent card JSON "supportedOperations" should be a non-empty list
    And all supported operations should start with "_cleveragents/"

  # -----------------------------------------------------------------------
  # Skill enumeration from facade
  # -----------------------------------------------------------------------

  Scenario: Agent Card enumerates plan lifecycle skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "plan-lifecycle"

  Scenario: Agent Card enumerates registry skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "registry-crud"

  Scenario: Agent Card enumerates context skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "context-mgmt"

  Scenario: Agent Card enumerates health skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "health-diagnostics"

  # -----------------------------------------------------------------------
  # Additional conformance edge cases
  # -----------------------------------------------------------------------

  Scenario: Agent Card with empty defaultInputModes fails conformance
    Given an agent card with empty default input modes
    When I validate the agent card conformance
    Then the conformance violations should include "defaultInputModes must not be empty"

  Scenario: Agent Card with empty defaultOutputModes fails conformance
    Given an agent card with empty default output modes
    When I validate the agent card conformance
    Then the conformance violations should include "defaultOutputModes must not be empty"

  Scenario: Agent Card enumerates entity sync skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "entity-sync"

  Scenario: Agent Card enumerates namespace management skill
    Given an A2aLocalFacade for agent card testing
    When I build an agent card from the facade
    Then the agent card skills should include id "namespace-mgmt"
