fix: make deeply-nested-body test platform-independent (fixes #3146)
Closed
G0
19d ago+40+40+01234567890123456789-2-2-0123456789
Fixes #3146.
Root cause
The test assumed a 100k-deep body always makes json.loads raise RecursionError. Since CPython 3.12 the C json scanner guards recursion by remaining C-stack headroom, not a fixed depth — so the outcome depends on the thread's stack size. Measured on Apple Silicon macOS, CPython 3.14:
- main thread: flips to
RecursionErrorat depth ~74k → deep body fails to parse →PARSE_ERROR - thread with a 64 MB stack: depth 100k parses fine → giant list fails request validation →
INVALID_REQUEST
macOS runner threads get a smaller default stack than the main thread, which is why macos-latest sees -32600 while Ubuntu/Windows see -32700. Both are correct 400 rejections of the same hostile body; the old assertion was pinning a platform accident.
Change (test-only)
test_modern_post_with_deeply_nested_body_is_rejected_not_a_crash: asserts 400 with eitherPARSE_ERRORorINVALID_REQUEST— the invariant that actually matters is "rejected, not crashed".- New
test_modern_post_recursion_error_during_parse_is_parse_error: monkeypatches the body parse to raiseRecursionError, pinning theRecursionError → PARSE_ERRORmapping deterministically on every platform (this is what the old test was really trying to cover).
Verified locally on macOS arm64: both tests pass on CPython 3.13 and 3.14, full test_streamable_http_modern.py 52/52, ruff + pyright clean.