Skip to content

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

test(fxsession): keep the recorded fx session byte-exact on Windows checkouts

Claude5ff23c78b508
diff --git a/cli/beacon/internal/fxsession/realsession_test.go b/cli/beacon/internal/fxsession/realsession_test.go
index 40357fef..0dad6ba7 100644
--- a/cli/beacon/internal/fxsession/realsession_test.go
+++ b/cli/beacon/internal/fxsession/realsession_test.go
@@ -35,6 +35,7 @@ func TestRealFxSessionRecordCollectsEndToEnd(t *testing.T) {
if ref.Manifest == nil {
t.Fatal("the recorded session's manifest was not readable")
}
+ requireByteExactFixture(t, ref)
events, stats, err := store.Read(ref)
if err != nil {
@@ -158,6 +159,7 @@ func mapRealSession(t *testing.T) []MappedEvent {
if err != nil || len(refs) != 1 {
t.Fatalf("List: %v (%d sessions)", err, len(refs))
}
+ requireByteExactFixture(t, refs[0])
events, _, err := store.Read(refs[0])
if err != nil {
t.Fatalf("Read: %v", err)
@@ -165,6 +167,25 @@ func mapRealSession(t *testing.T) []MappedEvent {
return MapSession(refs[0], events, MapOptions{})
}
+// requireByteExactFixture fails with the actual cause when the recorded log is no longer the bytes
+// fx wrote. The manifest's event_log_bytes is a byte watermark over those bytes, and the reader
+// stops there, so any rewrite of the file silently moves records past it. The one that happened: a
+// Windows checkout with core.autocrlf converted every LF to CRLF, 26 lines grew 26 bytes, and the
+// last record -- the only committed turn -- fell past the watermark as a "partial tail", leaving
+// session.started as the whole session. testdata/.gitattributes marks these files -text so git
+// never converts them; this names that instead of four unrelated-looking mapping failures.
+func requireByteExactFixture(t *testing.T, ref SessionRef) {
+ t.Helper()
+ if ref.Manifest == nil {
+ t.Fatal("the recorded session's manifest was not readable")
+ }
+ if ref.Manifest.EventLogBytes != ref.SizeBytes {
+ t.Fatalf("recorded events.jsonl is %d bytes but its manifest commits %d: the fixture was rewritten "+
+ "after capture (line-ending conversion on checkout?) -- see testdata/.gitattributes",
+ ref.SizeBytes, ref.Manifest.EventLogBytes)
+ }
+}
+
func findMapped(t *testing.T, mapped []MappedEvent, action string) schema.Event {
t.Helper()
for _, item := range mapped {
diff --git a/cli/beacon/internal/fxsession/testdata/.gitattributes b/cli/beacon/internal/fxsession/testdata/.gitattributes
new file mode 100644
index 00000000..cd7d854e
--- /dev/null
+++ b/cli/beacon/internal/fxsession/testdata/.gitattributes
@@ -0,0 +1,5 @@
+# Recorded fx sessions are byte-exact captures: session.json's event_log_bytes is a watermark over
+# the exact bytes fx wrote to events.jsonl, and the reader stops at it. Line-ending conversion on
+# checkout (core.autocrlf on Windows) grows the log by one byte per line and pushes the final
+# committed turn past the watermark. Never convert these files.
+* -text