mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
perf: Share managed Form callback Preview
This commit is contained in:
1 parent
baeaab904f
commit
de54665a1d
3 files changed
+171
-152
No files matched your search
@@ -186,7 +186,7 @@ builder_backend_write_schema_snapshot() {
|
||||
# Dump only the application-owned public schema so the snapshot can be
|
||||
# restored without replacing database-owned schemas.
|
||||
if builder_compose exec -T db \
|
||||
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" --schema=public --schema-only --clean --if-exists --no-owner --no-privileges --restrict-key=webstudioE2ESchema' \
|
||||
sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" --schema=public --schema-only --clean --if-exists --no-owner --no-privileges' \
|
||||
>"$temporary_snapshot"; then
|
||||
mv "$temporary_snapshot" "$SCHEMA_SNAPSHOT"
|
||||
else
|
||||
|
||||
+35
-6
@@ -2,10 +2,8 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict webstudioE2ESchema
|
||||
|
||||
-- Dumped from database version 15.19 (Debian 15.19-1.pgdg12+2)
|
||||
-- Dumped by pg_dump version 15.19 (Debian 15.19-1.pgdg12+2)
|
||||
-- Dumped from database version 15.8
|
||||
-- Dumped by pg_dump version 15.8
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
@@ -120,6 +118,7 @@ DROP TABLE IF EXISTS public."domainsVirtual";
|
||||
DROP FUNCTION IF EXISTS public.delete_stale_asset_file_metadata(p_project_id text, p_asset_ids text[]);
|
||||
DROP FUNCTION IF EXISTS public.delete_asset_file_metadata_if_matches(p_project_id text, p_asset_id text, p_revision text, p_document jsonb);
|
||||
DROP FUNCTION IF EXISTS public.database_cleanup(from_date timestamp without time zone, to_date timestamp without time zone);
|
||||
DROP FUNCTION IF EXISTS public.create_production_build_expected(project_id text, deployment text, expected_version integer);
|
||||
DROP FUNCTION IF EXISTS public.create_production_build(project_id text, deployment text);
|
||||
DROP FUNCTION IF EXISTS public.clone_project(project_id text, user_id text, title text, domain text);
|
||||
DROP TABLE IF EXISTS public."Project";
|
||||
@@ -362,6 +361,38 @@ END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: create_production_build_expected(text, text, integer); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.create_production_build_expected(project_id text, deployment text, expected_version integer) RETURNS text
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
new_build_id text;
|
||||
BEGIN
|
||||
INSERT INTO "Build" (
|
||||
version, "lastTransactionId", pages, breakpoints, styles, "styleSources",
|
||||
"styleSourceSelections", props, "dataSources", resources, instances,
|
||||
"marketplaceProduct", "projectSettings", "publishStatus", "projectId", id,
|
||||
deployment
|
||||
)
|
||||
SELECT
|
||||
version, "lastTransactionId", pages, breakpoints, styles, "styleSources",
|
||||
"styleSourceSelections", props, "dataSources", resources, instances,
|
||||
"marketplaceProduct", "projectSettings", "publishStatus", "projectId",
|
||||
extensions.uuid_generate_v4(), create_production_build_expected.deployment
|
||||
FROM "Build"
|
||||
WHERE "projectId" = project_id
|
||||
AND "Build".deployment IS NULL
|
||||
AND version = expected_version
|
||||
RETURNING id INTO new_build_id;
|
||||
|
||||
RETURN new_build_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: database_cleanup(timestamp without time zone, timestamp without time zone); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
@@ -1877,5 +1908,3 @@ ALTER TABLE ONLY public."latestBuildVirtual"
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict webstudioE2ESchema
|
||||
|
||||
@@ -11,155 +11,104 @@ import { test } from "../test";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
for (const mode of ["legacy", "managed"] as const) {
|
||||
test(`MCP-authored ${mode} Form callbacks report success, receiver failure, and recovery in generated Preview`, async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const receiver = await startFormCallbackReceiver();
|
||||
try {
|
||||
const fixture = await createContentModeProject({
|
||||
context,
|
||||
email: `mcp-${mode}-callbacks@webstudio.test`,
|
||||
title: `MCP ${mode} callbacks`,
|
||||
assetNamePrefix: `mcp-${mode}-callbacks-`,
|
||||
});
|
||||
await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"--import",
|
||||
fileURLToPath(
|
||||
const mode = "legacy";
|
||||
test("MCP-authored legacy Form callbacks report success, receiver failure, and recovery in generated Preview", async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
const receiver = await startFormCallbackReceiver();
|
||||
try {
|
||||
const fixture = await createContentModeProject({
|
||||
context,
|
||||
email: `mcp-${mode}-callbacks@webstudio.test`,
|
||||
title: `MCP ${mode} callbacks`,
|
||||
assetNamePrefix: `mcp-${mode}-callbacks-`,
|
||||
});
|
||||
await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"--import",
|
||||
fileURLToPath(
|
||||
new URL(
|
||||
"../../../../scripts/register-react-global.ts",
|
||||
import.meta.url
|
||||
)
|
||||
),
|
||||
"--conditions=webstudio",
|
||||
fileURLToPath(
|
||||
new URL("../fixtures/mcp-form-callbacks-author.ts", import.meta.url)
|
||||
),
|
||||
fixture.projectId,
|
||||
mode,
|
||||
"https://mcp-delivery.example/submit",
|
||||
],
|
||||
{
|
||||
timeout: 60_000,
|
||||
env: {
|
||||
...process.env,
|
||||
TSX_TSCONFIG_PATH: fileURLToPath(
|
||||
new URL(
|
||||
"../../../../scripts/register-react-global.ts",
|
||||
"../../../../packages/cli/tsconfig.local.json",
|
||||
import.meta.url
|
||||
)
|
||||
),
|
||||
"--conditions=webstudio",
|
||||
fileURLToPath(
|
||||
new URL("../fixtures/mcp-form-callbacks-author.ts", import.meta.url)
|
||||
),
|
||||
fixture.projectId,
|
||||
mode,
|
||||
"https://mcp-delivery.example/submit",
|
||||
],
|
||||
{
|
||||
timeout: 60_000,
|
||||
env: {
|
||||
...process.env,
|
||||
TSX_TSCONFIG_PATH: fileURLToPath(
|
||||
new URL(
|
||||
"../../../../packages/cli/tsconfig.local.json",
|
||||
import.meta.url
|
||||
)
|
||||
),
|
||||
},
|
||||
}
|
||||
);
|
||||
const callback = async ({ url }: { url: string }) => {
|
||||
if (mode === "managed") {
|
||||
for (const outcome of ["success", "failure", "success"] as const) {
|
||||
const submission = (
|
||||
await submitPreviewFormViaMcp({
|
||||
url,
|
||||
input: {
|
||||
path: "/",
|
||||
selector: "#callback-form",
|
||||
values: [{ name: "outcome", value: outcome }],
|
||||
submitter: "button[type=submit]",
|
||||
timeout: 30_000,
|
||||
},
|
||||
})
|
||||
).data;
|
||||
expect(submission).toMatchObject({
|
||||
status: "submitted",
|
||||
formState: outcome === "success" ? "success" : "error",
|
||||
});
|
||||
expect(submission.results).toEqual([
|
||||
expect.objectContaining({
|
||||
status: outcome === "success" ? 200 : 503,
|
||||
}),
|
||||
]);
|
||||
expect(submission.errors).toHaveLength(
|
||||
outcome === "success" ? 0 : 1
|
||||
);
|
||||
expect(submission.exchanges).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
status: outcome === "success" ? 200 : 502,
|
||||
url: expect.stringContaining("/__ws-form"),
|
||||
}),
|
||||
])
|
||||
);
|
||||
}
|
||||
expect(receiver.deliveries).toEqual([
|
||||
{ outcome: "success" },
|
||||
{ outcome: "failure" },
|
||||
{ outcome: "success" },
|
||||
]);
|
||||
return;
|
||||
}
|
||||
await page.route("**/*", (route) => {
|
||||
return new URL(route.request().url()).hostname === "127.0.0.1"
|
||||
? route.continue()
|
||||
: route.abort();
|
||||
});
|
||||
await page.goto(url);
|
||||
const form = page.locator("#callback-form");
|
||||
const audit = page.locator("#callback-audit");
|
||||
await expect(audit).toHaveText(
|
||||
"state=initial;history=;results=0;errors=0;status=0"
|
||||
);
|
||||
const history: string[] = [];
|
||||
for (const outcome of ["success", "failure", "success"] as const) {
|
||||
await form.locator('input[name="outcome"]').fill(outcome);
|
||||
const responsePromise = page.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" &&
|
||||
new URL(response.url()).origin === new URL(url).origin
|
||||
);
|
||||
await form
|
||||
.getByRole("button", { name: "Submit callback form" })
|
||||
.click();
|
||||
const response = await responsePromise;
|
||||
const state = outcome === "success" ? "success" : "error";
|
||||
history.push(state);
|
||||
const renderedHistory = "|" + history.join("|");
|
||||
await expect(form).toHaveAttribute("data-state", state);
|
||||
expect(response.status()).toBe(200);
|
||||
await expect(audit).toHaveText(
|
||||
`state=${state};history=${renderedHistory};results=0;errors=0;status=0`
|
||||
);
|
||||
if (outcome === "failure") {
|
||||
// Legacy Fetcher submissions use React Router's streamed data envelope.
|
||||
expect(await response.text()).toContain("Service Unavailable");
|
||||
}
|
||||
}
|
||||
expect(receiver.deliveries).toEqual([
|
||||
{ outcome: "success" },
|
||||
{ outcome: "failure" },
|
||||
{ outcome: "success" },
|
||||
]);
|
||||
};
|
||||
if (mode === "legacy") {
|
||||
await withGeneratedPreview({
|
||||
projectId: fixture.projectId,
|
||||
evaluationReceiverPort: String(receiver.port),
|
||||
callback,
|
||||
});
|
||||
} else {
|
||||
await withGeneratedFormDeliveryPreview({
|
||||
projectId: fixture.projectId,
|
||||
receiverPort: receiver.port,
|
||||
callback,
|
||||
});
|
||||
},
|
||||
}
|
||||
} finally {
|
||||
await receiver.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
const callback = async ({ url }: { url: string }) => {
|
||||
await page.route("**/*", (route) => {
|
||||
return new URL(route.request().url()).hostname === "127.0.0.1"
|
||||
? route.continue()
|
||||
: route.abort();
|
||||
});
|
||||
await page.goto(url);
|
||||
const form = page.locator("#callback-form");
|
||||
const audit = page.locator("#callback-audit");
|
||||
await expect(audit).toHaveText(
|
||||
"state=initial;history=;results=0;errors=0;status=0"
|
||||
);
|
||||
const history: string[] = [];
|
||||
for (const outcome of ["success", "failure", "success"] as const) {
|
||||
await form.locator('input[name="outcome"]').fill(outcome);
|
||||
const responsePromise = page.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" &&
|
||||
new URL(response.url()).origin === new URL(url).origin
|
||||
);
|
||||
await form
|
||||
.getByRole("button", { name: "Submit callback form" })
|
||||
.click();
|
||||
const response = await responsePromise;
|
||||
const state = outcome === "success" ? "success" : "error";
|
||||
history.push(state);
|
||||
const renderedHistory = "|" + history.join("|");
|
||||
await expect(form).toHaveAttribute("data-state", state);
|
||||
expect(response.status()).toBe(200);
|
||||
await expect(audit).toHaveText(
|
||||
`state=${state};history=${renderedHistory};results=0;errors=0;status=0`
|
||||
);
|
||||
if (outcome === "failure") {
|
||||
// Legacy Fetcher submissions use React Router's streamed data envelope.
|
||||
expect(await response.text()).toContain("Service Unavailable");
|
||||
}
|
||||
}
|
||||
expect(receiver.deliveries).toEqual([
|
||||
{ outcome: "success" },
|
||||
{ outcome: "failure" },
|
||||
{ outcome: "success" },
|
||||
]);
|
||||
};
|
||||
await withGeneratedPreview({
|
||||
projectId: fixture.projectId,
|
||||
evaluationReceiverPort: String(receiver.port),
|
||||
callback,
|
||||
});
|
||||
} finally {
|
||||
await receiver.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("MCP-authored managed Form callbacks update same-page history, error, and recovery feedback", async ({
|
||||
page,
|
||||
@@ -210,6 +159,47 @@ test("MCP-authored managed Form callbacks update same-page history, error, and r
|
||||
projectId: fixture.projectId,
|
||||
receiverPort: receiver.port,
|
||||
callback: async ({ url }) => {
|
||||
await test.step("MCP submissions report success, failure, and recovery", async () => {
|
||||
for (const outcome of ["success", "failure", "success"] as const) {
|
||||
const submission = (
|
||||
await submitPreviewFormViaMcp({
|
||||
url,
|
||||
input: {
|
||||
path: "/",
|
||||
selector: "#callback-form",
|
||||
values: [{ name: "outcome", value: outcome }],
|
||||
submitter: "button[type=submit]",
|
||||
timeout: 30_000,
|
||||
},
|
||||
})
|
||||
).data;
|
||||
expect(submission).toMatchObject({
|
||||
status: "submitted",
|
||||
formState: outcome === "success" ? "success" : "error",
|
||||
});
|
||||
expect(submission.results).toEqual([
|
||||
expect.objectContaining({
|
||||
status: outcome === "success" ? 200 : 503,
|
||||
}),
|
||||
]);
|
||||
expect(submission.errors).toHaveLength(
|
||||
outcome === "success" ? 0 : 1
|
||||
);
|
||||
expect(submission.exchanges).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
status: outcome === "success" ? 200 : 502,
|
||||
url: expect.stringContaining("/__ws-form"),
|
||||
}),
|
||||
])
|
||||
);
|
||||
}
|
||||
expect(receiver.deliveries).toEqual([
|
||||
{ outcome: "success" },
|
||||
{ outcome: "failure" },
|
||||
{ outcome: "success" },
|
||||
]);
|
||||
});
|
||||
await page.route("**/*", (route) =>
|
||||
new URL(route.request().url()).hostname === "127.0.0.1"
|
||||
? route.continue()
|
||||
@@ -238,7 +228,7 @@ test("MCP-authored managed Form callbacks update same-page history, error, and r
|
||||
outcome === "success" ? "no errors" : "Service Unavailable"
|
||||
);
|
||||
}
|
||||
expect(receiver.deliveries).toEqual([
|
||||
expect(receiver.deliveries.slice(3)).toEqual([
|
||||
{ outcome: "success" },
|
||||
{ outcome: "failure" },
|
||||
{ outcome: "success" },
|
||||
|
||||
Reference in new issue
Block a user