Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Detect test log rotation by size, not os.SameFile

shukieshahb315febec6bc
diff --git a/cli/beacon/internal/endpoint/dashboard/history_test.go b/cli/beacon/internal/endpoint/dashboard/history_test.go
index 2e4e3878..164017ed 100644
--- a/cli/beacon/internal/endpoint/dashboard/history_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/history_test.go
@@ -455,14 +455,20 @@ func (r *rotatingLog) append(t *testing.T, n int) {
}
}
-// appendRotations appends events until the log has rotated exactly n more times.
+// appendRotations appends events until the log has rotated exactly n more times. A rotation is
+// seen as the live file shrinking: it only grows until the writer renames it away. (os.SameFile
+// cannot tell here on Windows, where it resolves both paths' file IDs when it compares them, after
+// the rename, and so always reports the same file.)
func (r *rotatingLog) appendRotations(t *testing.T, n int) {
t.Helper()
- for rotated := 0; rotated < n; {
+ for rotated, appended := 0, 0; rotated < n; appended++ {
+ if appended > 10000 {
+ t.Fatalf("log rotated %d times in %d appends, want %d", rotated, appended, n)
+ }
before, beforeErr := os.Stat(r.path)
r.append(t, 1)
after, afterErr := os.Stat(r.path)
- if beforeErr == nil && afterErr == nil && !os.SameFile(before, after) {
+ if beforeErr == nil && afterErr == nil && after.Size() < before.Size() {
rotated++
}
}
@@ -493,6 +499,9 @@ func TestHistoryFollowsTheLogAcrossRotation(t *testing.T) {
t.Fatal(err)
}
}
+ if _, err := os.Stat(log.path + ".5"); err != nil {
+ t.Fatalf("the log never filled all five archives: %v", err)
+ }
log.compare(t)
status, err := TraceStoreStatus(log.path)
if err != nil {