Skip to content

test(sources): Gemini chunkedPrompt message extraction and metadata roundtrip contract (#1297) - #1405

Merged
Sinity merged 2 commits into
masterfrom
feature/test/gemini-chunked-prompt-contract-1297-v2
May 20, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/test/gemini-chunked-prompt-contract-1297-v2

Conversation

@Sinity

@Sinity Sinity commented May 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds dedicated contract tests for the Gemini AI Studio chunkedPrompt parser
(polylogue/sources/parsers/drive.py + drive_support*) covering chunks
decomposition, content_blocks emission, per-message provider_meta roundtrip,
and conversation envelope metadata. Drops the corresponding known_gaps
bullet from docs/plans/test-closure-matrix.yaml for
sources.parsers.gemini.

Problem

docs/plans/test-closure-matrix.yaml declared:

Gemini chunkedPrompt message-extraction and metadata roundtrip lacks
dedicated assertions; format detection only

tests/unit/sources/test_parsers_drive.py exercised dispatch and a few helper
contracts, but the actual decomposition of chunkedPrompt.chunks into
normalized messages — including the executableCode /
codeExecutionResult / isThought / safetyRatings paths — had no
dedicated assertions. Metadata could regress silently.

Solution

  • New tests/unit/sources/test_gemini_chunked_prompt_contract.py with 29
    contract assertions across six classes:
    • TestChunkedPromptEnvelopeShape — chunks-to-messages decomposition,
      role guard, top-level chunks fallback, string-chunk handling.
    • TestPerChunkContentBlocks — thinking / code / tool_result
      block emission from isThought, executableCode, codeExecutionResult.
    • TestMetadataRoundtrip — provider_meta.raw preservation,
      top-level typed projections (tokenCount, finishReason,
      thinkingBudget, isThought, safetyRatings, executableCode,
      codeExecutionResult), plus a full parse → serialize → reparse loop
      that proves raw is sufficient to reconstruct identical messages.
    • TestConversationLevelMetadata — title source precedence (title →
      displayName → fallback id), provider_conversation_id derivation,
      envelope vs chunk-derived createTime/updateTime.
    • TestPerChunkTimestamps — per-chunk createTime propagation and
      envelope fallback.
  • Three synthetic catalog payloads under
    tests/data/gemini_chunked_prompt/: text_only_prompt.json,
    code_execution_prompt.json, multi_turn_prompt.json.
  • docs/plans/test-closure-matrix.yaml: drops the known_gaps bullet for
    sources.parsers.gemini and lists the new test under
    representative_tests.

Mirrors the structural pattern established for the Codex event-stream
contract in #1296 / PR #1404.

Verification

nix develop -c pytest tests/unit/sources/test_gemini_chunked_prompt_contract.py tests/unit/sources/test_parsers_drive.py -q
# 52 passed in 8.67s
nix develop -c devtools verify --quick
# all 21 steps ok (mypy, ruff, render-all, verify-closure-matrix, ...)

Closes #1297

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for Gemini chunked prompt handling, including text-only, multi-turn, and code execution scenarios with message decomposition and metadata validation.
  • Documentation

    • Updated test closure matrix to reflect new Gemini chunked prompt test coverage.

Review Change Stack

Sinity added 2 commits May 20, 2026 04:46
29 contract tests over chunks decomposition, content_blocks emission,
provider_meta roundtrip, conversation envelope metadata, and per-chunk
timestamps. Three synthetic fixtures under tests/data/gemini_chunked_prompt/.

Ref #1297
Remove the closure-matrix known_gap now satisfied by
test_gemini_chunked_prompt_contract.py; add casts/type-narrowing for mypy
strict on the new test file.

Ref #1297
@Sinity
Sinity merged commit 80983b4 into master May 20, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a9d00456-c5b4-4bfc-8a29-1bbdb7c92eec

📥 Commits

Reviewing files that changed from the base of the PR and between 80b8870 and 6de19d3.

📒 Files selected for processing (5)
  • docs/plans/test-closure-matrix.yaml
  • tests/data/gemini_chunked_prompt/code_execution_prompt.json
  • tests/data/gemini_chunked_prompt/multi_turn_prompt.json
  • tests/data/gemini_chunked_prompt/text_only_prompt.json
  • tests/unit/sources/test_gemini_chunked_prompt_contract.py

📝 Walkthrough

Walkthrough

This PR adds a contract test suite for Gemini's chunkedPrompt parsing format, including three JSON test fixtures (text-only, multi-turn, code-execution), a comprehensive Python test module with five test classes covering decomposition, content block generation, metadata preservation, and timestamp behavior, and updates the test closure matrix to register the new suite.

Changes

Gemini chunkedPrompt contract test suite

Layer / File(s) Summary
Test fixtures and catalog smoke tests
tests/data/gemini_chunked_prompt/text_only_prompt.json, tests/data/gemini_chunked_prompt/multi_turn_prompt.json, tests/data/gemini_chunked_prompt/code_execution_prompt.json, tests/unit/sources/test_gemini_chunked_prompt_contract.py (module header, helpers, smoke tests)
Three JSON fixtures define different chunkedPrompt payloads (alternating user/model text, multi-turn with structured metadata, code execution with tool results). Test module loads fixtures, wraps parsing and detection helpers, and runs parametrized smoke tests asserting looks_like() detection and successful non-raising parse for all fixtures.
Envelope decomposition and content block generation
tests/unit/sources/test_gemini_chunked_prompt_contract.py::TestChunkedPromptEnvelopeShape, tests/unit/sources/test_gemini_chunked_prompt_contract.py::TestPerChunkContentBlocks
TestChunkedPromptEnvelopeShape pins how chunks become messages: role filtering, content validation, fallback to top-level chunks when chunkedPrompt is missing, and dropping of untyped string chunks. TestPerChunkContentBlocks asserts that typed chunk fields (isThought, executableCode, codeExecutionResult) correctly map to content block types with expected payload fields.
Metadata roundtrip and timestamp derivation
tests/unit/sources/test_gemini_chunked_prompt_contract.py::TestMetadataRoundtrip, tests/unit/sources/test_gemini_chunked_prompt_contract.py::TestConversationLevelMetadata, tests/unit/sources/test_gemini_chunked_prompt_contract.py::TestPerChunkTimestamps
TestMetadataRoundtrip verifies chunk dictionaries are preserved under provider_meta.raw and that parse→serialize→reparse yields identical message role, text, timestamps, and typed metadata. TestConversationLevelMetadata pins title selection precedence and provider conversation ID fallback. TestPerChunkTimestamps pins per-chunk and envelope-level timestamp fallback behavior.

Test closure matrix registration

Layer / File(s) Summary
Closure matrix update
docs/plans/test-closure-matrix.yaml
Registers tests/unit/sources/test_gemini_chunked_prompt_contract.py as representative test for sources.parsers.gemini, removing the prior known-gaps note about missing chunkedPrompt contract assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Possibly related PRs

  • Sinity/polylogue#1191: Updates the devtools closure matrix linter command that validates the very test-closure-matrix.yaml rows being registered by this PR.

Suggested labels

type:test, area:parser

Poem

🐰 Chunked prompts in the Gemini streams,
Now tested thoroughly—no more broken dreams!
From code blocks to thinking, each metadata flows,
The contract is pinned where it matters. Now it knows! ✨

✨ 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 feature/test/gemini-chunked-prompt-contract-1297-v2

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.

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(sources): Gemini chunkedPrompt message extraction and metadata roundtrip contract

1 participant