Files
cleveragents-core/robot/helper_correction_model.py
freemo a0000afc72
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Failing after 14s
CI / build (pull_request) Successful in 15s
CI / quality (pull_request) Successful in 21s
CI / typecheck (pull_request) Successful in 39s
CI / coverage (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Has been skipped
CI / security (pull_request) Successful in 56s
CI / integration_tests (pull_request) Successful in 2m27s
CI / unit_tests (pull_request) Successful in 5m59s
CI / docker (pull_request) Has been skipped
fix: update Robot helper and CLI to use target_decision_id, fix lint import order
- robot/helper_correction_model.py: decision_id -> target_decision_id in all
  request_correction calls; update validate_guidance test to accept empty
  guidance (M4.2 allows it); remove unused ValidationError import
- robot/correction_model.robot: update Validate Empty Guidance doc string
- src/cleveragents/cli/commands/plan.py: decision_id -> target_decision_id
- src/cleveragents/cli/main.py: fix import ordering (invariant before lsp)
2026-02-22 18:47:41 +00:00

183 lines
5.4 KiB
Python

"""Helper script for Robot Framework correction model smoke tests."""
from __future__ import annotations
import sys
from pathlib import Path
# Ensure src is importable when run from workspace root
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cleveragents.application.services.correction_service import CorrectionService
from cleveragents.domain.models.core.correction import (
CorrectionMode,
CorrectionStatus,
)
def _test_create_revert() -> None:
"""Create a correction in revert mode."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="Use FastAPI instead",
)
assert req.mode == CorrectionMode.REVERT
assert req.status == CorrectionStatus.PENDING
assert req.plan_id == "plan-1"
print("correction-create-revert-ok")
def _test_create_append() -> None:
"""Create a correction in append mode."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.APPEND,
guidance="Add caching layer",
)
assert req.mode == CorrectionMode.APPEND
assert req.status == CorrectionStatus.PENDING
print("correction-create-append-ok")
def _test_dry_run() -> None:
"""Analyze impact in dry-run mode."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="Change framework",
dry_run=True,
)
impact = svc.analyze_impact(req.correction_id)
assert len(impact.affected_decisions) > 0
assert impact.risk_level == "low"
print(
f"correction-dry-run-ok "
f"(affected={len(impact.affected_decisions)}, "
f"risk={impact.risk_level})"
)
def _test_cancel() -> None:
"""Cancel a pending correction."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="To be cancelled",
)
cancelled = svc.cancel_correction(req.correction_id)
assert cancelled.status == CorrectionStatus.CANCELLED
print("correction-cancel-ok")
def _test_execute() -> None:
"""Execute a correction."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="Execute this",
)
result = svc.execute_correction(req.correction_id)
assert result.status == CorrectionStatus.APPLIED
assert "DEC-001" in result.reverted_decisions
print(
f"correction-execute-ok "
f"(status={result.status.value}, "
f"reverted={result.reverted_decisions})"
)
def _test_list_by_plan() -> None:
"""List corrections filtered by plan."""
svc = CorrectionService()
svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="Fix A",
)
svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-002",
mode=CorrectionMode.APPEND,
guidance="Fix B",
)
svc.request_correction(
plan_id="plan-2",
target_decision_id="DEC-003",
mode=CorrectionMode.REVERT,
guidance="Fix C",
)
plan1 = svc.list_corrections(plan_id="plan-1")
plan2 = svc.list_corrections(plan_id="plan-2")
all_corrections = svc.list_corrections()
assert len(plan1) == 2
assert len(plan2) == 1
assert len(all_corrections) == 3
print(f"correction-list-ok (plan1={len(plan1)}, plan2={len(plan2)})")
def _test_validate_guidance() -> None:
"""Verify empty guidance is accepted (defaults to empty string)."""
svc = CorrectionService()
req = svc.request_correction(
plan_id="plan-1",
target_decision_id="DEC-001",
mode=CorrectionMode.REVERT,
guidance="",
)
assert req.guidance == ""
assert req.status == CorrectionStatus.PENDING
print("correction-validate-guidance-ok")
def _test_enums() -> None:
"""Verify enum values."""
assert CorrectionMode.REVERT.value == "revert"
assert CorrectionMode.APPEND.value == "append"
assert CorrectionStatus.PENDING.value == "pending"
assert CorrectionStatus.ANALYZING.value == "analyzing"
assert CorrectionStatus.EXECUTING.value == "executing"
assert CorrectionStatus.APPLIED.value == "applied"
assert CorrectionStatus.FAILED.value == "failed"
assert CorrectionStatus.CANCELLED.value == "cancelled"
print("correction-enums-ok")
_TESTS = {
"create_revert": _test_create_revert,
"create_append": _test_create_append,
"dry_run": _test_dry_run,
"cancel": _test_cancel,
"execute": _test_execute,
"list_by_plan": _test_list_by_plan,
"validate_guidance": _test_validate_guidance,
"enums": _test_enums,
}
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <test_name>")
print(f"Available tests: {', '.join(sorted(_TESTS))}")
sys.exit(1)
test_name = sys.argv[1]
if test_name not in _TESTS:
print(f"Unknown test: {test_name}")
print(f"Available: {', '.join(sorted(_TESTS))}")
sys.exit(1)
_TESTS[test_name]()