fix: skill test-task / precision helpers crash on a non-dict skill (#1638)
This commit is contained in:
@@ -79,6 +79,8 @@ def _skill_test_task(skill: dict) -> str:
|
|||||||
an email); if we just hand over the 'when to use' text the agent has nothing
|
an email); if we just hand over the 'when to use' text the agent has nothing
|
||||||
to work on and stalls asking for input. So we tell it to create its own
|
to work on and stalls asking for input. So we tell it to create its own
|
||||||
realistic fixture first, then apply the skill end-to-end."""
|
realistic fixture first, then apply the skill end-to-end."""
|
||||||
|
if not isinstance(skill, dict):
|
||||||
|
skill = {}
|
||||||
ctx = (skill.get("when_to_use") or skill.get("description") or skill.get("name") or "").strip()
|
ctx = (skill.get("when_to_use") or skill.get("description") or skill.get("name") or "").strip()
|
||||||
return (
|
return (
|
||||||
"Test this skill end-to-end. FIRST, set up a small realistic scenario it "
|
"Test this skill end-to-end. FIRST, set up a small realistic scenario it "
|
||||||
@@ -310,6 +312,8 @@ def _should_check_retrieval_precision(skill: dict) -> bool:
|
|||||||
"installation", "install", "system", "ssh", "document", "documents",
|
"installation", "install", "system", "ssh", "document", "documents",
|
||||||
"search", "email", "calendar", "gpu", "server", "python",
|
"search", "email", "calendar", "gpu", "server", "python",
|
||||||
}
|
}
|
||||||
|
if not isinstance(skill, dict):
|
||||||
|
return False
|
||||||
tags = {str(t or "").strip().lower() for t in (skill.get("tags") or [])}
|
tags = {str(t or "").strip().lower() for t in (skill.get("tags") or [])}
|
||||||
if tags & broad:
|
if tags & broad:
|
||||||
return True
|
return True
|
||||||
|
|||||||
14
tests/test_skills_routes_nondict.py
Normal file
14
tests/test_skills_routes_nondict.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
"""Regression: skill helpers must tolerate a non-dict skill.
|
||||||
|
|
||||||
|
_skill_test_task did `skill.get(...)` and _should_check_retrieval_precision did
|
||||||
|
`skill.get("tags")`; a skill row that loaded as a bare string/None raised
|
||||||
|
AttributeError. They now treat a non-dict as empty / not-applicable.
|
||||||
|
"""
|
||||||
|
from routes.skills_routes import _skill_test_task, _should_check_retrieval_precision
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_dict_skill_does_not_crash():
|
||||||
|
assert isinstance(_skill_test_task("not a dict"), str)
|
||||||
|
assert isinstance(_skill_test_task(None), str)
|
||||||
|
assert _should_check_retrieval_precision("x") is False
|
||||||
|
assert _should_check_retrieval_precision(None) is False
|
||||||
Reference in New Issue
Block a user