fix(cli): handle --format color in session delete as Rich output

The delete command's output branch used `fmt == OutputFormat.RICH` which
caused --format color to emit a JSON envelope instead of Rich panels.
Align with all other session commands by checking
`fmt not in (OutputFormat.RICH, OutputFormat.COLOR)` for machine-readable
paths. Add BDD scenario and step for --format color to close the coverage gap.

ISSUES CLOSED: #6457
This commit is contained in:
2026-05-31 13:32:08 -04:00
committed by drew
parent b1bfaf032e
commit c0606ce0ce
3 changed files with 28 additions and 16 deletions
+6
View File
@@ -119,6 +119,12 @@ Feature: Session CLI commands
And the session CLI output should be valid JSON
And the session CLI JSON envelope message should be "Session deleted"
Scenario: Delete session with --format color emits Rich output
Given there is a mocked session to delete
When I run session CLI delete with --yes and --format color
Then the session CLI delete should succeed
And the session CLI output should contain "deleted"
Scenario: Delete non-existent session
When I run session CLI delete with a non-existent ID
Then the session CLI should exit with error
+7
View File
@@ -428,6 +428,13 @@ def step_delete_yes_json(context: Context) -> None:
)
@when("I run session CLI delete with --yes and --format color")
def step_delete_yes_color(context: Context) -> None:
context.result = context.runner.invoke(
session_app, ["delete", context.session_id, "--yes", "--format", "color"]
)
@when("I run session CLI delete with a non-existent ID")
def step_delete_nonexistent(context: Context) -> None:
context.mock_service.get.side_effect = SessionNotFoundError("Session not found")
+15 -16
View File
@@ -717,9 +717,21 @@ def delete(
service.delete(session_id)
# Rich output: render Deletion Summary and Cleanup panels
if fmt == OutputFormat.RICH:
# Deletion Summary panel
if fmt not in (OutputFormat.RICH, OutputFormat.COLOR):
# Machine-readable formats: emit a structured JSON/YAML envelope per spec
# (docs/specification.md §"agents session delete" line ~1959)
typer.echo(
format_output(
{"session_id": session_id},
fmt.value,
command=_command_label(
"delete", session_id, "--yes", "--format", fmt.value
),
messages=[{"level": "ok", "text": "Session deleted"}],
)
)
else:
# Rich/Color output: render Deletion Summary and Cleanup panels
summary_table = Table.grid(padding=(0, 1))
summary_table.add_column(style="cyan bold", justify="left")
summary_table.add_column(style="white", justify="left")
@@ -746,19 +758,6 @@ def delete(
console.print(Panel(cleanup_table, title="Cleanup", border_style="blue"))
console.print()
console.print("[green]✓ OK[/green] Session deleted")
else:
# Non-rich formats: emit a structured JSON/YAML envelope per spec
# (docs/specification.md §"agents session delete" line ~1959)
typer.echo(
format_output(
{"session_id": session_id},
fmt.value,
command=_command_label(
"delete", session_id, "--yes", "--format", fmt.value
),
messages=[{"level": "ok", "text": "Session deleted"}],
)
)
except SessionNotFoundError as exc:
console.print(f"[red]Session not found:[/red] {session_id}")