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>
104 lines
4.4 KiB
Python
104 lines
4.4 KiB
Python
"""Soft links — the counting rules.
|
|
|
|
What a suggested link's evidence counts is a design decision with a failure
|
|
mode on each side: count every arrival and two similar records "prove" a
|
|
relation by resembling each other on every similar prompt; count too little
|
|
and nothing ever reaches the bar. These pin the rules as pure functions. The
|
|
recorder itself — ACL, judged pairs left alone, the proposal firing once —
|
|
is tested against Postgres in tests/test_integration_lesson_rule_links.py.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import inspect
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
from scribe.services import lesson_rules as links_svc
|
|
|
|
NOW = datetime(2026, 10, 1, 12, 0, tzinfo=timezone.utc)
|
|
|
|
|
|
def test_the_same_ask_reworded_trivially_is_one_situation():
|
|
a = links_svc.situation_key("p", "Merge dev to main, please.")
|
|
assert a == links_svc.situation_key("p", "please MERGE main to dev")
|
|
assert a != links_svc.situation_key("p", "merge the feature branch")
|
|
|
|
|
|
def test_a_file_is_one_situation_however_its_code_differs():
|
|
"""The write arm keys on the path, so a run of edits to one file — each
|
|
with different code — is one situation, not one per edit."""
|
|
path = "src/scribe/services/lesson_rules.py"
|
|
assert links_svc.situation_key("w", path) == links_svc.situation_key("w", path)
|
|
assert links_svc.situation_key("w", path) != links_svc.situation_key("w", "src/other.py")
|
|
|
|
|
|
def test_the_two_arms_never_share_a_key():
|
|
assert links_svc.situation_key("p", "routes.py") != links_svc.situation_key("w", "routes.py")
|
|
|
|
|
|
def test_nothing_to_key_on_is_no_situation():
|
|
assert links_svc.situation_key("p", "") == ""
|
|
assert links_svc.situation_key("p", "a is to") == "" # grammar only
|
|
|
|
|
|
def test_a_repeat_counts_as_an_arrival_but_not_a_situation():
|
|
key = links_svc.situation_key("p", "probe the deployed version")
|
|
ev = links_svc.add_evidence(None, key, 2, NOW)
|
|
ev = links_svc.add_evidence(ev, key, 2, NOW)
|
|
assert links_svc.evidence_summary(ev) == {"situations": 1, "projects": 1, "co_surfaced": 2}
|
|
|
|
|
|
def test_projects_are_distinct_and_an_unbound_reader_adds_none():
|
|
ev = links_svc.add_evidence(None, "p:1", 2, NOW)
|
|
ev = links_svc.add_evidence(ev, "p:2", 5, NOW)
|
|
ev = links_svc.add_evidence(ev, "p:3", None, NOW)
|
|
assert links_svc.evidence_summary(ev)["projects"] == 2
|
|
|
|
|
|
def test_evidence_is_a_new_dict_so_the_column_change_is_seen():
|
|
before = {"co_surfaced": 1, "situations": ["p:1"], "projects": []}
|
|
after = links_svc.add_evidence(before, "p:2", None, NOW)
|
|
assert after is not before
|
|
assert before["situations"] == ["p:1"]
|
|
|
|
|
|
def test_the_proposal_fires_at_the_bar_and_not_before():
|
|
ev = None
|
|
for i in range(links_svc.PROPOSE_SITUATIONS - 1):
|
|
ev = links_svc.add_evidence(ev, f"p:{i}", None, NOW)
|
|
assert not links_svc.proposal_due(ev, NOW)
|
|
ev = links_svc.add_evidence(ev, "p:last", None, NOW)
|
|
assert links_svc.proposal_due(ev, NOW)
|
|
|
|
|
|
def test_a_passed_over_proposal_waits_out_the_cooldown():
|
|
ev = {"situations": ["p:1", "p:2", "p:3"], "proposed_at": NOW.isoformat()}
|
|
assert not links_svc.proposal_due(ev, NOW + timedelta(minutes=5))
|
|
assert links_svc.proposal_due(ev, NOW + links_svc.PROPOSE_COOLDOWN)
|
|
|
|
|
|
def test_the_proposal_names_the_call_that_answers_it():
|
|
line = links_svc._proposal_line(
|
|
41, "An overrun run usually failed early", 7, "Read the job log first",
|
|
"rule", {"situations": ["p:1", "p:2", "p:3"], "projects": [2, 5]},
|
|
)
|
|
assert 'judge_lesson_link(41, 7, "confirm"' in line
|
|
assert '"reject"' in line
|
|
assert "3 distinct situations across 2 projects" in line
|
|
|
|
|
|
def test_evidence_summary_reads_nothing_as_zero_not_an_error():
|
|
assert links_svc.evidence_summary(None) == {"situations": 0, "projects": 0, "co_surfaced": 0}
|
|
|
|
|
|
def test_both_hook_doors_count_the_pair_on_their_own_arm():
|
|
"""The two responses that carry lessons and rules together. A door that
|
|
renders both and does not record the pair is the miss this step exists
|
|
to close, and it would produce no error anywhere — only an empty table."""
|
|
from scribe.routes import plugin as plugin_routes
|
|
from scribe.services import plugin_context
|
|
|
|
prompt_door = inspect.getsource(plugin_routes.autoinject_retrieve)
|
|
assert "co_surfaced(" in prompt_door and 'arm="p"' in prompt_door
|
|
write_door = inspect.getsource(plugin_context.build_write_path_hint)
|
|
assert "co_surfaced(" in write_door and 'arm="w"' in write_door
|