"""Tests for the setup-instructions template + resolver. `uv tool install` validates the PEP 427 filename in the URL path before fetching, so our setup snippet cannot use a stable alias like `agnes.whl`. These tests pin the wheel-filename substitution behavior. """ def test_resolve_lines_substitutes_wheel_filename(): from app.web.setup_instructions import resolve_lines lines = resolve_lines("agnes_the_ai_analyst-2.0.0-py3-none-any.whl") joined = "\n".join(lines) assert "{wheel_filename}" not in joined assert "/cli/wheel/agnes_the_ai_analyst-2.0.0-py3-none-any.whl" in joined def test_resolve_lines_fallback_filename_is_honoured(): """Callers pass `'agnes.whl'` when no wheel is on disk; substitution still works.""" from app.web.setup_instructions import resolve_lines lines = resolve_lines("agnes.whl") assert "{wheel_filename}" not in "\n".join(lines) assert any("/cli/wheel/agnes.whl" in line for line in lines) def test_render_setup_instructions_wires_all_placeholders(): from app.web.setup_instructions import render_setup_instructions out = render_setup_instructions( server_url="https://agnes.example.com", token="T-123", wheel_filename="agnes_the_ai_analyst-2.0.0-py3-none-any.whl", ) assert "{server_url}" not in out assert "{token}" not in out assert "{wheel_filename}" not in out assert "https://agnes.example.com/cli/wheel/agnes_the_ai_analyst-2.0.0-py3-none-any.whl" in out assert "T-123" in out def test_install_page_uses_versioned_wheel_url(monkeypatch, tmp_path): """End-to-end: the /install preview must render the PEP 427 wheel URL, so a user copy-pasting the snippet gets a URL `uv tool install` accepts.""" wheel = tmp_path / "agnes_the_ai_analyst-2.0.0-py3-none-any.whl" wheel.write_bytes(b"PK\x03\x04") monkeypatch.setenv("AGNES_CLI_DIST_DIR", str(tmp_path)) from fastapi.testclient import TestClient from app.main import app client = TestClient(app) resp = client.get("/install", headers={"host": "agnes.test", "Accept": "text/html"}) assert resp.status_code == 200 assert "/cli/wheel/agnes_the_ai_analyst-2.0.0-py3-none-any.whl" in resp.text # The bare alias must no longer appear in the rendered snippet. assert "/cli/agnes.whl" not in resp.text