| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/BurntSushi/toml" |
| 8 | ) |
| 9 | |
| 10 | func TestDesktopSessionExperienceDefaultsAndLegacyMigration(t *testing.T) { |
| 11 | for _, legacy := range []DesktopConfig{ |
| 12 | {DisplayMode: "compact"}, |
| 13 | {DisplayMode: "minimal"}, |
| 14 | {ReasoningDisplayMode: "hidden"}, |
| 15 | {ReasoningDisplayMode: "summary"}, |
| 16 | {ReasoningDisplayMode: "auto"}, |
| 17 | {ReasoningDisplayMode: "expanded", ExpandThinking: true}, |
| 18 | } { |
| 19 | cfg := Default() |
| 20 | cfg.Desktop = legacy |
| 21 | if got := cfg.DesktopSessionExperience(); got != "standard" { |
| 22 | t.Fatalf("legacy config %+v resolved to %q, want standard", legacy, got) |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestSetDesktopSessionExperienceSynchronizesCompatibilityFields(t *testing.T) { |
| 28 | tests := []struct { |
| 29 | mode string |
| 30 | reasoning string |
| 31 | }{ |
| 32 | {mode: "standard", reasoning: "auto"}, |
| 33 | {mode: "deep", reasoning: "expanded"}, |
| 34 | } |
| 35 | for _, tt := range tests { |
| 36 | t.Run(tt.mode, func(t *testing.T) { |
| 37 | cfg := Default() |
| 38 | if err := cfg.SetDesktopSessionExperience(tt.mode); err != nil { |
| 39 | t.Fatalf("SetDesktopSessionExperience(%q): %v", tt.mode, err) |
| 40 | } |
| 41 | if got := cfg.DesktopSessionExperience(); got != tt.mode { |
| 42 | t.Fatalf("experience = %q, want %q", got, tt.mode) |
| 43 | } |
| 44 | if cfg.Desktop.DisplayMode != "standard" || cfg.Desktop.ReasoningDisplayMode != tt.reasoning { |
| 45 | t.Fatalf("compatibility mirrors = %+v", cfg.Desktop) |
| 46 | } |
| 47 | if got := cfg.DesktopReasoningDisplayMode(); got != tt.reasoning { |
| 48 | t.Fatalf("reasoning mode = %q, want %q", got, tt.reasoning) |
| 49 | } |
| 50 | }) |
| 51 | } |
| 52 | if err := Default().SetDesktopSessionExperience("invalid"); err == nil { |
| 53 | t.Fatal("invalid session experience unexpectedly accepted") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestDesktopSessionExperienceRenderRoundTrip(t *testing.T) { |
| 58 | cfg := Default() |
| 59 | if err := cfg.SetDesktopSessionExperience("deep"); err != nil { |
| 60 | t.Fatal(err) |
| 61 | } |
| 62 | rendered := RenderTOML(cfg) |
| 63 | if !strings.Contains(rendered, `session_experience = "deep"`) { |
| 64 | t.Fatalf("rendered config missing canonical experience:\n%s", rendered) |
| 65 | } |
| 66 | var decoded Config |
| 67 | if _, err := toml.Decode(rendered, &decoded); err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | if got := decoded.DesktopSessionExperience(); got != "deep" { |
| 71 | t.Fatalf("round-tripped experience = %q, want deep", got) |
| 72 | } |
| 73 | } |
| 74 |