On a Coding Plan with a key Zhipu refuses, Test showed OpenAI 401 and Anthropic 401 but Responses (https://open.bigmodel.cn/api/v1) a green check, and the 5h/weekly windows showed only "Allowance unavailable". Cause: /api/v1 (Zhipu's real Responses endpoint, docs.bigmodel.cn coding-plan/tool/codex) and /api/monitor answer a refused key HTTP 200 with {"code":1000,"msg":"身份验证失败。","success":false}. probe (endpoint Test, model tests, Detect) took any 2xx as ok, and the gateway handed the 200 to Codex as a reply, so no failover and no rest. - provider.ZhipuEnveloped: a 2xx JSON, non-stream, unencoded reply from open.bigmodel.cn or api.z.ai whose body is the envelope with success:false becomes {"error":{...}} under the status Zhipu's code table gives (1000-1005 401, 1113/13xx 429, 1220 403, 121x/1261/1301 400, else 502). Anything else passes through unchanged (64KB cap, body restored). Applied in probe and in the gateway's forwardOnce. - planquota: a refused key (envelope 1000-1005 or HTTP 401 from a Zhipu/Z.ai host) says "Zhipu didn't take this key (...): it has expired, was deleted, or is mistyped; paste a current one from <keys page>", and skips the team retry. The card shows it in en, zh, zh-TW, ja, de. - docs: providers-accounts and gateway-routing rows. Run at this head (before rebase, base95e7c6bcc): - go test -timeout 20m ./internal/gateway ./internal/provider: ok (343s, 93s). New: TestZhipuResponsesRefusalNotGreen, TestZhipuEnveloped, TestZhipuRefusedKeyCard, TestZhipuResponsesRefusalIsRefusal (zhipu and zai presets). - Full go test ./...: every package ok except internal/gateway, which hit the default 10m timeout while the full GUI suite and another session's GUI tests ran beside it; alone with -timeout 20m it passed. - gofmt -l clean; GOOS=linux and GOOS=windows go vet on provider and gateway clean. - GUI: glm-quota-error (new) and opencode-go-quota-error 20/20 in chromium and webkit, five languages. The full GUI suite ran once (under load) and exited 1; each of its 16 red files was rerun alone here and on an origin/main03eb0633acopy of internal/gui: 10 pass on both; quota-count-wrap (1), quota-name-translated (1), refusal-retries-setting (2), usage-agents-hide (22), usage-fold (2) fail the same counts on both; routing-held-member fails 1 here, 2 on main. None touches quotaError's GLM line. Broken by hand: ZhipuEnveloped returning res unchanged, and zhipuEnvelope returning ok=false, turned the provider tests red; reverting the gateway line turned TestZhipuResponsesRefusalIsRefusal red; breaking the GLM regex in app.js turned glm-quota-error 0/5 in chromium. All restored. Not tried: no real Zhipu or Z.ai key, valid or expired. The refusal bytes are from a curl of /api/v1 with a bad key; the reporter's "令牌已过期或验证不正确" code is unknown (assumed 1000-1005 or HTTP 401, both handled). A valid key's quota read with a real plan was not run.
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package gateway
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// zhipuResponses plays the GLM Coding Plan's Responses API at /api/v1: a
|
|
// key it refuses is answered 200 in the platform's envelope, as
|
|
// open.bigmodel.cn answered one on 2026-10-15.
|
|
type zhipuResponses struct{}
|
|
|
|
func (zhipuResponses) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
if r.Body != nil {
|
|
io.Copy(io.Discard, r.Body)
|
|
}
|
|
body := `{"code":1000,"msg":"身份验证失败。","success":false}`
|
|
if r.Header.Get("Authorization") == "Bearer good" {
|
|
body = `{"id":"resp_1","object":"response","status":"completed","model":"glm-5.1","output":[{"type":"message","id":"m1","role":"assistant","content":[{"type":"output_text","text":"pong"}]}],"usage":{"input_tokens":3,"output_tokens":1,"total_tokens":4}}`
|
|
}
|
|
return &http.Response{StatusCode: 200, Status: "200 OK", Header: http.Header{"Content-Type": {"application/json"}},
|
|
Body: io.NopCloser(strings.NewReader(body)), Request: r}, nil
|
|
}
|
|
|
|
// Codex on a GLM Coding Plan whose key Zhipu refuses (@xanahopper on X)
|
|
// is told the key was refused, 401 with Zhipu's words, not handed the
|
|
// envelope as a 200 reply; a key Zhipu takes is answered as before.
|
|
func TestZhipuResponsesRefusalIsRefusal(t *testing.T) {
|
|
for _, tc := range []struct{ preset, host string }{
|
|
{"zhipu", "open.bigmodel.cn"},
|
|
{"zai", "api.z.ai"},
|
|
} {
|
|
t.Run(tc.preset, func(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
for _, id := range []string{"bad", "good"} {
|
|
p, err := provider.FromPreset(tc.preset)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p.ID, p.Name, p.Key, p.Models = tc.preset+"-"+id, id, id, []string{"glm-5.1"}
|
|
p.Chat, p.Anthropic, p.Responses = "", "", "https://"+tc.host+"/api/v1"
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
s := New()
|
|
s.client = &http.Client{Transport: zhipuResponses{}}
|
|
codex := func(id string) *httptest.ResponseRecorder {
|
|
rec := httptest.NewRecorder()
|
|
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/responses",
|
|
strings.NewReader(`{"model":"`+tc.preset+"-"+id+`/glm-5.1","input":"Say pong","stream":false}`)))
|
|
return rec
|
|
}
|
|
if rec := codex("bad"); rec.Code != http.StatusUnauthorized || !strings.Contains(rec.Body.String(), "身份验证失败") {
|
|
t.Errorf("refused key: %d %s", rec.Code, rec.Body)
|
|
}
|
|
if rec := codex("good"); rec.Code != 200 || !strings.Contains(rec.Body.String(), "pong") {
|
|
t.Errorf("a key Zhipu takes: %d %s", rec.Code, rec.Body)
|
|
}
|
|
})
|
|
}
|
|
}
|