mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
609ca49cf5
* feat(channel): add Matrix adapter support * fix(channel): prevent reasoning leaks in Matrix replies * fix(channel): persist Matrix sync cursors * fix(channel): improve Matrix markdown rendering * fix(channel): support Matrix attachments and multimodal history * fix(channel): expand Matrix reply media context * fix(handlers): allow media downloads for chat-access bots * fix(channel): classify Matrix DMs as direct chats * fix(channel): auto-join Matrix room invites * fix(channel): resolve Matrix room aliases for outbound send * fix(web): use Matrix brand icon in channel badges Replace the generic Matrix hashtag badge with the official brand asset so channel badges feel recognizable and fit the circular mask cleanly. * fix(channel): add Matrix room whitelist controls Let Matrix bots decide whether to auto-join invites and restrict inbound activity to allowed rooms or aliases. Expose the new controls in the web settings UI with line-based whitelist input so access rules stay explicit. * fix(channel): stabilize Matrix multimodal follow-ups and settings * fix(flow): avoid gosec panic on byte decoding * fix: fix golangci-lint * fix(channel): remove Matrix built-in ACL * fix(channel): preserve Matrix image captions * fix(channel): validate Matrix homeserver and sync access Fail Matrix connections early when the homeserver, access token, or /sync capability is misconfigured so bot health checks surface actionable errors. * fix(channel): preserve optional toggles and relax Matrix startup validation * fix(channel): tighten Matrix mention fallback parsing * fix(flow): skip structured assistant tool-call outputs * fix(flow): resolve merged resolver duplication Keep the internal agent resolver implementation after merging main so split helper files do not redeclare flow symbols. Restore user message normalization in sanitize and persistence paths to keep flow tests and command packages building. * fix(flow): remove unused merged resolver helper Drop the leftover truncate helper and import from the resolver merge fix so golangci-lint passes again without affecting flow behavior. --------- Co-authored-by: Acbox Liu <acbox0328@gmail.com>
99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package flow
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/memohai/memoh/internal/conversation"
|
|
)
|
|
|
|
func TestExtractAssistantOutputsSkipsAssistantToolCallMessages(t *testing.T) {
|
|
outputs := ExtractAssistantOutputs([]conversation.ModelMessage{
|
|
{
|
|
Role: "assistant",
|
|
Content: conversation.NewTextContent("I will inspect the file first."),
|
|
ToolCalls: []conversation.ToolCall{{
|
|
Type: "function",
|
|
Function: conversation.ToolCallFunction{
|
|
Name: "read_file",
|
|
Arguments: `{"path":"/tmp/a.txt"}`,
|
|
},
|
|
}},
|
|
},
|
|
{
|
|
Role: "assistant",
|
|
Content: conversation.NewTextContent("Done. Here is the final answer."),
|
|
},
|
|
})
|
|
|
|
if len(outputs) != 1 {
|
|
t.Fatalf("expected one assistant output, got %d", len(outputs))
|
|
}
|
|
if outputs[0].Content != "Done. Here is the final answer." {
|
|
t.Fatalf("unexpected assistant output: %q", outputs[0].Content)
|
|
}
|
|
}
|
|
|
|
func TestExtractAssistantOutputsExcludesReasoningParts(t *testing.T) {
|
|
content, err := json.Marshal([]conversation.ContentPart{
|
|
{Type: "reasoning", Text: "I should inspect the file first."},
|
|
{Type: "text", Text: "Here is the file summary."},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal content: %v", err)
|
|
}
|
|
|
|
outputs := ExtractAssistantOutputs([]conversation.ModelMessage{{
|
|
Role: "assistant",
|
|
Content: content,
|
|
}})
|
|
|
|
if len(outputs) != 1 {
|
|
t.Fatalf("expected one assistant output, got %d", len(outputs))
|
|
}
|
|
if outputs[0].Content != "Here is the file summary." {
|
|
t.Fatalf("unexpected visible assistant output: %q", outputs[0].Content)
|
|
}
|
|
if len(outputs[0].Parts) != 1 || outputs[0].Parts[0].Type != "text" {
|
|
t.Fatalf("unexpected visible parts: %#v", outputs[0].Parts)
|
|
}
|
|
}
|
|
|
|
func TestExtractAssistantOutputsSkipsReasoningOnlyStructuredMessage(t *testing.T) {
|
|
content, err := json.Marshal([]map[string]any{
|
|
{"type": "reasoning", "text": "I should inspect the file first."},
|
|
{"type": "tool-call", "toolName": "read", "toolCallId": "call_1", "input": map[string]any{"path": "/tmp/a.txt"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal content: %v", err)
|
|
}
|
|
|
|
outputs := ExtractAssistantOutputs([]conversation.ModelMessage{{
|
|
Role: "assistant",
|
|
Content: content,
|
|
}})
|
|
|
|
if len(outputs) != 0 {
|
|
t.Fatalf("expected no visible assistant outputs, got %#v", outputs)
|
|
}
|
|
}
|
|
|
|
func TestExtractAssistantOutputsSkipsStructuredToolCallMessageWithVisibleText(t *testing.T) {
|
|
content, err := json.Marshal([]map[string]any{
|
|
{"type": "text", "text": "I will inspect the file first."},
|
|
{"type": "tool-call", "toolName": "read", "toolCallId": "call_1", "input": map[string]any{"path": "/tmp/a.txt"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal content: %v", err)
|
|
}
|
|
|
|
outputs := ExtractAssistantOutputs([]conversation.ModelMessage{{
|
|
Role: "assistant",
|
|
Content: content,
|
|
}})
|
|
|
|
if len(outputs) != 0 {
|
|
t.Fatalf("expected no visible assistant outputs, got %#v", outputs)
|
|
}
|
|
}
|