style(video_endpoints): drop explanatory comments per repo convention

This commit is contained in:
Devin AI 2026-07-17 19:22:09 +00:00
parent 0b68e0b6ca
commit 4af23ecb6c
2 changed files with 17 additions and 72 deletions

View file

@ -59,17 +59,6 @@ def encode_character_id_in_response(response: Any, custom_llm_provider: str, mod
def reencode_video_id_with_model_id(response: Any, custom_llm_provider: str | None, model_id: str | None) -> Any:
"""
Re-encode a returned video id so it carries the router-selected deployment id.
The provider transformation layer encodes the client-facing model/group name
into the video id because it runs before the router attaches the deployment id
to ``_hidden_params``. That is enough for single-deployment groups, but for a
group backed by several deployments the status/content round-trip decodes the
group name and re-routes through load balancing instead of pinning to the
deployment that created the job. Preferring ``model_id`` (the deployment id)
here keeps the follow-up calls on the deployment that owns the video
"""
if not model_id:
return response

View file

@ -63,9 +63,7 @@ AZURE_VIDEO_ID = encode_video_id_with_provider("video_orig123", "azure", VIDEO_M
# A real model-encoded character id: decodes to provider "azure", VIDEO_MODEL_ID,
# original character id "char_orig". Distinct from the video id so a test cannot
# pass by reusing the wrong constant.
AZURE_CHARACTER_ID = encode_character_id_with_provider(
"char_orig", "azure", VIDEO_MODEL_ID
)
AZURE_CHARACTER_ID = encode_character_id_with_provider("char_orig", "azure", VIDEO_MODEL_ID)
RESOLVED_MODELS: Dict[str, str] = {VIDEO_MODEL_ID: "azure-sora"}
# Sentinel propagated by base_process for the passthrough endpoints.
@ -116,9 +114,7 @@ def harness():
logging = MagicMock(spec=ProxyLogging)
router = MagicMock(spec=Router)
resolve_model = MagicMock(
side_effect=lambda model_id: RESOLVED_MODELS.get(model_id)
)
resolve_model = MagicMock(side_effect=lambda model_id: RESOLVED_MODELS.get(model_id))
router.resolve_model_name_from_model_id = resolve_model
read_body = AsyncMock(return_value={})
@ -145,9 +141,7 @@ def harness():
)
)
stack.enter_context(patch.object(endpoints, "_read_request_body", read_body))
stack.enter_context(
patch.object(endpoints, "batch_to_bytesio", batch_to_bytesio)
)
stack.enter_context(patch.object(endpoints, "batch_to_bytesio", batch_to_bytesio))
stack.enter_context(
patch.object(
endpoints,
@ -173,9 +167,7 @@ def harness():
stack.enter_context(patch.object(proxy_server, "proxy_logging_obj", logging))
stack.enter_context(patch.object(proxy_server, "general_settings", {}))
stack.enter_context(patch.object(proxy_server, "proxy_config", MagicMock()))
stack.enter_context(
patch.object(proxy_server, "select_data_generator", MagicMock())
)
stack.enter_context(patch.object(proxy_server, "select_data_generator", MagicMock()))
stack.enter_context(patch.object(proxy_server, "user_model", None))
stack.enter_context(patch.object(proxy_server, "user_temperature", None))
stack.enter_context(patch.object(proxy_server, "user_request_timeout", None))
@ -205,9 +197,7 @@ def _user() -> UserAPIKeyAuth:
# =========================================================================== #
async def call_generation(
harness: Harness, *, body: Dict[str, Any], input_reference=None
):
async def call_generation(harness: Harness, *, body: Dict[str, Any], input_reference=None):
harness.read_body.return_value = body
return await endpoints.video_generation(
request=FakeRequest(),
@ -335,10 +325,7 @@ async def test_content__wraps_raw_bytes_in_response(harness):
assert isinstance(resp, Response)
assert resp.body == b"VIDEOBYTES"
assert resp.media_type == "video/mp4"
assert (
resp.headers["content-disposition"]
== "attachment; filename=video_video_plain.mp4"
)
assert resp.headers["content-disposition"] == "attachment; filename=video_video_plain.mp4"
@pytest.mark.asyncio
@ -372,9 +359,7 @@ async def test_content__model_encoded_id(harness):
# =========================================================================== #
async def call_edit(
harness: Harness, *, body: Dict[str, Any], headers=None, query=None
):
async def call_edit(harness: Harness, *, body: Dict[str, Any], headers=None, query=None):
return await endpoints.video_edit(
request=FakeRequest(headers=headers, query=query, raw_body=orjson.dumps(body)),
fastapi_response=Response(),
@ -384,9 +369,7 @@ async def call_edit(
@pytest.mark.asyncio
async def test_edit__extracts_nested_video_id_full_contract(harness):
resp = await call_edit(
harness, body={"prompt": "brighter", "video": {"id": AZURE_VIDEO_ID}}
)
resp = await call_edit(harness, body={"prompt": "brighter", "video": {"id": AZURE_VIDEO_ID}})
assert resp is SENTINEL
assert harness.route_type() == "avideo_edit"
@ -471,9 +454,7 @@ async def test_list__provider_from_header(harness):
# =========================================================================== #
async def call_remix(
harness: Harness, video_id: str, *, body, headers=None, query=None
):
async def call_remix(harness: Harness, video_id: str, *, body, headers=None, query=None):
return await endpoints.video_remix(
video_id=video_id,
request=FakeRequest(headers=headers, query=query, raw_body=orjson.dumps(body)),
@ -570,9 +551,7 @@ async def test_create_character__target_model_sets_model_and_encodes_id(harness)
assert data["model"] == "azure-sora-model"
assert data["custom_llm_provider"] == "azure"
# response id re-encoded with the resolved provider + model for the round-trip.
assert resp["id"] == encode_character_id_with_provider(
"char_raw", "azure", "azure-sora-model"
)
assert resp["id"] == encode_character_id_with_provider("char_raw", "azure", "azure-sora-model")
# =========================================================================== #
@ -580,9 +559,7 @@ async def test_create_character__target_model_sets_model_and_encodes_id(harness)
# =========================================================================== #
async def call_get_character(
harness: Harness, character_id: str, *, headers=None, query=None
):
async def call_get_character(harness: Harness, character_id: str, *, headers=None, query=None):
return await endpoints.video_get_character(
character_id=character_id,
request=FakeRequest(headers=headers, query=query),
@ -606,9 +583,7 @@ async def test_get_character__encoded_id_full_contract(harness):
"model": "azure-sora",
}
# response id re-encoded for the client round-trip.
assert resp["id"] == encode_character_id_with_provider(
"char_raw2", "azure", VIDEO_MODEL_ID
)
assert resp["id"] == encode_character_id_with_provider("char_raw2", "azure", VIDEO_MODEL_ID)
@pytest.mark.asyncio
@ -641,9 +616,7 @@ async def call_extension(harness: Harness, *, body, headers=None, query=None):
@pytest.mark.asyncio
async def test_extension__extracts_nested_video_id_full_contract(harness):
resp = await call_extension(
harness, body={"prompt": "continue", "video": {"id": AZURE_VIDEO_ID}}
)
resp = await call_extension(harness, body={"prompt": "continue", "video": {"id": AZURE_VIDEO_ID}})
assert resp is SENTINEL
assert harness.route_type() == "avideo_extension"
@ -658,18 +631,11 @@ async def test_extension__extracts_nested_video_id_full_contract(harness):
# =========================================================================== #
# Deployment pinning: the returned video id must carry the router-selected #
# deployment id, not the client-facing model group name, so status/content #
# round-trips pin to the deployment that owns the job (issue #33740). #
# deployment id, not the client-facing model group name (issue #33740). #
# =========================================================================== #
# What a provider transformation produces before the router attaches the
# deployment id: the client-facing group name ("sora-2") sits in the model_id
# slot of the encoded video id.
GROUP_ENCODED_ID = encode_video_id_with_provider("video_raw", "azure", "sora-2")
# What the round-trip needs instead: the same raw id pinned to the deployment.
DEPLOYMENT_ENCODED_ID = encode_video_id_with_provider(
"video_raw", "azure", VIDEO_MODEL_ID
)
DEPLOYMENT_ENCODED_ID = encode_video_id_with_provider("video_raw", "azure", VIDEO_MODEL_ID)
@pytest.mark.asyncio
@ -681,16 +647,11 @@ async def test_generation__repins_video_id_to_deployment_from_hidden_params(harn
resp = await call_generation(harness, body={"model": "sora-2", "prompt": "x"})
# the group name in the id is replaced by the deployment id the router picked.
assert resp["id"] == DEPLOYMENT_ENCODED_ID
@pytest.mark.asyncio
async def test_generation__repins_from_litellm_metadata_model_info_id(harness):
"""The reporter's core ask: fall back to litellm_metadata.model_info.id (via
_get_model_id_from_response), never to the client-facing data['model']. Here
_hidden_params carries no model_id, so a data['model'] fallback would re-stamp
the group name; only the metadata lookup yields the deployment id."""
harness.base_process.return_value = {
"id": GROUP_ENCODED_ID,
"_hidden_params": {},
@ -717,7 +678,6 @@ async def test_generation__no_deployment_id_leaves_video_id_untouched(harness):
resp = await call_generation(harness, body={"model": "sora-2", "prompt": "x"})
# nothing to pin to -> the id is left exactly as the transformation made it.
assert resp["id"] == GROUP_ENCODED_ID
@ -753,9 +713,7 @@ async def test_edit__repins_video_id_to_deployment(harness):
"_hidden_params": {"model_id": VIDEO_MODEL_ID, "custom_llm_provider": "azure"},
}
resp = await call_edit(
harness, body={"prompt": "brighter", "video": {"id": AZURE_VIDEO_ID}}
)
resp = await call_edit(harness, body={"prompt": "brighter", "video": {"id": AZURE_VIDEO_ID}})
assert resp["id"] == DEPLOYMENT_ENCODED_ID
@ -767,8 +725,6 @@ async def test_extension__repins_video_id_to_deployment(harness):
"_hidden_params": {"model_id": VIDEO_MODEL_ID, "custom_llm_provider": "azure"},
}
resp = await call_extension(
harness, body={"prompt": "continue", "video": {"id": AZURE_VIDEO_ID}}
)
resp = await call_extension(harness, body={"prompt": "continue", "video": {"id": AZURE_VIDEO_ID}})
assert resp["id"] == DEPLOYMENT_ENCODED_ID