package api import ( "net/http" "net/http/httptest" "os" "path/filepath" "testing" "github.com/go-chi/chi/v5" "github.com/will/k8s-agent-dashboard/internal/claude" ) type fakeClaudeDirLoader struct{ dir string } func (f fakeClaudeDirLoader) ClaudeDir() string { return f.dir } func (f fakeClaudeDirLoader) LoadStatsCache() (*claude.StatsCache, error) { return &claude.StatsCache{}, nil } func (f fakeClaudeDirLoader) ListDir(name string) ([]claude.DirEntry, error) { return nil, nil } func (f fakeClaudeDirLoader) FileMeta(relPath string) (claude.FileMeta, error) { return claude.FileMeta{}, nil } func (f fakeClaudeDirLoader) PathExists(relPath string) bool { return true } func TestClaudeLiveBacklog_DefaultLimit(t *testing.T) { dir := t.TempDir() p := filepath.Join(dir, "history.jsonl") if err := os.WriteFile(p, []byte("{\"display\":\"/model\"}\n"), 0o600); err != nil { t.Fatalf("write: %v", err) } loader := fakeClaudeDirLoader{dir: dir} r := chi.NewRouter() r.Get("/api/claude/live/backlog", GetClaudeLiveBacklog(loader)) req := httptest.NewRequest(http.MethodGet, "/api/claude/live/backlog", nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Fatalf("status=%d body=%s", w.Code, w.Body.String()) } if !jsonContainsKey(w.Body.String(), "events") { t.Fatalf("expected events in response: %s", w.Body.String()) } }