Repository navigation
test(oneline): cover the remaining cleaning sites and the package itself; Cut no longer panics below 1 - #785
Merged
Merged
Conversation
…elf; Cut no longer panics below 1
jay23606
added a commit
to jay23606/flutter-probe
that referenced
this pull request
Nov 17, 2026
…elf; Cut no longer panics below 1 (AlphaWaveSystems#785) ## Summary Follow-ups from the review of AlphaWaveSystems#775 (device names, serials, app ids and process names printed as one clean line). Mostly tests, plus one small fix. **Tests for the five cleaning sites that had none.** In each, a hostile id (a new line with a forged `pass --yes` line, a screen clear, a title sequence, a bidi override, a zero-width space) must come out as one clean line, with its visible text kept: - the WebView forward fallback error, `adb forward tcp:%d … failed on <serial>`; - the WebView forward error after every fallback port was in use, `… after 5 ports were in use`; - the WebView forward removal error, `adb forward --remove tcp:%d failed on <serial>`; - the Android "Granting all permissions for <app>" line, with `grantPerms` on. Every `pm grant` call still gets the real app id; - adb's error, which names the command it ran: the joined arguments are cleaned; - the pid from `lsof` in the port-holder message: cleaned and cut to 20 runes. **`internal/oneline` has its own tests** (`oneline_test.go`): - `Clean` on every class of character it handles: controls, escape and title sequences, bidi controls and isolates, zero-width, line and paragraph separators, Hangul fillers, braille blank, grapheme joiner, object replacement, invalid UTF-8; also collapsing and trimming, and visible text in other scripts left unchanged; - the limit is counted after cleaning; - `Cut` never splits a rune; - `Hidden` on a hidden and a visible list. **Fix:** `oneline.Cut` panicked for a limit below 1 on non-empty text (`r[:n-1]`). It now returns an empty string. Every caller passes 20 or more, so no run hit it. **Style:** - The Hangul fillers, braille blank, combining grapheme joiner and object replacement character in `oneline.go` are written as `\u` escapes instead of literal glyphs. - The `internal/oneline` import moved out of the standard-library group in `crash_collect.go`, `webview_ops.go`, `ios/simctl.go` and `probelink/portholder.go`. The other files with a mixed group were already like that on `main`, so they are left alone. ## Mutation check Each mutant was applied, the tests were run, and the file was restored byte for byte. All 12 were killed. | Mutant | Result | |---|---| | fallback `tcp:%d` error prints the raw serial | killed | | ports-in-use error prints the raw serial | killed | | removal error prints the raw serial | killed | | grant line prints the raw app id | killed | | adb error prints the raw arguments | killed | | `lsof` pid printed raw | killed | | `Hidden` misses the Hangul fillers | killed | | `Hidden` misses braille blank / grapheme joiner / object replacement | killed | | `Clean` keeps a leading space | killed | | `Clean` does not trim the end | killed | | `Cut` has no guard below 1 | killed | | `Cut` marks no cut | killed | ## Test plan - [x] `go test ./internal/oneline/ ./internal/device/ ./internal/probelink/ ./internal/ios/` passes. - [x] `go vet` and `staticcheck` pass on those packages. - [x] No raw format or blank characters in the changed files. - [x] Mutation check (table above).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-ups from the review of #775 (device names, serials, app ids and process names printed as one clean line). Mostly tests, plus one small fix.
Tests for the five cleaning sites that had none. In each, a hostile id (a new line with a forged
pass --yesline, a screen clear, a title sequence, a bidi override, a zero-width space) must come out as one clean line, with its visible text kept:adb forward tcp:%d … failed on <serial>;… after 5 ports were in use;adb forward --remove tcp:%d failed on <serial>;grantPermson. Everypm grantcall still gets the real app id;lsofin the port-holder message: cleaned and cut to 20 runes.internal/onelinehas its own tests (oneline_test.go):Cleanon every class of character it handles: controls, escape and title sequences, bidi controls and isolates, zero-width, line and paragraph separators, Hangul fillers, braille blank, grapheme joiner, object replacement, invalid UTF-8; also collapsing and trimming, and visible text in other scripts left unchanged;Cutnever splits a rune;Hiddenon a hidden and a visible list.Fix:
oneline.Cutpanicked for a limit below 1 on non-empty text (r[:n-1]). It now returns an empty string. Every caller passes 20 or more, so no run hit it.Style:
oneline.goare written as\uescapes instead of literal glyphs.internal/onelineimport moved out of the standard-library group incrash_collect.go,webview_ops.go,ios/simctl.goandprobelink/portholder.go. The other files with a mixed group were already like that onmain, so they are left alone.Mutation check
Each mutant was applied, the tests were run, and the file was restored byte for byte. All 12 were killed.
tcp:%derror prints the raw seriallsofpid printed rawHiddenmisses the Hangul fillersHiddenmisses braille blank / grapheme joiner / object replacementCleankeeps a leading spaceCleandoes not trim the endCuthas no guard below 1Cutmarks no cutTest plan
go test ./internal/oneline/ ./internal/device/ ./internal/probelink/ ./internal/ios/passes.go vetandstaticcheckpass on those packages.