| 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 TestBuildFailsWhenGuardianModelIsUnresolvable(t *testing.T) { |
| 13 | isolateConfigHome(t) |
| 14 | dir := robustTempDir(t) |
| 15 | t.Chdir(dir) |
| 16 | registerBootTokenProfileTestProvider() |
| 17 | setBootTokenProfileTestProvider(t, testutil.NewMock("guardian-missing")) |
| 18 | |
| 19 | writeFile(t, dir, "reasonix.toml", ` |
| 20 | default_model = "executor" |
| 21 | |
| 22 | [agent] |
| 23 | guardian_model = "missing-guardian" |
| 24 | |
| 25 | [[providers]] |
| 26 | name = "executor" |
| 27 | kind = "boot-token-profile-test" |
| 28 | model = "executor-model" |
| 29 | `) |
| 30 | |
| 31 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 32 | if err == nil || !strings.Contains(err.Error(), "guardian_model") { |
| 33 | t.Fatalf("Build = (%v, %v), want a guardian_model configuration error", ctrl, err) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestBuildIgnoresRetiredRecoveryModel(t *testing.T) { |
| 38 | isolateConfigHome(t) |
| 39 | dir := robustTempDir(t) |
| 40 | t.Chdir(dir) |
| 41 | registerBootTokenProfileTestProvider() |
| 42 | setBootTokenProfileTestProvider(t, testutil.NewMock("recovery-missing")) |
| 43 | |
| 44 | writeFile(t, dir, "reasonix.toml", ` |
| 45 | default_model = "executor" |
| 46 | |
| 47 | [agent] |
| 48 | recovery_model = "missing-recovery" |
| 49 | |
| 50 | [[providers]] |
| 51 | name = "executor" |
| 52 | kind = "boot-token-profile-test" |
| 53 | model = "executor-model" |
| 54 | `) |
| 55 | |
| 56 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 57 | if err != nil { |
| 58 | t.Fatalf("retired recovery_model affected Build: %v", err) |
| 59 | } |
| 60 | defer ctrl.Close() |
| 61 | } |
| 62 | |
| 63 | func TestBuildLeavesOptionalRolesOffWithoutExplicitModels(t *testing.T) { |
| 64 | isolateConfigHome(t) |
| 65 | dir := robustTempDir(t) |
| 66 | t.Chdir(dir) |
| 67 | registerBootTokenProfileTestProvider() |
| 68 | setBootTokenProfileTestProvider(t, testutil.NewMock("roles-off")) |
| 69 | |
| 70 | writeFile(t, dir, "reasonix.toml", ` |
| 71 | default_model = "executor" |
| 72 | |
| 73 | [[providers]] |
| 74 | name = "executor" |
| 75 | kind = "boot-token-profile-test" |
| 76 | model = "executor-model" |
| 77 | `) |
| 78 | |
| 79 | var notices []string |
| 80 | sink := event.FuncSink(func(e event.Event) { |
| 81 | if e.Kind == event.Notice { |
| 82 | notices = append(notices, e.Text) |
| 83 | } |
| 84 | }) |
| 85 | ctrl, err := Build(context.Background(), Options{Sink: sink}) |
| 86 | if err != nil { |
| 87 | t.Fatalf("Build: %v", err) |
| 88 | } |
| 89 | defer ctrl.Close() |
| 90 | for _, n := range notices { |
| 91 | if strings.Contains(strings.ToLower(n), "guardian enabled") { |
| 92 | t.Fatalf("guardian started without guardian_model: %v", notices) |
| 93 | } |
| 94 | } |
| 95 | if strings.Contains(ctrl.Label(), "planner") { |
| 96 | t.Fatalf("planner started without planner_model: %q", ctrl.Label()) |
| 97 | } |
| 98 | } |
| 99 |