Files
DECNET/tests/profiler/behave_shell/test_cognitive_planning_depth.py
anti 6c2e4ada83 feat(profiler/behave_shell): emit cognitive.planning_depth
Distribution of inter-command IATs bucketed against IKI_THINK_MAX_S
(deep) and INTER_CMD_INSTANT_MAX (reactive); fall-through is shallow.
v0.1 thresholds; D.8 re-tunes.
2026-05-03 23:55:16 -04:00

62 lines
2.0 KiB
Python

"""Step D.3: ``cognitive.planning_depth``."""
from __future__ import annotations
from decnet.profiler.behave_shell import extract_session
from decnet.profiler.behave_shell._parse import AsciinemaEvent
def _of(observations: list, primitive: str):
obs = [o for o in observations if o.primitive == primitive]
assert len(obs) == 1, f"expected exactly one {primitive}, got {len(obs)}"
return obs[0]
def _commands_at(starts: list[float]) -> list[AsciinemaEvent]:
events: list[AsciinemaEvent] = []
for s in starts:
events.append((s, "i", "x\r"))
return events
def test_no_inter_cmd_iats_no_emission() -> None:
out = list(extract_session(_commands_at([0.0]), sid="pd-empty"))
assert [o for o in out if o.primitive == "cognitive.planning_depth"] == []
def test_long_pauses_emit_deep() -> None:
"""Most pauses > 1.5s → deep."""
out = list(extract_session(
_commands_at([0.0, 3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0]),
sid="pd-deep",
))
obs = _of(out, "cognitive.planning_depth")
assert obs.value == "deep"
def test_sub_instant_pauses_emit_reactive() -> None:
"""Most pauses ≤ INTER_CMD_INSTANT_MAX (0.30s) → reactive."""
out = list(extract_session(
_commands_at([i * 0.10 for i in range(8)]),
sid="pd-react",
))
obs = _of(out, "cognitive.planning_depth")
assert obs.value == "reactive"
def test_typing_speed_pauses_emit_shallow() -> None:
"""Pauses around 1s — neither deep nor reactive → shallow."""
out = list(extract_session(
_commands_at([i * 1.0 for i in range(8)]),
sid="pd-shallow",
))
obs = _of(out, "cognitive.planning_depth")
assert obs.value == "shallow"
def test_low_sample_count_reduces_confidence() -> None:
short = list(extract_session(_commands_at([0.0, 1.0, 2.0]), sid="pd-short"))
full = list(extract_session(_commands_at([i * 1.0 for i in range(8)]), sid="pd-full"))
s = _of(short, "cognitive.planning_depth")
f = _of(full, "cognitive.planning_depth")
assert s.confidence < f.confidence