test(8249): area groups, first pass: one file folded in, three readout checks merged, two copies removed
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Successful in 2m23s
CI & Build / integration (push) Successful in 2m25s
CI & Build / Build & push image (push) Successful in 19s

- test_mcp_tool_tasks_kind.py is folded into test_mcp_tool_tasks.py, the
  tool's own file: the two "kind passes through" cases are one table, the two
  list-filter cases one table; the minted_kind refusals move to the service's
  kind tests (test_services_notes_task_kind.py).
- A fresh install reads as empty, not failed: three database tests each ran
  retrieval_summary on an empty install and checked one block
  (usage, judged, system_usage). One test now checks all three.
- test_reply_shapes::test_the_tool_is_registered_as_a_read: everything it
  checked, test_moments::test_the_tools_are_registered_and_classified checks.
- test_shape_ledger::test_classify_and_list_are_mounted_as_mcp_tools: every
  classified tool name must be a registered tool
  (test_mcp_auth::test_every_registered_tool_is_classified_exactly_once).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 19:45:38 -05:00
co-authored by Claude Opus 5.5
parent 1d3d72d2d4
commit 094089e374
8 changed files with 77 additions and 139 deletions
+48 -1
View File
@@ -8,7 +8,7 @@ from grimoire.mcp.tools.tasks import (
list_tasks, get_task, create_task, list_tasks, get_task, create_task,
update_task, add_task_log, update_task, add_task_log,
) )
from tests.helpers import fake_task from tests.helpers import fake_note, fake_task
pytestmark = pytest.mark.usefixtures("_bind_user") pytestmark = pytest.mark.usefixtures("_bind_user")
@@ -271,3 +271,50 @@ async def test_add_task_log_propagates_value_error_when_task_missing():
): ):
with pytest.raises(ValueError): with pytest.raises(ValueError):
await add_task_log(task_id=999, content="x") await add_task_log(task_id=999, content="x")
# ── kind: the door passes it through, and "" leaves it alone ─────────────
@pytest.mark.asyncio
@pytest.mark.parametrize("kind", ["issue", "spike"])
async def test_create_task_passes_the_kind_through(kind):
"""`spike` is the kind a failed rule-check asks for: time-boxed, and its
output is knowledge rather than a change, so filing one as `work` makes a
finished investigation look like an abandoned change."""
mock = AsyncMock(return_value=fake_note(task_kind=kind))
with patch("grimoire.mcp.tools.tasks.notes_svc.create_note", mock):
await create_task(title="Can the runner be given a bash shell?", kind=kind)
assert mock.call_args.kwargs["task_kind"] == kind
@pytest.mark.asyncio
@pytest.mark.parametrize("given,sent", [({"kind": "issue"}, "issue"), ({}, None)])
async def test_list_tasks_filters_by_kind_only_when_asked(given, sent):
mock = AsyncMock(return_value=([], 0))
with patch("grimoire.mcp.tools.tasks.notes_svc.list_notes", mock):
await list_tasks(**given)
assert mock.call_args.kwargs["task_kind"] == sent
@pytest.mark.asyncio
async def test_update_task_can_re_file_a_kind():
"""A task's kind must be CORRECTABLE, not write-once.
What a piece of work turns out to be is often clear only once it is under
way. Without a `kind` parameter on `update_task`, and with a REST route that
drops the field the editor sends, the save reports success and reverts on
reload.
"""
mock = AsyncMock(return_value=fake_note(task_kind="spike"))
with patch("grimoire.mcp.tools.tasks.notes_svc.update_note", mock):
await update_task(task_id=1, kind="spike")
assert mock.call_args.kwargs["task_kind"] == "spike"
@pytest.mark.asyncio
async def test_update_task_leaves_kind_alone_when_not_given():
""""" means leave unchanged, as it does for every other field here."""
mock = AsyncMock(return_value=fake_note())
with patch("grimoire.mcp.tools.tasks.notes_svc.update_note", mock):
await update_task(task_id=1, title="renamed")
assert "task_kind" not in mock.call_args.kwargs
-99
View File
@@ -1,99 +0,0 @@
from unittest.mock import AsyncMock, patch
import pytest
from tests.helpers import fake_note
pytestmark = pytest.mark.usefixtures("_bind_user")
@pytest.mark.asyncio
async def test_create_task_passes_kind():
# kind=plan is retired (plans are milestones); 'issue' exercises passthrough.
mock = AsyncMock(return_value=fake_note(task_kind="issue"))
with patch("grimoire.mcp.tools.tasks.notes_svc.create_note", mock):
from grimoire.mcp.tools.tasks import create_task
await create_task(title="P", kind="issue")
assert mock.call_args.kwargs["task_kind"] == "issue"
@pytest.mark.asyncio
async def test_list_tasks_passes_kind_filter():
mock = AsyncMock(return_value=([], 0))
with patch("grimoire.mcp.tools.tasks.notes_svc.list_notes", mock):
from grimoire.mcp.tools.tasks import list_tasks
await list_tasks(kind="plan")
assert mock.call_args.kwargs["task_kind"] == "plan"
@pytest.mark.asyncio
async def test_list_tasks_kind_empty_means_no_filter():
mock = AsyncMock(return_value=([], 0))
with patch("grimoire.mcp.tools.tasks.notes_svc.list_notes", mock):
from grimoire.mcp.tools.tasks import list_tasks
await list_tasks()
assert mock.call_args.kwargs["task_kind"] is None
@pytest.mark.asyncio
async def test_create_task_passes_spike():
"""The kind a failed rule-check asks for.
Time-boxed, and its output is knowledge rather than a change — filing one
as `work` makes a finished investigation look like an abandoned change.
"""
mock = AsyncMock(return_value=fake_note(task_kind="spike"))
with patch("grimoire.mcp.tools.tasks.notes_svc.create_note", mock):
from grimoire.mcp.tools.tasks import create_task
await create_task(title="Can the runner be given a bash shell?", kind="spike")
assert mock.call_args.kwargs["task_kind"] == "spike"
@pytest.mark.asyncio
async def test_update_task_can_re_file_a_kind():
"""A task's kind must be CORRECTABLE, not write-once.
What a piece of work turns out to be is often clear only once it is under
way. Without a `kind` parameter on `update_task`, and with a REST route that
drops the field the editor sends, the save reports success and reverts on
reload.
"""
mock = AsyncMock(return_value=fake_note(task_kind="spike"))
with patch("grimoire.mcp.tools.tasks.notes_svc.update_note", mock):
from grimoire.mcp.tools.tasks import update_task
await update_task(task_id=1, kind="spike")
assert mock.call_args.kwargs["task_kind"] == "spike"
@pytest.mark.asyncio
async def test_update_task_leaves_kind_alone_when_not_given():
""""" means leave unchanged, as it does for every other field here."""
mock = AsyncMock(return_value=fake_note())
with patch("grimoire.mcp.tools.tasks.notes_svc.update_note", mock):
from grimoire.mcp.tools.tasks import update_task
await update_task(task_id=1, title="renamed")
assert "task_kind" not in mock.call_args.kwargs
@pytest.mark.asyncio
async def test_minting_a_plan_is_refused_at_both_doors():
"""`plan` is a valid stored value and NOT a mintable one.
Historical plan-tasks carry it and must stay writable, so the column
keeps accepting it — but plans became milestones in 0066, so no door
hands out a new one. The error names start_planning rather than just
refusing, because a caller reaching for kind='plan' wants a plan.
"""
from grimoire.services.notes import minted_kind
with pytest.raises(ValueError, match="start_planning"):
minted_kind("plan")
@pytest.mark.asyncio
async def test_an_unknown_kind_raises_rather_than_defaulting():
"""A silently-corrected kind is the defect this whole fix exists to end."""
from grimoire.services.notes import minted_kind
with pytest.raises(ValueError, match="kind must be one of"):
minted_kind("investigation")
-10
View File
@@ -119,16 +119,6 @@ async def test_the_tool_returns_the_catalog():
assert await tool.list_reply_shapes() == reply_shapes.catalog() assert await tool.list_reply_shapes() == reply_shapes.catalog()
def test_the_tool_is_registered_as_a_read():
from grimoire.mcp.server import _READ_ONLY_TOOLS
from grimoire.mcp.tools import moments as tool
mcp = FakeMCP()
tool.register(mcp)
assert "list_reply_shapes" in mcp.names
assert "list_reply_shapes" in _READ_ONLY_TOOLS
def test_both_doors_read_one_catalog(): def test_both_doors_read_one_catalog():
"""Parity: the session and the Settings view cannot show """Parity: the session and the Settings view cannot show
different defaults.""" different defaults."""
-9
View File
@@ -381,12 +381,3 @@ async def test_verdicts_land_replace_and_read_back_by_rank(logged_calls):
assert [r["rank"] for r in ai["by_rank"]] == [1, 4] assert [r["rank"] for r in ai["by_rank"]] == [1, 4]
# Related and left closed: the number an open rate could never show. # Related and left closed: the number an open rate could never show.
assert ai["on_point_unopened"] == 1 assert ai["on_point_unopened"] == 1
@pytest.mark.integration
@pytest.mark.asyncio
@pytest.mark.usefixtures("_dispose_engine")
async def test_a_fresh_install_reads_an_empty_judged_block_not_a_failure():
from grimoire.services.retrieval_telemetry import retrieval_summary
assert (await retrieval_summary(990041, days=30))["judged"] == {}
+22
View File
@@ -21,3 +21,25 @@ async def test_create_note_passes_task_kind_to_model():
from grimoire.services.notes import create_note from grimoire.services.notes import create_note
await create_note(user_id=1, title="P", status="todo", task_kind="plan") await create_note(user_id=1, title="P", status="todo", task_kind="plan")
assert captured["task_kind"] == "plan" assert captured["task_kind"] == "plan"
def test_minting_a_plan_is_refused_at_both_doors():
"""`plan` is a valid stored value and NOT a mintable one.
Historical plan-tasks carry it and must stay writable, so the column
keeps accepting it — but plans became milestones in 0066, so no door
hands out a new one. The error names start_planning rather than just
refusing, because a caller reaching for kind='plan' wants a plan.
"""
from grimoire.services.notes import minted_kind
with pytest.raises(ValueError, match="start_planning"):
minted_kind("plan")
def test_an_unknown_kind_raises_rather_than_defaulting():
"""A silently-corrected kind is the defect this whole fix exists to end."""
from grimoire.services.notes import minted_kind
with pytest.raises(ValueError, match="kind must be one of"):
minted_kind("investigation")
@@ -341,6 +341,13 @@ async def test_retrieval_summary_is_empty_not_broken_for_a_fresh_install(_dispos
# "no rows" / "read broke" distinction the rest of this readout keeps. # "no rows" / "read broke" distinction the rest of this readout keeps.
assert out["usage"]["by_source"] == {} assert out["usage"]["by_source"] == {}
assert "by_source_failed" not in out["usage"] assert "by_source_failed" not in out["usage"]
# Every block reads as empty, never as a failure: the judged block, and
# the per-System usage block with no window to cover.
assert out["judged"] == {}
block = out["system_usage"]
assert "system_usage_failed" not in block
assert block["surfaced"] == 0 and block["by_system"] == []
assert block["covers_window"] is None
@pytest.mark.integration @pytest.mark.integration
-8
View File
@@ -78,14 +78,6 @@ def test_batch_validation_names_the_failing_item():
assert v([{"path": "a", "symbol": "f", "status": "unclassified"}]) is None assert v([{"path": "a", "symbol": "f", "status": "unclassified"}]) is None
def test_classify_and_list_are_mounted_as_mcp_tools():
from grimoire.mcp.server import build_mcp_server
mcp = build_mcp_server()
for name in ("classify_shapes", "list_shapes", "refresh_pattern_coverage"):
assert mcp._tool_manager.get_tool(name) is not None
# --- step 5: the write-path feed's evidence tests (pure) --------------------- # --- step 5: the write-path feed's evidence tests (pure) ---------------------
-12
View File
@@ -146,15 +146,3 @@ async def test_the_telemetry_block_names_the_areas_and_offers_no_ratio(ruled_are
# Rulings are delivered in full in the line; a ratio of opens would read # Rulings are delivered in full in the line; a ratio of opens would read
# near zero on an arm that is working. # near zero on an arm that is working.
assert "pull_through" not in block assert "pull_through" not in block
@pytest.mark.integration
@pytest.mark.asyncio
@pytest.mark.usefixtures("_dispose_engine")
async def test_a_fresh_install_reads_zero_not_failed():
from grimoire.services.retrieval_telemetry import retrieval_summary
block = (await retrieval_summary(990031, days=30))["system_usage"]
assert "system_usage_failed" not in block
assert block["surfaced"] == 0 and block["by_system"] == []
assert block["covers_window"] is None