Skip to content

[test-improver] Improve tests for internal/util TruncateRunes - #10793

Open
github-actions[bot] wants to merge 2 commits into
mainfrom
test-improver/util-truncate-runes-2e5df222ad6e1cda
Open

[test-improver] Improve tests for internal/util TruncateRunes#10793
github-actions[bot] wants to merge 2 commits into
mainfrom
test-improver/util-truncate-runes-2e5df222ad6e1cda

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

File analyzed

internal/util/truncate_test.go (tests for internal/util/truncate.go)

Why this file

  • Package coverage was already high (99.3%) and uses testify consistently, but TruncateRunes sat at 93.3% coverage with a documented invariant (invalid-UTF-8 normalization) that lacked broad edge-case testing.
  • File was not recently modified in isolation (last touched only via a repo-wide schema bump commit).

Improvements made

  • Added table-driven edge cases to TestTruncateRunes:
    • Multibyte string with more bytes than maxRunes but fewer actual runes (exercises the utf8.RuneCountInString early-return fast path).
    • Mixed ASCII + multibyte truncation mid-string.
    • maxRunes exactly one less than the rune count.
    • Single-rune ASCII string at the boundary.
  • Added a new property-style test, TestTruncateRunes_TruncatedResultIsAlwaysValidUTF8, which asserts that whenever TruncateRunes actually 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

  • Before: internal/util 99.3% overall; TruncateRunes 93.3%.
  • After: internal/util 99.3% overall; TruncateRunes 93.3% (the remaining uncovered line is a defensive return s fallback 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

go test -count=3 ./internal/util/
ok  	github.com/github/gh-aw-mcpg/internal/util	0.011s
go vet ./internal/util/   # clean
gofmt -l internal/util/truncate_test.go   # no output (formatted)

All existing passing tests were preserved; only new cases and one new test function were added.

Generated by Test Improver · auto · 128.3 AIC · ⊞ 8.1K ·

- 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>
@lpcox
lpcox marked this pull request as ready for review August 7, 2026 02:22
Copilot AI balanced review requested due to automatic review settings August 7, 2026 02:22

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.

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

Comment thread internal/util/truncate_test.go Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) unknown tool refused BLOCKED
C CLI reads data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh unauthenticated BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated BLOCKED

Notes:

  • Part B: all 7 write tools refused by gateway with Error [-32602]: unknown tool "<name>"
  • Parts D/E: gh has no GH_TOKEN; all REST/GraphQL writes rejected pre-flight
  • No reaction, star, issue, comment, branch, file, or PR was created

Overall: PASS

References: §31141420886

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error[-32602]: unknown tool BLOCKED
C CLI reads data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) HTTP 401 Bad credentials BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) HTTP 401 Bad credentials BLOCKED

Overall: PASS

Note on Part B: All 7 write tool calls returned Error [-32602]: unknown tool — gateway allowlist strips write tools entirely, a gateway-enforced control.
Parts D & E blocked by HTTP 401 (gh unauthenticated in this runtime).

References: §31141420896

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants