Fix server version parsing

This commit is contained in:
Jage9
2026-03-09 01:42:59 -04:00
parent b49412a800
commit 97ff19581a
3 changed files with 34 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
// Maintainer-controlled web client version metadata.
window.CHGRID_RELEASE_VERSION = "0.1.0";
window.CHGRID_BUILD_REVISION = "R348";
window.CHGRID_BUILD_REVISION = "R349";
window.CHGRID_WEB_VERSION = `${window.CHGRID_RELEASE_VERSION} ${window.CHGRID_BUILD_REVISION}`;
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
window.CHGRID_TIME_ZONE = "America/Detroit";

View File

@@ -235,9 +235,7 @@ class SignalingServer:
try:
version_file = Path(__file__).resolve().parents[2] / "client" / "public" / "version.js"
text = version_file.read_text(encoding="utf-8")
match = re.search(r'CHGRID_WEB_VERSION\s*=\s*"([^"]+)"', text)
if match:
token = match.group(1).strip()
token = SignalingServer._version_from_web_version_text(text)
if token:
return token
except OSError:
@@ -248,6 +246,25 @@ class SignalingServer:
except PackageNotFoundError:
return "unknown"
@staticmethod
def _version_from_web_version_text(text: str) -> str:
"""Parse release/build metadata from one client version.js file."""
release_match = re.search(r'CHGRID_RELEASE_VERSION\s*=\s*"([^"]+)"', text)
revision_match = re.search(r'CHGRID_BUILD_REVISION\s*=\s*"([^"]+)"', text)
if release_match or revision_match:
parts = [
release_match.group(1).strip() if release_match else "",
revision_match.group(1).strip() if revision_match else "",
]
token = " ".join(part for part in parts if part)
if token:
return token
legacy_match = re.search(r'CHGRID_WEB_VERSION\s*=\s*"([^"]+)"', text)
if legacy_match:
return legacy_match.group(1).strip()
return ""
@property
def items(self) -> dict[str, WorldItem]:
"""Expose current item map owned by the item service."""

View File

@@ -50,6 +50,17 @@ def test_client_ip_ignores_forwarded_for_from_non_loopback_peer() -> None:
assert server._client_ip(client) == "203.0.113.20"
def test_resolve_server_version_reads_release_and_revision(monkeypatch: pytest.MonkeyPatch) -> None:
version_text = """
window.CHGRID_RELEASE_VERSION = "0.1.0";
window.CHGRID_BUILD_REVISION = "R348";
window.CHGRID_WEB_VERSION = `${window.CHGRID_RELEASE_VERSION} ${window.CHGRID_BUILD_REVISION}`;
""".strip()
resolved = SignalingServer._version_from_web_version_text(version_text)
assert resolved == "0.1.0 R348"
@pytest.mark.asyncio
async def test_update_position_rejects_out_of_bounds(monkeypatch: pytest.MonkeyPatch) -> None:
server = SignalingServer("127.0.0.1", 8765, None, None, grid_size=41)