test_descriptions.py

tests/test_descriptions.py

Tests for the JSON tool-description loader.

test_a_bare_string_description_is_accepted

None test_descriptions.test_a_bare_string_description_is_accepted(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A one-sentence description may be a bare string.

tests/test_descriptions.py:361

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Checks

  • assert d.load_descriptions() == {"dossier": "Just the one line."}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_a_bare_string_description_is_accepted → load_descriptions
REQ-DDB-WIKI-054inferredtest_a_bare_string_description_is_accepted → load_descriptions → _entry → _joined → all
Source · 10 lines
def test_a_bare_string_description_is_accepted(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """The list form exists for diff readability, not as a ceremony a short
    description has to perform."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "dossier", {"tool": "dossier", "description": "Just the one line."})
    assert d.load_descriptions() == {"dossier": "Just the one line."}

Activity · 3 steps
lines 366–366_redirect(monkeypatch, tmp_path)lines 367–367_put(tmp_path, "dossier", {"tool": "dossier", "description": "Just the one line."})lines 368–368assert d.load_descriptions() == {"dossier": "Just the one line."}

test_bad_json_names_the_file

None test_descriptions.test_bad_json_names_the_file(Path tmp_path, pytest.MonkeyPatch monkeypatch)

Malformed JSON names the file it is in.

tests/test_descriptions.py:329

Show on the map →

Called by none

Calls _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_bad_json_names_the_file → load_descriptions
REQ-DDB-WIKI-054inferredtest_bad_json_names_the_file → load_descriptions → _entry → _joined → all
Source · 9 lines
def test_bad_json_names_the_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """A bare `JSONDecodeError` gives a line and column but not a filename, and these
    are hand-edited content files — the filename is the first thing you need."""
    _redirect(monkeypatch, tmp_path)
    (tmp_path / "dossier.json").write_text('{"tool": "dossier",}', encoding="utf-8")
    with pytest.raises(ValueError, match="dossier.json is not valid JSON"):
        d.load_descriptions()

Activity · 4 steps
lines 332–332_redirect(monkeypatch, tmp_path)lines 333–333(tmp_path / "dossier.json").write_text('{"tool": "dossier",}', encoding="utf-8")lines 334–334with pytest.raises(ValueError, match="dossier.json is not valid JSON")lines 335–335d.load_descriptions()

test_empty_directory_is_an_error

None test_descriptions.test_empty_directory_is_an_error(Path tmp_path, pytest.MonkeyPatch monkeypatch)

An empty descriptions directory raises instead of returning {}.

tests/test_descriptions.py:236

Show on the map →

Called by none

Calls _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_empty_directory_is_an_error → load_descriptions
REQ-DDB-WIKI-054inferredtest_empty_directory_is_an_error → load_descriptions → _entry → _joined → all
Source · 8 lines
def test_empty_directory_is_an_error(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """This is the packaging failure: a wheel built without the data files would
    otherwise start a server advertising nothing, with no explanation."""
    _redirect(monkeypatch, tmp_path)
    with pytest.raises(ValueError, match="no tool descriptions"):
        d.load_descriptions()

Activity · 3 steps
lines 239–239_redirect(monkeypatch, tmp_path)lines 240–240with pytest.raises(ValueError, match="no tool descriptions")lines 241–241d.load_descriptions()

test_filename_and_declared_tool_must_agree

None test_descriptions.test_filename_and_declared_tool_must_agree(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A file whose declared tool disagrees with its filename is refused.

tests/test_descriptions.py:263

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_filename_and_declared_tool_must_agree → load_descriptions
REQ-DDB-WIKI-054inferredtest_filename_and_declared_tool_must_agree → load_descriptions → _entry → _joined → all
Source · 12 lines
def test_filename_and_declared_tool_must_agree(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """Otherwise a copied-and-edited file describes one tool under another's name,
    and the correspondence test above would still pass because the FILENAME set is
    right."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "callers", {"tool": "callees", "description": ["mismatched"]})
    with pytest.raises(ValueError, match="declares tool"):
        d.load_descriptions()

Activity · 4 steps
lines 269–269_redirect(monkeypatch, tmp_path)lines 270–270_put(tmp_path, "callers", {"tool": "callees", "description": ["mismatched"]})lines 271–271with pytest.raises(ValueError, match="declares tool")lines 272–272d.load_descriptions()

test_missing_snippet_is_refused

None test_descriptions.test_missing_snippet_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

An unknown snippet name is refused.

tests/test_descriptions.py:203

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_missing_snippet_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_missing_snippet_is_refused → load_descriptions → _entry → _joined → all
Source · 8 lines
def test_missing_snippet_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """@brief A typo'd include must fail rather than silently append nothing."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "dossier", {"description": ["Body."], "include": ["row"]})
    with pytest.raises(ValueError, match="no such snippet"):
        d.load_descriptions()

Activity · 4 steps
lines 205–205_redirect(monkeypatch, tmp_path)lines 206–206_put(tmp_path, "dossier", {"description": ["Body."], "include": ["row"]})lines 207–207with pytest.raises(ValueError, match="no such snippet")lines 208–208d.load_descriptions()

test_missing_template_is_refused

None test_descriptions.test_missing_template_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A template name that does not exist is refused.

tests/test_descriptions.py:280

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_missing_template_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_missing_template_is_refused → load_descriptions → _entry → _joined → all
Source · 8 lines
def test_missing_template_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """@brief A typo'd template name must fail, not yield empty text."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "callers", {"tool": "callers", "template": "neighbour", "vars": {}})
    with pytest.raises(ValueError, match="no such template"):
        d.load_descriptions()

Activity · 4 steps
lines 282–282_redirect(monkeypatch, tmp_path)lines 283–283_put(tmp_path, "callers", {"tool": "callers", "template": "neighbour", "vars": {}})lines 284–284with pytest.raises(ValueError, match="no such template")lines 285–285d.load_descriptions()

test_missing_var_is_refused

None test_descriptions.test_missing_var_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A template var the text needs but the file omits is refused.

tests/test_descriptions.py:312

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_missing_var_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_missing_var_is_refused → load_descriptions → _entry → _joined → all
Source · 12 lines
def test_missing_var_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """@brief An unsupplied placeholder must fail rather than render a brace."""
    _redirect(monkeypatch, tmp_path)
    (tmp_path / "_templates").mkdir()
    (tmp_path / "_templates" / "t.json").write_text(
        json.dumps({"text": ["hello {lead} and {seam}"]}), encoding="utf-8"
    )
    _put(tmp_path, "callers", {"template": "t", "vars": {"lead": "x"}})
    with pytest.raises(ValueError, match="needs var"):
        d.load_descriptions()

Activity · 6 steps
lines 314–314_redirect(monkeypatch, tmp_path)lines 315–315(tmp_path / "_templates").mkdir()lines 316–318(tmp_path / "_templates" / "t.json").write_text( json.dumps({"text": ["hello {lead} and {seam}"]}), encoding="utf-8" )lines 319–319_put(tmp_path, "callers", {"template": "t", "vars": {"lead": "x"}})lines 320–320with pytest.raises(ValueError, match="needs var")lines 321–321d.load_descriptions()

test_no_description_claims_an_elided_field_is_null

None test_descriptions.test_no_description_claims_an_elided_field_is_null()

The neighbours template no longer claims a key row's confidence is null.

tests/test_descriptions.py:189

Checks

  • assert "is null" not in text, "a description claims a field is null; it is absent"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_no_description_claims_an_elided_field_is_null → load_descriptions
REQ-DDB-WIKI-054inferredtest_no_description_claims_an_elided_field_is_null → load_descriptions → _entry → _joined → all
Source · 9 lines
def test_no_description_claims_an_elided_field_is_null() -> None:
    """A REGRESSION TEST for a real contradiction: the template said `confidence` is
    null on a 'key' row, and that became false when `wire` began eliding fields carrying
    no value. A description that contradicts the payload is worse than a vague one,
    because a model acts on it."""
    for text in d.load_descriptions().values():
        assert "is null" not in text, "a description claims a field is null; it is absent"

Activity · 2 steps
lines 194–194◇ for text in d.load_descriptions().values()lines 195–195assert "is null" not in text, "a description claims a field is null; it is absent"

test_non_string_description_is_refused

None test_descriptions.test_non_string_description_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A non-string description value is refused.

tests/test_descriptions.py:343

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_non_string_description_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_non_string_description_is_refused → load_descriptions → _entry → _joined → all
Source · 13 lines
def test_non_string_description_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """Covers the absent case too: `description` missing entirely arrives here as
    None, and must not join to an empty string."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "dossier", {"tool": "dossier", "description": [1, 2]})
    with pytest.raises(ValueError, match="must be a string or a list"):
        d.load_descriptions()

    _put(tmp_path, "dossier", {"tool": "dossier", "priority": 1})
    with pytest.raises(ValueError, match="must be a string or a list"):
        d.load_descriptions()

Activity · 7 steps
lines 346–346_redirect(monkeypatch, tmp_path)lines 347–347_put(tmp_path, "dossier", {"tool": "dossier", "description": [1, 2]})lines 348–348with pytest.raises(ValueError, match="must be a string or a list")lines 349–349d.load_descriptions()lines 351–351_put(tmp_path, "dossier", {"tool": "dossier", "priority": 1})lines 352–352with pytest.raises(ValueError, match="must be a string or a list")lines 353–353d.load_descriptions()

test_registration_order_follows_declared_priority

None test_descriptions.test_registration_order_follows_declared_priority()

Declared priority orders registration; dossier leads.

tests/test_descriptions.py:157

Checks

  • assert list(d.load_descriptions()) == ["dossier", "search"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_registration_order_follows_declared_priority → load_descriptions
REQ-DDB-WIKI-054inferredtest_registration_order_follows_declared_priority → load_descriptions → _entry → _joined → all
Source · 14 lines
def test_registration_order_follows_declared_priority() -> None:
    """Order is part of how the tool list reads, and `dossier` leading is deliberate —
    its description opens with CALL THIS FIRST.

    @brief The tier-1 list is ordered by declared priority.
    @return None.
    @version 2
    """
    assert list(d.load_descriptions()) == ["dossier", "search"]


# ─── every malformed input fails loudly ──────────────────────────────────────

Activity · 1 steps
lines 165–165assert list(d.load_descriptions()) == ["dossier", "search"]

test_row_returning_tools_all_carry_the_shared_rows_note

None test_descriptions.test_row_returning_tools_all_carry_the_shared_rows_note()

Every row-returning tool states the absent-vs-null rule, from one source.

tests/test_descriptions.py:174

Checks

  • assert "ABSENT, not null" in loaded[name], f"{name} omits the row-field rule"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_row_returning_tools_all_carry_the_shared_rows_note → load_descriptions
REQ-DDB-WIKI-054inferredtest_row_returning_tools_all_carry_the_shared_rows_note → load_descriptions → _entry → _joined → all
Source · 12 lines
def test_row_returning_tools_all_carry_the_shared_rows_note() -> None:
    """The rule is load-bearing and easy to get wrong in BOTH directions: a model that
    tests `row.crosses_thread is None` hits a KeyError, and one that reads a missing key
    as a negative answer reports "this edge does not cross threads" for an edge nobody
    measured. MCP has no shared preamble, so the sentence is paid per tool on the wire —
    the point of the `include` is that the WORDING has one source, and this test is what
    stops a new row-returning tool from shipping without it."""
    loaded = d.load_descriptions()
    for name in ("dossier", "search"):
        assert "ABSENT, not null" in loaded[name], f"{name} omits the row-field rule"

Activity · 3 steps
lines 181–181loaded = d.load_descriptions()lines 182–182◇ for name in ("dossier", "search")lines 183–183assert "ABSENT, not null" in loaded[name], f"{name} omits the row-field rule"

test_shipped_descriptions_are_rendered_and_substantial

None test_descriptions.test_shipped_descriptions_are_rendered_and_substantial()

No shipped description is empty or left with an unfilled placeholder.

tests/test_descriptions.py:96

Checks

  • assert len(text) > 40, f"{name}: description is suspiciously short"
  • assert "{" not in text and "}" not in text, f"{name}: unrendered placeholder"
  • assert not text.startswith(" ") and not text.endswith(" "), f"{name}: stray edge space"
  • assert " " not in text, f"{name}: double space — a description line ended with one"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_shipped_descriptions_are_rendered_and_substantial → load_descriptions
REQ-DDB-WIKI-054inferredtest_shipped_descriptions_are_rendered_and_substantial → load_descriptions → _entry → _joined → all
Source · 23 lines
def test_shipped_descriptions_are_rendered_and_substantial() -> None:
    """An unfilled `{placeholder}` reaching a model's tool list is the specific
    failure the template mechanism can produce, and it looks like working prose
    until you read it closely.

    BOTH TIERS, because `load_descriptions()` defaults to tier 1 and a bare call would
    silently stop covering the five tier-0 files the moment they arrived — a coverage hole
    that looks exactly like a passing test. It caught real prose on the way in: the moved
    `build_or_refresh` text wrote `options=` with braces and a literal tag-to-role mapping,
    which this assertion reads as an unrendered placeholder, so the wording was changed
    rather than the invariant."""
    loaded = {
        **d.load_descriptions(tier=1),
        **d.load_descriptions(tier=0),
        **d.load_descriptions(tier=2),  # 2.0.0: the prompts
    }
    for name, text in loaded.items():
        assert len(text) > 40, f"{name}: description is suspiciously short"
        assert "{" not in text and "}" not in text, f"{name}: unrendered placeholder"
        assert not text.startswith(" ") and not text.endswith(" "), f"{name}: stray edge space"
        assert "  " not in text, f"{name}: double space — a description line ended with one"

Activity · 6 steps
lines 107–111loaded = { **d.load_descriptions(tier=1), **d.load_descriptions(tier=0), **d.load_descriptions(tier=2), # 2.0.0: the prompts }lines 112–112◇ for name, text in loaded.items()lines 113–113assert len(text) > 40, f"{name}: description is suspiciously short"lines 114–114assert "{" not in text and "}" not in text, f"{name}: unrendered placeholder"lines 115–115assert not text.startswith(" ") and not text.endswith(" "), f"{name}: stray edge space"lines 116–116assert " " not in text, f"{name}: double space — a description line ended with one"

test_snippet_with_a_placeholder_is_refused

None test_descriptions.test_snippet_with_a_placeholder_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A snippet containing a placeholder is refused.

tests/test_descriptions.py:216

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_snippet_with_a_placeholder_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_snippet_with_a_placeholder_is_refused → load_descriptions → _entry → _joined → all
Source · 15 lines
def test_snippet_with_a_placeholder_is_refused(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """An include takes no vars, so a placeholder in a snippet would reach a model's
    tool list as a literal brace. Refused with the fix named — use `template`."""
    _redirect(monkeypatch, tmp_path)
    (tmp_path / "_templates").mkdir()
    (tmp_path / "_templates" / "s.json").write_text(
        json.dumps({"text": ["needs {a}"]}), encoding="utf-8"
    )
    _put(tmp_path, "dossier", {"description": ["Body."], "include": ["s"]})
    with pytest.raises(ValueError, match="use 'template' instead"):
        d.load_descriptions()

Activity · 6 steps
lines 221–221_redirect(monkeypatch, tmp_path)lines 222–222(tmp_path / "_templates").mkdir()lines 223–225(tmp_path / "_templates" / "s.json").write_text( json.dumps({"text": ["needs {a}"]}), encoding="utf-8" )lines 226–226_put(tmp_path, "dossier", {"description": ["Body."], "include": ["s"]})lines 227–227with pytest.raises(ValueError, match="use 'template' instead")lines 228–228d.load_descriptions()

test_unknown_key_is_refused

None test_descriptions.test_unknown_key_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

An unknown key is refused rather than ignored.

tests/test_descriptions.py:249

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_unknown_key_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_unknown_key_is_refused → load_descriptions → _entry → _joined → all
Source · 9 lines
def test_unknown_key_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """`descriptio` for `description` must not parse to a tool with no text. Same
    reasoning as the dispatch manifest's entry-level rejection."""
    _redirect(monkeypatch, tmp_path)
    _put(tmp_path, "dossier", {"tool": "dossier", "descriptio": ["typo"]})
    with pytest.raises(ValueError, match="unknown key"):
        d.load_descriptions()

Activity · 4 steps
lines 252–252_redirect(monkeypatch, tmp_path)lines 253–253_put(tmp_path, "dossier", {"tool": "dossier", "descriptio": ["typo"]})lines 254–254with pytest.raises(ValueError, match="unknown key")lines 255–255d.load_descriptions()

test_unused_var_is_refused

None test_descriptions.test_unused_var_is_refused(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A template var the text never uses is refused.

tests/test_descriptions.py:293

Show on the map →

Called by none

Calls _put, _redirect, load_descriptions

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_unused_var_is_refused → load_descriptions
REQ-DDB-WIKI-054inferredtest_unused_var_is_refused → load_descriptions → _entry → _joined → all
Source · 14 lines
def test_unused_var_is_refused(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
    """The subtle half of the template contract. A RENAMED placeholder still renders —
    the old var is simply ignored and the new `{brace}` stays literal — so refusing an
    unused var is what turns that into an error instead of prose a model reads."""
    _redirect(monkeypatch, tmp_path)
    (tmp_path / "_templates").mkdir()
    (tmp_path / "_templates" / "t.json").write_text(
        json.dumps({"text": ["hello {lead}"]}), encoding="utf-8"
    )
    _put(tmp_path, "callers", {"template": "t", "vars": {"lead": "x", "stale": "y"}})
    with pytest.raises(ValueError, match="not used by template"):
        d.load_descriptions()

Activity · 6 steps
lines 297–297_redirect(monkeypatch, tmp_path)lines 298–298(tmp_path / "_templates").mkdir()lines 299–301(tmp_path / "_templates" / "t.json").write_text( json.dumps({"text": ["hello {lead}"]}), encoding="utf-8" )lines 302–302_put(tmp_path, "callers", {"template": "t", "vars": {"lead": "x", "stale": "y"}})lines 303–303with pytest.raises(ValueError, match="not used by template")lines 304–304d.load_descriptions()