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

113 lines
3.9 KiB
Python

"""Windows Server E2E test using cua-sandbox SDK.
Run:
CUA_API_KEY=sk-dev-test-key-local-12345 CUA_BASE_URL=http://localhost:8082 \
uv run pytest tests/test_windows_cloud.py -v -s
"""
import os
import time
import pytest
from cua_sandbox import Image, Sandbox
pytestmark = pytest.mark.asyncio
def P(*a, **kw):
print(*a, **kw, flush=True)
def _has_env() -> bool:
return bool(os.environ.get("CUA_API_KEY"))
@pytest.mark.skipif(not _has_env(), reason="CUA_API_KEY not set")
async def test_windows_create_and_snapshot():
"""Image.windows('server-2025') -> Sandbox.ephemeral -> snapshot -> fork."""
t0 = time.monotonic()
P("\n Creating Sandbox with Image.windows('server-2025')...")
async with Sandbox.ephemeral(Image.windows("server-2025"), local=False) as sb:
t_create = time.monotonic() - t0
P(f" Sandbox ready: {t_create:.1f}s name={sb.name}")
# Try screenshot
try:
screen = await sb.screenshot()
P(f" Screenshot: {len(screen)} bytes")
except Exception as e:
P(f" Screenshot not available: {e}")
screen = None
# Snapshot
t1 = time.monotonic()
P(" Taking snapshot...")
snapshot_img = await sb.snapshot()
t_snap = time.monotonic() - t1
P(f" Snapshot: {t_snap:.2f}s")
# Fork from snapshot
t2 = time.monotonic()
P(" Forking from snapshot...")
async with Sandbox.ephemeral(snapshot_img, local=False) as fork:
t_fork = time.monotonic() - t2
P(f" Fork ready: {t_fork:.1f}s name={fork.name}")
try:
fork_screen = await fork.screenshot()
P(f" Fork screenshot: {len(fork_screen)} bytes")
except Exception as e:
P(f" Fork screenshot not available: {e}")
fork_screen = None
t_total = time.monotonic() - t0
P("\n === TIMINGS ===")
P(f" Create+ready: {t_create:.1f}s")
P(f" Snapshot: {t_snap:.2f}s")
P(f" Fork+ready: {t_fork:.1f}s")
P(f" Total: {t_total:.1f}s")
@pytest.mark.skipif(not _has_env(), reason="CUA_API_KEY not set")
async def test_windows_stateful_snapshot_fork():
"""Stateful snapshot captures RAM — fork resumes instantly without rebooting."""
t0 = time.monotonic()
P("\n Creating Sandbox with Image.windows('server-2025')...")
async with Sandbox.ephemeral(Image.windows("server-2025"), local=False) as sb:
t_create = time.monotonic() - t0
P(f" Sandbox ready: {t_create:.1f}s name={sb.name}")
# Verify CUA server is running
screen = await sb.screenshot()
P(f" Screenshot: {len(screen)} bytes")
# Stateful snapshot — captures memory state
t1 = time.monotonic()
P(" Taking stateful snapshot...")
snapshot_img = await sb.snapshot(stateful=True)
t_snap = time.monotonic() - t1
P(f" Stateful snapshot: {t_snap:.2f}s")
# Fork from stateful snapshot — should resume instantly
t2 = time.monotonic()
P(" Forking from stateful snapshot...")
async with Sandbox.ephemeral(snapshot_img, local=False) as fork:
t_fork = time.monotonic() - t2
P(f" Fork ready: {t_fork:.1f}s name={fork.name}")
# Fork should have CUA server immediately available (no reboot)
fork_screen = await fork.screenshot()
P(f" Fork screenshot: {len(fork_screen)} bytes")
assert len(fork_screen) > 1000, "Fork screenshot should be non-trivial"
t_total = time.monotonic() - t0
P("\n === STATEFUL TIMINGS ===")
P(f" Create+ready: {t_create:.1f}s")
P(f" Stateful snapshot: {t_snap:.2f}s")
P(f" Fork+ready: {t_fork:.1f}s (should be <10s with stateful)")
P(f" Total: {t_total:.1f}s")