fix(skill): improve clawhub command handling

This commit is contained in:
Hua
2026-03-17 15:55:41 +08:00
parent d31d6cdbe6
commit 59b9b54cbc
4 changed files with 160 additions and 18 deletions

View File

@@ -63,6 +63,54 @@ async def test_skill_search_runs_clawhub_search(tmp_path: Path) -> None:
"--limit",
"5",
)
env = create_proc.await_args.kwargs["env"]
assert env["npm_config_cache"].endswith("nanobot-npm-cache")
assert env["npm_config_fetch_retries"] == "0"
assert env["npm_config_fetch_timeout"] == "5000"
@pytest.mark.asyncio
async def test_skill_search_surfaces_npm_network_errors(tmp_path: Path) -> None:
loop = _make_loop(tmp_path)
proc = _FakeProcess(
returncode=1,
stderr=(
"npm error code EAI_AGAIN\n"
"npm error request to https://registry.npmjs.org/clawhub failed"
),
)
create_proc = AsyncMock(return_value=proc)
with patch("nanobot.agent.loop.shutil.which", return_value="/usr/bin/npx"), \
patch("nanobot.agent.loop.asyncio.create_subprocess_exec", create_proc):
response = await loop._process_message(
InboundMessage(channel="cli", sender_id="user", chat_id="direct", content="/skill search test")
)
assert response is not None
assert "could not reach the npm registry" in response.content
assert "EAI_AGAIN" in response.content
@pytest.mark.asyncio
async def test_skill_search_empty_output_returns_no_results(tmp_path: Path) -> None:
loop = _make_loop(tmp_path)
proc = _FakeProcess(stdout="")
create_proc = AsyncMock(return_value=proc)
with patch("nanobot.agent.loop.shutil.which", return_value="/usr/bin/npx"), \
patch("nanobot.agent.loop.asyncio.create_subprocess_exec", create_proc):
response = await loop._process_message(
InboundMessage(
channel="cli",
sender_id="user",
chat_id="direct",
content="/skill search selfimprovingagent",
)
)
assert response is not None
assert 'No skills found for "selfimprovingagent"' in response.content
@pytest.mark.asyncio
@@ -74,6 +122,11 @@ async def test_skill_search_runs_clawhub_search(tmp_path: Path) -> None:
("install", "demo-skill"),
"Installed demo-skill",
),
(
"/skill uninstall demo-skill",
("uninstall", "demo-skill", "--yes"),
"Uninstalled demo-skill",
),
(
"/skill list",
("list",),
@@ -117,7 +170,7 @@ async def test_skill_help_includes_skill_command(tmp_path: Path) -> None:
)
assert response is not None
assert "/skill <search|install|list|update>" in response.content
assert "/skill <search|install|uninstall|list|update>" in response.content
@pytest.mark.asyncio
@@ -143,8 +196,13 @@ async def test_skill_usage_errors_are_user_facing(tmp_path: Path) -> None:
missing_slug = await loop._process_message(
InboundMessage(channel="cli", sender_id="user", chat_id="direct", content="/skill install")
)
missing_uninstall_slug = await loop._process_message(
InboundMessage(channel="cli", sender_id="user", chat_id="direct", content="/skill uninstall")
)
assert usage is not None
assert "/skill search <query>" in usage.content
assert missing_slug is not None
assert "Missing skill slug" in missing_slug.content
assert missing_uninstall_slug is not None
assert "/skill uninstall <slug>" in missing_uninstall_slug.content