Files
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

95 lines
3.0 KiB
Python

"""Simple click test task for native environments (Linux Docker or Windows QEMU)."""
import asyncio
from pathlib import Path
import cua_bench as cb
@cb.tasks_config(split="train")
def load():
"""Define task variants for each supported OS."""
os_types = ["linux", "windows"]
return [
cb.Task(
description=f'Click the big blue "Click Me" button to complete the task. ({os_type})',
metadata={"button_id": "click-me", "os_type": os_type},
computer={
"provider": "native",
"setup_config": {
"os_type": os_type,
"width": 1024,
"height": 768,
},
},
)
for os_type in os_types
]
pid = None
@cb.setup_task(split="train")
async def start(task_cfg, session: cb.DesktopSession):
"""Initialize the task - launch a webview with a button."""
global pid
pid = await session.launch_window(
html=(Path(__file__).parent / "gui/index.html").read_text("utf-8"),
title="Click Test",
width=400,
height=300,
)
# Wait for browser to open and render
await asyncio.sleep(3.0)
@cb.evaluate_task(split="train")
async def evaluate(task_cfg, session: cb.DesktopSession) -> list[float]:
"""Check if the button was clicked.
For native environments (QEMU), JavaScript execution returns None,
so we can't verify programmatically. Return 0.5 (uncertain) in that case.
For simulated environments (Playwright), we can check the JS state.
"""
global pid
if pid is None:
return [0.0]
clicked = await session.execute_javascript(pid, "window.__clicked")
if clicked is None:
# Native environment - can't verify via JS
# Could implement visual verification here in the future
return [0.5] # Uncertain - task ran but can't verify
return [1.0] if clicked is True else [0.0]
@cb.solve_task(split="train")
async def solve(task_cfg, session: cb.DesktopSession):
"""Oracle solution - click the button.
For native environments, click at the center of the screen where the
browser window with the centered button should be.
"""
global pid
if pid is None:
return
# Try element-based click first (works in simulated environments)
try:
await session.click_element(pid, "#click-me")
except (NotImplementedError, AttributeError):
# Native environment - use screen coordinates via execute_action
# The button is centered in a maximized or large browser window
# Assume it's roughly at screen center
screen_width = 1024 # From setup_config
screen_height = 768
# Click at approximate center of screen
# Note: Browser chrome adds ~100px at top, so adjust slightly down
click_action = cb.ClickAction(x=screen_width // 2, y=screen_height // 2 + 50)
await session.execute_action(click_action)
if __name__ == "__main__":
cb.interact(__file__)