Files
nousresearch--hermes-agent/tests/agent/test_none_deref_guards.py
T
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

39 lines
1.4 KiB
Python

"""Regression tests for None-dereference guards on ``.get(key, "").method()``
patterns (#55997 salvage + config-derived sibling sites).
``dict.get(key, default)`` only returns the default when the key is ABSENT;
a present-but-null value sails through as None and crashes any chained
method call.
"""
from agent.anthropic_adapter import _convert_user_message
from agent.moa_loop import _slot_label
class TestAnthropicNullTextBlock:
def test_null_text_block_treated_as_empty(self):
"""A text block with ``text: null`` must not crash the empty-message
check in _convert_user_message (#55997)."""
result = _convert_user_message([{"type": "text", "text": None}])
# Must not raise; result is a valid user message dict
assert result["role"] == "user"
def test_mixed_null_and_real_text_blocks(self):
result = _convert_user_message(
[
{"type": "text", "text": None},
{"type": "text", "text": "hello"},
]
)
assert result["role"] == "user"
class TestMoaSlotLabelNullFields:
def test_null_provider_and_model(self):
"""MoA slot with ``provider: null`` in config.yaml must not crash
label construction."""
assert _slot_label({"provider": None, "model": None}) == ":" # type: ignore[arg-type]
def test_normal_slot(self):
assert _slot_label({"provider": "openrouter", "model": "m"}) == "openrouter:m"