fix(ci): regenerate schema.d.ts, dispatch table for update_settings complexity, prettier

- schema.d.ts was stale after adding default_litellm_params/optional_pre_call_checks
  to UpdateRouterConfig; applied the exact diff CI's schema-vs-spec check expects.
- update_settings's two new elif branches pushed its cyclomatic complexity from 14
  to 16, crossing ruff-strict.toml's max-complexity=15 budget. Replaced both branches
  with a single `var in _CUSTOM_UPDATE_SETTINGS_HANDLERS` dispatch (one branch instead
  of two) so adding a custom-handled setting doesn't grow this function's branch count
  per field; also switched the two new helper signatures to `X | None` per UP045.
- prettier --write on the two test files flagged by frontend-lint.
This commit is contained in:
Krrish Dholakia 2026-07-13 18:48:11 -07:00
parent dcfdc6dbb0
commit 9a513aba77
4 changed files with 34 additions and 15 deletions

View file

@ -9706,6 +9706,26 @@ class Router:
_settings_to_return["routing_groups"] = [group.model_dump() for group in self._routing_groups.values()]
return _settings_to_return
def _merge_default_litellm_params_setting(self, value: dict | None) -> None:
if value is not None:
self.default_litellm_params = {**self.default_litellm_params, **value}
def _apply_optional_pre_call_checks_setting(self, value: OptionalPreCallChecks | None) -> None:
if value is None:
return
new_checks = [check for check in value if check not in self.optional_pre_call_checks]
if new_checks:
self.add_optional_pre_call_checks(new_checks)
# Settings whose update logic doesn't fit `setattr(self, var, value)` (e.g.
# merge-not-replace, or side effects beyond storing the value). Dispatched via
# a single `var in ...` branch in update_settings so adding an entry here
# doesn't grow that function's branch count per field.
_CUSTOM_UPDATE_SETTINGS_HANDLERS: dict = {
"default_litellm_params": _merge_default_litellm_params_setting,
"optional_pre_call_checks": _apply_optional_pre_call_checks_setting,
}
def update_settings(self, **kwargs):
"""
Update the router settings.
@ -9756,14 +9776,8 @@ class Router:
value = RetryPolicy(**value)
if value is None or isinstance(value, RetryPolicy):
setattr(self, var, value)
elif var == "default_litellm_params":
if kwargs[var] is not None:
self.default_litellm_params = {**self.default_litellm_params, **kwargs[var]}
elif var == "optional_pre_call_checks":
if kwargs[var] is not None:
new_checks = [check for check in kwargs[var] if check not in self.optional_pre_call_checks]
if new_checks:
self.add_optional_pre_call_checks(new_checks)
elif var in self._CUSTOM_UPDATE_SETTINGS_HANDLERS:
self._CUSTOM_UPDATE_SETTINGS_HANDLERS[var](self, kwargs[var])
else:
value = kwargs[var]
# only run routing strategy init if it has changed

View file

@ -36,17 +36,13 @@ const options = ["prompt_caching", "router_budget_limiting", "session_affinity"]
describe("OptionalPreCallChecksSelector", () => {
it("should render one option per entry in options", () => {
render(
<OptionalPreCallChecksSelector value={[]} options={options} routerFieldsMetadata={{}} onChange={vi.fn()} />,
);
render(<OptionalPreCallChecksSelector value={[]} options={options} routerFieldsMetadata={{}} onChange={vi.fn()} />);
const select = screen.getByTestId("optional-pre-call-checks-select") as HTMLSelectElement;
expect(Array.from(select.options).map((o) => o.value)).toEqual(options);
});
it("should display default label when no metadata is provided", () => {
render(
<OptionalPreCallChecksSelector value={[]} options={options} routerFieldsMetadata={{}} onChange={vi.fn()} />,
);
render(<OptionalPreCallChecksSelector value={[]} options={options} routerFieldsMetadata={{}} onChange={vi.fn()} />);
expect(screen.getByText("Optional Pre-call Checks")).toBeInTheDocument();
});

View file

@ -138,7 +138,10 @@ describe("RouterSettingsForm", () => {
const props = {
...baseProps,
routerFieldsMetadata: {
optional_pre_call_checks: { ui_field_name: "Optional Pre-call Checks", options: ["prompt_caching", "router_budget_limiting"] },
optional_pre_call_checks: {
ui_field_name: "Optional Pre-call Checks",
options: ["prompt_caching", "router_budget_limiting"],
},
},
};
render(<RouterSettingsForm {...props} />);

View file

@ -32223,6 +32223,10 @@ export interface components {
}[] | null;
/** Cooldown Time */
cooldown_time?: number | null;
/** Default Litellm Params */
default_litellm_params?: {
[key: string]: unknown;
} | null;
/** Fallbacks */
fallbacks?: {
[key: string]: unknown;
@ -32248,6 +32252,8 @@ export interface components {
} | null;
/** Num Retries */
num_retries?: number | null;
/** Optional Pre Call Checks */
optional_pre_call_checks?: ("prompt_caching" | "router_budget_limiting" | "responses_api_deployment_check" | "deployment_affinity" | "session_affinity" | "forward_client_headers_by_model_group" | "enforce_model_rate_limits" | "encrypted_content_affinity")[] | null;
/** Retry After */
retry_after?: number | null;
retry_policy?: components["schemas"]["RetryPolicy"] | null;