gitRepositoryRefresh.test.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { describe, expect, it } from "vitest";
  2. import { shouldRefreshLiveGitData } from "../src/hooks/useGitRepository.js";
  3. describe("shouldRefreshLiveGitData", () => {
  4. it("refreshes on initial load and workspace changes", () => {
  5. expect(
  6. shouldRefreshLiveGitData(null, {
  7. workspacePath: "/repo-a",
  8. workspaceKey: "/repo-a",
  9. includeExtendedData: false,
  10. refreshToken: 0,
  11. workspaceRpcEnabled: true,
  12. }),
  13. ).toBe(true);
  14. expect(
  15. shouldRefreshLiveGitData(
  16. {
  17. workspacePath: "/repo-a",
  18. workspaceKey: "/repo-a",
  19. includeExtendedData: false,
  20. refreshToken: 0,
  21. workspaceRpcEnabled: true,
  22. },
  23. {
  24. workspacePath: "/repo-b",
  25. workspaceKey: "/repo-b",
  26. includeExtendedData: false,
  27. refreshToken: 0,
  28. workspaceRpcEnabled: true,
  29. },
  30. ),
  31. ).toBe(true);
  32. });
  33. it("refreshes when the pane opens or user triggers an explicit refresh", () => {
  34. expect(
  35. shouldRefreshLiveGitData(
  36. {
  37. workspacePath: "/repo-a",
  38. workspaceKey: "/repo-a",
  39. includeExtendedData: false,
  40. refreshToken: 0,
  41. workspaceRpcEnabled: true,
  42. },
  43. {
  44. workspacePath: "/repo-a",
  45. workspaceKey: "/repo-a",
  46. includeExtendedData: true,
  47. refreshToken: 0,
  48. workspaceRpcEnabled: true,
  49. },
  50. ),
  51. ).toBe(true);
  52. expect(
  53. shouldRefreshLiveGitData(
  54. {
  55. workspacePath: "/repo-a",
  56. workspaceKey: "/repo-a",
  57. includeExtendedData: true,
  58. refreshToken: 0,
  59. workspaceRpcEnabled: true,
  60. },
  61. {
  62. workspacePath: "/repo-a",
  63. workspaceKey: "/repo-a",
  64. includeExtendedData: true,
  65. refreshToken: 1,
  66. workspaceRpcEnabled: true,
  67. },
  68. ),
  69. ).toBe(true);
  70. });
  71. it("refreshes when workspace identity changes even if the remote path is the same", () => {
  72. expect(
  73. shouldRefreshLiveGitData(
  74. {
  75. workspacePath: "/root",
  76. workspaceKey: "remote:ssh:root@server-a:/root",
  77. includeExtendedData: false,
  78. refreshToken: 0,
  79. workspaceRpcEnabled: true,
  80. },
  81. {
  82. workspacePath: "/root",
  83. workspaceKey: "remote:ssh:root@server-b:/root",
  84. includeExtendedData: false,
  85. refreshToken: 0,
  86. workspaceRpcEnabled: true,
  87. },
  88. ),
  89. ).toBe(true);
  90. });
  91. it("does not refresh when only the pane closes or task-local data changes", () => {
  92. expect(
  93. shouldRefreshLiveGitData(
  94. {
  95. workspacePath: "/repo-a",
  96. workspaceKey: "/repo-a",
  97. includeExtendedData: true,
  98. refreshToken: 1,
  99. workspaceRpcEnabled: true,
  100. },
  101. {
  102. workspacePath: "/repo-a",
  103. workspaceKey: "/repo-a",
  104. includeExtendedData: false,
  105. refreshToken: 1,
  106. workspaceRpcEnabled: true,
  107. },
  108. ),
  109. ).toBe(false);
  110. expect(
  111. shouldRefreshLiveGitData(
  112. {
  113. workspacePath: "/repo-a",
  114. workspaceKey: "/repo-a",
  115. includeExtendedData: false,
  116. refreshToken: 1,
  117. workspaceRpcEnabled: true,
  118. },
  119. {
  120. workspacePath: "/repo-a",
  121. workspaceKey: "/repo-a",
  122. includeExtendedData: false,
  123. refreshToken: 1,
  124. workspaceRpcEnabled: true,
  125. },
  126. ),
  127. ).toBe(false);
  128. });
  129. it("does not refresh disconnected remote placeholders until workspace RPC is available", () => {
  130. expect(
  131. shouldRefreshLiveGitData(null, {
  132. workspacePath: "/root",
  133. workspaceKey: "remote:ssh:root@server:/root",
  134. includeExtendedData: false,
  135. refreshToken: 0,
  136. workspaceRpcEnabled: false,
  137. }),
  138. ).toBe(false);
  139. expect(
  140. shouldRefreshLiveGitData(
  141. {
  142. workspacePath: "/root",
  143. workspaceKey: "remote:ssh:root@server:/root",
  144. includeExtendedData: false,
  145. refreshToken: 0,
  146. workspaceRpcEnabled: false,
  147. },
  148. {
  149. workspacePath: "/root",
  150. workspaceKey: "remote:ssh:root@server:/root",
  151. includeExtendedData: false,
  152. refreshToken: 0,
  153. workspaceRpcEnabled: true,
  154. },
  155. ),
  156. ).toBe(true);
  157. });
  158. });