@@ -1,331 +0,0 @@
1-package core
2-
3-import (
4- "testing"
5- "time"
6-
7- "github.com/xonecas/zoea-nova/internal/constants"
8-)
9-
10-// TestMysis_ShouldNudge_Idle tests nudge behavior when mysis is idle.
11-func TestMysis_ShouldNudge_Idle(t *testing.T) {
12- m := &Mysis{
13- activityState: ActivityStateIdle,
14- activityUntil: time.Time{}, // Zero time means no wait
15- }
16-
17- now := time.Now()
18-
19- if !m.shouldNudge(now) {
20- t.Error("Expected nudge when idle (no activity until time)")
21- }
22-}
23-
24-// TestMysis_ShouldNudge_Traveling_Arrived tests nudge after arrival.
25-func TestMysis_ShouldNudge_Traveling_Arrived(t *testing.T) {
26- m := &Mysis{
27- activityState: ActivityStateTraveling,
28- activityUntil: time.Now().Add(-1 * time.Second), // Already arrived
29- }
30-
31- now := time.Now()
32-
33- if !m.shouldNudge(now) {
34- t.Error("Expected nudge after arrival (activity until time in past)")
35- }
36-
37- // Verify state cleared to idle after nudge check
38- if m.activityState != ActivityStateIdle {
39- t.Errorf("Expected activity state cleared to idle, got %s", m.activityState)
40- }
41-
42- if !m.activityUntil.IsZero() {
43- t.Error("Expected activityUntil cleared to zero time")
44- }
45-}
46-
47-// TestMysis_ShouldNudge_Cooldown_Expired tests nudge after cooldown expires.
48-func TestMysis_ShouldNudge_Cooldown_Expired(t *testing.T) {
49- m := &Mysis{
50- activityState: ActivityStateCooldown,
51- activityUntil: time.Now().Add(-1 * time.Second), // Cooldown expired
52- }
53-
54- now := time.Now()
55-
56- if !m.shouldNudge(now) {
57- t.Error("Expected nudge after cooldown expires")
58- }
59-
60- // Verify state cleared
61- if m.activityState != ActivityStateIdle {
62- t.Errorf("Expected activity state cleared to idle, got %s", m.activityState)
63- }
64-}
65-
66-// TestMysis_ShouldNudge_Mining tests nudge during mining (should allow nudges).
67-func TestMysis_ShouldNudge_Mining(t *testing.T) {
68- m := &Mysis{
69- activityState: ActivityStateMining,
70- activityUntil: time.Time{},
71- }
72-
73- now := time.Now()
74-
75- if !m.shouldNudge(now) {
76- t.Error("Expected nudge during mining activity")
77- }
78-}
79-
80-// TestMysis_ShouldNudge_InCombat tests nudge during combat (should allow nudges).
81-func TestMysis_ShouldNudge_InCombat(t *testing.T) {
82- m := &Mysis{
83- activityState: ActivityStateInCombat,
84- activityUntil: time.Time{},
85- }
86-
87- now := time.Now()
88-
89- if !m.shouldNudge(now) {
90- t.Error("Expected nudge during combat activity")
91- }
92-}
93-
94-// TestMysis_ClearActivityIf_Matching tests clearing activity when state matches.
95-func TestMysis_ClearActivityIf_Matching(t *testing.T) {
96- m := &Mysis{
97- activityState: ActivityStateTraveling,
98- activityUntil: time.Now().Add(30 * time.Second),
99- }
100-
101- m.clearActivityIf(ActivityStateTraveling)
102-
103- if m.activityState != ActivityStateIdle {
104- t.Errorf("Expected activity state idle after clear, got %s", m.activityState)
105- }
106-
107- if !m.activityUntil.IsZero() {
108- t.Error("Expected activityUntil cleared to zero time")
109- }
110-}
111-
112-// TestMysis_ClearActivityIf_NotMatching tests that clearing doesn't happen for wrong state.
113-func TestMysis_ClearActivityIf_NotMatching(t *testing.T) {
114- originalUntil := time.Now().Add(30 * time.Second)
115- m := &Mysis{
116- activityState: ActivityStateTraveling,
117- activityUntil: originalUntil,
118- }
119-
120- // Try to clear with different state
121- m.clearActivityIf(ActivityStateCooldown)
122-
123- // Verify state NOT cleared
124- if m.activityState != ActivityStateTraveling {
125- t.Errorf("Expected activity state unchanged (traveling), got %s", m.activityState)
126- }
127-
128- if m.activityUntil.IsZero() {
129- t.Error("Expected activityUntil unchanged, but was cleared")
130- }
131-}
132-
133-// TestMysis_SetActivity tests setting activity state.
134-func TestMysis_SetActivity(t *testing.T) {
135- m := &Mysis{
136- activityState: ActivityStateIdle,
137- activityUntil: time.Time{},
138- }
139-
140- expectedUntil := time.Now().Add(1 * time.Minute)
141- m.setActivity(ActivityStateTraveling, expectedUntil)
142-
143- if m.activityState != ActivityStateTraveling {
144- t.Errorf("Expected activity state traveling, got %s", m.activityState)
145- }
146-
147- if m.activityUntil != expectedUntil {
148- t.Errorf("Expected activityUntil %v, got %v", expectedUntil, m.activityUntil)
149- }
150-}
151-
152-// TestMysis_SetActivity_ZeroTime tests setting activity with zero time.
153-func TestMysis_SetActivity_ZeroTime(t *testing.T) {
154- m := &Mysis{
155- activityState: ActivityStateTraveling,
156- activityUntil: time.Now(),
157- }
158-
159- m.setActivity(ActivityStateIdle, time.Time{})
160-
161- if m.activityState != ActivityStateIdle {
162- t.Errorf("Expected activity state idle, got %s", m.activityState)
163- }
164-
165- if !m.activityUntil.IsZero() {
166- t.Error("Expected activityUntil to be zero time")
167- }
168-}
169-
170-// TestMysis_ShouldNudge_Concurrent tests thread safety of shouldNudge.
171-func TestMysis_ShouldNudge_Concurrent(t *testing.T) {
172- m := &Mysis{
173- activityState: ActivityStateTraveling,
174- activityUntil: time.Now().Add(1 * time.Second),
175- }
176-
177- done := make(chan bool)
178-
179- // Run multiple goroutines calling shouldNudge
180- for i := 0; i < 10; i++ {
181- go func() {
182- now := time.Now()
183- _ = m.shouldNudge(now)
184- done <- true
185- }()
186- }
187-
188- // Wait for all goroutines
189- for i := 0; i < 10; i++ {
190- <-done
191- }
192-
193- // No assertions needed - just verify no data races (run with -race)
194-}
195-
196-// TestMysis_ActivityStateTransitions tests various activity state transitions.
197-func TestMysis_ActivityStateTransitions(t *testing.T) {
198- tests := []struct {
199- name string
200- initialState ActivityState
201- initialUntil time.Time
202- nudgeTime time.Time
203- expectNudge bool
204- expectedState ActivityState
205- }{
206- {
207- name: "idle_to_idle",
208- initialState: ActivityStateIdle,
209- initialUntil: time.Time{},
210- nudgeTime: time.Now(),
211- expectNudge: true,
212- expectedState: ActivityStateIdle,
213- },
214- {
215- name: "traveling_future_no_nudge",
216- initialState: ActivityStateTraveling,
217- initialUntil: time.Now().Add(10 * time.Second),
218- nudgeTime: time.Now(),
219- expectNudge: false,
220- expectedState: ActivityStateTraveling,
221- },
222- {
223- name: "traveling_past_nudge",
224- initialState: ActivityStateTraveling,
225- initialUntil: time.Now().Add(-5 * time.Second),
226- nudgeTime: time.Now(),
227- expectNudge: true,
228- expectedState: ActivityStateIdle,
229- },
230- {
231- name: "cooldown_future_no_nudge",
232- initialState: ActivityStateCooldown,
233- initialUntil: time.Now().Add(10 * time.Second),
234- nudgeTime: time.Now(),
235- expectNudge: false,
236- expectedState: ActivityStateCooldown,
237- },
238- {
239- name: "cooldown_past_nudge",
240- initialState: ActivityStateCooldown,
241- initialUntil: time.Now().Add(-5 * time.Second),
242- nudgeTime: time.Now(),
243- expectNudge: true,
244- expectedState: ActivityStateIdle,
245- },
246- {
247- name: "mining_nudge",
248- initialState: ActivityStateMining,
249- initialUntil: time.Time{},
250- nudgeTime: time.Now(),
251- expectNudge: true,
252- expectedState: ActivityStateMining,
253- },
254- {
255- name: "combat_nudge",
256- initialState: ActivityStateInCombat,
257- initialUntil: time.Time{},
258- nudgeTime: time.Now(),
259- expectNudge: true,
260- expectedState: ActivityStateInCombat,
261- },
262- }
263-
264- for _, tt := range tests {
265- t.Run(tt.name, func(t *testing.T) {
266- m := &Mysis{
267- activityState: tt.initialState,
268- activityUntil: tt.initialUntil,
269- }
270-
271- result := m.shouldNudge(tt.nudgeTime)
272-
273- if result != tt.expectNudge {
274- t.Errorf("Expected shouldNudge()=%v, got %v", tt.expectNudge, result)
275- }
276-
277- if m.activityState != tt.expectedState {
278- t.Errorf("Expected activity state %s, got %s", tt.expectedState, m.activityState)
279- }
280- })
281- }
282-}
283-
284-// TestMysis_ActivityStateFromWaitStates tests activity state tracking from tool results.
285-func TestMysis_ActivityStateFromWaitStates(t *testing.T) {
286- // This test verifies the activity tracking logic exists and is properly
287- // integrated with the mysis lifecycle. Detailed testing of
288- // updateActivityFromToolResult is in the existing mysis_test.go file.
289-
290- m := &Mysis{}
291-
292- // Verify initial state is empty (zero value)
293- // Note: NewMysis() initializes to ActivityStateIdle, but zero value is ""
294- if m.activityState != "" {
295- t.Errorf("Expected initial activity state empty string (zero value), got %s", m.activityState)
296- }
297-
298- // Verify activityUntil is zero
299- if !m.activityUntil.IsZero() {
300- t.Error("Expected initial activityUntil to be zero time")
301- }
302-}
303-
304-// TestMysis_NudgeInterval tests the nudge interval constant is reasonable.
305-func TestMysis_NudgeInterval(t *testing.T) {
306- // Verify nudge interval is reasonable (not too short, not too long)
307- if constants.IdleNudgeInterval < 10*time.Second {
308- t.Errorf("IdleNudgeInterval too short: %v (should be >= 10s)", constants.IdleNudgeInterval)
309- }
310-
311- if constants.IdleNudgeInterval > 5*time.Minute {
312- t.Errorf("IdleNudgeInterval too long: %v (should be <= 5m)", constants.IdleNudgeInterval)
313- }
314-}
315-
316-// TestMysis_WaitStateNudgeInterval tests the wait state nudge interval constant.
317-func TestMysis_WaitStateNudgeInterval(t *testing.T) {
318- // Verify wait state interval is reasonable
319- if constants.WaitStateNudgeInterval < 30*time.Second {
320- t.Errorf("WaitStateNudgeInterval too short: %v (should be >= 30s)", constants.WaitStateNudgeInterval)
321- }
322-
323- if constants.WaitStateNudgeInterval > 10*time.Minute {
324- t.Errorf("WaitStateNudgeInterval too long: %v (should be <= 10m)", constants.WaitStateNudgeInterval)
325- }
326-}
327-
328-// Note: TestMysis_ShouldNudge_Traveling_InFuture and TestMysis_ShouldNudge_Cooldown_Active
329-// conflict with TestMysis_ActivityStateTransitions which expects shouldNudge()=false during
330-// active travel/cooldown. The comprehensive activity state tests are authoritative.
331-// These individual tests need review and possible removal.