Files
magpie/internal/gateway/antigravity_enum_blank_test.go
T
yetone 2d04fe73dd gateway: Antigravity's tool enums go without a blank value (#5235)
Google's Schema proto refuses a blank enum value, so a tool whose enum
holds "" turned every tool-bearing Antigravity turn away with 400
"enum[N]: cannot be empty". Portainer's StatusMessage.operationStatus
(enum ["processing","warning","error",""] under allOf) did it for
ikunbots' dsh session, reported on X.

plainSchema now leaves blank (whitespace-only) values out of a string
enum, and leaves the enum out when nothing else is in it; a blank const
gives no enum. A number in an enum still drops it whole, as before.

Run (mote): go test ./internal/gateway -run
'PlainSchema|Antigravity|CodeAssist|GeminiSchema' ok;
TestPlainSchemaDropsBlankEnumValues red on origin/main's codeassist.go
(the "" went through), green with this. gofmt clean.
Not tried: a real Antigravity request with the reporter's Portainer
tools. Not changed: Vertex's chat path (geminiSchemaShapes), which
relays JSON Schema enums as they come; whether Vertex refuses a blank
value too is unknown.
2026-11-05 00:37:01 +08:00

43 lines
1.7 KiB
Go

package gateway
import (
"encoding/json"
"strings"
"testing"
)
// Antigravity refuses an enum with a blank value ("enum[3]: cannot be
// empty", #5235): Portainer's StatusMessage.operationStatus, as the
// reporter's dsh session recorded it, under allOf, goes without its "".
// An enum of blanks alone, and a blank const, go without their enum; a
// number in an enum still drops it whole.
func TestPlainSchemaDropsBlankEnumValues(t *testing.T) {
in := `{"type":"object","properties":{"StatusMessage":{"type":"object","properties":{"operationStatus":{"allOf":[{"enum":["processing","warning","error",""],"type":"string","x-enum-varnames":["EndpointOperationStatusProcessing","EndpointOperationStatusWarning","EndpointOperationStatusError","EndpointOperationStatusDone"]}],"description":"'', 'error', 'processing'","example":"error"}}},` +
`"blank":{"type":"string","enum":[""," "]},"c":{"type":"string","const":""},"n":{"enum":["a",1,""]}}}`
var got struct {
Properties map[string]struct {
Enum []any `json:"enum"`
Properties map[string]struct {
Type string `json:"type"`
Enum []any `json:"enum"`
} `json:"properties"`
} `json:"properties"`
}
out := plainSchema(json.RawMessage(in))
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("%v: %s", err, out)
}
op := got.Properties["StatusMessage"].Properties["operationStatus"]
if op.Type != "string" || len(op.Enum) != 3 || op.Enum[0] != "processing" || op.Enum[2] != "error" {
t.Fatalf("operationStatus: %+v in %s", op, out)
}
for _, k := range []string{"blank", "c", "n"} {
if e := got.Properties[k].Enum; e != nil {
t.Fatalf("%s kept enum %v: %s", k, e, out)
}
}
if strings.Contains(string(out), `""`) {
t.Fatalf("a blank value went: %s", out)
}
}