Files
openclaw/apps/macos/Tests/ClawdbotIPCTests/MacNodeRuntimeTests.swift

52 lines
2.0 KiB
Swift
Raw Normal View History

2026-01-04 14:32:47 +00:00
import ClawdbotKit
2025-12-24 17:42:24 +01:00
import Foundation
import Testing
2026-01-04 14:32:47 +00:00
@testable import Clawdbot
2025-12-24 17:42:24 +01:00
@Suite(.serialized)
struct MacNodeRuntimeTests {
@Test func handleInvokeRejectsUnknownCommand() async {
let runtime = MacNodeRuntime()
let response = await runtime.handleInvoke(
BridgeInvokeRequest(id: "req-1", command: "unknown.command"))
#expect(response.ok == false)
}
@Test func handleInvokeRejectsEmptySystemRun() async throws {
let runtime = MacNodeRuntime()
2026-01-04 14:32:47 +00:00
let params = ClawdbotSystemRunParams(command: [])
2025-12-24 17:42:24 +01:00
let json = String(data: try JSONEncoder().encode(params), encoding: .utf8)
let response = await runtime.handleInvoke(
2026-01-04 14:32:47 +00:00
BridgeInvokeRequest(id: "req-2", command: ClawdbotSystemCommand.run.rawValue, paramsJSON: json))
2025-12-24 17:42:24 +01:00
#expect(response.ok == false)
}
@Test func handleInvokeRejectsEmptyNotification() async throws {
let runtime = MacNodeRuntime()
2026-01-04 14:32:47 +00:00
let params = ClawdbotSystemNotifyParams(title: "", body: "")
2025-12-24 17:42:24 +01:00
let json = String(data: try JSONEncoder().encode(params), encoding: .utf8)
let response = await runtime.handleInvoke(
2026-01-04 14:32:47 +00:00
BridgeInvokeRequest(id: "req-3", command: ClawdbotSystemCommand.notify.rawValue, paramsJSON: json))
2025-12-24 17:42:24 +01:00
#expect(response.ok == false)
}
2026-01-02 20:22:53 +01:00
@Test func handleInvokeCameraListRequiresEnabledCamera() async {
let defaults = UserDefaults.standard
let previous = defaults.object(forKey: cameraEnabledKey)
defaults.set(false, forKey: cameraEnabledKey)
defer {
if let previous {
defaults.set(previous, forKey: cameraEnabledKey)
} else {
defaults.removeObject(forKey: cameraEnabledKey)
}
}
let runtime = MacNodeRuntime()
let response = await runtime.handleInvoke(
2026-01-04 14:32:47 +00:00
BridgeInvokeRequest(id: "req-4", command: ClawdbotCameraCommand.list.rawValue))
2026-01-02 20:22:53 +01:00
#expect(response.ok == false)
#expect(response.error?.message.contains("CAMERA_DISABLED") == true)
}
2025-12-24 17:42:24 +01:00
}