Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import { formatThreadLink, parseThreadLinkHref } from "./threadLinks.ts";
|
|
|
|
describe("thread links", () => {
|
|
it("round-trips ids that contain URL characters", () => {
|
|
const link = formatThreadLink({
|
|
environmentId: "studio mac",
|
|
threadId: "mcp:(1)/2",
|
|
title: "Fix [the] build\nnow",
|
|
});
|
|
const href = /\]\((.+)\)$/.exec(link)![1]!;
|
|
expect(link.startsWith("[Fix the build now](")).toBe(true);
|
|
// A raw parenthesis would end the Markdown link early.
|
|
expect(href).not.toMatch(/[()]/);
|
|
expect(parseThreadLinkHref(href)).toEqual({
|
|
environmentId: "studio mac",
|
|
threadId: "mcp:(1)/2",
|
|
});
|
|
});
|
|
|
|
it("rejects other links and malformed ones", () => {
|
|
expect(parseThreadLinkHref("https://t3.codes")).toBeNull();
|
|
expect(parseThreadLinkHref("t3-thread://v1/only-one")).toBeNull();
|
|
expect(parseThreadLinkHref("t3-thread://v1/env/%E0%A4%A")).toBeNull();
|
|
expect(parseThreadLinkHref("t3-thread://v1/%20/thread")).toBeNull();
|
|
});
|
|
});
|