Skip to content

fix(test): make the invalid-UTF-8 assertion code-page independent - #3615

Open
rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/stream-test-codepage-independent
Open

rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/stream-test-codepage-independent

Conversation

@rhishi99

Copy link
Copy Markdown
Contributor

Problem

test_read_lines_lossy_preserves_lines_after_invalid_utf8 asserts that the injected bad byte becomes U+FFFD. That is only true when there is no console code page to consult.

read_lines_lossy decodes through the console code page, so on a machine where one applies the byte legitimately decodes to a real character — 0xE3 is π on cp437, ã on cp1252 — and the test fails against a correctly working decoder:

panicked at src/core/stream.rs:611:9:
got: "ERRO B: π"

CI passes either way because a fresh runner's console has no code page to apply.

Fix

The property this test exists to protect is not which character comes out — it is that one bad byte does not swallow the rest of the line. Assert that directly: the line is its prefix plus exactly one character, whatever that character decodes to. The surrounding assertions (line count, the lines before and after) are unchanged, so the regression it was written for is still pinned.

Scope

Standalone on purpose. This is an existing test of yours, unrelated to any feature work, so it is not bundled with anything else.

Testing

cargo test --bin rtk test_read_lines_lossy
test result: ok. 5 passed; 0 failed

cargo clippy --all-targets clean.

🤖 Generated with Claude Code

`test_read_lines_lossy_preserves_lines_after_invalid_utf8` asserted that
the bad byte becomes U+FFFD. That only holds when no code page applies.
`read_lines_lossy` decodes through the console code page, so on cp437
`0xE3` is a valid character (pi) and on cp1252 it is a-tilde -- the
assertion fails on a correctly working decoder:

    panicked at src/core/stream.rs:611: got: "ERRO B: pi"

The property the test exists to protect is not which character comes
out, it is that one bad byte does not swallow the rest of the line.
Assert that instead: the line is the prefix plus exactly one character,
whatever that character decodes to.

CI passes either way because its console has no code page to consult.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Aug 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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