silverzhou (Discord): codex-auto-review has been free for a long time,
but magpie still estimates a cost for it. OpenAI's Codex lead
(thsottiaux, "Day 2.1"): "We have made Auto-review free for all users
signed in through a ChatGPT account."
provider.ListPrice now prices codex-auto-review at $0 on the "codex"
provider, the one that holds only ChatGPT sign-ins, unless that sign-in
is on the Free plan: cybercaius measured auto-review spending the Free
allowance, which is why the gateway's freeOnChatGPT already left Free
out. That rule now has one owner, provider.ChatGPTReviewFree, and
freeOnChatGPT calls it. The plan is read from Codex's current sign-in;
an unreadable plan or a Codex signed out since counts as a paid plan
(priceOf's unknown-model branch answers $0 for it too).
Still priced, since nothing says those are free: codex-auto-review sent
with an API key (openai, chatgpt-api), through a relay, or a review
magpie made follow the session's model (the row's served model is that
model). A price the user set for the model wins over the $0.
PricedNameFor names the model itself, so the Requests list no longer
says "priced as gpt-5.6-luna". The usage summary cache key carries the
Codex plan, so a plan change re-prices cached views.
Old rows: prices are applied when the log is read, so every past
codex-auto-review row through a ChatGPT sign-in reads $0 after the
upgrade: Usage's Overview and Requests, the tray, the ledger and key
limits' estimated-cost caps (their in-memory sums are rebuilt at start).
Nothing is rewritten on disk.
Left alone: a Codex window's holds (apiPricer) still count these calls,
filed as #4181. docs/subsystems/providers-accounts.md has the rule.
Run at this tree (rebased on 033b17baf):
- mote-run: TestAutoReviewFreeOnChatGPTSignIn (provider) and
TestAutoReviewFreeOnChatGPT (usage: ledger, Summarize, ledger sum,
NewCoster), the KimiCode, CodexSignInPlan and gateway Review tests: ok.
- Red on the old code: both new tests fail with the code changes taken
out (codex priced at luna, $0.234; summary 0.992 vs 0.758; key limit
0.134).
- Broken by hand: dropping the plan check or the provider check turns
the Free-plan and relay/openai assertions red in both tests.
- go vet on mote, and GOOS=linux and GOOS=windows; gofmt -l clean.
- At the rebased head, mote-run go test ./internal/provider
./internal/usage ./internal/usageapi ./internal/gateway: all ok (gateway 1883s, provider 846s,
usage 158s, usageapi 4s); gofmt -l clean.
- Full suite: a mote run at the pre-rebase head reached two packages (ok)
and then died (exit 144) when the touched-package run re-synced the
same mote copy, at load ~340 with five other full suites; per the owner's
ship-at-once rule it is run again after the push.
Not tried: a real auto-review row (none in ~/.codex/sessions or the
real usage log); a multi-account Codex with mixed plans (the live
sign-in's plan decides); the summary cache's plan key was not broken by
hand.
125 lines
4.9 KiB
Go
125 lines
4.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
func TestAutoReviewUsesSharedCatalogPrice(t *testing.T) {
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Deliberately different prices: the alias must use the catalog, never
|
|
// carry its own rates. Preserve exact-name prices if the catalog adds one.
|
|
write := func(models string) {
|
|
t.Helper()
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{"openai":{"id":"openai","models":{`+models+`}}}`), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
}
|
|
t.Cleanup(catalog.Reset)
|
|
write(`"gpt-5.6-luna":{"id":"gpt-5.6-luna","cost":{"input":3,"output":7,"cache_read":1}}`)
|
|
pr, ok := MakerPrice("codex-auto-review")
|
|
if !ok || pr.Input != 3 || pr.Output != 7 || pr.CacheRead != 1 {
|
|
t.Fatalf("alias did not use shared catalog: %+v, %v", pr, ok)
|
|
}
|
|
if PricedName("codex-auto-review") != "gpt-5.6-luna" {
|
|
t.Fatal("missing price reference")
|
|
}
|
|
write(`"codex-auto-review":{"id":"codex-auto-review","cost":{"input":4,"output":8}}`)
|
|
if pr, ok := MakerPrice("codex-auto-review"); !ok || pr.Input != 4 {
|
|
t.Fatalf("exact-name catalog price lost: %+v, %v", pr, ok)
|
|
}
|
|
if PricedName("codex-auto-review") != "codex-auto-review" {
|
|
t.Fatal("price reference must agree with exact-name catalog price")
|
|
}
|
|
write(`"unrelated":{"id":"unrelated","cost":{"input":1,"output":2}}`)
|
|
if _, ok := MakerPrice("codex-auto-review"); ok {
|
|
t.Fatal("missing catalog price must remain unknown")
|
|
}
|
|
}
|
|
|
|
// OpenAI made Auto-review free for every user signed in through a ChatGPT
|
|
// account (silverzhou on Discord, thsottiaux's "Day 2.1"): Codex's
|
|
// codex-auto-review through the Codex subscription costs nothing in the
|
|
// estimates, but not on a Free plan, where it spends the allowance
|
|
// (cybercaius), nor through anything that isn't a ChatGPT sign-in.
|
|
func TestAutoReviewFreeOnChatGPTSignIn(t *testing.T) {
|
|
home := signIn(t) // a Pro plan
|
|
if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{"openai":{"id":"openai","models":{`+
|
|
`"gpt-5.6-luna":{"id":"gpt-5.6-luna","cost":{"input":3,"output":7,"cache_read":1}}}}}`), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
s := settings.Load()
|
|
price := func(prov, model string) catalog.Price {
|
|
t.Helper()
|
|
pr, ok := EffectivePriceIn(s, prov, model)
|
|
if !ok {
|
|
t.Fatalf("%s/%s: no price", prov, model)
|
|
}
|
|
return pr
|
|
}
|
|
if pr := price("codex", "codex-auto-review"); pr.Cost(1e6, 1e6, 1e6, 0) != 0 {
|
|
t.Errorf("auto-review on a Pro sign-in priced %+v", pr)
|
|
}
|
|
if pr := price("codex", " Codex-Auto-Review "); pr.Cost(1e6, 1e6, 0, 0) != 0 {
|
|
t.Errorf("auto-review spelled otherwise priced %+v", pr)
|
|
}
|
|
if got := PricedNameFor("codex", "codex-auto-review"); got != "codex-auto-review" {
|
|
t.Errorf("a free call said to be priced as %q", got)
|
|
}
|
|
// a review that followed the session, or ran on Codex's other models
|
|
if pr := price("codex", "gpt-5.6-luna"); pr.Input != 3 {
|
|
t.Errorf("codex gpt-5.6-luna %+v", pr)
|
|
}
|
|
// the same model through anything else is OpenAI's list price
|
|
for _, prov := range []string{"openai", ChatGPTAPIID, "relay"} {
|
|
if pr := price(prov, "codex-auto-review"); pr.Input != 3 || pr.Output != 7 {
|
|
t.Errorf("%s auto-review %+v", prov, pr)
|
|
}
|
|
}
|
|
// what the user set wins
|
|
two, four, zero := 2.0, 4.0, 0.0
|
|
s.ModelPrices = map[string]settings.ModelPrice{"codex/codex-auto-review": {Input: &two, Output: &four, CacheRead: &zero, CacheWrite: &zero}}
|
|
if pr := price("codex", "codex-auto-review"); pr.Input != 2 {
|
|
t.Errorf("the user's price lost: %+v", pr)
|
|
}
|
|
s.ModelPrices = nil
|
|
|
|
// a Free plan spends its allowance on it: priced as gpt-5.6-luna
|
|
writeFile(t, filepath.Join(home, ".codex", "auth.json"), map[string]any{
|
|
"auth_mode": "chatgpt",
|
|
"tokens": map[string]any{
|
|
"id_token": fakeJWT(map[string]any{"email": "me@example.com", "https://api.openai.com/auth": map[string]any{"chatgpt_plan_type": "free", "chatgpt_account_id": "acct-1"}}),
|
|
"access_token": fakeJWT(map[string]any{"exp": float64(time.Now().Add(time.Hour).Unix())}),
|
|
"refresh_token": "r", "account_id": "acct-1",
|
|
},
|
|
})
|
|
forgetAccountCaches()
|
|
if pr := price("codex", "codex-auto-review"); pr.Input != 3 || pr.Output != 7 {
|
|
t.Errorf("auto-review on a Free plan priced %+v", pr)
|
|
}
|
|
if got := PricedNameFor("codex", "codex-auto-review"); got != "gpt-5.6-luna" {
|
|
t.Errorf("Free plan's review priced as %q", got)
|
|
}
|
|
|
|
// signed out since: the subscription's calls were a ChatGPT sign-in's
|
|
os.Remove(filepath.Join(home, ".codex", "auth.json"))
|
|
forgetAccountCaches()
|
|
if pr := price("codex", "codex-auto-review"); pr.Cost(1e6, 1e6, 0, 0) != 0 {
|
|
t.Errorf("auto-review of a signed-out Codex priced %+v", pr)
|
|
}
|
|
}
|