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) } }