Skip to content

test(py): run shared reflection_api and flow_server conformance specs - #71

Merged
huangjeff5 merged 2 commits into
mainfrom
test/py-cross-sdk-conformance-specs
Nov 11, 2026
Merged

huangjeff5 merged 2 commits into
mainfrom
test/py-cross-sdk-conformance-specs

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Python CI now runs two shared conformance specs from genkit-ai/genkit that only JS and Go ran before: reflection_api.yaml (the Dev UI's /api/runAction endpoint) and flow_server_tests.yaml (streaming a flow over HTTP with genkit-fastapi's serve_flow). Without them, a change to Python's reflection responses or SSE stream framing could drift from the other SDKs and nobody would notice until the Dev UI or a JS client broke. Test-only; no library code changes.

# 1. reflection_api.yaml: POST /api/runAction against a `customReflector` echo model,
#    response compared against the spec's expected body
response = await client.post('/api/runAction', json=test['post'])
go_compare(response.json(), test['body'])
# => []

# 2. flow_server_tests.yaml: POST /streamy {"data": 5} with Accept: text/event-stream
chunks, result = parse_flow_stream(response.text)
# => [{'count': 0}, {'count': 1}, {'count': 2}, {'count': 3}, {'count': 4}]
# => 'done 5, streamed: 5 times'

Changes

  • Specs come from upstream, not copies: each harness looks for the spec in GENKIT_SPECS_DIR, then a nearby genkit checkout, then downloads it from upstream main into a temp cache (partial downloads are cleaned up). CI prefetches both files next to agent.yaml and generate.yaml, so test runs make no network calls.
  • Same comparison rules as Go: go_compare ports compare1 from go/tests/api_test.go. Every key in the spec must match, extra keys in the response are ignored, lists must be the same length, and the keys the JS runner skips (inputSchema, outputSchema, description, telemetry, latencyMs, usage) are skipped here too. In Python True == 1, so booleans are compared by exact type.
  • Echo model emits the bytes the spec expects: the spec pins the exact JSON string Go's echo model returns (compact, keys sorted). go_marshal dumps the request the same way and drops unset fields, so Python's default empty output config doesn't add "output":{} where Go and JS omit it.
  • Stream read the way the JS client reads it: parse_flow_stream follows the JS streamFlow client: each frame is data: <json> plus a blank line, message frames are chunks, result ends the stream, and an error frame or a stream that ends early fails the test. Each chunk is also checked byte-for-byte against compact JSON.stringify output.

Breaking changes

None.

Notes for other SDK owners

Every upstream case passes with no xfail. Two upstream details, no Python wire change:

  • Python's GenerationUsage types character and token counts as float ("inputCharacters": 5.0). It sits under usage, which the spec runners skip.
  • Upstream tests/test_js_app's streamy returns "done: 5, ..." (with a colon). flow_server_tests.yaml, Go's test_app, and this harness return "done 5, ...".

@pavelgj

pavelgj commented Nov 10, 2026

Copy link
Copy Markdown
Member

/gemini review

@huangjeff5
huangjeff5 force-pushed the test/py-cross-sdk-conformance-specs branch from 16671e0 to 2e22152 Compare November 10, 2026 22:56

@pavelgj pavelgj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@huangjeff5
huangjeff5 merged commit 5603c07 into main Nov 11, 2026
21 of 22 checks passed
@huangjeff5
huangjeff5 deleted the test/py-cross-sdk-conformance-specs branch November 11, 2026 22:46
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.

2 participants