Skip to content

fix(device): device names, serials and app ids from adb and simctl are printed as plain text on one line - #775

Merged
pbertsch merged 4 commits into
mainfrom
fix/clean-printed-device-names
Nov 17, 2026
Merged

pbertsch merged 4 commits into
mainfrom
fix/clean-printed-device-names

Conversation

@pbertsch

@pbertsch pbertsch commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Device names, serials and app ids that come from adb or simctl output are now printed as plain text on one line. This is the first of three small changes. The other two cover the run's device context and the parallel run's device labels.

A device name can hold anything. A simulator name in simctl's JSON can hold a new line, and an adb model name can hold an escape sequence. Printed raw, it could carry a terminal escape (clear the screen, set the window title), a bidi override, a zero-width character, or a second line that looks like one of probe's own ("pass --yes to continue"). Each of these sites now prints its value through device.CleanOneLine(value, 80), the existing helper the runner already uses for app ids and serials. Display only: the value given to adb and simctl, and every value used in logic, is unchanged.

Site What is printed
internal/cli/device.go probe device list each row's serial, state and name
internal/cli/device_view.go probe device view "Connecting to the agent on ()"
internal/cli/device_set.go probe device set both refusals (state, physical iOS): name, id, state
internal/device/manager.go the install, grant and launch lines (app path, serial, app id) on Android and iOS; "device … not found"; "Created simulator … ()"; the token-not-found error's app id
internal/device/adb.go "versionName not found for "
internal/device/port_follow.go the port-following notice: the app id, and each package name of the holder, cleaned one by one so the notice's own wording is kept
internal/device/webview_forward.go the four forward errors' serial
after review: internal/cli/device_view.go the listening line in all three output modes (opts.Device.Name); the "several devices are ready" choice (the ids); the connect line, now connectingLine
after review: internal/cli/device_set.go the done line, now setDoneLine (name, id)
after review: internal/device/manager.go:311 the simulator-mismatch error (both udids)
after review: internal/device/adb.go the adb error that carries adb's stderr (cut to 400); the uiautomator dump error that carries the device's output (cut to 400)
after review: internal/ios/simctl.go "did not boot" (udid) and "is not installed on" (bundle id, udid)
after review: internal/probelink/portholder.go the port-holder hint: the lsof process name of this machine (any program can choose it) and the pid

internal/oneline (new leaf package). internal/device imports internal/probelink, so probelink could not use device.CleanOneLine. The cleaner, with its hidden-character rule and its cut, moved unchanged into internal/oneline. device.CleanOneLine, hiddenRune and cutRunes now delegate to it, and probelink and ios use it directly.

Not cleaned, and why:

  • probelink/version.go:100: the agent's handshake app id is already limited to a plain application id by plainAppID (version.go:112). A hostile one never reaches the mismatch warning, and a test now shows it.
  • The port-following notice: PortOwners keeps valid package names only, and the follower refuses an app id that is not a package name (ValidPackageName), so neither reaches the notice raw. The cleaning there is defense in depth. The test shows a hostile package name is filtered out, and the notice is clean with its wording kept.

A %q site was left as it is: Go's %q already escapes control, bidi and zero-width characters (strconv.Quote). Examples are "%d devices are named %q" and "simulator %q is %s".

