fix(shell): truncate metadata preview by bytes#29297
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #29288: Why it's related: Both PRs address the same core issue—using UTF-8 byte length instead of character/code unit length for shell tool metadata preview truncation. PR #29288 appears to cover the same fix, likely related to issue #29291 that this PR is closing. |
|
Checked #29288. It addresses the same area, but its regression test only checks that the preview has no replacement character. With the current broken implementation, the CJK case can avoid truncation entirely because This PR adds assertions that metadata preview actually truncates when UTF-8 bytes exceed the limit, keeps the retained tail within the byte limit, and does not start on an unpaired low surrogate for emoji output. It also reuses the same byte-tail helper in the existing shell tail path. |
|
tests failing, could you pls fix? |
|
CI update after the latest push:
The old app e2e failures match failures currently seen on |
Issue for this PR
Closes #29291
Type of change
What does this PR do?
Shell tool metadata previews were checking
text.length, which counts UTF-16 code units rather than UTF-8 bytes. Multi-byte output could exceed the metadata byte limit without being preview-truncated, and slicing by code units could start on an invalid surrogate boundary.This PR makes metadata preview truncation use UTF-8 byte length, trims from a valid byte boundary, and reuses the same byte-tail helper in the existing shell output tail path.
How did you verify your code works?
bun test test/tool/shell.test.ts -t "metadata output"bun test test/tool/shell.test.tsbun typecheckPATH="$HOME/.bun/bin:$PATH" .husky/pre-pushScreenshots / recordings
Not applicable; shell metadata behavior only.
Checklist