聊天入口只把项目 ID 放在授权字段,协调器仍读空的 UserCtx.Project.ID,受控任务因此以 project_id=0 跳过账本投影,回复却称正文已保存。
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/chat"
|
|
"chat-agent-system/internal/coordinator"
|
|
)
|
|
|
|
func TestBindSessionProjectContext_FillsEmptyProjectID(t *testing.T) {
|
|
sess := chat.NewSession("sess-p6024-u4", &coordinator.UserProjectContext{
|
|
Project: coordinator.ProjectInfo{Name: "吞咽电刺激"},
|
|
}, nil, nil)
|
|
sess.SetProjectID(6024)
|
|
bindSessionProjectContext(sess)
|
|
if sess.UserCtx.Project.ID != "6024" {
|
|
t.Fatalf("project id=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
}
|
|
|
|
func TestBindSessionProjectContext_KeepsExistingProjectID(t *testing.T) {
|
|
sess := chat.NewSession("sess-keep", &coordinator.UserProjectContext{
|
|
Project: coordinator.ProjectInfo{ID: "9", Name: "已绑定"},
|
|
}, nil, nil)
|
|
sess.SetProjectID(6024)
|
|
bindSessionProjectContext(sess)
|
|
if sess.UserCtx.Project.ID != "9" {
|
|
t.Fatalf("project id=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
}
|
|
|
|
func TestBindSessionProjectContext_SkipsUnboundSession(t *testing.T) {
|
|
sess := chat.NewSession("sess-none", &coordinator.UserProjectContext{
|
|
Project: coordinator.ProjectInfo{Name: "未选项目"},
|
|
}, nil, nil)
|
|
sess.SetProjectID(0)
|
|
bindSessionProjectContext(sess)
|
|
if sess.UserCtx.Project.ID != "" {
|
|
t.Fatalf("project id=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
}
|