From df7518cf54acdd795fff5e7f911ca2d3a845c494 Mon Sep 17 00:00:00 2001 From: Enmanuel Date: Thu, 9 Apr 2026 20:19:17 +0000 Subject: [PATCH] fix: usar fechas relativas en TestCleanOldLogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las fechas hardcoded (2026-02-24, 2026-03-01, 2026-03-06) quedaron fuera del periodo de retención de 7 días al avanzar el calendario. Ahora el test calcula las fechas relativas a time.Now() para que no caduque. Co-Authored-By: Claude Opus 4.6 (1M context) --- shell/logger/cleanup_test.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) 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) } }