From 6ae195baa09bc217d51f3fb0a38312dfdcc85fdb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 25 Aug 2026 18:42:40 +0200 Subject: fix: honor skills_enabled on restore, and final-review polish --- test_llamachat.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'test_llamachat.py') diff --git a/test_llamachat.py b/test_llamachat.py index d96b599..71a2c35 100755 --- a/test_llamachat.py +++ b/test_llamachat.py @@ -3156,6 +3156,7 @@ def test_date_note(): # keeps its instructions. class _Cfg: search_enabled = True + skills_enabled = False class _Win: cfg = _Cfg() @@ -3183,6 +3184,7 @@ def test_date_note(): class _Off(_Bare): class cfg: search_enabled = False + skills_enabled = False assert _Off._system_messages(_Off()) == [] print("ok date note") @@ -3425,6 +3427,63 @@ def test_skill_round_cap(): print("ok skill round cap") +def test_tools_combined(): + import urllib.request + + from llamachat import search, skills + + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + _write_skills(root, {"finance-cli/SKILL.md": SKILLS_SAMPLE["finance-cli/SKILL.md"]}) + store = skills.SkillStore(root) + + client = backend.Client("http://x") + sent_tools = [] + + def always_tool_calls(model, messages, tools): + sent_tools.append(tools) + yield from _tool_round() + + client._stream_once = always_tool_calls + search_cfg = backend.SearchConfig( + enabled=True, url="http://searx", max_searches=1 + ) + skills_cfg = backend.SkillsConfig(enabled=True, store=store, max_searches=1) + original = _with_urlopen(json.dumps({"results": []}).encode()) + try: + list(client.stream_chat( + "m", [{"role": "user", "content": "hi"}], search_cfg, skills_cfg + )) + finally: + urllib.request.urlopen = original + + # Both schemas are offered together; the shared cap withdraws both + # on the final round. + assert len(sent_tools) == 2, sent_tools + assert sent_tools[0] == [search.TOOL_SCHEMA, store.tool_schema()], sent_tools[0] + assert sent_tools[-1] is None, sent_tools[-1] + print("ok tools combined") + + +def test_skills_directory_truncation(): + from llamachat import skills + + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + path = root / "long-desc" / "SKILL.md" + path.parent.mkdir(parents=True) + path.write_text( + "---\nname: long-desc\n" + f"description: {'x' * 300}\n---\n\nbody\n" + ) + store = skills.SkillStore(root) + directory = store.directory() + assert "long-desc" in directory + # The 300-char description is capped for the model's listing. + assert len(directory) < 200, len(directory) + print("ok skills directory truncation") + + def test_title_cleaning(): clean = backend.clean_title @@ -3773,6 +3832,8 @@ if __name__ == "__main__": test_skill_tool_round() test_skill_tool_errors() test_skill_round_cap() + test_tools_combined() + test_skills_directory_truncation() test_title_cleaning() test_title_request() test_needs_title() -- cgit v1.2.3