perf: overlap Builder E2E preview work

This commit is contained in:
Oleg Isonen committed 2026-11-16 18:27:15 +00:00
1 parent cbee37d2e1
commit 775c8880e6
6 files changed
+270 -245

No files matched your search

@@ -0,0 +1,21 @@
import { mkdir, writeFile } from "node:fs/promises";
import { loadDevBuild } from "../db";
import { createLocalBundleFromDevBuild } from "../flows/generated-app";
import { authorManagedForm } from "./mcp-managed-form-author";
export const preparePreviewBundle = async (projectId: string) => {
const standard = await authorManagedForm(projectId, { mode: "email" });
const isolated = await authorManagedForm(projectId, {
mode: "email-isolation",
});
const combined = await authorManagedForm(projectId, {
mode: "email-http-combination",
});
const build = await loadDevBuild({ projectId });
await mkdir(".webstudio", { recursive: true });
await writeFile(
".webstudio/data.json",
`${JSON.stringify(createLocalBundleFromDevBuild(build))}\n`
);
return { standard, isolated, combined };
};
+11 -10
View File
@@ -185,19 +185,20 @@ export const expectGeneratedAppBuild = async (
}
};
export const withGeneratedPreview = async <Result>({
projectId,
callback,
evaluationReceiverPort,
}: {
projectId: string;
callback: ({ url, html }: { url: string; html: string }) => Promise<Result>;
evaluationReceiverPort?: string;
}) => {
export const withGeneratedPreview = async <Result>(
input: ({ projectId: string } | { build: BuildRow }) & {
callback: ({ url, html }: { url: string; html: string }) => Promise<Result>;
evaluationReceiverPort?: string;
}
) => {
const { callback, evaluationReceiverPort } = input;
const tempDir = await mkdtemp(join(tmpdir(), "webstudio-e2e-generated-"));
let preview: ChildProcess | undefined;
try {
const build = await loadDevBuild({ projectId });
const build =
"build" in input
? input.build
: await loadDevBuild({ projectId: input.projectId });
await mkdir(join(tempDir, ".webstudio"), { recursive: true });
await writeFile(
join(tempDir, ".webstudio", "data.json"),
@@ -108,6 +108,8 @@ export const withMcpEmailHttpPreview = async <Result>({
process: preview,
url,
output: () => output.join(""),
// Allow time for the author as well as the Preview build when combined.
timeout: prepareArgs.length === 0 ? undefined : 180_000,
});
if (prepareArgs.length === 0) {
return await measure("MCP email HTTP Preview callback", () =>
@@ -416,187 +416,203 @@ test("Builder variables render in generated Preview and persist after reload", a
await waitForSyncComplete({ page });
});
await test.step("Generated Preview renders variables and navigates linked routes", async () => {
await withGeneratedPreview({
projectId: fixture.projectId,
callback: async ({ url, html }) => {
expect(html).toContain(expectedText);
const target = new URL("/my-page", url).href;
const response = await fetch(target, { redirect: "manual" });
expect(response.ok).toBe(true);
expect(await response.text()).toContain(previewLinkText.pageLink);
// Preview uses the saved project before the Builder edits below.
const previewBuild = await loadDevBuild({ projectId: fixture.projectId });
const verifyPreview = () =>
test.step("Generated Preview renders variables and navigates linked routes", async () => {
await withGeneratedPreview({
build: previewBuild,
callback: async ({ url, html }) => {
expect(html).toContain(expectedText);
const target = new URL("/my-page", url).href;
const response = await fetch(target, { redirect: "manual" });
expect(response.ok).toBe(true);
expect(await response.text()).toContain(previewLinkText.pageLink);
const previewPage = await context.newPage();
try {
await previewPage.goto(url);
const link = previewPage.getByRole("link", {
name: previewLinkText.pageLink,
exact: true,
const previewPage = await context.newPage();
try {
await previewPage.goto(url);
const link = previewPage.getByRole("link", {
name: previewLinkText.pageLink,
exact: true,
});
await link.click();
await expect(previewPage).toHaveURL(target);
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("aria-current", "page");
} finally {
await previewPage.close();
}
},
});
});
const verifyPersistence = () =>
test.step("Builder edits persist after reload", async () => {
await measure(
"data variables runtime edit resources and variables",
async () => {
await editStringVariable({
page,
fixture,
name: staticName,
value: editedStaticValue,
});
await editHttpResourceVariableWithCurl({
page,
fixture,
name: httpName,
curl: `curl '${httpCurlUrl}?${httpSearchParamName}=${httpSearchParamValue}' --request POST --header '${httpHeaderName}: ${httpHeaderValue}' --header 'Content-Type: application/json' --data '{"${httpBodyValue}":true}'`,
});
await link.click();
await expect(previewPage).toHaveURL(target);
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("aria-current", "page");
} finally {
await previewPage.close();
}
},
});
});
);
await measure(
"data variables runtime edit resources and variables",
async () => {
await editStringVariable({
page,
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: undefined,
});
await expectVariableListItem({
page,
name: staticName,
value: editedStaticValue,
badge: "Static variable",
});
await editHttpResourceVariableWithCurl({
await expectVariableListItem({
page,
fixture,
name: httpName,
curl: `curl '${httpCurlUrl}?${httpSearchParamName}=${httpSearchParamValue}' --request POST --header '${httpHeaderName}: ${httpHeaderValue}' --header 'Content-Type: application/json' --data '{"${httpBodyValue}":true}'`,
badge: "Dynamic variable",
});
}
);
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: undefined,
});
await expectVariableListItem({
page,
name: staticName,
badge: "Static variable",
});
await expectVariableListItem({
page,
name: httpName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: graphqlName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: systemName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: currentDateName,
badge: "Dynamic variable",
});
await measure("data variables runtime reload builder", async () => {
await openProjectBuilder({
page,
projectId: fixture.projectId,
authToken: fixture.builderToken,
});
});
const editedText = expectedText.replace(staticValue, editedStaticValue);
await waitForCanvasText({ page, text: editedText });
await selectContentInstance({ page, text: editedText });
await expectVariableListItem({
page,
name: staticName,
badge: "Static variable",
});
await expectVariableListItem({
page,
name: httpName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: graphqlName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: systemName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: currentDateName,
badge: "Dynamic variable",
});
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: undefined,
});
await measure(
"data variables runtime delete graphql variable",
async () => {
await deleteVariable({
await expectVariableListItem({
page,
fixture,
name: graphqlName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: systemName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: currentDateName,
badge: "Dynamic variable",
});
await measure("data variables runtime reload builder", async () => {
await openProjectBuilder({
page,
projectId: fixture.projectId,
authToken: fixture.builderToken,
});
});
const editedText = expectedText.replace(staticValue, editedStaticValue);
await waitForCanvasText({ page, text: editedText });
await selectContentInstance({ page, text: editedText });
await expectVariableListItem({
page,
name: staticName,
badge: "Static variable",
});
await expectVariableListItem({
page,
name: httpName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: graphqlName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: systemName,
badge: "Dynamic variable",
});
await expectVariableListItem({
page,
name: currentDateName,
badge: "Dynamic variable",
});
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: undefined,
});
await measure(
"data variables runtime delete graphql variable",
async () => {
await deleteVariable({
page,
fixture,
name: graphqlName,
});
}
);
await page.getByText(graphqlName, { exact: true }).waitFor({
state: "hidden",
});
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: graphqlName,
});
});
const results = await Promise.allSettled([
verifyPreview(),
verifyPersistence(),
]);
for (const result of results) {
if (result.status === "rejected") {
throw result.reason;
}
);
await page.getByText(graphqlName, { exact: true }).waitFor({
state: "hidden",
});
await expectPersistedDataVariables({
fixture,
staticName,
staticValue: editedStaticValue,
httpName,
httpUrl,
httpCurlUrl,
httpSearchParamName,
httpSearchParamValue,
httpHeaderName,
httpHeaderValue,
httpBodyValue,
graphqlName,
graphqlUrl,
graphqlQuery,
systemName,
currentDateName,
deletedName: graphqlName,
});
}
} finally {
await Promise.all([http.close(), graphql.close()]);
}
@@ -1,5 +1,5 @@
import { expect } from "@playwright/test";
import { createContentModeProject } from "../fixtures/content-mode-suite";
import { createProjectThroughApi } from "../fixtures/create-project";
import { expectFormQueryDelivery } from "../flows/form-query";
import { startFormQueryReceiver } from "../flows/form-query-receiver";
import { runFormAuthor } from "../flows/mcp-form-author";
@@ -21,17 +21,12 @@ test("MCP form query delivery and Email binding changes across two production Pr
}) => {
test.setTimeout(twoPhaseTimeout);
await startPreviewFormMcpClient();
const fixture = await createContentModeProject({
const projectId = await createProjectThroughApi({
context,
email: "mcp-email-binding-scenarios@webstudio.test",
title: "MCP Email binding scenarios",
assetNamePrefix: "mcp-email-binding-scenarios-",
builderToken: "mcp-email-binding-scenarios-builder-token",
});
const { stdout } = await runFormAuthor(
"mcp-email-binding-author",
fixture.projectId
);
const { stdout } = await runFormAuthor("mcp-email-binding-author", projectId);
const { boundFormId, partialFormId, query, initialBundle, updatedBundle } =
JSON.parse(stdout) as {
boundFormId: string;
@@ -5,7 +5,7 @@ import { loadDevBuild } from "../db";
import { startFormDeliveryReceiver } from "../flows/generated-form-delivery";
import { withMcpEmailHttpPreview } from "../flows/mcp-email-http-preview";
import type { CapturedEmail } from "../flows/mcp-email-preview";
import { runFormAuthor } from "../flows/mcp-form-author";
import type { preparePreviewBundle } from "../fixtures/mcp-email-delivery-author";
import { configureSavedWebhookForm } from "../flows/webhook-form-action";
import { test } from "../test";
import {
@@ -31,64 +31,6 @@ test("Builder and MCP Form actions deliver from generated Preview", async ({
await test.step("save the legacy Webhook Form action through Builder", async () => {
await configureSavedWebhookForm({ page, fixture });
});
const { stdout } = await runFormAuthor(
"mcp-managed-form-author",
fixture.projectId,
"email",
"email-isolation",
"email-http-combination"
);
const [standard, isolated, combined] = stdout
.trim()
.split("\n")
.map((line) => JSON.parse(line)) as [
{ formId: string; emailResourceIds?: string[] },
{
formId: string;
secondFormId?: string;
emailResourceIdsByForm?: [string, string];
},
{ formId: string; emailResourceId: string; httpResourceId: string },
];
const emailResourceIds = standard.emailResourceIds;
const isolatedResourceIds = isolated.emailResourceIdsByForm;
if (
emailResourceIds === undefined ||
isolatedResourceIds === undefined ||
isolated.secondFormId === undefined
) {
throw new Error("Expected authored Email Forms and Resources");
}
expect(emailResourceIds).toHaveLength(2);
expect(isolated.secondFormId).toBeDefined();
expect(isolated.formId).not.toBe(isolated.secondFormId);
expect(isolatedResourceIds).toHaveLength(2);
expect(isolatedResourceIds[0]).not.toBe(isolatedResourceIds[1]);
const authoredBuild = await loadDevBuild({ projectId: fixture.projectId });
const authoredResources = JSON.parse(authoredBuild.resources) as Array<{
id: string;
name: string;
email?: Record<string, unknown>;
}>;
const authoredEmailResources = authoredResources.filter(({ id }) =>
emailResourceIds.includes(id)
);
expect(authoredEmailResources).toHaveLength(2);
expect(
authoredEmailResources.find(({ name }) => name === "Email to visitor")
?.email
).toMatchObject({
recipientMode: "visitor",
visitorEmailField: "email",
});
expect(JSON.parse(authoredBuild.projectSettings)).toMatchObject({
meta: {
contactEmail: "owner@mcp.test",
emailSender: "Contact Form <forms@mcp.test>",
},
});
const messages: CapturedMessage[] = [];
let rejectNext = false;
const receiver = createServer(async (request, response) => {
@@ -134,9 +76,57 @@ test("Builder and MCP Form actions deliver from generated Preview", async ({
}
await withMcpEmailHttpPreview({
projectId: fixture.projectId,
prepareModule: new URL(
"../fixtures/mcp-email-delivery-author.ts",
import.meta.url
).href,
emailPort: address.port,
httpPort: httpReceiver.port,
callback: async ({ url }) => {
callback: async ({ url, prepared }) => {
const { standard, isolated, combined } = prepared as Awaited<
ReturnType<typeof preparePreviewBundle>
>;
const emailResourceIds = standard.emailResourceIds;
const isolatedResourceIds = isolated.emailResourceIdsByForm;
if (
emailResourceIds === undefined ||
isolatedResourceIds === undefined ||
isolated.secondFormId === undefined
) {
throw new Error("Expected authored Email Forms and Resources");
}
expect(emailResourceIds).toHaveLength(2);
expect(isolated.secondFormId).toBeDefined();
expect(isolated.formId).not.toBe(isolated.secondFormId);
expect(isolatedResourceIds).toHaveLength(2);
expect(isolatedResourceIds[0]).not.toBe(isolatedResourceIds[1]);
const authoredBuild = await loadDevBuild({
projectId: fixture.projectId,
});
const authoredResources = JSON.parse(authoredBuild.resources) as Array<{
id: string;
name: string;
email?: Record<string, unknown>;
}>;
const authoredEmailResources = authoredResources.filter(({ id }) =>
emailResourceIds.includes(id)
);
expect(authoredEmailResources).toHaveLength(2);
expect(
authoredEmailResources.find(({ name }) => name === "Email to visitor")
?.email
).toMatchObject({
recipientMode: "visitor",
visitorEmailField: "email",
});
expect(JSON.parse(authoredBuild.projectSettings)).toMatchObject({
meta: {
contactEmail: "owner@mcp.test",
emailSender: "Contact Form <forms@mcp.test>",
},
});
await test.step("saved Webhook Form submits once in generated Preview", async () => {
await page.goto(url);
expect(httpReceiver.deliveries).toHaveLength(0);