mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-27 23:33:41 +08:00
Compare commits
10 Commits
testing
...
Nate-testing
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bd6528b33 | |||
| a41b9795fd | |||
| 8c14810edd | |||
| 947bc2026d | |||
| 88d9b60a13 | |||
| 7392d42e9e | |||
| c02a563a59 | |||
| 5ef8ef1009 | |||
| f6d3829470 | |||
| 00486de7ad |
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user