Files
Agent-System/internal/app/mutate_owner_test.go
T
weichen 016135d946 feat(intentflow): wire U9–U12 live adapters for multi-intent closeout
Connect LLM segment proposals into HandleTurn, replace U10–U12 dry-run stubs
with production owners (blackboard supplement, docgov claim/submit, workflow
run/resume) when flags are on, and update policy/sysadmin maturity metadata.
2026-09-23 15:26:46 +00:00

71 lines
2.2 KiB
Go

package app
import (
"context"
"testing"
"chat-agent-system/internal/app/intentflow"
)
func TestMutateOwnerMissingRevisionConflict(t *testing.T) {
m := NewMutateOwner(nil, ProjectBlackboardPort{})
ctx := context.Background()
_, err := m.Execute(ctx, intentflow.StepExec{
ActionKey: "project.fact.supplement",
IdempotencyKey: "k1", ActionDigest: "d1",
Principal: intentflow.Principal{UserID: 1, ProjectID: 2, SessionID: "s"},
SafeSummary: "补充目标市场为国内",
})
if err != intentflow.ErrPlanActionVersionConflict {
t.Fatalf("want version conflict, got %v", err)
}
}
func TestMutateOwnerDigestReplay(t *testing.T) {
ver := "1"
m := NewMutateOwner(nil, ProjectBlackboardPort{
CurrentVersion: func(context.Context, int64) (string, error) { return ver, nil },
MergeFacts: func(context.Context, int64, map[string]string) (string, error) {
return "2", nil
},
})
ctx := context.Background()
exec := intentflow.StepExec{
ActionKey: "project.fact.supplement",
IdempotencyKey: "k2", ActionDigest: "d2",
ExpectedResourceVersion: ver,
Principal: intentflow.Principal{UserID: 1, ProjectID: 2, SessionID: "s"},
SafeSummary: "补充目标市场为国内",
}
first, err := m.Execute(ctx, exec)
if err != nil {
t.Fatal(err)
}
again, err := m.Execute(ctx, exec)
if err != nil || again.ResultDigest != first.ResultDigest {
t.Fatalf("idempotent replay: %v %+v", err, again)
}
exec.ActionDigest = "other"
if _, err := m.Execute(ctx, exec); err != intentflow.ErrPlanDecisionConflict {
t.Fatalf("digest mismatch: %v", err)
}
}
func TestMutateOwnerForbiddenWithoutAccess(t *testing.T) {
m := NewMutateOwner(func(context.Context, int64, int64) error {
return intentflow.ErrPlanActionForbidden
}, ProjectBlackboardPort{
CurrentVersion: func(context.Context, int64) (string, error) { return "1", nil },
})
_, err := m.Execute(context.Background(), intentflow.StepExec{
ActionKey: "project.fact.supplement",
IdempotencyKey: "k3", ActionDigest: "d3",
ExpectedResourceVersion: "1",
Principal: intentflow.Principal{UserID: 1, ProjectID: 2, SessionID: "s"},
SafeSummary: "补充材料",
})
if err != intentflow.ErrPlanActionForbidden {
t.Fatalf("want forbidden, got %v", err)
}
}