forked from HAL9000/cleveragents-core
2e24483947
Add Markdown export format for sessions alongside the existing JSON export. Implement TUI slash command routing for /session:export and /session:import. - Add Session.as_export_markdown() domain method producing a human-readable Markdown transcript (lossy, not importable — for sharing/documentation) - Extend CLI 'agents session export' with --format flag (json|md) - Extend TuiCommandRouter._session_command() to handle 'export' and 'import' subcommands, delegating to the session service via the DI container - Add 16 Behave scenarios covering domain model, CLI, and TUI command paths Closes #1004
113 lines
5.7 KiB
Gherkin
113 lines
5.7 KiB
Gherkin
Feature: TUI session export/import (JSON + Markdown)
|
|
As a TUI user
|
|
I want to export sessions to JSON and Markdown formats
|
|
And import sessions from JSON files via slash commands
|
|
So that I can share, archive, and restore conversation history
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Session domain model: as_export_markdown()
|
|
# ---------------------------------------------------------------------------
|
|
|
|
Scenario: Session with messages exports to Markdown
|
|
Given a session with two messages for markdown export
|
|
When I call as_export_markdown on the session
|
|
Then the markdown output should start with "# Session:"
|
|
And the markdown output should contain "## Messages"
|
|
And the markdown output should contain "USER"
|
|
And the markdown output should contain "ASSISTANT"
|
|
And the markdown output should contain "Hello from user"
|
|
And the markdown output should contain "Hello from assistant"
|
|
|
|
Scenario: Session with no messages exports to Markdown with placeholder
|
|
Given a session with no messages for markdown export
|
|
When I call as_export_markdown on the session
|
|
Then the markdown output should start with "# Session:"
|
|
And the markdown output should contain "*(no messages)*"
|
|
|
|
Scenario: Markdown export includes actor and namespace
|
|
Given a session with actor "openai/gpt-4" for markdown export
|
|
When I call as_export_markdown on the session
|
|
Then the markdown output should contain "**Actor:** openai/gpt-4"
|
|
And the markdown output should contain "**Namespace:** local"
|
|
|
|
Scenario: Markdown export includes linked plan IDs
|
|
Given a session with linked plans for markdown export
|
|
When I call as_export_markdown on the session
|
|
Then the markdown output should contain "**Linked Plans:**"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# CLI export command: --format md flag
|
|
# ---------------------------------------------------------------------------
|
|
|
|
Scenario: Export session as Markdown to stdout
|
|
Given there is a mocked session for markdown export
|
|
When I run session CLI export with --format md and no output file
|
|
Then the md export CLI result code should be zero
|
|
And the md export CLI output should include "# Session:"
|
|
|
|
Scenario: Export session as Markdown to file
|
|
Given there is a mocked session for markdown export
|
|
When I run session CLI export with --format md to a temp file
|
|
Then the md export CLI result code should be zero
|
|
And the exported markdown file should exist
|
|
And the exported markdown file should contain "# Session:"
|
|
|
|
Scenario: Export session as JSON (default format)
|
|
Given there is a mocked session for markdown export
|
|
When I run session CLI export with no format flag
|
|
Then the md export CLI result code should be zero
|
|
And the md export CLI output should be parseable as JSON
|
|
|
|
Scenario: Export with invalid format flag returns error
|
|
Given there is a mocked session for markdown export
|
|
When I run session CLI export with --format xml
|
|
Then the md export CLI result code should be nonzero
|
|
And the md export CLI output should include "Invalid format"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# TUI command router: /session export and /session import
|
|
# ---------------------------------------------------------------------------
|
|
|
|
Scenario: TUI session export command returns success message
|
|
Given a TUI command router with mocked session service for export
|
|
When I call TUI handle with "session export" for the current session
|
|
Then the TUI handle result should contain "Session exported"
|
|
|
|
Scenario: TUI session export with path writes file
|
|
Given a TUI command router with mocked session service for export
|
|
When I call TUI handle with "session export /tmp/tui_test_export.json" for the current session
|
|
Then the TUI handle result should contain "Session exported to"
|
|
And the tui exported file "/tmp/tui_test_export.json" should exist
|
|
|
|
Scenario: TUI session export with --format md returns success
|
|
Given a TUI command router with mocked session service for export
|
|
When I call TUI handle with "session export --format md" for the current session
|
|
Then the TUI handle result should contain "Session exported (MD)"
|
|
|
|
Scenario: TUI session export with invalid format returns error
|
|
Given a TUI command router with mocked session service for export
|
|
When I call TUI handle with "session export --format xml" for the current session
|
|
Then the TUI handle result should contain "Invalid format"
|
|
|
|
Scenario: TUI session import with valid file returns success
|
|
Given a TUI command router with mocked session service for import
|
|
And there is a valid JSON export file for TUI import
|
|
When I call TUI handle with "session import <path>" for the import file
|
|
Then the TUI handle result should contain "Session imported:"
|
|
|
|
Scenario: TUI session import with no path returns usage
|
|
Given a TUI command router with mocked session service for import
|
|
When I call TUI handle with "session import" for the current session
|
|
Then the TUI handle result should be "Usage: /session:import <path>"
|
|
|
|
Scenario: TUI session import with non-existent file returns error
|
|
Given a TUI command router with mocked session service for import
|
|
When I call TUI handle with "session import /tmp/nonexistent_tui_file.json" for the current session
|
|
Then the TUI handle result should contain "File not found"
|
|
|
|
Scenario: TUI session import with invalid JSON returns error
|
|
Given a TUI command router with mocked session service for import
|
|
And there is an invalid JSON file for TUI import
|
|
When I call TUI handle with "session import <invalid_path>" for the import file
|
|
Then the TUI handle result should contain "Invalid JSON"
|