From 070bca431c6216f75bee72e71ea77a5f83c68abb Mon Sep 17 00:00:00 2001 From: ZQR1101 <278034003+ZQR1101@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:09:23 +0800 Subject: [PATCH] fix(config): let an explicit profile api_format survive the linked connection (#2451) --- deeptutor/services/config/provider_links.py | 12 ++++- .../test_provider_registry_workflow.py | 49 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/deeptutor/services/config/provider_links.py b/deeptutor/services/config/provider_links.py index dd7a13429..b571893a8 100644 --- a/deeptutor/services/config/provider_links.py +++ b/deeptutor/services/config/provider_links.py @@ -175,7 +175,17 @@ def resolve_profile_provider( binding, result["base_url"], (model or {}).get("model") ) for field in ("api_format", "wire_api"): - result[field] = source.get(field) or "auto" + # Precedence: the profile's explicit (non-default) setting wins over + # the linked connection's, which wins over "auto". Previously the + # connection unconditionally clobbered the profile — and a profile + # that named the Responses API silently lost it even when the + # connection left the default alone (#2451, profile-side). A profile + # whose own value is empty/"auto" falls through to the connection. + explicit = profile.get(field) + if explicit and explicit != "auto": + result[field] = explicit + else: + result[field] = source.get(field) or "auto" if source.get("owner_bound"): result["owner_bound"] = True result["name"] = source.get("name") or profile.get("name", "") diff --git a/tests/services/test_provider_registry_workflow.py b/tests/services/test_provider_registry_workflow.py index 9bcbe9b8e..edb0d0eb0 100644 --- a/tests/services/test_provider_registry_workflow.py +++ b/tests/services/test_provider_registry_workflow.py @@ -537,3 +537,52 @@ def test_manual_service_changes_do_not_rekey_or_remove_existing_models(tmp_path) saved = store.save(catalog) saved["services"]["llm"]["profiles"][0].pop("service_overrides") assert saved["services"] == before + + +# ── #2451 (profile side): an explicitly-set profile api_format must not be +# silently clobbered by the linked connection's value. + + +def _linked_profile_with_api_format(tmp_path, *, profile_format=None, connection_format=None): + store, catalog = fixture(tmp_path) + + +def _linked_profile_with_api_format(tmp_path, *, profile_format=None, connection_format=None): + store, catalog = fixture(tmp_path) + # merge_registry_edit is what materializes the "account" connection the + # profile links to; without it saved["connections"] stays empty. + catalog = merge_registry_edit(catalog, provider_edit()) + profile = catalog["services"]["llm"]["profiles"][0] + profile["provider_ref"] = {"connection_id": "account", "binding": "custom"} + if profile_format is not None: + profile["api_format"] = profile_format + saved = store.save(catalog) + source = next(c for c in saved["connections"] if c["id"] == "account") + if connection_format is not None: + source["api_format"] = connection_format + saved = store.save(saved) + return resolve_profile_provider(saved, "llm", saved["services"]["llm"]["profiles"][0]) + + +def test_profile_explicit_api_format_wins_over_connection(tmp_path): + resolved = _linked_profile_with_api_format( + tmp_path, profile_format="openai_responses", connection_format="auto" + ) + + assert resolved["api_format"] == "openai_responses" + + +def test_profile_without_api_format_inherits_connection(tmp_path): + resolved = _linked_profile_with_api_format( + tmp_path, profile_format=None, connection_format="openai_responses" + ) + + assert resolved["api_format"] == "openai_responses" + + +def test_api_format_defaults_to_auto_when_unset(tmp_path): + resolved = _linked_profile_with_api_format( + tmp_path, profile_format=None, connection_format=None + ) + + assert resolved["api_format"] == "auto"