|
17 | 17 | from __future__ import annotations |
18 | 18 |
|
19 | 19 | import asyncio |
| 20 | +import ast |
20 | 21 | import hmac |
21 | 22 | import json |
22 | 23 | import re |
23 | 24 | import time |
24 | 25 | from collections.abc import AsyncIterator, Mapping |
25 | 26 | from dataclasses import replace |
26 | 27 | from hashlib import sha256 |
| 28 | +from pathlib import Path |
27 | 29 | from types import SimpleNamespace |
28 | 30 |
|
| 31 | +import httpx |
29 | 32 | import pytest |
30 | 33 | from fastapi import FastAPI, HTTPException, Request |
31 | 34 | from fastapi.testclient import TestClient |
|
72 | 75 | ) |
73 | 76 |
|
74 | 77 |
|
| 78 | +@pytest.mark.parametrize("is_vestack_deployment", [False, True]) |
| 79 | +@pytest.mark.asyncio |
| 80 | +async def test_hermes_cli_surface_configuration_isolated_by_deployment( |
| 81 | + is_vestack_deployment: bool, |
| 82 | + monkeypatch: pytest.MonkeyPatch, |
| 83 | +) -> None: |
| 84 | + # Evaluate the real CLI registration without booting Studio or cloud clients. |
| 85 | + source = Path(frontend_sandbox.__file__).with_name("cli_frontend.py") |
| 86 | + tree = ast.parse(source.read_text()) |
| 87 | + registrations = [ |
| 88 | + node.value |
| 89 | + for node in ast.walk(tree) |
| 90 | + if isinstance(node, ast.Assign) |
| 91 | + and any( |
| 92 | + isinstance(target, ast.Name) and target.id == "sandbox_agent_services" |
| 93 | + for target in node.targets |
| 94 | + ) |
| 95 | + ] |
| 96 | + assert len(registrations) == 1 |
| 97 | + registration = registrations[0] |
| 98 | + hermes_call = next( |
| 99 | + value |
| 100 | + for key, value in zip(registration.keys, registration.values) |
| 101 | + if isinstance(key, ast.Constant) and key.value == "hermes" |
| 102 | + ) |
| 103 | + service = eval( |
| 104 | + compile(ast.Expression(hermes_call), str(source), "eval"), |
| 105 | + { |
| 106 | + "SandboxAgentSessionService": SandboxAgentSessionService, |
| 107 | + "sandbox_gateway": _FakeGateway(), |
| 108 | + "sandbox_chat_hermes_tool_id": "tool-hermes", |
| 109 | + "sandbox_chat_hermes_snapshot_tool_id": "tool-hermes-snapshot", |
| 110 | + "hermes_managed_tool_spec": None, |
| 111 | + "is_vestack_deployment": is_vestack_deployment, |
| 112 | + "os": SimpleNamespace(getenv=lambda _: ""), |
| 113 | + }, |
| 114 | + ) |
| 115 | + if is_vestack_deployment: |
| 116 | + assert service.surface_path == "/proxy/4500/" |
| 117 | + assert service._surface_ready_path == "/proxy/4500/" |
| 118 | + assert "hermes dashboard" in service._surface_start_command |
| 119 | + assert "--port 4500" in service._surface_start_command |
| 120 | + else: |
| 121 | + assert service.surface_path == "/hermes/" |
| 122 | + assert service._surface_ready_path == "" |
| 123 | + assert service._surface_start_command == "" |
| 124 | + |
| 125 | + def unexpected_http_client(*args, **kwargs): |
| 126 | + pytest.fail("Public-cloud Hermes must not start or probe Dashboard") |
| 127 | + |
| 128 | + monkeypatch.setattr(httpx, "AsyncClient", unexpected_http_client) |
| 129 | + created = await service.create("alice") |
| 130 | + opened, token = await service.open(created.instance_id, "alice") |
| 131 | + assert opened.instance_id == created.instance_id |
| 132 | + assert token |
| 133 | + |
| 134 | + |
75 | 135 | class _FakeCodex: |
76 | 136 | def __init__(self, turns: list[str], *, fail: bool = False) -> None: |
77 | 137 | self.thread_id = "thread-1" |
|
0 commit comments