Skip to content

refactor: trim jsonl_parser __all__ to public API only#88

Merged
wpak-ai merged 1 commit into
masterfrom
refactor/parser-all-cleanup
Jun 16, 2026
Merged

refactor: trim jsonl_parser __all__ to public API only#88
wpak-ai merged 1 commit into
masterfrom
refactor/parser-all-cleanup

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #80

Summary

  • Trim utils/jsonl_parser.py __all__ to the public API only: parse_session and quick_session_info.
  • Repoint callers that imported underscore-prefixed re-exports from jsonl_parser to their defining modules (utils/jsonl_helpers, utils/tool_dispatch).
  • Rewrite parser processor and file-activity tests to exercise behavior through parse_session() instead of private _process_* / _track_file_activity imports.
  • Update utils/md_exporter.py to import strip_system_tags from utils/jsonl_helpers.
  • Remove unused re-export imports from jsonl_parser.py (strip_system_tags, _TOOL_RESULT_DISPATCH).

Test plan

  • rg "from utils.jsonl_parser import _" tests/ api/ returns no matches
  • mypy -p api -p utils -p models
  • ruff check .
  • pytest -q
  • npm test

Summary by CodeRabbit

  • Tests

    • Refactored test suites to validate public helper functions and end-to-end parsing behavior rather than internal implementations.
  • Refactor

    • Narrowed public API exports to focus only on parse_session and quick_session_info, consolidating internal implementation details.
    • Reorganized imports to use public utility functions consistently across modules.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99be32ba-48ae-41aa-954f-6955090be1f1

📥 Commits

Reviewing files that changed from the base of the PR and between 0435b2d and 5c48fba.

📒 Files selected for processing (5)
  • tests/test_jsonl_parser.py
  • tests/test_null_usage_tokens.py
  • tests/test_real_session_fixtures.py
  • utils/jsonl_parser.py
  • utils/md_exporter.py

📝 Walkthrough

Walkthrough

utils/jsonl_parser.__all__ is trimmed to only ["parse_session", "quick_session_info"]. utils/md_exporter.py switches to a module-level import of strip_system_tags from utils.jsonl_helpers. All test files are updated: fixture tests re-source dispatch symbols from utils.tool_dispatch, and test_jsonl_parser.py/test_null_usage_tokens.py are rewritten to use public helpers and parse_session instead of private internal functions.

Changes

Public API narrowing and test migration

Layer / File(s) Summary
Narrow __all__ and fix md_exporter import
utils/jsonl_parser.py, utils/md_exporter.py
__all__ reduced to ["parse_session", "quick_session_info"]; md_exporter.py imports strip_system_tags from utils.jsonl_helpers at module scope and removes per-call local imports.
Fixture tests: repoint dispatch imports
tests/test_real_session_fixtures.py
_TOOL_RESULT_DISPATCH and _parse_tool_result now imported from utils.tool_dispatch instead of utils.jsonl_parser; parse_session remains from utils.jsonl_parser.
Test infra: public helper imports and _parse_entries utility
tests/test_jsonl_parser.py
Replaces private-helper imports with public equivalents from utils.jsonl_helpers and introduces _parse_entries(entries) that writes temp JSONL, calls parse_session, and cleans up.
Public helper unit tests
tests/test_jsonl_parser.py
TestNormalizeContent, TestExtractText, TestExtractImages, TestInferTitle, and TestStripSystemTags updated to call the renamed public functions and assert same outputs.
Integration tests via parse_session
tests/test_jsonl_parser.py
TestProcessUser, TestProcessAssistant, TestTrackFileActivity, and malformed toolUseResult cases rewritten to build JSONL entry lists and assert parsed session fields through _parse_entries.
Null token integration tests
tests/test_null_usage_tokens.py
Removes _process_assistant import and TestProcessAssistantNullUsage; adds module-level _write_session/_parse_entries helpers; expands TestParseSessionNullUsage to cover null input/output/cache tokens, all-null usage, null ephemeral tokens, per-message usage containing no None, and mixed accumulation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • cppalliance/claude-code-chat-browser#57: This PR directly targets the same refactor artifacts (split of utils/jsonl_helpers, utils/tool_dispatch) introduced by PR #57; the import repointing here is the downstream consumer of that split.
  • cppalliance/claude-code-chat-browser#52: Both PRs modify tests/test_real_session_fixtures.py, with this PR updating its imports to match the refactored dispatcher/helper locations.
  • cppalliance/claude-code-chat-browser#22: Both PRs update tests/test_jsonl_parser.py coverage for malformed/partial toolUseResult shapes, asserting parsed tool-result outcomes via parse_session.

Suggested reviewers

  • timon0305
  • wpak-ai

🐇 Hop hop, the private things hide,
No more underscore names outside!
parse_session stands proud and tall,
Just two entries in __all__ — that's all!
The tests now dance through public doors,
A cleaner burrow than before! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main refactoring objective: trimming jsonl_parser's all export to contain only the public API.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #80: all trimmed to two public symbols, internal symbols repointed to defining modules, tests refactored to use public parse_session interface, and no underscore imports remain.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #80 scope: trimming all, repointing internal imports, and refactoring tests to use the public API. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/parser-all-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@clean6378-max-it clean6378-max-it self-assigned this Jun 16, 2026
Comment thread utils/jsonl_parser.py
Comment thread utils/jsonl_parser.py
Comment thread utils/md_exporter.py
Comment thread tests/test_jsonl_parser.py
@clean6378-max-it clean6378-max-it requested a review from wpak-ai June 16, 2026 19:31
@wpak-ai wpak-ai merged commit abf4cc0 into master Jun 16, 2026
16 checks passed
@wpak-ai wpak-ai deleted the refactor/parser-all-cleanup branch June 16, 2026 21:08
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.

claude-code-chat-browser: __all__ export cleanup — trim parser public API

3 participants