@skyhook-io/radar-app 1.20.1 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +65 -16
  3. package/src/api/client.audit-gating.test.tsx +105 -5
  4. package/src/api/client.auditBadgesSync.test.tsx +118 -0
  5. package/src/api/client.capabilitiesPoll.test.ts +61 -0
  6. package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
  7. package/src/api/client.pauseDeployment.test.tsx +77 -0
  8. package/src/api/client.restartError.test.ts +14 -0
  9. package/src/api/client.revisionRefresh.test.tsx +44 -0
  10. package/src/api/client.rollbackError.test.ts +14 -0
  11. package/src/api/client.ts +347 -16
  12. package/src/api/namespaceScopeRetry.test.ts +14 -0
  13. package/src/api/networkAttachments.test.tsx +120 -0
  14. package/src/api/networkAttachments.ts +30 -0
  15. package/src/api/radarFeatures.test.ts +5 -0
  16. package/src/api/radarFeatures.ts +10 -0
  17. package/src/api/secretsStore.test.ts +33 -0
  18. package/src/api/secretsStore.ts +37 -0
  19. package/src/api/substrateHealth.ts +134 -0
  20. package/src/api/velero.test.ts +60 -0
  21. package/src/api/velero.ts +201 -0
  22. package/src/api/vulnerabilities.ts +255 -0
  23. package/src/components/ConnectionErrorView.test.tsx +11 -0
  24. package/src/components/ConnectionErrorView.tsx +19 -0
  25. package/src/components/ContextSwitcher.tsx +9 -2
  26. package/src/components/NamespaceSwitcher.tsx +3 -1
  27. package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
  28. package/src/components/applications/ApplicationsView.tsx +8 -11
  29. package/src/components/audit/AuditView.tsx +4 -0
  30. package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
  31. package/src/components/audit/ChecksViewTabs.tsx +11 -1
  32. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  33. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  34. package/src/components/audit/VulnerabilitiesView.tsx +907 -0
  35. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  36. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  37. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  38. package/src/components/cnpg/CNPGView.tsx +43 -117
  39. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  40. package/src/components/cnpg/host.tsx +2 -2
  41. package/src/components/cnpg/routes.ts +3 -1
  42. package/src/components/cnpg/shared.tsx +5 -53
  43. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  44. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  45. package/src/components/community.tsx +42 -0
  46. package/src/components/cost/CostView.tsx +27 -9
  47. package/src/components/diagnose/InvestigationView.tsx +12 -3
  48. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  49. package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
  50. package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
  51. package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
  52. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  53. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  54. package/src/components/diagnose/investigationMetrics.ts +2 -1
  55. package/src/components/dock/BottomDock.tsx +1 -0
  56. package/src/components/dock/LogsTab.tsx +3 -0
  57. package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
  58. package/src/components/dock/TerminalPreferences.test.tsx +68 -0
  59. package/src/components/dock/TerminalPreferences.tsx +73 -0
  60. package/src/components/gitops/GitOpsView.tsx +2 -10
  61. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  62. package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
  63. package/src/components/helm/HelmView.tsx +25 -19
  64. package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
  65. package/src/components/helm/NotCheckedBadge.tsx +39 -0
  66. package/src/components/helm/OwnedResources.test.tsx +86 -0
  67. package/src/components/helm/OwnedResources.tsx +69 -11
  68. package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
  69. package/src/components/home/ClusterHealthCard.test.ts +44 -1
  70. package/src/components/home/ClusterHealthCard.tsx +25 -11
  71. package/src/components/home/HelmSummary.tsx +15 -15
  72. package/src/components/home/HomeAgentBlock.tsx +3 -0
  73. package/src/components/home/HomeView.tsx +7 -0
  74. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  75. package/src/components/home/MCPSetupDialog.tsx +4 -2
  76. package/src/components/home/mcpToolCatalog.ts +17 -4
  77. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  78. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  79. package/src/components/logs/LogsViewer.tsx +3 -1
  80. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  81. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  82. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  83. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  84. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  85. package/src/components/resource/RightsizingStrip.test.ts +57 -0
  86. package/src/components/resource/RightsizingStrip.tsx +53 -4
  87. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  88. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  89. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  90. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  91. package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
  92. package/src/components/resources/ImageFilesystemModal.tsx +98 -6
  93. package/src/components/resources/PodFileUploadPanel.tsx +150 -0
  94. package/src/components/resources/PodFilesystemModal.tsx +246 -3
  95. package/src/components/resources/ResourcesView.tsx +12 -6
  96. package/src/components/resources/pod-file-upload.test.tsx +223 -0
  97. package/src/components/resources/pod-file-upload.ts +266 -0
  98. package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
  99. package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
  100. package/src/components/resources/renderers/PodRenderer.tsx +26 -1
  101. package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
  102. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  103. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  104. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  105. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  106. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  107. package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
  108. package/src/components/rightsizing/model.test.ts +11 -0
  109. package/src/components/rightsizing/model.ts +3 -1
  110. package/src/components/rightsizing/presentation.test.ts +46 -0
  111. package/src/components/rightsizing/presentation.ts +17 -2
  112. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  113. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  114. package/src/components/timeline/TimelineView.tsx +3 -1
  115. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  116. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  117. package/src/components/traffic/TrafficData.test.tsx +37 -0
  118. package/src/components/traffic/TrafficData.tsx +27 -0
  119. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  120. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  121. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  122. package/src/components/traffic/TrafficGraph.tsx +135 -64
  123. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  124. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  125. package/src/components/traffic/TrafficView.tsx +72 -155
  126. package/src/components/traffic/trafficFilters.test.ts +189 -1
  127. package/src/components/traffic/trafficFilters.ts +169 -1
  128. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  129. package/src/components/ui/Omnibar.tsx +4 -1
  130. package/src/components/ui/RadarOmnibar.test.tsx +55 -2
  131. package/src/components/ui/RadarOmnibar.tsx +7 -1
  132. package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
  133. package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
  134. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  135. package/src/components/ui/UpdateNotification.test.tsx +54 -3
  136. package/src/components/ui/UpdateNotification.tsx +60 -19
  137. package/src/components/ui/command-items.ts +24 -1
  138. package/src/components/ui/omnibar-match.test.ts +7 -0
  139. package/src/components/ui/omnibar-match.ts +1 -0
  140. package/src/components/ui/searchCoverageNote.test.ts +17 -0
  141. package/src/components/ui/searchCoverageNote.ts +31 -7
  142. package/src/components/useContextSwitchFlow.tsx +9 -1
  143. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  144. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  145. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  146. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  147. package/src/components/velero/VeleroDetailPage.tsx +148 -0
  148. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  149. package/src/components/velero/VeleroKindLists.tsx +43 -0
  150. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  151. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  152. package/src/components/velero/VeleroLocations.tsx +240 -0
  153. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  154. package/src/components/velero/VeleroOverview.tsx +485 -0
  155. package/src/components/velero/VeleroPages.test.tsx +516 -0
  156. package/src/components/velero/VeleroPages.tsx +1056 -0
  157. package/src/components/velero/VeleroRunLists.tsx +309 -0
  158. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  159. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  160. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  161. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  162. package/src/components/velero/VeleroSchedules.tsx +255 -0
  163. package/src/components/velero/VeleroView.tsx +59 -0
  164. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  165. package/src/components/velero/attention.test.ts +178 -0
  166. package/src/components/velero/attention.ts +281 -0
  167. package/src/components/velero/backupDelete.test.tsx +91 -0
  168. package/src/components/velero/backupDelete.tsx +182 -0
  169. package/src/components/velero/coverage.test.ts +87 -0
  170. package/src/components/velero/coverage.ts +150 -0
  171. package/src/components/velero/host.tsx +86 -0
  172. package/src/components/velero/routes.ts +78 -0
  173. package/src/components/velero/runs.tsx +121 -0
  174. package/src/components/velero/shared.test.ts +84 -0
  175. package/src/components/velero/shared.tsx +423 -0
  176. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  177. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  178. package/src/components/velero/velero.fixtures.ts +61 -0
  179. package/src/components/velero/workspaceRoute.ts +21 -0
  180. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
  181. package/src/components/vulnerabilities/parts.test.ts +72 -0
  182. package/src/components/vulnerabilities/parts.tsx +291 -0
  183. package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
  184. package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
  185. package/src/components/workload/WorkloadView.tsx +114 -37
  186. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  187. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  188. package/src/components/workspace/coverage.ts +61 -0
  189. package/src/components/workspace/layout.test.tsx +29 -1
  190. package/src/components/workspace/layout.tsx +15 -5
  191. package/src/components/workspace/sidebar.ts +9 -0
  192. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  193. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  194. package/src/context/ConnectionContext.test.ts +1 -0
  195. package/src/context/ConnectionContext.tsx +2 -2
  196. package/src/desktop/AboutDialog.test.ts +12 -0
  197. package/src/desktop/AboutDialog.tsx +151 -0
  198. package/src/desktop/WindowsTitleBar.tsx +359 -0
  199. package/src/desktop/titleBar.test.ts +61 -0
  200. package/src/desktop/titleBar.ts +45 -0
  201. package/src/index.css +19 -0
  202. package/src/integrations/resourceHost.ts +5 -1
  203. package/src/integrations/resourceHosts.test.tsx +15 -3
  204. package/src/integrations/resourceHosts.tsx +26 -6
  205. package/src/integrations/workspaceRoute.ts +1 -1
  206. package/src/integrations/workspaceRoutes.test.ts +11 -0
  207. package/src/integrations/workspaceRoutes.ts +3 -1
  208. package/src/integrations/workspaceScreens.tsx +2 -0
  209. package/src/main.tsx +8 -0
  210. package/src/utils/desktop-zoom.test.ts +53 -0
  211. package/src/utils/desktop-zoom.ts +30 -0
  212. package/src/utils/namespacePick.test.ts +87 -0
  213. package/src/utils/namespacePick.ts +88 -0
  214. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  215. package/src/utils/staleAssetPrompt.tsx +32 -0
