feat: harden support, localize knowledge and add operator availability [skip ci]
Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.
Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.
Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.
Expected source tree: 0a4a7528e9.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Modified in the independent hardening fork; see docs/hardening.
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
@@ -6,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/dto"
|
||||
"agent-desk/internal/pkg/dto/response"
|
||||
"agent-desk/internal/pkg/enums"
|
||||
)
|
||||
@@ -49,12 +50,9 @@ func TestWsAgentActivityEventType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublishAgentActivity(t *testing.T) {
|
||||
f := newWsAuthFixture(t, true)
|
||||
ws := newWsService()
|
||||
session := &ClientSession{
|
||||
ID: "test-sess",
|
||||
Topics: map[string]struct{}{},
|
||||
Send: make(chan []byte, 10),
|
||||
}
|
||||
session := newWsAuthClient(f, "test-sess", realtimeRoleAdmin)
|
||||
ws.manager.Register(session, []string{"conversation:100"})
|
||||
|
||||
conv := &models.Conversation{ID: 100}
|
||||
@@ -100,27 +98,16 @@ func TestWsOperatorPresenceEventType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPublishOperatorPresence(t *testing.T) {
|
||||
f := newWsAuthFixture(t, true)
|
||||
ws := newWsService()
|
||||
|
||||
subscriber := &ClientSession{
|
||||
ID: "subscriber-conn",
|
||||
Topics: map[string]struct{}{},
|
||||
Send: make(chan []byte, 10),
|
||||
}
|
||||
subscriber := newWsAuthClient(f, "subscriber-conn", realtimeRoleAdmin)
|
||||
ws.manager.Register(subscriber, []string{"conversation:100"})
|
||||
|
||||
sender := &ClientSession{
|
||||
ID: "sender-conn",
|
||||
Topics: map[string]struct{}{},
|
||||
Send: make(chan []byte, 10),
|
||||
}
|
||||
sender := newWsAuthClient(f, "sender-conn", realtimeRoleAdmin)
|
||||
ws.manager.Register(sender, []string{"conversation:100"})
|
||||
|
||||
principal := &dto.AuthPrincipal{
|
||||
UserID: 2,
|
||||
Username: "operator",
|
||||
Nickname: "Agent Smith",
|
||||
}
|
||||
principal := f.principal
|
||||
|
||||
ws.PublishOperatorPresence(100, principal, "typing", sender.ID)
|
||||
|
||||
@@ -136,7 +123,7 @@ func TestPublishOperatorPresence(t *testing.T) {
|
||||
if event.Type != enums.IMRealtimeEventOperatorPresence {
|
||||
t.Fatalf("expected type %s, got %s", enums.IMRealtimeEventOperatorPresence, event.Type)
|
||||
}
|
||||
if event.Data.ConversationID != 100 || event.Data.UserID != 2 || event.Data.Username != "operator" || event.Data.Nickname != "Agent Smith" || event.Data.Action != "typing" {
|
||||
if event.Data.ConversationID != 100 || event.Data.UserID != principal.UserID || event.Data.Username != principal.Username || event.Data.Nickname != principal.Nickname || event.Data.Action != "typing" {
|
||||
t.Fatalf("unexpected data: %+v", event.Data)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
@@ -151,26 +138,13 @@ func TestPublishOperatorPresence(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHandleClientMessagePresence(t *testing.T) {
|
||||
f := newWsAuthFixture(t, true)
|
||||
ws := newWsService()
|
||||
|
||||
subscriber := &ClientSession{
|
||||
ID: "subscriber-conn",
|
||||
Topics: map[string]struct{}{},
|
||||
Send: make(chan []byte, 10),
|
||||
}
|
||||
subscriber := newWsAuthClient(f, "subscriber-conn", realtimeRoleAdmin)
|
||||
ws.manager.Register(subscriber, []string{"conversation:100"})
|
||||
|
||||
principal := &dto.AuthPrincipal{
|
||||
UserID: 2,
|
||||
Username: "operator",
|
||||
Nickname: "Agent Smith",
|
||||
}
|
||||
sender := &ClientSession{
|
||||
ID: "sender-conn",
|
||||
Principal: principal,
|
||||
Topics: map[string]struct{}{},
|
||||
Send: make(chan []byte, 10),
|
||||
}
|
||||
sender := newWsAuthClient(f, "sender-conn", realtimeRoleAdmin)
|
||||
ws.manager.Register(sender, []string{"conversation:100"})
|
||||
|
||||
msgJSON := []byte(`{"type":"presence","conversationId":100,"action":"viewing"}`)
|
||||
@@ -188,7 +162,7 @@ func TestHandleClientMessagePresence(t *testing.T) {
|
||||
if event.Type != enums.IMRealtimeEventOperatorPresence {
|
||||
t.Fatalf("expected %s, got %s", enums.IMRealtimeEventOperatorPresence, event.Type)
|
||||
}
|
||||
if event.Data.ConversationID != 100 || event.Data.Action != "viewing" || event.Data.UserID != 2 {
|
||||
if event.Data.ConversationID != 100 || event.Data.Action != "viewing" || event.Data.UserID != f.principal.UserID {
|
||||
t.Fatalf("unexpected data: %+v", event.Data)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
|
||||
Reference in New Issue
Block a user