Files
cleveragents-core/features/plan_commands_new_coverage.feature
T
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

83 lines
3.8 KiB
Gherkin

Feature: Plan CLI commands new coverage
As a developer
I want to cover the remaining uncovered lines in plan.py
So that plan diff (with/without correction), plan artifacts, and _get_apply_service are fully tested
# ---------- plan diff with --correction flag ----------
Scenario: Plan diff with correction flag shows correction diff output
Given new_cov no service mocks are needed
When new_cov I run plan diff for "plan-100" with correction "corr-42"
Then new_cov the exit code should be 0
And new_cov the output should contain "Correction Diff"
And new_cov the output should contain "corr-42"
And new_cov the output should contain "orig-decision-001"
# ---------- plan diff without correction (lines 1869-1871) ----------
Scenario: Plan diff without correction calls service diff
Given new_cov the apply service diff returns "--- a/app.py\n+++ b/app.py\n@@ -1 +1 @@"
When new_cov I run plan diff for "plan-200"
Then new_cov the exit code should be 0
And new_cov the output should contain "app.py"
Scenario: Plan diff without correction with json format
Given new_cov the apply service diff returns '{"entries": [], "summary": {}}'
When new_cov I run plan diff for "plan-201" with format "json"
Then new_cov the exit code should be 0
And new_cov the output should contain "entries"
# ---------- plan diff error paths ----------
Scenario: Plan diff raises PlanError
Given new_cov the apply service diff raises PlanError "changeset missing"
When new_cov I run plan diff for "plan-bad"
Then new_cov the exit code should be nonzero
And new_cov the output should contain "Diff Error"
And new_cov the output should contain "changeset missing"
Scenario: Plan diff raises CleverAgentsError
Given new_cov the apply service diff raises CleverAgentsError "backend down"
When new_cov I run plan diff for "plan-err"
Then new_cov the exit code should be nonzero
And new_cov the output should contain "Error"
And new_cov the output should contain "backend down"
# ---------- plan artifacts (lines 1901-1904) ----------
Scenario: Plan artifacts calls service artifacts
Given new_cov the apply service artifacts returns "changeset_id: cs-999\nfiles: 3"
When new_cov I run plan artifacts for "plan-300"
Then new_cov the exit code should be 0
And new_cov the output should contain "cs-999"
Scenario: Plan artifacts with json format
Given new_cov the apply service artifacts returns '{"changeset_id": "cs-abc", "files": 5}'
When new_cov I run plan artifacts for "plan-301" with format "json"
Then new_cov the exit code should be 0
And new_cov the output should contain "cs-abc"
# ---------- plan artifacts error paths ----------
Scenario: Plan artifacts raises PlanError
Given new_cov the apply service artifacts raises PlanError "plan not found"
When new_cov I run plan artifacts for "plan-missing"
Then new_cov the exit code should be nonzero
And new_cov the output should contain "Artifacts Error"
And new_cov the output should contain "plan not found"
Scenario: Plan artifacts raises CleverAgentsError
Given new_cov the apply service artifacts raises CleverAgentsError "timeout"
When new_cov I run plan artifacts for "plan-timeout"
Then new_cov the exit code should be nonzero
And new_cov the output should contain "Error"
And new_cov the output should contain "timeout"
# ---------- _get_apply_service real body (lines 1817-1822) ----------
Scenario: _get_apply_service imports PlanApplyService and creates it
Given new_cov a mocked lifecycle service for apply service creation
When new_cov I call _get_apply_service directly
Then new_cov the returned object should be a PlanApplyService instance
And new_cov PlanApplyService was constructed with the lifecycle service