Fix server version parsing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Maintainer-controlled web client version metadata.
|
// Maintainer-controlled web client version metadata.
|
||||||
window.CHGRID_RELEASE_VERSION = "0.1.0";
|
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}`;
|
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.
|
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
||||||
window.CHGRID_TIME_ZONE = "America/Detroit";
|
window.CHGRID_TIME_ZONE = "America/Detroit";
|
||||||
|
|||||||
@@ -235,11 +235,9 @@ class SignalingServer:
|
|||||||
try:
|
try:
|
||||||
version_file = Path(__file__).resolve().parents[2] / "client" / "public" / "version.js"
|
version_file = Path(__file__).resolve().parents[2] / "client" / "public" / "version.js"
|
||||||
text = version_file.read_text(encoding="utf-8")
|
text = version_file.read_text(encoding="utf-8")
|
||||||
match = re.search(r'CHGRID_WEB_VERSION\s*=\s*"([^"]+)"', text)
|
token = SignalingServer._version_from_web_version_text(text)
|
||||||
if match:
|
if token:
|
||||||
token = match.group(1).strip()
|
return token
|
||||||
if token:
|
|
||||||
return token
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -248,6 +246,25 @@ class SignalingServer:
|
|||||||
except PackageNotFoundError:
|
except PackageNotFoundError:
|
||||||
return "unknown"
|
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
|
@property
|
||||||
def items(self) -> dict[str, WorldItem]:
|
def items(self) -> dict[str, WorldItem]:
|
||||||
"""Expose current item map owned by the item service."""
|
"""Expose current item map owned by the item service."""
|
||||||
|
|||||||
@@ -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"
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_update_position_rejects_out_of_bounds(monkeypatch: pytest.MonkeyPatch) -> None:
|
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)
|
server = SignalingServer("127.0.0.1", 8765, None, None, grid_size=41)
|
||||||
|
|||||||
Reference in New Issue
Block a user