Files
knowledge-governance/internal/qaopsorg/attribution_test.go
T

47 lines
2.2 KiB
Go

package qaopsorg
import (
"context"
"errors"
"testing"
)
func TestAttributionUsesStableIdentityAndKeepsAmbiguitiesExplicit(t *testing.T) {
d := Directory{Departments: []Department{{ID: "root", Name: "fixture"}, {ID: "a", ParentID: "root", Name: "one"}, {ID: "b", ParentID: "root", Name: "two"}}, People: []Person{{ID: "staff-a", UnionID: "union-a", DepartmentIDs: []string{"a", "a"}}, {ID: "staff-cross", UnionID: "union-cross", DepartmentIDs: []string{"a", "b"}}, {ID: "duplicate-one", UnionID: "duplicate", DepartmentIDs: []string{"a"}}, {ID: "duplicate-two", UnionID: "duplicate", DepartmentIDs: []string{"b"}}}}
p, err := BuildAttribution(State{State: "ready", DirectoryID: "d", RevisionID: "r", Rules: []Rule{{DepartmentID: "root", Region: "国内工业"}, {DepartmentID: "b", Region: "APAC"}}}, d)
if err != nil {
t.Fatal(err)
}
for _, key := range [][2]string{{"staff-a", ""}, {"", "union-a"}} {
got := p.Resolve(key[0], key[1])
if got.State != "matched" || got.Region != "国内工业" || len(got.Departments) != 1 || got.PersonID != "staff-a" {
t.Fatalf("stable identity not resolved/deduplicated: %+v", got)
}
}
if got := p.Resolve("staff-cross", ""); got.State != "cross_region" || got.Region != "" || len(got.Departments) != 2 {
t.Fatalf("invented primary region: %+v", got)
}
if got := p.Resolve("", "duplicate"); got.State != "identity_conflict" {
t.Fatalf("duplicate union selected first person: %+v", got)
}
if got := p.Resolve("staff-a", "union-cross"); got.State != "identity_conflict" {
t.Fatalf("contradictory identifiers silently preferred: %+v", got)
}
if got := p.Resolve("absent", ""); got.State != "unmatched" {
t.Fatalf("unknown identity inferred: %+v", got)
}
if got := p.Resolve("", ""); got.State != "no_identity" {
t.Fatalf("anonymous identity inferred: %+v", got)
}
}
func TestAttributionDoesNotTreatMissingDirectoryAsPermissionSuccess(t *testing.T) {
p, err := BuildAttribution(State{State: "empty"}, Directory{})
if err != nil || p.Resolve("staff", "").State != "directory_missing" {
t.Fatal("missing directory not explicit")
}
var store *Store
if _, err = store.GetAttribution(context.Background()); !errors.Is(err, ErrUnavailable) {
t.Fatal("unavailable store returned an empty directory")
}
}