feat(moments): skills and stored processes declare the moments they are for (milestone 458 step 5, #4923)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / integration (push) Successful in 1m3s
CI & Build / Python tests (push) Failing after 1m25s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / integration (push) Successful in 1m3s
CI & Build / Python tests (push) Failing after 1m25s
CI & Build / Build & push image (push) Skipped
Loading a procedure now also reaches the moment it is for. Loading the reporting procedure is a report; loading the release procedure is a delivery. - Bundled skills: each SKILL.md declares `metadata: moments:`. The same declaration ships as Skill defaults (BUNDLED_SKILL_MOMENTS), because the server never sees the plugin's files. test_skill_moments holds the two together and pins the plugin name that qualifies the skill. - Stored processes: `moments` on create_process and update_process, stored in the note's data and returned by get_process. A `scribe-proc-<slug>` load resolves its process through the sync manifest at load time. The moments are not copied into the stub, which would go stale mid-session. - reachable_tools lists the skill loader whenever anything is mounted, since a process's moments are known only when it loads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,9 +109,22 @@ def test_a_whole_tool_mapping_ignores_its_arguments():
|
||||
|
||||
|
||||
def test_loading_a_procedure_reaches_its_own_moment():
|
||||
assert _reached("Skill", {"skill": "release-notes"}) == ["skill.release-notes"]
|
||||
|
||||
|
||||
def test_a_bundled_skill_also_reaches_the_moment_it_is_for():
|
||||
"""Loading the planning procedure IS planning: a rule mounted on work.plan
|
||||
arrives on the load, not only on the plan it goes on to open."""
|
||||
assert _reached("Skill", {"skill": "scribe:writing-plans"}) == [
|
||||
"skill.scribe:writing-plans",
|
||||
"work.plan", "skill.scribe:writing-plans",
|
||||
]
|
||||
assert _reached("Skill", {"skill": "scribe:reporting-back"})[0] == "reply.report"
|
||||
|
||||
|
||||
def test_only_the_products_own_skill_reaches_a_bundled_default():
|
||||
"""Another plugin's `verification` skill is not the product's procedure;
|
||||
the plugin's name is what makes the declaration ours."""
|
||||
assert _reached("Skill", {"skill": "other:verification"}) == ["skill.other:verification"]
|
||||
|
||||
|
||||
def test_a_procedure_name_that_is_not_a_moment_reaches_nothing():
|
||||
@@ -119,6 +132,79 @@ def test_a_procedure_name_that_is_not_a_moment_reaches_nothing():
|
||||
assert _reached("Skill", {}) == []
|
||||
|
||||
|
||||
# ── a stored process's own moments ───────────────────────────────────────
|
||||
|
||||
def test_a_process_declares_moments_its_load_reaches():
|
||||
hits = ma.resolve("Skill", {"skill": "scribe-proc-release"}, [], ["work.deliver"])
|
||||
assert [(h["moment"], h["via"]) for h in hits] == [
|
||||
("work.deliver", ma.PROCESS), ("skill.scribe-proc-release", ma.DEFAULT),
|
||||
]
|
||||
assert hits[0]["match"] == "skill=scribe-proc-release"
|
||||
|
||||
|
||||
def test_a_declared_moment_another_action_reaches_is_named_once():
|
||||
rows = [_row("Skill", "skill=scribe-proc-release", "work.deliver")]
|
||||
hits = ma.resolve("Skill", {"skill": "scribe-proc-release"}, rows, ["work.deliver"])
|
||||
assert [h["moment"] for h in hits].count("work.deliver") == 1
|
||||
|
||||
|
||||
def test_declared_moments_only_reach_a_skill_load():
|
||||
hits = ma.resolve("Bash", {"command": "ls"}, [], ["work.deliver"])
|
||||
assert [h["moment"] for h in hits] == ["work.run"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data, expected", [
|
||||
(None, []),
|
||||
({}, []),
|
||||
({"moments": ["work.deliver", "Work.Deliver", "reply.report"]}, ["work.deliver", "reply.report"]),
|
||||
({"moments": "work.verify"}, ["work.verify"]),
|
||||
({"moments": ["work.finished", "skill.two words", "work.debug"]}, ["work.debug"]),
|
||||
])
|
||||
def test_a_process_field_is_read_defensively(data, expected):
|
||||
"""A moment the catalog no longer has stops firing; it does not break the load."""
|
||||
assert ma.declared_moments(data) == expected
|
||||
|
||||
|
||||
async def test_only_a_process_skill_asks_for_its_process():
|
||||
asked = AsyncMock(return_value=["work.deliver"])
|
||||
with patch.object(ma, "list_mappings", AsyncMock(return_value=[])), \
|
||||
patch.object(ma, "process_moments", asked):
|
||||
reached = await ma.moments_for(1, "Skill", {"skill": "scribe-proc-release"})
|
||||
await ma.moments_for(1, "Skill", {"skill": "scribe:verification"})
|
||||
await ma.moments_for(1, "Bash", {"command": "git push"})
|
||||
assert "work.deliver" in [h["moment"] for h in reached]
|
||||
asked.assert_awaited_once_with(1, "scribe-proc-release")
|
||||
|
||||
|
||||
async def _process_moments(manifest, note=None, *, raises=False):
|
||||
from scribe.services import notes as notes_svc
|
||||
from scribe.services import plugin_context
|
||||
|
||||
built = AsyncMock(side_effect=RuntimeError("down")) if raises else AsyncMock(return_value=manifest)
|
||||
loader = AsyncMock(return_value=(note, None) if note is not None else None)
|
||||
with patch.object(plugin_context, "build_process_manifest", built), \
|
||||
patch.object(notes_svc, "get_note_for_user", loader):
|
||||
return await ma.process_moments(1, "scribe-proc-release"), loader
|
||||
|
||||
|
||||
async def test_a_process_slug_resolves_through_the_sync_manifest():
|
||||
"""The same manifest the sync script wrote the skill from, so the slug
|
||||
names the same process here as it did on disk."""
|
||||
note = SimpleNamespace(data={"moments": ["work.deliver"]})
|
||||
found, loader = await _process_moments(
|
||||
{"processes": [{"id": 7, "slug": "other"}, {"id": 9, "slug": "release"}]}, note)
|
||||
assert found == ["work.deliver"]
|
||||
loader.assert_awaited_once_with(1, 9)
|
||||
|
||||
|
||||
async def test_an_unknown_or_unreadable_process_reaches_nothing_more():
|
||||
found, loader = await _process_moments({"processes": [{"id": 7, "slug": "other"}]})
|
||||
assert found == []
|
||||
loader.assert_not_awaited()
|
||||
found, _ = await _process_moments({}, raises=True)
|
||||
assert found == []
|
||||
|
||||
|
||||
# ── an install's own ─────────────────────────────────────────────────────
|
||||
|
||||
def test_an_install_mapping_adds_a_moment():
|
||||
|
||||
Reference in New Issue
Block a user