Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

*.docx diff=astextplain
*.DOCX diff=astextplain
src/HuaJiBot.NET.UnitTest/TestData/AgentProtocol/** text eol=lf

44 changes: 44 additions & 0 deletions src/HuaJiBot.NET.UnitTest/FlueBridgeProtocolTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using HuaJiBot.NET.Plugin.FlueBridge;

namespace HuaJiBot.NET.UnitTest;

public partial class FlueBridgeTest
{
private static string ProtocolFixture(string name) =>
File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "AgentProtocol", name));

[Test]
public void SharedProtocolExamplesRoundTripThroughActualBridgeRecords()
{
var ingressJson = ProtocolFixture("examples/ingress.json");
var ingress = JsonSerializer.Deserialize<IngressEvent>(ingressJson, BridgeJson.Options)!;
var replyJson = ProtocolFixture("examples/reply-job.json");
var reply = JsonSerializer.Deserialize<ReplyJob>(replyJson, BridgeJson.Options)!;
Assert.Multiple(() =>
{
Assert.That(JsonNode.DeepEquals(JsonNode.Parse(ingressJson), JsonSerializer.SerializeToNode(ingress, BridgeJson.Options)), Is.True);
Assert.That(JsonNode.DeepEquals(JsonNode.Parse(replyJson), JsonSerializer.SerializeToNode(reply, BridgeJson.Options)), Is.True);
Assert.That(ingress.Kind, Is.EqualTo("chat"));
Assert.That(reply.Destination.ReplyToMessageId, Is.EqualTo(ingress.Message.MessageId));
});
}

[Test]
public void SharedProtocolVectorsMatchRawBodySignatureAndIdentifierEncoding()
{
using var vectors = JsonDocument.Parse(ProtocolFixture("test-vectors.json"));
foreach (var vector in vectors.RootElement.GetProperty("hmac").EnumerateArray())
{
var actual = "v1=" + IngressClient.Sign(vector.GetProperty("secret").GetString()!,
vector.GetProperty("timestamp").GetString()!, Encoding.UTF8.GetBytes(vector.GetProperty("body").GetString()!));
Assert.That(actual, Is.EqualTo(vector.GetProperty("signature").GetString()));
}
foreach (var vector in vectors.RootElement.GetProperty("identifiers").EnumerateArray())
{
Assert.That(Uri.EscapeDataString(vector.GetProperty("raw").GetString()!), Is.EqualTo(vector.GetProperty("encoded").GetString()));
}
}
}
2 changes: 1 addition & 1 deletion src/HuaJiBot.NET.UnitTest/FlueBridgeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace HuaJiBot.NET.UnitTest;

public class FlueBridgeTest
public partial class FlueBridgeTest
{
private string _path = null!;
private BridgeStore _store = null!;
Expand Down
1 change: 1 addition & 0 deletions src/HuaJiBot.NET.UnitTest/HuaJiBot.NET.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</ItemGroup>

<ItemGroup>
<None Update="TestData\AgentProtocol\**\*" CopyToOutputDirectory="PreserveNewest" />
<ProjectReference Include="..\HuaJiBot.NET.Adapter.OneBot\HuaJiBot.NET.Adapter.OneBot.csproj" />
<ProjectReference Include="..\HuaJiBot.NET.Plugin.FlueBridge\HuaJiBot.NET.Plugin.FlueBridge.csproj" />
<ProjectReference Include="..\HuaJiBot.NET.Adapter.Telegram\HuaJiBot.NET.Adapter.Telegram.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 1,
"eventId": "development:test-bot:test-group:root",
"conversationId": "huajibot:development:test-bot:test-group:root",
"destination": {
"bridgeInstance": "development",
"robotId": "test-bot",
"groupId": "test-group"
},
"kind": "chat",
"message": {
"messageId": "root",
"senderId": "test-user",
"senderName": "开发测试",
"text": "中文问题",
"images": [],
"observedAt": 1791763200000
},
"replyTo": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"jobId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"conversationId": "huajibot:development:test-bot:test-group:root",
"destination": {
"bridgeInstance": "development",
"robotId": "test-bot",
"groupId": "test-group",
"replyToMessageId": "root"
},
"content": {
"format": "markdown",
"text": "中文回复"
},
"createdAt": "2026-10-12T00:00:00+00:00",
"kind": "chat"
}
149 changes: 149 additions & 0 deletions src/HuaJiBot.NET.UnitTest/TestData/AgentProtocol/ingress.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"type": "object",
"properties": {
"version": {
"const": 1
},
"eventId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"conversationId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"destination": {
"type": "object",
"properties": {
"bridgeInstance": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"robotId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"groupId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
}
},
"required": [
"bridgeInstance",
"robotId",
"groupId"
],
"additionalProperties": false
},
"kind": {
"enum": [
"chat",
"archive",
"summary"
],
"type": "string",
"default": "chat"
},
"message": {
"type": "object",
"properties": {
"messageId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"senderId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"senderName": {
"type": "string"
},
"text": {
"type": "string",
"minLength": 1
},
"images": {
"type": "array",
"items": {
"type": "string",
"maxLength": 4096
},
"maxItems": 4,
"default": []
},
"observedAt": {
"type": "integer",
"minimum": 0
}
},
"required": [
"messageId",
"senderId",
"senderName",
"text"
],
"additionalProperties": false
},
"replyTo": {
"anyOf": [
{
"type": "object",
"properties": {
"messageId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"senderId": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"content": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"messageId",
"senderId",
"content"
],
"additionalProperties": false
},
{
"type": "null"
}
]
}
},
"required": [
"version",
"eventId",
"conversationId",
"destination",
"message",
"replyTo"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "HuaJiBot local v1 ingress"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"type": "object",
"properties": {
"version": {
"const": 1
},
"jobId": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"conversationId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"destination": {
"type": "object",
"properties": {
"bridgeInstance": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"robotId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"groupId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"replyToMessageId": {
"type": "string",
"minLength": 1,
"maxLength": 1024
}
},
"required": [
"bridgeInstance",
"robotId",
"groupId",
"replyToMessageId"
],
"additionalProperties": false
},
"content": {
"type": "object",
"properties": {
"format": {
"const": "markdown"
},
"text": {
"type": "string",
"minLength": 1
}
},
"required": [
"format",
"text"
],
"additionalProperties": false
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"kind": {
"enum": [
"chat",
"summary"
],
"type": "string"
}
},
"required": [
"version",
"jobId",
"conversationId",
"destination",
"content",
"createdAt"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "HuaJiBot local v1 reply-job"
}
22 changes: 22 additions & 0 deletions src/HuaJiBot.NET.UnitTest/TestData/AgentProtocol/test-vectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"hmac": [
{
"secret": "public-test-secret-only",
"timestamp": "1791763200",
"body": "{\"text\":\"中文\"}",
"signature": "v1=616a031110382efc2fb59dde68e941b8031d3e98e1b01ab4e6a83df26d2abf0e"
},
{
"secret": "public-test-secret-only",
"timestamp": "1791763200",
"body": "{\"text\":\"line1\\nline2\",\"value\":1}",
"signature": "v1=cb0e1392168893429bc5a479a724bbbb2b89ccce1c9b9ffa479d72456c7210d1"
}
],
"identifiers": [
{
"raw": "topic:!'()*中文",
"encoded": "topic%3A%21%27%28%29%2A%E4%B8%AD%E6%96%87"
}
]
}