Files
cleveragents-core/features/mocks
hurui200320 0b415a6e5e
CI / lint (push) Successful in 16s
CI / build (push) Successful in 20s
CI / quality (push) Successful in 29s
CI / typecheck (push) Successful in 45s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 52s
CI / unit_tests (push) Successful in 3m12s
CI / integration_tests (push) Successful in 3m42s
CI / docker (push) Successful in 56s
CI / e2e_tests (push) Successful in 5m18s
CI / coverage (push) Successful in 7m0s
CI / benchmark-publish (push) Successful in 20m2s
test: add TDD bug-capture test for #969 — plan correct plan_id handling (#1051)
## Summary

Add TDD bug-capture tests for bug #969 (`plan correct` expects `decision_id` but M3 acceptance test passes `plan_id`). These tests prove the bug exists and will serve as regression guards once the fix in #969 is merged.

### Changes

- **Behave test** (`features/tdd_plan_correct_plan_id.feature`): Two scenarios tagged `@tdd_expected_fail @tdd_bug @tdd_bug_969` — one for `--mode revert` and one for `--mode append` — that invoke `plan correct <plan_id>` (without `--plan` flag) and assert the command resolves the plan_id to its root decision as `target_decision_id`. Both modes are tested because the bug affects `target_decision_id` resolution **before** mode-specific branching.

- **Step definitions** (`features/steps/tdd_plan_correct_plan_id_steps.py`): Mock setup for DI container (DecisionService), CorrectionService, and `_resolve_active_plan_id`. Uses `tpcpid` step prefix per project conventions.

- **Shared fixtures** (`features/mocks/tdd_plan_correct_plan_id_fixtures.py`): Centralised constants, patch targets, mock builders (`make_decision_ns`, `make_mock_container`, `make_correction_svc`, `make_default_decisions`, `make_default_container`), and `build_cli_args` helper. Both the Behave steps and Robot helper import from this shared module, eliminating code duplication and drift risk.

- **Robot test** (`robot/tdd_plan_correct_plan_id.robot`): Two integration-level tests (revert + append) with `tdd_expected_fail tdd_bug tdd_bug_969` tags, exercising the same code paths via the helper script.

- **Robot helper** (`robot/helper_tdd_plan_correct_plan_id.py`): Standalone helper that exits 0 with sentinel when the bug is fixed, exits 1 when the bug is present. Imports shared fixtures from `features/mocks/`.

- **Changelog** (`CHANGELOG.md`): Added entry under Unreleased for #979.

### Bug Description

The `correct_decision` function in `cleveragents.cli.commands.plan` declares `decision_id` as its first positional argument. When the M3 acceptance test calls `plan correct <plan_id> --mode revert --guidance "..."`, the plan_id is captured as `decision_id` and used directly as `target_decision_id` in `svc.request_correction()`. Since the plan_id is not a valid decision_id, the correction service cannot find the targeted decision. The same bug path is exercised by `--mode append`.

### How TDD Expected-Fail Works

- The `@tdd_expected_fail` tag causes the test framework to invert the result: the test passes CI when the underlying assertion fails (proving the bug exists) and fails CI if the assertion passes (bug was fixed without removing the tag).
- When bug #969 is fixed, the developer removes the `@tdd_expected_fail` tag, and the test runs normally as a regression guard.

### Quality Gates

All nox sessions pass:
- `nox -s lint` 
- `nox -s typecheck`  (0 errors)
- `nox -s unit_tests`  (387 features, 11121 scenarios, 0 failures)
- `nox -s integration_tests`  (1561 tests, 0 failures)
- `nox -s e2e_tests`  (16 tests, 0 failures)
- `nox -s coverage_report`  (≥97%)

Closes #979

Reviewed-on: #1051
Co-authored-by: Rui Hu <rui.hu@cleverthis.com>
Co-committed-by: Rui Hu <rui.hu@cleverthis.com>
2026-03-19 07:31:12 +00:00
..