Skip to content

test: add 26 unit tests for session-parser lib - #133

Closed
TerminalGravity wants to merge 3 commits into
mainfrom
test/session-parser-coverage
Closed

test: add 26 unit tests for session-parser lib#133
TerminalGravity wants to merge 3 commits into
mainfrom
test/session-parser-coverage

Conversation

@TerminalGravity

@TerminalGravity TerminalGravity commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

Comprehensive test coverage for src/lib/session-parser.ts (325 lines, previously zero tests).

26 tests covering:

  • findSessionFiles: top-level and subagent .jsonl discovery
  • parseSession: prompts, array content blocks, correction detection (all 7 patterns), assistant text + metadata, tool_use → tool_call events, Task/dispatch_agent → sub_agent_spawn, tool_result errors (is_error + stderr), compaction events (subtype + text match), summary record extraction (branch, sessionId), malformed JSON graceful handling, empty content skipping, content_preview truncation, unique ID generation
  • Timestamp normalization: epoch seconds, epoch ms, ISO strings, mtime fallback
  • parseSessionAsync: parity with sync parser
  • parseAllSessions: multi-file sorting, since-filter

All 69 tests pass (26 new + 43 existing).

@TerminalGravity TerminalGravity left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid test coverage for the session parser — 24 cases covering JSONL parsing, subagent detection, array content blocks, and edge cases like empty/malformed files. Clean temp dir setup/teardown.

One minor thing: the findSessionDirs test hardcodes a ~/.claude/projects path expectation — might be worth making that configurable via env var so CI doesn't depend on home dir structure. Not a blocker, LGTM.

Comprehensive coverage for the previously untested session-parser module:
- findSessionFiles: top-level and subagent discovery
- parseSession: prompts, corrections, assistant text, tool_use, sub_agent_spawn,
  tool_result errors, compaction events, summary extraction, malformed JSON
- Timestamp normalization: epoch seconds, epoch ms, string, fallback to mtime
- All 7 correction patterns verified
- parseSessionAsync: parity with sync parser
- parseAllSessions: sorting and since-filter

All 69 tests pass (26 new + 43 existing).
@TerminalGravity
TerminalGravity force-pushed the test/session-parser-coverage branch from 0760885 to ced3612 Compare March 7, 2026 05:15
@TerminalGravity TerminalGravity changed the title test: session-parser unit tests (24 cases) test: add 26 unit tests for session-parser lib Mar 7, 2026
@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

Closing — superseded by a newer version of this test PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant