diff --git a/ci/test-file-size-budget.json b/ci/test-file-size-budget.json index 62b508af933..98fbb723603 100644 --- a/ci/test-file-size-budget.json +++ b/ci/test-file-size-budget.json @@ -7,7 +7,7 @@ "src/lib/onboard/preflight.test.ts": 1904, "test/generate-openclaw-config.test.ts": 1941, "test/install-preflight.test.ts": 3934, - "test/nemoclaw-start.test.ts": 4827, + "test/nemoclaw-start.test.ts": 4826, "test/onboard-messaging.test.ts": 2062, "test/onboard-selection.test.ts": 4834, "test/onboard.test.ts": 4057, diff --git a/scripts/nemoclaw-start.sh b/scripts/nemoclaw-start.sh index 0942992b182..14c36313297 100755 --- a/scripts/nemoclaw-start.sh +++ b/scripts/nemoclaw-start.sh @@ -2406,7 +2406,11 @@ start_auto_pair() { ) <<'PYAUTOPAIR' >>/tmp/auto-pair.log 2>&1 & import json import importlib.util +import base64 +import binascii +import hashlib import os +import re import stat import subprocess import time @@ -2431,10 +2435,11 @@ def load_approval_policy(path): return ( module.approval_request_decision, module.gateway_approval_env, + module.ALLOWED_SCOPES, ) -approval_request_decision, gateway_approval_env = load_approval_policy(APPROVAL_POLICY_FILE) +approval_request_decision, gateway_approval_env, policy_allowed_scopes = load_approval_policy(APPROVAL_POLICY_FILE) OPENCLAW = os.environ.get('OPENCLAW_BIN', 'openclaw') @@ -2520,6 +2525,208 @@ HANDLED = set() # Track rejected/approved requestIds to avoid reprocessing RUN_TIMEOUT_SECS = _env_seconds('NEMOCLAW_AUTO_PAIR_RUN_TIMEOUT_SECS', 10) + +def _read_json_object(path): + with open(path, 'r', encoding='utf-8') as handle: + data = json.load(handle) + if not isinstance(data, dict): + raise RuntimeError(f'{path} is not a JSON object') + return data + + +def _identity_public_key(identity): + raw = str(identity.get('publicKey', '') or '').strip() + if raw: + return raw + pem = str(identity.get('publicKeyPem', '') or '') + body = ''.join(line.strip() for line in pem.splitlines() if '---' not in line) + if not body: + return '' + der = base64.b64decode(body) + if len(der) < 32: + return '' + return base64.urlsafe_b64encode(der[-32:]).decode('ascii').rstrip('=') + + +def initial_cli_request_is_allowlisted(request_id): + # SOURCE_OF_TRUTH_REVIEW (NemoClaw#6113 gated-list bootstrap): + # Invalid state: `devices list --json` can be gated by the same initial + # CLI pairing request the watcher needs to approve, so the request id is + # only available in the structured error text. + # Source boundary: this function reads local OpenClaw pending/identity + # state only to validate the parsed request id before delegating approval + # back to `openclaw devices approve`, which owns locking, token creation, + # and state publication. The watcher never writes OpenClaw state. + # Source-fix constraint: OpenClaw should expose a first-run local + # bootstrap/list API that returns the pending request without requiring an + # already-approved device. This compatibility path supports packaged + # gateway builds that still gate list. + # Removal condition: delete this branch once the pinned OpenClaw release + # exposes that bootstrap/list API and NemoClaw no longer supports gated + # list behavior for first-run CLI pairing. + state_dir = os.environ.get('OPENCLAW_STATE_DIR') or '/sandbox/.openclaw' + pending_path = os.path.join(state_dir, 'devices', 'pending.json') + identity_path = os.path.join(state_dir, 'identity', 'device.json') + try: + pending = _read_json_object(pending_path) + identity = _read_json_object(identity_path) + request = pending.get(request_id) + if not isinstance(request, dict): + return False + # The map key is the authoritative request id. Reject a record whose + # embedded requestId is missing or disagrees with its key, so a + # malformed/tampered pending.json cannot approve a mismatched request. + # (PR #6330 review, cv item 3.) + if str(request.get('requestId', '') or '').strip() != str(request_id).strip(): + return False + device_id = str(identity.get('deviceId', '') or '').strip() + public_key = _identity_public_key(identity) + if not device_id or not public_key: + return False + public_key_raw = base64.urlsafe_b64decode(public_key + '=' * (-len(public_key) % 4)) + if len(public_key_raw) != 32 or hashlib.sha256(public_key_raw).hexdigest() != device_id: + return False + if str(request.get('deviceId', '')).strip() != device_id: + return False + if str(request.get('publicKey', '')).strip() != public_key: + return False + # OpenClaw CLI initial pairing records use clientId/clientMode `cli` + # in the observed DGX Spark/Station repros and in the paired-state + # fixtures for this PR. The broader policy still handles normal + # openclaw-cli scope upgrades through the main pending-list branch. + if str(request.get('clientId', '')).strip() != 'cli': + return False + if str(request.get('clientMode', '')).strip() != 'cli': + return False + roles = set() + role = request.get('role') + if role is not None: + if not isinstance(role, str) or not role.strip(): + return False + roles.add(role.strip()) + raw_roles = request.get('roles') + if raw_roles is not None: + if not isinstance(raw_roles, list): + return False + for item in raw_roles: + if not isinstance(item, str) or not item.strip(): + return False + roles.add(item.strip()) + if roles != {'operator'}: + return False + raw_scopes = request.get('scopes') + if not isinstance(raw_scopes, list) or not raw_scopes: + return False + scopes = set() + for item in raw_scopes: + if not isinstance(item, str) or not item.strip(): + return False + scope = item.strip() + if scope not in policy_allowed_scopes or scope in scopes: + return False + scopes.add(scope) + if scopes != {'operator.pairing'}: + return False + return approval_request_decision(request)['allowed'] is True + except (OSError, ValueError, RuntimeError, binascii.Error) as err: + print(f'[auto-pair] initial CLI pairing validation skipped request={request_id}: {brief_child_error("", str(err))}') + return False + + +def is_pairing_required_list_failure(out, err): + # SOURCE_OF_TRUTH_REVIEW (NemoClaw#6113 gated-list failure detection): + # Invalid state: initial `openclaw devices list --json` returns the gateway + # pairing-required denial instead of the pending request list. + # Source boundary: the compatibility trigger only recognizes the stable + # gateway denial text and still requires local pending/identity validation + # before approval is delegated to OpenClaw. + # Source-fix constraint: OpenClaw should expose a structured bootstrap/list + # API for first-run CLI pairing. + # Regression test: the non-pairing error fixture must not call approve. + # Removal condition: delete with initial_cli_request_is_allowlisted once the + # pinned OpenClaw release exposes that bootstrap/list API. + message = f'{out}\n{err}'.lower() + return 'pairing required' in message and 'device is not approved yet' in message + + +REQUEST_ID_RE = re.compile(r'^[A-Za-z0-9._:-]{1,128}$') + + +def _structured_request_ids(text): + try: + data = json.loads(text) + except Exception: + return [] + found = [] + + def walk(value): + if isinstance(value, dict): + for key, item in value.items(): + if key in {'requestId', 'request_id'} and isinstance(item, str): + found.append(item.strip()) + else: + walk(item) + elif isinstance(value, list): + for item in value: + walk(item) + + walk(data) + return found + + +def pairing_required_request_id(out, err): + # SOURCE_OF_TRUTH_REVIEW (NemoClaw#6113 gated-list requestId extraction): + # Invalid state: the requestId needed for canonical `devices approve` is + # sometimes only present in the list denial payload. + # Source boundary: parse one bounded requestId from structured JSON first, + # then from the reviewed error-text forms; ambiguous, overlong, or malformed + # output fails closed and never reaches approve. + # Source-fix constraint: OpenClaw should return requestId in a stable + # structured error field for this first-run bootstrap path. + # Regression test: malformed, overlong, whitespace, and multiple requestIds + # must not call approve. + # Removal condition: delete with initial_cli_request_is_allowlisted once the + # pinned OpenClaw release exposes a bootstrap/list API. + if not is_pairing_required_list_failure(out, err): + return None + message = f'{out}\n{err}' + if len(re.findall(r'\brequestId\b', message)) != 1: + return None + candidates = [] + for text in (out, err): + candidates.extend(_structured_request_ids(text)) + candidates.extend( + next(group for group in match.groups() if group is not None) + for match in re.finditer( + r'\brequestId\b["\']?\s*[:=]\s*(?:"([A-Za-z0-9._:-]{1,128})"(?=$|[,}\]\)])|\'([A-Za-z0-9._:-]{1,128})\'(?=$|[,}\]\)])|([A-Za-z0-9._:-]{1,128})(?=$|[,}\]\)]))', + message, + ) + ) + candidates.extend( + match.group(1).strip() + for match in re.finditer(r'\(requestId:\s*([A-Za-z0-9._:-]{1,128})\)', message) + ) + valid = [candidate for candidate in candidates if REQUEST_ID_RE.fullmatch(candidate)] + if not valid or len(set(valid)) != 1 or len(valid) != len(candidates): + return None + return valid[0] + + +def brief_child_error(out, err): + # SOURCE_OF_TRUTH_REVIEW (auto-pair child error summary): + # Invalid state: child openclaw failures often include noisy locale/setup + # output before the actual error. + # Source boundary: logs only the last non-empty child line, capped to 400 + # characters; decisions never depend on this summary. + # Source-fix constraint: OpenClaw should expose structured error codes so + # callers do not need stdout/stderr message summaries. + # Regression test: approve-failure fixtures assert the actionable child + # error remains visible. + # Removal condition: retire when OpenClaw CLI returns structured errors for + # the watched devices list/approve calls. + lines = [line.strip() for line in f'{err}\n{out}'.splitlines() if line.strip()] + return (lines[-1] if lines else '')[:400] + # Workaround boundary (NemoClaw#4462): the watcher child sources the trusted # runtime environment, so list calls resolve the same live gateway through # local loopback instead of the injected private-interface URL. Approval calls @@ -2575,8 +2782,37 @@ def sleep_for_next_poll(default_seconds, productive=True): while time.time() < DEADLINE: + # Fast-to-slow transition is checked at the TOP of every iteration — before + # any list/approve-failure `continue` below — so a permanently failing gated + # list/approve (or a sticky pending request) cannot hold the watcher in 1s + # polling for the full DEADLINE window; after FAST_DEADLINE it drops to + # SLOW_INTERVAL. Preventing that long-timeline re-creation of the + # NemoClaw#2484 connect-handler pile-up is exactly the point. + # (PR #6330 review, cv item 2.) + if not SLOW_MODE and time.time() >= FAST_DEADLINE: + SLOW_MODE = True + print(f'[auto-pair] fast-mode deadline reached; switching to slow-mode approvals={APPROVED}') rc, out, err = run(OPENCLAW, 'devices', 'list', '--json') if rc != 0 or not out: + initial_request_id = pairing_required_request_id(out, err) + if ( + initial_request_id + and initial_request_id not in HANDLED + and initial_cli_request_is_allowlisted(initial_request_id) + ): + arc, aout, aerr = run( + OPENCLAW, 'devices', 'approve', initial_request_id, '--json', strip_gateway_env=True, + ) + if arc == 0: + HANDLED.add(initial_request_id) + APPROVED += 1 + print(f'[auto-pair] approved initial CLI pairing request={initial_request_id}') + FAST_REENTRY_REMAINING = max(FAST_REENTRY_REMAINING, FAST_REENTRY_POLLS) + sleep_for_next_poll(FAST_REENTRY_INTERVAL) + continue + failure = brief_child_error(aout, aerr) + if arc != 124 and failure: + print(f'[auto-pair] initial CLI approve failed request={initial_request_id}: {failure}') sleep_for_next_poll(SLOW_INTERVAL if SLOW_MODE else 1, productive=False) continue try: @@ -2589,16 +2825,6 @@ while time.time() < DEADLINE: paired = data.get('paired') or [] has_browser = any((d.get('clientId') == 'openclaw-control-ui') or (d.get('clientMode') == 'webchat') for d in paired if isinstance(d, dict)) - # Fast-deadline transition is checked here, BEFORE the pending-branch - # `continue`, so that a sticky pending request (rejected unknown client - # added to HANDLED, or a permanent approve failure) cannot hold the - # watcher in 1s polling for the full DEADLINE window — that would - # re-create the NemoClaw#2484 connect-handler pile-up on a much longer - # timeline. - if not SLOW_MODE and time.time() >= FAST_DEADLINE: - SLOW_MODE = True - print(f'[auto-pair] fast-mode deadline reached; switching to slow-mode approvals={APPROVED}') - if pending: QUIET_POLLS = 0 attempted_request_ids = set() @@ -2643,8 +2869,10 @@ while time.time() < DEADLINE: HANDLED.add(request_id) APPROVED += 1 print(f'[auto-pair] approved request={request_id} client={client_id} mode={client_mode}') - elif aout or aerr: - print(f'[auto-pair] approve failed request={request_id}: {(aerr or aout)[:400]}') + else: + failure = brief_child_error(aout, aerr) + if failure: + print(f'[auto-pair] approve failed request={request_id}: {failure}') # Drop previously-bumped requestIds that the gateway no longer reports # as pending so a future re-appearance of the same id (very unlikely, # but kept robust) can bump again. The set is otherwise small and diff --git a/src/lib/actions/sandbox/auto-pair-approval.test.ts b/src/lib/actions/sandbox/auto-pair-approval.test.ts index ee3f8790322..a918ae3b590 100644 --- a/src/lib/actions/sandbox/auto-pair-approval.test.ts +++ b/src/lib/actions/sandbox/auto-pair-approval.test.ts @@ -97,6 +97,12 @@ describe("auto-pair approval pass behaviour (#4616)", () => { clientMode: "cli", requestedScopes: ["operator.pairing"], }, + { + requestId: "ok-agent-cli", + clientId: "cli", + clientMode: "cli", + requestedScopes: ["operator.pairing"], + }, { requestId: "deny-unknown", clientId: "evil", @@ -169,10 +175,10 @@ process.exit(2); ? fs.readFileSync(approveEnvFile, "utf-8").trim().split("\n").filter(Boolean) : []; - expect(approvals).toEqual(["ok-webchat", "ok-cli"]); + expect(approvals).toEqual(["ok-webchat", "ok-cli", "ok-agent-cli"]); // Gateway env stripped on the approve subprocess (#4462 workaround). - expect(approveEnv).toEqual(["unset:unset:unset", "unset:unset:unset"]); - expect(result.stdout).toContain(`${SUMMARY_MARKER}=2`); + expect(approveEnv).toEqual(["unset:unset:unset", "unset:unset:unset", "unset:unset:unset"]); + expect(result.stdout).toContain(`${SUMMARY_MARKER}=3`); } finally { fs.rmSync(tmpDir, { recursive: true, force: true }); } diff --git a/test/nemoclaw-start-auto-pair-bootstrap.test.ts b/test/nemoclaw-start-auto-pair-bootstrap.test.ts new file mode 100644 index 00000000000..ff4c5caea7b --- /dev/null +++ b/test/nemoclaw-start-auto-pair-bootstrap.test.ts @@ -0,0 +1,782 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { spawnSync } from "node:child_process"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +const START_SCRIPT = path.join(import.meta.dirname, "..", "scripts", "nemoclaw-start.sh"); +const APPROVAL_POLICY_DIR = path.join(import.meta.dirname, "..", "scripts", "lib"); + +function startScriptHeredoc(src: string, marker: string): string { + const match = src.match(new RegExp(`<<'${marker}'[^\\n]*\\n([\\s\\S]*?)\\n${marker}`)); + expect(match).not.toBeNull(); + return match![1]; +} + +function trustedApprovalPolicyFile(tmpDir: string): string { + const helperPath = path.join(tmpDir, "openclaw_device_approval_policy.py"); + fs.copyFileSync(path.join(APPROVAL_POLICY_DIR, "openclaw_device_approval_policy.py"), helperPath); + fs.chmodSync(helperPath, 0o444); + return helperPath; +} + +function autoPairPythonScript(src: string, tmpDir: string): string { + return startScriptHeredoc(src, "PYAUTOPAIR") + .replace( + "APPROVAL_POLICY_FILE = '/usr/local/lib/nemoclaw/openclaw_device_approval_policy.py'", + `APPROVAL_POLICY_FILE = ${JSON.stringify(trustedApprovalPolicyFile(tmpDir))}`, + ) + .replaceAll("time.time()", "_nemoclaw_test_time()") + .replaceAll("time.sleep(", "_nemoclaw_test_sleep(") + .replace( + "import time", + `import time +_nemoclaw_test_clock = [time.time()] +_nemoclaw_test_time = lambda: _nemoclaw_test_clock[0] +def _nemoclaw_test_sleep(seconds): _nemoclaw_test_clock.__setitem__(0, _nemoclaw_test_clock[0] + min(max(float(seconds), 0), 0.25)) +`, + ); +} + +describe("nemoclaw-start initial CLI auto-pair bootstrap (#6113)", () => { + const src = fs.readFileSync(START_SCRIPT, "utf-8"); + + it("approves an initial CLI pairing request when device list is itself gated (#6113)", () => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-bootstrap-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pendingFile = path.join(devicesDir, "pending.json"); + const pairedFile = path.join(devicesDir, "paired.json"); + const authFile = path.join(identityDir, "device-auth.json"); + const approveLog = path.join(tmpDir, "approve-env.json"); + const agentOutput = path.join(tmpDir, "agent-output.txt"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + version: 1, + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + pendingFile, + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + platform: "linux", + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + remoteIp: "10.200.0.2", + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + if [ -s ${JSON.stringify(pairedFile)} ]; then + cat <<'JSON' +{"pending":[],"paired":[{"deviceId":${JSON.stringify(deviceId)},"publicKey":${JSON.stringify(publicKey)},"clientId":"cli","clientMode":"cli","scopes":["operator.pairing"],"approvedScopes":["operator.pairing"]}]} +JSON + exit 0 + fi + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + cat > ${JSON.stringify(approveLog)} <<'JSON' +{"url":null,"port":null,"token":null,"args":["devices","approve","request-1","--json"]} +JSON + cat > ${JSON.stringify(pairedFile)} <<'JSON' +{${JSON.stringify(deviceId)}:{"deviceId":${JSON.stringify(deviceId)},"publicKey":${JSON.stringify(publicKey)},"clientId":"cli","clientMode":"cli","scopes":["operator.pairing"],"approvedScopes":["operator.pairing"]}} +JSON + exit 0 +fi +if [ "\${1:-}" = "agent" ]; then + if [ ! -s ${JSON.stringify(pairedFile)} ]; then + echo "EMBEDDED FALLBACK: gateway unavailable" + exit 0 + fi + printf 'tool:file-write-ok\\n' > ${JSON.stringify(agentOutput)} + echo "gateway agent completed" + exit 0 +fi +echo "unexpected: $*" >&2 +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + OPENCLAW_GATEWAY_TOKEN: "gateway-token", + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "3", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).toContain("[auto-pair] approved initial CLI pairing request=request-1"); + expect(JSON.parse(fs.readFileSync(approveLog, "utf-8"))).toEqual({ + url: null, + port: null, + token: null, + args: ["devices", "approve", "request-1", "--json"], + }); + const paired = JSON.parse(fs.readFileSync(pairedFile, "utf-8")); + expect(Object.keys(paired)).toEqual([deviceId]); + expect(paired[deviceId]).toMatchObject({ + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + scopes: ["operator.pairing"], + approvedScopes: ["operator.pairing"], + }); + expect(fs.existsSync(authFile)).toBe(false); + expect(JSON.parse(fs.readFileSync(pendingFile, "utf-8"))).toHaveProperty("request-1"); + + const agent = spawnSync(fakeOpenclaw, ["agent", "run", "write-file"], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_STATE_DIR: stateDir, + }, + timeout: 10_000, + }); + expect(agent.status).toBe(0); + expect(`${agent.stdout}\n${agent.stderr}`).not.toContain("EMBEDDED FALLBACK"); + expect(fs.readFileSync(agentOutput, "utf-8")).toBe("tool:file-write-ok\n"); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, 40_000); + + it.each([ + ["mismatched embedded requestId", { requestId: "request-2" }], + ["missing embedded requestId", { requestId: "" }], + ["mismatched public key", { publicKey: "wrong" }], + ["non-cli client id", { clientId: "browser" }], + ["non-cli client mode", { clientMode: "webchat" }], + ["non-operator role", { role: "viewer", roles: ["viewer"] }], + ["empty role", { role: "" }], + ["malformed roles", { roles: "operator" }], + ["empty role entry", { roles: ["operator", ""] }], + ["malformed scopes", { scopes: "operator.pairing" }], + ["empty scopes", { scopes: [] }], + ["duplicate scopes", { scopes: ["operator.pairing", "operator.pairing"] }], + ["extra allowed scope", { scopes: ["operator.pairing", "operator.write"] }], + ["disallowed scope", { scopes: ["operator.pairing", "admin.write"] }], + ["missing pairing scope", { scopes: ["operator.write"] }], + ])( + "rejects %s before initial CLI approve (#6113)", + (_name, override) => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-reject-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pendingFile = path.join(devicesDir, "pending.json"); + const approveLog = path.join(tmpDir, "approve-called"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + pendingFile, + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + ...override, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + touch ${JSON.stringify(approveLog)} + exit 0 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "1", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).not.toContain("approved initial CLI pairing"); + expect(fs.existsSync(approveLog)).toBe(false); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, + 40_000, + ); + + it.each([ + [ + "multiple request ids", + "pairing required: device is not approved yet requestId: request-1 requestId: request-2", + ], + ["missing request id", "pairing required: device is not approved yet"], + [ + "overlong request id", + `pairing required: device is not approved yet requestId: ${"r".repeat(129)}`, + ], + [ + "overlong request id with pending prefix", + `pairing required: device is not approved yet requestId: ${"p".repeat(129)}`, + ], + [ + "whitespace request id", + "pairing required: device is not approved yet (requestId: request 1)", + ], + [ + "whitespace request id with pending prefix", + "pairing required: device is not approved yet requestId: request 1", + ], + [ + "quoted request id with trailing text", + 'pairing required: device is not approved yet requestId: "request" 1', + ], + ])( + "rejects %s from gated-list errors before initial CLI approve (#6113)", + (_name, listError) => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-requestid-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pendingFile = path.join(devicesDir, "pending.json"); + const approveLog = path.join(tmpDir, "approve-called"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + const validRequest = { + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + pendingFile, + JSON.stringify({ + "request-1": { requestId: "request-1", ...validRequest }, + "request-2": { requestId: "request-2", ...validRequest }, + ["r".repeat(129)]: { requestId: "r".repeat(129), ...validRequest }, + ["p".repeat(128)]: { requestId: "p".repeat(128), ...validRequest }, + "request 1": { requestId: "request 1", ...validRequest }, + request: { requestId: "request", ...validRequest }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' ${JSON.stringify(listError)} + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + touch ${JSON.stringify(approveLog)} + exit 0 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "1", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).not.toContain("approved initial CLI pairing"); + expect(fs.existsSync(approveLog)).toBe(false); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, + 40_000, + ); + + it.each([ + ["missing identity device id", { deviceId: undefined }], + ["missing identity public key", { publicKeyPem: undefined }], + [ + "malformed identity public key PEM", + { publicKeyPem: "-----BEGIN PUBLIC KEY-----\nnot-base64\n-----END PUBLIC KEY-----\n" }, + ], + ["mismatched identity device id", { deviceId: "not-the-device" }], + ["short identity public key", { publicKey: "short" }], + [ + "identity public key with wrong hash", + { publicKey: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, + ], + ])( + "rejects %s before initial CLI approve (#6113)", + (_name, identityOverride) => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-identity-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const approveLog = path.join(tmpDir, "approve-called"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + ...identityOverride, + }), + ); + fs.writeFileSync( + path.join(devicesDir, "pending.json"), + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + touch ${JSON.stringify(approveLog)} + exit 0 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "1", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).not.toContain("approved initial CLI pairing"); + expect(fs.existsSync(approveLog)).toBe(false); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, + 40_000, + ); + + it("fails closed for malformed identity public keys without terminating the watcher (#6113)", () => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-bad-identity-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const approveLog = path.join(tmpDir, "approve-called"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId: "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47", + publicKeyPem: "-----BEGIN PUBLIC KEY-----\nnot-valid-base64\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + path.join(devicesDir, "pending.json"), + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId: "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47", + publicKey: "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8", + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + touch ${JSON.stringify(approveLog)} + exit 0 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "1", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).not.toContain("approved initial CLI pairing"); + expect(fs.existsSync(approveLog)).toBe(false); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, 40_000); + + it("retries a transient initial CLI approve failure on the next gated-list poll (#6113)", () => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-retry-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pendingFile = path.join(devicesDir, "pending.json"); + const approveCount = path.join(tmpDir, "approve-count"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + pendingFile, + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + count=0 + if [ -f ${JSON.stringify(approveCount)} ]; then + count=$(cat ${JSON.stringify(approveCount)}) + fi + count=$((count + 1)) + printf '%s' "$count" > ${JSON.stringify(approveCount)} + if [ "$count" -eq 1 ]; then + echo "gateway restarting" >&2 + exit 1 + fi + exit 0 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "2", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(fs.readFileSync(approveCount, "utf-8")).toBe("2"); + expect(run.stdout).toContain( + "[auto-pair] initial CLI approve failed request=request-1: gateway restarting", + ); + expect(run.stdout).toContain("[auto-pair] approved initial CLI pairing request=request-1"); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, 40_000); + + it("drops a permanently-failing gated approve to slow-mode instead of 1s-looping to the deadline (#6113)", () => { + // cv #6330 item 2: the fast->slow transition must be reached even when the + // gated list/approve path keeps failing and `continue`s. With a near-zero + // FAST_DEADLINE the first iteration must emit the slow-mode transition + // (proving the check runs before the failure `continue`), and the watcher + // must exit within the short deadline rather than busy-polling at 1s. + // (`_env_seconds` rejects a literal 0 as non-positive, so use a tiny value.) + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-permfail-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pendingFile = path.join(devicesDir, "pending.json"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + pendingFile, + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then + printf '%s\\n' '{"ok":false,"error":{"reason":"pairing required: device is not approved yet (requestId: request-1)"}}' + exit 1 +fi +if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then + echo "gateway permanently unavailable" >&2 + exit 1 +fi +exit 2 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_FAST_DEADLINE_SECS: "0.01", + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "1", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + // The transition fired on the permanently-failing gated path (loop-top check). + expect(run.stdout).toContain( + "[auto-pair] fast-mode deadline reached; switching to slow-mode", + ); + expect(run.stdout).toContain( + "[auto-pair] initial CLI approve failed request=request-1: gateway permanently unavailable", + ); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, 40_000); + + it("does not seed when device list fails for a non-pairing error (#6113)", () => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-auto-pair-nonpairing-")); + const fakeOpenclaw = path.join(tmpDir, "openclaw"); + const stateDir = path.join(tmpDir, "state"); + const devicesDir = path.join(stateDir, "devices"); + const identityDir = path.join(stateDir, "identity"); + const pairedFile = path.join(devicesDir, "paired.json"); + const authFile = path.join(identityDir, "device-auth.json"); + fs.mkdirSync(devicesDir, { recursive: true }); + fs.mkdirSync(identityDir, { recursive: true }); + const publicKey = "y3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8"; + const deviceId = "04a4c561c730435e9f6a2e38d2e7b929bcbec2ea1c37d3dd053f3341ecce4e47"; + fs.writeFileSync( + path.join(identityDir, "device.json"), + JSON.stringify({ + version: 1, + deviceId, + publicKeyPem: + "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAy3vjb9p8tAecivI1l5f1Hdc9QdZJSt3BmLkJMM7wZD8=\n-----END PUBLIC KEY-----\n", + }), + ); + fs.writeFileSync( + path.join(devicesDir, "pending.json"), + JSON.stringify({ + "request-1": { + requestId: "request-1", + deviceId, + publicKey, + clientId: "cli", + clientMode: "cli", + role: "operator", + roles: ["operator"], + scopes: ["operator.pairing"], + ts: 100, + }, + }), + ); + fs.writeFileSync( + fakeOpenclaw, + `#!/usr/bin/env bash +set -euo pipefail +printf '%s\\n' '{"ok":false,"error":{"reason":"gateway unavailable"}}' +exit 1 +`, + { mode: 0o755 }, + ); + + try { + const run = spawnSync("python3", ["-c", autoPairPythonScript(src, tmpDir)], { + encoding: "utf-8", + env: { + ...process.env, + OPENCLAW_BIN: fakeOpenclaw, + OPENCLAW_STATE_DIR: stateDir, + NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "2", + NEMOCLAW_AUTO_PAIR_SLOW_INTERVAL_SECS: "1", + }, + timeout: 30_000, + }); + + expect(run.status).toBe(0); + expect(run.stdout).not.toContain("approved initial CLI pairing"); + expect(fs.existsSync(pairedFile)).toBe(false); + expect(fs.existsSync(authFile)).toBe(false); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }, 40_000); +}); diff --git a/test/nemoclaw-start.test.ts b/test/nemoclaw-start.test.ts index 18c9064c4ef..d5873b8baa6 100644 --- a/test/nemoclaw-start.test.ts +++ b/test/nemoclaw-start.test.ts @@ -548,7 +548,6 @@ describe("nemoclaw-start non-root fallback", () => { ["#!/usr/bin/env bash", "set -euo pipefail", fn, "fix_openclaw_ownership"].join("\n"), { mode: 0o700 }, ); - try { const result = spawnSync("bash", [scriptPath], { encoding: "utf-8", @@ -1554,6 +1553,7 @@ describe("nemoclaw-start auto-pair client whitelisting (#117)", () => { "not-a-device", { requestId: "ok-browser", clientId: "openclaw-control-ui", clientMode: "unknown" }, { requestId: "ok-browser", clientId: "openclaw-control-ui", clientMode: "unknown" }, + { requestId: "ok-agent-cli", clientId: "cli", clientMode: "cli" }, { requestId: "ok-webchat", clientId: "other-client", clientMode: "webchat" }, { requestId: "reject-me", clientId: "evil-client", clientMode: "unknown" }, ], @@ -1592,7 +1592,6 @@ exit 2 ); const autoPairScript = autoPairPythonScript(src); - try { const run = spawnSync("python3", ["-c", autoPairScript], { encoding: "utf-8", @@ -1613,22 +1612,26 @@ exit 2 expect(run.stdout).toContain( "[auto-pair] approved request=ok-browser client=openclaw-control-ui", ); + expect(run.stdout).toContain("[auto-pair] approved request=ok-agent-cli client=cli mode=cli"); expect(run.stdout).toContain("[auto-pair] rejected unknown client=other-client mode=webchat"); expect(run.stdout).toContain("[auto-pair] rejected unknown client=evil-client mode=unknown"); expect(run.stdout).toContain( - "[auto-pair] browser pairing converged; entering slow-mode approvals=1", + "[auto-pair] browser pairing converged; entering slow-mode approvals=2", ); - expect(fs.readFileSync(approveLog, "utf-8").trim().split("\n")).toEqual(["ok-browser"]); + expect(fs.readFileSync(approveLog, "utf-8").trim().split("\n")).toEqual([ + "ok-browser", + "ok-agent-cli", + ]); const envLogLines = fs.readFileSync(envLog, "utf-8").trim().split("\n"); expect(envLogLines).toContain("list:ws://127.0.0.1:18789:18789:test-gateway-token"); expect(envLogLines).toContain("approve:ok-browser:unset:unset:unset"); + expect(envLogLines).toContain("approve:ok-agent-cli:unset:unset:unset"); expect(envLogLines).not.toContain("approve:ok-webchat:unset:unset:unset"); } finally { fs.rmSync(tmpDir, { recursive: true, force: true }); } }, 40_000); }); - describe("nemoclaw-start auto-pair slow-mode keepalive (#4263)", () => { const src = fs.readFileSync(START_SCRIPT, "utf-8"); @@ -1651,7 +1654,7 @@ describe("nemoclaw-start auto-pair slow-mode keepalive (#4263)", () => { const stateFile = path.join(tmpDir, "list-count"); const approveLog = path.join(tmpDir, "approvals.log"); const browserClient = { clientId: "openclaw-control-ui", clientMode: "webchat" }; - const cliClient = { clientId: "openclaw-cli", clientMode: "cli" }; + const cliClient = { clientId: "cli", clientMode: "cli" }; const initialPending = JSON.stringify({ pending: [{ requestId: "browser-pair", ...browserClient }], paired: [], @@ -1717,12 +1720,8 @@ exit 2 "[auto-pair] browser pairing converged; entering slow-mode approvals=1", ); // Concurrent late wave — proxy for two sibling sandboxes' upgrades. - expect(run.stdout).toContain( - "[auto-pair] approved request=late-cli client=openclaw-cli mode=cli", - ); - expect(run.stdout).toContain( - "[auto-pair] approved request=late-cli-b client=openclaw-cli mode=cli", - ); + expect(run.stdout).toContain("[auto-pair] approved request=late-cli client=cli mode=cli"); + expect(run.stdout).toContain("[auto-pair] approved request=late-cli-b client=cli mode=cli"); expect(run.stdout).toContain("watcher deadline reached approvals=3"); // Single marker per poll wave, transition after convergence. expect(run.stdout).toContain("[auto-pair] fast-reentry bumped polls=3 approved=3 mode=slow");