Compare commits

...

10 Commits

Author SHA1 Message Date
natehuby76 3bd6528b33 send galaxy diagnostic summaries with staged logs 2026-11-25 09:41:57 -05:00
natehuby76 a41b9795fd sync nate-testing with official testing 2026-11-25 09:41:47 -05:00
natehuby76 8c14810edd sync testing and remove retired support code handling 2026-11-25 00:01:25 -05:00
natehuby76 947bc2026d sync galaxy reporting and companion bot with testing 2026-11-24 23:50:26 -05:00
natehuby76 88d9b60a13 keep galaxy report links private to the sending session 2026-11-24 21:56:02 -05:00
Danny 7392d42e9e Simplify Galaxy log reporting (#/logs/help) with one-way relay staging 2026-11-24 18:27:42 -08:00
natehuby76 c02a563a59 make starting a starport report easier to find 2026-11-24 19:27:10 -05:00
natehuby76 5ef8ef1009 send starport logs to companion support 2026-11-24 19:16:52 -05:00
natehuby76 f6d3829470 refresh prebuilt receipt for galaxy changes 2026-11-24 18:16:18 -05:00
natehuby76 00486de7ad fix galaxy support code entry 2026-11-24 18:02:18 -05:00
2 changed files with 58 additions and 1 deletions
@@ -2,10 +2,13 @@
from __future__ import annotations from __future__ import annotations
import json
import re import re
import threading import threading
from collections.abc import Callable from collections.abc import Callable
from io import BytesIO
from urllib.parse import quote from urllib.parse import quote
from zipfile import BadZipFile, ZipFile
from openpilot.starpilot.galaxy.starport_send import DISCORD_FILE_LIMIT, official_install from openpilot.starpilot.galaxy.starport_send import DISCORD_FILE_LIMIT, official_install
@@ -72,6 +75,32 @@ def clean_stage_request(payload: object) -> tuple[str, str, str]:
return kind, "android", note return kind, "android", note
def _capture_summary(kind: str, data: bytes) -> str:
"""Summarize the staged capture without collecting a second snapshot."""
member = {"starport": "SUMMARY.txt", "connection": "connection-logs.txt", "controller": "bluetooth-log.json"}[kind]
try:
with ZipFile(BytesIO(data)) as archive, archive.open(member) as stream:
raw = stream.read(256 * 1024 + 1)
if len(raw) > 256 * 1024:
return ""
if kind == "controller":
capture = json.loads(raw)
rows = capture["externalInputInterfaces"]
counts = [sum(row["discovery"] == state for row in rows) for state in ("eligible", "filtered", "duplicate identity")]
suffix = " (inventory truncated)" if capture.get("truncated") else ""
return (f"External input interfaces: {len(rows)}{suffix}\n"
f"Eligible: {counts[0]} | Filtered: {counts[1]} | Duplicate identity: {counts[2]}")
text = raw.decode("utf-8", errors="replace").strip()
if kind == "starport":
return text[:600]
labels = ("Comma uptime: ", "Parked configuration allowed: ", "Bonjour advertiser: ", "Bluetooth bridge: ")
lines = text.splitlines()
return "\n".join(line[:220] for line in lines if line.startswith(labels))[:600]
except (BadZipFile, KeyError, ValueError, TypeError, AttributeError, OSError, EOFError):
# Missing or older summary formats should still deliver the original ZIP.
return ""
def _response_error(response) -> str: def _response_error(response) -> str:
try: try:
body = response.json() body = response.json()
@@ -166,12 +195,14 @@ class LogRelayStager:
post = requests.post post = requests.post
else: else:
post = self._post post = self._post
summary = _capture_summary(kind, data)
response = post( response = post(
self._url(), self._url(),
data=data, data=data,
headers={ headers={
"Content-Type": "application/zip", "Content-Type": "application/zip",
"X-Galaxy-Kind": kind, "X-Galaxy-Kind": kind,
**({"X-Galaxy-Summary": quote(summary, safe="")} if summary else {}),
"X-Galaxy-Platform": platform, "X-Galaxy-Platform": platform,
"X-Galaxy-Note": quote(formatted_note, safe=""), "X-Galaxy-Note": quote(formatted_note, safe=""),
}, },
@@ -1,5 +1,8 @@
"""Tests for one-way log relay staging and Galaxy /api/logs/stage endpoints.""" """Tests for one-way log relay staging and Galaxy /api/logs/stage endpoints."""
from io import BytesIO
from zipfile import ZipFile
import http.client import http.client
import json import json
from pathlib import Path from pathlib import Path
@@ -21,7 +24,6 @@ from openpilot.starpilot.galaxy.log_relay_stage import (
StageRejected, StageRejected,
clean_stage_request, clean_stage_request,
) )
from openpilot.starpilot.galaxy.server import make_server
from openpilot.starpilot.galaxy.starport_send import DISCORD_FILE_LIMIT from openpilot.starpilot.galaxy.starport_send import DISCORD_FILE_LIMIT
VALID_CLAIM = "https://starpilot-log-relay.nathan-g-hubbard.workers.dev/report/galaxy/claim/" + ("a1b2" * 16) VALID_CLAIM = "https://starpilot-log-relay.nathan-g-hubbard.workers.dev/report/galaxy/claim/" + ("a1b2" * 16)
@@ -120,12 +122,34 @@ class LogRelayStagerTest(unittest.TestCase):
call = calls[-1] call = calls[-1]
self.assertEqual(call["url"], STAGE_URL) self.assertEqual(call["url"], STAGE_URL)
self.assertEqual(call["data"], expected_zip) self.assertEqual(call["data"], expected_zip)
self.assertNotIn("X-Galaxy-Summary", call["headers"])
self.assertFalse(call["allow_redirects"]) self.assertFalse(call["allow_redirects"])
self.assertEqual(call["headers"]["Content-Type"], "application/zip") self.assertEqual(call["headers"]["Content-Type"], "application/zip")
self.assertEqual(call["headers"]["X-Galaxy-Kind"], expected_kind) self.assertEqual(call["headers"]["X-Galaxy-Kind"], expected_kind)
self.assertEqual(call["headers"]["X-Galaxy-Platform"], expected_platform) self.assertEqual(call["headers"]["X-Galaxy-Platform"], expected_platform)
self.assertEqual(unquote(call["headers"]["X-Galaxy-Note"]), expected_note) self.assertEqual(unquote(call["headers"]["X-Galaxy-Note"]), expected_note)
def test_summary_header_matches_staged_archive(self):
cases = (
("starport", "SUMMARY.txt", "Device abc12345\nCar: Test car\nHead unit: Unité", "Device abc12345\nCar: Test car\nHead unit: Unité"),
("connection", "connection-logs.txt", "Bonjour advertiser: active\nen0: private\nBluetooth bridge: inactive",
"Bonjour advertiser: active\nBluetooth bridge: inactive"),
("controller", "bluetooth-log.json", json.dumps({"externalInputInterfaces": [{"discovery": "eligible"}, {"discovery": "filtered"}]}),
"External input interfaces: 2\nEligible: 1 | Filtered: 1 | Duplicate identity: 0"),
)
for kind, member, contents, expected in cases:
with self.subTest(kind=kind):
stream = BytesIO()
with ZipFile(stream, "w") as archive:
archive.writestr(member, contents)
data = stream.getvalue()
post = Mock(return_value=Mock(status_code=200))
post.return_value.json.return_value = {"claimUrl": VALID_CLAIM}
stager = LogRelayStager(lambda: ("logs.zip", data), lambda: data, lambda: data, post=post)
stager._run(kind, "ios", "Test")
self.assertEqual(post.call_args.kwargs["data"], data)
self.assertEqual(unquote(post.call_args.kwargs["headers"]["X-Galaxy-Summary"]), expected)
def test_retries_starport_without_system_snapshot_when_oversize(self): def test_retries_starport_without_system_snapshot_when_oversize(self):
seen_args = [] seen_args = []
posts = [] posts = []
@@ -208,6 +232,8 @@ class LogRelayStagerTest(unittest.TestCase):
class LogStageHTTPTest(unittest.TestCase): class LogStageHTTPTest(unittest.TestCase):
def setUp(self): def setUp(self):
from openpilot.starpilot.galaxy.server import make_server
self.temp = tempfile.TemporaryDirectory() self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup) self.addCleanup(self.temp.cleanup)
self.access = GalaxyAccessOwner(Path(self.temp.name)) self.access = GalaxyAccessOwner(Path(self.temp.name))