conversationShareReadonlyTimeline.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { beforeEach, describe, expect, it } from "vitest";
  4. import { ConversationShareReadonlyTimeline } from "@/v4/ConversationShareReadonlyTimeline.js";
  5. // SG-01 注入边界:时间线不再静态 import OpenSplitButton(避免 open-with 子树进公开页 bundle),
  6. // 改由消费方通过 artifactOpenAction 注入;测试用 stub 组件验证同一注入契约。
  7. const openActionProps: { values: Array<Record<string, unknown>> } = { values: [] };
  8. function StubArtifactOpenAction(props: Record<string, unknown>) {
  9. openActionProps.values.push(props);
  10. const target = props.target as
  11. | {
  12. path?: string;
  13. previewSource?: { workspacePath?: string };
  14. }
  15. | undefined;
  16. return createElement(
  17. "button",
  18. {
  19. type: "button",
  20. "data-open-split-button": "true",
  21. "data-target-path": target?.path ?? "",
  22. "data-preview-workspace": target?.previewSource?.workspacePath ?? "",
  23. },
  24. "Open",
  25. );
  26. }
  27. const rows = [
  28. {
  29. rowId: 1,
  30. turnId: "turn-1",
  31. productTurnId: "product-turn-1",
  32. createdAt: 1,
  33. createdAtSeq: 1,
  34. kind: "turnHeader" as const,
  35. origin: "userInput" as const,
  36. state: "completedSuccess" as const,
  37. startedAt: 1,
  38. },
  39. {
  40. rowId: 2,
  41. turnId: "turn-1",
  42. productTurnId: "product-turn-1",
  43. createdAt: 2,
  44. createdAtSeq: 2,
  45. kind: "userInput" as const,
  46. origin: "realUser" as const,
  47. text: "请总结今天的新闻",
  48. },
  49. {
  50. rowId: 3,
  51. turnId: "turn-1",
  52. productTurnId: "product-turn-1",
  53. createdAt: 3,
  54. createdAtSeq: 3,
  55. kind: "assistantText" as const,
  56. text: "这是 **摘要**",
  57. state: "complete" as const,
  58. },
  59. {
  60. rowId: 4,
  61. turnId: "turn-1",
  62. productTurnId: "product-turn-1",
  63. createdAt: 4,
  64. createdAtSeq: 4,
  65. kind: "toolCall" as const,
  66. toolCallId: "tool-1",
  67. toolName: "WebSearch",
  68. status: "success" as const,
  69. inputText: "query",
  70. output: { text: "result" },
  71. },
  72. ];
  73. const buildArtifactRow = (rowId: number, artifactVersionId: string) => ({
  74. rowId,
  75. turnId: "turn-1",
  76. productTurnId: "product-turn-1",
  77. createdAt: rowId,
  78. createdAtSeq: rowId,
  79. kind: "artifact" as const,
  80. artifactVersionId,
  81. logicalArtifactKey: "report",
  82. displayName: "晨报.pdf",
  83. artifactType: "pdf" as const,
  84. mimeType: "application/pdf",
  85. sizeBytes: 172_974,
  86. sha256: "a".repeat(64),
  87. ref: `zcode-artifact://share/${artifactVersionId}`,
  88. state: "current" as const,
  89. });
  90. describe("ConversationShareReadonlyTimeline", () => {
  91. beforeEach(() => {
  92. openActionProps.values = [];
  93. });
  94. it("uses Desktop user bubble, assistant markdown, turn grouping, and tool summary", () => {
  95. const html = renderToStaticMarkup(
  96. createElement(ConversationShareReadonlyTimeline, {
  97. rows,
  98. locale: "zh-CN",
  99. }),
  100. );
  101. expect(html).toContain('data-v4-user-input-bubble="true"');
  102. expect(html).toContain("这是");
  103. expect(html).toContain('data-conversation-share-turn="turn-1"');
  104. expect(html).toContain("搜索");
  105. expect(html).toContain("tool-summary");
  106. expect(html).not.toContain("<details");
  107. });
  108. it("renders shared user input attachments as downloadable file pills", () => {
  109. const attachmentRows = [
  110. rows[0],
  111. {
  112. ...rows[1],
  113. attachments: [
  114. {
  115. ref: "zcode-artifact://share/share-input-text-1",
  116. previewRef: "zcode-artifact://share/share-input-text-1",
  117. fileName: "pasted-text.txt",
  118. mime: "text/plain",
  119. bytes: 245_760,
  120. },
  121. ],
  122. },
  123. rows[2],
  124. ];
  125. const html = renderToStaticMarkup(
  126. createElement(ConversationShareReadonlyTimeline, {
  127. rows: attachmentRows,
  128. artifactUrls: new Map([
  129. ["share-input-text-1", "https://share.example.test/artifacts/text-1"],
  130. ]),
  131. locale: "en-US",
  132. }),
  133. );
  134. expect(html).toContain("pasted-text.txt");
  135. expect(html).toContain("https://share.example.test/artifacts/text-1");
  136. expect(html).toContain('data-v4-user-input-attachment-pill="true"');
  137. });
  138. it("keeps the user prompt before the history status and formats work duration like Desktop", () => {
  139. const historyRows = [
  140. {
  141. ...rows[0],
  142. activeMs: 165_000,
  143. },
  144. rows[1],
  145. {
  146. rowId: 7,
  147. turnId: "turn-1",
  148. productTurnId: "product-turn-1",
  149. createdAt: 7,
  150. createdAtSeq: 7,
  151. kind: "reasoning" as const,
  152. text: "先整理数据,再输出结论。",
  153. state: "complete" as const,
  154. durationMs: 2_000,
  155. },
  156. rows[2],
  157. ];
  158. const html = renderToStaticMarkup(
  159. createElement(ConversationShareReadonlyTimeline, {
  160. rows: historyRows,
  161. locale: "zh-CN",
  162. }),
  163. );
  164. expect(html.indexOf('data-v4-user-input-bubble="true"')).toBeLessThan(
  165. html.indexOf('data-conversation-share-history-trigger="true"'),
  166. );
  167. expect(html).toContain("已工作 2 分 45 秒");
  168. });
  169. it("renders headings and tables through the Desktop MessageResponse pipeline", () => {
  170. const markdownRows = [
  171. rows[0],
  172. rows[1],
  173. {
  174. ...rows[2],
  175. text: [
  176. "普通段落",
  177. "",
  178. "---",
  179. "",
  180. "# 标题",
  181. "",
  182. "## 二级标题",
  183. "",
  184. "| 项目 | 内容 |",
  185. "| --- | --- |",
  186. "| 公司 | **ZCode** |",
  187. "",
  188. "```ts",
  189. "const answer = 42;",
  190. "```",
  191. ].join("\n"),
  192. },
  193. ];
  194. const html = renderToStaticMarkup(
  195. createElement(ConversationShareReadonlyTimeline, {
  196. rows: markdownRows,
  197. locale: "zh-CN",
  198. }),
  199. );
  200. expect(html).toContain('data-streamdown="heading-1"');
  201. expect(html).toContain('data-streamdown="heading-2"');
  202. expect(html).toContain("<table");
  203. expect(html).toContain("data-markdown-table-toolbar");
  204. expect(html).not.toContain("# 标题");
  205. expect(html).not.toContain("| 项目 | 内容 |");
  206. });
  207. it("uses Desktop execute grouping for consecutive shell tool rows", () => {
  208. const executeRows = [
  209. rows[0],
  210. rows[1],
  211. rows[2],
  212. {
  213. rowId: 5,
  214. turnId: "turn-1",
  215. productTurnId: "product-turn-1",
  216. createdAt: 5,
  217. createdAtSeq: 5,
  218. kind: "toolCall" as const,
  219. toolCallId: "execute-1",
  220. toolName: "Bash",
  221. status: "success" as const,
  222. inputText: "echo one",
  223. input: { command: "echo one" },
  224. output: { text: "one" },
  225. },
  226. {
  227. rowId: 6,
  228. turnId: "turn-1",
  229. productTurnId: "product-turn-1",
  230. createdAt: 6,
  231. createdAtSeq: 6,
  232. kind: "toolCall" as const,
  233. toolCallId: "execute-2",
  234. toolName: "Bash",
  235. status: "success" as const,
  236. inputText: "echo two",
  237. input: { command: "echo two" },
  238. output: { text: "two" },
  239. },
  240. ];
  241. const html = renderToStaticMarkup(
  242. createElement(ConversationShareReadonlyTimeline, {
  243. rows: executeRows,
  244. locale: "zh-CN",
  245. }),
  246. );
  247. expect(html).toContain('data-conversation-share-work-group="executeGroup"');
  248. expect(html).toContain("2 个命令");
  249. expect(html).toContain("终端");
  250. });
  251. it("renders the public query summary for search rows", () => {
  252. const searchRows = [
  253. rows[0],
  254. rows[1],
  255. rows[2],
  256. {
  257. ...rows[3],
  258. input: { query: "AI coding" },
  259. },
  260. ];
  261. const html = renderToStaticMarkup(
  262. createElement(ConversationShareReadonlyTimeline, {
  263. rows: searchRows,
  264. locale: "zh-CN",
  265. }),
  266. );
  267. expect(html).toContain("AI coding");
  268. });
  269. it("marker 不再把枚举名当文案印出来", () => {
  270. // Bug 根因:原本直接渲染 row.marker.type,分享页会出现一条写着字面量 compact 的分割线。
  271. const markerRows = [
  272. rows[0],
  273. rows[1],
  274. {
  275. rowId: 90,
  276. turnId: "turn-1",
  277. productTurnId: "product-turn-1",
  278. createdAt: 90,
  279. createdAtSeq: 90,
  280. kind: "timelineMarker" as const,
  281. lane: "turnTailBoundary" as const,
  282. marker: { type: "compact" as const, origin: "auto" as const, status: "success" as const },
  283. },
  284. {
  285. rowId: 91,
  286. turnId: "turn-1",
  287. productTurnId: "product-turn-1",
  288. createdAt: 91,
  289. createdAtSeq: 91,
  290. kind: "timelineMarker" as const,
  291. lane: "turnTailBoundary" as const,
  292. marker: { type: "goalVerify" as const, iteration: 1, outcome: "pass" as const },
  293. },
  294. ];
  295. const html = renderToStaticMarkup(
  296. createElement(ConversationShareReadonlyTimeline, {
  297. rows: markerRows as never,
  298. locale: "zh-CN",
  299. }),
  300. );
  301. expect(html).toContain("上下文已压缩");
  302. expect(html).not.toContain(">compact<");
  303. // 识别不了的类型整行不渲染,而不是退化成打印枚举名。
  304. expect(html).not.toContain("goalVerify");
  305. });
  306. it("artifact 显示公开文件元数据与下载入口", () => {
  307. const artifactRows = [
  308. rows[0],
  309. rows[1],
  310. {
  311. rowId: 80,
  312. turnId: "turn-1",
  313. productTurnId: "product-turn-1",
  314. createdAt: 80,
  315. createdAtSeq: 80,
  316. kind: "artifact" as const,
  317. artifactVersionId: "artifact-1",
  318. logicalArtifactKey: "report",
  319. displayName: "晨报.pdf",
  320. artifactType: "pdf" as const,
  321. mimeType: "application/pdf",
  322. sizeBytes: 172_974,
  323. sha256: "a".repeat(64),
  324. ref: "zcode-artifact://share/artifact-1",
  325. state: "current" as const,
  326. },
  327. ];
  328. const html = renderToStaticMarkup(
  329. createElement(ConversationShareReadonlyTimeline, {
  330. rows: artifactRows as never,
  331. locale: "zh-CN",
  332. artifactUrls: new Map([["artifact-1", "https://example.invalid/a.pdf"]]),
  333. }),
  334. );
  335. // 副标题复用正文同一套词汇,并且不再直接印裸字节数。
  336. expect(html).toContain("文档 · PDF");
  337. expect(html).toContain("169 KB");
  338. expect(html).not.toContain("172974 bytes");
  339. expect(html).toContain('data-share-preview-button="true"');
  340. });
  341. it("为 Desktop 导入副本的本地 artifact 渲染 OpenSplitButton", () => {
  342. const artifactRows = [
  343. rows[0],
  344. rows[1],
  345. {
  346. rowId: 80,
  347. turnId: "turn-1",
  348. productTurnId: "product-turn-1",
  349. createdAt: 80,
  350. createdAtSeq: 80,
  351. kind: "artifact" as const,
  352. artifactVersionId: "artifact-1",
  353. logicalArtifactKey: "report",
  354. displayName: "晨报.pdf",
  355. artifactType: "pdf" as const,
  356. mimeType: "application/pdf",
  357. sizeBytes: 172_974,
  358. sha256: "a".repeat(64),
  359. ref: "zcode-artifact://share/artifact-1",
  360. state: "current" as const,
  361. },
  362. ];
  363. const html = renderToStaticMarkup(
  364. createElement(ConversationShareReadonlyTimeline, {
  365. rows: artifactRows as never,
  366. locale: "zh-CN",
  367. workspacePath: "/workspace",
  368. artifactWorkspaceRelativePaths: new Map([
  369. ["artifact-1", ".zcode-share/share-1/shared-artifacts/晨报.pdf"],
  370. ]),
  371. onOpenCodeViewer: () => undefined,
  372. artifactOpenAction: StubArtifactOpenAction,
  373. }),
  374. );
  375. expect(html).toContain('data-open-split-button="true"');
  376. expect(html).toContain(
  377. 'data-target-path="/workspace/.zcode-share/share-1/shared-artifacts/晨报.pdf"',
  378. );
  379. expect(openActionProps.values).toHaveLength(1);
  380. expect(openActionProps.values[0]?.target).toMatchObject({
  381. type: "file",
  382. path: "/workspace/.zcode-share/share-1/shared-artifacts/晨报.pdf",
  383. title: "晨报.pdf",
  384. label: "晨报.pdf",
  385. previewSource: {
  386. type: "file",
  387. title: "晨报.pdf",
  388. path: "/workspace/.zcode-share/share-1/shared-artifacts/晨报.pdf",
  389. workspacePath: "/workspace",
  390. },
  391. });
  392. });
  393. it("不注入 artifactOpenAction 时本地 artifact 不渲染任何打开控件", () => {
  394. // 与静态守卫(conversationShareBundleBoundary.test.ts)互补的运行时负例:公开页
  395. // (packages/web/src/share)不传 artifactOpenAction。锁住 ArtifactOpenContext 门控里的
  396. // !artifactOpenAction 条件——即使 workspacePath、合法相对路径、打开回调齐备,也必须
  397. // 退回纯只读卡片,防止后续加默认回退实现让公开页重新获得本地打开入口。
  398. const artifactRows = [rows[0], rows[1], buildArtifactRow(80, "artifact-1")];
  399. const html = renderToStaticMarkup(
  400. createElement(ConversationShareReadonlyTimeline, {
  401. rows: artifactRows as never,
  402. locale: "zh-CN",
  403. workspacePath: "/workspace",
  404. artifactWorkspaceRelativePaths: new Map([
  405. ["artifact-1", ".zcode-share/share-1/shared-artifacts/晨报.pdf"],
  406. ]),
  407. onOpenCodeViewer: () => undefined,
  408. }),
  409. );
  410. expect(html).toContain("晨报.pdf");
  411. expect(html).not.toContain('data-open-split-button="true"');
  412. expect(html).not.toContain('data-share-preview-button="true"');
  413. expect(openActionProps.values).toHaveLength(0);
  414. });
  415. it("拒绝导入副本里越界的 artifact path", () => {
  416. const artifactRows = [
  417. rows[0],
  418. rows[1],
  419. {
  420. rowId: 80,
  421. turnId: "turn-1",
  422. productTurnId: "product-turn-1",
  423. createdAt: 80,
  424. createdAtSeq: 80,
  425. kind: "artifact" as const,
  426. artifactVersionId: "artifact-1",
  427. logicalArtifactKey: "report",
  428. displayName: "晨报.pdf",
  429. artifactType: "pdf" as const,
  430. mimeType: "application/pdf",
  431. sizeBytes: 172_974,
  432. sha256: "a".repeat(64),
  433. ref: "zcode-artifact://share/artifact-1",
  434. state: "current" as const,
  435. },
  436. ];
  437. const html = renderToStaticMarkup(
  438. createElement(ConversationShareReadonlyTimeline, {
  439. rows: artifactRows as never,
  440. locale: "zh-CN",
  441. workspacePath: "/workspace",
  442. artifactWorkspaceRelativePaths: new Map([["artifact-1", "../secret.pdf"]]),
  443. onOpenCodeViewer: () => undefined,
  444. artifactOpenAction: StubArtifactOpenAction,
  445. }),
  446. );
  447. expect(html).toContain("晨报.pdf");
  448. expect(html).not.toContain('data-open-split-button="true"');
  449. expect(openActionProps.values).toHaveLength(0);
  450. });
  451. it("拒绝导入副本里的绝对路径 artifact path", () => {
  452. // 公开页隐私边界:posix / Windows 盘符 / UNC 三种绝对路径形态都必须退回纯只读卡片。
  453. const artifactRows = [
  454. rows[0],
  455. rows[1],
  456. buildArtifactRow(80, "artifact-1"),
  457. buildArtifactRow(81, "artifact-2"),
  458. buildArtifactRow(82, "artifact-3"),
  459. ];
  460. const html = renderToStaticMarkup(
  461. createElement(ConversationShareReadonlyTimeline, {
  462. rows: artifactRows as never,
  463. locale: "zh-CN",
  464. workspacePath: "/workspace",
  465. artifactWorkspaceRelativePaths: new Map([
  466. ["artifact-1", "/etc/passwd"],
  467. ["artifact-2", "C:\\x\\a.pdf"],
  468. ["artifact-3", "\\\\srv\\share\\a.pdf"],
  469. ]),
  470. onOpenCodeViewer: () => undefined,
  471. artifactOpenAction: StubArtifactOpenAction,
  472. }),
  473. );
  474. expect(html).toContain("晨报.pdf");
  475. expect(html).not.toContain('data-open-split-button="true"');
  476. expect(openActionProps.values).toHaveLength(0);
  477. });
  478. it("拒绝导入副本里段数不为 4 或含 ./.. 段的 artifact path", () => {
  479. // "../secret.pdf" 在段数校验就被拒了,这里专门补 4 段但段内含 .. 的逃逸形态。
  480. const artifactRows = [
  481. rows[0],
  482. rows[1],
  483. buildArtifactRow(80, "artifact-1"),
  484. buildArtifactRow(81, "artifact-2"),
  485. buildArtifactRow(82, "artifact-3"),
  486. buildArtifactRow(83, "artifact-4"),
  487. buildArtifactRow(84, "artifact-5"),
  488. ];
  489. const html = renderToStaticMarkup(
  490. createElement(ConversationShareReadonlyTimeline, {
  491. rows: artifactRows as never,
  492. locale: "zh-CN",
  493. workspacePath: "/workspace",
  494. artifactWorkspaceRelativePaths: new Map([
  495. // 嵌套子目录:5 段。
  496. ["artifact-1", ".zcode-share/share-1/shared-artifacts/sub/a.pdf"],
  497. // 浅路径:3 段。
  498. ["artifact-2", ".zcode-share/share-1/a.pdf"],
  499. // 4 段但第 2 段是 ..:等价于跳出本 share 目录。
  500. ["artifact-3", ".zcode-share/../shared-artifacts/a.pdf"],
  501. // 4 段但文件名是 .:不是合法产物文件。
  502. ["artifact-4", ".zcode-share/share-1/shared-artifacts/."],
  503. // 反斜杠分隔不能绕过段校验。
  504. ["artifact-5", ".zcode-share\\share-1\\shared-artifacts\\a.pdf\\..\\b.pdf"],
  505. ]),
  506. onOpenCodeViewer: () => undefined,
  507. artifactOpenAction: StubArtifactOpenAction,
  508. }),
  509. );
  510. expect(html).toContain("晨报.pdf");
  511. expect(html).not.toContain('data-open-split-button="true"');
  512. expect(openActionProps.values).toHaveLength(0);
  513. });
  514. it.each([
  515. ["zh-CN", "下载文件"],
  516. ["en-US", "Download file"],
  517. ])("artifactUrls 与本地路径同时存在时 url 必须胜出(%s)", (locale, label) => {
  518. // 公开页隐私边界的关键前提:ArtifactPresentation 只在 !url 时解析本地路径;
  519. // url 存在时必须渲染 window.open 按钮,而不是能触达本地文件服务的 OpenSplitButton。
  520. const artifactRows = [rows[0], rows[1], buildArtifactRow(80, "artifact-1")];
  521. const html = renderToStaticMarkup(
  522. createElement(ConversationShareReadonlyTimeline, {
  523. rows: artifactRows as never,
  524. locale,
  525. workspacePath: "/workspace",
  526. artifactUrls: new Map([["artifact-1", "https://example.invalid/a.pdf"]]),
  527. artifactWorkspaceRelativePaths: new Map([
  528. ["artifact-1", ".zcode-share/share-1/shared-artifacts/晨报.pdf"],
  529. ]),
  530. onOpenCodeViewer: () => undefined,
  531. artifactOpenAction: StubArtifactOpenAction,
  532. }),
  533. );
  534. // 资源 URL 实际下载文件,按钮文案必须对应下载,且注入的本地打开动作完全未挂载。
  535. expect(html).toContain(label);
  536. expect(html).not.toContain("预览文件");
  537. expect(html).not.toContain("Preview file");
  538. expect(html).toContain('data-share-preview-button="true"');
  539. expect(html).not.toContain('data-open-split-button="true"');
  540. expect(openActionProps.values).toHaveLength(0);
  541. });
  542. // Bug 回归:公开分享页不传 workspacePath/readAttachment,MarkdownImage 会 fallback 成
  543. // <img src={远程}>,匿名访客一打开就自动向第三方发请求(泄露 IP/UA/Referer)。
  544. // 正文与工具输出都必须只剩链接,不能出现自动加载的 <img>。
  545. it("不为正文与工具输出里的远程图片渲染自动加载的 img", () => {
  546. const remoteImageRows = [
  547. {
  548. rowId: 1,
  549. turnId: "turn-1",
  550. productTurnId: "product-turn-1",
  551. createdAt: 1,
  552. createdAtSeq: 1,
  553. kind: "turnHeader" as const,
  554. origin: "userInput" as const,
  555. state: "completedSuccess" as const,
  556. startedAt: 1,
  557. },
  558. {
  559. rowId: 2,
  560. turnId: "turn-1",
  561. productTurnId: "product-turn-1",
  562. createdAt: 2,
  563. createdAtSeq: 2,
  564. kind: "assistantText" as const,
  565. text: "看图 ![tracker](https://tracker.invalid/pixel.png)",
  566. state: "complete" as const,
  567. },
  568. {
  569. rowId: 3,
  570. turnId: "turn-1",
  571. productTurnId: "product-turn-1",
  572. createdAt: 3,
  573. createdAtSeq: 3,
  574. kind: "toolCall" as const,
  575. toolCallId: "tool-1",
  576. toolName: "WebSearch",
  577. status: "success" as const,
  578. inputText: "query",
  579. output: { text: "结果 ![tracker](https://tracker.invalid/tool.png)" },
  580. },
  581. ];
  582. const html = renderToStaticMarkup(
  583. createElement(ConversationShareReadonlyTimeline, {
  584. rows: remoteImageRows as never,
  585. locale: "zh-CN",
  586. }),
  587. );
  588. // 关键不是 URL 是否出现在 HTML 里(链接的 title 属性带着它无害),
  589. // 而是不能有任何自动发起请求的 <img src>。
  590. expect(html).not.toContain("<img");
  591. expect(html).not.toContain('src="https://tracker.invalid');
  592. // 信息不丢:降级成外链后 URL 仍可被访客显式点击。
  593. expect(html).toContain('title="https://tracker.invalid/pixel.png"');
  594. expect(html).toContain("tracker");
  595. });
  596. });
  597. it("分享页展示 workflow 静态图,不需要桌面宿主或执行回调", () => {
  598. const html = renderToStaticMarkup(
  599. createElement(ConversationShareReadonlyTimeline, {
  600. locale: "zh-CN",
  601. rows: [
  602. ...rows,
  603. {
  604. rowId: 5,
  605. turnId: "turn-1",
  606. productTurnId: "product-turn-1",
  607. createdAt: 5,
  608. createdAtSeq: 5,
  609. kind: "toolCall",
  610. toolCallId: "workflow-test",
  611. toolName: "CreateWorkflow",
  612. status: "success",
  613. inputText: "{}",
  614. input: { name: "调研工作流" },
  615. display: {
  616. kind: "create_workflow",
  617. ok: true,
  618. errorCount: 0,
  619. diagnostics: [],
  620. causalityGraph: {
  621. steps: [{ id: "s", kind: "ask", label: "检索", lane: "l", phase: "p" }],
  622. lanes: [{ id: "l", name: "研究员" }],
  623. participants: [{ id: "a", phase: "p", lane: "l", steps: ["s"] }],
  624. handoffs: [],
  625. phases: [{ id: "p", name: "调研阶段" }],
  626. phaseEdges: [],
  627. exits: ["p"],
  628. },
  629. },
  630. },
  631. ],
  632. }),
  633. );
  634. expect(html).toContain("调研工作流");
  635. expect(html).toContain("调研阶段");
  636. expect(html).toContain("研究员");
  637. expect(html).toContain("工具调用时的快照");
  638. expect(html).not.toContain('data-testid="workflow-card-resume"');
  639. });