import Foundation import OpenClawDiscovery import OpenClawIPC import SwiftUI import Testing @testable import OpenClaw @Suite(.serialized) @MainActor struct OnboardingViewSmokeTests { @Test func `onboarding view builds body`() { let state = AppState(preview: true) let view = OnboardingView( state: state, permissionMonitor: PermissionMonitor.shared, discoveryModel: GatewayDiscoveryModel(localDisplayName: InstanceIdentity.displayName)) _ = view.body } @Test func `page order omits workspace and identity steps`() { let order = OnboardingView.pageOrder( for: .local, showOnboardingChat: false, requiresCLIInstall: false) #expect(!order.contains(7)) #expect(order.contains(3)) } @Test func `page order omits onboarding chat when identity known`() { let order = OnboardingView.pageOrder( for: .local, showOnboardingChat: false, requiresCLIInstall: false) #expect(!order.contains(8)) } @Test func `fresh local setup installs CLI before the Crestodian chat`() { let order = OnboardingView.pageOrder( for: .local, showOnboardingChat: false, requiresCLIInstall: true) #expect(order.firstIndex(of: 2) == 2) #expect(order.firstIndex(of: 3) == 3) } @Test func `configured local setup skips CLI install page`() { let order = OnboardingView.pageOrder( for: .local, showOnboardingChat: false, requiresCLIInstall: false) #expect(!order.contains(2)) } @Test func `fresh onboarding defaults to this Mac`() { let state = AppState(preview: true) state.onboardingSeen = false state.connectionMode = .unconfigured let view = OnboardingView(state: state) #expect(view.selectedConnectionMode == .local) #expect(view.isConnectionSelectionBlocking) #expect(state.connectionMode == .unconfigured) } @Test func `reopened onboarding preserves configure later selection`() { let state = AppState(preview: true) state.onboardingSeen = true state.connectionMode = .unconfigured let view = OnboardingView(state: state) #expect(view.selectedConnectionMode == .unconfigured) #expect(!view.isConnectionSelectionBlocking) #expect(state.connectionMode == .unconfigured) } @Test func `advancing from recommended this Mac commits local mode`() { let state = AppState(preview: true) state.onboardingSeen = false state.connectionMode = .unconfigured let view = OnboardingView(state: state) view.commitRecommendedConnectionIfNeeded(for: view.connectionPageIndex) #expect(state.connectionMode == .local) } @Test func `automatic CLI setup waits for the initial status probe`() { #expect(!OnboardingView.shouldAutoInstallCLI( onCLIPage: true, isLocal: true, visible: true, statusKnown: false, installed: false, installing: false)) #expect(OnboardingView.shouldAutoInstallCLI( onCLIPage: true, isLocal: true, visible: true, statusKnown: true, installed: false, installing: false)) #expect(!OnboardingView.shouldAutoInstallCLI( onCLIPage: true, isLocal: true, visible: false, statusKnown: true, installed: false, installing: false)) } @Test func `Crestodian setup requires a nonempty auth value`() { #expect(!OnboardingView.hasCrestodianSetupAuth([:])) #expect(!OnboardingView.hasCrestodianSetupAuth(["token": " "])) #expect(OnboardingView.hasCrestodianSetupAuth(["mode": "token"])) #expect(OnboardingView.hasCrestodianSetupAuth([ "token": ["source": "env", "provider": "default", "id": "GATEWAY_TOKEN"], ])) } @Test func `select remote gateway clears stale ssh target when endpoint unresolved`() async { let override = FileManager().temporaryDirectory .appendingPathComponent("openclaw-config-\(UUID().uuidString)") .appendingPathComponent("openclaw.json") .path await TestIsolation.withEnvValues(["OPENCLAW_CONFIG_PATH": override]) { let state = AppState(preview: true) state.remoteTransport = .ssh state.remoteTarget = "user@old-host:2222" let view = OnboardingView( state: state, permissionMonitor: PermissionMonitor.shared, discoveryModel: GatewayDiscoveryModel(localDisplayName: InstanceIdentity.displayName)) let gateway = GatewayDiscoveryModel.DiscoveredGateway( displayName: "Unresolved", serviceHost: nil, servicePort: nil, lanHost: "txt-host.local", tailnetDns: "txt-host.ts.net", sshPort: 22, gatewayPort: 18789, cliPath: "/tmp/openclaw", stableID: UUID().uuidString, debugID: UUID().uuidString, isLocal: false) view.selectRemoteGateway(gateway) #expect(state.remoteTarget.isEmpty) } } @Test func `permission list covers every capability in importance order`() { #expect(Set(Capability.importanceOrdered) == Set(Capability.allCases)) #expect(Capability.importanceOrdered.count == Capability.allCases.count) // App control and context capture lead; location stays last. #expect(Capability.importanceOrdered.first == .appleScript) #expect(Array(Capability.importanceOrdered.prefix(3)) == [.appleScript, .accessibility, .screenRecording]) #expect(Capability.importanceOrdered.last == Capability.location) } }