GatewayConnection: validate agent message
This commit is contained in:
@@ -165,9 +165,11 @@ extension GatewayConnection {
|
||||
channel: String? = nil,
|
||||
idempotencyKey: String = UUID().uuidString) async -> (ok: Bool, error: String?)
|
||||
{
|
||||
let trimmed = message.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return (false, "message empty") }
|
||||
do {
|
||||
let params: [String: Any] = [
|
||||
"message": message,
|
||||
"message": trimmed,
|
||||
"sessionKey": sessionKey,
|
||||
"thinking": thinking ?? "default",
|
||||
"deliver": deliver,
|
||||
|
||||
@@ -2,16 +2,21 @@ import Testing
|
||||
@testable import Clawdis
|
||||
@testable import ClawdisIPC
|
||||
|
||||
@Suite(.serialized) struct AgentRPCTests {
|
||||
@Suite(.serialized) struct GatewayConnectionControlTests {
|
||||
@Test func statusFailsWhenProcessMissing() async {
|
||||
let result = await AgentRPC.shared.status()
|
||||
let result = await GatewayConnection.shared.status()
|
||||
// We don't assert ok because the worker may not be available in CI.
|
||||
// Instead, ensure the call returns without throwing and provides a message.
|
||||
#expect(result.ok == true || result.error != nil)
|
||||
}
|
||||
|
||||
@Test func rejectEmptyMessage() async {
|
||||
let result = await AgentRPC.shared.send(text: "", thinking: nil, sessionKey: "main", deliver: false, to: nil)
|
||||
let result = await GatewayConnection.shared.sendAgent(
|
||||
message: "",
|
||||
thinking: nil,
|
||||
sessionKey: "main",
|
||||
deliver: false,
|
||||
to: nil)
|
||||
#expect(result.ok == false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user