Files
cleveragents-core/tests/features/context_manager.feature

159 lines
7.1 KiB
Gherkin

Feature: Context Manager for CLI Sessions
As a user of CleverAgents
I want to save and restore conversation contexts
So that I can have stateful interactions across CLI runs
Background:
Given I have a temporary test directory for contexts
Scenario: Create a new context manager
When I create a context manager with name "test-session"
Then the context manager should be initialized
And the context directory should exist
And the context files should be created
Scenario: Save and load messages
Given I have a context manager with name "chat-session"
When I add a user message "Hello, how are you?"
And I add an assistant message "I'm doing well, thank you!"
And I save the context
Then the messages should be persisted to disk
When I create a new context manager with the same name "chat-session"
Then the loaded messages should match the saved messages
Scenario: Save and restore global context
Given I have a context manager with name "stateful-session"
When I save global context with key "writing_stage" and value "planning"
And I save global context with key "document_type" and value "research_paper"
Then the global context should be persisted to disk
When I reload the context manager
Then the global context should contain "writing_stage" with value "planning"
And the global context should contain "document_type" with value "research_paper"
Scenario: Update existing context state
Given I have a context manager with name "update-session"
And the context has state "current_task" with value "writing"
When I update the state "current_task" to "reviewing"
And I add metadata "last_update" with current timestamp
Then the state should be updated
And the metadata should contain the timestamp
Scenario: Get last N messages from history
Given I have a context manager with name "history-session"
And I have added 10 messages to the conversation
When I request the last 5 messages
Then I should receive exactly 5 messages
And the messages should be the most recent ones
Scenario: Clear conversation history
Given I have a context manager with name "clear-session"
And the context has 5 messages in history
When I clear the context
Then the message history should be empty
But the context directory should still exist
Scenario: Delete entire context
Given I have a context manager with name "delete-session"
And the context has messages and state data
When I delete the context
Then the context directory should not exist
And attempting to load the context should indicate it doesn't exist
Scenario: List available contexts
Given I have created contexts named "context1", "context2", "context3"
When I list all contexts
Then the list should contain "context1", "context2", "context3"
And the list should be sorted alphabetically
Scenario: Export and import context
Given I have a context manager with name "export-session"
And the context has messages, state, and global context data
When I export the context to a file
Then the export file should contain all context data
When I import the context as "import-session"
Then the imported context should match the original
Scenario: Get formatted conversation history
Given I have a context manager with name "format-session"
And I have added messages with timestamps
When I get formatted history without metadata
Then the output should show timestamps, roles, and content
When I get formatted history with metadata
Then the output should include metadata information
Scenario: Handle non-existent context gracefully
When I create a context manager with name "new-session"
And I check if the context exists
Then it should indicate the context doesn't exist
When I try to get messages from the empty context
Then it should return an empty list
Scenario: Preserve context across CLI runs
Given I run the CLI with context "persistent-session" and prompt "What is Python?"
When the assistant responds with information about Python
And I run the CLI again with the same context and prompt "Tell me more"
Then the second response should reference the previous conversation
Scenario: Tool agent context updates are captured
Given I have a context manager tool agent with Python code that updates context
When the tool executes code that sets context["writing_stage"] to "drafting"
Then the global context updates should be captured
And the context should persist after execution
Scenario: Context updates through stream routing
Given I have a reactive stream router with context-aware agents
When a message flows through the stream with context metadata
And agents modify the context during processing
Then all context modifications should be preserved
And the final context should reflect all changes
Scenario: CLI context command - list contexts
When I run the CLI command "context list"
Then it should display all available contexts
Scenario: CLI context command - show specific context
Given I have a context "cli-test" with conversation history
When I run the CLI command "context show cli-test"
Then it should display the conversation history
When I run the CLI command "context show cli-test --last 3"
Then it should display only the last 3 messages
Scenario: CLI context command - clear context
Given I have a context "cli-clear" with data
When I run the CLI command "context clear cli-clear" with confirmation
Then the context should be cleared
And the context directory should still exist
Scenario: CLI context command - delete context
Given I have a context "cli-delete" with data
When I run the CLI command "context delete cli-delete" with confirmation
Then the context should be deleted
And the context directory should not exist
Scenario: CLI context command - export and import
Given I have a context "cli-export" with data
When I run the CLI command "context export cli-export output.json"
Then the export file "output.json" should be created
When I run the CLI command "context import cli-import output.json"
Then the context "cli-import" should exist with the same data
Scenario: Run with context and conversation history
Given an application with simple config for context
When running with 15 message conversation history
Then only last 10 messages are used
And prompt is formatted with history
Scenario: Run with context and long assistant response
Given an application with simple config for context
When running with 600 character assistant response
Then response is truncated to 500 characters
Scenario: Run with context without history
Given an application with simple config for context
When running with no conversation history
Then prompt is used without modification
Scenario: Temperature override in global context
Given a config file path for context
When creating app with temperature override 0.8
Then global context contains temperature value 0.8