Skip to content

Commit dcdf840

Browse files
committed
fix(app): format low disk space in GiB and MiB
1 parent 5c41d81 commit dcdf840

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎src/agent6/app/session_runtime.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ def note_state_disk_space(state_dir: pathlib.Path, *, reporter: app_reporter.Rep
152152
return
153153
if usage.free * 10 < usage.total:
154154
percent = 100 * usage.free / usage.total
155-
reporter.note(f"low disk space: {usage.free} bytes free ({percent:.1f}%) at {state_dir}")
155+
free_space = (
156+
f"{usage.free / 1024**3:.1f} GiB"
157+
if usage.free >= 1024**3
158+
else f"{usage.free / 1024**2:.0f} MiB"
159+
)
160+
reporter.note(f"low disk space: {free_space} free ({percent:.1f}%) at {state_dir}")
156161

157162

158163
def install_inside_workspace(cwd: pathlib.Path) -> pathlib.Path | None:

‎tests/unit/test_run_lifecycle_bugfix.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,35 @@ def _setup(tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch) -> pathlib.P
149149
return repo
150150

151151

152-
@pytest.mark.parametrize("free", [90, 100, 110])
152+
@pytest.mark.parametrize(
153+
("total", "free", "free_note"),
154+
[
155+
(1000, 90, "0 MiB free (9.0%)"),
156+
(1000, 100, None),
157+
(1000, 110, None),
158+
(82_000_000_000, 5_492_600_832, "5.1 GiB free (6.7%)"),
159+
(20 * 1024**3, 1024**3, "1.0 GiB free (5.0%)"),
160+
(20 * 1024**3, 1024**3 - 1, "1024 MiB free (5.0%)"),
161+
(20 * 1024**3, 550_000_000, "525 MiB free (2.6%)"),
162+
],
163+
)
153164
def test_launch_reports_low_state_disk_space_without_refusing(
154165
tmp_path: pathlib.Path,
155166
monkeypatch: pytest.MonkeyPatch,
156167
capsys: pytest.CaptureFixture[str],
168+
total: int,
157169
free: int,
170+
free_note: str | None,
158171
) -> None:
159-
"""Fresh and resumed executions warn strictly below ten percent, without refusing work."""
172+
"""Fresh and resumed executions report low space in GiB or MiB without refusing work."""
160173
repo = _setup(tmp_path, monkeypatch)
161174
state = paths.state_dir(repo)
162175
usage = shutil.disk_usage(repo)
163176
seen: list[pathlib.Path] = []
164177

165178
def disk_usage(path: Any) -> Any:
166179
seen.append(pathlib.Path(path))
167-
return usage._replace(total=1000, used=1000 - free, free=free)
180+
return usage._replace(total=total, used=total - free, free=free)
168181

169182
monkeypatch.setattr(shutil, "disk_usage", disk_usage)
170183
monkeypatch.setattr(role_providers, "build_role_provider", _use(_Scripted([_finish()])))
@@ -175,9 +188,8 @@ def disk_usage(path: Any) -> Any:
175188
assert cli_main(command) == 0
176189
notice = capsys.readouterr().err
177190
assert state in seen
178-
assert ("low disk space" in notice) == (free < 100)
179-
if free < 100:
180-
assert f"{free} bytes" in notice and "9.0%" in notice and str(state) in notice
191+
expected = [] if free_note is None else [f"[agent6] low disk space: {free_note} at {state}"]
192+
assert [line for line in notice.splitlines() if "low disk space" in line] == expected
181193
seen.clear()
182194

183195

0 commit comments

Comments
 (0)