test(tool-search): make salvage-seam tests order- and stem-robust

Two interaction seams between the #92693 salvage (merged as #95050) and
this branch: the source-label indexing test now compares in token space
(the stemmer shortens 'catalogsource' to 'catalogsourc'), and the
unregistered-core-name describe test forces the unregistered condition
via monkeypatch instead of depending on which sibling test file imported
model_tools first.
This commit is contained in:
Teknium
2026-08-25 16:31:29 -07:00
parent 00305aec61
commit a935154378
2 changed files with 21 additions and 3 deletions

View File

@@ -297,9 +297,14 @@ class TestSourceNameIndexing:
_td("mcp__catalogsource__native_action", "Perform a native action."),
_td("plugin_action", "Perform a plugin action."),
])
# Compare in token space: the tokenizer may stem (e.g.
# "catalogsource" -> "catalogsourc"), and the contract is that
# the label lands in the document exactly once either way.
from tools.tool_search import _tokenize
label_token = _tokenize(source_label)[0]
tokens_by_name = {entry.name: entry._tokens for entry in catalog}
assert tokens_by_name[names[0]].count(source_label) == 1
assert tokens_by_name[names[1]].count(source_label) == 1
assert tokens_by_name[names[0]].count(label_token) == 1
assert tokens_by_name[names[1]].count(label_token) == 1
finally:
for name in names:
registry.deregister(name)

View File

@@ -422,9 +422,22 @@ class TestBatchedDescribe:
assert result["not_found"] == ["mcp__linear__does_not_exist_zzz"]
assert "errors" not in result
def test_unregistered_core_name_is_not_found(self, issue_defs):
def test_unregistered_core_name_is_not_found(self, issue_defs, monkeypatch):
from tools import registry as registry_module
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
# The intent: a name that is NOT registered lands in not_found, even
# when it looks like a core tool. Whether "terminal" is registered in
# this process depends on which test files imported model_tools
# earlier, so force the unregistered condition instead of relying on
# collection order.
real_get_entry = registry_module.registry.get_entry
monkeypatch.setattr(
registry_module.registry,
"get_entry",
lambda name: None if name == "terminal" else real_get_entry(name),
)
result = json.loads(dispatch_tool_describe(
{"names": ["terminal", "mq_linear_create_issue"]},
current_tool_defs=issue_defs,