Files
cleveragents-core/features/plan_cli_uncovered_region_coverage.feature
hurui200320 1fda56b778
CI / lint (pull_request) Successful in 29s
CI / typecheck (pull_request) Successful in 58s
CI / quality (pull_request) Successful in 29s
CI / security (pull_request) Successful in 1m11s
CI / build (pull_request) Successful in 24s
CI / push-validation (pull_request) Successful in 21s
CI / helm (pull_request) Successful in 41s
CI / integration_tests (pull_request) Successful in 4m22s
CI / e2e_tests (pull_request) Successful in 4m39s
CI / unit_tests (pull_request) Successful in 9m51s
CI / coverage (pull_request) Successful in 13m30s
CI / docker (pull_request) Successful in 1m23s
CI / status-check (pull_request) Successful in 2s
fix(cli): implement plan diff --correction to show real correction attempt diff
Implement spec-compliant correction diff output for `agents plan diff
--correction <CORRECTION_ATTEMPT_ID>`. Fixes the following issues from
the cycle-1 PR review:

- C1/M1: Replace direct `unit_of_work.correction_attempts` access with
  the proper `unit_of_work.transaction()` context manager, eliminating
  the AttributeError crash and the resource (session) leak.
- C2: Add `unit_of_work: UnitOfWork | None = None` constructor parameter
  to `PlanApplyService` and wire it in `_get_apply_service()` via
  `container.unit_of_work()`, removing the illegal `get_container()`
  call inside the method body (ADR-003 DI violation).
- C3: Replace metadata serialization stub with a three-section structured
  diff (Correction Diff summary, Comparison table, Patch Preview) as
  specified in §agents plan diff of the specification.
- C4/M2: Add `features/plan_correction_diff.feature` with 6 BDD
  scenarios covering all 4 output formats plus plan-not-found and
  correction-not-found error paths.
- C5: Update the three existing BDD scenarios that tested old stub
  behavior to mock `_get_apply_service()` and assert the new output.
- C6: Rename branch to `bugfix/m4-plan-diff-correction-stub` per
  CONTRIBUTING.md convention.
- C7: Amend commit message with body and ISSUES CLOSED footer.
- C8: Narrow `except Exception` to `except CorrectionAttemptNotFoundError`
  to avoid masking programming errors.
- M3: Add `robot/plan_correction_diff.robot` and
  `robot/helper_plan_correction_diff.py` integration test covering rich,
  plain, and JSON formats and the not-found error path.
- M4: Type `_build_correction_diff_dict` parameter as
  `CorrectionAttemptRecord` instead of `Any`.
- M5: Change `fmt: str` to `fmt: Literal["rich", "plain", "json", "yaml"]`
  on both `diff()` and `correction_diff()`, with a `cast()` call in the
  CLI layer where Typer supplies a plain `str`.
- M6: Add `ValueError` guards for empty `plan_id` and
  `correction_attempt_id` at the top of `correction_diff()`.
- M7: Add blank line between `diff()` and `correction_diff()` method
  definitions.
- M8: Update PR description to reflect actual implementation.
- m1: Remove unused `plan` variable in `correction_diff()`.
- m2: Reduce three blank lines to two between top-level definitions in
  `plan_apply_service.py`.
- n1: Remove trailing whitespace from blank line in `plan.py`.

Quality gates: lint (ruff), typecheck (pyright strict), unit_tests
(Behave 632 features / 0 failures) all pass.

ISSUES CLOSED: #9085
2026-04-17 08:34:33 +00:00

197 lines
11 KiB
Gherkin

