From eb5cc6d3a76ae0c055659e6d15bc55f47b42921d Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 30 Sep 2026 23:27:07 -0400 Subject: [PATCH] fix(shapes): weak stamps elect no canon; the arrival line names the review; Svelte scopes by default (#4608) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Librarian and Stash had 132 and 488 write-path stamps written at 0.68-0.72, before the 0.80 floor (#4204). Nothing re-judged them, and dominant_canon counted them, so a YAML CI snippet (#3410) "dominated" Librarian's web directory and every write there was told it diverged from it — 1408 flags on one project, 902 on the other, all skimmed past. - is_weak_stamp: one predicate for "hook-stamped below today's floor". dominant_canon and canon_form skip such rows; stamps_to_review lists them by the same predicate. No stored row changes — they stay for judgment. - flag_divergence withdraws a standing flag whose canon no longer dominates its directory. A flag is a mechanical prompt, not a judgment. - The coverage line ends "N weak stamps · M incoherent canons to judge — stamps_to_review" when either is nonzero, so a project's own session sees the queue on arrival. The shape-accounting skill says what to do with it. - scoped_definitions handles .svelte: every \n" + ) + defs = extract_definitions(svelte) + names = {(d.kind, d.name) for d in defs} + assert {("sym", "stageOf"), ("sym", "toggle"), ("css", "card")} <= names + scoped = scoped_definitions("web/src/lib/A.svelte", svelte, defs) + assert ("sym", "toggle") in scoped and ("css", "card") in scoped + assert ("sym", "stageOf") not in scoped, "a module script's export is importable" + assert not any(n == "toast" for _, n in scoped), ":global(...) opts a selector out" + # The legacy spelling of the module block, and a whole global style block. + legacy = ( + "\n" + "\n" + ) + assert scoped_definitions("web/src/lib/B.svelte", legacy, extract_definitions(legacy)) == set() + + +def test_the_line_names_the_review_queue_and_the_tool_that_holds_it(): + """#4608: `stamps_to_review` existed and two projects never called it, + because nothing on arrival said there was anything to review.""" + from scribe.services.coverage import coverage_line + base = {"accounted": 10, "total": 10, "counts": {"exempt": 10}, + "unclassified": 0, "computed_at": "2026-09-30T00:00:00"} + assert "stamps_to_review" not in coverage_line(base) + line = coverage_line({**base, "weak_stamps": 132, "incoherent_canons": 3}) + assert line.endswith("; 132 weak stamps · 3 incoherent canons to judge — stamps_to_review") + assert coverage_line({**base, "weak_stamps": 1}).endswith("; 1 weak stamp to judge — stamps_to_review") + + @pytest.mark.integration async def test_binding_ref_is_the_branch_the_ledger_follows(seeded): """#2873: a binding that names a ref is read at that ref (not the forge's diff --git a/tests/test_stamps_to_review.py b/tests/test_stamps_to_review.py index ac839b6..b4d7066 100644 --- a/tests/test_stamps_to_review.py +++ b/tests/test_stamps_to_review.py @@ -350,3 +350,53 @@ def test_the_coherence_verdict_reads_rows_and_writes_nothing() -> None: canon_coherence(rows) assert [(r.path, r.symbol, r.status, r.snippet_id, r.signature) for r in rows] == before + + +# ── a weak stamp is listed for judgment and counted by nobody (#4608) ───── +# +# The floor guarded new writes; the rows written before it went on electing +# canons. On two projects a YAML CI snippet "dominated" a Svelte directory on +# the strength of 0.68-0.72 stamps, and every write there was told it +# diverged from it. The readers below must agree with the review surface +# about what "weak" means — one predicate, so they cannot drift apart. + +def test_one_predicate_says_what_weak_is() -> None: + from scribe.services.shape_ledger import is_weak_stamp + + assert is_weak_stamp(_stamped(0.72)) + assert not is_weak_stamp(_stamped(_RESEMBLE_MIN)) + # A by-name stamp carries no score: it is not resemblance evidence at all. + assert not is_weak_stamp(_Row(reason="hook: pulled #1; payload references `f`")) + for by in ("agent", "audit", "mechanical"): + assert not is_weak_stamp(_stamped(0.5, classified_by=by)), by + + +def test_weak_stamps_do_not_elect_a_dominant_canon() -> None: + from scribe.services.shape_ledger import dominant_canon + + weak = [_stamped(0.72, path=f"web/src/lib/{i}.ts", symbol=f"f{i}") for i in range(5)] + assert dominant_canon(weak) is None + # The same rows judged by an agent do — the kind of evidence is the point. + judged = [_stamped(0.72, path=f"web/src/lib/{i}.ts", symbol=f"f{i}", classified_by="agent") + for i in range(5)] + assert dominant_canon(judged) == (1, 5, 5) + # And weak rows do not dilute a real majority either: they are not counted + # as judged at all. + mixed = judged[:3] + [_stamped(0.7, snippet_id=2, symbol=f"g{i}") for i in range(4)] + assert dominant_canon(mixed) == (1, 3, 3) + + +def test_weak_stamps_do_not_say_what_form_a_canon_is() -> None: + from scribe.services.shape_ledger import FORM_UNKNOWN, canon_form + + weak = [_stamped(0.7, symbol=f"T{i}", signature=f"class T{i}:") for i in range(5)] + assert canon_form(weak, 1) == FORM_UNKNOWN + judged = [_stamped(0.7, symbol=f"T{i}", signature=f"class T{i}:", classified_by="audit") + for i in range(5)] + assert canon_form(judged + weak, 1) == canon_form(judged, 1) != FORM_UNKNOWN + + +def test_counting_them_out_leaves_them_listed() -> None: + """Not counted is not withdrawn: the review still lists every one.""" + rows = [_stamped(0.7, symbol=f"f{i}") for i in range(3)] + assert stamps_to_review(rows)["weak_count"] == 3