@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
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { ApiError, isStableClientError, workloadPodsRefetchInterval } from './client'
3
+
4
+ describe('isStableClientError', () => {
5
+ it('stops on answers that will repeat: rejected, denied, missing, recreated', () => {
6
+ for (const status of [400, 403, 404, 409]) expect(isStableClientError(new ApiError('x', status))).toBe(true)
7
+ })
8
+ it('keeps going on an expired session, throttling, timeouts and server errors', () => {
9
+ for (const status of [401, 408, 429, 500, 503]) expect(isStableClientError(new ApiError('x', status))).toBe(false)
10
+ expect(isStableClientError(new Error('network'))).toBe(false)
11
+ })
12
+ })
13
+
14
+ describe('workloadPodsRefetchInterval', () => {
15
+ const polled = { ownerUID: 'uid', refetchInterval: 5000 }
16
+ it('stops an owner-UID poll on an answer that will repeat and keeps it on one that may pass', () => {
17
+ expect(workloadPodsRefetchInterval(new ApiError('denied', 403), polled)).toBe(false)
18
+ expect(workloadPodsRefetchInterval(new ApiError('recreated', 409), polled)).toBe(false)
19
+ expect(workloadPodsRefetchInterval(new ApiError('warming', 503), polled)).toBe(5000)
20
+ expect(workloadPodsRefetchInterval(null, polled)).toBe(5000)
21
+ })
22
+ it('leaves callers without an owner UID polling as they asked', () => {
23
+ expect(workloadPodsRefetchInterval(new ApiError('missing', 404), { refetchInterval: 5000 })).toBe(5000)
24
+ expect(workloadPodsRefetchInterval(null, undefined)).toBe(false)
25
+ })
26
+ })
@@ -0,0 +1,86 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6
+ import type { CloudInstallStage } from '../api/client'
7
+ import { CloudConnectFlow } from './CloudConnectFlow'
8
+
9
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
10
+ let root: Root
11
+
12
+ beforeEach(() => {
13
+ const element = document.createElement('div')
14
+ document.body.appendChild(element)
15
+ root = createRoot(element)
16
+ })
17
+
18
+ afterEach(async () => {
19
+ await act(async () => root.unmount())
20
+ document.body.replaceChildren()
21
+ })
22
+
23
+ async function renderPreparing(prepareStep?: CloudInstallStage, context?: string) {
24
+ await act(async () => {
25
+ root.render(
26
+ <QueryClientProvider client={new QueryClient()}>
27
+ <CloudConnectFlow
28
+ status={{ state: 'preparing', prepareStep }}
29
+ blocked={null}
30
+ where={{ context }}
31
+ exit={{ href: 'https://cloud.example', label: 'Continue in Radar Cloud', install: false }}
32
+ onStatus={() => {}}
33
+ onExit={() => {}}
34
+ />
35
+ </QueryClientProvider>,
36
+ )
37
+ })
38
+ }
39
+
40
+ function rows() {
41
+ return Array.from(document.querySelectorAll('li')).map(li => {
42
+ const icon = li.querySelector('svg')
43
+ const state = !icon ? 'todo' : icon.classList.contains('animate-spin') ? 'active' : 'done'
44
+ return `${state}: ${li.textContent}`
45
+ })
46
+ }
47
+
48
+ describe('Cloud connect preparation steps', () => {
49
+ it.each([
50
+ [undefined, ['active', 'todo', 'todo']],
51
+ ['inspect', ['active', 'todo', 'todo']],
52
+ ['prepare', ['done', 'active', 'todo']],
53
+ ['preflight', ['done', 'done', 'active']],
54
+ ] as const)('step %s marks the rows %j', async (step, states) => {
55
+ await renderPreparing(step)
56
+ expect(rows()).toEqual([
57
+ `${states[0]}: Looking for an existing Radar install`,
58
+ `${states[1]}: Preparing the Radar Helm chart`,
59
+ `${states[2]}: Checking your permissions with a dry run`,
60
+ ])
61
+ expect(document.body.textContent).toContain('Checking this cluster')
62
+ expect(document.body.textContent).toContain('Nothing is installed in this step.')
63
+ })
64
+
65
+ it('names the cluster from its kubeconfig context, keeping the full name on hover', async () => {
66
+ await renderPreparing('inspect', 'gke_my-project_us-east1_prod-eu')
67
+ const title = document.querySelector('h4')!
68
+ expect(title.textContent).toBe('Checking prod-eu')
69
+
70
+ // The full context is reachable through the themed Tooltip, not a native
71
+ // title attribute (which the no-native-title lint check forbids).
72
+ expect(title.querySelector('[title]')).toBeNull()
73
+ const trigger = title.querySelector('span')!
74
+ vi.useFakeTimers()
75
+ try {
76
+ await act(async () => {
77
+ trigger.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }))
78
+ vi.advanceTimersByTime(400)
79
+ })
80
+ const tip = document.querySelector('[role="tooltip"]')
81
+ expect(tip?.textContent).toBe('gke_my-project_us-east1_prod-eu')
82
+ } finally {
83
+ vi.useRealTimers()
84
+ }
85
+ })
86
+ })
@@ -3,6 +3,7 @@ import { useMutation } from '@tanstack/react-query'
3
3
  import { AlertTriangle, ArrowUpRight, Check, Copy, ExternalLink, GitBranch, Info, Loader2, ShieldAlert, X } from 'lucide-react'
