@skyhook-io/radar-app 1.22.1 → 1.23.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 (234) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +131 -38
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/RadarApp.tsx +5 -0
  6. package/src/api/agentSandbox.ts +259 -0
  7. package/src/api/client.autoPromConnect.test.tsx +43 -0
  8. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  9. package/src/api/client.ts +128 -25
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/prometheusCharts.ts +5 -0
  15. package/src/api/radarFeatures.test.ts +9 -0
  16. package/src/api/radarFeatures.ts +13 -0
  17. package/src/api/substrateWorkspace.test.ts +72 -0
  18. package/src/api/substrateWorkspace.ts +1394 -0
  19. package/src/api/vulnerabilities.ts +207 -9
  20. package/src/api/workloadSource.test.tsx +1172 -0
  21. package/src/api/workloadSource.ts +408 -0
  22. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  23. package/src/components/APIUnreachableBanner.tsx +20 -0
  24. package/src/components/CloudConnectFlow.tsx +46 -7
  25. package/src/components/CloudFunnelButton.test.tsx +193 -7
  26. package/src/components/CloudFunnelButton.tsx +127 -32
  27. package/src/components/ConnectionErrorView.test.tsx +63 -2
  28. package/src/components/ConnectionErrorView.tsx +88 -68
  29. package/src/components/SelfManagedStart.tsx +12 -2
  30. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  31. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  32. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  33. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  34. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  35. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  36. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  37. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  38. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  39. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  40. package/src/components/agentsandbox/data.ts +135 -0
  41. package/src/components/agentsandbox/host.test.ts +27 -0
  42. package/src/components/agentsandbox/host.tsx +85 -0
  43. package/src/components/agentsandbox/labels.test.ts +42 -0
  44. package/src/components/agentsandbox/labels.ts +146 -0
  45. package/src/components/agentsandbox/listFilters.ts +85 -0
  46. package/src/components/agentsandbox/lists.ts +52 -0
  47. package/src/components/agentsandbox/routes.ts +23 -0
  48. package/src/components/agentsandbox/shared.tsx +321 -0
  49. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  50. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  51. package/src/components/agentsandbox/workspace.tsx +258 -0
  52. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  53. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  54. package/src/components/applications/ApplicationsView.tsx +156 -3
  55. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  56. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  57. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  58. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  59. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  60. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  61. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  62. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  63. package/src/components/cloudHints/cloudHints.ts +131 -0
  64. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  65. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  66. package/src/components/cloudHints/cloudLinks.ts +31 -0
  67. package/src/components/cloudHints/hintStorage.ts +28 -0
  68. package/src/components/cnpg/CNPGView.tsx +4 -7
  69. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  70. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  71. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  72. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  73. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  74. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  75. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  76. package/src/components/diagnose/Home.test.tsx +6 -0
  77. package/src/components/diagnose/Home.tsx +10 -3
  78. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  79. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  80. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  81. package/src/components/diagnose/InvestigationView.tsx +120 -23
  82. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  83. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  84. package/src/components/diagnose/investigationState.ts +9 -0
  85. package/src/components/diagnose/parts.test.tsx +11 -3
  86. package/src/components/diagnose/toolCallLabel.ts +3 -0
  87. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  88. package/src/components/home/ActivitySummary.tsx +3 -8
  89. package/src/components/home/ClusterHealthCard.tsx +91 -17
  90. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  91. package/src/components/home/HomeAgentBlock.tsx +2 -0
  92. package/src/components/home/HomeView.tsx +9 -29
  93. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  94. package/src/components/home/MCPSetupDialog.tsx +6 -2
  95. package/src/components/home/McpCloudLine.test.tsx +162 -0
  96. package/src/components/home/McpCloudLine.tsx +95 -0
  97. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  98. package/src/components/home/TopologyPreview.test.tsx +31 -30
  99. package/src/components/home/TopologyPreview.tsx +19 -28
  100. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  101. package/src/components/home/mcpToolCatalog.ts +7 -7
  102. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  103. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  104. package/src/components/issues/IssuesPane.tsx +181 -23
  105. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  106. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  107. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  108. package/src/components/issues/sinceLastVisit.ts +439 -0
  109. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  110. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  111. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  112. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  113. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  114. package/src/components/kagent/KagentLists.tsx +412 -0
  115. package/src/components/kagent/KagentOverview.tsx +234 -0
  116. package/src/components/kagent/KagentPages.tsx +690 -0
  117. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  118. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  119. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  120. package/src/components/kagent/KagentView.tsx +109 -0
  121. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  122. package/src/components/kagent/host.tsx +144 -0
  123. package/src/components/kagent/routes.ts +31 -0
  124. package/src/components/kagent/shared.tsx +336 -0
  125. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  126. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  127. package/src/components/kagent/workspace.fixtures.ts +108 -0
  128. package/src/components/kagent/workspaceRoute.ts +18 -0
  129. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  130. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  131. package/src/components/resource/PrometheusCharts.tsx +10 -1
  132. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  133. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  134. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  135. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  136. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  137. package/src/components/resources/ResourcesView.tsx +2 -6
  138. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  139. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  140. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  141. package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
  142. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  143. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  144. package/src/components/settings/SettingsDialog.tsx +84 -16
  145. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  146. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  147. package/src/components/settings/SubstrateSettings.tsx +544 -0
  148. package/src/components/settings/settings-state.test.ts +21 -3
  149. package/src/components/settings/settings-state.ts +13 -3
  150. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  151. package/src/components/share/ShareLinkButton.tsx +391 -0
  152. package/src/components/share/openShareInCloud.test.ts +29 -0
  153. package/src/components/share/openShareInCloud.ts +10 -0
  154. package/src/components/share/shareLink.test.ts +129 -0
  155. package/src/components/share/shareLink.ts +175 -0
  156. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  157. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  158. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  159. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  160. package/src/components/substrate/SubstrateActors.tsx +612 -0
  161. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  162. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  163. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  164. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  165. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  166. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  167. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  168. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  169. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  170. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  171. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  172. package/src/components/substrate/SubstrateView.tsx +173 -0
  173. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  174. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  175. package/src/components/substrate/attention.ts +81 -0
  176. package/src/components/substrate/contextPin.tsx +69 -0
  177. package/src/components/substrate/host.tsx +83 -0
  178. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  179. package/src/components/substrate/readings.test.ts +484 -0
  180. package/src/components/substrate/readings.ts +997 -0
  181. package/src/components/substrate/routes.ts +103 -0
  182. package/src/components/substrate/shared.tsx +426 -0
  183. package/src/components/substrate/substrate.fixtures.ts +325 -0
  184. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  185. package/src/components/substrate/workspaceRoute.ts +23 -0
  186. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  187. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  188. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  189. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  190. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  191. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  192. package/src/components/traffic/TrafficGraph.tsx +17 -14
  193. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  194. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  195. package/src/components/traffic/TrafficView.tsx +26 -56
  196. package/src/components/traffic/trafficFilters.test.ts +61 -1
  197. package/src/components/traffic/trafficFilters.ts +68 -8
  198. package/src/components/velero/VeleroOverview.tsx +2 -2
  199. package/src/components/velero/VeleroView.tsx +3 -6
  200. package/src/components/vulnerabilities/columns.tsx +132 -0
  201. package/src/components/vulnerabilities/filters.tsx +317 -0
  202. package/src/components/vulnerabilities/owner.test.ts +54 -0
  203. package/src/components/vulnerabilities/owner.tsx +163 -0
  204. package/src/components/vulnerabilities/parts.test.ts +126 -12
  205. package/src/components/vulnerabilities/parts.tsx +612 -52
  206. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  207. package/src/components/vulnerabilities/traffic.tsx +40 -0
  208. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  209. package/src/components/workload/WorkloadView.tsx +119 -14
  210. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  211. package/src/components/workspace/layout.tsx +13 -7
  212. package/src/components/workspace/sidebar.test.ts +48 -0
  213. package/src/components/workspace/sidebar.ts +73 -3
  214. package/src/components/workspace/table.ts +2 -1
  215. package/src/context/ConnectionContext.tsx +24 -5
  216. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  217. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  218. package/src/context/DiagnoseCustomization.tsx +20 -2
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/hooks/useEventSource.test.tsx +275 -4
  222. package/src/hooks/useEventSource.ts +278 -51
  223. package/src/index.ts +1 -0
  224. package/src/integrations/resourceHost.ts +12 -6
  225. package/src/integrations/resourceHosts.test.tsx +27 -1
  226. package/src/integrations/resourceHosts.tsx +15 -7
  227. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  228. package/src/integrations/sidebarWorkspaces.ts +41 -0
  229. package/src/integrations/workspaceRoute.ts +1 -1
  230. package/src/integrations/workspaceRoutes.ts +7 -1
  231. package/src/integrations/workspaceScreens.tsx +6 -0
  232. package/src/utils/navigation.test.ts +1 -6
  233. package/src/utils/navigation.ts +9 -44
  234. package/src/utils/network-policy-navigation.test.ts +21 -36
