Files
cleveragents-core/features/cli_global_options.feature
hurui200320 b4a514e0f4
CI / benchmark-regression (push) Failing after 34s
CI / tdd_quality_gate (push) Has been skipped
CI / push-validation (push) Successful in 1m5s
CI / helm (push) Successful in 1m6s
CI / build (push) Successful in 1m23s
CI / lint (push) Successful in 1m55s
CI / typecheck (push) Successful in 2m4s
CI / quality (push) Successful in 2m2s
CI / security (push) Successful in 2m2s
CI / integration_tests (push) Successful in 7m35s
CI / e2e_tests (push) Successful in 4m30s
CI / unit_tests (push) Successful in 9m19s
CI / docker (push) Successful in 1m47s
CI / coverage (push) Successful in 12m33s
CI / status-check (push) Successful in 3s
CI / benchmark-publish (push) Has been cancelled
fix(cli): add spec-required --data-dir, --config-path, and -v global options to main_callback
Implements ADR-021 §Global CLI Flags and ADR-024 §Resolution Chain.
All three global options were missing from main_callback(), causing any
invocation with these flags to crash with 'No such option'.

Changes:
- src/cleveragents/cli/main.py
  * Add _VERBOSITY_LOG_LEVELS tuple mapping verbose count to log levels
    (0=CRITICAL/silent, 1=ERROR, 2=WARNING, 3=INFO, 4=DEBUG, 5+=DEBUG)
  * Add --data-dir PATH option: validates path is a directory if it exists,
    sets CLEVERAGENTS_DATA_DIR env var, resets Settings singleton
  * Add --config-path PATH option: validates file exists and is a file,
    sets CLEVERAGENTS_CONFIG_PATH env var for ConfigService to pick up
  * Add -v (count=True) option: wires verbose count to configure_structlog
  * Store all three values in ctx.obj for subcommand access
  * Update _print_basic_help() to include the three new global options so
    'cleveragents --help' (fast path) also lists them
  * In the catch-all Exception handler, print the original exception
    type+message directly to err_console so actionable details remain
    visible even when log level is CRITICAL (e.g. 'No such option')

- src/cleveragents/application/services/config_service.py
  * ConfigService.__init__ now checks CLEVERAGENTS_CONFIG_PATH env var
    when no explicit config_path is passed, completing the resolution
    chain for --config-path CLI override

Tests (all passing):
- features/cli_global_options.feature (21 Behave scenarios)
- features/steps/cli_global_options_steps.py
- robot/cli_global_options.robot (8 Robot Framework integration tests)
- robot/helper_cli_global_options.py

Quality gates: lint ✓  typecheck ✓  unit_tests ✓  integration_tests ✓
Coverage: 96.52% (threshold 96.5% ✓)

ISSUES CLOSED: #6785
2026-05-12 01:05:10 +00:00

129 lines
5.6 KiB
Gherkin

Feature: CLI global options --data-dir, --config-path, and -v
Background:
Given global options test env is clean
# -----------------------------------------------------------------------
# --data-dir option
# -----------------------------------------------------------------------
@tdd_issue @tdd_issue_6785
Scenario: --data-dir option is accepted with an existing directory
Given a temp data dir is prepared
When I run the global options CLI with data-dir flag and "version"
Then the global options CLI should succeed
Scenario: --data-dir option overrides CLEVERAGENTS_DATA_DIR for the invocation
Given a temp data dir is prepared
When I run the global options CLI with data-dir flag and "version"
Then the CLEVERAGENTS_DATA_DIR env var should match the temp data dir
Scenario: --data-dir with a path that is an existing file fails with a clear error
Given a temp file path is prepared
When I run the global options CLI with data-dir as temp file and "version"
Then the global options CLI should fail
And the global options output should contain "--data-dir"
Scenario: --data-dir stores value in ctx.obj for subcommands
Given a temp data dir is prepared
When I run the global options CLI with data-dir flag and "version"
Then the CLEVERAGENTS_DATA_DIR env var should match the temp data dir
# -----------------------------------------------------------------------
# --config-path option
# -----------------------------------------------------------------------
@tdd_issue @tdd_issue_6785
Scenario: --config-path option is accepted with an existing file
Given a temp config file is prepared
When I run the global options CLI with config-path flag and "version"
Then the global options CLI should succeed
Scenario: --config-path overrides CLEVERAGENTS_CONFIG_PATH for the invocation
Given a temp config file is prepared
When I run the global options CLI with config-path flag and "version"
Then the CLEVERAGENTS_CONFIG_PATH env var should match the temp config file
Scenario: --config-path with a non-existent file fails with a clear error
When I run the global options CLI with invalid config-path and "version"
Then the global options CLI should fail
And the global options output should contain "--config-path"
Scenario: --config-path stores value in ctx.obj for subcommands
Given a temp config file is prepared
When I run the global options CLI with config-path flag and "version"
Then the CLEVERAGENTS_CONFIG_PATH env var should match the temp config file
# -----------------------------------------------------------------------
# Combining --data-dir and --config-path
# -----------------------------------------------------------------------
Scenario: --data-dir and --config-path can be combined
Given a temp data dir is prepared
And a temp config file is prepared
When I run the global options CLI with both path flags and "version"
Then the global options CLI should succeed
And the CLEVERAGENTS_DATA_DIR env var should match the temp data dir
And the CLEVERAGENTS_CONFIG_PATH env var should match the temp config file
# -----------------------------------------------------------------------
# -v verbosity option
# -----------------------------------------------------------------------
Scenario: No -v flag results in CRITICAL (silent) log level
When I call main_callback with verbosity 0
Then the global options log level should be "CRITICAL"
Scenario: Single -v flag results in ERROR log level
When I call main_callback with verbosity 1
Then the global options log level should be "ERROR"
Scenario: -vv results in WARNING log level
When I call main_callback with verbosity 2
Then the global options log level should be "WARNING"
Scenario: -vvv results in INFO log level
When I call main_callback with verbosity 3
Then the global options log level should be "INFO"
Scenario: -vvvv results in DEBUG log level
When I call main_callback with verbosity 4
Then the global options log level should be "DEBUG"
Scenario: -vvvvv or more results in DEBUG log level
When I call main_callback with verbosity 5
Then the global options log level should be "DEBUG"
@tdd_issue @tdd_issue_6785
Scenario: -v flag is accepted by the CLI without crashing
When I run the global options CLI with args "-v version"
Then the global options CLI should succeed
Scenario: -vvv flags are accepted by the CLI without crashing
When I run the global options CLI with args "-v -v -v version"
Then the global options CLI should succeed
# -----------------------------------------------------------------------
# --help shows all three options
# -----------------------------------------------------------------------
Scenario: --help output includes --data-dir option
When I run the global options CLI with args "--help"
Then the global options output should contain "--data-dir"
Scenario: --help output includes --config-path option
When I run the global options CLI with args "--help"
Then the global options output should contain "--config-path"
Scenario: -v flag appears in --help output
When I run the global options CLI with args "--help"
Then the global options output should contain "-v"
# -----------------------------------------------------------------------
# -v verbosity stored in ctx.obj
# -----------------------------------------------------------------------
Scenario: verbose count is stored in ctx.obj
When I call main_callback with verbosity 3
Then the global options ctx obj "verbose" should be 3