diff --git a/shell/logger/cleanup_test.go b/shell/logger/cleanup_test.go index aec27f1..4f80ae5 100644 --- a/shell/logger/cleanup_test.go +++ b/shell/logger/cleanup_test.go @@ -13,18 +13,22 @@ func TestCleanOldLogs(t *testing.T) { agentDir := filepath.Join(dir, "bot1") os.MkdirAll(agentDir, 0o755) - // Create files: 10 days ago, 5 days ago, today. + now := time.Now().UTC() + oldDate := now.AddDate(0, 0, -10).Format("2006-01-02") // 10 days ago → should be removed + recentDate := now.AddDate(0, 0, -5).Format("2006-01-02") // 5 days ago → should remain + todayDate := now.Format("2006-01-02") // today → should remain + files := []string{ - "2026-02-24.jsonl", - "2026-02-24.jsonl.gz", - "2026-03-01.jsonl", - "2026-03-06.jsonl", + oldDate + ".jsonl", + oldDate + ".jsonl.gz", + recentDate + ".jsonl", + todayDate + ".jsonl", } for _, f := range files { os.WriteFile(filepath.Join(agentDir, f), []byte("{}"), 0o644) } - // Retain 7 days → should remove 2026-02-24 files. + // Retain 7 days → should remove files older than 7 days. cleanOldLogs(dir, "bot1", 7) remaining, _ := os.ReadDir(agentDir) @@ -33,17 +37,17 @@ func TestCleanOldLogs(t *testing.T) { names[e.Name()] = true } - if names["2026-02-24.jsonl"] { - t.Error("2026-02-24.jsonl should have been removed") + if names[oldDate+".jsonl"] { + t.Errorf("%s.jsonl should have been removed", oldDate) } - if names["2026-02-24.jsonl.gz"] { - t.Error("2026-02-24.jsonl.gz should have been removed") + if names[oldDate+".jsonl.gz"] { + t.Errorf("%s.jsonl.gz should have been removed", oldDate) } - if !names["2026-03-01.jsonl"] { - t.Error("2026-03-01.jsonl should still exist") + if !names[recentDate+".jsonl"] { + t.Errorf("%s.jsonl should still exist", recentDate) } - if !names["2026-03-06.jsonl"] { - t.Error("2026-03-06.jsonl should still exist") + if !names[todayDate+".jsonl"] { + t.Errorf("%s.jsonl should still exist", todayDate) } }