@skyhook-io/radar-app 1.19.0 → 1.20.1
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.
- package/README.md +1 -1
- package/package.json +5 -5
- package/src/App.tsx +37 -9
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +353 -64
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/helmInventory.test.tsx +108 -0
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +42 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/curl/ServiceCurlAvailability.test.tsx +32 -0
- package/src/components/curl/ServiceCurlButton.tsx +2 -2
- package/src/components/diagnose/AIMarkdown.tsx +3 -0
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
- package/src/components/diagnose/DiagnoseContext.tsx +68 -2
- package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +26 -0
- package/src/components/diagnose/Home.tsx +20 -1
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
- package/src/components/diagnose/InvestigationView.tsx +94 -26
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.tsx +8 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.test.tsx +50 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +72 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +51 -16
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/listings.ts +34 -4
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +3 -2
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/helm/HelmDrawerFrame.tsx +101 -0
- package/src/components/helm/HelmDrawerRouting.test.tsx +86 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +23 -86
- package/src/components/helm/HelmView.tsx +213 -71
- package/src/components/helm/ObservedHelmNotice.tsx +146 -0
- package/src/components/helm/ObservedHelmRelease.test.tsx +261 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +80 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +228 -0
- package/src/components/helm/OwnedResources.tsx +4 -2
- package/src/components/home/ClusterHealthCard.restricted.test.tsx +76 -0
- package/src/components/home/ClusterHealthCard.tsx +28 -5
- package/src/components/home/HelmSummary.tsx +23 -4
- package/src/components/home/HelmSummary.unread.test.ts +16 -0
- package/src/components/home/HomeAgentBlock.test.tsx +31 -3
- package/src/components/home/HomeAgentBlock.tsx +20 -4
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +81 -41
- package/src/components/home/MCPSetupDialog.test.tsx +126 -10
- package/src/components/home/MCPSetupDialog.tsx +33 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +67 -14
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +22 -1
- package/src/components/issues/uncheckedSources.ts +21 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/resources/renderers/ServiceRenderer.test.tsx +15 -2
- package/src/components/resources/renderers/ServiceRenderer.tsx +1 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +160 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +128 -0
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
- package/src/components/whats-new/releaseNotes.ts +77 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +8 -4
- package/src/hooks/useElementSize.ts +30 -0
- package/src/hooks/useResolvedGitOpsOwner.test.ts +22 -0
- package/src/hooks/useResolvedGitOpsOwner.ts +6 -3
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +17 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { automaticRequestHeaders, setAutomaticRequestMarking } from './config'
|
|
6
|
+
import { useUsageRecording, type UsageDataStatus } from './usage-data'
|
|
7
|
+
import { exampleStatus } from './usage-data.fixtures'
|
|
8
|
+
|
|
9
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
10
|
+
|
|
11
|
+
const TICK_MS = 5 * 60_000
|
|
12
|
+
let root: Root
|
|
13
|
+
let container: HTMLDivElement
|
|
14
|
+
let visibility: DocumentVisibilityState
|
|
15
|
+
const fetchMock = vi.fn<(...args: unknown[]) => Promise<Response>>(() => Promise.resolve(new Response(null, { status: 204 })))
|
|
16
|
+
|
|
17
|
+
function Recorder({ view, status }: { view: string; status: UsageDataStatus | undefined }) {
|
|
18
|
+
useUsageRecording(view, status)
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function render(view: string, status: UsageDataStatus | undefined) {
|
|
23
|
+
act(() => root.render(<Recorder view={view} status={status} />))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sentEvents(): Array<Record<string, unknown>> {
|
|
27
|
+
return fetchMock.mock.calls.map((call) => JSON.parse(String((call[1] as RequestInit).body)))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function activeEvents() {
|
|
31
|
+
return sentEvents().filter((e) => e.type === 'active')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tick() {
|
|
35
|
+
act(() => {
|
|
36
|
+
vi.advanceTimersByTime(TICK_MS)
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const on = exampleStatus({ state: 'on', source: 'user' })
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
vi.useFakeTimers()
|
|
44
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
45
|
+
fetchMock.mockClear()
|
|
46
|
+
visibility = 'visible'
|
|
47
|
+
Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => visibility })
|
|
48
|
+
container = document.createElement('div')
|
|
49
|
+
document.body.appendChild(container)
|
|
50
|
+
root = createRoot(container)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
// Leave recording off for whatever runs next in this worker.
|
|
55
|
+
render('home', undefined)
|
|
56
|
+
act(() => root.unmount())
|
|
57
|
+
container.remove()
|
|
58
|
+
vi.useRealTimers()
|
|
59
|
+
vi.unstubAllGlobals()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('useUsageRecording active time', () => {
|
|
63
|
+
it('counts a tick only when someone used the visible page during it', () => {
|
|
64
|
+
render('topology', on)
|
|
65
|
+
tick()
|
|
66
|
+
expect(activeEvents()).toEqual([])
|
|
67
|
+
|
|
68
|
+
act(() => {
|
|
69
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'j' }))
|
|
70
|
+
})
|
|
71
|
+
tick()
|
|
72
|
+
expect(activeEvents()).toEqual([{ type: 'active', minutes: 5 }])
|
|
73
|
+
|
|
74
|
+
// Input belongs to the tick it happened in.
|
|
75
|
+
tick()
|
|
76
|
+
expect(activeEvents()).toHaveLength(1)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('does not count a hidden page, even with input', () => {
|
|
80
|
+
render('topology', on)
|
|
81
|
+
visibility = 'hidden'
|
|
82
|
+
act(() => {
|
|
83
|
+
window.dispatchEvent(new PointerEvent('pointerdown'))
|
|
84
|
+
})
|
|
85
|
+
tick()
|
|
86
|
+
expect(activeEvents()).toEqual([])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('ignores a page that scrolls by itself, such as logs being followed', () => {
|
|
90
|
+
render('resources:pods', on)
|
|
91
|
+
const list = document.createElement('div')
|
|
92
|
+
container.appendChild(list)
|
|
93
|
+
act(() => {
|
|
94
|
+
list.dispatchEvent(new Event('scroll'))
|
|
95
|
+
})
|
|
96
|
+
tick()
|
|
97
|
+
expect(activeEvents()).toEqual([])
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('sends nothing while usage data is off', () => {
|
|
101
|
+
render('topology', exampleStatus({ state: 'off', source: 'user' }))
|
|
102
|
+
act(() => {
|
|
103
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'j' }))
|
|
104
|
+
})
|
|
105
|
+
tick()
|
|
106
|
+
expect(fetchMock).not.toHaveBeenCalled()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('automatic request marking', () => {
|
|
111
|
+
afterEach(() => setAutomaticRequestMarking(false))
|
|
112
|
+
|
|
113
|
+
it('keeps an embedding host unmarked', () => {
|
|
114
|
+
render('home', undefined)
|
|
115
|
+
expect(automaticRequestHeaders()).toEqual({})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('stays marked until the status says usage data is not recorded', () => {
|
|
119
|
+
setAutomaticRequestMarking(true)
|
|
120
|
+
render('home', undefined)
|
|
121
|
+
expect(automaticRequestHeaders()).toEqual({ 'X-Radar-Request-Origin': 'auto' })
|
|
122
|
+
render('home', on)
|
|
123
|
+
expect(automaticRequestHeaders()).toEqual({ 'X-Radar-Request-Origin': 'auto' })
|
|
124
|
+
render('home', exampleStatus({ state: 'off', source: 'user' }))
|
|
125
|
+
expect(automaticRequestHeaders()).toEqual({})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('marks requests when usage data is turned on later', () => {
|
|
129
|
+
render('home', exampleStatus({ state: 'off', source: 'user' }))
|
|
130
|
+
expect(automaticRequestHeaders()).toEqual({})
|
|
131
|
+
render('home', on)
|
|
132
|
+
expect(automaticRequestHeaders()).toEqual({ 'X-Radar-Request-Origin': 'auto' })
|
|
133
|
+
})
|
|
134
|
+
})
|
package/src/api/usage-data.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect } from 'react'
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
3
3
|
import { fetchJSON } from './client'
|
|
4
|
-
import { apiUrl, getApiBase, getAuthHeaders, getCredentialsMode } from './config'
|
|
4
|
+
import { apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, setAutomaticRequestMarking } from './config'
|
|
5
5
|
|
|
6
6
|
export type UsageDataState = 'undecided' | 'on' | 'off'
|
|
7
7
|
export type UsageDataSource = 'default' | 'user' | 'env' | 'deployment'
|
|
@@ -26,9 +26,12 @@ export interface UsageReport {
|
|
|
26
26
|
authMode: string
|
|
27
27
|
timelineStorage: string
|
|
28
28
|
mcpEnabled: boolean
|
|
29
|
+
// 'none' | 'discovered' | 'manual'
|
|
29
30
|
prometheus: string
|
|
30
31
|
costSource: string
|
|
31
32
|
browsers: string[]
|
|
33
|
+
aiConfigured: boolean
|
|
34
|
+
trafficSource: string
|
|
32
35
|
}
|
|
33
36
|
engagement: { sessions: number; activeMinutes: string }
|
|
34
37
|
views: Record<string, number>
|
|
@@ -36,6 +39,8 @@ export interface UsageReport {
|
|
|
36
39
|
mcpTools: Record<string, number>
|
|
37
40
|
uiEvents: Record<string, number>
|
|
38
41
|
errors: Record<string, number>
|
|
42
|
+
actionKinds: Record<string, number>
|
|
43
|
+
connectionFailures: Record<string, number>
|
|
39
44
|
clusters: { contexts: string; used: number; shapes: ClusterShape[] }
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -140,14 +145,27 @@ export function recordUsageEvent(event: UsageEvent): void {
|
|
|
140
145
|
|
|
141
146
|
const ACTIVE_TICK_MINUTES = 5
|
|
142
147
|
|
|
143
|
-
//
|
|
144
|
-
//
|
|
148
|
+
// Real use: a window left open on a second screen sees none of these. Scroll
|
|
149
|
+
// isn't one: following logs scrolls by itself, and a person scrolling already
|
|
150
|
+
// shows up as wheel, touch, pointer or key input.
|
|
151
|
+
const INPUT_EVENTS = ['pointerdown', 'pointermove', 'keydown', 'wheel', 'touchstart'] as const
|
|
152
|
+
|
|
153
|
+
// Counts views, one session per page load, and time in use in five-minute
|
|
154
|
+
// ticks: a tick counts only if the page is visible and someone used it during
|
|
155
|
+
// that tick. Nothing is sent unless usage data is on.
|
|
145
156
|
export function useUsageRecording(view: string, status: UsageDataStatus | undefined) {
|
|
146
157
|
const on = isRecording(status)
|
|
158
|
+
|
|
147
159
|
useEffect(() => {
|
|
148
160
|
setUsageRecording(on)
|
|
149
161
|
}, [on])
|
|
150
162
|
|
|
163
|
+
// No status yet leaves the mark as the entry point set it.
|
|
164
|
+
const decided = status !== undefined
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (decided) setAutomaticRequestMarking(on)
|
|
167
|
+
}, [decided, on])
|
|
168
|
+
|
|
151
169
|
useEffect(() => {
|
|
152
170
|
if (on) recordUsageEvent({ type: 'view', name: view })
|
|
153
171
|
}, [view, on])
|
|
@@ -155,11 +173,21 @@ export function useUsageRecording(view: string, status: UsageDataStatus | undefi
|
|
|
155
173
|
useEffect(() => {
|
|
156
174
|
if (!on) return
|
|
157
175
|
recordUsageEvent({ type: 'session' })
|
|
176
|
+
let usedThisTick = false
|
|
177
|
+
const markUsed = () => {
|
|
178
|
+
usedThisTick = true
|
|
179
|
+
}
|
|
180
|
+
// Capture, because views may stop propagation.
|
|
181
|
+
const listenerOptions = { capture: true, passive: true }
|
|
182
|
+
for (const type of INPUT_EVENTS) window.addEventListener(type, markUsed, listenerOptions)
|
|
158
183
|
const tick = window.setInterval(() => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
184
|
+
const used = usedThisTick && document.visibilityState === 'visible'
|
|
185
|
+
usedThisTick = false
|
|
186
|
+
if (used) recordUsageEvent({ type: 'active', minutes: ACTIVE_TICK_MINUTES })
|
|
162
187
|
}, ACTIVE_TICK_MINUTES * 60_000)
|
|
163
|
-
return () =>
|
|
188
|
+
return () => {
|
|
189
|
+
window.clearInterval(tick)
|
|
190
|
+
for (const type of INPUT_EVENTS) window.removeEventListener(type, markUsed, listenerOptions)
|
|
191
|
+
}
|
|
164
192
|
}, [on])
|
|
165
193
|
}
|
|
@@ -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:
|
|
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
|
-
<
|
|
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.
|
|
13
|
-
vi.mock('./
|
|
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
|
+
})
|