mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
fix: Preserve custom page metadata on partial updates (#6721)
A partial page metadata update no longer removes existing custom tags. Passing `meta.custom: []` still clears the collection. The cause was an omitted `custom` field becoming an own property with value `undefined` during expression binding. Patch generation treated it as an explicit removal. The update now binds custom entries only when the field is supplied. - [x] Add regression coverage for dry-run and committed updates with existing custom metadata. - [x] Verify explicit `custom: []` clears the collection. - [x] Verify both `mcp single-op-call` and `mcp run` manifest paths; tests fail with the old helper and pass with the fix. - [x] Run project-build tests (2,764) and CLI tests (1,356). - [x] Run both package typechecks, lint, formatting, package-boundary check, and diff check. - [x] Review documentation impact; no docs or fixture changes are needed. Closes #6718
This commit is contained in:
1 parent
fc5b7e140e
commit
57b20ee85b
3 files changed
+151
-6
No files matched your search
@@ -8,7 +8,6 @@ import {
|
||||
expectContentModePageSettingsRestrictions,
|
||||
expectCustomMetadataValue,
|
||||
fillAllowedPageSettings,
|
||||
fillCustomMetadata,
|
||||
getPageSettingsPathInput,
|
||||
openPage,
|
||||
openPageSettings,
|
||||
@@ -123,7 +122,6 @@ test("Editor can create a styled page, edit allowed settings, and reload it in c
|
||||
filename: fixture.assetTemplateImageName,
|
||||
label: fixture.assetTemplateImageAlt,
|
||||
});
|
||||
await fillCustomMetadata({ page, ...metadata });
|
||||
});
|
||||
|
||||
await measure("content mode reload created page and settings", async () => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
createProjectSession,
|
||||
} from "@webstudio-is/project-build/project-session";
|
||||
import {
|
||||
applyBuilderPatchTransactions,
|
||||
createBuilderStateFromSnapshot,
|
||||
createBuilderStateFreshness,
|
||||
} from "@webstudio-is/project-build/state";
|
||||
@@ -399,6 +400,150 @@ afterEach(async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test.each(["single-op-call", "run"])(
|
||||
"preserves omitted custom page metadata and clears an explicit empty list through MCP %s",
|
||||
async (mode) => {
|
||||
const operation = publicApiOperations.find(
|
||||
({ command }) => command === "update-page"
|
||||
);
|
||||
if (operation === undefined) {
|
||||
throw new Error("Expected update-page MCP operation");
|
||||
}
|
||||
const directory = await mkdtemp(path.join(tmpdir(), "webstudio-mcp-page-"));
|
||||
tempDirs.push(directory);
|
||||
const custom = [{ property: "og:type", content: '"website"' }];
|
||||
let state = createBuilderStateFromSnapshot({
|
||||
pages: {
|
||||
homePageId: "home",
|
||||
rootFolderId: "root",
|
||||
pages: new Map([
|
||||
[
|
||||
"home",
|
||||
{
|
||||
id: "home",
|
||||
name: "Home",
|
||||
path: "",
|
||||
title: '"Home"',
|
||||
rootInstanceId: "body",
|
||||
meta: { custom },
|
||||
},
|
||||
],
|
||||
]),
|
||||
folders: new Map([
|
||||
["root", { id: "root", name: "Root", slug: "", children: ["home"] }],
|
||||
]),
|
||||
},
|
||||
instances: [
|
||||
[
|
||||
"body",
|
||||
{ id: "body", type: "instance", component: "Body", children: [] },
|
||||
],
|
||||
],
|
||||
dataSources: [],
|
||||
});
|
||||
let version = 1;
|
||||
const session = createProjectSession({
|
||||
projectId: "project-1",
|
||||
storage: createCliProjectSessionStorage(
|
||||
path.join(directory, "session.json")
|
||||
),
|
||||
runtimeContext: { createId: () => crypto.randomUUID() },
|
||||
transport: {
|
||||
async fetchNamespaces() {
|
||||
return { projectId: "project-1", buildId: "build-1", version, state };
|
||||
},
|
||||
async commitPatch({ baseVersion, transactions }) {
|
||||
state = applyBuilderPatchTransactions(state, transactions).state;
|
||||
version = baseVersion + 1;
|
||||
return { version };
|
||||
},
|
||||
async commitRestorePoint() {
|
||||
throw new Error("Page updates must use patch commits");
|
||||
},
|
||||
},
|
||||
});
|
||||
const core = createProjectSessionMcpCore({
|
||||
operations: [operation],
|
||||
createProjectSession: () => session,
|
||||
executeOperation: ({ input, dryRun }) =>
|
||||
session.mutate("pages.update", input, { dryRun }),
|
||||
});
|
||||
const tool = operation.command;
|
||||
const input = {
|
||||
pageId: "home",
|
||||
values: { meta: { excludePageFromSearch: true } },
|
||||
};
|
||||
const clearInput = { pageId: "home", values: { meta: { custom: [] } } };
|
||||
const calls = [
|
||||
{ tool, input, dryRun: true },
|
||||
{ tool, input, dryRun: false },
|
||||
{ tool, input: clearInput, dryRun: false },
|
||||
];
|
||||
const [preview, commit, clear] =
|
||||
mode === "run"
|
||||
? await parseMcpRunInput(JSON.stringify({ calls }))
|
||||
: calls;
|
||||
const execute = async (
|
||||
call: ReturnType<typeof parseMcpRunCalls>[number]
|
||||
) => {
|
||||
if (mode === "run") {
|
||||
const { result } = await executeMcpRunCall({
|
||||
core,
|
||||
call,
|
||||
scope: { projectRoot: directory },
|
||||
});
|
||||
return result.structuredContent;
|
||||
}
|
||||
const input = await parseMcpSingleOpCallInput({
|
||||
input: JSON.stringify(call.input),
|
||||
});
|
||||
validateSingleOpCallInput(tool, input);
|
||||
const result = await core.callTool({
|
||||
name: tool,
|
||||
input,
|
||||
dryRun: call.dryRun,
|
||||
});
|
||||
return result.structuredContent;
|
||||
};
|
||||
|
||||
const previewResult = await execute(preview);
|
||||
expect(previewResult).toMatchObject({
|
||||
ok: true,
|
||||
meta: { session: { committed: false } },
|
||||
});
|
||||
expect(previewResult.meta.session?.transaction?.payload).toEqual([
|
||||
{
|
||||
namespace: "pages",
|
||||
patches: [
|
||||
{
|
||||
op: "add",
|
||||
path: ["pages", "home", "meta", "excludePageFromSearch"],
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
expect(version).toBe(1);
|
||||
expect(await execute(commit)).toMatchObject({
|
||||
ok: true,
|
||||
meta: { session: { committed: true } },
|
||||
});
|
||||
expect(state.pages?.pages.get("home")?.meta).toEqual({
|
||||
custom,
|
||||
excludePageFromSearch: "true",
|
||||
});
|
||||
|
||||
expect(await execute(clear)).toMatchObject({
|
||||
ok: true,
|
||||
meta: { session: { committed: true } },
|
||||
});
|
||||
expect(state.pages?.pages.get("home")?.meta).toEqual({
|
||||
custom: [],
|
||||
excludePageFromSearch: "true",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
test("confirms a resource deletion across persisted CLI sessions only for the unchanged plan", async () => {
|
||||
const operation = publicApiOperations.find(
|
||||
({ command }) => command === "delete-resource"
|
||||
|
||||
@@ -902,10 +902,12 @@ const bindPageFieldsExpressionInputs = <Input extends PageFieldsPatchInput>({
|
||||
meta[name] = bindExpressionInput(state, rootInstanceId, value);
|
||||
}
|
||||
}
|
||||
meta.custom = meta.custom?.map((customMeta) => ({
|
||||
...customMeta,
|
||||
content: bindExpressionInput(state, rootInstanceId, customMeta.content),
|
||||
}));
|
||||
if (meta.custom !== undefined) {
|
||||
meta.custom = meta.custom.map((customMeta) => ({
|
||||
...customMeta,
|
||||
content: bindExpressionInput(state, rootInstanceId, customMeta.content),
|
||||
}));
|
||||
}
|
||||
bound.meta = meta;
|
||||
return bound;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user