Files
Agent-System/internal/bizdev/testutil.go
T
weichen f8730791b9 fix(coordinator): 回填会话项目绑定,避免受控投影被跳过
聊天入口只把项目 ID 放在授权字段,协调器仍读空的 UserCtx.Project.ID,受控任务因此以 project_id=0 跳过账本投影,回复却称正文已保存。
2026-09-28 12:34:32 +00:00

42 lines
939 B
Go

package bizdev
import (
"testing"
"chat-agent-system/internal/config"
)
// MustNewService 测试辅助:允许内存降级,连接失败时不 fatal(除非显式需要 DB)。
func MustNewService(t testing.TB, cfg *config.Config) *Service {
t.Helper()
if cfg == nil {
cfg = &config.Config{DataDir: t.TempDir(), AgentBackend: "stub"}
}
if cfg.ContextDbHost != "" {
svc, err := NewService(cfg)
if err != nil {
t.Fatalf("NewService: %v", err)
}
return svc
}
cfg.AllowInMemory = true
if cfg.Env == "" {
cfg.Env = "test"
}
svc, err := NewService(cfg)
if err != nil {
t.Fatalf("NewService: %v", err)
}
return svc
}
// ClearDocumentGovernanceForTest 去掉账本,让阶段编排测试只覆盖小队产出。
// 受控任务仍须带 ProjectID,否则 ExecuteTask 会拒绝未绑定项目。
func ClearDocumentGovernanceForTest(s *Service) {
if s == nil {
return
}
s.docGov = nil
s.docRev = nil
}