Files
TryWorldandTryWorld2026 8c87a843b5 model-map 0.1.1: a Gemini request's model is mapped, and its reply names it back (#26)
onRequest returned early for ctx.protocol === "gemini", on the grounds that a
Gemini request names its model in the URL and not in the body. magpie puts it
in the body before the middleware runs (gateway.go, serveAgent is called with
withFields(body, {"model": model, "stream": stream})), and reads it from there
to route, so the mapping applied to every API but Gemini: a Gemini client
asking for a mapped name got "magpie knows no model" as a 404.

onEvent and onResponse also never looked at modelVersion, where a Gemini reply
names its model (internal/gateway/member.go lists exactly that path), so the
name a Gemini client read back was the upstream's even when the mapping did
apply.

cases.json's "Gemini's body has no model to map" asserted the old assumption
with a body carrying no model — a body the gateway never sends. It is replaced
by one that carries the model the gateway fills, covering the request, the
stream and a whole reply; a second case keeps the no-model body passing as it
is. The new case fails on 0.1.0 and passes here.

Co-authored-by: TryWorld2026 <tryworld@users.noreply.github.com>
2026-10-05 23:45:07 +08:00

71 lines
4.3 KiB
JSON

[
{ "name": "an exact name is sent as its target",
"options": { "mapping": { "fast": "deepseek-chat" } },
"request": { "model": "fast", "messages": [] },
"expect_request": { "model": "deepseek-chat", "messages": [] } },
{ "name": "New API's flat form",
"options": { "fast": "deepseek-chat" },
"request": { "model": "fast" },
"expect_request": { "model": "deepseek-chat" } },
{ "name": "a name not mapped passes as it is, and so does its reply",
"options": { "mapping": { "fast": "deepseek-chat" } },
"request": { "model": "deepseek-chat" },
"events": [{ "event": "message_start", "data": { "type": "message_start", "message": { "model": "deepseek-chat" } } }] },
{ "name": "chains, and a cycle stops",
"options": { "mapping": { "a": "b", "b": "c", "x": "y", "y": "x" } },
"request": { "model": "a", "n": [{ "model": "x" }] },
"expect_request": { "model": "c", "n": [{ "model": "x" }] } },
{ "name": "a cycle stops where it would repeat",
"options": { "mapping": { "x": "y", "y": "x" } },
"request": { "model": "x" },
"expect_request": { "model": "y" } },
{ "name": "a pattern with a group",
"options": { "mapping": { "/^claude-(.*)$/": "glm-$1" } },
"request": { "model": "claude-4.6" },
"expect_request": { "model": "glm-4.6" } },
{ "name": "Anthropic's stream names the asked model",
"options": { "mapping": { "fast": "deepseek-chat" } },
"request": { "model": "fast", "stream": true },
"expect_request": { "model": "deepseek-chat", "stream": true },
"events": [
{ "event": "message_start", "data": { "type": "message_start", "message": { "id": "m1", "model": "deepseek-chat", "content": [] } } },
{ "event": "content_block_delta", "data": { "type": "content_block_delta", "index": 0, "delta": { "type": "text_delta", "text": "hi" } } }],
"expect_events": [
{ "type": "message_start", "message": { "id": "m1", "model": "fast", "content": [] } },
{ "type": "content_block_delta", "index": 0, "delta": { "type": "text_delta", "text": "hi" } }] },
{ "name": "Chat chunks name the asked model; [DONE] passes",
"ctx": { "protocol": "chat" },
"options": { "mapping": { "fast": "deepseek-chat" } },
"request": { "model": "fast" },
"expect_request": { "model": "deepseek-chat" },
"events": [{ "data": { "id": "c", "model": "deepseek-chat", "choices": [{ "delta": { "content": "hi" } }] } }, { "data": "[DONE]" }],
"expect_events": [{ "id": "c", "model": "fast", "choices": [{ "delta": { "content": "hi" } }] }, "[DONE]"] },
{ "name": "Responses events and a whole reply",
"ctx": { "protocol": "responses" },
"options": { "mapping": { "fast": "gpt-5" } },
"request": { "model": "fast" },
"expect_request": { "model": "gpt-5" },
"events": [{ "event": "response.created", "data": { "type": "response.created", "response": { "model": "gpt-5" } } }],
"expect_events": [{ "type": "response.created", "response": { "model": "fast" } }],
"response": { "id": "r", "model": "gpt-5", "output": [] },
"expect_response": { "id": "r", "model": "fast", "output": [] } },
{ "name": "keep_upstream_name leaves replies alone",
"options": { "mapping": { "fast": "deepseek-chat" }, "keep_upstream_name": true },
"request": { "model": "fast" },
"expect_request": { "model": "deepseek-chat" },
"response": { "model": "deepseek-chat" } },
{ "name": "Gemini's model is in the body the gateway fills, and is mapped",
"ctx": { "protocol": "gemini", "model": "fast" },
"options": { "mapping": { "fast": "x" } },
"request": { "model": "fast", "contents": [] },
"expect_request": { "model": "x", "contents": [] },
"events": [{ "data": { "candidates": [{ "content": { "parts": [{ "text": "hi" }], "role": "model" } }], "modelVersion": "x" } }],
"expect_events": [{ "candidates": [{ "content": { "parts": [{ "text": "hi" }], "role": "model" } }], "modelVersion": "fast" }],
"response": { "candidates": [{ "content": { "parts": [{ "text": "hi" }], "role": "model" } }], "modelVersion": "x" },
"expect_response": { "candidates": [{ "content": { "parts": [{ "text": "hi" }], "role": "model" } }], "modelVersion": "fast" } },
{ "name": "a Gemini request naming no model passes as it is",
"ctx": { "protocol": "gemini", "model": "fast" },
"options": { "mapping": { "fast": "x" } },
"request": { "contents": [] } }
]