server 侧窄端口适配 projectworkflow,消除 chat→projectworkflow 边界违规;记录单测与 arch-check 证据,PI 全链路待补证。
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package chat
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/bizdev"
|
|
"chat-agent-system/internal/config"
|
|
"chat-agent-system/internal/coordinator"
|
|
"chat-agent-system/internal/docgov"
|
|
)
|
|
|
|
type stubWorkflowRunner struct {
|
|
last WorkflowStartRequest
|
|
err error
|
|
}
|
|
|
|
func (s *stubWorkflowRunner) CreateWorkflowRun(_ context.Context, req WorkflowStartRequest) (*WorkflowStartResult, error) {
|
|
if s.err != nil {
|
|
return nil, s.err
|
|
}
|
|
s.last = req
|
|
return &WorkflowStartResult{RunID: req.RunID}, nil
|
|
}
|
|
|
|
func TestExecuteAction_DocGovClaimAndSubmit(t *testing.T) {
|
|
cfg := &config.Config{DataDir: t.TempDir()}
|
|
svc := bizdev.MustNewService(t, cfg)
|
|
docGov := bizdev.Snapshot(svc).Gov
|
|
ctx := context.Background()
|
|
|
|
docID := "doc_proj1_intake_p0"
|
|
_, err := docGov.CreateOrGetDocument(
|
|
ctx, docID, 1, "intake", "需求表", "V0.5", "",
|
|
1, "张工", 2, "李主管", 3, "王总监",
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("CreateOrGetDocument: %v", err)
|
|
}
|
|
_ = docGov.MarkDocumentContentUpdated(ctx, docID, "hash-p0", false)
|
|
|
|
sess := &Session{
|
|
UserID: 1,
|
|
ProjectID: 1,
|
|
Actions: &ActionServices{DocGov: docGov},
|
|
}
|
|
userCtx := &coordinator.UserProjectContext{
|
|
User: coordinator.UserInfo{ID: "1", Name: "张工"},
|
|
}
|
|
|
|
claimRes, err := sess.executeAction(ctx, &coordinator.PendingAction{Kind: "docgov.claim", DocID: docID}, userCtx)
|
|
if err != nil {
|
|
t.Fatalf("claim: %v", err)
|
|
}
|
|
if claimRes.Message != "认领完成" {
|
|
t.Fatalf("claim message=%q", claimRes.Message)
|
|
}
|
|
if len(userCtx.UserDocs.Claimed) == 0 {
|
|
t.Fatal("expected Claimed list update after successful claim")
|
|
}
|
|
|
|
submitRes, err := sess.executeAction(ctx, &coordinator.PendingAction{Kind: "docgov.submit_review", DocID: docID}, userCtx)
|
|
if err != nil {
|
|
t.Fatalf("submit: %v", err)
|
|
}
|
|
if submitRes.DocState != string(docgov.StateReviewing) {
|
|
t.Fatalf("expected reviewing, got %s", submitRes.DocState)
|
|
}
|
|
}
|
|
|
|
func TestExecuteAction_WorkflowRun(t *testing.T) {
|
|
stub := &stubWorkflowRunner{}
|
|
sess := &Session{
|
|
UserID: 7,
|
|
ProjectID: 42,
|
|
Actions: &ActionServices{Workflow: stub},
|
|
}
|
|
userCtx := &coordinator.UserProjectContext{
|
|
User: coordinator.UserInfo{ID: "7", Name: "运维"},
|
|
Project: coordinator.ProjectInfo{ActiveWorkflowKey: "main"},
|
|
}
|
|
res, err := sess.executeAction(context.Background(), &coordinator.PendingAction{Kind: "workflow.run", WorkflowKey: "main"}, userCtx)
|
|
if err != nil {
|
|
t.Fatalf("workflow.run: %v", err)
|
|
}
|
|
if stub.last.ProjectID != 42 || stub.last.WorkflowKey != "main" || stub.last.StartedBy != 7 {
|
|
t.Fatalf("unexpected run %+v", stub.last)
|
|
}
|
|
if res.RunID == "" {
|
|
t.Fatal("expected run id")
|
|
}
|
|
}
|