feat(7836): a lesson arrives at the situation confirmed for it, once per session
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped
Each lesson can carry its situation: a moment of work (work.deliver, work.finish, ...) or a typed trigger on the act (path, command, tool, keyword, matched as rule triggers are). A pass proposes, a person judges: - lesson_situations (migration 0137): one row per lesson, kind and value, suggested / confirmed / rejected; `none` records that no situation fits; - MCP: lessons_to_situate, propose_lesson_situations, lesson_situation_proposals, judge_lesson_situations; - Settings > Moments lists waiting proposals with Apply / Not this / Apply all; a lesson page lists its situations and lets a writer add one or take one off (kept as rejected, never proposed again). Delivery: the moment doors (the plugin catch-all hook and MCP replies) add the lessons whose confirmed moment the act reached or whose trigger it matches. The plugin door shows each once per session, using the record ledger, and records it as pushed (source lesson_situation); the tool filter now includes the tools a lesson trigger listens on. The edit door no longer finds lessons by meaning: lesson leaves the work.change default kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""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."""
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from grimoire.services import lesson_situations, moment_delivery
|
||||
from grimoire.services import retrieval_pipeline as rp
|
||||
|
||||
ARRIVALS = [
|
||||
lesson_situations.Arrival(41, "A green build is not a running deploy", "moment `work.deliver`"),
|
||||
lesson_situations.Arrival(42, "Read the job log first", "command `git push`"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_plugin_door_leaves_out_what_the_session_already_has():
|
||||
with patch.object(lesson_situations, "for_act", AsyncMock(return_value=ARRIVALS)), \
|
||||
patch("grimoire.services.record_deliveries.delivered_this_session",
|
||||
AsyncMock(return_value={41})):
|
||||
lines, ids = await moment_delivery.lessons_for_act(
|
||||
1, [{"moment": "work.deliver"}], "Bash", {"command": "git push"},
|
||||
)
|
||||
assert ids == [42]
|
||||
assert lines == [lesson_situations.line(ARRIVALS[1])]
|
||||
assert "`get_lesson(42)`" in lines[0] and "command `git push`" in lines[0]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_an_mcp_reply_carries_the_lessons_for_its_act_every_time():
|
||||
ledger = AsyncMock(return_value={41, 42})
|
||||
with patch.object(moment_delivery, "deliver_for_act",
|
||||
AsyncMock(return_value=([{"moment": "work.finish"}], rp.RuleResult()))), \
|
||||
patch.object(moment_delivery, "shapes_for_act", lambda reached: ([], {})), \
|
||||
patch.object(lesson_situations, "for_act", AsyncMock(return_value=ARRIVALS[:1])), \
|
||||
patch("grimoire.services.record_deliveries.delivered_this_session", ledger):
|
||||
data = await moment_delivery.attach_moment_rules(1, "update_task", {"status": "done"}, {})
|
||||
assert data["moment_lessons"]["lesson_ids"] == [41]
|
||||
assert data["moment_lessons"]["open_with"] == "get_lesson(id)"
|
||||
ledger.assert_not_awaited()
|
||||
|
||||
|
||||
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/**`"
|
||||
Reference in New Issue
Block a user