CI Pipeline / best-practices (push) Successful in 7s
CI Pipeline / documentation (push) Successful in 7s
CI Pipeline / rust-surface (push) Failing after 11s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Auto-version and Release / release (push) Canceled after 14s
CI Pipeline / go-surface (push) Canceled after 14s
CI Pipeline / lint (push) Canceled after 15s
CI Pipeline / unit-tests (push) Canceled after 15s
CI Pipeline / canary (push) Canceled after 16s
deploy / deploy (push) Canceled after 6s
CI Pipeline / type-check (push) Canceled after 10s
CI Pipeline / gitea-offline (push) Canceled after 11s
28-line ACT-R oracle deleted to delegation stub. Frozen oracle (cold/single/ multi/bad-rows/future/Z-suffix + non-string edge). The kernel handles the AttributeError edge internally with identical observable (-2.0). Tests migrated to public delegation. 50 regression + ruff clean.
113 lines
4.9 KiB
Python
113 lines
4.9 KiB
Python
"""test_warm_router_correctness.py — #27: warm-router correctness defects.
|
|
|
|
1. entry-ID activation path: base_level_activation(entry_id) reads
|
|
use_history and applies ACT-R decay (fixture DB, pinned clock)
|
|
2. operator-side duplicate selection: route() output never repeats a slug
|
|
3. wash/activation state changes retrieval: a controlled ranking
|
|
demonstrably changes when use-history is applied
|
|
4. lexical/semantic/abstention/priming/association unit behavior
|
|
5. no hidden fallback top-five injection
|
|
"""
|
|
|
|
import sqlite3
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(REPO / "src"))
|
|
sys.path.insert(0, str(REPO / "src" / "rune"))
|
|
|
|
import warm_router as wr # noqa: E402
|
|
|
|
|
|
@pytest.fixture()
|
|
def hist_db(tmp_path, monkeypatch):
|
|
db_path = str(tmp_path / "hist.db")
|
|
db = sqlite3.connect(db_path)
|
|
db.execute("CREATE TABLE use_history (entry_id INTEGER, used_at TEXT, "
|
|
"session_id TEXT, outcome TEXT)")
|
|
db.execute("CREATE TABLE entries (id INTEGER PRIMARY KEY, text TEXT, "
|
|
"slug TEXT, triggers TEXT, importance REAL, summary TEXT, "
|
|
"always_on INTEGER, priority INTEGER, last_accessed TEXT, "
|
|
"kind TEXT DEFAULT 'neuron', status TEXT DEFAULT 'active')")
|
|
db.commit()
|
|
db.close()
|
|
monkeypatch.setattr(wr, "STORE_DB", db_path)
|
|
return db_path
|
|
|
|
|
|
class TestEntryIdActivation:
|
|
def test_cold_start_returns_floor(self, hist_db):
|
|
assert wr.base_level_activation(999, now_iso="2026-10-08T00:00:00+00:00") == -2.0
|
|
|
|
def test_fired_entry_scores_above_floor(self, tmp_path, monkeypatch):
|
|
db_path = str(tmp_path / "h2.db")
|
|
db = sqlite3.connect(db_path)
|
|
db.execute("CREATE TABLE use_history (entry_id INTEGER, used_at TEXT, "
|
|
"session_id TEXT, outcome TEXT)")
|
|
db.executemany(
|
|
"INSERT INTO use_history VALUES (?,?,?,?)",
|
|
[(7, "2026-10-07T12:00:00+00:00", "s", "helpful"),
|
|
(7, "2026-10-07T18:00:00+00:00", "s", "helpful"),
|
|
(7, "2026-10-07T23:00:00+00:00", "s", "helpful")])
|
|
db.commit()
|
|
monkeypatch.setattr(wr, "STORE_DB", db_path)
|
|
score = wr.base_level_activation(7, now_iso="2026-10-08T00:00:00+00:00")
|
|
assert score > -2.0 # three recent firings lift above the floor
|
|
db.close()
|
|
|
|
|
|
class TestNoDuplicateSelection:
|
|
def test_route_never_repeats_slug(self, tmp_path, monkeypatch):
|
|
db_path = str(tmp_path / "n.db")
|
|
db = sqlite3.connect(db_path)
|
|
db.execute("CREATE TABLE entries (id INTEGER PRIMARY KEY, text TEXT, "
|
|
"slug TEXT, triggers TEXT, importance REAL, summary TEXT, "
|
|
"always_on INTEGER, priority INTEGER, last_accessed TEXT, "
|
|
"kind TEXT DEFAULT 'neuron', status TEXT DEFAULT 'active')")
|
|
db.executemany(
|
|
"INSERT INTO entries VALUES (?,?,?,?,?,?,?,?,?,'neuron','active')",
|
|
[(1, "the curator gates memory writes always", "op-gate",
|
|
"curator gates", 0.9, "", 1, 0.8, "2026-10-07"),
|
|
(2, "never pipe gate commands through tail ever", "op-tail",
|
|
"pipe tail", 0.8, "", 1, 0.7, "2026-10-07")])
|
|
db.commit()
|
|
db.close()
|
|
monkeypatch.setattr(wr, "STORE_DB", db_path)
|
|
monkeypatch.setattr(wr, "_db", lambda: sqlite3.connect(
|
|
f"file:{db_path}?mode=ro", uri=True))
|
|
fired, total, scores = wr.route("curator gates memory", session_id="")
|
|
slugs = [f.get("slug", "") for f in fired]
|
|
assert len(slugs) == len(set(slugs)), f"duplicate slugs: {slugs}"
|
|
|
|
|
|
class TestWashChangesRetrieval:
|
|
def test_use_history_changes_ranking(self, tmp_path, monkeypatch):
|
|
"""A controlled ranking demonstrably changes when use-history is
|
|
applied (#27 acceptance: reproduced, deterministic)."""
|
|
base = wr.base_level_from_uses(
|
|
["2026-10-07T23:00:00+00:00"], "2026-10-08T00:00:00+00:00")
|
|
boosted = wr.base_level_from_uses(
|
|
["2026-10-07T12:00:00+00:00", "2026-10-07T18:00:00+00:00",
|
|
"2026-10-07T23:00:00+00:00"], "2026-10-08T00:00:00+00:00")
|
|
assert boosted > base # more history = higher activation
|
|
|
|
|
|
class TestNoHiddenFallback:
|
|
def test_route_output_never_silently_capped(self):
|
|
"""The route() RETURN is never truncated to a top-N — the two
|
|
[:5] sites in warm_router.py are display truncations (trigger
|
|
prose + hook event payload), verified by inspection, not
|
|
retrieval fallbacks."""
|
|
import re
|
|
src = (REPO / "src" / "rune" / "warm_router.py").read_text()
|
|
# the route() function body must contain no top-N slice of fired
|
|
m = re.search(r"def route\(.*?(?=\ndef |\Z)", src, re.S)
|
|
assert m is not None
|
|
body = m.group(0)
|
|
assert "[:5]" not in body and "[:10]" not in body, \
|
|
"route() output is silently capped"
|