Improve handling of version info in pre-built bundles

This commit is contained in:
Jack Kingsman
2026-03-16 18:41:19 -07:00
parent 9c06ed62a4
commit 47276dcb6c
3 changed files with 78 additions and 2 deletions
+22 -1
View File
@@ -1,5 +1,6 @@
import hashlib
import importlib.metadata
import json
import logging
import subprocess
import sys
@@ -23,6 +24,7 @@ router = APIRouter(tags=["debug"])
LOG_COPY_BOUNDARY_MESSAGE = "STOP COPYING HERE IF YOU DO NOT WANT TO INCLUDE LOGS BELOW"
LOG_COPY_BOUNDARY_LINE = "-" * 64
RELEASE_BUILD_INFO_FILENAME = "build_info.json"
LOG_COPY_BOUNDARY_PREFIX = [
LOG_COPY_BOUNDARY_LINE,
LOG_COPY_BOUNDARY_LINE,
@@ -128,11 +130,30 @@ def _git_output(*args: str) -> str | None:
return output or None
def _release_build_info() -> dict[str, Any] | None:
build_info_path = _repo_root() / RELEASE_BUILD_INFO_FILENAME
try:
data = json.loads(build_info_path.read_text())
except Exception:
return None
if isinstance(data, dict):
return data
return None
def _build_application_info() -> DebugApplicationInfo:
release_build_info = _release_build_info()
dirty_output = _git_output("status", "--porcelain")
commit_hash = _git_output("rev-parse", "HEAD")
if commit_hash is None and release_build_info is not None:
commit_hash_value = release_build_info.get("commit_hash")
if isinstance(commit_hash_value, str) and commit_hash_value.strip():
commit_hash = commit_hash_value.strip()
return DebugApplicationInfo(
version=_get_app_version(),
commit_hash=_git_output("rev-parse", "HEAD"),
commit_hash=commit_hash,
git_branch=_git_output("rev-parse", "--abbrev-ref", "HEAD"),
git_dirty=(dirty_output is not None and dirty_output != ""),
python_version=sys.version.split()[0],
+8 -1
View File
@@ -11,6 +11,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$SCRIPT_DIR"
RELEASE_WORK_DIR=""
RELEASE_BUNDLE_DIR_NAME="Remote-Terminal-for-MeshCore"
cleanup_release_build_artifacts() {
if [ -d "$SCRIPT_DIR/frontend/prebuilt" ]; then
@@ -178,11 +179,17 @@ npm run packaged-build
cd "$SCRIPT_DIR"
RELEASE_WORK_DIR=$(mktemp -d)
RELEASE_BUNDLE_DIR="$RELEASE_WORK_DIR/remoteterm-prebuilt-frontend-v${VERSION}-${GIT_HASH}"
RELEASE_BUNDLE_DIR="$RELEASE_WORK_DIR/$RELEASE_BUNDLE_DIR_NAME"
mkdir -p "$RELEASE_BUNDLE_DIR"
git archive "$FULL_GIT_HASH" | tar -x -C "$RELEASE_BUNDLE_DIR"
mkdir -p "$RELEASE_BUNDLE_DIR/frontend"
cp -R "$SCRIPT_DIR/frontend/prebuilt" "$RELEASE_BUNDLE_DIR/frontend/prebuilt"
cat > "$RELEASE_BUNDLE_DIR/build_info.json" <<EOF
{
"commit_hash": "$FULL_GIT_HASH",
"build_source": "prebuilt-release"
}
EOF
rm -f "$SCRIPT_DIR/$RELEASE_ASSET"
(
cd "$RELEASE_WORK_DIR"
+48
View File
@@ -5,6 +5,7 @@ Uses httpx.AsyncClient or direct function calls with real in-memory SQLite.
"""
import hashlib
import json
import logging
import time
from unittest.mock import AsyncMock, MagicMock, patch
@@ -274,6 +275,53 @@ class TestRadioDisconnectedHandler:
assert "not connected" in response.json()["detail"].lower()
class TestDebugApplicationInfo:
"""Test debug application metadata resolution."""
def test_build_application_info_uses_release_build_info_without_git(self, tmp_path):
"""Release bundles should still surface commit metadata without a .git directory."""
from app.routers import debug as debug_router
(tmp_path / "build_info.json").write_text(
json.dumps(
{
"commit_hash": "cf1a55e25828ee62fb077d6202b174f69f6e6340",
"build_source": "prebuilt-release",
}
)
)
with (
patch("app.routers.debug._repo_root", return_value=tmp_path),
patch("app.routers.debug._get_app_version", return_value="3.4.0"),
patch("app.routers.debug._git_output", return_value=None),
):
info = debug_router._build_application_info()
assert info.version == "3.4.0"
assert info.commit_hash == "cf1a55e25828ee62fb077d6202b174f69f6e6340"
assert info.git_branch is None
assert info.git_dirty is False
def test_build_application_info_ignores_invalid_release_build_info(self, tmp_path):
"""Malformed release metadata should not break the debug endpoint."""
from app.routers import debug as debug_router
(tmp_path / "build_info.json").write_text("{not-json")
with (
patch("app.routers.debug._repo_root", return_value=tmp_path),
patch("app.routers.debug._get_app_version", return_value="3.4.0"),
patch("app.routers.debug._git_output", return_value=None),
):
info = debug_router._build_application_info()
assert info.version == "3.4.0"
assert info.commit_hash is None
assert info.git_branch is None
assert info.git_dirty is False
class TestMessagesEndpoint:
"""Test message-related endpoints."""