@@ -9,8 +9,10 @@ class TestStream extends EventTarget {
9
9
  onopen?: () => void
10
10
  onerror?: () => void
11
11
  close = vi.fn()
12
- constructor() {
12
+ params: URLSearchParams
13
+ constructor(url: string) {
13
14
  super()
15
+ this.params = new URL(url, 'http://radar.test').searchParams
14
16
  TestStream.opened.push(this)
15
17
  }
16
18
  send(type: string, data: unknown) {
@@ -23,11 +25,14 @@ const hook = createRef<ReturnType<typeof useEventSource>>()
23
25
  const changed = vi.fn()
24
26
  const complete = vi.fn()
25
27
  const eventReceived = vi.fn()
26
- function Probe() {
27
- const result = useEventSource([], 'resources', { onContextChanged: changed, onContextSwitchComplete: complete, onK8sEvent: eventReceived })
28
+ const connectionState = vi.fn()
29
+ const deferredReady = vi.fn()
30
+ function Probe({ wantsTopology = true, viewMode = 'resources' as 'resources' | 'traffic', filter = undefined as string[] | undefined }) {
31
+ const result = useEventSource([], viewMode, { onContextChanged: changed, onContextSwitchComplete: complete, onK8sEvent: eventReceived, onConnectionStateChange: connectionState, onDeferredReady: deferredReady }, filter, false, wantsTopology)
28
32
  useImperativeHandle(hook, () => result, [result])
29
33
  return null
30
34
  }
35
+ const render = (props: Parameters<typeof Probe>[0]) => act(() => root.render(<Probe {...props} />))
31
36
 
32
37
  beforeEach(() => {
33
38
  vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
@@ -35,7 +40,7 @@ beforeEach(() => {
35
40
  TestStream.opened = []
36
41
  vi.clearAllMocks()
37
42
  root = createRoot(document.createElement('div'))
38
- act(() => root.render(<Probe />))
43
+ render({})
39
44
  })
40
45
  afterEach(() => {
41
46
  act(() => root.unmount())
@@ -83,3 +88,269 @@ test('an ordered stream completion keeps its target topology when the matching p
83
88
  expect(complete).toHaveBeenCalledOnce()
84
89
  expect(hook.current!.topology?.nodes[0].id).toBe('target')
85
90
  })
91
+
92
+ test('a tab asks for topology frames, and the view that shapes them, only while it draws the graph', () => {
93
+ expect(TestStream.opened[0].params.get('topology')).toBe('1')
94
+ render({ wantsTopology: false, viewMode: 'traffic' })
95
+ const off = TestStream.opened[1]
96
+ expect(off.params.has('topology')).toBe(false)
97
+ expect(off.params.has('view')).toBe(false)
98
+ render({ wantsTopology: true, viewMode: 'traffic' })
99
+ const on = TestStream.opened[2]
100
+ expect(on.params.get('topology')).toBe('1')
101
+ expect(on.params.get('view')).toBe('traffic')
102
+ })
103
+
104
+ test('status comes from topology_status, and its arrival ends a switch wait', () => {
105
+ render({ wantsTopology: false })
106
+ act(() => hook.current!.applyContextChange('target', 'op'))
107
+ expect(hook.current!.topologyStatus).toBeNull()
108
+ const stream = TestStream.opened.at(-1)!
109
+ act(() => stream.send('topology_status', { requiresNamespaceFilter: true, crdDiscoveryStatus: 'discovering' }))
110
+ expect(complete).toHaveBeenCalledOnce()
111
+ expect(hook.current!.topologyStatus).toEqual({ requiresNamespaceFilter: true, crdDiscoveryStatus: 'discovering' })
112
+ expect(hook.current!.topology).toBeNull()
113
+ })
114
+
115
+ test('an older Radar that sends every tab the graph feeds status and switch completion, not the graph', () => {
116
+ render({ wantsTopology: false })
117
+ act(() => hook.current!.applyContextChange('target', 'op'))
118
+ const stream = TestStream.opened.at(-1)!
119
+ act(() => stream.send('topology', { nodes: [{ id: 'unwanted' }], edges: [], requiresNamespaceFilter: true, crdDiscoveryStatus: 'ready' }))
120
+ expect(complete).toHaveBeenCalledOnce()
121
+ expect(hook.current!.topology).toBeNull()
122
+ expect(hook.current!.topologyStatus).toEqual({ requiresNamespaceFilter: true, crdDiscoveryStatus: 'ready' })
123
+ })
124
+
125
+ test('new parameters hand over: the old stream delivers until the new one starts, which is not a reconnect', () => {
126
+ const old = TestStream.opened[0]
127
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
128
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
129
+ render({ wantsTopology: false })
130
+ const next = TestStream.opened[1]
131
+ expect(old.close).not.toHaveBeenCalled()
132
+ act(() => old.send('k8s_event', { name: 'during-handover' }))
133
+ expect(eventReceived).toHaveBeenCalledOnce()
134
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
135
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: true })
136
+ expect(hook.current!.connected).toBe(true)
137
+ })
138
+
139
+ // Old stream live, new parameters, new stream promoted: the old one drains.
140
+ function handOver() {
141
+ const old = TestStream.opened.at(-1)!
142
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
143
+ render({ wantsTopology: false })
144
+ const next = TestStream.opened.at(-1)!
145
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
146
+ return { old, next }
147
+ }
148
+
149
+ test('a change the old stream had queued before the new one subscribed still arrives; it closes once the new one reads', () => {
150
+ vi.useFakeTimers()
151
+ try {
152
+ const { old, next } = handOver()
153
+ act(() => old.send('k8s_event', { name: 'queued-behind-a-large-frame' }))
154
+ expect(eventReceived).toHaveBeenCalledOnce()
155
+ act(() => old.send('topology_status', { requiresNamespaceFilter: true }))
156
+ expect(hook.current!.topologyStatus?.requiresNamespaceFilter).not.toBe(true)
157
+ act(() => vi.advanceTimersByTime(3000))
158
+ // Still building its first frame: not yet reading its own changes.
159
+ expect(old.close).not.toHaveBeenCalled()
160
+ act(() => next.send('topology_status', { requiresNamespaceFilter: false }))
161
+ expect(old.close).toHaveBeenCalledOnce()
162
+ act(() => old.send('k8s_event', { name: 'after-close' }))
163
+ expect(eventReceived).toHaveBeenCalledOnce()
164
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: true })
165
+ } finally {
166
+ vi.useRealTimers()
167
+ }
168
+ })
169
+
170
+ test('a drain whose new stream never starts reading ends as a reconnect', () => {
171
+ vi.useFakeTimers()
172
+ try {
173
+ const { old } = handOver()
174
+ act(() => vi.advanceTimersByTime(30_000))
175
+ expect(old.close).toHaveBeenCalledOnce()
176
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
177
+ } finally {
178
+ vi.useRealTimers()
179
+ }
180
+ })
181
+
182
+ test('an old stream that fails while draining ends as a reconnect', () => {
183
+ const { old } = handOver()
184
+ act(() => old.onerror?.())
185
+ expect(old.close).toHaveBeenCalled()
186
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
187
+ })
188
+
189
+ test('a second handover while the first still drains is not a handover', () => {
190
+ const { old, next } = handOver()
191
+ render({ wantsTopology: true })
192
+ const third = TestStream.opened.at(-1)!
193
+ act(() => third.send('connection_state', { state: 'connected', context: 'c' }))
194
+ expect(old.close).toHaveBeenCalled()
195
+ expect(next.close).toHaveBeenCalled()
196
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
197
+ })
198
+
199
+ test('deferred readiness counts from a draining stream', () => {
200
+ const { old } = handOver()
201
+ act(() => old.send('deferred_ready', {}))
202
+ expect(deferredReady).toHaveBeenCalledOnce()
203
+ })
204
+
205
+ test('a namespace filter change reconnects instead of handing over', () => {
206
+ const old = TestStream.opened[0]
207
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
208
+ render({ filter: ['shop'] })
209
+ expect(old.close).toHaveBeenCalled()
210
+ const next = TestStream.opened.at(-1)!
211
+ expect(next.params.get('namespaces')).toBe('shop')
212
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
213
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
214
+ })
215
+
216
+ test('a cluster switch that reaches only the draining stream reconnects', () => {
217
+ const old = TestStream.opened[0]
218
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
219
+ render({ wantsTopology: false })
220
+ const next = TestStream.opened[1]
221
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
222
+ act(() => old.send('context_changed', { context: 'target', switchId: 'op' }))
223
+ expect(changed).toHaveBeenCalledOnce()
224
+ expect(next.close).toHaveBeenCalled()
225
+ expect(old.close).toHaveBeenCalled()
226
+ expect(TestStream.opened).toHaveLength(3)
227
+ })
228
+
229
+ test('a handover stream that fails before delivering falls back to a hard reconnect', () => {
230
+ vi.useFakeTimers()
231
+ try {
232
+ const old = TestStream.opened[0]
233
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
234
+ render({ wantsTopology: false })
235
+ const next = TestStream.opened[1]
236
+ act(() => next.onerror?.())
237
+ expect(next.close).toHaveBeenCalled()
238
+ expect(old.close).toHaveBeenCalled()
239
+ expect(hook.current!.connected).toBe(false)
240
+ act(() => vi.advanceTimersByTime(3000))
241
+ const retry = TestStream.opened[2]
242
+ expect(retry.params.has('topology')).toBe(false)
243
+ } finally {
244
+ vi.useRealTimers()
245
+ }
246
+ })
247
+
248
+ test('a stream that dropped is not handed over: a parameter change during backoff reconnects at once, as a reconnect', () => {
249
+ vi.useFakeTimers()
250
+ try {
251
+ const old = TestStream.opened[0]
252
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
253
+ act(() => old.onerror?.())
254
+ render({ wantsTopology: false })
255
+ const next = TestStream.opened[1]
256
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
257
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
258
+ act(() => vi.advanceTimersByTime(30_000))
259
+ expect(TestStream.opened).toHaveLength(2)
260
+ } finally {
261
+ vi.useRealTimers()
262
+ }
263
+ })
264
+
265
+ test('a handover whose old stream dropped first is not reported as one', () => {
266
+ const old = TestStream.opened[0]
267
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
268
+ render({ wantsTopology: false })
269
+ const next = TestStream.opened[1]
270
+ act(() => old.onerror?.())
271
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
272
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
273
+ })
274
+
275
+ test('a cluster switch during a handover drops the new stream, which may hold the old cluster’s frames', () => {
276
+ const old = TestStream.opened[0]
277
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
278
+ render({ wantsTopology: false })
279
+ const pending = TestStream.opened[1]
280
+ act(() => old.send('context_changed', { context: 'target', switchId: 'op' }))
281
+ expect(pending.close).toHaveBeenCalled()
282
+ const fresh = TestStream.opened[2]
283
+ expect(fresh).toBeDefined()
284
+ act(() => pending.send('topology_status', { requiresNamespaceFilter: true }))
285
+ expect(complete).not.toHaveBeenCalled()
286
+ act(() => fresh.send('topology_status', { requiresNamespaceFilter: false }))
287
+ expect(complete).toHaveBeenCalledOnce()
288
+ expect(hook.current!.topologyStatus?.requiresNamespaceFilter).toBe(false)
289
+ })
290
+
291
+ test('a failed handover clears the graph it was replacing', () => {
292
+ const old = TestStream.opened[0]
293
+ act(() => old.send('topology', { nodes: [{ id: 'graph' }], edges: [] }))
294
+ expect(hook.current!.topology).not.toBeNull()
295
+ render({ wantsTopology: false })
296
+ act(() => TestStream.opened[1].onerror?.())
297
+ expect(hook.current!.topology).toBeNull()
298
+ })
299
+
300
+ test('a new stream’s first graph shows at once, not after the previous stream’s throttle', () => {
301
+ const old = TestStream.opened[0]
302
+ act(() => old.send('topology', { nodes: [{ id: 'resources-view' }], edges: [] }))
303
+ render({ wantsTopology: true, viewMode: 'traffic' })
304
+ const next = TestStream.opened[1]
305
+ act(() => {
306
+ next.send('connection_state', { state: 'connected', context: 'c' })
307
+ next.send('topology', { nodes: [{ id: 'traffic-view' }], edges: [] })
308
+ })
309
+ expect(hook.current!.topology?.nodes[0].id).toBe('traffic-view')
310
+ })
311
+
312
+ test('a parameter change while a reconnect is still connecting is not a handover', () => {
313
+ vi.useFakeTimers()
314
+ try {
315
+ const old = TestStream.opened[0]
316
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
317
+ act(() => old.onerror?.())
318
+ act(() => vi.advanceTimersByTime(3000))
319
+ const reconnecting = TestStream.opened[1]
320
+ render({ wantsTopology: false })
321
+ expect(reconnecting.close).toHaveBeenCalled()
322
+ const next = TestStream.opened[2]
323
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
324
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
325
+ } finally {
326
+ vi.useRealTimers()
327
+ }
328
+ })
329
+
330
+ test('a reconnect that opened but hasn’t reported its state is not handed over from', () => {
331
+ vi.useFakeTimers()
332
+ try {
333
+ const old = TestStream.opened[0]
334
+ act(() => old.send('connection_state', { state: 'connected', context: 'c' }))
335
+ act(() => old.onerror?.())
336
+ act(() => vi.advanceTimersByTime(3000))
337
+ const reconnecting = TestStream.opened[1]
338
+ act(() => reconnecting.onopen?.())
339
+ render({ wantsTopology: false })
340
+ expect(reconnecting.close).toHaveBeenCalled()
341
+ const next = TestStream.opened[2]
342
+ act(() => next.send('connection_state', { state: 'connected', context: 'c' }))
343
+ expect(connectionState).toHaveBeenLastCalledWith({ state: 'connected', context: 'c' }, { handover: false })
344
+ } finally {
345
+ vi.useRealTimers()
346
+ }
347
+ })
348
+
349
+ test('a cluster switch on the new stream ends the drain', () => {
350
+ const { old, next } = handOver()
351
+ act(() => next.send('context_changed', { context: 'target' }))
352
+ expect(changed).toHaveBeenCalledOnce()
353
+ expect(old.close).toHaveBeenCalled()
354
+ act(() => old.send('context_changed', { context: 'target' }))
355
+ expect(changed).toHaveBeenCalledOnce()
356
+ })