feat: record CLI command telemetry
This commit is contained in:
@@ -127,6 +127,63 @@ def test_read_events_skips_malformed_lines(tmp_path: Path) -> None:
|
||||
assert events[1].event_type == "also_ok"
|
||||
|
||||
|
||||
# -- CLI command events --
|
||||
|
||||
COMMANDS = [
|
||||
"rdb init",
|
||||
"rdb discover",
|
||||
"rdb ask_more",
|
||||
"rdb status",
|
||||
"rdb next",
|
||||
"rdb start",
|
||||
"rdb complete",
|
||||
"rdb handoff",
|
||||
"rdb prompt",
|
||||
"rdb guardrails",
|
||||
]
|
||||
|
||||
|
||||
def test_record_event_creates_command_events(tmp_path: Path) -> None:
|
||||
"""Each CLI command records an event with event_type 'command' and target 'rdb <name>'."""
|
||||
for target in COMMANDS:
|
||||
record_event(tmp_path, "command", target)
|
||||
|
||||
events = read_events(tmp_path)
|
||||
assert len(events) == len(COMMANDS)
|
||||
for event in events:
|
||||
assert event.event_type == "command"
|
||||
|
||||
|
||||
def test_record_event_target_matches_command_name(tmp_path: Path) -> None:
|
||||
"""Event target matches 'rdb <cmd>' format."""
|
||||
for expected in COMMANDS:
|
||||
record_event(tmp_path, "command", expected)
|
||||
|
||||
events = read_events(tmp_path)
|
||||
targets = [e.target for e in events]
|
||||
assert set(targets) == set(COMMANDS)
|
||||
|
||||
|
||||
def test_record_command_event_has_timestamp(tmp_path: Path) -> None:
|
||||
"""Each command event has a non-empty timestamp."""
|
||||
record_event(tmp_path, "command", "rdb status")
|
||||
events = read_events(tmp_path)
|
||||
assert len(events) == 1
|
||||
assert events[0].timestamp
|
||||
assert "+" in events[0].timestamp # UTC offset
|
||||
|
||||
|
||||
def test_record_command_event_with_details(tmp_path: Path) -> None:
|
||||
"""Commands like start/complete can pass details dict."""
|
||||
record_event(tmp_path, "command", "rdb start", {"task_id": "TASK-013"})
|
||||
events = read_events(tmp_path)
|
||||
assert events[0].details["task_id"] == "TASK-013"
|
||||
|
||||
record_event(tmp_path, "command", "rdb complete", {"task_id": "TASK-007"})
|
||||
events = read_events(tmp_path)
|
||||
assert events[-1].details["task_id"] == "TASK-007"
|
||||
|
||||
|
||||
# -- Helpers --
|
||||
|
||||
def log_lines(root: Path) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user