Files
cleveragents-core/robot/helper_plan_explain.py
T
khyari hamza f66cb8d68e
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 18s
CI / security (pull_request) Successful in 31s
CI / typecheck (pull_request) Successful in 33s
CI / unit_tests (pull_request) Successful in 1m44s
CI / docker (pull_request) Successful in 44s
CI / integration_tests (pull_request) Successful in 2m53s
CI / coverage (pull_request) Successful in 3m51s
CI / benchmark-regression (pull_request) Successful in 24m19s
fix(cli): address review findings for plan explain and tree commands
- Remove global _PLAN_ID; generate per-step plan IDs on context (#8)
- Fix sham orphan test; build children_map from all decisions (#1)
- Delete dead constants; use _PATCH_RESUME_SVC_MOD in resume steps (#2)
- Remove dead _resolve_active_plan_id mock from _invoke_correct (#5)
- Make --mode/--guidance required Typer options (#3)
- Show alternatives by default; remove --show-alternatives flag (#4)
- Strengthen weak assertions on depth-limit and show-superseded (#6)
- Add negative assertions for error type conflation (#7)

ISSUES CLOSED: #174
2026-03-03 12:10:25 +00:00

104 lines
2.8 KiB
Python

"""Helper script for Robot Framework plan explain smoke tests."""
from __future__ import annotations
import sys
from collections.abc import Callable
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 ulid import ULID
from cleveragents.cli.commands.plan import (
_build_explain_dict,
build_decision_tree,
)
from cleveragents.domain.models.core.decision import (
ContextSnapshot,
Decision,
DecisionType,
ResourceRef,
)
_PLAN_ID = str(ULID())
def _test_explain_format() -> None:
"""Create a decision and verify explain formatting."""
decision = Decision(
plan_id=_PLAN_ID,
sequence_number=0,
decision_type=DecisionType.PROMPT_DEFINITION,
question="What to build?",
chosen_option="REST API",
rationale="Simple and well-understood",
context_snapshot=ContextSnapshot(
hot_context_hash="sha256:robot_test",
relevant_resources=[
ResourceRef(resource_id=str(ULID()), path="src/app.py"),
],
),
)
data = _build_explain_dict(
decision,
show_context=True,
show_reasoning=True,
)
assert "decision_id" in data
assert "context_snapshot" in data
assert "rationale" in data
assert "alternatives_considered" in data
assert data["question"] == "What to build?"
print("plan-explain-ok")
def _test_tree_build() -> None:
"""Create decisions and build a tree."""
root_id = str(ULID())
child_id = str(ULID())
decisions = [
Decision(
decision_id=root_id,
plan_id=_PLAN_ID,
sequence_number=0,
decision_type=DecisionType.PROMPT_DEFINITION,
question="Root?",
chosen_option="Yes",
),
Decision(
decision_id=child_id,
plan_id=_PLAN_ID,
parent_decision_id=root_id,
sequence_number=1,
decision_type=DecisionType.STRATEGY_CHOICE,
question="Child?",
chosen_option="Also yes",
),
]
tree = build_decision_tree(decisions)
assert len(tree) == 1
assert len(tree[0]["children"]) == 1
print("plan-tree-ok")
_TESTS: dict[str, Callable[[], None]] = {
"explain_format": _test_explain_format,
"tree_build": _test_tree_build,
}
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]()