Files
magpie/internal/provider/codex_usedup_test.go
T
yetone 27f0e4ebdd codex: when the ChatGPT account runs out of its allowance after a magpie model was picked, magpie becomes Codex's provider, and goes back beside the sign-in when the allowance is back (#540: once the Codex 5-hour/weekly quota is used up, a third-party model through magpie sends nothing in new or old sessions; Dazzle-sys: the session was on the magpie model all along, the quota went elsewhere) — the Codex desktop app refuses to send for a ChatGPT account that is out of its allowance before any request is made, whichever model the turn is on, so a magpie model beside the sign-in (openai_base_url, ChatGPT mode) is blocked with it; Codex's open-source core and TUI only report a usage limit after a response, the block is the app's, keyed on the account. bd5bf422 made magpie the provider (model_provider = "magpie", model_catalog_json; the app-server's getAuthStatus then answers requires_openai_auth false, the app's API state) only when a model was picked while the account was already out, so an allowance running out later left Codex as it was. KeepOnAnAccountWithRoom now also looks, every 5 minutes, whether the active Codex account is out (CodexUsedUp, now read through LoginUsage's cache, fetched at most once a minute, as the agents' sync asks it on every catalog sync) and tells the agents' sync when that changes (noteCodexUsedUp → catalog.Touched); Codex's Sync then sets the magpie model again, which wires it as the provider while the account is out, marked codex.out in the stash, and puts it back beside the sign-in once the allowance is back, only where it was moved for that (a provider asked for with sign-in "api" stays). Threads started on Codex's own provider and reopened may still be held by the app; the Codex app may need a restart to take the new config. agent's TestMain stubs codexUsedUp so no test asks OpenAI. TestCodexRunsOutAfterPick (ChatGPT mode, then out: provider; out again: stays; back: beside the sign-in; api stays) fails without the change; TestNoteCodexUsedUp checks only a change is told. No request was made to OpenAI. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-02 16:48:26 +08:00

28 lines
765 B
Go

package provider
import (
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// The ChatGPT account running out of its allowance, or getting it back, is
// told to the agents' sync (#540), which makes magpie Codex's provider while
// the account is out; the same state again is not.
func TestNoteCodexUsedUp(t *testing.T) {
told := 0
was := catalog.Changed
catalog.Changed = func() { told++ }
t.Cleanup(func() { catalog.Changed = was; codexWasUsedUp.Store(false) })
codexWasUsedUp.Store(false)
for i, c := range []struct {
now bool
told int
}{{false, 0}, {true, 1}, {true, 1}, {false, 2}, {false, 2}} {
noteCodexUsedUp(c.now)
if told != c.told {
t.Fatalf("step %d (used up %v): told %d times, want %d", i, c.now, told, c.told)
}
}
}