Feature: agents config get spec-compliant output
  As a developer
  I want `agents config get` to render all spec-required panels and JSON fields
  So that the output matches the specification exactly

  Background:
    Given a clean config get spec test environment

  # --- Rich output: three panels ---

  Scenario: Rich output shows Config panel with correct title
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain panel "Config"

  Scenario: Rich output shows Overridden field in Config panel
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain "Overridden"

  Scenario: Rich output shows Origin panel
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain panel "Origin"

  Scenario: Rich output shows Resolution Chain panel
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain panel "Resolution Chain"

  Scenario: Rich output shows Winner in Resolution Chain panel
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain "Winner"

  Scenario: Rich output uses spec type string not Python type name
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain "string"
    And the spec config get rich output should not contain "str"

  Scenario: Rich output shows OK confirmation message
    When I run spec config get "core.log.level"
    Then the spec config get should succeed
    And the spec config get rich output should contain "OK"

  # --- JSON output: standard envelope ---

  Scenario: JSON output is wrapped in standard envelope
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON envelope should have field "command" equal to "config get"
    And the spec config get JSON envelope should have field "status" equal to "ok"
    And the spec config get JSON envelope should have field "exit_code" equal to 0
    And the spec config get JSON envelope should have field "data"
    And the spec config get JSON envelope should have field "timing"
    And the spec config get JSON envelope should have field "messages"

  Scenario: JSON data contains all required fields
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data should have field "key"
    And the spec config get JSON data should have field "value"
    And the spec config get JSON data should have field "source"
    And the spec config get JSON data should have field "overridden"
    And the spec config get JSON data should have field "type"
    And the spec config get JSON data should have field "origin"
    And the spec config get JSON data should have field "resolution_chain"
    And the spec config get JSON data should have field "winner"

  Scenario: JSON data type field uses spec type string
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data field "type" should equal "string"

  Scenario: JSON data overridden field is false for default value
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data field "overridden" should be false

  Scenario: JSON data overridden field is true when value is set
    Given I have set spec config "core.log.level" to "DEBUG"
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data field "overridden" should be true

  Scenario: JSON data origin contains default field
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON origin should have field "default"

  Scenario: JSON data resolution chain uses human-readable source names
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON resolution chain should use human-readable source names

  Scenario: JSON data winner contains source and level
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON winner should have field "source"
    And the spec config get JSON winner should have field "level"

  Scenario: JSON timing contains started and duration_ms
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON timing should have field "started"
    And the spec config get JSON timing should have field "duration_ms"

  # --- Source name mapping ---

  Scenario: JSON source uses short name "config" when value from global config
    Given I have set spec config "core.log.level" to "WARNING"
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data field "source" should equal "config"

  Scenario: JSON source uses short name "default" when value from default
    When I run spec config get "core.log.level" with format "json"
    Then the spec config get should succeed
    And the spec config get JSON data field "source" should equal "default"
