| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestSetGoalForTabReturnsErrorWhenTabMissing(t *testing.T) { |
| 9 | isolateDesktopUserDirs(t) |
| 10 | |
| 11 | app := NewApp() |
| 12 | app.tabs = map[string]*WorkspaceTab{} |
| 13 | app.tabOrder = nil |
| 14 | app.activeTabID = "" |
| 15 | |
| 16 | err := app.SetGoalForTab("missing-tab", "ship the goal skill path") |
| 17 | if err == nil { |
| 18 | t.Fatal("SetGoalForTab with a missing tab returned nil error") |
| 19 | } |
| 20 | if !strings.Contains(err.Error(), "workspace is still starting") { |
| 21 | t.Fatalf("SetGoalForTab missing-tab error = %v, want workspace-not-ready wording", err) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestClearGoalForTabReturnsErrorWhenTabMissing(t *testing.T) { |
| 26 | isolateDesktopUserDirs(t) |
| 27 | |
| 28 | app := NewApp() |
| 29 | app.tabs = map[string]*WorkspaceTab{} |
| 30 | app.tabOrder = nil |
| 31 | app.activeTabID = "" |
| 32 | |
| 33 | err := app.ClearGoalForTab("gone") |
| 34 | if err == nil { |
| 35 | t.Fatal("ClearGoalForTab with a missing tab returned nil error") |
| 36 | } |
| 37 | if !strings.Contains(err.Error(), "workspace is still starting") { |
| 38 | t.Fatalf("ClearGoalForTab missing-tab error = %v, want workspace-not-ready wording", err) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestSetGoalForTabSucceedsAndPersistsLocalGoal(t *testing.T) { |
| 43 | isolateDesktopUserDirs(t) |
| 44 | |
| 45 | app := NewApp() |
| 46 | tab := testTab("a", t.TempDir()) |
| 47 | app.tabs = map[string]*WorkspaceTab{tab.ID: tab} |
| 48 | app.tabOrder = []string{tab.ID} |
| 49 | app.activeTabID = tab.ID |
| 50 | defer tab.Ctrl.Close() |
| 51 | |
| 52 | if err := app.SetGoalForTab(tab.ID, "finish the goal skill path"); err != nil { |
| 53 | t.Fatalf("SetGoalForTab: %v", err) |
| 54 | } |
| 55 | if tab.goal != "finish the goal skill path" { |
| 56 | t.Fatalf("tab.goal = %q, want set", tab.goal) |
| 57 | } |
| 58 | if tab.Ctrl.Goal() != "finish the goal skill path" { |
| 59 | t.Fatalf("controller goal = %q, want set", tab.Ctrl.Goal()) |
| 60 | } |
| 61 | |
| 62 | if err := app.ClearGoalForTab(tab.ID); err != nil { |
| 63 | t.Fatalf("ClearGoalForTab: %v", err) |
| 64 | } |
| 65 | if tab.goal != "" { |
| 66 | t.Fatalf("cleared tab.goal = %q, want empty", tab.goal) |
| 67 | } |
| 68 | if tab.Ctrl.Goal() != "" { |
| 69 | t.Fatalf("cleared controller goal = %q, want empty", tab.Ctrl.Goal()) |
| 70 | } |
| 71 | } |
| 72 |