diff --git a/api/routers/health.py b/api/routers/health.py index 0004c803..41488adc 100644 --- a/api/routers/health.py +++ b/api/routers/health.py @@ -314,7 +314,14 @@ def health_system(): } with contextlib.suppress(OSError): info["loadavg"] = os.getloadavg() - info.update(meminfo_summary()) + memory_kb = meminfo_summary() + info.update(memory_kb) + # Portable read-only resource shape. Retain legacy flat Linux fields for + # existing clients while offering bytes to Windows/Wine consumers. + info["memory"] = { + "total_bytes": memory_kb.get("mem_total_kb", 0) * 1024, + "available_bytes": memory_kb.get("mem_available_kb", 0) * 1024, + } return info diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh index fdff62e5..b4931410 100755 --- a/scripts/ci/test.sh +++ b/scripts/ci/test.sh @@ -28,4 +28,5 @@ pytest \ tests/test_ci_public_conformance_summary.py \ tests/test_ci_unit_isolation.py \ tests/test_winepath_startup_retry.py \ - tests/test_wininspect_error_redaction.py + tests/test_wininspect_error_redaction.py \ + tests/test_health_system_memory.py diff --git a/tests/test_health_system_memory.py b/tests/test_health_system_memory.py new file mode 100644 index 00000000..7e0a403e --- /dev/null +++ b/tests/test_health_system_memory.py @@ -0,0 +1,36 @@ +"""Portable health/system resource contract, using synthetic memory data only.""" + +from unittest.mock import patch + +from api.routers.health import health_system + + +def test_health_system_reports_byte_normalized_memory_without_dropping_legacy_fields(): + with patch( + "api.routers.health.meminfo_summary", + return_value={"mem_total_kb": 4096, "mem_available_kb": 1024}, + ), patch( + "api.core.discovery.discovery_manager.status", return_value={} + ), patch( + "api.routers.health.platform.node", return_value="synthetic-test-host" + ): + payload = health_system() + + assert payload["memory"] == { + "total_bytes": 4096 * 1024, + "available_bytes": 1024 * 1024, + } + assert payload["mem_total_kb"] == 4096 + assert payload["mem_available_kb"] == 1024 + assert "cpu_count" in payload + + +def test_health_system_memory_shape_remains_defined_without_proc_meminfo(): + with patch( + "api.routers.health.meminfo_summary", return_value={} + ), patch( + "api.core.discovery.discovery_manager.status", return_value={} + ): + payload = health_system() + + assert payload["memory"] == {"total_bytes": 0, "available_bytes": 0}