From f446439e33949e013e2a76fdd8a52591250b5633 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 23 Apr 2026 17:33:19 +0700 Subject: [PATCH] feat(driver): add env param to Launch interface and all implementations --- internal/driver/chrome/driver.go | 2 +- internal/driver/driver.go | 2 +- internal/driver/mock/mock.go | 2 +- internal/driver/mock/mock_test.go | 2 +- internal/driver/sidecar/client.go | 3 ++- internal/driver/sidecar/client_test.go | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/driver/chrome/driver.go b/internal/driver/chrome/driver.go index d96a8e8..d119bcd 100644 --- a/internal/driver/chrome/driver.go +++ b/internal/driver/chrome/driver.go @@ -77,7 +77,7 @@ func New() *Driver { return d } -func (d *Driver) Launch(ctx context.Context, bundleID string, clearState bool) error { +func (d *Driver) Launch(ctx context.Context, bundleID string, clearState bool, _ map[string]string) error { if clearState { if err := chromedp.Run(d.tabCtx, network.ClearBrowserCookies()); err != nil { return fmt.Errorf("clear cookies: %w", err) diff --git a/internal/driver/driver.go b/internal/driver/driver.go index d67603a..974ca09 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -10,7 +10,7 @@ import ( // lives under driver/sidecar; the web implementation under driver/chrome; // tests use driver/mock. type DeviceDriver interface { - Launch(ctx context.Context, bundleID string, clearState bool) error + Launch(ctx context.Context, bundleID string, clearState bool, env map[string]string) error Terminate(ctx context.Context) error Tap(ctx context.Context, x, y int) error diff --git a/internal/driver/mock/mock.go b/internal/driver/mock/mock.go index c2c45a8..07adadc 100644 --- a/internal/driver/mock/mock.go +++ b/internal/driver/mock/mock.go @@ -88,7 +88,7 @@ func (d *Driver) failure(kind ActionKind) error { return d.Failures[kind] } -func (d *Driver) Launch(_ context.Context, bundleID string, clearState bool) error { +func (d *Driver) Launch(_ context.Context, bundleID string, clearState bool, _ map[string]string) error { if err := d.failure(ActionLaunch); err != nil { return err } diff --git a/internal/driver/mock/mock_test.go b/internal/driver/mock/mock_test.go index d16c791..d56da5c 100644 --- a/internal/driver/mock/mock_test.go +++ b/internal/driver/mock/mock_test.go @@ -29,7 +29,7 @@ func TestRecordsAllActionsInOrder(t *testing.T) { mock := New() ctx := context.Background() - if err := mock.Launch(ctx, "com.example", true); err != nil { + if err := mock.Launch(ctx, "com.example", true, nil); err != nil { t.Fatal(err) } if err := mock.Tap(ctx, 100, 200); err != nil { diff --git a/internal/driver/sidecar/client.go b/internal/driver/sidecar/client.go index a002161..5dc2a47 100644 --- a/internal/driver/sidecar/client.go +++ b/internal/driver/sidecar/client.go @@ -48,10 +48,11 @@ func (c *Client) WaitForHealth(ctx context.Context, pollInterval time.Duration) } } -func (c *Client) Launch(ctx context.Context, bundleID string, clearState bool) error { +func (c *Client) Launch(ctx context.Context, bundleID string, clearState bool, env map[string]string) error { _, err := c.stub.Launch(ctx, &driverpb.LaunchRequest{ BundleId: bundleID, ClearState: clearState, + Env: env, }) return err } diff --git a/internal/driver/sidecar/client_test.go b/internal/driver/sidecar/client_test.go index 4ec69a9..00799b7 100644 --- a/internal/driver/sidecar/client_test.go +++ b/internal/driver/sidecar/client_test.go @@ -191,7 +191,7 @@ func TestClient_LaunchAndTerminate(t *testing.T) { client, _ := Dial(state.address) defer client.Close() - if err := client.Launch(context.Background(), "com.example", true); err != nil { + if err := client.Launch(context.Background(), "com.example", true, nil); err != nil { t.Fatal(err) } if state.fake.launchedBundleID != "com.example" || !state.fake.clearState {