mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-17 23:30:48 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
|
|
@ -0,0 +1,101 @@
|
|||
import OpenClawChatUI
|
||||
import OpenClawProtocol
|
||||
import Testing
|
||||
@testable import OpenClaw
|
||||
|
||||
struct MacGatewayChatTransportMappingTests {
|
||||
@Test func `snapshot maps to health`() {
|
||||
let snapshot = Snapshot(
|
||||
presence: [],
|
||||
health: OpenClawProtocol.AnyCodable(["ok": OpenClawProtocol.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: OpenClawProtocol.AnyCodable(["ok": OpenClawProtocol.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 = OpenClawProtocol.AnyCodable([
|
||||
"runId": OpenClawProtocol.AnyCodable("run-1"),
|
||||
"sessionKey": OpenClawProtocol.AnyCodable("main"),
|
||||
"state": OpenClawProtocol.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: OpenClawProtocol.AnyCodable(["a": OpenClawProtocol.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
|
||||
}())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue