mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-08 13:12:08 +00:00
test(gateway): cover extension-less MEDIA delivery
Add regression tests for Caddyfile-style paths in MEDIA: tags and for strip_media_directives_for_display on the streaming path.
This commit is contained in:
parent
6da181062b
commit
6b89439ef1
1 changed files with 48 additions and 0 deletions
|
|
@ -649,6 +649,54 @@ class TestMediaExtensionAllowlistParity:
|
|||
assert "Here is your report:" in stripped
|
||||
|
||||
|
||||
class TestExtensionlessMediaDelivery:
|
||||
"""Regression: MEDIA: tags for extension-less files (Caddyfile, Makefile)."""
|
||||
|
||||
def _patch_allow_root(self, monkeypatch, root):
|
||||
monkeypatch.setattr(
|
||||
"gateway.platforms.base.MEDIA_DELIVERY_SAFE_ROOTS",
|
||||
(str(root),),
|
||||
)
|
||||
monkeypatch.delenv("HERMES_MEDIA_DELIVERY_STRICT", raising=False)
|
||||
|
||||
def test_extensionless_media_extracted_when_file_validates(self, tmp_path, monkeypatch):
|
||||
root = tmp_path / "output"
|
||||
root.mkdir()
|
||||
caddy = root / "Caddyfile"
|
||||
caddy.write_text("localhost {}", encoding="utf-8")
|
||||
self._patch_allow_root(monkeypatch, root)
|
||||
|
||||
content = f"Here is your config:\nMEDIA:{caddy}\nDone."
|
||||
media, cleaned = BasePlatformAdapter.extract_media(content)
|
||||
assert len(media) == 1
|
||||
assert media[0][0] == str(caddy.resolve())
|
||||
assert "MEDIA:" not in cleaned
|
||||
assert "Done." in cleaned
|
||||
|
||||
def test_extensionless_media_left_visible_when_not_on_disk(self, tmp_path, monkeypatch):
|
||||
root = tmp_path / "output"
|
||||
root.mkdir()
|
||||
self._patch_allow_root(monkeypatch, root)
|
||||
|
||||
content = "MEDIA:/nonexistent/Caddyfile"
|
||||
media, cleaned = BasePlatformAdapter.extract_media(content)
|
||||
assert media == []
|
||||
assert "MEDIA:/nonexistent/Caddyfile" in cleaned
|
||||
|
||||
def test_strip_media_directives_for_display_strips_validated_extensionless(
|
||||
self, tmp_path, monkeypatch,
|
||||
):
|
||||
root = tmp_path / "output"
|
||||
root.mkdir()
|
||||
caddy = root / "Caddyfile"
|
||||
caddy.write_text("x", encoding="utf-8")
|
||||
self._patch_allow_root(monkeypatch, root)
|
||||
|
||||
text = f"MEDIA:{caddy}"
|
||||
stripped = BasePlatformAdapter.strip_media_directives_for_display(text)
|
||||
assert "MEDIA:" not in stripped
|
||||
|
||||
|
||||
class TestMediaDeliveryPathValidation:
|
||||
def _patch_roots(self, monkeypatch, *roots):
|
||||
monkeypatch.setattr(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue