fix: new chat cannot be edit (#16434)

### What problem does this PR solve?

As title
main fix:

```go
if _, ok := req["meta_data_filter"]; !ok || req["meta_data_filter"] == nil {
	req["meta_data_filter"] = map[string]interface{}{}
}
```


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring
This commit is contained in:
Haruko386
2026-06-29 19:04:59 +08:00
committed by GitHub
parent 43f75fdfc7
commit 445a13ee9a
7 changed files with 314 additions and 15 deletions
+55
View File
@@ -905,6 +905,61 @@ func TestParseMessages_LegacyWrappedObject(t *testing.T) {
}
}
func TestBuildSessionPayload_EmptyCollectionsEncodeAsEmptyArrays(t *testing.T) {
svc := &ChatSessionService{}
payload := svc.buildSessionPayload(&entity.ChatSession{
ID: "session-1",
DialogID: "chat-1",
Message: nil,
Reference: json.RawMessage(`null`),
}, nil, false)
if payload.Messages == nil {
t.Fatal("messages is nil")
}
if payload.Reference == nil {
t.Fatal("reference is nil")
}
body, err := json.Marshal(payload)
if err != nil {
t.Fatalf("Marshal failed: %v", err)
}
if !strings.Contains(string(body), `"messages":[]`) {
t.Fatalf("messages did not encode as empty array: %s", string(body))
}
if !strings.Contains(string(body), `"reference":[]`) {
t.Fatalf("reference did not encode as empty array: %s", string(body))
}
}
func TestParseCollections_ReturnEmptySlicesForMissingNullOrInvalid(t *testing.T) {
messageInputs := []json.RawMessage{
nil,
json.RawMessage(`null`),
json.RawMessage(`{"messages":null}`),
json.RawMessage(`not-json`),
}
for _, input := range messageInputs {
got := parseMessages(input)
if got == nil || len(got) != 0 {
t.Fatalf("parseMessages(%s)=%#v", string(input), got)
}
}
referenceInputs := []json.RawMessage{
nil,
json.RawMessage(`null`),
json.RawMessage(`not-json`),
}
for _, input := range referenceInputs {
got := parseReferenceList(input)
if got == nil || len(got) != 0 {
t.Fatalf("parseReferenceList(%s)=%#v", string(input), got)
}
}
}
func TestCompletionStream_EmptyMessages(t *testing.T) {
svc := &ChatSessionService{
chatSessionDAO: &fakeSessionStore{},