package web import ( "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestParseLogErrorsStopsAtNextTimestampedLine(t *testing.T) { content := strings.Join([]string{ "[2026-08-19 10:00:00] [INFO] starting", "[2026-08-19 10:00:01] [ERROR] first failure", "stack trace line one", "[2026-08-19 10:00:02] [INFO] unrelated next entry", "should not be collected", "[2026-08-19 10:00:03] [FATAL] second failure", "[2026-08-19 10:00:04] [INFO] tail", }, "\n") errs := parseLogErrors(content, 5) require.Len(t, errs, 2) // Results are returned in chronological order. assert.Equal(t, "2026-08-19 10:00:01", errs[0].Timestamp) assert.Equal(t, "first failure", errs[0].Message) assert.Equal(t, "stack trace line one", errs[0].Details) // The following line is a separate timestamped entry, not details. assert.Equal(t, "second failure", errs[1].Message) assert.Equal(t, "", errs[1].Details) } func TestParseLogErrorsSkipsEmptyDetailLines(t *testing.T) { content := strings.Join([]string{ "[2026-08-19 10:00:00] [ERROR] failure", "", "detail after blank line", }, "\n") errs := parseLogErrors(content, 5) require.Len(t, errs, 1) assert.Equal(t, "detail after blank line", errs[0].Details) }