Files
cleveragents-core/robot/scientific_paper_e2e_test.robot
CoreRasurae e4c01492d5 refactor(cli): align actor run signature with spec positional args
Aligned the `agents actor run` command signature with the
specification by introducing positional NAME and PROMPT arguments.
The --config/-c option is preserved as an optional fallback for
direct YAML invocation. When NAME is provided without --config,
the actor is resolved from the Actor Registry.

Updated both actor_run.py and actor.py run commands. Added backward
compatibility: if --config is provided, it takes precedence over
name-based resolution.

Review fixes applied (code review round 1):
- P1-1: Narrowed bare `except Exception` to `except NotFoundError`
  in _resolve_config_files to avoid masking infrastructure errors.
- P1-2: Moved _resolve_config_files call inside the try block in
  run() so container/registry init errors get user-friendly messages.
  Added `except click.exceptions.Exit: raise` to let typer.Exit
  propagate through the broadened try scope.
- P1-3: Added atexit.register cleanup for temp files created by
  _resolve_config_files (resource leak fix).
- P1-4: Added CHANGELOG.md entry for the breaking CLI change.
- P2-1: Extracted duplicated _resolve_config_files to shared module
  `_resolve_actor.py`; both actor.py and actor_run.py now import it.
- P2-2: Added guard for actors with no configuration data
  (config_blob=None) to produce a clear error instead of invalid YAML.
- P2-3/P2-4: Added 5 BDD scenarios exercising the real
  resolve_config_files function (registry path, yaml_text path,
  config_blob fallback, no-config-data error, not-found error).
- P2-5: Added @coverage tags to all new BDD scenarios.
- P3-1: Added timeout=120s and on_timeout=kill to Robot tests.
- Fixed rxpy_route_validation.robot tests that used the removed
  --prompt/-p option (replaced with positional NAME + PROMPT args).

Review fixes applied (code review round 2):
- P2-1: Aligned actor_run.py exception handler from
  `CleverAgentsException` to `CleverAgentsError`, matching actor.py
  so infrastructure errors from registry resolution get user-friendly
  messages instead of falling through to the generic handler.
- P2-2: Changed `yaml.dump` to `yaml.safe_dump` in _resolve_actor.py
  for fail-fast behavior on unexpected types, consistent with the
  codebase's dominant pattern.
- P3-6: Replaced defensive `getattr(actor, ...)` calls with direct
  Pydantic model attribute access (`actor.yaml_text`, `actor.config_blob`)
  for type-checker coverage.
- P3-1: Switched BDD temp file cleanup from post-assertion
  `unlink()` to `context.add_cleanup()` for leak-proof teardown.
- P2-3/P3-2/P3-3/P3-4: Added 3 BDD edge-case scenarios
  (empty config_blob dict, infrastructure error propagation, empty
  string name) and 1 Robot test case (actor_app registry resolution).

Review fixes applied (code review round 3):
- P1-1: Migrated 48 remaining `-p` invocations across 9 Robot test
  files to the new positional `NAME PROMPT` pattern (context_delete_all_yes,
  load_context_test, scientific_paper_e2e_test, routing_prefix_stripping,
  scientific_paper_basic, scientific_paper_writer_test,
  context_management_test, initial_next_command_test,
  system_prompt_template_rendering).
- P2-1: Documented `--config/-c` as a spec deviation in
  `_resolve_actor.py` module docstring (spec lines 4562-4566 define
  `actor run` with no --config option; issue #901 AC accepts keeping
  it as optional).
- P2-2: Corrected `--config` help text from "fallback" to "overrides
  registry-based name resolution" — the option takes precedence, not
  the other way around.
- P3-1: Added `.strip()` to `yaml_text` emptiness check in
  `_resolve_actor.py` to handle whitespace-only values that would
  otherwise bypass the `config_blob` fallback.
- P3-2: Added `from None` to the no-configuration-data
  `typer.Exit(code=2)` for consistency with the not-found path.
- P3-3: Added BDD scenario testing `--config` precedence for
  `actor_run_app` (was only tested for `actor_app`).
- P3-4: Strengthened config_blob BDD scenario to verify generated
  YAML is parseable via `yaml.safe_load` round-trip.
- P3-7: Replaced hardcoded `/tmp/dummy.yaml` with
  `tempfile.gettempdir()` for portability.
- P3-8: Moved 5 inline imports to module level per CONTRIBUTING.md
  §1292-1294 (3x `import click`, 1x InfrastructureError in steps;
  1x `import typer` in robot helper).
