fix(studio): normalize catalog identifiers

parent 1137ae24
...@@ -217,9 +217,10 @@ def build_catalog_entry( ...@@ -217,9 +217,10 @@ def build_catalog_entry(
def _build_named_catalog_entry( def _build_named_catalog_entry(
*, *,
prefix: str, kind: str,
scope: str, scope: str,
owner_id: Optional[int], owner_id: Optional[int],
source_id: str,
target_id: str, target_id: str,
label: str, label: str,
description: Optional[str], description: Optional[str],
...@@ -229,8 +230,8 @@ def _build_named_catalog_entry( ...@@ -229,8 +230,8 @@ def _build_named_catalog_entry(
entry = build_catalog_entry( entry = build_catalog_entry(
scope=scope, scope=scope,
owner_id=owner_id, owner_id=owner_id,
kind=prefix, kind=kind,
source_id=prefix, source_id=source_id,
target_id=target_id, target_id=target_id,
label=label, label=label,
description=description, description=description,
...@@ -239,7 +240,7 @@ def _build_named_catalog_entry( ...@@ -239,7 +240,7 @@ def _build_named_catalog_entry(
availability_reason=None, availability_reason=None,
metadata=metadata, metadata=metadata,
) )
entry["id"] = f"{prefix}/{prefix}/{target_id}" entry["id"] = f"{kind}/{target_id}"
return entry return entry
...@@ -345,9 +346,10 @@ def _build_rotation_entries(scope: str, owner_id: Optional[int], rotations: Dict ...@@ -345,9 +346,10 @@ def _build_rotation_entries(scope: str, owner_id: Optional[int], rotations: Dict
config_data = rotation_config if isinstance(rotation_config, dict) else rotation_config.model_dump() config_data = rotation_config if isinstance(rotation_config, dict) else rotation_config.model_dump()
entries.append( entries.append(
_build_named_catalog_entry( _build_named_catalog_entry(
prefix="rotation", kind="rotation",
scope=scope, scope=scope,
owner_id=owner_id, owner_id=owner_id,
source_id=rotation_id,
target_id=rotation_id, target_id=rotation_id,
label=config_data.get("model_name") or rotation_id, label=config_data.get("model_name") or rotation_id,
description=config_data.get("description"), description=config_data.get("description"),
...@@ -368,9 +370,10 @@ def _build_autoselect_entries(scope: str, owner_id: Optional[int], autoselects: ...@@ -368,9 +370,10 @@ def _build_autoselect_entries(scope: str, owner_id: Optional[int], autoselects:
available_models = config_data.get("available_models") or [] available_models = config_data.get("available_models") or []
entries.append( entries.append(
_build_named_catalog_entry( _build_named_catalog_entry(
prefix="autoselect", kind="autoselect",
scope=scope, scope=scope,
owner_id=owner_id, owner_id=owner_id,
source_id=autoselect_id,
target_id=autoselect_id, target_id=autoselect_id,
label=config_data.get("model_name") or autoselect_id, label=config_data.get("model_name") or autoselect_id,
description=config_data.get("description"), description=config_data.get("description"),
......
...@@ -275,12 +275,12 @@ def test_build_studio_catalog_reuses_catalog_entry_contract_for_non_provider_res ...@@ -275,12 +275,12 @@ def test_build_studio_catalog_reuses_catalog_entry_contract_for_non_provider_res
rotation_entry = next(entry for entry in catalog["entries"] if entry["kind"] == "rotation") rotation_entry = next(entry for entry in catalog["entries"] if entry["kind"] == "rotation")
autoselect_entry = next(entry for entry in catalog["entries"] if entry["kind"] == "autoselect") autoselect_entry = next(entry for entry in catalog["entries"] if entry["kind"] == "autoselect")
assert rotation_entry["source_id"] == "rotation" assert rotation_entry["source_id"] == "team-default"
assert rotation_entry["target_id"] == "team-default" assert rotation_entry["target_id"] == "team-default"
assert rotation_entry["id"] == "rotation/rotation/team-default" assert rotation_entry["id"] == "rotation/team-default"
assert autoselect_entry["source_id"] == "autoselect" assert autoselect_entry["source_id"] == "writer"
assert autoselect_entry["target_id"] == "writer" assert autoselect_entry["target_id"] == "writer"
assert autoselect_entry["id"] == "autoselect/autoselect/writer" assert autoselect_entry["id"] == "autoselect/writer"
def test_build_studio_catalog_uses_user_owned_resources_for_user_scope(): def test_build_studio_catalog_uses_user_owned_resources_for_user_scope():
...@@ -322,8 +322,8 @@ def test_build_studio_catalog_uses_user_owned_resources_for_user_scope(): ...@@ -322,8 +322,8 @@ def test_build_studio_catalog_uses_user_owned_resources_for_user_scope():
assert all(entry["owner_scope"] == "user" for entry in catalog["entries"]) assert all(entry["owner_scope"] == "user" for entry in catalog["entries"])
assert {entry["id"] for entry in catalog["entries"]} == { assert {entry["id"] for entry in catalog["entries"]} == {
"provider/local-openai/gpt-4o-mini", "provider/local-openai/gpt-4o-mini",
"rotation/rotation/my-rotation", "rotation/my-rotation",
"autoselect/autoselect/my-autoselect", "autoselect/my-autoselect",
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment