Skip to content

test(batch): cover non-ASCII UTF-8 in batch result downloads - #2804

Closed
SWAPI03 wants to merge 3 commits into
567-labs:mainfrom
SWAPI03:fix/batch-utf8-encoding
Closed

SWAPI03 wants to merge 3 commits into
567-labs:mainfrom
SWAPI03:fix/batch-utf8-encoding

Conversation

@SWAPI03

@SWAPI03 SWAPI03 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#2667 made the batch module write result files as UTF-8, which fixed the UnicodeEncodeError on Windows and the mojibake on non-UTF-8 locales. That fix landed without a regression test that exercises non-ASCII content, so the behavior is easy to break again (for example by dropping encoding= or re-adding ensure_ascii).

This PR adds that coverage. It originally also carried the encoding fix itself; after rebasing on main, the source change is identical to what #2667 shipped, so the only remaining diff is the tests.

Tests

One regression test per provider in tests/coverage:

  • Download a batch result containing Café ☕ 東京
  • Assert the saved file round-trips as readable UTF-8

Both tests raise UnicodeEncodeError under a cp1252 locale if the UTF-8 encoding is removed, and pass against current main. The full tests/coverage batch suites stay green.

download_results and the batch CLI opened result files without an
explicit encoding, so results containing non-ASCII text (any non-English
model output, emoji, accented characters) raised UnicodeEncodeError on
Windows and were written as mojibake on any other non-UTF-8 locale. Open
the result files with encoding="utf-8", matching the existing BytesIO
path in BatchRequest.save_to_file which already encodes as UTF-8.

Add regression tests for both the OpenAI and Anthropic providers that
download non-ASCII results and assert the file round-trips as UTF-8.
@SWAPI03 SWAPI03 changed the title fix(batch): write downloaded results as UTF-8 test(batch): cover non-ASCII UTF-8 in batch result downloads Oct 16, 2026
@SWAPI03

SWAPI03 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main. Since #2667 shipped the batch UTF-8 fix in 1.18.0, the encoding change here is now identical to what's already merged, so I've narrowed this PR to just the non-ASCII regression tests it was missing (one per provider). Both fail if the UTF-8 encoding is removed and pass against current main.

@jxnl-oai

jxnl-oai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

The UTF-8 implementation shipped in #2708. Both provider download tests are now in #2906, including an ASCII-default regression for each provider.

@jxnl-oai jxnl-oai closed this Nov 5, 2026
jxnl-oai added a commit that referenced this pull request Nov 5, 2026
Consolidates OpenAI batch request error handling. Current main already
retrieves both output and error files for completed jobs, preserves the
raw record and uses provider type before code. Keep that public
contract, preserve string errors at either location, and report
unsuccessful HTTP status codes when the provider omits the error body.
The full provider code is available in raw_data when both type and code
are present.

Validation: 90 offline tests passed across parsing, retrieval, file
downloads and malformed records.

The OpenAI and Anthropic download tests from #2804 verify that non-ASCII
results are written as UTF-8 on platforms with an ASCII default. The
production encoding fix shipped in #2708.

Consolidates #2820, #2822, #2825, #2657 and #2804.
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