sidePaneTabPresentation.test.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // 侧栏 tab 总览(SidePaneTabOverview)的展示三件套:搜索提示、本地化标题、类型标签。
  2. // 新增 tab 类型漏掉这三处不会报错——getSidePaneTabTypeLabel 的兜底是 codeViewerTitle,
  3. // 于是一个 workflow run tab 会在总览里被标成「代码预览」。所以三处各钉一条。
  4. import { describe, expect, it } from "vitest";
  5. import {
  6. getLocalizedSidePaneTabTitle,
  7. getSidePaneTabSearchHint,
  8. getSidePaneTabTypeLabel,
  9. type SidePaneTabPresentationLabels,
  10. } from "@/app-shell/sidePaneTabPresentation.js";
  11. import type { WorkspaceSidePaneTab } from "@/lib/workspaceSidePane.js";
  12. const labels: SidePaneTabPresentationLabels = {
  13. browserTitle: "Browser",
  14. reviewTitle: "Review",
  15. codeViewerTitle: "Code preview",
  16. treemappingTitle: "Treemapping",
  17. whiteboardTitle: "Whiteboard",
  18. modelTrajectoryTitle: "Model trajectory",
  19. developerToolsTitle: "Developer tools",
  20. terminalTitle: "Terminal",
  21. subagentTypeLabel: "Subagent",
  22. subagentDirectoryTitle: "Subagents",
  23. selectionChatTitle: "Auxiliary conversation",
  24. planTitle: "Plan",
  25. workflowRunTitle: "Workflow run",
  26. workflowActorTitle: "Workflow subagent",
  27. workflowArtifactTitle: "Artifact",
  28. workflowScriptTitle: "Script steps",
  29. };
  30. const workflowActorTab: Extract<WorkspaceSidePaneTab, { type: "workflow-actor-session" }> = {
  31. id: "workflow-actor-session:%2Fworkspace:parent-a:dwf-dwfrun-1-actor_1%401",
  32. type: "workflow-actor-session",
  33. workspaceKey: "/workspace",
  34. workspacePath: "/workspace",
  35. parentSessionId: "parent-a",
  36. runId: "dwfrun-1",
  37. actorSessionId: "dwf-dwfrun-1-actor_1@1",
  38. siteId: "actor#1",
  39. ordinal: 2,
  40. actorName: "reviewer",
  41. };
  42. const workflowRunTab: Extract<WorkspaceSidePaneTab, { type: "workflow-run" }> = {
  43. id: "workflow-run:%2Fworkspace:parent-a:dwfrun-1",
  44. type: "workflow-run",
  45. workspaceKey: "/workspace",
  46. workspacePath: "/workspace",
  47. parentSessionId: "parent-a",
  48. toolCallId: "tool-wf-1",
  49. runId: "dwfrun-1",
  50. workflowName: "Three-way review",
  51. };
  52. // ⚠ 术语:这里的 artifact 是脚本经 `artifact.*` 交付给用户的产出(docs/dynamic-workflow/authoring.md
  53. // 的「术语」表),不是引擎内部那个「脚本顶层返回值」的同名词。
  54. const workflowArtifactTab: Extract<WorkspaceSidePaneTab, { type: "workflow-artifact" }> = {
  55. id: "workflow-artifact:%2Fworkspace:parent-a:dwfrun-1:book",
  56. type: "workflow-artifact",
  57. workspaceKey: "/workspace",
  58. workspacePath: "/workspace",
  59. parentSessionId: "parent-a",
  60. runId: "dwfrun-1",
  61. artifactId: "book",
  62. title: "审计报告",
  63. };
  64. describe("workflow-run tab presentation", () => {
  65. it("makes the run searchable by run id, tool call id and parent session", () => {
  66. const hint = getSidePaneTabSearchHint(workflowRunTab);
  67. expect(hint).toContain("dwfrun-1");
  68. expect(hint).toContain("tool-wf-1");
  69. expect(hint).toContain("parent-a");
  70. expect(hint).toContain("Three-way review");
  71. expect(hint).toContain("workflow");
  72. });
  73. it("labels the type as a workflow run rather than falling through to code preview", () => {
  74. expect(getSidePaneTabTypeLabel(workflowRunTab, labels)).toBe("Workflow run");
  75. expect(getSidePaneTabTypeLabel(workflowRunTab, labels)).not.toBe(labels.codeViewerTitle);
  76. });
  77. it("localizes the generic title but keeps a captured workflow name verbatim", () => {
  78. expect(getLocalizedSidePaneTabTitle(workflowRunTab, labels)).toBe("Three-way review");
  79. const { workflowName: _dropped, ...unnamed } = workflowRunTab;
  80. expect(getLocalizedSidePaneTabTitle(unnamed, labels)).toBe("Workflow run");
  81. });
  82. });
  83. describe("workflow-actor-session tab presentation", () => {
  84. it("makes the actor searchable by run, site, ordinal and session id", () => {
  85. const hint = getSidePaneTabSearchHint(workflowActorTab);
  86. expect(hint).toContain("dwfrun-1");
  87. expect(hint).toContain("actor#1");
  88. expect(hint).toContain("dwf-dwfrun-1-actor_1@1");
  89. expect(hint).toContain("parent-a");
  90. expect(hint).toContain("reviewer");
  91. expect(hint).toContain("workflow subagent actor transcript");
  92. });
  93. it("labels the type as a workflow actor rather than falling through to code preview", () => {
  94. expect(getSidePaneTabTypeLabel(workflowActorTab, labels)).toBe("Workflow subagent");
  95. expect(getSidePaneTabTypeLabel(workflowActorTab, labels)).not.toBe(labels.codeViewerTitle);
  96. // 也不能被标成 subagent:actor 会话不是子智能体的子会话,两者的回收语义都不同。
  97. expect(getSidePaneTabTypeLabel(workflowActorTab, labels)).not.toBe(labels.subagentTypeLabel);
  98. });
  99. it("keeps the script-authored actor name verbatim and always carries the instance ordinal", () => {
  100. // 车道显示名的约定:脚本里写下的名字原样显示。序号必须在标题里——同一车道族的两个
  101. // 实例名字相同,少了序号 tab 条上就是两个无法区分的「reviewer」。
  102. expect(getLocalizedSidePaneTabTitle(workflowActorTab, labels)).toBe("reviewer #2");
  103. const { actorName: _dropped, ...unnamed } = workflowActorTab;
  104. expect(getLocalizedSidePaneTabTitle(unnamed, labels)).toBe("Workflow subagent #2");
  105. });
  106. });
  107. describe("workflow-artifact tab presentation", () => {
  108. it("makes the artifact searchable by its id, run and parent session", () => {
  109. const hint = getSidePaneTabSearchHint(workflowArtifactTab);
  110. // 产物 id 是脚本里写死的字面量,排查者手里往往就是它。
  111. expect(hint).toContain("book");
  112. expect(hint).toContain("dwfrun-1");
  113. expect(hint).toContain("parent-a");
  114. expect(hint).toContain("审计报告");
  115. expect(hint).toContain("workflow artifact deliverable");
  116. });
  117. it("labels the type as an artifact rather than falling through to code preview", () => {
  118. expect(getSidePaneTabTypeLabel(workflowArtifactTab, labels)).toBe("Artifact");
  119. expect(getSidePaneTabTypeLabel(workflowArtifactTab, labels)).not.toBe(labels.codeViewerTitle);
  120. });
  121. it("keeps the captured title verbatim, then the artifact id, then the generic label", () => {
  122. expect(getLocalizedSidePaneTabTitle(workflowArtifactTab, labels)).toBe("审计报告");
  123. const { title: _dropped, ...untitled } = workflowArtifactTab;
  124. // 展示名是打开时冻结的兜底;身份始终是 (runId, artifactId),所以退回产物 id。
  125. expect(getLocalizedSidePaneTabTitle(untitled, labels)).toBe("book");
  126. expect(getLocalizedSidePaneTabTitle({ ...untitled, artifactId: "" }, labels)).toBe("Artifact");
  127. });
  128. });
  129. // 脚本 transcript(docs/dynamic-workflow/transcript-and-notifications.md「Opening the tab」):与 actor transcript
  130. // 同档的 run 内详情 tab;标题是 run 名,类型标签才说「Workflow workspace」。
  131. describe("workflow-workspace tab presentation", () => {
  132. const workflowWorkspaceTab: Extract<WorkspaceSidePaneTab, { type: "workflow-workspace" }> = {
  133. id: "workflow-workspace:%2Fworkspace:parent-a:dwfrun-1",
  134. type: "workflow-workspace",
  135. workspaceKey: "/workspace",
  136. workspacePath: "/workspace",
  137. parentSessionId: "parent-a",
  138. toolCallId: "tool-wf-1",
  139. runId: "dwfrun-1",
  140. workflowName: "Fan-out review",
  141. };
  142. it("makes the transcript searchable by run, tool call, parent session and the facade words", () => {
  143. const hint = getSidePaneTabSearchHint(workflowWorkspaceTab);
  144. expect(hint).toContain("dwfrun-1");
  145. expect(hint).toContain("tool-wf-1");
  146. expect(hint).toContain("parent-a");
  147. expect(hint).toContain("Fan-out review");
  148. expect(hint).toContain("workflow script steps workspace transcript files git run");
  149. });
  150. it("labels the type as a workflow workspace rather than falling through to code preview", () => {
  151. expect(getSidePaneTabTypeLabel(workflowWorkspaceTab, labels)).toBe("Script steps");
  152. expect(getSidePaneTabTypeLabel(workflowWorkspaceTab, labels)).not.toBe(labels.codeViewerTitle);
  153. expect(getSidePaneTabTypeLabel(workflowWorkspaceTab, labels)).not.toBe(labels.workflowRunTitle);
  154. });
  155. it("titles the tab with the run name and falls back to the generic label", () => {
  156. expect(getLocalizedSidePaneTabTitle(workflowWorkspaceTab, labels)).toBe("Fan-out review");
  157. const { workflowName: _dropped, ...unnamed } = workflowWorkspaceTab;
  158. expect(getLocalizedSidePaneTabTitle(unnamed, labels)).toBe("Script steps");
  159. });
  160. });