Files
Agent-System/internal/app/docgov_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

82 lines
2.7 KiB
Go

package app
import (
"context"
"testing"
"chat-agent-system/internal/app/intentflow"
"chat-agent-system/internal/docgov"
)
func TestDocGovOwnerProject143Forbidden(t *testing.T) {
engine := docgov.NewGovernanceEngine(nil)
ctx := context.Background()
doc, err := engine.CreateOrGetDocument(ctx, "doc_test_143", 99, "intake", "t", "V0.5", "", 1, "A", 2, "R", 3, "P")
if err != nil {
t.Fatal(err)
}
owner := NewDocGovOwner(engine, nil, nil)
_, err = owner.Execute(ctx, intentflow.StepExec{
ActionKey: "document.claim",
IdempotencyKey: "143-deny", ActionDigest: "d",
ExpectedResourceVersion: "1",
Principal: intentflow.Principal{UserID: 1, ProjectID: 143, SessionID: "s"},
SafeSummary: doc.DocID,
})
if err != intentflow.ErrPlanActionForbidden {
t.Fatalf("project 143 must stay read-only, got %v", err)
}
}
func TestDocGovOwnerMissingVersionConflict(t *testing.T) {
engine := docgov.NewGovernanceEngine(nil)
ctx := context.Background()
doc, err := engine.CreateOrGetDocument(ctx, "doc_ver_test", 5, "intake", "t", "V0.5", "", 1, "A", 2, "R", 3, "P")
if err != nil {
t.Fatal(err)
}
owner := NewDocGovOwner(engine, func(context.Context, int64, int64) error { return nil }, nil)
_, err = owner.Execute(ctx, intentflow.StepExec{
ActionKey: "document.claim",
IdempotencyKey: "ver-miss", ActionDigest: "d",
ExpectedResourceVersion: "",
Principal: intentflow.Principal{UserID: 1, ProjectID: 5, SessionID: "s"},
SafeSummary: doc.DocID,
})
if err != intentflow.ErrPlanActionVersionConflict {
t.Fatalf("missing version: %v", err)
}
_, err = owner.Execute(ctx, intentflow.StepExec{
ActionKey: "document.claim",
IdempotencyKey: "ver-stale", ActionDigest: "d",
ExpectedResourceVersion: "999",
Principal: intentflow.Principal{UserID: 1, ProjectID: 5, SessionID: "s"},
SafeSummary: doc.DocID,
})
if err != intentflow.ErrPlanActionVersionConflict {
t.Fatalf("stale version: %v", err)
}
}
func TestDocGovOwnerAuthNegative(t *testing.T) {
engine := docgov.NewGovernanceEngine(nil)
ctx := context.Background()
doc, err := engine.CreateOrGetDocument(ctx, "doc_auth", 5, "intake", "t", "V0.5", "", 1, "A", 2, "R", 3, "P")
if err != nil {
t.Fatal(err)
}
owner := NewDocGovOwner(engine, func(context.Context, int64, int64) error {
return intentflow.ErrPlanActionForbidden
}, nil)
_, err = owner.Execute(ctx, intentflow.StepExec{
ActionKey: "document.claim",
IdempotencyKey: "auth-no", ActionDigest: "d",
ExpectedResourceVersion: "1",
Principal: intentflow.Principal{UserID: 9, ProjectID: 5, SessionID: "s"},
SafeSummary: doc.DocID,
})
if err != intentflow.ErrPlanActionForbidden {
t.Fatalf("auth negative: %v", err)
}
}