Fix output capture breaking on multi-byte characters - #102
Merged
Conversation
The demultiplexer that attributes a test process's output to test items mixed character counts with byte indices, so a `✔` next to the end of a frame header raised a StringIndexError on the output-reading task, after which nothing the process printed was forwarded any more. Replace the inline parser with a byte-oriented `OutputDemuxer`: markers are ASCII and the id is cut out by byte offset, so no string index can be invalid; an incomplete trailing UTF-8 sequence is held back so every forwarded chunk is valid UTF-8; and whatever is still buffered when the process exits is forwarded instead of dropped. The frame header the test server writes now ends in `\x1f` rather than `"` and goes out as a single write, so a test item name containing a double quote, or output another task writes at the same moment, no longer truncates the id. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #101.
What was wrong
The output demultiplexer in
src/testprocess.jl— the loop that attributes a test process's output to test items by the\x1f…frame markers — mixed character counts (length(buffer)) with byte indices (buffer[i],SubString(buffer, i, j)). Three consequences:"", which is not a character boundary when the byte before the quote is the tail of a multi-byte character. That is theStringIndexErrorin the report ([119]=>'✔', [122]=>'"'). Once the reading task dies, nothing the process prints is forwarded for the rest of its life.The
"terminator was also fragile: the server wrote the marker and the id as separateprintarguments, i.e. separate libuv writes with a yield between them, so output from another task (or fromstdout, which is a different fd into the same pipe) could land inside the frame header. Genie's own✔ "…"logging is the likely origin of the✔"in the report. A test item whose name contains a"was truncated the same way.What changed
src/testprocess.jl: the parser is now a small, pureOutputDemuxer(feed!/flush!) that works on bytes throughout. It holds back a partial marker, an id without its terminator, and an incomplete trailing UTF-8 sequence for the next chunk, so every forwarded string is valid UTF-8 when the process's output is, and it never throws on any byte sequence. The@asyncreader is now a thin loop over it, and forwards the buffered tail at EOF.testprocess/TestItemServer/src/TestItemServer.jl: the frame header is written as one string —marker * id * '\x1f'— so it goes out in a single write, and the id terminator is\x1f(a control character that cannot appear in an id or in ordinary output) instead of". Server and parser ship together via the[sources]path, so the wire format changes in lockstep.docs/src/internals.md: describes the frame and the parsing rules.test/test_output_demux.jlunit-tests the demuxer directly (the Capture gets irritated by unicode output #101 stream, ids with quotes and multi-byte characters, every chunk split point, UTF-8 hold-back, stray\x1fbytes, a random-bytes fuzz that checks nothing is lost and nothing throws).test/test_output.jlgains an end-to-end item —unicode output ✔inBasicPackage, whose id therefore ends in✔like the report's crash site — that prints a 100,000-character✔line so a pipe read really does split a character, and checks the output is complete, valid UTF-8 and attributed to the right item.Verification
Full suite via the workspace test runner: 239/239 test items pass on Julia 1.12 / Windows.
🤖 Generated with Claude Code