Skip to content

test(python-sdk): add regression tests for template upload Content-Length#1292

Closed
mishushakov wants to merge 1 commit intomainfrom
fix/python-sdk-upload-content-length-tests
Closed

test(python-sdk): add regression tests for template upload Content-Length#1292
mishushakov wants to merge 1 commit intomainfrom
fix/python-sdk-upload-content-length-tests

Conversation

@mishushakov
Copy link
Copy Markdown
Member

Summary

No Python SDK code changes — the current implementation already passes bytes to httpx.put(..., content=...), so this is purely a regression guard.

Test plan

  • poetry run pytest tests/sync/template_sync/test_upload_file.py tests/async/template_async/test_upload_file.py -v — both pass locally
  • poetry run ruff check / ruff format --check clean

🤖 Generated with Claude Code

…ngth

Guards against future changes swapping the buffered bytes for a
generator/stream, which would trigger Transfer-Encoding: chunked and
break S3 presigned PUT uploads with 501 NotImplemented.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 24, 2026

PR Summary

Low Risk
Low risk because it only adds tests and does not change SDK runtime behavior; the main risk is potential test flakiness due to local HTTP server/thread handling.

Overview
Adds new sync and async regression tests for template_* .upload_file that spin up a local HTTP server and assert the PUT request includes a valid Content-Length matching the received body.

The tests also guard against future changes that would switch the request body to a stream/generator and trigger Transfer-Encoding: chunked, which can break S3 presigned PUT uploads.

Reviewed by Cursor Bugbot for commit bc3f865. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: bc3f865

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 3d860d5. Download artifacts from this workflow run.

JS SDK (e2b@2.19.1-fix-python-sdk-upload-content-length-tests.0):

npm install ./e2b-2.19.1-fix-python-sdk-upload-content-length-tests.0.tgz

CLI (@e2b/cli@2.9.1-fix-python-sdk-upload-content-length-tests.0):

npm install ./e2b-cli-2.9.1-fix-python-sdk-upload-content-length-tests.0.tgz

Python SDK (e2b==2.20.0+fix-python-sdk-upload-content-length-tests):

pip install ./e2b-2.20.0+fix.python.sdk.upload.content.length.tests-py3-none-any.whl

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc3f865330

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


class Handler(BaseHTTPRequestHandler):
def do_PUT(self):
state["headers"] = dict(self.headers)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep header lookups case-insensitive

Converting self.headers to a plain dict here drops the case-insensitive behavior of HTTPMessage, so later checks like .get("Content-Length") / .get("Transfer-Encoding") can fail if the client sends lowercase header names (which is valid HTTP). In that case this regression test would report a false failure even though Content-Length is present and correct, making CI flaky across client/library versions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — test-only regression guard, no SDK behavior change.

Extended reasoning...

Overview

Adds two new test files (sync + async) under packages/python-sdk/tests/ that spin up a local http.server.HTTPServer in a daemon thread and assert that upload_file sends a Content-Length header matching the received body and does not use Transfer-Encoding: chunked. No production SDK code is touched.

Security risks

None. The tests bind to 127.0.0.1 on an ephemeral port and only run within the test suite. No credentials, network egress, or new dependencies.

Level of scrutiny

Low. Test-only additions that guard against a specific S3 presigned PUT regression (501 NotImplemented on chunked encoding, mirroring the JS SDK fix in #1285/#1243). The tests are self-contained, mechanical, and well-commented.

Other factors

The bug hunting system found no issues. Minor potential for test flakiness from thread shutdown exists, but the server.shutdown() + thread.join(timeout=5) pattern in a finally block is standard. No changeset is needed since this doesn't affect published behavior.

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.

1 participant