mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-02 05:15:21 +09:00
## What changes When MCP starts, the CLI checks npm's `latest` release while the project session and API contract are loading. If a newer CLI is available, the MCP initialization instructions tell the connected agent which versions are running and recommend restarting with the latest CLI. The CLI never updates or restarts itself. The registry request has a 1.5-second timeout and fails open on network or response errors. It may add up to 1.5 seconds to startup if the project session finishes before the check; the existing server compatibility check remains the authority for whether writes are supported. ## Verification - [x] Added tests for newer, same/older, invalid, and unavailable registry responses; the newer-version test failed when the check was temporarily disabled. - [x] Verified the update notice reaches the connected MCP client; the handshake test failed when the notice was temporarily omitted. - [x] Full CLI suite: 1,159 tests passed. - [x] CLI and project-build typechecks passed; focused MCP initialization integration test passed. - [x] Lint, formatting, and diff checks passed. - [x] Documentation impact reviewed: no docs change is needed because the notice is sent dynamically at MCP startup. - [ ] Full Luna/low agent evaluation suite: approval requested, not received; not run. Ref #6461
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { expect, test, vi } from "vitest";
|
|
import { checkForCliUpdate } from "./cli-update";
|
|
|
|
test("detects a newer CLI release from the npm registry", async () => {
|
|
const request = vi.fn(async () => Response.json({ version: "0.301.0" }));
|
|
|
|
await expect(
|
|
checkForCliUpdate({ currentVersion: "0.299.0", request })
|
|
).resolves.toEqual({
|
|
currentVersion: "0.299.0",
|
|
latestVersion: "0.301.0",
|
|
});
|
|
expect(request).toHaveBeenCalledWith(
|
|
"https://registry.npmjs.org/webstudio/latest",
|
|
expect.objectContaining({ signal: expect.any(AbortSignal) })
|
|
);
|
|
});
|
|
|
|
test.each(["0.301.0", "0.300.0"])(
|
|
"does not recommend an update when installed CLI is %s or newer",
|
|
async (currentVersion) => {
|
|
const request = vi.fn(async () => Response.json({ version: "0.300.0" }));
|
|
|
|
await expect(
|
|
checkForCliUpdate({ currentVersion, request })
|
|
).resolves.toBeUndefined();
|
|
}
|
|
);
|
|
|
|
test("fails open when the registry is unavailable or has invalid data", async () => {
|
|
const failedRequest = vi.fn(async () => {
|
|
throw new Error("registry unavailable");
|
|
});
|
|
const invalidResponse = vi.fn(async () =>
|
|
Response.json({ version: "not-semver" })
|
|
);
|
|
|
|
await expect(
|
|
checkForCliUpdate({ currentVersion: "0.299.0", request: failedRequest })
|
|
).resolves.toBeUndefined();
|
|
await expect(
|
|
checkForCliUpdate({ currentVersion: "0.299.0", request: invalidResponse })
|
|
).resolves.toBeUndefined();
|
|
});
|
|
|
|
test("skips the registry check for a development build without a release version", async () => {
|
|
const request = vi.fn();
|
|
|
|
await expect(
|
|
checkForCliUpdate({ currentVersion: "0.0.0-webstudio-version", request })
|
|
).resolves.toBeUndefined();
|
|
expect(request).not.toHaveBeenCalled();
|
|
});
|