package governance import "testing" func TestParseAutoReviewPolicy(t *testing.T) { for _, testCase := range []struct { input string want AutoReviewPolicy wantErr bool }{ {"", AutoReviewInternal, false}, {"internal", AutoReviewInternal, false}, {" INTERNAL ", AutoReviewInternal, false}, {"off", AutoReviewOff, false}, {"all", AutoReviewAll, false}, {"sometimes", "", true}, } { got, err := ParseAutoReviewPolicy(testCase.input) if testCase.wantErr { if err == nil { t.Fatalf("ParseAutoReviewPolicy(%q) = %q, want error", testCase.input, got) } continue } if err != nil || got != testCase.want { t.Fatalf("ParseAutoReviewPolicy(%q) = %q error=%v, want %q", testCase.input, got, err, testCase.want) } } } func TestAutoReviewPolicyAllows(t *testing.T) { // 认不出的目标范围一律不自动批准(fail-closed)。 for _, targetScope := range []string{"", "both", "blocked", "unknown"} { if AutoReviewAll.Allows(targetScope) { t.Fatalf("scope %q must not be auto-approved", targetScope) } } if !AutoReviewInternal.Allows("internal") || AutoReviewInternal.Allows("external") { t.Fatal("internal policy must allow only internal") } if !AutoReviewAll.Allows("internal") || !AutoReviewAll.Allows("external") { t.Fatal("all policy must allow both scopes") } if AutoReviewOff.Allows("internal") || AutoReviewOff.Allows("external") { t.Fatal("off policy must allow nothing") } }