Repository navigation
test(sources): Codex event-stream contract (#1296) - #1404
Conversation
Adds a dedicated contract test module for the Codex on-disk streaming envelope shape — the realized form of OpenAI's response.delta / response.completed stream as persisted in Codex JSONL sessions. Problem: docs/plans/test-closure-matrix.yaml flagged sources.parsers.codex as having no dedicated event-stream contract test (coverage was property-shape only). The streaming envelope is the most likely surface to drift on an upstream format change and the existing parser tests do not pin response_item dispatch, tool-call call_id pairing, truncated stream behavior, or unknown payload-type fallback. Solution: tests/unit/sources/test_codex_event_stream_contract.py with 22 contract assertions across five concerns — streaming envelope shape, response.completed terminal-state semantics, tool-call streaming (call_id pairing across function_call / function_call_output), stream resilience (truncated / out-of-order / malformed), and cross-message references (parent session, turn_context cwd, compaction). Three catalog JSONL fixtures under tests/data/codex_event_stream/ cover text-only, tool-call, and interleaved realistic shapes. Removes the known_gaps bullet from the closure matrix. Ref #1296. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
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 (5)
✨ 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 |
…oundtrip contract (#1297) (#1405) ## 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
Adds a dedicated contract test module for the Codex on-disk streaming envelope shape — the realized form of OpenAI's
response.delta/response.completedstream as persisted in Codex JSONL session files. Closes the correspondingknown_gapsbullet indocs/plans/test-closure-matrix.yaml.Problem
docs/plans/test-closure-matrix.yamlflaggedsources.parsers.codexas having no dedicated event-stream contract test — coverage was property-shape only. The streaming envelope is the surface most likely to drift on an upstream Codex / OpenAI format change, and the existing parser tests undertests/unit/sources/test_parsers_codex.pydo not pin:response_itemmessage-vs-event dispatch, tool-callcall_idpairing semantics acrossfunction_call/function_call_output, truncated stream behavior, or the unknown payload-type fallback that protects against silent drops when OpenAI introduces a new event class.Solution
tests/unit/sources/test_codex_event_stream_contract.pywith 22 contract assertions grouped into five concerns:response_itemouter envelope, message-vs-event dispatch, unknown payload type surfaces as a provider event (canary for upstream changes).response.completedterminal state — multi-segment text concatenation, trailingtoken_countdoes not corrupt the prior message, terminal message timestamp drivesconversation.updated_at.function_callrealizes as a singletool_useblock;function_call_outputproduces a pairedtool_result; cross-messagecall_idpairing.function_call_output) keeps the orphantool_usevisible; out-of-order pairs survive; malformed records do not abort the stream;parse_streamandparseagree on truncated input.session_metabecomes parent +BranchType.CONTINUATION;turn_contextcwd changes collected intoworking_directories;compactedevent surfaced withhas_replacement_history.tests/data/codex_event_stream/:text_only_stream.jsonl— session_meta + user/assistant text turn + trailing token_count.tool_call_stream.jsonl— single function_call paired with function_call_output viacall_id.interleaved_stream.jsonl— multiple tool turns, mixed assistant messages, turn_context cwd changes, compaction event.known_gapsbullet from thesources.parsers.codexrow indocs/plans/test-closure-matrix.yamland registers the new test as a representative test for the domain.The tests pin the observable contract of the current parser (which is intentionally forgiving — it does not raise on truncation or reorder, it must not silently drop content). A future shift to "reject with typed error" would correctly fail these tests and force a deliberate update.
Verification
Ref #1296.