@skyhook-io/radar-app 1.19.0 → 1.20.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 (173) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -5
  3. package/src/App.tsx +31 -5
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.ts +4 -0
  15. package/src/api/radarFeatures.render.test.tsx +33 -1
  16. package/src/api/radarFeatures.test.ts +47 -0
  17. package/src/api/radarFeatures.ts +40 -1
  18. package/src/api/rbac.settled.test.tsx +42 -0
  19. package/src/api/rbac.test.ts +18 -0
  20. package/src/api/rbac.ts +37 -7
  21. package/src/api/traffic.ts +9 -4
  22. package/src/api/usage-data.fixtures.ts +3 -1
  23. package/src/api/usage-data.test.tsx +134 -0
  24. package/src/api/usage-data.ts +35 -7
  25. package/src/api/workloadPodsPolling.test.ts +26 -0
  26. package/src/components/CloudConnectFlow.test.tsx +86 -0
  27. package/src/components/CloudConnectFlow.tsx +65 -27
  28. package/src/components/CloudFunnelButton.test.tsx +140 -5
  29. package/src/components/CloudFunnelButton.tsx +50 -9
  30. package/src/components/ConnectionErrorView.test.tsx +34 -0
  31. package/src/components/ConnectionErrorView.tsx +35 -11
  32. package/src/components/ContextSwitcher.tsx +5 -2
  33. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  34. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  35. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  38. package/src/components/capacity/CapacityDemand.tsx +3 -2
  39. package/src/components/capacity/demandSummary.test.ts +38 -0
  40. package/src/components/capacity/shared.tsx +12 -1
  41. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  42. package/src/components/cost/CostTrendChart.tsx +2 -0
  43. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  44. package/src/components/cost/source.test.ts +5 -0
  45. package/src/components/cost/source.ts +11 -0
  46. package/src/components/diagnose/AIMarkdown.tsx +3 -0
  47. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  48. package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
  49. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  50. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  51. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  52. package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
  53. package/src/components/diagnose/DiagnoseContext.tsx +68 -2
  54. package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
  55. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  56. package/src/components/diagnose/Home.test.tsx +26 -0
  57. package/src/components/diagnose/Home.tsx +20 -1
  58. package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
  59. package/src/components/diagnose/InvestigationView.tsx +94 -26
  60. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  61. package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
  62. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  63. package/src/components/diagnose/NextStepJump.tsx +75 -0
  64. package/src/components/diagnose/QuestionComposer.tsx +8 -0
  65. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  66. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  67. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  68. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  69. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  70. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  71. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
  72. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  73. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  74. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  75. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  76. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  77. package/src/components/diagnose/investigationState.ts +28 -0
  78. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  79. package/src/components/diagnose/lastInvestigation.ts +58 -0
  80. package/src/components/diagnose/launch.test.ts +125 -1
  81. package/src/components/diagnose/launch.ts +57 -10
  82. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  83. package/src/components/execution/BatchExecutionView.tsx +24 -11
  84. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  85. package/src/components/execution/JobSetAdmission.tsx +18 -3
  86. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  87. package/src/components/execution/runState.test.ts +14 -0
  88. package/src/components/execution/runState.ts +8 -0
  89. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  90. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  91. package/src/components/gitops/GitOpsView.tsx +86 -17
  92. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  93. package/src/components/gitops/destination-toast.test.ts +1 -1
  94. package/src/components/gitops/destination-toast.ts +2 -2
  95. package/src/components/home/ClusterHealthCard.tsx +1 -1
  96. package/src/components/home/HomeAgentBlock.test.tsx +31 -3
  97. package/src/components/home/HomeAgentBlock.tsx +13 -4
  98. package/src/components/home/HomeDiagramCard.tsx +47 -0
  99. package/src/components/home/HomeView.tsx +81 -41
  100. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  101. package/src/components/home/MCPSetupDialog.tsx +30 -5
  102. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  103. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  104. package/src/components/home/TopologyPreview.test.tsx +73 -0
  105. package/src/components/home/TopologyPreview.tsx +120 -233
  106. package/src/components/home/TrafficSummary.test.tsx +63 -0
  107. package/src/components/home/TrafficSummary.tsx +135 -138
  108. package/src/components/home/mcpToolCatalog.ts +23 -10
  109. package/src/components/issues/IssuesPane.test.ts +11 -0
  110. package/src/components/issues/IssuesPane.tsx +15 -5
  111. package/src/components/issues/uncheckedSources.test.ts +20 -1
  112. package/src/components/issues/uncheckedSources.ts +18 -0
  113. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  114. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  115. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  116. package/src/components/kueue/useRelatedReads.ts +205 -0
  117. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  118. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  119. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  120. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  121. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  122. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  123. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  124. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  125. package/src/components/logs/rayClusterPods.ts +32 -0
  126. package/src/components/outageSince.test.ts +21 -0
  127. package/src/components/outageSince.ts +10 -0
  128. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  129. package/src/components/resource/PrometheusCharts.tsx +3 -40
  130. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  131. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  132. package/src/components/resources/crd/host.tsx +14 -0
  133. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  134. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  135. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  136. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  137. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  138. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  139. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  140. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  141. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  142. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  143. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  144. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  145. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  146. package/src/components/traffic/TrafficView.tsx +3 -3
  147. package/src/components/ui/command-items-crd.test.tsx +23 -0
  148. package/src/components/ui/command-items.ts +2 -1
  149. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  150. package/src/components/useContextSwitchFlow.tsx +21 -4
  151. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  152. package/src/components/whats-new/WhatsNew.tsx +5 -1
  153. package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
  154. package/src/components/whats-new/releaseNotes.ts +77 -4
  155. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  156. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  157. package/src/components/workload/WorkloadView.test.ts +10 -1
  158. package/src/components/workload/WorkloadView.tsx +85 -98
  159. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  160. package/src/components/workload/issueResourceOpener.ts +17 -0
  161. package/src/context/ConnectionContext.tsx +133 -60
  162. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  163. package/src/context/ContextSwitchContext.tsx +14 -1
  164. package/src/context/DiagnoseCustomization.tsx +3 -0
  165. package/src/context/clusterConnected.ts +10 -0
  166. package/src/contexts/CapabilitiesContext.tsx +6 -4
  167. package/src/hooks/useElementSize.ts +30 -0
  168. package/src/integrations/resourceHost.test.tsx +1 -0
  169. package/src/integrations/resourceHost.ts +5 -1
  170. package/src/integrations/resourceHosts.test.tsx +21 -4
  171. package/src/integrations/resourceHosts.tsx +12 -0
  172. package/src/main.tsx +5 -0
  173. package/src/utils/related-findings.ts +46 -0
