sidePaneTabPresentation.test.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. pluginMarketTitle: "Plugins",
  21. terminalTitle: "Terminal",
  22. subagentTypeLabel: "Subagent",
  23. subagentDirectoryTitle: "Subagents",
  24. selectionChatTitle: "Auxiliary conversation",
  25. planTitle: "Plan",
  26. workflowRunTitle: "Workflow run",
  27. workflowActorTitle: "Workflow subagent",
  28. workflowArtifactTitle: "Artifact",
  29. workflowScriptTitle: "Script steps",
  30. };
  31. const workflowActorTab: Extract<WorkspaceSidePaneTab, { type: "workflow-actor-session" }> = {
  32. id: "workflow-actor-session:%2Fworkspace:parent-a:dwf-dwfrun-1-actor_1%401",
  33. type: "workflow-actor-session",
  34. workspaceKey: "/workspace",
  35. workspacePath: "/workspace",
  36. parentSessionId: "parent-a",
  37. runId: "dwfrun-1",
  38. actorSessionId: "dwf-dwfrun-1-actor_1@1",
  39. siteId: "actor#1",
  40. ordinal: 2,
  41. actorName: "reviewer",
  42. };
  43. const workflowRunTab: Extract<WorkspaceSidePaneTab, { type: "workflow-run" }> = {
  44. id: "workflow-run:%2Fworkspace:parent-a:dwfrun-1",
  45. type: "workflow-run",
  46. workspaceKey: "/workspace",
  47. workspacePath: "/workspace",
  48. parentSessionId: "parent-a",
  49. toolCallId: "tool-wf-1",
  50. runId: "dwfrun-1",
  51. workflowName: "Three-way review",
  52. };
  53. // ⚠ 术语:这里的 artifact 是脚本经 `artifact.*` 交付给用户的产出(docs/dynamic-workflow/authoring.md
  54. // 的「术语」表),不是引擎内部那个「脚本顶层返回值」的同名词。
  55. const workflowArtifactTab: Extract<WorkspaceSidePaneTab, { type: "workflow-artifact" }> = {
  56. id: "workflow-artifact:%2Fworkspace:parent-a:dwfrun-1:book",
  57. type: "workflow-artifact",
  58. workspaceKey: "/workspace",
  59. workspacePath: "/workspace",
  60. parentSessionId: "parent-a",
  61. runId: "dwfrun-1",
  62. artifactId: "book",
  63. title: "审计报告",
  64. };
  65. describe("workflow-run tab presentation", () => {
  66. it("makes the run searchable by run id, tool call id and parent session", () => {
  67. const hint = getSidePaneTabSearchHint(workflowRunTab);
  68. expect(hint).toContain("dwfrun-1");
  69. expect(hint).toContain("tool-wf-1");
  70. expect(hint).toContain("parent-a");
  71. expect(hint).toContain("Three-way review");
  72. expect(hint).toContain("workflow");
  73. });
  74. it("labels the type as a workflow run rather than falling through to code preview", () => {
  75. expect(getSidePaneTabTypeLabel(workflowRunTab, labels)).toBe("Workflow run");
  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. });
  96. it("keeps the script-authored actor name verbatim and always carries the instance ordinal", () => {
  97. // 车道显示名的约定:脚本里写下的名字原样显示。序号必须在标题里——同一车道族的两个
  98. // 实例名字相同,少了序号 tab 条上就是两个无法区分的「reviewer」。
  99. expect(getLocalizedSidePaneTabTitle(workflowActorTab, labels)).toBe("reviewer #2");
  100. const { actorName: _dropped, ...unnamed } = workflowActorTab;
  101. expect(getLocalizedSidePaneTabTitle(unnamed, labels)).toBe("Workflow subagent #2");
  102. });
  103. });
  104. describe("workflow-artifact tab presentation", () => {
  105. it("makes the artifact searchable by its id, run and parent session", () => {
  106. const hint = getSidePaneTabSearchHint(workflowArtifactTab);
  107. // 产物 id 是脚本里写死的字面量,排查者手里往往就是它。
  108. expect(hint).toContain("book");
  109. expect(hint).toContain("dwfrun-1");
  110. expect(hint).toContain("parent-a");
  111. expect(hint).toContain("审计报告");
  112. expect(hint).toContain("workflow artifact deliverable");
  113. });
  114. it("labels the type as an artifact rather than falling through to code preview", () => {
  115. expect(getSidePaneTabTypeLabel(workflowArtifactTab, labels)).toBe("Artifact");
  116. });
  117. it("keeps the captured title verbatim, then the artifact id, then the generic label", () => {
  118. expect(getLocalizedSidePaneTabTitle(workflowArtifactTab, labels)).toBe("审计报告");
  119. const { title: _dropped, ...untitled } = workflowArtifactTab;
  120. // 展示名是打开时冻结的兜底;身份始终是 (runId, artifactId),所以退回产物 id。
  121. expect(getLocalizedSidePaneTabTitle(untitled, labels)).toBe("book");
  122. expect(getLocalizedSidePaneTabTitle({ ...untitled, artifactId: "" }, labels)).toBe("Artifact");
  123. });
  124. });
  125. // 脚本 transcript(docs/dynamic-workflow/transcript-and-notifications.md「Opening the tab」):与 actor transcript
  126. // 同档的 run 内详情 tab;标题是 run 名,类型标签才说「Workflow workspace」。
  127. describe("workflow-workspace tab presentation", () => {
  128. const workflowWorkspaceTab: Extract<WorkspaceSidePaneTab, { type: "workflow-workspace" }> = {
  129. id: "workflow-workspace:%2Fworkspace:parent-a:dwfrun-1",
  130. type: "workflow-workspace",
  131. workspaceKey: "/workspace",
  132. workspacePath: "/workspace",
  133. parentSessionId: "parent-a",
  134. toolCallId: "tool-wf-1",
  135. runId: "dwfrun-1",
  136. workflowName: "Fan-out review",
  137. };
  138. it("makes the transcript searchable by run, tool call, parent session and the facade words", () => {
  139. const hint = getSidePaneTabSearchHint(workflowWorkspaceTab);
  140. expect(hint).toContain("dwfrun-1");
  141. expect(hint).toContain("tool-wf-1");
  142. expect(hint).toContain("parent-a");
  143. expect(hint).toContain("Fan-out review");
  144. expect(hint).toContain("workflow script steps workspace transcript files git run");
  145. });
  146. it("labels the type as a workflow workspace rather than falling through to code preview", () => {
  147. expect(getSidePaneTabTypeLabel(workflowWorkspaceTab, labels)).toBe("Script steps");
  148. });
  149. it("titles the tab with the run name and falls back to the generic label", () => {
  150. expect(getLocalizedSidePaneTabTitle(workflowWorkspaceTab, labels)).toBe("Fan-out review");
  151. const { workflowName: _dropped, ...unnamed } = workflowWorkspaceTab;
  152. expect(getLocalizedSidePaneTabTitle(unnamed, labels)).toBe("Script steps");
  153. });
  154. });