generated from coulomb/repo-seed
detect/quality.py: is_real_coding_session drops health-checks / smoke-tests / interrupted / trivially-short sessions (event floor, repo present, substantive tool activity, non-trivial prompt). Wired into run_detect so signals only form over real sessions — fixes the abandoned false-positive. [detect.quality] knobs; existing detect/curate fixtures made realistic. 8 new tests; suite 80/80. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""Detect entrypoint tests (T07): end-to-end digests -> patterns, persisted."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from session_memory.core.store import Store # noqa: E402
|
|
from session_memory.detect.__main__ import run_detect # noqa: E402
|
|
|
|
|
|
def _digest(uid, flavor, repo, **markers):
|
|
return {
|
|
"session_uid": uid, "flavor": flavor, "repo": repo, "outcome": "fail",
|
|
"cost": {"input_tokens": 10, "output_tokens": 1},
|
|
"markers": {"errors": markers.get("errors", 0), "retries": markers.get("retries", 0),
|
|
"test_runs": 0, "edits": 0, "human_interventions": 0},
|
|
# fields the quality filter (WP-0005 T01) checks — real coding session
|
|
"event_count": 40, "first_prompt": "Fix the failing build and retry the suite",
|
|
"tool_histogram": {"Bash": 20, "Edit": 12, "Read": 8},
|
|
}
|
|
|
|
|
|
def _config(tmp_path):
|
|
return {"store": {"db_path": str(tmp_path / ".store/m.db"),
|
|
"blob_dir": str(tmp_path / ".store/blobs"),
|
|
"cursor": str(tmp_path / ".store/c.json")}}
|
|
|
|
|
|
def test_run_detect_persists_cross_flavor_pattern(tmp_path):
|
|
cfg = _config(tmp_path)
|
|
st = Store(cfg["store"]["db_path"], cfg["store"]["blob_dir"])
|
|
# same problem (retry_storm) across two flavors -> cross-flavor candidate
|
|
st.write_digest("claude:a", _digest("claude:a", "claude", "r1", retries=5))
|
|
st.write_digest("codex:b", _digest("codex:b", "codex", "r2", retries=4))
|
|
st.close()
|
|
|
|
patterns = run_detect(cfg, min_frequency=2)
|
|
assert len(patterns) == 1
|
|
assert patterns[0]["cross_flavor"] is True
|
|
assert patterns[0]["signal_type"] == "retry_storm"
|
|
|
|
# persisted to the Tier 2 patterns table
|
|
st2 = Store(cfg["store"]["db_path"], cfg["store"]["blob_dir"])
|
|
rows = st2.db.execute("SELECT key FROM patterns").fetchall()
|
|
assert len(rows) == 1
|
|
st2.close()
|