Files
ECC/tests/test_selector.py
a15c8e8533 ci: add Python CI job (ruff, mypy, pytest) for the llm-abstraction package (#2364)
* ci: add ruff + mypy to the Python CI job and fix pyproject tool config

The python-tests job runs pytest but not lint/type checks, and the ruff
and mypy configuration in pyproject.toml was silently broken, so neither
tool could run at all.

- add ruff and mypy steps to the existing python-tests job
- fix invalid pyproject keys: [tool.ruff] src-path -> src,
  [tool.mypy] src_paths -> mypy_path
- ignore ruff UP042 (the (str, Enum) mixin is intentional)
- resolve ruff findings (unused/unsorted imports) across src and tests
- fix mypy errors in tools/executor.py and prompt/builder.py

* fix(ci): satisfy Python lint after main refresh

---------

Co-authored-by: haelyra <49814733+haelyra@users.noreply.github.com>
2026-08-11 14:15:57 -04:00

64 lines
2.0 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 "sponsorship link is passive" in output
assert "ecc ito find" in output
assert "explicitly configured canonical Itô CLI" in output
assert "submits a live authenticated RFQ" in output
assert "does not reserve capacity" 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 == ""