mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-04 15:34:39 +00:00
* feat(website): serve paseo.sh in Simplified Chinese
Every page of the website now has a Simplified Chinese version under
/zh-CN: the interface, docs, blog posts, comparison pages, legal pages,
all changelog releases and the homepage mockup. English URLs are unchanged.
The URL alone decides the language. There is no browser-language redirect
and no stored preference, because either would have to redirect the
unprefixed English URLs that people share and search engines index.
Internal links carry the page's language instead, and hreflang alternates
point Chinese search results at /zh-CN.
Translated headings pin the English anchor with {#id}, so section links
work in both languages. content-translations.test.ts fails when a page
has no translation or a translation's headings drift from the English.
Changelog releases and plugin listings without a translation render
whole in English under a notice, so a release never waits on one.
Plugin manifests and the registry gain optional translations and
OVERVIEW.zh-CN.md fields; older clients and registries ignore them.
* feat(website): replace the native language select with an EN/ZH menu
The header showed an OS-native select whose popup did not match the site.
The trigger now shows the language abbreviated (EN, ZH) and opens a menu in
the app's dropdown style that names each language in itself, with its name
in the page language underneath. Rows are real links to the same page in
that language; arrows, Escape, outside presses and taps behave as a menu
button, and the menu keeps itself on screen when a narrow header pushes the
trigger toward an edge.
Also drops the stray space after the full-width comma in the Chinese
homepage subtitle.
* docs(website): translate main's new docs and 0.12.0 release notes
Main added Keep run workspaces to the schedules docs, rewrote plugin icons
around inline SVG, and promoted 0.12.0 with new entries. Bring the Chinese
pages and changelog in line so no section falls back to English.
* fix(server): leave plugin listing translations to the registry
The daemon rejected manifests whose translations the registry would refuse,
so a plugin main installs could fail to load here. Paseo never reads
translations; the registry validates them at publish. Docs now say which
checks are automated at publish and which are human review.
* docs(plugins): describe the registry's final overview translation discovery
* style(server): format manifest test
* test(app): measure sidebar rows one at a time
After a reload the developer error toast appears while expectVerticalOrder
measures every row at once. Each concurrent boundingBox runs the toast
locator handler, and only one of them resumes, so the poll timed out on
every attempt since #7424. Measuring sequentially keeps one action in flight.
* test(app): return sidebar row measuring to main
#7480 hides the developer toast instead of running a locator handler, so
measuring the rows concurrently no longer races it. Reverts 41ac23016.
* test(app): wait for the compact shell before opening compact Changes
The shell survives the breakpoint, so right after the resize the wide
Explorer could still be visible: the test skipped the Explorer toggle and
the tab then disappeared, or toggled at the wrong time. Wait for the
compact-shell marker, as the composer helpers do since #7424.
* docs(website): translate main's plugin file panel docs
* test(app): edit the code font size after the font family remount
A committed appearance change remounts the settings screen through
AppearanceStyleBoundary, and the new form starts from the stored size.
Filling the size before that remount lost the edit in CI.
* docs(website): translate main's client/ui import docs
Follows #7474: one /client/ui entry, StreamedText instead of useRevealedText,
SettingsGroup dropped from the settings table, and the new
'UI imports in v0.13' migration section.
* test(app): wait for the previous layout's file panel picker to leave
After a resize the old layout's picker animates out while the new one is
already mounted, so the Use button matched two elements and the strict
locator failed. Wait for the shell's layout and a single picker first.
276 lines
10 KiB
TypeScript
276 lines
10 KiB
TypeScript
import {
|
|
createMemoryHistory,
|
|
createRootRoute,
|
|
createRouter,
|
|
RouterProvider,
|
|
} from "@tanstack/react-router";
|
|
import { createElement, type ReactElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
import { LocaleProvider } from "~/i18n";
|
|
import { handlePluginThumbnailRequest, pluginCardScreenshot } from "./thumbnails";
|
|
import { PluginCard } from "./plugin-card";
|
|
import type { Plugin } from "./registry";
|
|
|
|
const source = "https://cdn.jsdelivr.net/npm/paseo-example@1.2.3/preview.png";
|
|
const video = "https://cdn.jsdelivr.net/npm/paseo-example@1.2.3/demo.mp4";
|
|
const plugin: Plugin = {
|
|
id: "acme/example",
|
|
name: "Example",
|
|
description: "An example",
|
|
categories: ["themes"],
|
|
author: { github: "acme" },
|
|
repository: { url: "https://github.com/acme/example" },
|
|
artifact: {
|
|
kind: "npm",
|
|
package: "paseo-example",
|
|
version: "1.2.3",
|
|
resolved: "https://registry.npmjs.org/example.tgz",
|
|
integrity: "sha512-YWJj",
|
|
},
|
|
media: [source],
|
|
submittedAt: "2026-10-03",
|
|
reviewedAt: "2026-10-03",
|
|
updatedAt: "2026-10-03",
|
|
publishedAt: "2026-10-03",
|
|
installs: 42,
|
|
};
|
|
|
|
const avatar = 'src="https://github.com/acme.png?size=80"';
|
|
|
|
/** Renders a card on an English page, inside the router and language provider every page has. */
|
|
async function renderOnPage(card: ReactElement): Promise<string> {
|
|
const router = createRouter({
|
|
routeTree: createRootRoute({ component: () => createElement(LocaleProvider, null, card) }),
|
|
history: createMemoryHistory({ initialEntries: ["/"] }),
|
|
});
|
|
await router.load();
|
|
return renderToStaticMarkup(createElement(RouterProvider, { router }));
|
|
}
|
|
|
|
describe("plugin card thumbnails", () => {
|
|
it("uses the first image in the plugin's media, skipping a leading video", async () => {
|
|
const html = await renderOnPage(
|
|
createElement(PluginCard, { plugin: { ...plugin, media: [video, source] } }),
|
|
);
|
|
expect(html).toContain(`/plugins/thumb/592/${encodeURIComponent(source)}?`);
|
|
expect(html).not.toContain(encodeURIComponent(video));
|
|
});
|
|
|
|
it("shows the plugin tile when the media has no image", async () => {
|
|
const html = await renderOnPage(
|
|
createElement(PluginCard, { plugin: { ...plugin, media: [video] } }),
|
|
);
|
|
expect(html.match(/<img [^>]*>/g)).toEqual([expect.stringContaining(avatar)]);
|
|
expect(html).not.toContain("<video");
|
|
expect(html).toContain(">E</div>");
|
|
});
|
|
|
|
it("keeps a screenshot on an unsupported host visible at its original URL", async () => {
|
|
const screenshot = "https://example.com/preview.png";
|
|
const html = await renderOnPage(
|
|
createElement(PluginCard, { plugin: { ...plugin, media: [screenshot] } }),
|
|
);
|
|
expect(html).toContain(`src="${screenshot}"`);
|
|
expect(html).not.toContain("/plugins/thumb/");
|
|
});
|
|
|
|
it("shows the author's avatar and name beside the card detail", async () => {
|
|
const html = await renderOnPage(createElement(PluginCard, { plugin }, "today"));
|
|
expect(html).toContain(avatar);
|
|
expect(html).toMatch(/>acme<\/span><span aria-hidden="true">·<\/span><span[^>]*>today<\/span>/);
|
|
});
|
|
|
|
it("renders a thumbnail instead of downloading the original screenshot", async () => {
|
|
const html = await renderOnPage(createElement(PluginCard, { plugin }, "today"));
|
|
expect(html).toContain(
|
|
`src="/plugins/thumb/592/${encodeURIComponent(source)}?plugin=acme%2Fexample"`,
|
|
);
|
|
expect(html).toContain(
|
|
`srcSet="/plugins/thumb/592/${encodeURIComponent(source)}?plugin=acme%2Fexample 1x, /plugins/thumb/1184/${encodeURIComponent(source)}?plugin=acme%2Fexample 2x"`,
|
|
);
|
|
expect(html).toContain('loading="lazy"');
|
|
expect(html).toContain('decoding="async"');
|
|
});
|
|
});
|
|
|
|
function thumbnailRequest(
|
|
sourceUrl = source,
|
|
width = 592,
|
|
id = plugin.id,
|
|
accept = "image/avif,image/webp",
|
|
) {
|
|
return new Request(
|
|
`https://paseo.sh/plugins/thumb/${width}/${encodeURIComponent(sourceUrl)}?plugin=${encodeURIComponent(id)}`,
|
|
{ headers: { accept } },
|
|
);
|
|
}
|
|
|
|
function imageResponse(body: string, headers: Record<string, string> = {}) {
|
|
return new Response(body, { headers: { "content-type": "image/png", ...headers } });
|
|
}
|
|
|
|
// A typed fetch dependency, returning real Responses without patching the global fetch.
|
|
function imageFetch(...responses: (Response | Error)[]) {
|
|
const calls: { input: Parameters<typeof fetch>[0]; init: Parameters<typeof fetch>[1] }[] = [];
|
|
const fetchImage: typeof fetch = async (input, init) => {
|
|
calls.push({ input, init });
|
|
const response = responses.shift();
|
|
if (!response) throw new Error("Unexpected fetch");
|
|
if (response instanceof Error) throw response;
|
|
return response;
|
|
};
|
|
return { calls, fetchImage };
|
|
}
|
|
|
|
describe("thumbnail route", () => {
|
|
it("sandboxes an SVG fallback when opened as a document on the website origin", async () => {
|
|
const svg =
|
|
'<svg xmlns="http://www.w3.org/2000/svg"><script>alert(document.domain)</script></svg>';
|
|
const upstream = imageFetch(
|
|
new Response("unsupported", { status: 415 }),
|
|
imageResponse(svg, { "content-type": "image/svg+xml" }),
|
|
);
|
|
const response = await handlePluginThumbnailRequest(
|
|
thumbnailRequest(),
|
|
[plugin],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(await response.text()).toBe(svg);
|
|
expect(response.headers.get("content-security-policy")).toBe("sandbox");
|
|
expect(response.headers.get("x-content-type-options")).toBe("nosniff");
|
|
});
|
|
|
|
it.each([
|
|
[592, source, "image/avif,image/webp", "avif"],
|
|
[592, source, "image/avif;q=0,image/webp", "webp"],
|
|
[592, source, "image/avif;q=0,image/webp;q=0", undefined],
|
|
[
|
|
1184,
|
|
"https://raw.githubusercontent.com/acme/example/abc123/preview.png",
|
|
"image/webp",
|
|
"webp",
|
|
],
|
|
[592, source, "image/png,image/*;q=0.8", undefined],
|
|
] as const)(
|
|
"transforms a registered screenshot at %s from %s for %s",
|
|
async (width, screenshot, accept, format) => {
|
|
const upstream = imageFetch(imageResponse("thumbnail"));
|
|
const response = await handlePluginThumbnailRequest(
|
|
thumbnailRequest(screenshot, width, plugin.id, accept),
|
|
[{ ...plugin, media: [screenshot] }],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(upstream.calls).toEqual([
|
|
{
|
|
input: screenshot,
|
|
init: {
|
|
cf: { image: { width, fit: "scale-down", format, quality: 80 } },
|
|
},
|
|
},
|
|
]);
|
|
expect(response.status).toBe(200);
|
|
expect(await response.text()).toBe("thumbnail");
|
|
expect(response.headers.get("content-type")).toBe("image/png");
|
|
expect(response.headers.get("cache-control")).toBe("public, max-age=31536000, immutable");
|
|
expect(response.headers.get("vary")).toBe("Accept");
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
["Cloudflare error", () => new Response("error 9401", { status: 403 })],
|
|
[
|
|
"non-image success",
|
|
() => new Response("<html>unavailable</html>", { headers: { "content-type": "text/html" } }),
|
|
],
|
|
["Cf-Resized error", () => imageResponse("error", { "cf-resized": "err=9401" })],
|
|
["network exception", () => new Error("Transform unavailable")],
|
|
] as const)("proxies the original with immutable caching on %s", async (_, failure) => {
|
|
const upstream = imageFetch(failure(), imageResponse("original"));
|
|
const response = await handlePluginThumbnailRequest(
|
|
thumbnailRequest(),
|
|
[plugin],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(upstream.calls.map((call) => call.input)).toEqual([source, source]);
|
|
expect(upstream.calls[1].init).toBeUndefined();
|
|
expect(response.status).toBe(200);
|
|
expect(await response.text()).toBe("original");
|
|
expect(response.headers.get("cache-control")).toBe("public, max-age=31536000, immutable");
|
|
});
|
|
|
|
it.each([
|
|
["arbitrary width", thumbnailRequest(source, 593), [plugin], 400],
|
|
["unlisted source on allowed host", thumbnailRequest(source + "?different"), [plugin], 404],
|
|
["wrong plugin ID", thumbnailRequest(source, 592, "acme/other"), [plugin], 404],
|
|
[
|
|
"missing plugin ID",
|
|
new Request(`https://paseo.sh/plugins/thumb/592/${encodeURIComponent(source)}`),
|
|
[plugin],
|
|
404,
|
|
],
|
|
["removed plugin", thumbnailRequest(), [], 404],
|
|
["listed video", thumbnailRequest(video), [{ ...plugin, media: [video, source] }], 404],
|
|
["malformed encoding", new Request("https://paseo.sh/plugins/thumb/592/%ZZ"), [plugin], 400],
|
|
["malformed URL", thumbnailRequest("not a URL"), [plugin], 400],
|
|
...[
|
|
"https://example.com/preview.png",
|
|
"https://cdn.jsdelivr.net.evil.test/preview.png",
|
|
"http://cdn.jsdelivr.net/preview.png",
|
|
"https://user:pass@cdn.jsdelivr.net/preview.png",
|
|
"https://cdn.jsdelivr.net:8080/preview.png",
|
|
].map(
|
|
(url) =>
|
|
[
|
|
"disallowed registered source",
|
|
thumbnailRequest(url),
|
|
[{ ...plugin, media: [url] }],
|
|
400,
|
|
] satisfies [string, Request, Plugin[], number],
|
|
),
|
|
] satisfies [string, Request, Plugin[], number][])(
|
|
"rejects %s without fetching an image",
|
|
async (_, request, plugins, status) => {
|
|
const upstream = imageFetch();
|
|
const response = await handlePluginThumbnailRequest(
|
|
request,
|
|
[...plugins],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(response.status).toBe(status);
|
|
expect(upstream.calls).toEqual([]);
|
|
expect(response.headers.get("cache-control")).toBeNull();
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
() => new Response("missing", { status: 404 }),
|
|
() => new Response("<html>error</html>", { headers: { "content-type": "text/html" } }),
|
|
() => new Error("Origin unavailable"),
|
|
])("does not cache a failed original for a year", async (failure) => {
|
|
const upstream = imageFetch(new Response("transform error", { status: 502 }), failure());
|
|
const response = await handlePluginThumbnailRequest(
|
|
thumbnailRequest(),
|
|
[plugin],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(response.status).toBe(502);
|
|
expect(response.headers.get("cache-control")).toBe("no-store");
|
|
});
|
|
|
|
it("round-trips screenshot URL punctuation through the card URL", async () => {
|
|
const screenshot = source + "?name=a&other=b#preview";
|
|
const upstream = imageFetch(imageResponse("thumbnail"));
|
|
const request = new Request(
|
|
"https://paseo.sh" + pluginCardScreenshot(plugin.id, screenshot).src,
|
|
);
|
|
const response = await handlePluginThumbnailRequest(
|
|
request,
|
|
[{ ...plugin, media: [screenshot] }],
|
|
upstream.fetchImage,
|
|
);
|
|
expect(response.status).toBe(200);
|
|
expect(upstream.calls[0].input).toBe(screenshot);
|
|
});
|
|
});
|