qoder and qoder-cn join retiredBuiltins, as Zed did in c0605abc2. @magpie-community/opencode-qoder-auth serves both, moved or not. Removed (built-in only): - gateway: the Qoder dispatch in gateway.go and gateway/qoder.go (the translator), with its tests (qoder_test, qoder_busy_test, qoder_cn_test). - provider: qoder_usage.go; the Accounts() loop, builtinLogins case and loginQuota branch, the Logins/side-list/switch/forget cases, SetLoginOn and alsoOn, the sign-in case, the subscription_usage fetch, and qoder in asksOwnBackend; qoderLogins(); the built-in tests (qoder_test, qoder_cn_test, qoder_free_test). - internal/qoder: codec, cosy, models, oauth, usage, userinfo, ids, store and their tests. Kept, and why: - migrate_qoder.go (the mover) and the legacy qoder.json migration it reaches through qoderLoginsOf. It now reads a pair with qoderSaved. - qoder_checkin.go: the check-in walks plugin accounts (heldPlugins). - internal/qoder/endpoints.go: the provider keys, Site/SiteOf, the Credential the mover reads and NewMachineID, with the notice. - The PLUGIN-SERVED notice in provider/qoder.go and internal/qoder. - gateway's relayStatus/retryAfterOn, which commandcode.go uses, moved to relay_status.go; the tests' qoderRoundTrip is now roundTripFunc (roundtrip_test.go), no change in meaning. Tests changed in meaning: - TestOwnStoreSignInAgainDropsTheReading lost its qoder case. - New TestQoderLegacyFileMoves: a legacy qoder.json moves through the mover and is removed. Red when migrateQoder is skipped (tried by hand). Run (machine load ~300, so narrow by request): - gofmt -l internal: empty - go vet -tags nogui ./...; GOOS=linux and GOOS=windows the same: clean - go test -tags nogui -count=1 -timeout 45m -run 'Qoder|qoder|Migrat|migrat|Mover|Moved|Retired|SignIn|AsksOwnBackend|Plugin|Afresh|Checkin' ./internal/provider ./internal/gateway ./internal/cli ./internal/gui ./internal/qoder provider ok 114s, gateway ok 201s, cli ok 18s, gui ok 12s, qoder no tests Not run: the whole packages, the full suite, the GUI node suite.
57 lines
2.7 KiB
Go
57 lines
2.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #2379 (jiz4oh): OpenCode's fast variant of a Codex account's GPT model
|
|
// reaches the ChatGPT backend as Codex's /fast asks it, service_tier
|
|
// "priority", beside the variant's reasoning effort. OpenCode 2 sends the
|
|
// tier from the variant's extraBody, OpenCode 1 sends both of the
|
|
// variant's options as they are, extraBody a field of its own: that one
|
|
// never reaches the backend. A variant that isn't fast asks no tier.
|
|
func TestOpenCodeFastVariantReachesCodex(t *testing.T) {
|
|
codexSignedIn(t)
|
|
d := daybreak(t)
|
|
// at chatgpt.com, the one host buildResponses sends Codex's tiers to,
|
|
// reaching the fake backend
|
|
to, _ := url.Parse(provider.CodexBase)
|
|
provider.CodexBase = "https://chatgpt.com/backend-api/codex"
|
|
s := New()
|
|
s.client = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
|
r.URL.Scheme, r.URL.Host = to.Scheme, to.Host
|
|
return http.DefaultTransport.RoundTrip(r)
|
|
})}
|
|
const msgs = `"messages":[{"role":"user","content":"Respond with OK."}]`
|
|
for _, c := range []struct{ name, body string }{
|
|
{"OpenCode 2, streamed", `{"model":"codex/gpt-daybreak-blue-latest","stream":true,` + msgs + `,"reasoning_effort":"medium","service_tier":"priority"}`},
|
|
{"OpenCode 2, whole", `{"model":"codex/gpt-daybreak-blue-latest",` + msgs + `,"reasoning_effort":"medium","service_tier":"priority"}`},
|
|
{"OpenCode 1, streamed", `{"model":"codex/gpt-daybreak-blue-latest","stream":true,` + msgs + `,"reasoning_effort":"medium","service_tier":"priority","extraBody":{"service_tier":"priority"}}`},
|
|
{"OpenCode 1, whole", `{"model":"codex/gpt-daybreak-blue-latest",` + msgs + `,"reasoning_effort":"medium","service_tier":"priority","extraBody":{"service_tier":"priority"}}`},
|
|
} {
|
|
r := postFrom(t, s, "opencode", "/v1/chat/completions", c.body)
|
|
if r.Tier != "priority" {
|
|
t.Errorf("%s: the route says tier %q was asked", c.name, r.Tier)
|
|
}
|
|
b := d.last(t)
|
|
if got := gjson.GetBytes(b, "service_tier").String(); got != "priority" {
|
|
t.Errorf("%s: the backend got service_tier %q in %s", c.name, got, b)
|
|
}
|
|
if got := gjson.GetBytes(b, "reasoning.effort").String(); got != "medium" {
|
|
t.Errorf("%s: the backend got effort %q in %s", c.name, got, b)
|
|
}
|
|
if gjson.GetBytes(b, "extraBody").Exists() {
|
|
t.Errorf("%s: extraBody reached the backend: %s", c.name, b)
|
|
}
|
|
}
|
|
postFrom(t, s, "opencode", "/v1/chat/completions", `{"model":"codex/gpt-daybreak-blue-latest",`+msgs+`,"reasoning_effort":"medium"}`)
|
|
if b := d.last(t); gjson.GetBytes(b, "service_tier").Exists() {
|
|
t.Errorf("a variant that isn't fast asked a tier: %s", b)
|
|
}
|
|
}
|