946ebdec66
Add BDD/Behave test scenarios for the existing --format/-f flag on `agents session tell`,
and update CHANGELOG.md and CONTRIBUTORS.md.
The implementation of --format on session tell exists in the codebase (commit 87a7ce35d),
but lacks dedicated BDD test coverage. This PR adds:
- 6 new Behave scenarios in features/session_cli.feature testing JSON, YAML, plain, table,
short flag (-f), and Rich output regression paths
- 6 corresponding step definitions in features/steps/session_cli_steps.py verifying
spec-compliant JSON envelopes, valid YAML/JSON output, ASCII table output, and Rich console
content preservation
- CHANGELOG.md entry under [Unreleased] documenting the --format flag feature
- CONTRIBUTORS.md entry crediting Jeffrey Phillips Freeman
Quality gates: lint ✓, typecheck ✓ (only pre-existing warnings about optional provider imports)
ISSUES CLOSED: #10466
300 lines
13 KiB
Gherkin
300 lines
13 KiB
Gherkin
Feature: Session CLI commands
|
|
As a developer
|
|
I want to manage sessions via CLI commands
|
|
So that I can create and use persistent conversation threads
|
|
|
|
Background:
|
|
Given a session CLI runner with mocked service
|
|
|
|
# Create command tests
|
|
Scenario: Create session with defaults
|
|
When I run session CLI create with no arguments
|
|
Then the session CLI create should succeed
|
|
And the session CLI output should contain "Session created"
|
|
|
|
Scenario: Create session with custom actor
|
|
When I run session CLI create with --actor "openai/gpt-4"
|
|
Then the session CLI create should succeed
|
|
And the session CLI output should contain "openai/gpt-4"
|
|
|
|
Scenario: Create session with JSON format
|
|
When I run session CLI create with --format json
|
|
Then the session CLI create should succeed
|
|
And the session CLI output should be valid JSON
|
|
And the session CLI JSON envelope message should be "Session created"
|
|
|
|
# List command tests
|
|
Scenario: List sessions when empty
|
|
Given there are no mocked sessions
|
|
When I run session CLI list
|
|
Then the session CLI output should contain "No sessions found"
|
|
|
|
Scenario: List sessions with JSON format when empty
|
|
Given there are no mocked sessions
|
|
When I run session CLI list with --format json
|
|
Then the session CLI output should be valid JSON
|
|
And the session CLI JSON envelope message should be "0 sessions listed"
|
|
|
|
Scenario: List sessions with populated data
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list
|
|
Then the session CLI should show all sessions in a table
|
|
|
|
Scenario: List sessions with JSON format
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list with --format json
|
|
Then the session CLI output should be valid JSON
|
|
And the session CLI JSON should contain "sessions"
|
|
And the session CLI JSON envelope message should be "2 sessions listed"
|
|
|
|
Scenario: List sessions JSON matches the documented contract
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list with --format json
|
|
Then the session CLI JSON list entries should match the documented contract
|
|
|
|
Scenario: List sessions displays full 26-character ULIDs in Rich table
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list
|
|
Then the session CLI rich table should display full session ULIDs
|
|
|
|
Scenario: List sessions summary panel shows full ULIDs for unnamed sessions
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list
|
|
Then the session CLI summary panel should contain full session ULIDs
|
|
|
|
Scenario: List sessions summary panel shows session names for named sessions
|
|
Given there are mocked existing named sessions
|
|
When I run session CLI list
|
|
Then the session CLI summary panel should show session names
|
|
|
|
Scenario: Full session ID from list output works with session tell
|
|
Given there are mocked existing sessions
|
|
When I run session CLI list
|
|
And I capture the first session full ULID from the output
|
|
And I run session CLI tell with the full session ID and prompt "Hello from list"
|
|
Then the session CLI tell should succeed
|
|
|
|
# Show command tests
|
|
Scenario: Show session with valid ID
|
|
Given there is a mocked session with messages
|
|
When I run session CLI show with a valid session ID
|
|
Then the session CLI show should succeed
|
|
And the session CLI output should contain "Session Summary"
|
|
And the session CLI output should contain "ID:"
|
|
And the session CLI output should contain "Actor:"
|
|
And the session CLI output should contain "Messages:"
|
|
And the session CLI output should contain "Created:"
|
|
And the session CLI output should contain "Updated:"
|
|
And the session CLI output should contain "Automation:"
|
|
And the session CLI output should not contain "Session ID:"
|
|
And the session CLI output should not contain "Namespace:"
|
|
|
|
Scenario: Show session with JSON format
|
|
Given there is a mocked session with messages
|
|
When I run session CLI show with --format json
|
|
Then the session CLI output should be valid JSON
|
|
And the session CLI JSON envelope message should be "Session details loaded"
|
|
|
|
Scenario: Show session JSON includes token usage counts
|
|
Given there is a mocked session with messages
|
|
When I run session CLI show with --format json
|
|
Then the session CLI JSON token usage should include counts
|
|
|
|
Scenario: Show session with invalid ID
|
|
When I run session CLI show with an invalid session ID
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "Session not found"
|
|
|
|
# Delete command tests
|
|
Scenario: Delete session with --yes flag
|
|
Given there is a mocked session to delete
|
|
When I run session CLI delete with --yes
|
|
Then the session CLI delete should succeed
|
|
And the session CLI output should contain "deleted"
|
|
|
|
Scenario: Delete session with JSON format emits envelope
|
|
Given there is a mocked session to delete
|
|
When I run session CLI delete with --yes and --format json
|
|
Then the session CLI delete should succeed
|
|
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
|
|
And the session CLI output should contain "Session not found"
|
|
|
|
# Export command tests
|
|
Scenario: Export session to stdout renders Rich panels
|
|
Given there is a mocked session for export
|
|
When I run session CLI export with no output file
|
|
Then the session CLI export should succeed
|
|
And the session CLI output should contain "Session Export"
|
|
And the session CLI output should contain "Contents"
|
|
And the session CLI output should contain "Integrity"
|
|
And the session CLI output should contain "Export completed"
|
|
|
|
Scenario: Export session to file renders Rich panels
|
|
Given there is a mocked session for export
|
|
When I run session CLI export with --output to a temp file
|
|
Then the session CLI export should succeed
|
|
And the exported file should exist
|
|
And the session CLI output should contain "Session Export"
|
|
And the session CLI output should contain "Contents"
|
|
And the session CLI output should contain "Integrity"
|
|
And the session CLI output should contain "Export completed"
|
|
|
|
Scenario: Export session to file shows correct output path in panel
|
|
Given there is a mocked session for export
|
|
When I run session CLI export with --output to a temp file
|
|
Then the session CLI export should succeed
|
|
And the session CLI output should contain "Output:"
|
|
|
|
Scenario: Export session to stdout shows stdout indicator in panel
|
|
Given there is a mocked session for export
|
|
When I run session CLI export with no output file
|
|
Then the session CLI export should succeed
|
|
And the session CLI output should contain "(stdout)"
|
|
|
|
Scenario: Export refuses overwrite without --force
|
|
Given there is a mocked session for export
|
|
And there is an existing export file
|
|
When I run session CLI export to an existing file without --force
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "File already exists"
|
|
|
|
Scenario: Export with --force overwrites file
|
|
Given there is a mocked session for export
|
|
And there is an existing export file
|
|
When I run session CLI export to an existing file with --force
|
|
Then the session CLI export should succeed
|
|
And the session CLI output should contain "Export completed"
|
|
|
|
Scenario: Export session with JSON output format emits envelope
|
|
Given there is a mocked session for export
|
|
When I run session CLI export with --output-format json
|
|
Then the session CLI export should succeed
|
|
And the session CLI output should be valid JSON
|
|
And the session CLI JSON envelope message should be "Export completed"
|
|
|
|
Scenario: Export non-existent session
|
|
When I run session CLI export with a non-existent session ID
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "Session not found"
|
|
|
|
# Import command tests
|
|
Scenario: Import session from valid file
|
|
Given there is a valid session export file
|
|
When I run session CLI import with the export file
|
|
Then the session CLI import should succeed
|
|
And the session CLI output should contain "Session Import"
|
|
And the session CLI output should contain "Validation"
|
|
And the session CLI output should contain "Merge"
|
|
And the session CLI output should contain "Import completed"
|
|
|
|
Scenario: Import session shows correct panel fields
|
|
Given there is a valid session export file
|
|
When I run session CLI import with the export file
|
|
Then the session CLI import should succeed
|
|
And the session CLI output should contain "Input:"
|
|
And the session CLI output should contain "Session ID:"
|
|
And the session CLI output should contain "Messages:"
|
|
And the session CLI output should contain "Schema:"
|
|
And the session CLI output should contain "Checksum:"
|
|
And the session CLI output should contain "Actor Ref:"
|
|
And the session CLI output should contain "Existing:"
|
|
And the session CLI output should contain "Strategy:"
|
|
|
|
Scenario: Import from non-existent file
|
|
When I run session CLI import with a non-existent file
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "File not found"
|
|
|
|
Scenario: Import from corrupt file
|
|
Given there is a corrupt session export file
|
|
When I run session CLI import with the corrupt file
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "Import error"
|
|
|
|
Scenario: Import session with JSON format emits envelope
|
|
Given there is a valid session export file
|
|
When I run session CLI import with the export file and --format json
|
|
Then the session CLI import should succeed
|
|
And the session CLI output should be valid JSON
|
|
And the session CLI JSON envelope message should be "Import completed"
|
|
|
|
Scenario: Import from invalid JSON file
|
|
Given there is an invalid JSON file
|
|
When I run session CLI import with the invalid JSON file
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "Invalid JSON"
|
|
|
|
# Tell command tests
|
|
Scenario: Tell appends message to session
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with a prompt "Hello, world"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI output should contain "Acknowledged"
|
|
|
|
Scenario: Tell with custom actor
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with --actor "openai/gpt-4" and prompt "Plan a feature"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI output should contain "openai/gpt-4"
|
|
|
|
Scenario: Tell to non-existent session
|
|
When I run session CLI tell to a non-existent session
|
|
Then the session CLI should exit with error
|
|
And the session CLI output should contain "Session not found"
|
|
|
|
# Tell command format flag tests (issue #10466)
|
|
@format_flag
|
|
Scenario: Tell with JSON format outputs spec-compliant envelope
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with --format json and prompt "What files were changed?"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI output should be valid JSON
|
|
And the session CLI tell JSON should contain a data envelope
|
|
|
|
@format_flag
|
|
Scenario: Tell YAML format outputs structured output
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with --format yaml and prompt "Hello"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI tell output should be valid YAML
|
|
|
|
@format_flag
|
|
Scenario: Tell plain format outputs key-value lines
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with --format plain and prompt "Test"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI tell output should contain "session_id:"
|
|
|
|
@format_flag
|
|
Scenario: Tell table format outputs ASCII table
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with --format table and prompt "Table test"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI tell output should contain a table border character
|
|
|
|
@format_flag
|
|
Scenario: Tell short flag -f works the same as --format
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with short format flag json and prompt "Short flag"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI output should be valid JSON
|
|
|
|
@format_flag
|
|
Scenario: Tell default Rich output has no regression
|
|
Given there is a mocked session for tell
|
|
When I run session CLI tell with a prompt "Rich output test"
|
|
Then the session CLI tell should succeed
|
|
And the session CLI output should contain "user:"
|
|
And the session CLI output should contain "assistant:"
|