@@ -1,4 +1,4 @@
1
- import { ServerOff, RefreshCw, Loader2, Copy, Check, TerminalSquare } from 'lucide-react'
1
+ import { ServerOff, RefreshCw, Loader2, Copy, Check, TerminalSquare, ArrowLeft } from 'lucide-react'
2
2
  import { useEffect, useState } from 'react'
3
3
  import type { ConnectionState } from '../context/ConnectionContext'
4
4
  import { ContextSwitcher } from './ContextSwitcher'
@@ -11,11 +11,18 @@ import { Collapse, CollapseChevron } from '@skyhook-io/k8s-ui/components/ui/Coll
11
11
  import { allShellSafe, awsProfileFlag } from '../utils/shell-safe'
12
12
  import { apiUrl } from '../api/config'
13
13
  import { useCapabilitiesContext } from '../contexts/CapabilitiesContext'
14
+ import { outageSinceLabel } from './outageSince'
14
15
 
15
16
  interface ConnectionErrorViewProps {
16
17
  connection: ConnectionState
17
18
  onRetry: () => void
18
19
  isRetrying: boolean
20
+ // A one-click way back to the cluster the person was using.
21
+ back?: { label: string; onBack: () => void; disabled?: boolean }
22
+ // 'switch': a switch Radar refused before leaving the current cluster.
23
+ // Nothing re-checks that cluster in the background, so the note saying so
24
+ // is left out.
25
+ variant?: 'connection' | 'switch'
19
26
  }
20
27
 
21
28
  interface CommandHint {
@@ -167,13 +174,15 @@ export function getAuthRejectedHints(context: string, awsProfile?: string): Auth
167
174
  }
168
175
  }
169
176
 
