Files
Agent-System/internal/server/document_revision_duty_write_test.go
T
weichenandCursor 6a68e04f1f feat(docduty): resolve project reviewer onto controlled docs
Stop inventing reviewer_id=2. Use project document_duty as the authority, heal missing or non-member placeholders, and keep write paths rejected for reviewer and outsiders.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 21:57:44 +00:00

49 lines
1.5 KiB
Go

package server
import (
"context"
"testing"
"chat-agent-system/internal/auth"
"chat-agent-system/internal/authz"
"chat-agent-system/internal/docrevision"
)
func TestAuthorizeDocRevision_ReviewerAndNonMemberCannotWrite(t *testing.T) {
srv := newTestServer(t)
ctx := context.Background()
const (
authorID int64 = 170
reviewerID int64 = 171
strangerID int64 = 99
docID = "doc_proj_duty_write"
)
if _, err := srv.svc.DocGov().CreateOrGetDocument(
ctx, docID, 6145, "intake", "摸底", "V0.1", "",
authorID, "编制人A", reviewerID, "审核人B", 0, "",
); err != nil {
t.Fatal(err)
}
ref := &docRevisionRef{
Kind: "controlled", ProjectID: 6145, LifecycleState: "drafting", AuthorID: authorID,
}
author := &auth.UserAccount{ID: authorID, Name: "编制人A"}
if err := srv.authorizeDocRevision(ctx, author, ref, true); err != nil && err != authz.ErrForbidden {
// 无 project_members 时可能因 authorizer 策略拒绝项目访问;编制人写权仍由 AuthorID 门闩覆盖。
if err != docrevision.ErrForbidden {
t.Fatalf("author write unexpected err: %v", err)
}
}
reviewer := &auth.UserAccount{ID: reviewerID, Name: "审核人B"}
if err := srv.authorizeDocRevision(ctx, reviewer, ref, true); err == nil {
t.Fatal("reviewer B must not write controlled body")
}
stranger := &auth.UserAccount{ID: strangerID, Name: "局外人C"}
if err := srv.authorizeDocRevision(ctx, stranger, ref, true); err == nil {
t.Fatal("non-member C must not write controlled body")
}
}