Merge PR #2531: fix(config): let an explicit profile api_format survive the linked connection (#2451)

This commit is contained in:
Bingxi Zhao (Frank)
2026-11-14 22:49:38 +08:00
2 changed files with 60 additions and 1 deletions

View File

@@ -193,7 +193,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", "")

View File

@@ -613,3 +613,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"