chatStatus.test.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. canForkFromTaskRuntimeStatus,
  4. deriveChatTaskStatusForMainActivity,
  5. deriveChatComposerStatusFromTaskRuntime,
  6. getChatSubmitLabelId,
  7. isChatComposerEditingDisabled,
  8. isChatComposerSubmissionBlocked,
  9. isChatTaskRunning,
  10. shouldShowChatSubmitSpinner,
  11. shouldShowChatThinkingShimmer,
  12. } from "../src/lib/chatStatus.js";
  13. describe("deriveChatComposerStatusFromTaskRuntime", () => {
  14. it("maps streaming tasks to the stop-button state", () => {
  15. expect(deriveChatComposerStatusFromTaskRuntime("streaming")).toBe("streaming");
  16. });
  17. it("resets completed and ready tasks back to the send-button state", () => {
  18. expect(deriveChatComposerStatusFromTaskRuntime("completed")).toBe("idle");
  19. expect(deriveChatComposerStatusFromTaskRuntime("ready")).toBe("idle");
  20. });
  21. });
  22. describe("getChatSubmitLabelId", () => {
  23. it("returns preparing while workspace ZCode Agent is still initializing", () => {
  24. expect(getChatSubmitLabelId("submitting", "initializing", "idle")).toBe("chat.preparing");
  25. });
  26. it("returns preparing while task is still being created or restored", () => {
  27. expect(getChatSubmitLabelId("submitting", "ready", "creating")).toBe("chat.preparing");
  28. expect(getChatSubmitLabelId("submitting", "ready", "restoring")).toBe("chat.preparing");
  29. });
  30. it("keeps preparing during submitting even if task runtime already flipped to streaming", () => {
  31. expect(getChatSubmitLabelId("submitting", "ready", "streaming")).toBe("chat.preparing");
  32. });
  33. it("falls back to send outside of the submitting state", () => {
  34. expect(getChatSubmitLabelId("idle", "ready", "ready")).toBe("chat.send");
  35. });
  36. });
  37. describe("chat composer availability", () => {
  38. it("allows editing while the assistant is streaming", () => {
  39. expect(isChatComposerEditingDisabled("streaming")).toBe(false);
  40. });
  41. it("keeps editing enabled while the request is still submitting", () => {
  42. expect(isChatComposerEditingDisabled("submitting")).toBe(false);
  43. });
  44. it("allows submission while the assistant is streaming so the next prompt can be queued", () => {
  45. expect(isChatComposerSubmissionBlocked("streaming")).toBe(false);
  46. });
  47. it("still blocks submission while submitting", () => {
  48. expect(isChatComposerSubmissionBlocked("submitting")).toBe(true);
  49. });
  50. });
  51. describe("shouldShowChatSubmitSpinner", () => {
  52. it("shows a spinner while a prompt is still submitting", () => {
  53. expect(shouldShowChatSubmitSpinner("submitting")).toBe(true);
  54. });
  55. it("hides the spinner outside the submitting window", () => {
  56. expect(shouldShowChatSubmitSpinner("idle")).toBe(false);
  57. expect(shouldShowChatSubmitSpinner("streaming")).toBe(false);
  58. expect(shouldShowChatSubmitSpinner("error")).toBe(false);
  59. });
  60. });
  61. describe("isChatTaskRunning", () => {
  62. it("treats creating, restoring and streaming as running", () => {
  63. expect(isChatTaskRunning("creating")).toBe(true);
  64. expect(isChatTaskRunning("restoring")).toBe(true);
  65. expect(isChatTaskRunning("streaming")).toBe(true);
  66. });
  67. it("treats idle, ready, completed and failed as not running", () => {
  68. expect(isChatTaskRunning("idle")).toBe(false);
  69. expect(isChatTaskRunning("ready")).toBe(false);
  70. expect(isChatTaskRunning("completed")).toBe(false);
  71. expect(isChatTaskRunning("failed")).toBe(false);
  72. });
  73. });
  74. describe("deriveChatTaskStatusForMainActivity", () => {
  75. it("keeps raw streaming for background-only task status but hides main loading state", () => {
  76. expect(deriveChatTaskStatusForMainActivity("streaming", false)).toBe("completed");
  77. expect(deriveChatTaskStatusForMainActivity("streaming", true)).toBe("streaming");
  78. });
  79. it("does not rewrite non-streaming task statuses", () => {
  80. expect(deriveChatTaskStatusForMainActivity("creating", false)).toBe("creating");
  81. expect(deriveChatTaskStatusForMainActivity("completed", false)).toBe("completed");
  82. });
  83. });
  84. describe("canForkFromTaskRuntimeStatus", () => {
  85. it("allows fork only from stable completed-like runtime states", () => {
  86. expect(canForkFromTaskRuntimeStatus("idle")).toBe(true);
  87. expect(canForkFromTaskRuntimeStatus("ready")).toBe(true);
  88. expect(canForkFromTaskRuntimeStatus("completed")).toBe(true);
  89. });
  90. it("blocks fork while active, not ready, or failed", () => {
  91. expect(canForkFromTaskRuntimeStatus("creating")).toBe(false);
  92. expect(canForkFromTaskRuntimeStatus("restoring")).toBe(false);
  93. expect(canForkFromTaskRuntimeStatus("streaming")).toBe(false);
  94. expect(canForkFromTaskRuntimeStatus("notReady")).toBe(false);
  95. expect(canForkFromTaskRuntimeStatus("failed")).toBe(false);
  96. });
  97. });
  98. describe("shouldShowChatThinkingShimmer", () => {
  99. it("shows thinking only while creating or streaming", () => {
  100. expect(shouldShowChatThinkingShimmer("creating")).toBe(true);
  101. expect(shouldShowChatThinkingShimmer("streaming")).toBe(true);
  102. });
  103. it("does not show thinking while restoring", () => {
  104. expect(shouldShowChatThinkingShimmer("restoring")).toBe(false);
  105. });
  106. });