aps-agent/tests/golden/test_health_version.py

62 lines
2.2 KiB
Python
Raw Normal View History

# ============================================================
# /api/health 版本字段(round-44 FF):version 来自 APS_APP_VERSION
# (桌面 sidecar 由 Electron main 注入 app.getVersion(),即
# apps/desktop/package.json 的 version);无来源时返回 null。
# 新增字段不破坏既有握手字段。
# ============================================================
from __future__ import annotations
import pytest
from fastapi.testclient import TestClient
from server.contracts import INTERFACE_VERSION
from tests.auth_provider import install_test_auth
@pytest.fixture()
def health_app(tmp_path, monkeypatch):
monkeypatch.setenv("APS_DB_PATH", str(tmp_path / "health.db"))
monkeypatch.setenv("APS_WORLD_PATH", str(tmp_path / "world.json"))
from server.db.database import reset_engine
from server.state import store as world_store
install_test_auth(monkeypatch, "tenant-a-000000000000000000000000001")
world_store._stores.clear()
reset_engine()
from server.gateway.app import create_app
app = create_app()
yield app
reset_engine()
world_store._stores.clear()
def test_health_version_defaults_to_null(health_app):
body = TestClient(health_app).get("/api/health").json()
assert body["ok"] is True
assert body["version"] is None
assert body["interfaceVersion"] == INTERFACE_VERSION
assert body["clientMode"] in {"web", "desktop"}
assert "authProvider" in body
assert "licenseProvider" in body
def test_health_version_reads_aps_app_version_env(health_app, monkeypatch):
monkeypatch.setenv("APS_APP_VERSION", "9.8.7")
body = TestClient(health_app).get("/api/health").json()
assert body["version"] == "9.8.7"
# 既有字段保持兼容
assert body["ok"] is True
assert body["interfaceVersion"] == INTERFACE_VERSION
assert body["clientMode"] in {"web", "desktop"}
def test_health_version_desktop_client_mode_preserved(health_app, monkeypatch):
monkeypatch.setenv("APS_APP_VERSION", "0.2.0")
body = TestClient(health_app).get(
"/api/health", headers={"x-aps-client": "desktop"}
).json()
assert body["clientMode"] == "desktop"
assert body["version"] == "0.2.0"
assert body["ok"] is True