Cover the core JSONL byte-level parser with targeted tests and a fuzz harness to prevent regressions and catch panics on malformed input: Unit tests: - TestParseFile_UserMessages: verifies user message counting and ProjectPath extraction from cwd field - TestParseFile_AssistantDedup: confirms message-ID-based deduplication where the last entry wins (handles edits/retries) - TestParseFile_TimeRange: validates StartTime/EndTime tracking across out-of-order timestamps - TestParseFile_SystemDuration: tests turn_duration aggregation from system entries (durationMs -> DurationSecs conversion) - TestParseFile_EmptyFile: ensures zero stats without errors on empty input - TestParseFile_MalformedLines: confirms graceful skip of unparseable lines without aborting the entire file - TestParseFile_CacheTokens: validates extraction of cache_read, cache_creation_5m, and cache_creation_1h token fields - TestExtractTopLevelType: table-driven tests for the byte-level type extractor covering user, assistant, system, nested-type-ignored, unknown, no-type, and empty cases Fuzz test: - FuzzExtractTopLevelType: seeds with realistic patterns plus edge cases (unterminated strings, non-string type values, empty input). Asserts the parser never panics and only returns known type strings or empty. Uses a writeSession helper that creates temp JSONL files for each test, keeping tests isolated and cleanup automatic via t.TempDir().
6.4 KiB
6.4 KiB