继续之前的重构:把根目录残留的非数据/资源类子目录(agents、agenttool、ai、 autoreply、completion、conversation、llm、message、mqtpp、stream、 toolmanager、toolrouter)一并搬到 internal/ 下,并把全工程引用它们的 import 路径从 "meshtastic_mqtt_server/<x>" 重写为 "meshtastic_mqtt_server/internal/<x>"。 变更 - git mv 12 个顶层目录进 internal/,无函数体改动。 - 全工程 sed 把 import path 加上 internal/ 前缀,包括 main.go、 internal/bot/bot_service.go、internal/store/bot_store.go 中对 mqtpp 的引用,以及 ai 子系统内部 agents/agenttool/autoreply/conversation/ llm/toolmanager/toolrouter 之间的相互引用。 验证 - go build ./... 通过;go test ./... 全部包通过。 - AI 自动回复链路(main → ai.NewService → autoreply.Service → botSender) 保持不变,仅 import 路径调整。 - 根目录最终只剩 main.go / main_test.go / internal/ 加 go.mod / go.sum 与数据资源目录(dist、doc、firmware、py、win、meshmap_frontend)。 Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package mqtpp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"google.golang.org/protobuf/encoding/protowire"
|
|
)
|
|
|
|
func TestMQTTPPEncryptedPacketDefaultRejected(t *testing.T) {
|
|
raw := encryptedServiceEnvelopeTestPayload()
|
|
valid, payload, record := MQTTPP("msh/test", raw, nil, Options{})
|
|
if valid {
|
|
t.Fatalf("valid = true, want false")
|
|
}
|
|
if payload != nil {
|
|
t.Fatalf("payload = %v, want nil", payload)
|
|
}
|
|
if record["type"] != "encrypted_packet" {
|
|
t.Fatalf("type = %v, want encrypted_packet", record["type"])
|
|
}
|
|
if record["error"] != "cannot be decrypted" {
|
|
t.Fatalf("error = %v, want cannot be decrypted", record["error"])
|
|
}
|
|
}
|
|
|
|
func TestMQTTPPEncryptedPacketAllowed(t *testing.T) {
|
|
raw := encryptedServiceEnvelopeTestPayload()
|
|
valid, payload, record := MQTTPP("msh/test", raw, nil, Options{AllowEncryptedForwarding: true})
|
|
if !valid {
|
|
t.Fatalf("valid = false, want true: %+v", record)
|
|
}
|
|
if string(payload) != string(raw) {
|
|
t.Fatalf("payload = %v, want raw payload", payload)
|
|
}
|
|
if record["type"] != "encrypted_packet" {
|
|
t.Fatalf("type = %v, want encrypted_packet", record["type"])
|
|
}
|
|
if record["error"] != nil {
|
|
t.Fatalf("error = %v, want nil", record["error"])
|
|
}
|
|
}
|
|
|
|
func encryptedServiceEnvelopeTestPayload() []byte {
|
|
packet := protowire.AppendTag(nil, 5, protowire.BytesType)
|
|
packet = protowire.AppendBytes(packet, []byte{1, 2, 3, 4})
|
|
envelope := protowire.AppendTag(nil, 1, protowire.BytesType)
|
|
return protowire.AppendBytes(envelope, packet)
|
|
}
|