Tests (through the real print paths)

  • TestDeviceListPrintsAHostileNameCleaned: probe device list against a fake adb on PATH whose model name holds an escape sequence, a bidi override and a zero-width space.
  • TestDeviceSetRefusalNamesAHostileDeviceOnOneLine and TestCleaningIsForDisplayOnly: the device set refusals with a name holding a new line and a fake "pass --yes" line; checkSettable returns the device unchanged.
  • TestDeviceViewStartupLineNamesAHostileDeviceCleaned: serveDeviceView in json, plain and print-token mode with a hostile device name.
  • TestDeviceViewChoiceListsHostileIDsCleaned: pickViewDevice with two ready devices whose serials hold an escape and a title sequence.
  • TestConnectAndSetDoneLinesNameAHostileDeviceCleaned: connectingLine and setDoneLine. These two lines sit after a real agent connection or a real device setting, so the line builders the commands call are tested directly.
  • TestEnsureADBNamesTheSerialCleaned, TestStartIOSNamedPrintsIDsCleaned (the mismatch error, and the created line with a hostile udid from a fake xcrun), TestIOSInstallAndLaunchPrintsNamesCleaned (simctl gets the real udid and bundle id), TestInstallAndLaunchPrintsNamesCleaned (Android: adb gets the real serial).
  • TestAndroidLaunchGetsTheRealAppID: a fake adb logs each argument NUL-separated, so a new line inside an argument stays one argument. The am start call carries the real, hostile app id.
  • TestTokenErrorNamesTheAppCleaned, TestGetAppVersionNamesTheAppCleaned, TestADBErrorsCarryStderrCleaned (adb stderr, and the dump retry), TestUIAutomatorDumpCarriesDeviceOutputCleaned (a dump that runs but does not dump), TestWebViewForwardErrorsNameTheSerialCleaned, TestPortFollowNoticeNamesPackagesCleaned.
  • TestSimctlErrorsNameIDsCleaned (fake xcrun), TestPortHolderNamesAHostileProcessCleaned (a fake lsof on PATH, through PortHolder), TestHostileHandshakeAppIDNeverReachesTheWarning.

Hostile Unicode is built from code points in the test source, so the source is ASCII (staticcheck ST1018). An earlier push of this PR had raw U+202E and U+200B in two tests, and hosted Lint failed on it.

Mutation check

Each mutant was applied, the tests were run, and the file was restored byte for byte.

  • First round: 8 of 8 killed. "adb gets the cleaned serial" survived at first and was killed after the test checked each call.
  • After review: 16 of 18 killed. "uiautomator: raw last error" survived until the dump-output test was added. The two port-follow mutants survive by design: their values are filtered upstream, as explained above, so no input reaches those lines raw.
Mutant Result
device list prints the raw name killed
device set prints the raw name / the raw state killed
the physical-device refusal prints the raw name killed
the app-not-running error prints the raw app id killed
Launching prints the raw app id killed
Installing prints the raw serial (Android) killed
adb gets the cleaned serial killed
device view listening line: raw name killed
device view choice: raw ids killed
connect line: raw name killed
set done line: raw name killed
StartIOSNamed mismatch: raw udid killed
StartIOSNamed created: raw udid killed
EnsureADB: raw serial killed
iOS Installing: raw serial killed
Android launch gets the cleaned app id killed
versionName: raw app id killed
adb run: raw stderr killed
uiautomator: raw last error killed
webview forward: raw serial killed
port holder: raw command name killed
simctl boot: raw udid killed
simctl reinstall: raw bundle id killed
port follow: raw app id survives: filtered upstream (ValidPackageName)
port follow: raw holder names survives: filtered upstream (PortOwners)

