[test-improver] Improve tests for internal/util TruncateRunes - #10793
[test-improver] Improve tests for internal/util TruncateRunes#10793github-actions[bot] wants to merge 2 commits into
Conversation
- Add table-driven cases: multibyte with more bytes than maxRunes but fewer runes, mixed ASCII/multibyte truncation, maxRunes one less than rune count, and single-rune edge cases. - Add TestTruncateRunes_TruncatedResultIsAlwaysValidUTF8 property test verifying truncated output is always valid UTF-8 across ASCII, multibyte, emoji, and malformed-byte inputs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Expands TruncateRunes tests with boundary, multibyte, and malformed UTF-8 cases.
Changes:
- Adds table-driven truncation edge cases.
- Adds UTF-8 validity invariant coverage.
Show a summary per file
| File | Description |
|---|---|
internal/util/truncate_test.go |
Extends TruncateRunes tests and UTF-8 validation. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Notes:
Overall: PASS References: §31141420886
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §31141420896
|
File analyzed
internal/util/truncate_test.go(tests forinternal/util/truncate.go)Why this file
TruncateRunessat at 93.3% coverage with a documented invariant (invalid-UTF-8 normalization) that lacked broad edge-case testing.Improvements made
TestTruncateRunes:maxRunesbut fewer actual runes (exercises theutf8.RuneCountInStringearly-return fast path).maxRunesexactly one less than the rune count.TestTruncateRunes_TruncatedResultIsAlwaysValidUTF8, which asserts that wheneverTruncateRunesactually truncates a string, the result is always valid UTF-8 — covering ASCII, multibyte (Japanese), emoji, and malformed-byte inputs, guarding the invariant documented in the function's doc comment.Coverage
internal/util99.3% overall;TruncateRunes93.3%.internal/util99.3% overall;TruncateRunes93.3% (the remaining uncovered line is a defensivereturn sfallback at the end of the byte-walk loop that is unreachable given the preceding fast-path checks — kept as documented defensive code, not removed).Test output
All existing passing tests were preserved; only new cases and one new test function were added.