From e58f0759c213075f70d89834b4a6a8908c3089b7 Mon Sep 17 00:00:00 2001 From: G4614 <92488762+G4614@users.noreply.github.com> Date: Thu, 9 Jul 2026 21:37:24 +0800 Subject: [PATCH 1/2] fix(python): add async SimpleBox metrics --- sdks/python/boxlite/simplebox.py | 9 +++++++++ sdks/python/tests/test_simplebox.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 sdks/python/tests/test_simplebox.py diff --git a/sdks/python/boxlite/simplebox.py b/sdks/python/boxlite/simplebox.py index e6082c4e9..d9f61a18c 100644 --- a/sdks/python/boxlite/simplebox.py +++ b/sdks/python/boxlite/simplebox.py @@ -292,6 +292,15 @@ async def collect_stderr(): error_message=error_message, ) + async def metrics(self): + """Get box metrics (CPU, memory usage).""" + if not self._started: + raise RuntimeError( + "Box not started. Use 'async with SimpleBox(...) as box:' " + "or call 'await box.start()' first." + ) + return await self._box.metrics() + async def stop(self): """ Stop the box and release resources. diff --git a/sdks/python/tests/test_simplebox.py b/sdks/python/tests/test_simplebox.py new file mode 100644 index 000000000..1d00593cf --- /dev/null +++ b/sdks/python/tests/test_simplebox.py @@ -0,0 +1,20 @@ +"""Integration tests for the async SimpleBox convenience wrapper.""" + +from __future__ import annotations + +import pytest + +import boxlite + +pytestmark = [pytest.mark.integration, pytest.mark.asyncio] + + +async def test_simplebox_metrics(shared_runtime): + """Async SimpleBox exposes box metrics like SyncSimpleBox.""" + async with boxlite.SimpleBox( + image="alpine:latest", runtime=shared_runtime + ) as box: + await box.exec("echo", "test") + metrics = await box.metrics() + assert metrics is not None + assert metrics.commands_executed_total >= 1 From ec139c2379a6019629087e8fff07d9348914bb02 Mon Sep 17 00:00:00 2001 From: G4614 <92488762+G4614@users.noreply.github.com> Date: Thu, 9 Jul 2026 21:53:25 +0800 Subject: [PATCH 2/2] style(python): format simplebox metrics test --- sdks/python/tests/test_simplebox.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdks/python/tests/test_simplebox.py b/sdks/python/tests/test_simplebox.py index 1d00593cf..3f6d9601c 100644 --- a/sdks/python/tests/test_simplebox.py +++ b/sdks/python/tests/test_simplebox.py @@ -11,9 +11,7 @@ async def test_simplebox_metrics(shared_runtime): """Async SimpleBox exposes box metrics like SyncSimpleBox.""" - async with boxlite.SimpleBox( - image="alpine:latest", runtime=shared_runtime - ) as box: + async with boxlite.SimpleBox(image="alpine:latest", runtime=shared_runtime) as box: await box.exec("echo", "test") metrics = await box.metrics() assert metrics is not None