Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
efe49ef
test(e2e): bound scope watcher to install
rsliter Aug 27, 2026
d09ad26
test(e2e): address watcher review findings
rsliter Aug 27, 2026
47422a8
test(e2e): remove duplicate approval actions
rsliter Aug 27, 2026
9257b97
test(e2e): make scope approval watcher-owned
rsliter Aug 27, 2026
4dc3303
test(e2e): address scope approval review
rsliter Aug 27, 2026
08521bb
merge: sync main into scope approval fix
rsliter Aug 27, 2026
6cb2aa2
test(e2e): keep gateway snapshot identity private
rsliter Aug 27, 2026
bdfd7a2
test(e2e): simplify scope approval proof
rsliter Aug 27, 2026
aaccf9c
test(e2e): harden approval evidence
rsliter Aug 27, 2026
fe9f2c7
test(e2e): bind admin approval evidence
prekshivyas Aug 27, 2026
9bc41a6
test(e2e): upload scope observer to directory
prekshivyas Aug 27, 2026
09b35c3
Merge branch 'main' into codex/fix-e2e-watcher-lifetime
prekshivyas Aug 27, 2026
588da2e
test(e2e): bind gateway snapshot identity
prekshivyas Aug 27, 2026
27880fb
test(e2e): clarify approval assertions
rsliter Aug 27, 2026
8ab9d59
test(e2e): classify admin approval failures
rsliter Aug 27, 2026
c32edfd
test(e2e): clarify observer upload contract
rsliter Aug 27, 2026
e4cc2d2
test(e2e): name Docker availability phase
rsliter Aug 27, 2026
26d2b20
Merge branch 'main' into codex/fix-e2e-watcher-lifetime
prekshivyas Aug 27, 2026
b59d303
test(e2e): preserve fast watcher reentry
rsliter Aug 27, 2026
a9a5f17
test(e2e): clarify watcher poll cadence
rsliter Aug 27, 2026
1424727
fix(e2e): preserve host path in shell probes
prekshivyas Aug 27, 2026
ed3d718
merge: resolve conflicts with main
github-actions[bot] Aug 27, 2026
29d65f2
test(e2e): use default watcher reentry
rsliter Aug 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions test/e2e/lib/issue-4462-fresh-agent-gateway-snapshot.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import base64
import binascii
import hashlib
import json
import re
import sys
import time
from pathlib import Path

minimum_gateway_runs = int(sys.argv[1])
root = Path("/sandbox/.openclaw")
output_mode = sys.argv[2] if len(sys.argv) > 2 else "snapshot"
if output_mode not in {"snapshot", "gateway-runs"}:
raise SystemExit(f"unsupported output mode: {output_mode}")
timeout_seconds = float(sys.argv[3]) if len(sys.argv) > 3 else 30
if timeout_seconds <= 0:
raise SystemExit("observation timeout must be positive")
root = Path(sys.argv[4]) if len(sys.argv) > 4 else Path("/sandbox/.openclaw")
gateway_log = Path(sys.argv[5]) if len(sys.argv) > 5 else Path("/tmp/gateway.log")
observation_deadline = time.monotonic() + timeout_seconds


def norm(value):
Expand All @@ -25,19 +36,65 @@ def load_map(path):
return value


def identity_public_key(value):
direct = norm(value.get("publicKey"))
if direct:
return direct
pem = norm(value.get("publicKeyPem"))
if not pem:
return ""
body = "".join(line.strip() for line in pem.splitlines() if not line.startswith("-----"))
try:
der = base64.b64decode(body, validate=True)
except Exception:
return ""
prefix = bytes.fromhex("302a300506032b6570032100")
if len(der) != len(prefix) + 32 or not der.startswith(prefix):
return ""
return base64.urlsafe_b64encode(der[len(prefix) :]).decode("ascii").rstrip("=")


def gateway_completed_runs():
try:
value = Path("/tmp/gateway.log").read_text(encoding="utf-8", errors="replace")
value = gateway_log.read_text(encoding="utf-8", errors="replace")
except FileNotFoundError:
return 0
return len(re.findall(r"\[agent\] run \S+ ended with stopReason=", value))


def wait_for_gateway_runs():
runs = gateway_completed_runs()
while runs < minimum_gateway_runs and time.monotonic() < observation_deadline:
time.sleep(0.1)
runs = gateway_completed_runs()
return runs
Comment thread
prekshivyas marked this conversation as resolved.
Resolved


if output_mode == "gateway-runs":
print(json.dumps({"gatewayCompletedRuns": wait_for_gateway_runs()}, sort_keys=True))
raise SystemExit(0)


identity = load_map(root / "identity" / "device.json")
device_id = norm(identity.get("deviceId"))
if not device_id:
raise SystemExit("CLI identity has no deviceId")
pairing_deadline = time.monotonic() + 10
identity_key = identity_public_key(identity)
if not identity_key:
raise SystemExit("CLI identity has no public key")
try:
identity_key_raw = base64.b64decode(
identity_key + "=" * (-len(identity_key) % 4),
altchars=b"-_",
validate=True,
)
except (binascii.Error, ValueError):
raise SystemExit("CLI identity public key is invalid") from None
if (
len(identity_key_raw) != 32
or hashlib.sha256(identity_key_raw).hexdigest() != device_id
):
raise SystemExit("CLI identity binding is invalid")
while True:
pending = [
value
Expand All @@ -54,8 +111,13 @@ def gateway_completed_runs():
for value in paired
if value.get("clientId") == "cli" and value.get("clientMode") == "cli"
]
matching = [value for value in paired_cli if norm(value.get("deviceId")) == device_id]
if len(matching) == 1 or time.monotonic() >= pairing_deadline:
matching = [
value
for value in paired_cli
if norm(value.get("deviceId")) == device_id
and norm(value.get("publicKey")) == identity_key
]
if len(matching) == 1 or time.monotonic() >= observation_deadline:
break
time.sleep(0.1)
if len(matching) != 1:
Expand Down Expand Up @@ -86,11 +148,7 @@ def gateway_completed_runs():
and norm(token.get("role")) == "operator"
and not token.get("revokedAtMs")
]
deadline = time.monotonic() + 5
runs = gateway_completed_runs()
while runs < minimum_gateway_runs and time.monotonic() < deadline:
time.sleep(0.1)
runs = gateway_completed_runs()
runs = wait_for_gateway_runs()
print(
json.dumps(
{
Expand All @@ -110,15 +168,13 @@ def gateway_completed_runs():
if norm(scope)
}
),
"deviceId": device_id,
"deviceScopes": sorted(
{norm(scope) for scope in (device.get("scopes") or []) if norm(scope)}
),
"gatewayCompletedRuns": runs,
"matchingPairedCount": len(matching),
"pairedCliCount": len(paired_cli),
"pendingCount": len(pending),
"publicKey": norm(device.get("publicKey")),
"sameDevicePendingCount": sum(
1 for value in pending if norm(value.get("deviceId")) == device_id
),
Expand Down
Loading
Loading