6e47abbd63
The format_output() function in src/cleveragents/cli/formatting.py had two routing bugs that caused incorrect output for the 'rich' and 'color' formats: 1. The 'rich' format had no explicit dispatch branch and silently fell through to the final JSON fallback, returning raw JSON instead of styled terminal output. Since 'rich' is the default CLI format (per ADR-021), this meant all commands using format_output() (version, info, diagnostics) produced JSON by default. 2. The 'color' format was incorrectly routed to _format_plain() instead of a color-aware renderer, producing plain text with no ANSI color codes. Fix: - Added _format_rich() helper that delegates to RichMaterializer via OutputSession, producing ANSI-styled terminal output consistent with format_output_session(). - Added _format_color() helper that delegates to ColorMaterializer via OutputSession, producing ANSI-colored terminal output. - Added explicit OutputFormat.RICH dispatch in format_output() routing. - Fixed OutputFormat.COLOR dispatch to use _format_color() instead of _format_plain(). Tests: - Updated existing BDD scenario that was validating the buggy behavior (expected JSON for rich format) to now assert correct styled output. - Added new BDD scenarios: 'rich format produces styled terminal output not JSON' and 'color format produces ANSI-colored output not plain text'. - Added Robot Framework integration tests in cli_formats.robot and helper_cli_formats.py verifying end-to-end styled output for both formats. All nox sessions pass: lint, typecheck, unit_tests, security_scan. ISSUES CLOSED: #2921
118 lines
6.5 KiB
Plaintext
118 lines
6.5 KiB
Plaintext
*** Settings ***
|
|
Documentation Smoke tests for CLI --format flag parity (json/yaml/plain/table/rich)
|
|
... and global --format flag propagation to subcommands.
|
|
Resource ${CURDIR}/common.resource
|
|
Suite Setup Setup Test Environment
|
|
Suite Teardown Cleanup Test Environment
|
|
|
|
*** Variables ***
|
|
${HELPER} ${CURDIR}/helper_cli_formats.py
|
|
|
|
*** Test Cases ***
|
|
Action List Format JSON Outputs Valid JSON
|
|
[Documentation] Verify that ``action list --format json`` emits parseable JSON
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} action-list-json cwd=${WORKSPACE}
|
|
Log ${result.stdout}
|
|
Log ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-action-list-json-ok
|
|
|
|
Action Show Format YAML Outputs Valid YAML
|
|
[Documentation] Verify that ``action show --format yaml`` emits parseable YAML
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} action-show-yaml cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-action-show-yaml-ok
|
|
|
|
Plan Lifecycle List Format JSON Outputs Valid JSON
|
|
[Documentation] Verify that ``plan list --format json`` emits JSON
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} plan-list-json cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-plan-list-json-ok
|
|
|
|
Plan Status Format Plain Outputs Key-Value Pairs
|
|
[Documentation] Verify that ``plan status <id> --format plain`` emits plain text
|
|
[Tags] tdd_issue tdd_issue_4206
|
|
${result}= Run Process ${PYTHON} ${HELPER} plan-status-plain cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-plan-status-plain-ok
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Global --format flag propagation tests (Issue #2908)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
Global Format Flag JSON Propagates To Version Command
|
|
[Documentation] Verify that global ``--format json`` propagates to the version command
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-json-version cwd=${WORKSPACE}
|
|
Log ${result.stdout}
|
|
Log ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-json-version-ok
|
|
|
|
Global Format Flag YAML Propagates To Version Command
|
|
[Documentation] Verify that global ``--format yaml`` propagates to the version command
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-yaml-version cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-yaml-version-ok
|
|
|
|
Global Format Flag Plain Propagates To Version Command
|
|
[Documentation] Verify that global ``--format plain`` propagates to the version command
|
|
[Tags] tdd_issue tdd_issue_4206
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-plain-version cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-plain-version-ok
|
|
|
|
Global Format Flag JSON Propagates To Info Command
|
|
[Documentation] Verify that global ``--format json`` propagates to the info command
|
|
[Tags] tdd_issue tdd_issue_4206
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-json-info cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-json-info-ok
|
|
|
|
Global Format Flag JSON Propagates To Diagnostics Command
|
|
[Documentation] Verify that global ``--format json`` propagates to the diagnostics command
|
|
[Tags] tdd_issue tdd_issue_4206
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-json-diagnostics cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-json-diagnostics-ok
|
|
|
|
Global Format Shorthand Flag Works
|
|
[Documentation] Verify that global ``-f json`` shorthand propagates to the version command
|
|
[Tags] tdd_issue tdd_issue_4206 tdd_expected_fail
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-shorthand cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-shorthand-ok
|
|
|
|
All Six Formats Work With Version Command
|
|
[Documentation] Verify all six output formats work via the global --format flag
|
|
[Tags] tdd_issue tdd_issue_4206
|
|
${result}= Run Process ${PYTHON} ${HELPER} global-format-all-six cwd=${WORKSPACE}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-global-format-all-six-ok
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# format_output() renderer routing tests (Issue #2921)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
Format Output Rich Produces Styled Output Not JSON
|
|
[Documentation] Verify that format_output(data, "rich") produces styled terminal output
|
|
... and NOT raw JSON (fix for issue #2921: rich format silently fell back to JSON)
|
|
${result}= Run Process ${PYTHON} ${HELPER} format-output-rich cwd=${WORKSPACE}
|
|
Log ${result.stdout}
|
|
Log ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-format-output-rich-ok
|
|
|
|
Format Output Color Produces ANSI Colored Output Not Plain Text
|
|
[Documentation] Verify that format_output(data, "color") produces ANSI-colored output
|
|
... and NOT plain text (fix for issue #2921: color format used plain renderer)
|
|
${result}= Run Process ${PYTHON} ${HELPER} format-output-color cwd=${WORKSPACE}
|
|
Log ${result.stdout}
|
|
Log ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} cli-formats-format-output-color-ok
|