| 1 | package doctor |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/config" |
| 10 | ) |
| 11 | |
| 12 | func TestDoctorPreservesProjectSandboxHintAndDeclarationValues(t *testing.T) { |
| 13 | home, root := t.TempDir(), t.TempDir() |
| 14 | t.Setenv("REASONIX_HOME", home) |
| 15 | t.Chdir(root) |
| 16 | project := "[sandbox]\nnetwork=false\n[permissions]\nallow=['Bash=echo synthetic-rule']\n" |
| 17 | if err := os.WriteFile(filepath.Join(root, "reasonix.toml"), []byte(project), 0600); err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | cfg, err := config.LoadForRootReadOnly(root) |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if cfg.HasLoadWarnings() { |
| 25 | t.Fatalf("ordinary declaration produced a banner warning: %v", cfg.LoadWarnings()) |
| 26 | } |
| 27 | text := RenderText(Collect(Options{Config: cfg})) |
| 28 | for _, want := range []string{"sets [sandbox]", "narrow user-level Settings", "permissions.allow", "Bash=echo synthetic-rule", "approval is required"} { |
| 29 | if !strings.Contains(text, want) { |
| 30 | t.Fatalf("missing %q: %s", want, text) |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func TestDoctorPreservesUnknownPresetKeyValueAndProjectOrigin(t *testing.T) { |
| 36 | t.Setenv("REASONIX_HOME", t.TempDir()) |
| 37 | root := t.TempDir() |
| 38 | t.Chdir(root) |
| 39 | if err := os.WriteFile(filepath.Join(root, "reasonix.toml"), []byte("[desktop]\ndefault_tool_approval_mode='unknown-project-preset'\n"), 0600); err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | cfg, err := config.LoadForRootReadOnly(root) |
| 43 | if err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | text := RenderText(Collect(Options{Config: cfg})) |
| 47 | if !strings.Contains(text, "project config sets desktop.default_tool_approval_mode") || !strings.Contains(text, "unknown-project-preset") { |
| 48 | t.Fatalf("warning lost project origin or key/value: %s", text) |
| 49 | } |
| 50 | } |
| 51 |