testsAndMisc/python_pkg/session_autopsy/tests/test_signatures.py
Krzysztof kuhy Rudnicki a83b5abc27
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Python tests / test (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
python_pkg: track session_autopsy, finishing its interrupted refactor
The transcript analyzer behind /compile-candidate lived only in the working
tree. Untracked meant unlinted — pre-commit only inspects files handed to it —
so nothing had ever checked it, and it had been abandoned mid-refactor with
every parse raising AttributeError: '_Accumulator' object has no attribute
'first_timestamp'.

The accumulator had been moved onto the grouped records dataclasses, but three
increment sites and parse_session still read flat attributes that no longer
existed. parse_session now hands over acc.meta and acc.counts directly; only
subagent_count comes from elsewhere, since no transcript line carries it.

Two modules broke the 500-line limit, so they were split along seams that were
already there. signatures.py takes the text-signature helpers — traces.py was
importing them from parse.py, making parse an accidental hub, and now neither
imports the other. stats.py takes the pure number and time helpers. parse.py
521 -> 458, detectors.py 559 -> 467.

The structural lint findings were refactored, not configured away.
_counter_candidates took eight arguments; the five naming which counter field to
mine and at what thresholds became a frozen _CounterSpec, so both call sites are
one line. _extract_skill carried in_span and a line budget as loop variables
across thirteen branches; a _SpanBuffer owns that state now, leaving the walk at
four. record() took twelve flat kwargs and now takes one override per record
block, with session_meta() so a partial meta override keeps the standard
timestamp — a bare SessionMeta(slug=...) would have nulled started_at and
quietly changed the per-week arithmetic. All 36 call sites rewritten by an AST
pass. tests/factories.py moved into conftest.py, where every other package here
keeps shared builders and where name-tests-test does not object.

965 tests pass at 100% statement and branch coverage, every hook is green, and
no suppression was added anywhere. `candidates` and `traces skill-finish` both
run against the real corpus.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-25 16:56:43 +02:00

29 lines
1.2 KiB
Python

"""Tests for the cross-session text signatures."""
from __future__ import annotations
from python_pkg.session_autopsy import signatures
from python_pkg.session_autopsy.signatures import command_signature, normalize_signature
def test_normalize_signature() -> None:
"""Paths, hex runs, and numbers are masked; first line only."""
assert normalize_signature("") == ""
assert normalize_signature(" \n\n") == ""
sig = normalize_signature("rm -rf /home/kuhy/.cache/yay/python-jaxlib\nsecond line")
assert sig == "rm -rf <PATH>"
assert normalize_signature("deadbeefcafe1234") == "<HEX>"
assert normalize_signature("retry 12 times") == "retry <N> times"
assert len(normalize_signature("x" * 500)) == signatures.MAX_SIG_LEN
def test_command_signature() -> None:
"""Wrappers keep their first non-flag, non-numeric argument."""
assert command_signature("") == ""
assert command_signature("git status") == "git"
assert command_signature("cd /home/kuhy/testsAndMisc && ls") == "cd <PATH>"
assert command_signature("timeout 120 python3 -m x") == "timeout python3"
assert command_signature("sudo -n true") == "sudo true"
assert command_signature("sudo -n") == "sudo"
assert command_signature("cd") == "cd"