CI & Build / Python lint (push) Successful in 5s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / TypeScript typecheck (push) Successful in 57s
CI & Build / integration (push) Successful in 1m19s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / Build & push image (push) Successful in 15s
Docstrings, section headers and assertion messages drop the record number, milestone or step that introduced the behaviour, and incident accounts are restated as the present-tense failure shape. A dead pointer to a design doc that is not in the repo is removed. Renamed to the property they check: test_the_old_shape_would_be_caught -> test_a_rank_then_scope_query_is_caught test_a_ledger_repeat_no_longer_produces_that_case_at_all -> test_a_ledger_repeat_is_counted_not_withheld test_the_header_no_longer_promises_once_per_session -> test_the_header_explains_the_seen_marker test_the_portal_case_no_longer_stamps_one_canon_onto_a_whole_file -> test_one_canon_is_not_stamped_onto_a_whole_file test_the_repos_own_prose_no_longer_defines_with -> test_the_repos_own_prose_does_not_define_with test_the_original_regression_create_note_with_content -> test_the_real_server_refuses_content_on_create_note Fixture and example ids stay: "note 5" in a supersession chain, "rule 156" in an illustrative question, `#2275` as the hex-versus-citation case, `#3244` as the example of a bare number, fixed dates in date-filter tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
4.6 KiB
Python
105 lines
4.6 KiB
Python
"""Moment proposals and judgments — what a mock can see.
|
||
|
||
The behaviour against real tables is tests/test_integration_rule_moment_judgments.py.
|
||
These pin the pieces that need no database: that the migration's CHECKs and
|
||
the model agree, which moments count as evidence, and that the line
|
||
the signal hands a session names the tool that answers it.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import importlib.util
|
||
from datetime import datetime, timedelta, timezone
|
||
from pathlib import Path
|
||
from types import SimpleNamespace
|
||
|
||
from scribe.models.rule_moment_judgment import JUDGMENT_STATES, NO_MOMENT, SOURCES
|
||
from scribe.services import moments as moments_svc
|
||
from scribe.services import rule_moment_judgments as svc
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
|
||
|
||
def _migration():
|
||
path = ROOT / "alembic" / "versions" / "0118_rule_moment_judgments.py"
|
||
spec = importlib.util.spec_from_file_location("m0118", path)
|
||
module = importlib.util.module_from_spec(spec)
|
||
spec.loader.exec_module(module)
|
||
return module
|
||
|
||
|
||
def test_the_migration_checks_and_the_model_agree():
|
||
m = _migration()
|
||
assert tuple(m._STATES) == tuple(JUDGMENT_STATES)
|
||
assert tuple(m._SOURCES) == tuple(SOURCES)
|
||
|
||
|
||
def test_verdicts_name_real_states():
|
||
assert set(svc.VERDICTS.values()) <= set(JUDGMENT_STATES)
|
||
|
||
|
||
def test_no_moment_is_not_a_mountable_name():
|
||
""""" is the "none fits" answer; if it ever became mountable, a pass's
|
||
"no moment" would read as a mount on nothing."""
|
||
assert not moments_svc.is_moment(NO_MOMENT)
|
||
|
||
|
||
def test_the_ubiquitous_moments_are_not_evidence():
|
||
assert svc.signal_moments(["work.run", "work.verify", "work.change", "work.verify",
|
||
"not.a.moment", "skill.brainstorming"]) == [
|
||
"work.verify", "skill.brainstorming",
|
||
]
|
||
# Every skipped name is a real moment — a typo here would skip nothing.
|
||
assert all(moments_svc.is_moment(m) for m in svc.SIGNAL_SKIP)
|
||
|
||
|
||
def test_the_proposal_line_names_the_tool_that_answers_it():
|
||
rule = SimpleNamespace(id=11, title="Definition of done", kind="rule")
|
||
line = svc._proposal_line(rule, "work.verify", {"situations": ["a", "b", "c"]})
|
||
assert line.startswith("> Rule #11")
|
||
assert "`work.verify`" in line and "3 distinct sessions" in line
|
||
assert '"rule_id": 11' in line and '"moment": "work.verify"' in line
|
||
assert "judge_rule_moments" in line and '"reject"' in line
|
||
|
||
|
||
# ── The misfire ──────────────────────────────────────────────────────────────
|
||
|
||
|
||
def test_a_day_is_one_situation_and_days_are_distinct():
|
||
"""The day arm keys verbatim: tokenised, "10" and "05" fall under the
|
||
minimum token length and every day of a year would be one situation."""
|
||
a = datetime(2026, 10, 5, 1, tzinfo=timezone.utc)
|
||
assert svc.misfire_situation(a) == svc.misfire_situation(a + timedelta(hours=20))
|
||
assert svc.misfire_situation(a) != svc.misfire_situation(a + timedelta(days=1))
|
||
assert svc.misfire_situation(a) != svc.misfire_situation(a + timedelta(days=31))
|
||
|
||
|
||
def test_a_misfire_counts_reasons_and_actions():
|
||
now = datetime(2026, 10, 5, tzinfo=timezone.utc)
|
||
mf = None
|
||
for i in range(svc.MISFIRE_REASONS + 2):
|
||
mf = svc.add_misfire(mf, svc.misfire_situation(now + timedelta(days=i)), 7, now,
|
||
why=f"reason {i}", reached_by="git push" if i % 2 else "make ship")
|
||
assert len(mf["situations"]) == svc.MISFIRE_REASONS + 2
|
||
assert [r["why"] for r in mf["reasons"]][-1] == f"reason {svc.MISFIRE_REASONS + 1}"
|
||
assert len(mf["reasons"]) == svc.MISFIRE_REASONS
|
||
assert mf["reached_by"] == {"make ship": 4, "git push": 3}
|
||
assert mf["projects"] == [7]
|
||
|
||
|
||
def test_the_unmount_line_offers_both_fixes():
|
||
rule = SimpleNamespace(id=10, title="CI verifies", kind="rule")
|
||
mf = {"situations": ["a", "b", "c"], "reached_by": {"actions_run_read": 3}}
|
||
line = svc._unmount_line(rule, "work.verify", mf)
|
||
assert line.startswith("> Rule #10") and "3 distinct days" in line
|
||
assert "`actions_run_read` ×3" in line
|
||
assert '"verdict": "reject"' in line and "unmap_action" in line and '"confirm"' in line
|
||
|
||
|
||
def test_a_held_reply_names_the_misfire_call_only_for_a_mount():
|
||
from scribe.services.moment_delivery import reply_hold_reason
|
||
|
||
mounted = {"rule_id": 11, "title": "Definition of done", "moment": "reply.report", "trigger": ""}
|
||
scored = {"rule_id": 12, "title": "Other", "moment": "", "score": 0.81, "trigger": ""}
|
||
assert 'rule_misfired(11, "reply.report", why)' in reply_hold_reason([mounted])
|
||
assert "rule_misfired" not in reply_hold_reason([scored])
|