diff --git a/tests/test_mcp_tool_tasks.py b/tests/test_mcp_tool_tasks.py index f1a8e32e..8cc83ea5 100644 --- a/tests/test_mcp_tool_tasks.py +++ b/tests/test_mcp_tool_tasks.py @@ -8,7 +8,7 @@ from grimoire.mcp.tools.tasks import ( list_tasks, get_task, create_task, 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") @@ -271,3 +271,50 @@ async def test_add_task_log_propagates_value_error_when_task_missing(): ): with pytest.raises(ValueError): 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 diff --git a/tests/test_mcp_tool_tasks_kind.py b/tests/test_mcp_tool_tasks_kind.py deleted file mode 100644 index 3ffa04af..00000000 --- a/tests/test_mcp_tool_tasks_kind.py +++ /dev/null @@ -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") diff --git a/tests/test_reply_shapes.py b/tests/test_reply_shapes.py index 52578b45..3e65f776 100644 --- a/tests/test_reply_shapes.py +++ b/tests/test_reply_shapes.py @@ -119,16 +119,6 @@ async def test_the_tool_returns_the_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(): """Parity: the session and the Settings view cannot show different defaults.""" diff --git a/tests/test_retrieval_review.py b/tests/test_retrieval_review.py index ce4501a6..0648a6c4 100644 --- a/tests/test_retrieval_review.py +++ b/tests/test_retrieval_review.py @@ -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] # Related and left closed: the number an open rate could never show. 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"] == {} diff --git a/tests/test_services_notes_task_kind.py b/tests/test_services_notes_task_kind.py index 4c9de31a..999adb2a 100644 --- a/tests/test_services_notes_task_kind.py +++ b/tests/test_services_notes_task_kind.py @@ -21,3 +21,25 @@ async def test_create_note_passes_task_kind_to_model(): from grimoire.services.notes import create_note await create_note(user_id=1, title="P", status="todo", 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") diff --git a/tests/test_services_retrieval_telemetry.py b/tests/test_services_retrieval_telemetry.py index 5c434221..de6d36b7 100644 --- a/tests/test_services_retrieval_telemetry.py +++ b/tests/test_services_retrieval_telemetry.py @@ -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. assert out["usage"]["by_source"] == {} 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 diff --git a/tests/test_shape_ledger.py b/tests/test_shape_ledger.py index 2632845d..2d544ea2 100644 --- a/tests/test_shape_ledger.py +++ b/tests/test_shape_ledger.py @@ -78,14 +78,6 @@ def test_batch_validation_names_the_failing_item(): 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) --------------------- diff --git a/tests/test_system_usage_readout.py b/tests/test_system_usage_readout.py index 5cab7614..4cd80be5 100644 --- a/tests/test_system_usage_readout.py +++ b/tests/test_system_usage_readout.py @@ -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 # near zero on an arm that is working. 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