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:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user