@@ -58,12 +58,87 @@ func TestModelFilterWithWildcardInMiddle(t *testing.T) {
5858 assert .False (t , filter .Allows ("DeepSeek/empty-old-v1" ))
5959 assert .False (t , filter .Allows ("Foo/old" ))
6060 assert .False (t , filter .Allows ("Bar/deprecated" ))
61-
61+
6262 // Test that */pattern* requires the pattern immediately after /
6363 filter2 , err := NewModelFilter (nil , []string {"*/deprecated" , "*/old*" })
6464 require .NoError (t , err )
65-
65+
6666 assert .True (t , filter2 .Allows ("Mistral/empty-deprecated" )) // doesn't match */deprecated (no immediate match after /)
67- assert .False (t , filter2 .Allows ("Foo/deprecated" )) // matches */deprecated
68- assert .False (t , filter2 .Allows ("Bar/old-model" )) // matches */old*
67+ assert .False (t , filter2 .Allows ("Foo/deprecated" )) // matches */deprecated
68+ assert .False (t , filter2 .Allows ("Bar/old-model" )) // matches */old*
69+ }
70+
71+ func TestValidateSourceFilters (t * testing.T ) {
72+ t .Run ("valid source with no filters" , func (t * testing.T ) {
73+ source := & Source {
74+ CatalogSource : apimodels.CatalogSource {
75+ Id : "test" ,
76+ Name : "Test source" ,
77+ },
78+ }
79+ err := ValidateSourceFilters (source )
80+ assert .NoError (t , err )
81+ })
82+
83+ t .Run ("valid source with patterns" , func (t * testing.T ) {
84+ source := & Source {
85+ CatalogSource : apimodels.CatalogSource {
86+ Id : "test" ,
87+ Name : "Test source" ,
88+ IncludedModels : []string {"Granite/*" , "Meta/*" },
89+ ExcludedModels : []string {"*-beta" },
90+ },
91+ }
92+ err := ValidateSourceFilters (source )
93+ assert .NoError (t , err )
94+ })
95+
96+ t .Run ("conflicting patterns" , func (t * testing.T ) {
97+ source := & Source {
98+ CatalogSource : apimodels.CatalogSource {
99+ Id : "test" ,
100+ Name : "Test source" ,
101+ IncludedModels : []string {"Granite/*" },
102+ ExcludedModels : []string {"Granite/*" },
103+ },
104+ }
105+ err := ValidateSourceFilters (source )
106+ require .Error (t , err )
107+ assert .Contains (t , err .Error (), "source test" )
108+ assert .Contains (t , err .Error (), "Granite/*" )
109+ })
110+
111+ t .Run ("empty pattern in includedModels" , func (t * testing.T ) {
112+ source := & Source {
113+ CatalogSource : apimodels.CatalogSource {
114+ Id : "test" ,
115+ Name : "Test source" ,
116+ IncludedModels : []string {"Granite/*" , "" },
117+ },
118+ }
119+ err := ValidateSourceFilters (source )
120+ require .Error (t , err )
121+ assert .Contains (t , err .Error (), "source test" )
122+ assert .Contains (t , err .Error (), "pattern cannot be empty" )
123+ })
124+
125+ t .Run ("invalid regex pattern" , func (t * testing.T ) {
126+ // This shouldn't happen with our glob-to-regex conversion,
127+ // but validates the error path exists
128+ source := & Source {
129+ CatalogSource : apimodels.CatalogSource {
130+ Id : "test" ,
131+ Name : "Test source" ,
132+ IncludedModels : []string {"valid/*" },
133+ },
134+ }
135+ err := ValidateSourceFilters (source )
136+ assert .NoError (t , err ) // Our conversion always produces valid regex
137+ })
138+
139+ t .Run ("nil source" , func (t * testing.T ) {
140+ err := ValidateSourceFilters (nil )
141+ require .Error (t , err )
142+ assert .Contains (t , err .Error (), "source cannot be nil" )
143+ })
69144}
0 commit comments