Feature: Tool and Validation CLI coverage
  As a developer
  I want full coverage of tool and validation CLI commands
  So that all code paths are tested

  Background:
    Given a tool CLI coverage runner with mocks

  # Coverage: Tool with as_cli_dict method (domain model)
  Scenario: Show tool that has as_cli_dict method
    Given a tool with as_cli_dict method exists
    When I run tool show for "local/domain-tool"
    Then the tool show output should succeed

  Scenario: Show tool with lifecycle hooks
    Given a tool with lifecycle hooks exists
    When I run tool show for "local/lifecycle-tool"
    Then the tool show output should succeed

  Scenario: Show tool with resource slots
    Given a tool with resource slots exists
    When I run tool show for "local/slotted-tool"
    Then the tool show output should succeed

  Scenario: Show tool with validation mode field
    Given a tool with validation mode exists
    When I run tool show for "local/val-mode-tool"
    Then the tool show output should succeed

  Scenario: Show tool with wraps field
    Given a tool with wraps field exists
    When I run tool show for "local/wrap-tool"
    Then the tool show output should succeed

  Scenario: Show tool with plain format uses dict rendering
    Given a tool with as_cli_dict method exists
    When I run tool show formatted "local/domain-tool" using fmt "plain"
    Then the tool show output should succeed

  Scenario: Show tool with table format
    Given a tool with as_cli_dict method exists
    When I run tool show formatted "local/domain-tool" using fmt "table"
    Then the tool show output should succeed

  Scenario: Show tool with yaml format
    Given a tool with as_cli_dict method exists
    When I run tool show formatted "local/domain-tool" using fmt "yaml"
    Then the tool show output should succeed

  # Coverage: _tool_spec_dict with string tool (fallback)
  Scenario: List tools returns items without name key
    Given a tool list returns minimal objects
    When I run tool list with fmt "json"
    Then the tool list result should succeed

  # Coverage: validation _print_validation with wraps and transform
  Scenario: Show validation with wraps and transform
    Given a validation with wraps and transform exists
    When I run validation show via add with "local/wrapped-val"
    Then the validation add result should succeed

  # Coverage: validation _attachment_dict with object
  Scenario: Attach validation returns object-like attachment
    Given an object-like attachment from service
    When I run validation attach "res/x" "local/v1"
    Then the validation attach result should succeed

  # Coverage: tool add with yaml format
  Scenario: Add tool with yaml format
    Given a tool add yaml config exists
    When I run tool add with fmt "yaml"
    Then the tool add result should succeed

  # Coverage: tool add with ValidationError
  Scenario: Add tool with ValidationError from service
    Given a tool add yaml config exists
    And tool service raises validation error on register
    When I run tool add from config
    Then the tool add result should abort

  # Coverage: validation add with yaml format
  Scenario: Add validation with yaml format
    Given a validation add yaml config exists
    When I run validation add with fmt "yaml"
    Then the validation add result should succeed

  # Coverage: tool list with CleverAgentsError from source filter
  Scenario: List tools with source and CleverAgentsError
    Given tool service raises CleverAgentsError on list
    When I run tool list with source "bad"
    Then the tool list result should abort

  # Coverage: validation attach with plan id
  Scenario: Attach validation with plan id
    Given an attachment service returns attachment
    When I run validation attach with plan "plan-123"
    Then the validation attach result should succeed

  # Coverage: _tool_spec_dict with dict tool missing namespace
  Scenario: Tool spec dict from dict without explicit namespace
    Given a dict tool without explicit namespace
    When I run tool show for "other/thing"
    Then the tool show output should succeed

  # Coverage: _validation_spec_dict with dict having wraps/transform
  Scenario: Validation spec dict includes wraps and transform
    Given a dict validation with wraps and transform
    When I run validation show via add for "local/wrapped-val" with fmt "json"
    Then the validation add result should succeed

  # Coverage: validation detach without confirmation (abort)
  Scenario: Detach validation declines confirmation
    Given an attachment service returns true on detach
    When I run validation detach "att-1" declining confirmation
    Then the validation detach result should abort

  # Coverage: tool remove without confirmation (abort)
  Scenario: Remove tool declines confirmation
    Given a tool exists for removal
    When I run tool remove "local/rm-tool" declining confirmation
    Then the tool remove result should abort

  # Coverage: dict tool with mode and wraps keys (_tool_spec_dict dict branch)
  Scenario: Show dict tool with mode and wraps
    Given a dict tool with mode and wraps
    When I run tool show for "local/dict-mw"
    Then the tool show output should succeed

  # Coverage: non-empty capability dict and long description truncation
  Scenario: List tools with long description and capabilities
    Given tools with long descriptions exist
    When I run tool list as rich
    Then the tool list result should succeed

  # Coverage: _get_name on object (not dict) in regex filter path
  Scenario: List tools with regex filters object names
    Given tools as objects exist
    When I run tool list regex filtered "obj"
    Then the tool list result should succeed

  # Coverage: tool add with non-mapping YAML triggers ValueError
  Scenario: Add tool with non-mapping YAML
    Given a non-mapping YAML tool file exists
    When I run tool add from non-mapping config
    Then the tool add result should abort

  # Coverage: validation add with non-mapping YAML triggers ValueError
  Scenario: Add validation with non-mapping YAML
    Given a non-mapping YAML validation file exists
    When I run validation add from non-mapping config
    Then the validation add result should abort

  # Coverage: _validation_spec_dict as_cli_dict branch
  Scenario: Validation add returns object with as_cli_dict
    Given validation add returns as_cli_dict object
    When I run validation add via cli_dict config
    Then the validation add result should succeed

  # Coverage: _validation_spec_dict string fallback
  Scenario: Validation add returns raw string
    Given validation add returns raw string object
    When I run validation add via string config
    Then the validation add result should succeed
