Skip to content

Commit ba17894

Browse files
authored
Stabilize browser e2e setup (#233)
## Summary - reinstall Playwright dependencies when `node_modules` exists but `tsx` is missing - stop Chromium before transfer benchmarks archive `/home/kernel/user-data`, avoiding live profile writes during zip/zstd creation ## Test plan - `PATH="/usr/local/go/bin:$PATH" go test -v -race ./e2e/ -run 'TestZipTransferTiming|TestZstdTransferTiming|TestZipVsZstdComparison' -count=1` - `PATH="/usr/local/go/bin:$PATH" go test -v -race $(go list ./... | rg -v '/e2e$')` Made with [Cursor](https://cursor.com) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: changes are limited to e2e/benchmark test setup, mainly improving dependency installation checks and reducing flakiness from live Chromium profile writes. > > **Overview** > Improves e2e Chromium test reliability by re-running `pnpm install` when Playwright’s `node_modules` exists but the `tsx` CLI is missing, with clearer install logging and early error return. > > Stabilizes the zip/zstd transfer benchmark tests by explicitly stopping `chromium` via `supervisorctl` (and briefly sleeping) before reading/archiving `/home/kernel/user-data`, avoiding races with in-flight profile writes during compression. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fa5ed61. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent c058cb0 commit ba17894

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

server/e2e/e2e_chromium_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,27 @@ func ensurePlaywrightDeps(t *testing.T) {
7272

7373
playwrightDepsOnce.Do(func() {
7474
nodeModulesPath := getPlaywrightPath() + "/node_modules"
75+
tsxPath := getPlaywrightPath() + "/node_modules/tsx/dist/cli.mjs"
7576
if _, err := os.Stat(nodeModulesPath); os.IsNotExist(err) {
77+
t.Log("Installing playwright dependencies...")
7678
cmd := exec.Command("pnpm", "install")
7779
cmd.Dir = getPlaywrightPath()
7880
output, err := cmd.CombinedOutput()
7981
if err != nil {
8082
playwrightDepsErr = fmt.Errorf("failed to install playwright dependencies: %w\noutput: %s", err, string(output))
83+
return
8184
}
85+
t.Log("Playwright dependencies installed successfully")
86+
} else if _, err := os.Stat(tsxPath); os.IsNotExist(err) {
87+
t.Log("Installing playwright dependencies...")
88+
cmd := exec.Command("pnpm", "install")
89+
cmd.Dir = getPlaywrightPath()
90+
output, err := cmd.CombinedOutput()
91+
if err != nil {
92+
playwrightDepsErr = fmt.Errorf("failed to install playwright dependencies: %w\noutput: %s", err, string(output))
93+
return
94+
}
95+
t.Log("Playwright dependencies installed successfully")
8296
}
8397
})
8498

server/e2e/e2e_zip_transfer_bench_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestZipTransferTiming(t *testing.T) {
5454
err = populateUserData(ctx, client)
5555
require.NoError(t, err, "failed to populate user-data")
5656
t.Logf("User-data population took %dms", time.Since(populateStart).Milliseconds())
57+
stopChromiumForStableUserData(t, ctx, client)
5758

5859
// Get initial directory size for reference
5960
dirSize, fileCount, err := getDirStats(ctx, client, "/home/kernel/user-data")
@@ -139,6 +140,25 @@ func populateUserData(ctx context.Context, client *instanceoapi.ClientWithRespon
139140
return nil
140141
}
141142

143+
func stopChromiumForStableUserData(t *testing.T, ctx context.Context, client *instanceoapi.ClientWithResponses) {
144+
t.Helper()
145+
146+
args := []string{"-c", "/etc/supervisor/supervisord.conf", "stop", "chromium"}
147+
req := instanceoapi.ProcessExecJSONRequestBody{
148+
Command: "supervisorctl",
149+
Args: &args,
150+
}
151+
rsp, err := client.ProcessExecWithResponse(ctx, req)
152+
require.NoError(t, err, "failed to stop chromium before reading user-data")
153+
require.Equal(t, http.StatusOK, rsp.StatusCode(), "unexpected status stopping chromium: %s body=%s", rsp.Status(), string(rsp.Body))
154+
if rsp.JSON200 != nil && rsp.JSON200.ExitCode != nil {
155+
require.Equal(t, 0, *rsp.JSON200.ExitCode, "supervisorctl stop chromium failed")
156+
}
157+
158+
// Give Chromium's profile databases a brief moment to settle after shutdown.
159+
time.Sleep(500 * time.Millisecond)
160+
}
161+
142162
// getDirStats returns approximate size and file count of a directory
143163
func getDirStats(ctx context.Context, client *instanceoapi.ClientWithResponses, path string) (int64, int, error) {
144164
// Use du command via process exec to get accurate size
@@ -286,6 +306,7 @@ func TestZstdTransferTiming(t *testing.T) {
286306
err = populateUserData(ctx, client)
287307
require.NoError(t, err, "failed to populate user-data")
288308
t.Logf("User-data population took %dms", time.Since(populateStart).Milliseconds())
309+
stopChromiumForStableUserData(t, ctx, client)
289310

290311
// Get directory stats for reference
291312
dirSize, fileCount, err := getDirStats(ctx, client, "/home/kernel/user-data")
@@ -436,6 +457,7 @@ func TestZipVsZstdComparison(t *testing.T) {
436457
t.Logf("Populating user-data by browsing...")
437458
err = populateUserData(ctx, client)
438459
require.NoError(t, err, "failed to populate user-data")
460+
stopChromiumForStableUserData(t, ctx, client)
439461

440462
// Get directory stats
441463
dirSize, fileCount, err := getDirStats(ctx, client, "/home/kernel/user-data")

0 commit comments

Comments
 (0)