Not covered

  • internal/runner (the device context, the reconnect hints, the orchestrator's labels) is in the next two PRs.

Test plan

  • go test ./internal/... passes.
  • staticcheck ./... passes, and there are no raw format characters in the changed files.
  • go vet ./internal/cli/ ./internal/device/ passes.
  • Mutation check (table above).

@pbertsch
pbertsch merged commit f3eba66 into main Nov 17, 2026
10 of 11 checks passed
pbertsch added a commit that referenced this pull request Nov 17, 2026
… one line (#776)

## Summary

A parallel run (`--devices`) now names each lane's device as plain text on one line. This is part 2 of 3. Part 1 (#775) covered the names printed by `probe device`, and part 3 covers the run's device context.

**On main**, `internal/runner/orchestrator.go` printed a lane's device id and name as `adb` or `simctl` reported them:
- `deviceLabel` (the "Device N: …" lane list);
- `shortID` (the `[device]` label of the progress, warning and "Connected" lines and of the result rows; it cut the id to 12 **bytes**, which can split a multi-byte character);
- the `[id]` prefix of the port-forward, hold, token, connect and handshake errors;
- the run's error summary.

A name can hold a new line, an escape sequence, a bidi override or a zero-width character, and so could print a second line that looked like probe's own ("pass --yes to continue").

## The change

- **`shortID`** cleans the id with `device.CleanOneLine` and cuts it to 12 **characters**. A plain serial reads exactly as before (`emulator-5554` → `emulator-555`).
- **`label`** (new) is the whole id for error messages, cleaned.
- **`deviceLabel`** returns the cleaned name, or the cleaned id when there is no name.
- **Display only:** the lane's `DeviceID` and `DeviceName` are unchanged. That is the id given to `adb` and `simctl`, used for the port, and written to the JSON and JUnit reports, whose encoders escape it.

## Tests (through the real run)

- `TestParallelRunPrintsHostileDeviceLabelsCleaned` runs a one-lane parallel run with the orchestrator harness. The lane's name and id hold a new line with a fake "pass --yes to continue" line, an escape sequence, an OSC title sequence, a bidi override and a zero-width space. No printed line forges its own line or carries one of those characters; the color codes probe adds itself are allowed. The name's visible text is shown.
- `TestFailedLaneErrorNamesTheDeviceCleaned` runs a lane whose connect fails, because no fake agent is on its port. Its error and the run's summary name the hostile id on one clean line, and a lane with no name is listed by its cleaned id.
- `TestLaneLabelsAreDisplayOnly`: the lane keeps its raw id and name; `shortID` cuts by characters (Japanese text) and leaves a plain serial as before.

## Mutation check

Each mutant was applied, the tests were run, and the file was restored byte for byte. All 5 were killed. "label prints the raw id" survived at first, because the happy-path run never reaches an error message. The failed-lane test was added for it, and it is now killed.

| Mutant | Result |
|---|---|
| `shortID` prints the raw id | killed |
| `shortID` cuts bytes | killed |
| `deviceLabel` prints the raw name | killed |
| `label` prints the raw id | killed |
| the Connected line prints the raw id | killed |

## Test plan

- [x] `go test ./internal/runner/` passes.
- [x] `go vet ./internal/runner/` passes.
- [x] Mutation check (table above).
pbertsch added a commit that referenced this pull request Nov 17, 2026
…elf; Cut no longer panics below 1 (#785)

## 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 --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).
pbertsch added a commit that referenced this pull request Nov 17, 2026
… the app id and serial as plain text (#779)

## Summary

This makes the lines a run prints about the app and the device show the app id and the serial as plain text on one line. It is part 3 of 3: #775 covered `probe device` and `internal/device`, and #776 the parallel run's lane labels.

**On main**, these printed `dc.AppID` and `dc.Serial` (or `deviceSerial`) as given:
- `internal/runner/device_context.go`: the single-device warning `[serial]`, force-stopping, relaunching (×5), the reinstall question, clearing data, the data-path error, the set-language error, iOS notification reinstall, granting permissions, killing, launching;
- `internal/runner/reconnect_hint.go`: the three "the app … is not running" hints;
- `internal/runner/runner.go`: the pull error;
- `internal/cli/test.go`: "Physical device detected";
- `internal/cli/record.go`: "Recording on".

A serial comes from `adb` or `simctl`. The app id is validated when it comes from `probe.yaml`, but these lines print whatever the device context holds. A value with a new line, an escape sequence, a bidi override or a zero-width character could forge a line or change the terminal.

## The change

- `DeviceContext.appShown()` and `serialShown()` return `device.CleanOneLine(value, 80)`. Each of the 15 print sites in `device_context.go` and the hint and pull sites use them. The two CLI sites call `device.CleanOneLine` directly.
- **Display only:** every value given to `adb`, `simctl` or `devicectl`, and every comparison, still uses `dc.AppID` and `dc.Serial` as they are.
- The reconnect hint is only reached for an app id that passes `ValidPackageName`, so a hostile id never got there. It is cleaned anyway, the same way.
- Script-authored names printed by the runner (test, recipe and measurement names, mostly `%q`) are not device output and are not part of this change.

## Tests (through the real print path)

`TestLifecycleLinesPrintAppAndSerialCleaned` runs kill, launch, restart and clear data on a `DeviceContext` with the recording fake `adb` (`recordingDevice`). Its app id holds a new line with a fake "pass --yes to continue" line, an escape sequence, a bidi override and a zero-width space, and its serial an OSC title sequence. For each step:
- no printed line forges its own line or carries one of those characters (probe's own color codes are allowed);
- every `adb -s` call gets the **real** serial.

## Mutation check

Each mutant was applied, the test was run, and the file was restored byte for byte. All 5 were killed.

| Mutant | Result |
|---|---|
| `appShown` returns the raw app id | killed |
| `serialShown` returns the raw serial | killed |
| the kill line prints the raw app id | killed |
| the clear line prints the raw serial | killed |
| adb gets the cleaned serial (display-only rule broken) | killed |

## Not covered

- The two CLI lines ("Physical device detected", "Recording on") are cleaned with the same call but have no test of their own: they sit deep in the `probe test` and `probe record` flows.

## Test plan

- [x] `go test ./internal/runner/ ./internal/cli/` passes.
- [x] `go vet ./internal/runner/ ./internal/cli/` passes.
- [x] Mutation check (table above).


## Review follow-up

- **Windows build:** `printed_device_names_test.go` uses `recordingDevice`, which is defined only for `!windows`, so it now has the same build tag. `GOOS=windows go vet ./internal/...` passes.
- **More prints cleaned in `probe test`:**
  - "Connected to ProbeAgent on <serial>" (an auto-picked id comes from the device list and is not validated);
  - the `-v` "ensuring adb + device <serial> reachable" line;
  - the cloud run's "Connected to ProbeAgent on <device>";
  - both "App uploaded: <id>" lines (the id is the provider's API response).
- **Data-path errors** quote the path `simctl` returned with `%q`.
- **Tests for the other sites**, through their real paths with hostile values:
  - the three data-path errors;
  - set language on a physical iPhone;
  - grant all permissions (the grants still get the real id);
  - the reconnect hint, which is skipped for an app id that is not a package name, so its cleaning is a second line behind that gate.

  A failed pull is not printed, so its cleaning can't be observed; the CHANGELOG now says which sites are tested and which are a second line. A source check covers the `probe test` prints.
- **Mutants:** 10 of 10 killed.
  - raw data path (×3), raw serial in the data-path error;
  - raw app id in set language and in grant;
  - the hint's package-name gate removed;
  - raw connected, trace and upload prints.

## Second follow-up

- **Cloud prints:** the cloud upload and session start, which were the same code in two paths, are now one function, `uploadAndStartCloudSession`. Its "Starting cloud session on <device>" line and the relay "Connected to ProbeAgent via relay on <device>" line print the device cleaned, like the other cloud lines.
- **The provider gets the real values:** `TestCloudSessionGetsTheRealValuesAndPrintsThemCleaned` checks, with a fake provider, that `UploadApp` gets the app path and `StartSession` gets the id `UploadApp` returned and the target device as they are, while both printed lines are clean.
- **Mutants:** 5 of 5 killed: the provider gets a cleaned device, the provider gets a cleaned app id, and the starting, upload and relay lines printed raw.
- **CHANGELOG:** says the data-path errors quote the path with `%q`, and names the cloud lines.
jay23606 added a commit to jay23606/flutter-probe that referenced this pull request Nov 17, 2026
…e printed as plain text on one line (AlphaWaveSystems#775)

## Summary

Device names, serials and app ids that come from `adb` or `simctl` output are now printed as plain text on one line. This is the first of three small changes. The other two cover the run's device context and the parallel run's device labels.

A device name can hold anything. A simulator name in simctl's JSON can hold a new line, and an `adb` model name can hold an escape sequence. Printed raw, it could carry a terminal escape (clear the screen, set the window title), a bidi override, a zero-width character, or a second line that looks like one of probe's own ("pass --yes to continue"). Each of these sites now prints its value through `device.CleanOneLine(value, 80)`, the existing helper the runner already uses for app ids and serials. **Display only:** the value given to `adb` and `simctl`, and every value used in logic, is unchanged.

| Site | What is printed |
|---|---|
| `internal/cli/device.go` `probe device list` | each row's serial, state and name |
| `internal/cli/device_view.go` `probe device view` | "Connecting to the agent on <name> (<id>)" |
| `internal/cli/device_set.go` `probe device set` | both refusals (state, physical iOS): name, id, state |
| `internal/device/manager.go` | the install, grant and launch lines (app path, serial, app id) on Android and iOS; "device … not found"; "Created simulator … (<udid>)"; the token-not-found error's app id |
| `internal/device/adb.go` | "versionName not found for <app id>" |
| `internal/device/port_follow.go` | the port-following notice: the app id, and each package name of the holder, cleaned one by one so the notice's own wording is kept |
| `internal/device/webview_forward.go` | the four forward errors' serial |
| **after review:** `internal/cli/device_view.go` | the listening line in all three output modes (`opts.Device.Name`); the "several devices are ready" choice (the ids); the connect line, now `connectingLine` |
| **after review:** `internal/cli/device_set.go` | the done line, now `setDoneLine` (name, id) |
| **after review:** `internal/device/manager.go:311` | the simulator-mismatch error (both udids) |
| **after review:** `internal/device/adb.go` | the `adb` error that carries `adb`'s stderr (cut to 400); the `uiautomator dump` error that carries the device's output (cut to 400) |
| **after review:** `internal/ios/simctl.go` | "did not boot" (udid) and "is not installed on" (bundle id, udid) |
| **after review:** `internal/probelink/portholder.go` | the port-holder hint: the `lsof` process name of this machine (any program can choose it) and the pid |

**`internal/oneline` (new leaf package).** `internal/device` imports `internal/probelink`, so `probelink` could not use `device.CleanOneLine`. The cleaner, with its hidden-character rule and its cut, moved unchanged into `internal/oneline`. `device.CleanOneLine`, `hiddenRune` and `cutRunes` now delegate to it, and `probelink` and `ios` use it directly.

**Not cleaned, and why:**
- `probelink/version.go:100`: the agent's handshake app id is already limited to a plain application id by `plainAppID` (`version.go:112`). A hostile one never reaches the mismatch warning, and a test now shows it.
- The port-following notice: `PortOwners` keeps valid package names only, and the follower refuses an app id that is not a package name (`ValidPackageName`), so neither reaches the notice raw. The cleaning there is defense in depth. The test shows a hostile package name is filtered out, and the notice is clean with its wording kept.

A `%q` site was left as it is: Go's `%q` already escapes control, bidi and zero-width characters (`strconv.Quote`). Examples are "%d devices are named %q" and "simulator %q is %s".

## Tests (through the real print paths)

- `TestDeviceListPrintsAHostileNameCleaned`: `probe device list` against a fake `adb` on PATH whose model name holds an escape sequence, a bidi override and a zero-width space.
- `TestDeviceSetRefusalNamesAHostileDeviceOnOneLine` and `TestCleaningIsForDisplayOnly`: the `device set` refusals with a name holding a new line and a fake "pass --yes" line; `checkSettable` returns the device unchanged.
- `TestDeviceViewStartupLineNamesAHostileDeviceCleaned`: `serveDeviceView` in json, plain and print-token mode with a hostile device name.
- `TestDeviceViewChoiceListsHostileIDsCleaned`: `pickViewDevice` with two ready devices whose serials hold an escape and a title sequence.
- `TestConnectAndSetDoneLinesNameAHostileDeviceCleaned`: `connectingLine` and `setDoneLine`. These two lines sit after a real agent connection or a real device setting, so the line builders the commands call are tested directly.
- `TestEnsureADBNamesTheSerialCleaned`, `TestStartIOSNamedPrintsIDsCleaned` (the mismatch error, and the created line with a hostile udid from a fake `xcrun`), `TestIOSInstallAndLaunchPrintsNamesCleaned` (simctl gets the real udid and bundle id), `TestInstallAndLaunchPrintsNamesCleaned` (Android: `adb` gets the real serial).
- **`TestAndroidLaunchGetsTheRealAppID`**: a fake `adb` logs each argument NUL-separated, so a new line inside an argument stays one argument. The `am start` call carries the real, hostile app id.
- `TestTokenErrorNamesTheAppCleaned`, `TestGetAppVersionNamesTheAppCleaned`, `TestADBErrorsCarryStderrCleaned` (`adb` stderr, and the dump retry), `TestUIAutomatorDumpCarriesDeviceOutputCleaned` (a dump that runs but does not dump), `TestWebViewForwardErrorsNameTheSerialCleaned`, `TestPortFollowNoticeNamesPackagesCleaned`.
- `TestSimctlErrorsNameIDsCleaned` (fake `xcrun`), `TestPortHolderNamesAHostileProcessCleaned` (a fake `lsof` on PATH, through `PortHolder`), `TestHostileHandshakeAppIDNeverReachesTheWarning`.

Hostile Unicode is built from code points in the test source, so the source is ASCII (staticcheck ST1018). An earlier push of this PR had raw U+202E and U+200B in two tests, and hosted Lint failed on it.

## Mutation check

Each mutant was applied, the tests were run, and the file was restored byte for byte.

- **First round: 8 of 8 killed.** "adb gets the cleaned serial" survived at first and was killed after the test checked each call.
- **After review: 16 of 18 killed.** "uiautomator: raw last error" survived until the dump-output test was added. **The two port-follow mutants survive by design:** their values are filtered upstream, as explained above, so no input reaches those lines raw.

| Mutant | Result |
|---|---|
| device list prints the raw name | killed |
| device set prints the raw name / the raw state | killed |
| the physical-device refusal prints the raw name | killed |
| the app-not-running error prints the raw app id | killed |
| Launching prints the raw app id | killed |
| Installing prints the raw serial (Android) | killed |
| adb gets the cleaned serial | killed |
| device view listening line: raw name | killed |
| device view choice: raw ids | killed |
| connect line: raw name | killed |
| set done line: raw name | killed |
| StartIOSNamed mismatch: raw udid | killed |
| StartIOSNamed created: raw udid | killed |
| EnsureADB: raw serial | killed |
| iOS Installing: raw serial | killed |
| **Android launch gets the cleaned app id** | killed |
| versionName: raw app id | killed |
| adb run: raw stderr | killed |
| uiautomator: raw last error | killed |
| webview forward: raw serial | killed |
| port holder: raw command name | killed |
| simctl boot: raw udid | killed |
| simctl reinstall: raw bundle id | killed |
| port follow: raw app id | survives: filtered upstream (`ValidPackageName`) |
| port follow: raw holder names | survives: filtered upstream (`PortOwners`) |

## Not covered

- `internal/runner` (the device context, the reconnect hints, the orchestrator's labels) is in the next two PRs.

## Test plan

- [x] `go test ./internal/...` passes.
- [x] `staticcheck ./...` passes, and there are no raw format characters in the changed files.
- [x] `go vet ./internal/cli/ ./internal/device/` passes.
- [x] Mutation check (table above).
jay23606 added a commit to jay23606/flutter-probe that referenced this pull request Nov 17, 2026
… one line (AlphaWaveSystems#776)

## Summary

A parallel run (`--devices`) now names each lane's device as plain text on one line. This is part 2 of 3. Part 1 (AlphaWaveSystems#775) covered the names printed by `probe device`, and part 3 covers the run's device context.

**On main**, `internal/runner/orchestrator.go` printed a lane's device id and name as `adb` or `simctl` reported them:
- `deviceLabel` (the "Device N: …" lane list);
- `shortID` (the `[device]` label of the progress, warning and "Connected" lines and of the result rows; it cut the id to 12 **bytes**, which can split a multi-byte character);
- the `[id]` prefix of the port-forward, hold, token, connect and handshake errors;
- the run's error summary.

A name can hold a new line, an escape sequence, a bidi override or a zero-width character, and so could print a second line that looked like probe's own ("pass --yes to continue").

## The change

- **`shortID`** cleans the id with `device.CleanOneLine` and cuts it to 12 **characters**. A plain serial reads exactly as before (`emulator-5554` → `emulator-555`).
- **`label`** (new) is the whole id for error messages, cleaned.
- **`deviceLabel`** returns the cleaned name, or the cleaned id when there is no name.
- **Display only:** the lane's `DeviceID` and `DeviceName` are unchanged. That is the id given to `adb` and `simctl`, used for the port, and written to the JSON and JUnit reports, whose encoders escape it.

## Tests (through the real run)

- `TestParallelRunPrintsHostileDeviceLabelsCleaned` runs a one-lane parallel run with the orchestrator harness. The lane's name and id hold a new line with a fake "pass --yes to continue" line, an escape sequence, an OSC title sequence, a bidi override and a zero-width space. No printed line forges its own line or carries one of those characters; the color codes probe adds itself are allowed. The name's visible text is shown.
- `TestFailedLaneErrorNamesTheDeviceCleaned` runs a lane whose connect fails, because no fake agent is on its port. Its error and the run's summary name the hostile id on one clean line, and a lane with no name is listed by its cleaned id.
- `TestLaneLabelsAreDisplayOnly`: the lane keeps its raw id and name; `shortID` cuts by characters (Japanese text) and leaves a plain serial as before.

## Mutation check

Each mutant was applied, the tests were run, and the file was restored byte for byte. All 5 were killed. "label prints the raw id" survived at first, because the happy-path run never reaches an error message. The failed-lane test was added for it, and it is now killed.

| Mutant | Result |
|---|---|
| `shortID` prints the raw id | killed |
| `shortID` cuts bytes | killed |
| `deviceLabel` prints the raw name | killed |
| `label` prints the raw id | killed |
| the Connected line prints the raw id | killed |

## Test plan

- [x] `go test ./internal/runner/` passes.
- [x] `go vet ./internal/runner/` passes.
- [x] Mutation check (table above).
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).
jay23606 added a commit to jay23606/flutter-probe that referenced this pull request Nov 17, 2026
… the app id and serial as plain text (AlphaWaveSystems#779)

## Summary

This makes the lines a run prints about the app and the device show the app id and the serial as plain text on one line. It is part 3 of 3: AlphaWaveSystems#775 covered `probe device` and `internal/device`, and AlphaWaveSystems#776 the parallel run's lane labels.

**On main**, these printed `dc.AppID` and `dc.Serial` (or `deviceSerial`) as given:
- `internal/runner/device_context.go`: the single-device warning `[serial]`, force-stopping, relaunching (×5), the reinstall question, clearing data, the data-path error, the set-language error, iOS notification reinstall, granting permissions, killing, launching;
- `internal/runner/reconnect_hint.go`: the three "the app … is not running" hints;
- `internal/runner/runner.go`: the pull error;
- `internal/cli/test.go`: "Physical device detected";
- `internal/cli/record.go`: "Recording on".

A serial comes from `adb` or `simctl`. The app id is validated when it comes from `probe.yaml`, but these lines print whatever the device context holds. A value with a new line, an escape sequence, a bidi override or a zero-width character could forge a line or change the terminal.

## The change

- `DeviceContext.appShown()` and `serialShown()` return `device.CleanOneLine(value, 80)`. Each of the 15 print sites in `device_context.go` and the hint and pull sites use them. The two CLI sites call `device.CleanOneLine` directly.
- **Display only:** every value given to `adb`, `simctl` or `devicectl`, and every comparison, still uses `dc.AppID` and `dc.Serial` as they are.
- The reconnect hint is only reached for an app id that passes `ValidPackageName`, so a hostile id never got there. It is cleaned anyway, the same way.
- Script-authored names printed by the runner (test, recipe and measurement names, mostly `%q`) are not device output and are not part of this change.

## Tests (through the real print path)

`TestLifecycleLinesPrintAppAndSerialCleaned` runs kill, launch, restart and clear data on a `DeviceContext` with the recording fake `adb` (`recordingDevice`). Its app id holds a new line with a fake "pass --yes to continue" line, an escape sequence, a bidi override and a zero-width space, and its serial an OSC title sequence. For each step:
- no printed line forges its own line or carries one of those characters (probe's own color codes are allowed);
- every `adb -s` call gets the **real** serial.

## Mutation check

Each mutant was applied, the test was run, and the file was restored byte for byte. All 5 were killed.

| Mutant | Result |
|---|---|
| `appShown` returns the raw app id | killed |
| `serialShown` returns the raw serial | killed |
| the kill line prints the raw app id | killed |
| the clear line prints the raw serial | killed |
| adb gets the cleaned serial (display-only rule broken) | killed |

## Not covered

- The two CLI lines ("Physical device detected", "Recording on") are cleaned with the same call but have no test of their own: they sit deep in the `probe test` and `probe record` flows.

## Test plan

- [x] `go test ./internal/runner/ ./internal/cli/` passes.
- [x] `go vet ./internal/runner/ ./internal/cli/` passes.
- [x] Mutation check (table above).


## Review follow-up

- **Windows build:** `printed_device_names_test.go` uses `recordingDevice`, which is defined only for `!windows`, so it now has the same build tag. `GOOS=windows go vet ./internal/...` passes.
- **More prints cleaned in `probe test`:**
  - "Connected to ProbeAgent on <serial>" (an auto-picked id comes from the device list and is not validated);
  - the `-v` "ensuring adb + device <serial> reachable" line;
  - the cloud run's "Connected to ProbeAgent on <device>";
  - both "App uploaded: <id>" lines (the id is the provider's API response).
- **Data-path errors** quote the path `simctl` returned with `%q`.
- **Tests for the other sites**, through their real paths with hostile values:
  - the three data-path errors;
  - set language on a physical iPhone;
  - grant all permissions (the grants still get the real id);
  - the reconnect hint, which is skipped for an app id that is not a package name, so its cleaning is a second line behind that gate.

  A failed pull is not printed, so its cleaning can't be observed; the CHANGELOG now says which sites are tested and which are a second line. A source check covers the `probe test` prints.
- **Mutants:** 10 of 10 killed.
  - raw data path (×3), raw serial in the data-path error;
  - raw app id in set language and in grant;
  - the hint's package-name gate removed;
  - raw connected, trace and upload prints.

## Second follow-up

- **Cloud prints:** the cloud upload and session start, which were the same code in two paths, are now one function, `uploadAndStartCloudSession`. Its "Starting cloud session on <device>" line and the relay "Connected to ProbeAgent via relay on <device>" line print the device cleaned, like the other cloud lines.
- **The provider gets the real values:** `TestCloudSessionGetsTheRealValuesAndPrintsThemCleaned` checks, with a fake provider, that `UploadApp` gets the app path and `StartSession` gets the id `UploadApp` returned and the target device as they are, while both printed lines are clean.
- **Mutants:** 5 of 5 killed: the provider gets a cleaned device, the provider gets a cleaned app id, and the starting, upload and relay lines printed raw.
- **CHANGELOG:** says the data-path errors quote the path with `%q`, and names the cloud lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant