Files
cleveragents-core/features/plan_correction_diff.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

77 lines
4.7 KiB
Gherkin

Feature: Plan correction diff command
As a developer using the v3 plan lifecycle
I want to view a structured diff for a correction attempt
So that I can understand what changes a correction will introduce
# ---------- All 4 output formats ----------
Scenario: correction diff returns rich format output
Given correction-diff a mocked apply service returning rich correction diff
When correction-diff I run plan diff for "PLAN-001" with correction "CORR-001" format "rich"
Then correction-diff the exit code should be 0
And correction-diff the output should contain "Correction Diff"
And correction-diff the output should contain "CORR-001"
Scenario: correction diff returns plain format output
Given correction-diff a mocked apply service returning plain correction diff
When correction-diff I run plan diff for "PLAN-002" with correction "CORR-002" format "plain"
Then correction-diff the exit code should be 0
And correction-diff the output should contain "Correction Diff"
And correction-diff the output should contain "CORR-002"
Scenario: correction diff returns json format output
Given correction-diff a mocked apply service returning json correction diff for "CORR-003"
When correction-diff I run plan diff for "PLAN-003" with correction "CORR-003" format "json"
Then correction-diff the exit code should be 0
And correction-diff the output should contain "correction_diff"
And correction-diff the output should contain "CORR-003"
And correction-diff the service was called with format "json"
Scenario: correction diff returns yaml format output
Given correction-diff a mocked apply service returning yaml correction diff for "CORR-004"
When correction-diff I run plan diff for "PLAN-004" with correction "CORR-004" format "yaml"
Then correction-diff the exit code should be 0
And correction-diff the output should contain "correction_diff"
And correction-diff the output should contain "CORR-004"
And correction-diff the service was called with format "yaml"
# ---------- Error paths ----------
Scenario: correction diff raises PlanError when plan not found
Given correction-diff the apply service correction_diff raises PlanError "Plan PLAN-999 not found"
When correction-diff I run plan diff for "PLAN-999" with correction "CORR-999" format "rich"
Then correction-diff the exit code should be nonzero
And correction-diff the output should contain "Diff Error"
And correction-diff the output should contain "Plan PLAN-999 not found"
Scenario: correction diff raises PlanError when correction not found
Given correction-diff the apply service correction_diff raises PlanError "Correction attempt CORR-404 not found"
When correction-diff I run plan diff for "PLAN-001" with correction "CORR-404" format "rich"
Then correction-diff the exit code should be nonzero
And correction-diff the output should contain "Diff Error"
And correction-diff the output should contain "Correction attempt CORR-404 not found"
Scenario: correction diff raises PlanError when attempt does not belong to the plan
Given correction-diff the apply service correction_diff raises PlanError "Correction attempt CORR-001 does not belong to plan PLAN-999"
When correction-diff I run plan diff for "PLAN-999" with correction "CORR-001" format "rich"
Then correction-diff the exit code should be nonzero
And correction-diff the output should contain "Diff Error"
And correction-diff the output should contain "does not belong to plan"
Scenario: correction diff raises error when plan_id is empty
Given correction-diff the apply service correction_diff raises ValidationError "plan_id must not be empty"
When correction-diff I run plan diff for "" with correction "CORR-001" format "rich"
Then correction-diff the exit code should be nonzero
And correction-diff the output should contain "Error"
And correction-diff the output should contain "plan_id must not be empty"
Scenario: correction diff raises error when correction_attempt_id is empty (service guard)
# The CLI passes --correction through to correction_diff() only when it is non-empty.
# The service-level ValidationError guard for empty correction_attempt_id is tested
# here by mocking the service to raise the error and asserting the CLI surfaces it.
Given correction-diff the apply service correction_diff raises ValidationError "correction_attempt_id must not be empty"
When correction-diff I run plan diff for "PLAN-001" with correction "CORR-001" format "rich"
Then correction-diff the exit code should be nonzero
And correction-diff the output should contain "Error"
And correction-diff the output should contain "correction_attempt_id must not be empty"