forked from HAL9000/cleveragents-core
89c215e62c
Implemented a rich output upgrade for the agents plan rollback in the CLI by replacing the previous plain-text output in rollback_plan() with a set of four spec-required Rich panels. - Rollback Summary panel: includes Plan, Checkpoint, Label (only if available), and Files fields. - Changes Reverted panel: a Rich table with File and Action columns; supports both dict entries and plain string paths for forward compatibility with issue #2454. - Impact panel: shows Sandbox state and optional fields Child Plans Invalidated, Decisions After CP, Tool Calls After CP. - Post-Rollback State panel: includes Phase, State, and optional Checkpoints Remaining fields. - Confirmation line: "✓ OK Rollback complete" displayed after the panels. - Tests updated: Updated BDD test assertions in features/plan_cli_coverage_r2.feature to align with new panel-based output. Key design decisions: - Used getattr(result, field, None) pattern for optional fields not yet present in RollbackResult model (fields: label, child_plans_invalidated, decisions_after_cp, tool_calls_after_cp, phase, state, checkpoints_remaining) to support forward-compatibility as fields get added. - Handling mixed formats in changed_paths/changes_reverted: both dict-format entries and string-format paths are supported to remain compatible with issue #2454. - Sandbox state defaults to "restored to {checkpoint_id}" when not explicitly provided. Files changed: - src/cleveragents/cli/commands/plan.py (rollback_plan rich output section) - features/plan_cli_coverage_r2.feature (updated test assertions) ISSUES CLOSED: #2591
228 lines
10 KiB
Gherkin
228 lines
10 KiB
Gherkin
Feature: Plan CLI coverage round 2 – remaining uncovered lines
|
||
As a developer
|
||
I want to exercise the remaining uncovered lines in plan.py
|
||
So that coverage gaps at lines 724, 737-741, 832-833, 879-883,
|
||
930-931, 1007-1008, 1094-1095, 1108-1115, 1223-1245,
|
||
1469-1481, 1565-1578, 2588-2598, 2616-2618, 2691-2762 are closed
|
||
|
||
# ===================================================================
|
||
# Legacy build command — >5 changes truncation (line 724)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy build shows truncation message when more than 5 changes
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov build returning 8 changes
|
||
When I invoke r2cov legacy build
|
||
Then the r2cov command should exit normally
|
||
And the r2cov output should contain "and 3 more"
|
||
|
||
# ===================================================================
|
||
# Legacy build command — PlanError handler (lines 737-738)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy build raises PlanError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov build that raises PlanError
|
||
When I invoke r2cov legacy build
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Build Error"
|
||
|
||
# ===================================================================
|
||
# Legacy build command — CleverAgentsError handler (lines 740-741)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy build raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov build that raises CleverAgentsError
|
||
When I invoke r2cov legacy build
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
# ===================================================================
|
||
# Legacy new command — ValidationError handler (lines 879-880)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy new raises ValidationError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov new that raises ValidationError
|
||
When I invoke r2cov legacy new "bad-name"
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Validation Error"
|
||
|
||
# ===================================================================
|
||
# Legacy new command — CleverAgentsError handler (lines 882-883)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy new raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov new that raises CleverAgentsError
|
||
When I invoke r2cov legacy new "bad-name"
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
# ===================================================================
|
||
# Legacy current command — CleverAgentsError handler (lines 930-931)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy current raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov current that raises CleverAgentsError
|
||
When I invoke r2cov legacy current
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
# ===================================================================
|
||
# Legacy continue command — CleverAgentsError handler (lines 1094-1095)
|
||
# ===================================================================
|
||
|
||
Scenario: Legacy continue raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked legacy container for r2cov continue that raises CleverAgentsError
|
||
When I invoke r2cov legacy continue
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
# ===================================================================
|
||
# _get_lifecycle_service body (lines 1108-1115)
|
||
# ===================================================================
|
||
|
||
Scenario: _get_lifecycle_service creates a PlanLifecycleService
|
||
Given a r2cov CLI runner
|
||
And a mocked container for r2cov lifecycle service construction
|
||
When I call r2cov _get_lifecycle_service
|
||
Then the r2cov lifecycle service should be returned
|
||
|
||
# ===================================================================
|
||
# Multi-project scopes in _print_lifecycle_plan (lines 1223-1245)
|
||
# ===================================================================
|
||
|
||
Scenario: Lifecycle plan display with multi-project scopes and changeset summaries
|
||
Given a r2cov CLI runner
|
||
And a lifecycle plan with multi-project scopes for r2cov
|
||
When I invoke r2cov _print_lifecycle_plan on the plan
|
||
Then the r2cov output should contain "Multi-Project Scopes"
|
||
And the r2cov output should contain "proj-alpha"
|
||
And the r2cov output should contain "Changed:"
|
||
|
||
Scenario: Multi-project scopes with validation passed and failed
|
||
Given a r2cov CLI runner
|
||
And a lifecycle plan with multi-project scopes with validation for r2cov
|
||
When I invoke r2cov _print_lifecycle_plan on the plan
|
||
Then the r2cov output should contain "Validation"
|
||
And the r2cov output should contain "PASSED"
|
||
|
||
# ===================================================================
|
||
# use_action — execution_environment validation (lines 1469-1481)
|
||
# ===================================================================
|
||
|
||
Scenario: use_action rejects invalid execution_environment
|
||
Given a r2cov CLI runner
|
||
And a mocked lifecycle service for r2cov use action
|
||
When I invoke r2cov use with execution-environment "invalid_env"
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Invalid execution environment"
|
||
|
||
Scenario: use_action accepts valid execution_environment
|
||
Given a r2cov CLI runner
|
||
And a mocked lifecycle service for r2cov use action
|
||
When I invoke r2cov use with execution-environment "container"
|
||
Then the r2cov command should exit normally
|
||
|
||
# ===================================================================
|
||
# execute_plan — execution_environment validation (lines 1565-1578)
|
||
# ===================================================================
|
||
|
||
Scenario: execute_plan rejects invalid execution_environment
|
||
Given a r2cov CLI runner
|
||
And a mocked lifecycle service for r2cov execute with a valid plan
|
||
When I invoke r2cov execute with execution-environment "badenv"
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Invalid execution environment"
|
||
|
||
Scenario: execute_plan accepts valid execution_environment
|
||
Given a r2cov CLI runner
|
||
And a mocked lifecycle service for r2cov execute with a valid plan
|
||
When I invoke r2cov execute with execution-environment "host"
|
||
Then the r2cov command should exit normally
|
||
|
||
# ===================================================================
|
||
# resume_plan rich output branches (lines 2588, 2593, 2598)
|
||
# ===================================================================
|
||
|
||
Scenario: Resume plan rich output shows decision_id, checkpoint, and sandbox_ref
|
||
Given a r2cov CLI runner
|
||
And a mocked resume service for r2cov with all optional fields
|
||
When I invoke r2cov plan resume "PLAN123" in rich format
|
||
Then the r2cov command should exit normally
|
||
And the r2cov output should contain "Decision ID"
|
||
And the r2cov output should contain "Checkpoint"
|
||
And the r2cov output should contain "Sandbox"
|
||
|
||
# ===================================================================
|
||
# resume_plan — CleverAgentsError handler (lines 2616-2618)
|
||
# ===================================================================
|
||
|
||
Scenario: Resume plan raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked resume service for r2cov that raises CleverAgentsError
|
||
When I invoke r2cov plan resume "PLAN123" in rich format
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
# ===================================================================
|
||
# rollback_plan — full command body (lines 2691-2762)
|
||
# ===================================================================
|
||
|
||
Scenario: Rollback plan succeeds with --yes flag in rich format
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that succeeds
|
||
When I invoke r2cov plan rollback with --yes
|
||
Then the r2cov command should exit normally
|
||
And the r2cov output should contain "Rollback Summary"
|
||
And the r2cov output should contain "Changes Reverted"
|
||
And the r2cov output should contain "Impact"
|
||
And the r2cov output should contain "Post-Rollback State"
|
||
And the r2cov output should contain "Rollback complete"
|
||
|
||
Scenario: Rollback plan succeeds in json format
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that succeeds
|
||
When I invoke r2cov plan rollback with --yes and --format json
|
||
Then the r2cov command should exit normally
|
||
And the r2cov output should contain "rollback_summary"
|
||
|
||
Scenario: Rollback plan raises BusinessRuleViolation
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that raises BusinessRuleViolation
|
||
When I invoke r2cov plan rollback with --yes
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Rollback blocked"
|
||
|
||
Scenario: Rollback plan raises ResourceNotFoundError
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that raises ResourceNotFoundError
|
||
When I invoke r2cov plan rollback with --yes
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Not found"
|
||
|
||
Scenario: Rollback plan raises ValidationError
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that raises ValidationError
|
||
When I invoke r2cov plan rollback with --yes
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Validation Error"
|
||
|
||
Scenario: Rollback plan raises CleverAgentsError
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that raises CleverAgentsError
|
||
When I invoke r2cov plan rollback with --yes
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Error"
|
||
|
||
Scenario: Rollback plan cancelled when user declines confirmation
|
||
Given a r2cov CLI runner
|
||
And a mocked checkpoint service for r2cov rollback that succeeds
|
||
When I invoke r2cov plan rollback without --yes and decline
|
||
Then the r2cov command should abort
|
||
And the r2cov output should contain "Rollback cancelled"
|