返回 DeepSeek-Reasonix
model_selection_test.go
根目录 / internal / control / model_selection_test.go
1 package control
2
3 import (
4 "errors"
5 "testing"
6
7 "reasonix/internal/agent"
8 "reasonix/internal/event"
9 "reasonix/internal/provider"
10 )
11
12 func TestControllerModelSelectionPersistsAndBranches(t *testing.T) {
13 dir := schemaOneTempDir(t)
14 path := agent.NewSessionPath(dir, "original")
15 s := agent.NewSession("fixture system")
16 s.Add(provider.Message{Role: provider.RoleUser, Content: "keep this"})
17 exec := agent.New(nil, nil, s, agent.Options{}, event.Discard)
18 ctrl := newOwnedTestController(t, Options{Executor: exec, Sink: event.Discard, SessionDir: dir, ModelRef: "go/model", ModelIdentity: "accepted"})
19 defer ctrl.Close()
20 ctrl.SetFreshSessionPath(path)
21 if err := ctrl.Snapshot(); err != nil {
22 t.Fatal(err)
23 }
24 if model, identity, ok := agent.LoadSessionModelSelection(path); !ok || model != "go/model" || identity != "accepted" {
25 t.Fatal("snapshot did not persist the assembled model identity")
26 }
27 branch, err := ctrl.Branch("copy")
28 if err != nil {
29 t.Fatal(err)
30 }
31 if model, identity, ok := agent.LoadSessionModelSelection(branch); !ok || model != "go/model" || identity != "accepted" {
32 t.Fatal("branch did not inherit the assembled model identity")
33 }
34 }
35
36 func TestControllerRejectsHistoricalBranchBeforeTransition(t *testing.T) {
37 dir := schemaOneTempDir(t)
38 path := agent.NewSessionPath(dir, "other")
39 s := agent.NewSession("fixture")
40 s.Add(provider.Message{Role: provider.RoleUser, Content: "historical branch"})
41 if err := s.Save(path); err != nil {
42 t.Fatal(err)
43 }
44 if err := agent.SetBranchModelSelectionPreserveUpdated(path, "go/model", "old"); err != nil {
45 t.Fatal(err)
46 }
47 blocked := errors.New("MIGRATED_MODEL_UNAVAILABLE")
48 ctrl := newOwnedTestController(t, Options{SessionDir: dir, ResolveSessionModel: func(model, identity string) (string, error) {
49 if model != "go/model" || identity != "old" {
50 t.Fatal("branch did not pass the saved selection to the validator")
51 }
52 return "", blocked
53 }})
54 defer ctrl.Close()
55 if _, err := ctrl.SwitchBranch(agent.BranchID(path)); !errors.Is(err, blocked) {
56 t.Fatalf("branch was not rejected: %v", err)
57 }
58 if ctrl.SessionPath() != "" {
59 t.Fatal("failed validation changed the active session")
60 }
61 }
62
62 lines GO