test(shared): add unit tests for surrogate-safe UTF-16 string slicing helpers#97805
Conversation
… helpers Add unit tests for sliceUtf16Safe and truncateUtf16Safe functions in src/shared/utf16-slice.ts to verify UTF-16 string slicing behavior. Tests cover: - sliceUtf16Safe slices ASCII string normally - sliceUtf16Safe handles negative start/end - sliceUtf16Safe handles start/end beyond length - sliceUtf16Safe swaps start and end when start > end - sliceUtf16Safe preserves emoji with surrogate pairs - sliceUtf16Safe avoids splitting surrogate pair at start/end - truncateUtf16Safe returns input when shorter than limit - truncateUtf16Safe truncates when longer than limit - truncateUtf16Safe handles zero/negative limit - truncateUtf16Safe floors decimal limit - truncateUtf16Safe preserves emoji with surrogate pairs - truncateUtf16Safe avoids splitting surrogate pair
|
Codex review: needs maintainer review before merge. Reviewed June 29, 2026, 11:03 AM ET / 15:03 UTC. Summary PR surface: Tests +88. Total +88 across 1 file. Reproducibility: not applicable. This PR adds regression tests for an existing helper rather than reporting a runtime bug. The expected helper contract is visible in Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Land the focused helper test coverage after ordinary maintainer and CI review, while keeping the production helper behavior unchanged. Do we have a high-confidence way to reproduce the issue? Not applicable; this PR adds regression tests for an existing helper rather than reporting a runtime bug. The expected helper contract is visible in Is this the best way to solve the issue? Yes; a colocated Vitest file is the narrowest maintainable layer for direct helper coverage, and current main does not already have equivalent shared-helper tests. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 86b9b88f4066. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Tests +88. Total +88 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
Replace vague 'result.length >= 0' assertions with exact expected output checks for surrogate pair boundary cases. The helper returns empty string when slicing at surrogate pair boundaries.
… helpers (openclaw#97805) * test(shared): add unit tests for surrogate-safe UTF-16 string slicing helpers Add unit tests for sliceUtf16Safe and truncateUtf16Safe functions in src/shared/utf16-slice.ts to verify UTF-16 string slicing behavior. Tests cover: - sliceUtf16Safe slices ASCII string normally - sliceUtf16Safe handles negative start/end - sliceUtf16Safe handles start/end beyond length - sliceUtf16Safe swaps start and end when start > end - sliceUtf16Safe preserves emoji with surrogate pairs - sliceUtf16Safe avoids splitting surrogate pair at start/end - truncateUtf16Safe returns input when shorter than limit - truncateUtf16Safe truncates when longer than limit - truncateUtf16Safe handles zero/negative limit - truncateUtf16Safe floors decimal limit - truncateUtf16Safe preserves emoji with surrogate pairs - truncateUtf16Safe avoids splitting surrogate pair * fix: replace tautological surrogate assertions with exact output checks Replace vague 'result.length >= 0' assertions with exact expected output checks for surrogate pair boundary cases. The helper returns empty string when slicing at surrogate pair boundaries.
… helpers (openclaw#97805) * test(shared): add unit tests for surrogate-safe UTF-16 string slicing helpers Add unit tests for sliceUtf16Safe and truncateUtf16Safe functions in src/shared/utf16-slice.ts to verify UTF-16 string slicing behavior. Tests cover: - sliceUtf16Safe slices ASCII string normally - sliceUtf16Safe handles negative start/end - sliceUtf16Safe handles start/end beyond length - sliceUtf16Safe swaps start and end when start > end - sliceUtf16Safe preserves emoji with surrogate pairs - sliceUtf16Safe avoids splitting surrogate pair at start/end - truncateUtf16Safe returns input when shorter than limit - truncateUtf16Safe truncates when longer than limit - truncateUtf16Safe handles zero/negative limit - truncateUtf16Safe floors decimal limit - truncateUtf16Safe preserves emoji with surrogate pairs - truncateUtf16Safe avoids splitting surrogate pair * fix: replace tautological surrogate assertions with exact output checks Replace vague 'result.length >= 0' assertions with exact expected output checks for surrogate pair boundary cases. The helper returns empty string when slicing at surrogate pair boundaries.
… helpers (openclaw#97805) * test(shared): add unit tests for surrogate-safe UTF-16 string slicing helpers Add unit tests for sliceUtf16Safe and truncateUtf16Safe functions in src/shared/utf16-slice.ts to verify UTF-16 string slicing behavior. Tests cover: - sliceUtf16Safe slices ASCII string normally - sliceUtf16Safe handles negative start/end - sliceUtf16Safe handles start/end beyond length - sliceUtf16Safe swaps start and end when start > end - sliceUtf16Safe preserves emoji with surrogate pairs - sliceUtf16Safe avoids splitting surrogate pair at start/end - truncateUtf16Safe returns input when shorter than limit - truncateUtf16Safe truncates when longer than limit - truncateUtf16Safe handles zero/negative limit - truncateUtf16Safe floors decimal limit - truncateUtf16Safe preserves emoji with surrogate pairs - truncateUtf16Safe avoids splitting surrogate pair * fix: replace tautological surrogate assertions with exact output checks Replace vague 'result.length >= 0' assertions with exact expected output checks for surrogate pair boundary cases. The helper returns empty string when slicing at surrogate pair boundaries.
… helpers (openclaw#97805) * test(shared): add unit tests for surrogate-safe UTF-16 string slicing helpers Add unit tests for sliceUtf16Safe and truncateUtf16Safe functions in src/shared/utf16-slice.ts to verify UTF-16 string slicing behavior. Tests cover: - sliceUtf16Safe slices ASCII string normally - sliceUtf16Safe handles negative start/end - sliceUtf16Safe handles start/end beyond length - sliceUtf16Safe swaps start and end when start > end - sliceUtf16Safe preserves emoji with surrogate pairs - sliceUtf16Safe avoids splitting surrogate pair at start/end - truncateUtf16Safe returns input when shorter than limit - truncateUtf16Safe truncates when longer than limit - truncateUtf16Safe handles zero/negative limit - truncateUtf16Safe floors decimal limit - truncateUtf16Safe preserves emoji with surrogate pairs - truncateUtf16Safe avoids splitting surrogate pair * fix: replace tautological surrogate assertions with exact output checks Replace vague 'result.length >= 0' assertions with exact expected output checks for surrogate pair boundary cases. The helper returns empty string when slicing at surrogate pair boundaries.
What Problem This Solves
The
utf16-slice.tsmodule provides surrogate-safe UTF-16 string slicing helpers. However, this module lacked unit tests to verify the UTF-16 string slicing behavior, which could lead to regressions when the function is modified.Why This Change Was Made
Add unit tests for
sliceUtf16SafeandtruncateUtf16Safefunctions to verify UTF-16 string slicing behavior. This improves test coverage and prevents regressions.Focused tests cover ASCII slicing, negative indices, out-of-bounds handling, surrogate pair preservation, and emoji handling.
User Impact
UTF-16 string slicing now has comprehensive test coverage, reducing the risk of regressions when the function is modified.
Evidence
Reproducibility: not applicable. This PR adds direct coverage for existing helper behavior rather than reporting a user-visible runtime bug. Source inspection confirms the helper behavior the tests target.
Direct behavior probe:
Targeted test:
Formatting:
Whitespace:
AI-assisted
Prepared with Codex. I reviewed the change, understand the touched code path, and kept the PR focused on the bug described above.