Skip to content

test: add regression coverage for list-of-primitive multipart fields - #827

Open
kraenhansen wants to merge 1 commit into
mainfrom
cursor/regression-test-multipart-list-fields-bd2e
Open

test: add regression coverage for list-of-primitive multipart fields#827
kraenhansen wants to merge 1 commit into
mainfrom
cursor/regression-test-multipart-list-fields-bd2e

Conversation

@kraenhansen

Copy link
Copy Markdown
Member

Summary

Adds tests/test_multipart_list_fields.py, a regression test for the fix in #825 (which resolved #819).

The bug: generator fern-python-sdk 4.46.9 began serializing every non-scalar multipart field via json.dumps(jsonable_encoder(...)). List[str] is not a scalar, so speech_to_text.convert(keyterms=["a", "b"]) was sent as one form field containing ["a", "b"] instead of two keyterms fields, and the API validated the whole JSON array against its per-item limits (invalid_keyword_length).

Because the fix lives in Fern-generated raw_client.py files and is re-applied on every regeneration by Fern Replay, there was nothing stopping a future regeneration from silently reverting it. These tests assert the wire format directly, so a revert fails CI.

How it works

Each test builds a real ElevenLabs / AsyncElevenLabs client backed by an httpx.MockTransport whose handler records the outgoing request and raises a sentinel to abort before a response is needed. The captured multipart body is parsed with email.message_from_bytes into an ordered list of (name, value) pairs, and the tests assert on those pairs.

Coverage

All eight fields restored by #825, plus the async path and a negative control:

Test target Field(s)
speech_to_text.convert (sync + async) keyterms
dubbing.project.create keyterms
music.video_to_music tags
music.finetunes.create tags
studio.projects.create genres, pronunciation_dictionary_locators, voice_settings
audio_native.create pronunciation_dictionary_locators

test_speech_to_text_object_fields_stay_json_encoded is the negative control: object-valued fields such as entity_detection must keep json.dumps encoding, so the tests would also catch an over-broad "fix" that unwrapped those too.

Test plan

Notes

The tests only touch tests/, which is listed in .fernignore, so nothing here is at risk of being overwritten by regeneration.

Open in Web Open in Cursor 

Locks in the wire format restored by #825: each item of a List[str]
multipart field must be sent as its own form field, not as a single
json.dumps'd array (which caused invalid_keyword_length on
speech_to_text.convert(keyterms=[...]) -- #819).

Covers all eight affected fields across speech_to_text, dubbing,
music, music.finetunes, studio.projects and audio_native, plus the
async path, and asserts object-valued fields stay JSON-encoded. The
fields live in Fern-generated raw_client.py files, so these tests are
the guardrail against a regeneration silently reverting the fix.

Co-authored-by: Kræn Hansen <mail@kraenhansen.dk>
@kraenhansen kraenhansen self-assigned this Jul 30, 2026
@kraenhansen
kraenhansen requested a review from PaulAsjes July 30, 2026 10:12
@kraenhansen
kraenhansen marked this pull request as ready for review July 30, 2026 10:12
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.

keyterms parameter causes invalid_keyword_length error in v2.59.0 due to json.dumps() serialization regression

3 participants