170
- function getAuthPluginStuckHints(): AuthHints {
177
+ function getAuthPluginStuckHints(backgroundRecovery = true): AuthHints {
171
178
  return {
172
179
  title: 'Credential Plugin Stopped Responding',
173
180
  hints: [
174
181
  'The credential command configured by this kubeconfig did not return before the deadline.',
175
182
  'Check that your cloud-provider CLI and its identity-provider or network dependencies are responsive.',
176
- 'Radar will keep checking in the background and reconnect when the credential command recovers.',
183
+ backgroundRecovery
184
+ ? 'Radar will keep checking in the background and reconnect when the credential command recovers.'
185
+ : 'Once the credential command responds, use Retry Connection.',
177
186
  ],
178
187
  }
179
188
  }
@@ -334,7 +343,7 @@ export function CopyableCommand({ command, onRunInTerminal }: { command: string;
334
343
  )
335
344
  }
336
345
 
337
- export function selectConnectionHints(errorType: string | undefined, context: string, originalContext?: string, awsProfile?: string): AuthHints | null {
346
+ export function selectConnectionHints(errorType: string | undefined, context: string, originalContext?: string, awsProfile?: string, backgroundRecovery = true): AuthHints | null {
338
347
  const parsedContext = originalContext || context
339
348
  switch (errorType) {
340
349
  case 'auth':
@@ -342,7 +351,7 @@ export function selectConnectionHints(errorType: string | undefined, context: st
342
351
  case 'auth-rejected':
343
352
  return getAuthRejectedHints(parsedContext, awsProfile)
344
353
  case 'auth-plugin-stuck':
345
- return getAuthPluginStuckHints()
354
+ return getAuthPluginStuckHints(backgroundRecovery)
346
355
  case 'timeout':
347
356
  return getTimeoutHints(parsedContext, awsProfile)
348
357
  default:
@@ -350,7 +359,7 @@ export function selectConnectionHints(errorType: string | undefined, context: st
350
359
  }
351
360
  }
352
361
 
353
- export function ConnectionErrorView({ connection, onRetry, isRetrying }: ConnectionErrorViewProps) {
362
+ export function ConnectionErrorView({ connection, onRetry, isRetrying, back, variant = 'connection' }: ConnectionErrorViewProps) {
354
363
  // For auth errors, generate context-aware hints with a specific re-auth command
355
364
  const isAuth = connection.errorType === 'auth'
356
365
  const isAuthRejected = connection.errorType === 'auth-rejected'
@@ -360,7 +369,8 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
360
369
  const matchedContext = contexts?.find((context) => context.name === connection.context)
361
370
  const originalContext = matchedContext?.originalName
362
371
  const awsProfile = contextsLoading ? undefined : matchedContext?.awsProfile
363
- const commandInfo = selectConnectionHints(connection.errorType, connection.context || '', originalContext, awsProfile)
372
+ const since = outageSinceLabel(connection.disconnectedAt)
373
+ const commandInfo = selectConnectionHints(connection.errorType, connection.context || '', originalContext, awsProfile, variant === 'connection')
364
374
  const errorInfo = commandInfo || errorHints[connection.errorType || 'unknown'] || errorHints.unknown
365
375
  const openLocalTerminal = useOpenLocalTerminal()
366
376
  const { data: authMe } = useAuthMe()
@@ -378,7 +388,9 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
378
388
 
379
389
  const handleAuthInTerminal = () => {
380
390
  if (!commandInfo?.authCommand) return
381
- const cmd = authMe?.authEnabled === false
391
+ // The follow-up retry reconnects the current context, so it only belongs on
392
+ // the screen for a lost connection, not on one for a refused switch.
393
+ const cmd = authMe?.authEnabled === false && variant === 'connection'
382
394
  ? `${commandInfo.authCommand.command} && ${retryCmd}`
383
395
  : commandInfo.authCommand.command
384
396
  openLocalTerminal({
@@ -410,6 +422,7 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
410
422
  ) : (
411
423
  <span className="inline-code">(none)</span>
412
424
  )}
425
+ {since && <span>· since {since}</span>}
413
426
  </p>
414
427
 
415
428
  {connection.clusterName && (
@@ -475,11 +488,11 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
475
488
  )}
476
489
  </div>
477
490
 
478
- <div className="flex items-center gap-5">
491
+ <div className="flex flex-wrap items-center justify-center gap-3">
479
492
  <button
480
493
  onClick={onRetry}
481
494
  disabled={isRetrying}
482
- className="inline-flex items-center gap-2 px-4 py-2 btn-brand rounded-lg"
495
+ className="inline-flex items-center gap-2 px-4 py-2 btn-brand rounded-lg whitespace-nowrap"
483
496
  >
484
497
  {isRetrying ? (
485
498
  <>
@@ -494,10 +507,21 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
494
507
  )}
495
508
  </button>
496
509
 
510
+ {back && (
511
+ <button
512
+ onClick={back.onBack}
513
+ disabled={back.disabled}
514
+ className="inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-theme-border bg-theme-surface text-theme-text-primary hover:bg-theme-hover disabled:opacity-50 whitespace-nowrap"
515
+ >
516
+ <ArrowLeft className="w-4 h-4" />
517
+ Back to {back.label}
518
+ </button>
519
+ )}
520
+
497
521
  {connection.context && <ContextSwitcher triggerName="Switch context" />}
498
522
  </div>
499
523
 
500
- {isAuthError && (
524
+ {isAuthError && variant === 'connection' && (
501
525
  <p className="mt-4 text-xs text-theme-text-tertiary">
502
526
  {isAuthRejected
503
527
  ? 'Radar re-checks in the background — access changes are picked up automatically. Use Retry Connection to check immediately.'
@@ -6,6 +6,7 @@ import {
6
6
  import { useContexts, useClusterInfo, useCapabilities } from '../api/client'
7
7
  import type { ContextInfo } from '../types'
8
8
  import { useContextSwitchFlow } from './useContextSwitchFlow'
9
+ import { useContextSwitch } from '../context/ContextSwitchContext'
9
10
  import { parseContextForSwitcher, visibleContextQualifier, type ParsedContextName } from '../utils/context-name'
10
11
 
11
12
  interface ContextSwitcherProps {
@@ -29,6 +30,7 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
29
30
  const { data: clusterInfo } = useClusterInfo()
30
31
  const { data: capabilities } = useCapabilities()
31
32
  const switchFlow = useContextSwitchFlow()
33
+ const { failedSwitch } = useContextSwitch()
32
34
 
33
35
  // Parse contexts and decide whether to render group headers (multi-account only).
34
36
  // hasMultipleSources gates the kubeconfig-source chip — only useful when 2+
@@ -134,10 +136,11 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
134
136
  loading={switchFlow.isPending}
135
137
  disabled={contextsLoading || !capabilities || capabilities.configManagement === 'operator'}
136
138
  searchable={items.length > 1}
139
+ currentSelectable={!!failedSwitch}
137
140
  showGroupHeaders={hasMultipleAccounts}
138
141
  errorSlot={
139
- switchFlow.error ? (
140
- <span className="text-xs text-red-400">{switchFlow.error.message}</span>
142
+ switchFlow.errorText ? (
143
+ <span className="text-xs text-red-400">{switchFlow.errorText}</span>
141
144
  ) : undefined
142
145
  }
143
146
  />
@@ -0,0 +1,43 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ import type { ContextInfo } from '../types'
4
+
5
+ const requestSwitch = vi.fn()
6
+ const contexts: ContextInfo[] = [
7
+ { name: 'kind-radar-ph-video', cluster: 'kind-radar-ph-video', user: 'u', namespace: '', isCurrent: false } as ContextInfo,
8
+ { name: 'gke_acme_europe-west1_staging-eu', cluster: 'staging-eu', user: 'u', namespace: '', isCurrent: true } as ContextInfo,
9
+ ]
10
+
11
+ vi.mock('../api/client', () => ({ useContexts: () => ({ data: contexts }) }))
12
+ vi.mock('./useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ requestSwitch, isPending: false, confirmDialog: null }) }))
13
+ vi.mock('../context/ContextSwitchContext', () => ({ useContextSwitch: () => ({ failedSwitch: null, setFailedSwitch: vi.fn() }) }))
14
+ vi.mock('./ConnectionErrorView', () => ({
15
+ ConnectionErrorView: ({ back }: { back?: { label: string } }) => <div>{back ? `back:${back.label}` : 'no back'}</div>,
16
+ }))
17
+
18
+ const { DisconnectedView } = await import('./SwitchAwareConnectionError')
19
+
20
+ const down = { state: 'disconnected' as const, context: 'gke_acme_europe-west1_staging-eu', errorType: 'timeout' }
21
+
22
+ describe('DisconnectedView', () => {
23
+ it('offers the last connected cluster after a switch that left it', () => {
24
+ const markup = renderToStaticMarkup(
25
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext="kind-radar-ph-video" />,
26
+ )
27
+ expect(markup).toContain('back:kind-radar-ph-video')
28
+ })
29
+
30
+ it('offers nothing when the cluster that is down is the one that last worked', () => {
31
+ const markup = renderToStaticMarkup(
32
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext="gke_acme_europe-west1_staging-eu" />,
33
+ )
34
+ expect(markup).toContain('no back')
35
+ })
36
+
37
+ it('offers nothing before anything has connected', () => {
38
+ const markup = renderToStaticMarkup(
39
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext={null} />,
40
+ )
41
+ expect(markup).toContain('no back')
42
+ })
43
+ })
@@ -0,0 +1,85 @@
1
+ import { useState } from 'react'
2
+ import { useContexts } from '../api/client'
3
+ import type { ConnectionState } from '../context/ConnectionContext'
4
+ import { useContextSwitch } from '../context/ContextSwitchContext'
5
+ import type { ContextInfo } from '../types'
6
+ import { parseContextForSwitcher } from '../utils/context-name'
7
+ import { ConnectionErrorView } from './ConnectionErrorView'
8
+ import { useContextSwitchFlow } from './useContextSwitchFlow'
9
+
10
+ function clusterLabel(contexts: ContextInfo[] | undefined, name: string): string {
11
+ const match = contexts?.find(context => context.name === name)
12
+ return match ? parseContextForSwitcher(match).clusterName : name
13
+ }
14
+
15
+ // A switch Radar refused before leaving the current cluster: the connection
16
+ // error screen for the cluster that didn't answer, with its fix steps. The
17
+ // current cluster is still connected underneath, so Back only closes this.
18
+ export function FailedSwitchView({ currentContext }: { currentContext: string }) {
19
+ const { failedSwitch, setFailedSwitch } = useContextSwitch()
20
+ const { data: contexts } = useContexts()
21
+ const { requestSwitch, isPending, confirmDialog } = useContextSwitchFlow()
22
+ // Retry checks for open sessions before the switch itself is pending; Back
23
+ // stays disabled through that, so it can't close the screen and then switch.
24
+ const [starting, setStarting] = useState(false)
25
+ if (!failedSwitch) return null
26
+ const target = contexts?.find(context => context.name === failedSwitch.context)
27
+ const busy = starting || isPending
28
+
29
+ return (
30
+ <>
31
+ <ConnectionErrorView
32
+ connection={{
33
+ state: 'disconnected',
34
+ context: failedSwitch.context,
35
+ error: failedSwitch.error,
36
+ errorType: failedSwitch.errorType,
37
+ }}
38
+ onRetry={() => {
39
+ if (!target || busy) return
40
+ setStarting(true)
41
+ void requestSwitch(target).finally(() => setStarting(false))
42
+ }}
43
+ isRetrying={busy}
44
+ back={{ label: clusterLabel(contexts, currentContext), onBack: () => setFailedSwitch(null), disabled: busy }}
45
+ variant="switch"
46
+ />
47
+ {confirmDialog}
48
+ </>
49
+ )
50
+ }
51
+
52
+ // Disconnected after leaving a cluster that worked (an older Radar server, or
53
+ // a new cluster that answered and then failed to load): Back switches to the
54
+ // last cluster that was connected.
55
+ export function DisconnectedView({
56
+ connection,
57
+ onRetry,
58
+ isRetrying,
59
+ lastConnectedContext,
60
+ }: {
61
+ connection: ConnectionState
62
+ onRetry: () => void
63
+ isRetrying: boolean
64
+ lastConnectedContext: string | null
65
+ }) {
66
+ const { data: contexts } = useContexts()
67
+ const { requestSwitch, isPending, confirmDialog } = useContextSwitchFlow()
68
+ const previous = lastConnectedContext && lastConnectedContext !== connection.context
69
+ ? contexts?.find(context => context.name === lastConnectedContext)
70
+ : undefined
71
+
72
+ return (
73
+ <>
74
+ <ConnectionErrorView
75
+ connection={connection}
76
+ onRetry={onRetry}
77
+ isRetrying={isRetrying}
78
+ back={previous
79
+ ? { label: parseContextForSwitcher(previous).clusterName, onBack: () => void requestSwitch(previous), disabled: isPending }
80
+ : undefined}
81
+ />
82
+ {confirmDialog}
83
+ </>
84
+ )
85
+ }
@@ -0,0 +1,234 @@
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 { guardRadarFeature, radarFeatureSupport } from '../../api/radarFeatures'
7
+ import { ApiError } from '../../api/client'
8
+ import { ApplicationEvidenceAction, ApplicationEvidenceObservation } from './ApplicationEvidenceAction'
9
+ import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
10
+
11
+ vi.mock('@skyhook-io/k8s-ui/utils/clipboard', () => ({ copyText: vi.fn().mockResolvedValue(true) }))
12
+
13
+ const state = vi.hoisted(() => ({ fetch: vi.fn(), supported: true, ApiError: class extends Error { constructor(message: string, readonly status: number) { super(message) } } }))
14
+ vi.mock('../../api/client', () => ({
15
+ ApiError: state.ApiError,
16
+ fetchJSON: (...args: unknown[]) => state.fetch(...args),
17
+ useClusterInfo: () => ({ data: { context: 'test-cluster' } }),
18
+ useCapabilities: () => ({ data: { deployment: { mode: 'local' }, features: state.supported ? { applicationEvidence: true } : {} } }),
19
+ useRadarFeature: () => {
20
+ const support = radarFeatureSupport('applicationEvidence', { features: state.supported ? { applicationEvidence: true } : {} }, 'v1.16.0')
21
+ return { support, gatedKey: [], guard: <T,>(request: () => Promise<T>) => guardRadarFeature('applicationEvidence', support, {}, request) }
22
+ },
23
+ }))
24
+ const candidates = { enabled: true, context: 'test-cluster', subjectUID: 'subject-uid', candidates: [{ application: 'vault', target: { namespace: 'demo', pod: 'vault-0', uid: 'pod-uid', container: 'vault' }, expectedEvidence: ['sealed'], coverage: 'One selected Pod.' }] }
25
+ let root: ReturnType<typeof createRoot>
26
+ let host: HTMLDivElement
27
+ let client: QueryClient
28
+ beforeEach(() => {
29
+ state.fetch.mockReset(); state.supported = true
30
+ ;(globalThis as Record<string, unknown>).IS_REACT_ACT_ENVIRONMENT = true
31
+ window.matchMedia = vi.fn().mockReturnValue({ matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() })
32
+ host = document.createElement('div'); document.body.append(host); root = createRoot(host)
33
+ client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
34
+ })
35
+ afterEach(() => { act(() => root.unmount()); client.clear(); host.remove() })
36
+ it('keeps limitations expandable and in copied observations, with guidance for omitted Pods', async () => {
37
+ const limitations = ['One selected Pod only.', 'Identity checks do not attest endpoint contents.']
38
+ const observation = { adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', httpStatus: 501, facts: { vault: { initialized: false, sealed: true, standby: true, removedFromCluster: false } }, limitations }
39
+ state.fetch.mockResolvedValueOnce({ ...candidates, coverageLimited: true }).mockResolvedValueOnce(observation)
40
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Service" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
41
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
42
+ act(() => host.querySelector('button')!.click())
43
+ expect(document.body.textContent).toContain('To inspect another endpoint, open that Pod directly.')
44
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
45
+ const toggle = [...document.querySelectorAll('button')].find(item => item.textContent === 'Collection limits')!
46
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
47
+ expect(document.body.textContent).toContain('Endpoint status: HTTP 501')
48
+ expect(document.body.textContent).toContain('This Pod at collection time; other replicas were not checked.')
49
+ act(() => toggle.click())
50
+ expect(toggle.getAttribute('aria-expanded')).toBe('true')
51
+ expect(document.getElementById(toggle.getAttribute('aria-controls')!)!.textContent).toContain(limitations[1])
52
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Copy observation')!.click())
53
+ expect(JSON.parse(vi.mocked(copyText).mock.calls.at(-1)![0])).toEqual({ context: 'test-cluster', ...observation })
54
+ })
55
+ it('does not request endpoints from a Radar without the collection flag', async () => {
56
+ state.supported = false
57
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
58
+ expect(state.fetch).not.toHaveBeenCalled()
59
+ expect(host.textContent).toBe('')
60
+ })
61
+ it('collects only on explicit click and discards a cancelled response on reopen', async () => {
62
+ let finish: (value: unknown) => void = () => {}
63
+ const delayed = new Promise(resolve => { finish = resolve })
64
+ state.fetch.mockImplementation((path: string) => path.startsWith('/application-evidence/candidates') ? Promise.resolve(candidates) : delayed)
65
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
66
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
67
+ act(() => host.querySelector('button')!.click())
68
+ expect(state.fetch).toHaveBeenCalledTimes(1)
69
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
70
+ const [path, request] = state.fetch.mock.calls[1]
71
+ expect(path).toBe('/application-evidence/collect')
72
+ expect(JSON.parse(request.body)).toEqual({ application: 'vault', namespace: 'demo', pod: 'vault-0', uid: 'pod-uid', context: 'test-cluster', confirmNetworkAccess: true })
73
+ act(() => [...document.querySelectorAll('button')].find(item => item.textContent === 'Cancel')!.click())
74
+ expect(request.signal.aborted).toBe(true)
75
+ act(() => host.querySelector('button')!.click())
76
+ await act(async () => finish({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', facts: { vault: { initialized: true, sealed: false, standby: false } }, limitations: [] }))
77
+ expect(document.body.textContent).not.toContain('Endpoint observations')
78
+ expect(state.fetch).toHaveBeenCalledTimes(2)
79
+ })
80
+
81
+ it('recovers from one transient cache failure without collecting an endpoint', async () => {
82
+ state.fetch.mockRejectedValueOnce(new ApiError('not connected', 503)).mockResolvedValue(candidates)
83
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
84
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'), { timeout: 2500 })
85
+ expect(state.fetch).toHaveBeenCalledTimes(2)
86
+ expect(state.fetch.mock.calls.every(([path]) => path.startsWith('/application-evidence/candidates'))).toBe(true)
87
+ })
88
+
89
+ it('keeps an open observation and validated targets after a permission retry fails', async () => {
90
+ state.fetch.mockResolvedValueOnce({ ...candidates, permissionCheckTimedOut: true })
91
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
92
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
93
+ act(() => [...host.querySelectorAll('button')].find(item => item.textContent === 'Collect Vault evidence')!.click())
94
+ state.fetch.mockResolvedValueOnce({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', facts: { vault: { initialized: false, sealed: true, standby: true } }, limitations: [] })
95
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
96
+ expect(document.body.textContent).toContain('Endpoint observations')
97
+ state.fetch.mockRejectedValue(new ApiError('permission check failed', 500))
98
+ await act(async () => [...host.querySelectorAll('button')].find(item => item.textContent === 'Retry permission check')!.click())
99
+ await vi.waitFor(() => expect(host.textContent).toContain('Could not refresh application evidence'))
100
+ expect(document.body.textContent).toContain('Endpoint observations')
101
+ expect(document.body.textContent).toContain('Copy observation')
102
+ expect(host.textContent).toContain('Collect Vault evidence')
103
+ state.fetch.mockResolvedValue(candidates)
104
+ await act(async () => [...host.querySelectorAll('button')].find(item => item.textContent === 'Retry permission check')!.click())
105
+ await vi.waitFor(() => expect(host.textContent).not.toContain('Could not refresh application evidence'))
106
+ expect(document.body.textContent).toContain('Endpoint observations')
107
+ })
108
+
109
+ it.each(['target_changed', 'pod_not_running', 'container_not_running'])('preserves a %s refusal without offering its stale target after a failed refresh', async reason => {
110
+ state.fetch.mockResolvedValueOnce(candidates)
111
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
112
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
113
+ act(() => host.querySelector('button')!.click())
114
+ state.fetch.mockResolvedValueOnce({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'unavailable', reason, limitations: [] }).mockRejectedValue(new ApiError('refresh failed', 500))
115
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
116
+ await vi.waitFor(() => expect(host.textContent).toContain('Could not refresh application evidence'))
117
+ expect(document.body.textContent).toContain('Evidence unavailable')
118
+ expect(document.body.textContent).toContain('Copy observation')
119
+ expect(host.textContent).not.toContain('Collect Vault evidence')
120
+ state.fetch.mockResolvedValue({ ...candidates, candidates: [{ ...candidates.candidates[0], target: { ...candidates.candidates[0].target, uid: 'replacement-uid' } }] })
121
+ await act(async () => [...host.querySelectorAll('button')].find(item => item.textContent === 'Retry')!.click())
122
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
123
+ act(() => [...document.querySelectorAll('button')].find(item => item.textContent === 'Close')!.click())
124
+ act(() => [...host.querySelectorAll('button')].find(item => item.textContent === 'Collect Vault evidence')!.click())
125
+ state.fetch.mockResolvedValue({ adapter: 'vault', target: { ...candidates.candidates[0].target, uid: 'replacement-uid' }, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', limitations: [] })
126
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
127
+ const [, request] = state.fetch.mock.calls.at(-1)!
128
+ expect(JSON.parse(request.body).uid).toBe('replacement-uid')
129
+ })
130
+
131
+ it('allows the same Pod UID after a container restart and a successful refresh', async () => {
132
+ state.fetch.mockResolvedValueOnce(candidates)
133
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
134
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
135
+ act(() => host.querySelector('button')!.click())
136
+ state.fetch.mockResolvedValueOnce({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'unavailable', reason: 'target_changed', limitations: [] }).mockResolvedValue(candidates)
137
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
138
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
139
+ expect(document.body.textContent).toContain('Evidence unavailable')
140
+ act(() => [...document.querySelectorAll('button')].find(item => item.textContent === 'Close')!.click())
141
+ act(() => host.querySelector('button')!.click())
142
+ state.fetch.mockResolvedValue({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', limitations: [] })
143
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
144
+ expect(document.body.textContent).toContain('Endpoint observations')
145
+ const [, request] = state.fetch.mock.calls.at(-1)!
146
+ expect(JSON.parse(request.body).uid).toBe('pod-uid')
147
+ })
148
+ it('keeps an optional first-lookup failure quiet until the user has used the feature', async () => {
149
+ state.fetch.mockRejectedValue(new ApiError('access denied', 403))
150
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
151
+ await vi.waitFor(() => expect(state.fetch).toHaveBeenCalledTimes(1))
152
+ expect(host.textContent).toBe('')
153
+ })
154
+
155
+ it('offers an explicit retry after permission evaluation fails without collecting', async () => {
156
+ state.fetch.mockResolvedValueOnce({ ...candidates, candidates: [], permissionCheckFailed: true })
157
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
158
+ await vi.waitFor(() => expect(host.textContent).toContain('Application evidence permissions could not be verified'))
159
+ expect(host.textContent).not.toContain('Collect Vault evidence')
160
+ state.fetch.mockResolvedValue(candidates)
161
+ await act(async () => [...host.querySelectorAll('button')].find(item => item.textContent === 'Retry permission check')!.click())
162
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
163
+ expect(state.fetch.mock.calls.every(([path]) => path.startsWith('/application-evidence/candidates'))).toBe(true)
164
+ expect(state.fetch.mock.calls.at(-1)![0]).toContain('retryPermissions=true')
165
+ })
166
+
167
+ it.each(['pod-uid', 'replacement-uid'])('allows deliberate reselection of %s inside the dialog while keeping the refusal', async nextUID => {
168
+ state.fetch.mockResolvedValueOnce(candidates)
169
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
170
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect Vault evidence'))
171
+ act(() => host.querySelector('button')!.click())
172
+ const refreshed = { ...candidates, candidates: [{ ...candidates.candidates[0], target: { ...candidates.candidates[0].target, uid: nextUID } }] }
173
+ state.fetch.mockResolvedValueOnce({ adapter: 'vault', target: candidates.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'unavailable', reason: 'target_changed', limitations: [] }).mockResolvedValueOnce(nextUID === 'replacement-uid' ? { ...candidates, candidates: [], permissionCheckFailed: true } : refreshed).mockResolvedValue(refreshed)
174
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
175
+ if (nextUID === 'replacement-uid') {
176
+ await vi.waitFor(() => expect(host.textContent).toContain('Application evidence permissions could not be verified'))
177
+ await vi.waitFor(() => expect(document.body.textContent).toContain('A current Pod endpoint has not been verified'))
178
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Refresh Pod choices')!.click())
179
+ expect(state.fetch.mock.calls.at(-1)![0]).toContain('retryPermissions=true')
180
+ }
181
+ await vi.waitFor(() => expect(document.querySelector<HTMLButtonElement>('button[aria-label="Pod endpoint"]')?.disabled).toBe(false))
182
+ expect(document.body.textContent).toContain('Evidence unavailable')
183
+ expect(document.body.textContent).toContain('Copy observation')
184
+ expect([...document.querySelectorAll<HTMLButtonElement>('button')].find(item => item.textContent === 'Collect again')!.disabled).toBe(true)
185
+ act(() => document.querySelector<HTMLButtonElement>('button[aria-label="Pod endpoint"]')!.click())
186
+ act(() => document.querySelector<HTMLButtonElement>('[role="option"]')!.click())
187
+ expect(document.body.textContent).toContain('Evidence unavailable')
188
+ expect(state.fetch.mock.calls.filter(([path]) => path === '/application-evidence/collect')).toHaveLength(1)
189
+ state.fetch.mockResolvedValue({ adapter: 'vault', target: refreshed.candidates[0].target, observedAt: '2026-10-13T00:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', limitations: [] })
190
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect again')!.click())
191
+ expect(JSON.parse(state.fetch.mock.calls.at(-1)![1].body).uid).toBe(nextUID)
192
+ expect(document.body.textContent).toContain('Endpoint observations')
193
+ })
194
+
195
+
196
+ it('keeps background refresh errors quiet for a resource with no eligible endpoints', async () => {
197
+ state.fetch.mockResolvedValueOnce({ ...candidates, candidates: [] })
198
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Deployment" group="apps" namespace="demo" name="vault" uid="subject-uid" /></QueryClientProvider>))
199
+ await vi.waitFor(() => expect(client.getQueryCache().getAll()[0]?.state.status).toBe('success'))
200
+ expect(host.textContent).toBe('')
201
+ state.fetch.mockRejectedValue(new ApiError('temporary refresh failure', 500))
202
+ await act(async () => { await client.invalidateQueries({ queryKey: ['application-evidence-candidates'] }) })
203
+ expect(state.fetch).toHaveBeenCalledTimes(2)
204
+ expect(host.textContent).toBe('')
205
+ })
206
+
207
+ it('copies exact RabbitMQ bytes and identity without an additional collection request', async () => {
208
+ const target = { namespace: 'demo', pod: 'rabbitmq-0', uid: 'rabbit-uid', container: 'rabbitmq' }
209
+ const observation = { adapter: 'rabbitmq', target, observedAt: '2026-11-03T10:00:00Z', source: 'selected_pod_endpoint', outcome: 'observed', facts: { rabbitmq: { diskAlarm: true, memoryAlarm: false, diskAvailableBytes: 15277850624, diskWatermarkBytes: 1000000000000, memoryUsedBytes: 134975488, memoryWatermarkBytes: 2412409651 } }, limitations: ['Only the selected Pod was checked.'] }
210
+ state.fetch.mockResolvedValueOnce({ ...candidates, subjectUID: 'rabbit-uid', candidates: [{ application: 'rabbitmq', target, expectedEvidence: ['disk/memory alarms'], coverage: 'One selected Pod.' }] }).mockResolvedValueOnce(observation)
211
+ await act(async () => root.render(<QueryClientProvider client={client}><ApplicationEvidenceAction kind="Pod" namespace="demo" name="rabbitmq-0" uid="rabbit-uid" /></QueryClientProvider>))
212
+ await vi.waitFor(() => expect(host.textContent).toContain('Collect RabbitMQ evidence'))
213
+ act(() => host.querySelector('button')!.click())
214
+ expect(state.fetch).toHaveBeenCalledTimes(1)
215
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Collect evidence')!.click())
216
+ await act(async () => [...document.querySelectorAll('button')].find(item => item.textContent === 'Copy observation')!.click())
217
+ expect(JSON.parse(vi.mocked(copyText).mock.calls.at(-1)![0])).toEqual({ context: 'test-cluster', ...observation })
218
+ expect(state.fetch).toHaveBeenCalledTimes(2)
219
+ })
220
+
221
+ it('keeps NATS progress collapsed until requested without changing the four-column count table', () => {
222
+ act(() => root.render(<ApplicationEvidenceObservation result={{ adapter: 'nats', target: { namespace: 'demo', pod: 'nats-0' }, observedAt: '2026-11-03T01:44:19Z', source: 'selected_pod_endpoint', outcome: 'observed', limitations: [], facts: { nats: { jetStreamEnabled: true, coverage: 'node_reported', returnedAccounts: 1, returnedStreams: 1, returnedConsumers: 1, truncated: false, consumers: [{ account: '$G', stream: 'events', name: 'worker', pending: 0, ackPending: 5, redelivered: 0, delivered: { consumerSequence: '5', streamSequence: '5' }, ackFloor: { consumerSequence: '0', streamSequence: '0' }, waitingPullRequests: 1 }] } } }} />))
223
+ const toggle = [...host.querySelectorAll('button')].find(item => item.textContent === 'Consumer progress')!
224
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
225
+ expect(host.querySelectorAll('th')).toHaveLength(4)
226
+ act(() => toggle.click())
227
+ expect(toggle.getAttribute('aria-expanded')).toBe('true')
228
+ const details = document.getElementById(toggle.getAttribute('aria-controls')!)!
229
+ expect(details.textContent).toContain('Consumer seq 5 · Stream seq 5')
230
+ expect(details.textContent).toContain('Ack floorConsumer seq 0 · Stream seq 0')
231
+ expect(details.textContent).toContain('Waiting pull requests on this node1')
232
+ act(() => toggle.click())
233
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
234
+ })