Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { formatThreadLink, parseThreadLinkHref } from "./threadLinks.ts";
4
5describe("thread links", () => {
6 it("round-trips ids that contain URL characters", () => {
7 const link = formatThreadLink({
8 environmentId: "studio mac",
9 threadId: "mcp:(1)/2",
10 title: "Fix [the] build\nnow",
11 });
12 const href = /\]\((.+)\)$/.exec(link)![1]!;
13 expect(link.startsWith("[Fix the build now](")).toBe(true);
14 // A raw parenthesis would end the Markdown link early.
15 expect(href).not.toMatch(/[()]/);
16 expect(parseThreadLinkHref(href)).toEqual({
17 environmentId: "studio mac",
18 threadId: "mcp:(1)/2",
19 });
20 });
21
22 it("rejects other links and malformed ones", () => {
23 expect(parseThreadLinkHref("https://t3.codes")).toBeNull();
24 expect(parseThreadLinkHref("t3-thread://v1/only-one")).toBeNull();
25 expect(parseThreadLinkHref("t3-thread://v1/env/%E0%A4%A")).toBeNull();
26 expect(parseThreadLinkHref("t3-thread://v1/%20/thread")).toBeNull();
27 });
28});