Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(cli): clear failed Linux screenshot attempts

cyh5d1390e31ce1
diff --git a/tests/test_cli_screenshot_command.py b/tests/test_cli_screenshot_command.py
index 214f09072..ea1ca9561 100644
--- a/tests/test_cli_screenshot_command.py
+++ b/tests/test_cli_screenshot_command.py
@@ -117,6 +117,35 @@ def test_capture_screenshot_preserves_existing_output_when_linux_backend_fails(
assert output.read_bytes() == b"existing"
+def test_linux_fallback_clears_partial_capture_before_next_backend(tmp_path: Path, monkeypatch) -> None:
+ output = tmp_path / "screen.png"
+ output.write_bytes(b"existing")
+ available = {"grim", "gnome-screenshot"}
+
+ monkeypatch.setattr(screenshot.sys, "platform", "linux")
+ monkeypatch.setattr(screenshot, "which", lambda name: f"/usr/bin/{name}" if name in available else None)
+
+ def capture_with_partial_then_empty_success(command, label):
+ capture_path = Path(command[-1])
+ if label == "grim":
+ capture_path.write_bytes(b"partial")
+ raise ScreenshotError("backend failed")
+ if label == "gnome-screenshot":
+ return
+ raise AssertionError(f"unexpected backend: {label}")
+
+ monkeypatch.setattr(screenshot, "_run_capture_command", capture_with_partial_then_empty_success)
+
+ try:
+ capture_screenshot(output)
+ except ScreenshotError as exc:
+ assert "screenshot file was not created" in str(exc)
+ else:
+ raise AssertionError("expected ScreenshotError")
+
+ assert output.read_bytes() == b"existing"
+
+
def test_capture_screenshot_replaces_existing_output_only_after_success(tmp_path: Path, monkeypatch) -> None:
output = tmp_path / "screen.png"
output.write_bytes(b"existing")
diff --git a/vibe/screenshot.py b/vibe/screenshot.py
index 2a310eaf9..f52a6384b 100644
--- a/vibe/screenshot.py
+++ b/vibe/screenshot.py
@@ -135,17 +135,25 @@ def _capture_linux(output: Path) -> str:
if which(name) is None:
continue
attempted.append(name)
+ _remove_output_if_exists(output)
try:
_run_capture_command(command, name)
return name
except ScreenshotError:
- pass
+ _remove_output_if_exists(output)
if attempted:
raise ScreenshotError(f"installed screenshot tools failed: {', '.join(attempted)}")
raise ScreenshotError("no Linux screenshot tool found; install grim, gnome-screenshot, spectacle, scrot, or ImageMagick")
+def _remove_output_if_exists(output: Path) -> None:
+ try:
+ output.unlink(missing_ok=True)
+ except OSError:
+ pass
+
+
def _run_capture_command(command: list[str], label: str) -> None:
try:
result = subprocess.run(command, capture_output=True, text=True, timeout=30)