CI & Build / TypeScript typecheck (push) Successful in 38s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m45s
CI & Build / integration (push) Successful in 2m10s
CI & Build / Build & push image (push) Skipped
- A rule set to enforce, reached by a mount or a trigger, refuses the tool call in its own words every time (`act_decision`, `/moment` returns `decision`, grimoire_moment.sh denies). Opening it does not lift it. - A rule set to hold denies the call once until read, under the act checkpoint's per-rule and per-session guard; file writes are never held. - The reply hold, the reply backstop and the act checkpoint hold only on rules declared hold or enforce (`rule_order.holds`). An inform rule is a line beside the work. - The prompt arm leaves rules that arrive at an act (mounted on a non-reply moment, or with a tool/path/command trigger) to that act. - The end-of-turn shape check no longer blocks: its note is kept for the next prompt, carried as `carry` into the one fitted payload, and the stop after that prompt records whether the lines were judged (noted / judged_after_note / left_after_note). - Rule editor and list copy say what hold and enforce now do. Plugin 2026.11.23.0005. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.1 KiB
Python
94 lines
4.1 KiB
Python
"""The server half of the end-of-turn shape check: what the
|
|
agent is asked at its next prompt, what the hook's ledger may say, and the
|
|
outcome record."""
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from tests.helpers import make_mock_session
|
|
|
|
|
|
def test_the_ledger_lines_parse_and_garbage_is_dropped():
|
|
from grimoire.services.shape_check import parse_written
|
|
|
|
raw = ("a.py\tsym\thelper\n"
|
|
"a.py\tsym\thelper\n" # duplicate
|
|
"web/A.svelte\tfile\tA\n"
|
|
"x.py\tbogus\tthing\n" # unknown kind
|
|
"only-two\tsym\n" # malformed
|
|
"\tsym\tnameless-path\n")
|
|
assert parse_written(raw) == [("a.py", "sym", "helper"), ("web/A.svelte", "file", "A")]
|
|
assert len(parse_written("".join(f"p\tsym\tn{i}\n" for i in range(500)), cap=7)) == 7
|
|
|
|
|
|
def test_a_stop_notes_or_passes_and_the_stop_after_the_note_records_the_answer():
|
|
from grimoire.services.shape_check import outcome_for
|
|
|
|
one = [{"path": "a", "kind": "sym", "symbol": "b"}]
|
|
assert outcome_for("check", one) == "noted"
|
|
assert outcome_for("check", []) == "passed"
|
|
assert outcome_for("after", one) == "left_after_note"
|
|
assert outcome_for("after", []) == "judged_after_note"
|
|
|
|
|
|
def test_the_note_names_each_shape_its_evidence_and_the_one_call():
|
|
from grimoire.services.shape_check import note_text
|
|
|
|
unjudged = [
|
|
{"path": "web/A.svelte", "kind": "file", "symbol": "A", "status": "new", "evidence": {}},
|
|
{"path": "src/x.py", "kind": "sym", "symbol": "load", "status": "unclassified",
|
|
"evidence": {"looks_like": {"snippet_id": 12, "basis": "semantic", "score": 0.84},
|
|
"diverges_from": 9}},
|
|
]
|
|
reason = note_text(unjudged, project_id=3, repo="git.example.com/a/w")
|
|
assert "last turn wrote 2 definitions" in reason
|
|
assert "web/A.svelte · A (file) — new" in reason
|
|
assert "looks like #12 0.84" in reason and "#9 is canon in this directory" in reason
|
|
assert 'classify_shapes(project_id=3, repo="git.example.com/a/w"' in reason
|
|
for verdict in ("create_snippet", "`instance`", "`variant`", "`exempt`"):
|
|
assert verdict in reason, verdict
|
|
|
|
|
|
def test_a_long_turn_is_listed_with_a_tail_not_dropped():
|
|
from grimoire.services.shape_check import _LISTED, note_text
|
|
|
|
many = [{"path": "p.py", "kind": "sym", "symbol": f"f{i}", "status": "new", "evidence": {}}
|
|
for i in range(_LISTED + 3)]
|
|
reason = note_text(many, project_id=1, repo="")
|
|
assert "… and 3 more" in reason
|
|
assert "repo=" not in reason
|
|
|
|
|
|
async def test_the_outcome_is_recorded_as_a_plugin_event():
|
|
from grimoire.services.shape_check import record_shape_check
|
|
|
|
session = make_mock_session()
|
|
with patch("grimoire.services.shape_check.async_session", return_value=session):
|
|
await record_shape_check(7, "noted", written=5, unjudged=2, project_id=2)
|
|
row = session.add.call_args.args[0]
|
|
assert (row.category, row.action, row.user_id) == ("plugin", "shape_check", 7)
|
|
assert json.loads(row.details) == {"outcome": "noted", "written": 5,
|
|
"unjudged": 2, "project_id": 2}
|
|
|
|
|
|
async def test_an_unknown_outcome_is_refused_before_anything_is_written():
|
|
from grimoire.services.shape_check import record_shape_check
|
|
|
|
session = make_mock_session()
|
|
with patch("grimoire.services.shape_check.async_session", return_value=session), \
|
|
pytest.raises(ValueError):
|
|
await record_shape_check(7, "skipped", written=1, unjudged=1)
|
|
session.add.assert_not_called()
|
|
|
|
|
|
def test_the_window_counts_turns_asks_and_asks_walked_past():
|
|
from grimoire.services.shape_check import summarise
|
|
|
|
assert summarise([]) == {"checked": 0, "asked": 0, "left": 0}
|
|
got = summarise(["passed", "noted", "judged_after_note", "noted", "left_after_note"])
|
|
assert got == {"checked": 3, "asked": 2, "left": 1}
|
|
# A window that spans the end-of-turn hold this check once was still sums.
|
|
mixed = summarise(["blocked", "left_after_block", "noted", "judged_after_note"])
|
|
assert mixed == {"checked": 2, "asked": 2, "left": 1}
|