mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
fix: keep MCP publish inputs valid and finish superseded builds
This commit is contained in:
1 parent
e2784fa6f7
commit
852023b5c8
5 files changed
+107
-3
No files matched your search
@@ -135,6 +135,43 @@ test("static status waits for the matching runner before download readiness", as
|
||||
expect(getJob).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test.each(["site", "static"] as const)(
|
||||
"finishes an accepted %s publish when a newer build becomes latest",
|
||||
async (target) => {
|
||||
vi.useFakeTimers();
|
||||
const newerBuild = {
|
||||
buildId: "build-2",
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
publishStatus: "PUBLISHED",
|
||||
};
|
||||
const refresh = vi.fn(
|
||||
async () =>
|
||||
({
|
||||
latestBuildVirtual: target === "site" ? newerBuild : null,
|
||||
latestStaticBuild: target === "static" ? newerBuild : null,
|
||||
}) as Project
|
||||
);
|
||||
const getJob = vi.fn(async () => ({ status: "success" }));
|
||||
const waiting = waitForPublishStatus(
|
||||
refresh,
|
||||
() => true,
|
||||
undefined,
|
||||
{
|
||||
projectId: "project",
|
||||
buildId: "build-1",
|
||||
logHandle: "handle-1",
|
||||
target,
|
||||
},
|
||||
getJob
|
||||
);
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
expect((await waiting)?.status).toBe("PUBLISHED");
|
||||
expect(refresh).toHaveBeenCalledOnce();
|
||||
}
|
||||
);
|
||||
|
||||
test("reopening refresh retries after a rejected status request", async () => {
|
||||
vi.useFakeTimers();
|
||||
const errorLog = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
@@ -36,6 +36,7 @@ export const waitForPublishStatus = async (
|
||||
const timeToFinish = Date.now() + PENDING_TIMEOUT + 2 * sleepTime;
|
||||
|
||||
while (Date.now() < timeToFinish && isCurrentProject()) {
|
||||
let runnerSucceeded = false;
|
||||
try {
|
||||
let runnerPending = false;
|
||||
if (execution?.logHandle !== undefined) {
|
||||
@@ -56,6 +57,7 @@ export const waitForPublishStatus = async (
|
||||
};
|
||||
}
|
||||
runnerPending = job.status === "pending";
|
||||
runnerSucceeded = job.status === "success";
|
||||
} catch (error) {
|
||||
console.error("Could not refresh publish status", error);
|
||||
}
|
||||
@@ -95,6 +97,13 @@ export const waitForPublishStatus = async (
|
||||
// A failed status request should not stop watching an ongoing publish.
|
||||
console.error("Could not refresh publish status", error);
|
||||
}
|
||||
if (runnerSucceeded && isCurrentProject()) {
|
||||
return {
|
||||
status: "PUBLISHED" as const,
|
||||
statusContent:
|
||||
execution?.target === "static" ? "Downloaded" : "Published",
|
||||
};
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, sleepTime));
|
||||
sleepTime = Math.max(5000, sleepTime - 5000);
|
||||
|
||||
@@ -2617,6 +2617,21 @@ test("exposes asset content editing through MCP discovery", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("exposes valid inputs for both publish targets through MCP discovery", () => {
|
||||
const tool = listProjectSessionMcpTools(publicApiOperations).find(
|
||||
({ name }) => name === "publish"
|
||||
);
|
||||
|
||||
expect(tool?.inputSchema).toMatchObject({
|
||||
additionalProperties: true,
|
||||
required: ["target"],
|
||||
oneOf: [
|
||||
{ properties: { target: expect.any(Object) } },
|
||||
{ properties: { target: expect.any(Object) } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("exposes a client-valid update-props schema", () => {
|
||||
const tool = listProjectSessionMcpTools(publicApiOperations).find(
|
||||
({ name }) => name === "update-props"
|
||||
|
||||
@@ -1323,6 +1323,39 @@ describe("project session mcp adapter", () => {
|
||||
expect(tool?.inputSchema.properties).not.toHaveProperty("runtime");
|
||||
});
|
||||
|
||||
test("keeps discriminated publish inputs valid in the MCP tool schema", () => {
|
||||
const [tool] = listProjectSessionMcpTools([
|
||||
publicOperation({
|
||||
command: "publish",
|
||||
id: "build.publish",
|
||||
description: "Publish a site or static export",
|
||||
localCapable: false,
|
||||
serverOnly: true,
|
||||
inputSchema: getTestInputSchema(
|
||||
z.discriminatedUnion("target", [
|
||||
z.object({
|
||||
target: z.literal("production"),
|
||||
domains: z.array(z.string()),
|
||||
}),
|
||||
z.object({
|
||||
target: z.literal("static"),
|
||||
templates: z.array(z.string()),
|
||||
}),
|
||||
])
|
||||
),
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(tool?.inputSchema).toMatchObject({
|
||||
oneOf: [
|
||||
{ properties: { target: { const: "production" } } },
|
||||
{ properties: { target: { const: "static" } } },
|
||||
],
|
||||
required: ["target"],
|
||||
additionalProperties: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("defers oversized input schemas until focused discovery", async () => {
|
||||
const description = "x".repeat(25_000);
|
||||
const operation = publicOperation({
|
||||
|
||||
@@ -683,9 +683,16 @@ const getOperationInputSchema = (
|
||||
operation.inputSchema
|
||||
);
|
||||
const properties = getInputJsonSchemaProperties(operation.inputSchema);
|
||||
const hasComposedBranches =
|
||||
operation.inputSchema.oneOf !== undefined ||
|
||||
operation.inputSchema.anyOf !== undefined ||
|
||||
operation.inputSchema.allOf !== undefined;
|
||||
const additionalProperties =
|
||||
operation.inputSchema.additionalProperties ??
|
||||
(properties === undefined || Object.keys(properties).length === 0);
|
||||
hasComposedBranches &&
|
||||
Object.keys(operation.inputSchema.properties ?? {}).length === 0
|
||||
? true
|
||||
: (operation.inputSchema.additionalProperties ??
|
||||
(properties === undefined || Object.keys(properties).length === 0));
|
||||
return {
|
||||
...emptyInputSchema,
|
||||
...operation.inputSchema,
|
||||
@@ -2010,7 +2017,10 @@ const getMcpOperationInputSchema = (
|
||||
const properties = getInputJsonSchemaProperties(schema);
|
||||
if (
|
||||
schema.additionalProperties === true &&
|
||||
(properties === undefined || Object.keys(properties).length === 0)
|
||||
(properties === undefined || Object.keys(properties).length === 0) &&
|
||||
schema.oneOf === undefined &&
|
||||
schema.anyOf === undefined &&
|
||||
schema.allOf === undefined
|
||||
) {
|
||||
schema = { ...schema, additionalProperties: false };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user