Skip to content

Commit 8f0d0fb

Browse files
committed
test(macos): remove final private test seams
1 parent d498daa commit 8f0d0fb

8 files changed

Lines changed: 63 additions & 215 deletions

‎apps/macos/Sources/OpenClaw/QuickChatController+Testing.swift‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎apps/macos/Sources/OpenClaw/QuickChatController.swift‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,6 @@ final class QuickChatController: NSObject, NSWindowDelegate {
935935
}
936936

937937
#if DEBUG
938-
var hasGlobalMonitorForTesting: Bool {
939-
self.globalMonitor != nil
940-
}
941-
942-
var hasLocalMonitorForTesting: Bool {
943-
self.localMonitor != nil
944-
}
945-
946-
var hotkeyRegisteredForTesting: Bool {
947-
self.hotkeyRegistered
948-
}
949-
950938
func handleSendAcceptedForTesting(openChat: Bool) {
951939
self.handleSendAccepted(openChat: openChat)
952940
}

‎apps/macos/Sources/OpenClaw/TailscaleIntegrationSection.swift‎

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ struct TailscaleIntegrationSection: View {
7070
let isPaused: Bool
7171

7272
@Environment(TailscaleService.self) private var tailscaleService
73-
#if DEBUG
74-
private var testingService: TailscaleService?
75-
#endif
7673

7774
@State private var hasLoaded = false
7875
@State private var tailscaleMode: GatewayTailscaleMode = .serve
@@ -86,17 +83,6 @@ struct TailscaleIntegrationSection: View {
8683
init(connectionMode: AppState.ConnectionMode, isPaused: Bool) {
8784
self.connectionMode = connectionMode
8885
self.isPaused = isPaused
89-
#if DEBUG
90-
self.testingService = nil
91-
#endif
92-
}
93-
94-
private var effectiveService: TailscaleService {
95-
#if DEBUG
96-
return self.testingService ?? self.tailscaleService
97-
#else
98-
return self.tailscaleService
99-
#endif
10086
}
10187

10288
var body: some View {
@@ -106,7 +92,7 @@ struct TailscaleIntegrationSection: View {
10692

10793
self.statusRow
10894

109-
if !self.effectiveService.isInstalled {
95+
if !self.tailscaleService.isInstalled {
11096
self.installButtons
11197
} else {
11298
self.modePicker
@@ -145,7 +131,7 @@ struct TailscaleIntegrationSection: View {
145131
guard !self.hasLoaded else { return }
146132
await self.loadConfig()
147133
self.hasLoaded = true
148-
await self.effectiveService.checkTailscaleStatus()
134+
await self.tailscaleService.checkTailscaleStatus()
149135
self.startStatusTimer()
150136
}
151137
.onDisappear {
@@ -168,32 +154,32 @@ struct TailscaleIntegrationSection: View {
168154
.font(.callout)
169155
Spacer()
170156
Button("Refresh") {
171-
Task { await self.effectiveService.checkTailscaleStatus() }
157+
Task { await self.tailscaleService.checkTailscaleStatus() }
172158
}
173159
.buttonStyle(.bordered)
174160
.controlSize(.small)
175161
}
176162
}
177163

178164
private var statusColor: Color {
179-
if !self.effectiveService.isInstalled { return .yellow }
180-
if self.effectiveService.isRunning { return .green }
165+
if !self.tailscaleService.isInstalled { return .yellow }
166+
if self.tailscaleService.isRunning { return .green }
181167
return .orange
182168
}
183169

184170
private var statusText: String {
185-
if !self.effectiveService.isInstalled { return "Tailscale is not installed" }
186-
if self.effectiveService.isRunning { return "Tailscale is installed and running" }
171+
if !self.tailscaleService.isInstalled { return "Tailscale is not installed" }
172+
if self.tailscaleService.isRunning { return "Tailscale is installed and running" }
187173
return "Tailscale is installed but not running"
188174
}
189175

190176
private var installButtons: some View {
191177
HStack(spacing: 12) {
192-
Button("App Store") { self.effectiveService.openAppStore() }
178+
Button("App Store") { self.tailscaleService.openAppStore() }
193179
.buttonStyle(.link)
194-
Button("Direct Download") { self.effectiveService.openDownloadPage() }
180+
Button("Direct Download") { self.tailscaleService.openDownloadPage() }
195181
.buttonStyle(.link)
196-
Button("Setup Guide") { self.effectiveService.openSetupGuide() }
182+
Button("Setup Guide") { self.tailscaleService.openSetupGuide() }
197183
.buttonStyle(.link)
198184
}
199185
.controlSize(.small)
@@ -217,7 +203,7 @@ struct TailscaleIntegrationSection: View {
217203

218204
@ViewBuilder
219205
private var accessURLRow: some View {
220-
if let host = self.effectiveService.tailscaleHostname {
206+
if let host = self.tailscaleService.tailscaleHostname {
221207
let url = "https://\(host)/ui/"
222208
HStack(spacing: 8) {
223209
Text("Dashboard URL:")
@@ -231,14 +217,14 @@ struct TailscaleIntegrationSection: View {
231217
.font(.system(.caption, design: .monospaced))
232218
}
233219
}
234-
} else if !self.effectiveService.isRunning {
220+
} else if !self.tailscaleService.isRunning {
235221
Text("Start Tailscale to get your tailnet hostname.")
236222
.font(.caption)
237223
.foregroundStyle(.secondary)
238224
}
239225

240-
if self.effectiveService.isAppInstalled, !self.effectiveService.isRunning {
241-
Button("Start Tailscale") { self.effectiveService.openTailscaleApp() }
226+
if self.tailscaleService.isAppInstalled, !self.tailscaleService.isRunning {
227+
Button("Start Tailscale") { self.tailscaleService.openTailscaleApp() }
242228
.buttonStyle(.borderedProminent)
243229
.controlSize(.small)
244230
}
@@ -510,7 +496,7 @@ struct TailscaleIntegrationSection: View {
510496
self.stopStatusTimer()
511497
if ProcessInfo.processInfo.isRunningTests { return }
512498
self.statusTimer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
513-
Task { await self.effectiveService.checkTailscaleStatus() }
499+
Task { await self.tailscaleService.checkTailscaleStatus() }
514500
}
515501
}
516502

@@ -522,26 +508,6 @@ struct TailscaleIntegrationSection: View {
522508

523509
#if DEBUG
524510
extension TailscaleIntegrationSection {
525-
mutating func setTestingState(
526-
mode: String,
527-
requireCredentials: Bool,
528-
password: String = "secret",
529-
statusMessage: String? = nil,
530-
validationMessage: String? = nil)
531-
{
532-
if let mode = GatewayTailscaleMode(rawValue: mode) {
533-
self.tailscaleMode = mode
534-
}
535-
self.requireCredentialsForServe = requireCredentials
536-
self.password = password
537-
self.statusMessage = statusMessage
538-
self.validationMessage = validationMessage
539-
}
540-
541-
mutating func setTestingService(_ service: TailscaleService?) {
542-
self.testingService = service
543-
}
544-
545511
static func simulateHydrationApplyForTesting(
546512
root: [String: Any],
547513
connectionMode: AppState.ConnectionMode,

‎apps/macos/Tests/OpenClawIPCTests/Placeholder.swift‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎apps/macos/Tests/OpenClawIPCTests/QuickChatControllerTests.swift‎

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,53 @@ struct QuickChatControllerTests {
9494
}
9595

9696
@Test func `controller lifecycle cleans monitor tokens without UI`() {
97-
let snapshots = QuickChatController.exerciseForTesting()
98-
99-
#expect(snapshots.count == 4)
100-
#expect(!snapshots[0].isVisible)
101-
#expect(snapshots[0].hotkeyRegistered)
102-
#expect(snapshots[0].isEnabled)
103-
#expect(snapshots[1].isVisible)
104-
#expect(snapshots[1].hasGlobalMonitor)
105-
#expect(snapshots[1].hasLocalMonitor)
106-
#expect(!snapshots[2].isVisible)
107-
#expect(!snapshots[2].hasGlobalMonitor)
108-
#expect(!snapshots[2].hasLocalMonitor)
109-
#expect(!snapshots[2].hotkeyRegistered)
110-
#expect(!snapshots[2].isEnabled)
111-
#expect(!snapshots[3].hotkeyRegistered)
97+
var globalMonitorInstallCount = 0
98+
var localMonitorInstallCount = 0
99+
var clearedMonitorCount = 0
100+
var hotkeyRegisterCount = 0
101+
var hotkeyRemoveCount = 0
102+
let controller = QuickChatController(
103+
enableUI: false,
104+
model: Self.makeModel(),
105+
monitoringEnabled: true,
106+
globalMonitorInstaller: { _, _ in
107+
globalMonitorInstallCount += 1
108+
return NSObject()
109+
},
110+
localMonitorInstaller: { _, _ in
111+
localMonitorInstallCount += 1
112+
return NSObject()
113+
},
114+
monitorClearer: { monitor in
115+
if monitor != nil {
116+
clearedMonitorCount += 1
117+
}
118+
monitor = nil
119+
},
120+
hotkeyRegistrar: { _ in hotkeyRegisterCount += 1 },
121+
hotkeyRemover: { hotkeyRemoveCount += 1 },
122+
allowsHotkeyRegistrationInTests: true)
123+
124+
controller.start()
125+
controller.setEnabled(true)
126+
#expect(!controller.isVisible)
127+
#expect(controller.isEnabled)
128+
#expect(hotkeyRegisterCount == 1)
129+
130+
controller.present()
131+
#expect(controller.isVisible)
132+
#expect(globalMonitorInstallCount == 1)
133+
#expect(localMonitorInstallCount == 1)
134+
135+
controller.setEnabled(false)
136+
#expect(!controller.isVisible)
137+
#expect(!controller.isEnabled)
138+
#expect(hotkeyRemoveCount == 1)
139+
#expect(clearedMonitorCount == 2)
140+
141+
controller.stop()
142+
#expect(hotkeyRemoveCount == 1)
143+
#expect(clearedMonitorCount == 2)
112144
}
113145

114146
@Test func `resign key keeps bar visible while granting permissions`() async {

‎apps/macos/Tests/OpenClawIPCTests/SettingsViewSmokeTests.swift‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,6 @@ struct SettingsViewSmokeTests {
8989
_ = view.body
9090
}
9191

92-
@Test func `instances settings builds body`() {
93-
let store = InstancesStore(isPreview: true)
94-
store.instances = [
95-
InstanceInfo(
96-
id: "local",
97-
host: "this-mac",
98-
ip: "127.0.0.1",
99-
version: "1.0",
100-
platform: "macos 15.0",
101-
deviceFamily: "Mac",
102-
modelIdentifier: "MacPreview",
103-
lastInputSeconds: 12,
104-
mode: "local",
105-
reason: "test",
106-
text: "test instance",
107-
ts: Date().timeIntervalSince1970 * 1000),
108-
]
109-
let view = InstancesSettings(store: store)
110-
_ = view.body
111-
}
112-
11392
@Test func `permissions settings builds body`() {
11493
let state = AppState(preview: true)
11594
let view = PermissionsSettings(

‎apps/macos/Tests/OpenClawIPCTests/TailscaleIntegrationSectionTests.swift‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -124,48 +124,6 @@ struct TailscaleIntegrationSectionTests {
124124
#expect(await loader.requestCount == 2)
125125
}
126126

127-
@Test func `tailscale section builds body when not installed`() {
128-
let service = TailscaleService(isInstalled: false, isRunning: false, statusError: "not installed")
129-
var view = TailscaleIntegrationSection(connectionMode: .local, isPaused: false)
130-
view.setTestingService(service)
131-
view.setTestingState(mode: "off", requireCredentials: false, statusMessage: "Idle")
132-
_ = view.body
133-
}
134-
135-
@Test func `tailscale section builds body for serve mode`() {
136-
let service = TailscaleService(
137-
isInstalled: true,
138-
isRunning: true,
139-
tailscaleHostname: "openclaw.tailnet.ts.net",
140-
tailscaleIP: "100.64.0.1")
141-
var view = TailscaleIntegrationSection(connectionMode: .local, isPaused: false)
142-
view.setTestingService(service)
143-
view.setTestingState(
144-
mode: "serve",
145-
requireCredentials: true,
146-
password: "secret",
147-
statusMessage: "Running")
148-
_ = view.body
149-
}
150-
151-
@Test func `tailscale section builds body for funnel mode`() {
152-
let service = TailscaleService(
153-
isInstalled: true,
154-
isAppInstalled: true,
155-
isRunning: false,
156-
tailscaleHostname: nil,
157-
tailscaleIP: nil,
158-
statusError: "not running")
159-
var view = TailscaleIntegrationSection(connectionMode: .remote, isPaused: false)
160-
view.setTestingService(service)
161-
view.setTestingState(
162-
mode: "funnel",
163-
requireCredentials: false,
164-
statusMessage: "Needs start",
165-
validationMessage: "Invalid token")
166-
_ = view.body
167-
}
168-
169127
@Test func `general tailscale hydration does not rewrite existing config`() async throws {
170128
let stateDir = FileManager().temporaryDirectory
171129
.appendingPathComponent("openclaw-state-\(UUID().uuidString)", isDirectory: true)

0 commit comments

Comments
 (0)