Skip to content

test: add unit tests for services/session_parsers/claude_code.py#1445

Open
Madhumidha-S wants to merge 2 commits into
BlazeUp-AI:mainfrom
Madhumidha-S:fix/issue-1441
Open

test: add unit tests for services/session_parsers/claude_code.py#1445
Madhumidha-S wants to merge 2 commits into
BlazeUp-AI:mainfrom
Madhumidha-S:fix/issue-1441

Conversation

@Madhumidha-S

Copy link
Copy Markdown

Purpose / Description

Adds unit testing for the Claude Code JSONL session parser to ensure transcript lines are correctly parsed into normalised frontend events.

Fixes

Approach

Created a new test suite (tests/test_claude_code_session_parser.py) utilising pytest. Modelled against the existing session parser tests, the suite injects raw JSONL text samples through parse_rows.

  • Tool Result Merging: Validated that tool result events correctly merge back into their parent tool use events, while orphan results safely skip without crashing.
  • Complex Turn Sequences: Validated turns containing sequential combinations of thinking blocks, tool usages, and text responses.
  • Resilience: Ensured malformed JSON, integer content types, and missing fields (like empty timestamps falling back to DB ingested_at sentinels) are handled gracefully.
  • Metrics & Metadata: Verified accurate extraction of token usage metrics and system events, alongside the proper skipping of noisy events (e.g., meta, agent-setting).

How Has This Been Tested?

  • uv run pytest tests/test_claude_code_session_parser.py -v (all 23 tests passed).
  • Verified linter rules via uv run ruff check --fix.
  • Verified the global test suite continues to pass (make test).

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)

AI Assistance

Was generative AI tooling used to co-author this PR?

  • Yes(Please Specify the tool): Google Gemini
  • Was the generated code manually reviewed and tested? Yes

@github-actions github-actions Bot added new contributor Pull request from a first-time contributor tests Pull request adds or modifies tests labels Jun 16, 2026

# ── Sample Claude Code JSONL lines ────────────────────────────────────────────

USER_SIMPLE = '{"type":"user","message":{"content":"Hello world"},"timestamp":"2026-06-01T10:00:00.000Z"}'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See these don't really follow the claude code jsonL pattern. If you do use. Claude code, copy over a small section containing tool calls and stuff. Copy that over and remove any PII. These don't follow that pattern.

If you don't have access to claude code, please pick another issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review!! I'll update the fixtures to match actual Claude Code JSONL data.

@Madhumidha-S Madhumidha-S requested a review from Haz3-jolt June 24, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new contributor Pull request from a first-time contributor tests Pull request adds or modifies tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for services/session_parsers/claude_code.py

2 participants