Files
magpie/internal/agent/codex_image_tool_test.go
yetone 72ca3d593b codex: magpie as Codex's provider keeps the Codex app's ChatGPT account while it has room, so its Work chats and projects stay
Qyburn3 on X: with magpie taking Codex over, the Codex app's "Work"
sessions don't load while the model still answers; turned off, they
come back.

Cause: [model_providers.magpie] had no requires_openai_auth, so Codex's
app-server answers account/read and getAuthStatus with no account and no
token whenever magpie is Codex's provider (magpie API, or the codex.out
takeover). ChatGPT.app 26.1021 then switches to an identity of no
account: onboarding again with no name, ChatGPT mode's projects and
chats ("Work") empty, no avatar, no Chrome control (#1824).

Now putProvider writes requires_openai_auth = true while Codex has a
ChatGPT sign-in with room (openaiAuth: codexChatGPTKnown and not
codexUsedUp), and takes it out otherwise:
- API key alone: left out. With it Codex drops image_gen (captured: 11
  tools without, 10 with), and there is no account to keep.
- No sign-in: left out (the app would ask for a sign-in).
- A sign-in the Codex app holds (codex.out, or magpie API while used
  up): left out, since the app's composer gate (authMethod chatgpt +
  allowed false, #540) would grey Send for magpie's models again. The
  takeover's note now names "its ChatGPT chats and projects" among what
  is off till the reset, beside Keep on ChatGPT.
- An unknown sign-in read leaves the table as it is.
Sync rewrites the key on any table that disagrees (authStale), an older
magpie's included, and the key joins codexAppRoute, so the Codex app's
app-server is restarted onto its account with nothing for the user to
do. The magpie API note no longer says Chrome control needs ChatGPT (en,
zh, zh-TW, ja, de); agent-wiring.md says why.

Real app (mote, ChatGPT.app 26.1021 with its codex 0.164.0-alpha.11,
sandbox CODEX_HOME, copied real ChatGPT auth, auth.json unchanged after):
- native config: the account's projects and recent chats listed.
- magpie table without the key: onboarding, "ChatGPT Work" with no
  projects, no chats. app-server: account null, authMethod null.
- magpie table with requires_openai_auth = true (the keys this commit
  writes): every project and chat back; account/read chatgpt pro,
  getAuthStatus authMethod chatgpt with a token.
- Model requests to a capturing server, with and without the key:
  Bearer is magpie's experimental_bearer_token, no ChatGPT-Account-ID,
  15 tools both ways with a ChatGPT sign-in (image_gen kept).

Tests: TestCodexMagpieProviderKeepsChatGPTAccount (ChatGPT + magpie API,
used up and back; taken over and the reset; an older magpie's table from
live config bytes; API key and no sign-in, fresh and after ChatGPT) and
TestCodexAppRouteFollowsOpenAIAuth. Broken by hand: on the old codex.go
5 of 7 subtests red; without the Sync re-derive 3 red; with the key kept
while used up 2 red; agents.go without the route key, the route test red.

Run (mote-run, at this tree on origin/main 157d575c3; the build and the
agent run again after the rebase onto e5e2aa58e, ok; 5a85a9836 after it touches redact only,
no agent
or GUI file, ok): gofmt -l clean;
go build ./...; go vet linux (-tags nogui) and windows ./..., darwin
./internal/agent; go test -tags nogui -run 'Codex|Agents|Sync|Disconnect|Route'
./internal/agent ok; GUI codex-signin-always, codex-app-out, i18n-keys
and the i18n files, Chromium and WebKit, 96/96.
Not run before the push: the full go test ./... (mote had three other
sessions' full suites at load ~100); it runs after, and any red gets an
issue. Not tried: the used-up case on the real app with the key (the
composer gate is from #540's reading of 26.1013), Windows and Linux
Codex apps.
2026-10-29 01:18:59 +08:00

40 lines
1.6 KiB
Go

package agent
import (
"strings"
"testing"
)
// Codex gives the model its built-in image tool (image_gen.imagegen) only to
// a provider it reads as the OpenAI actor: one that does not require OpenAI
// auth but carries x-openai-actor-authorization
// (ModelProviderInfo::uses_openai_actor_authorization). So magpie's own
// provider table must carry that header and must not require OpenAI auth, or
// a Codex on magpie never has the tool at all and cannot draw through a Codex
// backend (sub2api's).
func TestCodexMagpieProviderCarriesActorAuthorization(t *testing.T) {
home, read := codexHome(t, `{"OPENAI_API_KEY":"sk-relay"}`,
"model = \"gpt-5.5\"\nmodel_provider = \"relay\"\n\n[model_providers.relay]\nname = \"relay\"\nbase_url = \"https://relay.example/v1\"\nwire_api = \"responses\"\n")
cx := codex(home)
if err := cx.Fields[0].Set("fake/m1"); err != nil {
t.Fatal(err)
}
cfg := read()
if !strings.Contains(cfg, "[model_providers.magpie]") {
t.Fatalf("no magpie provider table:\n%s", cfg)
}
if !strings.Contains(cfg, `"x-openai-actor-authorization" = "magpie"`) {
t.Fatalf("magpie provider table carries no actor-authorization header:\n%s", cfg)
}
// uses_openai_actor_authorization() also requires !requires_openai_auth:
// the header beside that key would turn the flag off again. A ChatGPT
// sign-in gets the key (openaiAuth) and keeps the image tool on its
// account; an API key, as here, has no account to keep.
if strings.Contains(cfg, "requires_openai_auth") {
t.Fatalf("magpie provider table requires OpenAI auth, hiding the actor header:\n%s", cfg)
}
if c := cx.Check(); c != "" {
t.Fatal(c)
}
}