fix: improve media failure diagnostics and token fallback coverage

This commit is contained in:
Xubin Ren
2026-05-02 11:37:07 +00:00
parent fde530de01
commit 2fa15ccf1b
3 changed files with 50 additions and 3 deletions
+8
View File
@@ -643,6 +643,14 @@ def test_slack_download_rejects_login_html() -> None:
assert SlackChannel._looks_like_html_download(markdown_response) is False
def test_slack_download_failure_marker_is_actionable() -> None:
marker = SlackChannel._download_failure_marker("image", "screenshot.png", "download failed")
assert "not available to nanobot" in marker
assert "files:read" in marker
assert "reinstall the Slack app" in marker
def test_slack_channel_uses_channel_aware_allow_policy() -> None:
channel = SlackChannel(SlackConfig(enabled=True, allow_from=[]), MessageBus())
assert channel.is_allowed("U1") is True
+32
View File
@@ -0,0 +1,32 @@
from nanobot.utils.helpers import estimate_prompt_tokens_chain
class _NoCounterProvider:
pass
class _BrokenCounterProvider:
def estimate_prompt_tokens(self, messages, tools=None, model=None):
raise RuntimeError("counter unavailable")
def test_estimate_prompt_tokens_chain_falls_back_without_provider_counter() -> None:
tokens, source = estimate_prompt_tokens_chain(
_NoCounterProvider(),
"test-model",
[{"role": "user", "content": "hello"}],
)
assert tokens > 0
assert source == "tiktoken"
def test_estimate_prompt_tokens_chain_falls_back_when_provider_counter_fails() -> None:
tokens, source = estimate_prompt_tokens_chain(
_BrokenCounterProvider(),
"test-model",
[{"role": "user", "content": "hello"}],
)
assert tokens > 0
assert source == "tiktoken"