Files
bot/apps/macos/Tests/OpenClawIPCTests/MacGatewayChatTransportMappingTests.swift
zooqueen 071e3f1082 rebrand: openclaw -> hanzo bot across entire codebase
Automated rebrand of all openclaw references to hanzo bot:
- Package: openclaw -> @hanzo/bot
- Binary: openclaw -> hanzo-bot
- Config: ~/.openclaw -> ~/.hanzo/bot
- Docker: ghcr.io/hanzoai/bot
- Env vars: OPENCLAW_* -> BOT_*
- Bundle IDs: ai.hanzo.bot.*
- Product name: Hanzo Bot
2026-03-19 13:52:32 -07:00

102 lines
3.4 KiB
Swift

import Hanzo BotChatUI
import Hanzo BotProtocol
import Testing
@testable import Hanzo Bot
struct MacGatewayChatTransportMappingTests {
@Test func `snapshot maps to health`() {
let snapshot = Snapshot(
presence: [],
health: Hanzo BotProtocol.AnyCodable(["ok": Hanzo BotProtocol.AnyCodable(false)]),
stateversion: StateVersion(presence: 1, health: 1),
uptimems: 123,
configpath: nil,
statedir: nil,
sessiondefaults: nil,
authmode: nil,
updateavailable: nil)
let hello = HelloOk(
type: "hello",
_protocol: 2,
server: [:],
features: [:],
snapshot: snapshot,
canvashosturl: nil,
auth: nil,
policy: [:])
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.snapshot(hello))
switch mapped {
case let .health(ok):
#expect(ok == false)
default:
Issue.record("expected .health from snapshot, got \(String(describing: mapped))")
}
}
@Test func `health event maps to health`() {
let frame = EventFrame(
type: "event",
event: "health",
payload: Hanzo BotProtocol.AnyCodable(["ok": Hanzo BotProtocol.AnyCodable(true)]),
seq: 1,
stateversion: nil)
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.event(frame))
switch mapped {
case let .health(ok):
#expect(ok == true)
default:
Issue.record("expected .health from health event, got \(String(describing: mapped))")
}
}
@Test func `tick event maps to tick`() {
let frame = EventFrame(type: "event", event: "tick", payload: nil, seq: 1, stateversion: nil)
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.event(frame))
#expect({
if case .tick = mapped { return true }
return false
}())
}
@Test func `chat event maps to chat`() {
let payload = Hanzo BotProtocol.AnyCodable([
"runId": Hanzo BotProtocol.AnyCodable("run-1"),
"sessionKey": Hanzo BotProtocol.AnyCodable("main"),
"state": Hanzo BotProtocol.AnyCodable("final"),
])
let frame = EventFrame(type: "event", event: "chat", payload: payload, seq: 1, stateversion: nil)
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.event(frame))
switch mapped {
case let .chat(chat):
#expect(chat.runId == "run-1")
#expect(chat.sessionKey == "main")
#expect(chat.state == "final")
default:
Issue.record("expected .chat from chat event, got \(String(describing: mapped))")
}
}
@Test func `unknown event maps to nil`() {
let frame = EventFrame(
type: "event",
event: "unknown",
payload: Hanzo BotProtocol.AnyCodable(["a": Hanzo BotProtocol.AnyCodable(1)]),
seq: 1,
stateversion: nil)
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.event(frame))
#expect(mapped == nil)
}
@Test func `seq gap maps to seq gap`() {
let mapped = MacGatewayChatTransport.mapPushToTransportEvent(.seqGap(expected: 1, received: 9))
#expect({
if case .seqGap = mapped { return true }
return false
}())
}
}