UAT: format_output() renders rich format as JSON — should use rich terminal rendering #2103

Open
opened 2026-04-03 04:04:35 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/format-output-rich-falls-back-to-json
  • Commit Message: fix(cli): format_output() rich format should use rich terminal rendering, not JSON
  • Milestone: v3.7.0
  • Parent Epic: #936

Subtasks

  • Update format_output() in src/cleveragents/cli/formatting.py to use RichMaterializer or Rich console rendering for the rich format
  • Ensure the rich format in format_output() produces Rich-styled terminal output (panels, tables, etc.)
  • Add unit tests (Behave) for format_output(data, 'rich') producing Rich-styled output
  • Verify that commands using format_output() with rich format produce proper rich output

Definition of Done

  • format_output(data, 'rich') returns Rich-styled terminal output (not JSON)
  • Commands that use format_output() with rich format produce visually rich output
  • Tests pass at ≥97% coverage

Bug Report

What Was Tested

The spec (§Output Rendering Framework, §Format Descriptions) defines the rich format as:

rich (Default): Modern rich CLI output with dynamic effects, animated spinners, progress bars, and extensive color.

Expected Behavior (from spec)

format_output(data, 'rich') should return Rich-styled terminal output with panels, colored text, and structured visual elements.

Actual Behavior

format_output(data, 'rich') returns JSON-formatted output — the same as format_output(data, 'json'):

from cleveragents.cli.formatting import format_output
data = {'key': 'value', 'status': 'active'}
result = format_output(data, 'rich')
# Result: '{\n  "key": "value",\n  "status": "active"\n}'
# Expected: Rich terminal panels/styled output

Root Cause

In src/cleveragents/cli/formatting.py, the format_output() function has this fallback:

# ``rich`` and any unknown value fall back to JSON
return _format_json(safe_data)

The rich format is not handled explicitly and falls through to the JSON fallback. This is incorrect — the rich format should use Rich library rendering or at minimum the RichMaterializer.

Note: Commands that explicitly call render_version_rich() or similar rich-specific renderers work correctly. The bug is specifically in the format_output() helper function which is used by many commands for non-rich formats but incorrectly falls back to JSON for rich.

Code Location

  • src/cleveragents/cli/formatting.pyformat_output() function, the final fallback (line ~180)
  • The fix should add an explicit rich branch that uses RichMaterializer or Rich console rendering

Steps to Reproduce

from cleveragents.cli.formatting import format_output
data = {'key': 'value', 'status': 'active'}
result = format_output(data, 'rich')
import json
try:
    json.loads(result)
    print("Bug: rich format returned JSON")  # This prints
except:
    print("OK: rich format returned non-JSON")

Impact

Commands that use format_output() for the rich format (instead of calling a dedicated rich renderer) will output JSON instead of rich terminal output. This affects any command that doesn't have a special-case if fmt.lower() == 'rich': render_rich(data) branch.

Severity

Medium — The rich format is the default format. Commands that use format_output() for all formats (including rich) will silently output JSON instead of rich terminal output.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Branch**: `fix/format-output-rich-falls-back-to-json` - **Commit Message**: `fix(cli): format_output() rich format should use rich terminal rendering, not JSON` - **Milestone**: v3.7.0 - **Parent Epic**: #936 ## Subtasks - [ ] Update `format_output()` in `src/cleveragents/cli/formatting.py` to use `RichMaterializer` or Rich console rendering for the `rich` format - [ ] Ensure the `rich` format in `format_output()` produces Rich-styled terminal output (panels, tables, etc.) - [ ] Add unit tests (Behave) for `format_output(data, 'rich')` producing Rich-styled output - [ ] Verify that commands using `format_output()` with `rich` format produce proper rich output ## Definition of Done - `format_output(data, 'rich')` returns Rich-styled terminal output (not JSON) - Commands that use `format_output()` with `rich` format produce visually rich output - Tests pass at ≥97% coverage ## Bug Report ### What Was Tested The spec (§Output Rendering Framework, §Format Descriptions) defines the `rich` format as: > **`rich`** (Default): Modern rich CLI output with dynamic effects, animated spinners, progress bars, and extensive color. ### Expected Behavior (from spec) `format_output(data, 'rich')` should return Rich-styled terminal output with panels, colored text, and structured visual elements. ### Actual Behavior `format_output(data, 'rich')` returns JSON-formatted output — the same as `format_output(data, 'json')`: ```python from cleveragents.cli.formatting import format_output data = {'key': 'value', 'status': 'active'} result = format_output(data, 'rich') # Result: '{\n "key": "value",\n "status": "active"\n}' # Expected: Rich terminal panels/styled output ``` ### Root Cause In `src/cleveragents/cli/formatting.py`, the `format_output()` function has this fallback: ```python # ``rich`` and any unknown value fall back to JSON return _format_json(safe_data) ``` The `rich` format is not handled explicitly and falls through to the JSON fallback. This is incorrect — the `rich` format should use Rich library rendering or at minimum the `RichMaterializer`. Note: Commands that explicitly call `render_version_rich()` or similar rich-specific renderers work correctly. The bug is specifically in the `format_output()` helper function which is used by many commands for non-rich formats but incorrectly falls back to JSON for `rich`. ### Code Location - `src/cleveragents/cli/formatting.py` — `format_output()` function, the final fallback (line ~180) - The fix should add an explicit `rich` branch that uses `RichMaterializer` or Rich console rendering ### Steps to Reproduce ```python from cleveragents.cli.formatting import format_output data = {'key': 'value', 'status': 'active'} result = format_output(data, 'rich') import json try: json.loads(result) print("Bug: rich format returned JSON") # This prints except: print("OK: rich format returned non-JSON") ``` ### Impact Commands that use `format_output()` for the `rich` format (instead of calling a dedicated rich renderer) will output JSON instead of rich terminal output. This affects any command that doesn't have a special-case `if fmt.lower() == 'rich': render_rich(data)` branch. ### Severity **Medium** — The `rich` format is the default format. Commands that use `format_output()` for all formats (including `rich`) will silently output JSON instead of rich terminal output. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.6.0 milestone 2026-04-05 06:52:49 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium
  • Milestone: v3.6.0 (assigned — was previously unassigned)
  • MoSCoW: Should Have — format_output() rendering rich format as JSON is a spec deviation; the rich format should use terminal rendering
  • Parent Epic: #398 (Post-MVP Resources) — output formatting is a cross-cutting concern

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium - **Milestone**: v3.6.0 (assigned — was previously unassigned) - **MoSCoW**: Should Have — `format_output()` rendering rich format as JSON is a spec deviation; the rich format should use terminal rendering - **Parent Epic**: #398 (Post-MVP Resources) — output formatting is a cross-cutting concern --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#2103
No description provided.