Skip to content

test(parsers): catalog-driven contract tests for claude-ai/gemini/codex (#1184) - #1194

Merged
Sinity merged 1 commit into
masterfrom
feature/test/parser-catalog-contracts-1184
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/parser-catalog-contracts-1184

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Mirrors the ChatGPT _METADATA_PERMUTATION_CASES catalog pattern in
tests/unit/sources/test_parsers_chatgpt.py for the three remaining
parsers 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.parametrize over a
(label, payload_factory, expectations) triple that runs the full
parser → transform → save → hydrate pipeline through the shared
tests.infra.pipeline_roundtrip helpers.

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 not
exist for the other two providers. Codex had test_parsers_codex.py
covering 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 — 9
    parametrized cases over the chat_messages shape: plain text,
    model variants (claude-3-opus, claude-3-5-sonnet), thinking
    blocks, tool_use + tool_result pair (covering the
    reclassify_tool_result_envelope user→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 over
    chunkedPrompt.chunks: plain exchange, displayName fallback,
    role normalisation (model → assistant), thinking chunks
    (isThought + thinkingBudget), executableCode +
    codeExecutionResult, 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
    context + 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:

  • Uses @pytest.mark.parametrize against a module-level list.
  • Reuses tests.infra.pipeline_roundtrip.parse_and_transform_payload
    / save_transform_and_hydrate and tests.infra.storage_records.db_setup.
  • Asserts title, role normalisation, content-block kinds,
    timestamp ordering, and attachment counts where applicable.
  • Includes a fast parser-only smoke test that walks the catalog
    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 materialisation
boundary) instead of the hydrated Message.content_blocks, because
the sync store_records helper does not currently propagate the
bundle'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) where
possible" is satisfied transitively: test_parser_crashlessness.py
and test_parsers_props.py already drive the same parsers with
schema-conformant Hypothesis payloads; this PR adds a complementary
hand-curated catalog where each row exercises a specific named
metadata surface.

Verification

nix develop -c pytest tests/unit/sources/test_parsers_claude_ai_catalog.py \
                     tests/unit/sources/test_parsers_drive_catalog.py \
                     tests/unit/sources/test_parsers_codex_catalog.py \
                     -p no:cacheprovider -o "addopts="
# 28 passed, 1 warning in 0.30s

nix develop -c devtools verify --quick
# exit_code: 0  (format, lint, mypy, render-all --check, manifest gates)

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

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
@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 24 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9a717fe3-6e9c-4e75-a67a-865c09539e5b

📥 Commits

Reviewing files that changed from the base of the PR and between dd059e0 and a7f916a.

📒 Files selected for processing (3)
  • tests/unit/sources/test_parsers_claude_ai_catalog.py
  • tests/unit/sources/test_parsers_codex_catalog.py
  • tests/unit/sources/test_parsers_drive_catalog.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/parser-catalog-contracts-1184

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.

❤️ Share

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

@Sinity
Sinity merged commit b526dd4 into master May 17, 2026
3 checks passed
@Sinity
Sinity deleted the feature/test/parser-catalog-contracts-1184 branch May 17, 2026 17:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +252 to +254
_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"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

test(parsers): catalog-driven contract tests for Claude-AI and Gemini parsers

1 participant