Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/routers/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion scripts/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions tests/test_health_system_memory.py
Original file line number Diff line number Diff line change
@@ -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}
Loading