ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
57 lines
2.4 KiB
Go
57 lines
2.4 KiB
Go
package vikingmemory
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestConsoleScopeFullContentAndProviderFilters(t *testing.T) {
|
|
long := strings.Repeat("完整正文", 500)
|
|
var calls []map[string]any
|
|
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var p map[string]any
|
|
_ = json.NewDecoder(r.Body).Decode(&p)
|
|
calls = append(calls, p)
|
|
if r.URL.Path == "/api/memory/event/delete" {
|
|
if p["event_id"] != "owned" {
|
|
t.Error(p)
|
|
}
|
|
_, _ = w.Write([]byte(`{"code":0}`))
|
|
return
|
|
}
|
|
if r.URL.Path != "/api/memory/event/search" {
|
|
t.Error(r.URL.Path)
|
|
}
|
|
items := []map[string]any{}
|
|
for _, scope := range []struct{ id, user, assistant string }{{"owned", "user-a", AssistantID}, {"foreign-user", "user-b", AssistantID}, {"memoir", "user-a", ManagedAssistantID}} {
|
|
items = append(items, map[string]any{"id": scope.id, "user_id": []string{scope.user}, "assistant_id": []string{scope.assistant}, "memory_type": []string{"event_v1"}, "time": int64(123000), "memory_info": map[string]any{"summary": long, "original_messages": []string{"合成原文"}}})
|
|
}
|
|
items = append(items, map[string]any{"id": "shared", "user_id": []string{"user-a", "user-b"}, "assistant_id": []string{AssistantID}, "memory_type": []string{"event_v1"}})
|
|
_ = json.NewEncoder(w).Encode(map[string]any{"code": 0, "data": map[string]any{"result_list": items}})
|
|
}))
|
|
defer server.Close()
|
|
c, e := NewClient(Options{BaseURL: server.URL, ResourceID: "synthetic", APIKey: "fake-key", EventType: "event_v1", ProfileType: "profile_v1", Timeout: 1000000000})
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c.http = server.Client()
|
|
records, limited, e := c.ChatMemories(context.Background(), "user-a", "event", "家乡", 100, 10, 20)
|
|
if e != nil || !limited || len(records) != 1 || records[0].Content != long || len(records[0].Digest) != 64 {
|
|
t.Fatal(records, limited, e)
|
|
}
|
|
filter := calls[0]["filter"].(map[string]any)
|
|
if filter["start_time"] != float64(10) || filter["end_time"] != float64(20) || calls[0]["query"] != "家乡" || calls[0]["resource_id"] != "synthetic" {
|
|
t.Fatal(calls)
|
|
}
|
|
if e = c.DeleteChatMemory(context.Background(), "event", records[0].ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e = c.DeleteChatMemory(context.Background(), "unexpected", "owned"); e == nil || len(calls) != 2 {
|
|
t.Fatal("invalid kind reached provider")
|
|
}
|
|
}
|