refactor(ioscompanion): inline single-use devicectl argv builders

This commit is contained in:
pj committed 2026-06-09 18:21:06 +05:30
1 parent 82dc7566a1
commit 27e2cbf956
2 files changed
+2 -25

No files matched your search

+2 -12
View File
@@ -199,24 +199,14 @@ func (d *Driver) respawnDevice(ctx context.Context) error {
// keyed on the CoreDevice id. App lifecycle stays with devicectl: the runner's // keyed on the CoreDevice id. App lifecycle stays with devicectl: the runner's
// own install path is simulator-specific. // own install path is simulator-specific.
func (d *Driver) devicectlReinstall(ctx context.Context) error { func (d *Driver) devicectlReinstall(ctx context.Context) error {
_ = exec.CommandContext(ctx, "xcrun", devicectlUninstallArgs(d.coreDeviceID, d.bundleID)...).Run() _ = exec.CommandContext(ctx, "xcrun", "devicectl", "device", "uninstall", "app", "--device", d.coreDeviceID, d.bundleID).Run()
output, err := exec.CommandContext(ctx, "xcrun", devicectlInstallArgs(d.coreDeviceID, d.appPath)...).CombinedOutput() output, err := exec.CommandContext(ctx, "xcrun", "devicectl", "device", "install", "app", "--device", d.coreDeviceID, d.appPath).CombinedOutput()
if err != nil { if err != nil {
return fmt.Errorf("devicectl install: %w: %s", err, strings.TrimSpace(string(output))) return fmt.Errorf("devicectl install: %w: %s", err, strings.TrimSpace(string(output)))
} }
return nil return nil
} }
// devicectlUninstallArgs and devicectlInstallArgs build the devicectl app
// lifecycle commands keyed on the CoreDevice id, as xcrun subcommand arguments.
func devicectlUninstallArgs(coreDeviceID, bundleID string) []string {
return []string{"devicectl", "device", "uninstall", "app", "--device", coreDeviceID, bundleID}
}
func devicectlInstallArgs(coreDeviceID, appPath string) []string {
return []string{"devicectl", "device", "install", "app", "--device", coreDeviceID, appPath}
}
// deviceResetContainerUnsupported warns once that device clear-state needs an // deviceResetContainerUnsupported warns once that device clear-state needs an
// app path for a devicectl reinstall: there is no simulator-style data-container // app path for a devicectl reinstall: there is no simulator-style data-container
// wipe on a physical device. // wipe on a physical device.
@@ -196,19 +196,6 @@ func TestDeviceCloseStopsRunnerAndTunnel(t *testing.T) {
} }
} }
func TestDevicectlReinstallArgs(t *testing.T) {
uninstall := devicectlUninstallArgs("CORE-1", "com.example.app")
wantUninstall := []string{"devicectl", "device", "uninstall", "app", "--device", "CORE-1", "com.example.app"}
if !equalArgs(uninstall, wantUninstall) {
t.Fatalf("uninstall args = %v, want %v", uninstall, wantUninstall)
}
install := devicectlInstallArgs("CORE-1", "/tmp/app.app")
wantInstall := []string{"devicectl", "device", "install", "app", "--device", "CORE-1", "/tmp/app.app"}
if !equalArgs(install, wantInstall) {
t.Fatalf("install args = %v, want %v", install, wantInstall)
}
}
func equalArgs(got, want []string) bool { func equalArgs(got, want []string) bool {
if len(got) != len(want) { if len(got) != len(want) {
return false return false