X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/2532718d5288e1a2586fe5716cc41bb2a0210e16..723f6e18adc6482ed913e1618c8a76e981720c2b:/log_test.go?ds=sidebyside diff --git a/log_test.go b/log_test.go index 97d28a5..5b30426 100644 --- a/log_test.go +++ b/log_test.go @@ -16,6 +16,7 @@ func TestLogReopenLoadsTheSameMessages(t *testing.T) { require.NoError(t, err) var written []Message + for _, kind := range []string{"user", "reply", "tool", "echo", "work", "note"} { message, err := log.Append(kind, kind+" text ✓") require.NoError(t, err) @@ -35,6 +36,7 @@ func TestLogReopenLoadsTheSameMessages(t *testing.T) { }() require.Equal(t, len(written), log.Len()) + for _, message := range written { read, err := log.Message(message.ID) require.NoError(t, err) @@ -62,7 +64,7 @@ func TestLogBuildsAMissingIndexAgain(t *testing.T) { require.NoError(t, log.Close()) // A missing index, and an index that a crash cut in a record. - for _, cut := range []func(string) error{os.Remove, truncateToOneAndAHalf} { + for _, cut := range []func(string) error{os.Remove, logTruncateToOneAndAHalf} { require.NoError(t, cut(filepath.Join(root, "index", "main.idx"))) log, err = openLog(t.Context(), root, clock.Now) @@ -95,11 +97,11 @@ func TestLogWritesOneFilePerDay(t *testing.T) { first, err := os.ReadFile(filepath.Join(root, "main", "2026-01-01.jsonl")) require.NoError(t, err) - require.Equal(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first)) + require.JSONEq(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first)) second, err := os.ReadFile(filepath.Join(root, "main", "2026-01-02.jsonl")) require.NoError(t, err) - require.Equal(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second)) + require.JSONEq(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second)) } func TestLogAllowsOneWriter(t *testing.T) { @@ -186,6 +188,7 @@ func TestLogRejectsAnIncompleteLineBeforeTheLastDay(t *testing.T) { first := `{"i":0,"kind":"user","text":"x","size":1,"date":"2026-01-01T12:00:00Z"}` + "\n" + `{"i":1,"kin` second := `{"i":1,"kind":"user","text":"y","size":1,"date":"2026-01-02T12:00:00Z"}` + "\n" + require.NoError(t, os.WriteFile(filepath.Join(root, "main", "2026-01-01.jsonl"), []byte(first), 0o600)) require.NoError(t, os.WriteFile(filepath.Join(root, "main", "2026-01-02.jsonl"), []byte(second), 0o600)) @@ -193,7 +196,7 @@ func TestLogRejectsAnIncompleteLineBeforeTheLastDay(t *testing.T) { require.ErrorContains(t, err, "ends in an incomplete line") } -// truncateToOneAndAHalf cuts the index at path in its second record. -func truncateToOneAndAHalf(path string) error { +// logTruncateToOneAndAHalf cuts the index at path in its second record. +func logTruncateToOneAndAHalf(path string) error { return os.Truncate(path, positionBytes+positionBytes/2) }