60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A ChatGPT account that runs out of its allowance after a magpie model was
|
|
// picked beside its sign-in leaves the Codex app sending nothing, a magpie
|
|
// model's turn included (#540): Sync makes magpie Codex's provider then, as
|
|
// a pick does for an account already out, and puts magpie back beside the
|
|
// sign-in once the allowance is back. A provider the user asked for (api)
|
|
// or one for a Codex not signed in to ChatGPT stays.
|
|
func TestCodexRunsOutAfterPick(t *testing.T) {
|
|
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "")
|
|
cx := codex(home)
|
|
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); strings.Contains(cfg, "model_provider =") || !strings.Contains(cfg, "openai_base_url") {
|
|
t.Fatalf("beside the sign-in:\n%s", cfg)
|
|
}
|
|
codexUsedUp = func() bool { return true }
|
|
if err := cx.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) || !strings.Contains(cfg, "model_catalog_json") ||
|
|
!strings.Contains(cfg, "openai_base_url") || !strings.Contains(cfg, `model = "fake/m1"`) {
|
|
t.Fatalf("used up:\n%s", cfg)
|
|
}
|
|
if err := cx.Sync(); err != nil { // still out: stays
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) {
|
|
t.Fatalf("used up, synced again:\n%s", cfg)
|
|
}
|
|
codexUsedUp = func() bool { return false }
|
|
if err := cx.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); strings.Contains(cfg, "model_provider =") || strings.Contains(cfg, "model_catalog_json") ||
|
|
!strings.Contains(cfg, "openai_base_url") || !strings.Contains(cfg, `model = "fake/m1"`) {
|
|
t.Fatalf("allowance back:\n%s", cfg)
|
|
}
|
|
|
|
// magpie as the provider because the user asked for it stays so
|
|
if err := cx.Field("login").Set("api"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) {
|
|
t.Fatalf("api:\n%s", cfg)
|
|
}
|
|
if err := cx.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg := read(); !strings.Contains(cfg, `model_provider = "magpie"`) {
|
|
t.Fatalf("api, allowance there, synced:\n%s", cfg)
|
|
}
|
|
}
|