diff --git a/client/public/version.js b/client/public/version.js index 1207c09..0fc9288 100644 --- a/client/public/version.js +++ b/client/public/version.js @@ -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"; diff --git a/server/app/server.py b/server/app/server.py index 99e454f..59403f2 100644 --- a/server/app/server.py +++ b/server/app/server.py @@ -235,11 +235,9 @@ 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() - if token: - return token + token = SignalingServer._version_from_web_version_text(text) + if token: + return token except OSError: pass @@ -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.""" diff --git a/server/tests/test_server_message_handling.py b/server/tests/test_server_message_handling.py index 52633c1..2f7d2c0 100644 --- a/server/tests/test_server_message_handling.py +++ b/server/tests/test_server_message_handling.py @@ -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)