Skip to content

Truncate example output on rune boundaries in verifyexamples - #1154

Open
PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/verifyexamples-truncate-utf8
Open

PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/verifyexamples-truncate-utf8

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

truncate in cmd/verifyexamples sliced by byte index (text[:maxLength]), which can split a multi-byte UTF-8 rune — examples print °C, emoji, etc. — and emit invalid UTF-8 into logs, the CSV report, and the AI-verifier prompt.

Change

  • Back off to a rune boundary (utf8.RuneStart) before cutting.

Test

  • TestTruncateDoesNotSplitRunes: truncating "a°cdef" mid-rune now yields valid UTF-8. Fails before ("a\xc2..."), passes after.

truncate sliced by byte index, which can split a multi-byte UTF-8 rune
(examples print degree signs, emoji, etc.) and emit invalid UTF-8 into logs,
CSV, and the AI-verifier prompt. Back off to a rune boundary before cutting.
Copilot AI lite review requested due to automatic review settings September 22, 2026 03:18
@github-actions github-actions Bot added area:tooling Changes files in the tooling area size:small At most 30 changed lines across at most 2 files labels Sep 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The core logic change is correct and is covered by a focused regression test; only minor comment wording nits were identified.

Review effort: Lite
Findings: 2 Low severity

Open (2)
What changed in this PR

Fixes cmd/verifyexamples output truncation to avoid splitting multi-byte UTF-8 runes (e.g., °C, emoji), which could previously produce invalid UTF-8 in logs, CSV reports, and the AI-verifier prompt.

Changes:

  • Update truncate to back off to a UTF-8 rune boundary before slicing.
  • Add a unit test ensuring truncation does not produce invalid UTF-8 when cutting mid-rune.
File Description
cmd/​verifyexamples/​verifier.go Adjust truncation logic to avoid cutting in the middle of multi-byte UTF-8 runes.
cmd/​verifyexamples/​verifier_test.go Add regression test validating truncation preserves valid UTF-8 and doesn’t introduce replacement characters.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +143 to +144
// Back off to a rune boundary so truncation never splits a multi-byte rune
// (examples print °C, emoji, etc.) and emits invalid UTF-8 into logs/CSV.
Comment on lines +40 to +41
// "°" is two bytes (0xC2 0xB0); truncating at byte 1 must not split it.
got := truncate("a°cdef", 2)
@github-actions

Copy link
Copy Markdown
Contributor

Scope: internal-only

Changed Go contract: None — truncate in cmd/verifyexamples/verifier.go is an unexported helper in a standalone CLI tool (cmd/verifyexamples) used to verify example output during CI/dev tooling. No exported package API, public type/method, option, or user-visible framework behavior is changed. The fix only makes byte-length truncation UTF-8-safe.

Upstream evidence reviewed: No equivalent found. cmd/verifyexamples is a Go-specific internal verification tool with no analogous component in dotnet/src/, dotnet/samples/, python/packages/core/agent_framework/, or python/samples/ — it is ecosystem/tooling-specific to this repo's example-testing pipeline, not part of the Agent Framework's cross-language public surface.

Result: out of scope — this PR only touches an internal Go tooling helper (cmd/verifyexamples) with no exported API or observable framework behavior change, so no cross-repo parity review applies.

Generated by Go API Consistency Review Agent · copilot · auto · 13.5 AIC · ⌖ 7.24 AIC · ⊞ 9.2K ·

@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tooling Changes files in the tooling area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure size:small At most 30 changed lines across at most 2 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants