feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
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.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package elderagent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"data-terminal-cloud/internal/vikingmemory"
|
||||
)
|
||||
|
||||
func TestNativeMemoryFollowsElderUploadIdentityAndConsent(t *testing.T) {
|
||||
s := Service{VikingCollectionName: "aiphone", VikingEventType: "event_v1"}
|
||||
a, err := s.nativeMemoryConfiguration("tenant-one", "elder-one", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, _ := s.nativeMemoryConfiguration("tenant-two", "elder-one", true)
|
||||
c, _ := s.nativeMemoryConfiguration("tenant-one", "elder-two", true)
|
||||
user := func(m map[string]any) string {
|
||||
return m["ProviderParams"].(map[string]any)["filter"].(map[string]any)["user_id"].([]string)[0]
|
||||
}
|
||||
if user(a) != vikingmemory.UserID("tenant-one", "elder-one") || user(a) == user(b) || user(a) == user(c) {
|
||||
t.Fatal("wrong upload identity or cross-elder filter")
|
||||
}
|
||||
filter := a["ProviderParams"].(map[string]any)["filter"].(map[string]any)
|
||||
if filter["assistant_id"].([]string)[0] != vikingmemory.AssistantID {
|
||||
t.Fatal("wrong assistant")
|
||||
}
|
||||
off, err := (&Service{}).nativeMemoryConfiguration("", "", false)
|
||||
if err != nil || off["Enable"] != false || len(off) != 1 {
|
||||
t.Fatal("withdrawal retained filters", off, err)
|
||||
}
|
||||
if _, err := (&Service{}).nativeMemoryConfiguration("tenant", "elder", true); err == nil {
|
||||
t.Fatal("authorized memory silently uses missing configuration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyNativeMemoryRejectsWrongElderEvenWhenEnabled(t *testing.T) {
|
||||
s := Service{VikingCollectionName: "aiphone", VikingEventType: "event_v1"}
|
||||
want, _ := s.nativeMemoryConfiguration("tenant", "elder", true)
|
||||
for _, wrong := range []bool{false, true} {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
got, _ := s.nativeMemoryConfiguration("tenant", "elder", true)
|
||||
if wrong {
|
||||
got, _ = s.nativeMemoryConfiguration("tenant", "another-elder", true)
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{"Result": map[string]any{"Bots": []any{map[string]any{"Id": "bot", "Config": map[string]any{"MemoryConfig": got}}}}})
|
||||
}))
|
||||
client := NewClient("test-key", "test-secret", "", server.URL, "cn-north-1")
|
||||
err := client.VerifyNativeMemory(context.Background(), "bot", want)
|
||||
server.Close()
|
||||
if (err != nil) != wrong {
|
||||
t.Fatalf("readback wrong=%v err=%v", wrong, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyNativeMemoryAcceptsOmittedFalseButRejectsEnabledOrMalformed(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
memory map[string]any
|
||||
fail bool
|
||||
}{
|
||||
{"omitted-false", map[string]any{}, false},
|
||||
{"explicit-false", map[string]any{"Enable": false}, false},
|
||||
{"still-enabled", map[string]any{"Enable": true}, true},
|
||||
{"malformed", map[string]any{"Enable": "false"}, true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]any{"Result": map[string]any{"Bots": []any{map[string]any{"Id": "bot", "Config": map[string]any{"MemoryConfig": tc.memory}}}}})
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewClient("test-key", "test-secret", "", server.URL, "cn-north-1")
|
||||
err := client.VerifyNativeMemory(context.Background(), "bot", map[string]any{"Enable": false})
|
||||
if (err != nil) != tc.fail {
|
||||
t.Fatalf("unexpected readback: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user