Feature: Plan CLI uncovered region coverage (lines 1950-2273)
As a developer
I want targeted tests for the uncovered lines and branches in plan.py
So that coverage gaps at lines 1950-1954, 1956-1957, 2132, 2135-2143,
2146-2184, 2202-2233, and 2231-2273 are closed
# ===================================================================
# list_plans empty result after filtering (lines 1950-1954)
# ===================================================================
Scenario: uncov-rgn list shows "No plans found" when action filter excludes all
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn lifecycle service returns plans that do not match an action filter
When I uncov-rgn invoke list with action filter "nonexistent/action"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "No plans found"
# ===================================================================
# list_plans — non-rich format output (lines 1956-1957)
# ===================================================================
Scenario: uncov-rgn list outputs JSON when format is json
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn lifecycle service returns a single plan for listing
When I uncov-rgn invoke list with format "json"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "plan_id"
Scenario: uncov-rgn list outputs YAML when format is yaml
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn lifecycle service returns a single plan for listing
When I uncov-rgn invoke list with format "yaml"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "plan_id"
# ===================================================================
# revert_plan — CleverAgentsError handler (line 2132)
# ===================================================================
Scenario: uncov-rgn revert_plan raises CleverAgentsError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn lifecycle service revert raises CleverAgentsError
When I uncov-rgn invoke revert for plan "01ARZ3NDEKTSV4RRFFQ69G5FAA"
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Error"
# ===================================================================
# _get_apply_service — function body (lines 2136-2143)
# ===================================================================
Scenario: uncov-rgn _get_apply_service creates a PlanApplyService instance
Given an uncov-rgn mocked lifecycle service for apply service creation
When I uncov-rgn call _get_apply_service directly
Then the uncov-rgn apply service should be returned successfully
# ===================================================================
# plan_diff — correction parameter branch (lines 2149-2184)
# ===================================================================
Scenario: uncov-rgn plan diff with correction flag shows correction diff output
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service correction_diff returns formatted output for "CORR-001"
When I uncov-rgn invoke diff for plan "PLAN-001" with correction "CORR-001"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "Correction Diff"
And the uncov-rgn output should contain "CORR-001"
Scenario: uncov-rgn plan diff without correction calls apply service
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service diff returns formatted output "--- a/main.py"
When I uncov-rgn invoke diff for plan "PLAN-002" without correction
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "main.py"
Scenario: uncov-rgn plan diff raises PlanError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service diff raises PlanError "missing changeset"
When I uncov-rgn invoke diff for plan "PLAN-003" without correction
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Diff Error"
Scenario: uncov-rgn plan diff raises CleverAgentsError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service diff raises CleverAgentsError "service down"
When I uncov-rgn invoke diff for plan "PLAN-004" without correction
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Error"
# ===================================================================
# plan_artifacts — full command coverage (lines 2202-2233)
# ===================================================================
Scenario: uncov-rgn plan artifacts success in rich format
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service artifacts returns "changeset-id: cs-100"
When I uncov-rgn invoke artifacts for plan "PLAN-005" in rich format
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "cs-100"
Scenario: uncov-rgn plan artifacts success in json format
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service artifacts returns '{"changeset": "cs-200"}'
When I uncov-rgn invoke artifacts for plan "PLAN-006" with format "json"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "cs-200"
Scenario: uncov-rgn plan artifacts raises PlanError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service artifacts raises PlanError "no changeset"
When I uncov-rgn invoke artifacts for plan "PLAN-007" in rich format
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Artifacts Error"
Scenario: uncov-rgn plan artifacts raises CleverAgentsError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn apply service artifacts raises CleverAgentsError "timeout"
When I uncov-rgn invoke artifacts for plan "PLAN-008" in rich format
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Error"
# ===================================================================
# correct_decision — full command coverage (lines 2231-2273+)
# ===================================================================
Scenario: uncov-rgn correct revert with --yes succeeds in rich format
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service returns a revert result with reverted decisions
When I uncov-rgn invoke correct in revert mode with --yes and guidance "Use Flask instead"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "Correction applied"
And the uncov-rgn output should contain "Reverted"
Scenario: uncov-rgn correct append with --yes succeeds in rich format
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service returns an append result with new decisions
When I uncov-rgn invoke correct in append mode with --yes and guidance "Add caching layer"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "Correction applied"
And the uncov-rgn output should contain "New decisions"
Scenario: uncov-rgn correct revert with --yes succeeds in json format
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service returns a revert result with reverted decisions
When I uncov-rgn invoke correct in revert mode with --yes, format "json", and guidance "Refactor"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "correction_id"
And the uncov-rgn output should contain "reverted_decisions"
Scenario: uncov-rgn correct dry-run in rich format shows impact panel
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service returns an impact analysis
When I uncov-rgn invoke correct in dry-run mode with rich format and guidance "Preview changes"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "Correction Impact"
And the uncov-rgn output should contain "Dry Run"
Scenario: uncov-rgn correct dry-run in json format shows impact data
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service returns an impact analysis
When I uncov-rgn invoke correct in dry-run mode with format "json" and guidance "Check impact"
Then the uncov-rgn command should exit normally
And the uncov-rgn output should contain "correction_id"
And the uncov-rgn output should contain "risk_level"
Scenario: uncov-rgn correct raises ResourceNotFoundError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service request raises ResourceNotFoundError
When I uncov-rgn invoke correct in revert mode with --yes and guidance "Fix something"
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Not found"
Scenario: uncov-rgn correct raises ValidationError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service request raises ValidationError
When I uncov-rgn invoke correct in revert mode with --yes and guidance "Validate me"
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Validation Error"
Scenario: uncov-rgn correct raises CleverAgentsError
Given an uncov-rgn CLI runner and mocked lifecycle service
And the uncov-rgn correction service request raises CleverAgentsError
When I uncov-rgn invoke correct in revert mode with --yes and guidance "General error"
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Error"
Scenario: uncov-rgn correct with invalid mode aborts
Given an uncov-rgn CLI runner and mocked lifecycle service
When I uncov-rgn invoke correct with invalid mode "rollback" and guidance "test"
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "Invalid mode"
Scenario: uncov-rgn correct with empty guidance aborts
Given an uncov-rgn CLI runner and mocked lifecycle service
When I uncov-rgn invoke correct with valid mode "revert" and empty guidance
Then the uncov-rgn command should abort
And the uncov-rgn output should contain "guidance"