60255
Zn
Zoea-Nova / files
Zoea-Nova / internal / tui / integration_test.go
43.5 KB
1package tui 2 3// Integration tests for Zoea Nova TUI using teatest. 4// 5// These tests cover: 6// - Navigation & view switching (dashboard, focus, help) 7// - Input modes (broadcast, message, new mysis, configure) 8// - Window resize and viewport scrolling 9// - Async event handling (mysis state changes, broadcasts) 10// - Complex interaction flows 11// 12// Test Pattern: 13// 1. Setup model and create test data 14// 2. Create teatest model with initial term size 15// 3. Wait for initial render (WaitFor with dashboard/content check) 16// 4. Send input keys 17// 5. Wait briefly for model updates (time.Sleep) 18// 6. Send quit command ('q') to exit cleanly 19// 7. Verify final model state with FinalModel() 20 21import ( 22 "bytes" 23 "fmt" 24 "strings" 25 "testing" 26 "time" 27 28 tea "github.com/charmbracelet/bubbletea" 29 "github.com/charmbracelet/x/exp/teatest" 30) 31 32func quitAndFinalModel(t *testing.T, tm *teatest.TestModel, timeout time.Duration) Model { 33 t.Helper() 34 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}}) 35 fm := tm.FinalModel(t, teatest.WithFinalTimeout(timeout)) 36 return fm.(Model) 37} 38 39func programQuitAndFinalModel(t *testing.T, tm *teatest.TestModel, timeout time.Duration) Model { 40 t.Helper() 41 _ = tm.Quit() 42 fm := tm.FinalModel(t, teatest.WithFinalTimeout(timeout)) 43 return fm.(Model) 44} 45 46// TestIntegration_DashboardNavigation tests up/down key navigation in dashboard 47func TestIntegration_DashboardNavigation(t *testing.T) { 48 m, cleanup := setupTestModel(t) 49 defer cleanup() 50 51 // Create two myses for navigation 52 m.commander.CreateMysis("mysis-1", "ollama-qwen") 53 m.commander.CreateMysis("mysis-2", "ollama-qwen") 54 m.refreshMysisList() 55 56 // Initial state: selectedIdx should be 0 57 if m.selectedIdx != 0 { 58 t.Fatalf("initial selectedIdx = %d, want 0", m.selectedIdx) 59 } 60 61 tm := teatest.NewTestModel( 62 t, 63 m, 64 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 65 ) 66 defer tm.Quit() 67 68 // Wait for initial render 69 teatest.WaitFor( 70 t, 71 tm.Output(), 72 func(bts []byte) bool { 73 return bytes.Contains(bts, []byte("MYSIS SWARM")) 74 }, 75 teatest.WithCheckInterval(50*time.Millisecond), 76 teatest.WithDuration(2*time.Second), 77 ) 78 79 // Send down key 80 tm.Send(tea.KeyMsg{Type: tea.KeyDown}) 81 82 // Small delay for model update 83 time.Sleep(200 * time.Millisecond) 84 85 // Send quit to exit cleanly 86 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 87 if finalModel.selectedIdx != 1 { 88 t.Errorf("after down key: selectedIdx = %d, want 1", finalModel.selectedIdx) 89 } 90} 91 92// TestIntegration_DashboardNavigationUp tests up key navigation 93func TestIntegration_DashboardNavigationUp(t *testing.T) { 94 m, cleanup := setupTestModel(t) 95 defer cleanup() 96 97 // Create two myses 98 m.commander.CreateMysis("mysis-1", "ollama-qwen") 99 m.commander.CreateMysis("mysis-2", "ollama-qwen") 100 m.refreshMysisList() 101 m.selectedIdx = 1 // Start at second mysis 102 103 tm := teatest.NewTestModel( 104 t, 105 m, 106 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 107 ) 108 defer tm.Quit() 109 110 // Send up key 111 tm.Send(tea.KeyMsg{Type: tea.KeyUp}) 112 113 // Small delay for update 114 time.Sleep(100 * time.Millisecond) 115 116 // Verify selection moved up 117 finalModel := quitAndFinalModel(t, tm, time.Second) 118 if finalModel.selectedIdx != 0 { 119 t.Errorf("after up key: selectedIdx = %d, want 0", finalModel.selectedIdx) 120 } 121} 122 123// TestIntegration_FocusViewTransition tests Enter to focus and Esc to return 124func TestIntegration_FocusViewTransition(t *testing.T) { 125 m, cleanup := setupTestModel(t) 126 defer cleanup() 127 128 // Create a mysis 129 _, _ = m.commander.CreateMysis("test-mysis", "ollama-qwen") 130 m.refreshMysisList() 131 132 tm := teatest.NewTestModel( 133 t, 134 m, 135 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 136 ) 137 defer tm.Quit() 138 139 // Press Enter to focus 140 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 141 142 // Wait for focus view to appear 143 teatest.WaitFor( 144 t, 145 tm.Output(), 146 func(bts []byte) bool { 147 return bytes.Contains(bts, []byte("CONVERSATION LOG")) 148 }, 149 teatest.WithDuration(2*time.Second), 150 ) 151 152 // Press Escape to return to dashboard 153 tm.Send(tea.KeyMsg{Type: tea.KeyEsc}) 154 155 // Wait for dashboard view 156 teatest.WaitFor( 157 t, 158 tm.Output(), 159 func(bts []byte) bool { 160 return bytes.Contains(bts, []byte("MYSIS SWARM")) 161 }, 162 teatest.WithDuration(2*time.Second), 163 ) 164 165 // Verify returned to dashboard 166 finalModel := quitAndFinalModel(t, tm, time.Second) 167 if finalModel.view != ViewDashboard { 168 t.Errorf("after Escape: view = %d, want ViewDashboard (%d)", finalModel.view, ViewDashboard) 169 } 170 if finalModel.focusID != "" { 171 t.Errorf("after Escape: focusID = %s, want empty", finalModel.focusID) 172 } 173} 174 175// TestIntegration_HelpToggle tests ? key toggles help 176func TestIntegration_HelpToggle(t *testing.T) { 177 m, cleanup := setupTestModel(t) 178 defer cleanup() 179 180 tm := teatest.NewTestModel( 181 t, 182 m, 183 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 184 ) 185 defer tm.Quit() 186 187 // Press ? to show help 188 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) 189 190 // Wait for help to appear in output 191 teatest.WaitFor( 192 t, 193 tm.Output(), 194 func(bts []byte) bool { 195 return bytes.Contains(bts, []byte("COMMAND REFERENCE")) 196 }, 197 teatest.WithCheckInterval(50*time.Millisecond), 198 teatest.WithDuration(2*time.Second), 199 ) 200 201 // Press ? again to hide help 202 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) 203 204 // Small delay for update 205 time.Sleep(200 * time.Millisecond) 206 207 // Verify help is hidden 208 finalModel := quitAndFinalModel(t, tm, time.Second) 209 if finalModel.showHelp { 210 t.Error("after second ? key: showHelp should be false") 211 } 212} 213 214// TestIntegration_BroadcastInput tests 'b' key, type message, Enter sends 215func TestIntegration_BroadcastInput(t *testing.T) { 216 m, cleanup := setupTestModel(t) 217 defer cleanup() 218 219 // Create a running mysis to receive broadcast 220 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 221 m.commander.StartMysis(mysis.ID()) 222 m.refreshMysisList() 223 224 tm := teatest.NewTestModel( 225 t, 226 m, 227 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 228 ) 229 defer tm.Quit() 230 231 // Press 'b' to start broadcast input 232 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'b'}}) 233 234 // Wait for input prompt 235 teatest.WaitFor( 236 t, 237 tm.Output(), 238 func(bts []byte) bool { 239 return bytes.Contains(bts, []byte("BROADCAST")) 240 }, 241 teatest.WithDuration(2*time.Second), 242 ) 243 244 // Type message characters 245 testMessage := "Hello swarm" 246 for _, r := range testMessage { 247 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 248 } 249 250 // Press Enter to send 251 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 252 253 // Allow model to process broadcast and reset input 254 time.Sleep(200 * time.Millisecond) 255 256 // Verify input cleared 257 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 258 if finalModel.input.IsActive() { 259 t.Error("after Enter: input should be inactive") 260 } 261} 262 263// TestIntegration_MessageInput tests 'm' key, type message, Enter sends 264func TestIntegration_MessageInput(t *testing.T) { 265 m, cleanup := setupTestModel(t) 266 defer cleanup() 267 268 // Create a mysis 269 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 270 m.commander.StartMysis(mysis.ID()) 271 m.refreshMysisList() 272 273 tm := teatest.NewTestModel( 274 t, 275 m, 276 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 277 ) 278 defer tm.Quit() 279 280 // Press 'm' to start message input 281 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'m'}}) 282 283 // Wait for input prompt 284 teatest.WaitFor( 285 t, 286 tm.Output(), 287 func(bts []byte) bool { 288 return bytes.Contains(bts, []byte("Message to mysis")) 289 }, 290 teatest.WithDuration(2*time.Second), 291 ) 292 293 // Type message 294 testMessage := "Test message" 295 for _, r := range testMessage { 296 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 297 } 298 299 // Press Enter to send 300 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 301 302 // Wait for completion 303 teatest.WaitFor( 304 t, 305 tm.Output(), 306 func(bts []byte) bool { 307 return !bytes.Contains(bts, []byte("Message to mysis")) 308 }, 309 teatest.WithDuration(3*time.Second), 310 ) 311 312 // Verify input cleared 313 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 314 if finalModel.input.IsActive() { 315 t.Error("after Enter: input should be inactive") 316 } 317} 318 319// TestIntegration_NewMysisInput tests 'n' key, type name, Enter creates 320func TestIntegration_NewMysisInput(t *testing.T) { 321 // Skipped: E2E test with teatest is timing-sensitive and flaky. 322 // Functionality is covered by unit tests: TestMysisCreation_TwoStageFlow 323 t.Skip("Flaky E2E test - covered by unit tests") 324 m, cleanup := setupTestModel(t) 325 defer cleanup() 326 327 tm := teatest.NewTestModel( 328 t, 329 m, 330 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 331 ) 332 defer tm.Quit() 333 334 // Press 'n' to start new mysis input 335 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}}) 336 337 // Wait for input prompt 338 teatest.WaitFor( 339 t, 340 tm.Output(), 341 func(bts []byte) bool { 342 return bytes.Contains(bts, []byte("NEW MYSIS")) 343 }, 344 teatest.WithDuration(2*time.Second), 345 ) 346 347 // Type mysis name 348 mysisName := "new-mysis" 349 for _, r := range mysisName { 350 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 351 } 352 353 // Press Enter to create 354 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 355 356 // Wait for mysis to appear 357 teatest.WaitFor( 358 t, 359 tm.Output(), 360 func(bts []byte) bool { 361 return bytes.Contains(bts, []byte(mysisName)) 362 }, 363 teatest.WithDuration(3*time.Second), 364 ) 365 366 // Verify mysis was created 367 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 368 if len(finalModel.myses) != 1 { 369 t.Errorf("after creating mysis: myses count = %d, want 1", len(finalModel.myses)) 370 } 371 if len(finalModel.myses) > 0 && finalModel.myses[0].Name != mysisName { 372 t.Errorf("after creating mysis: name = %s, want %s", finalModel.myses[0].Name, mysisName) 373 } 374} 375 376// TestIntegration_ConfigProviderInput tests 'c' key, select provider 377func TestIntegration_ConfigProviderInput(t *testing.T) { 378 m, cleanup := setupTestModel(t) 379 defer cleanup() 380 381 // Create a mysis 382 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 383 mysisID := mysis.ID() 384 m.refreshMysisList() 385 386 tm := teatest.NewTestModel( 387 t, 388 m, 389 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 390 ) 391 defer tm.Quit() 392 393 // Press 'c' to start config input 394 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}}) 395 396 // Wait for config prompt 397 teatest.WaitFor( 398 t, 399 tm.Output(), 400 func(bts []byte) bool { 401 return bytes.Contains(bts, []byte("Enter provider")) 402 }, 403 teatest.WithDuration(2*time.Second), 404 ) 405 406 // Verify input mode 407 finalModel := programQuitAndFinalModel(t, tm, time.Second) 408 if finalModel.input.Mode() != InputModeConfigProvider { 409 t.Errorf("after 'c' key: input mode = %d, want InputModeConfigProvider (%d)", finalModel.input.Mode(), InputModeConfigProvider) 410 } 411 if finalModel.input.TargetID() != mysisID { 412 t.Errorf("after 'c' key: target ID = %s, want %s", finalModel.input.TargetID(), mysisID) 413 } 414} 415 416// TestIntegration_ConfigModelInput tests continue from provider, set model 417func TestIntegration_ConfigModelInput(t *testing.T) { 418 m, cleanup := setupTestModel(t) 419 defer cleanup() 420 421 // Create a mysis 422 _, _ = m.commander.CreateMysis("mysis-1", "ollama-qwen") 423 m.refreshMysisList() 424 425 tm := teatest.NewTestModel( 426 t, 427 m, 428 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 429 ) 430 defer tm.Quit() 431 432 // Press 'c' to start config input 433 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}}) 434 435 // Wait for config prompt 436 teatest.WaitFor( 437 t, 438 tm.Output(), 439 func(bts []byte) bool { 440 return bytes.Contains(bts, []byte("Enter provider")) 441 }, 442 teatest.WithDuration(2*time.Second), 443 ) 444 445 // Type provider name 446 provider := "ollama-qwen" 447 for _, r := range provider { 448 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 449 } 450 451 // Press Enter to continue to model 452 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 453 454 // Wait for model prompt 455 teatest.WaitFor( 456 t, 457 tm.Output(), 458 func(bts []byte) bool { 459 return bytes.Contains(bts, []byte("Enter model name")) 460 }, 461 teatest.WithDuration(2*time.Second), 462 ) 463 464 // Type model name 465 modelName := "test-model" 466 for _, r := range modelName { 467 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 468 } 469 470 // Press Enter to save config 471 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 472 473 // Wait for config to complete 474 teatest.WaitFor( 475 t, 476 tm.Output(), 477 func(bts []byte) bool { 478 return !bytes.Contains(bts, []byte("Enter model name")) 479 }, 480 teatest.WithDuration(2*time.Second), 481 ) 482 483 // Verify input cleared and pendingProvider cleared 484 finalModel := quitAndFinalModel(t, tm, time.Second) 485 if finalModel.input.IsActive() { 486 t.Error("after model input: input should be inactive") 487 } 488 if finalModel.pendingProvider != "" { 489 t.Errorf("after model input: pendingProvider = %s, want empty", finalModel.pendingProvider) 490 } 491} 492 493// TestIntegration_InputCancel tests Esc cancels input mode 494func TestIntegration_InputCancel(t *testing.T) { 495 m, cleanup := setupTestModel(t) 496 defer cleanup() 497 498 tm := teatest.NewTestModel( 499 t, 500 m, 501 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 502 ) 503 defer tm.Quit() 504 505 // Press 'b' to start broadcast input 506 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'b'}}) 507 508 // Wait for input to activate 509 teatest.WaitFor( 510 t, 511 tm.Output(), 512 func(bts []byte) bool { 513 return bytes.Contains(bts, []byte("BROADCAST")) 514 }, 515 teatest.WithDuration(2*time.Second), 516 ) 517 518 // Type some text 519 for _, r := range "test" { 520 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 521 } 522 523 // Press Escape to cancel 524 tm.Send(tea.KeyMsg{Type: tea.KeyEsc}) 525 526 // Wait for input to clear 527 teatest.WaitFor( 528 t, 529 tm.Output(), 530 func(bts []byte) bool { 531 return !bytes.Contains(bts, []byte("BROADCAST")) 532 }, 533 teatest.WithDuration(2*time.Second), 534 ) 535 536 // Verify input was cancelled 537 finalModel := quitAndFinalModel(t, tm, time.Second) 538 if finalModel.input.IsActive() { 539 t.Error("after Escape: input should be inactive") 540 } 541 if finalModel.input.Value() != "" { 542 t.Errorf("after Escape: input value = %s, want empty", finalModel.input.Value()) 543 } 544} 545 546// TestIntegration_ViewportScroll tests scrolling in focus view 547func TestIntegration_ViewportScroll(t *testing.T) { 548 m, cleanup := setupTestModel(t) 549 defer cleanup() 550 551 // Create a mysis and add some messages 552 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 553 m.commander.StartMysis(mysis.ID()) 554 555 // Add enough messages to require scrolling 556 for i := 0; i < 20; i++ { 557 m.commander.SendMessage(mysis.ID(), "Test message "+string(rune('A'+i))) 558 } 559 560 m.refreshMysisList() 561 m.focusID = mysis.ID() 562 m.view = ViewFocus 563 m.loadMysisLogs() 564 565 tm := teatest.NewTestModel( 566 t, 567 m, 568 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 569 ) 570 defer tm.Quit() 571 572 // Scroll down to bottom first (since auto-scroll was removed, viewport starts at top) 573 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'G'}}) 574 575 // Wait for scroll 576 teatest.WaitFor( 577 t, 578 tm.Output(), 579 func(bts []byte) bool { 580 return len(bts) > 0 581 }, 582 teatest.WithDuration(2*time.Second), 583 ) 584 585 // Now scroll up 586 tm.Send(tea.KeyMsg{Type: tea.KeyUp}) 587 588 // Wait for scroll 589 teatest.WaitFor( 590 t, 591 tm.Output(), 592 func(bts []byte) bool { 593 return len(bts) > 0 594 }, 595 teatest.WithDuration(2*time.Second), 596 ) 597 598 // Verify viewport scrolled up from bottom 599 finalModel := quitAndFinalModel(t, tm, time.Second) 600 if finalModel.viewport.AtBottom() && len(finalModel.logs) > finalModel.viewport.Height { 601 // If there's content to scroll and we're still at bottom, scrolling up didn't work 602 t.Error("viewport should have scrolled up from bottom") 603 } 604} 605 606// TestIntegration_ViewportBounds tests can't scroll past content 607func TestIntegration_ViewportBounds(t *testing.T) { 608 m, cleanup := setupTestModel(t) 609 defer cleanup() 610 611 // Create a mysis with minimal content 612 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 613 m.refreshMysisList() 614 m.focusID = mysis.ID() 615 m.view = ViewFocus 616 m.loadMysisLogs() 617 618 tm := teatest.NewTestModel( 619 t, 620 m, 621 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 622 ) 623 defer tm.Quit() 624 625 // Try to scroll up when at top 626 tm.Send(tea.KeyMsg{Type: tea.KeyUp}) 627 628 // Wait briefly 629 time.Sleep(100 * time.Millisecond) 630 631 // Verify didn't scroll past bounds 632 finalModel := quitAndFinalModel(t, tm, time.Second) 633 if finalModel.viewport.YOffset < 0 { 634 t.Errorf("viewport scrolled past top: YOffset = %d", finalModel.viewport.YOffset) 635 } 636 637 // Offset should not have increased beyond content 638 if len(finalModel.logs) > 0 && finalModel.viewport.YOffset > finalModel.viewportTotalLines { 639 t.Errorf("viewport scrolled past content: YOffset = %d, totalLines = %d", 640 finalModel.viewport.YOffset, finalModel.viewportTotalLines) 641 } 642} 643 644// TestIntegration_MysisStartedEvent tests event updates dashboard 645func TestIntegration_MysisStartedEvent(t *testing.T) { 646 m, cleanup := setupTestModel(t) 647 defer cleanup() 648 649 // Create a mysis in idle state 650 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 651 m.refreshMysisList() 652 653 tm := teatest.NewTestModel( 654 t, 655 m, 656 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 657 ) 658 defer tm.Quit() 659 660 // Start the mysis (this will trigger an event) 661 m.commander.StartMysis(mysis.ID()) 662 663 // Wait for state to update in output 664 teatest.WaitFor( 665 t, 666 tm.Output(), 667 func(bts []byte) bool { 668 return bytes.Contains(bts, []byte("running")) 669 }, 670 teatest.WithDuration(3*time.Second), 671 ) 672 673 // Verify mysis state updated 674 finalModel := quitAndFinalModel(t, tm, time.Second) 675 finalModel.refreshMysisList() 676 if len(finalModel.myses) > 0 && finalModel.myses[0].State != "running" { 677 t.Errorf("after start event: mysis state = %s, want running", finalModel.myses[0].State) 678 } 679} 680 681// TestIntegration_MysisStoppedEvent tests event updates dashboard 682func TestIntegration_MysisStoppedEvent(t *testing.T) { 683 m, cleanup := setupTestModel(t) 684 defer cleanup() 685 686 // Create and start a mysis 687 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 688 m.commander.StartMysis(mysis.ID()) 689 m.refreshMysisList() 690 691 tm := teatest.NewTestModel( 692 t, 693 m, 694 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 695 ) 696 defer tm.Quit() 697 698 // Stop the mysis 699 m.commander.StopMysis(mysis.ID()) 700 701 // Wait for state to update 702 teatest.WaitFor( 703 t, 704 tm.Output(), 705 func(bts []byte) bool { 706 return bytes.Contains(bts, []byte("stopped")) || bytes.Contains(bts, []byte("idle")) 707 }, 708 teatest.WithDuration(3*time.Second), 709 ) 710 711 // Verify mysis state updated 712 finalModel := quitAndFinalModel(t, tm, time.Second) 713 finalModel.refreshMysisList() 714 if len(finalModel.myses) > 0 && finalModel.myses[0].State == "running" { 715 t.Errorf("after stop event: mysis state = %s, should not be running", finalModel.myses[0].State) 716 } 717} 718 719// TestIntegration_BroadcastEvent tests event appears in swarm messages 720func TestIntegration_BroadcastEvent(t *testing.T) { 721 m, cleanup := setupTestModel(t) 722 defer cleanup() 723 724 // Create a running mysis 725 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 726 m.commander.StartMysis(mysis.ID()) 727 m.refreshMysisList() 728 729 tm := teatest.NewTestModel( 730 t, 731 m, 732 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 733 ) 734 defer tm.Quit() 735 736 // Send a broadcast 737 broadcastMsg := "Test broadcast message" 738 m.commander.Broadcast(broadcastMsg) 739 740 // Wait for broadcast to appear 741 teatest.WaitFor( 742 t, 743 tm.Output(), 744 func(bts []byte) bool { 745 return bytes.Contains(bts, []byte(broadcastMsg)) 746 }, 747 teatest.WithDuration(3*time.Second), 748 ) 749 750 // Verify broadcast appears in swarm messages 751 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 752 finalModel.refreshSwarmMessages() 753 754 found := false 755 for _, msg := range finalModel.swarmMessages { 756 if strings.Contains(msg.Content, broadcastMsg) { 757 found = true 758 break 759 } 760 } 761 if !found { 762 t.Error("broadcast message not found in swarm messages") 763 } 764} 765 766// TestIntegration_CreateAndStartMysis tests full lifecycle 767func TestIntegration_CreateAndStartMysis(t *testing.T) { 768 // Skipped: Complex E2E test with teatest is timing-sensitive and flaky. 769 // Functionality is covered by unit tests: TestMysisCreation_TwoStageFlow, TestMysisCreation_ZenNanoProvider 770 t.Skip("Flaky E2E test - covered by unit tests") 771 m, cleanup := setupTestModel(t) 772 defer cleanup() 773 774 tm := teatest.NewTestModel( 775 t, 776 m, 777 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 778 ) 779 defer tm.Quit() 780 781 // Start: press 'n' to create new mysis 782 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}}) 783 784 // Wait for input 785 teatest.WaitFor( 786 t, 787 tm.Output(), 788 func(bts []byte) bool { 789 return bytes.Contains(bts, []byte("NEW MYSIS")) 790 }, 791 teatest.WithDuration(2*time.Second), 792 ) 793 794 // Type name 795 mysisName := "lifecycle-mysis" 796 for _, r := range mysisName { 797 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 798 } 799 800 // Press Enter to create 801 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 802 803 // Wait for mysis to appear and auto-start 804 teatest.WaitFor( 805 t, 806 tm.Output(), 807 func(bts []byte) bool { 808 return bytes.Contains(bts, []byte(mysisName)) && 809 (bytes.Contains(bts, []byte("running")) || bytes.Contains(bts, []byte("idle"))) 810 }, 811 teatest.WithDuration(3*time.Second), 812 ) 813 814 // Navigate to the mysis and focus 815 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 816 817 // Wait for focus view 818 teatest.WaitFor( 819 t, 820 tm.Output(), 821 func(bts []byte) bool { 822 return bytes.Contains(bts, []byte("CONVERSATION LOG")) 823 }, 824 teatest.WithDuration(2*time.Second), 825 ) 826 827 // Verify in focus view 828 finalModel := quitAndFinalModel(t, tm, time.Second) 829 finalModel.refreshMysisList() 830 if len(finalModel.myses) != 1 { 831 t.Fatalf("expected 1 mysis, got %d", len(finalModel.myses)) 832 } 833 if finalModel.myses[0].Name != mysisName { 834 t.Errorf("mysis name = %s, want %s", finalModel.myses[0].Name, mysisName) 835 } 836 if finalModel.view != ViewFocus { 837 t.Errorf("view = %d, want ViewFocus (%d)", finalModel.view, ViewFocus) 838 } 839} 840 841// TestIntegration_MultipleKeySequence tests complex interaction 842func TestIntegration_MultipleKeySequence(t *testing.T) { 843 m, cleanup := setupTestModel(t) 844 defer cleanup() 845 846 // Create two myses 847 m.commander.CreateMysis("mysis-1", "ollama-qwen") 848 m.commander.CreateMysis("mysis-2", "ollama-qwen") 849 m.refreshMysisList() 850 851 tm := teatest.NewTestModel( 852 t, 853 m, 854 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 855 ) 856 defer tm.Quit() 857 858 // Sequence: navigate down, show help, hide help, navigate up 859 tm.Send(tea.KeyMsg{Type: tea.KeyDown}) 860 time.Sleep(100 * time.Millisecond) 861 862 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) 863 teatest.WaitFor( 864 t, 865 tm.Output(), 866 func(bts []byte) bool { 867 return bytes.Contains(bts, []byte("COMMAND REFERENCE")) 868 }, 869 teatest.WithDuration(2*time.Second), 870 ) 871 872 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'?'}}) 873 teatest.WaitFor( 874 t, 875 tm.Output(), 876 func(bts []byte) bool { 877 return !bytes.Contains(bts, []byte("COMMAND REFERENCE")) 878 }, 879 teatest.WithDuration(2*time.Second), 880 ) 881 882 tm.Send(tea.KeyMsg{Type: tea.KeyUp}) 883 884 // Verify final state: selectedIdx=0, help hidden 885 finalModel := quitAndFinalModel(t, tm, time.Second) 886 if finalModel.selectedIdx != 0 { 887 t.Errorf("after sequence: selectedIdx = %d, want 0", finalModel.selectedIdx) 888 } 889 if finalModel.showHelp { 890 t.Error("after sequence: help should be hidden") 891 } 892} 893 894// TestIntegration_VerboseToggle tests 'v' key toggles verbose JSON in focus view 895func TestIntegration_VerboseToggle(t *testing.T) { 896 m, cleanup := setupTestModel(t) 897 defer cleanup() 898 899 // Create a mysis and focus on it 900 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 901 m.refreshMysisList() 902 m.focusID = mysis.ID() 903 m.view = ViewFocus 904 m.loadMysisLogs() 905 906 tm := teatest.NewTestModel( 907 t, 908 m, 909 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 910 ) 911 defer tm.Quit() 912 913 // Initial state: verboseJSON should be false 914 if m.verboseJSON { 915 t.Error("initial verboseJSON should be false") 916 } 917 918 // Press 'v' to toggle verbose 919 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'v'}}) 920 921 // Wait for output 922 teatest.WaitFor( 923 t, 924 tm.Output(), 925 func(bts []byte) bool { 926 return len(bts) > 0 927 }, 928 teatest.WithDuration(2*time.Second), 929 ) 930 931 // Press 'v' again to toggle back 932 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'v'}}) 933 934 // Wait for output 935 teatest.WaitFor( 936 t, 937 tm.Output(), 938 func(bts []byte) bool { 939 return len(bts) > 0 940 }, 941 teatest.WithDuration(2*time.Second), 942 ) 943 944 // Verify verboseJSON toggled back 945 finalModel := quitAndFinalModel(t, tm, time.Second) 946 if finalModel.verboseJSON { 947 t.Error("after second 'v' key: verboseJSON should be false") 948 } 949} 950 951// TestIntegration_AutoScrollBehavior - REMOVED: auto-scroll functionality removed per TODO item 952// Manual scrolling still works via G/End key and arrow keys 953 954// ============================================================================ 955// Phase 10: New Integration Tests (Border, Spinner, Input, StatusBar, Resize) 956// ============================================================================ 957 958// TestIntegration_BorderRendering tests borders render correctly in dashboard and focus view 959func TestIntegration_BorderRendering(t *testing.T) { 960 t.Run("dashboard_borders_visible", func(t *testing.T) { 961 m, cleanup := setupTestModel(t) 962 defer cleanup() 963 964 // Create myses to populate the bordered list 965 m.commander.CreateMysis("mysis-1", "ollama-qwen") 966 m.commander.CreateMysis("mysis-2", "ollama-qwen") 967 m.refreshMysisList() 968 969 tm := teatest.NewTestModel( 970 t, 971 m, 972 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 973 ) 974 defer tm.Quit() 975 976 // Small delay for initial render 977 time.Sleep(100 * time.Millisecond) 978 979 // Verify model state (borders are rendered via View() method) 980 // We test that the dashboard renders correctly with borders by checking model state 981 finalModel := quitAndFinalModel(t, tm, time.Second) 982 if len(finalModel.myses) != 2 { 983 t.Errorf("expected 2 myses in bordered list, got %d", len(finalModel.myses)) 984 } 985 if finalModel.view != ViewDashboard { 986 t.Errorf("expected ViewDashboard, got view %d", finalModel.view) 987 } 988 989 // Verify View() renders borders correctly (indirect test via golden files) 990 view := finalModel.View() 991 if !strings.Contains(view, "MYSIS SWARM") { 992 t.Error("dashboard view should contain 'MYSIS SWARM' section") 993 } 994 // Border characters are rendered in the view 995 if !strings.Contains(view, "╔") && !strings.Contains(view, "═") { 996 t.Log("Warning: border characters not found in view (may be environment-dependent)") 997 } 998 }) 999 1000 t.Run("focus_view_borders_visible", func(t *testing.T) { 1001 m, cleanup := setupTestModel(t) 1002 defer cleanup() 1003 1004 // Create a mysis and focus on it 1005 mysis, _ := m.commander.CreateMysis("test-mysis", "ollama-qwen") 1006 m.refreshMysisList() 1007 m.focusID = mysis.ID() 1008 m.view = ViewFocus 1009 m.loadMysisLogs() 1010 1011 tm := teatest.NewTestModel( 1012 t, 1013 m, 1014 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1015 ) 1016 defer tm.Quit() 1017 1018 // Small delay for initial render 1019 time.Sleep(100 * time.Millisecond) 1020 1021 // Verify model state and view rendering 1022 finalModel := quitAndFinalModel(t, tm, time.Second) 1023 if finalModel.view != ViewFocus { 1024 t.Errorf("expected ViewFocus, got view %d", finalModel.view) 1025 } 1026 1027 // Verify View() renders header decorations (borders) 1028 view := finalModel.View() 1029 if !strings.Contains(view, "CONVERSATION LOG") { 1030 t.Error("focus view should contain 'CONVERSATION LOG' section") 1031 } 1032 // Header decoration characters 1033 if !strings.Contains(view, "⬥") || !strings.Contains(view, "⬡") { 1034 t.Log("Warning: header decoration characters not found in view") 1035 } 1036 }) 1037 1038 t.Run("borders_no_layout_issues", func(t *testing.T) { 1039 m, cleanup := setupTestModel(t) 1040 defer cleanup() 1041 1042 // Create multiple myses to test layout with borders 1043 for i := 0; i < 5; i++ { 1044 m.commander.CreateMysis(fmt.Sprintf("mysis-%d", i), "ollama-qwen") 1045 } 1046 m.refreshMysisList() 1047 1048 tm := teatest.NewTestModel( 1049 t, 1050 m, 1051 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1052 ) 1053 defer tm.Quit() 1054 1055 // Navigate through list to ensure borders don't cause selection issues 1056 tm.Send(tea.KeyMsg{Type: tea.KeyDown}) 1057 time.Sleep(50 * time.Millisecond) 1058 tm.Send(tea.KeyMsg{Type: tea.KeyDown}) 1059 time.Sleep(50 * time.Millisecond) 1060 tm.Send(tea.KeyMsg{Type: tea.KeyUp}) 1061 1062 // Verify navigation works correctly with borders 1063 finalModel := quitAndFinalModel(t, tm, time.Second) 1064 if finalModel.selectedIdx != 1 { 1065 t.Errorf("expected selectedIdx=1 after navigation, got %d", finalModel.selectedIdx) 1066 } 1067 }) 1068} 1069 1070// TestIntegration_SpinnerAnimation tests spinner updates during mysis execution 1071func TestIntegration_SpinnerAnimation(t *testing.T) { 1072 t.Run("spinner_updates_during_execution", func(t *testing.T) { 1073 m, cleanup := setupTestModel(t) 1074 defer cleanup() 1075 1076 // Create and start a mysis 1077 mysis, _ := m.commander.CreateMysis("running-mysis", "ollama-qwen") 1078 m.commander.StartMysis(mysis.ID()) 1079 m.refreshMysisList() 1080 1081 tm := teatest.NewTestModel( 1082 t, 1083 m, 1084 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1085 ) 1086 defer tm.Quit() 1087 1088 // Wait for initial render with running mysis 1089 teatest.WaitFor( 1090 t, 1091 tm.Output(), 1092 func(bts []byte) bool { 1093 return bytes.Contains(bts, []byte("running")) 1094 }, 1095 teatest.WithDuration(2*time.Second), 1096 ) 1097 1098 // Wait for spinner tick (spinner updates at 8 FPS = 125ms per frame) 1099 time.Sleep(300 * time.Millisecond) 1100 1101 // Note: Testing spinner animation in output is timing-dependent and fragile 1102 // We verify the spinner exists in the model instead 1103 finalModel := quitAndFinalModel(t, tm, time.Second) 1104 if len(finalModel.myses) > 0 && finalModel.myses[0].State != "running" { 1105 t.Errorf("mysis should be running, got state: %s", finalModel.myses[0].State) 1106 } 1107 // Spinner is active as long as there are running myses (verified via state) 1108 }) 1109 1110 t.Run("spinner_no_flicker", func(t *testing.T) { 1111 m, cleanup := setupTestModel(t) 1112 defer cleanup() 1113 1114 // Create a running mysis 1115 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 1116 m.commander.StartMysis(mysis.ID()) 1117 m.refreshMysisList() 1118 1119 tm := teatest.NewTestModel( 1120 t, 1121 m, 1122 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1123 ) 1124 defer tm.Quit() 1125 1126 // Wait for initial render 1127 teatest.WaitFor( 1128 t, 1129 tm.Output(), 1130 func(bts []byte) bool { 1131 return bytes.Contains(bts, []byte("running")) 1132 }, 1133 teatest.WithDuration(2*time.Second), 1134 ) 1135 1136 // Wait through multiple spinner ticks 1137 time.Sleep(500 * time.Millisecond) 1138 1139 // Verify model state remains consistent (no flicker = no unexpected state changes) 1140 finalModel := quitAndFinalModel(t, tm, time.Second) 1141 if len(finalModel.myses) == 0 { 1142 t.Fatal("mysis disappeared during spinner animation") 1143 } 1144 if finalModel.myses[0].State != "running" { 1145 t.Errorf("mysis state changed unexpectedly: %s", finalModel.myses[0].State) 1146 } 1147 }) 1148 1149 t.Run("multiple_myses_with_spinners", func(t *testing.T) { 1150 m, cleanup := setupTestModel(t) 1151 defer cleanup() 1152 1153 // Create multiple running myses 1154 for i := 0; i < 3; i++ { 1155 mysis, _ := m.commander.CreateMysis(fmt.Sprintf("mysis-%d", i), "ollama-qwen") 1156 m.commander.StartMysis(mysis.ID()) 1157 } 1158 m.refreshMysisList() 1159 1160 tm := teatest.NewTestModel( 1161 t, 1162 m, 1163 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1164 ) 1165 defer tm.Quit() 1166 1167 // Wait for all myses to render 1168 teatest.WaitFor( 1169 t, 1170 tm.Output(), 1171 func(bts []byte) bool { 1172 return bytes.Contains(bts, []byte("mysis-0")) && 1173 bytes.Contains(bts, []byte("mysis-1")) && 1174 bytes.Contains(bts, []byte("mysis-2")) 1175 }, 1176 teatest.WithDuration(2*time.Second), 1177 ) 1178 1179 // Wait for spinner updates 1180 time.Sleep(300 * time.Millisecond) 1181 1182 // Verify all myses present and running 1183 finalModel := quitAndFinalModel(t, tm, time.Second) 1184 if len(finalModel.myses) != 3 { 1185 t.Errorf("expected 3 myses, got %d", len(finalModel.myses)) 1186 } 1187 for i, mysis := range finalModel.myses { 1188 if mysis.State != "running" { 1189 t.Errorf("mysis-%d state = %s, want running", i, mysis.State) 1190 } 1191 } 1192 }) 1193} 1194 1195// TestIntegration_InputPrompt tests input prompt interactions 1196func TestIntegration_InputPrompt(t *testing.T) { 1197 t.Run("broadcast_message_entry", func(t *testing.T) { 1198 m, cleanup := setupTestModel(t) 1199 defer cleanup() 1200 1201 // Create a mysis to receive broadcast 1202 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 1203 m.commander.StartMysis(mysis.ID()) 1204 m.refreshMysisList() 1205 1206 tm := teatest.NewTestModel( 1207 t, 1208 m, 1209 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1210 ) 1211 defer tm.Quit() 1212 1213 // Press 'b' to open broadcast input 1214 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'b'}}) 1215 1216 // Wait for broadcast prompt 1217 teatest.WaitFor( 1218 t, 1219 tm.Output(), 1220 func(bts []byte) bool { 1221 return bytes.Contains(bts, []byte("BROADCAST")) || 1222 bytes.Contains(bts, []byte("Broadcasting")) 1223 }, 1224 teatest.WithDuration(2*time.Second), 1225 ) 1226 1227 // Verify input is active and in broadcast mode 1228 finalModel := programQuitAndFinalModel(t, tm, time.Second) 1229 if !finalModel.input.IsActive() { 1230 t.Error("input should be active after 'b' key") 1231 } 1232 if finalModel.input.Mode() != InputModeBroadcast { 1233 t.Errorf("input mode = %d, want InputModeBroadcast (%d)", finalModel.input.Mode(), InputModeBroadcast) 1234 } 1235 }) 1236 1237 t.Run("direct_message_entry", func(t *testing.T) { 1238 m, cleanup := setupTestModel(t) 1239 defer cleanup() 1240 1241 // Create a mysis to message 1242 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 1243 m.commander.StartMysis(mysis.ID()) 1244 m.refreshMysisList() 1245 1246 tm := teatest.NewTestModel( 1247 t, 1248 m, 1249 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1250 ) 1251 defer tm.Quit() 1252 1253 // Press 'm' to open message input 1254 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'m'}}) 1255 1256 // Wait for message prompt 1257 teatest.WaitFor( 1258 t, 1259 tm.Output(), 1260 func(bts []byte) bool { 1261 return bytes.Contains(bts, []byte("Message to mysis")) 1262 }, 1263 teatest.WithDuration(2*time.Second), 1264 ) 1265 1266 // Verify input is active and in message mode 1267 finalModel := programQuitAndFinalModel(t, tm, time.Second) 1268 if !finalModel.input.IsActive() { 1269 t.Error("input should be active after 'm' key") 1270 } 1271 if finalModel.input.Mode() != InputModeMessage { 1272 t.Errorf("input mode = %d, want InputModeMessage (%d)", finalModel.input.Mode(), InputModeMessage) 1273 } 1274 }) 1275 1276 t.Run("cancel_input_esc", func(t *testing.T) { 1277 m, cleanup := setupTestModel(t) 1278 defer cleanup() 1279 1280 tm := teatest.NewTestModel( 1281 t, 1282 m, 1283 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1284 ) 1285 defer tm.Quit() 1286 1287 // Open broadcast input 1288 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'b'}}) 1289 1290 // Wait for input to activate 1291 teatest.WaitFor( 1292 t, 1293 tm.Output(), 1294 func(bts []byte) bool { 1295 return bytes.Contains(bts, []byte("BROADCAST")) 1296 }, 1297 teatest.WithDuration(2*time.Second), 1298 ) 1299 1300 // Type some text 1301 for _, r := range "test message" { 1302 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 1303 } 1304 1305 // Cancel with Escape 1306 tm.Send(tea.KeyMsg{Type: tea.KeyEsc}) 1307 1308 // Wait for input to deactivate 1309 teatest.WaitFor( 1310 t, 1311 tm.Output(), 1312 func(bts []byte) bool { 1313 return !bytes.Contains(bts, []byte("BROADCAST")) 1314 }, 1315 teatest.WithDuration(2*time.Second), 1316 ) 1317 1318 // Verify input cleared 1319 finalModel := quitAndFinalModel(t, tm, time.Second) 1320 if finalModel.input.IsActive() { 1321 t.Error("input should be inactive after Escape") 1322 } 1323 if finalModel.input.Value() != "" { 1324 t.Errorf("input value = %q, want empty after cancel", finalModel.input.Value()) 1325 } 1326 }) 1327 1328 t.Run("submit_input_enter", func(t *testing.T) { 1329 m, cleanup := setupTestModel(t) 1330 defer cleanup() 1331 1332 // Create a running mysis 1333 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 1334 m.commander.StartMysis(mysis.ID()) 1335 m.refreshMysisList() 1336 1337 tm := teatest.NewTestModel( 1338 t, 1339 m, 1340 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1341 ) 1342 defer tm.Quit() 1343 1344 // Open broadcast input 1345 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'b'}}) 1346 1347 // Wait for input 1348 teatest.WaitFor( 1349 t, 1350 tm.Output(), 1351 func(bts []byte) bool { 1352 return bytes.Contains(bts, []byte("BROADCAST")) 1353 }, 1354 teatest.WithDuration(2*time.Second), 1355 ) 1356 1357 // Type message 1358 testMsg := "Hello" 1359 for _, r := range testMsg { 1360 tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) 1361 } 1362 1363 // Submit with Enter 1364 tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) 1365 1366 // Wait for input to clear 1367 time.Sleep(200 * time.Millisecond) 1368 1369 // Verify input cleared after submit 1370 finalModel := quitAndFinalModel(t, tm, 2*time.Second) 1371 if finalModel.input.IsActive() { 1372 t.Error("input should be inactive after Enter submit") 1373 } 1374 }) 1375} 1376 1377// TestIntegration_StatusBar tests status bar updates 1378func TestIntegration_StatusBar(t *testing.T) { 1379 t.Run("status_bar_mysis_state_changes", func(t *testing.T) { 1380 m, cleanup := setupTestModel(t) 1381 defer cleanup() 1382 1383 // Create a mysis 1384 mysis, _ := m.commander.CreateMysis("mysis-1", "ollama-qwen") 1385 m.refreshMysisList() 1386 1387 tm := teatest.NewTestModel( 1388 t, 1389 m, 1390 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1391 ) 1392 defer tm.Quit() 1393 1394 // Wait for initial render (idle state - should show idle count or no myses) 1395 teatest.WaitFor( 1396 t, 1397 tm.Output(), 1398 func(bts []byte) bool { 1399 // Check for either state icons or "(no myses)" text 1400 return bytes.Contains(bts, []byte("◦")) || bytes.Contains(bts, []byte("(no myses)")) 1401 }, 1402 teatest.WithDuration(2*time.Second), 1403 ) 1404 1405 // Start the mysis 1406 m.commander.StartMysis(mysis.ID()) 1407 1408 // Wait for status bar to update (should show 1 running) 1409 teatest.WaitFor( 1410 t, 1411 tm.Output(), 1412 func(bts []byte) bool { 1413 return bytes.Contains(bts, []byte("running")) 1414 }, 1415 teatest.WithDuration(3*time.Second), 1416 ) 1417 1418 finalModel := quitAndFinalModel(t, tm, time.Second) 1419 finalModel.refreshMysisList() 1420 if len(finalModel.myses) > 0 && finalModel.myses[0].State != "running" { 1421 t.Errorf("status bar should reflect running state, got %s", finalModel.myses[0].State) 1422 } 1423 }) 1424 1425 t.Run("status_bar_network_indicator", func(t *testing.T) { 1426 m, cleanup := setupTestModel(t) 1427 defer cleanup() 1428 1429 tm := teatest.NewTestModel( 1430 t, 1431 m, 1432 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1433 ) 1434 defer tm.Quit() 1435 1436 // Small delay for initial render 1437 time.Sleep(100 * time.Millisecond) 1438 1439 // Verify status bar rendering via View() method 1440 finalModel := quitAndFinalModel(t, tm, time.Second) 1441 view := finalModel.View() 1442 1443 // Status bar should show tick timestamp in format T#### ⬡ [HH:MM] 1444 if !strings.Contains(view, "T") || !strings.Contains(view, "[") || !strings.Contains(view, "]") { 1445 t.Error("status bar should contain tick timestamp format (T#### ⬡ [HH:MM])") 1446 } 1447 // Status bar should show activity indicator (IDLE/LLM/MCP) 1448 if !strings.Contains(view, "IDLE") && !strings.Contains(view, "LLM") && !strings.Contains(view, "MCP") { 1449 t.Error("status bar should contain activity indicator (IDLE/LLM/MCP)") 1450 } 1451 }) 1452 1453 t.Run("status_bar_state_counts_update", func(t *testing.T) { 1454 m, cleanup := setupTestModel(t) 1455 defer cleanup() 1456 1457 // Create a mysis 1458 _, _ = m.commander.CreateMysis("test-mysis", "ollama-qwen") 1459 m.refreshMysisList() 1460 1461 // Render status bar directly 1462 statusBar := m.renderStatusBar() 1463 1464 // Should contain tick timestamp format 1465 if !strings.Contains(statusBar, "T") || !strings.Contains(statusBar, "⬡") { 1466 t.Error("status bar should contain tick timestamp (T#### ⬡ [HH:MM])") 1467 } 1468 1469 // Should contain activity indicator 1470 if !strings.Contains(statusBar, "IDLE") && !strings.Contains(statusBar, "LLM") && !strings.Contains(statusBar, "MCP") { 1471 t.Error("status bar should contain activity indicator") 1472 } 1473 1474 // Should contain state count (idle mysis) 1475 if !strings.Contains(statusBar, "◦") { 1476 t.Error("status bar should contain idle state icon (◦)") 1477 } 1478 }) 1479} 1480 1481// TestIntegration_WindowResize tests window resize handling 1482func TestIntegration_WindowResize(t *testing.T) { 1483 t.Run("resize_during_dashboard", func(t *testing.T) { 1484 m, cleanup := setupTestModel(t) 1485 defer cleanup() 1486 1487 // Create myses to populate dashboard 1488 m.commander.CreateMysis("mysis-1", "ollama-qwen") 1489 m.commander.CreateMysis("mysis-2", "ollama-qwen") 1490 m.refreshMysisList() 1491 1492 tm := teatest.NewTestModel( 1493 t, 1494 m, 1495 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1496 ) 1497 defer tm.Quit() 1498 1499 // Wait for initial render 1500 teatest.WaitFor( 1501 t, 1502 tm.Output(), 1503 func(bts []byte) bool { 1504 return bytes.Contains(bts, []byte("MYSIS SWARM")) 1505 }, 1506 teatest.WithDuration(2*time.Second), 1507 ) 1508 1509 // Resize to larger 1510 newWidth := 160 1511 newHeight := 50 1512 tm.Send(tea.WindowSizeMsg{Width: newWidth, Height: newHeight}) 1513 1514 // Wait for resize to process 1515 time.Sleep(200 * time.Millisecond) 1516 1517 // Verify dimensions updated 1518 finalModel := quitAndFinalModel(t, tm, time.Second) 1519 if finalModel.width != newWidth { 1520 t.Errorf("width = %d, want %d after resize", finalModel.width, newWidth) 1521 } 1522 if finalModel.height != newHeight { 1523 t.Errorf("height = %d, want %d after resize", finalModel.height, newHeight) 1524 } 1525 }) 1526 1527 t.Run("resize_during_focus_view", func(t *testing.T) { 1528 m, cleanup := setupTestModel(t) 1529 defer cleanup() 1530 1531 // Create a mysis and focus on it 1532 mysis, _ := m.commander.CreateMysis("test-mysis", "ollama-qwen") 1533 m.refreshMysisList() 1534 m.focusID = mysis.ID() 1535 m.view = ViewFocus 1536 m.loadMysisLogs() 1537 1538 tm := teatest.NewTestModel( 1539 t, 1540 m, 1541 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1542 ) 1543 defer tm.Quit() 1544 1545 // Wait for focus view 1546 teatest.WaitFor( 1547 t, 1548 tm.Output(), 1549 func(bts []byte) bool { 1550 return bytes.Contains(bts, []byte("CONVERSATION LOG")) 1551 }, 1552 teatest.WithDuration(2*time.Second), 1553 ) 1554 1555 // Resize to smaller 1556 newWidth := 100 1557 newHeight := 30 1558 tm.Send(tea.WindowSizeMsg{Width: newWidth, Height: newHeight}) 1559 1560 // Wait for resize 1561 time.Sleep(200 * time.Millisecond) 1562 1563 // Verify dimensions and viewport updated 1564 finalModel := quitAndFinalModel(t, tm, time.Second) 1565 if finalModel.width != newWidth { 1566 t.Errorf("width = %d, want %d after resize", finalModel.width, newWidth) 1567 } 1568 if finalModel.height != newHeight { 1569 t.Errorf("height = %d, want %d after resize", finalModel.height, newHeight) 1570 } 1571 // Viewport should have been recreated with new dimensions 1572 if finalModel.viewport.Width == TestTerminalWidth { 1573 t.Error("viewport width should have changed after resize") 1574 } 1575 }) 1576 1577 t.Run("layout_recalculates_correctly", func(t *testing.T) { 1578 m, cleanup := setupTestModel(t) 1579 defer cleanup() 1580 1581 // Create myses 1582 for i := 0; i < 3; i++ { 1583 m.commander.CreateMysis(fmt.Sprintf("mysis-%d", i), "ollama-qwen") 1584 } 1585 m.refreshMysisList() 1586 1587 tm := teatest.NewTestModel( 1588 t, 1589 m, 1590 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1591 ) 1592 defer tm.Quit() 1593 1594 // Initial render 1595 teatest.WaitFor( 1596 t, 1597 tm.Output(), 1598 func(bts []byte) bool { 1599 return bytes.Contains(bts, []byte("mysis-0")) 1600 }, 1601 teatest.WithDuration(2*time.Second), 1602 ) 1603 1604 // Resize multiple times 1605 sizes := []struct{ w, h int }{ 1606 {140, 45}, 1607 {100, 35}, 1608 {120, 40}, 1609 } 1610 1611 for _, size := range sizes { 1612 tm.Send(tea.WindowSizeMsg{Width: size.w, Height: size.h}) 1613 time.Sleep(100 * time.Millisecond) 1614 } 1615 1616 // Verify final dimensions 1617 finalModel := quitAndFinalModel(t, tm, time.Second) 1618 if finalModel.width != 120 { 1619 t.Errorf("width = %d, want 120 after resize sequence", finalModel.width) 1620 } 1621 if finalModel.height != 40 { 1622 t.Errorf("height = %d, want 40 after resize sequence", finalModel.height) 1623 } 1624 // Myses should still be present and navigable 1625 if len(finalModel.myses) != 3 { 1626 t.Errorf("myses count = %d, want 3 after resizes", len(finalModel.myses)) 1627 } 1628 }) 1629 1630 t.Run("minimum_size_handling", func(t *testing.T) { 1631 m, cleanup := setupTestModel(t) 1632 defer cleanup() 1633 1634 tm := teatest.NewTestModel( 1635 t, 1636 m, 1637 teatest.WithInitialTermSize(TestTerminalWidth, TestTerminalHeight), 1638 ) 1639 defer tm.Quit() 1640 1641 // Resize to below minimum (80x20) 1642 tm.Send(tea.WindowSizeMsg{Width: 60, Height: 15}) 1643 1644 // Wait for resize 1645 time.Sleep(200 * time.Millisecond) 1646 1647 // Verify model updated dimensions (even if too small) 1648 finalModel := quitAndFinalModel(t, tm, time.Second) 1649 if finalModel.width != 60 { 1650 t.Errorf("width = %d, want 60 (model should store actual size)", finalModel.width) 1651 } 1652 if finalModel.height != 15 { 1653 t.Errorf("height = %d, want 15 (model should store actual size)", finalModel.height) 1654 } 1655 // View method should detect small size and show warning 1656 // (This is tested via rendering, not model state) 1657 }) 1658}