@skyhook-io/radar-app 1.22.0 → 1.22.2

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 (95) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +98 -29
  3. package/src/RadarApp.tsx +5 -0
  4. package/src/api/client.ts +18 -1
  5. package/src/api/cnpg-history.ts +3 -3
  6. package/src/api/cnpg-storage.ts +3 -3
  7. package/src/api/diagnose.test.ts +34 -0
  8. package/src/api/diagnose.ts +17 -4
  9. package/src/api/radarFeatures.test.ts +13 -1
  10. package/src/api/radarFeatures.ts +2 -0
  11. package/src/api/resourceActions.test.ts +829 -0
  12. package/src/api/resourceActions.ts +584 -0
  13. package/src/api/resourceActions.ui.test.tsx +1882 -0
  14. package/src/api/reviewedActionMutation.ts +56 -28
  15. package/src/api/substrateHealth.ts +2 -3
  16. package/src/api/traffic.ts +13 -5
  17. package/src/api/workloadMetrics.test.ts +11 -2
  18. package/src/api/workloadMetrics.ts +2 -2
  19. package/src/api/workloadSource.test.tsx +857 -0
  20. package/src/api/workloadSource.ts +292 -0
  21. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  22. package/src/components/APIUnreachableBanner.tsx +20 -0
  23. package/src/components/ConnectionErrorView.test.tsx +63 -2
  24. package/src/components/ConnectionErrorView.tsx +88 -68
  25. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  26. package/src/components/diagnose/AnalysisStory.test.tsx +12 -0
  27. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  28. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +34 -1
  30. package/src/components/diagnose/DiagnoseContext.tsx +28 -3
  31. package/src/components/diagnose/DiagnoseSurface.tsx +5 -4
  32. package/src/components/diagnose/Home.test.tsx +6 -0
  33. package/src/components/diagnose/Home.tsx +13 -3
  34. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  35. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +61 -0
  36. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  37. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  38. package/src/components/diagnose/InvestigationView.followupFailure.test.tsx +122 -0
  39. package/src/components/diagnose/InvestigationView.tsx +130 -25
  40. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +1 -1
  41. package/src/components/diagnose/LocalDiagnoseAction.tsx +2 -2
  42. package/src/components/diagnose/QuestionComposer.test.tsx +16 -2
  43. package/src/components/diagnose/QuestionComposer.tsx +13 -8
  44. package/src/components/diagnose/diagnoseEvidenceTypes.ts +47 -8
  45. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +153 -0
  46. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +9 -13
  47. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +21 -5
  48. package/src/components/diagnose/investigationEvidence/bodies/network.tsx +63 -26
  49. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  51. package/src/components/diagnose/investigationState.ts +9 -0
  52. package/src/components/diagnose/launch.ts +1 -1
  53. package/src/components/diagnose/parts.test.tsx +11 -3
  54. package/src/components/diagnose/toolCallLabel.ts +3 -0
  55. package/src/components/dock/PodDebugSession.test.tsx +66 -0
  56. package/src/components/dock/PodDebugSession.tsx +3 -1
  57. package/src/components/dock/TerminalTab.test.tsx +43 -3
  58. package/src/components/dock/TerminalTab.tsx +10 -1
  59. package/src/components/helm/HelmReleaseDrawer.tsx +1 -1
  60. package/src/components/helm/InstallWizard.tsx +1 -1
  61. package/src/components/home/ActivitySummary.tsx +3 -8
  62. package/src/components/home/ClusterHealthCard.tsx +91 -17
  63. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  64. package/src/components/home/HomeView.tsx +6 -26
  65. package/src/components/home/TopologyPreview.test.tsx +31 -30
  66. package/src/components/home/TopologyPreview.tsx +19 -28
  67. package/src/components/home/mcpToolCatalog.ts +4 -4
  68. package/src/components/resources/PodEvictAction.test.tsx +951 -0
  69. package/src/components/resources/PodEvictAction.tsx +167 -0
  70. package/src/components/resources/ResourcesView.tsx +3 -0
  71. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  72. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  73. package/src/components/resources/renderers/WorkloadRenderer.tsx +7 -1
  74. package/src/components/settings/LocalConnectionSettings.tsx +4 -4
  75. package/src/components/settings/SettingsDialog.tsx +23 -18
  76. package/src/components/settings/integrationQueries.test.ts +98 -0
  77. package/src/components/settings/integrationQueries.ts +36 -0
  78. package/src/components/traffic/TrafficView.reconnect.test.tsx +229 -0
  79. package/src/components/traffic/TrafficView.tsx +91 -35
  80. package/src/components/ui/Markdown.test.tsx +37 -0
  81. package/src/components/ui/Markdown.tsx +15 -2
  82. package/src/components/useContextSwitchFlow.test.tsx +27 -2
  83. package/src/components/useContextSwitchFlow.tsx +20 -22
  84. package/src/components/workload/WorkloadView.tsx +83 -4
  85. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  86. package/src/context/ConnectionContext.tsx +24 -5
  87. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  88. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  89. package/src/context/DiagnoseCustomization.tsx +20 -2
  90. package/src/hooks/useEventSource.test.tsx +275 -4
  91. package/src/hooks/useEventSource.ts +278 -51
  92. package/src/index.ts +1 -0
  93. package/src/utils/navigation.test.ts +1 -6
  94. package/src/utils/navigation.ts +9 -44
  95. 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
+ })