Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

2.6 KB
Raw Blame
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Cua AI, Inc.

#![cfg(target_os = "linux")]

use platform_linux::wayland::kwin_helper::{available, parse_snapshot};

#[test]
fn parses_versioned_kwin_snapshot() {
    let snapshot = parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":100,"y":80,"w":800,"h":600,"active":false,"minimized":false,"stacking":3}]"#,
    )
    .expect("valid KWin helper snapshot");

    assert_eq!(snapshot.len(), 1);
    assert_eq!(snapshot[0].token, 41);
    assert_eq!(snapshot[0].pid, 1200);
    assert_eq!((snapshot[0].x, snapshot[0].y), (100, 80));
}

#[test]
fn preserves_title_with_apostrophe_from_dbus_string() {
    let snapshot = parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":100,"y":80,"w":800,"h":600,"active":false,"minimized":false,"stacking":3,"title":"owner's editor","app_id":"org.example.Editor"}]"#,
    )
    .expect("apostrophe in the decoded D-Bus string must remain valid JSON");

    assert_eq!(snapshot[0].title, "owner's editor");
}

#[test]
fn parses_snapshot_when_title_contains_closing_bracket() {
    let snapshot = parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":100,"y":80,"w":800,"h":600,"active":false,"minimized":false,"stacking":3,"title":"A ] title","app_id":"org.example.Editor"}]"#,
    )
    .expect("title brackets must not break snapshot parsing");

    assert_eq!(snapshot[0].title, "A ] title");
}

#[test]
fn parses_fractional_plasma_geometry() {
    let snapshot = parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":100,"y":80,"w":332,"h":99.33333333333336,"active":false,"minimized":false,"stacking":3}]"#,
    )
    .expect("finite fractional geometry is valid metadata");

    assert_eq!(snapshot[0].height, 99);
}

#[test]
fn rejects_zero_token() {
    assert!(parse_snapshot(
        r#"[{"token":0,"pid":1200,"x":0,"y":0,"w":10,"h":10,"active":false,"minimized":false,"stacking":0}]"#,
    )
    .is_none());
}

#[test]
fn rejects_duplicate_tokens() {
    assert!(parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":0,"y":0,"w":10,"h":10,"active":false,"minimized":false,"stacking":0},{"token":41,"pid":1300,"x":20,"y":20,"w":10,"h":10,"active":false,"minimized":false,"stacking":1}]"#,
    )
    .is_none());
}

#[test]
fn rejects_multiple_active_records() {
    assert!(parse_snapshot(
        r#"[{"token":41,"pid":1200,"x":0,"y":0,"w":10,"h":10,"active":true,"minimized":false,"stacking":0},{"token":42,"pid":1300,"x":20,"y":20,"w":10,"h":10,"active":true,"minimized":false,"stacking":1}]"#,
    )
    .is_none());
}

#[test]
fn kwin_reports_no_target_bound_input() {
    assert!(
        !available(),
        "focus-bound KWin input must not be advertised as safe"
    );
}