The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): a typed-root 404 no longer hides the /v1 key rejection; pin the Settings Test URL rewrite
teknium1754d229bea94
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsxindex 8aa6f4b5771..e248218bed0 100644--- a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx@@ -6,6 +6,7 @@ import type { CustomEndpointsResponse } from '@/types/hermes'const getCustomEndpoints = vi.fn()const saveCustomEndpoint = vi.fn()+const validateCustomEndpoint = vi.fn()const notify = vi.fn()const notifyError = vi.fn()const triggerHaptic = vi.fn()@@ -16,7 +17,7 @@ vi.mock('@/hermes', async importOriginal => ({deleteCustomEndpoint: vi.fn(),getCustomEndpoints: (...args: unknown[]) => getCustomEndpoints(...args),saveCustomEndpoint: (...args: unknown[]) => saveCustomEndpoint(...args),- validateCustomEndpoint: vi.fn()+ validateCustomEndpoint: (...args: unknown[]) => validateCustomEndpoint(...args)}))vi.mock('./profile-scope', () => ({ ActiveProfileNote: () => null }))vi.mock('@/lib/haptics', () => ({ triggerHaptic: (...args: unknown[]) => triggerHaptic(...args) }))@@ -86,4 +87,20 @@ describe('CustomEndpointsSettings', () => {expect(notify).not.toHaveBeenCalled()expect(notifyError).not.toHaveBeenCalled()})++ it('Test rewrites the URL field to the base that actually served /models (#65488)', async () => {+ getCustomEndpoints.mockResolvedValue(emptyResponse)+ validateCustomEndpoint.mockResolvedValue({ ok: true, message: '', models: ['model-a'], resolved_base_url: 'http://h.test/v1' })+ const { CustomEndpointsSettings } = await import('./custom-endpoints-settings')+ render(<CustomEndpointsSettings onConfigSaved={vi.fn()} onMainModelChanged={vi.fn()} />)++ await screen.findByText('No custom endpoints')+ const urlInput = screen.getByPlaceholderText<HTMLInputElement>('http://127.0.0.1:8081/v1')+ fireEvent.change(urlInput, { target: { value: 'http://h.test' } })+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Test' })))++ // Save stores form.baseUrl verbatim and chat POSTs {base_url}/chat/completions, so the+ // typed bare root would 404 every request even though the test looked green.+ expect(urlInput.value).toBe('http://h.test/v1')+ })})diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.pyindex 1c2a8d341a5..4a909762b13 100644--- a/hermes_cli/web_routers/config_env.py+++ b/hermes_cli/web_routers/config_env.py@@ -745,7 +745,9 @@ async def _probe_openai_compatible_models(base_url: str, headers: Optional[dict]candidate_resp = await client.get(candidate + "/models", headers=headers)except Exception:continue- if resp is None or candidate_resp.is_success:+ # Keep the most telling failure: a 401/403 from the /v1 alternate says "server is+ # there, key rejected", which beats the typed root's 404 (wrong path).+ if resp is None or candidate_resp.is_success or resp.status_code == 404:resolved, resp = candidate, candidate_respif candidate_resp.is_success:breakdiff --git a/tests/hermes_cli/test_web_routers_endpoint_probe.py b/tests/hermes_cli/test_web_routers_endpoint_probe.pyindex aecb490bf63..783d3df17d0 100644--- a/tests/hermes_cli/test_web_routers_endpoint_probe.py+++ b/tests/hermes_cli/test_web_routers_endpoint_probe.py@@ -106,3 +106,40 @@ def test_bare_root_probe_resolves_to_the_v1_base_that_served_models(route, monkeassert seen == ["http://127.0.0.1:39080/models", "http://127.0.0.1:39080/v1/models"]assert data["ok"] is True and data["models"] == ["local-model"]assert data["resolved_base_url"] == "http://127.0.0.1:39080/v1"++[email protected]("route", ["/api/providers/validate", "/api/providers/custom-endpoints/validate"])+def test_bare_root_probe_reports_the_v1_key_rejection_not_the_root_404(route, monkeypatch):+ """Server lives at ``/v1`` and wants a key: typed root 404s, ``/v1/models`` answers 401. The+ verdict must be the key rejection from the candidate that produced it, not the first 404."""+ import hermes_cli.web_routers.config_env as mod+ from hermes_cli.web_models import CustomEndpointUpdate, EnvVarUpdate++ class _Resp:+ def __init__(self, status):+ self.status_code, self.is_success = status, False++ def json(self):+ return {"error": "unauthorized"}++ class _Client:+ async def __aenter__(self):+ return self++ async def __aexit__(self, *a):+ return False++ async def get(self, url, *a, **k):+ return _Resp(401 if url.endswith("/v1/models") else 404)++ monkeypatch.setattr(mod, "_endpoint_probe_client", lambda url, timeout: _Client())+ monkeypatch.setattr(mod, "_require_token", lambda request: None)+ if route == "/api/providers/validate":+ body = EnvVarUpdate(key="OPENAI_BASE_URL", value="http://127.0.0.1:39080", api_key="k")+ data = asyncio.run(mod.validate_provider_credential(body, request=None))+ assert data["message"] == "http://127.0.0.1:39080/v1/models answered HTTP 401."+ else:+ body = CustomEndpointUpdate(id="", name="local", base_url="http://127.0.0.1:39080", api_key="k", model="")+ data = asyncio.run(mod.validate_custom_endpoint(body))+ assert data["message"] == "The endpoint rejected the API key."+ assert data["ok"] is False and data["reachable"] is True