Unify auth middleware and remove X-User-ID trust, add project_members authorization, sandbox workspaces via resolver, and admin-only reconcile by run_id. Introduce goose migrations with startup schema gate, fail closed when DB unavailable outside explicit ALLOW_IN_MEMORY, bundle web/dist in app Dockerfile, and remove frontend pseudo-login fallback.
107 lines
3.1 KiB
Go
107 lines
3.1 KiB
Go
package bizdev
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/config"
|
|
"chat-agent-system/internal/ctxmgr"
|
|
)
|
|
|
|
func TestService_BlendedContextInjection(t *testing.T) {
|
|
tempDir, err := os.MkdirTemp("", "blended_ctx_test_*")
|
|
if err != nil {
|
|
t.Fatalf("mkdir temp failed: %v", err)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
cfg := &config.Config{
|
|
Env: "test",
|
|
DataDir: tempDir,
|
|
AgentBackend: "stub",
|
|
}
|
|
|
|
svc := MustNewService(t, cfg)
|
|
ctx := context.Background()
|
|
|
|
// 1. 设置用户个性化偏好
|
|
userID := int64(108)
|
|
projectID := int64(9001)
|
|
|
|
pref := &ctxmgr.UserPreference{
|
|
UserID: userID,
|
|
AccountID: "user_blended_test",
|
|
Name: "项目总监",
|
|
Role: "director",
|
|
CommunicationStyle: ctxmgr.StyleExecutiveSummary,
|
|
FocusAreas: []string{"cost_budget", "timeline"},
|
|
OutputFormatPref: "ppt_bullets",
|
|
}
|
|
_ = svc.ContextManager().UpdateUserPreference(ctx, pref)
|
|
|
|
// 2. 记录先验里程碑决策
|
|
_, _ = svc.ContextManager().RecordActivity(ctx, projectID, userID, "项目总监", "decision", "首期控制在50万预算内并优先过型检", nil, 1.0, true)
|
|
|
|
// 3. 执行任务 (使用 stub 后端进行快速逻辑验证)
|
|
res, err := svc.ExecuteTask(ctx, TaskRunRequest{
|
|
TaskKey: "intake",
|
|
ProjectName: "微型超声内窥镜系统",
|
|
CustomerName: "北京水木东方",
|
|
DeviceType: "超声内窥镜",
|
|
TargetMarket: "国内",
|
|
Backend: "stub",
|
|
ProjectID: projectID,
|
|
UserID: userID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("execute task failed: %v", err)
|
|
}
|
|
if !res.Success {
|
|
t.Fatalf("expected task success")
|
|
}
|
|
|
|
// 4. 验证工作区内的 context/user.md 与 context/memory/ 是否注入了混合上下文
|
|
userMdPath := filepath.Join(res.WorkDir, "context", "user.md")
|
|
userMdData, err := os.ReadFile(userMdPath)
|
|
if err != nil {
|
|
t.Fatalf("read user.md failed: %v", err)
|
|
}
|
|
userMdStr := string(userMdData)
|
|
|
|
if !strings.Contains(userMdStr, "高管决策摘要") {
|
|
t.Errorf("user.md missing executive style guidance: %s", userMdStr)
|
|
}
|
|
if !strings.Contains(userMdStr, "CDO工时核算、BOM成本与预算边界") {
|
|
t.Errorf("user.md missing cost focus: %s", userMdStr)
|
|
}
|
|
|
|
// 5. 验证 context/memory/team_decisions.md 注入
|
|
teamDecPath := filepath.Join(res.WorkDir, "context", "memory", "team_decisions.md")
|
|
teamDecData, err := os.ReadFile(teamDecPath)
|
|
if err != nil {
|
|
t.Fatalf("read team_decisions.md failed: %v", err)
|
|
}
|
|
if !strings.Contains(string(teamDecData), "首期控制在50万预算内") {
|
|
t.Errorf("team_decisions.md missing milestone decision: %s", string(teamDecData))
|
|
}
|
|
|
|
// 6. 验证任务完成后自动记录了里程碑活动
|
|
pCtx, err := svc.ContextManager().GetProjectContext(ctx, projectID)
|
|
if err != nil {
|
|
t.Fatalf("get project context failed: %v", err)
|
|
}
|
|
foundDeliveryActivity := false
|
|
for _, act := range pCtx.AllActivities {
|
|
if strings.Contains(act.Title, "完成交付物") {
|
|
foundDeliveryActivity = true
|
|
break
|
|
}
|
|
}
|
|
if !foundDeliveryActivity {
|
|
t.Errorf("expected delivery activity recorded in project context")
|
|
}
|
|
}
|