Files
ECC/tests/test_selector.py
T
Affaan MustafaandGitHub 96789caaf9 feat: add Itô compute sponsor routing and Phase 2 plan (#2546)
* feat: add Ito compute sponsor routing

* fix: harden Ito integration CI and framing
2026-07-22 03:07:45 -04:00

60 lines
1.8 KiB
Python

"""Tests for provider-selection compute guidance."""
import importlib.util
import re
from pathlib import Path
from urllib.parse import urlsplit
import pytest
SELECTOR_PATH = Path(__file__).parents[1] / "src" / "llm" / "cli" / "selector.py"
SPEC = importlib.util.spec_from_file_location("ecc_selector", SELECTOR_PATH)
assert SPEC is not None and SPEC.loader is not None
SELECTOR = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(SELECTOR)
print_self_host_compute_notice = SELECTOR.print_self_host_compute_notice
URL_TOKEN_PATTERN = re.compile(r"https?://[^\s<>\"'`()\[\]{}\\]+")
EXPECTED_COMPUTE_ROUTE = (
"https",
"compute.itomarkets.com",
"",
"",
"",
)
def assert_exact_compute_route(content: str) -> None:
candidates = URL_TOKEN_PATTERN.findall(content)
routes = (
urlsplit(candidate.rstrip(".,;:!?"))
for candidate in candidates
)
assert any(route == EXPECTED_COMPUTE_ROUTE for route in routes), (
"Should include the exact Itô compute route"
)
def test_compute_route_validation_rejects_deceptive_lookalike_host():
deceptive_output = "https://compute.itomarkets.com.attacker.example"
with pytest.raises(AssertionError, match="exact Itô compute route"):
assert_exact_compute_route(deceptive_output)
def test_ollama_notice_routes_to_ito_without_claiming_serving(capsys):
print_self_host_compute_notice("ollama")
output = capsys.readouterr().out
assert_exact_compute_route(output)
assert "preferred compute sponsor" in output
assert "Any GPU provider works" in output
assert "Managed inference through Itô is not live yet" in output
def test_managed_provider_does_not_show_self_host_compute_notice(capsys):
print_self_host_compute_notice("openai")
assert capsys.readouterr().out == ""