4
4
  import { type AdminNoteContext, type BlockedExit, composeAdminNote, composeFailureNote, needsAdminHandoff, trimRefusal } from './cloudConnectHandoff'
5
5
  import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
6
+ import { parseContextName } from '@skyhook-io/k8s-ui/utils/context-name'
6
7
  import { Collapse, CollapseChevron } from '@skyhook-io/k8s-ui/components/ui/Collapse'
7
8
  import { Tooltip } from './ui/Tooltip'
8
9
  import {
@@ -10,6 +11,7 @@ import {
10
11
  cancelCloudInstall,
11
12
  type CloudInstallBlocked,
12
13
  type CloudInstallRecoveryGuidance,
14
+ type CloudInstallStage,
13
15
  type CloudInstallStatus,
14
16
  dismissCloudInstall,
15
17
  startCloudInstall,
@@ -43,14 +45,7 @@ export function CloudConnectFlow({
43
45
 
44
46
  switch (status.state) {
45
47
  case 'preparing':
46
- return (
47
- <div className="px-8 py-10 flex flex-col items-center gap-3 text-center">
48
- <Loader2 className="w-5 h-5 animate-spin text-emerald-600 dark:text-emerald-400" />
49
- <p className="text-[13px] text-theme-text-secondary">
50
- Checking this cluster and preparing the install. This can take a moment on a slow link.
51
- </p>
52
- </div>
53
- )
48
+ return <PreparingCard step={status.prepareStep} context={where?.context} />
54
49
  case 'ready':
55
50
  return <PlanCard status={status} onStatus={onStatus} onExit={onExit} />
56
51
  case 'starting':
@@ -694,10 +689,70 @@ function ApprovalCard({ status, onStatus }: { status: CloudInstallStatus; onStat
694
689
  )
695
690
  }
696
691
 
692
+ type StepState = 'done' | 'active' | 'todo'
693
+
694
+ function StepList({ steps }: { steps: Array<{ label: string; state: StepState }> }) {
695
+ return (
696
+ <ul className="space-y-2.5">
697
+ {steps.map((step) => (
698
+ <li key={step.label} className="flex items-center gap-2.5 text-[12.5px]">
699
+ {step.state === 'done' ? (
700
+ <Check className="w-4 h-4 text-emerald-600 dark:text-emerald-400" />
701
+ ) : step.state === 'active' ? (
702
+ <Loader2 className="w-4 h-4 animate-spin text-emerald-600 dark:text-emerald-400" />
703
+ ) : (
704
+ <span className="w-4 h-4 grid place-items-center">
705
+ <span className="w-1.5 h-1.5 rounded-full bg-theme-border" />
706
+ </span>
707
+ )}
708
+ <span className={step.state === 'todo' ? 'text-theme-text-tertiary' : 'text-theme-text-secondary'}>
709
+ {step.label}
710
+ </span>
711
+ </li>
712
+ ))}
713
+ </ul>
714
+ )
715
+ }
716
+
717
+ const PREPARE_STEPS: Array<{ stage: CloudInstallStage; label: string }> = [
718
+ { stage: 'inspect', label: 'Looking for an existing Radar install' },
719
+ { stage: 'prepare', label: 'Preparing the Radar Helm chart' },
720
+ { stage: 'preflight', label: 'Checking your permissions with a dry run' },
721
+ ]
722
+
723
+ // Before the first status poll answers (or from a server that does not
724
+ // report steps) the first check is the one shown as running.
725
+ export function PreparingCard({ step, context }: { step?: CloudInstallStage; context?: string }) {
726
+ const current = Math.max(0, PREPARE_STEPS.findIndex((s) => s.stage === step))
727
+ return (
728
+ <div className="px-8 pt-6 pb-5">
729
+ <h4 className="text-[15px] font-semibold text-theme-text-primary mb-3.5 break-words">
730
+ Checking{' '}
731
+ {context ? (
732
+ <Tooltip content={context} position="bottom">
733
+ <span>{parseContextName(context).clusterName}</span>
734
+ </Tooltip>
735
+ ) : (
736
+ 'this cluster'
737
+ )}
738
+ </h4>
739
+ <StepList
740
+ steps={PREPARE_STEPS.map((s, i) => ({
741
+ label: s.label,
742
+ state: i < current ? 'done' : i === current ? 'active' : 'todo',
743
+ }))}
744
+ />
745
+ <p className="mt-4 text-[11px] text-theme-text-tertiary">
746
+ Nothing is installed in this step. You’ll see the plan before anything changes.
747
+ </p>
748
+ </div>
749
+ )
750
+ }
751
+
697
752
  function ProgressCard({ status, onStatus }: { status: CloudInstallStatus; onStatus: (st: CloudInstallStatus) => void }) {
698
753
  const provisioning = status.state === 'provisioning'
699
754
  const cancel = useCancelButton(status, onStatus)
700
- const steps: Array<{ label: string; state: 'done' | 'active' | 'todo' }> = [
755
+ const steps: Array<{ label: string; state: StepState }> = [
701
756
  { label: 'Approved in browser', state: 'done' },
702
757
  { label: `Installing Radar (namespace ${status.plan?.namespace ?? 'radar'})`, state: provisioning ? 'active' : 'done' },
703
758
  { label: 'Waiting for Radar to connect to Cloud', state: provisioning ? 'todo' : 'active' },
@@ -707,24 +762,7 @@ function ProgressCard({ status, onStatus }: { status: CloudInstallStatus; onStat
707
762
  <h4 className="text-[15px] font-semibold text-theme-text-primary mb-3.5">
708
763
  Connecting {status.clusterName}
709
764
  </h4>
710
- <ul className="space-y-2.5">
711
- {steps.map((step) => (
712
- <li key={step.label} className="flex items-center gap-2.5 text-[12.5px]">
713
- {step.state === 'done' ? (
714
- <Check className="w-4 h-4 text-emerald-600 dark:text-emerald-400" />
715
- ) : step.state === 'active' ? (
716
- <Loader2 className="w-4 h-4 animate-spin text-emerald-600 dark:text-emerald-400" />
717
- ) : (
718
- <span className="w-4 h-4 grid place-items-center">
719
- <span className="w-1.5 h-1.5 rounded-full bg-theme-border" />
720
- </span>
721
- )}
722
- <span className={step.state === 'todo' ? 'text-theme-text-tertiary' : 'text-theme-text-secondary'}>
723
- {step.label}
724
- </span>
725
- </li>
726
- ))}
727
- </ul>
765
+ <StepList steps={steps} />
728
766
  <div className="mt-4">
729
767
  {provisioning ? (
730
768
  <p className="text-[11px] text-theme-text-tertiary">
@@ -9,8 +9,16 @@ import { CloudFunnelButton } from './CloudFunnelButton'
9
9
  const connection = vi.hoisted(() => ({ state: 'connecting' as ConnectionStateType }))
10
10
  vi.mock('../context/ConnectionContext', () => ({ useConnection: () => ({ connection }) }))
11
11
  vi.mock('./ui/Tooltip', () => ({ Tooltip: ({ children }: { children: ReactNode }) => children }))
12
- vi.mock('./ui/Toast', () => ({ showApiError: vi.fn() }))
13
- vi.mock('./CloudConnectFlow', () => ({ CloudConnectFlow: () => <div>Install flow</div> }))
12
+ const toast = vi.hoisted(() => ({ showApiError: vi.fn() }))
13
+ vi.mock('./ui/Toast', () => toast)
14
+ vi.mock('./CloudConnectFlow', () => ({
15
+ CloudConnectFlow: ({ status, blocked, onExit }: { status: { state: string; prepareStep?: string }; blocked: unknown; onExit: () => void }) => (
16
+ <div>
17
+ Install flow [{blocked ? 'blocked' : status.state} {status.prepareStep ?? '-'}]
18
+ <button onClick={onExit}>Leave flow</button>
19
+ </div>
20
+ ),
21
+ }))
14
22
 
15
23
  Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
16
24
  let root: Root
@@ -19,6 +27,10 @@ let lane: 'driver' | 'wizard'
19
27
  let discovery: { connected: { namespace: string; deployment: string; clusterUrl: string }[] }
20
28
  let discoveryStatus: number
21
29
  let flowState: 'idle' | 'awaiting_approval'
30
+ // When set, /status answers with this body instead of { state: flowState }.
31
+ let statusBody: Record<string, unknown> | null
32
+ // When set, the prepare POST stays pending until the test settles it.
33
+ let prepareReply: { promise: Promise<Response>; resolve: (r: Response) => void; reject: (e: unknown) => void } | null
22
34
  const requests: string[] = []
23
35
 
24
36
  beforeEach(() => {
@@ -27,6 +39,9 @@ beforeEach(() => {
27
39
  discovery = { connected: [] }
28
40
  discoveryStatus = 200
29
41
  flowState = 'idle'
42
+ statusBody = null
43
+ prepareReply = null
44
+ toast.showApiError.mockClear()
30
45
  requests.length = 0
31
46
  client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
32
47
  const element = document.createElement('div')
@@ -38,12 +53,13 @@ beforeEach(() => {
38
53
  const bodies: Record<string, unknown> = {
39
54
  '/api/capabilities': { cloudConnect: { lane, appUrl: 'https://cloud.example', apiUrl: 'https://cloud.example' }, deployment: { mode: 'local' } },
40
55
  '/api/cluster-info': { context: 'test-cluster' },
41
- '/api/cloud/install/status': { state: flowState },
56
+ '/api/cloud/install/status': statusBody ?? { state: flowState },
42
57
  '/api/cloud/install/discover': discoveryStatus === 200 ? discovery : { error: 'Discovery failed' },
43
58
  '/api/cloud/install/prepare': { error: 'Not connected to cluster' },
44
59
  '/api/connect/info': {},
45
60
  }
46
61
  if (!(url.pathname in bodies)) throw new Error(`Unexpected request: ${input}`)
62
+ if (url.pathname.endsWith('/prepare') && prepareReply) return prepareReply.promise
47
63
  const status = url.pathname.endsWith('/prepare') ? 503 : url.pathname.endsWith('/discover') ? discoveryStatus : 200
48
64
  return new Response(JSON.stringify(bodies[url.pathname]), { status })
49
65
  }))
@@ -62,11 +78,28 @@ async function render() {
62
78
  })
63
79
  }
64
80
 
65
- async function until(assertion: () => void) {
81
+ async function until(assertion: () => void, timeout = 1000) {
66
82
  await vi.waitFor(async () => {
67
83
  await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
68
84
  assertion()
69
- })
85
+ }, { timeout })
86
+ }
87
+
88
+ function holdPrepare() {
89
+ let resolve!: (r: Response) => void
90
+ let reject!: (e: unknown) => void
91
+ const promise = new Promise<Response>((res, rej) => { resolve = res; reject = rej })
92
+ prepareReply = { promise, resolve, reject }
93
+ return prepareReply
94
+ }
95
+
96
+ const statusPolls = () => requests.filter(path => path === '/api/cloud/install/status').length
97
+
98
+ async function startConnect() {
99
+ connection.state = 'connected'
100
+ await openDialog()
101
+ await until(() => expect(button('Connect this cluster…')?.disabled).toBe(false))
102
+ await act(async () => { button('Connect this cluster…')!.click() })
70
103
  }
71
104
 
72
105
  function button(text: string) {
@@ -153,3 +186,105 @@ describe('Cloud dialog connection availability', () => {
153
186
  expect(document.body.textContent).not.toContain('Continue in Radar Cloud')
154
187
  })
155
188
  })
189
+
190
+ describe('Cloud connect preparation progress', () => {
191
+ it('polls the server while the prepare request is pending and shows its step', async () => {
192
+ holdPrepare()
193
+ await startConnect()
194
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing -]'))
195
+ const before = statusPolls()
196
+ statusBody = { flowId: 'f1', state: 'preparing', prepareStep: 'prepare' }
197
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing prepare]'), 3000)
198
+ expect(statusPolls()).toBeGreaterThan(before)
199
+ })
200
+
201
+ it('keeps the last step seen when the server clears a blocked preparation before answering', async () => {
202
+ const reply = holdPrepare()
203
+ await startConnect()
204
+ statusBody = { flowId: 'f1', state: 'preparing', prepareStep: 'preflight' }
205
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing preflight]'), 3000)
206
+ statusBody = { state: 'idle' }
207
+ const before = statusPolls()
208
+ await until(() => expect(statusPolls()).toBeGreaterThan(before), 3000)
209
+ expect(document.body.textContent).toContain('Install flow [preparing preflight]')
210
+
211
+ await act(async () => {
212
+ reply.resolve(new Response(JSON.stringify({ state: 'blocked', blocked: { reason: 'preflight', message: 'No permission' } }), { status: 200 }))
213
+ })
214
+ await until(() => expect(document.body.textContent).toContain('Install flow [blocked -]'))
215
+ const settled = statusPolls()
216
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 1300)) })
217
+ expect(statusPolls()).toBe(settled)
218
+ })
219
+
220
+ it.each(['ready', 'failed'] as const)('stays on a flow the poll saw %s when the prepare request itself is lost', async state => {
221
+ const reply = holdPrepare()
222
+ await startConnect()
223
+ statusBody = { flowId: 'f1', state: 'preparing', prepareStep: 'preflight' }
224
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing preflight]'), 3000)
225
+ statusBody = { flowId: 'f1', state }
226
+ await until(() => expect(document.body.textContent).toContain(`Install flow [${state} -]`), 3000)
227
+ await act(async () => { reply.reject(new TypeError('Failed to fetch')) })
228
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
229
+ expect(document.body.textContent).toContain(`Install flow [${state} -]`)
230
+ expect(toast.showApiError).not.toHaveBeenCalled()
231
+ expect(button('Try again')).toBeUndefined()
232
+ })
233
+
234
+ it('keeps a reattached flow that moved on when the retry\'s own answer is lost', async () => {
235
+ // The first request fails while the server is still preparing f1, so the
236
+ // dialog returns to the pitch with f1 cached as preparing.
237
+ const first = holdPrepare()
238
+ await startConnect()
239
+ statusBody = { flowId: 'f1', state: 'preparing', prepareStep: 'inspect' }
240
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing inspect]'), 3000)
241
+ await act(async () => { first.reject(new TypeError('Failed to fetch')) })
242
+ await until(() => expect(button('Try again')).toBeDefined())
243
+ // The retry attaches to the same flow; it reaches ready, and this answer
244
+ // is lost too. Same flow id, but a state seen only after the retry began.
245
+ const retry = holdPrepare()
246
+ await act(async () => { button('Try again')!.click() })
247
+ statusBody = { flowId: 'f1', state: 'ready' }
248
+ await until(() => expect(document.body.textContent).toContain('Install flow [ready -]'), 3000)
249
+ toast.showApiError.mockClear()
250
+ await act(async () => { retry.reject(new TypeError('Failed to fetch')) })
251
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
252
+ expect(document.body.textContent).toContain('Install flow [ready -]')
253
+ expect(toast.showApiError).not.toHaveBeenCalled()
254
+ })
255
+
256
+ it('reports a failed attempt even when an older flow arrived in the status cache after the click', async () => {
257
+ const reply = holdPrepare()
258
+ await startConnect()
259
+ // The status fetched as the dialog opened answers late, with a failed
260
+ // flow from an earlier session that this attempt never saw preparing.
261
+ statusBody = { flowId: 'f0', state: 'failed' }
262
+ await until(() => expect(document.body.textContent).toContain('Install flow [failed -]'), 3000)
263
+ await act(async () => { reply.reject(new TypeError('Failed to fetch')) })
264
+ await until(() => expect(toast.showApiError).toHaveBeenCalled())
265
+ expect(button('Try again')).toBeDefined()
266
+ })
267
+
268
+ it('ignores a late answer from an earlier attempt once a new one has started', async () => {
269
+ const first = holdPrepare()
270
+ await startConnect()
271
+ statusBody = { flowId: 'f1', state: 'preparing', prepareStep: 'inspect' }
272
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing inspect]'), 3000)
273
+ statusBody = { flowId: 'f1', state: 'ready' }
274
+ await until(() => expect(document.body.textContent).toContain('Install flow [ready -]'), 3000)
275
+ // The person leaves the first plan and connects again while the first
276
+ // request still has not answered.
277
+ statusBody = { state: 'idle' }
278
+ await act(async () => { button('Leave flow')!.click() })
279
+ await until(() => expect(button('Connect this cluster…')?.disabled).toBe(false), 3000)
280
+ holdPrepare()
281
+ await act(async () => { button('Connect this cluster…')!.click() })
282
+ statusBody = { flowId: 'f2', state: 'preparing', prepareStep: 'prepare' }
283
+ await until(() => expect(document.body.textContent).toContain('Install flow [preparing prepare]'), 3000)
284
+
285
+ await act(async () => { first.reject(new TypeError('Failed to fetch')) })
286
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
287
+ expect(document.body.textContent).toContain('Install flow [preparing prepare]')
288
+ expect(toast.showApiError).not.toHaveBeenCalled()
289
+ })
290
+ })
@@ -1,5 +1,5 @@
1
- import { useEffect, useId, useState } from 'react'
2
- import { useMutation, useQueryClient } from '@tanstack/react-query'
1
+ import { useEffect, useId, useRef, useState } from 'react'
2
+ import { useIsMutating, useMutation, useQueryClient } from '@tanstack/react-query'
3
3
  import { Bell, Check, Cloud, Globe, History, Sparkles, Users, X } from 'lucide-react'
4
4
  import { Collapse, CollapseChevron } from '@skyhook-io/k8s-ui/components/ui/Collapse'
5
5
  import { DialogPortal } from '@skyhook-io/k8s-ui/components/ui/DialogPortal'
@@ -22,6 +22,7 @@ import {
22
22
  type CloudConnectSelf,
23
23
  type CloudInstallConnectedRadar,
24
24
  type CloudInstallBlocked,
25
+ type CloudInstallStage,
25
26
  type CloudInstallStatus,
26
27
  prepareCloudInstall,
27
28
  useCapabilities,
@@ -76,6 +77,7 @@ const ABOUT_URL = 'https://radarhq.io/about'
76
77
  const BENCHMARK_URL = 'https://radarhq.io/benchmark'
77
78
  const PRICING_URL = 'https://radarhq.io/pricing'
78
79
  const SEEN_KEY = 'radar.cloudFunnel.seen'
80
+ const PREPARE_MUTATION_KEY = ['cloud-install-prepare']
79
81
 
80
82
  // localStorage access can throw (SecurityError) where storage is denied —
81
83
  // sandboxed embeds, some privacy modes. This button mounts in the top bar
@@ -104,6 +106,17 @@ export function CloudFunnelButton() {
104
106
  const [inFlowView, setInFlowView] = useState(false)
105
107
  const [selfManaged, setSelfManaged] = useState(false)
106
108
  const [blocked, setBlocked] = useState<CloudInstallBlocked | null>(null)
109
+ // The server flow this attempt was seen preparing, and the furthest check it
110
+ // reached. A blocked preparation clears the flow before its request answers,
111
+ // so a poll in between reads idle; the synthesized view resumes at this
112
+ // step rather than the first. Only this flow can stand in for a prepare
113
+ // answer that was lost: a status from before the click, or another flow
114
+ // fetched late, says nothing about this attempt.
115
+ const [seenPreparing, setSeenPreparing] = useState<{ flowId: string; step?: CloudInstallStage } | null>(null)
116
+ // Identifies the latest Connect attempt. The status poll can show a plan
117
+ // before its prepare request answers, so the person may move on and start
118
+ // again; a late answer from an earlier attempt must not act on the new one.
119
+ const attemptRef = useRef(0)
107
120
  // Set once an in-app attempt has ended without connecting, naming what
108
121
  // happened (a flow failure kind, a blocked plan, a canceled plan, or the
109
122
  // prepare call itself failing) and whether it is worth trying again. It
@@ -157,7 +170,8 @@ export function CloudFunnelButton() {
157
170
 
158
171
  // The flow is server-owned: polling here both drives the live progress view
159
172
  // and re-attaches to an ongoing flow after a reload or modal close.
160
- const flowStatus = useCloudInstallStatus(lane === 'driver')
173
+ const preparing = useIsMutating({ mutationKey: PREPARE_MUTATION_KEY }) > 0
174
+ const flowStatus = useCloudInstallStatus(lane === 'driver', preparing)
161
175
  const flow = flowStatus.data
162
176
  const flowLive = cloudInstallActive(flow?.state) || flow?.state === 'connected' || flow?.state === 'failed'
163
177
 
@@ -167,13 +181,17 @@ export function CloudFunnelButton() {
167
181
  flowStatus.invalidate()
168
182
  }
169
183
 
170
- const prepare = useMutation({
171
- mutationFn: prepareCloudInstall,
172
- onSuccess: (st) => {
184
+ // The variable is the attempt id, read back in the callbacks.
185
+ const prepare = useMutation<CloudInstallStatus, Error, number>({
186
+ mutationKey: PREPARE_MUTATION_KEY,
187
+ mutationFn: () => prepareCloudInstall(),
188
+ onSuccess: (st, attempt) => {
189
+ if (attempt !== attemptRef.current) return
173
190
  if (st.state === 'blocked' && st.blocked) setBlocked(st.blocked)
174
191
  else applyStatus(st)
175
192
  },
176
- onError: (err) => {
193
+ onError: (err, attempt) => {
194
+ if (attempt !== attemptRef.current) return
177
195
  // A single-flight 409 is not a failure: its body IS the live flow (one
178
196
  // started in another tab, or before this tab's status cache refreshed).
179
197
  // Attach to it rather than showing an error over a running install.
@@ -182,6 +200,20 @@ export function CloudFunnelButton() {
182
200
  applyStatus(live)
183
201
  return
184
202
  }
203
+ // The status poll may already have seen this attempt's preparation
204
+ // finish (and the flow move on from there): only this request's answer
205
+ // was lost. Stay on what the server reports rather than calling a
206
+ // finished inspection a failure.
207
+ const polled = queryClient.getQueryData<CloudInstallStatus>(['cloud-install-status'])
208
+ if (
209
+ polled?.flowId &&
210
+ polled.flowId === seenPreparing?.flowId &&
211
+ polled.state !== 'idle' &&
212
+ polled.state !== 'preparing'
213
+ ) {
214
+ flowStatus.invalidate()
215
+ return
216
+ }
185
217
  // Anything else failed before a flow existed. Return to the pitch rather
186
218
  // than leaving the flow view armed, where a later status change would
187
219
  // pull the user into a screen they did not ask for.
@@ -205,8 +237,10 @@ export function CloudFunnelButton() {
205
237
  const startConnect = () => {
206
238
  setBlocked(null)
207
239
  setHandoff(null)
240
+ setSeenPreparing(null)
208
241
  setInFlowView(true)
209
- prepare.mutate()
242
+ attemptRef.current += 1
243
+ prepare.mutate(attemptRef.current)
210
244
  }
211
245
 
212
246
  // A flow that ended without connecting returns to a pitch whose CTA must
@@ -242,6 +276,13 @@ export function CloudFunnelButton() {
242
276
  return { outcome: 'install_plan_canceled', retryable: false }
243
277
  }
244
278
 
279
+ const observed = prepare.isPending && flow?.state === 'preparing' ? flow : undefined
280
+ if (observed?.flowId) {
281
+ const sameFlow = observed.flowId === seenPreparing?.flowId
282
+ const step = observed.prepareStep ?? (sameFlow ? seenPreparing?.step : undefined)
283
+ if (!sameFlow || step !== seenPreparing?.step) setSeenPreparing({ flowId: observed.flowId, step })
284
+ }
285
+
245
286
  useEffect(() => {
246
287
  window.addEventListener(OPEN_EVENT, openModal)
247
288
  return () => window.removeEventListener(OPEN_EVENT, openModal)
@@ -280,7 +321,7 @@ export function CloudFunnelButton() {
280
321
  // explanation back to the pitch.
281
322
  const flowForView: CloudInstallStatus | undefined =
282
323
  prepare.isPending && !flowLive
283
- ? { state: 'preparing' }
324
+ ? { state: 'preparing', prepareStep: seenPreparing?.step }
284
325
  : (flow ?? (blocked ? { state: 'blocked', blocked } : undefined))
285
326
 
286
327
  return (
@@ -191,3 +191,37 @@ describe('ConnectionErrorView kubeconfig guidance', () => {
191
191
  expect(markup).not.toContain('Switch context')
192
192
  })
193
193
  })
194
+
195
+ describe('ConnectionErrorView after a refused switch', () => {
196
+ const connection = { state: 'disconnected' as const, context: 'staging-eu', errorType: 'auth', error: 'safe error' }
197
+
198
+ it('offers a way back to the cluster the person was using', () => {
199
+ const markup = renderToStaticMarkup(
200
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} back={{ label: 'kind-radar-ph-video', onBack: () => {} }} variant="switch" />,
201
+ )
202
+ expect(markup).toContain('Back to kind-radar-ph-video')
203
+ })
204
+
205
+ it('does not promise background re-checks for a cluster it never connected to', () => {
206
+ const switchMarkup = renderToStaticMarkup(
207
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} variant="switch" />,
208
+ )
209
+ const connectionMarkup = renderToStaticMarkup(
210
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} />,
211
+ )
212
+ expect(connectionMarkup).toContain('re-checks in the background')
213
+ expect(switchMarkup).not.toContain('re-checks in the background')
214
+ expect(switchMarkup).not.toContain('Back to')
215
+ })
216
+ })
217
+
218
+ describe('ConnectionErrorView after a refused switch with a stuck credential plugin', () => {
219
+ it('does not say Radar keeps checking a cluster it never connected to', () => {
220
+ const connection = { state: 'disconnected' as const, context: 'prod', errorType: 'auth-plugin-stuck', error: 'safe error' }
221
+ const switchMarkup = renderToStaticMarkup(<ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} variant="switch" />)
222
+ const connectionMarkup = renderToStaticMarkup(<ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} />)
223
+ expect(connectionMarkup).toContain('keep checking in the background')
224
+ expect(switchMarkup).not.toContain('keep checking in the background')
225
+ expect(switchMarkup).toContain('use Retry Connection')
226
+ })
227
+ })