| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/boot" |
| 10 | "reasonix/internal/config" |
| 11 | "reasonix/internal/control" |
| 12 | ) |
| 13 | |
| 14 | // TestBuildTabControllerIgnoresRetiredAutoRecoveryKillSwitch exercises the |
| 15 | // desktop wiring after boot.Build. Retired global/project keys must not disable |
| 16 | // Auto Guard either during controller construction or fresh-session binding. |
| 17 | func TestBuildTabControllerIgnoresRetiredAutoRecoveryKillSwitch(t *testing.T) { |
| 18 | isolateDesktopUserDirs(t) |
| 19 | userCfg := config.UserConfigPath() |
| 20 | if err := os.MkdirAll(filepath.Dir(userCfg), 0o755); err != nil { |
| 21 | t.Fatalf("mkdir user config: %v", err) |
| 22 | } |
| 23 | if err := os.WriteFile(userCfg, []byte(` |
| 24 | default_model = "test-model" |
| 25 | |
| 26 | [agent] |
| 27 | auto_recovery_checkpoint = "on" |
| 28 | |
| 29 | [[providers]] |
| 30 | name = "test-model" |
| 31 | kind = "openai" |
| 32 | base_url = "https://example.invalid" |
| 33 | model = "x" |
| 34 | api_key_env = "REASONIX_TEST_KEY_UNSET" |
| 35 | `), 0o644); err != nil { |
| 36 | t.Fatalf("write user config: %v", err) |
| 37 | } |
| 38 | |
| 39 | root := robustTempDir(t) |
| 40 | if err := os.WriteFile(filepath.Join(root, "reasonix.toml"), []byte(` |
| 41 | default_model = "test-model" |
| 42 | |
| 43 | [agent] |
| 44 | auto_recovery_checkpoint = "off" |
| 45 | |
| 46 | [[providers]] |
| 47 | name = "test-model" |
| 48 | kind = "openai" |
| 49 | base_url = "https://example.invalid" |
| 50 | model = "x" |
| 51 | api_key_env = "REASONIX_TEST_KEY_UNSET" |
| 52 | `), 0o644); err != nil { |
| 53 | t.Fatalf("write project config: %v", err) |
| 54 | } |
| 55 | |
| 56 | app := NewApp() |
| 57 | app.ctx = context.Background() |
| 58 | app.readyHook = func() {} |
| 59 | tab := &WorkspaceTab{ |
| 60 | ID: "project-auto-guard-off", |
| 61 | Scope: "project", |
| 62 | WorkspaceRoot: root, |
| 63 | model: "test-model", |
| 64 | tokenMode: boot.TokenModeFull, |
| 65 | mode: "normal", |
| 66 | toolApprovalMode: control.ToolApprovalAuto, |
| 67 | disabledMCP: map[string]ServerView{}, |
| 68 | } |
| 69 | tab.sink = &tabEventSink{tabID: tab.ID, app: app} |
| 70 | app.tabs = map[string]*WorkspaceTab{tab.ID: tab} |
| 71 | app.tabOrder = []string{tab.ID} |
| 72 | app.activeTabID = tab.ID |
| 73 | defer func() { |
| 74 | if tab.Ctrl != nil { |
| 75 | tab.Ctrl.Close() |
| 76 | } |
| 77 | app.releaseTabSharedHost(tab) |
| 78 | tab.releaseSessionLease() |
| 79 | }() |
| 80 | |
| 81 | app.buildTabController(tab) |
| 82 | if tab.StartupErr != "" { |
| 83 | t.Fatalf("build tab controller: %s", tab.StartupErr) |
| 84 | } |
| 85 | ctrl, ok := tab.Ctrl.(*control.Controller) |
| 86 | if !ok || ctrl == nil { |
| 87 | t.Fatalf("tab controller = %T, want *control.Controller", tab.Ctrl) |
| 88 | } |
| 89 | |
| 90 | fresh := filepath.Join(ctrl.SessionDir(), "fresh-auto-guard-off.jsonl") |
| 91 | ctrl.SetFreshSessionPath(fresh) |
| 92 | if got := ctrl.SessionPath(); got != fresh { |
| 93 | t.Fatalf("fresh session path = %q, want %q", got, fresh) |
| 94 | } |
| 95 | } |
| 96 |