subagentDirectorySidePane.test.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { SubagentDirectorySidePaneTab } from "@/lib/workspaceSidePane.js";
  5. vi.mock("@/components/ui/button.js", () => ({
  6. Button: ({ children, ...props }: { children: ReactNode; [key: string]: unknown }) =>
  7. createElement("button", props, children),
  8. }));
  9. vi.mock("@/hooks/useSessionSubagents.js", () => ({
  10. useSessionSubagents: () => ({
  11. error: null,
  12. loading: false,
  13. loadMore: vi.fn(),
  14. refresh: vi.fn(),
  15. revision: 2,
  16. ended: {
  17. total: 21,
  18. nextCursor: "cursor",
  19. items: [
  20. {
  21. childSessionId: "child-failed",
  22. subagentType: "general-purpose",
  23. title: "Run verification",
  24. summary: "Provider request failed",
  25. status: "failed",
  26. endedAt: Date.now() - 60_000,
  27. },
  28. ],
  29. },
  30. }),
  31. }));
  32. vi.mock("@/v4/V4ConversationContext.js", () => ({
  33. V4PaneConversationProvider: ({ children }: { children: ReactNode }) => children,
  34. useV4Conversation: () => ({
  35. layer: { acquire: vi.fn(() => ({ release: vi.fn() })) },
  36. }),
  37. }));
  38. vi.mock("@/v4/useConversationProjection.js", () => ({
  39. useConversationProjection: () => ({
  40. snapshot: {
  41. subagents: {
  42. revision: 2,
  43. childSessionIds: ["child-running", "child-failed"],
  44. running: [
  45. {
  46. childSessionId: "child-running",
  47. subagentType: "Explore",
  48. title: "Inspect source tree",
  49. status: "blocked",
  50. startedAt: Date.now() - 5_000,
  51. },
  52. ],
  53. endedTotal: 21,
  54. },
  55. },
  56. }),
  57. }));
  58. vi.mock("@/i18n/IntlProvider.js", () => ({
  59. useZCodeIntl: () => ({
  60. intl: {
  61. formatMessage: (descriptor: { id: string }, values?: Record<string, string>) =>
  62. values ? `${descriptor.id}:${Object.values(values).join("/")}` : descriptor.id,
  63. },
  64. }),
  65. }));
  66. const tab: SubagentDirectorySidePaneTab = {
  67. id: "subagent-directory:workspace:root:parent",
  68. type: "subagent-directory",
  69. workspaceKey: "ssh://host/workspace",
  70. workspacePath: "/workspace",
  71. workspaceIdentity: "ssh://host/workspace",
  72. remoteSessionId: "remote-session",
  73. rootSessionId: "root-session",
  74. parentSessionId: "parent-session",
  75. };
  76. describe("SubagentDirectorySidePane", () => {
  77. it("renders unpaged running and paged ended sections with status and summary", async () => {
  78. const { SubagentDirectorySidePane } = await import("@/app-shell/SubagentDirectorySidePane.js");
  79. const html = renderToStaticMarkup(
  80. createElement(SubagentDirectorySidePane, {
  81. tab,
  82. onOpenSubagentSession: vi.fn(),
  83. }),
  84. );
  85. expect(html).toContain("subagentDirectory.running · 1");
  86. expect(html).toContain("subagentDirectory.ended · 21");
  87. expect(html).toContain("Inspect source tree");
  88. expect(html).toContain("subagentDirectory.status.blocked");
  89. expect(html).toContain("Provider request failed");
  90. expect(html).toContain("subagentDirectory.status.failed");
  91. expect(html).toContain("subagentDirectory.showMore");
  92. });
  93. it("builds a scoped detail request that preserves remote workspace identity", async () => {
  94. const { buildSubagentDirectoryOpenRequest } =
  95. await import("@/app-shell/SubagentDirectorySidePane.js");
  96. expect(
  97. buildSubagentDirectoryOpenRequest(tab, {
  98. childSessionId: "child-failed",
  99. subagentType: "Explore",
  100. title: "Inspect source tree",
  101. status: "failed",
  102. }),
  103. ).toEqual({
  104. workspacePath: "/workspace",
  105. workspaceIdentity: "ssh://host/workspace",
  106. remoteSessionId: "remote-session",
  107. rootSessionId: "root-session",
  108. parentSessionId: "parent-session",
  109. childSessionId: "child-failed",
  110. subagentType: "Explore",
  111. title: "Inspect source tree",
  112. });
  113. });
  114. });