@@ -135,11 +135,120 @@ func TestValidateModelOptionPolicySettings(t *testing.T) {
135135 }
136136}
137137
138- func TestValidateFullContextMaxTokensAllowsLargeContextWindows (t * testing.T ) {
139- if err := validatePatchItem (PatchItem {Namespace : "file" , Key : "full_context_max_tokens" , Value : "1000000" }); err != nil {
140- t .Fatalf ("expected 1M full context token limit to pass, got %v" , err )
138+ func TestValidateFullContextLimitsAllowUnlimitedValues (t * testing.T ) {
139+ cases := []PatchItem {
140+ {Namespace : "file" , Key : "full_context_limit_enabled" , Value : "true" },
141+ {Namespace : "file" , Key : "full_context_limit_enabled" , Value : "false" },
142+ {Namespace : "file" , Key : "file_full_context_max_bytes" , Value : "" },
143+ {Namespace : "file" , Key : "file_full_context_max_bytes" , Value : "0" },
144+ {Namespace : "file" , Key : "full_context_max_tokens" , Value : "" },
145+ {Namespace : "file" , Key : "full_context_max_tokens" , Value : "0" },
146+ {Namespace : "file" , Key : "full_context_pdf_max_pages" , Value : "" },
147+ {Namespace : "file" , Key : "full_context_pdf_max_pages" , Value : "0" },
148+ }
149+
150+ for _ , item := range cases {
151+ if err := validatePatchItem (item ); err != nil {
152+ t .Fatalf ("expected %s:%s=%q to pass, got %v" , item .Namespace , item .Key , item .Value , err )
153+ }
154+ }
155+ }
156+
157+ func TestValidateFullContextLimitsEnforcesConfiguredRanges (t * testing.T ) {
158+ cases := []struct {
159+ name string
160+ item PatchItem
161+ want bool
162+ }{
163+ {
164+ name : "full context limit mode must be boolean" ,
165+ item : PatchItem {Namespace : "file" , Key : "full_context_limit_enabled" , Value : "disabled" },
166+ want : false ,
167+ },
168+ {
169+ name : "1M token limit passes" ,
170+ item : PatchItem {Namespace : "file" , Key : "full_context_max_tokens" , Value : "1000000" },
171+ want : true ,
172+ },
173+ {
174+ name : "token limit below minimum fails" ,
175+ item : PatchItem {Namespace : "file" , Key : "full_context_max_tokens" , Value : "127" },
176+ want : false ,
177+ },
178+ {
179+ name : "token limit above maximum fails" ,
180+ item : PatchItem {Namespace : "file" , Key : "full_context_max_tokens" , Value : "1000001" },
181+ want : false ,
182+ },
183+ {
184+ name : "negative byte limit fails" ,
185+ item : PatchItem {Namespace : "file" , Key : "file_full_context_max_bytes" , Value : "-1" },
186+ want : false ,
187+ },
188+ {
189+ name : "pdf page limit above maximum fails" ,
190+ item : PatchItem {Namespace : "file" , Key : "full_context_pdf_max_pages" , Value : "501" },
191+ want : false ,
192+ },
193+ }
194+
195+ for _ , tc := range cases {
196+ t .Run (tc .name , func (t * testing.T ) {
197+ err := validatePatchItem (tc .item )
198+ if tc .want && err != nil {
199+ t .Fatalf ("expected validation to pass, got %v" , err )
200+ }
201+ if ! tc .want && err == nil {
202+ t .Fatal ("expected validation to fail" )
203+ }
204+ })
205+ }
206+ }
207+
208+ func TestRuntimeSettingsDisablesFullContextLimits (t * testing.T ) {
209+ runtimeSettings := NewRuntimeSettings (nil , nil , "test-data-encryption-key" )
210+ cfg := config.Config {
211+ FileFullContextLimitEnabled : true ,
212+ FileFullContextMaxBytes : 51200 ,
213+ FileFullContextMaxTokens : 12000 ,
214+ FileFullContextPDFMaxPages : 20 ,
141215 }
142- if err := validatePatchItem (PatchItem {Namespace : "file" , Key : "full_context_max_tokens" , Value : "1000001" }); err == nil {
143- t .Fatal ("expected full context token limit above 1M to fail" )
216+
217+ runtimeSettings .applyItem (& cfg , domainsettings.SystemSetting {Namespace : "file" , Key : "full_context_limit_enabled" , Value : "false" })
218+ runtimeSettings .normalizeConfig (& cfg )
219+
220+ if cfg .FileFullContextLimitEnabled {
221+ t .Fatal ("expected full context limit switch to be disabled" )
222+ }
223+ if cfg .FileFullContextMaxBytes != 0 || cfg .FileFullContextMaxTokens != 0 || cfg .FileFullContextPDFMaxPages != 0 {
224+ t .Fatalf (
225+ "expected disabled full context limits to be unlimited, got bytes=%d tokens=%d pdfPages=%d" ,
226+ cfg .FileFullContextMaxBytes ,
227+ cfg .FileFullContextMaxTokens ,
228+ cfg .FileFullContextPDFMaxPages ,
229+ )
230+ }
231+ }
232+
233+ func TestRuntimeSettingsTreatsEmptyFullContextLimitsAsUnlimited (t * testing.T ) {
234+ runtimeSettings := NewRuntimeSettings (nil , nil , "test-data-encryption-key" )
235+ cfg := config.Config {
236+ FileFullContextLimitEnabled : true ,
237+ FileFullContextMaxBytes : 51200 ,
238+ FileFullContextMaxTokens : 12000 ,
239+ FileFullContextPDFMaxPages : 20 ,
240+ }
241+
242+ runtimeSettings .applyItem (& cfg , domainsettings.SystemSetting {Namespace : "file" , Key : "file_full_context_max_bytes" , Value : "" })
243+ runtimeSettings .applyItem (& cfg , domainsettings.SystemSetting {Namespace : "file" , Key : "full_context_max_tokens" , Value : "" })
244+ runtimeSettings .applyItem (& cfg , domainsettings.SystemSetting {Namespace : "file" , Key : "full_context_pdf_max_pages" , Value : "" })
245+
246+ if cfg .FileFullContextMaxBytes != 0 || cfg .FileFullContextMaxTokens != 0 || cfg .FileFullContextPDFMaxPages != 0 {
247+ t .Fatalf (
248+ "expected empty full context limits to be unlimited, got bytes=%d tokens=%d pdfPages=%d" ,
249+ cfg .FileFullContextMaxBytes ,
250+ cfg .FileFullContextMaxTokens ,
251+ cfg .FileFullContextPDFMaxPages ,
252+ )
144253 }
145254}
0 commit comments