v4ConversationStatusPanelModel.test.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. import { describe, expect, it } from "vitest";
  2. import type { GitRepositorySummary } from "@zcode/shared";
  3. import type {
  4. BackgroundWorkSummary,
  5. GoalState,
  6. PlanState,
  7. ToolCallRow,
  8. WorkflowRunNode,
  9. WorkflowRunState,
  10. } from "@zcode/shared/zcode-protocol-v4";
  11. import {
  12. buildConversationStatusPanelModel,
  13. resolveSoleRunningWorkflowRunTarget,
  14. workflowRunOpenTarget,
  15. } from "@/v4/conversationStatusPanelModel.js";
  16. import {
  17. CONVERSATION_STATUS_PANEL_INLINE_OFFSET_CLASS_NAME,
  18. CONVERSATION_STATUS_PANEL_INLINE_OFFSET_PX,
  19. CONVERSATION_STATUS_PANEL_WIDE_OFFSET_CLASS_NAME,
  20. getConversationStatusPanelOffsetClassName,
  21. resolveConversationStatusPanelVariant,
  22. shouldUseConversationStatusPanelInlineLayout,
  23. } from "@/v4/conversationLayout.js";
  24. function gitSummary(overrides: Partial<GitRepositorySummary> = {}): GitRepositorySummary {
  25. return {
  26. workspacePath: "/repo",
  27. repoRoot: "/repo",
  28. workspaceInRepoPath: "",
  29. autoRefreshWatchPaths: [],
  30. branchName: "main",
  31. trackingBranchName: "origin/main",
  32. headRefType: "branch",
  33. ahead: 0,
  34. behind: 0,
  35. isDirty: true,
  36. isGitAvailable: true,
  37. isRepository: true,
  38. ...overrides,
  39. };
  40. }
  41. function goalState(overrides: Partial<GoalState> = {}): GoalState {
  42. return {
  43. objective: "修好聊天渲染",
  44. status: "active",
  45. iteration: 2,
  46. verifications: [],
  47. ...overrides,
  48. };
  49. }
  50. function planState(overrides: Partial<PlanState> = {}): PlanState {
  51. return {
  52. updatedAt: 1_700_000_000_000,
  53. items: [
  54. { id: "1", content: "看旧实现", status: "completed" },
  55. { id: "2", content: "补状态卡", status: "inProgress" },
  56. { id: "3", content: "跑校验", status: "pending" },
  57. ],
  58. ...overrides,
  59. };
  60. }
  61. function backgroundWork(overrides: Partial<BackgroundWorkSummary> = {}): BackgroundWorkSummary {
  62. return {
  63. workId: "work-1",
  64. kind: "subagent",
  65. title: "探索代码",
  66. status: "running",
  67. startedAt: 1_700_000_000_000,
  68. anchorRowId: null,
  69. ...overrides,
  70. };
  71. }
  72. function workflowNode(
  73. overrides: Partial<WorkflowRunNode> & Pick<WorkflowRunNode, "phase">,
  74. ): WorkflowRunNode {
  75. return { siteId: "ask#1", ordinal: 1, ...overrides };
  76. }
  77. function workflowRun(overrides: Partial<WorkflowRunState> = {}): WorkflowRunState {
  78. return {
  79. runId: "dwfrun-1",
  80. toolCallId: "tool-wf-1",
  81. status: "running",
  82. usage: { spentTokens: 0, nodesUsed: 0 },
  83. actors: [],
  84. nodes: [],
  85. lastEventSequence: 0,
  86. ...overrides,
  87. };
  88. }
  89. function sessionPlan(rowId: number, overrides: Partial<ToolCallRow> = {}): ToolCallRow {
  90. return {
  91. rowId,
  92. turnId: `turn-${rowId}`,
  93. createdAt: 1_700_000_000_000 + rowId,
  94. createdAtSeq: rowId,
  95. kind: "toolCall",
  96. toolCallId: `plan-${rowId}`,
  97. toolName: "ExitPlanMode",
  98. status: "success",
  99. input: { plan: `# 计划 ${rowId}` },
  100. inputText: JSON.stringify({ plan: `# 计划 ${rowId}` }),
  101. ...overrides,
  102. };
  103. }
  104. describe("buildConversationStatusPanelModel", () => {
  105. it("aggregates git, goal, todo, and running background work", () => {
  106. const model = buildConversationStatusPanelModel({
  107. gitSummary: gitSummary(),
  108. gitDirtyFileCount: 3,
  109. gitWorktreeChangeSummary: { added: 42, removed: 0 },
  110. goal: goalState(),
  111. plan: planState(),
  112. backgroundWorks: [
  113. backgroundWork(),
  114. backgroundWork({ workId: "work-bash", kind: "bash" }),
  115. backgroundWork({ workId: "work-2", status: "resultPending" }),
  116. ],
  117. runningSubagents: [
  118. {
  119. childSessionId: "child-1",
  120. subagentType: "Explore",
  121. title: "探索代码",
  122. status: "running",
  123. startedAt: 1_700_000_000_000,
  124. },
  125. ],
  126. });
  127. expect(model.hasContent).toBe(true);
  128. expect(model.git).toMatchObject({
  129. added: 42,
  130. removed: 0,
  131. dirtyFileCount: 3,
  132. isClean: false,
  133. });
  134. expect(model.goal?.objective).toBe("修好聊天渲染");
  135. expect(model.plan).toMatchObject({
  136. completedCount: 1,
  137. waitingCount: 2,
  138. totalCount: 3,
  139. });
  140. expect(model.runningBashWorks.map((work) => work.workId)).toEqual(["work-bash"]);
  141. expect(model.runningSubagentWorks.map((work) => work.childSessionId)).toEqual(["child-1"]);
  142. });
  143. // 回归:dwf run 的停止入口在任何投影形态下都不许消失——面板的停止是 spec 里三个取消入口
  144. // 之一(取消只有一条实现)。旧版把 workflow work 塞进 Terminals(runningBashWorks)来保住
  145. // 它,那个错标现在由 Workflows 分区取代;这条用例因此反过来钉「不在 Terminals 里」。
  146. it("routes a running dwf workflow work into the workflow section instead of Terminals", () => {
  147. const model = buildConversationStatusPanelModel({
  148. backgroundWorks: [backgroundWork({ workId: "dwfrun-1", kind: "workflow" })],
  149. workflowRuns: [workflowRun({ runId: "dwfrun-1" })],
  150. });
  151. expect(model.hasContent).toBe(true);
  152. expect(model.runningWorkflowRuns.map((row) => row.runId)).toEqual(["dwfrun-1"]);
  153. expect(model.runningBashWorks).toEqual([]);
  154. });
  155. it("joins each active run with its background work by workId ≡ runId", () => {
  156. const model = buildConversationStatusPanelModel({
  157. backgroundWorks: [
  158. backgroundWork({
  159. workId: "dwfrun-1",
  160. kind: "workflow",
  161. title: "重构状态胶囊",
  162. startedAt: 1_700_000_000_500,
  163. cancellable: true,
  164. }),
  165. ],
  166. workflowRuns: [
  167. workflowRun({
  168. runId: "dwfrun-1",
  169. toolCallId: "tool-wf-9",
  170. nodes: [
  171. workflowNode({ phase: "settled" }),
  172. workflowNode({ ordinal: 2, phase: "queued" }),
  173. ],
  174. }),
  175. ],
  176. });
  177. expect(model.runningWorkflowRuns).toEqual([
  178. {
  179. runId: "dwfrun-1",
  180. toolCallId: "tool-wf-9",
  181. status: "running",
  182. nodesSettled: 1,
  183. nodesTotal: 2,
  184. phases: [],
  185. title: "重构状态胶囊",
  186. startedAt: 1_700_000_000_500,
  187. workId: "dwfrun-1",
  188. cancellable: true,
  189. },
  190. ]);
  191. });
  192. // 无 work 的 run 照常成行:状态词与步数来自投影本身,只有时长和 Stop 依赖 work。
  193. it("keeps a run without background work as a status-only row", () => {
  194. const model = buildConversationStatusPanelModel({
  195. workflowRuns: [
  196. workflowRun({ runId: "dwfrun-lonely", nodes: [workflowNode({ phase: "settled" })] }),
  197. ],
  198. });
  199. expect(model.hasContent).toBe(true);
  200. expect(model.runningWorkflowRuns).toEqual([
  201. {
  202. runId: "dwfrun-lonely",
  203. toolCallId: "tool-wf-1",
  204. status: "running",
  205. nodesSettled: 1,
  206. nodesTotal: 1,
  207. phases: [],
  208. },
  209. ]);
  210. });
  211. // 偏斜兜底:旧 CLI 不发 workflowRuns 投影键,只有 backgroundWorks 那一条 workflow work。
  212. // 降级行没有状态词与步数(无从得知),但题名/时长/Stop 齐全——cancel 入口在任何偏斜下不消失。
  213. it("degrades a workflow work with no matching run into a title-and-stop row", () => {
  214. const model = buildConversationStatusPanelModel({
  215. backgroundWorks: [
  216. backgroundWork({
  217. workId: "dwfrun-skew",
  218. kind: "workflow",
  219. title: "旧 CLI 的 run",
  220. startedAt: 1_700_000_001_000,
  221. }),
  222. ],
  223. workflowRuns: [],
  224. });
  225. expect(model.runningWorkflowRuns).toEqual([
  226. {
  227. runId: "dwfrun-skew",
  228. workId: "dwfrun-skew",
  229. title: "旧 CLI 的 run",
  230. startedAt: 1_700_000_001_000,
  231. // cancellable 缺省即可停(与 Agent 行同款 `!== false` 语义)。
  232. cancellable: true,
  233. },
  234. ]);
  235. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("status");
  236. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("nodesSettled");
  237. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("phases");
  238. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("toolCallId");
  239. expect(model.hasContent).toBe(true);
  240. });
  241. // 站点表与侧栏运行行同一条推导(shared 的 deriveSessionWorkflowPhases):声明表在场用声明表,
  242. // 当前站 running、进入过的 done、其余 pending;任务岛不另写第二套。
  243. it("carries the sidebar's phase list and the current phase on a live row", () => {
  244. const model = buildConversationStatusPanelModel({
  245. workflowRuns: [
  246. workflowRun({
  247. runId: "dwfrun-1",
  248. phaseNames: ["盘点", "计划", "构建"],
  249. phases: [{ name: "盘点", rounds: 1 }],
  250. currentPhase: "计划",
  251. }),
  252. ],
  253. });
  254. expect(model.runningWorkflowRuns[0]?.phases).toEqual([
  255. { name: "盘点", status: "done" },
  256. { name: "计划", status: "running" },
  257. { name: "构建", status: "pending" },
  258. ]);
  259. expect(model.runningWorkflowRuns[0]?.currentPhase).toBe("计划");
  260. });
  261. // 降级行排在 run 支撑的行之后:投影序是启动序,偏斜行没有位置可言,追加是唯一不撒谎的落位。
  262. it("appends degraded skew rows after the run-backed rows", () => {
  263. const model = buildConversationStatusPanelModel({
  264. backgroundWorks: [
  265. backgroundWork({ workId: "dwfrun-skew", kind: "workflow" }),
  266. backgroundWork({ workId: "dwfrun-2", kind: "workflow" }),
  267. ],
  268. workflowRuns: [workflowRun({ runId: "dwfrun-1" }), workflowRun({ runId: "dwfrun-2" })],
  269. });
  270. expect(model.runningWorkflowRuns.map((row) => row.runId)).toEqual([
  271. "dwfrun-1",
  272. "dwfrun-2",
  273. "dwfrun-skew",
  274. ]);
  275. });
  276. it("counts pending as active and drops terminal runs from the section", () => {
  277. const model = buildConversationStatusPanelModel({
  278. workflowRuns: [
  279. workflowRun({ runId: "dwfrun-pending", status: "pending" }),
  280. workflowRun({ runId: "dwfrun-running", status: "running" }),
  281. workflowRun({ runId: "dwfrun-completed", status: "completed" }),
  282. workflowRun({ runId: "dwfrun-failed", status: "failed" }),
  283. workflowRun({ runId: "dwfrun-cancelled", status: "cancelled" }),
  284. ],
  285. });
  286. expect(model.runningWorkflowRuns.map((row) => row.runId)).toEqual([
  287. "dwfrun-pending",
  288. "dwfrun-running",
  289. ]);
  290. expect(model.runningWorkflowRuns[0]?.status).toBe("pending");
  291. });
  292. // 顺序 = 投影 runs 序 = 启动序;模型不排序(重排会让面板行在每次投影更新时跳位)。
  293. it("preserves projection order for active runs", () => {
  294. const model = buildConversationStatusPanelModel({
  295. workflowRuns: [
  296. workflowRun({ runId: "dwfrun-c" }),
  297. workflowRun({ runId: "dwfrun-a", status: "completed" }),
  298. workflowRun({ runId: "dwfrun-b", status: "pending" }),
  299. ],
  300. });
  301. expect(model.runningWorkflowRuns.map((row) => row.runId)).toEqual(["dwfrun-c", "dwfrun-b"]);
  302. });
  303. // 步数与聊天紧凑卡同源(workflowRunCardJoin 的共享 helper):分母是**已排程**节点数,
  304. // 动态工作流没有静态总数,未结算的相位一律不计入 settled。
  305. it("counts settled over observed nodes through the shared card helper", () => {
  306. const model = buildConversationStatusPanelModel({
  307. workflowRuns: [
  308. workflowRun({
  309. nodes: [
  310. workflowNode({ phase: "settled", outcome: "ok" }),
  311. workflowNode({ ordinal: 2, phase: "settled", outcome: "failed" }),
  312. workflowNode({ ordinal: 3, phase: "settled", outcome: "cancelled" }),
  313. workflowNode({ ordinal: 4, phase: "dispatched" }),
  314. workflowNode({ ordinal: 5, phase: "repairing" }),
  315. workflowNode({ ordinal: 6, phase: "nudged" }),
  316. workflowNode({ ordinal: 7, phase: "queued" }),
  317. ],
  318. }),
  319. ],
  320. });
  321. expect(model.runningWorkflowRuns[0]).toMatchObject({ nodesSettled: 3, nodesTotal: 7 });
  322. });
  323. // 联接按**字段含义**分簇,而不是按 work 的 status 一刀切:title / startedAt 是静态元数据,
  324. // work 走到 resultPending 时把它们一起丢掉,行会当场闪成 fallbackName 并失去时长——run 还
  325. // 在跑,这就是纯视觉故障。只有 Stop 真的没了:已结束的 work 没有可取消的东西。
  326. it("keeps title and elapsed from a settled work while dropping only its Stop control", () => {
  327. const model = buildConversationStatusPanelModel({
  328. backgroundWorks: [
  329. backgroundWork({
  330. workId: "dwfrun-1",
  331. kind: "workflow",
  332. status: "resultPending",
  333. title: "结果待投递的工作流",
  334. startedAt: 1_700_000_002_000,
  335. cancellable: true,
  336. }),
  337. backgroundWork({ workId: "work-bash", kind: "bash" }),
  338. ],
  339. workflowRuns: [workflowRun({ runId: "dwfrun-1" })],
  340. });
  341. expect(model.runningWorkflowRuns).toEqual([
  342. {
  343. runId: "dwfrun-1",
  344. toolCallId: "tool-wf-1",
  345. status: "running",
  346. nodesSettled: 0,
  347. nodesTotal: 0,
  348. phases: [],
  349. title: "结果待投递的工作流",
  350. startedAt: 1_700_000_002_000,
  351. },
  352. ]);
  353. // Stop 的两个前提字段一起缺席:渲染层只看 workId 就能判断这行停不了。
  354. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("workId");
  355. expect(model.runningWorkflowRuns[0]).not.toHaveProperty("cancellable");
  356. expect(model.runningBashWorks.map((work) => work.workId)).toEqual(["work-bash"]);
  357. });
  358. // 反向:running 的 work 把 Stop 的两个字段一起带上(与上一条共同钉住这条分簇线)。
  359. it("gates the Stop control on the work still running", () => {
  360. const model = buildConversationStatusPanelModel({
  361. backgroundWorks: [
  362. backgroundWork({ workId: "dwfrun-1", kind: "workflow", cancellable: false }),
  363. ],
  364. workflowRuns: [workflowRun({ runId: "dwfrun-1" })],
  365. });
  366. expect(model.runningWorkflowRuns[0]).toMatchObject({
  367. workId: "dwfrun-1",
  368. cancellable: false,
  369. });
  370. });
  371. // 降级行只收 running 的 work:既没有 run、work 也已结束,这行没有任何可操作的东西,
  372. // 显示它等于在面板上留一条永不消失的死行。
  373. it("does not degrade a settled workflow work with no run into a row", () => {
  374. const model = buildConversationStatusPanelModel({
  375. backgroundWorks: [
  376. backgroundWork({ workId: "dwfrun-gone", kind: "workflow", status: "resultPending" }),
  377. backgroundWork({ workId: "dwfrun-failed", kind: "workflow", status: "failed" }),
  378. backgroundWork({ workId: "dwfrun-cancelled", kind: "workflow", status: "cancelled" }),
  379. ],
  380. workflowRuns: [],
  381. });
  382. expect(model.runningWorkflowRuns).toEqual([]);
  383. expect(model.hasContent).toBe(false);
  384. });
  385. it("stays empty without repository or session status", () => {
  386. const model = buildConversationStatusPanelModel({
  387. gitSummary: gitSummary({ isRepository: false }),
  388. gitDirtyFileCount: 0,
  389. gitWorktreeChangeSummary: { added: 0, removed: 0 },
  390. goal: null,
  391. plan: null,
  392. backgroundWorks: [],
  393. });
  394. expect(model.hasContent).toBe(false);
  395. expect(model.git).toBeNull();
  396. });
  397. it("keeps the complete Todo projection in snapshot order when statuses are mixed", () => {
  398. const model = buildConversationStatusPanelModel({
  399. plan: planState({
  400. items: [
  401. { id: "done-1", content: "已完成一", status: "completed" },
  402. { id: "active", content: "进行中", status: "inProgress" },
  403. { id: "pending", content: "待处理", status: "pending" },
  404. { id: "done-2", content: "已完成二", status: "completed" },
  405. { id: "pending-2", content: "待处理二", status: "pending" },
  406. ],
  407. }),
  408. });
  409. expect(model.plan?.displayItems.map((item) => item.id)).toEqual([
  410. "done-1",
  411. "active",
  412. "pending",
  413. "done-2",
  414. "pending-2",
  415. ]);
  416. });
  417. it("joins running Agent controls only by exact child session identity", () => {
  418. const model = buildConversationStatusPanelModel({
  419. backgroundWorks: [
  420. backgroundWork({
  421. workId: "agent-control-work",
  422. childSessionId: "child-match",
  423. cancellable: true,
  424. }),
  425. backgroundWork({
  426. workId: "agent-disabled-work",
  427. childSessionId: "child-disabled",
  428. cancellable: false,
  429. }),
  430. backgroundWork({
  431. workId: "agent-terminal-work",
  432. childSessionId: "child-terminal",
  433. status: "cancelled",
  434. }),
  435. backgroundWork({
  436. workId: "agent-ambiguous-a",
  437. childSessionId: "child-ambiguous",
  438. }),
  439. backgroundWork({
  440. workId: "agent-ambiguous-b",
  441. childSessionId: "child-ambiguous",
  442. }),
  443. ],
  444. runningSubagents: [
  445. {
  446. childSessionId: "child-match",
  447. subagentType: "Explore",
  448. title: "相同标题",
  449. status: "running",
  450. },
  451. {
  452. childSessionId: "child-disabled",
  453. subagentType: "Explore",
  454. title: "不可停止",
  455. status: "running",
  456. },
  457. {
  458. childSessionId: "child-foreground",
  459. subagentType: "Explore",
  460. title: "相同标题",
  461. status: "running",
  462. },
  463. {
  464. childSessionId: "child-ambiguous",
  465. subagentType: "Explore",
  466. title: "身份重复",
  467. status: "running",
  468. },
  469. ],
  470. });
  471. expect(model.runningSubagentWorks).toMatchObject([
  472. {
  473. childSessionId: "child-match",
  474. controlWorkId: "agent-control-work",
  475. cancellable: true,
  476. },
  477. {
  478. childSessionId: "child-disabled",
  479. controlWorkId: "agent-disabled-work",
  480. cancellable: false,
  481. },
  482. {
  483. childSessionId: "child-foreground",
  484. },
  485. {
  486. childSessionId: "child-ambiguous",
  487. },
  488. ]);
  489. expect(model.runningSubagentWorks[2]).not.toHaveProperty("controlWorkId");
  490. expect(model.runningSubagentWorks[3]).not.toHaveProperty("controlWorkId");
  491. });
  492. it("keeps a uniquely identified running Agent controllable while directory projection catches up", () => {
  493. const model = buildConversationStatusPanelModel({
  494. backgroundWorks: [
  495. backgroundWork({
  496. workId: "agent-runtime-work",
  497. childSessionId: "child-runtime",
  498. title: "运行中的 Agent",
  499. blocked: true,
  500. cancellable: true,
  501. }),
  502. backgroundWork({
  503. workId: "ambiguous-a",
  504. childSessionId: "child-ambiguous",
  505. }),
  506. backgroundWork({
  507. workId: "ambiguous-b",
  508. childSessionId: "child-ambiguous",
  509. }),
  510. ],
  511. runningSubagents: [],
  512. });
  513. expect(model.runningSubagentWorks).toEqual([
  514. expect.objectContaining({
  515. agentId: "agent-runtime-work",
  516. childSessionId: "child-runtime",
  517. controlWorkId: "agent-runtime-work",
  518. status: "blocked",
  519. title: "运行中的 Agent",
  520. }),
  521. ]);
  522. });
  523. it("does not show git tools for a clean repository without worktree line changes", () => {
  524. const model = buildConversationStatusPanelModel({
  525. gitSummary: gitSummary({ isDirty: false, ahead: 0 }),
  526. gitDirtyFileCount: 0,
  527. gitWorktreeChangeSummary: { added: 0, removed: 0 },
  528. goal: null,
  529. plan: null,
  530. backgroundWorks: [],
  531. });
  532. expect(model.hasContent).toBe(false);
  533. expect(model.git).toBeNull();
  534. });
  535. it("lists only terminal ExitPlanMode rows with markdown, newest first", () => {
  536. const model = buildConversationStatusPanelModel({
  537. workspacePath: "/repo",
  538. sessionPlans: [
  539. sessionPlan(4, { status: "cancelled" }),
  540. sessionPlan(8, { status: "error", input: { plan: "# 最新计划" } }),
  541. sessionPlan(9, { status: "running" }),
  542. sessionPlan(10, { toolName: "Write" }),
  543. sessionPlan(11, { input: {}, inputText: "{}" }),
  544. ],
  545. });
  546. expect(model.hasContent).toBe(true);
  547. expect(model.sessionPlans?.items.map((item) => item.toolCallId)).toEqual(["plan-8", "plan-4"]);
  548. expect(model.sessionPlans?.items[0]?.title).toBe("最新计划");
  549. });
  550. });
  551. describe("conversation status panel layout", () => {
  552. it("uses the z-code-2 inline offset for the conversation column", () => {
  553. expect(CONVERSATION_STATUS_PANEL_INLINE_OFFSET_PX).toBe(168);
  554. expect(CONVERSATION_STATUS_PANEL_INLINE_OFFSET_CLASS_NAME).toBe("-translate-x-42");
  555. expect(CONVERSATION_STATUS_PANEL_WIDE_OFFSET_CLASS_NAME).toBe(
  556. "@min-[1280px]/conversation:-translate-x-42",
  557. );
  558. expect(getConversationStatusPanelOffsetClassName("auto")).toBe(
  559. CONVERSATION_STATUS_PANEL_WIDE_OFFSET_CLASS_NAME,
  560. );
  561. expect(getConversationStatusPanelOffsetClassName("inline")).toBe(
  562. CONVERSATION_STATUS_PANEL_WIDE_OFFSET_CLASS_NAME,
  563. );
  564. expect(getConversationStatusPanelOffsetClassName("none")).toBeUndefined();
  565. });
  566. it("preserves manual variants while leaving auto mode to CSS", () => {
  567. expect(
  568. resolveConversationStatusPanelVariant({
  569. variantOverride: "mini",
  570. }),
  571. ).toBe("mini");
  572. expect(
  573. resolveConversationStatusPanelVariant({
  574. variantOverride: null,
  575. }),
  576. ).toBe("auto");
  577. });
  578. it("only applies inline offset when content can render in expanded inline mode", () => {
  579. expect(
  580. shouldUseConversationStatusPanelInlineLayout({
  581. hasContent: true,
  582. variant: "auto",
  583. }),
  584. ).toBe(true);
  585. expect(
  586. shouldUseConversationStatusPanelInlineLayout({
  587. hasContent: false,
  588. variant: "panel",
  589. }),
  590. ).toBe(false);
  591. expect(
  592. shouldUseConversationStatusPanelInlineLayout({
  593. hasContent: true,
  594. variant: "mini",
  595. }),
  596. ).toBe(false);
  597. });
  598. });
  599. // composer 徽标直达(docs/dynamic-workflow/presentation.md「Other places a run appears」):
  600. // 判定吃的是 buildConversationStatusPanelModel 的产出,徽标与胶囊共用同一份运行态真值。
  601. describe("resolveSoleRunningWorkflowRunTarget", () => {
  602. const workflowWork = backgroundWork({
  603. workId: "dwfrun-1",
  604. kind: "workflow",
  605. title: "发布前检查",
  606. startedAt: 1_700_000_000_000,
  607. });
  608. it("returns the open target when the only running activity is one workflow run", () => {
  609. const model = buildConversationStatusPanelModel({
  610. backgroundWorks: [workflowWork],
  611. workflowRuns: [workflowRun()],
  612. });
  613. expect(resolveSoleRunningWorkflowRunTarget(model)).toEqual({
  614. runId: "dwfrun-1",
  615. toolCallId: "tool-wf-1",
  616. workflowName: "发布前检查",
  617. });
  618. });
  619. it("treats a pending run as running and omits the name when the title is the id", () => {
  620. const model = buildConversationStatusPanelModel({
  621. backgroundWorks: [
  622. backgroundWork({ workId: "dwfrun-1", kind: "workflow", title: "dwfrun-1" }),
  623. ],
  624. workflowRuns: [workflowRun({ status: "pending" })],
  625. });
  626. expect(resolveSoleRunningWorkflowRunTarget(model)).toEqual({
  627. runId: "dwfrun-1",
  628. toolCallId: "tool-wf-1",
  629. });
  630. });
  631. it("returns null once a terminal or a subagent runs alongside the workflow", () => {
  632. const withBash = buildConversationStatusPanelModel({
  633. backgroundWorks: [workflowWork, backgroundWork({ workId: "bash-1", kind: "bash" })],
  634. workflowRuns: [workflowRun()],
  635. });
  636. expect(resolveSoleRunningWorkflowRunTarget(withBash)).toBeNull();
  637. const withSubagent = buildConversationStatusPanelModel({
  638. backgroundWorks: [workflowWork],
  639. workflowRuns: [workflowRun()],
  640. runningSubagents: [
  641. {
  642. childSessionId: "child-1",
  643. agentId: "agent-1",
  644. subagentType: "Explore",
  645. title: "分析",
  646. status: "running",
  647. },
  648. ],
  649. });
  650. expect(resolveSoleRunningWorkflowRunTarget(withSubagent)).toBeNull();
  651. });
  652. it("returns null for two workflow runs and for a sole run without a tool call id", () => {
  653. const two = buildConversationStatusPanelModel({
  654. backgroundWorks: [workflowWork, backgroundWork({ workId: "dwfrun-2", kind: "workflow" })],
  655. workflowRuns: [workflowRun(), workflowRun({ runId: "dwfrun-2", toolCallId: "tool-wf-2" })],
  656. });
  657. expect(resolveSoleRunningWorkflowRunTarget(two)).toBeNull();
  658. const withoutToolCallId = buildConversationStatusPanelModel({
  659. backgroundWorks: [workflowWork],
  660. workflowRuns: [workflowRun({ toolCallId: undefined })],
  661. });
  662. expect(resolveSoleRunningWorkflowRunTarget(withoutToolCallId)).toBeNull();
  663. // 偏斜降级行(work 有、run 无)同样没有可开的详情页。
  664. const degraded = buildConversationStatusPanelModel({
  665. backgroundWorks: [workflowWork],
  666. workflowRuns: [],
  667. });
  668. expect(degraded.runningWorkflowRuns).toHaveLength(1);
  669. expect(resolveSoleRunningWorkflowRunTarget(degraded)).toBeNull();
  670. expect(resolveSoleRunningWorkflowRunTarget(buildConversationStatusPanelModel({}))).toBeNull();
  671. });
  672. it("shares the row-to-target conversion with the panel row", () => {
  673. expect(workflowRunOpenTarget({ runId: "r", toolCallId: "t", title: "名字" })).toEqual({
  674. runId: "r",
  675. toolCallId: "t",
  676. workflowName: "名字",
  677. });
  678. expect(workflowRunOpenTarget({ runId: "r", toolCallId: "t", title: "r" })).toEqual({
  679. runId: "r",
  680. toolCallId: "t",
  681. });
  682. expect(workflowRunOpenTarget({ runId: "r", title: "名字" })).toBeNull();
  683. });
  684. });
  685. describe("通用模式 Git 投影", () => {
  686. it("隐藏 Git 但保留目标和计划,切回后恢复原始 Git 数据", () => {
  687. const input = {
  688. gitSummary: gitSummary(),
  689. gitWorktreeChangeSummary: { added: 7, removed: 2 },
  690. goal: goalState(),
  691. plan: planState(),
  692. };
  693. const original = JSON.stringify(input);
  694. const coding = buildConversationStatusPanelModel(input);
  695. const general = buildConversationStatusPanelModel({ ...input, isOfficeMode: true });
  696. expect(general.git).toBeNull();
  697. expect(general.goal).toEqual(coding.goal);
  698. expect(general.plan).toEqual(coding.plan);
  699. expect(general.hasContent).toBe(true);
  700. expect(buildConversationStatusPanelModel(input).git).toMatchObject({ added: 7, removed: 2 });
  701. expect(JSON.stringify(input)).toBe(original);
  702. });
  703. });