Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
248 lines
10 KiB
Swift
248 lines
10 KiB
Swift
import Foundation
|
|
import OpenClawKit
|
|
import Testing
|
|
|
|
struct GatewayErrorsTests {
|
|
@Test func `bootstrap token invalid is non recoverable`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "setup code expired",
|
|
detailCode: GatewayConnectAuthDetailCode.authBootstrapTokenInvalid.rawValue,
|
|
canRetryWithDeviceToken: false)
|
|
|
|
#expect(error.isNonRecoverable)
|
|
#expect(error.detail == .authBootstrapTokenInvalid)
|
|
}
|
|
|
|
@Test func `connect auth error preserves structured metadata`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "pairing required",
|
|
detailCode: GatewayConnectAuthDetailCode.pairingRequired.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
recommendedNextStep: "review_auth_configuration",
|
|
requestId: "req-123",
|
|
detailsReason: "scope-upgrade",
|
|
ownerRaw: "gateway",
|
|
titleOverride: "Additional permissions required",
|
|
userMessageOverride: "Approve the requested permissions on the gateway, then reconnect.",
|
|
actionLabel: "Approve on gateway",
|
|
actionCommand: "openclaw devices approve req-123",
|
|
docsURLString: "https://docs.openclaw.ai/gateway/pairing",
|
|
retryableOverride: false,
|
|
pauseReconnectOverride: true,
|
|
clientMinProtocol: 4,
|
|
clientMaxProtocol: 4,
|
|
expectedProtocol: 5,
|
|
minimumProbeProtocol: 4)
|
|
|
|
#expect(error.requestId == "req-123")
|
|
#expect(error.detailsReason == "scope-upgrade")
|
|
#expect(error.ownerRaw == "gateway")
|
|
#expect(error.titleOverride == "Additional permissions required")
|
|
#expect(error.actionCommand == "openclaw devices approve req-123")
|
|
#expect(error.docsURLString == "https://docs.openclaw.ai/gateway/pairing")
|
|
#expect(error.pauseReconnectOverride == true)
|
|
#expect(error.clientMinProtocol == 4)
|
|
#expect(error.clientMaxProtocol == 4)
|
|
#expect(error.expectedProtocol == 5)
|
|
#expect(error.minimumProbeProtocol == 4)
|
|
}
|
|
|
|
@Test func `protocol mismatch maps older app to update problem`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "protocol mismatch",
|
|
detailCode: GatewayConnectAuthDetailCode.protocolMismatch.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
clientMinProtocol: 4,
|
|
clientMaxProtocol: 4,
|
|
expectedProtocol: 5,
|
|
minimumProbeProtocol: 4)
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(error.detail == .protocolMismatch)
|
|
#expect(error.isNonRecoverable)
|
|
#expect(problem?.kind == .protocolMismatch)
|
|
#expect(problem?.owner == .iphone)
|
|
#expect(problem?.title == "App update required")
|
|
#expect(problem?.message == "This app is older than the gateway. Update OpenClaw on this device, then retry.")
|
|
#expect(problem?.retryable == false)
|
|
#expect(problem?.pauseReconnect == true)
|
|
#expect(problem?.technicalDetails?.contains("clientProtocol=4") == true)
|
|
#expect(problem?.technicalDetails?.contains("gatewayProtocol=5") == true)
|
|
}
|
|
|
|
@Test func `protocol mismatch maps older gateway to update problem`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "protocol mismatch",
|
|
detailCode: GatewayConnectAuthDetailCode.protocolMismatch.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
clientMinProtocol: 4,
|
|
clientMaxProtocol: 4,
|
|
expectedProtocol: 3,
|
|
minimumProbeProtocol: 3)
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .protocolMismatch)
|
|
#expect(problem?.owner == .gateway)
|
|
#expect(problem?.title == "Gateway update required")
|
|
#expect(problem?
|
|
.message == "The gateway is older than this app. Update OpenClaw on the gateway host, then retry.")
|
|
#expect(problem?.retryable == false)
|
|
#expect(problem?.pauseReconnect == true)
|
|
}
|
|
|
|
@Test func `protocol mismatch without versions still gives actionable fallback`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "protocol mismatch",
|
|
detailCode: GatewayConnectAuthDetailCode.protocolMismatch.rawValue,
|
|
canRetryWithDeviceToken: false)
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .protocolMismatch)
|
|
#expect(problem?.owner == .both)
|
|
#expect(problem?
|
|
.message == "The app and gateway use incompatible protocol versions. Update OpenClaw on both, then retry.")
|
|
#expect(problem?.retryable == false)
|
|
#expect(problem?.pauseReconnect == true)
|
|
}
|
|
|
|
@Test func `pairing problem uses structured request metadata`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "pairing required",
|
|
detailCode: GatewayConnectAuthDetailCode.pairingRequired.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
requestId: "req-123",
|
|
detailsReason: "scope-upgrade")
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .pairingScopeUpgradeRequired)
|
|
#expect(problem?.requestId == "req-123")
|
|
#expect(problem?.pauseReconnect == true)
|
|
#expect(problem?.actionCommand == "openclaw devices approve req-123")
|
|
}
|
|
|
|
@Test func `scope mismatch maps to pairing or repair problem`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "device token scope mismatch",
|
|
detailCode: GatewayConnectAuthDetailCode.authScopeMismatch.rawValue,
|
|
canRetryWithDeviceToken: false)
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(error.detail == .authScopeMismatch)
|
|
#expect(error.isNonRecoverable)
|
|
#expect(problem?.kind == .deviceTokenScopeMismatch)
|
|
#expect(problem?.needsPairingApproval == true)
|
|
#expect(problem?.needsCredentialUpdate == false)
|
|
}
|
|
|
|
@Test func `token mismatch suggests onboarding reset`() {
|
|
let error = GatewayConnectAuthError(
|
|
message: "token mismatch",
|
|
detailCode: GatewayConnectAuthDetailCode.authTokenMismatch.rawValue,
|
|
canRetryWithDeviceToken: false)
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .gatewayAuthTokenMismatch)
|
|
#expect(problem?.suggestsOnboardingReset == true)
|
|
#expect(problem?.needsCredentialUpdate == true)
|
|
}
|
|
|
|
@Test func `cancelled transport does not replace structured pairing problem`() {
|
|
let pairing = GatewayConnectAuthError(
|
|
message: "pairing required",
|
|
detailCode: GatewayConnectAuthDetailCode.pairingRequired.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
requestId: "req-123")
|
|
let previousProblem = GatewayConnectionProblemMapper.map(error: pairing)
|
|
let cancelled = NSError(
|
|
domain: URLError.errorDomain,
|
|
code: URLError.cancelled.rawValue,
|
|
userInfo: [NSLocalizedDescriptionKey: "gateway receive: cancelled"])
|
|
|
|
let preserved = GatewayConnectionProblemMapper.map(error: cancelled, preserving: previousProblem)
|
|
|
|
#expect(preserved?.kind == .pairingRequired)
|
|
#expect(preserved?.requestId == "req-123")
|
|
}
|
|
|
|
@Test func `unmapped transport error clears stale structured problem`() {
|
|
let pairing = GatewayConnectAuthError(
|
|
message: "pairing required",
|
|
detailCode: GatewayConnectAuthDetailCode.pairingRequired.rawValue,
|
|
canRetryWithDeviceToken: false,
|
|
requestId: "req-123")
|
|
let previousProblem = GatewayConnectionProblemMapper.map(error: pairing)
|
|
let unknownTransport = NSError(
|
|
domain: NSURLErrorDomain,
|
|
code: -1202,
|
|
userInfo: [NSLocalizedDescriptionKey: "certificate chain validation failed"])
|
|
|
|
let mapped = GatewayConnectionProblemMapper.map(error: unknownTransport, preserving: previousProblem)
|
|
|
|
#expect(mapped == nil)
|
|
}
|
|
|
|
@Test func `tls pin mismatch maps to actionable problem`() {
|
|
let error = GatewayTLSValidationError(
|
|
failure: GatewayTLSValidationFailure(
|
|
kind: .pinMismatch,
|
|
host: "gateway.example.ts.net",
|
|
storeKey: "gateway.example.ts.net:443",
|
|
expectedFingerprint: "old",
|
|
observedFingerprint: "new",
|
|
systemTrustOk: true),
|
|
context: "connect to gateway")
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .tlsPinMismatch)
|
|
#expect(problem?.retryable == false)
|
|
#expect(problem?.pauseReconnect == true)
|
|
#expect(problem?.actionLabel == "Review certificate")
|
|
#expect(problem?.canTrustRotatedCertificate == true)
|
|
#expect(problem?.tlsStoreKey == "gateway.example.ts.net:443")
|
|
#expect(problem?.tlsExpectedFingerprint == "old")
|
|
#expect(problem?.tlsObservedFingerprint == "new")
|
|
}
|
|
|
|
@Test func `untrusted TLS certificate pauses reconnect`() {
|
|
let error = GatewayTLSValidationError(
|
|
failure: GatewayTLSValidationFailure(
|
|
kind: .untrustedCertificate,
|
|
host: "gateway.example.com",
|
|
storeKey: "gateway.example.com:443",
|
|
expectedFingerprint: nil,
|
|
observedFingerprint: nil,
|
|
systemTrustOk: false),
|
|
context: "connect to gateway")
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .tlsCertificateUntrusted)
|
|
#expect(problem?.retryable == false)
|
|
#expect(problem?.pauseReconnect == true)
|
|
}
|
|
|
|
@Test func `untrusted TLS mismatch cannot be recovered in app`() {
|
|
let error = GatewayTLSValidationError(
|
|
failure: GatewayTLSValidationFailure(
|
|
kind: .pinMismatch,
|
|
host: "gateway.example.ts.net",
|
|
storeKey: "gateway.example.ts.net:443",
|
|
expectedFingerprint: "old",
|
|
observedFingerprint: "new",
|
|
systemTrustOk: false),
|
|
context: "connect to gateway")
|
|
|
|
let problem = GatewayConnectionProblemMapper.map(error: error)
|
|
|
|
#expect(problem?.kind == .tlsPinMismatch)
|
|
#expect(problem?.canTrustRotatedCertificate == false)
|
|
}
|
|
}
|