Repository navigation
Expand file tree
/
Copy pathcodex_window_test.go
More file actions
69 lines (66 loc) · 2.47 KB
/
Copy pathcodex_window_test.go
File metadata and controls
69 lines (66 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package config
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/Agent-Field/codeaf/internal/catalog"
"github.com/Agent-Field/codeaf/internal/codexauth"
)
func TestW3ConnectCodexRemembersEachModelsWindow(t *testing.T) {
// W3 (#1383): the catalog a Codex connection remembers carries each model's
// window — the listing's own figure when it answered, the fallback rows'
// one observed figure when it did not — because that catalog is what the
// picker, the status line and the session's compaction read.
for _, testCase := range []struct {
name string
listing http.HandlerFunc
want map[string]int
}{
{
name: "listing answered",
listing: func(writer http.ResponseWriter, request *http.Request) {
_ = json.NewEncoder(writer).Encode(map[string]any{"models": []any{
map[string]any{"slug": "gpt-5.5", "visibility": "list", "context_window": 272000},
map[string]any{"slug": "gpt-wide", "visibility": "list", "context_window": 400000},
}})
},
want: map[string]int{"gpt-5.5": 272000, "gpt-wide": 400000},
},
{
name: "listing unreachable",
listing: func(writer http.ResponseWriter, request *http.Request) { writer.WriteHeader(http.StatusBadGateway) },
want: map[string]int{
"gpt-5.5": codexauth.FallbackContextWindow, "gpt-5.6-sol": codexauth.FallbackContextWindow,
"gpt-5.6-terra": codexauth.FallbackContextWindow, "gpt-5.6-luna": codexauth.FallbackContextWindow,
},
},
} {
t.Run(testCase.name, func(t *testing.T) {
backend := httptest.NewServer(testCase.listing)
defer backend.Close()
t.Setenv("CODEAF_CODEX_BACKEND", backend.URL)
dir := t.TempDir()
tokens := codexauth.Tokens{AccessToken: "window-access", RefreshToken: "window-refresh", IDToken: "window-identity", AccountID: "acct-window", ExpiresAt: time.Now().Add(time.Hour)}
if _, err := ConnectCodex(context.Background(), dir, tokens); err != nil {
t.Fatal(err)
}
service, ok := ResolveSources(dir, "", DefaultBaseURL).ByID("codex")
if !ok {
t.Fatal("connection was not kept")
}
remembered := catalog.Recall(CatalogOptionsFor(service, dir))
rows := remembered.ModelsNow()
if len(rows) != len(testCase.want) {
t.Fatalf("remembered rows = %+v, want %d", rows, len(testCase.want))
}
for id, window := range testCase.want {
if got := remembered.ContextLengthNow(id); got != window {
t.Fatalf("remembered window of %s = %d, want %d", id, got, window)
}
}
})
}
}