Repository navigation
test(parsers): catalog-driven contract tests for claude-ai/gemini/codex (#1184) - #1194
Conversation
Mirror the ChatGPT _METADATA_PERMUTATION_CASES pattern from tests/unit/sources/test_parsers_chatgpt.py for the three remaining parsers called out in #1184: - tests/unit/sources/test_parsers_claude_ai_catalog.py 9 cases over the chat_messages shape: plain text, model variants (opus, sonnet), thinking blocks, tool_use+tool_result pair, attachments, citations metadata, system prompt prelude, and a rich mixed turn. - tests/unit/sources/test_parsers_drive_catalog.py 8 cases over chunkedPrompt.chunks: plain exchange, displayName fallback, role normalisation (model->assistant), thinking chunks, executable code + execution result, Drive document attachments, inline image attachments, and timestamp ordering. - tests/unit/sources/test_parsers_codex_catalog.py 8 cases over Codex JSONL envelopes: plain exchange, session_meta with git/instructions, developer->system normalisation, function_call+function_call_output -> tool_use+tool_result, direct (non-envelope) format, role casing normalisation, multi- turn ordering, and state-record skipping. Each catalog is a module-level @pytest.mark.parametrize against a (label, factory, expectations) triple and runs the full parse -> transform -> save -> hydrate pipeline via the shared tests.infra.pipeline_roundtrip helpers. Contract assertions cover title, role normalisation, content-block kinds, timestamp ordering, and attachment counts, as required by issue #1184's acceptance criteria. Content-block kind assertions read roundtrip.transform.bundle. content_blocks (the canonical materialised representation) rather than the hydrated Message.content_blocks, because the shared sync store_records helper does not yet propagate the bundle's block rows through MessageRecord.content_blocks. Title, role, and timestamp assertions still run against the hydrated Conversation. Ref #1184
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7f916ac79
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _chunk("c1", "user", text="first", create_time="2024-04-10T08:00:00Z"), | ||
| _chunk("c2", "model", text="second", create_time="2024-04-10T08:00:01Z"), | ||
| _chunk("c3", "user", text="third", create_time="2024-04-10T08:00:02Z"), |
There was a problem hiding this comment.
Make out-of-order timestamp case actually unordered
The case labeled "timestamp ordering across out-of-order chunks" currently uses monotonically increasing createTime values, so it never exercises the intended edge case. Because _assert_roundtrip only checks timestamps == sorted(timestamps), this test would still pass even if the parser regressed on handling genuinely out-of-order chunk timestamps, leaving the advertised ordering contract unverified.
Useful? React with 👍 / 👎.
Summary
Mirrors the ChatGPT
_METADATA_PERMUTATION_CASEScatalog pattern intests/unit/sources/test_parsers_chatgpt.pyfor the three remainingparsers called out in #1184: Claude-AI (web export), Gemini (Drive
chunkedPrompt), and Codex (JSONL session envelopes). Each new test
file is a module-level
@pytest.mark.parametrizeover a(label, payload_factory, expectations)triple that runs the fullparser → transform → save → hydrate pipeline through the shared
tests.infra.pipeline_roundtriphelpers.Problem
PR #928 (under #997's predecessor #807) explicitly deferred parser
contract tests for Claude-AI and Gemini — they remained in the AC3
"uncovered domains" list when #997 was reopened. ChatGPT now has
catalog-driven metadata roundtrip coverage in
tests/unit/sources/test_parsers_chatgpt.py; the equivalent did notexist for the other two providers. Codex had
test_parsers_codex.pycovering format detection / session metadata / git context, but no
metadata-permutation catalog comparable to ChatGPT's.
Solution
Three new test files, each ~300 LOC, no per-case copy-paste:
tests/unit/sources/test_parsers_claude_ai_catalog.py— 9parametrized cases over the
chat_messagesshape: plain text,model variants (claude-3-opus, claude-3-5-sonnet), thinking
blocks, tool_use + tool_result pair (covering the
reclassify_tool_result_envelopeuser→tool reclassification),attachments, citations metadata in content blocks, system prompt
prelude, and a rich mixed turn.
tests/unit/sources/test_parsers_drive_catalog.py— 8 cases overchunkedPrompt.chunks: plain exchange,displayNamefallback,role normalisation (
model→assistant), thinking chunks(
isThought+thinkingBudget),executableCode+codeExecutionResult, Drive document attachments, inline imageattachments, and timestamp ordering.
tests/unit/sources/test_parsers_codex_catalog.py— 8 cases overCodex JSONL envelopes: plain exchange,
session_metawith gitcontext + instructions,
developer→systemnormalisation,function_call+function_call_output→tool_use+tool_result, direct (non-envelope) format, role casingnormalisation, multi-turn ordering, and state-record skipping.
Each catalog:
@pytest.mark.parametrizeagainst a module-level list.tests.infra.pipeline_roundtrip.parse_and_transform_payload/
save_transform_and_hydrateandtests.infra.storage_records.db_setup.timestamp ordering, and attachment counts where applicable.
without going through storage so a parser-side regression is
caught before the pipeline roundtrip runs.
Non-obvious decision: content-block kind assertions read
roundtrip.transform.bundle.content_blocks(the materialisationboundary) instead of the hydrated
Message.content_blocks, becausethe sync
store_recordshelper does not currently propagate thebundle's content_block rows through
MessageRecord.content_blocks;the materialised bundle is the canonical block representation the
daemon write path persists. Title, role, and timestamp assertions
still run against the hydrated
Conversation.The AC's "reuse
schema_conformant_payload(provider)wherepossible" is satisfied transitively:
test_parser_crashlessness.pyand
test_parsers_props.pyalready drive the same parsers withschema-conformant Hypothesis payloads; this PR adds a complementary
hand-curated catalog where each row exercises a specific named
metadata surface.
Verification
Pre-existing master failures (
tests/infra/test_storage_records.py::test_store_records_commits_within_lock—no such table: user_marks; topology-projection / artifact-graph cells; surface→storage boundary lint) are present on the underlying branch before this change and are unrelated to the catalog additions. Verified by stashing the three new files and re-running the affected suites.Closes #1184