boma/tests/test_friction_scan.py
sjat 72b9262f34 feat(kaizen): parse tag/first_seen/age per signal
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 21:17:03 +02:00

61 lines
1.6 KiB
Python

import importlib.util
import os
_SPEC = importlib.util.spec_from_file_location(
"friction_scan",
os.path.join(os.path.dirname(__file__), "..", "scripts", "friction-scan.py"),
)
fs = importlib.util.module_from_spec(_SPEC)
_SPEC.loader.exec_module(fs)
SAMPLE = """# FRICTION.md
## Open signals
_(append new raw signals here)_
- `[gotcha]` **First thing** (2026-06-01): body line one.
continuation line two.
- `[friction]` **Second thing** (2026-06-10): only one line.
---
## Kaizen reviews — decisions ledger
- `[gotcha]` **Should not be parsed** (2026-01-01): in the ledger.
"""
def test_extract_open_section_stops_at_next_heading():
section = fs.extract_open_section(SAMPLE)
assert "First thing" in section
assert "Second thing" in section
assert "Should not be parsed" not in section
def test_split_signals_finds_two_items_and_joins_continuations():
signals = fs.split_signals(fs.extract_open_section(SAMPLE))
assert len(signals) == 2
assert "continuation line two" in signals[0]
assert signals[1].startswith("`[friction]`")
import datetime
TODAY = datetime.date(2026, 6, 15)
def test_parse_signal_extracts_tag_and_date_and_age():
raw = fs.split_signals(fs.extract_open_section(SAMPLE))[0]
sig = fs.parse_signal(raw, TODAY)
assert sig["tag"] == "gotcha"
assert sig["first_seen"] == "2026-06-01"
assert sig["age_days"] == 14
assert "First thing" in sig["text"]
def test_parse_signal_handles_missing_date():
sig = fs.parse_signal("`[unused]` **No date here** something", TODAY)
assert sig["tag"] == "unused"
assert sig["first_seen"] is None
assert sig["age_days"] is None