| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/agent/testutil" |
| 9 | "reasonix/internal/event" |
| 10 | ) |
| 11 | |
| 12 | func TestBuildOmitsCoordinatorWithoutPlannerModel(t *testing.T) { |
| 13 | isolateConfigHome(t) |
| 14 | dir := robustTempDir(t) |
| 15 | t.Chdir(dir) |
| 16 | registerBootTokenProfileTestProvider() |
| 17 | setBootTokenProfileTestProvider(t, testutil.NewMock("executor-only")) |
| 18 | |
| 19 | writeFile(t, dir, "reasonix.toml", ` |
| 20 | default_model = "executor" |
| 21 | |
| 22 | [[providers]] |
| 23 | name = "executor" |
| 24 | kind = "boot-token-profile-test" |
| 25 | model = "executor-model" |
| 26 | `) |
| 27 | |
| 28 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 29 | if err != nil { |
| 30 | t.Fatalf("Build: %v", err) |
| 31 | } |
| 32 | defer ctrl.Close() |
| 33 | if strings.Contains(ctrl.Label(), "planner") { |
| 34 | t.Fatalf("label = %q, want executor-only without planner_model", ctrl.Label()) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestBuildConstructsCoordinatorWhenPlannerModelConfigured(t *testing.T) { |
| 39 | isolateConfigHome(t) |
| 40 | dir := robustTempDir(t) |
| 41 | t.Chdir(dir) |
| 42 | registerBootTokenProfileTestProvider() |
| 43 | setBootTokenProfileTestProvider(t, testutil.NewMock("dual")) |
| 44 | |
| 45 | writeFile(t, dir, "reasonix.toml", ` |
| 46 | default_model = "executor" |
| 47 | |
| 48 | [agent] |
| 49 | planner_model = "planner" |
| 50 | |
| 51 | [[providers]] |
| 52 | name = "executor" |
| 53 | kind = "boot-token-profile-test" |
| 54 | model = "executor-model" |
| 55 | |
| 56 | [[providers]] |
| 57 | name = "planner" |
| 58 | kind = "boot-token-profile-test" |
| 59 | model = "planner-model" |
| 60 | `) |
| 61 | |
| 62 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 63 | if err != nil { |
| 64 | t.Fatalf("Build: %v", err) |
| 65 | } |
| 66 | defer ctrl.Close() |
| 67 | if !strings.Contains(ctrl.Label(), "planner") { |
| 68 | t.Fatalf("label = %q, want a coordinator when planner_model is set", ctrl.Label()) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | func TestBuildConstructsCoordinatorWhenPlannerModelMatchesExecutor(t *testing.T) { |
| 73 | isolateConfigHome(t) |
| 74 | dir := robustTempDir(t) |
| 75 | t.Chdir(dir) |
| 76 | registerBootTokenProfileTestProvider() |
| 77 | setBootTokenProfileTestProvider(t, testutil.NewMock("same-model")) |
| 78 | |
| 79 | writeFile(t, dir, "reasonix.toml", ` |
| 80 | default_model = "executor" |
| 81 | |
| 82 | [agent] |
| 83 | planner_model = "executor" |
| 84 | |
| 85 | [[providers]] |
| 86 | name = "executor" |
| 87 | kind = "boot-token-profile-test" |
| 88 | model = "shared-model" |
| 89 | `) |
| 90 | |
| 91 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 92 | if err != nil { |
| 93 | t.Fatalf("Build: %v", err) |
| 94 | } |
| 95 | defer ctrl.Close() |
| 96 | if !strings.Contains(ctrl.Label(), "planner") { |
| 97 | t.Fatalf("label = %q, want a coordinator when planner_model is explicitly set even to the same model", ctrl.Label()) |
| 98 | } |
| 99 | } |
| 100 |