The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): play an SSH profile's host-staged clip spelled as a file: URL
unsupportedpastels92a94fb403b5
diff --git a/hermes_cli/web_routers/files.py b/hermes_cli/web_routers/files.pyindex b20ed620230..3ce6d8c854e 100644--- a/hermes_cli/web_routers/files.py+++ b/hermes_cli/web_routers/files.py@@ -37,7 +37,7 @@ from hermes_cli.web_server_remote_media import remote_media_responsefrom hermes_cli.web_upload_limit import CHAT_IMAGE_MAX_BYTESfrom hermes_cli.web_server_surface import route_onfrom hermes_cli.web_server_files import (- SANDBOX_NOT_FOUND, _agent_fs_path, _fs_path, _hosted_fs_read_guard, _is_unmapped_container_path,+ SANDBOX_NOT_FOUND, _agent_fs_path, _file_url_path, _fs_path, _hosted_fs_read_guard, _is_unmapped_container_path,_managed_file_entry, _managed_response_meta, _resolve_managed_path, _session_workspace_key,)from hermes_cli.web_models import (@@ -339,7 +339,13 @@ def _is_host_file(path: str, profile: Optional[str]) -> bool:"""Whether *path* is a file the profile keeps on this host even when its workspace is an SSHmachine, read back to be previewed and sent: a browser paste in its image cache, or a file thebrowser's picker staged in its uploads folder. Only a file directly in one of those two folders- counts, after resolving symlinks and ``..``, so an SSH profile reads no other host file here."""+ counts, after resolving symlinks and ``..``, so an SSH profile reads no other host file here.+ A ``file:`` URL counts by the native path it names, decoded once as ``_fs_path`` decodes it."""+ if path.lower().startswith("file:"):+ try:+ path = _file_url_path(path)+ except ValueError:+ return Falseif not Path(path).is_absolute():return Falsetry:diff --git a/tests/hermes_cli/test_web_server_ssh_media_stream.py b/tests/hermes_cli/test_web_server_ssh_media_stream.pyindex f5e417dab86..fcbf30f1c0a 100644--- a/tests/hermes_cli/test_web_server_ssh_media_stream.py+++ b/tests/hermes_cli/test_web_server_ssh_media_stream.py@@ -236,6 +236,54 @@ def test_a_host_staged_clip_of_an_ssh_profile_streams_from_this_host(client, sshassert workspace.reads == [][email protected]("ssh_down", [False, True])+def test_a_host_staged_clip_spelled_as_a_file_url_streams_from_this_host(client, ssh, monkeypatch, ssh_down):+ from fastapi import HTTPException++ _profile, workspace = ssh+ staged = client.post("/api/chat/file-upload", params={"profile": "remote-dev"},+ files={"file": ("clip.mp4", b"host clip", "video/mp4")})+ assert staged.status_code == 200, staged.text+ if ssh_down:+ def down(profile=None):+ raise HTTPException(status_code=503, detail="SSH workspace is unavailable")++ monkeypatch.setattr(file_routes, "_fs_backend", down)+ query = {"path": Path(staged.json()["path"]).as_uri(), "profile": "remote-dev"}++ direct = client.get("/api/files/stream", params=query, headers={"Range": "bytes=0-3"})+ data_url = client.get("/api/fs/read-data-url", params=query)+ download = client.get("/api/fs/download", params=query)+ minted = client.post("/api/files/ticket", json={"route": "stream", **query})+ assert minted.status_code == 200, minted.text+ del client.headers[web_server._SESSION_HEADER_NAME]+ ticketed = client.get("/api/files/stream", params={**query, "ticket": minted.json()["ticket"]})++ assert (direct.status_code, direct.content) == (206, b"host"), direct.text+ assert data_url.json() == {"dataUrl": "data:video/mp4;base64,aG9zdCBjbGlw"}+ assert (download.status_code, download.content) == (200, b"host clip")+ assert (ticketed.status_code, ticketed.content) == (200, b"host clip")+ assert workspace.reads == []+++def test_a_file_url_off_this_hosts_staging_still_goes_to_the_ssh_workspace(client, ssh, monkeypatch):+ _profile, workspace = ssh+ asked = []+ monkeypatch.setattr(workspace, "inspect_file", lambda path: asked.append(path) or (CLIP, len(BYTES)))+ staged = client.post("/api/chat/file-upload", params={"profile": "remote-dev"},+ files={"file": ("clip.mp4", b"host clip", "video/mp4")})+ staged_path = Path(staged.json()["path"])+ beside = staged_path.parent.parent / "clip.mp4" # not directly in the staging folder+ beside.write_bytes(b"host file")+ encoded = staged_path.as_uri().replace(f"/{staged_path.name}", f"%2f{staged_path.name}")++ for url in (beside.as_uri(), encoded):+ response = _stream(client, path=url)+ assert (response.status_code, response.content) == (200, BYTES), url+ # Neither is a host-staged file, so the SSH workspace was asked for both.+ assert len(asked) == 2++def test_a_down_ssh_host_is_unavailable_to_the_stream(client, ssh, monkeypatch):from tools.environments.base import EnvironmentConnectionError