Files
magpie/internal/gui/tune_now_test.go
T
yetone 5143bf593a tune: Codex's "Now" is read the same way in every range, and a model's own Compact at is not "In use"
hoobnn (Discord #feedback): Usage > Context's Codex card read differently
for Today and 7 days. 7 days: "Now 380K", "Not the leanest" and a Use
220K button. Today: "Now 430K -> Fewest tokens 170K" with a green "In use".

Two causes:
- codexWindow dropped what magpie tells Codex (told) for the whole range
  as soon as one call was on a model outside the catalog or with an
  unknown window (Codex's own gpt-5.x beside a provider's). "Now" was
  then guessed from the prompts' peaks (380K) over 7 days, while today's
  calls, on catalog models only, read told (430K). told is now the
  largest value over the models magpie knows, in every range.
- Long conversations held magpie's 170K and the advice was 170K, so the
  row said "In use", but a provider's or model's own Compact at (430K)
  comes first and is where Codex runs. The advice now carries Own
  {model, value}; the card shows "{model} compacts at its own {value},
  which comes first" in place of "In use" and hides Use and Other window,
  as it does for a locked setting. Undo stays. New string in en, zh,
  zh-TW, ja, de.

Run (at this tree, rebased on origin/main 296f66a74):
- mote: go test ./internal/gui -run TestTune: ok. go vet ./internal/gui
  ./internal/tune, GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., go build ./... and -tags nogui: ok. gofmt -l clean.
- WSL GUI: context-tune (Chromium + WebKit, every language, 360 and
  1100 wide), i18n-keys, gui-zh-tw, gui-ja, gui-de: 125/127 before the
  rebase; the one red, webkit "a window of the reader's own" zh-TW
  360x760 (boundingBox() null while the row re-rendered, a test I did
  not touch), passed 3 of 3 alone and is filed separately.
Broken by hand: the old tune.go turns TestTuneCodexNowIsTheSameInEveryRange
red (170000 vs 1000000 with Codex's own model beside, 440000 vs 430000);
the old context.js turns "a model's own Compact at isn't called In use"
red in all 10 language/width cases.
Running at push (shipped at once per owner): full go test -tags nogui
-timeout 45m ./... on mote and the whole GUI suite in WSL; reds get
issues.
Not tried: hoobnn's own config. That the 430K comes from a provider's
own Compact at is read from the code (only ModelCompacts lifts told over
a CompactAt of 170K); the advice differing by range (timed "Tokens +
wait" over 7 days, "Fewest tokens" today) follows the data and stays.
2026-10-29 16:31:37 +08:00

66 lines
2.7 KiB
Go

package gui
import (
"testing"
"github.com/yetone/magpie/internal/provider"
)
// Where Tuned for you says Codex runs now is worked out the same way in
// every range (hoobnn on Discord). Over 7 days the calls held one of
// Codex's own models as well, outside magpie's catalog, which made "Now"
// unknown for the whole range: it was guessed from the prompts (380K)
// while today's calls, on magpie's models alone, read the 430K magpie
// tells Codex. And a model's own Compact at is where Codex runs, over Long
// conversations: the card says so instead of "In use" for a Long
// conversations value that doesn't move it.
func TestTuneCodexNowIsTheSameInEveryRange(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
home := t.TempDir()
if err := provider.Save(provider.Provider{ID: "cpa", Name: "CPA", Key: "k", Chat: "http://127.0.0.1:1/v1",
Models: []string{"gpt-cpa-1m", "gpt-cpa-own"},
Contexts: map[string]int{"gpt-cpa-1m": 1000000, "gpt-cpa-own": 440000}}); err != nil {
t.Fatal(err)
}
if err := provider.SetCompactAt(170000); err != nil {
t.Fatal(err)
}
advice := func(models ...string) tuneAdvice {
t.Helper()
var cs = tuneCalls("codex", models[0], 80)
for _, m := range models[1:] {
cs = append(cs, tuneCalls("codex", m, 80)...)
}
st := tuneOf(cs, 7, home)
if len(st.Agents) != 1 || len(st.Agents[0].Advice) != 1 || st.Agents[0].Advice[0].Compact == nil {
t.Fatalf("%v: no compaction advice for Codex: %+v", models, st)
}
return st.Agents[0].Advice[0]
}
// Long conversations at 170K: magpie's model runs at 170K, with one of
// Codex's own models beside it or not
today, week := advice("cpa/gpt-cpa-1m"), advice("cpa/gpt-cpa-1m", "gpt-5.5")
if today.Compact.Current != 170000 || week.Compact.Current != 170000 {
t.Errorf("Codex now: %d on magpie's model, %d with Codex's own beside it; want 170000 both", today.Compact.Current, week.Compact.Current)
}
if today.Own != nil || week.Own != nil {
t.Errorf("Long conversations is where Codex runs, yet the advice names a model's own threshold: %+v, %+v", today.Own, week.Own)
}
// the provider's own Compact at, 430K, over Long conversations' 170K
if err := provider.SetModelCompacts("cpa", map[string]int{"*": 430000}); err != nil {
t.Fatal(err)
}
for _, ms := range [][]string{{"cpa/gpt-cpa-own"}, {"cpa/gpt-cpa-own", "gpt-5.5"}} {
a := advice(ms...)
if a.Compact.Current != 430000 {
t.Errorf("%v: Codex now %d; want the provider's 430000", ms, a.Compact.Current)
}
if a.Own == nil || a.Own.Model != "cpa/gpt-cpa-own" || a.Own.Value != 430000 {
t.Errorf("%v: own threshold %+v; want cpa/gpt-cpa-own at 430000", ms, a.Own)
}
}
}