Files
magpie/internal/gateway/gemini_view_image_test.go
T
yetone 7b5c069c3a gateway: Vertex AI gets a tool's image in a user turn of its own, no "Requests ending with a model turn" after view_image (Voo_Ler on X)
What the user saw: Codex on Google Vertex AI stopped right after "Viewed an
image" with "Requests ending with a model turn are not supported".

Why: Codex's view_image answers with a function_call_output whose output is
[input_text, input_image] (as ~/.codex/sessions rollouts record it). The
Gemini build kept a tool's images in the same user turn as its
functionResponse. Vertex AI answers a response turn mixing in anything else
with that 400 although the last role is user (#1533 showed it for text, and
ce11b1801 split the text out but left images with the response).

What changed: buildCodeAssistSent, for Vertex AI, puts a tool's images in a
user turn after the responses (with what the user said, if anything). The
image and the words are kept. AI Studio, Code Assist (Gemini CLI,
Antigravity) are unchanged: Gemini CLI itself sends a read image beside the
response, and no refusal is known there. Chat and Messages clients reach the
same builder, so they are covered; the image-under-assistant and trailing
model turn cases already end with a user turn (continueText).

Tests: gemini_view_image_test.go posts Codex's real view_image shape (array
output, image-only output, image in a following user message, image in a
model-role message) to /v1/responses against a fake Vertex that refuses as
the real one does; vertexTurnsAway now also refuses an image beside a
response. Reverting codeassist.go makes it fail with the reporter's exact
message, and TestGeminiToolResponseTurnHoldsNoText fails too.

Run: go test ./internal/gateway ./internal/provider on mote, gofmt -l, go vet
-tags nogui for darwin, linux and windows.
Not tried against real Vertex AI: no Vertex credentials on this machine.
2026-11-12 07:50:22 +08:00

37 lines
1.9 KiB
Go

package gateway
import (
"encoding/json"
"net/http"
"strings"
"testing"
)
func TestVertexViewImageTurn(t *testing.T) {
v := &vertexUp{}
v.reply = vertexTurnsAway
s := vertexServe(t, v, vertexLevels)
const img = "data:image/png;base64,iVBORw0KGgo="
hist := `{"type":"message","role":"user","content":[{"type":"input_text","text":"look at the screenshot"}]},` +
`{"type":"function_call","name":"view_image","arguments":"{\"path\":\"/tmp/a.png\"}","call_id":"call_1"},`
for name, tail := range map[string]string{
"array": `{"type":"function_call_output","call_id":"call_1","output":[{"type":"input_text","text":"ok"},{"type":"input_image","image_url":"` + img + `","detail":"high"}]}`,
"imageonly": `{"type":"function_call_output","call_id":"call_1","output":[{"type":"input_image","image_url":"` + img + `"}]}`,
"separate": `{"type":"function_call_output","call_id":"call_1","output":"ok"},{"type":"message","role":"user","content":[{"type":"input_image","image_url":"` + img + `"}]}`,
"separate-asst": `{"type":"function_call_output","call_id":"call_1","output":"ok"},{"type":"message","role":"assistant","content":[{"type":"input_image","image_url":"` + img + `"}]}`,
} {
rec := codexPostTo(s, `{"model":"google-vertex/gemini-3.8-flash","instructions":"You are Codex.","stream":true,"tools":[{"type":"function","name":"view_image","parameters":{"type":"object","properties":{}}}],"input":[`+hist+tail+`]}`)
if rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "model turn") {
t.Errorf("%s: %d %s", name, rec.Code, rec.Body.String())
continue
}
b, _ := json.Marshal(v.last(t).body["contents"])
if !strings.Contains(string(b), "iVBORw0KGgo=") {
t.Errorf("%s: the image was lost: %s", name, b)
}
if role, _ := lastTurn(t, v.last(t).body["contents"]); role != "user" {
t.Errorf("%s: ends with %s: %s", name, role, b)
}
}
}