Konik Tooling

This commit is contained in:
firestar5683
2026-06-27 23:23:39 -05:00
parent a8ec45ec12
commit e82a4f034b
16 changed files with 472 additions and 119 deletions
+12
View File
@@ -0,0 +1,12 @@
from openpilot.tools.lib.auth_config import DEFAULT_API_HOST, KONIK_API_HOST, get_token, set_token
def test_set_token_preserves_comma_token_when_adding_konik(mocker, tmp_path):
mocker.patch("openpilot.tools.lib.auth_config.Paths.config_root", return_value=str(tmp_path))
set_token("comma-token", DEFAULT_API_HOST)
set_token("konik-token", KONIK_API_HOST)
assert get_token(DEFAULT_API_HOST) == "comma-token"
assert get_token(KONIK_API_HOST) == "konik-token"
assert get_token() == "comma-token"
+5
View File
@@ -95,10 +95,15 @@ class TestLogReader:
(f"{TEST_ROUTE}/13/14/a", f"{TEST_ROUTE}/0:1/a"),
(f"https://connect.comma.ai/{TEST_ROUTE}/13/14", f"{TEST_ROUTE}/0:1"),
(f"https://connect.comma.ai/{TEST_ROUTE}/13/14/a", f"{TEST_ROUTE}/0:1/a"),
(f"https://connect.konik.ai/{TEST_ROUTE}/13/14", f"{TEST_ROUTE}/0:1"),
(f"https://stable.konik.ai/{TEST_ROUTE}/13/14/a", f"{TEST_ROUTE}/0:1/a"),
])
def test_parse_indirect_accepts_second_window_route_style(self, identifier, expected):
assert parse_indirect(identifier) == expected
def test_parse_indirect_accepts_konik_useradmin(self):
assert parse_indirect(f"https://useradmin.konik.ai/?onebox={TEST_ROUTE}") == TEST_ROUTE
@pytest.mark.parametrize("cache_enabled", [True, False])
def test_direct_parsing(self, mocker, cache_enabled):
file_exists_mock = mocker.patch("openpilot.tools.lib.filereader.file_exists")
+54 -1
View File
@@ -1,6 +1,10 @@
from collections import namedtuple
from openpilot.tools.lib.route import SegmentName
import pytest
from openpilot.tools.lib.api import APIError, UnauthorizedError
from openpilot.tools.lib.auth_config import DEFAULT_API_HOST, KONIK_API_HOST
from openpilot.tools.lib.route import Route, SegmentName
class TestRouteLibrary:
def test_segment_name_formats(self):
@@ -25,3 +29,52 @@ class TestRouteLibrary:
for case in cases:
_validate(case)
def test_route_falls_back_to_konik_when_comma_route_missing(self, mocker):
route_name = "59679e5e40b60ce0/0000091b--316e931f07"
file_url = "https://konik.example/59679e5e40b60ce0/0000091b--316e931f07/0/qlog.zst"
calls = []
class FakeApi:
def __init__(self, token=None, host=None):
self.host = host
def get(self, endpoint):
calls.append((self.host, endpoint))
if self.host == DEFAULT_API_HOST:
raise APIError("404:not found", 404)
if endpoint.endswith("/files"):
return {"qlogs": [file_url]}
return {"url": "https://connect.konik.ai/59679e5e40b60ce0/0000091b--316e931f07"}
mocker.patch("openpilot.tools.lib.route.route_api_hosts", return_value=[DEFAULT_API_HOST, KONIK_API_HOST])
mocker.patch("openpilot.tools.lib.route.get_token", return_value=None)
mocker.patch("openpilot.tools.lib.route.CommaApi", FakeApi)
route = Route(route_name)
assert route.qlog_paths() == [file_url]
assert calls[0] == (DEFAULT_API_HOST, f"v1/route/{route_name.replace('/', '|')}/files")
assert calls[1] == (KONIK_API_HOST, f"v1/route/{route_name.replace('/', '|')}/files")
assert calls[2] == (KONIK_API_HOST, f"v1/route/{route_name.replace('/', '|')}")
def test_route_does_not_fall_back_to_konik_when_comma_unauthorized(self, mocker):
route_name = "59679e5e40b60ce0/0000091b--316e931f07"
calls = []
class FakeApi:
def __init__(self, token=None, host=None):
self.host = host
def get(self, endpoint):
calls.append((self.host, endpoint))
raise UnauthorizedError("unauthorized", 401)
mocker.patch("openpilot.tools.lib.route.route_api_hosts", return_value=[DEFAULT_API_HOST, KONIK_API_HOST])
mocker.patch("openpilot.tools.lib.route.get_token", return_value=None)
mocker.patch("openpilot.tools.lib.route.CommaApi", FakeApi)
with pytest.raises(UnauthorizedError):
Route(route_name)
assert calls == [(DEFAULT_API_HOST, f"v1/route/{route_name.replace('/', '|')}/files")]