mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
* feat(ios): add simulator management package * feat(testrun): add iOS platform path (simctl launch + direct TCP) * feat(cli): add --ios-device flag and IosDevice option * feat(sdk-ios): add Kotlin Native iOS SDK (TCP agent + POSIX socket + dispatch pauser) * feat(folio-ios): wire SanderlingIos.start() in MainViewController * feat(folio-ios): add test-ios justfile recipe * fix(sdk-ios): remove unavailable C macros; manual byte swap + no-cast warnings * fix(testrun): simctl-first launch order for iOS; Maestro init after SDK connects * feat(proto): add env map to LaunchRequest * feat(driver): add env param to Launch interface + all implementations * feat(testrun): launch iOS app via XCTest with env vars instead of simctl * feat(sidecar): add IosDriverBackend using Maestro IOSDriver + env pass-through * feat(sidecar): wire env map in DriverService + IosDriverBackend in Main * fix(sidecar): use LocalIOSDevice (WDA+simctl) + stop before relaunch * fix(sidecar): include exception type in gRPC error description * fix(sidecar): pick free WDA port instead of hardcoded 9100 Use SocketUtils.nextFreePort to pick a free port in the 22000-23000 range rather than hardcoding 9100, which only worked if a previous WDA session left a listener there. * fix(sdk-ios): check semaphore wait result and throw on snapshot timeout dispatch_semaphore_wait returns nonzero on timeout; ignoring the return value caused pauseAndSnapshot to silently return an empty map, sending a garbage empty STATE frame to the host. Now throws so the agent loop reconnects instead. * fix(folio-ios): register snapshot extractors before starting agent SanderlingIos.start() was called before the snapshot objects were initialized, so a PAUSE message arriving early produced an empty snapshot. Move start() to after all extractors are registered. * chore(ios): remove dead LaunchApp function LaunchApp had no callers sincebff3a49switched iOS launch to go through the sidecar driver. Remove the dead code and unused os import. * test(ios): add unit tests for pickSimulator and iOS flag parsing Tests for all pickSimulator branches (by name, by UDID, unknown, empty list, iPhone preference, fallback to first). Also tests BootedUDID on a canceled context and verifies --platform ios and --ios-device flags are accepted by parseTestArgs. * fix(ios): propagate error from BootedUDID instead of silently swallowing * fix(sidecar): IosDriverBackend.healthy() returns true; WDA liveness checked in open() * fix(sidecar): warm up WDA after health check to absorb startup race * fix(runner): surface clear message on WDA connection drop * docs(testrun): note WDA warmup location above WaitForHealth * fix(sidecar): extract warmup + add one-shot WDA reconnect on IOException * fix(runner): fatal on permanent WDA drop during hierarchy fetch * fix(sidecar): walk cause chain in withReconnect to catch Maestro-wrapped IOException * fix(sidecar): explicit Unit return in pressKey and waitForIdle withReconnect lambdas * fix(sidecar): serialize WDA reconnect with ReentrantLock to prevent concurrent xcodebuild races * fix web examples package config * Revert "fix web examples package config" This reverts commit70c10ade27. * chore: gitignore built sanderling binary * fix(hierarchy): parse iOS [x1,y1][x2,y2] bounds + match iOS merged desc labels * refactor(folio-spec): replace bloated spec with two focused properties Login is opportunistic. Two concrete properties: 1. every new account starts with balance 0 2. every new txn changes ledger balance by exactly its signed amount Actions: directed login -> addAccount -> addTxn -> back weighted flow.
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package testrun
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"strconv"
|
|
|
|
"github.com/priyanshujain/sanderling/internal/android"
|
|
"github.com/priyanshujain/sanderling/internal/driver"
|
|
"github.com/priyanshujain/sanderling/internal/driver/chrome"
|
|
driverSidecar "github.com/priyanshujain/sanderling/internal/driver/sidecar"
|
|
"github.com/priyanshujain/sanderling/internal/ios"
|
|
"github.com/priyanshujain/sanderling/internal/sidecar"
|
|
)
|
|
|
|
// buildDriver creates the appropriate DeviceDriver for the platform and returns
|
|
// a cleanup function. For web, ChromeDriver is used directly; for android/ios
|
|
// the JVM sidecar is extracted, spawned, and dialed.
|
|
func buildDriver(ctx context.Context, options Options, stdout io.Writer) (driver.DeviceDriver, func(), error) {
|
|
if options.Platform == "web" {
|
|
d := chrome.New()
|
|
return d, func() { _ = d.Terminate(context.Background()) }, nil
|
|
}
|
|
|
|
sidecarDirectory := os.TempDir() + "/sanderling-sidecar"
|
|
jarPath, err := sidecar.Extract(sidecarDirectory)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("extract sidecar: %w", err)
|
|
}
|
|
fmt.Fprintf(stdout, "sidecar JAR: %s (size=%d)\n", jarPath, sidecar.EmbeddedSize())
|
|
|
|
sidecarPort, err := pickFreePort()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
sidecarArgs := []string{"-jar", jarPath,
|
|
"--port", strconv.Itoa(sidecarPort),
|
|
"--platform", options.Platform,
|
|
}
|
|
if options.Platform == "ios" {
|
|
if udid := ios.BootedUDID(ctx); udid != "" {
|
|
sidecarArgs = append(sidecarArgs, "--udid", udid)
|
|
}
|
|
}
|
|
sidecarCommand := exec.CommandContext(ctx, "java", sidecarArgs...)
|
|
sidecarCommand.Stdout = stdout
|
|
sidecarCommand.Stderr = stdout
|
|
sidecarCommand.Env = android.EnvWithAndroidPlatformTools(os.Environ())
|
|
if err := sidecarCommand.Start(); err != nil {
|
|
return nil, nil, fmt.Errorf("spawn sidecar: %w", err)
|
|
}
|
|
fmt.Fprintf(stdout, "sidecar pid=%d listening on 127.0.0.1:%d\n", sidecarCommand.Process.Pid, sidecarPort)
|
|
|
|
driverClient, err := driverSidecar.Dial(fmt.Sprintf("127.0.0.1:%d", sidecarPort))
|
|
if err != nil {
|
|
_ = sidecarCommand.Process.Kill()
|
|
return nil, nil, fmt.Errorf("dial sidecar: %w", err)
|
|
}
|
|
// WaitForHealth confirms the gRPC sidecar is up. For iOS, the WDA warmup
|
|
// (absorbing the XCUITest startup race) runs inside IosDriverBackend.init
|
|
// in the sidecar - no additional sleep needed here.
|
|
healthCtx, healthCancel := context.WithTimeout(ctx, sidecarStartupTimeout)
|
|
if err := driverClient.WaitForHealth(healthCtx, 250e6); err != nil {
|
|
healthCancel()
|
|
_ = sidecarCommand.Process.Kill()
|
|
_ = driverClient.Close()
|
|
return nil, nil, fmt.Errorf("sidecar health check: %w", err)
|
|
}
|
|
healthCancel()
|
|
fmt.Fprintln(stdout, "sidecar is healthy")
|
|
|
|
cleanup := func() {
|
|
_ = driverClient.Close()
|
|
if sidecarCommand.Process != nil {
|
|
_ = sidecarCommand.Process.Kill()
|
|
}
|
|
}
|
|
return driverClient, cleanup, nil
|
|
}
|