refactor: Move the reusable code out of the CLI into a package - #4
Open
jocelyne-a wants to merge 1 commit into
Open
refactor: Move the reusable code out of the CLI into a package#4jocelyne-a wants to merge 1 commit into
jocelyne-a wants to merge 1 commit into
Conversation
3 tasks
jocelyne-a
force-pushed
the
importable-bridge-package
branch
2 times, most recently
from
August 18, 2026 15:58
3cbe0e4 to
b14dce9
Compare
jocelyne-a
marked this pull request as ready for review
August 18, 2026 17:02
Everything lived in package main, which Go will not let other programs import, so the only way to use it was to run the command; this moves the reusable parts into a bridge package and lets whoever calls it decide where to listen, so a test can serve on an ordinary TCP port instead of taking over /var/run/usbmuxd as root. The command itself behaves exactly as it did before. Two things are renamed while they are still unexported and renaming is free rather than breaking: runTCPServer becomes ServeRaw and AdbConnectionBridge becomes RawConnectionBridge, because neither contains any adb-specific logic — they copy bytes without interpreting them, which is what both adbUrl on Android and usbmuxdUrl on iOS need. The per-connection log lines lose their adb prefix for the same reason, since they otherwise report an adb client while serving usbmux. The CLI keeps its own adb naming, which is accurate: runAndroid really does serve adb.
rillgen-saucelabs
force-pushed
the
importable-bridge-package
branch
from
August 26, 2026 09:43
b14dce9 to
e692da5
Compare
rillgen-saucelabs
approved these changes
Aug 26, 2026
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.
Move the reusable code out of the CLI into an importable package
Description
Everything in this repo lives in
package main, which Go will not let another program import. The RDC device-controller integration tests need the session and tunnel logic that already works here, and the only way to reach it today is to run the CLI.This moves the reusable parts into a
bridgepackage and turns the one hardcoded decision — where to listen locally — into a parameter. The CLI still binds/var/run/usbmuxdand127.0.0.1:7001exactly as before; a caller can pass an ordinary TCP listener instead, which also means it needs no root.Nothing is rewritten, only relocated. The files moved with
git mvso history follows them, and the edits are the package declaration, exporting what now crosses a package boundary, and the listener change.Two renames, done now because these identifiers are unexported in
package maintoday, so renaming is free rather than breaking:runTCPServer→ServeRaw, andAdbConnectionBridge→RawConnectionBridge. Neither contains adb-specific logic — they copy bytes without interpreting them, which is exactly whatadbUrlon Android andusbmuxdUrlon iOS both need. The per-connection log lines lose theiradbprefix for the same reason: they otherwise report an "adb client" while serving usbmux.main.gokeeps its own adb naming, which is accurate —runAndroidreally does serve adb.Types of Changes
Tasks
bridge/withgit mvServeRaw/ServeUsbmuxtaking anet.Listeneradbwhile it is still unexportedmain.goas the CLI onlymainReview
bridge/serve_test.go: usbmux over a TCP listener, byte relaying in both directions, and clean shutdown on context cancel.gofmt -s,go vet ./...andgo test -race -count=2 ./...all clean.The claim worth checking hardest is that the CLI didn't move: binaries built from
mainand from this branch produce byte-identical output across-h, no arguments,-version, an unknown region and an undefined flag.Deployment Notes
None. GoReleaser still builds
main: ., the Makefile and CI stillgo build ., and./...picks the new package up automatically. Coverage is now reported per package because the code moved out of the root, but CI uploads it as an artifact without a threshold.