webRemoteControlTaskRead.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { describe, expect, it, vi } from "vitest";
  2. import {
  3. markWebRemoteControlBridgeTaskRead,
  4. markWebRemoteControlTaskRead,
  5. } from "#src/web-remote-control/index.js";
  6. describe("markWebRemoteControlTaskRead", () => {
  7. it("file-only bridge without initialTaskId never changes unread metadata", async () => {
  8. const setTaskUnread = vi.fn();
  9. await markWebRemoteControlBridgeTaskRead({
  10. bridge: { kind: "local", workspacePath: "/files" },
  11. service: { setTaskUnread },
  12. });
  13. expect(setTaskUnread).not.toHaveBeenCalled();
  14. });
  15. it("persists the exact mobile task target as read", async () => {
  16. const setTaskUnread = vi.fn(async () => ({}));
  17. const result = await markWebRemoteControlTaskRead({
  18. service: { setTaskUnread },
  19. target: {
  20. taskId: "task-1",
  21. workspacePath: "/workspace/remote",
  22. workspaceIdentity: "ssh://host/workspace/remote",
  23. expectedUnreadAt: 123,
  24. },
  25. });
  26. expect(result).toEqual({ ok: true });
  27. expect(setTaskUnread).toHaveBeenCalledWith({
  28. taskId: "task-1",
  29. workspacePath: "/workspace/remote",
  30. workspaceIdentity: "ssh://host/workspace/remote",
  31. unread: false,
  32. expectedUnreadAt: 123,
  33. });
  34. });
  35. it("reports a failed read mutation without rejecting task navigation", async () => {
  36. const failure = new Error("task index unavailable");
  37. await expect(
  38. markWebRemoteControlTaskRead({
  39. service: {
  40. setTaskUnread: vi.fn(async () => {
  41. throw failure;
  42. }),
  43. },
  44. target: {
  45. taskId: "task-1",
  46. workspacePath: "/workspace/local",
  47. expectedUnreadAt: 123,
  48. },
  49. }),
  50. ).resolves.toEqual({ ok: false, error: failure });
  51. });
  52. it("uses the newly connected remote bridge identity for cross-workspace read clearing", async () => {
  53. const setTaskUnread = vi.fn(async () => ({}));
  54. const result = await markWebRemoteControlBridgeTaskRead({
  55. bridge: {
  56. kind: "remote",
  57. workspacePath: "/workspace/shared-path",
  58. workspaceIdentity: "ssh://new-host/workspace/shared-path",
  59. initialTaskId: "task-cross-workspace",
  60. },
  61. service: { setTaskUnread },
  62. expectedUnreadAt: 456,
  63. });
  64. expect(result).toEqual({ ok: true });
  65. expect(setTaskUnread).toHaveBeenCalledWith({
  66. taskId: "task-cross-workspace",
  67. workspacePath: "/workspace/shared-path",
  68. workspaceIdentity: "ssh://new-host/workspace/shared-path",
  69. unread: false,
  70. expectedUnreadAt: 456,
  71. });
  72. });
  73. });