TestLoop_LastOutputTimeUpdated tests that lastOutputTime is updated on each scanner output.
(t *testing.T)
| 605 | |
| 606 | // TestLoop_LastOutputTimeUpdated tests that lastOutputTime is updated on each scanner output. |
| 607 | func TestLoop_LastOutputTimeUpdated(t *testing.T) { |
| 608 | l := NewLoop("/test/prd.json", "test", 5, testProvider) |
| 609 | l.iteration = 1 |
| 610 | |
| 611 | // Drain events to avoid blocking |
| 612 | go func() { |
| 613 | for range l.Events() { |
| 614 | } |
| 615 | }() |
| 616 | |
| 617 | // Record initial time |
| 618 | l.mu.Lock() |
| 619 | l.lastOutputTime = time.Now().Add(-1 * time.Hour) // Set to an old time |
| 620 | initialTime := l.lastOutputTime |
| 621 | l.mu.Unlock() |
| 622 | |
| 623 | // Send output through processOutput |
| 624 | r, w, _ := os.Pipe() |
| 625 | go func() { |
| 626 | w.WriteString(`{"type":"assistant","message":{"content":[{"type":"text","text":"hello"}]}}` + "\n") |
| 627 | time.Sleep(50 * time.Millisecond) |
| 628 | w.WriteString(`{"type":"assistant","message":{"content":[{"type":"text","text":"world"}]}}` + "\n") |
| 629 | w.Close() |
| 630 | }() |
| 631 | |
| 632 | l.processOutput(r) |
| 633 | close(l.events) |
| 634 | |
| 635 | // Verify lastOutputTime was updated |
| 636 | l.mu.Lock() |
| 637 | finalTime := l.lastOutputTime |
| 638 | l.mu.Unlock() |
| 639 | |
| 640 | if !finalTime.After(initialTime) { |
| 641 | t.Errorf("Expected lastOutputTime to be updated after output, initial=%v, final=%v", initialTime, finalTime) |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | // TestLoop_WatchdogReturnsError tests that watchdog kill causes runIteration to return an error |
| 646 | // that feeds into retry logic. |
nothing calls this directly
no test coverage detected