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.

fix(cua-driver): SDK create() prefers the daemon on macOS so the agent cursor works (#5090)

Francesco Bonacci1974dc39cb41
diff --git a/docs/content/docs/cua-driver/guides/use-the-sdk.mdx b/docs/content/docs/cua-driver/guides/use-the-sdk.mdx
index 141b580410..b707577d18 100644
--- a/docs/content/docs/cua-driver/guides/use-the-sdk.mdx
+++ b/docs/content/docs/cua-driver/guides/use-the-sdk.mdx
@@ -5,10 +5,26 @@ description: Call Cua Driver from Python or TypeScript in process, verify each a
import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
-`CuaDriver.create()` loads the Rust runtime into your process: no daemon,
-socket, or executable. Your app owns the OS permissions, sessions, and
-shutdown. On macOS, the process that imports the SDK needs the Accessibility
-and Screen Recording grants.
+`CuaDriver.create()` gives you a driver for your Python or TypeScript app.
+Where the platform allows it, it is the in-process Rust runtime: no daemon,
+socket, or executable, and your app owns the OS permissions, sessions, and
+shutdown.
+
+**On macOS, `create()` prefers the `CuaDriver.app` daemon.** An in-process
+runtime has no AppKit host, so it cannot draw the agent cursor overlay (the
+visible "the agent is working here" cursor), and macOS attributes the
+Accessibility and Screen Recording grants to your Python, Node, or IDE process
+instead of `CuaDriver.app`. The daemon draws the cursor and owns the grants, so
+`create()` connects to a running daemon, or starts the installed app through
+LaunchServices (the same way `cua-driver permissions grant` does). Run
+`cua-driver permissions grant` once; there is nothing else to configure.
+
+If `CuaDriver.app` is not installed, `create()` falls back to the in-process
+runtime and prints a one-time warning that the agent cursor is unavailable.
+Pass `embedded=True` (Python) or `{ embedded: true }` (TypeScript), or set
+`CUA_DRIVER_EMBEDDED=1`, to force the in-process runtime on purpose. Other
+platforms always run in process. To pick the daemon explicitly, use
+`CuaDriver.connect()`.
<Tabs groupId="language" persist items={['Python', 'TypeScript']}>
<Tab value="Python">
@@ -225,12 +241,12 @@ confirms the value through a separate `/state` endpoint lives in
| Python / TypeScript | Use |
| --- | --- |
-| `create()` | Same-process runtime. The default. |
+| `create()` | The default. On macOS, connects to (or starts) the `CuaDriver.app` daemon so the agent cursor and permissions work; elsewhere, or with `embedded=True` / `{ embedded: true }`, the same-process runtime. |
| `create_configured(options)` / `createConfigured` | Trusted host sets an immutable permission ceiling and session TTLs. |
| `create_configured_with_authorization_host(options, host)` | Adds a callback that approves residual boundaries, such as attaching to a logged-in browser profile. |
| `create_configured_with_activity_observer(options, observer)` | Adds content-free activity events (tool, risk class, refusal code; never arguments or images). |
| `create_private_worker(options)` / `createPrivateWorker` | One supervised child runtime over inherited pipes; no listener, closes with its channel. |
-| `connect(socket_path)` / `connect(socketPath)` | Connects to a running daemon. |
+| `connect(socket_path)` / `connect(socketPath)` | Connects to a running daemon without falling back. |
Python uses `snake_case`, TypeScript `camelCase`. Desktop methods mirror the
[MCP tools](/cua-driver/reference/mcp-tools) (`get_window_state`, `click`,
@@ -245,7 +261,7 @@ the overlay.
When a signed desktop app must let an external agent use its permissions, host
a private daemon from the app process and hand its MCP connection to the agent.
-If only your app calls the driver, use `create()` instead.
+If only your app calls the driver, use `create()` instead (on macOS it uses the daemon and draws the agent cursor).
```ts skip="no-runner"
import { CuaDriver, EmbeddedCuaDriverHost } from '@trycua/cua-driver';
diff --git a/docs/content/docs/cua-driver/index.mdx b/docs/content/docs/cua-driver/index.mdx
index 3e9fdc3ade..09ecfbc70a 100644
--- a/docs/content/docs/cua-driver/index.mdx
+++ b/docs/content/docs/cua-driver/index.mdx
@@ -13,7 +13,9 @@ cursor overlay.
Use it from any agent through **MCP** (`cua-driver mcp`), from a shell through
the **CLI** (`cua-driver call <tool>`), or inside your own app through the
-Python and TypeScript **SDK** (`CuaDriver.create()`).
+Python and TypeScript **SDK** (`CuaDriver.create()`). On macOS the SDK
+uses the `CuaDriver.app` daemon, which draws the agent cursor and holds the
+permission grants.
<VideoDemo
src="https://github.com/user-attachments/assets/e9344780-e780-46e7-bcce-91f61eda9599"
@@ -52,7 +54,7 @@ sessions, and browser connections.
| --------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------- |
| An agent or harness (Claude Code, Codex, Cursor, …) | [MCP](/cua-driver/guides/connect-your-agent): `cua-driver mcp` | The MCP process; on macOS, the `CuaDriver.app` daemon |
| An agent that can only run shell commands | [CLI](/cua-driver/reference/cli): `cua-driver call <tool>` | The `cua-driver serve` daemon |
-| An app with built-in computer use | [SDK](/cua-driver/guides/use-the-sdk): `CuaDriver.create()` | Your app process |
+| An app with built-in computer use | [SDK](/cua-driver/guides/use-the-sdk): `CuaDriver.create()` | On macOS, the `CuaDriver.app` daemon; elsewhere your app process |
| A signed desktop app that serves an external agent | [App-hosted service](/cua-driver/guides/use-the-sdk#expose-mcp-from-a-desktop-app) | The permission-owning desktop app |
| Several clients sharing one desktop | `cua-driver serve --socket <path>` plus `cua-driver mcp --socket <path>` | The daemon |
diff --git a/libs/cua-driver/python/src/cua_driver/__init__.py b/libs/cua-driver/python/src/cua_driver/__init__.py
index 17cf5f8b59..a2b165a007 100644
--- a/libs/cua-driver/python/src/cua_driver/__init__.py
+++ b/libs/cua-driver/python/src/cua_driver/__init__.py
@@ -182,6 +182,7 @@ from ._native_contract import (
VerifyStateOutput,
WindowPredicate,
)
+from . import _daemon
from .wrapper import get_binary_path, run_cua_driver
@@ -191,10 +192,23 @@ def _connect_python_sdk(cls, socket_path):
return cls.connect_with_client_kind(socket_path, SdkClientKind.PYTHON)
-def _create_python_sdk(cls, options=None):
- """Create the canonical same-process SDK runtime for Python."""
+def _create_python_sdk(cls, options=None, *, embedded=False):
+ """Create the Python SDK runtime.
- return cls.create_with_client_kind(options, SdkClientKind.PYTHON)
+ On macOS this prefers the CuaDriver.app daemon (starting it when installed)
+ so the agent cursor overlay and the app's permission grants work; pass
+ ``embedded=True`` to force the in-process runtime. Other platforms are
+ always in-process.
+ """
+
+ return _daemon.create_driver(
+ lambda: cls.connect_with_client_kind(None, SdkClientKind.PYTHON),
+ lambda: cls.create_with_client_kind(options, SdkClientKind.PYTHON),
+ embedded=embedded,
+ claude_code_compatibility=bool(
+ getattr(options, "claude_code_compatibility", False)
+ ),
+ )
def _create_configured_python_sdk(cls, options):
diff --git a/libs/cua-driver/python/src/cua_driver/_daemon.py b/libs/cua-driver/python/src/cua_driver/_daemon.py
new file mode 100644
index 0000000000..1acb2878b0
--- /dev/null
+++ b/libs/cua-driver/python/src/cua_driver/_daemon.py
@@ -0,0 +1,93 @@
+"""macOS daemon preference for ``CuaDriver.create()``.
+
+An embedded (in-process) runtime on macOS has no AppKit host, so the agent
+cursor overlay cannot be drawn and the permission identity is the host
+process (python, node, an IDE) instead of CuaDriver.app. The daemon
+(``CuaDriver.app`` running ``serve``) draws the cursor and owns the TCC grants,
+so on macOS ``create()`` connects to it, starting it through LaunchServices
+when the app is installed. This module has no native dependency so it can be
+tested without the staged library.
+"""
+
+from __future__ import annotations
+
+import os
+import subprocess
+import sys
+import time
+import warnings
+from typing import Any, Callable, Optional
+
+APP_NAME = "CuaDriver"
+APP_PATH = f"/Applications/{APP_NAME}.app"
+EMBEDDED_ENV = "CUA_DRIVER_EMBEDDED"
+START_TIMEOUT_SECONDS = 15.0
+
+_warned = False
+
+
+def _warn_once(message: str) -> None:
+ global _warned
+ if _warned:
+ return
+ _warned = True
+ warnings.warn(message, RuntimeWarning, stacklevel=4)
+
+
+def launch_app() -> bool:
+ """Start the daemon through LaunchServices, like ``permissions grant``."""
+ try:
+ status = subprocess.run(
+ ["/usr/bin/open", "-n", "-g", "-a", APP_NAME, "--args", "serve"],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+ except OSError:
+ return False
+ return status.returncode == 0
+
+
+def create_driver(
+ connect: Callable[[], Any],
+ create_embedded: Callable[[], Any],
+ *,
+ embedded: bool = False,
+ claude_code_compatibility: bool = False,
+ platform: Optional[str] = None,
+ app_installed: Optional[Callable[[], bool]] = None,
+ launch: Callable[[], bool] = launch_app,
+ timeout: float = START_TIMEOUT_SECONDS,
+ sleep: Callable[[float], None] = time.sleep,
+) -> Any:
+ """Return a daemon-backed driver on macOS when possible, else embedded."""
+ platform = sys.platform if platform is None else platform
+ if (
+ embedded
+ or claude_code_compatibility
+ or platform != "darwin"
+ or os.environ.get(EMBEDDED_ENV) == "1"
+ ):
+ return create_embedded()
+
+ if app_installed is None:
+ app_installed = lambda: os.path.isdir(APP_PATH)
+
+ driver = connect()
+ if driver.is_available():
+ return driver
+
+ if app_installed() and launch():
+ deadline = time.monotonic() + timeout
+ while time.monotonic() < deadline:
+ if driver.is_available():
+ return driver
+ sleep(0.25)
+
+ _warn_once(
+ "CuaDriver.create() is using the in-process runtime, which cannot draw "
+ "the agent cursor on macOS and attributes permissions to this process. "
+ "Install CuaDriver.app and run `cua-driver serve` (or call "
+ "CuaDriver.connect()) to get the agent cursor, or pass embedded=True "
+ "to silence this warning."
+ )
+ return create_embedded()
diff --git a/libs/cua-driver/python/tests/test_daemon_default.py b/libs/cua-driver/python/tests/test_daemon_default.py
new file mode 100644
index 0000000000..2badd0f3cc
--- /dev/null
+++ b/libs/cua-driver/python/tests/test_daemon_default.py
@@ -0,0 +1,82 @@
+"""CuaDriver.create() prefers the macOS daemon so the agent cursor works."""
+
+import importlib.util
+import warnings
+from pathlib import Path
+
+
+def load():
+ path = Path(__file__).resolve().parents[1] / "src/cua_driver/_daemon.py"
+ spec = importlib.util.spec_from_file_location("cua_driver_daemon", path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ module._warned = False
+ return module
+
+
+class Fake:
+ def __init__(self, name, up_after=0):
+ self.name = name
+ self.calls = 0
+ self.up_after = up_after
+
+ def is_available(self):
+ self.calls += 1
+ return self.calls > self.up_after
+
+
+def run(module, daemon, **kwargs):
+ embedded = Fake("embedded")
+ kwargs.setdefault("platform", "darwin")
+ kwargs.setdefault("sleep", lambda _: None)
+ result = module.create_driver(lambda: daemon, lambda: embedded, **kwargs)
+ return result, embedded
+
+
+def test_running_daemon_is_used(monkeypatch):
+ monkeypatch.delenv("CUA_DRIVER_EMBEDDED", raising=False)
+ m = load()
+ daemon = Fake("daemon")
+ result, _ = run(m, daemon)
+ assert result is daemon
+
+
+def test_installed_app_is_launched(monkeypatch):
+ monkeypatch.delenv("CUA_DRIVER_EMBEDDED", raising=False)
+ m = load()
+ daemon = Fake("daemon", up_after=2)
+ launched = []
+ result, _ = run(
+ m, daemon, app_installed=lambda: True, launch=lambda: launched.append(1) or True
+ )
+ assert result is daemon and launched == [1]
+
+
+def test_fallback_warns_once(monkeypatch):
+ monkeypatch.delenv("CUA_DRIVER_EMBEDDED", raising=False)
+ m = load()
+ with warnings.catch_warnings(record=True) as caught:
+ warnings.simplefilter("always")
+ for _ in range(2):
+ result, embedded = run(m, Fake("d", up_after=10**6), app_installed=lambda: False)
+ assert result is embedded
+ messages = [str(w.message) for w in caught if "agent cursor" in str(w.message)]
+ assert len(messages) == 1
+
+
+def test_embedded_forced_or_non_macos(monkeypatch):
+ monkeypatch.delenv("CUA_DRIVER_EMBEDDED", raising=False)
+ m = load()
+ daemon = Fake("daemon")
+ for kwargs in (
+ {"embedded": True},
+ {"platform": "linux"},
+ {"platform": "win32"},
+ {"claude_code_compatibility": True},
+ ):
+ result, embedded = run(m, daemon, **kwargs)
+ assert result is embedded
+ monkeypatch.setenv("CUA_DRIVER_EMBEDDED", "1")
+ result, embedded = run(m, daemon)
+ assert result is embedded
+ assert daemon.calls == 0
diff --git a/libs/cua-driver/python/tests/test_uniffi_loader.py b/libs/cua-driver/python/tests/test_uniffi_loader.py
index 92a0ec2e7c..11d14e5180 100644
--- a/libs/cua-driver/python/tests/test_uniffi_loader.py
+++ b/libs/cua-driver/python/tests/test_uniffi_loader.py
@@ -30,9 +30,9 @@ class GeneratedOptionsTests(unittest.TestCase):
from cua_driver import CuaDriver
- # Released callers pass these by keyword; the helpers behind them are private.
+ # Released callers pass these by keyword; embedded is an additive keyword-only option.
self.assertEqual(str(inspect.signature(CuaDriver.connect)), "(socket_path)")
- self.assertEqual(str(inspect.signature(CuaDriver.create)), "(options=None)")
+ self.assertEqual(str(inspect.signature(CuaDriver.create)), "(options=None, *, embedded=False)")
def test_action_target_is_public_and_uses_the_generated_contract(self) -> None:
import cua_driver
diff --git a/libs/cua-driver/typescript/package.json b/libs/cua-driver/typescript/package.json
index 41d5c9aa4b..6e06b491ec 100644
--- a/libs/cua-driver/typescript/package.json
+++ b/libs/cua-driver/typescript/package.json
@@ -38,7 +38,9 @@
"dist/fleet.js",
"dist/fleet.d.ts",
"dist/native",
- "README.md"
+ "README.md",
+ "dist/daemon.js",
+ "dist/daemon.d.ts"
],
"publishConfig": {
"access": "public"
diff --git a/libs/cua-driver/typescript/src/daemon.ts b/libs/cua-driver/typescript/src/daemon.ts
new file mode 100644
index 0000000000..2f539a1e57
--- /dev/null
+++ b/libs/cua-driver/typescript/src/daemon.ts
@@ -0,0 +1,92 @@
+/**
+ * macOS daemon preference for `CuaDriver.create()`.
+ *
+ * An embedded (in-process) runtime on macOS has no AppKit host, so the agent
+ * cursor overlay cannot be drawn and permissions are attributed to the host
+ * process. The daemon (CuaDriver.app running `serve`) draws the cursor and owns
+ * the TCC grants, so on macOS `create()` connects to it, starting it through
+ * LaunchServices when the app is installed. No native dependency, so it is
+ * testable without the staged library.
+ */
+import { spawnSync } from "node:child_process"
+import { existsSync } from "node:fs"
+
+const APP_NAME = "CuaDriver"
+const APP_PATH = `/Applications/${APP_NAME}.app`
+const EMBEDDED_ENV = "CUA_DRIVER_EMBEDDED"
+
+export interface Availability {
+ isAvailable(): boolean
+}
+
+export interface CreateDriverHooks {
+ platform?: NodeJS.Platform
+ appInstalled?: () => boolean
+ launch?: () => boolean
+ timeoutMs?: number
+ sleep?: (ms: number) => void
+ warn?: (message: string) => void
+}
+
+let warned = false
+
+/** Reset the one-time warning (tests only). */
+export function resetDaemonWarning(): void {
+ warned = false
+}
+
+function launchApp(): boolean {
+ const result = spawnSync(
+ "/usr/bin/open",
+ ["-n", "-g", "-a", APP_NAME, "--args", "serve"],
+ { stdio: "ignore" },
+ )
+ return result.status === 0
+}
+
+function blockingSleep(ms: number): void {
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
+}
+
+export function createDriver<T extends Availability>(
+ connect: () => T,
+ createEmbedded: () => T,
+ embedded: boolean,
+ claudeCodeCompatibility: boolean,
+ hooks: CreateDriverHooks = {},
+): T {
+ const platform = hooks.platform ?? process.platform
+ if (
+ embedded ||
+ claudeCodeCompatibility ||
+ platform !== "darwin" ||
+ process.env[EMBEDDED_ENV] === "1"
+ ) {
+ return createEmbedded()
+ }
+
+ const driver = connect()
+ if (driver.isAvailable()) return driver
+
+ const installed = (hooks.appInstalled ?? (() => existsSync(APP_PATH)))()
+ if (installed && (hooks.launch ?? launchApp)()) {
+ const sleep = hooks.sleep ?? blockingSleep
+ const deadline = Date.now() + (hooks.timeoutMs ?? 15_000)
+ while (Date.now() < deadline) {
+ if (driver.isAvailable()) return driver
+ sleep(250)
+ }
+ }
+
+ if (!warned) {
+ warned = true
+ const message =
+ "CuaDriver.create() is using the in-process runtime, which cannot draw " +
+ "the agent cursor on macOS and attributes permissions to this process. " +
+ "Install CuaDriver.app and run `cua-driver serve` (or call " +
+ "CuaDriver.connect()) to get the agent cursor, or pass " +
+ "{ embedded: true } to silence this warning."
+ ;(hooks.warn ?? ((m) => process.emitWarning(m)))(message)
+ }
+ return createEmbedded()
+}
diff --git a/libs/cua-driver/typescript/src/index.ts b/libs/cua-driver/typescript/src/index.ts
index 6370b93337..e8f315f3f6 100644
--- a/libs/cua-driver/typescript/src/index.ts
+++ b/libs/cua-driver/typescript/src/index.ts
@@ -4,38 +4,68 @@
* Agents should configure `cua-driver mcp` through their runtime's existing
* MCP client instead of importing a language MCP facade.
*/
-import { CuaDriver, SdkClientKind } from "./native/cua_driver_sdk.js"
+import {
+ CuaDriver as NativeCuaDriver,
+ type CuaDriverLike,
+ type DriverOptions,
+ SdkClientKind,
+} from "./native/cua_driver_sdk.js"
+import { createDriver } from "./daemon.js"
+
+/**
+ * Options for `CuaDriver.create()`. `embedded: true` forces the in-process
+ * runtime on macOS, where `create()` otherwise prefers the CuaDriver.app
+ * daemon so the agent cursor overlay and the app's permissions work.
+ */
+export type CreateOptions = DriverOptions & { embedded?: boolean }
+
+const CuaDriver = NativeCuaDriver as typeof NativeCuaDriver & {
+ create(options?: CreateOptions): CuaDriverLike
+}
+type CuaDriver = NativeCuaDriver
// The same native library backs Python and TypeScript. The package root tags
// both the canonical same-process constructor and the temporary daemon
// compatibility constructor with the importing runtime.
-CuaDriver.create = (options) =>
- CuaDriver.createWithClientKind(options, SdkClientKind.Typescript)
-CuaDriver.createConfigured = (options) =>
- CuaDriver.createConfiguredWithClientKind(options, SdkClientKind.Typescript)
-CuaDriver.createConfiguredWithAuthorizationHost = (options, host) =>
- CuaDriver.createConfiguredWithAuthorizationHostAndClientKind(
+NativeCuaDriver.create = (options?: CreateOptions) => {
+ const { embedded, ...driverOptions } = options ?? {}
+ return createDriver(
+ () => NativeCuaDriver.connectWithClientKind(undefined, SdkClientKind.Typescript),
+ () =>
+ NativeCuaDriver.createWithClientKind(
+ options === undefined ? undefined : (driverOptions as DriverOptions),
+ SdkClientKind.Typescript,
+ ),
+ embedded === true,
+ (driverOptions as Partial<DriverOptions>).claudeCodeCompatibility === true,
+ )
+}
+NativeCuaDriver.createConfigured = (options) =>
+ NativeCuaDriver.createConfiguredWithClientKind(options, SdkClientKind.Typescript)
+NativeCuaDriver.createConfiguredWithAuthorizationHost = (options, host) =>
+ NativeCuaDriver.createConfiguredWithAuthorizationHostAndClientKind(
options,
host,
SdkClientKind.Typescript,
)
-CuaDriver.createConfiguredWithActivityObserver = (options, observer) =>
- CuaDriver.createConfiguredWithActivityObserverAndClientKind(
+NativeCuaDriver.createConfiguredWithActivityObserver = (options, observer) =>
+ NativeCuaDriver.createConfiguredWithActivityObserverAndClientKind(
options,
observer,
SdkClientKind.Typescript,
)
-CuaDriver.createConfiguredWithHostIntegrations = (options, host, observer) =>
- CuaDriver.createConfiguredWithHostIntegrationsAndClientKind(
+NativeCuaDriver.createConfiguredWithHostIntegrations = (options, host, observer) =>
+ NativeCuaDriver.createConfiguredWithHostIntegrationsAndClientKind(
options,
host,
observer,
SdkClientKind.Typescript,
)
-CuaDriver.createPrivateWorker = (options) =>
- CuaDriver.createPrivateWorkerWithClientKind(options, SdkClientKind.Typescript)
-CuaDriver.connect = (socketPath: string | undefined) =>
- CuaDriver.connectWithClientKind(socketPath, SdkClientKind.Typescript)
+NativeCuaDriver.createPrivateWorker = (options) =>
+ NativeCuaDriver.createPrivateWorkerWithClientKind(options, SdkClientKind.Typescript)
+NativeCuaDriver.connect = (socketPath: string | undefined) =>
+ NativeCuaDriver.connectWithClientKind(socketPath, SdkClientKind.Typescript)
export * from "./native/index.js"
+export { CuaDriver }
export { default } from "./native/index.js"
diff --git a/libs/cua-driver/typescript/test/daemon-default.test.mjs b/libs/cua-driver/typescript/test/daemon-default.test.mjs
new file mode 100644
index 0000000000..face3bae80
--- /dev/null
+++ b/libs/cua-driver/typescript/test/daemon-default.test.mjs
@@ -0,0 +1,62 @@
+import assert from "node:assert/strict"
+import { test } from "node:test"
+import { createDriver, resetDaemonWarning } from "../dist/daemon.js"
+
+const fake = (name, upAfter = 0) => {
+ let calls = 0
+ return { name, calls: () => calls, isAvailable: () => ++calls > upAfter }
+}
+const base = { platform: "darwin", sleep() {} }
+
+test("a running daemon is used on macOS", () => {
+ delete process.env.CUA_DRIVER_EMBEDDED
+ const daemon = fake("daemon")
+ const embedded = fake("embedded")
+ assert.equal(createDriver(() => daemon, () => embedded, false, false, base), daemon)
+})
+
+test("an installed app is launched and awaited", () => {
+ delete process.env.CUA_DRIVER_EMBEDDED
+ const daemon = fake("daemon", 2)
+ let launched = 0
+ const result = createDriver(() => daemon, () => fake("e"), false, false, {
+ ...base,
+ appInstalled: () => true,
+ launch: () => (launched++, true),
+ })
+ assert.equal(result, daemon)
+ assert.equal(launched, 1)
+})
+
+test("fallback to embedded warns once", () => {
+ delete process.env.CUA_DRIVER_EMBEDDED
+ resetDaemonWarning()
+ const warnings = []
+ const embedded = fake("embedded")
+ for (let i = 0; i < 2; i++) {
+ const result = createDriver(() => fake("d", 1e9), () => embedded, false, false, {
+ ...base,
+ appInstalled: () => false,
+ warn: (m) => warnings.push(m),
+ })
+ assert.equal(result, embedded)
+ }
+ assert.equal(warnings.length, 1)
+ assert.match(warnings[0], /agent cursor/)
+})
+
+test("embedded is forced by option, env, compat flag or non-macOS", () => {
+ delete process.env.CUA_DRIVER_EMBEDDED
+ const daemon = fake("daemon")
+ const embedded = fake("embedded")
+ const connect = () => daemon
+ const create = () => embedded
+ assert.equal(createDriver(connect, create, true, false, base), embedded)
+ assert.equal(createDriver(connect, create, false, true, base), embedded)
+ assert.equal(createDriver(connect, create, false, false, { platform: "linux" }), embedded)
+ assert.equal(createDriver(connect, create, false, false, { platform: "win32" }), embedded)
+ process.env.CUA_DRIVER_EMBEDDED = "1"
+ assert.equal(createDriver(connect, create, false, false, base), embedded)
+ delete process.env.CUA_DRIVER_EMBEDDED
+ assert.equal(daemon.calls(), 0)
+})