refactor: extract reusable ios/uidriver from the CLI - #820
Open
danielpaulus wants to merge 1 commit into
Open
Conversation
Extract the private WDA/DeviceKit UI-automation HTTP client that lived in cmd_ui.go into a new, exported ios/uidriver package so the CLI and the upcoming REST ui endpoints can share one driver. uidriver.Driver is constructed against a backend base URL (the forwarded WDA :8100 / DeviceKit :12004 address) and exposes Tap/Swipe/LongPress/ Type/PressButton/Screenshot/Source/WindowSize/Orientation/SetOrientation/ AppLaunch/AppTerminate/AppForeground/Status/API/Stream. Methods return values and errors instead of calling os.Exit, so the package is safe to embed. Request/response types are exported and JSON-tagged. cmd_ui.go keeps arg parsing, backend resolution (wda/devicekit/auto) and output formatting, delegating all HTTP work to the driver. CLI behavior is unchanged. Adds ios/uidriver unit tests driving the client against an httptest backend (methods/paths/bodies for every action plus the chunked streaming helper). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk
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.
What
Extracts the private WDA/DeviceKit UI-automation HTTP client that lived inside
cmd_ui.go(theuiClienttype and itswdaHTTP/deviceKitRPC/pipeHTTPmachinery) into a new, exportedios/uidriverpackage.uidriver.New(backend, baseURL, opts...)constructs aDriverbound to a backend (BackendWDA/BackendDeviceKit) at a base URL — typically the local end of a forwarded connection to WDA (:8100) or DeviceKit (:12004). Not tied to the CLI.Tap,Swipe,LongPress,Type,PressButton,Screenshot,Source,WindowSize,Orientation/SetOrientation,AppLaunch/AppTerminate/AppForeground,Status,API(raw WDA-HTTP / DeviceKit-RPC passthrough), andStream(returns the backend mjpeg/h264 body as anio.ReadCloserfor callers to pipe).os.Exit, so the package is embeddable. Request/response types (Response,APIRequest,StreamOptions,HTTPError, sentinel errors) are exported and JSON-tagged.WithHTTPClient,WithTimeout,WithSessionID,WithUDID. Logging viagologwithconst logModule = "go-ios/uidriver".cmd_ui.gonow keeps only CLI arg parsing, backend resolution (wda/devicekit/auto, with health probing for auto) and output formatting, delegating all HTTP work to the driver. CLI behavior is unchanged — everyios ui ...subcommand hits the same endpoints/methods/bodies as before, and non-2xx responses still exit 1 with the backend body surfaced.Why
This is the prerequisite for the REST
uiendpoints wave: the REST API (and other embedders) can now drive UI automation through the same driver instead of shelling out or duplicating the HTTP wiring.Tests
Adds
ios/uidriverunit tests that drive the client against an in-processhttptest.Serverstanding in for WDA/DeviceKit, asserting the correct HTTP method/path/body for tap/swipe/type/button/orientation/app/status/screenshot/source/api, base64 screenshot decoding,*HTTPErroron non-2xx, health probing, and the streaming helper against a chunked server.go build ./... && go vet ./... && go test ./...all pass;gofmtclean on changed files.Note for the REST ui-endpoints wave
Construct the driver against a forwarded WDA/DeviceKit address, e.g.
d, err := uidriver.New(uidriver.BackendWDA, "http://127.0.0.1:<forwardedPort>", uidriver.WithUDID(udid)),then call the action methods.
Stream(ctx, opts)returns anio.ReadCloseryou own and mustClose.restapi/was intentionally left untouched here.🤖 Generated with Claude Code
https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk