fix: filter skills.sh route query params (#3450)

This commit is contained in:
Patrick Erichsen
2026-08-11 13:00:09 -07:00
committed by GitHub
parent fb2515649a
commit faab45bace
2 changed files with 45 additions and 5 deletions
+40 -4
View File
@@ -22,17 +22,34 @@ async function loadRoute() {
};
}
async function runLoader() {
async function runLoader(params = { owner: "patrick-erichsen", repo: "skills", slug: "html" }) {
const route = await loadRoute();
try {
return await route.__config.loader({
params: { owner: "patrick-erichsen", repo: "skills", slug: "html" },
});
return await route.__config.loader({ params });
} catch (error) {
return error;
}
}
async function getFuzzyMatchParams() {
const { createMemoryHistory, createRootRoute, createRoute, createRouter } =
await vi.importActual<typeof import("@tanstack/react-router")>("@tanstack/react-router");
const rootRoute = createRootRoute();
const detailRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/skills-sh/$owner/$repo/$slug",
});
const router = createRouter({
routeTree: rootRoute.addChildren([detailRoute]),
history: createMemoryHistory({ initialEntries: ["/"] }),
});
const match = router
.matchRoutes("/skills-sh/patrick-erichsen/skills/html/extra")
.find((candidate) => candidate.routeId === "/skills-sh/$owner/$repo/$slug");
if (!match) throw new Error("Expected TanStack Router to fuzzy-match the skills.sh detail route");
return match.params;
}
describe("skills.sh detail route", () => {
beforeEach(() => queryMock.mockReset());
@@ -48,6 +65,25 @@ describe("skills.sh detail route", () => {
});
});
it("omits TanStack fuzzy-match metadata from the Convex query", async () => {
const entry = { displayName: "HTML Artifact Chooser" };
queryMock.mockResolvedValue({ kind: "external", entry });
const params = await getFuzzyMatchParams();
expect(params).toEqual({
owner: "patrick-erichsen",
repo: "skills",
slug: "html",
"**": "extra",
});
expect(await runLoader(params)).toEqual(entry);
expect(queryMock.mock.calls[0]?.[1]).toEqual({
owner: "patrick-erichsen",
repo: "skills",
slug: "html",
});
});
it("redirects a promoted alias to its canonical publisher route", async () => {
queryMock.mockResolvedValue({
kind: "redirect",
+5 -1
View File
@@ -5,7 +5,11 @@ import { convexHttp } from "../../../../convex/client";
export const Route = createFileRoute("/skills-sh/$owner/$repo/$slug")({
loader: async ({ params }) => {
const result = await convexHttp.query(api.skillsShMirrorPublic.getByRoute, params);
const result = await convexHttp.query(api.skillsShMirrorPublic.getByRoute, {
owner: params.owner,
repo: params.repo,
slug: params.slug,
});
if (!result) throw notFound();
if (result.kind === "redirect") throw redirect({ href: result.canonicalRoute });
return result.entry;