返回 DeepSeek-Reasonix
model_settings_persisted_connection_test.go
根目录 / desktop / model_settings_persisted_connection_test.go
1 package main
2
3 import (
4 "context"
5 "testing"
6
7 "reasonix/internal/control"
8 )
9
10 func TestModelSettingsCredentialRefreshPersistsSelectedConnection(t *testing.T) {
11 isolateDesktopUserDirs(t)
12 app := NewApp()
13 for _, name := range []string{"connection-one", "connection-two"} {
14 if _, err := app.SaveProviderWithKey(ProviderView{Name: name, Kind: "openai", BaseURL: "http://127.0.0.1:1/v1", Models: []string{"same-model"}}, "test-key"); err != nil {
15 t.Fatal(err)
16 }
17 }
18 app.ctx = context.Background()
19 app.readyHook = func() {}
20 tab := modelSettingsBootTab(t, app, "persisted-connection", t.TempDir(), "connection-one/same-model")
21 app.activeTabID = tab.ID
22 const want = "connection-two/same-model"
23 if err := app.SetModelForTab(tab.ID, want); err != nil {
24 t.Fatal(err)
25 }
26 if _, err := app.SetConnectionKey("connection-two", "next-test-key"); err != nil {
27 t.Fatal(err)
28 }
29 admission, current, err := app.beginTabTurn(tab.ID, false)
30 if err != nil {
31 t.Fatal(err)
32 }
33 admission.abort()
34 if got := current.ModelRef(); got != want {
35 t.Fatalf("runtime model = %q, want %q", got, want)
36 }
37 _, runtime, ok := current.(*control.Controller).SessionBinding()
38 if !ok {
39 t.Fatal("rebuilt controller lost its v3 runtime")
40 }
41 if _, err := runtime.Session().Flush(t.Context()); err != nil {
42 t.Fatal(err)
43 }
44 if got := runtime.Session().Snapshot().Projection.ModelRef; got != want {
45 t.Fatalf("persisted model event = %q, want %q", got, want)
46 }
47 }
48
48 lines GO