feat(chat): persist safe Codex next-turn model selection
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOperatorModelSelectionMigratesAndPersists(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
path := filepath.Join(t.TempDir(), "old.db")
|
||||
db, err := sql.Open("sqlite", path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = db.Exec(`CREATE TABLE operator_sessions (session_id TEXT PRIMARY KEY, directory TEXT NOT NULL, title TEXT NOT NULL DEFAULT '', tag TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, last_used_at INTEGER NOT NULL)`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.Close()
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{"codex-chat", "other-chat"} {
|
||||
if err := store.RecordOperatorSession(ctx, id, "/fixture", "title", "operator"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := store.SetOperatorSessionBackend(ctx, "codex-chat", "codex"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SetChatModelSelection(ctx, "other-chat", "fixture-provider", "fixture-model"); err == nil {
|
||||
t.Fatal("OpenCode row accepted Codex model")
|
||||
}
|
||||
if err := store.SetChatModelSelection(ctx, "missing", "fixture-provider", "fixture-model"); err == nil {
|
||||
t.Fatal("unregistered selection accepted")
|
||||
}
|
||||
if err := store.SetChatModelSelection(ctx, "codex-chat", "fixture-provider", "fixture-model"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _, err := store.OperatorSession(ctx, "codex-chat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
provider, model, err := store.ChatModelSelection(ctx, "codex-chat")
|
||||
if err != nil || provider != "fixture-provider" || model != "fixture-model" {
|
||||
t.Fatalf("restored %q/%q: %v", provider, model, err)
|
||||
}
|
||||
provider, model, err = store.ChatModelSelection(ctx, "other-chat")
|
||||
if err != nil || provider != "" || model != "" {
|
||||
t.Fatalf("selection leaked: %q/%q: %v", provider, model, err)
|
||||
}
|
||||
after, _, err := store.OperatorSession(ctx, "codex-chat")
|
||||
if err != nil || before.UpdatedAt != after.UpdatedAt {
|
||||
t.Fatal("selection changed recency", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user