test(gemini): assert tool turns reach $ai_input as normalized blocks - #834
Closed
marco-g-pm wants to merge 1 commit into
Closed
test(gemini): assert tool turns reach $ai_input as normalized blocks#834marco-g-pm wants to merge 1 commit into
marco-g-pm wants to merge 1 commit into
Conversation
The existing coverage stops at the converter. This drives the whole capture path with a mocked google-genai client and real `types.Content` objects, then asserts on the `$ai_input` property actually handed to `capture()`, including that it survives a JSON round trip. Verified it fails against the pre-fix converter with the exact defect from #725: the tool call arrives as `{"type": "function_call", "function_call": {...}}` instead of the shared block. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
posthog-python Compliance ReportDate: 2026-08-05 19:02:44 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Follow-up to #823, which fixed the Gemini tool block shapes for #725. That PR tested the converter. This one tests the payload PostHog actually receives.
The gap mattered. A converter test proves
format_gemini_inputreturns the right dict. It does not prove that dict reaches$ai_input, survives the capture path, and stays JSON-serializable.Changes
One test. It drives the whole path with a mocked google-genai client and real
types.Contentobjects, then reads the$ai_inputproperty handed tocapture():{"type": "function", "function": {name, arguments}}{"type": "function", "tool_name": ..., "content": ...}💚 How did you test it?
I ran the test against the pre-fix converter to confirm it catches the original bug:
That is the exact defect from #725. A test that cannot fail is not worth adding.
On current main,
posthog/test/ai/gemini/gives 74 pass and 5 skip.I also fed the captured payload through both downstream consumers:
isInternalToolResultUserMessagehides it instead of letting it leak as a user bubble.[FUNCTION] {'temp_c': 18}, which is what the judge needs.No live Gemini key and no real project.
📝 Checklist
If releasing new changes
sampo addto generate a changeset fileTests only, so there is nothing to release.
A gap this test surfaced
The eval formatter still prints a Gemini tool call as a raw dict dump.
_format_special_blockreturnsNonefortype: "function"and leaves it to the message-leveltool_callsfield, which this payload does not use. Anthropictool_useand OpenAItool_callsboth print a clean call.This predates #823. The SDK already used that block for
$ai_output_choices, so Gemini tool calls have always printed this way for the judge. The fix belongs inmessage_formatter.py, not here.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Written with Claude Code (Opus 5), directed by @marco-g-pm.
I wrote this after #823 merged, so it lands as its own PR. The end-to-end run is also what surfaced the eval formatter gap above, which no converter test could have shown.