@@ -3,7 +3,8 @@ import { act } from "react";
3
3
  import { createRoot } from "react-dom/client";
4
4
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
5
  import { afterEach, expect, it, vi } from "vitest";
6
- import { useSetActiveNamespace } from "./client";
6
+ import { useNamespaceScope, useSetActiveNamespace } from "./client";
7
+ import { readTabPick, writeTabPick } from "../utils/namespacePick";
7
8
 
8
9
  (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
9
10
 
@@ -52,3 +53,171 @@ it("keeps a timed-out rescope an error even when the scope already names its tar
52
53
  expect(outcome).toMatch(/rescope timed out/);
53
54
  expect(calls).not.toContain("GET /api/cluster/namespace-scope");
54
55
  });
56
+
57
+ const tabScope = { actives: [] as string[], context: "ctx-a", kubeconfigNamespace: "", mode: "cluster-wide", accessibleNamespaces: ["team-a", "team-b"], deniedNamespaces: [], authoritative: true, canClearNamespace: true, cacheScoped: false, namespaceRescope: false };
58
+
59
+ // Each POST answers when its gate opens, with the server's stored pick after
60
+ // the write, which another tab may already have changed.
61
+ function serveSwitches(serverActives: () => string[]) {
62
+ const gates: Array<() => void> = [];
63
+ vi.stubGlobal("fetch", vi.fn((_url: string, init?: RequestInit) => {
64
+ const body = () => new Response(JSON.stringify({ ...tabScope, actives: serverActives() }), { status: 200, headers: { "Content-Type": "application/json" } });
65
+ if (init?.method !== "POST") return Promise.resolve(body());
66
+ return new Promise<Response>(resolve => gates.push(() => resolve(body())));
67
+ }));
68
+ return gates;
69
+ }
70
+
71
+ function mountSwitcher(client: QueryClient) {
72
+ let mutate!: ReturnType<typeof useSetActiveNamespace>["mutateAsync"];
73
+ function Probe() {
74
+ mutate = useSetActiveNamespace().mutateAsync;
75
+ return null;
76
+ }
77
+ const root = createRoot(document.createElement("div"));
78
+ act(() => root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>));
79
+ return { mutate: (namespaces: string[]) => mutate({ namespaces }), unmount: () => act(() => root.unmount()) };
80
+ }
81
+
82
+ it("records the pick this tab asked for, not the one another tab stored meanwhile", async () => {
83
+ sessionStorage.clear();
84
+ const gates = serveSwitches(() => ["team-b"]);
85
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
86
+ client.setQueryData(["namespace-scope"], tabScope);
87
+ const { mutate, unmount } = mountSwitcher(client);
88
+ const done = mutate(["team-a", "team-a", ""]);
89
+ await vi.waitFor(() => expect(gates).toHaveLength(1));
90
+ gates[0]();
91
+ await done;
92
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-a"]);
93
+ expect(readTabPick("/api", "ctx-a")).toEqual(["team-a"]);
94
+ unmount();
95
+ });
96
+
97
+ it("ignores a switch that answers after a newer one", async () => {
98
+ sessionStorage.clear();
99
+ const gates = serveSwitches(() => []);
100
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
101
+ client.setQueryData(["namespace-scope"], tabScope);
102
+ const { mutate, unmount } = mountSwitcher(client);
103
+ const older = mutate(["team-b"]);
104
+ const newer = mutate([]);
105
+ await vi.waitFor(() => expect(gates).toHaveLength(2));
106
+ gates[1]();
107
+ await newer;
108
+ gates[0]();
109
+ await older;
110
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual([]);
111
+ expect(readTabPick("/api", "ctx-a")).toEqual([]);
112
+ unmount();
113
+ });
114
+
115
+ it("doesn't record a pick whose answer lands after a context switch", async () => {
116
+ sessionStorage.clear();
117
+ const gates = serveSwitches(() => []);
118
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
119
+ client.setQueryData(["namespace-scope"], tabScope);
120
+ const { mutate, unmount } = mountSwitcher(client);
121
+ const done = mutate(["team-a"]);
122
+ await vi.waitFor(() => expect(gates).toHaveLength(1));
123
+ client.setQueryData(["namespace-scope"], { ...tabScope, context: "ctx-b" });
124
+ gates[0]();
125
+ await done;
126
+ expect(client.getQueryData<{ context: string }>(["namespace-scope"])?.context).toBe("ctx-b");
127
+ expect(readTabPick("/api", "ctx-a")).toBeUndefined();
128
+ unmount();
129
+ });
130
+
131
+ it("drops a requested namespace the answer shows is gone", async () => {
132
+ sessionStorage.clear();
133
+ const gates = serveSwitches(() => ["team-a"]);
134
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
135
+ client.setQueryData(["namespace-scope"], tabScope);
136
+ const { mutate, unmount } = mountSwitcher(client);
137
+ const done = mutate(["team-a", "deleted-meanwhile"]);
138
+ await vi.waitFor(() => expect(gates).toHaveLength(1));
139
+ gates[0]();
140
+ await done;
141
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-a"]);
142
+ expect(readTabPick("/api", "ctx-a")).toEqual(["team-a"]);
143
+ unmount();
144
+ });
145
+
146
+ // A tab with the scope query mounted, as App has it, so an error refetches.
147
+ function mountTab(client: QueryClient) {
148
+ let mutate!: ReturnType<typeof useSetActiveNamespace>["mutateAsync"];
149
+ function Probe() {
150
+ useNamespaceScope();
151
+ mutate = useSetActiveNamespace().mutateAsync;
152
+ return null;
153
+ }
154
+ const root = createRoot(document.createElement("div"));
155
+ act(() => root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>));
156
+ return { mutate: (namespaces: string[]) => mutate({ namespaces }), unmount: () => act(() => root.unmount()) };
157
+ }
158
+
159
+ const json = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status, headers: { "Content-Type": "application/json" } });
160
+
161
+ it("keeps an accepted clear when a newer pick is refused", async () => {
162
+ sessionStorage.clear();
163
+ writeTabPick("/api", "ctx-a", ["team-a"]);
164
+ let server = ["team-a"];
165
+ let releaseClear!: () => void;
166
+ vi.stubGlobal("fetch", vi.fn((_url: string, init?: RequestInit) => {
167
+ if (init?.method !== "POST") return Promise.resolve(json({ ...tabScope, actives: server }));
168
+ const { namespaces } = JSON.parse(String(init.body)) as { namespaces: string[] };
169
+ if (namespaces.includes("secret-ns")) return Promise.resolve(json({ error: "no access to namespace secret-ns" }, 403));
170
+ return new Promise<Response>(resolve => { releaseClear = () => { server = namespaces; resolve(json({ ...tabScope, actives: server })); }; });
171
+ }));
172
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
173
+ const { mutate, unmount } = mountTab(client);
174
+ await vi.waitFor(() => expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-a"]));
175
+ const clear = mutate([]);
176
+ await vi.waitFor(() => expect(releaseClear).toBeDefined());
177
+ await mutate(["secret-ns"]).catch(() => undefined);
178
+ releaseClear();
179
+ await clear;
180
+ await vi.waitFor(() => expect(client.isFetching()).toBe(0));
181
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual([]);
182
+ expect(readTabPick("/api", "ctx-a")).toEqual([]);
183
+ unmount();
184
+ });
185
+
186
+ it("keeps a switch the server applied when its answer is lost", async () => {
187
+ sessionStorage.clear();
188
+ writeTabPick("/api", "ctx-a", ["team-a"]);
189
+ let server = ["team-a"];
190
+ vi.stubGlobal("fetch", vi.fn((_url: string, init?: RequestInit) => {
191
+ if (init?.method !== "POST") return Promise.resolve(json({ ...tabScope, actives: server }));
192
+ server = (JSON.parse(String(init.body)) as { namespaces: string[] }).namespaces;
193
+ return Promise.reject(new TypeError("Failed to fetch"));
194
+ }));
195
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
196
+ const { mutate, unmount } = mountTab(client);
197
+ await vi.waitFor(() => expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-a"]));
198
+ await mutate(["team-b"]).catch(() => undefined);
199
+ await vi.waitFor(() => expect(client.isFetching()).toBe(0));
200
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-b"]);
201
+ expect(readTabPick("/api", "ctx-a")).toEqual(["team-b"]);
202
+ unmount();
203
+ });
204
+
205
+ it("keeps a switch the server applied when its answer's body is lost", async () => {
206
+ sessionStorage.clear();
207
+ writeTabPick("/api", "ctx-a", ["team-a"]);
208
+ let server = ["team-a"];
209
+ vi.stubGlobal("fetch", vi.fn((_url: string, init?: RequestInit) => {
210
+ if (init?.method !== "POST") return Promise.resolve(json({ ...tabScope, actives: server }));
211
+ server = (JSON.parse(String(init.body)) as { namespaces: string[] }).namespaces;
212
+ const body = new ReadableStream({ start(controller) { controller.error(new TypeError("network error")); } });
213
+ return Promise.resolve(new Response(body, { status: 200, headers: { "Content-Type": "application/json" } }));
214
+ }));
215
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } });
216
+ const { mutate, unmount } = mountTab(client);
217
+ await vi.waitFor(() => expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-a"]));
218
+ await mutate(["team-b"]).catch(() => undefined);
219
+ await vi.waitFor(() => expect(client.isFetching()).toBe(0));
220
+ expect(client.getQueryData<{ actives: string[] }>(["namespace-scope"])?.actives).toEqual(["team-b"]);
221
+ expect(readTabPick("/api", "ctx-a")).toEqual(["team-b"]);
222
+ unmount();
223
+ });
@@ -0,0 +1,77 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot } from 'react-dom/client'
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
+ import { afterEach, beforeEach, expect, it, vi } from 'vitest'
6
+ import { usePauseDeployment, useRadarFeature, useResumeDeployment } from './client'
7
+ import { isRadarFeatureUnsupported } from './radarFeatures'
8
+
9
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
10
+ beforeEach(() => {
11
+ vi.spyOn(console, 'log').mockImplementation(() => {})
12
+ })
13
+ afterEach(() => {
14
+ vi.unstubAllGlobals()
15
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
16
+ vi.restoreAllMocks()
17
+ })
18
+
19
+ const target = { kind: 'deployments', namespace: 'prod', name: 'web' }
20
+
21
+ async function run(action: 'pause' | 'resume', features: Record<string, boolean>, response = new Response('{"message":"ok"}', { status: 200 })) {
22
+ const posts: string[] = []
23
+ vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input, init) => {
24
+ const url = String(input)
25
+ if (init?.method === 'POST') {
26
+ posts.push(url)
27
+ return response
28
+ }
29
+ if (url.includes('/capabilities')) return new Response(JSON.stringify({ features }), { status: 200 })
30
+ return new Response('{}', { status: 200 })
31
+ }))
32
+
33
+ const client = new QueryClient({ defaultOptions: { mutations: { retry: false }, queries: { retry: false } } })
34
+ const invalidate = vi.spyOn(client, 'invalidateQueries')
35
+ let mutate: (() => Promise<unknown>) | undefined
36
+ let support = ''
37
+ function Probe() {
38
+ const pause = usePauseDeployment()
39
+ const resume = useResumeDeployment()
40
+ support = useRadarFeature('deploymentPause').support
41
+ mutate = () => (action === 'pause' ? pause : resume).mutateAsync(target)
42
+ return null
43
+ }
44
+ const root = createRoot(document.createElement('div'))
45
+ await act(async () => { root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>) })
46
+ await vi.waitFor(() => expect(support).not.toBe('unknown'))
47
+
48
+ let failure: unknown
49
+ await act(async () => { try { await mutate!() } catch (err) { failure = err } })
50
+ const invalidated = invalidate.mock.calls.map(([filters]) => JSON.stringify(filters?.queryKey))
51
+ act(() => root.unmount())
52
+ client.clear()
53
+ return { posts, failure, invalidated }
54
+ }
55
+
56
+ it.each(['pause', 'resume'] as const)('%s posts to its route and refreshes the open Deployment', async (action) => {
57
+ const { posts, failure, invalidated } = await run(action, { deploymentPause: true })
58
+
59
+ expect(failure).toBeUndefined()
60
+ expect(posts).toHaveLength(1)
61
+ expect(posts[0]).toContain(`/api/workloads/deployments/prod/web/${action}`)
62
+ expect(invalidated).toContain(JSON.stringify(['resource', 'deployments', 'prod', 'web']))
63
+ expect(invalidated).toContain(JSON.stringify(['resources', 'deployments']))
64
+ })
65
+
66
+ it('surfaces the server error', async () => {
67
+ const { failure } = await run('pause', { deploymentPause: true }, new Response('{"error":"nope"}', { status: 403 }))
68
+
69
+ expect((failure as Error).message).toBe('nope')
70
+ })
71
+
72
+ it('sends nothing to a Radar that predates the routes', async () => {
73
+ const { posts, failure } = await run('pause', { workloadImages: true })
74
+
75
+ expect(posts).toHaveLength(0)
76
+ expect(isRadarFeatureUnsupported(failure, 'deploymentPause')).toBe(true)
77
+ })
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { restartErrorMessage } from './client'
3
+
4
+ describe('restartErrorMessage', () => {
5
+ it('points a paused refusal at the Resume rollout button instead of the server text', () => {
6
+ const msg = restartErrorMessage({ error: 'Deployment ns/web: the Deployment is paused, so a restart would not roll out; resume it, then restart', error_code: 'workload_paused' }, 409)
7
+ expect(msg).toContain('Resume rollout')
8
+ expect(msg).not.toContain('ns/web')
9
+ })
10
+ it('keeps the server text for every other failure', () => {
11
+ expect(restartErrorMessage({ error: 'deployments.apps "web" not found' }, 404)).toBe('deployments.apps "web" not found')
12
+ expect(restartErrorMessage({}, 500)).toBe('HTTP 500')
13
+ })
14
+ })
@@ -0,0 +1,44 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot } from 'react-dom/client'
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
+ import { expect, it, vi } from 'vitest'
6
+ import { useRefreshRevisionsOnNewRollout } from './client'
7
+
8
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
9
+
10
+ async function observe(revisions: (string | undefined)[]) {
11
+ const client = new QueryClient()
12
+ const invalidate = vi.spyOn(client, 'invalidateQueries')
13
+ function Probe({ revision }: { revision?: string }) {
14
+ useRefreshRevisionsOnNewRollout('deployments', 'prod', 'web', revision)
15
+ return null
16
+ }
17
+ const root = createRoot(document.createElement('div'))
18
+ for (const revision of revisions) {
19
+ await act(async () => {
20
+ root.render(<QueryClientProvider client={client}><Probe revision={revision} /></QueryClientProvider>)
21
+ })
22
+ }
23
+ act(() => root.unmount())
24
+ client.clear()
25
+ return invalidate
26
+ }
27
+
28
+ it('refreshes the revision list when the Deployment records a new revision', async () => {
29
+ const invalidate = await observe(['1', '2'])
30
+
31
+ expect(invalidate).toHaveBeenCalledExactlyOnceWith({ queryKey: ['workload-revisions', 'deployments', 'prod', 'web'] })
32
+ })
33
+
34
+ it('refreshes when a Deployment created paused records its first revision', async () => {
35
+ expect(await observe(['', '2'])).toHaveBeenCalledTimes(1)
36
+ })
37
+
38
+ it('leaves the list alone while the revision stays the same', async () => {
39
+ expect(await observe(['1', '1', '1'])).not.toHaveBeenCalled()
40
+ })
41
+
42
+ it('leaves the list alone when the resource first loads', async () => {
43
+ expect(await observe([undefined, '2'])).not.toHaveBeenCalled()
44
+ })
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { rollbackErrorMessage } from './client'
3
+
4
+ describe('rollbackErrorMessage', () => {
5
+ it('points a paused refusal at the Resume rollout button instead of the server text', () => {
6
+ const msg = rollbackErrorMessage({ error: 'Deployment ns/web: the Deployment is paused, so a rollback would not roll out; resume it, then roll back', error_code: 'workload_paused' }, 409)
7
+ expect(msg).toContain('Resume rollout')
8
+ expect(msg).not.toContain('ns/web')
9
+ })
10
+ it('keeps the server text for every other failure', () => {
11
+ expect(rollbackErrorMessage({ error: 'revision 9 not found' }, 404)).toBe('revision 9 not found')
12
+ expect(rollbackErrorMessage({}, 500)).toBe('HTTP 500')
13
+ })
14
+ })