Files
Agent-System/internal/projectinstance/message_scope_test.go
T
weichenandCursor 1abafa3176 fix(chat): add message scope columns and write-path resolution
Persist workflow_instance_id, stage_instance_id, scope_kind on chat
messages and task runs; resolve scope from live instance for chat and
document tasks so refresh can apply consistent stage authorization.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 03:06:08 +00:00

55 lines
1.8 KiB
Go

package projectinstance
import "testing"
func TestMessageVisible_PreActivationOwnerOnly(t *testing.T) {
access := &StageAccess{Restricted: true, AllowedStageKeys: map[string]bool{"V0.1_triage": true}}
scope := MessageScope{ScopeKind: ScopePreActivation}
if !MessageVisible(scope, access, 9, 9) {
t.Fatal("owner should see pre_activation messages")
}
if MessageVisible(scope, access, 9, 99) {
t.Fatal("non-owner must not see pre_activation messages")
}
}
func TestMessageVisible_WorkflowStageRestricted(t *testing.T) {
access := &StageAccess{
Restricted: true,
AllowedStageKeys: map[string]bool{"V0.1_triage": true},
}
scope := MessageScope{ScopeKind: ScopeWorkflowStage, StageKey: "V0.1_triage"}
if !MessageVisible(scope, access, 9, 9) {
t.Fatal("allowed stage should be visible")
}
scope.StageKey = "V0.5_feasibility"
if MessageVisible(scope, access, 9, 9) {
t.Fatal("disallowed stage must be hidden")
}
}
func TestMessageVisible_LegacyUnscopedOwnerWhenRestricted(t *testing.T) {
access := &StageAccess{Restricted: true}
scope := MessageScope{ScopeKind: ScopeLegacyUnscoped}
if !MessageVisible(scope, access, 9, 9) {
t.Fatal("owner should see legacy_unscoped when restricted")
}
if MessageVisible(scope, access, 9, 99) {
t.Fatal("non-owner must not see legacy_unscoped when restricted")
}
}
func TestScopeFromMetadata_RoundTrip(t *testing.T) {
meta := map[string]any{
"scope_kind": ScopeWorkflowStage,
"workflow_instance_id": float64(89),
"stage_instance_id": float64(201),
"stage_key": "V0.1_triage",
}
scope := ScopeFromMetadata(meta)
if scope.ScopeKind != ScopeWorkflowStage || scope.WorkflowInstanceID != 89 || scope.StageInstanceID != 201 || scope.StageKey != "V0.1_triage" {
t.Fatalf("unexpected scope: %+v", scope)
}
}