返回 DeepSeek-Reasonix
set_goal_for_tab_error_test.go
根目录 / desktop / set_goal_for_tab_error_test.go
1 package main
2
3 import (
4 "errors"
5 "strings"
6 "testing"
7
8 "reasonix/internal/control"
9 )
10
11 type rejectingGoalSession struct {
12 control.SessionAPI
13 err error
14 }
15
16 func (s *rejectingGoalSession) SetGoalDurable(string) error { return s.err }
17 func (s *rejectingGoalSession) EditGoalDurable(string, *uint64) error { return s.err }
18
19 func TestSetGoalForTabReturnsErrorWhenTabMissing(t *testing.T) {
20 isolateDesktopUserDirs(t)
21
22 app := NewApp()
23 app.tabs = map[string]*WorkspaceTab{}
24 app.tabOrder = nil
25 app.activeTabID = ""
26
27 err := app.SetGoalForTab("missing-tab", "ship the goal skill path")
28 if err == nil {
29 t.Fatal("SetGoalForTab with a missing tab returned nil error")
30 }
31 if !strings.Contains(err.Error(), "workspace is still starting") {
32 t.Fatalf("SetGoalForTab missing-tab error = %v, want workspace-not-ready wording", err)
33 }
34 }
35
36 func TestClearGoalForTabReturnsErrorWhenTabMissing(t *testing.T) {
37 isolateDesktopUserDirs(t)
38
39 app := NewApp()
40 app.tabs = map[string]*WorkspaceTab{}
41 app.tabOrder = nil
42 app.activeTabID = ""
43
44 err := app.ClearGoalForTab("gone")
45 if err == nil {
46 t.Fatal("ClearGoalForTab with a missing tab returned nil error")
47 }
48 if !strings.Contains(err.Error(), "workspace is still starting") {
49 t.Fatalf("ClearGoalForTab missing-tab error = %v, want workspace-not-ready wording", err)
50 }
51 }
52
53 func TestSetGoalForTabSucceedsAndPersistsLocalGoal(t *testing.T) {
54 isolateDesktopUserDirs(t)
55
56 app := NewApp()
57 tab := testTab("a", t.TempDir())
58 app.tabs = map[string]*WorkspaceTab{tab.ID: tab}
59 app.tabOrder = []string{tab.ID}
60 app.activeTabID = tab.ID
61 defer tab.Ctrl.Close()
62
63 if err := app.SetGoalForTab(tab.ID, "finish the goal skill path"); err != nil {
64 t.Fatalf("SetGoalForTab: %v", err)
65 }
66 if tab.goal != "finish the goal skill path" {
67 t.Fatalf("tab.goal = %q, want set", tab.goal)
68 }
69 if tab.Ctrl.Goal() != "finish the goal skill path" {
70 t.Fatalf("controller goal = %q, want set", tab.Ctrl.Goal())
71 }
72
73 if err := app.ClearGoalForTab(tab.ID); err != nil {
74 t.Fatalf("ClearGoalForTab: %v", err)
75 }
76 if tab.goal != "" {
77 t.Fatalf("cleared tab.goal = %q, want empty", tab.goal)
78 }
79 if tab.Ctrl.Goal() != "" {
80 t.Fatalf("cleared controller goal = %q, want empty", tab.Ctrl.Goal())
81 }
82 }
83
84 func TestSetGoalForTabDoesNotPublishMetadataWhenPersistenceFails(t *testing.T) {
85 isolateDesktopUserDirs(t)
86
87 app := NewApp()
88 tab := testTab("a", t.TempDir())
89 base := tab.Ctrl
90 tab.Ctrl = &rejectingGoalSession{SessionAPI: base, err: errors.New("disk full")}
91 tab.goal = "existing goal"
92 app.tabs = map[string]*WorkspaceTab{tab.ID: tab}
93 app.tabOrder = []string{tab.ID}
94 app.activeTabID = tab.ID
95 defer base.Close()
96
97 err := app.SetGoalForTab(tab.ID, "replacement goal")
98 if err == nil || !strings.Contains(err.Error(), "disk full") {
99 t.Fatalf("SetGoalForTab error = %v, want persistence failure", err)
100 }
101 if tab.goal != "existing goal" {
102 t.Fatalf("tab goal = %q, want unchanged metadata", tab.goal)
103 }
104 if base.Goal() != "" {
105 t.Fatalf("controller goal = %q, want no accepted mutation", base.Goal())
106 }
107 }
108
109 func TestEditGoalForTabDoesNotPublishMetadataWhenPersistenceFails(t *testing.T) {
110 isolateDesktopUserDirs(t)
111
112 app := NewApp()
113 tab := testTab("a", t.TempDir())
114 base := tab.Ctrl
115 tab.Ctrl = &rejectingGoalSession{SessionAPI: base, err: errors.New("disk full")}
116 tab.goal = "existing goal"
117 app.tabs = map[string]*WorkspaceTab{tab.ID: tab}
118 app.tabOrder = []string{tab.ID}
119 app.activeTabID = tab.ID
120 defer base.Close()
121
122 limit := uint64(9)
123 err := app.EditGoalForTab(tab.ID, "revised goal", &limit)
124 if err == nil || !strings.Contains(err.Error(), "disk full") {
125 t.Fatalf("EditGoalForTab error = %v, want persistence failure", err)
126 }
127 if tab.goal != "existing goal" {
128 t.Fatalf("tab goal = %q, want unchanged metadata", tab.goal)
129 }
130 }
131
131 lines GO