(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func TestIsContextLimitKey(t *testing.T) { |
| 80 | t.Parallel() |
| 81 | |
| 82 | tests := []struct { |
| 83 | name string |
| 84 | key string |
| 85 | want bool |
| 86 | }{ // Exact matches after normalization. |
| 87 | {name: "context_limit", key: "context_limit", want: true}, |
| 88 | {name: "context_window", key: "context_window", want: true}, |
| 89 | {name: "context_length", key: "context_length", want: true}, |
| 90 | {name: "max_context", key: "max_context", want: true}, |
| 91 | {name: "max_context_tokens", key: "max_context_tokens", want: true}, |
| 92 | {name: "max_input_tokens", key: "max_input_tokens", want: true}, |
| 93 | {name: "max_input_token", key: "max_input_token", want: true}, |
| 94 | {name: "input_token_limit", key: "input_token_limit", want: true}, |
| 95 | |
| 96 | // Case and separator variations. |
| 97 | {name: "Context-Window mixed case", key: "Context-Window", want: true}, |
| 98 | {name: "MAX_CONTEXT_TOKENS screaming", key: "MAX_CONTEXT_TOKENS", want: true}, |
| 99 | {name: "contextLimit camelCase", key: "contextLimit", want: true}, |
| 100 | {name: "modelContextLimit camelCase", key: "modelContextLimit", want: true}, |
| 101 | |
| 102 | // Fallback heuristic: tokenized "context" + limit/window/length. |
| 103 | {name: "model_context_limit", key: "model_context_limit", want: true}, |
| 104 | {name: "context_window_size", key: "context_window_size", want: true}, |
| 105 | {name: "context_length_max", key: "context_length_max", want: true}, |
| 106 | |
| 107 | // Exact matches remain valid after separator stripping. |
| 108 | {name: "max_context_", key: "max_context_", want: true}, |
| 109 | {name: "max_context_limit", key: "max_context_limit", want: true}, |
| 110 | |
| 111 | // Non-matching keys should not be treated as context limits. |
| 112 | {name: "max_context_version false positive", key: "max_context_version", want: false}, |
| 113 | {name: "context_tokens_used false positive", key: "context_tokens_used", want: false}, |
| 114 | {name: "context_length_used false positive", key: "context_length_used", want: false}, |
| 115 | {name: "context_window_used false positive", key: "context_window_used", want: false}, |
| 116 | {name: "context_id no limit keyword", key: "context_id", want: false}, |
| 117 | {name: "empty string", key: "", want: false}, |
| 118 | {name: "unrelated key", key: "model_name", want: false}, |
| 119 | {name: "limit without context", key: "rate_limit", want: false}, |
| 120 | {name: "max without context", key: "max_tokens", want: false}, |
| 121 | {name: "context alone", key: "context", want: false}, |
| 122 | } |
| 123 | for _, tt := range tests { |
| 124 | t.Run(tt.name, func(t *testing.T) { |
| 125 | t.Parallel() |
| 126 | got := isContextLimitKey(tt.key) |
| 127 | require.Equal(t, tt.want, got) |
| 128 | }) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestNumericContextLimitValue(t *testing.T) { |
| 133 | t.Parallel() |
nothing calls this directly
no test coverage detected