fix: pre-car-test bug fixes from full code audit
- app_alerts.py: null guard on list_local_videos() result (.get('files', []))
- app_cellular.py: remove erroneous .encode(errors='replace') on str response body
- app_settings.py: initialize apn='' when isinstance check fails (NameError guard)
- app_upload.py: move json import to top of file instead of inside except handler
- server/app.py: wrap int(request.args.get('limit')) in try/except ValueError
- server/app.py: wrap os.path.commonpath() in try/except ValueError (cross-root paths)
- tests/test_app_settings.py: add missing trips_upload_enabled/video_convert_enabled
to valid_payload() (fields added in Phase 23.5 but test not updated)
All 63 tests pass.
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -231,7 +231,7 @@ def _power_condition(throttling, now=None):
|
||||
def collect_conditions(config):
|
||||
health = app_health.collect_health()
|
||||
videos = app_video.list_local_videos()
|
||||
pending_videos = sum(1 for video in videos["files"] if not video["uploaded"])
|
||||
pending_videos = sum(1 for video in (videos or {}).get("files", []) if not video["uploaded"])
|
||||
pending_tracking = app_sql.count_unsent_tracking_rows()
|
||||
speed = app_obd.get_fresh_speed()
|
||||
fix_age = app_gps.get_fix_age()
|
||||
|
||||
@@ -229,7 +229,7 @@ def http_post(
|
||||
break
|
||||
|
||||
read_resp = _at(ser, "AT+HTTPREAD", terminators=("OK", "ERROR"), timeout=15)
|
||||
body = read_resp.encode(errors="replace")
|
||||
body = read_resp
|
||||
|
||||
return status_code, body
|
||||
finally:
|
||||
|
||||
@@ -121,6 +121,7 @@ def update_settings(body):
|
||||
apn = body.get("cellular_apn")
|
||||
if not isinstance(apn, str):
|
||||
errors["cellular_apn"] = "Must be text."
|
||||
apn = ""
|
||||
else:
|
||||
apn = apn.strip()
|
||||
if len(apn) > 100 or not _APN_PATTERN.fullmatch(apn):
|
||||
|
||||
@@ -35,6 +35,7 @@ never commit real values - mirrors the db/creds.env pattern already used by
|
||||
app_db.py for MongoDB).
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from threading import Thread
|
||||
@@ -178,9 +179,7 @@ def _upload_tracking_batch():
|
||||
if not app_cellular.is_configured():
|
||||
raise
|
||||
print(f"WiFi/Ethernet upload unreachable ({wifi_err}), trying cellular fallback...")
|
||||
import json as _json
|
||||
|
||||
body_bytes = _json.dumps({"points": points}).encode()
|
||||
body_bytes = json.dumps({"points": points}).encode()
|
||||
try:
|
||||
status_code, _body = app_cellular.http_post_json(
|
||||
f"{SERVER_URL}/api/v1/tracking/batch", body_bytes, _headers()
|
||||
|
||||
Reference in New Issue
Block a user