Skip to content

refactor: extract reusable ios/uidriver from the CLI - #820

Open
danielpaulus wants to merge 1 commit into
mainfrom
refactor/uidriver-extract
Open

refactor: extract reusable ios/uidriver from the CLI#820
danielpaulus wants to merge 1 commit into
mainfrom
refactor/uidriver-extract

Conversation

@danielpaulus

Copy link
Copy Markdown
Owner

What

Extracts the private WDA/DeviceKit UI-automation HTTP client that lived inside cmd_ui.go (the uiClient type and its wdaHTTP/deviceKitRPC/pipeHTTP machinery) into a new, exported ios/uidriver package.

  • uidriver.New(backend, baseURL, opts...) constructs a Driver bound 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.
  • Exported action methods: Tap, Swipe, LongPress, Type, PressButton, Screenshot, Source, WindowSize, Orientation/SetOrientation, AppLaunch/AppTerminate/AppForeground, Status, API (raw WDA-HTTP / DeviceKit-RPC passthrough), and Stream (returns the backend mjpeg/h264 body as an io.ReadCloser for callers to pipe).
  • All methods return values + errors instead of os.Exit, so the package is embeddable. Request/response types (Response, APIRequest, StreamOptions, HTTPError, sentinel errors) are exported and JSON-tagged.
  • Options: WithHTTPClient, WithTimeout, WithSessionID, WithUDID. Logging via golog with const logModule = "go-ios/uidriver".

cmd_ui.go now 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 — every ios 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 ui endpoints 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/uidriver unit tests that drive the client against an in-process httptest.Server standing 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, *HTTPError on non-2xx, health probing, and the streaming helper against a chunked server. go build ./... && go vet ./... && go test ./... all pass; gofmt clean 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 an io.ReadCloser you own and must Close. restapi/ was intentionally left untouched here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk

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
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