Files
DECNET/tests/profiler/behave_shell/test_cognitive_inter_command_consistency.py
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

59 lines
2.2 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Step 8: ``cognitive.inter_command_consistency``."""
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_too_few_iats_no_emission() -> None:
out = list(extract_session(_commands_at([0.0, 1.0]), sid="cv-low"))
assert [o for o in out if o.primitive == "cognitive.inter_command_consistency"] == []
def test_uniform_pace_emits_metronomic() -> None:
# Constant 1s gap → CV 0
out = list(extract_session(
_commands_at([i * 1.0 for i in range(8)]), sid="cv-metro",
))
obs = _of(out, "cognitive.inter_command_consistency")
assert obs.value == "metronomic"
def test_human_like_dispersion_emits_variable() -> None:
# Pauses around 1s mean with CV ≈ 0.9 (human empirical)
starts = [0.0, 0.4, 1.4, 1.6, 4.0, 4.4, 7.5]
out = list(extract_session(_commands_at(starts), sid="cv-var"))
obs = _of(out, "cognitive.inter_command_consistency")
assert obs.value == "variable"
def test_extreme_dispersion_emits_bimodal() -> None:
# Mix of very tight bursts and very long gaps → CV well above 1.5
starts = [0.0, 0.1, 0.2, 30.0, 30.1, 30.2, 60.0]
out = list(extract_session(_commands_at(starts), sid="cv-bi"))
obs = _of(out, "cognitive.inter_command_consistency")
assert obs.value == "bimodal"
def test_low_sample_count_reduces_confidence() -> None:
# 3 commands → 2 IATs; below the floor of 5
short = list(extract_session(_commands_at([0.0, 1.0, 2.0]), sid="cv-short"))
full = list(extract_session(_commands_at([i * 1.0 for i in range(8)]), sid="cv-full"))
s = _of(short, "cognitive.inter_command_consistency")
f = _of(full, "cognitive.inter_command_consistency")
assert s.confidence < f.confidence