Files
qwenpaw/tests/unit/agents/tools/test_desktop_screenshot.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

74 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""Tests for desktop_screenshot cancel cleanup."""
# pylint: disable=protected-access
from __future__ import annotations
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from agentscope.message import Base64Source
from PIL import Image
from qwenpaw.agents.tools.desktop_screenshot import (
_tool_ok,
_capture_macos_screencapture,
desktop_screenshot,
)
@pytest.mark.asyncio
async def test_macos_screencapture_kills_proc_on_cancel(tmp_path):
"""Cancel/timeout must terminate the interactive screencapture process."""
proc = MagicMock()
proc.returncode = None
proc.kill = MagicMock()
proc.wait = AsyncMock(return_value=0)
async def _raise_cancelled(*_args, **_kwargs):
raise asyncio.CancelledError()
with (
patch(
"asyncio.create_subprocess_exec",
new=AsyncMock(return_value=proc),
),
patch(
"qwenpaw.tool_calls.cancellable_wait",
new=_raise_cancelled,
),
):
result = await _capture_macos_screencapture(
str(tmp_path / "shot.png"),
capture_window=True,
)
assert "timed out" in result.content[0].text.lower()
proc.kill.assert_called_once()
proc.wait.assert_awaited()
@pytest.mark.asyncio
async def test_desktop_screenshot_freezes_local_image(tmp_path):
"""A captured screenshot is immutable before tool return."""
image_path = tmp_path / "desktop.png"
def capture(path):
Image.new("RGB", (2, 2), color="red").save(path)
return _tool_ok(path, f"Desktop screenshot saved to {path}")
with (
patch("platform.system", return_value="Linux"),
patch(
"qwenpaw.agents.tools.desktop_screenshot._capture_mss",
side_effect=capture,
),
):
result = await desktop_screenshot(str(image_path))
assert isinstance(result.content[0].source, Base64Source)
first_data = result.content[0].source.data
Image.new("RGB", (2, 2), color="blue").save(image_path)
assert result.content[0].source.data == first_data