Feature: Config CLI commands
  As a developer
  I want to manage configuration via CLI
  So that I can set, get, and list runtime configuration values

  Background:
    Given a clean config CLI test environment

  # --- SET ---
  Scenario: Set a configuration value
    When I run config set "core.log.level" "DEBUG"
    Then the config set should succeed
    And the config set output should contain key "core.log.level"
    And the config set output should contain value "DEBUG"

  Scenario: Set a configuration value with underscore normalization
    When I run config set "core_log_level" "INFO"
    Then the config set should succeed
    And the config set output should contain key "core.log.level"

  Scenario: Set an unknown key fails
    When I run config set "nonexistent_key" "value"
    Then the config set should fail with unknown key error

  # --- GET ---
  Scenario: Get a configuration value
    When I run config get "core.log.level" with verbose
    Then the config get should succeed
    And the config get output should contain key "core.log.level"
    And the config get output should show the resolution chain

  Scenario: Get a value after setting it
    Given I have set config "core.log.level" to "WARNING"
    When I run config get "core.log.level"
    Then the config get should succeed

  Scenario: Get with underscore alias
    When I run config get "plan_concurrency"
    Then the config get should succeed
    And the config get output should contain key "plan.concurrency"

  Scenario: Get an unknown key fails
    When I run config get "totally_bogus_key"
    Then the config get should fail with unknown key error

  # --- LIST ---
  Scenario: List all configuration values
    When I run config list
    Then the config list should succeed
    And the config list output should contain multiple settings

  Scenario: List with key regex filter
    When I run config list "core\.log.*"
    Then the config list should succeed
    And every listed key should match "core\.log.*"

  Scenario: List with value regex filter
    When I run config list with --filter-values "FATAL"
    Then the config list should succeed

  Scenario: List with invalid key regex fails
    When I run config list with invalid regex "[invalid"
    Then the config list should fail with regex error

  Scenario: List with invalid value regex fails
    When I run config list with invalid value regex "[bad"
    Then the config list should fail with regex error

  # --- SECRET MASKING ---
  Scenario: Secret values are masked by default
    When I run config list
    Then secret keys should show masked values

  Scenario: Show-secrets reveals secret values
    When I run config list with --show-secrets
    Then secret keys should show actual values

  # --- RESOLUTION CHAIN ---
  Scenario: Resolution chain shows default source
    When I run config get key "core.log.level" formatted as "json"
    Then the resolution chain should include "Default" source

  # --- SET/GET ROUNDTRIP ---
  Scenario: Set and get roundtrip
    Given I have set config "core.log.file-enabled" to "true"
    When I run config get key "core.log.file-enabled" formatted as "json"
    Then the config get should succeed
    And the get value source should be "config"

  # --- FORMAT ---
  Scenario: Config list with JSON format
    When I run config list with format "json"
    Then the config list should succeed
    And the output should be valid JSON

  Scenario: Config get with JSON format
    When I run config get key "core.format" formatted as "json"
    Then the config get should succeed
    And the output should be valid JSON
