messageResponseStreamdownMode.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import {
  5. buildMessageFileLinkTarget,
  6. buildMessageStreamdownRenderKey,
  7. messageResponsePropsAreEqual,
  8. MessageResponse,
  9. openMessageFileLinkInEditor,
  10. resolveMessageStreamdownMode,
  11. } from "@/components/ai-elements/message.js";
  12. import { TooltipProvider } from "@/components/ui/tooltip.js";
  13. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  14. vi.mock("@/store/StoreProvider.js", () => ({
  15. useZCodeStore: (selector: (state: unknown) => unknown) =>
  16. selector({
  17. codePreviewSettings: {
  18. darkTheme: "github-dark",
  19. fontSizePx: 13,
  20. lightTheme: "github-light",
  21. wrapLongLines: true,
  22. },
  23. theme: "zai-light",
  24. }),
  25. }));
  26. vi.mock("@/hooks/usePlatform.js", () => ({
  27. usePlatform: () => ({
  28. getInstalledEditors: vi.fn().mockResolvedValue([]),
  29. openInEditor: vi.fn().mockResolvedValue({ success: true }),
  30. openInFileManager: vi.fn().mockResolvedValue({ success: true }),
  31. }),
  32. useOptionalPlatform: () => ({
  33. getInstalledEditors: vi.fn().mockResolvedValue([]),
  34. openInEditor: vi.fn().mockResolvedValue({ success: true }),
  35. openInFileManager: vi.fn().mockResolvedValue({ success: true }),
  36. }),
  37. }));
  38. describe("resolveMessageStreamdownMode", () => {
  39. it("invalidates memoized artifact images when their session or reader changes", () => {
  40. const readAttachment = vi.fn();
  41. const base = {
  42. children: "![CUA](zcode-artifact://session-1/shot)",
  43. sessionId: "session-1",
  44. readAttachment,
  45. };
  46. expect(messageResponsePropsAreEqual(base, base)).toBe(true);
  47. expect(messageResponsePropsAreEqual(base, { ...base, sessionId: "session-2" })).toBe(false);
  48. expect(messageResponsePropsAreEqual(base, { ...base, readAttachment: vi.fn() })).toBe(false);
  49. });
  50. it("保留 Markdown 目录链接的 pathKind 和远程 workspace scope", () => {
  51. expect(
  52. buildMessageFileLinkTarget({
  53. href: "./src/",
  54. label: "src",
  55. path: "/workspace/repo/src/",
  56. workspacePath: "/workspace/repo",
  57. workspaceIdentity: "remote:wsl:Ubuntu:/workspace/repo",
  58. workspaceRemoteSessionId: "wsl-session",
  59. }),
  60. ).toEqual({
  61. path: "/workspace/repo/src/",
  62. label: "src",
  63. pathKind: "directory",
  64. relativePath: "src",
  65. workspacePath: "/workspace/repo",
  66. workspaceIdentity: "remote:wsl:Ubuntu:/workspace/repo",
  67. workspaceRemoteSessionId: "wsl-session",
  68. });
  69. });
  70. it.each([
  71. ["./src/App.tsx", "/workspace/repo/src/App.tsx"],
  72. ["./config", "/workspace/repo/config"],
  73. ["/etc/hosts", "/etc/hosts"],
  74. ])("Markdown 文件链接 %s 不在渲染阶段猜测文件系统类型", (href, path) => {
  75. expect(
  76. buildMessageFileLinkTarget({
  77. href,
  78. label: "file",
  79. path,
  80. workspacePath: "/workspace/repo",
  81. }).pathKind,
  82. ).toBeUndefined();
  83. });
  84. it.each(["file", "directory"] as const)(
  85. "Markdown 打开方式通过 workspace stat 传递真实 %s 类型",
  86. async (type) => {
  87. const statFile = vi.fn().mockResolvedValue({ type });
  88. const openInEditor = vi.fn().mockResolvedValue({ success: true });
  89. const fileLink = buildMessageFileLinkTarget({
  90. href: "./config",
  91. label: "config",
  92. path: "/workspace/repo/config",
  93. workspacePath: "/workspace/repo",
  94. workspaceIdentity: "remote:wsl:Ubuntu:/workspace/repo",
  95. });
  96. const remoteTarget = { kind: "wsl" as const, distro: "Ubuntu" };
  97. await expect(
  98. openMessageFileLinkInEditor({
  99. editorId: "vscode",
  100. fileLink,
  101. openInEditor,
  102. remoteTarget,
  103. statFile,
  104. }),
  105. ).resolves.toEqual({ success: true });
  106. expect(statFile).toHaveBeenCalledWith({ path: "/workspace/repo/config" });
  107. expect(openInEditor).toHaveBeenCalledWith("vscode", "/workspace/repo/config", {
  108. pathKind: type,
  109. remoteTarget,
  110. workspaceIdentity: "remote:wsl:Ubuntu:/workspace/repo",
  111. });
  112. },
  113. );
  114. it("Markdown 打开方式 stat 失败时不调用本机编辑器", async () => {
  115. const statFile = vi.fn().mockRejectedValue(new Error("path not found"));
  116. const openInEditor = vi.fn();
  117. const fileLink = buildMessageFileLinkTarget({
  118. href: "./config",
  119. label: "config",
  120. path: "/workspace/repo/config",
  121. workspacePath: "/workspace/repo",
  122. });
  123. await expect(
  124. openMessageFileLinkInEditor({
  125. editorId: "vscode",
  126. fileLink,
  127. openInEditor,
  128. statFile,
  129. }),
  130. ).rejects.toThrow("path not found");
  131. expect(openInEditor).not.toHaveBeenCalled();
  132. });
  133. it("越界相对 Markdown 链接不生成可点击文件操作目标", () => {
  134. const html = renderToStaticMarkup(
  135. createElement(
  136. MessageResponse,
  137. {
  138. workspacePath: "/workspace",
  139. onOpenFileLink: vi.fn(),
  140. },
  141. "[private](foo/../../private.pdf)",
  142. ),
  143. );
  144. expect(html).toContain("private");
  145. expect(html).not.toContain("/workspace/foo/../../private.pdf");
  146. expect(html).not.toContain("cursor-pointer");
  147. });
  148. it("Assistant citation 使用现有文件链接渲染,普通文件名仍保持原文", () => {
  149. const html = renderToStaticMarkup(
  150. createElement(
  151. ZCodeIntlProvider,
  152. { initialLocale: "zh-CN" },
  153. createElement(
  154. MessageResponse,
  155. {
  156. renderZCodeFileCitations: true,
  157. workspacePath: "/workspace",
  158. onOpenFileLink: vi.fn(),
  159. },
  160. [
  161. "普通文件 report.pdf。",
  162. ':zcode-file-citation{path="docs/年度 报告.pdf" purpose="output" page_number=2}',
  163. ':::zcode-file-citation{path="docs/论文.pdf" purpose="source"}',
  164. ].join("\n\n"),
  165. ),
  166. ),
  167. );
  168. expect(html).toContain("普通文件 report.pdf");
  169. expect(html).not.toContain(":zcode-file-citation");
  170. expect(html).toContain("<button");
  171. expect(html).toContain('title="/workspace/docs/年度 报告.pdf"');
  172. expect(html).toContain('title="/workspace/docs/论文.pdf"');
  173. expect(html).toContain("年度 报告.pdf");
  174. });
  175. it("citation 和 Markdown 文件链接支持智能引号且不污染路径", () => {
  176. const html = renderToStaticMarkup(
  177. createElement(
  178. ZCodeIntlProvider,
  179. { initialLocale: "zh-CN" },
  180. createElement(
  181. MessageResponse,
  182. {
  183. renderZCodeFileCitations: true,
  184. workspacePath: "/workspace",
  185. onOpenFileLink: vi.fn(),
  186. },
  187. [
  188. '规划完成。已生成 ::zcode-file-citation{path=“/workspace/冰岛 行程.pdf” purpose="output"}',
  189. "[说明](‘docs/说明.md’)",
  190. ].join("\n\n"),
  191. ),
  192. ),
  193. );
  194. expect(html).toContain('title="/workspace/冰岛 行程.pdf"');
  195. expect(html).toContain('title="/workspace/docs/说明.md"');
  196. expect(html).not.toContain("/workspace/“");
  197. expect(html).not.toContain("说明.md’");
  198. expect(html).not.toContain("[blocked]");
  199. });
  200. it("streaming 时隐藏未闭合 citation,异常换行后的正文仍可见", () => {
  201. const html = renderToStaticMarkup(
  202. createElement(
  203. ZCodeIntlProvider,
  204. { initialLocale: "zh-CN" },
  205. createElement(
  206. MessageResponse,
  207. {
  208. renderZCodeFileCitations: true,
  209. streaming: true,
  210. workspacePath: "/workspace",
  211. onOpenFileLink: vi.fn(),
  212. },
  213. '正文\n::zcode-file-citation{path="docs/report.pdf"',
  214. ),
  215. ),
  216. );
  217. expect(html).toContain("正文");
  218. expect(html).not.toContain("::zcode-file-citation");
  219. const malformedHtml = renderToStaticMarkup(
  220. createElement(
  221. ZCodeIntlProvider,
  222. { initialLocale: "zh-CN" },
  223. createElement(
  224. MessageResponse,
  225. {
  226. renderZCodeFileCitations: true,
  227. streaming: true,
  228. workspacePath: "/workspace",
  229. onOpenFileLink: vi.fn(),
  230. },
  231. '正文\n::zcode-file-citation{path="docs/report.pdf"\n后续说明仍然可见',
  232. ),
  233. ),
  234. );
  235. expect(malformedHtml).toContain("后续说明仍然可见");
  236. });
  237. it.each([
  238. ["盘符路径", String.raw`C:\Users\demo\年度 报告.pdf`, "C:/Users/demo/年度 报告.pdf"],
  239. ["Windows file URL", "file:///C:/Users/demo/report.pdf", "C:/Users/demo/report.pdf"],
  240. ])("Assistant citation 的 Windows %s 通过 harden 后仍可点击", (_case, path, resolvedPath) => {
  241. const html = renderToStaticMarkup(
  242. createElement(
  243. ZCodeIntlProvider,
  244. { initialLocale: "zh-CN" },
  245. createElement(
  246. MessageResponse,
  247. {
  248. renderZCodeFileCitations: true,
  249. workspacePath: "C:\\workspace",
  250. onOpenFileLink: vi.fn(),
  251. },
  252. `::zcode-file-citation{path="${path}" purpose="output"}`,
  253. ),
  254. ),
  255. );
  256. expect(html).not.toContain("[blocked]");
  257. expect(html).toContain("<button");
  258. expect(html).toContain(`title="${resolvedPath}"`);
  259. });
  260. it("越界 citation 保持原文且不生成文件链接", () => {
  261. const directive = '::zcode-file-citation{path="foo/../../private.pdf"}';
  262. const html = renderToStaticMarkup(
  263. createElement(
  264. MessageResponse,
  265. {
  266. renderZCodeFileCitations: true,
  267. workspacePath: "/workspace",
  268. onOpenFileLink: vi.fn(),
  269. },
  270. directive,
  271. ),
  272. );
  273. expect(html).toContain("::zcode-file-citation");
  274. expect(html).not.toContain('title="/workspace/foo/../../private.pdf"');
  275. });
  276. it("citation 不解析代码节点,并保留 Streamdown 默认 GFM 表格", () => {
  277. const directive = '::zcode-file-citation{path="docs/report.pdf"}';
  278. const compatibilityDirective = ':zcode-file-citation{path="docs/legacy.pdf"}';
  279. const html = renderToStaticMarkup(
  280. createElement(
  281. ZCodeIntlProvider,
  282. { initialLocale: "zh-CN" },
  283. createElement(
  284. TooltipProvider,
  285. null,
  286. createElement(
  287. MessageResponse,
  288. {
  289. renderZCodeFileCitations: true,
  290. workspacePath: "/workspace",
  291. onOpenFileLink: vi.fn(),
  292. },
  293. [
  294. `\`${directive}\``,
  295. `\`${compatibilityDirective}\``,
  296. "",
  297. "| 文件 | 状态 |",
  298. "| --- | --- |",
  299. "| report.pdf | 完成 |",
  300. ].join("\n"),
  301. ),
  302. ),
  303. ),
  304. );
  305. expect(html).toContain("::zcode-file-citation");
  306. expect(html).toContain(":zcode-file-citation");
  307. expect(html).toContain("<table");
  308. expect(html).not.toContain('title="/workspace/docs/report.pdf"');
  309. expect(html).not.toContain('title="/workspace/docs/legacy.pdf"');
  310. });
  311. it.each([
  312. ["盘符正斜杠", "[报告](C:/Users/demo/report.md)", "C:/Users/demo/report.md"],
  313. ["盘符反斜杠", String.raw`[报告](C:\Users\demo\report.md)`, "C:/Users/demo/report.md"],
  314. ["Windows file URL", "[报告](file:///C:/Users/demo/report.md)", "C:/Users/demo/report.md"],
  315. [
  316. "中文空格路径",
  317. "[报告](<C:/Users/demo/中文 目录/report.md>)",
  318. "C:/Users/demo/中文 目录/report.md",
  319. ],
  320. ])("Windows 绝对 Markdown 链接(%s)通过 harden 后仍可点击", (_case, markdown, path) => {
  321. const html = renderToStaticMarkup(
  322. createElement(
  323. ZCodeIntlProvider,
  324. { initialLocale: "zh-CN" },
  325. createElement(
  326. MessageResponse,
  327. {
  328. workspacePath: "C:\\workspace",
  329. onOpenFileLink: vi.fn(),
  330. },
  331. markdown,
  332. ),
  333. ),
  334. );
  335. expect(html).not.toContain("[blocked]");
  336. expect(html).toContain("<button");
  337. expect(html).toContain(`title="${path}"`);
  338. });
  339. it("UNC workspace 中 Windows 绝对 Markdown 链接通过 harden 后仍可点击", () => {
  340. const html = renderToStaticMarkup(
  341. createElement(
  342. ZCodeIntlProvider,
  343. { initialLocale: "zh-CN" },
  344. createElement(
  345. MessageResponse,
  346. {
  347. workspacePath: "\\\\server\\share\\repo",
  348. onOpenFileLink: vi.fn(),
  349. },
  350. "[报告](C:/Users/demo/report.md)",
  351. ),
  352. ),
  353. );
  354. expect(html).not.toContain("[blocked]");
  355. expect(html).toContain("<button");
  356. expect(html).toContain('title="C:/Users/demo/report.md"');
  357. });
  358. it.each([
  359. ["盘符正斜杠", "![截图](C:/Users/demo/screenshot.png)"],
  360. ["盘符反斜杠", String.raw`![截图](C:\Users\demo\screenshot.png)`],
  361. ["Windows file URL", "![截图](file:///C:/Users/demo/screenshot.png)"],
  362. ])("Windows 绝对 Markdown 图片(%s)通过 harden 后保留本地路径", (_case, markdown) => {
  363. const html = renderToStaticMarkup(
  364. createElement(
  365. ZCodeIntlProvider,
  366. { initialLocale: "zh-CN" },
  367. createElement(MessageResponse, { workspacePath: "C:\\workspace" }, markdown),
  368. ),
  369. );
  370. expect(html).not.toContain("[blocked]");
  371. expect(html).toContain('data-markdown-local-image="loading"');
  372. expect(html).toContain('title="C:/Users/demo/screenshot.png"');
  373. });
  374. it("UNC workspace 中 Windows 绝对 Markdown 图片通过 harden 后保留本地路径", () => {
  375. const html = renderToStaticMarkup(
  376. createElement(
  377. ZCodeIntlProvider,
  378. { initialLocale: "zh-CN" },
  379. createElement(
  380. MessageResponse,
  381. { workspacePath: "\\\\server\\share\\repo" },
  382. "![截图](C:/Users/demo/screenshot.png)",
  383. ),
  384. ),
  385. );
  386. expect(html).not.toContain("[blocked]");
  387. expect(html).toContain('data-markdown-local-image="loading"');
  388. expect(html).toContain('title="C:/Users/demo/screenshot.png"');
  389. });
  390. it("正文裸文件名保持普通文本且 GFM 表格正常渲染", () => {
  391. const html = renderToStaticMarkup(
  392. createElement(
  393. ZCodeIntlProvider,
  394. { initialLocale: "zh-CN" },
  395. createElement(
  396. TooltipProvider,
  397. null,
  398. createElement(
  399. MessageResponse,
  400. {
  401. workspacePath: "/workspace",
  402. },
  403. [
  404. "| 项 | 状态 |",
  405. "| --- | --- |",
  406. "| Word 文档 | ✅ |",
  407. "",
  408. "已生成 report.docx。",
  409. ].join("\n"),
  410. ),
  411. ),
  412. ),
  413. );
  414. expect(html).toContain("<table");
  415. expect(html).toContain("已生成 report.docx。");
  416. expect(html).not.toMatch(/title="[^"]*report\.docx"/);
  417. });
  418. it.each([false, true])("仅双波浪线渲染删除线(streaming=%s)", (streaming) => {
  419. const html = renderToStaticMarkup(
  420. createElement(
  421. MessageResponse,
  422. { streaming, workspacePath: "/workspace" },
  423. "~单波浪线~ 与 ~~双波浪线。~~后续文字",
  424. ),
  425. );
  426. expect(html).toContain("~单波浪线~");
  427. expect(html).not.toContain("<del>单波浪线</del>");
  428. expect(html).toContain("<del>双波浪线。</del>后续文字");
  429. });
  430. it("keeps completed messages on Streamdown static mode", () => {
  431. expect(resolveMessageStreamdownMode(false)).toBe("static");
  432. });
  433. it("uses Streamdown streaming mode only while the message is actively streaming", () => {
  434. expect(resolveMessageStreamdownMode(true)).toBe("streaming");
  435. });
  436. it("changes the Streamdown render key when code block rendering settings change", () => {
  437. const base = buildMessageStreamdownRenderKey({
  438. codeBlockTheme: "github-light",
  439. fontSizePx: 12,
  440. workspacePath: "/workspace",
  441. wrapLongLines: false,
  442. });
  443. expect(
  444. buildMessageStreamdownRenderKey({
  445. codeBlockTheme: "github-dark",
  446. fontSizePx: 12,
  447. workspacePath: "/workspace",
  448. wrapLongLines: false,
  449. }),
  450. ).not.toBe(base);
  451. expect(
  452. buildMessageStreamdownRenderKey({
  453. codeBlockTheme: "github-light",
  454. fontSizePx: 13,
  455. workspacePath: "/workspace",
  456. wrapLongLines: false,
  457. }),
  458. ).not.toBe(base);
  459. expect(
  460. buildMessageStreamdownRenderKey({
  461. codeBlockTheme: "github-light",
  462. fontSizePx: 12,
  463. workspacePath: "/workspace",
  464. wrapLongLines: true,
  465. }),
  466. ).not.toBe(base);
  467. });
  468. it("changes the Streamdown render key with artifact permission context", () => {
  469. const base = buildMessageStreamdownRenderKey({
  470. attachmentReaderEpoch: 1,
  471. codeBlockTheme: "github-light",
  472. fontSizePx: 12,
  473. sessionId: "session-a",
  474. workspacePath: "/workspace",
  475. wrapLongLines: false,
  476. });
  477. expect(
  478. buildMessageStreamdownRenderKey({
  479. attachmentReaderEpoch: 1,
  480. codeBlockTheme: "github-light",
  481. fontSizePx: 12,
  482. sessionId: "session-b",
  483. workspacePath: "/workspace",
  484. wrapLongLines: false,
  485. }),
  486. ).not.toBe(base);
  487. expect(
  488. buildMessageStreamdownRenderKey({
  489. attachmentReaderEpoch: 2,
  490. codeBlockTheme: "github-light",
  491. fontSizePx: 12,
  492. sessionId: "session-a",
  493. workspacePath: "/workspace",
  494. wrapLongLines: false,
  495. }),
  496. ).not.toBe(base);
  497. });
  498. it("renders single-dollar inline math as KaTeX", () => {
  499. const html = renderToStaticMarkup(
  500. createElement(
  501. MessageResponse,
  502. { workspacePath: "/workspace" },
  503. "其中 $c(\\mathbf{r})$ 是声速,$\\omega=2\\pi f$ 是角频率。",
  504. ),
  505. );
  506. expect(html).toContain("katex");
  507. expect(html).not.toContain("$c(\\mathbf{r})$");
  508. expect(html).not.toContain("$\\omega=2\\pi f$");
  509. });
  510. it("rewrites assistant artifact images before Streamdown hardening", () => {
  511. const html = renderToStaticMarkup(
  512. createElement(
  513. ZCodeIntlProvider,
  514. { initialLocale: "zh-CN" },
  515. createElement(
  516. MessageResponse,
  517. {
  518. workspacePath: "/workspace",
  519. sessionId: "session-1",
  520. readAttachment: async () => ({
  521. bytes: new Uint8Array([1]),
  522. mediaType: "image/png",
  523. }),
  524. },
  525. "![CUA](zcode-artifact://session-1/shot)",
  526. ),
  527. ),
  528. );
  529. expect(html).toContain('data-markdown-local-image="loading"');
  530. expect(html).not.toContain("Image blocked");
  531. expect(html).not.toContain("zcode-artifact://");
  532. });
  533. it("keeps paired currency dollars as text", () => {
  534. const html = renderToStaticMarkup(
  535. createElement(
  536. MessageResponse,
  537. { workspacePath: "/workspace" },
  538. "Pricing is $5 today and $10 tomorrow.",
  539. ),
  540. );
  541. expect(html).not.toContain("katex");
  542. expect(html).toContain("Pricing is $5 today and $10 tomorrow.");
  543. });
  544. it("keeps compact currency ranges as text", () => {
  545. const html = renderToStaticMarkup(
  546. createElement(
  547. MessageResponse,
  548. { workspacePath: "/workspace" },
  549. "Pricing is $5-$10 depending on usage.",
  550. ),
  551. );
  552. expect(html).not.toContain("katex");
  553. expect(html).toContain("Pricing is $5-$10 depending on usage.");
  554. });
  555. it("keeps paired shell environment dollars as text", () => {
  556. const html = renderToStaticMarkup(
  557. createElement(
  558. MessageResponse,
  559. { workspacePath: "/workspace" },
  560. "Use $HOME and $PATH to inspect environment variables.",
  561. ),
  562. );
  563. expect(html).not.toContain("katex");
  564. expect(html).toContain("Use $HOME and $PATH to inspect environment variables.");
  565. });
  566. });
  567. it("通用模式回答保留代码容器和复制入口,锁定换行入口且模式变化会重新渲染", () => {
  568. const codePreviewSettings = {
  569. darkTheme: "github-dark",
  570. lightTheme: "github-light",
  571. fontSizePx: 13,
  572. wrapLongLines: false,
  573. };
  574. const props = { children: "```python\nprint('MODE_CODE_RETAINED')\n```", codePreviewSettings };
  575. const render = (forceCodeWrap: boolean) =>
  576. renderToStaticMarkup(
  577. createElement(
  578. ZCodeIntlProvider,
  579. { initialLocale: "zh-CN" },
  580. createElement(
  581. TooltipProvider,
  582. null,
  583. createElement(MessageResponse, { ...props, forceCodeWrap }),
  584. ),
  585. ),
  586. );
  587. const general = render(true);
  588. expect(general).toContain('data-language="python"');
  589. expect(general).toContain("复制代码");
  590. expect(general).not.toContain("自动换行");
  591. expect(render(false)).toContain("自动换行");
  592. expect(codePreviewSettings.wrapLongLines).toBe(false);
  593. expect(
  594. messageResponsePropsAreEqual(
  595. { ...props, forceCodeWrap: true },
  596. { ...props, forceCodeWrap: false },
  597. ),
  598. ).toBe(false);
  599. });