forked from HAL9000/cleveragents-core
297823c291
Implement three new actor context subcommands as specified in the v3 CLI specification: - `agents actor context remove [--yes|-y] (--all|-a|<NAME>)`: Remove a named context or all contexts with interactive confirmation. Supports --all for bulk removal and --yes to skip prompts. - `agents actor context export (--output|-o) <FILE> <NAME>`: Export a named context to JSON or YAML (detected from file extension). Includes sha256 integrity checksum in output metadata. - `agents actor context import [--update] (--input|-i) <FILE> [<NAME>]`: Import a context from JSON or YAML. Name is inferred from file metadata if omitted. Refuses to overwrite existing contexts unless --update is specified. All commands: - Support 6 output formats (json, yaml, plain, table, rich, color) via the shared format_output framework - Use ContextManager for persistence (messages, metadata, state, global_context) - Follow existing error handling patterns (typer.Exit for user errors) - Are wired as `agents actor context` subcommand group via add_typer New files: - src/cleveragents/cli/commands/actor_context.py (command module) - features/actor_context_cmds.feature (Behave BDD scenarios) - features/steps/actor_context_cmds_steps.py (BDD step definitions) - robot/actor_context_export_import.robot (Robot integration test) ISSUES CLOSED: #869
122 lines
6.0 KiB
Plaintext
122 lines
6.0 KiB
Plaintext
*** Settings ***
|
|
Documentation Integration test for actor context export-then-import round-trip
|
|
Library Process
|
|
Library OperatingSystem
|
|
Library String
|
|
Library DateTime
|
|
Library Collections
|
|
Resource ${CURDIR}/common.resource
|
|
Suite Setup Setup Test Environment
|
|
Suite Teardown Cleanup Test Environment
|
|
|
|
*** Variables ***
|
|
${TEST_CTX_DIR} ${EMPTY}
|
|
${EXPORT_FILE} ${EMPTY}
|
|
${CONTEXT_NAME} roundtrip-robot
|
|
|
|
*** Test Cases ***
|
|
Export Then Import Round-Trip Preserves Context
|
|
[Documentation] Create a context, export it, delete it, import it, and verify data integrity.
|
|
|
|
# 1. Create a named context by running actor with --context
|
|
${ctx_dir} = Set Variable ${TEMP}/actor_ctx
|
|
Set Suite Variable ${TEST_CTX_DIR} ${ctx_dir}
|
|
Create Directory ${ctx_dir}
|
|
|
|
# Create context data manually via Python helper
|
|
${result} = Run Process ${PYTHON} -c
|
|
... from cleveragents.reactive.context_manager import ContextManager; mgr \= ContextManager("${CONTEXT_NAME}", "${ctx_dir}"); mgr.add_message("user", "Hello from Robot"); mgr.add_message("assistant", "Hello Robot!"); print("created")
|
|
Log Create stdout: ${result.stdout}
|
|
Log Create stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} created
|
|
|
|
# 2. Export the context to JSON
|
|
${export_path} = Set Variable ${TEMP}/exported-context.json
|
|
Set Suite Variable ${EXPORT_FILE} ${export_path}
|
|
|
|
${result} = Run Process ${PYTHON} -m cleveragents actor context export
|
|
... ${CONTEXT_NAME} --output ${export_path} --context-dir ${ctx_dir}
|
|
Log Export stdout: ${result.stdout}
|
|
Log Export stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
File Should Exist ${export_path}
|
|
|
|
# 3. Remove the original context
|
|
${result} = Run Process ${PYTHON} -m cleveragents actor context remove
|
|
... ${CONTEXT_NAME} --yes --context-dir ${ctx_dir}
|
|
Log Remove stdout: ${result.stdout}
|
|
Log Remove stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Directory Should Not Exist ${ctx_dir}/${CONTEXT_NAME}
|
|
|
|
# 4. Import the context back
|
|
${result} = Run Process ${PYTHON} -m cleveragents actor context import
|
|
... ${CONTEXT_NAME} --input ${export_path} --context-dir ${ctx_dir}
|
|
Log Import stdout: ${result.stdout}
|
|
Log Import stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
|
|
# 5. Verify the round-trip preserved messages
|
|
${result} = Run Process ${PYTHON} -c
|
|
... import json; from cleveragents.reactive.context_manager import ContextManager; mgr \= ContextManager("${CONTEXT_NAME}", "${ctx_dir}"); msgs \= mgr.messages; assert len(msgs) \=\= 2, f"Expected 2 messages, got {len(msgs)}"; assert msgs[0]["content"] \=\= "Hello from Robot"; assert msgs[1]["content"] \=\= "Hello Robot!"; print("verified")
|
|
Log Verify stdout: ${result.stdout}
|
|
Log Verify stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} verified
|
|
|
|
Export With JSON Format Flag Shows Structured Output
|
|
[Documentation] Verify --format json produces machine-readable output.
|
|
|
|
${ctx_dir} = Set Variable ${TEMP}/actor_ctx_fmt
|
|
Create Directory ${ctx_dir}
|
|
|
|
# Create context
|
|
${result} = Run Process ${PYTHON} -c
|
|
... from cleveragents.reactive.context_manager import ContextManager; mgr \= ContextManager("fmt-test", "${ctx_dir}"); mgr.add_message("user", "test"); print("ok")
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
|
|
# Export with --format json
|
|
${export_path} = Set Variable ${TEMP}/fmt-export.json
|
|
${result} = Run Process ${PYTHON} -m cleveragents actor context export
|
|
... fmt-test --output ${export_path} --context-dir ${ctx_dir} --format json
|
|
Log Export stdout: ${result.stdout}
|
|
Log Export stderr: ${result.stderr}
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
Should Contain ${result.stdout} context_export
|
|
|
|
Import Without Update Fails For Existing Context
|
|
[Documentation] Verify importing into an existing context without --update fails.
|
|
|
|
${ctx_dir} = Set Variable ${TEMP}/actor_ctx_noupdate
|
|
Create Directory ${ctx_dir}
|
|
|
|
# Create existing context
|
|
${result} = Run Process ${PYTHON} -c
|
|
... from cleveragents.reactive.context_manager import ContextManager; mgr \= ContextManager("existing", "${ctx_dir}"); mgr.add_message("user", "original"); print("ok")
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
|
|
# Create import file
|
|
${import_path} = Set Variable ${TEMP}/existing-import.json
|
|
${result} = Run Process ${PYTHON} -c
|
|
... import json; data \= {"context_name": "existing", "messages": [{"role": "user", "content": "new", "timestamp": "2026-01-01", "metadata": {}}], "metadata": {}, "state": {}, "global_context": {}}; open("${import_path}", "w").write(json.dumps(data)); print("ok")
|
|
Should Be Equal As Integers ${result.rc} 0
|
|
|
|
# Import without --update should fail
|
|
${result} = Run Process ${PYTHON} -m cleveragents actor context import
|
|
... existing --input ${import_path} --context-dir ${ctx_dir}
|
|
Should Be Equal As Integers ${result.rc} 1
|
|
|
|
*** Keywords ***
|
|
Setup Test Environment
|
|
[Documentation] Create test environment
|
|
common.Setup Test Environment
|
|
${temp} = Evaluate tempfile.mkdtemp() modules=tempfile
|
|
Set Suite Variable ${TEMP} ${temp}
|
|
Create Directory ${TEMP}
|
|
Log Test environment created at: ${TEMP}
|
|
|
|
Cleanup Test Environment
|
|
[Documentation] Clean up test environment
|
|
Run Keyword If '${TEMP}' != '${EMPTY}' Remove Directory ${TEMP} recursive=True
|