Add versioned HTTP API routes

This commit is contained in:
2026-06-07 10:24:08 -06:00
parent ec39182bbd
commit d87080d23f
11 changed files with 226 additions and 137 deletions
+44 -3
View File
@@ -22,14 +22,41 @@ def assert_keys(payload, keys):
def registered_routes():
pattern = re.compile(r'server\.on\("([^"]+)"(?:,\s*(HTTP_[A-Z]+))?')
return {(match.group(1), match.group(2) or "ANY") for match in pattern.finditer(firmware_source())}
source = firmware_source()
literal_pattern = re.compile(r'server\.on\("([^"]+)"(?:,\s*(HTTP_[A-Z]+))?')
macro_pattern = re.compile(r'server\.on\(API_V1\("([^"]+)"\)(?:,\s*(HTTP_[A-Z]+))?')
routes = {(match.group(1), match.group(2) or "ANY") for match in literal_pattern.finditer(source)}
routes.update({
(f"/api/v1{match.group(1)}", match.group(2) or "ANY")
for match in macro_pattern.finditer(source)
})
return routes
def test_firmware_registers_current_http_contract_routes():
routes = registered_routes()
expected_routes = {
("/api/v1/status", "ANY"),
("/api/v1/config", "HTTP_GET"),
("/api/v1/relay/set", "HTTP_POST"),
("/api/v1/config/wifi", "HTTP_GET"),
("/api/v1/config/wifi", "HTTP_POST"),
("/api/v1/wifi/connect", "HTTP_POST"),
("/api/v1/wifi/clear", "HTTP_POST"),
("/api/v1/temps/scan", "HTTP_POST"),
("/api/v1/temps/assign", "HTTP_POST"),
("/api/v1/temps/clear", "HTTP_POST"),
}
assert expected_routes <= routes
def test_firmware_keeps_root_compatibility_aliases():
routes = registered_routes()
compatibility_routes = {
("/status", "ANY"),
("/config", "HTTP_GET"),
("/relay/set", "HTTP_POST"),
@@ -42,7 +69,21 @@ def test_firmware_registers_current_http_contract_routes():
("/temps/clear", "HTTP_POST"),
}
assert expected_routes <= routes
assert compatibility_routes <= routes
def test_embedded_webui_uses_versioned_api_routes():
source = firmware_source()
assert 'const API_BASE="/api/v1";' in source
assert 'fetch(api("' in source
assert 'fetch("/status"' not in source
assert 'fetch("/config' not in source
assert 'fetch("/relay' not in source
assert 'fetch("/temps' not in source
assert 'fetch("/wifi' not in source
assert "/bms/reconnect" not in source
assert "/system/restart" not in source
def test_status_fixture_matches_dashboard_contract_shape():