fix(7883): a lesson recorded for reply.report reaches the turn before the reply, and reply.ask is not offered to a lesson
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / integration (push) Successful in 2m0s
CI & Build / Python tests (push) Successful in 3m48s
CI & Build / Build & push image (push) Successful in 20s

Situated lessons arrived only at tool acts and in MCP replies, so a lesson
given a reply moment was accepted and never shown. The per-turn delivery now
carries lessons confirmed on reply.report, once per session, between the
turn's rules and its reply shape. reply.ask is known only after the reply is
written, so lesson_situations refuses it and leaves it out of the catalog the
pass and the lesson page offer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:48:12 -05:00
co-authored by Claude Opus 5.5
parent 5bde619511
commit 07c4a716bd
7 changed files with 114 additions and 23 deletions
+38 -2
View File
@@ -1,6 +1,7 @@
"""A situated lesson reaches the work through the moment doors: the plugin's
door shows it once per session, and an MCP reply, which has no session,
carries it every time its act happens."""
act door and the turn's delivery before a reply show it once per session,
and an MCP reply, which has no session, carries it every time its act
happens. A moment no door reaches is not offered to a lesson."""
from unittest.mock import AsyncMock, patch
import pytest
@@ -41,6 +42,41 @@ async def test_an_mcp_reply_carries_the_lessons_for_its_act_every_time():
ledger.assert_not_awaited()
@pytest.mark.asyncio
async def test_a_turn_carries_the_lessons_recorded_for_the_reply_before_it_is_written():
found = AsyncMock(return_value=ARRIVALS[:1])
with patch.object(moment_delivery, "deliver_moments", AsyncMock(return_value=rp.RuleResult())), \
patch.object(lesson_situations, "for_act", found), \
patch("grimoire.services.record_deliveries.delivered_this_session",
AsyncMock(return_value=set())):
out = await moment_delivery.deliver_for_turn(1, record=False)
assert found.await_args.args[1] == ["reply.report"]
assert out["lesson_ids"] == [41]
assert [p.block for p in out["lesson_parts"]] == ["lessons"]
assert lesson_situations.line(ARRIVALS[0]) in out["context"]
@pytest.mark.asyncio
async def test_a_turn_leaves_out_a_reply_lesson_the_session_already_has():
with patch.object(moment_delivery, "deliver_moments", AsyncMock(return_value=rp.RuleResult())), \
patch.object(lesson_situations, "for_act", AsyncMock(return_value=ARRIVALS[:1])), \
patch("grimoire.services.record_deliveries.delivered_this_session",
AsyncMock(return_value={41})):
out = await moment_delivery.deliver_for_turn(1, record=False)
assert out["lesson_ids"] == [] and out["lesson_parts"] == []
def test_a_lesson_is_offered_only_the_moments_a_door_brings_it_to():
offered = {m["name"] for m in lesson_situations.lesson_moments()}
assert "reply.report" in offered and "work.deliver" in offered
assert offered.isdisjoint(lesson_situations.NO_LESSON_DOOR)
# Whether a reply asks is known only after it is written: refused, with
# the moment that does arrive in time named in the reason.
with pytest.raises(ValueError, match="reply.report"):
lesson_situations._values(["reply.ask"], [])
assert lesson_situations._values(["reply.report"], []) == [("moment", "reply.report")]
def test_a_situation_reads_as_what_the_act_carries():
assert lesson_situations.describe("moment", "work.finish") == "moment `work.finish`"
assert lesson_situations.describe("trigger", "path\tmigrations/**\t") == "path `migrations/**`"
+17 -3
View File
@@ -30,11 +30,11 @@ SESSION_START = ROOT / "plugin" / "hooks" / "grimoire_session_context.sh"
# ── the route ────────────────────────────────────────────────────────────
async def _retrieve(query_string, turn_context="CORE SHAPE"):
async def _retrieve(query_string, turn_context="CORE SHAPE", turn_value=None):
from grimoire.routes import plugin as routes
turn = AsyncMock(return_value={"context": turn_context, "rule_ids": [173],
"shape_forms": {"core": reply_shapes.FULL}})
turn = AsyncMock(return_value=turn_value or {"context": turn_context, "rule_ids": [173],
"shape_forms": {"core": reply_shapes.FULL}})
app = Quart(__name__)
async with app.test_request_context("/api/plugin/retrieve", query_string=query_string):
g.user = SimpleNamespace(id=7)
@@ -57,6 +57,20 @@ async def test_the_turns_shape_follows_the_rules_and_its_key_comes_back():
assert body["rule_ids"] == [11, 173]
async def test_a_lesson_recorded_for_the_reply_sits_between_the_turns_rules_and_its_shape():
from grimoire.services import hook_payload as hp
body, _turn = await _retrieve({"q": "write the report"}, turn_value={
"context": "", "rule_ids": [173], "shape_forms": {"core": reply_shapes.FULL},
"rule_parts": [hp.Part(text="TURN RULE", block="rules", ids={hp.RULE: (173,)})],
"lesson_parts": [hp.Part(text="LESSON LINE", block="lessons", ids={hp.NOTE: (41,)})],
"lesson_ids": [41],
"shape_parts": [hp.Part(text="CORE SHAPE", ids={hp.SHAPE: ("core",)})],
})
ctx = body["context"]
assert ctx.index("TURN RULE") < ctx.index("LESSON LINE") < ctx.index("CORE SHAPE") < ctx.index("NOTES MENU")
async def test_the_route_hands_the_ledger_and_the_rules_just_named_to_the_turn():
_body, turn = await _retrieve({"q": "x", "shapes_seen": "core,bogus",
"exclude_rule_ids": "9", "held_rule_ids": "4"})