mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
test: strengthen assertions across 7 test files (batch 1)
Replaced weak 'is not None' / '> 0' / 'len >= 1' assertions with concrete value checks across the most flagged test files: gateway/test_pairing.py (11 weak → 0): - Code assertions verify isinstance + len == CODE_LENGTH - Approval results verify dict structure + specific user_id/user_name - Added code2 != code1 check in rate_limit_expires test_hermes_state.py (6 weak → 0): - ended_at verified as float timestamp - Search result counts exact (== 2, not >= 1) - Context verified as non-empty list - Export verified as dict, session ID verified test_cli_init.py (4 weak → 0): - max_turns asserts exact value (60) - model asserts string with provider/name format gateway/test_hooks.py (2 zero-assert tests → fixed): - test_no_handlers_for_event: verifies no handler registered - test_handler_error_does_not_propagate: verifies handler count + return gateway/test_platform_base.py (9 weak image tests → fixed): - extract_images tests now verify actual URL and alt_text - truncate_message verifies content preservation after splitting cron/test_scheduler.py (1 weak → 0): - resolve_origin verifies dict equality, not just existence cron/test_jobs.py (2 weak → 0 + 4 new tests): - Schedule parsing verifies ISO timestamp type - Cron expression verifies result is valid datetime string - NEW: 4 tests for update_job() (was completely untested)
This commit is contained in:
parent
e9f05b3524
commit
a44e041acf
7 changed files with 115 additions and 28 deletions
|
|
@ -92,36 +92,50 @@ class TestExtractImages:
|
|||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/photo.jpg"
|
||||
assert images[0][1] == "photo"
|
||||
|
||||
def test_markdown_image_jpeg(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/photo.jpeg"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_markdown_image_gif(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/anim.gif"
|
||||
assert images[0][1] == "anim"
|
||||
|
||||
def test_markdown_image_webp(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/img.webp"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_fal_media_cdn(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://fal.media/files/abc123/output.png"
|
||||
assert images[0][1] == "gen"
|
||||
|
||||
def test_fal_cdn_url(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://fal-cdn.example.com/result"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_replicate_delivery(self):
|
||||
content = ""
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://replicate.delivery/pbxt/abc/output"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_non_image_ext_not_extracted(self):
|
||||
"""Markdown image with non-image extension should not be extracted."""
|
||||
|
|
@ -142,11 +156,15 @@ class TestExtractImages:
|
|||
content = '<img src="https://example.com/photo.png"/>'
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/photo.png"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_html_img_with_closing_tag(self):
|
||||
content = '<img src="https://example.com/photo.png"></img>'
|
||||
images, _ = BasePlatformAdapter.extract_images(content)
|
||||
assert len(images) == 1
|
||||
assert images[0][0] == "https://example.com/photo.png"
|
||||
assert images[0][1] == ""
|
||||
|
||||
def test_multiple_images(self):
|
||||
content = "\n"
|
||||
|
|
@ -267,6 +285,11 @@ class TestTruncateMessage:
|
|||
msg = "word " * 200 # ~1000 chars
|
||||
chunks = adapter.truncate_message(msg, max_length=200)
|
||||
assert len(chunks) > 1
|
||||
# Verify all original content is preserved across chunks
|
||||
reassembled = "".join(chunks)
|
||||
# Strip chunk indicators like (1/N) to get raw content
|
||||
for word in msg.strip().split():
|
||||
assert word in reassembled, f"Word '{word}' lost during truncation"
|
||||
|
||||
def test_chunks_have_indicators(self):
|
||||
adapter = self._adapter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue