From d62fc4bfa9a489a0640126d911cd1de26bccfe48 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Fri, 13 Nov 2026 17:10:02 +0000 Subject: [PATCH] perf: Speed up Builder E2E setup and project opens --- .github/actions/builder-e2e-build/action.yml | 27 ++++++++++++++++++++ apps/builder/backend/lib.node.test.ts | 20 ++++++++++++++- apps/builder/backend/lib.sh | 9 ++++++- apps/builder/e2e/README.md | 3 +++ apps/builder/e2e/flows/builder.ts | 14 ---------- apps/builder/e2e/run.sh | 4 ++- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/.github/actions/builder-e2e-build/action.yml b/.github/actions/builder-e2e-build/action.yml index 08868bcb78..ad47b3ea3a 100644 --- a/.github/actions/builder-e2e-build/action.yml +++ b/.github/actions/builder-e2e-build/action.yml @@ -38,10 +38,37 @@ runs: shell: bash run: pnpm --filter @webstudio-is/sdk-components-react-router build + - name: Identify schema snapshot + id: schema + shell: bash + run: | + ROOT_DIR="$PWD" + source apps/builder/backend/lib.sh + echo "fingerprint=$(builder_backend_schema_fingerprint)" >> "$GITHUB_OUTPUT" + + - name: Restore schema snapshot + id: schema-cache + uses: actions/cache/restore@v5 + with: + path: .cache/builder-e2e/schema-${{ steps.schema.outputs.fingerprint }}.sql + key: builder-e2e-schema-v1-${{ runner.os }}-${{ steps.schema.outputs.fingerprint }} + - name: Generate schema snapshot + if: steps.schema-cache.outputs.cache-hit != 'true' shell: bash run: pnpm --filter @webstudio-is/builder e2e:schema-cache + - name: Check schema snapshot + shell: bash + run: test -s ".cache/builder-e2e/schema-${{ steps.schema.outputs.fingerprint }}.sql" + + - name: Save schema snapshot + if: steps.schema-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + path: .cache/builder-e2e/schema-${{ steps.schema.outputs.fingerprint }}.sql + key: builder-e2e-schema-v1-${{ runner.os }}-${{ steps.schema.outputs.fingerprint }} + - name: Upload prerequisites uses: actions/upload-artifact@v6 with: diff --git a/apps/builder/backend/lib.node.test.ts b/apps/builder/backend/lib.node.test.ts index a6a79736ee..990f4ca9cb 100644 --- a/apps/builder/backend/lib.node.test.ts +++ b/apps/builder/backend/lib.node.test.ts @@ -1,7 +1,7 @@ import { execFile } from "node:child_process"; import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; -import { join } from "node:path"; +import { dirname, join } from "node:path"; import { promisify } from "node:util"; import { afterEach, expect, test } from "vitest"; @@ -67,6 +67,24 @@ test("schema fingerprint includes new backend files", async () => { expect(await readSchemaFingerprint(root)).not.toBe(before); }); +test.each([ + "packages/prisma-client/prisma/migrations/initial/schema.prisma", + "packages/prisma-client/prisma/schema.prisma", + "packages/prisma-client/migrations-cli/commands.ts", + "packages/prisma-client/src/prisma.ts", + "packages/prisma-client/package.json", + "pnpm-lock.yaml", +])("schema fingerprint includes %s", async (file) => { + const root = await createRepositoryFixture(); + const path = join(root, file); + await mkdir(dirname(path), { recursive: true }); + await writeFile(path, "before"); + const before = await readSchemaFingerprint(root); + await writeFile(path, "after"); + + expect(await readSchemaFingerprint(root)).not.toBe(before); +}); + test("backend modes select safe Compose projects", async () => { const root = await createRepositoryFixture(); const readProjectName = async (mode: "development" | "test") => { diff --git a/apps/builder/backend/lib.sh b/apps/builder/backend/lib.sh index d114540670..f29d71ea8b 100644 --- a/apps/builder/backend/lib.sh +++ b/apps/builder/backend/lib.sh @@ -36,8 +36,15 @@ builder_backend_schema_fingerprint() { find packages/prisma-client/prisma/migrations \ -mindepth 1 -maxdepth 1 -type d -print find packages/prisma-client/prisma/migrations \ - -type f \( -name migration.sql -o -name migration.ts \) -print + -type f \( -name migration.sql -o -name migration.ts -o -name schema.prisma -o -name migration_lock.toml -o -name template.txt \) -print + find packages/prisma-client/migrations-cli \ + -type f -name '*.ts' ! -name '*.test.ts' -print find apps/builder/backend -type f ! -name '*.test.*' -print + printf '%s\n' \ + packages/prisma-client/prisma/schema.prisma \ + packages/prisma-client/src/prisma.ts \ + packages/prisma-client/package.json \ + pnpm-lock.yaml } | LC_ALL=C sort | while IFS= read -r file; do if [ -f "$file" ]; then printf '%s ' "$file" diff --git a/apps/builder/e2e/README.md b/apps/builder/e2e/README.md index ec05a3ff22..79c158e71c 100644 --- a/apps/builder/e2e/README.md +++ b/apps/builder/e2e/README.md @@ -12,6 +12,9 @@ Use the full command for CI-like validation: pnpm e2e:builder ``` +The local command builds Builder and the generated React Router components +used by Preview tests. + The first run after migrations change applies the regular migration pipeline and writes an ignored schema cache under `.cache/builder-e2e`. Refresh it explicitly with: diff --git a/apps/builder/e2e/flows/builder.ts b/apps/builder/e2e/flows/builder.ts index cc8731baaa..3ea61b0960 100644 --- a/apps/builder/e2e/flows/builder.ts +++ b/apps/builder/e2e/flows/builder.ts @@ -110,18 +110,6 @@ export const waitForCanvasTextHidden = async ({ }); }; -export const dismissBlockingAlerts = async ({ page }: { page: Page }) => { - const startedAt = Date.now(); - while (Date.now() - startedAt < 3_000) { - const dismissButton = page.getByRole("button", { name: "Dismiss" }); - if (await dismissButton.isVisible({ timeout: 500 }).catch(() => false)) { - await dismissButton.click(); - return; - } - await delay(100); - } -}; - export const openProjectBuilder = async ({ page, projectId, @@ -148,7 +136,6 @@ export const openProjectBuilder = async ({ .waitForLoadState("networkidle", { timeout: builderNetworkIdleTimeout }) .catch(() => undefined); const canvas = await waitForCanvasFrame({ page }); - await dismissBlockingAlerts({ page }); return canvas; }; @@ -164,6 +151,5 @@ export const openBuilderUrl = async ({ .waitForLoadState("networkidle", { timeout: builderNetworkIdleTimeout }) .catch(() => undefined); const canvas = await waitForCanvasFrame({ page }); - await dismissBlockingAlerts({ page }); return canvas; }; diff --git a/apps/builder/e2e/run.sh b/apps/builder/e2e/run.sh index 8fe417182e..99bdfb8d27 100644 --- a/apps/builder/e2e/run.sh +++ b/apps/builder/e2e/run.sh @@ -137,13 +137,15 @@ install_playwright_chromium() { build_e2e_apps() { pnpm --dir "$ROOT_DIR" e2e:builder:build + pnpm --dir "$ROOT_DIR" --filter=@webstudio-is/sdk-components-react-router build } verify_e2e_apps_built() { local builder_server="$ROOT_DIR/apps/builder/build/server" local builder_assets="$ROOT_DIR/apps/builder/build/client/assets" + local router_components="$ROOT_DIR/packages/sdk-components-react-router/lib/components.js" - if [ ! -d "$builder_server" ] || [ ! -d "$builder_assets" ]; then + if [ ! -d "$builder_server" ] || [ ! -d "$builder_assets" ] || [ ! -f "$router_components" ]; then echo "E2E_SKIP_BUILDER_BUILD requires prebuilt Builder artifacts" >&2 return 1 fi