- P3-9: Added `encoding="utf-8"` to `_write_yaml` in Robot helper
  for consistency with production code.

Review fixes applied (code review round 4):
- P2-1: Wrapped `yaml.safe_dump` in `_resolve_actor.py` with
  `try/except yaml.YAMLError` so non-serialisable config_blob values
  produce a user-friendly error message instead of a raw traceback.
- P2-2: Moved remaining inline `import yaml` to module level in
  `actor_run_signature_steps.py` per CONTRIBUTING.md §1292-1294.
- P2-3: Replaced 3 bare `assert` statements in Robot helper
  `helper_actor_run_signature.py` with diagnostic `if/print/sys.exit`
  pattern matching the rest of the file, improving failure diagnostics.

Review fixes applied (code review round 5):
- P3-4: Replaced per-call `atexit.register(lambda)` in
  `_resolve_actor.py` with a module-level `_temp_files` set and a
  single `atexit` handler (`_cleanup_temp_files`) to prevent
  unbounded handler accumulation in same-process usage (e.g. test
  suites running multiple CliRunner invocations).
- P3-1/P3-2/P3-3: Added 4 BDD scenarios: whitespace-only
  `yaml_text` fallback to config_blob, config-precedence
  registry-not-consulted assertion for both `actor_app` and
  `actor_run_app`, multiple `--config` files with positional NAME.
- P4-1: Strengthened error-path BDD assertions to verify error
  message content (not-found, no-config-data, serialisation-error)
  alongside exit codes via captured stderr.
- P4-2: Added Robot test case for `actor_app` unknown-name error
  path and corresponding helper function.

ISSUES CLOSED: #901
2026-03-26 13:41:31 +00:00

262 lines
10 KiB
Plaintext

