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.

ci(cua-driver): consolidate Linux Nix validation (conv2 6/7) (#2184)

Francesco Bonacci5abbd802690d
diff --git a/.github/workflows/ci-distro-compat-cua-driver.yml b/.github/workflows/ci-distro-compat-cua-driver.yml
index f65d3bc824..a176113cf2 100644
--- a/.github/workflows/ci-distro-compat-cua-driver.yml
+++ b/.github/workflows/ci-distro-compat-cua-driver.yml
@@ -18,7 +18,7 @@ name: "CI: cua-driver distro-compat matrix"
# built one. This is the only way to catch ABI mismatches because the NixOS
# CI builds its own binary against NixOS's own glibc.
# - Keep this fast and cheap: containers + --version/doctor only. Full GUI
-# integration tests stay in nix-build.yml.
+# behavior stays in the canonical Rust X11 and Wayland E2E workflows.
# - Non-blocking by default (continue-on-error: true) — the released binary
# may not exist yet on a fresh branch; the job is informational until the
# first linux release tag exists.
@@ -27,7 +27,8 @@ name: "CI: cua-driver distro-compat matrix"
# Also runs on push to main and on workflow_dispatch so it works as a
# post-release regression guard.
#
-# Companion to nix-build.yml — does NOT replace it. See CUA-599.
+# Companion to the Rust desktop E2E workflows; it validates released binaries,
+# not source-built harness behavior.
on:
pull_request:
diff --git a/.github/workflows/ci-nix-linux.yml b/.github/workflows/ci-nix-linux.yml
index 611a3b0cbc..b99fff3480 100644
--- a/.github/workflows/ci-nix-linux.yml
+++ b/.github/workflows/ci-nix-linux.yml
@@ -1,14 +1,13 @@
name: "CI: Nix Linux Rust source"
-# This is the automatic Nix lane. Desktop-heavy legacy checks live in
-# nix-build.yml and nix-wayland.yml and are maintainer-dispatched instead.
+# Nix owns reproducible Linux package and Rust-source builds. Interactive
+# desktop behavior is owned by the Rust E2E workflows.
on:
pull_request:
paths:
- "flake.nix"
- "flake.lock"
- - "nix/cua-driver/package.nix"
- - "nix/cua-driver/tests/rust-unit.nix"
+ - "nix/cua-driver/**"
- "libs/cua-driver/rust/**"
- ".github/workflows/ci-nix-linux.yml"
push:
@@ -16,8 +15,7 @@ on:
paths:
- "flake.nix"
- "flake.lock"
- - "nix/cua-driver/package.nix"
- - "nix/cua-driver/tests/rust-unit.nix"
+ - "nix/cua-driver/**"
- "libs/cua-driver/rust/**"
- ".github/workflows/ci-nix-linux.yml"
workflow_dispatch:
@@ -31,9 +29,19 @@ concurrency:
jobs:
rust-source:
- name: Nix Linux Rust source check
+ name: Nix / ${{ matrix.name }}
runs-on: ubuntu-latest
- timeout-minutes: 45
+ timeout-minutes: 60
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - name: compositor build
+ attribute: cua-compositor-build
+ - name: driver package
+ attribute: cua-driver-build
+ - name: Rust unit tests
+ attribute: cua-driver-linux-rust-unit
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Install Nix
@@ -41,5 +49,8 @@ jobs:
with:
extra_nix_config: |
experimental-features = nix-command flakes
- - name: Run source-built Rust check
- run: nix build .#checks.x86_64-linux.cua-driver-linux-rust-unit --print-build-logs --show-trace
+ - name: Build ${{ matrix.name }}
+ run: >-
+ nix build
+ .#checks.x86_64-linux.${{ matrix.attribute }}
+ --no-link --print-build-logs --show-trace
diff --git a/.github/workflows/e2e-rust-linux-wayland.yml b/.github/workflows/e2e-rust-linux-wayland.yml
index d03136df3d..da15038b2e 100644
--- a/.github/workflows/e2e-rust-linux-wayland.yml
+++ b/.github/workflows/e2e-rust-linux-wayland.yml
@@ -14,6 +14,7 @@ on:
default: sway
options:
- sway
+ - cua-compositor
lane:
description: "Diagnostic lane; canonical dispatches use all"
required: false
@@ -80,6 +81,7 @@ jobs:
ref: ${{ needs.source.outputs.sha }}
- uses: dtolnay/rust-toolchain@stable
- name: Install Sway and Rust build dependencies
+ if: inputs.environment == 'sway'
shell: bash
run: |
sudo apt-get update
@@ -91,11 +93,23 @@ jobs:
libxext-dev libdrm-dev libgbm-dev libwebkit2gtk-4.1-dev \
libssl-dev libxdo-dev libayatana-appindicator3-dev librsvg2-dev \
ffmpeg jq
+ - name: Install Nix for the custom compositor environment
+ if: inputs.environment == 'cua-compositor'
+ uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
+ with:
+ extra_nix_config: |
+ experimental-features = nix-command flakes
- name: Run complete native Wayland matrix
shell: bash
env:
CUA_AT_SPI_BUS_LAUNCHER: /usr/libexec/at-spi-bus-launcher
- run: scripts/ci/linux/run-rust-e2e-wayland.sh
+ run: |
+ if [[ "${{ inputs.environment }}" == "cua-compositor" ]]; then
+ nix develop .#cua-driver-inject-e2e \
+ -c scripts/ci/linux/run-rust-e2e-inject.sh
+ else
+ scripts/ci/linux/run-rust-e2e-wayland.sh
+ fi
- name: Upload Wayland results
if: always()
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml
deleted file mode 100644
index 8cf029dbaa..0000000000
--- a/.github/workflows/nix-build.yml
+++ /dev/null
@@ -1,437 +0,0 @@
-name: Nix Build & Integration Tests
-
-on:
- # The legacy GUI/toolkit matrix is expensive and includes GIF diagnostics.
- # It remains available for maintainers, while ci-nix-linux.yml owns the
- # automatic source-built Rust check.
- workflow_dispatch:
-
-permissions:
- id-token: write
- contents: read
- pull-requests: write
-
-env:
- AWS_REGION: us-west-2
- NIX_CACHE_BUCKET: trycua-nix-cache
- NIX_CACHE_SECRET: nix-cache/trycua-nix-cache/signing-key
-
-jobs:
- nix-checks:
- name: ${{ matrix.name }}
- runs-on: ubuntu-latest
- timeout-minutes: 60
- strategy:
- fail-fast: false
- matrix:
- include:
- - name: NixOS integration test
- check_attr: cua-driver-integration
- timeout_minutes: 8
- visual: false
- result_link: result-cua-driver-integration
- artifact_name: ""
- - name: NixOS set_config persistence test
- check_attr: cua-driver-set-config
- timeout_minutes: 8
- visual: false
- result_link: result-cua-driver-set-config
- artifact_name: ""
- - name: Linux cursor click GIF test
- check_attr: cua-driver-linux-cursor-click-gif
- timeout_minutes: 12
- visual: true
- result_link: result-linux-cursor-click-gif
- artifact_name: cua-driver-linux-cursor-click-gif
- - name: Linux background terminal GIF test
- check_attr: cua-driver-linux-background-terminal-gif
- timeout_minutes: 12
- visual: true
- result_link: result-linux-background-terminal-gif
- artifact_name: cua-driver-linux-background-terminal-gif
- - name: Linux parallel multi-cursor drag test
- check_attr: cua-driver-linux-parallel-drag-xserver
- timeout_minutes: 20
- visual: true
- result_link: result-linux-parallel-drag-xserver
- artifact_name: cua-driver-linux-parallel-drag-xserver
- # NOTE: the older "parallel multi-cursor drag GIF" scenario
- # (linux-parallel-drag-gif.nix) is intentionally not in this matrix —
- # it hand-launches Xorg, which can't get a VT/seat in the emulated
- # nixos-test VM. The services.xserver entry above supersedes it; the
- # old scenario file is kept for local/real-X runs.
- # Full entries (CDP / Tk focus-free-write overrides) — kept as-is.
- - name: Linux background GUI test (chromium)
- check_attr: cua-driver-linux-background-gui-chromium
- timeout_minutes: 25
- visual: true
- result_link: result-linux-background-gui-chromium
- artifact_name: cua-driver-linux-background-gui-chromium
- - name: Linux background GUI test (tk)
- check_attr: cua-driver-linux-background-gui-tk
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-tk
- artifact_name: cua-driver-linux-background-gui-tk
- # Real-app READ-ONLY skeleton matrix (5 per toolkit category).
- # GTK3
- - name: Linux background GUI test (gtk3-gedit)
- check_attr: cua-driver-linux-background-gui-gtk3-gedit
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-gtk3-gedit
- artifact_name: cua-driver-linux-background-gui-gtk3-gedit
- - name: Linux background GUI test (gtk3-mousepad)
- check_attr: cua-driver-linux-background-gui-gtk3-mousepad
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-gtk3-mousepad
- artifact_name: cua-driver-linux-background-gui-gtk3-mousepad
- # gtk3-geany temporarily disabled (huge AT-SPI tree grinds the emulated VM; job times out)
- # - name: Linux background GUI test (gtk3-geany)
- # check_attr: cua-driver-linux-background-gui-gtk3-geany
- # timeout_minutes: 15
- # visual: true
- # result_link: result-linux-background-gui-gtk3-geany
- # artifact_name: cua-driver-linux-background-gui-gtk3-geany
- - name: Linux background GUI test (gtk3-scite)
- check_attr: cua-driver-linux-background-gui-gtk3-scite
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-gtk3-scite
- artifact_name: cua-driver-linux-background-gui-gtk3-scite
- # gtk3-abiword temporarily disabled (huge AT-SPI tree grinds the emulated VM; job times out)
- # - name: Linux background GUI test (gtk3-abiword)
- # check_attr: cua-driver-linux-background-gui-gtk3-abiword
- # timeout_minutes: 15
- # visual: true
- # result_link: result-linux-background-gui-gtk3-abiword
- # artifact_name: cua-driver-linux-background-gui-gtk3-abiword
- # GTK4
- - name: Linux background GUI test (gtk4-characters)
- check_attr: cua-driver-linux-background-gui-gtk4-characters
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-gtk4-characters
- artifact_name: cua-driver-linux-background-gui-gtk4-characters
- # Qt5
- - name: Linux background GUI test (qt5-manuskript)
- check_attr: cua-driver-linux-background-gui-qt5-manuskript
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt5-manuskript
- artifact_name: cua-driver-linux-background-gui-qt5-manuskript
- - name: Linux background GUI test (qt5-klog)
- check_attr: cua-driver-linux-background-gui-qt5-klog
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt5-klog
- artifact_name: cua-driver-linux-background-gui-qt5-klog
- - name: Linux background GUI test (qt5-openambit)
- check_attr: cua-driver-linux-background-gui-qt5-openambit
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt5-openambit
- artifact_name: cua-driver-linux-background-gui-qt5-openambit
- # Qt6
- - name: Linux background GUI test (qt6-kate)
- check_attr: cua-driver-linux-background-gui-qt6-kate
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt6-kate
- artifact_name: cua-driver-linux-background-gui-qt6-kate
- - name: Linux background GUI test (qt6-kcalc)
- check_attr: cua-driver-linux-background-gui-qt6-kcalc
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt6-kcalc
- artifact_name: cua-driver-linux-background-gui-qt6-kcalc
- - name: Linux background GUI test (qt6-okular)
- check_attr: cua-driver-linux-background-gui-qt6-okular
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt6-okular
- artifact_name: cua-driver-linux-background-gui-qt6-okular
- - name: Linux background GUI test (qt6-qownnotes)
- check_attr: cua-driver-linux-background-gui-qt6-qownnotes
- timeout_minutes: 15
- visual: true
- result_link: result-linux-background-gui-qt6-qownnotes
- artifact_name: cua-driver-linux-background-gui-qt6-qownnotes
- # Electron (heavy: more memory + 25-min timeout)
- - name: Linux background GUI test (electron-zettlr)
- check_attr: cua-driver-linux-background-gui-electron-zettlr
- timeout_minutes: 25
- visual: true
- result_link: result-linux-background-gui-electron-zettlr
- artifact_name: cua-driver-linux-background-gui-electron-zettlr
- - name: Linux background GUI test (electron-joplin)
- check_attr: cua-driver-linux-background-gui-electron-joplin
- timeout_minutes: 25
- visual: true
- result_link: result-linux-background-gui-electron-joplin
- artifact_name: cua-driver-linux-background-gui-electron-joplin
- - name: Linux background GUI test (electron-logseq)
- check_attr: cua-driver-linux-background-gui-electron-logseq
- timeout_minutes: 25
- visual: true
- result_link: result-linux-background-gui-electron-logseq
- artifact_name: cua-driver-linux-background-gui-electron-logseq
- # Firefox is temporarily disabled: under the emulated CI VM (no KVM) it
- # does not surface its window within the launch timeout, so the job
- # times out before any AT-SPI subtest runs. The browser/AT-SPI read
- # path is already covered by the chromium job. Re-enable once launch is
- # made reliable (longer timeout + pre-seeded first-run-free profile).
- # - name: Linux background GUI test (firefox)
- # check_attr: cua-driver-linux-background-gui-firefox
- # timeout_minutes: 25
- # visual: false
- # result_link: result-linux-background-gui-firefox
- # artifact_name: ""
-
- steps:
- - name: Checkout
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
-
- - name: Configure AWS Credentials via OIDC
- uses: aws-actions/configure-aws-credentials@ff717079ee2060e4bcee96c4779b553acc87447c # v4
- with:
- role-to-assume: arn:aws:iam::296062593712:role/github-actions-nix-cache
- aws-region: ${{ env.AWS_REGION }}
-
- - name: Get Nix signing key
- id: nix-key
- run: |
- SECRET=$(aws secretsmanager get-secret-value \
- --secret-id "${{ env.NIX_CACHE_SECRET }}" \
- --query 'SecretString' --output text)
-
- SECRET_KEY=$(echo "$SECRET" | jq -r '.secret_key')
- echo "::add-mask::$SECRET_KEY"
- echo "$SECRET_KEY" > "${{ runner.temp }}/signing-key.sec"
- chmod 600 "${{ runner.temp }}/signing-key.sec"
-
- PUBLIC_KEY=$(echo "$SECRET" | jq -r '.public_key')
- echo "public_key=$PUBLIC_KEY" >> "$GITHUB_OUTPUT"
-
- - name: Setup AWS credentials file for Nix
- run: |
- mkdir -p ~/.aws
- printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_SESSION_TOKEN" "$AWS_REGION" > ~/.aws/credentials
- chmod 600 ~/.aws/credentials
-
- sudo mkdir -p /root/.aws
- sudo bash -c "printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- '$AWS_ACCESS_KEY_ID' '$AWS_SECRET_ACCESS_KEY' '$AWS_SESSION_TOKEN' '$AWS_REGION' > /root/.aws/credentials"
- sudo chmod 600 /root/.aws/credentials
-
- - name: Install Nix
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- # Container-based NixOS integration tests (testers.nixosTest with
- # `containers`) run under systemd-nspawn instead of QEMU: no KVM
- # needed, much faster/cheaper. The nspawn builds require an allocated
- # UID range and cgroup delegation, advertised here on the builder.
- extra-experimental-features = auto-allocate-uids cgroups
- auto-allocate-uids = true
- extra-system-features = uid-range
- substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }} https://cache.nixos.org
- trusted-substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}
- trusted-public-keys = ${{ steps.nix-key.outputs.public_key }} cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
-
- - name: Run ${{ matrix.name }}
- timeout-minutes: ${{ matrix.timeout_minutes }}
- run: |
- nix build .#checks.x86_64-linux.${{ matrix.check_attr }} \
- --print-build-logs --show-trace \
- -o ${{ matrix.result_link }}
-
- - name: Collect GIF artifacts
- if: always() && matrix.visual
- run: |
- mkdir -p artifacts
- find -L "${{ matrix.result_link }}/" \( -name '*.gif' -o -name '*.png' -o -name '*.json' \) -type f -exec cp {} artifacts/ \; 2>/dev/null || true
- ls -la artifacts/ 2>/dev/null || echo "No visual artifacts found"
-
- - name: Upload GIF artifacts
- if: always() && matrix.visual
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- with:
- name: ${{ matrix.artifact_name }}
- path: artifacts/*
- if-no-files-found: warn
-
- - name: Sign and upload to Nix cache
- if: always()
- run: |
- echo "Signing and uploading build artifacts to Nix cache..."
- nix store sign --key-file "${{ runner.temp }}/signing-key.sec" --all
- nix copy --to "s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}&want-mass-query=true" --all -L
-
- - name: Cleanup signing key
- if: always()
- run: rm -f "${{ runner.temp }}/signing-key.sec"
-
- comment-linux-visual-artifacts:
- name: Comment Linux visual artifacts
- if: always() && github.event_name == 'pull_request'
- needs: [nix-checks]
- runs-on: ubuntu-latest
- steps:
- - name: Comment Linux visual artifacts on PR
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
- with:
- script: |
- const marker = '<!-- cua-driver-linux-visual-gifs -->';
- const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
- const artifactNames = [
- 'cua-driver-linux-cursor-click-gif',
- 'cua-driver-linux-background-terminal-gif',
- 'cua-driver-linux-parallel-drag-xserver',
- 'cua-driver-linux-background-gui-chromium',
- 'cua-driver-linux-background-gui-tk',
- 'cua-driver-linux-background-gui-gtk3-gedit',
- 'cua-driver-linux-background-gui-gtk3-mousepad',
- 'cua-driver-linux-background-gui-gtk3-scite',
- 'cua-driver-linux-background-gui-gtk4-characters',
- 'cua-driver-linux-background-gui-qt5-manuskript',
- 'cua-driver-linux-background-gui-qt5-klog',
- 'cua-driver-linux-background-gui-qt5-openambit',
- 'cua-driver-linux-background-gui-qt6-kate',
- 'cua-driver-linux-background-gui-qt6-kcalc',
- 'cua-driver-linux-background-gui-qt6-okular',
- 'cua-driver-linux-background-gui-qt6-qownnotes',
- 'cua-driver-linux-background-gui-electron-zettlr',
- 'cua-driver-linux-background-gui-electron-joplin',
- 'cua-driver-linux-background-gui-electron-logseq',
- 'cua-driver-linux-som-overlays',
- ];
-
- let body = `${marker}\n## Linux visual regression artifacts\n\n`;
- body += 'Matrix jobs now run independently. Download visual artifacts from this workflow run.\n';
- body += 'Each background-GUI job uploads a `.gif` of the interaction plus two annotated PNGs ';
- body += '(`<app>.png` raw, `<app>-atspi.png` with AT-SPI element boxes); ';
- body += 'the `cua-driver-linux-som-overlays` artifact adds `<app>-som.png` cua Set-of-Marks overlays:\n';
- for (const artifactName of artifactNames) {
- body += `- \`${artifactName}\`\n`;
- }
- body += `\n[Open workflow run and download artifacts](${runUrl})\n`;
-
- const comments = await github.paginate(github.rest.issues.listComments, {
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number,
- per_page: 100,
- });
- const existing = comments.find(comment =>
- comment.user?.type === 'Bot' && comment.body?.includes(marker)
- );
-
- if (existing) {
- await github.rest.issues.updateComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- comment_id: existing.id,
- body,
- });
- } else {
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number,
- body,
- });
- }
-
- # ── Set-of-Marks overlays ───────────────────────────────────────────────────
- # Downstream aggregate job: consumes the raw `<app>.png` screenshots uploaded
- # by the background-GUI matrix and emits `<app>-som.png` cua Set-of-Marks
- # overlays. Deliberately OFF the hot path — `needs: [nix-checks]` + `if:
- # always()` so it runs after the matrix regardless of pass/fail and never
- # blocks it. NOTE: `pip install -e libs/python/som` pulls torch + ultralytics +
- # easyocr (~GBs) and downloads model weights at first parse, so this job is
- # the slow/expensive one; it is intentionally isolated from the build matrix.
- som-annotate:
- name: Annotate screenshots with cua Set-of-Marks
- if: always()
- needs: [nix-checks]
- runs-on: ubuntu-latest
- steps:
- - name: Checkout
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
-
- - name: Download all run artifacts
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
- with:
- path: downloaded-artifacts
-
- - name: Set up Python
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
- with:
- python-version: "3.12"
-
- - name: Install cua-som
- run: |
- python -m pip install --upgrade pip
- pip install -e libs/python/som
-
- - name: Generate Set-of-Marks overlays
- run: |
- mkdir -p som-overlays
- python - <<'PY'
- import base64, glob, os, sys, traceback
-
- # Collect raw background-GUI screenshots: <app>.png produced by the
- # skeleton matrix. Exclude the AT-SPI overlays (-atspi) and any prior
- # SoM outputs (-som). Artifacts land under downloaded-artifacts/<name>/.
- candidates = []
- for p in glob.glob("downloaded-artifacts/**/*-background-gui-*.png", recursive=True):
- stem = os.path.basename(p)
- if stem.endswith("-atspi.png") or stem.endswith("-som.png"):
- continue
- candidates.append(p)
- candidates = sorted(set(candidates))
- print(f"Found {len(candidates)} raw screenshot(s) to annotate:", flush=True)
- for p in candidates:
- print(f" {p}", flush=True)
-
- if not candidates:
- print("No raw screenshots found; nothing to annotate.", flush=True)
- sys.exit(0)
-
- from som import OmniParser
- parser = OmniParser()
-
- ok = 0
- for p in candidates:
- try:
- with open(p, "rb") as f:
- data = f.read()
- result = parser.parse(data)
- b64 = result.annotated_image_base64
- # Strip a possible data URL prefix before decoding.
- if "," in b64 and b64.strip().startswith("data:"):
- b64 = b64.split(",", 1)[1]
- out_name = os.path.splitext(os.path.basename(p))[0] + "-som.png"
- out_path = os.path.join("som-overlays", out_name)
- with open(out_path, "wb") as f:
- f.write(base64.b64decode(b64))
- print(f"OK {p} -> {out_path}", flush=True)
- ok += 1
- except Exception:
- print(f"FAIL {p}", flush=True)
- traceback.print_exc()
- print(f"Annotated {ok}/{len(candidates)} screenshot(s).", flush=True)
- PY
- ls -la som-overlays/ 2>/dev/null || echo "No SoM overlays produced"
-
- - name: Upload Set-of-Marks overlays
- if: always()
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- with:
- name: cua-driver-linux-som-overlays
- path: som-overlays/*-som.png
- if-no-files-found: warn
diff --git a/.github/workflows/nix-screenshot.yml b/.github/workflows/nix-screenshot.yml
deleted file mode 100644
index 7d9f8b9a59..0000000000
--- a/.github/workflows/nix-screenshot.yml
+++ /dev/null
@@ -1,149 +0,0 @@
-name: CUA Driver Screenshot Test
-
-on:
- pull_request:
- types: [labeled]
-
-permissions:
- id-token: write
- contents: read
- pull-requests: write
-
-env:
- AWS_REGION: us-west-2
- NIX_CACHE_BUCKET: trycua-nix-cache
- NIX_CACHE_SECRET: nix-cache/trycua-nix-cache/signing-key
-
-jobs:
- screenshot-test:
- name: Run cua-driver screenshot test
- if: github.event.label.name == 'cua-driver-screenshot'
- runs-on: ubuntu-latest
- timeout-minutes: 15
-
- steps:
- - name: Checkout
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
-
- - name: Configure AWS Credentials via OIDC
- uses: aws-actions/configure-aws-credentials@ff717079ee2060e4bcee96c4779b553acc87447c # v4
- with:
- role-to-assume: arn:aws:iam::296062593712:role/github-actions-nix-cache
- aws-region: ${{ env.AWS_REGION }}
-
- - name: Get Nix signing key
- id: nix-key
- run: |
- SECRET=$(aws secretsmanager get-secret-value \
- --secret-id "${{ env.NIX_CACHE_SECRET }}" \
- --query 'SecretString' --output text)
-
- SECRET_KEY=$(echo "$SECRET" | jq -r '.secret_key')
- echo "::add-mask::$SECRET_KEY"
- echo "$SECRET_KEY" > "${{ runner.temp }}/signing-key.sec"
- chmod 600 "${{ runner.temp }}/signing-key.sec"
-
- PUBLIC_KEY=$(echo "$SECRET" | jq -r '.public_key')
- echo "public_key=$PUBLIC_KEY" >> "$GITHUB_OUTPUT"
-
- - name: Setup AWS credentials file for Nix
- run: |
- mkdir -p ~/.aws
- printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_SESSION_TOKEN" "$AWS_REGION" > ~/.aws/credentials
- chmod 600 ~/.aws/credentials
-
- sudo mkdir -p /root/.aws
- sudo bash -c "printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- '$AWS_ACCESS_KEY_ID' '$AWS_SECRET_ACCESS_KEY' '$AWS_SESSION_TOKEN' '$AWS_REGION' > /root/.aws/credentials"
- sudo chmod 600 /root/.aws/credentials
-
- - name: Install Nix
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- # Container-based NixOS integration tests (testers.nixosTest with
- # `containers`) run under systemd-nspawn instead of QEMU: no KVM
- # needed, much faster/cheaper. The nspawn builds require an allocated
- # UID range and cgroup delegation, advertised here on the builder.
- extra-experimental-features = auto-allocate-uids cgroups
- auto-allocate-uids = true
- extra-system-features = uid-range
- substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }} https://cache.nixos.org
- trusted-substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}
- trusted-public-keys = ${{ steps.nix-key.outputs.public_key }} cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
-
- - name: Run screenshot test
- timeout-minutes: 12
- run: nix build .#checks.x86_64-linux.cua-driver-screenshot --print-build-logs --show-trace
-
- - name: Extract screenshot
- if: always()
- run: |
- if [ -L result ]; then
- find -L result/ -name '*.png' -type f -exec cp {} . \; 2>/dev/null || true
- fi
- ls -la *.png 2>/dev/null || echo "No screenshots found"
-
- - name: Upload screenshot artifact
- if: always()
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- with:
- name: cua-driver-screenshot
- path: "*.png"
- if-no-files-found: warn
-
- - name: Comment screenshot on PR
- if: always()
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
- with:
- script: |
- const fs = require('fs');
- const pngs = fs.readdirSync('.').filter(f => f.endsWith('.png'));
-
- let body = '## CUA Driver Screenshot Test\n\n';
-
- if (pngs.length > 0) {
- const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
- body += `Screenshot captured by cua-driver's \`get_window_state\` tool from inside a NixOS container.\n\n`;
- body += `📸 [Download screenshot artifact](${artifactUrl})\n\n`;
- body += '✅ Test passed\n';
- } else {
- body += '⚠️ No screenshots were captured. Check the [workflow run](' +
- `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` +
- ') for details.\n';
- }
-
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number,
- body: body,
- });
-
- - name: Remove label
- if: always()
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
- with:
- script: |
- try {
- await github.rest.issues.removeLabel({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: context.issue.number,
- name: 'cua-driver-screenshot',
- });
- } catch (e) {
- console.log('Label already removed or not found:', e.message);
- }
-
- - name: Sign and upload to Nix cache
- if: always()
- run: |
- nix store sign --key-file "${{ runner.temp }}/signing-key.sec" --all
- nix copy --to "s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}&want-mass-query=true" --all -L
-
- - name: Cleanup signing key
- if: always()
- run: rm -f "${{ runner.temp }}/signing-key.sec"
diff --git a/.github/workflows/nix-wayland.yml b/.github/workflows/nix-wayland.yml
deleted file mode 100644
index e651b513b3..0000000000
--- a/.github/workflows/nix-wayland.yml
+++ /dev/null
@@ -1,199 +0,0 @@
-name: CUA Driver Native-Wayland TDD Suite
-
-# Native-Wayland reproduction of the cua-driver NixOS tests across five desktop
-# sessions (XFCE on labwc/sway, plus KDE and GNOME). The cursor-click-gif and
-# background-terminal-gif tests use the EIS-backed cua-compositor injection path
-# for deterministic keyboard delivery without relying on compositor focus policy.
-# These jobs are maintainer-dispatched desktop diagnostics. They are BLOCKING
-# within a dispatched run, but do not charge every PR with the full compositor
-# matrix.
-# Artifacts (screenshots, GIFs, logs) are uploaded so you can see exactly what
-# each compositor does.
-on:
- # Native-compositor checks are maintainer-dispatched because they are
- # desktop e2e coverage, not cheap pull-request unit checks.
- workflow_dispatch:
-
-permissions:
- id-token: write
- contents: read
-env:
- AWS_REGION: us-west-2
- NIX_CACHE_BUCKET: trycua-nix-cache
- NIX_CACHE_SECRET: nix-cache/trycua-nix-cache/signing-key
-
-jobs:
- wayland-scenarios:
- name: ${{ matrix.desktop }} / ${{ matrix.scenario }}
- runs-on: ubuntu-latest
- timeout-minutes: 30
- strategy:
- fail-fast: false
- matrix:
- desktop: [xfce-labwc, xfce-sway, kde, gnome]
- scenario:
- - integration
- - screenshot
- - cursor-click-gif
- - background-terminal-gif
- - parallel-drag
- steps:
- - name: Checkout
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
-
- - name: Configure AWS Credentials via OIDC
- uses: aws-actions/configure-aws-credentials@ff717079ee2060e4bcee96c4779b553acc87447c # v4
- with:
- role-to-assume: arn:aws:iam::296062593712:role/github-actions-nix-cache
- aws-region: ${{ env.AWS_REGION }}
-
- - name: Get Nix signing key
- id: nix-key
- run: |
- SECRET=$(aws secretsmanager get-secret-value \
- --secret-id "${{ env.NIX_CACHE_SECRET }}" \
- --query 'SecretString' --output text)
- SECRET_KEY=$(echo "$SECRET" | jq -r '.secret_key')
- echo "::add-mask::$SECRET_KEY"
- echo "$SECRET_KEY" > "${{ runner.temp }}/signing-key.sec"
- chmod 600 "${{ runner.temp }}/signing-key.sec"
- PUBLIC_KEY=$(echo "$SECRET" | jq -r '.public_key')
- echo "public_key=$PUBLIC_KEY" >> "$GITHUB_OUTPUT"
-
- - name: Setup AWS credentials file for Nix
- run: |
- mkdir -p ~/.aws
- printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_SESSION_TOKEN" "$AWS_REGION" > ~/.aws/credentials
- chmod 600 ~/.aws/credentials
- sudo mkdir -p /root/.aws
- sudo bash -c "printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- '$AWS_ACCESS_KEY_ID' '$AWS_SECRET_ACCESS_KEY' '$AWS_SESSION_TOKEN' '$AWS_REGION' > /root/.aws/credentials"
- sudo chmod 600 /root/.aws/credentials
-
- - name: Install Nix
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }} https://cache.nixos.org
- trusted-substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}
- trusted-public-keys = ${{ steps.nix-key.outputs.public_key }} cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
-
- - name: Run cua-driver-wayland-${{ matrix.desktop }}-${{ matrix.scenario }}
- run: |
- nix build ".#checks.x86_64-linux.cua-driver-wayland-${{ matrix.desktop }}-${{ matrix.scenario }}" \
- --print-build-logs --show-trace \
- -o "result-${{ matrix.desktop }}-${{ matrix.scenario }}"
-
- - name: Collect artifacts
- if: always()
- run: |
- mkdir -p artifacts
- find -L "result-${{ matrix.desktop }}-${{ matrix.scenario }}/" \
- \( -name '*.gif' -o -name '*.png' -o -name '*.json' \) -type f \
- -exec cp {} artifacts/ \; 2>/dev/null || true
- ls -la artifacts/ 2>/dev/null || echo "No artifacts found"
-
- - name: Upload artifacts
- if: always()
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- with:
- name: cua-driver-wayland-${{ matrix.desktop }}-${{ matrix.scenario }}
- path: artifacts/*
- if-no-files-found: warn
-
- - name: Sign and upload to Nix cache
- if: always()
- run: |
- nix store sign --key-file "${{ runner.temp }}/signing-key.sec" --all || true
- nix copy --to "s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}&want-mass-query=true" --all -L || true
-
- - name: Cleanup signing key
- if: always()
- run: rm -f "${{ runner.temp }}/signing-key.sec"
-
- wayland-background-gui:
- name: ${{ matrix.desktop }} / background-gui ${{ matrix.app }}
- runs-on: ubuntu-latest
- timeout-minutes: 30
- strategy:
- fail-fast: false
- matrix:
- desktop: [xfce-labwc, xfce-sway, kde, gnome]
- app: [foot, gtk3-gedit, qt6-kcalc]
- steps:
- - name: Checkout
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
-
- - name: Configure AWS Credentials via OIDC
- uses: aws-actions/configure-aws-credentials@ff717079ee2060e4bcee96c4779b553acc87447c # v4
- with:
- role-to-assume: arn:aws:iam::296062593712:role/github-actions-nix-cache
- aws-region: ${{ env.AWS_REGION }}
-
- - name: Get Nix signing key
- id: nix-key
- run: |
- SECRET=$(aws secretsmanager get-secret-value \
- --secret-id "${{ env.NIX_CACHE_SECRET }}" \
- --query 'SecretString' --output text)
- SECRET_KEY=$(echo "$SECRET" | jq -r '.secret_key')
- echo "::add-mask::$SECRET_KEY"
- echo "$SECRET_KEY" > "${{ runner.temp }}/signing-key.sec"
- chmod 600 "${{ runner.temp }}/signing-key.sec"
- PUBLIC_KEY=$(echo "$SECRET" | jq -r '.public_key')
- echo "public_key=$PUBLIC_KEY" >> "$GITHUB_OUTPUT"
-
- - name: Setup AWS credentials file for Nix
- run: |
- mkdir -p ~/.aws
- printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_SESSION_TOKEN" "$AWS_REGION" > ~/.aws/credentials
- chmod 600 ~/.aws/credentials
- sudo mkdir -p /root/.aws
- sudo bash -c "printf '[default]\naws_access_key_id = %s\naws_secret_access_key = %s\naws_session_token = %s\nregion = %s\n' \
- '$AWS_ACCESS_KEY_ID' '$AWS_SECRET_ACCESS_KEY' '$AWS_SESSION_TOKEN' '$AWS_REGION' > /root/.aws/credentials"
- sudo chmod 600 /root/.aws/credentials
-
- - name: Install Nix
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }} https://cache.nixos.org
- trusted-substituters = s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}
- trusted-public-keys = ${{ steps.nix-key.outputs.public_key }} cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
-
- - name: Run cua-driver-wayland-${{ matrix.desktop }}-background-gui-${{ matrix.app }}
- run: |
- nix build ".#checks.x86_64-linux.cua-driver-wayland-${{ matrix.desktop }}-background-gui-${{ matrix.app }}" \
- --print-build-logs --show-trace \
- -o "result-${{ matrix.desktop }}-bg-gui-${{ matrix.app }}"
-
- - name: Collect artifacts
- if: always()
- run: |
- mkdir -p artifacts
- find -L "result-${{ matrix.desktop }}-bg-gui-${{ matrix.app }}/" \
- \( -name '*.gif' -o -name '*.png' -o -name '*.json' \) -type f \
- -exec cp {} artifacts/ \; 2>/dev/null || true
- ls -la artifacts/ 2>/dev/null || echo "No artifacts found"
-
- - name: Upload artifacts
- if: always()
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
- with:
- name: cua-driver-wayland-${{ matrix.desktop }}-background-gui-${{ matrix.app }}
- path: artifacts/*
- if-no-files-found: warn
-
- - name: Sign and upload to Nix cache
- if: always()
- run: |
- nix store sign --key-file "${{ runner.temp }}/signing-key.sec" --all || true
- nix copy --to "s3://${{ env.NIX_CACHE_BUCKET }}?region=${{ env.AWS_REGION }}&want-mass-query=true" --all -L || true
-
- - name: Cleanup signing key
- if: always()
- run: rm -f "${{ runner.temp }}/signing-key.sec"
diff --git a/flake.nix b/flake.nix
index d18f04e733..7fe61048bc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -21,17 +21,7 @@
(
system:
let
- pkgs = import nixpkgs {
- inherit system;
- # Several Electron-based apps in the background-GUI test matrix
- # (logseq, joplin, zettlr) pin Electron releases that nixos-26.05
- # flags as EOL/insecure. These are read-only smoke tests running in
- # throwaway CI containers, so permit insecure Electron specifically
- # (version-agnostic, so a nixpkgs bump to a newer EOL Electron keeps
- # working without editing an exact version string here).
- config.allowInsecurePredicate =
- pkg: nixpkgs.lib.hasPrefix "electron" (nixpkgs.lib.getName pkg);
- };
+ pkgs = import nixpkgs { inherit system; };
rustSrc = ./libs/cua-driver/rust;
@@ -39,223 +29,109 @@
inherit pkgs;
src = rustSrc;
};
+
+ cuaCompositorPackage = pkgs.callPackage ./nix/cua-driver/compositor { };
+
+ # nixpkgs builds the AT-SPI launcher for NixOS's system profile.
+ # The E2E shell also runs on non-NixOS hosts such as GitHub's Ubuntu
+ # image, so point its private accessibility bus at store binaries.
+ hostAtSpi = pkgs.at-spi2-core.overrideAttrs (old: {
+ mesonFlags = map (
+ flag:
+ if pkgs.lib.hasPrefix "-Ddbus_daemon=" flag then
+ "-Ddbus_daemon=${pkgs.dbus}/bin/dbus-daemon"
+ else if pkgs.lib.hasPrefix "-Ddbus_broker=" flag then
+ "-Ddbus_broker=${pkgs.dbus-broker}/bin/dbus-broker-launch"
+ else
+ flag
+ ) old.mesonFlags;
+ });
+
+ waylandE2eLibraries = with pkgs; [
+ alsa-lib
+ cairo
+ cups
+ dbus
+ expat
+ glib
+ gtk3
+ libayatana-appindicator
+ libdrm
+ libei
+ libgbm
+ librsvg
+ libsoup_3
+ libx11
+ libxcb
+ libxcomposite
+ libxdamage
+ libxext
+ libxfixes
+ libxi
+ libxkbcommon
+ libxrandr
+ libxtst
+ mesa
+ nspr
+ nss
+ openssl
+ pango
+ pipewire
+ webkitgtk_4_1
+ ];
+
+ waylandE2eShell = extraPackages: pkgs.mkShell {
+ # hostAtSpi is referenced by absolute launcher path below, but is
+ # deliberately not a shell package: adding its rebuilt library and
+ # typelib hooks alongside GTK's stock AT-SPI closure loads two ATK
+ # copies and crashes PyGObject during Gtk import.
+ packages = (with pkgs; [
+ cargo
+ clang
+ dbus
+ ffmpeg
+ gobject-introspection
+ grim
+ jq
+ nodejs
+ pkg-config
+ procps
+ rustc
+ rustfmt
+ sway
+ unzip
+ wf-recorder
+ wtype
+ # Keep the GTK3 fixture on the mature Python/PyGObject combination.
+ (python312.withPackages (pythonPackages: [ pythonPackages.pygobject3 ]))
+ ]) ++ extraPackages;
+ buildInputs = waylandE2eLibraries;
+ LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath waylandE2eLibraries;
+ shellHook = ''
+ export NO_AT_BRIDGE=0
+ export CUA_AT_SPI_BUS_LAUNCHER="${hostAtSpi}/libexec/at-spi-bus-launcher"
+ export XDG_DATA_DIRS="${hostAtSpi}/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
+ '';
+ };
in
{
packages = {
+ cua-compositor = cuaCompositorPackage;
cua-driver = cuaDriverPackage;
default = cuaDriverPackage;
};
- checks =
- {
- cua-driver-build = cuaDriverPackage;
- # Source-built, headless Rust checks. The desktop behavioral
- # matrix remains an explicit maintainer-dispatched e2e lane.
- cua-driver-linux-rust-unit = import ./nix/cua-driver/tests/rust-unit.nix {
- inherit pkgs;
- src = rustSrc;
- };
- }
- // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
- # NixOS container integration test (x86_64-linux only)
- cua-driver-integration = import ./nix/cua-driver/tests/integration.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
-
- # set_config persistence test — regression for #1923 (fixed in
- # #1928): the {key, value} write shape must persist and read back
- # via get_config (it was silently dropped on Linux before).
- cua-driver-set-config = import ./nix/cua-driver/tests/set-config.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
-
- # Screenshot test — uses cua-driver's own get_window_state tool
- # to capture a screenshot via MCP, proving the driver can see the display
- cua-driver-screenshot = import ./nix/cua-driver/tests/screenshot.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
-
- cua-driver-linux-cursor-click-gif = import ./nix/cua-driver/tests/linux-cursor-click-gif.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
-
- cua-driver-linux-background-terminal-gif = import ./nix/cua-driver/tests/linux-background-terminal-gif.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
-
- # Multi-cursor (MPX) parallel-drag test on a REAL Xorg brought up
- # by NixOS services.xserver (dummy video + libinput, on a seat via
- # a display manager). This is the CI-viable replacement for the
- # hand-launched-Xorg linux-parallel-drag-gif.nix (which timed out
- # because a self-launched Xorg couldn't get a VT/seat in the
- # emulated nixos-test VM). Proves uinput slaves enumerate as X
- # devices, two cursors draw concurrent window-targeted events, and
- # the shield grab keeps focus off the drag.
- cua-driver-linux-parallel-drag-xserver = import ./nix/cua-driver/tests/linux-parallel-drag-xserver.nix {
- inherit pkgs;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- };
+ checks = {
+ cua-compositor-build = cuaCompositorPackage;
+ cua-driver-build = cuaDriverPackage;
+ cua-driver-linux-rust-unit = import ./nix/cua-driver/tests/rust-unit.nix {
+ inherit pkgs;
+ src = rustSrc;
+ };
+ };
- # NOTE: cua-driver-linux-parallel-drag-gif (nix/cua-driver/tests/
- # linux-parallel-drag-gif.nix) is intentionally NOT a flake check —
- # it hand-launches Xorg, which can't get a VT/seat in the emulated
- # GHA nixos-test VM. It is superseded by the services.xserver test
- # above and kept only for local/real-X manual runs.
- }
- // pkgs.lib.optionalAttrs (system == "x86_64-linux") (
- # Background GUI input coverage — one independent matrix job per
- # app, proving focus-free typing into real toolkit/browser windows.
- pkgs.lib.listToAttrs (
- map (
- app:
- pkgs.lib.nameValuePair "cua-driver-linux-background-gui-${app}" (
- import ./nix/cua-driver/tests/linux-background-gui.nix {
- inherit pkgs app;
- inherit (pkgs) lib;
- cuaDriverModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- }
- )
- # Real-app matrix: 5 apps per toolkit category run as a LENIENT,
- # READ-ONLY skeleton (find window + driver page/get_text + GIF;
- # focus-free WRITE / typed-text assertions are added later via
- # trajectories). chromium keeps the full CDP focus-free-write
- # override; tk is the negative-control full entry (Tk `send`).
- # "firefox" remains disabled: historically it did not surface its
- # window within the launch timeout in CI. Container tests run at
- # native speed, so this may now pass — left disabled pending
- # verification.
- ) [
- "chromium"
- "tk"
- # GTK3
- "gtk3-gedit"
- "gtk3-mousepad"
- # gtk3-geany / gtk3-abiword temporarily disabled: their huge
- # AT-SPI trees made the bounds walk + recorder grind in the
- # previous emulated VM and the jobs timed out. Container tests run
- # at native speed, so this may now pass — re-enable once verified
- # fast enough for 700+-node trees.
- # "gtk3-geany"
- "gtk3-scite"
- # "gtk3-abiword"
- # GTK4
- "gtk4-characters"
- # Qt5
- "qt5-manuskript"
- "qt5-klog"
- "qt5-openambit"
- # Qt6
- "qt6-kate"
- "qt6-kcalc"
- "qt6-okular"
- "qt6-qownnotes"
- # Electron
- "electron-zettlr"
- "electron-joplin"
- "electron-logseq"
- ]
- )
- )
- # Native-Wayland TDD matrix — reproduce the cua-driver scenarios on
- # real, NATIVE Wayland sessions (XFCE on labwc/wayfire/sway, plus KDE
- # and GNOME). Apps run as Wayland clients and the tests never set
- # DISPLAY, so the X11-only driver cannot see them: this is a RED suite
- # specifying native Wayland support. One check per (desktop × scenario)
- # and per (desktop × background-GUI app). See
- # nix/cua-driver/tests/wayland/README.md.
- // pkgs.lib.optionalAttrs (system == "x86_64-linux") (
- let
- # NOTE: xfce-wayfire dropped — the wayfire package fails to
- # build in the current nixpkgs pin (wf-config can't link
- # -ldoctest), an upstream packaging bug unrelated to cua-driver.
- # labwc + sway still cover XFCE-on-wlroots.
- waylandDesktops = [
- "xfce-labwc"
- "xfce-sway"
- "kde"
- "gnome"
- ];
- waylandScenarios = {
- integration = ./nix/cua-driver/tests/wayland/integration.nix;
- screenshot = ./nix/cua-driver/tests/wayland/screenshot.nix;
- cursor-click-gif = ./nix/cua-driver/tests/wayland/cursor-click-gif.nix;
- background-terminal-gif = ./nix/cua-driver/tests/wayland/background-terminal-gif.nix;
- parallel-drag = ./nix/cua-driver/tests/wayland/parallel-drag.nix;
- };
- waylandBgApps = [
- "foot"
- "gtk3-gedit"
- "qt6-kcalc"
- ];
- waylandModule = {
- imports = [ ./nix/cua-driver/module.nix ];
- services.cua-driver.package = cuaDriverPackage;
- };
- scenarioChecks = pkgs.lib.listToAttrs (
- pkgs.lib.concatMap (
- desktop:
- map (
- scenario:
- pkgs.lib.nameValuePair "cua-driver-wayland-${desktop}-${scenario}" (
- import waylandScenarios.${scenario} {
- inherit pkgs desktop;
- inherit (pkgs) lib;
- cuaDriverModule = waylandModule;
- }
- )
- ) (builtins.attrNames waylandScenarios)
- ) waylandDesktops
- );
- bgGuiChecks = pkgs.lib.listToAttrs (
- pkgs.lib.concatMap (
- desktop:
- map (
- app:
- pkgs.lib.nameValuePair "cua-driver-wayland-${desktop}-background-gui-${app}" (
- import ./nix/cua-driver/tests/wayland/background-gui.nix {
- inherit pkgs desktop app;
- inherit (pkgs) lib;
- cuaDriverModule = waylandModule;
- }
- )
- ) waylandBgApps
- ) waylandDesktops
- );
- in
- scenarioChecks // bgGuiChecks
- );
+ devShells.cua-driver-wayland-e2e = waylandE2eShell [ ];
+ devShells.cua-driver-inject-e2e = waylandE2eShell [ cuaCompositorPackage ];
}
)
// {
diff --git a/nix/cua-driver/README.md b/nix/cua-driver/README.md
index 649a5a7490..7de0b2f6d6 100644
--- a/nix/cua-driver/README.md
+++ b/nix/cua-driver/README.md
@@ -1,37 +1,29 @@
# Linux driver checks
-Nix is the Linux test environment. It is used for reproducible builds and for
-containerized or compositor-backed Linux checks; Windows and macOS checks do
-not belong here.
-
-## Check tiers
-
-| Tier | Check family | Trigger | Evidence |
-| --- | --- | --- | --- |
-| Source | `cua-driver-linux-rust-unit` | Linux Rust/Nix changes | Cargo unit tests and compilation |
-| Contract | `cua-driver-integration`, `cua-driver-set-config`, `cua-driver-screenshot` | Maintainer or Linux CI | service, config, and capture assertions |
-| Behavioral | `e2e-rust-linux` and the shared Rust matrix | Manual maintainer dispatch | external app state, AX trees, logs, failure screenshots |
-| Supporting | legacy background GUI and compatibility checks | Explicitly selected | toolkit-specific diagnostics |
-
-The behavioral matrix is owned by
-`libs/cua-driver/rust/crates/cua-driver/tests/cross_platform_behavior_test.rs`.
-Nix checks must not create a second scenario list in Nix expressions.
-
-The current automatic Nix lane builds the driver and Rust workspace from source.
-The manual Linux desktop runner builds Electron/Tauri from the repo-local
-fixture sources in the desktop session. Moving those app builds fully inside
-Nix requires committing and hashing their dependency lockfiles, especially the
-Electron npm graph, and is intentionally a follow-up rather than an opaque
-prebuilt download.
-
-## Naming and artifacts
-
-Use `cua-driver-linux-<surface>-<scenario>` for new checks. Do not add `gif`
-to new check names. A failing behavioral check should retain structured output,
-the driver log, an AX/UIA tree where available, and a PNG when the scenario is
-pixel-based. GIF recorders remain legacy supporting diagnostics until their
-behavior is covered by the Rust matrix.
-
-The old `linux-background-gui.nix` and compositor matrix are not deleted in one
-step. They contain useful toolkit and regression evidence, but read-only
-skeleton entries must not be reported as equivalent to a passing user workflow.
+Nix has two responsibilities in the cua-driver test stack: reproducible Linux
+builds and desktop-session dependencies for the canonical Rust harnesses.
+
+| Attribute | Purpose | CI |
+| --- | --- | --- |
+| `cua-driver-build` | Build the shipped Linux package from the locked Rust source | `ci-nix-linux.yml` |
+| `cua-driver-linux-rust-unit` | Compile and run the source-owned headless Rust tests | `ci-nix-linux.yml` |
+| `cua-driver-wayland-e2e` | Provide the Sway, GTK, WebKit, Electron, capture, and Rust toolchain used by native Wayland E2E | `e2e-rust-linux-wayland.yml` |
+| `cua-driver-inject-e2e` | Provide the same typed harness toolchain plus the nested `cua-compositor` package | Experimental nested-injection workflow |
+| `cua-compositor-build` | Build the optional compositor-owned injection backend against pinned wlroots | Flake check |
+
+The Rust tests own all protocol and desktop behavior. The old NixOS Python
+clients, GIF scenarios, real-app smoke rows, and compositor matrix were removed
+because they maintained a second scenario catalog with different assertions.
+The canonical Rust matrix is the coverage source of truth; retired rows are not
+treated as equivalent unless a current typed case proves the same contract.
+
+Run the native Wayland matrix from the repository root:
+
+```bash
+nix develop .#cua-driver-wayland-e2e -c \
+ scripts/ci/linux/run-rust-e2e-wayland.sh
+```
+
+The wrapper starts a pure Wayland Sway session with Xwayland disabled, then
+calls the same canonical Rust runner used by X11. Results use the common typed
+JSONL schema and retain MP4 trajectories under `artifacts/cua-driver/linux/`.
diff --git a/nix/cua-driver/compositor/cua_compositor_patch.py b/nix/cua-driver/compositor/cua_compositor_patch.py
index e6abdaabd5..7283f44c46 100644
--- a/nix/cua-driver/compositor/cua_compositor_patch.py
+++ b/nix/cua-driver/compositor/cua_compositor_patch.py
@@ -7,17 +7,19 @@
# * focus-FREE per-surface KEYBOARD injection (type into an unfocused window),
# * MULTI-cursor pointer injection (N independent cursors on one window),
#
-# both routed to a target window by its xdg app_id, driven over a tiny line
+# both routed by stable process identity (with app_id fallback), driven over a tiny line
# protocol on a unix control socket ($CUA_INJECT_SOCKET). It also exposes
# foreign-toplevel-management (so cua-driver's list_windows enumerates windows)
# and screencopy (so grim captures the output) — the same protocols labwc gives
-# the non-nested cells — so the EIS cells keep working end to end.
+# the non-nested cells — so the nested-injection cells keep working end to end.
#
# The injection primitives (cua_motion/cua_button/cua_kbd_*) deliver wl_pointer/
# wl_keyboard straight to a target client's resources, bypassing seat focus —
-# routed by app_id (not positional device index) and transported over a plain
-# socket instead of libei/EIS, since cua owns both ends and the portal/libei
-# layer buys nothing here.
+# routed by process identity rather than a connection-local object id and transported over a plain
+# socket rather than libei/EIS, since cua owns both ends and the portal/libei
+# layer buys nothing here. The socket speaks a versioned v1 line protocol: the
+# client sends the `cua-inject v1` banner (echoed back on match), then every
+# command line is answered by exactly one `ok` / `err <reason>` acknowledgement.
#
# Usage: cua_compositor_patch.py <tinywl.c in> <cua-compositor.c out>
import sys, io
@@ -33,6 +35,7 @@ INCLUDES = r"""#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
@@ -54,9 +57,13 @@ static struct cua_devstate cua_kbd_state[CUA_MAXDEV];
static int g_keymap_fd = -1;
static size_t g_keymap_size = 0;
static xkb_mod_mask_t g_shift_mask = 1;
+static xkb_mod_mask_t g_ctrl_mask = 0;
+static xkb_mod_mask_t g_alt_mask = 0;
+static xkb_mod_mask_t g_logo_mask = 0;
struct cua_keyent { uint32_t keycode; int shift; int valid; };
static struct cua_keyent g_chartab[128];
static struct wlr_foreign_toplevel_manager_v1 *g_ftl_mgr = NULL;
+static void cua_ftl_request_activate(struct wl_listener *listener, void *data);
"""
@@ -64,26 +71,137 @@ static struct wlr_foreign_toplevel_manager_v1 *g_ftl_mgr = NULL;
STRUCT_FIELD = (
"\tstruct wlr_xdg_toplevel *xdg_toplevel;\n"
"\tstruct wlr_foreign_toplevel_handle_v1 *ftl;\n"
+ "\tstruct wl_listener ftl_request_activate;\n"
)
FUNCS = r"""
+/* v1 control-protocol banner: the client sends this line, the compositor echoes
+ * it to confirm both speak v1. Any other first line is refused. */
+#define CUA_PROTO_HELLO "cua-inject v1"
+static void cua_ftl_request_activate(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct tinywl_toplevel *t = wl_container_of(listener, t, ftl_request_activate);
+ focus_toplevel(t);
+}
static uint32_t cua_now_ms(void) {
struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}
+/* Write a single acknowledgement line back to the control client. Best-effort:
+ * a dead peer is torn down by the read side on the next loop iteration. */
+static void cua_reply(int fd, const char *line) {
+ char buf[256];
+ int n = snprintf(buf, sizeof buf, "%s\n", line);
+ if (n < 0) return;
+ if (n >= (int)sizeof buf) n = (int)sizeof buf - 1;
+ ssize_t off = 0;
+ while (off < n) {
+ ssize_t w = write(fd, buf + off, (size_t)n - (size_t)off);
+ if (w <= 0) break;
+ off += w;
+ }
+}
static void cua_pframe(struct wl_resource *res) {
if (wl_resource_get_version(res) >= WL_POINTER_FRAME_SINCE_VERSION)
wl_pointer_send_frame(res);
}
-/* Resolve a target window by its xdg app_id. */
-static struct tinywl_toplevel *cua_find_appid(struct tinywl_server *server, const char *app_id) {
- struct tinywl_toplevel *t;
+static pid_t cua_toplevel_pid(struct tinywl_toplevel *t);
+/* Resolve a target window by its xdg app_id, refusing missing and ambiguous
+ * matches so a command never silently drives the wrong window. In v1 duplicate
+ * app_ids are simply not addressable. On failure returns NULL and points *err
+ * at a stable reason token; on success *err is left untouched. */
+static struct tinywl_toplevel *cua_resolve_target(struct tinywl_server *server, const char *app_id, const char **err) {
+ struct tinywl_toplevel *t, *found = NULL;
+ int matches = 0;
+ if (!strncmp(app_id, "pid:", 4)) {
+ char *end = NULL;
+ long pid = strtol(app_id + 4, &end, 10);
+ if (pid <= 0 || !end || *end) { *err = "bad-pid"; return NULL; }
+ wl_list_for_each(t, &server->toplevels, link) {
+ if (cua_toplevel_pid(t) == (pid_t)pid) { found = t; matches++; }
+ }
+ if (matches == 0) { *err = "unknown-pid"; return NULL; }
+ if (matches > 1) { *err = "ambiguous-pid"; return NULL; }
+ return found;
+ }
wl_list_for_each(t, &server->toplevels, link) {
const char *a = t->xdg_toplevel ? t->xdg_toplevel->app_id : NULL;
- if (a && strcmp(a, app_id) == 0) return t;
+ if (a && strcmp(a, app_id) == 0) { found = t; matches++; }
+ }
+ if (matches == 0) { *err = "unknown-app-id"; return NULL; }
+ if (matches > 1) { *err = "ambiguous-app-id"; return NULL; }
+ return found;
+}
+static pid_t cua_toplevel_pid(struct tinywl_toplevel *t) {
+ if (!t || !t->xdg_toplevel || !t->xdg_toplevel->base->surface) return 0;
+ struct wl_client *client = wl_resource_get_client(t->xdg_toplevel->base->surface->resource);
+ pid_t pid = 0; uid_t uid = 0; gid_t gid = 0;
+ wl_client_get_credentials(client, &pid, &uid, &gid);
+ return pid;
+}
+/* Focus exactly one mapped toplevel owned by `target_pid`. Refuse ambiguity:
+ * process-scoped activation is only safe when the process owns one window. */
+static const char *cua_activate_pid(struct tinywl_server *server, pid_t target_pid) {
+ struct tinywl_toplevel *t, *found = NULL;
+ int matches = 0;
+ wl_list_for_each(t, &server->toplevels, link) {
+ if (target_pid > 0 && cua_toplevel_pid(t) == target_pid) {
+ found = t;
+ matches++;
+ }
+ }
+ if (matches == 0) return "unknown-pid";
+ if (matches > 1) return "ambiguous-pid";
+ focus_toplevel(found);
+ /* tinywl only notifies seat keyboard focus when a physical wlr_keyboard is
+ * attached. Headless CI has none, so establish the logical focus explicitly
+ * for observer truth and client activation semantics. */
+ struct wlr_surface *surface = found->xdg_toplevel->base->surface;
+ if (server->seat->keyboard_state.focused_surface != surface) {
+ struct wlr_keyboard_modifiers modifiers = {0};
+ wlr_seat_keyboard_notify_enter(server->seat, surface, NULL, 0, &modifiers);
}
return NULL;
}
+/* Independent observer query used only by the Rust E2E testkit. The target is
+ * selected by the Wayland client's process credentials, not by driver-owned
+ * object ids. In this minimal compositor every mapped toplevel shares origin;
+ * a non-focused target beneath another focused surface is therefore occluded. */
+static void cua_query_state(struct tinywl_server *server, pid_t target_pid, char *out, size_t out_len) {
+ struct wlr_surface *focused = server->seat->keyboard_state.focused_surface;
+ struct wlr_surface *focused_root = focused ? wlr_surface_get_root_surface(focused) : NULL;
+ struct tinywl_toplevel *t, *target = NULL, *focused_toplevel = NULL;
+ wl_list_for_each(t, &server->toplevels, link) {
+ struct wlr_surface *surface = t->xdg_toplevel ? t->xdg_toplevel->base->surface : NULL;
+ if (surface == focused_root) focused_toplevel = t;
+ if (target_pid > 0 && cua_toplevel_pid(t) == target_pid) target = t;
+ }
+ pid_t focused_pid = cua_toplevel_pid(focused_toplevel);
+ const char *state = !target ? "not_found" :
+ (target == focused_toplevel ? "foreground" :
+ (focused_toplevel ? "background_occluded" : "background_visible"));
+ snprintf(out, out_len, "state %d %s", (int)focused_pid, state);
+}
+static const char *cua_query_geometry(struct tinywl_server *server, pid_t target_pid, char *out, size_t out_len) {
+ struct tinywl_toplevel *t, *target = NULL;
+ int matches = 0;
+ wl_list_for_each(t, &server->toplevels, link) {
+ if (cua_toplevel_pid(t) == target_pid) { target = t; matches++; }
+ }
+ if (!matches) return "target-not-found";
+ if (matches > 1) return "ambiguous-pid";
+ int x = 0, y = 0;
+ if (!wlr_scene_node_coords(&target->scene_tree->node, &x, &y)) return "unmapped-target";
+ /* AT-SPI Window coordinates for native GTK are rooted at the xdg window
+ * geometry, while scene coordinates and screencopy include the complete root
+ * surface (including client-side decorations). Rebase into that coordinate
+ * system so `origin + accessible_window_xy` lands on the captured pixel. */
+ int scene_x = x, scene_y = y;
+ struct wlr_box geo = target->xdg_toplevel->base->geometry;
+ x -= geo.x; y -= geo.y;
+ snprintf(out, out_len, "geometry %d %d %d %d", x, y, scene_x, scene_y);
+ return NULL;
+}
static void cua_ptr_leave(struct wlr_seat *seat, struct wlr_surface *surf) {
if (!surf) return;
struct wlr_seat_client *sc = wlr_seat_client_for_wl_client(seat, wl_resource_get_client(surf->resource));
@@ -97,13 +215,34 @@ static void cua_ptr_leave(struct wlr_seat *seat, struct wlr_surface *surf) {
* independent cursors against the same or different surfaces. Focus-free: we
* write straight to the client's wl_pointer resources, never touching the seat
* focus or any real cursor. */
-static void cua_motion(struct tinywl_server *server, struct tinywl_toplevel *t, int idx, double x, double y) {
- if (!t || idx < 0 || idx >= CUA_MAXDEV) return;
- struct wlr_surface *surface = t->xdg_toplevel->base->surface;
- struct wlr_box geo = t->xdg_toplevel->base->geometry;
- wl_fixed_t sx = wl_fixed_from_double(geo.x + x), sy = wl_fixed_from_double(geo.y + y);
+static bool cua_motion(struct tinywl_server *server, struct tinywl_toplevel *t, int idx, double x, double y) {
+ if (!t || idx < 0 || idx >= CUA_MAXDEV) return false;
+ /* Public PX coordinates come from the cropped root-surface screenshot. Hit
+ * test that point through the scene so Chromium/WebKit child surfaces receive
+ * enter/motion in their own local coordinates instead of the top-level root. */
+ int scene_x = 0, scene_y = 0;
+ if (!wlr_scene_node_coords(&t->scene_tree->node, &scene_x, &scene_y)) return false;
+ double local_x = 0, local_y = 0;
+ /* Search only the requested toplevel's scene subtree. A global hit test
+ * would select the foreground sentinel when this target is occluded. */
+ struct wlr_scene_node *node = wlr_scene_node_at(&t->scene_tree->node,
+ scene_x + x, scene_y + y, &local_x, &local_y);
+ if (!node || node->type != WLR_SCENE_NODE_BUFFER) return false;
+ struct wlr_scene_buffer *buffer = wlr_scene_buffer_from_node(node);
+ struct wlr_scene_surface *scene_surface = wlr_scene_surface_try_from_buffer(buffer);
+ if (!scene_surface) return false;
+ struct wlr_surface *surface = scene_surface->surface;
struct wlr_seat_client *sc = wlr_seat_client_for_wl_client(server->seat, wl_resource_get_client(surface->resource));
- if (!sc || wl_list_empty(&sc->pointers)) return;
+ if (!sc || wl_list_empty(&sc->pointers)) {
+ /* Chromium can compose a renderer-owned child surface whose wl_client
+ * never bound wl_pointer while the owning toplevel client did. Use that
+ * target root while retaining the caller's screenshot-local point. */
+ surface = t->xdg_toplevel->base->surface;
+ local_x = x; local_y = y;
+ sc = wlr_seat_client_for_wl_client(server->seat, wl_resource_get_client(surface->resource));
+ if (!sc || wl_list_empty(&sc->pointers)) return false;
+ }
+ wl_fixed_t sx = wl_fixed_from_double(local_x), sy = wl_fixed_from_double(local_y);
struct wl_resource *res;
if (cua_ptr[idx].entered != surface) {
if (cua_ptr[idx].entered) cua_ptr_leave(server->seat, cua_ptr[idx].entered);
@@ -113,18 +252,68 @@ static void cua_motion(struct tinywl_server *server, struct tinywl_toplevel *t,
}
uint32_t tm = cua_now_ms();
wl_resource_for_each(res, &sc->pointers) { wl_pointer_send_motion(res, tm, sx, sy); cua_pframe(res); }
+ return true;
}
-static void cua_button(struct tinywl_server *server, struct tinywl_toplevel *t, int idx, uint32_t button, bool pressed) {
- if (!t || idx < 0 || idx >= CUA_MAXDEV) return;
- struct wlr_surface *surface = t->xdg_toplevel->base->surface;
+/* Resolve an output-layout point through the compositor scene, preserving
+ * subsurface offsets and output scaling. This is the desktop-scope path. */
+static struct tinywl_toplevel *cua_desktop_motion(struct tinywl_server *server, double x, double y) {
+ double sx = 0, sy = 0;
+ struct wlr_surface *surface = NULL;
+ struct tinywl_toplevel *t = desktop_toplevel_at(server, x, y, &surface, &sx, &sy);
+ if (!t || !surface) return NULL;
struct wlr_seat_client *sc = wlr_seat_client_for_wl_client(server->seat, wl_resource_get_client(surface->resource));
- if (!sc || wl_list_empty(&sc->pointers)) return;
+ if (!sc || wl_list_empty(&sc->pointers)) return NULL;
+ struct wl_resource *res;
+ if (cua_ptr[0].entered != surface) {
+ if (cua_ptr[0].entered) cua_ptr_leave(server->seat, cua_ptr[0].entered);
+ uint32_t serial = wlr_seat_client_next_serial(sc);
+ wl_resource_for_each(res, &sc->pointers) {
+ wl_pointer_send_enter(res, serial, surface->resource, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
+ cua_pframe(res);
+ }
+ cua_ptr[0].entered = surface;
+ }
+ uint32_t tm = cua_now_ms();
+ wl_resource_for_each(res, &sc->pointers) {
+ wl_pointer_send_motion(res, tm, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
+ cua_pframe(res);
+ }
+ return t;
+}
+static bool cua_button(struct tinywl_server *server, struct tinywl_toplevel *t, int idx, uint32_t button, bool pressed) {
+ if (!t || idx < 0 || idx >= CUA_MAXDEV) return false;
+ /* `cua_motion` establishes the exact child or root surface for this logical
+ * pointer. Button and axis events must use that same wl_pointer resource. */
+ struct wlr_surface *surface = cua_ptr[idx].entered ? cua_ptr[idx].entered : t->xdg_toplevel->base->surface;
+ struct wlr_seat_client *sc = wlr_seat_client_for_wl_client(server->seat, wl_resource_get_client(surface->resource));
+ if (!sc || wl_list_empty(&sc->pointers)) return false;
uint32_t tm = cua_now_ms(), bs = wlr_seat_client_next_serial(sc);
struct wl_resource *res;
wl_resource_for_each(res, &sc->pointers) {
wl_pointer_send_button(res, bs, tm, button, pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED);
cua_pframe(res);
}
+ return true;
+}
+static bool cua_axis(struct tinywl_server *server, struct tinywl_toplevel *t, int idx, uint32_t axis, double value) {
+ if (!t || idx < 0 || idx >= CUA_MAXDEV) return false;
+ struct wlr_surface *surface = cua_ptr[idx].entered ? cua_ptr[idx].entered : t->xdg_toplevel->base->surface;
+ struct wlr_seat_client *sc = wlr_seat_client_for_wl_client(server->seat, wl_resource_get_client(surface->resource));
+ if (!sc || wl_list_empty(&sc->pointers)) return false;
+ uint32_t tm = cua_now_ms();
+ struct wl_resource *res;
+ wl_resource_for_each(res, &sc->pointers) {
+ int32_t step = value < 0 ? -1 : 1;
+ if (wl_resource_get_version(res) >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION)
+ wl_pointer_send_axis_source(res, WL_POINTER_AXIS_SOURCE_WHEEL);
+ if (wl_resource_get_version(res) >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION)
+ wl_pointer_send_axis_value120(res, axis, step * 120);
+ else if (wl_resource_get_version(res) >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION)
+ wl_pointer_send_axis_discrete(res, axis, step);
+ wl_pointer_send_axis(res, tm, axis, wl_fixed_from_double(value));
+ cua_pframe(res);
+ }
+ return true;
}
static void cua_init_keymap(void) {
struct xkb_context *ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
@@ -143,6 +332,12 @@ static void cua_init_keymap(void) {
* evdev+8; wl_keyboard.key wants the evdev code. */
xkb_mod_index_t shift = xkb_keymap_mod_get_index(km, XKB_MOD_NAME_SHIFT);
if (shift != XKB_MOD_INVALID) g_shift_mask = (xkb_mod_mask_t)1 << shift;
+ xkb_mod_index_t ctrl = xkb_keymap_mod_get_index(km, XKB_MOD_NAME_CTRL);
+ if (ctrl != XKB_MOD_INVALID) g_ctrl_mask = (xkb_mod_mask_t)1 << ctrl;
+ xkb_mod_index_t alt = xkb_keymap_mod_get_index(km, XKB_MOD_NAME_ALT);
+ if (alt != XKB_MOD_INVALID) g_alt_mask = (xkb_mod_mask_t)1 << alt;
+ xkb_mod_index_t logo = xkb_keymap_mod_get_index(km, XKB_MOD_NAME_LOGO);
+ if (logo != XKB_MOD_INVALID) g_logo_mask = (xkb_mod_mask_t)1 << logo;
for (xkb_keycode_t kc = 9; kc < 256; kc++) {
for (int lvl = 0; lvl < 2; lvl++) {
const xkb_keysym_t *syms;
@@ -192,27 +387,28 @@ static void cua_kbd_key(struct wlr_seat_client *sc, uint32_t keycode, bool press
wl_keyboard_send_key(res, wlr_seat_client_next_serial(sc), tm, keycode,
pressed ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED);
}
-static void cua_type_cp(struct tinywl_server *server, struct tinywl_toplevel *t, uint32_t cp) {
- if (cp >= 128 || !g_chartab[cp].valid) return;
+static bool cua_type_cp(struct tinywl_server *server, struct tinywl_toplevel *t, uint32_t cp) {
+ if (cp >= 128 || !g_chartab[cp].valid) return false;
struct wlr_seat_client *sc = cua_kbd_enter(server, t);
- if (!sc) return;
+ if (!sc) return false;
struct cua_keyent e = g_chartab[cp];
if (e.shift) cua_kbd_mods(sc, g_shift_mask);
cua_kbd_key(sc, e.keycode, true);
cua_kbd_key(sc, e.keycode, false);
if (e.shift) cua_kbd_mods(sc, 0);
+ return true;
}
/* Decode a hex-encoded ASCII string and type it focus-free into `t`. */
-static void cua_type_hex(struct tinywl_server *server, struct tinywl_toplevel *t, const char *hex) {
- if (!t) return;
+static bool cua_type_hex(struct tinywl_server *server, struct tinywl_toplevel *t, const char *hex) {
+ if (!t) return false;
for (const char *p = hex; p[0] && p[1]; p += 2) {
int hi = (p[0] <= '9') ? p[0] - '0' : (p[0] | 0x20) - 'a' + 10;
int lo = (p[1] <= '9') ? p[1] - '0' : (p[1] | 0x20) - 'a' + 10;
- cua_type_cp(server, t, (uint32_t)((hi << 4) | lo));
+ if (!cua_type_cp(server, t, (uint32_t)((hi << 4) | lo))) return false;
}
+ return true;
}
-static void cua_key_named(struct tinywl_server *server, struct tinywl_toplevel *t, const char *name) {
- if (!t) return;
+static uint32_t cua_named_keycode(const char *name) {
uint32_t kc = 0;
if (!strcasecmp(name, "enter") || !strcasecmp(name, "return")) kc = KEY_ENTER;
else if (!strcasecmp(name, "tab")) kc = KEY_TAB;
@@ -223,35 +419,114 @@ static void cua_key_named(struct tinywl_server *server, struct tinywl_toplevel *
else if (!strcasecmp(name, "down")) kc = KEY_DOWN;
else if (!strcasecmp(name, "left")) kc = KEY_LEFT;
else if (!strcasecmp(name, "right")) kc = KEY_RIGHT;
- if (!kc) return;
+ else if (!strncasecmp(name, "f", 1)) {
+ char *end = NULL; long fn = strtol(name + 1, &end, 10);
+ if (end && !*end && fn >= 1 && fn <= 10) kc = KEY_F1 + (uint32_t)fn - 1;
+ else if (end && !*end && fn == 11) kc = KEY_F11;
+ else if (end && !*end && fn == 12) kc = KEY_F12;
+ }
+ return kc;
+}
+/* Returns 1 when `name` is a recognised key (delivered if the target had a
+ * keyboard bound), 0 when it is outside the whitelist so the caller can NAK. */
+static int cua_key_named(struct tinywl_server *server, struct tinywl_toplevel *t, const char *name) {
+ if (!t) return 0;
+ uint32_t kc = cua_named_keycode(name);
+ if (!kc) return 0;
struct wlr_seat_client *sc = cua_kbd_enter(server, t);
- if (!sc) return;
+ if (!sc) return -1;
cua_kbd_key(sc, kc, true);
cua_kbd_key(sc, kc, false);
+ return 1;
+}
+static int cua_hotkey(struct tinywl_server *server, struct tinywl_toplevel *t, const char *mods, const char *key) {
+ if (!t) return 0;
+ uint32_t kc = cua_named_keycode(key);
+ if (!kc && key[0] && !key[1]) {
+ unsigned char cp = (unsigned char)key[0];
+ if (cp < 128 && g_chartab[cp].valid) kc = g_chartab[cp].keycode;
+ }
+ if (!kc) return 0;
+ xkb_mod_mask_t mask = 0;
+ char copy[128]; snprintf(copy, sizeof copy, "%s", mods);
+ char *save = NULL;
+ for (char *mod = strtok_r(copy, ",", &save); mod; mod = strtok_r(NULL, ",", &save)) {
+ if (!strcasecmp(mod, "ctrl") || !strcasecmp(mod, "control")) mask |= g_ctrl_mask;
+ else if (!strcasecmp(mod, "shift")) mask |= g_shift_mask;
+ else if (!strcasecmp(mod, "alt") || !strcasecmp(mod, "option")) mask |= g_alt_mask;
+ else if (!strcasecmp(mod, "meta") || !strcasecmp(mod, "super") || !strcasecmp(mod, "win") || !strcasecmp(mod, "cmd")) mask |= g_logo_mask;
+ else return 0;
+ }
+ struct wlr_seat_client *sc = cua_kbd_enter(server, t);
+ if (!sc) return -1;
+ cua_kbd_mods(sc, mask);
+ cua_kbd_key(sc, kc, true);
+ cua_kbd_key(sc, kc, false);
+ cua_kbd_mods(sc, 0);
+ return 1;
}
/* ── control socket: one line per command, routed by app_id ───────────────── */
-static void cua_handle_cmd(struct tinywl_server *server, char *line) {
+/* Process one command line. Returns NULL on success, else a stable error token
+ * the caller sends back as `err <token>`. The command is only acknowledged
+ * after it has been resolved and applied — never before. */
+static const char *cua_handle_cmd(struct tinywl_server *server, char *line) {
char cmd[8], app[128];
- if (sscanf(line, "%7s", cmd) != 1) return;
- if (!strcmp(cmd, "m")) {
+ if (sscanf(line, "%7s", cmd) != 1) return "empty";
+ const char *err = NULL;
+ struct tinywl_toplevel *t;
+ if (!strcmp(cmd, "d")) {
+ double x, y; unsigned count, btn;
+ if (sscanf(line, "d %lf %lf %u %u", &x, &y, &count, &btn) != 4) return "bad-args";
+ if (!(t = cua_desktop_motion(server, x, y))) return "no-surface-at-point";
+ for (unsigned i = 0; i < (count ? count : 1); i++) {
+ if (!cua_button(server, t, 0, btn, true)) return "no-pointer-resource";
+ if (!cua_button(server, t, 0, btn, false)) return "no-pointer-resource";
+ }
+ return NULL;
+ } else if (!strcmp(cmd, "m")) {
int idx; double x, y;
- if (sscanf(line, "m %127s %d %lf %lf", app, &idx, &x, &y) == 4)
- cua_motion(server, cua_find_appid(server, app), idx, x, y);
+ if (sscanf(line, "m %127s %d %lf %lf", app, &idx, &x, &y) != 4) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ if (!cua_motion(server, t, idx, x, y)) return "no-pointer-resource";
+ return NULL;
} else if (!strcmp(cmd, "b")) {
int idx; unsigned btn, pr;
- if (sscanf(line, "b %127s %d %u %u", app, &idx, &btn, &pr) == 4)
- cua_button(server, cua_find_appid(server, app), idx, btn, pr != 0);
+ if (sscanf(line, "b %127s %d %u %u", app, &idx, &btn, &pr) != 4) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ if (!cua_button(server, t, idx, btn, pr != 0)) return "no-pointer-resource";
+ return NULL;
} else if (!strcmp(cmd, "t")) {
char hex[8192];
- if (sscanf(line, "t %127s %8191s", app, hex) == 2)
- cua_type_hex(server, cua_find_appid(server, app), hex);
+ if (sscanf(line, "t %127s %8191s", app, hex) != 2) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ if (!cua_type_hex(server, t, hex)) return "no-keyboard-resource";
+ return NULL;
} else if (!strcmp(cmd, "k")) {
char key[32];
- if (sscanf(line, "k %127s %31s", app, key) == 2)
- cua_key_named(server, cua_find_appid(server, app), key);
+ if (sscanf(line, "k %127s %31s", app, key) != 2) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ int result = cua_key_named(server, t, key);
+ if (result < 0) return "no-keyboard-resource";
+ if (!result) return "unknown-key";
+ return NULL;
+ } else if (!strcmp(cmd, "h")) {
+ char mods[128], key[32];
+ if (sscanf(line, "h %127s %127s %31s", app, mods, key) != 3) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ int result = cua_hotkey(server, t, mods, key);
+ if (result < 0) return "no-keyboard-resource";
+ if (!result) return "unknown-hotkey";
+ return NULL;
+ } else if (!strcmp(cmd, "a")) {
+ int idx; unsigned axis; double value;
+ if (sscanf(line, "a %127s %d %u %lf", app, &idx, &axis, &value) != 4) return "bad-args";
+ if (!(t = cua_resolve_target(server, app, &err))) return err;
+ if (!cua_axis(server, t, idx, axis, value)) return "no-pointer-resource";
+ return NULL;
}
+ return "unknown-command";
}
-struct cua_conn { struct tinywl_server *server; struct wl_event_source *src; char buf[16384]; size_t len; };
+struct cua_conn { struct tinywl_server *server; struct wl_event_source *src; int hello; char buf[16384]; size_t len; };
/* Tear a connection down once: remove its event source (else the loop fires it
* again on freed data -> double free), close the fd, free the state. */
static int cua_conn_drop(struct cua_conn *c, int fd) {
@@ -267,7 +542,54 @@ static int cua_conn_readable(int fd, uint32_t mask, void *data) {
c->len += (size_t)n; c->buf[c->len] = 0;
char *p = c->buf, *nl;
while ((nl = memchr(p, '\n', (size_t)(c->buf + c->len - p)))) {
- *nl = 0; cua_handle_cmd(c->server, p); p = nl + 1;
+ *nl = 0;
+ /* Tolerate CRLF clients by trimming a trailing carriage return. */
+ if (nl > p && nl[-1] == '\r') nl[-1] = 0;
+ if (!c->hello) {
+ /* The first line must be the versioned v1 handshake. */
+ if (!strcmp(p, CUA_PROTO_HELLO)) {
+ c->hello = 1;
+ cua_reply(fd, CUA_PROTO_HELLO);
+ } else {
+ cua_reply(fd, "err unsupported-version");
+ return cua_conn_drop(c, fd);
+ }
+ } else {
+ int query_pid, geometry_pid, activate_pid;
+ if (sscanf(p, "q %d", &query_pid) == 1) {
+ char msg[128]; cua_query_state(c->server, (pid_t)query_pid, msg, sizeof msg);
+ cua_reply(fd, msg);
+ } else if (sscanf(p, "g %d", &geometry_pid) == 1) {
+ char msg[128];
+ const char *err = cua_query_geometry(c->server, (pid_t)geometry_pid, msg, sizeof msg);
+ if (err) {
+ char reply[128]; snprintf(reply, sizeof reply, "err %s", err); cua_reply(fd, reply);
+ } else {
+ cua_reply(fd, msg);
+ }
+ } else if (sscanf(p, "f %d", &activate_pid) == 1) {
+ const char *err = cua_activate_pid(c->server, (pid_t)activate_pid);
+ wl_display_flush_clients(c->server->wl_display);
+ if (err) {
+ char msg[128]; snprintf(msg, sizeof msg, "err %s", err); cua_reply(fd, msg);
+ } else {
+ cua_reply(fd, "ok");
+ }
+ } else {
+ const char *err = cua_handle_cmd(c->server, p);
+ /* Deliver injected events before acking so `ok` means "processed",
+ * never merely "parsed". */
+ wl_display_flush_clients(c->server->wl_display);
+ if (err) {
+ char msg[128];
+ snprintf(msg, sizeof msg, "err %s", err);
+ cua_reply(fd, msg);
+ } else {
+ cua_reply(fd, "ok");
+ }
+ }
+ }
+ p = nl + 1;
}
size_t rem = (size_t)(c->buf + c->len - p);
memmove(c->buf, p, rem); c->len = rem;
@@ -327,13 +649,20 @@ src = repl(src,
"\t\t\twlr_foreign_toplevel_handle_v1_set_title(toplevel->ftl, toplevel->xdg_toplevel->title);\n"
"\t\tif (toplevel->xdg_toplevel->app_id)\n"
"\t\t\twlr_foreign_toplevel_handle_v1_set_app_id(toplevel->ftl, toplevel->xdg_toplevel->app_id);\n"
+ "\t\ttoplevel->ftl_request_activate.notify = cua_ftl_request_activate;\n"
+ "\t\twl_signal_add(&toplevel->ftl->events.request_activate, &toplevel->ftl_request_activate);\n"
"\t}\n\n\tfocus_toplevel(toplevel);",
"ftl-on-map")
# 4) On unmap: drop the foreign-toplevel handle.
src = repl(src,
"\twl_list_remove(&toplevel->link);\n}",
- "\tif (toplevel->ftl) { wlr_foreign_toplevel_handle_v1_destroy(toplevel->ftl); toplevel->ftl = NULL; }\n"
+ "\tstruct wlr_surface *cua_surface = toplevel->xdg_toplevel->base->surface;\n"
+ "\tfor (int i = 0; i < CUA_MAXDEV; i++) {\n"
+ "\t\tif (cua_ptr[i].entered && wlr_surface_get_root_surface(cua_ptr[i].entered) == cua_surface) cua_ptr[i].entered = NULL;\n"
+ "\t\tif (cua_kbd_state[i].entered && wlr_surface_get_root_surface(cua_kbd_state[i].entered) == cua_surface) cua_kbd_state[i].entered = NULL;\n"
+ "\t}\n"
+ "\tif (toplevel->ftl) { wl_list_remove(&toplevel->ftl_request_activate.link); wlr_foreign_toplevel_handle_v1_destroy(toplevel->ftl); toplevel->ftl = NULL; }\n"
"\twl_list_remove(&toplevel->link);\n}",
"ftl-on-unmap")
diff --git a/nix/cua-driver/package.nix b/nix/cua-driver/package.nix
index 6bc154bb26..6a18a05a83 100644
--- a/nix/cua-driver/package.nix
+++ b/nix/cua-driver/package.nix
@@ -39,16 +39,14 @@ pkgs.rustPlatform.buildRustPackage {
# which are gated behind cfg(target_os) and won't compile on Linux.
# Using -p cua-driver ensures Cargo only resolves Linux dependencies.
#
- # Enable the `portal-libei` feature so the Nix build pulls the
- # GNOME/KDE portal stack (PipeWire ScreenCast per-window capture +
- # libei RemoteDesktop input). nixpkgs provides a recent enough
+ # Enable both portal capabilities so the Nix build pulls the GNOME/KDE
+ # portal stack (PipeWire ScreenCast per-window capture + libei
+ # RemoteDesktop input). nixpkgs provides a recent enough
# PipeWire (>= 0.3.40 needed by libspa-sys) and libei, so this feature
- # builds fine here. The cross-platform release CD leaves it off — its
- # debian:11 container ships PipeWire 0.3.19 (too old for libspa-sys
- # 0.8) and lacks libei entirely, but the wlroots screencopy +
- # virtual-pointer paths still cover sway/Hyprland/labwc/wayfire/dwl.
- cargoBuildFlags = [ "-p" "cua-driver" "--features" "portal-libei" ];
- cargoTestFlags = [ "-p" "cua-driver" "--features" "portal-libei" ];
+ # builds fine here. Release builds enable portal input as well; keeping
+ # capture explicit here validates both halves of the split feature contract.
+ cargoBuildFlags = [ "-p" "cua-driver" "--features" "portal-input,portal-capture" ];
+ cargoTestFlags = [ "-p" "cua-driver" "--features" "portal-input,portal-capture" ];
# Mostly pure Rust:
# x11rb -> RustConnection (no libxcb C binding)
@@ -80,6 +78,8 @@ pkgs.rustPlatform.buildRustPackage {
pipewire
# libei via reis — same as the ashpd RemoteDesktop+EIS flow.
libei
+ # reis links its keyboard support directly against libxkbcommon.
+ libxkbcommon
];
# Skip tests that require a running X11 display or AT-SPI bus
diff --git a/nix/cua-driver/tests/README.md b/nix/cua-driver/tests/README.md
index f1b8a59c35..3b699d7616 100644
--- a/nix/cua-driver/tests/README.md
+++ b/nix/cua-driver/tests/README.md
@@ -1,17 +1,15 @@
-# Linux Nix test layout
+# Linux Nix check layout
Nix expressions are grouped by what they prove:
| Path | Role |
| --- | --- |
| `rust-unit.nix` | Source-built Rust workspace checks without a desktop session |
-| `integration.nix` | Driver service starts and answers protocol requests |
-| `set-config.nix` | Configuration persistence contract |
-| `screenshot.nix` | Capture contract in a managed display |
-| `wayland/` | Compositor-specific supporting and red/green checks |
-| `linux-background-gui.nix` | Legacy toolkit matrix, supporting coverage only |
-| `linux-*-gif.nix` | Legacy visual diagnostics, never the canonical Rust matrix |
+
+This directory intentionally contains no desktop behavior catalog. Nix builds
+the driver, unit checks, session dependencies, and optional compositor package.
+The canonical GUI scenarios and assertions live in the typed Rust harnesses.
New user-behavior coverage belongs in the Rust test harness first. A Nix check
-may provide the session and package environment, but it should invoke the
-shared Rust scenario or clearly identify itself as supporting coverage.
+may provide the session and package environment, but it must invoke the shared
+Rust catalog instead of defining a second set of behavioral assertions.
diff --git a/nix/cua-driver/tests/integration.nix b/nix/cua-driver/tests/integration.nix
deleted file mode 100644
index c391385147..0000000000
--- a/nix/cua-driver/tests/integration.nix
+++ /dev/null
@@ -1,198 +0,0 @@
-# CUA Driver Integration Test
-#
-# Tests the cua-driver MCP server end-to-end in a NixOS container with Xvfb.
-# Verifies CLI subcommands, MCP protocol handshake, and tool invocation.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-integration
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- # Python MCP client that drives cua-driver over stdio.
- # Sends JSON-RPC requests, reads responses, validates structure.
- mcpClientTest = pkgs.writeText "mcp-client-test.py" ''
- import subprocess
- import json
- import sys
- import os
- import threading
- import time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def main():
- print("=== CUA Driver MCP Integration Test ===", flush=True)
-
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- # Drain stderr in background to prevent blocking
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
- t = threading.Thread(target=drain_stderr, daemon=True)
- t.start()
-
- def send_request(method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- line = json.dumps(msg) + "\n"
- print(f"[send] {line.strip()}", flush=True)
- proc.stdin.write(line.encode())
- proc.stdin.flush()
-
- def read_response(timeout=30):
- # Simple blocking read with timeout via thread
- result = [None]
- def reader():
- result[0] = proc.stdout.readline()
- rt = threading.Thread(target=reader)
- rt.start()
- rt.join(timeout)
- if rt.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- print(f"[recv] {line}", flush=True)
- return json.loads(line)
-
- try:
- # Test 1: Initialize
- print("\n--- Test 1: Initialize ---", flush=True)
- send_request("initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-test", "version": "1.0.0"},
- }, req_id=1)
- resp = read_response()
- assert resp.get("id") == 1, f"Expected id=1, got {resp.get('id')}"
- assert "result" in resp, f"Expected result in response: {resp}"
- assert "serverInfo" in resp["result"], f"Expected serverInfo: {resp['result']}"
- print("PASS: initialize", flush=True)
-
- # Send initialized notification (no response expected)
- send_request("notifications/initialized", {})
- time.sleep(0.5)
-
- # Test 2: List tools
- print("\n--- Test 2: tools/list ---", flush=True)
- send_request("tools/list", {}, req_id=2)
- resp = read_response()
- assert resp.get("id") == 2, f"Expected id=2, got {resp.get('id')}"
- tools = resp.get("result", {}).get("tools", [])
- tool_names = [t["name"] for t in tools]
- print(f"Found {len(tools)} tools: {tool_names[:10]}...", flush=True)
- assert "click" in tool_names, f"click not in tools: {tool_names}"
- assert "type_text" in tool_names, f"type_text not in tools: {tool_names}"
- assert "get_screen_size" in tool_names, f"get_screen_size not in tools: {tool_names}"
- assert "get_window_state" in tool_names, f"get_window_state not in tools: {tool_names}"
- print("PASS: tools/list", flush=True)
-
- # Test 3: Call get_screen_size (works without any windows)
- print("\n--- Test 3: tools/call get_screen_size ---", flush=True)
- send_request("tools/call", {
- "name": "get_screen_size",
- "arguments": {},
- }, req_id=3)
- resp = read_response(timeout=15)
- assert resp.get("id") == 3, f"Expected id=3, got {resp.get('id')}"
- # get_screen_size should return display dimensions from Xvfb
- if "result" in resp:
- content = resp["result"].get("content", [])
- text = content[0].get("text", "") if content else ""
- print(f"PASS: get_screen_size returned: {text[:200]}", flush=True)
- elif "error" in resp:
- err_msg = resp.get("error", {}).get("message", "unknown")
- print(f"PASS: get_screen_size returned error (acceptable in headless): {err_msg}", flush=True)
- else:
- raise AssertionError(f"Unexpected response: {resp}")
-
- print("\n=== All MCP tests passed! ===", flush=True)
-
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-integration-test";
- meta = {
- maintainers = [ ];
- };
-
- containers.machine =
- {
- config,
- pkgs,
- lib,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver # Xvfb for headless X11
- python3 # MCP client test script
- jq
- procps # pgrep/pkill
- ];
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Binary exists and runs"):
- machine.succeed("cua-driver --help")
-
- with subtest("list-tools prints available tools"):
- result = machine.succeed("cua-driver list-tools")
- assert "click" in result, f"click not in: {result}"
- assert "type_text" in result, f"type_text not in: {result}"
- assert "get_screen_size" in result, f"get_screen_size not in: {result}"
-
- with subtest("describe tool outputs schema"):
- result = machine.succeed("cua-driver describe get_screen_size")
- assert "input_schema" in result, f"Unexpected describe output: {result[:200]}"
-
- with subtest("Start Xvfb"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/dev/null 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
-
- with subtest("doctor with X11 display"):
- # Timeout doctor to 15s — AT-SPI/gdbus probes can hang without a session bus
- result = machine.succeed("timeout 15 env DISPLAY=:99 cua-driver doctor 2>&1 || true")
- machine.log(result)
-
- with subtest("MCP protocol handshake and tool listing"):
- machine.copy_from_host("${mcpClientTest}", "/tmp/mcp-client-test.py")
- result = machine.succeed(
- "timeout 60 env DISPLAY=:99 "
- "python3 /tmp/mcp-client-test.py 2>&1"
- )
- machine.log(result)
- assert "All MCP tests passed" in result, f"MCP tests failed: {result}"
- '';
-}
diff --git a/nix/cua-driver/tests/linux-background-gui.nix b/nix/cua-driver/tests/linux-background-gui.nix
deleted file mode 100644
index 7af374d0a6..0000000000
--- a/nix/cua-driver/tests/linux-background-gui.nix
+++ /dev/null
@@ -1,1062 +0,0 @@
-# Linux background GUI test — matrix over REAL desktop apps, via AT-SPI.
-#
-# X11 only routes keystrokes to the focused toplevel's focused widget, so the
-# driver reads/types into GUI apps focus-free through AT-SPI instead. This test
-# stands up an AT-SPI accessibility bus, launches a real app in the background
-# (a separate control terminal stays focused), then drives cua-driver against
-# the inactive app window and asserts the accessibility tree is reachable.
-#
-# Two classes of entry live in `apps`:
-#
-# 1. SKELETON entries (skeleton = true) — the real-app matrix. These run a
-# LENIENT, READ-ONLY smoke test: find the app window, drive cua-driver
-# `page get_text` (read) against it, assert it returned a non-error
-# accessibility response, assert focus stayed on the control terminal, and
-# produce a GIF. Focus-free WRITE / typed-text assertions are intentionally
-# OUT OF SCOPE here — they are added later per-app via trajectories.
-#
-# 2. Full entries (skeleton unset) — chromium and tk. These keep their
-# original full behaviour: chromium exercises the approved CDP focus-free
-# *write* override (Input.insertText into the background window); tk
-# exercises the Tk `send` focus-free write override. Both also type via the
-# native AT-SPI path and read it back.
-#
-# Each run screen-records X11 display :99 into a per-app animated GIF
-# (/tmp/cua-driver-linux-background-gui-<app>.gif) and copies it into the test
-# derivation's $out, so the Nix workflow's `visual: true` artifact upload finds
-# a `.gif` for every matrix job. The GIF is stopped and copied out before any
-# toolkit assertion can fail, so even failing jobs still upload one.
-#
-# `app` selects one entry from `apps`, so flake.nix wires one matrix job per app.
-# To run: nix build .#checks.x86_64-linux.cua-driver-linux-background-gui-<app>
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- app,
- ...
-}:
-
-let
- typed = "cuatyped1234";
-
- # Records an animated GIF of X11 display :99 while the driver interacts with
- # the background window, so every matrix job (not just the dedicated GIF
- # tests) produces a `.gif` artifact for the Nix workflow's `visual: true`
- # upload. Shared with the linux-cursor-click / linux-background-terminal GIF
- # tests. Needs `pkgs.imagemagick` in environment.systemPackages (below).
- recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-
- # openbox config with focusNew=no so background apps can't steal X focus when
- # their window maps mid-test (see openbox-rc.nix).
- openboxRc = import ./openbox-rc.nix { inherit pkgs; };
-
- # Distinct per-app GIF name so concurrent matrix jobs and their artifacts
- # never collide; the workflow's `find -L "<result>/" -name '*.gif'` picks it
- # up once it has been copied into the test derivation's $out.
- outputGif = "/tmp/cua-driver-linux-background-gui-${app}.gif";
-
- # Per-app still screenshot + AT-SPI overlay PNGs. The raw PNG is a full-screen
- # capture whose pixel coordinates align 1:1 with the AT-SPI screen-coordinate
- # bounds (no translation), so the overlay can draw element boxes directly.
- rawPng = "/tmp/cua-driver-linux-background-gui-${app}.png";
- atspiPng = "/tmp/cua-driver-linux-background-gui-${app}-atspi.png";
- # Per-app copy of the AT-SPI element bounds JSON ({element_index, role, name,
- # x, y, width, height} in screen coords) — emitted as a CI artifact so the
- # coordinates are inspectable alongside the annotated screenshots.
- elementsJson = "/tmp/cua-driver-linux-background-gui-${app}-elements.json";
-
- # Reads /tmp/cua-elements.json and draws each element's screen-coordinate box
- # + label onto a copy of the raw PNG via a single ImageMagick `convert`. If
- # the element list is empty (or anything goes wrong) it just copies the raw
- # PNG through, so an overlay hiccup never fails the job.
- # stdlib-python overlay: reads the raw PNG + /tmp/cua-elements.json and shells
- # out to ImageMagick `convert` to draw a red box + label per element, in a
- # single invocation. Tolerant: on an empty list or ANY error it copies the raw
- # PNG through, so the *-atspi.png artifact is always produced.
- atspiOverlayPy = pkgs.writeText "cua-atspi-overlay.py" ''
- import json, os, shutil, subprocess, sys
-
- CONVERT = "${pkgs.imagemagick}/bin/convert"
- # -annotate renders TEXT and needs an explicit font: the minimal test container has
- # no fontconfig-discoverable fonts, so convert exits 1 without this.
- FONT = "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuSans.ttf"
-
- def main():
- raw, out = sys.argv[1], sys.argv[2]
- elems_path = sys.argv[3] if len(sys.argv) > 3 else "/tmp/cua-elements.json"
- if not (os.path.exists(raw) and os.path.getsize(raw) > 0):
- return
- try:
- with open(elems_path) as f:
- elems = json.load(f)
- except Exception:
- elems = []
- if not isinstance(elems, list):
- elems = []
- argv = [CONVERT, raw]
- drew = False
- for e in elems:
- try:
- x = int(e["x"]); y = int(e["y"])
- w = int(e["width"]); h = int(e["height"])
- idx = e.get("element_index")
- except Exception:
- continue
- # Skip AT-SPI's "no extents" sentinel (i32::MIN) and degenerate
- # 1x1 boxes from unrealized widgets (items inside closed menus) —
- # ImageMagick errors out on those coordinates. The driver filters
- # these too; this is belt-and-braces for older driver builds.
- if x < 0 or y < 0 or x > 16384 or y > 16384 or w <= 1 or h <= 1:
- continue
- label = "%s (%d,%d %dx%d)" % (idx, x, y, w, h)
- argv += ["-stroke", "red", "-fill", "none",
- "-draw", "rectangle %d,%d %d,%d" % (x, y, x + w, y + h)]
- argv += ["-stroke", "none", "-fill", "red", "-font", FONT,
- "-pointsize", "12",
- "-annotate", "+%d+%d" % (x + 2, max(y + 12, 12)), label]
- drew = True
- if not drew:
- shutil.copyfile(raw, out)
- print("ATSPI_OVERLAY: no elements, copied raw -> " + out, flush=True)
- return
- argv.append(out)
- try:
- r = subprocess.run(argv, capture_output=True, text=True)
- if r.returncode != 0:
- raise RuntimeError("convert rc=%d stderr=%s" % (r.returncode, r.stderr[-500:]))
- print("ATSPI_OVERLAY: drew overlay -> " + out, flush=True)
- except Exception as ex:
- print("ATSPI_OVERLAY_ERROR: " + repr(ex), flush=True)
- shutil.copyfile(raw, out)
-
- if __name__ == "__main__":
- try:
- main()
- except Exception as ex:
- print("ATSPI_OVERLAY_FATAL: " + repr(ex), flush=True)
- '';
-
- # Plain python3 (stdlib only) to drive the MCP JSON-RPC handshake in the test.
- # The driver now speaks AT-SPI natively over D-Bus (no pyatspi / GI typelibs),
- # so no accessibility Python packages are needed anywhere.
- testPython = pkgs.python3;
-
- # Shared environment: same session D-Bus + a11y settings for the apps and the
- # driver, so the driver's native AT-SPI client reaches the same registry the
- # apps register with. Fixed bus path so every `machine.*` shell can opt in.
- a11yEnv = lib.concatStringsSep " " [
- "DISPLAY=:99"
- "DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/cua-session-bus"
- "XDG_RUNTIME_DIR=/run/user/0"
- "XDG_DATA_DIRS=/run/current-system/sw/share"
- # A GTK3 app dlopens libatk-bridge-2.0.so by soname to join the AT-SPI bus;
- # in this hand-rolled session it isn't on the loader path, so expose it.
- # (Chromium ships its own AT-SPI implementation and doesn't need this.)
- "LD_LIBRARY_PATH=${pkgs.at-spi2-atk}/lib"
- # GTK3 only exports its accessible tree when assistive tech is enabled. That
- # flag is the GSettings key org.gnome.desktop.interface toolkit-accessibility.
- # Use the keyfile backend with a shared config dir so a one-shot `gsettings
- # set` is visible to every app + the bus launcher, without poking org.a11y.Bus
- # at runtime (which D-Bus-activates a second launcher and breaks the bus).
- "GSETTINGS_BACKEND=keyfile"
- "XDG_CONFIG_HOME=/tmp/cua-cfg"
- "GSETTINGS_SCHEMA_DIR=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}/glib-2.0/schemas"
- "GTK_MODULES=gail:atk-bridge"
- "GNOME_ACCESSIBILITY=1"
- "QT_ACCESSIBILITY=1"
- "NO_AT_BRIDGE=0"
- ];
-
- # A page whose input is autofocused; its title is fixed so the window can be
- # found by name. Readback is via AT-SPI, so no JS mirroring is needed. Used by
- # the chromium full entry.
- htmlFile = pkgs.writeText "cua-input.html" ''
- <html><head><title>cua-initial</title></head>
- <body><input autofocus></body></html>
- '';
-
- # ── Per-toolkit launch-environment helpers (shared across the real-app sets) ──
-
- # GTK4 talks AT-SPI directly (not via atk-bridge), but only exports its
- # accessible tree when it selects the AT-SPI backend at startup; GTK_A11Y=atspi
- # forces it on. x11 backend + cairo renderer keep it headless-safe.
- gtk4EnvExports = ''
- export GTK_A11Y=atspi
- export GDK_BACKEND=x11
- export GSK_RENDERER=cairo
- '';
-
- # Qt5: point Qt at qtbase's xcb platform plugin (bare apps don't always inherit
- # it) and force the AT-SPI bridge on regardless of the bus enabled-handshake.
- qt5EnvExports = ''
- export QT_QPA_PLATFORM=xcb
- export QT_PLUGIN_PATH=${pkgs.qt5.qtbase}/${pkgs.qt5.qtbase.qtPluginPrefix}
- export QT_QPA_PLATFORM_PLUGIN_PATH=${pkgs.qt5.qtbase}/${pkgs.qt5.qtbase.qtPluginPrefix}/platforms
- export QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
- export QT_ACCESSIBILITY=1
- '';
-
- # Qt6: Qt 6.5+ aborts loading the xcb plugin unless libxcb-cursor is present;
- # put it on LD_LIBRARY_PATH and force the AT-SPI bridge on.
- qt6EnvExports = ''
- export QT_QPA_PLATFORM=xcb
- export LD_LIBRARY_PATH=${pkgs.xcb-util-cursor}/lib:''${LD_LIBRARY_PATH:-}
- export QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
- export QT_ACCESSIBILITY=1
- '';
-
- # Electron: heavy Chromium embed; standard headless-safe flags.
- electronCommonFlags = "--no-sandbox --disable-gpu --disable-dev-shm-usage";
-
- # ── CDP (Chrome DevTools Protocol) focus-free write — approved override ──────
- # AT-SPI exposes Chromium read-only, so the driver can't write into a
- # *background* browser window through it. CDP talks to the renderer over the
- # debug socket instead: Input.insertText lands in the page's focused DOM
- # element (document.activeElement) regardless of whether the OS window holds X
- # focus. This is a Chromium-specific override, not the generic path.
- cdpPort = 9222;
- cdpMarker = "cdptyped5678";
-
- # Self-contained CDP client (stdlib only: HTTP target discovery + a minimal
- # RFC-6455 WebSocket client), so it runs under plain python3 with no extra deps.
- cdpWriteScript = pkgs.writeText "cdp-write.py" ''
- import json, sys, time, socket, base64, os, struct, urllib.request
- from urllib.parse import urlparse
-
- PORT = ${toString cdpPort}
- MARKER = "${cdpMarker}"
-
- def http_json(path):
- url = "http://127.0.0.1:%d%s" % (PORT, path)
- with urllib.request.urlopen(url, timeout=10) as r:
- return json.load(r)
-
- def pick_page():
- cands = [t for t in http_json("/json")
- if t.get("type") == "page" and t.get("webSocketDebuggerUrl")]
- for t in cands:
- if t.get("title") == "cua-initial" or "cua-input" in t.get("url", ""):
- return t["webSocketDebuggerUrl"]
- return cands[0]["webSocketDebuggerUrl"] if cands else None
-
- class WS:
- def __init__(self, url):
- u = urlparse(url)
- self.sock = socket.create_connection((u.hostname, u.port), timeout=15)
- key = base64.b64encode(os.urandom(16)).decode()
- path = (u.path or "/") + (("?" + u.query) if u.query else "")
- req = (
- "GET %s HTTP/1.1\r\nHost: %s:%d\r\nUpgrade: websocket\r\n"
- "Connection: Upgrade\r\nSec-WebSocket-Key: %s\r\n"
- "Sec-WebSocket-Version: 13\r\n\r\n"
- ) % (path, u.hostname, u.port, key)
- self.sock.sendall(req.encode())
- self._buf = b""
- while b"\r\n\r\n" not in self._buf:
- chunk = self.sock.recv(4096)
- if not chunk:
- raise RuntimeError("ws handshake closed early")
- self._buf += chunk
- head, self._buf = self._buf.split(b"\r\n\r\n", 1)
- if b"101" not in head.split(b"\r\n")[0]:
- raise RuntimeError("ws handshake failed: " + head.decode("latin1"))
-
- def _exact(self, n):
- while len(self._buf) < n:
- chunk = self.sock.recv(4096)
- if not chunk:
- raise RuntimeError("ws closed")
- self._buf += chunk
- out, self._buf = self._buf[:n], self._buf[n:]
- return out
-
- def send_text(self, text):
- payload = text.encode()
- n = len(payload)
- header = bytearray([0x81])
- if n < 126:
- header.append(0x80 | n)
- elif n < 65536:
- header.append(0x80 | 126); header += struct.pack(">H", n)
- else:
- header.append(0x80 | 127); header += struct.pack(">Q", n)
- mask = os.urandom(4)
- header += mask
- self.sock.sendall(bytes(header) + bytes(b ^ mask[i % 4] for i, b in enumerate(payload)))
-
- def recv_text(self):
- data = b""
- while True:
- b0, b1 = self._exact(2)
- fin, opcode, masked, length = b0 & 0x80, b0 & 0x0F, b1 & 0x80, b1 & 0x7F
- if length == 126:
- length = struct.unpack(">H", self._exact(2))[0]
- elif length == 127:
- length = struct.unpack(">Q", self._exact(8))[0]
- mask = self._exact(4) if masked else None
- payload = self._exact(length)
- if mask:
- payload = bytes(b ^ mask[i % 4] for i, b in enumerate(payload))
- if opcode == 0x8:
- raise RuntimeError("ws closed by server")
- if opcode in (0x9, 0xA):
- continue
- data += payload
- if fin:
- return data.decode()
-
- def close(self):
- try:
- self.sock.close()
- except Exception:
- pass
-
- ws_url = None
- for _ in range(30):
- try:
- ws_url = pick_page()
- except Exception:
- ws_url = None
- if ws_url:
- break
- time.sleep(1)
- if not ws_url:
- print("NO_CDP_PAGE_TARGET", flush=True); sys.exit(1)
-
- ws = WS(ws_url)
- _id = [0]
- def cmd(method, params=None):
- _id[0] += 1
- mid = _id[0]
- ws.send_text(json.dumps({"id": mid, "method": method, "params": params or {}}))
- while True:
- msg = json.loads(ws.recv_text())
- if msg.get("id") == mid:
- return msg
-
- cmd("Runtime.enable")
- cmd("DOM.enable")
- # Focus + clear the page input through the DOM (not OS window focus).
- cmd("Runtime.evaluate", {"expression": 'var i=document.querySelector("input"); i.focus(); i.value=""; "ok"'})
- # The override: CDP injects into the renderer's focused element, no OS focus.
- cmd("Input.insertText", {"text": MARKER})
- time.sleep(0.3)
- res = cmd("Runtime.evaluate", {"expression": "document.querySelector('input').value", "returnByValue": True})
- val = res.get("result", {}).get("result", {}).get("value", "")
- print("CDP_VALUE: " + repr(val), flush=True)
- ws.close()
- if val == MARKER:
- print("CDP_READBACK_OK", flush=True); sys.exit(0)
- print("CDP_READBACK_MISMATCH", flush=True); sys.exit(1)
- '';
-
- # Tk (tkinter) app — Tk has no AT-SPI bridge, so focus-free writes use Tk's
- # `send` command instead: the app registers itself with a known name, and the
- # driver injects text by invoking `wish` to send Tcl commands over X11 IPC.
- # This is the Tk-specific override (like CDP for Chromium), proving that
- # non-accessible toolkits can still support background input with bespoke paths.
- tkEnv = pkgs.python3.withPackages (ps: [ ps.tkinter ]);
- tkScript = pkgs.writeText "cua-tk.py" ''
- import tkinter as tk
- root = tk.Tk()
- root.title("cua-initial")
- # Register the app with a known name so `send` commands can reach it.
- tk._default_root.tk.call('tk', 'appname', 'cua-tk-target')
- entry = tk.Entry(root, width=40, name='entry')
- entry.pack(padx=20, pady=20)
- entry.focus_set()
- root.geometry("400x120+700+150")
- root.mainloop()
- '';
-
- # ── Helpers to build real-app skeleton entries tersely ──────────────────────
- # mkSkeleton builds a "skeleton = true" app entry: a launch script (the given
- # `cmd` run with the per-toolkit env exports) plus a `windowMatch` xdotool
- # search expression used to find the background window.
- mkSkeleton =
- {
- packages,
- envExports ? "",
- cmd,
- windowMatch,
- }:
- {
- inherit packages windowMatch;
- skeleton = true;
- launch = pkgs.writeShellScript "cua-launch-${app}.sh" ''
- ${envExports}
- exec ${cmd}
- '';
- };
-
- apps = {
- # ── GTK3 real apps (READ-ONLY SKELETON) ─────────────────────────────────
- gtk3-gedit = mkSkeleton {
- packages = [ pkgs.gedit ];
- cmd = "${pkgs.gedit}/bin/gedit --new-window";
- windowMatch = "--class gedit";
- };
- gtk3-mousepad = mkSkeleton {
- packages = [ pkgs.mousepad ];
- cmd = "${pkgs.mousepad}/bin/mousepad --disable-server";
- windowMatch = "--class mousepad";
- };
- gtk3-geany = mkSkeleton {
- packages = [ pkgs.geany ];
- cmd = "${pkgs.geany}/bin/geany";
- windowMatch = "--class geany";
- };
- gtk3-scite = mkSkeleton {
- packages = [ pkgs.scite ];
- cmd = "${pkgs.scite}/bin/SciTE";
- windowMatch = "--class scite";
- };
- gtk3-abiword = mkSkeleton {
- packages = [ pkgs.abiword ];
- cmd = "${pkgs.abiword}/bin/abiword";
- windowMatch = "--class abiword";
- };
-
- # ── GTK4 real apps (READ-ONLY SKELETON) ─────────────────────────────────
- # Only gnome-characters reliably surfaces a window headless; the other GNOME
- # GTK4 apps (text-editor/console/contacts/calendar) never mapped a window
- # within 120s in CI (missing portals/EDS/VTE runtime), so they were dropped.
- gtk4-characters = mkSkeleton {
- packages = [ pkgs.gnome-characters ];
- envExports = gtk4EnvExports;
- cmd = "${pkgs.gnome-characters}/bin/gnome-characters";
- windowMatch = "--class org.gnome.Characters";
- };
-
- # ── Qt5 real apps (READ-ONLY SKELETON) ──────────────────────────────────
- # manuskript is PyQt5; klog/openambit are Qt5 (qtbase 5.15.x). wsjtx (no
- # window headless) and qsstv (steals focus on launch) were dropped.
- qt5-manuskript = mkSkeleton {
- packages = [ pkgs.manuskript ];
- envExports = qt5EnvExports;
- cmd = "${pkgs.manuskript}/bin/manuskript";
- windowMatch = "--class manuskript";
- };
- qt5-klog = mkSkeleton {
- packages = [ pkgs.klog ];
- envExports = qt5EnvExports;
- cmd = "${pkgs.klog}/bin/klog";
- windowMatch = "--class klog";
- };
- qt5-openambit = mkSkeleton {
- packages = [ pkgs.openambit ];
- envExports = qt5EnvExports;
- cmd = "${pkgs.openambit}/bin/openambit";
- windowMatch = "--class openambit";
- };
-
- # ── Qt6 real apps (READ-ONLY SKELETON) ──────────────────────────────────
- # All from the kdePackages (Qt6) scope, plus qownnotes (Qt6). ghostwriter
- # was dropped (no window surfaced headless within 120s).
- qt6-kate = mkSkeleton {
- packages = [ pkgs.kdePackages.kate ];
- envExports = qt6EnvExports;
- cmd = "${pkgs.kdePackages.kate}/bin/kate --new";
- windowMatch = "--class kate";
- };
- qt6-kcalc = mkSkeleton {
- packages = [ pkgs.kdePackages.kcalc ];
- envExports = qt6EnvExports;
- cmd = "${pkgs.kdePackages.kcalc}/bin/kcalc";
- windowMatch = "--class kcalc";
- };
- qt6-okular = mkSkeleton {
- packages = [ pkgs.kdePackages.okular ];
- envExports = qt6EnvExports;
- cmd = "${pkgs.kdePackages.okular}/bin/okular";
- windowMatch = "--class okular";
- };
- qt6-qownnotes = mkSkeleton {
- packages = [ pkgs.qownnotes ];
- envExports = qt6EnvExports;
- cmd = "${pkgs.qownnotes}/bin/QOwnNotes";
- windowMatch = "--class qownnotes";
- };
-
- # ── Electron real apps (READ-ONLY SKELETON) ─────────────────────────────
- # Heavy Chromium embeds; given a longer CI timeout. Read-only
- # skeleton (CDP write is exercised by the chromium full entry instead).
- # marktext (steals focus on launch) and vscodium (no window headless within
- # 120s) were dropped.
- electron-zettlr = mkSkeleton {
- packages = [ pkgs.zettlr ];
- cmd = "${pkgs.zettlr}/bin/zettlr ${electronCommonFlags}";
- windowMatch = "--class zettlr";
- };
- electron-joplin = mkSkeleton {
- packages = [ pkgs.joplin-desktop ];
- cmd = "${pkgs.joplin-desktop}/bin/joplin-desktop ${electronCommonFlags}";
- windowMatch = "--class joplin";
- };
- electron-logseq = mkSkeleton {
- packages = [ pkgs.logseq ];
- cmd = "${pkgs.logseq}/bin/logseq ${electronCommonFlags}";
- windowMatch = "--class logseq";
- };
-
- # ── Full entries (unchanged behaviour): chromium (CDP) + tk (send) ───────
- chromium = {
- packages = [ pkgs.chromium ];
- cdp = true;
- windowMatch = "--name cua-initial";
- launch = pkgs.writeShellScript "cua-launch-chromium.sh" ''
- exec ${pkgs.chromium}/bin/chromium \
- --no-sandbox --no-first-run --no-default-browser-check --disable-gpu \
- --force-renderer-accessibility \
- --remote-debugging-port=${toString cdpPort} --remote-allow-origins=* \
- --disable-backgrounding-occluded-windows --disable-renderer-backgrounding \
- --user-data-dir=/tmp/cua-chromium --window-position=700,150 --window-size=480,360 \
- --new-window file://${htmlFile}
- '';
- };
- tk = {
- packages = [ tkEnv pkgs.tk ];
- tksend = true;
- windowMatch = "--name cua-initial";
- launch = pkgs.writeShellScript "cua-launch-tk.sh" ''
- exec ${tkEnv}/bin/python3 ${tkScript}
- '';
- };
- };
-
- selected = apps.${app};
- isSkeleton = selected.skeleton or false;
-
- # CDP focus-free write subtest — only for Chromium-backed full entries. Asserts
- # the approved override writes into the *background* window while the control
- # terminal keeps focus. (Skeleton entries skip this.)
- cdpSubtest = lib.optionalString (selected.cdp or false) ''
- with subtest("CDP focus-free write into the background window (approved override)"):
- # CDP reaches the renderer over the debug socket, so Input.insertText lands
- # in the page's focused DOM element while the OS window stays in the
- # background. This is the one path that writes into an unfocused browser
- # window; AT-SPI exposes Chromium read-only.
- machine.copy_from_host("${cdpWriteScript}", "/tmp/cdp-write.py")
- cdp_out = machine.succeed("${a11yEnv} timeout 120 python3 /tmp/cdp-write.py 2>&1")
- machine.log(cdp_out)
- assert "CDP_READBACK_OK" in cdp_out, cdp_out
- # The override must remain focus-free: control terminal still active.
- cdp_control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- cdp_active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- assert cdp_control == cdp_active, "focus moved during CDP write: got " + cdp_active
- '';
-
- # Tk send focus-free write subtest — only for the Tk full entry. Reads the
- # entry value back over Tk `send`, guarded by a Tcl `after` timer + `timeout`
- # backstop so wish always terminates promptly.
- tkGetScript = pkgs.writeText "tk-get-value.tcl" ''
- set ::rc 1
- after 20000 {
- puts "TK_SEND_READBACK_TIMEOUT"
- flush stdout
- exit 1
- }
- if {[catch {send cua-tk-target {.entry get}} val]} {
- puts "TK_SEND_READBACK_ERROR: $val"
- flush stdout
- exit 1
- }
- puts $val
- flush stdout
- exit 0
- '';
- tkSubtest = lib.optionalString (selected.tksend or false) ''
- with subtest("Tk send focus-free write into the background window (Tk override)"):
- # The driver already typed via inject_tk_send in the main test. Now read
- # the entry widget's value back via Tk send to prove the write landed.
- machine.copy_from_host("${tkGetScript}", "/tmp/tk-get-value.tcl")
- status, tk_readback = machine.execute("${a11yEnv} timeout 30 ${pkgs.tk}/bin/wish /tmp/tk-get-value.tcl 2>&1")
- tk_readback = tk_readback.strip()
- machine.log("Tk send readback (exit=" + str(status) + "): " + repr(tk_readback))
- assert "${typed}" in tk_readback, f"Expected '${typed}' in Tk entry, got (exit={status}): {tk_readback}"
- # The override must remain focus-free: control terminal still active.
- tk_control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- tk_active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- assert tk_control == tk_active, "focus moved during Tk write: got " + tk_active
- '';
-
- # Full-entry MCP driver script: type via native AT-SPI then read back.
- mcpTest = pkgs.writeText "mcp-background-gui-test.py" ''
- import json, os, sys, threading, time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- import subprocess
- env = {**os.environ, "CUA_ATSPI_DEBUG": "1"}
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=env,
- )
- def drain():
- for line in proc.stderr:
- sys.stderr.buffer.write(line); sys.stderr.buffer.flush()
- threading.Thread(target=drain, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode()); proc.stdin.flush()
-
- def recv(proc, timeout=45):
- result = [None]
- def reader():
- result[0] = proc.stdout.readline()
- t = threading.Thread(target=reader); t.start(); t.join(timeout)
- if t.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("Driver returned an empty response")
- return json.loads(line)
-
- def call_tool(proc, req_id, name, arguments):
- send(proc, "tools/call", {"name": name, "arguments": arguments}, req_id=req_id)
- resp = recv(proc)
- if resp.get("error"):
- raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"):
- raise RuntimeError(f"{name} returned isError: {resp}")
- return resp
-
- def main():
- with open("/tmp/target-xid.txt") as f:
- target_xid = int(f.read().strip())
- with open("/tmp/target-pid.txt") as f:
- target_pid = int(f.read().strip())
-
- proc = start_driver()
- try:
- send(proc, "initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-background-gui-test", "version": "1.0.0"},
- }, req_id=1)
- recv(proc)
- send(proc, "notifications/initialized", {})
- time.sleep(0.3)
- # Type into the *inactive* app window — focus-free, via native AT-SPI.
- call_tool(proc, 2, "type_text", {
- "pid": target_pid,
- "window_id": target_xid,
- "text": "${typed}",
- })
- time.sleep(1.5)
- print("background GUI test typed", flush=True)
-
- # Read it back through the driver's *own* native AT-SPI client.
- readback = ""
- last_resp = None
- for _ in range(8):
- resp = call_tool(proc, 3, "page", {
- "action": "get_text",
- "pid": target_pid,
- "window_id": target_xid,
- })
- last_resp = resp
- content = resp.get("result", {}).get("content", [])
- readback = " ".join(
- c.get("text", "") for c in content if c.get("type") == "text"
- )
- if "${typed}" in readback:
- break
- time.sleep(1.0)
- print("RAW_GET_TEXT_RESPONSE: " + json.dumps(last_resp), flush=True)
- print("READBACK_BEGIN", flush=True)
- print(readback, flush=True)
- print("READBACK_END", flush=True)
- finally:
- proc.stdin.close(); proc.terminate(); proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- # ── SKELETON: read-only smoke + GIF; focus-free WRITE / typed-text assertions
- # are added later via trajectories. ─────────────────────────────────────────
- # Skeleton MCP driver script: ONLY drives `page get_text` (read) against the
- # found window. It does NOT call type_text and does NOT assert any typed text.
- # It prints the raw get_text response so the testScript can check it returned a
- # non-error accessibility payload.
- skeletonMcpTest = pkgs.writeText "mcp-background-gui-skeleton.py" ''
- import json, os, sys, threading, time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- import subprocess
- env = {**os.environ, "CUA_ATSPI_DEBUG": "1"}
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=env,
- )
- def drain():
- for line in proc.stderr:
- sys.stderr.buffer.write(line); sys.stderr.buffer.flush()
- threading.Thread(target=drain, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode()); proc.stdin.flush()
-
- def recv(proc, timeout=45):
- result = [None]
- def reader():
- result[0] = proc.stdout.readline()
- t = threading.Thread(target=reader); t.start(); t.join(timeout)
- if t.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("Driver returned an empty response")
- return json.loads(line)
-
- def main():
- with open("/tmp/target-xid.txt") as f:
- target_xid = int(f.read().strip())
- with open("/tmp/target-pid.txt") as f:
- target_pid = int(f.read().strip())
-
- proc = start_driver()
- try:
- send(proc, "initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-background-gui-skeleton", "version": "1.0.0"},
- }, req_id=1)
- recv(proc)
- send(proc, "notifications/initialized", {})
- time.sleep(0.3)
-
- # READ-ONLY: drive page/get_text against the inactive window. Retry a
- # few times — real apps (Electron/KDE) take a moment to build their
- # accessibility tree after first paint.
- readback = ""
- last_resp = None
- is_error = True
- for _ in range(10):
- send(proc, "tools/call", {
- "name": "page",
- "arguments": {
- "action": "get_text",
- "pid": target_pid,
- "window_id": target_xid,
- },
- }, req_id=3)
- resp = recv(proc)
- last_resp = resp
- # A transport-level error or isError=true is a non-result; keep
- # retrying. Any structured content counts as a non-error response.
- if resp.get("error") or resp.get("result", {}).get("isError"):
- time.sleep(1.0)
- continue
- content = resp.get("result", {}).get("content", [])
- readback = " ".join(
- c.get("text", "") for c in content if c.get("type") == "text"
- )
- is_error = False
- if readback.strip():
- break
- time.sleep(1.0)
-
- print("RAW_GET_TEXT_RESPONSE: " + json.dumps(last_resp), flush=True)
- print("GET_TEXT_IS_ERROR: " + ("yes" if is_error else "no"), flush=True)
- if not is_error:
- print("GET_TEXT_OK", flush=True)
- print("READBACK_BEGIN", flush=True)
- print(readback, flush=True)
- print("READBACK_END", flush=True)
-
- # READ-ONLY: pull the AT-SPI element bounds via get_window_state so
- # we can draw an overlay PNG as a CI artifact. Tolerant — any
- # failure here just yields an empty element list; it never affects
- # the read-only assertions above.
- elements = []
- try:
- send(proc, "tools/call", {
- "name": "get_window_state",
- "arguments": {
- "pid": target_pid,
- "window_id": target_xid,
- },
- }, req_id=4)
- # Bounds collection does one D-Bus GetExtents round-trip per
- # action node; big trees (geany walked 787 nodes) need well over
- # the default 45s, so give this call a longer window.
- ws = recv(proc, timeout=90)
- result_obj = ws.get("result", {}) if isinstance(ws, dict) else {}
- # The structured `elements` array lives in structuredContent;
- # fall back to scanning any text content that carries JSON.
- structured = result_obj.get("structuredContent") or {}
- if isinstance(structured, dict) and isinstance(structured.get("elements"), list):
- elements = structured["elements"]
- else:
- for c in result_obj.get("content", []):
- if c.get("type") == "text":
- try:
- obj = json.loads(c.get("text", ""))
- except Exception:
- continue
- if isinstance(obj, dict) and isinstance(obj.get("elements"), list):
- elements = obj["elements"]
- break
- except Exception as e:
- print("GET_WINDOW_STATE_ERROR: " + repr(e), flush=True)
- elements = []
- if not isinstance(elements, list):
- elements = []
- with open("/tmp/cua-elements.json", "w") as f:
- json.dump(elements, f)
- print("ELEMENTS_JSON: " + json.dumps(elements), flush=True)
- print("ELEMENTS_COUNT: " + str(len(elements)), flush=True)
- finally:
- proc.stdin.close(); proc.terminate(); proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- # The window-find shell command, parameterised on the app's windowMatch. Tries
- # the toolkit class/name match first, then falls back to the launched PID's
- # window, then the newest visible window — so real apps that don't expose the
- # expected class still surface a window for the read-only drive.
- # A store-path script (not an inline multi-line string): it is interpolated
- # into the Python testScript as a single `machine.wait_until_succeeds("...")`
- # argument. A multi-line shell snippet with embedded quotes/newlines would
- # break that Python string literal (it did — every GUI job failed the
- # testScript type-check). As a script path it is one safe token.
- windowFindCmd = pkgs.writeShellScript "cua-window-find.sh" ''
- export DISPLAY=:99
- xid=$(${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible ${selected.windowMatch} 2>/dev/null | head -1)
- if [ -z "$xid" ]; then
- xid=$(${pkgs.xdotool}/bin/xdotool search --all --pid "$(cat /tmp/target-pid.txt)" 2>/dev/null | head -1)
- fi
- if [ -z "$xid" ]; then
- xid=$(${pkgs.xdotool}/bin/xdotool search --onlyvisible "" 2>/dev/null | tail -1)
- fi
- test -n "$xid" && printf "%s" "$xid" >/tmp/target-xid.txt && test -s /tmp/target-xid.txt
- '';
-
- # ── Skeleton (read-only) drive + assertions ─────────────────────────────────
- skeletonDrive = ''
- with subtest("SKELETON read-only: drive cua-driver page/get_text against the inactive window"):
- # SKELETON: read-only smoke + GIF; focus-free WRITE / typed-text
- # assertions are added later via trajectories. This path only proves the
- # app window appeared and the driver can READ its accessibility tree.
- machine.copy_from_host("${skeletonMcpTest}", "/tmp/mcp-background-gui-skeleton.py")
- machine.execute(
- "sh -lc '${recordGifScript} :99 /tmp/gui-frames ${outputGif} "
- "/tmp/stop-gui-recorder /tmp/record-gui.log 10 0.2 >/dev/null 2>&1 & echo $! >/tmp/record-gui.pid'"
- )
- # 300s: get_text retries + the bounded get_window_state bounds walk
- # (recv timeout 150s) must both fit.
- status, result = machine.execute("${a11yEnv} timeout 300 python3 /tmp/mcp-background-gui-skeleton.py 2>&1")
- machine.log(result)
- # Stop the recorder and copy the GIF out *now*, before any assertion can
- # fail, so every matrix job uploads a GIF of the interaction.
- machine.execute("touch /tmp/stop-gui-recorder")
- machine.execute("timeout 60 sh -lc 'while kill -0 $(cat /tmp/record-gui.pid) 2>/dev/null; do sleep 0.2; done'")
- # If the recorder (or its convert) is still grinding past the wait,
- # kill it hard so it can't thrash the container and wedge later commands.
- machine.execute("pkill -9 -f record-x11-gif >/dev/null 2>&1; pkill -9 -x convert >/dev/null 2>&1; pkill -9 -x import >/dev/null 2>&1; true")
- machine.log(machine.execute("sh -lc 'cat /tmp/record-gui.log || true'")[1])
- # Best-effort: a missing GIF (recorder/convert hiccup under load) must
- # not fail the read-only job — copy only when the file exists.
- if machine.execute("test -s ${outputGif}")[0] == 0:
- machine.copy_from_machine("${outputGif}", "")
- else:
- machine.log("WARN: ${outputGif} missing; skipping GIF copy")
-
- # Annotated screenshots (CI artifacts), produced BEFORE any assertion can
- # fail and wrapped in execute() so a capture/drawing hiccup never fails
- # the read-only job:
- # ${rawPng} full-screen still (screen coords == AT-SPI bounds)
- # ${atspiPng} raw + AT-SPI element boxes/labels overlay
- # The downstream `som-annotate` job consumes the raw PNG to emit *-som.png.
- # `import` can block indefinitely if another client wedges the X server
- # grab (it hung a job to the GH 15-min cap once) — bound it hard.
- machine.execute("${a11yEnv} timeout 30 ${pkgs.imagemagick}/bin/import -window root ${rawPng}")
- machine.copy_from_host("${atspiOverlayPy}", "/tmp/cua-atspi-overlay.py")
- st_ov, out_ov = machine.execute(
- "${a11yEnv} timeout 60 ${pkgs.python3}/bin/python3 /tmp/cua-atspi-overlay.py "
- "${rawPng} ${atspiPng} /tmp/cua-elements.json 2>&1"
- )
- machine.log(out_ov)
- # Always emit both PNGs; fall back to copying the raw PNG if the overlay
- # step produced nothing. Copies are best-effort — a capture hiccup must
- # not fail the read-only job.
- machine.execute("test -s ${atspiPng} || cp ${rawPng} ${atspiPng} 2>/dev/null")
- if machine.execute("test -s ${rawPng}")[0] == 0:
- machine.copy_from_machine("${rawPng}", "")
- else:
- machine.log("WARN: ${rawPng} missing; skipping raw screenshot copy")
- if machine.execute("test -s ${atspiPng}")[0] == 0:
- machine.copy_from_machine("${atspiPng}", "")
- else:
- machine.log("WARN: ${atspiPng} missing; skipping atspi overlay copy")
- # Emit the element-bounds JSON (the coordinates) as an artifact too.
- machine.execute("cp /tmp/cua-elements.json ${elementsJson} 2>/dev/null; true")
- if machine.execute("test -s ${elementsJson}")[0] == 0:
- machine.copy_from_machine("${elementsJson}", "")
- else:
- machine.log("WARN: ${elementsJson} missing; skipping elements JSON copy")
-
- # Lenient assertion: get_text returned a NON-error accessibility response.
- # Do NOT require any specific role (entry/text/...) — any content is fine.
- assert "GET_TEXT_OK" in result, (
- "driver page/get_text did not return a non-error response for the "
- "background app:\n" + result
- )
-
- with subtest("Focus stayed on the control terminal"):
- control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- assert control == active, "expected active window " + control + ", got " + active
- '';
-
- # ── Full-entry (chromium/tk) drive + assertions (original behaviour) ─────────
- fullDrive = ''
- with subtest("Drive cua-driver against the inactive window (AT-SPI)"):
- machine.copy_from_host("${mcpTest}", "/tmp/mcp-background-gui-test.py")
- machine.execute(
- "sh -lc '${recordGifScript} :99 /tmp/gui-frames ${outputGif} "
- "/tmp/stop-gui-recorder /tmp/record-gui.log 10 0.2 >/dev/null 2>&1 & echo $! >/tmp/record-gui.pid'"
- )
- status, result = machine.execute("${a11yEnv} timeout 200 python3 /tmp/mcp-background-gui-test.py 2>&1")
- machine.log(result)
- machine.execute("touch /tmp/stop-gui-recorder")
- machine.execute("timeout 60 sh -lc 'while kill -0 $(cat /tmp/record-gui.pid) 2>/dev/null; do sleep 0.2; done'")
- # If the recorder (or its convert) is still grinding past the wait,
- # kill it hard so it can't thrash the container and wedge later commands.
- machine.execute("pkill -9 -f record-x11-gif >/dev/null 2>&1; pkill -9 -x convert >/dev/null 2>&1; pkill -9 -x import >/dev/null 2>&1; true")
- machine.log(machine.execute("sh -lc 'cat /tmp/record-gui.log || true'")[1])
- # Best-effort GIF copy (see skeleton path): a recorder hiccup must not
- # fail the job before the real assertions run.
- if machine.execute("test -s ${outputGif}")[0] == 0:
- machine.copy_from_machine("${outputGif}", "")
- else:
- machine.log("WARN: ${outputGif} missing; skipping GIF copy")
- assert "background GUI test typed" in result, result
-
- with subtest("Input landed: driver's native AT-SPI reads the window back"):
- assert any(tok in result for tok in ('frame "', 'window "', 'document', 'text "', 'entry "')), (
- "driver get_text did not return an accessibility node for the background app:\n"
- + result
- )
-
- with subtest("Focus stayed on the control terminal"):
- control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- assert control == active, "expected active window " + control + ", got " + active
-
- ${cdpSubtest}
- ${tkSubtest}
- '';
-
- driveBody = if isSkeleton then skeletonDrive else fullDrive;
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-linux-background-gui-${app}-test";
- meta.maintainers = [ ];
-
- containers.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- services.dbus.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver
- xterm
- openbox
- picom
- xdotool
- imagemagick # `import` + `convert` for the screen-recorded GIF
- dbus
- at-spi2-core
- testPython
- jq
- procps
- glib # `gsettings` to flip toolkit-accessibility
- gsettings-desktop-schemas # provides org.gnome.desktop.interface schema
- ] ++ selected.packages;
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Start X11 + session D-Bus + AT-SPI bus"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/tmp/xvfb.log 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
- machine.execute("DISPLAY=:99 openbox --config-file ${openboxRc} >/tmp/openbox.log 2>&1 &")
- machine.execute("DISPLAY=:99 picom --backend xrender >/tmp/picom.log 2>&1 &")
- machine.succeed("mkdir -p /run/user/0 && chmod 700 /run/user/0")
- machine.execute("dbus-daemon --session --address=unix:path=/tmp/cua-session-bus --fork >/tmp/dbus.log 2>&1")
- machine.wait_until_succeeds("test -S /tmp/cua-session-bus", timeout=10)
- machine.succeed("mkdir -p /tmp/cua-cfg")
- machine.execute("${a11yEnv} ${pkgs.at-spi2-core}/libexec/at-spi-bus-launcher --launch-immediately >/tmp/atspi-launcher.log 2>&1 &")
- machine.wait_until_succeeds(
- "${a11yEnv} dbus-send --session --print-reply "
- "--dest=org.freedesktop.DBus / org.freedesktop.DBus.NameHasOwner "
- "string:org.a11y.Bus | grep -q 'boolean true'",
- timeout=15,
- )
- machine.execute(
- "${a11yEnv} dbus-send --session --print-reply --dest=org.a11y.Bus "
- "/org/a11y/bus org.freedesktop.DBus.Properties.Set "
- "string:org.a11y.Status string:IsEnabled variant:boolean:true 2>&1 | tee /tmp/a11y-enable.log"
- )
- machine.log("a11y IsEnabled set: " + machine.execute("cat /tmp/a11y-enable.log")[1])
- machine.execute(
- "${a11yEnv} dbus-send --session --print-reply --dest=org.a11y.Bus "
- "/org/a11y/bus org.freedesktop.DBus.Properties.Get "
- "string:org.a11y.Status string:IsEnabled 2>&1 | tee /tmp/a11y-get.log"
- )
- machine.log("a11y IsEnabled get: " + machine.execute("cat /tmp/a11y-get.log")[1])
- machine.log("atspi-launcher.log: " + machine.execute("cat /tmp/atspi-launcher.log")[1])
-
- with subtest("Focused control terminal"):
- machine.execute("sh -lc 'DISPLAY=:99 xterm -T Control -geometry 60x20+40+120 >/tmp/control.log 2>&1 & echo $! >/tmp/control-pid.txt'")
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/control-pid.txt) >/tmp/control-xid.txt", timeout=20)
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(head -1 /tmp/control-xid.txt)")
-
- with subtest("Launch target app (${app}) in the background"):
- machine.execute("sh -lc '${a11yEnv} ${selected.launch} >/tmp/target.log 2>&1 & echo $! >/tmp/target-pid.txt'")
- # Surface the app's own stdout/stderr early so launch failures (e.g. a Qt
- # platform-plugin error) are visible instead of just a window-find timeout.
- machine.sleep(5)
- machine.log("target.log after launch: " + machine.execute("cat /tmp/target.log")[1])
- # Find the background window via the per-app matcher, with a PID / newest
- # -window fallback. Generous timeout: Electron/KDE are slow to first paint.
- machine.wait_until_succeeds("${windowFindCmd}", timeout=120)
- machine.log("target-xid: " + machine.execute("cat /tmp/target-xid.txt")[1])
- # Keep focus on the control terminal — launching the app in the
- # background must not steal focus.
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(head -1 /tmp/control-xid.txt)")
- machine.succeed("DISPLAY=:99 xdotool windowfocus --sync $(head -1 /tmp/control-xid.txt)")
-
- ${driveBody}
- '';
-}
diff --git a/nix/cua-driver/tests/linux-background-terminal-gif.nix b/nix/cua-driver/tests/linux-background-terminal-gif.nix
deleted file mode 100644
index 949c129d8d..0000000000
--- a/nix/cua-driver/tests/linux-background-terminal-gif.nix
+++ /dev/null
@@ -1,203 +0,0 @@
-# Linux background terminal GIF test
-#
-# Records a GIF while cua-driver types into an inactive xterm window and
-# executes a shell command without stealing focus.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-linux-background-terminal-gif
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- mcpBackgroundTerminalTest = pkgs.writeText "mcp-background-terminal-gif-test.py" ''
- import json
- import os
- import subprocess
- import sys
- import threading
- import time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
-
- threading.Thread(target=drain_stderr, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode())
- proc.stdin.flush()
-
- def recv(proc, timeout=30):
- result = [None]
-
- def reader():
- result[0] = proc.stdout.readline()
-
- thread = threading.Thread(target=reader)
- thread.start()
- thread.join(timeout)
- if thread.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("Driver returned an empty response")
- return json.loads(line)
-
- def call_tool(proc, req_id, name, arguments):
- send(proc, "tools/call", {"name": name, "arguments": arguments}, req_id=req_id)
- resp = recv(proc, timeout=45)
- if "error" in resp and resp["error"] is not None:
- raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"):
- raise RuntimeError(f"{name} returned isError: {resp}")
- return resp
-
- def main():
- with open("/tmp/background-target-xid.txt", "r", encoding="utf-8") as f:
- target_window_id = int(f.read().strip())
- with open("/tmp/background-target-pid.txt", "r", encoding="utf-8") as f:
- target_pid = int(f.read().strip())
- with open("/tmp/background-control-xid.txt", "r", encoding="utf-8") as f:
- control_window_id = int(f.read().strip())
- with open("/tmp/background-control-pid.txt", "r", encoding="utf-8") as f:
- control_pid = int(f.read().strip())
-
- proc = start_driver()
- try:
- send(proc, "initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-background-terminal-gif-test", "version": "1.0.0"},
- }, req_id=1)
- recv(proc)
- send(proc, "notifications/initialized", {})
- time.sleep(0.3)
-
- call_tool(proc, 2, "set_agent_cursor_enabled", {"enabled": True})
- call_tool(proc, 3, "move_cursor", {"x": 50.0, "y": 900.0})
- time.sleep(0.5)
- call_tool(proc, 4, "click", {
- "pid": control_pid,
- "window_id": control_window_id,
- "x": 120.0,
- "y": 120.0,
- })
- time.sleep(0.6)
- call_tool(proc, 5, "type_text", {
- "pid": target_pid,
- "window_id": target_window_id,
- "text": "echo hello | tee /tmp/background-hello.txt",
- })
- call_tool(proc, 6, "press_key", {
- "pid": target_pid,
- "window_id": target_window_id,
- "key": "enter",
- })
- time.sleep(1.8)
- print("background terminal GIF test complete", flush=True)
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-
- # openbox config with focusNew=no (see openbox-rc.nix) so focus stays on the
- # control terminal when the target xterm maps.
- openboxRc = import ./openbox-rc.nix { inherit pkgs; };
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-linux-background-terminal-gif-test";
- meta.maintainers = [ ];
-
- containers.machine =
- {
- pkgs,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver
- xterm
- openbox
- picom
- xdotool
- imagemagick
- python3
- jq
- procps
- ];
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Start X11 desktop and target/control xterms"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/tmp/xvfb.log 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
- machine.execute("DISPLAY=:99 openbox --config-file ${openboxRc} >/tmp/openbox.log 2>&1 &")
- machine.execute("DISPLAY=:99 picom --backend xrender >/tmp/picom.log 2>&1 &")
- machine.execute("sh -lc \"DISPLAY=:99 xterm -T 'Background Target' -fa Monospace -fs 14 -geometry 70x24+40+120 >/tmp/background-target.log 2>&1 & echo \\$! >/tmp/background-target-pid.txt\"")
- machine.execute("sh -lc \"DISPLAY=:99 xterm -T 'Background Control' -fa Monospace -fs 14 -geometry 70x24+690+120 >/tmp/background-control.log 2>&1 & echo \\$! >/tmp/background-control-pid.txt\"")
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/background-target-pid.txt) >/tmp/background-target-xid.txt", timeout=20)
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/background-control-pid.txt) >/tmp/background-control-xid.txt", timeout=20)
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(head -1 /tmp/background-control-xid.txt)")
- machine.succeed("DISPLAY=:99 xdotool windowfocus --sync $(head -1 /tmp/background-control-xid.txt)")
-
- with subtest("Record GIF and execute command in inactive terminal"):
- machine.copy_from_host("${mcpBackgroundTerminalTest}", "/tmp/mcp-background-terminal-gif-test.py")
- machine.execute(
- "sh -lc '${recordGifScript} :99 /tmp/background-frames /tmp/cua-driver-linux-background-terminal.gif "
- "/tmp/stop-background-recorder /tmp/ffmpeg-background.log 10 0.15 >/dev/null 2>&1 & echo $! >/tmp/ffmpeg-background.pid'"
- )
- result = machine.succeed("timeout 60 env DISPLAY=:99 python3 /tmp/mcp-background-terminal-gif-test.py 2>&1")
- machine.log(result)
- assert "background terminal GIF test complete" in result, result
- machine.succeed("touch /tmp/stop-background-recorder")
- machine.wait_until_succeeds("! kill -0 $(cat /tmp/ffmpeg-background.pid) 2>/dev/null", timeout=60)
- machine.log(machine.succeed("sh -lc 'cat /tmp/ffmpeg-background.log || true'"))
- machine.succeed("test -s /tmp/cua-driver-linux-background-terminal.gif")
- machine.wait_until_succeeds("grep -Fx 'hello' /tmp/background-hello.txt", timeout=20)
-
- with subtest("Verify focus stayed on control terminal"):
- control = machine.succeed("head -1 /tmp/background-control-xid.txt").strip()
- active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- assert control == active, f"expected active window {control}, got {active}"
-
- with subtest("Copy GIF out of the container"):
- machine.copy_from_machine("/tmp/cua-driver-linux-background-terminal.gif", "")
- '';
-}
diff --git a/nix/cua-driver/tests/linux-cursor-click-gif.nix b/nix/cua-driver/tests/linux-cursor-click-gif.nix
deleted file mode 100644
index d847d538fb..0000000000
--- a/nix/cua-driver/tests/linux-cursor-click-gif.nix
+++ /dev/null
@@ -1,186 +0,0 @@
-# Linux cursor click GIF test
-#
-# Records a GIF of the Linux overlay cursor moving as part of a click action
-# and proves the click focused the target xterm and allowed a shell command to
-# execute.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-linux-cursor-click-gif
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- mcpClickTest = pkgs.writeText "mcp-click-gif-test.py" ''
- import json
- import os
- import subprocess
- import sys
- import threading
- import time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
-
- threading.Thread(target=drain_stderr, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode())
- proc.stdin.flush()
-
- def recv(proc, timeout=30):
- result = [None]
-
- def reader():
- result[0] = proc.stdout.readline()
-
- thread = threading.Thread(target=reader)
- thread.start()
- thread.join(timeout)
- if thread.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("Driver returned an empty response")
- return json.loads(line)
-
- def call_tool(proc, req_id, name, arguments):
- send(proc, "tools/call", {"name": name, "arguments": arguments}, req_id=req_id)
- resp = recv(proc, timeout=45)
- if "error" in resp and resp["error"] is not None:
- raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"):
- raise RuntimeError(f"{name} returned isError: {resp}")
- return resp
-
- def main():
- with open("/tmp/target-click-xid.txt", "r", encoding="utf-8") as f:
- window_id = int(f.read().strip())
- with open("/tmp/target-click-pid.txt", "r", encoding="utf-8") as f:
- pid = int(f.read().strip())
-
- proc = start_driver()
- try:
- send(proc, "initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-click-gif-test", "version": "1.0.0"},
- }, req_id=1)
- recv(proc)
- send(proc, "notifications/initialized", {})
- time.sleep(0.3)
-
- call_tool(proc, 2, "set_agent_cursor_enabled", {"enabled": True})
- call_tool(proc, 3, "move_cursor", {"x": 1100.0, "y": 900.0})
- time.sleep(0.8)
- call_tool(proc, 4, "click", {"pid": pid, "window_id": window_id, "x": 120.0, "y": 120.0})
- time.sleep(0.5)
- call_tool(proc, 5, "type_text", {
- "pid": pid,
- "window_id": window_id,
- "text": "echo click-focus > /tmp/click-focus.txt",
- })
- call_tool(proc, 6, "press_key", {"pid": pid, "window_id": window_id, "key": "enter"})
- time.sleep(1.5)
- print("click GIF test complete", flush=True)
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-
- # openbox config with focusNew=no (see openbox-rc.nix) so the control terminal
- # keeps X focus when the second xterm maps.
- openboxRc = import ./openbox-rc.nix { inherit pkgs; };
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-linux-cursor-click-gif-test";
- meta.maintainers = [ ];
-
- containers.machine =
- {
- pkgs,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver
- xterm
- openbox
- picom
- xdotool
- imagemagick
- python3
- jq
- procps
- ];
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Start X11 desktop and two xterms"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/tmp/xvfb.log 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
- machine.execute("DISPLAY=:99 openbox --config-file ${openboxRc} >/tmp/openbox.log 2>&1 &")
- machine.execute("DISPLAY=:99 picom --backend xrender >/tmp/picom.log 2>&1 &")
- machine.execute("sh -lc \"DISPLAY=:99 xterm -T 'Target Click' -fa Monospace -fs 14 -geometry 70x24+80+120 >/tmp/target-click.log 2>&1 & echo \\$! >/tmp/target-click-pid.txt\"")
- machine.execute("sh -lc \"DISPLAY=:99 xterm -T 'Control Click' -fa Monospace -fs 14 -geometry 70x24+700+120 >/tmp/control-click.log 2>&1 & echo \\$! >/tmp/control-click-pid.txt\"")
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/target-click-pid.txt) >/tmp/target-click-xid.txt", timeout=20)
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/control-click-pid.txt) >/tmp/control-click-xid.txt", timeout=20)
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(head -1 /tmp/control-click-xid.txt)")
- machine.succeed("DISPLAY=:99 xdotool windowfocus --sync $(head -1 /tmp/control-click-xid.txt)")
-
- with subtest("Record click GIF and run driver actions"):
- machine.copy_from_host("${mcpClickTest}", "/tmp/mcp-click-gif-test.py")
- machine.execute(
- "sh -lc '${recordGifScript} :99 /tmp/click-frames /tmp/cua-driver-linux-cursor-click.gif "
- "/tmp/stop-click-recorder /tmp/ffmpeg-click.log 10 0.15 >/dev/null 2>&1 & echo $! >/tmp/ffmpeg-click.pid'"
- )
- result = machine.succeed("timeout 60 env DISPLAY=:99 python3 /tmp/mcp-click-gif-test.py 2>&1")
- machine.log(result)
- assert "click GIF test complete" in result, result
- machine.succeed("touch /tmp/stop-click-recorder")
- machine.wait_until_succeeds("! kill -0 $(cat /tmp/ffmpeg-click.pid) 2>/dev/null", timeout=60)
- machine.log(machine.succeed("sh -lc 'cat /tmp/ffmpeg-click.log || true'"))
- machine.succeed("test -s /tmp/cua-driver-linux-cursor-click.gif")
- machine.wait_until_succeeds("test -f /tmp/click-focus.txt", timeout=20)
-
- with subtest("Copy GIF out of the container"):
- machine.copy_from_machine("/tmp/cua-driver-linux-cursor-click.gif", "")
- '';
-}
diff --git a/nix/cua-driver/tests/linux-parallel-drag-gif.nix b/nix/cua-driver/tests/linux-parallel-drag-gif.nix
deleted file mode 100644
index dc2562211f..0000000000
--- a/nix/cua-driver/tests/linux-parallel-drag-gif.nix
+++ /dev/null
@@ -1,387 +0,0 @@
-# Linux parallel multi-cursor drag GIF test
-#
-# NOT WIRED INTO CI (flake checks / nix-build.yml). It needs a real Xorg
-# (dummy video + libinput) so the MPX path's uinput slaves enumerate as X
-# input devices, and that server does not start reliably in the emulated
-# GHA nixos-test VM (the hand-launched Xorg times out before the socket
-# appears). The feature's logic is covered by unit tests in
-# platform-linux/src/input/mod.rs (arc-length path glide + fn sampling);
-# this scenario is kept for local / real-X manual runs:
-# nix build .#checks.x86_64-linux.cua-driver-linux-parallel-drag-gif
-# (re-add the flake check + matrix entry to run it where a real Xorg works).
-#
-# Pilots cua-driver through its Linux MPX `parallel_mouse_drag` path: two
-# per-session master pointers drawing concurrent strokes into the SAME window,
-# while a separate control window keeps the input focus. Proves the three
-# guarantees the feature is built on:
-#
-# 1. Concurrent delivery — both masters' presses/motions/releases reach the
-# target window as cooked, window-targeted XI2 events (an XI2 paint app
-# logs every event with its device id; we assert two distinct devices).
-# 2. No focus steal — the "shield grab" keeps the window manager blind to
-# the presses, so the control window stays active throughout.
-# 3. Pixel-exact endpoints — the recorded GIF shows two crossing strokes.
-#
-# Unlike the other Linux visual tests, this one needs a REAL Xorg server, not
-# Xvfb: the MPX path attaches uinput slave devices to per-session master
-# pointers, and only a real Xorg with the libinput input driver enumerates
-# uinput devices as X input devices (Xvfb — like the old Xtigervnc setup —
-# does not). So we launch Xorg with the `dummy` video driver + libinput, with
-# the `uinput` kernel module loaded.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-linux-parallel-drag-gif
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- # XI2 paint + event logger. Selects XI2 events for ALL master devices on its
- # own window and, for each ButtonPress/Motion/ButtonRelease, appends a line
- # "<KIND> dev=<id> x=<> y=<>" to a log file and paints a square (per-device
- # colour). The log is what proves cooked, window-delivered, multi-device
- # input — not just raw motion. Prints "READY 0x<xid>" on stdout at startup.
- xi2paintSrc = pkgs.writeText "xi2paint.c" ''
- #include <X11/Xlib.h>
- #include <X11/extensions/XInput2.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int main(int argc, char **argv) {
- const char *logpath = argc > 1 ? argv[1] : "/tmp/xi2paint-events.log";
- Display *dpy = XOpenDisplay(NULL);
- if (!dpy) { fprintf(stderr, "no display\n"); return 1; }
- int xi_opcode, ev, err;
- if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &ev, &err)) {
- fprintf(stderr, "no XInputExtension\n"); return 1;
- }
- int major = 2, minor = 3;
- XIQueryVersion(dpy, &major, &minor);
-
- int scr = DefaultScreen(dpy);
- Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 40, 40, 800, 600,
- 1, BlackPixel(dpy, scr), WhitePixel(dpy, scr));
- XStoreName(dpy, win, "XI2 MPX Paint");
- XSelectInput(dpy, win, ExposureMask);
-
- unsigned char mask[XIMaskLen(XI_LASTEVENT)];
- memset(mask, 0, sizeof mask);
- XISetMask(mask, XI_ButtonPress);
- XISetMask(mask, XI_Motion);
- XISetMask(mask, XI_ButtonRelease);
- XISetMask(mask, XI_Enter);
- XISetMask(mask, XI_FocusIn);
- XIEventMask em;
- em.deviceid = XIAllMasterDevices;
- em.mask_len = sizeof mask;
- em.mask = mask;
- XISelectEvents(dpy, win, &em, 1);
- XMapWindow(dpy, win);
- XFlush(dpy);
- GC gc = XCreateGC(dpy, win, 0, NULL);
-
- FILE *logf = fopen(logpath, "w");
- if (!logf) { fprintf(stderr, "cannot open log\n"); return 1; }
- setvbuf(logf, NULL, _IOLBF, 0);
- printf("READY 0x%lx\n", win); fflush(stdout);
- fprintf(logf, "READY 0x%lx\n", win);
-
- int down[256]; memset(down, 0, sizeof down);
- unsigned long colors[] = { 0xd00000, 0x0040d0, 0x00a000, 0xc08000 };
- for (;;) {
- XEvent e;
- XNextEvent(dpy, &e);
- if (e.type == GenericEvent && e.xcookie.extension == xi_opcode &&
- XGetEventData(dpy, &e.xcookie)) {
- int t = e.xcookie.evtype;
- if (t == XI_ButtonPress || t == XI_Motion || t == XI_ButtonRelease) {
- XIDeviceEvent *de = e.xcookie.data;
- const char *n = t == XI_ButtonPress ? "PRESS"
- : t == XI_Motion ? "MOTION" : "RELEASE";
- fprintf(logf, "%s dev=%d x=%.0f y=%.0f\n",
- n, de->deviceid, de->event_x, de->event_y);
- int d = de->deviceid & 255;
- if (t == XI_ButtonPress) down[d] = 1;
- if (t == XI_ButtonRelease) down[d] = 0;
- if ((t == XI_Motion && down[d]) || t == XI_ButtonPress) {
- XSetForeground(dpy, gc, colors[de->deviceid % 4]);
- XFillRectangle(dpy, win, gc, (int)de->event_x - 3,
- (int)de->event_y - 3, 6, 6);
- XFlush(dpy);
- }
- } else if (t == XI_Enter || t == XI_FocusIn) {
- XIEnterEvent *ee = e.xcookie.data;
- fprintf(logf, "%s dev=%d\n", t == XI_Enter ? "ENTER" : "FOCUSIN",
- ee->deviceid);
- }
- XFreeEventData(dpy, &e.xcookie);
- }
- }
- return 0;
- }
- '';
-
- xi2paint = pkgs.runCommandCC "xi2paint" {
- buildInputs = [ pkgs.xorg.libX11 pkgs.xorg.libXi ];
- } ''
- mkdir -p $out/bin
- cc -O2 -o $out/bin/xi2paint ${xi2paintSrc} -lX11 -lXi
- '';
-
- # Real Xorg config: dummy video driver (software framebuffer) + libinput
- # input hotplug so cua-driver's uinput slaves get enumerated as X devices.
- xorgConf = pkgs.writeText "xorg-dummy.conf" ''
- Section "ServerFlags"
- Option "AutoAddDevices" "true"
- Option "AutoEnableDevices" "true"
- Option "DontVTSwitch" "true"
- EndSection
- Section "Device"
- Identifier "dummy"
- Driver "dummy"
- VideoRam 256000
- EndSection
- Section "Monitor"
- Identifier "mon"
- HorizSync 30.0 - 1000.0
- VertRefresh 30.0 - 200.0
- Modeline "1280x1024" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync
- EndSection
- Section "Screen"
- Identifier "screen"
- Device "dummy"
- Monitor "mon"
- DefaultDepth 24
- SubSection "Display"
- Depth 24
- Modes "1280x1024"
- EndSubSection
- EndSection
- '';
-
- # Manually-launched Xorg needs an explicit module path covering the server's
- # own modules plus the separately-packaged dummy video + libinput drivers.
- xorgModulePath = lib.concatStringsSep "," [
- "${pkgs.xorg.xorgserver}/lib/xorg/modules"
- "${pkgs.xorg.xf86videodummy}/lib/xorg/modules/drivers"
- "${pkgs.xorg.xf86inputlibinput}/lib/xorg/modules/input"
- ];
-
- mcpDragTest = pkgs.writeText "mcp-parallel-drag-test.py" ''
- import json
- import os
- import subprocess
- import sys
- import threading
- import time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
-
- threading.Thread(target=drain_stderr, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode())
- proc.stdin.flush()
-
- def recv(proc, timeout=30):
- result = [None]
-
- def reader():
- result[0] = proc.stdout.readline()
-
- thread = threading.Thread(target=reader)
- thread.start()
- thread.join(timeout)
- if thread.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("Driver returned an empty response")
- return json.loads(line)
-
- def call_tool(proc, req_id, name, arguments, timeout=60):
- send(proc, "tools/call", {"name": name, "arguments": arguments}, req_id=req_id)
- resp = recv(proc, timeout=timeout)
- if "error" in resp and resp["error"] is not None:
- raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"):
- raise RuntimeError(f"{name} returned isError: {resp}")
- return resp
-
- def main():
- with open("/tmp/paint-xid.txt", "r", encoding="utf-8") as f:
- window_id = int(f.readline().strip())
-
- proc = start_driver()
- try:
- send(proc, "initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-parallel-drag-test", "version": "1.0.0"},
- }, req_id=1)
- recv(proc)
- send(proc, "notifications/initialized", {})
- time.sleep(0.3)
-
- # Two concurrent strokes forming the left half of an "X" with two
- # cursors, into a window that does NOT hold focus.
- call_tool(proc, 2, "parallel_mouse_drag", {"drags": [
- {"session": "agent-1", "window_id": window_id,
- "from_x": 100.0, "from_y": 100.0, "to_x": 380.0, "to_y": 420.0,
- "duration_ms": 2500, "steps": 80},
- {"session": "agent-2", "window_id": window_id,
- "from_x": 700.0, "from_y": 100.0, "to_x": 420.0, "to_y": 420.0,
- "duration_ms": 2500, "steps": 80},
- ]})
- time.sleep(0.6)
-
- # Second pass completes both "X" shapes.
- call_tool(proc, 3, "parallel_mouse_drag", {"drags": [
- {"session": "agent-1", "window_id": window_id,
- "from_x": 100.0, "from_y": 420.0, "to_x": 380.0, "to_y": 120.0,
- "duration_ms": 2500, "steps": 80},
- {"session": "agent-2", "window_id": window_id,
- "from_x": 700.0, "from_y": 420.0, "to_x": 420.0, "to_y": 120.0,
- "duration_ms": 2500, "steps": 80},
- ]})
- time.sleep(0.6)
- print("parallel drag test complete", flush=True)
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-linux-parallel-drag-gif-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- {
- pkgs,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 2048;
- };
- services.cua-driver.enable = true;
- # The MPX path opens /dev/uinput and relies on Xorg+libinput enumerating
- # the resulting devices, so the uinput module must be present.
- boot.kernelModules = [ "uinput" ];
- environment.systemPackages = with pkgs; [
- xorg.xorgserver
- xorg.xf86videodummy
- xorg.xf86inputlibinput
- xorg.xinput
- xi2paint
- xterm
- openbox
- picom
- xdotool
- imagemagick
- python3
- jq
- procps
- ];
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
- machine.succeed("modprobe uinput && test -e /dev/uinput")
-
- with subtest("Start a real Xorg (dummy video + libinput) and a WM"):
- machine.execute(
- "Xorg :99 -ac -noreset -keeptty -nolisten tcp "
- "-config ${xorgConf} -modulepath ${xorgModulePath} "
- "-logfile /tmp/xorg.log >/tmp/xorg.out 2>&1 &"
- )
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=30)
- machine.wait_until_succeeds("DISPLAY=:99 xdpyinfo >/dev/null 2>&1", timeout=30)
- machine.execute("DISPLAY=:99 openbox >/tmp/openbox.log 2>&1 &")
- machine.execute("DISPLAY=:99 picom --backend xrender >/tmp/picom.log 2>&1 &")
-
- with subtest("Launch the XI2 paint target and a control window that holds focus"):
- machine.execute(
- "sh -lc \"DISPLAY=:99 xi2paint /tmp/xi2paint-events.log >/tmp/paint.log 2>&1 & echo \\$! >/tmp/paint-pid.txt\""
- )
- machine.execute(
- "sh -lc \"DISPLAY=:99 xterm -T 'Control' -fa Monospace -fs 14 -geometry 50x12+980+120 >/tmp/control.log 2>&1 & echo \\$! >/tmp/control-pid.txt\""
- )
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --name 'XI2 MPX Paint' >/tmp/paint-xid.txt", timeout=20)
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --sync --pid $(cat /tmp/control-pid.txt) >/tmp/control-xid.txt", timeout=20)
- # Give input focus to the CONTROL window — the drags target the paint
- # window, which must never steal it.
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(head -1 /tmp/control-xid.txt)")
- machine.succeed("DISPLAY=:99 xdotool windowfocus --sync $(head -1 /tmp/control-xid.txt)")
-
- with subtest("Record GIF and pilot cua-driver through parallel_mouse_drag"):
- machine.copy_from_host("${mcpDragTest}", "/tmp/mcp-parallel-drag-test.py")
- machine.execute(
- "sh -lc '${recordGifScript} :99 /tmp/drag-frames /tmp/cua-driver-linux-parallel-drag.gif "
- "/tmp/stop-drag-recorder /tmp/ffmpeg-drag.log 8 0.12 >/dev/null 2>&1 & echo $! >/tmp/ffmpeg-drag.pid'"
- )
- result = machine.succeed("timeout 90 env DISPLAY=:99 python3 /tmp/mcp-parallel-drag-test.py 2>&1")
- machine.log(result)
- assert "parallel drag test complete" in result, result
- machine.succeed("touch /tmp/stop-drag-recorder")
- machine.wait_until_succeeds("! kill -0 $(cat /tmp/ffmpeg-drag.pid) 2>/dev/null", timeout=60)
- machine.log(machine.succeed("sh -lc 'cat /tmp/ffmpeg-drag.log || true'"))
-
- with subtest("Both cursors delivered cooked, window-targeted events"):
- machine.log(machine.succeed("cat /tmp/xi2paint-events.log"))
- # Four presses total (two strokes x two cursors).
- machine.succeed("test \"$(grep -c '^PRESS ' /tmp/xi2paint-events.log)\" -eq 4")
- # From two DISTINCT master pointer devices — i.e. genuinely concurrent
- # multi-cursor input, not one pointer reused.
- distinct = machine.succeed(
- "grep '^PRESS ' /tmp/xi2paint-events.log | sed -n 's/.*dev=\\([0-9]*\\).*/\\1/p' | sort -u | wc -l"
- ).strip()
- assert int(distinct) == 2, f"expected 2 distinct devices, got {distinct}"
- machine.succeed("test \"$(grep -c '^MOTION ' /tmp/xi2paint-events.log)\" -ge 4")
-
- with subtest("The drags did not steal focus from the control window"):
- active = machine.succeed("DISPLAY=:99 xdotool getactivewindow").strip()
- control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- assert active == control, f"focus stolen: active={active} control={control}"
-
- with subtest("GIF artifact exists"):
- machine.succeed("test -s /tmp/cua-driver-linux-parallel-drag.gif")
-
- with subtest("Copy GIF out of the VM"):
- machine.copy_from_machine("/tmp/cua-driver-linux-parallel-drag.gif", "")
- '';
-}
diff --git a/nix/cua-driver/tests/linux-parallel-drag-xserver.nix b/nix/cua-driver/tests/linux-parallel-drag-xserver.nix
deleted file mode 100644
index f812ca5482..0000000000
--- a/nix/cua-driver/tests/linux-parallel-drag-xserver.nix
+++ /dev/null
@@ -1,314 +0,0 @@
-# Linux parallel multi-cursor drag test — real Xorg via services.xserver
-#
-# A CI-viable rewrite of linux-parallel-drag-gif.nix. The MPX path needs a
-# REAL Xorg with the libinput input backend so cua-driver's uinput slaves
-# enumerate as X input devices (Xvfb can't; a hand-launched Xorg couldn't get
-# a VT/seat in the emulated nixos-test VM and timed out). Here NixOS's
-# services.xserver brings up Xorg properly on a seat via a display manager,
-# with the `dummy` video driver (software framebuffer, headless) and libinput.
-# A normal user is auto-logged-in to an icewm session; the session runs
-# `xhost +local:` so the root-run test driver / cua-driver can connect to :0.
-#
-# Proves: two per-session master pointers draw concurrent cooked, window-
-# targeted XI2 events into one window (assert 2 distinct devices), the shield
-# grab keeps focus on a separate control window, and a GIF is produced.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-linux-parallel-drag-xserver
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- # XI2 paint + event logger (selects XI2 for all master devices; logs each
- # press/motion/release with its device id and paints per-device squares).
- xi2paintSrc = pkgs.writeText "xi2paint.c" ''
- #include <X11/Xlib.h>
- #include <X11/extensions/XInput2.h>
- #include <stdio.h>
- #include <string.h>
-
- int main(int argc, char **argv) {
- const char *logpath = argc > 1 ? argv[1] : "/tmp/xi2paint-events.log";
- Display *dpy = XOpenDisplay(NULL);
- if (!dpy) { fprintf(stderr, "no display\n"); return 1; }
- int xi_opcode, ev, err;
- if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &ev, &err)) {
- fprintf(stderr, "no XInputExtension\n"); return 1;
- }
- int major = 2, minor = 3;
- XIQueryVersion(dpy, &major, &minor);
- int scr = DefaultScreen(dpy);
- Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 40, 40, 800, 600,
- 1, BlackPixel(dpy, scr), WhitePixel(dpy, scr));
- XStoreName(dpy, win, "XI2 MPX Paint");
- XSelectInput(dpy, win, ExposureMask);
- unsigned char mask[XIMaskLen(XI_LASTEVENT)];
- memset(mask, 0, sizeof mask);
- XISetMask(mask, XI_ButtonPress);
- XISetMask(mask, XI_Motion);
- XISetMask(mask, XI_ButtonRelease);
- XIEventMask em;
- em.deviceid = XIAllMasterDevices;
- em.mask_len = sizeof mask;
- em.mask = mask;
- XISelectEvents(dpy, win, &em, 1);
- XMapWindow(dpy, win);
- XFlush(dpy);
- GC gc = XCreateGC(dpy, win, 0, NULL);
- FILE *logf = fopen(logpath, "w");
- if (!logf) { fprintf(stderr, "cannot open log\n"); return 1; }
- setvbuf(logf, NULL, _IOLBF, 0);
- printf("READY 0x%lx\n", win); fflush(stdout);
- int down[256]; memset(down, 0, sizeof down);
- unsigned long colors[] = { 0xd00000, 0x0040d0, 0x00a000, 0xc08000 };
- for (;;) {
- XEvent e;
- XNextEvent(dpy, &e);
- if (e.type == GenericEvent && e.xcookie.extension == xi_opcode &&
- XGetEventData(dpy, &e.xcookie)) {
- int t = e.xcookie.evtype;
- if (t == XI_ButtonPress || t == XI_Motion || t == XI_ButtonRelease) {
- XIDeviceEvent *de = e.xcookie.data;
- const char *n = t == XI_ButtonPress ? "PRESS"
- : t == XI_Motion ? "MOTION" : "RELEASE";
- fprintf(logf, "%s dev=%d x=%.0f y=%.0f\n",
- n, de->deviceid, de->event_x, de->event_y);
- int d = de->deviceid & 255;
- if (t == XI_ButtonPress) down[d] = 1;
- if (t == XI_ButtonRelease) down[d] = 0;
- if ((t == XI_Motion && down[d]) || t == XI_ButtonPress) {
- XSetForeground(dpy, gc, colors[de->deviceid % 4]);
- XFillRectangle(dpy, win, gc, (int)de->event_x - 3,
- (int)de->event_y - 3, 6, 6);
- XFlush(dpy);
- }
- }
- XFreeEventData(dpy, &e.xcookie);
- }
- }
- return 0;
- }
- '';
-
- xi2paint = pkgs.runCommandCC "xi2paint" {
- buildInputs = [ pkgs.xorg.libX11 pkgs.xorg.libXi ];
- } ''
- mkdir -p $out/bin
- cc -O2 -o $out/bin/xi2paint ${xi2paintSrc} -lX11 -lXi
- '';
-
- mcpDragTest = pkgs.writeText "mcp-parallel-drag-test.py" ''
- import json, os, subprocess, sys, threading, time
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def start_driver():
- proc = subprocess.Popen([DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={**os.environ})
- def drain():
- for line in proc.stderr:
- sys.stderr.buffer.write(line); sys.stderr.buffer.flush()
- threading.Thread(target=drain, daemon=True).start()
- return proc
-
- def send(proc, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None: msg["params"] = params
- if req_id is not None: msg["id"] = req_id
- proc.stdin.write((json.dumps(msg) + "\n").encode()); proc.stdin.flush()
-
- def recv(proc, timeout=30):
- result = [None]
- def reader(): result[0] = proc.stdout.readline()
- th = threading.Thread(target=reader); th.start(); th.join(timeout)
- if th.is_alive(): raise TimeoutError("no response")
- line = result[0].decode().strip()
- if not line: raise RuntimeError("empty response")
- return json.loads(line)
-
- def call_tool(proc, rid, name, args, timeout=60):
- send(proc, "tools/call", {"name": name, "arguments": args}, req_id=rid)
- resp = recv(proc, timeout=timeout)
- if resp.get("error"): raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"): raise RuntimeError(f"{name} isError: {resp}")
- return resp
-
- def main():
- with open("/tmp/paint-xid.txt") as f:
- wid = int(f.readline().strip())
- proc = start_driver()
- try:
- send(proc, "initialize", {"protocolVersion": "2024-11-05", "capabilities": {},
- "clientInfo": {"name": "nixos-parallel-drag-xserver", "version": "1.0.0"}}, req_id=1)
- recv(proc); send(proc, "notifications/initialized", {}); time.sleep(0.3)
- # Two concurrent strokes (one per cursor) into an UNFOCUSED window;
- # each is a single held-path drag (press once, glide, release once).
- call_tool(proc, 2, "parallel_mouse_drag", {"drags": [
- {"session": "agent-1", "window_id": wid, "from_x": 100.0, "from_y": 100.0, "to_x": 380.0, "to_y": 420.0, "duration_ms": 2200, "steps": 80},
- {"session": "agent-2", "window_id": wid, "from_x": 700.0, "from_y": 100.0, "to_x": 420.0, "to_y": 420.0, "duration_ms": 2200, "steps": 80},
- ]})
- time.sleep(0.6)
- call_tool(proc, 3, "parallel_mouse_drag", {"drags": [
- {"session": "agent-1", "window_id": wid, "from_x": 100.0, "from_y": 420.0, "to_x": 380.0, "to_y": 120.0, "duration_ms": 2200, "steps": 80},
- {"session": "agent-2", "window_id": wid, "from_x": 700.0, "from_y": 420.0, "to_x": 420.0, "to_y": 120.0, "duration_ms": 2200, "steps": 80},
- ]})
- time.sleep(0.6)
- print("parallel drag test complete", flush=True)
- finally:
- proc.stdin.close(); proc.terminate(); proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-linux-parallel-drag-xserver-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 2048;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- # Root opens /dev/uinput directly; the group rule is belt-and-suspenders.
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
-
- # Real Xorg on a seat (DM handles the VT), dummy video, libinput input.
- services.xserver = {
- enable = true;
- videoDrivers = [ "dummy" ];
- deviceSection = ''VideoRam 256000'';
- monitorSection = ''
- HorizSync 30.0 - 1000.0
- VertRefresh 30.0 - 200.0
- Modeline "1280x1024" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync
- '';
- screenSection = ''
- DefaultDepth 24
- SubSection "Display"
- Depth 24
- Modes "1280x1024"
- Virtual 1280 1024
- EndSubSection
- '';
- windowManager.icewm.enable = true;
- # A display manager is what actually starts Xorg on a seat/VT — the bit
- # the hand-launched Xorg couldn't arrange in the emulated VM. lightdm is
- # the lightest. (lightdm.enable still lives under xserver.displayManager;
- # autoLogin/defaultSession moved to the top-level services.displayManager.)
- displayManager.lightdm.enable = true;
- # Disable X access control outright: this is a throwaway single-user
- # test VM, and the root-run cua-driver / clients must reach :0. Relying
- # on the session's `xhost +local:` proved unreliable across uids (the
- # server's auth ACL only lists the autologin user), so `-ac` is the
- # bulletproof grant. `xhost +local:` is kept as belt-and-suspenders.
- displayManager.xserverArgs = [ "-ac" ];
- displayManager.sessionCommands = ''
- ${pkgs.xorg.xhost}/bin/xhost +local: || true
- '';
- };
- services.libinput.enable = true;
- services.displayManager = {
- defaultSession = "none+icewm";
- autoLogin = {
- enable = true;
- user = "cua";
- };
- };
- users.users.cua = {
- isNormalUser = true;
- extraGroups = [ "input" ];
- };
-
- environment.systemPackages = with pkgs; [
- xorg.xinput
- xorg.xhost
- xorg.xdpyinfo # the :0 connectivity probe in the test script
- xi2paint
- xterm
- xdotool
- imagemagick
- python3
- jq
- procps
- ];
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
- machine.succeed("modprobe uinput && test -e /dev/uinput")
-
- with subtest("Real Xorg up via the display manager"):
- try:
- machine.wait_for_x()
- # With `-ac` the root-run clients can connect to :0 immediately.
- machine.wait_until_succeeds("DISPLAY=:0 xdpyinfo >/dev/null 2>&1", timeout=30)
- except Exception:
- # Diagnostics: surface why X/lightdm did not come up or why root
- # can't reach :0, so we don't burn a CI round-trip guessing.
- machine.log(machine.execute("systemctl status display-manager.service --no-pager || true")[1])
- machine.log(machine.execute("journalctl -u display-manager.service --no-pager | tail -n 200 || true")[1])
- machine.log(machine.execute("ls -la /tmp/.X11-unix/ || true")[1])
- machine.log(machine.execute("cat /var/log/X.0.log 2>/dev/null | tail -n 200 || true")[1])
- machine.log(machine.execute("find / -name 'Xorg.0.log' 2>/dev/null | head; cat $(find / -name 'Xorg.0.log' 2>/dev/null | head -1) 2>/dev/null | tail -n 120 || true")[1])
- raise
- machine.log(machine.succeed("DISPLAY=:0 xinput list --short || true"))
-
- with subtest("Launch XI2 paint target + a control window that holds focus"):
- machine.execute(
- "sh -lc \"DISPLAY=:0 xi2paint /tmp/xi2paint-events.log >/tmp/paint.log 2>&1 & echo \\$! >/tmp/paint-pid.txt\""
- )
- machine.execute(
- "sh -lc \"DISPLAY=:0 xterm -T 'Control' -fa Monospace -fs 14 -geometry 50x12+980+120 >/tmp/control.log 2>&1 & echo \\$! >/tmp/control-pid.txt\""
- )
- machine.wait_until_succeeds("DISPLAY=:0 xdotool search --sync --name 'XI2 MPX Paint' >/tmp/paint-xid.txt", timeout=20)
- machine.wait_until_succeeds("DISPLAY=:0 xdotool search --sync --pid $(cat /tmp/control-pid.txt) >/tmp/control-xid.txt", timeout=20)
- machine.succeed("DISPLAY=:0 xdotool windowactivate --sync $(head -1 /tmp/control-xid.txt)")
- machine.succeed("DISPLAY=:0 xdotool windowfocus --sync $(head -1 /tmp/control-xid.txt)")
-
- with subtest("Record GIF and pilot cua-driver through parallel_mouse_drag"):
- machine.copy_from_host("${mcpDragTest}", "/tmp/mcp-parallel-drag-test.py")
- machine.execute(
- "sh -lc '${recordGifScript} :0 /tmp/drag-frames /tmp/cua-driver-linux-parallel-drag-xserver.gif "
- "/tmp/stop-drag-recorder /tmp/ffmpeg-drag.log 8 0.12 >/dev/null 2>&1 & echo $! >/tmp/ffmpeg-drag.pid'"
- )
- result = machine.succeed("timeout 90 env DISPLAY=:0 python3 /tmp/mcp-parallel-drag-test.py 2>&1")
- machine.log(result)
- assert "parallel drag test complete" in result, result
- machine.succeed("touch /tmp/stop-drag-recorder")
- machine.wait_until_succeeds("! kill -0 $(cat /tmp/ffmpeg-drag.pid) 2>/dev/null", timeout=60)
-
- with subtest("Both cursors delivered cooked, window-targeted events"):
- machine.log(machine.succeed("cat /tmp/xi2paint-events.log"))
- machine.succeed("test \"$(grep -c '^PRESS ' /tmp/xi2paint-events.log)\" -eq 4")
- distinct = machine.succeed(
- "grep '^PRESS ' /tmp/xi2paint-events.log | sed -n 's/.*dev=\\([0-9]*\\).*/\\1/p' | sort -u | wc -l"
- ).strip()
- assert int(distinct) == 2, f"expected 2 distinct devices, got {distinct}"
- machine.succeed("test \"$(grep -c '^MOTION ' /tmp/xi2paint-events.log)\" -ge 4")
-
- with subtest("The drags did not steal focus from the control window"):
- active = machine.succeed("DISPLAY=:0 xdotool getactivewindow").strip()
- control = machine.succeed("head -1 /tmp/control-xid.txt").strip()
- assert active == control, f"focus stolen: active={active} control={control}"
-
- with subtest("GIF artifact exists"):
- machine.succeed("test -s /tmp/cua-driver-linux-parallel-drag-xserver.gif")
-
- with subtest("Copy GIF out of the VM"):
- machine.copy_from_machine("/tmp/cua-driver-linux-parallel-drag-xserver.gif", "")
- '';
-}
diff --git a/nix/cua-driver/tests/openbox-rc.nix b/nix/cua-driver/tests/openbox-rc.nix
deleted file mode 100644
index 5ca8b439d1..0000000000
--- a/nix/cua-driver/tests/openbox-rc.nix
+++ /dev/null
@@ -1,29 +0,0 @@
-# Shared openbox config for the X11 GUI tests.
-#
-# Returns an openbox rc.xml whose only non-default setting is
-# `<focus><focusNew>no</focusNew></focus>`: openbox must NOT auto-focus a
-# window when it is first mapped. Everything else falls back to openbox's
-# built-in defaults (missing nodes are defaulted by the parser).
-#
-# Why: the background-GUI tests launch a real app (chromium/electron) in the
-# background while a control terminal stays focused, then assert focus never
-# left the control terminal. Under the faster container backend, chromium-based
-# apps finish loading and map/raise their toplevel mid-test; with the default
-# `focusNew=yes` openbox would shift X input focus to the freshly-mapped window
-# and break that invariant. Explicit `xdotool windowactivate` requests are user
-# actions and are still honoured, so the control terminal is still focusable.
-#
-# Usage (in a test's `let`):
-# openboxRc = import ./openbox-rc.nix { inherit pkgs; };
-# then launch openbox with it:
-# openbox --config-file ${openboxRc}
-{ pkgs }:
-
-pkgs.writeText "openbox-rc.xml" ''
- <?xml version="1.0" encoding="UTF-8"?>
- <openbox_config xmlns="http://openbox.org/3.4/rc">
- <focus>
- <focusNew>no</focusNew>
- </focus>
- </openbox_config>
-''
diff --git a/nix/cua-driver/tests/record-x11-gif.nix b/nix/cua-driver/tests/record-x11-gif.nix
deleted file mode 100644
index 81a49a9001..0000000000
--- a/nix/cua-driver/tests/record-x11-gif.nix
+++ /dev/null
@@ -1,49 +0,0 @@
-# Shared X11 screen-recording helper for the Linux visual (GIF) tests.
-#
-# Returns a `pkgs.writeShellScript` that loops `import -display <display>
-# -window root frame-XXXX.png` until a stop-file appears, then stitches the
-# frames into an animated GIF with `convert`. Both tools come from
-# `pkgs.imagemagick`, which the importing test must add to
-# `environment.systemPackages`.
-#
-# Usage (in a test's `let`):
-# recordGifScript = import ./record-x11-gif.nix { inherit pkgs; };
-# then, inside the testScript, start it in the background before driving and
-# `touch` the stop-file afterwards:
-# ${recordGifScript} <display> <frames_dir> <output_gif> <stop_file> \
-# <log_file> <delay_cs> <interval>
-{ pkgs }:
-
-pkgs.writeShellScript "record-x11-gif.sh" ''
- set -eu
- display="$1"
- frames_dir="$2"
- output_gif="$3"
- stop_file="$4"
- log_file="$5"
- delay_cs="$6"
- interval="$7"
-
- rm -f "$stop_file" "$output_gif" "$log_file"
- rm -rf "$frames_dir"
- mkdir -p "$frames_dir"
-
- # Cap the frame count: long driver runs (the skeleton budget is 300s) can
- # otherwise pile up 1000+ frames and the final `convert` thrashes/OOMs the
- # test container, wedging every later command in the job. 450 frames is a ~45s
- # GIF at the default cadence — plenty. Each `import` and the final `convert`
- # are also time-bounded so a wedged X grab or a slow stitch can't stall the
- # job.
- max_frames=450
- i=0
- while [ ! -f "$stop_file" ] && [ "$i" -lt "$max_frames" ]; do
- frame=$(printf "%s/frame-%04d.png" "$frames_dir" "$i")
- timeout 10 import -display "$display" -window root "$frame" >>"$log_file" 2>&1 || true
- i=$((i + 1))
- sleep "$interval"
- done
-
- if ls "$frames_dir"/frame-*.png >/dev/null 2>&1; then
- timeout 120 convert -delay "$delay_cs" -loop 0 "$frames_dir"/frame-*.png "$output_gif" >>"$log_file" 2>&1 || true
- fi
-''
diff --git a/nix/cua-driver/tests/screenshot.nix b/nix/cua-driver/tests/screenshot.nix
deleted file mode 100644
index 695983e407..0000000000
--- a/nix/cua-driver/tests/screenshot.nix
+++ /dev/null
@@ -1,265 +0,0 @@
-# CUA Driver Screenshot Test
-#
-# Runs the integration test and then uses cua-driver's own get_window_state
-# tool to capture a screenshot of an xterm window via MCP. The screenshot
-# is extracted as a PNG from the base64 MCP response and copied out of the
-# container.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-screenshot
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- # Python MCP client that runs the integration tests and then uses
- # cua-driver to screenshot an xterm window via get_window_state.
- mcpScreenshotTest = pkgs.writeText "mcp-screenshot-test.py" ''
- import subprocess
- import json
- import sys
- import os
- import threading
- import time
- import base64
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def main():
- print("=== CUA Driver Screenshot Test ===", flush=True)
-
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
- t = threading.Thread(target=drain_stderr, daemon=True)
- t.start()
-
- next_id = [0]
- def send_request(method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- line = json.dumps(msg) + "\n"
- print(f"[send] {method}", flush=True)
- proc.stdin.write(line.encode())
- proc.stdin.flush()
-
- def read_response(timeout=30):
- result = [None]
- def reader():
- result[0] = proc.stdout.readline()
- rt = threading.Thread(target=reader)
- rt.start()
- rt.join(timeout)
- if rt.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- if len(line) > 500:
- print(f"[recv] {line[:200]}...({len(line)} bytes)", flush=True)
- else:
- print(f"[recv] {line}", flush=True)
- return json.loads(line)
-
- try:
- # Initialize
- print("\n--- Initialize ---", flush=True)
- send_request("initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-screenshot-test", "version": "1.0.0"},
- }, req_id=1)
- resp = read_response()
- assert "result" in resp, f"Initialize failed: {resp}"
- print("PASS: initialize", flush=True)
-
- send_request("notifications/initialized", {})
- time.sleep(0.5)
-
- # List tools
- print("\n--- tools/list ---", flush=True)
- send_request("tools/list", {}, req_id=2)
- resp = read_response()
- tools = resp.get("result", {}).get("tools", [])
- tool_names = [t["name"] for t in tools]
- assert "get_window_state" in tool_names, f"get_window_state missing"
- assert "list_windows" in tool_names, f"list_windows missing"
- print(f"PASS: {len(tools)} tools", flush=True)
-
- # Read xterm window ID and PID from files saved by the test setup
- pid = None
- window_id = None
- try:
- with open("/tmp/xterm-xid.txt") as f:
- window_id = int(f.read().strip().split("\n")[0])
- with open("/tmp/xterm-pid.txt") as f:
- pid = int(f.read().strip().split("\n")[0])
- print(f"Found xterm window: pid={pid} window_id={window_id}", flush=True)
- except Exception as e:
- print(f"ERROR: Could not read window info: {e}", flush=True)
-
- if pid is not None and window_id is not None:
- # Use get_window_state with capture_mode=vision to get screenshot
- print(f"\n--- get_window_state (vision) pid={pid} window_id={window_id} ---", flush=True)
- send_request("tools/call", {
- "name": "get_window_state",
- "arguments": {
- "pid": pid,
- "window_id": window_id,
- "capture_mode": "vision",
- },
- }, req_id=5)
- resp = read_response(timeout=30)
-
- # Extract base64 image from response
- content = resp.get("result", {}).get("content", [])
- screenshot_saved = False
- for item in content:
- if item.get("type") == "image":
- img_data = item.get("data", "")
- if img_data:
- img_bytes = base64.b64decode(img_data)
- with open("/tmp/cua-driver-screenshot.png", "wb") as f:
- f.write(img_bytes)
- print(f"PASS: Screenshot saved ({len(img_bytes)} bytes)", flush=True)
- screenshot_saved = True
- break
- elif item.get("type") == "text":
- text = item.get("text", "")
- # Check if text contains base64 image data
- if "base64" in text.lower() or len(text) > 1000:
- print(f"Text content (may contain image ref): {text[:200]}", flush=True)
-
- if not screenshot_saved:
- print(f"WARN: No image in response, saving raw response", flush=True)
- with open("/tmp/cua-driver-response.json", "w") as f:
- json.dump(resp, f, indent=2)
- else:
- print("SKIP: No window found for screenshot", flush=True)
-
- print("\n=== Screenshot test complete ===", flush=True)
-
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
- # Shell script displayed in xterm for a visible window to screenshot
- testPage = pkgs.writeText "test-page.sh" ''
- #!/bin/sh
- cat <<'HEREDOC'
-
- ╔══════════════════════════════════════════════╗
- ║ CUA Driver - NixOS Integration Test ║
- ║ ║
- ║ cua-driver v0.3.2 ║
- ║ MCP server running on Xvfb :99 ║
- ║ 34 tools registered ║
- ║ ║
- ║ All tests passed! ║
- ╚══════════════════════════════════════════════╝
-
- HEREDOC
- sleep infinity
- '';
-
- # openbox config with focusNew=no (see openbox-rc.nix) so the xterm under test
- # keeps X focus when it maps.
- openboxRc = import ./openbox-rc.nix { inherit pkgs; };
-
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-screenshot-test";
- meta = {
- maintainers = [ ];
- };
-
- containers.machine =
- {
- config,
- pkgs,
- lib,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver
- xterm
- openbox # lightweight WM needed for _NET_CLIENT_LIST
- picom # compositing manager so X11 GetImage returns rendered pixels
- xdotool # window ID lookup
- python3
- jq
- procps
- ];
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Binary exists and runs"):
- machine.succeed("cua-driver --help")
-
- with subtest("list-tools prints available tools"):
- result = machine.succeed("cua-driver list-tools")
- assert "click" in result, f"click not in: {result}"
- assert "get_window_state" in result, f"get_window_state not in: {result}"
-
- with subtest("Start Xvfb, window manager, and xterm"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/dev/null 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
- # Start openbox WM so _NET_CLIENT_LIST is populated for list_windows
- machine.execute("DISPLAY=:99 openbox --config-file ${openboxRc} >/dev/null 2>&1 &")
- # Start compositing manager so X11 GetImage returns rendered pixels
- machine.execute("DISPLAY=:99 picom --backend xrender >/dev/null 2>&1 &")
- machine.copy_from_host("${testPage}", "/tmp/test-page.sh")
- machine.succeed("chmod +x /tmp/test-page.sh")
- machine.execute("DISPLAY=:99 xterm -T 'CUA Test' -fa Monospace -fs 14 -geometry 60x20+100+100 -e /tmp/test-page.sh >/dev/null 2>&1 &")
- # Wait for xterm window to appear (poll via xdotool inside the container)
- machine.wait_until_succeeds("DISPLAY=:99 xdotool search --class xterm", timeout=15)
- # Save the xterm window ID and PID for the MCP screenshot test
- machine.succeed("DISPLAY=:99 xdotool search --class xterm | head -1 > /tmp/xterm-xid.txt")
- machine.succeed("pgrep -f 'xterm.*CUA Test' | head -1 > /tmp/xterm-pid.txt")
- # Focus and raise the window so it's fully rendered
- machine.succeed("DISPLAY=:99 xdotool windowactivate --sync $(cat /tmp/xterm-xid.txt)")
- machine.succeed("DISPLAY=:99 xdotool windowfocus --sync $(cat /tmp/xterm-xid.txt)")
-
- with subtest("Screenshot via cua-driver MCP"):
- machine.copy_from_host("${mcpScreenshotTest}", "/tmp/mcp-screenshot-test.py")
- result = machine.succeed(
- "timeout 60 env DISPLAY=:99 "
- "python3 /tmp/mcp-screenshot-test.py 2>&1"
- )
- machine.log(result)
- assert "Screenshot test complete" in result, f"Test did not complete: {result}"
-
- with subtest("Extract screenshot"):
- # Copy screenshot out of the container if it exists
- machine.succeed("test -f /tmp/cua-driver-screenshot.png || test -f /tmp/cua-driver-response.json")
- machine.copy_from_machine("/tmp/cua-driver-screenshot.png", "")
- '';
-}
diff --git a/nix/cua-driver/tests/set-config.nix b/nix/cua-driver/tests/set-config.nix
deleted file mode 100644
index ef4cd84862..0000000000
--- a/nix/cua-driver/tests/set-config.nix
+++ /dev/null
@@ -1,185 +0,0 @@
-# CUA Driver set_config Persistence Test
-#
-# Regression test for #1923 (fixed in PR #1928): on Linux the `set_config`
-# tool only read the legacy per-field keys, so a `{"key":..., "value":...}`
-# write (the shape the Swift/macOS and Windows callers send) was silently
-# dropped. This boots a NixOS container, drives the driver over MCP stdio,
-# writes config via the `{key, value}` shape, then reads it back with
-# `get_config` and asserts the new value persisted.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-set-config
-#
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- ...
-}:
-
-let
- # Python MCP client that drives cua-driver over stdio.
- # Writes config via the {key, value} shape, reads it back, asserts.
- setConfigTest = pkgs.writeText "set-config-test.py" ''
- import subprocess
- import json
- import sys
- import os
- import threading
- import time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
- def main():
- print("=== CUA Driver set_config Persistence Test ===", flush=True)
-
- proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env={**os.environ},
- )
-
- # Drain stderr in background to prevent blocking
- def drain_stderr():
- for line in proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
- t = threading.Thread(target=drain_stderr, daemon=True)
- t.start()
-
- def send_request(method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- line = json.dumps(msg) + "\n"
- print(f"[send] {line.strip()}", flush=True)
- proc.stdin.write(line.encode())
- proc.stdin.flush()
-
- def read_response(timeout=30):
- # Simple blocking read with timeout via thread
- result = [None]
- def reader():
- result[0] = proc.stdout.readline()
- rt = threading.Thread(target=reader)
- rt.start()
- rt.join(timeout)
- if rt.is_alive():
- raise TimeoutError("No response within timeout")
- line = result[0].decode().strip()
- print(f"[recv] {line}", flush=True)
- return json.loads(line)
-
- def call_tool(name, arguments, req_id):
- send_request("tools/call", {"name": name, "arguments": arguments}, req_id=req_id)
- resp = read_response()
- assert resp.get("id") == req_id, f"Expected id={req_id}, got {resp.get('id')}"
- assert "result" in resp, f"Expected result in response: {resp}"
- return resp["result"]
-
- def get_config(req_id):
- result = call_tool("get_config", {}, req_id)
- sc = result.get("structuredContent", {})
- assert sc, f"get_config returned no structuredContent: {result}"
- return sc
-
- try:
- # Initialize
- send_request("initialize", {
- "protocolVersion": "2024-11-05",
- "capabilities": {},
- "clientInfo": {"name": "nixos-set-config-test", "version": "1.0.0"},
- }, req_id=1)
- resp = read_response()
- assert resp.get("id") == 1 and "result" in resp, f"initialize failed: {resp}"
- send_request("notifications/initialized", {})
- time.sleep(0.5)
-
- # Baseline: confirm the value we will write differs from the default
- # (max_image_dimension default is 1568), so a passing read-back can
- # only mean the write took effect — not a coincidental default.
- print("\n--- Baseline get_config ---", flush=True)
- before = get_config(2)
- print(f"before: max_image_dimension={before.get('max_image_dimension')} "
- f"capture_mode={before.get('capture_mode')}", flush=True)
- assert before.get("max_image_dimension") != 800, \
- f"baseline already 800; cannot prove persistence: {before}"
-
- # The regression: write via the {key, value} shape (#1923). This is
- # the exact path that was silently dropped on Linux before #1928.
- print("\n--- set_config {key, value} ---", flush=True)
- call_tool("set_config", {"key": "max_image_dimension", "value": 800}, 3)
- call_tool("set_config", {"key": "capture_mode", "value": "ax"}, 4)
-
- # Read back: get_config must reflect the {key, value} writes.
- print("\n--- get_config read-back ---", flush=True)
- after = get_config(5)
- print(f"after: max_image_dimension={after.get('max_image_dimension')} "
- f"capture_mode={after.get('capture_mode')}", flush=True)
- assert after.get("max_image_dimension") == 800, \
- f"set_config {{key,value}} did not persist max_image_dimension: {after}"
- assert after.get("capture_mode") == "ax", \
- f"set_config {{key,value}} did not persist capture_mode: {after}"
-
- print("\n=== set_config persistence test passed! ===", flush=True)
-
- finally:
- proc.stdin.close()
- proc.terminate()
- proc.wait(timeout=5)
-
- if __name__ == "__main__":
- main()
- '';
-
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-set-config-test";
- meta = {
- maintainers = [ ];
- };
-
- containers.machine =
- {
- config,
- pkgs,
- lib,
- ...
- }:
- {
- imports = [ cuaDriverModule ];
- services.cua-driver.enable = true;
- environment.systemPackages = with pkgs; [
- xorg.xorgserver # Xvfb for headless X11
- python3 # MCP client test script
- ];
- };
-
- testScript = ''
- # cache-bust 2026-06-08.1: this comment is part of the test derivation, so
- # bumping it changes the output path and forces the test to actually re-run
- # instead of being substituted from the binary cache. Bump again to re-run.
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Binary exists and runs"):
- machine.succeed("cua-driver --help")
-
- with subtest("Start Xvfb"):
- machine.execute("Xvfb :99 -screen 0 1280x1024x24 >/dev/null 2>&1 &")
- machine.wait_until_succeeds("test -e /tmp/.X11-unix/X99", timeout=10)
-
- with subtest("set_config {key, value} persists and reads back via get_config"):
- machine.copy_from_host("${setConfigTest}", "/tmp/set-config-test.py")
- result = machine.succeed(
- "timeout 60 env DISPLAY=:99 "
- "python3 /tmp/set-config-test.py 2>&1"
- )
- machine.log(result)
- assert "set_config persistence test passed" in result, f"set_config test failed: {result}"
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/README.md b/nix/cua-driver/tests/wayland/README.md
deleted file mode 100644
index 33a01cd6d9..0000000000
--- a/nix/cua-driver/tests/wayland/README.md
+++ /dev/null
@@ -1,67 +0,0 @@
-# cua-driver native-Wayland TDD suite
-
-A reproduction of the cua-driver NixOS tests on **native Wayland**, across five
-desktop sessions. These tests are a **TDD red suite**: the Linux backend is
-X11-only today, so they are **expected to fail** until native Wayland support is
-added. They exist to *specify* that work and to show, per compositor, exactly
-what survives.
-
-## Why they fail today
-
-cua-driver enumerates windows with X11 `_NET_CLIENT_LIST`, captures with
-`import`/`xwd`/XGetImage, and injects input with X11 `XSendEvent` (plus uinput +
-XI2 for the agent cursor / parallel drags). On native Wayland:
-
-- apps are **Wayland clients with no X11 window id**, so `list_windows` returns
- nothing and `find_window` times out;
-- there is no X display to capture or `XSendEvent` into (the tests never set
- `DISPLAY`, so there is no XWayland fallback either).
-
-To make a scenario green you implement the corresponding native-Wayland path in
-`libs/cua-driver/rust/crates/platform-linux` (e.g. a Wayland window enumerator,
-a `grim`/screencopy capture path, and a `wlr-virtual-pointer` /
-`virtual-keyboard` / `libei` input path), then re-run the matching check.
-
-## Layout
-
-- `session.nix` — brings up a chosen desktop headless and exposes the Wayland
- socket. The compositor is the only per-desktop difference.
-- `driver-client.nix` — shared MCP client; window discovery goes **only** through
- cua-driver's own `list_windows` (no xdotool/X11 cheat).
-- `record-wayland-gif.nix` — `grim`-based GIF recorder (wlroots only; no-op
- elsewhere).
-- `integration.nix`, `screenshot.nix`, `cursor-click-gif.nix`,
- `background-terminal-gif.nix`, `parallel-drag.nix`, `background-gui.nix` — the
- scenarios, each parameterised by `desktop` (and `background-gui` also by `app`).
-
-## Matrix
-
-Desktops: `xfce-labwc`, `xfce-sway` (XFCE 4.20's Wayland-session compositors),
-`kde` (kwin_wayland), `gnome` (mutter headless). (`xfce-wayfire` was dropped —
-wayfire fails to build in the current nixpkgs pin, an upstream `wf-config`/
-`doctest` issue unrelated to cua-driver.)
-
-Checks (built on demand):
-
-```
-nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-<scenario>
-nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-background-gui-<app>
-```
-
-Scenarios: `integration`, `screenshot`, `cursor-click-gif`,
-`background-terminal-gif`, `parallel-drag`.
-Background-GUI apps: `foot`, `gtk3-gedit`, `qt6-kcalc`.
-
-`parallel-drag` is the hardest: it needs X11 MPX master pointers, for which there
-is no native Wayland equivalent — keep it red, or redesign around multi-seat /
-virtual-pointer protocols.
-
-## Running in CI
-
-The `.github/workflows/nix-wayland.yml` workflow runs the whole matrix on the
-same triggers as the X11 `nix-build.yml` workflow — PRs and `main` pushes that
-touch `nix/**`, `flake.{nix,lock}`, `libs/cua-driver/rust/**`, or the workflow
-itself, plus manual `workflow_dispatch`. The jobs are BLOCKING: a red cell fails
-the PR, so the suite only goes green once native Wayland support lands. Each job
-uploads its screenshots / GIFs / logs as artifacts so you can see what each
-compositor did.
diff --git a/nix/cua-driver/tests/wayland/background-gui.nix b/nix/cua-driver/tests/wayland/background-gui.nix
deleted file mode 100644
index 0df054f28b..0000000000
--- a/nix/cua-driver/tests/wayland/background-gui.nix
+++ /dev/null
@@ -1,159 +0,0 @@
-# CUA Driver native-Wayland background-GUI skeleton (per desktop, per app) — TDD red.
-#
-# Native-Wayland analogue of the READ-ONLY skeleton class in
-# ../../tests/linux-background-gui.nix. Launches a real toolkit app as a NATIVE
-# Wayland client (no GDK_BACKEND/QT_QPA forcing), finds it via cua-driver
-# list_windows, and screenshots it via get_window_state (vision). Records a GIF
-# via grim. Fails today: the driver can neither enumerate nor capture native
-# Wayland surfaces — the spec for native Wayland read support across toolkits.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-background-gui-<app>
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- app,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
- recordGifScript = import ./record-wayland-gif.nix { inherit pkgs; };
-
- # Representative native-Wayland apps, one per major toolkit. `match` is the
- # identity substring find_window looks for (title/app_id/app/class).
- #
- # NOTE: no per-app env prefix here. Apps are launched via cua-driver's
- # `launch_app`, which execs the command's FIRST token as the program — an
- # `ENV=val cmd` prefix would be (mis)read as the program name. The native
- # Wayland backends (GDK_BACKEND/QT_QPA_PLATFORM) are exported by the session
- # driver wrapper instead (session.nix appBackendEnv), so the launched toolkit
- # apps inherit them. Do not reintroduce an `env` field on these.
- apps = {
- foot = {
- packages = [ pkgs.foot ];
- launch = "foot --app-id=cua-wayland-foot-app --title=cua-wayland-foot-app";
- match = "cua-wayland-foot-app";
- };
- "gtk3-gedit" = {
- packages = [ pkgs.gedit ];
- launch = "gedit";
- match = "gedit";
- };
- "qt6-kcalc" = {
- packages = [ pkgs.kdePackages.kcalc ];
- launch = "kcalc";
- match = "kcalc";
- };
- };
-
- cfg = apps.${app} or (throw "wayland/background-gui.nix: unknown app '${app}'");
- outputGif = "/tmp/cua-driver-wayland-${desktop}-background-gui-${app}.gif";
- outputPng = "/tmp/cua-driver-wayland-${desktop}-background-gui-${app}.png";
-
- # GIF recorder env: native desktops point grim at the host socket; nested
- # desktops leave WAYLAND_DISPLAY unset so the recorder self-resolves the
- # driver's published nested socket ($XDG_RUNTIME_DIR/.cua-nested-display).
- # No quotes around the command substitution: this string is interpolated into
- # a python double-quoted string, and the socket path has no spaces. The inner
- # `sh -c` re-parses and expands $(cat ...) itself.
- recorderWlEnv =
- if session.nested then
- "env XDG_RUNTIME_DIR=/run/user/0"
- else
- "env XDG_RUNTIME_DIR=/run/user/0 WAYLAND_DISPLAY=$(cat /tmp/wl-display)";
-
- testScriptPy = pkgs.writeText "wayland-bg-gui.py" ''
- import base64, sys
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- MATCH = "${cfg.match}"
- OUTPNG = "${outputPng}"
- LAUNCH = "${cfg.launch}"
- d = Driver()
- try:
- d.initialize("nixos-wayland-bg-gui")
- # Launch through cua-driver so the app lands in the session it owns
- # (host compositor on native desktops; nested labwc on kde/gnome).
- d.launch_app(LAUNCH)
- pid, wid = d.find_window(MATCH, timeout=50)
- print(f"app window pid={pid} window_id={wid}", flush=True)
- resp = d.call("get_window_state", {
- "pid": pid, "window_id": wid, "capture_mode": "vision"}, timeout=45)
- saved = False
- for item in resp.get("result", {}).get("content", []):
- if item.get("type") == "image" and item.get("data"):
- with open(OUTPNG, "wb") as f:
- f.write(base64.b64decode(item["data"]))
- saved = True
- break
- assert saved, f"no capture for native Wayland window: {resp}"
- print("background gui read test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-background-gui-${app}-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 4096;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- environment.systemPackages =
- session.packages ++ cfg.packages ++ (with pkgs; [ python3 jq at-spi2-core ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
-
- with subtest("Launch (via cua-driver) + record GIF + read inactive app window"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-bg-gui.py")
- # Start the recorder first; it grabs frames while the driver launches
- # and reads the app. (Native: host socket; nested: self-resolves.)
- machine.execute(
- "sh -lc '${recorderWlEnv} ${recordGifScript} /tmp/bg-gui-frames "
- "${outputGif} /tmp/stop-bg-gui-recorder /tmp/rec-bg-gui.log 12 0.2 "
- ">/dev/null 2>&1 & echo $! >/tmp/rec-bg-gui.pid'"
- )
- result = machine.execute(
- "timeout 150 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-bg-gui.py 2>&1"
- )[1]
- machine.log(result)
- # Stop + copy the GIF BEFORE asserting so even failing jobs upload one.
- machine.execute("touch /tmp/stop-bg-gui-recorder")
- machine.execute("sh -lc 'for i in $(seq 1 60); do kill -0 $(cat /tmp/rec-bg-gui.pid) 2>/dev/null || break; sleep 1; done'")
- machine.execute("test -e ${outputGif} || : > ${outputGif}")
- machine.copy_from_machine("${outputGif}", "")
-
- with subtest("cua-driver read/captured the native Wayland app window"):
- assert "background gui read test complete" in result, result
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/background-terminal-gif.nix b/nix/cua-driver/tests/wayland/background-terminal-gif.nix
deleted file mode 100644
index 871d62d18b..0000000000
--- a/nix/cua-driver/tests/wayland/background-terminal-gif.nix
+++ /dev/null
@@ -1,111 +0,0 @@
-# CUA Driver native-Wayland background-terminal GIF test (per desktop).
-#
-# The hard one: type into an UNFOCUSED window. Stock Wayland delivers keyboard
-# only to the focused surface, so cua-driver nests its own cua-compositor (EIS
-# mode) which injects wl_keyboard straight into a target surface by app_id,
-# bypassing focus. A control terminal is launched AFTER the target so the target
-# is NOT focused; cua-driver types a command into the inactive target and we
-# verify it ran via a file side-effect. Records a GIF via grim.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-background-terminal-gif
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; eis = true; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
- recordGifScript = import ./record-wayland-gif.nix { inherit pkgs; };
-
- testScriptPy = pkgs.writeText "wayland-background-terminal.py" ''
- import sys, time
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- d = Driver()
- try:
- d.initialize("nixos-wayland-bg-terminal")
- # Launch the TARGET first, then the CONTROL — so control holds focus and
- # the target is the inactive window we must type into focus-free.
- d.launch_app("foot --app-id=cua-wayland-target --title=cua-wayland-target")
- time.sleep(1.2)
- d.launch_app("foot --app-id=cua-wayland-control --title=cua-wayland-control")
- tpid, twid = d.find_window("cua-wayland-target", timeout=40)
- cpid, cwid = d.find_window("cua-wayland-control", timeout=40)
- print(f"target pid={tpid} window_id={twid} control pid={cpid} window_id={cwid}", flush=True)
- d.call("set_agent_cursor_enabled", {"enabled": True})
- # Focus-free type into the INACTIVE target while control stays focused.
- d.call("type_text", {"pid": tpid, "window_id": twid,
- "text": "echo hello | tee /tmp/background-hello.txt"})
- d.call("press_key", {"pid": tpid, "window_id": twid, "key": "enter"})
- time.sleep(1.8)
- print("background terminal GIF test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-background-terminal-gif-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 3072;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- environment.systemPackages = session.packages ++ (with pkgs; [ python3 jq ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
-
- with subtest("Record GIF + driver types focus-free into the INACTIVE Wayland terminal"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-background-terminal.py")
- # Recorder self-resolves the driver's nested cua-compositor socket.
- machine.execute(
- "sh -lc 'env XDG_RUNTIME_DIR=/run/user/0 ${recordGifScript} /tmp/background-frames "
- "/tmp/cua-driver-wayland-${desktop}-background-terminal.gif /tmp/stop-background-recorder "
- "/tmp/rec-background.log 10 0.15 >/dev/null 2>&1 & echo $! >/tmp/rec-background.pid'"
- )
- result = machine.execute(
- "timeout 120 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-background-terminal.py 2>&1"
- )[1]
- machine.log(result)
- machine.execute("touch /tmp/stop-background-recorder")
- machine.execute("sh -lc 'for i in $(seq 1 60); do kill -0 $(cat /tmp/rec-background.pid) 2>/dev/null || break; sleep 1; done'")
-
- with subtest("Copy GIF out of the VM (best-effort)"):
- machine.execute("test -e /tmp/cua-driver-wayland-${desktop}-background-terminal.gif || : > /tmp/cua-driver-wayland-${desktop}-background-terminal.gif")
- machine.copy_from_machine("/tmp/cua-driver-wayland-${desktop}-background-terminal.gif", "")
-
- with subtest("Driver typed into inactive terminal AND the command ran"):
- assert "background terminal GIF test complete" in result, result
- machine.wait_until_succeeds("grep -Fx 'hello' /tmp/background-hello.txt", timeout=20)
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/cursor-click-gif.nix b/nix/cua-driver/tests/wayland/cursor-click-gif.nix
deleted file mode 100644
index 3e05fbcaf6..0000000000
--- a/nix/cua-driver/tests/wayland/cursor-click-gif.nix
+++ /dev/null
@@ -1,129 +0,0 @@
-# CUA Driver native-Wayland cursor-click GIF test (per desktop).
-#
-# Launches two native Wayland terminals (foot) THROUGH cua-driver (launch_app),
-# clicks the target, types a command through cua-driver's Wayland injection path,
-# and verifies the command RAN by checking a file it writes
-# (display-server-agnostic proof).
-# Records a GIF of the composited output via grim. On wlroots desktops the driver
-# can drive the host compositor, but compositor-specific focus heuristics make
-# virtual-keyboard delivery after a click unreliable in headless CI. This visual
-# test therefore uses the same EIS-backed nested compositor as the background
-# terminal test so it remains a deterministic click+type regression guard across
-# labwc, sway, KDE, and GNOME hosts.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-cursor-click-gif
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; eis = true; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
- recordGifScript = import ./record-wayland-gif.nix { inherit pkgs; };
-
- # GIF recorder env: native points grim at the host socket; nested self-resolves
- # the driver's published nested socket ($XDG_RUNTIME_DIR/.cua-nested-display).
- recorderWlEnv =
- if session.nested then
- "env XDG_RUNTIME_DIR=/run/user/0"
- else
- "env XDG_RUNTIME_DIR=/run/user/0 WAYLAND_DISPLAY=$(cat /tmp/wl-display)";
-
- testScriptPy = pkgs.writeText "wayland-cursor-click.py" ''
- import sys, time
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- d = Driver()
- try:
- d.initialize("nixos-wayland-click")
- # Launch a control terminal then the target. The click still exercises
- # the target pointer path, while type_text/press_key use the EIS-backed
- # injection path so headless compositor focus policy cannot make the
- # test flaky.
- d.launch_app("foot --app-id=cua-wayland-control --title=cua-wayland-control")
- time.sleep(1)
- d.launch_app("foot --app-id=cua-wayland-target --title=cua-wayland-target")
- pid, wid = d.find_window("cua-wayland-target", timeout=40)
- print(f"target pid={pid} window_id={wid}", flush=True)
- d.call("set_agent_cursor_enabled", {"enabled": True})
- d.call("move_cursor", {"x": 1100.0, "y": 900.0})
- time.sleep(0.6)
- d.call("click", {"pid": pid, "window_id": wid, "x": 120.0, "y": 120.0})
- time.sleep(0.4)
- d.call("type_text", {"pid": pid, "window_id": wid,
- "text": "echo click-focus > /tmp/click-focus.txt"})
- d.call("press_key", {"pid": pid, "window_id": wid, "key": "enter"})
- time.sleep(1.5)
- print("click GIF test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-cursor-click-gif-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 3072;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- environment.systemPackages = session.packages ++ (with pkgs; [ python3 jq ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
- machine.succeed("modprobe uinput && test -e /dev/uinput")
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
-
- with subtest("Record GIF + driver launches, clicks, and types into a native Wayland terminal"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-cursor-click.py")
- machine.execute(
- "sh -lc '${recorderWlEnv} ${recordGifScript} /tmp/click-frames "
- "/tmp/cua-driver-wayland-${desktop}-cursor-click.gif /tmp/stop-click-recorder "
- "/tmp/rec-click.log 10 0.15 >/dev/null 2>&1 & echo $! >/tmp/rec-click.pid'"
- )
- result = machine.execute(
- "timeout 120 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-cursor-click.py 2>&1"
- )[1]
- machine.log(result)
- machine.execute("touch /tmp/stop-click-recorder")
- machine.execute("sh -lc 'for i in $(seq 1 60); do kill -0 $(cat /tmp/rec-click.pid) 2>/dev/null || break; sleep 1; done'")
-
- with subtest("Copy GIF out of the VM (best-effort)"):
- # Ensure the path exists so copy never errors before the real assertion;
- # it may be empty on compositors where grim could not capture.
- machine.execute("test -e /tmp/cua-driver-wayland-${desktop}-cursor-click.gif || : > /tmp/cua-driver-wayland-${desktop}-cursor-click.gif")
- machine.copy_from_machine("/tmp/cua-driver-wayland-${desktop}-cursor-click.gif", "")
-
- with subtest("Driver completed click+type AND the command ran in the Wayland terminal"):
- assert "click GIF test complete" in result, result
- machine.wait_until_succeeds("test -f /tmp/click-focus.txt", timeout=20)
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/driver-client.nix b/nix/cua-driver/tests/wayland/driver-client.nix
deleted file mode 100644
index 5b20fe0c52..0000000000
--- a/nix/cua-driver/tests/wayland/driver-client.nix
+++ /dev/null
@@ -1,138 +0,0 @@
-# Shared MCP client used by the native-Wayland TDD tests.
-#
-# It is copied into the VM as /tmp/driver_client.py and imported by the small
-# per-test scripts. Crucially, window discovery goes ONLY through cua-driver's
-# own `list_windows` tool — there is no xdotool/X11 fallback — so on native
-# Wayland (where the driver currently enumerates nothing) `find_window` times
-# out and the test fails. That is the intended red state for TDD.
-{ pkgs }:
-
-pkgs.writeText "driver_client.py" ''
- import json, os, subprocess, sys, threading, time
-
- DRIVER_BIN = os.environ.get("CUA_DRIVER_BIN", "cua-driver")
-
-
- class Driver:
- def __init__(self):
- self.proc = subprocess.Popen(
- [DRIVER_BIN, "mcp", "--no-daemon-relaunch"],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env={**os.environ},
- )
- threading.Thread(target=self._drain, daemon=True).start()
- self._id = 1
-
- def _drain(self):
- for line in self.proc.stderr:
- sys.stderr.buffer.write(line)
- sys.stderr.buffer.flush()
-
- def _send(self, method, params=None, req_id=None):
- msg = {"jsonrpc": "2.0", "method": method}
- if params is not None:
- msg["params"] = params
- if req_id is not None:
- msg["id"] = req_id
- self.proc.stdin.write((json.dumps(msg) + "\n").encode())
- self.proc.stdin.flush()
-
- def _recv(self, timeout=45):
- result = [None]
-
- def reader():
- result[0] = self.proc.stdout.readline()
-
- th = threading.Thread(target=reader)
- th.start()
- th.join(timeout)
- if th.is_alive():
- raise TimeoutError("no response from driver within timeout")
- line = result[0].decode().strip()
- if not line:
- raise RuntimeError("driver returned an empty response")
- return json.loads(line)
-
- def initialize(self, client="nixos-wayland"):
- self._send("initialize", {
- "protocolVersion": "2024-11-05", "capabilities": {},
- "clientInfo": {"name": client, "version": "1.0.0"},
- }, req_id=self._id)
- resp = self._recv()
- self._id += 1
- assert "result" in resp, f"initialize failed: {resp}"
- self._send("notifications/initialized", {})
- time.sleep(0.3)
- return resp
-
- def call(self, name, args, timeout=60):
- self._send("tools/call", {"name": name, "arguments": args}, req_id=self._id)
- self._id += 1
- resp = self._recv(timeout=timeout)
- if resp.get("error"):
- raise RuntimeError(f"{name} failed: {resp}")
- if resp.get("result", {}).get("isError"):
- raise RuntimeError(f"{name} returned isError: {resp}")
- return resp
-
- def launch_app(self, command):
- """Launch an app THROUGH cua-driver so it lands in whatever Wayland
- session the driver owns — the host compositor (native desktops) or the
- driver's own nested labwc (kde/gnome). Returns the launch response."""
- return self.call("launch_app", {"name": command})
-
- def list_windows(self):
- resp = self.call("list_windows", {})
- result = resp.get("result", {})
- # Preferred: MCP structuredContent = { "windows": [ {window_id, pid,
- # title, ...}, ... ] }.
- structured = result.get("structuredContent")
- if isinstance(structured, dict) and isinstance(structured.get("windows"), list):
- return structured["windows"]
- if isinstance(structured, list):
- return structured
- # Fallback: a text item that happens to be JSON.
- for item in result.get("content", []):
- if item.get("type") == "text":
- try:
- data = json.loads(item.get("text", ""))
- except Exception:
- continue
- if isinstance(data, list):
- return data
- if isinstance(data, dict) and "windows" in data:
- return data["windows"]
- return []
-
- def find_window(self, title_substr, timeout=30, interval=1.0):
- """Poll list_windows until a native Wayland toplevel whose title
- contains `title_substr` appears. Raises on timeout — the red point on
- a driver that cannot yet enumerate Wayland windows."""
- deadline = time.time() + timeout
- needle = title_substr.lower()
- last = []
- while time.time() < deadline:
- last = self.list_windows()
- for w in last:
- # Match across whatever identity fields a Wayland-capable
- # list_windows might surface (title today; app_id/app/class
- # once native Wayland metadata is wired up).
- hay = " ".join(
- str(w.get(k, "")) for k in ("title", "app_id", "app", "class")
- ).lower()
- if needle in hay:
- return int(w.get("pid") or 0), int(w["window_id"])
- time.sleep(interval)
- raise AssertionError(
- f"cua-driver never enumerated a Wayland window titled ~{title_substr!r}; "
- f"last list_windows() = {last}"
- )
-
- def close(self):
- try:
- self.proc.stdin.close()
- self.proc.terminate()
- self.proc.wait(timeout=5)
- except Exception:
- pass
-''
diff --git a/nix/cua-driver/tests/wayland/integration.nix b/nix/cua-driver/tests/wayland/integration.nix
deleted file mode 100644
index e249141167..0000000000
--- a/nix/cua-driver/tests/wayland/integration.nix
+++ /dev/null
@@ -1,109 +0,0 @@
-# CUA Driver native-Wayland integration test (per desktop).
-#
-# Brings up the desktop session, then launches a native Wayland terminal (foot)
-# THROUGH cua-driver (launch_app) and asserts cua-driver can ENUMERATE it via
-# list_windows. On native (wlroots) desktops the driver talks to the host
-# compositor; on kde/gnome it drives its own nested labwc (CUA_WAYLAND_NEST=1,
-# set by the session driver wrapper). Either way the app lands in the session
-# the driver owns.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-integration
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
-
- testScriptPy = pkgs.writeText "wayland-integration.py" ''
- import sys, time
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- d = Driver()
- try:
- d.initialize("nixos-wayland-integration")
-
- # Handshake sanity: required tools are advertised.
- d._send("tools/list", {}, req_id=999)
- resp = d._recv()
- names = [t["name"] for t in resp.get("result", {}).get("tools", [])]
- for t in ("list_windows", "get_window_state", "click", "type_text", "launch_app"):
- assert t in names, f"{t} not advertised: {names}"
- print(f"tools advertised: {len(names)}", flush=True)
-
- # Launch foot through cua-driver so it lands in the session the driver
- # owns (host compositor on native desktops; nested labwc on kde/gnome).
- d.launch_app("foot --app-id=cua-wayland-foot --title=cua-wayland-foot")
-
- # list_windows must surface the foot terminal the driver just launched.
- pid, wid = d.find_window("cua-wayland-foot", timeout=40)
- print(f"RESOLVED native wayland window pid={pid} window_id={wid}", flush=True)
- print("integration test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-integration-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 3072;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- environment.systemPackages = session.packages ++ (with pkgs; [ python3 jq ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Binary exists and lists tools"):
- machine.succeed("cua-driver --help")
- tools = machine.succeed("cua-driver list-tools")
- for t in ("list_windows", "get_window_state", "click", "type_text"):
- assert t in tools, f"{t} missing from list-tools"
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
- machine.log("host WAYLAND_DISPLAY=" + machine.succeed("cat /tmp/wl-display").strip())
-
- with subtest("doctor reports a Wayland status line"):
- result = machine.succeed("timeout 30 ${session.driverWrapper} doctor 2>&1 || true")
- machine.log(result)
- assert "Wayland" in result, f"doctor did not report Wayland: {result}"
-
- with subtest("cua-driver launches + enumerates a native Wayland window"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-integration.py")
- result = machine.succeed(
- "timeout 120 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-integration.py 2>&1"
- )
- machine.log(result)
- assert "integration test complete" in result, result
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/parallel-drag.nix b/nix/cua-driver/tests/wayland/parallel-drag.nix
deleted file mode 100644
index 7d67ce50d0..0000000000
--- a/nix/cua-driver/tests/wayland/parallel-drag.nix
+++ /dev/null
@@ -1,104 +0,0 @@
-# CUA Driver native-Wayland parallel multi-cursor drag test (per desktop).
-#
-# Two simultaneous drag gestures on one window. Stock Wayland has a single seat
-# cursor and no multi-pointer protocol, so cua-driver nests its own
-# cua-compositor (EIS mode), which drives N independent logical cursors and
-# injects wl_pointer per cursor by app_id. parallel_mouse_drag routes through
-# the compositor's control socket (window-local coords, no X11 MPX). Records a
-# GIF via grim.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-parallel-drag
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; eis = true; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
- recordGifScript = import ./record-wayland-gif.nix { inherit pkgs; };
-
- testScriptPy = pkgs.writeText "wayland-parallel-drag.py" ''
- import sys, time
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- d = Driver()
- try:
- d.initialize("nixos-wayland-parallel-drag")
- d.launch_app("foot --app-id=cua-wayland-paint --title=cua-wayland-paint")
- pid, wid = d.find_window("cua-wayland-paint", timeout=40)
- print(f"target pid={pid} window_id={wid}", flush=True)
- d.call("parallel_mouse_drag", {"drags": [
- {"session": "agent-1", "window_id": wid, "from_x": 100.0, "from_y": 100.0, "to_x": 380.0, "to_y": 420.0, "duration_ms": 2000, "steps": 60},
- {"session": "agent-2", "window_id": wid, "from_x": 700.0, "from_y": 100.0, "to_x": 420.0, "to_y": 420.0, "duration_ms": 2000, "steps": 60},
- ]})
- time.sleep(0.6)
- print("parallel drag test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-parallel-drag-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 3072;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- services.libinput.enable = true;
- environment.systemPackages = session.packages ++ (with pkgs; [ python3 jq ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
-
- with subtest("Record GIF + pilot cua-driver through parallel_mouse_drag (multi-cursor)"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-parallel-drag.py")
- machine.execute(
- "sh -lc 'env XDG_RUNTIME_DIR=/run/user/0 ${recordGifScript} /tmp/drag-frames "
- "/tmp/cua-driver-wayland-${desktop}-parallel-drag.gif /tmp/stop-drag-recorder "
- "/tmp/rec-drag.log 8 0.12 >/dev/null 2>&1 & echo $! >/tmp/rec-drag.pid'"
- )
- result = machine.execute(
- "timeout 120 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-parallel-drag.py 2>&1"
- )[1]
- machine.log(result)
- machine.execute("touch /tmp/stop-drag-recorder")
- machine.execute("sh -lc 'for i in $(seq 1 60); do kill -0 $(cat /tmp/rec-drag.pid) 2>/dev/null || break; sleep 1; done'")
-
- with subtest("Copy GIF out of the VM (best-effort)"):
- machine.execute("test -e /tmp/cua-driver-wayland-${desktop}-parallel-drag.gif || : > /tmp/cua-driver-wayland-${desktop}-parallel-drag.gif")
- machine.copy_from_machine("/tmp/cua-driver-wayland-${desktop}-parallel-drag.gif", "")
-
- with subtest("parallel_mouse_drag completed on native Wayland (multi-cursor via EIS compositor)"):
- assert "parallel drag test complete" in result, result
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/record-wayland-gif.nix b/nix/cua-driver/tests/wayland/record-wayland-gif.nix
deleted file mode 100644
index bc870404ba..0000000000
--- a/nix/cua-driver/tests/wayland/record-wayland-gif.nix
+++ /dev/null
@@ -1,59 +0,0 @@
-# Native-Wayland screen-recording helper for the cua-driver Wayland TDD tests.
-#
-# Captures the composited Wayland output with `grim` (wlr-screencopy) in a loop
-# and stitches the frames into an animated GIF. grim only works on wlroots
-# compositors (labwc/wayfire/sway); on kwin/mutter it simply produces no frames
-# and no GIF — which is fine, the GIF is a best-effort artifact and these tests
-# are expected to fail before/around it anyway.
-#
-# Usage (in a test's `let`):
-# recordGifScript = import ./record-wayland-gif.nix { inherit pkgs; };
-# then inside the testScript, start it in the background before driving and
-# `touch` the stop-file afterwards:
-# ${recordGifScript} <frames_dir> <output_gif> <stop_file> <log_file> \
-# <delay_cs> <interval>
-# The caller must export WAYLAND_DISPLAY and XDG_RUNTIME_DIR for grim.
-{ pkgs }:
-
-pkgs.writeShellScript "record-wayland-gif.sh" ''
- set -u
- frames_dir="$1"
- output_gif="$2"
- stop_file="$3"
- log_file="$4"
- delay_cs="$5"
- interval="$6"
-
- rm -f "$stop_file" "$output_gif" "$log_file"
- rm -rf "$frames_dir"
- mkdir -p "$frames_dir"
-
- # In nested mode the caller can't know cua-driver's private socket ahead of
- # time; the driver publishes it to $XDG_RUNTIME_DIR/.cua-nested-display once
- # up. If WAYLAND_DISPLAY isn't already set, wait for and adopt that socket so
- # the GIF captures the SAME session the driver drives.
- if [ -z "''${WAYLAND_DISPLAY:-}" ]; then
- dfile="''${XDG_RUNTIME_DIR:-/run/user/0}/.cua-nested-display"
- w=0
- while [ ! -s "$dfile" ] && [ "$w" -lt 60 ]; do sleep 0.5; w=$((w + 1)); done
- if [ -s "$dfile" ]; then
- WAYLAND_DISPLAY="$(cat "$dfile")"
- export WAYLAND_DISPLAY
- echo "recorder adopted nested WAYLAND_DISPLAY=$WAYLAND_DISPLAY" >>"$log_file"
- fi
- fi
-
- max_frames=450
- i=0
- while [ ! -f "$stop_file" ] && [ "$i" -lt "$max_frames" ]; do
- frame=$(printf "%s/frame-%04d.png" "$frames_dir" "$i")
- timeout 10 ${pkgs.grim}/bin/grim "$frame" >>"$log_file" 2>&1 || true
- i=$((i + 1))
- sleep "$interval"
- done
-
- if ls "$frames_dir"/frame-*.png >/dev/null 2>&1; then
- timeout 120 ${pkgs.imagemagick}/bin/convert -delay "$delay_cs" -loop 0 \
- "$frames_dir"/frame-*.png "$output_gif" >>"$log_file" 2>&1 || true
- fi
-''
diff --git a/nix/cua-driver/tests/wayland/screenshot.nix b/nix/cua-driver/tests/wayland/screenshot.nix
deleted file mode 100644
index 7a3cd31317..0000000000
--- a/nix/cua-driver/tests/wayland/screenshot.nix
+++ /dev/null
@@ -1,98 +0,0 @@
-# CUA Driver native-Wayland screenshot test (per desktop) — TDD red.
-#
-# Launches a native Wayland terminal (foot), finds it via cua-driver
-# list_windows, and asserts get_window_state (capture_mode=vision) returns a
-# real PNG of that native Wayland surface. The driver captures via X11 today, so
-# both discovery and capture fail on native Wayland — the spec for native
-# Wayland window capture.
-#
-# To run: nix build .#checks.x86_64-linux.cua-driver-wayland-<desktop>-screenshot
-{
- pkgs,
- lib ? pkgs.lib,
- cuaDriverModule,
- desktop,
- ...
-}:
-
-let
- session = import ./session.nix { inherit pkgs desktop; };
- driverClient = import ./driver-client.nix { inherit pkgs; };
-
- testScriptPy = pkgs.writeText "wayland-screenshot.py" ''
- import base64, sys
- sys.path.insert(0, "/tmp")
- from driver_client import Driver
-
- d = Driver()
- try:
- d.initialize("nixos-wayland-screenshot")
- d.launch_app("foot --app-id=cua-wayland-foot --title=cua-wayland-foot")
- pid, wid = d.find_window("cua-wayland-foot", timeout=40)
- print(f"window pid={pid} window_id={wid}", flush=True)
- resp = d.call("get_window_state", {
- "pid": pid, "window_id": wid, "capture_mode": "vision"}, timeout=30)
- saved = False
- for item in resp.get("result", {}).get("content", []):
- if item.get("type") == "image" and item.get("data"):
- data = base64.b64decode(item["data"])
- assert len(data) > 0, "empty image payload"
- with open("/tmp/cua-driver-wayland-${desktop}-screenshot.png", "wb") as f:
- f.write(data)
- saved = True
- break
- assert saved, f"no image returned for native Wayland window: {resp}"
- print("screenshot test complete", flush=True)
- finally:
- d.close()
- '';
-in
-
-pkgs.testers.nixosTest {
- name = "cua-driver-wayland-${desktop}-screenshot-test";
- meta.maintainers = [ ];
-
- nodes.machine =
- { pkgs, ... }:
- {
- imports = [ cuaDriverModule ];
- virtualisation = {
- cores = 2;
- memorySize = 3072;
- };
- services.cua-driver.enable = true;
- boot.kernelModules = [ "uinput" ];
- hardware.graphics.enable = true;
- services.udev.extraRules = ''
- KERNEL=="uinput", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
- '';
- environment.systemPackages = session.packages ++ (with pkgs; [ python3 jq ]);
- };
-
- testScript = ''
- machine.start()
- machine.wait_for_unit("multi-user.target")
-
- with subtest("Bring up ${session.label}"):
- machine.execute("${session.start} >/tmp/session.log 2>&1 &")
- try:
- machine.wait_for_file("/tmp/wl-ready", timeout=120)
- except Exception:
- machine.log(machine.execute("cat /tmp/session.log || true")[1])
- machine.log(machine.execute("cat /tmp/compositor.log || true")[1])
- raise
-
- with subtest("Launch + screenshot a native Wayland window via cua-driver"):
- machine.copy_from_host("${driverClient}", "/tmp/driver_client.py")
- machine.copy_from_host("${testScriptPy}", "/tmp/wayland-screenshot.py")
- result = machine.succeed(
- "timeout 120 env CUA_DRIVER_BIN=${session.driverWrapper} "
- "XDG_RUNTIME_DIR=/run/user/0 python3 /tmp/wayland-screenshot.py 2>&1"
- )
- machine.log(result)
- assert "screenshot test complete" in result, result
-
- with subtest("Extract screenshot"):
- machine.copy_from_machine("/tmp/cua-driver-wayland-${desktop}-screenshot.png", "")
- '';
-}
diff --git a/nix/cua-driver/tests/wayland/session.nix b/nix/cua-driver/tests/wayland/session.nix
deleted file mode 100644
index 8f1fa48533..0000000000
--- a/nix/cua-driver/tests/wayland/session.nix
+++ /dev/null
@@ -1,246 +0,0 @@
-# Shared Wayland desktop-session bring-up for the cua-driver Wayland suite.
-#
-# Two execution models, selected per desktop:
-#
-# * NATIVE (wlroots: labwc, sway) — apps run as real Wayland clients of the
-# HOST compositor, and the driver talks to that same compositor's wlr
-# protocols (foreign-toplevel + screencopy). The session `start` script
-# launches the compositor headless, waits for its socket, and publishes it
-# to /tmp/wl-display.
-#
-# * NESTED (kde: kwin, gnome: mutter) — kwin/mutter expose NO client protocols
-# for cross-window enumeration/capture, so the driver cannot drive them
-# directly. Instead cua-driver "brings its own compositor": with
-# CUA_WAYLAND_NEST=1 it spawns a private headless labwc and points
-# WAYLAND_DISPLAY at it, so every app launched via `launch_app` runs inside
-# that nested session where the wlr protocols DO work. The host kwin/mutter
-# is still booted (best-effort) to prove cua-driver coexists with a real
-# KDE/GNOME host, but the test never depends on it.
-#
-# Given a `desktop` this returns:
-#
-# { packages; start; label; nested; driverWrapper; }
-#
-# * packages — extra `environment.systemPackages` the session needs.
-# * start — a `writeShellScript` that brings the session up and
-# `touch`es /tmp/wl-ready, then blocks.
-# * label — human label for logs.
-# * nested — true for kde/gnome (driver hosts its own compositor).
-# * driverWrapper — a `writeShellScript` to use as CUA_DRIVER_BIN: it sets the
-# correct env (host WAYLAND_DISPLAY for native; the nest env
-# for nested) and execs `cua-driver "$@"`. Tests spawn the
-# driver through this so the python harness stays
-# desktop-agnostic.
-{
- pkgs,
- desktop,
- # EIS mode: cua-driver nests its OWN cua-compositor (focus-free keyboard +
- # multi-cursor injection over a control socket) instead of labwc, on ANY host.
- # Used by the background-terminal-gif + parallel-drag cells.
- eis ? false,
-}:
-
-let
- inherit (pkgs) lib;
- cuaCompositor = pkgs.callPackage ../../compositor { };
-
- # Native-Wayland tooling only. No xorg.* / xdotool / xterm here — those are
- # X11 and would let the driver cheat via XWayland. `foot` is a Wayland-native
- # terminal; `grim` captures the wlroots output for the GIF artifacts.
- commonPkgs = with pkgs; [
- foot
- grim
- wtype # virtual-keyboard CLI: cua-driver shells out to it for type_text/press_key
- dbus
- procps
- ];
-
- # Minimal sway config: native Wayland only (XWayland off), stable output.
- # `workspace_layout stacking` makes the focused window fill the output, so the
- # driver's centre virtual-pointer click reliably lands on the activated target
- # (sway needs a pointer interaction to route virtual-keyboard input on a
- # headless seat with no physical keyboard).
- swayConfig = pkgs.writeText "sway-config" ''
- xwayland disable
- output HEADLESS-1 resolution 1280x1024
- workspace_layout stacking
- exec_always foot --server
- '';
-
- desktops = {
- "xfce-labwc" = {
- label = "XFCE on labwc (native Wayland)";
- packages = with pkgs; [ labwc ];
- wlroots = true;
- nested = false;
- launch = "labwc >/tmp/compositor.log 2>&1 &";
- };
- # NOTE: xfce-wayfire intentionally omitted — wayfire fails to build in the
- # current nixpkgs pin (wf-config can't link -ldoctest). labwc + sway cover
- # XFCE-on-wlroots.
- "xfce-sway" = {
- label = "XFCE on sway (native Wayland)";
- packages = with pkgs; [ sway ];
- wlroots = true;
- nested = false;
- launch = "sway -c ${swayConfig} >/tmp/compositor.log 2>&1 &";
- };
- "kde" = {
- label = "KDE Plasma kwin_wayland host + cua-driver nested labwc";
- # labwc is what cua-driver nests; kwin is the host it coexists with.
- packages = with pkgs; [ labwc kdePackages.kwin ];
- wlroots = false;
- nested = true;
- # No --xwayland: keep the host session native-Wayland only.
- launch = "kwin_wayland --virtual --width 1280 --height 1024 --no-lockscreen >/tmp/compositor.log 2>&1 &";
- };
- "gnome" = {
- label = "GNOME Shell / mutter host + cua-driver nested labwc";
- packages = with pkgs; [ labwc gnome-shell mutter ];
- wlroots = false;
- nested = true;
- launch = "gnome-shell --wayland --headless --virtual-monitor 1280x1024 --unsafe-mode >/tmp/compositor.log 2>&1 &";
- };
- };
-
- cfg = desktops.${desktop} or (throw "wayland/session.nix: unknown desktop '${desktop}'");
-
- wlrootsEnv = lib.optionalString cfg.wlroots ''
- export WLR_BACKENDS=headless
- export WLR_RENDERER=pixman
- export WLR_RENDERER_ALLOW_SOFTWARE=1
- export WLR_LIBINPUT_NO_DEVICES=1
- '';
-
- # Native model: block until the HOST compositor's socket appears, publish it.
- nativeStart = ''
- dbus-run-session -- sh -c '
- wlsock() { ls "$XDG_RUNTIME_DIR" 2>/dev/null | grep -E "^wayland-[0-9]+$" | head -1; }
-
- ${cfg.launch}
- compositor_pid=$!
-
- n=0
- while [ -z "$(wlsock)" ] && [ "$n" -lt 120 ]; do
- if ! kill -0 "$compositor_pid" 2>/dev/null; then
- echo "compositor exited early" >&2
- break
- fi
- sleep 0.5
- n=$((n + 1))
- done
-
- sock="$(wlsock)"
- if [ -z "$sock" ]; then
- echo "no Wayland display socket appeared" >&2
- cat /tmp/compositor.log >&2 2>/dev/null || true
- exit 1
- fi
- echo "$sock" > /tmp/wl-display
-
- touch /tmp/wl-ready
- exec sleep infinity
- '
- '';
-
- # Nested model: boot the host compositor BEST-EFFORT (log whether it came up),
- # but never block the test on it — cua-driver provides its own session. We
- # record the host socket (if any) for logs; the driver wrapper ignores it.
- nestedStart = ''
- dbus-run-session -- sh -c '
- wlsock() { ls "$XDG_RUNTIME_DIR" 2>/dev/null | grep -E "^wayland-[0-9]+$" | head -1; }
-
- ${cfg.launch}
-
- n=0
- while [ -z "$(wlsock)" ] && [ "$n" -lt 40 ]; do
- sleep 0.5
- n=$((n + 1))
- done
- sock="$(wlsock)"
- if [ -n "$sock" ]; then
- echo "host compositor up: $sock" >&2
- else
- echo "host compositor did not come up; proceeding with nested session only" >&2
- cat /tmp/compositor.log >&2 2>/dev/null || true
- fi
- echo "''${sock:-none}" > /tmp/wl-display
-
- touch /tmp/wl-ready
- exec sleep infinity
- '
- '';
-
- start = pkgs.writeShellScript "wayland-session-start-${desktop}.sh" ''
- set -u
- export PATH=${lib.makeBinPath (commonPkgs ++ cfg.packages)}:$PATH
-
- export XDG_RUNTIME_DIR=/run/user/0
- mkdir -p "$XDG_RUNTIME_DIR"
- chmod 700 "$XDG_RUNTIME_DIR"
-
- ${wlrootsEnv}
- export QT_QPA_PLATFORM=wayland
- export GDK_BACKEND=wayland
- export LIBGL_ALWAYS_SOFTWARE=1
-
- rm -f /tmp/wl-ready /tmp/wl-display "$XDG_RUNTIME_DIR/.cua-nested-display" "$XDG_RUNTIME_DIR/cua-inject.sock"
-
- ${if (cfg.nested || eis) then nestedStart else nativeStart}
- '';
-
- # Driver launcher used as CUA_DRIVER_BIN. It owns the WAYLAND env so the python
- # harness never has to. labwc/foot/grim are on PATH for the app/compositor
- # processes cua-driver spawns.
- # Toolkit apps cua-driver launches inherit its env, so force the NATIVE
- # Wayland backends here (GTK auto-detects from WAYLAND_DISPLAY; Qt would
- # otherwise default to xcb and fail with no X). Harmless for foot.
- appBackendEnv = ''
- export GDK_BACKEND=wayland
- export QT_QPA_PLATFORM=wayland
- export LIBGL_ALWAYS_SOFTWARE=1
- # The native-Wayland backend is opt-in (off by default); these tests exist
- # to exercise it, so turn it on for every Wayland-session driver wrapper.
- export CUA_DRIVER_RS_ENABLE_WAYLAND=1
- '';
-
- driverWrapper =
- if eis then
- # EIS mode: nest cua-compositor (focus-free + multi-cursor injection over
- # the control socket) on ANY host. Apps launched via launch_app land in it.
- pkgs.writeShellScript "cua-driver-eis-${desktop}" ''
- export PATH=${lib.makeBinPath (commonPkgs ++ cfg.packages ++ [ cuaCompositor ])}:$PATH
- export XDG_RUNTIME_DIR=/run/user/0
- export CUA_WAYLAND_NEST=1
- export CUA_WAYLAND_NEST_COMPOSITOR=${cuaCompositor}/bin/cua-compositor
- export CUA_INJECT_SOCKET=/run/user/0/cua-inject.sock
- ${appBackendEnv}
- unset DISPLAY WAYLAND_DISPLAY
- exec cua-driver "$@"
- ''
- else if cfg.nested then
- pkgs.writeShellScript "cua-driver-nested-${desktop}" ''
- export PATH=${lib.makeBinPath (commonPkgs ++ cfg.packages)}:$PATH
- export XDG_RUNTIME_DIR=/run/user/0
- export CUA_WAYLAND_NEST=1
- export CUA_WAYLAND_NEST_COMPOSITOR=labwc
- ${appBackendEnv}
- unset DISPLAY WAYLAND_DISPLAY
- exec cua-driver "$@"
- ''
- else
- pkgs.writeShellScript "cua-driver-native-${desktop}" ''
- export PATH=${lib.makeBinPath (commonPkgs ++ cfg.packages)}:$PATH
- export XDG_RUNTIME_DIR=/run/user/0
- export WAYLAND_DISPLAY="$(cat /tmp/wl-display)"
- ${appBackendEnv}
- unset DISPLAY
- exec cua-driver "$@"
- '';
-in
-{
- label = if eis then "${cfg.label} + cua-compositor (EIS injection)" else cfg.label;
- nested = cfg.nested || eis;
- packages = commonPkgs ++ cfg.packages ++ lib.optional eis cuaCompositor;
- inherit start driverWrapper;
-}
diff --git a/scripts/ci/linux/run-rust-e2e-inject.sh b/scripts/ci/linux/run-rust-e2e-inject.sh
new file mode 100755
index 0000000000..c58a1df452
--- /dev/null
+++ b/scripts/ci/linux/run-rust-e2e-inject.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# Run the canonical Rust matrix inside the nested cua-compositor environment.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+export CUA_E2E_WAYLAND_SESSION=cua-compositor
+exec "${SCRIPT_DIR}/run-rust-e2e-wayland.sh" "$@"