62 lines
2.7 KiB
Go
62 lines
2.7 KiB
Go
package callmemory
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"data-terminal-cloud/internal/identity"
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestVoiceConsentWithdrawalStopsLease(t *testing.T) {
|
||
|
|
f := setup(t)
|
||
|
|
m, k, d := f.call(t)
|
||
|
|
f.exec(t, `INSERT INTO consent_snapshot(tenant_id,subject_id,snapshot_version,effective_consents,source_consent_ids) VALUES($1::uuid,$2::uuid,2,'{"voice_chat":false}','[]')`, f.tenant, f.subject)
|
||
|
|
out, e := f.s.DeviceRequest(context.Background(), d, nil, uuid.NewString(), "heartbeat", jsonBytes(HeartbeatInput{CallKey: k, ManifestID: m.ManifestID, AttemptID: uuid.NewString(), Runtime: "STARTING"}))
|
||
|
|
if e != nil {
|
||
|
|
t.Fatal(e)
|
||
|
|
}
|
||
|
|
if out.(map[string]any)["allowed"] != false {
|
||
|
|
t.Fatal("revoked voice consent renewed microphone lease")
|
||
|
|
}
|
||
|
|
if out.(map[string]any)["transcript_upload_allowed"] != false {
|
||
|
|
t.Fatal("revoked call allowed transcript upload")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestCallRecordsScopePaginationAndTranscript(t *testing.T) {
|
||
|
|
f := setup(t)
|
||
|
|
for i := 0; i < 3; i++ {
|
||
|
|
sid := uuid.NewString()
|
||
|
|
f.exec(t, `INSERT INTO call_session(id,tenant_id,subject_id,device_id,boot_id,hook_event_id,call_generation,binding_generation,call_state,transcript_state,ended_at) VALUES($1::uuid,$2::uuid,$3::uuid,$4::uuid,$5::uuid,$1,1,1,'ENDED','COMPLETE',now())`, sid, f.tenant, f.subject, f.device, f.boot)
|
||
|
|
f.exec(t, `INSERT INTO call_utterance(session_id,utterance_id,source_revision,speaker,text_content,interrupted,source_at) VALUES($1::uuid,'u1',0,'USER','测试聊天记录',false,now())`, sid)
|
||
|
|
}
|
||
|
|
in := CallRecordsInput{ElderID: f.elder, Limit: 2}
|
||
|
|
first := f.request(t, "calls/query", in)
|
||
|
|
items := first["items"].([]any)
|
||
|
|
if len(items) != 2 || first["next_cursor"] == "" {
|
||
|
|
t.Fatal(first)
|
||
|
|
}
|
||
|
|
in.Cursor = first["next_cursor"].(string)
|
||
|
|
last := f.request(t, "calls/query", in)
|
||
|
|
if len(last["items"].([]any)) != 1 || last["next_cursor"] != "" {
|
||
|
|
t.Fatal(last)
|
||
|
|
}
|
||
|
|
sid := items[0].(map[string]any)["id"].(string)
|
||
|
|
turns := f.request(t, "calls/turns", CallRecordsInput{ElderID: f.elder, SessionID: sid})
|
||
|
|
if len(turns["items"].([]any)) != 1 {
|
||
|
|
t.Fatal(turns)
|
||
|
|
}
|
||
|
|
_, e := f.s.MemoryRequest(context.Background(), identity.Principal{Issuer: f.principal.Issuer, Subject: uuid.NewString()}, "calls/query", jsonBytes(CallRecordsInput{ElderID: f.elder}))
|
||
|
|
if e == nil {
|
||
|
|
t.Fatal("unrelated account read transcripts")
|
||
|
|
}
|
||
|
|
_, e = f.s.MemoryRequest(context.Background(), f.principal, "calls/turns", jsonBytes(CallRecordsInput{ElderID: f.elder, SessionID: uuid.NewString()}))
|
||
|
|
if e == nil {
|
||
|
|
t.Fatal("unknown call accepted")
|
||
|
|
}
|
||
|
|
_, e = f.s.MemoryRequest(context.Background(), f.principal, "calls/query", jsonBytes(CallRecordsInput{ElderID: f.elder, Cursor: "not-a-cursor"}))
|
||
|
|
if e == nil {
|
||
|
|
t.Fatal("invalid cursor accepted")
|
||
|
|
}
|
||
|
|
}
|