*** Settings ***
Documentation End-to-end integration test for Scientific Paper Writer
Library Process
Library OperatingSystem
Library String
Resource ${CURDIR}/v2_paths.resource
Suite Setup Setup Test Environment
Suite Teardown Cleanup Test Environment
*** Variables ***
${PYTHON} python
${CONFIG_FILE} ${CURDIR}/../examples/scientific_paper_writer.yaml
${CONTEXT_DIR} ${TEMPDIR}/paper_e2e_contexts
${CONTEXT_NAME} paper_e2e_${TEST_ID}
${TEST_ID} ${EMPTY}
*** Test Cases ***
Scientific Paper Writer Full Workflow
[Documentation] Test the complete workflow from intro through multiple stages
[Tags] integration e2e slow
[Timeout] 10 minutes
# Test 1: Intro stage
Log Testing intro stage...
${result}= Run Paper Command Hello
Should Contain ${result.stdout} Paper Writer
# Test 2: Advance to discovery
Log Advancing to discovery stage...
${result}= Run Paper Command !next discovery
Should Be Equal As Integers ${result.rc} 0
# Verify we're now in discovery stage
${stage_check}= Run Paper Command !stage
Should Contain ${stage_check.stdout} discovery
# Test 3: Commands work
Log Testing commands...
${result}= Run Paper Command !stages
Should Contain ${result.stdout} discovery
Should Contain ${result.stdout} brainstorming
# Test 4: Test help command
Log Testing help command...
${result}= Run Paper Command !help
Should Contain ${result.stdout} Available Commands
Should Contain ${result.stdout} !next
Should Contain ${result.stdout} !accept
# Test 5: Skip to brainstorming with mock data
Log Setting up mock paper details and advancing to brainstorming...
${result}= Run Paper Command !next brainstorming
Should Be Equal As Integers ${result.rc} 0
# Verify we're now in brainstorming stage
${stage_check}= Run Paper Command !stage
Should Contain ${stage_check.stdout} brainstorming
# Test 6: Test brainstorming stage
Log Testing brainstorming stage...
${result}= Run Paper Command I want to write about the impact of machine learning on healthcare, focusing on diagnostic imaging and patient outcomes timeout=90s
Length Should Be Greater Than ${result.stdout} 50
# Test 7: Verify stage may have advanced (brainstorming stage might auto-advance after LLM response)
# So we don't check for specific stage here anymore
# Test 8: Advance toward later stages (using structure or latex_generation as targets)
Log Advancing toward later stages...
${result}= Run Paper Command !next structure timeout=120s
Should Be Equal As Integers ${result.rc} 0
# Test 9: Verify stage list command works
Log Verifying stage list command...
${result}= Run Paper Command !stages
Should Contain ${result.stdout} structure
Should Contain ${result.stdout} latex_generation
Log End-to-end test completed successfully
Scientific Paper Writer LaTeX Generation
[Documentation] Test LaTeX generation using pre-populated context
[Tags] integration e2e latex code_blocks
[Timeout] 5 minutes
${ctx}= Set Variable latex_test_${TEST_ID}
# Import the brainstorming context fixture
Log Importing brainstorming context fixture...
${result}= Run Process ${PYTHON} -m cleveragents context import
... ${ctx}
... ${V2_PAPER_CONTEXTS_DIR}/03_brainstorming.json
... --context-dir ${CONTEXT_DIR}
... stderr=STDOUT
... timeout=30s
Should Be Equal As Integers ${result.rc} 0
Log Context imported: ${result.stdout}
# Advance to latex_generation stage
Log Advancing to latex_generation stage...
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !next latex_generation
... stderr=STDOUT
... timeout=180s
Should Be Equal As Integers ${result.rc} 0
# Note: Stage may auto-advance after !next is called
# Generate LaTeX document (send message that should trigger LaTeX generation)
# The exact stage doesn't matter - the system should generate LaTeX when asked
Log Generating LaTeX document...
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor Generate the complete LaTeX document
... stderr=STDOUT
... timeout=180s
Should Be Equal As Integers ${result.rc} 0
# System should produce SOME output (not just echo the input)
Should Not Be Equal ${result.stdout} Generate the complete LaTeX document
# Verify LaTeX structure
Log Verifying LaTeX document structure...
Should Contain ${result.stdout} \\documentclass
Should Contain ${result.stdout} \\begin{document}
Should Contain ${result.stdout} \\end{document}
Should Contain ${result.stdout} \\section
# Verify context was updated
Log Verifying context is accessible...
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !context
... stderr=STDOUT
... timeout=30s
Should Contain ${result.stdout} latex_source
Log LaTeX generation test completed
Scientific Paper Writer Stage Navigation
[Documentation] Test stage navigation and command processing
[Tags] integration commands code_blocks
[Timeout] 3 minutes
${ctx}= Set Variable stage_nav_${TEST_ID}
# Start at intro
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !stages
... stderr=STDOUT
... timeout=20s
Should Contain ${result.stdout} intro
# Test !next command
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !next
... stderr=STDOUT
... timeout=20s
Should Be Equal As Integers ${result.rc} 0
# Verify we advanced from intro (stage may auto-advance past discovery to brainstorming)
${stage_check}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !stage
... stderr=STDOUT
... timeout=20s
Should Not Contain ${stage_check.stdout} intro
# Test !help command
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !help
... stderr=STDOUT
... timeout=20s
Should Contain ${result.stdout} Available Commands
Should Contain ${result.stdout} !next
Should Contain ${result.stdout} !accept
# Test !stage command
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${ctx}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor !stage
... stderr=STDOUT
... timeout=20s
Should Contain ${result.stdout} Current Stage
Should Contain ${result.stdout} Purpose
*** Keywords ***
Setup Test Environment
${timestamp}= Get Time epoch
Set Suite Variable ${TEST_ID} ${timestamp}
Set Suite Variable ${CONTEXT_NAME} paper_e2e_${TEST_ID}
Create Directory ${CONTEXT_DIR}
Log Test environment setup complete with ID: ${TEST_ID}
Cleanup Test Environment
Run Keyword And Ignore Error Remove Directory ${CONTEXT_DIR} recursive=True
Log Test environment cleaned up
Run Paper Command
[Arguments] ${command} ${timeout}=30s
[Documentation] Run a command against the paper writer with the persistent context
${result}= Run Process ${PYTHON} -m cleveragents actor run
... -c ${CONFIG_FILE}
... --context ${CONTEXT_NAME}
... --context-dir ${CONTEXT_DIR}
... --unsafe
... --allow-rxpy-in-run-mode
... test-actor ${command}
... stderr=STDOUT
... timeout=${timeout}
Log Command: ${command}
Log Output: ${result.stdout}
RETURN ${result}
Should Contain Any
[Arguments] ${text} @{patterns}
[Documentation] Check if text contains at least one of the patterns
FOR ${pattern} IN @{patterns}
${status}= Run Keyword And Return Status Should Contain ${text} ${pattern} ignore_case=True
IF ${status} RETURN
END
Fail Text does not contain any of: @{patterns}
Length Should Be Greater Than
[Arguments] ${text} ${min_length}
[Documentation] Check if text length is greater than minimum
${length}= Get Length ${text}
Should Be True ${length} > ${min_length} Text length ${length} is not greater than ${min_length}