@skyhook-io/radar-app 1.20.1 → 1.21.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.
- package/package.json +10 -9
- package/src/App.tsx +65 -16
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
- package/src/api/client.pauseDeployment.test.tsx +77 -0
- package/src/api/client.restartError.test.ts +14 -0
- package/src/api/client.revisionRefresh.test.tsx +44 -0
- package/src/api/client.rollbackError.test.ts +14 -0
- package/src/api/client.ts +347 -16
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/networkAttachments.test.tsx +120 -0
- package/src/api/networkAttachments.ts +30 -0
- package/src/api/radarFeatures.test.ts +5 -0
- package/src/api/radarFeatures.ts +10 -0
- package/src/api/secretsStore.test.ts +33 -0
- package/src/api/secretsStore.ts +37 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +201 -0
- package/src/api/vulnerabilities.ts +255 -0
- package/src/components/ConnectionErrorView.test.tsx +11 -0
- package/src/components/ConnectionErrorView.tsx +19 -0
- package/src/components/ContextSwitcher.tsx +9 -2
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
- package/src/components/applications/ApplicationsView.tsx +8 -11
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
- package/src/components/audit/ChecksViewTabs.tsx +11 -1
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +907 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/cost/CostView.tsx +27 -9
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
- package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
- package/src/components/dock/TerminalPreferences.test.tsx +68 -0
- package/src/components/dock/TerminalPreferences.tsx +73 -0
- package/src/components/gitops/GitOpsView.tsx +2 -10
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
- package/src/components/helm/HelmView.tsx +25 -19
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- package/src/components/helm/OwnedResources.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +69 -11
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +25 -11
- package/src/components/home/HelmSummary.tsx +15 -15
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +17 -4
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/RightsizingStrip.test.ts +57 -0
- package/src/components/resource/RightsizingStrip.tsx +53 -4
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
- package/src/components/resources/ImageFilesystemModal.tsx +98 -6
- package/src/components/resources/PodFileUploadPanel.tsx +150 -0
- package/src/components/resources/PodFilesystemModal.tsx +246 -3
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/pod-file-upload.test.tsx +223 -0
- package/src/components/resources/pod-file-upload.ts +266 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
- package/src/components/resources/renderers/PodRenderer.tsx +26 -1
- package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
- package/src/components/rightsizing/model.test.ts +11 -0
- package/src/components/rightsizing/model.ts +3 -1
- package/src/components/rightsizing/presentation.test.ts +46 -0
- package/src/components/rightsizing/presentation.ts +17 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +72 -155
- package/src/components/traffic/trafficFilters.test.ts +189 -1
- package/src/components/traffic/trafficFilters.ts +169 -1
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/Omnibar.tsx +4 -1
- package/src/components/ui/RadarOmnibar.test.tsx +55 -2
- package/src/components/ui/RadarOmnibar.tsx +7 -1
- package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
- package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +54 -3
- package/src/components/ui/UpdateNotification.tsx +60 -19
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/ui/omnibar-match.test.ts +7 -0
- package/src/components/ui/omnibar-match.ts +1 -0
- package/src/components/ui/searchCoverageNote.test.ts +17 -0
- package/src/components/ui/searchCoverageNote.ts +31 -7
- package/src/components/useContextSwitchFlow.tsx +9 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +148 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +86 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
- package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +114 -37
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +2 -2
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +15 -3
- package/src/integrations/resourceHosts.tsx +26 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyhook-io/radar-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Radar's full web UI as a reusable React component. Used by Radar's own binary and by external consumers like Radar Cloud.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"test": "vitest run src",
|
|
28
28
|
"test:e2e:settings": "playwright test --config playwright.settings.config.ts",
|
|
29
29
|
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
30
|
-
"lint": "eslint src && node scripts/check-no-native-title.mjs"
|
|
30
|
+
"lint": "eslint src && node scripts/check-no-native-title.mjs",
|
|
31
|
+
"check:startup-bundle": "node scripts/check-startup-bundle.mjs"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@fontsource-variable/dm-sans": "^5.3.0",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"react-markdown": "^10.1.0",
|
|
39
40
|
"react-virtuoso": "^4.18.16",
|
|
40
41
|
"remark-gfm": "^4.0.1",
|
|
41
|
-
"shiki": "^4.
|
|
42
|
+
"shiki": "^4.6.0",
|
|
42
43
|
"yaml": "^2.9.1"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
@@ -65,17 +66,17 @@
|
|
|
65
66
|
"@vitejs/plugin-react": "^6.1.2",
|
|
66
67
|
"@xyflow/react": "^12.12.0",
|
|
67
68
|
"clsx": "^2.1.1",
|
|
68
|
-
"elkjs": "^0.
|
|
69
|
-
"eslint": "^10.
|
|
69
|
+
"elkjs": "^0.12.1",
|
|
70
|
+
"eslint": "^10.15.0",
|
|
70
71
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
71
72
|
"eslint-plugin-react-refresh": "^0.5.7",
|
|
72
|
-
"globals": "^17.
|
|
73
|
+
"globals": "^17.14.0",
|
|
73
74
|
"lucide-react": "^1.48.0",
|
|
74
|
-
"postcss": "^8.5.
|
|
75
|
-
"prettier": "^3.
|
|
75
|
+
"postcss": "^8.5.33",
|
|
76
|
+
"prettier": "^3.10.1",
|
|
76
77
|
"react": "^19.3.0",
|
|
77
78
|
"react-dom": "^19.3.0",
|
|
78
|
-
"react-router-dom": "^7.18.
|
|
79
|
+
"react-router-dom": "^7.18.5",
|
|
79
80
|
"tailwind-merge": "^3.7.0",
|
|
80
81
|
"tailwindcss": "^4.3.3",
|
|
81
82
|
"typescript": "^6.0.2",
|
package/src/App.tsx
CHANGED
|
@@ -30,6 +30,7 @@ import { ApplicationsView } from './components/applications/ApplicationsView'
|
|
|
30
30
|
import { HelmReleaseDrawer } from './components/helm/HelmReleaseDrawer'
|
|
31
31
|
import { PortForwardProvider, PortForwardIndicator, PortForwardPanel } from './components/portforward/PortForwardManager'
|
|
32
32
|
import { DockProvider, BottomDock, useDock, useDockReservedHeight, useOpenLocalTerminal } from './components/dock'
|
|
33
|
+
import { TerminalPreferences } from './components/dock/TerminalPreferences'
|
|
33
34
|
import { DURATION_DOCK, overlayExitMs } from '@skyhook-io/k8s-ui/utils/animation'
|
|
34
35
|
import { ContextSwitcher } from './components/ContextSwitcher'
|
|
35
36
|
import { NamespaceSwitcher, type NamespaceSwitcherHandle } from './components/NamespaceSwitcher'
|
|
@@ -37,7 +38,7 @@ import { CloudFunnelButton } from './components/CloudFunnelButton'
|
|
|
37
38
|
import { useNavCustomization } from './context/NavCustomization'
|
|
38
39
|
import type { FleetTakeoverTarget } from './context/NavCustomization'
|
|
39
40
|
import { PrimaryNavRail } from './components/nav/PrimaryNavRail'
|
|
40
|
-
import { resourceExpandedPath, resourceKindListTitle } from './integrations/resourceHosts'
|
|
41
|
+
import { resourceExpandedPath, resourceKindListNamespaceFilterTooltip, resourceKindListTitle, useResourceHostFeatures } from './integrations/resourceHosts'
|
|
41
42
|
import { workspaceContextSwitchSearch, workspaceForPath, workspaceForView, workspaceLabels } from './integrations/workspaceRoutes'
|
|
42
43
|
import { WorkspaceScreen } from './integrations/workspaceScreens'
|
|
43
44
|
import { currentPageLabel } from './utils/page-links'
|
|
@@ -52,9 +53,11 @@ import { NoClusterAccessBanner } from './components/NoClusterAccessBanner'
|
|
|
52
53
|
import { CapabilitiesProvider, useCapabilitiesContext } from './contexts/CapabilitiesContext'
|
|
53
54
|
import { RadarUpgradeProvider } from './context/RadarUpgrade'
|
|
54
55
|
import { UserMenu } from './components/UserMenu'
|
|
56
|
+
import { COMMUNITY_SLACK_URL } from './components/community'
|
|
55
57
|
import { ErrorBoundary } from './components/ui/ErrorBoundary'
|
|
56
58
|
import { UpdateNotification } from './components/ui/UpdateNotification'
|
|
57
59
|
import { openWhatsNew, useWhatsNewStatus, WhatsNew } from './components/whats-new/WhatsNew'
|
|
60
|
+
import { AboutDialog, type AboutInfo } from './desktop/AboutDialog'
|
|
58
61
|
import { useUsageData, useUsageRecording } from './api/usage-data'
|
|
59
62
|
import { UsageDataPrompt } from './components/usage-data/UsageDataPrompt'
|
|
60
63
|
import { ProductHuntNotice } from './components/product-hunt/ProductHuntNotice'
|
|
@@ -62,7 +65,7 @@ import { useProductHuntRailEntry } from './components/product-hunt/useProductHun
|
|
|
62
65
|
import { ShortcutHelpOverlay } from './components/ui/ShortcutHelpOverlay'
|
|
63
66
|
import { DiagnosticsOverlay, type DiagnosticsFocus } from './components/ui/DiagnosticsOverlay'
|
|
64
67
|
import { useEventSource } from './hooks/useEventSource'
|
|
65
|
-
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, useSwitchContext, useAuthMe,
|
|
68
|
+
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useSwitchContext, useAuthMe, useAuditBadges, useClusterInfo, useCapabilities } from './api/client'
|
|
66
69
|
import { buildAuditSeverityMap } from './utils/auditBadges'
|
|
67
70
|
import { isInNamespaceScope, scopeNodesToNamespaces } from './utils/topology-namespace'
|
|
68
71
|
import { routePath, apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, stripBasename } from './api/config'
|
|
@@ -132,7 +135,7 @@ const FLEET_MODE_KINDS = new Set<NodeKind>([
|
|
|
132
135
|
|
|
133
136
|
// Convert API resource name back to topology node ID prefix
|
|
134
137
|
// Extended MainView type that includes traffic and cost
|
|
135
|
-
type ExtendedMainView = MainView | 'traffic' | 'cost' | 'capacity' | 'cnpg' | 'workload' | 'checks' | 'gitops' | 'compare' | 'helmCompare' | 'issues' | 'applications' | 'investigations'
|
|
138
|
+
type ExtendedMainView = MainView | 'traffic' | 'cost' | 'capacity' | 'cnpg' | 'velero' | 'workload' | 'checks' | 'gitops' | 'compare' | 'helmCompare' | 'issues' | 'applications' | 'investigations'
|
|
136
139
|
|
|
137
140
|
// Views that have been laid out for phone width (640px and below). The rest
|
|
138
141
|
// keep their desktop width on a phone and scroll sideways; add a view here in
|
|
@@ -196,6 +199,8 @@ const CRASH_LABELS = {
|
|
|
196
199
|
// browsing filter.
|
|
197
200
|
// - A cluster-scoped resource kind (Nodes, PVs, ClusterRoles…) has no
|
|
198
201
|
// namespace at all.
|
|
202
|
+
// - A kind whose own list ignores the filter (Velero's lists read every
|
|
203
|
+
// installation, since Velero keeps its objects in its own namespace).
|
|
199
204
|
// The pick itself is preserved so it re-applies when the user returns to a
|
|
200
205
|
// namespaced view.
|
|
201
206
|
function namespaceFilterDisabled(
|
|
@@ -203,6 +208,7 @@ function namespaceFilterDisabled(
|
|
|
203
208
|
pathname: string,
|
|
204
209
|
search = '',
|
|
205
210
|
apiResources?: APIResource[],
|
|
211
|
+
kindListTooltip?: (kind: { name: string; group: string }) => string | undefined,
|
|
206
212
|
): { disabled: boolean; tooltip?: string } {
|
|
207
213
|
if (
|
|
208
214
|
view === 'cost' &&
|
|
@@ -232,6 +238,8 @@ function namespaceFilterDisabled(
|
|
|
232
238
|
const kindSlug = segments[1]
|
|
233
239
|
const group = new URLSearchParams(search).get('apiGroup') || ''
|
|
234
240
|
const match = kindSlug ? findAPIResourceForRoute(apiResources, kindSlug, group) : undefined
|
|
241
|
+
const listTooltip = match ? kindListTooltip?.({ name: match.name, group: match.group }) : undefined
|
|
242
|
+
if (listTooltip) return { disabled: true, tooltip: listTooltip }
|
|
235
243
|
if (match && !match.namespaced) {
|
|
236
244
|
return {
|
|
237
245
|
disabled: true,
|
|
@@ -287,6 +295,7 @@ function radarPageTitle(pathname: string, search = '', apiResources?: APIResourc
|
|
|
287
295
|
}
|
|
288
296
|
|
|
289
297
|
if (view === 'checks' && pathSegments[1] === 'upgrade') return 'Upgrade impact'
|
|
298
|
+
if (view === 'checks' && pathSegments[1] === 'vulnerabilities') return 'Vulnerabilities'
|
|
290
299
|
|
|
291
300
|
// The landing view reads "Overview" rather than "Home" in the tab.
|
|
292
301
|
const workspace = workspaceForView(view)
|
|
@@ -438,6 +447,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
438
447
|
const mainView = getViewFromPath(location.pathname)
|
|
439
448
|
const activeWorkspace = workspaceForView(mainView)
|
|
440
449
|
const upgradeReadinessRoute = location.pathname.startsWith('/checks/upgrade')
|
|
450
|
+
// Checks sub-routes a Cloud host's fleet Checks pages don't have, so they
|
|
451
|
+
// render here even when the host takes over /checks.
|
|
452
|
+
const localChecksRoute = upgradeReadinessRoute || location.pathname.startsWith('/checks/vulnerabilities')
|
|
441
453
|
|
|
442
454
|
// Opt-in usage data. Embedded hosts own their own consent, so Radar never asks there.
|
|
443
455
|
const usageData = useUsageData(!navCustomization.embedded)
|
|
@@ -449,7 +461,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
449
461
|
|
|
450
462
|
// View-aware namespace scope: disabled on cluster-scoped surfaces so the
|
|
451
463
|
// chip isn't a dead control next to the cluster switcher.
|
|
452
|
-
|
|
464
|
+
// A kind whose own list ignores the filter (Velero's) disables it too, once that list is what shows.
|
|
465
|
+
const hostFeatures = useResourceHostFeatures()
|
|
466
|
+
const { isPending: capabilitiesPending } = useCapabilities()
|
|
467
|
+
const namespaceFilter = namespaceFilterDisabled(mainView, location.pathname, location.search, navApiResources,
|
|
468
|
+
(kind) => resourceKindListNamespaceFilterTooltip(kind, hostFeatures, capabilitiesPending))
|
|
453
469
|
|
|
454
470
|
// One URL-derived tab title for every view (see radarPageTitle). Driving it
|
|
455
471
|
// from the URL — not the mounted component. Off unless the host opts in
|
|
@@ -586,7 +602,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
586
602
|
// The host's URL for the CURRENT view, if taken over. Drives the redirect
|
|
587
603
|
// effect and the "Opening…" splash.
|
|
588
604
|
const viewTakeoverHref =
|
|
589
|
-
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !
|
|
605
|
+
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !localChecksRoute
|
|
590
606
|
? takeover[mainView]
|
|
591
607
|
: undefined
|
|
592
608
|
useEffect(() => {
|
|
@@ -648,6 +664,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
648
664
|
return () => window.removeEventListener('radar:open-settings', handler)
|
|
649
665
|
}, [openSettings])
|
|
650
666
|
|
|
667
|
+
// Help → About Radar in the Windows desktop app (cmd/desktop/menu.go).
|
|
668
|
+
const [aboutInfo, setAboutInfo] = useState<AboutInfo | null>(null)
|
|
669
|
+
useEffect(() => {
|
|
670
|
+
const handler = (e: Event) => setAboutInfo((e as CustomEvent<AboutInfo>).detail)
|
|
671
|
+
window.addEventListener('radar:open-about', handler)
|
|
672
|
+
return () => window.removeEventListener('radar:open-about', handler)
|
|
673
|
+
}, [])
|
|
674
|
+
|
|
651
675
|
// Listen for "open-local-terminal" DOM event — the AI surface is portaled above
|
|
652
676
|
// the DockProvider, so it can't call useOpenLocalTerminal directly; it dispatches
|
|
653
677
|
// this instead (mirrors the open-settings pattern).
|
|
@@ -915,7 +939,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
915
939
|
gitops: 'g o', checks: 'g u', cost: 'g c', capacity: 'g p',
|
|
916
940
|
// Non-rail views (reachable via deep links / actions, not the rail) get no
|
|
917
941
|
// dedicated mnemonic — listed for exhaustiveness so the type stays total.
|
|
918
|
-
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '',
|
|
942
|
+
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '', velero: '',
|
|
919
943
|
}
|
|
920
944
|
const views = Object.keys(VIEW_SHORTCUT_KEYS).filter(
|
|
921
945
|
(v): v is ExtendedMainView => VIEW_SHORTCUT_KEYS[v as ExtendedMainView] !== '',
|
|
@@ -1034,11 +1058,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1034
1058
|
const hideGroupHeader = namespaces.length === 1 && effectiveGroupingMode === 'namespace'
|
|
1035
1059
|
|
|
1036
1060
|
// Fetch available namespaces
|
|
1037
|
-
const { data: availableNamespaces } = useNamespaces()
|
|
1061
|
+
const { data: availableNamespaces, error: availableNamespacesError } = useNamespaces()
|
|
1038
1062
|
|
|
1039
|
-
//
|
|
1040
|
-
// picker can render its current
|
|
1041
|
-
// fallback during the initial
|
|
1063
|
+
// This tab's namespace pick plus the picker's source list (see
|
|
1064
|
+
// utils/namespacePick). Loaded eagerly so the picker can render its current
|
|
1065
|
+
// state without showing the multi-select fallback during the initial fetch.
|
|
1042
1066
|
const { data: namespaceScope } = useNamespaceScope()
|
|
1043
1067
|
|
|
1044
1068
|
// Context switch state
|
|
@@ -1125,6 +1149,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1125
1149
|
timer: number | null
|
|
1126
1150
|
}>({ changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null })
|
|
1127
1151
|
const cnpgInvalidationPendingRef = useRef(false)
|
|
1152
|
+
const veleroInvalidationPendingRef = useRef(false)
|
|
1128
1153
|
const slowInvalidationRef = useRef<{
|
|
1129
1154
|
updatedKinds: Set<string> // update-only churn → throttled list + dashboard
|
|
1130
1155
|
timer: number | null
|
|
@@ -1157,6 +1182,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1157
1182
|
const applicationWorkload = ['deployments', 'statefulsets', 'daemonsets', 'rollouts'].includes(kind)
|
|
1158
1183
|
|
|
1159
1184
|
if (event.group?.endsWith('.cnpg.io')) cnpgInvalidationPendingRef.current = true
|
|
1185
|
+
if (event.group === 'velero.io') veleroInvalidationPendingRef.current = true
|
|
1160
1186
|
|
|
1161
1187
|
const fast = fastInvalidationRef.current
|
|
1162
1188
|
fast.changedKinds.add(kind)
|
|
@@ -1211,6 +1237,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1211
1237
|
cnpgInvalidationPendingRef.current = false
|
|
1212
1238
|
queryClient.invalidateQueries({ queryKey: ['cnpg', 'workspace'] })
|
|
1213
1239
|
}
|
|
1240
|
+
if (veleroInvalidationPendingRef.current) {
|
|
1241
|
+
veleroInvalidationPendingRef.current = false
|
|
1242
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'workspace'] })
|
|
1243
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'schedule-activity'] })
|
|
1244
|
+
}
|
|
1214
1245
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1215
1246
|
}, 3000)
|
|
1216
1247
|
}
|
|
@@ -1381,8 +1412,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1381
1412
|
showClusterWarmupLabel ? clusterLoadState.message :
|
|
1382
1413
|
crdDiscoveryStatus === 'discovering' ? 'Discovering Custom Resources…' :
|
|
1383
1414
|
''
|
|
1415
|
+
// A settings error (ConnectionErrorView) clears only on restart.
|
|
1384
1416
|
const showHeaderReconnect =
|
|
1385
|
-
clusterConnectionState === 'disconnected' ||
|
|
1417
|
+
(clusterConnectionState === 'disconnected' && connection.errorType !== 'settings') ||
|
|
1386
1418
|
liveUpdatesDisconnected
|
|
1387
1419
|
const headerReconnect = clusterConnectionState === 'disconnected' ? retryConnection : reconnectEventStream
|
|
1388
1420
|
const headerReconnectPending = clusterConnectionState === 'disconnected' ? isRetrying : false
|
|
@@ -1451,7 +1483,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1451
1483
|
// Serialize namespaces for stable dependency tracking
|
|
1452
1484
|
const namespacesKey = namespaces.join(',')
|
|
1453
1485
|
|
|
1454
|
-
// The
|
|
1486
|
+
// The scope query holds this tab's namespace pick. Mirror its
|
|
1455
1487
|
// `actives` into App.tsx state so consumer hooks (SSE, dashboard, resource
|
|
1456
1488
|
// lists) stay in lockstep with the picker. The dedicated URL-write effect
|
|
1457
1489
|
// below propagates the mirrored state to `?namespaces=`.
|
|
@@ -1475,7 +1507,8 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1475
1507
|
if (namespaces.length === 0) return
|
|
1476
1508
|
setActiveNamespace.mutate(
|
|
1477
1509
|
{ namespaces: [] },
|
|
1478
|
-
|
|
1510
|
+
// A clear answered after a newer switch landed must not override it.
|
|
1511
|
+
{ onSuccess: (_scope, _vars, start) => { if (isAppliedNamespaceSwitch(start)) setNamespaces([]) } },
|
|
1479
1512
|
)
|
|
1480
1513
|
}, [namespaceScope?.cacheScoped, namespaces.length, setActiveNamespace])
|
|
1481
1514
|
// Same write as the header picker, which then mirrors it into `namespaces`.
|
|
@@ -1773,7 +1806,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1773
1806
|
// backend stamps on each node (data.auditKey). Only badge-worthy findings
|
|
1774
1807
|
// reach the graph; the raw auditDanger/auditWarning property names remain at
|
|
1775
1808
|
// this compatibility boundary while the node presents them as High/Medium.
|
|
1776
|
-
|
|
1809
|
+
// Only badge-worthy findings, small next to the full scan (they grow with
|
|
1810
|
+
// broken references, not with the cluster), so they stay loaded app-wide: a
|
|
1811
|
+
// view that badges resources has them on arrival.
|
|
1812
|
+
const audit = useAuditBadges(namespaces)
|
|
1777
1813
|
const auditSeverityMap = useMemo(
|
|
1778
1814
|
() => buildAuditSeverityMap(audit.data?.findings, audit.data?.checks),
|
|
1779
1815
|
[audit.data?.findings, audit.data?.checks],
|
|
@@ -1856,6 +1892,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1856
1892
|
accountSlot={<UserMenu variant="rail" pinned={navRailEffectivePinned} />}
|
|
1857
1893
|
whatsNew={whatsNewStatus.available ? { unread: whatsNewStatus.unread, onOpen: openWhatsNew } : undefined}
|
|
1858
1894
|
productHunt={productHuntRailEntry}
|
|
1895
|
+
communityUrl={COMMUNITY_SLACK_URL}
|
|
1859
1896
|
/>
|
|
1860
1897
|
)}
|
|
1861
1898
|
{/* `relative` makes this column the containing block for the absolute
|
|
@@ -1960,6 +1997,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1960
1997
|
onToggleTheme={toggleTheme}
|
|
1961
1998
|
onShowDiagnostics={() => setShowDiagnostics(true)}
|
|
1962
1999
|
onShowWhatsNew={whatsNewStatus.available ? openWhatsNew : undefined}
|
|
2000
|
+
onOpenCommunity={() => openExternal(COMMUNITY_SLACK_URL)}
|
|
1963
2001
|
onOpenResource={(hit) => navigateToResourceList(searchHitToSelectedResource(hit))}
|
|
1964
2002
|
/>
|
|
1965
2003
|
</div>
|
|
@@ -2208,6 +2246,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2208
2246
|
<div className="relative">
|
|
2209
2247
|
<LargeClusterNamespacePicker
|
|
2210
2248
|
namespaces={availableNamespaces}
|
|
2249
|
+
error={availableNamespacesError?.message}
|
|
2211
2250
|
onSelect={(ns) => {
|
|
2212
2251
|
setNamespaces([ns])
|
|
2213
2252
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2339,6 +2378,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2339
2378
|
initialTimeRange={(searchParams.get('time') as '5m' | '30m' | '1h' | '6h' | '24h' | 'all') || undefined}
|
|
2340
2379
|
requiresNamespaceFilter={topology?.requiresNamespaceFilter && namespaces.length === 0}
|
|
2341
2380
|
availableNamespaces={availableNamespaces}
|
|
2381
|
+
availableNamespacesError={availableNamespacesError?.message}
|
|
2342
2382
|
onNamespaceSelect={(ns) => {
|
|
2343
2383
|
setNamespaces([ns])
|
|
2344
2384
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2433,7 +2473,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2433
2473
|
|
|
2434
2474
|
{/* Checks detail view. Cloud can take over fleet best practices while
|
|
2435
2475
|
the target-specific upgrade route continues to render locally. */}
|
|
2436
|
-
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') ||
|
|
2476
|
+
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') || localChecksRoute) && (
|
|
2437
2477
|
<AuditView
|
|
2438
2478
|
namespaces={namespaces}
|
|
2439
2479
|
onNavigateToResource={navigateToResourceList}
|
|
@@ -2621,7 +2661,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2621
2661
|
{helpOverlay.shouldRender && <ShortcutHelpOverlay isOpen={helpOverlay.isOpen} onClose={() => setShowHelp(false)} currentView={mainView} />}
|
|
2622
2662
|
|
|
2623
2663
|
{/* Diagnostics overlay */}
|
|
2624
|
-
{diagnosticsOverlay.shouldRender && <DiagnosticsOverlay isOpen={diagnosticsOverlay.isOpen} focus={diagnosticsFocus} onClose={() => { setShowDiagnostics(false); setDiagnosticsFocus(undefined) }} />}
|
|
2664
|
+
{diagnosticsOverlay.shouldRender && <DiagnosticsOverlay isOpen={diagnosticsOverlay.isOpen} focus={diagnosticsFocus} communityUrl={embedded ? undefined : COMMUNITY_SLACK_URL} onClose={() => { setShowDiagnostics(false); setDiagnosticsFocus(undefined) }} />}
|
|
2665
|
+
|
|
2666
|
+
<AboutDialog
|
|
2667
|
+
info={aboutInfo}
|
|
2668
|
+
onClose={() => setAboutInfo(null)}
|
|
2669
|
+
onShowWhatsNew={whatsNewStatus.available ? openWhatsNew : undefined}
|
|
2670
|
+
onReportIssue={() => { setDiagnosticsFocus(undefined); setShowDiagnostics(true) }}
|
|
2671
|
+
/>
|
|
2625
2672
|
|
|
2626
2673
|
{/* Settings dialog — My permissions is rendered inline in its own section */}
|
|
2627
2674
|
<SettingsDialog
|
|
@@ -2661,6 +2708,7 @@ function DockSpacer() {
|
|
|
2661
2708
|
// Main App component wrapped with providers
|
|
2662
2709
|
function App({ manageDocumentTitle = false, documentTitleSuffix, onClusterLoadStateChange }: AppProps) {
|
|
2663
2710
|
return (
|
|
2711
|
+
<TerminalPreferences>
|
|
2664
2712
|
<ConnectionProvider>
|
|
2665
2713
|
<CapabilitiesProvider>
|
|
2666
2714
|
<RadarUpgradeProvider>
|
|
@@ -2678,6 +2726,7 @@ function App({ manageDocumentTitle = false, documentTitleSuffix, onClusterLoadSt
|
|
|
2678
2726
|
</RadarUpgradeProvider>
|
|
2679
2727
|
</CapabilitiesProvider>
|
|
2680
2728
|
</ConnectionProvider>
|
|
2729
|
+
</TerminalPreferences>
|
|
2681
2730
|
)
|
|
2682
2731
|
}
|
|
2683
2732
|
|
|
@@ -4,12 +4,14 @@ import { createRoot } from 'react-dom/client'
|
|
|
4
4
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
6
|
import { ClusterConnectedContext } from '../context/clusterConnected'
|
|
7
|
-
import { useAudit } from './client'
|
|
7
|
+
import { projectAuditBadges, useAudit, useAuditBadges } from './client'
|
|
8
8
|
|
|
9
9
|
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
10
10
|
|
|
11
|
+
let useProbe: () => void = () => useAudit([])
|
|
12
|
+
|
|
11
13
|
function AuditProbe() {
|
|
12
|
-
|
|
14
|
+
useProbe()
|
|
13
15
|
return null
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -32,17 +34,115 @@ async function renderWith(connected: boolean) {
|
|
|
32
34
|
)
|
|
33
35
|
})
|
|
34
36
|
await act(async () => { await Promise.resolve() })
|
|
35
|
-
const auditCalls = fetchMock.mock.calls.
|
|
37
|
+
const auditCalls = fetchMock.mock.calls.map(([input]) => String(input)).filter((url) => url.includes('/audit'))
|
|
36
38
|
act(() => root.unmount())
|
|
37
39
|
return auditCalls
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
describe('useAudit', () => {
|
|
41
43
|
it('does not ask a disconnected cluster for checks', async () => {
|
|
42
|
-
|
|
44
|
+
useProbe = () => useAudit([])
|
|
45
|
+
expect(await renderWith(false)).toHaveLength(0)
|
|
43
46
|
})
|
|
44
47
|
|
|
45
48
|
it('fetches checks while connected', async () => {
|
|
46
|
-
|
|
49
|
+
useProbe = () => useAudit([])
|
|
50
|
+
expect(await renderWith(true)).toHaveLength(1)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('useAuditBadges', () => {
|
|
55
|
+
it('asks only for badge findings, in the picked namespaces', async () => {
|
|
56
|
+
useProbe = () => useAuditBadges(['shop', 'web'])
|
|
57
|
+
const [url, ...rest] = await renderWith(true)
|
|
58
|
+
expect(rest).toHaveLength(0)
|
|
59
|
+
const params = new URL(url, 'http://radar').searchParams
|
|
60
|
+
expect(params.get('include')).toBe('badges')
|
|
61
|
+
expect(params.get('namespaces')).toBe('shop,web')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('does not ask a disconnected cluster', async () => {
|
|
65
|
+
useProbe = () => useAuditBadges([])
|
|
66
|
+
expect(await renderWith(false)).toHaveLength(0)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('stays idle while disabled', async () => {
|
|
70
|
+
useProbe = () => useAuditBadges([], { enabled: false })
|
|
71
|
+
expect(await renderWith(true)).toHaveLength(0)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('projectAuditBadges', () => {
|
|
76
|
+
const check = (id: string, badgeWorthy: boolean) => ({ id, title: id, description: '', remediation: '', category: 'Reliability', severity: 'warning', badgeWorthy }) as never
|
|
77
|
+
const finding = (checkID: string, name: string) => ({ kind: 'Service', group: '', namespace: 'shop', name, checkID, category: 'Reliability', severity: 'warning', message: name }) as never
|
|
78
|
+
|
|
79
|
+
it('cuts an older server\'s full response down to badge-worthy findings and their checks', () => {
|
|
80
|
+
const full = {
|
|
81
|
+
findings: [finding('noEndpoints', 'a'), finding('runAsRoot', 'b'), finding('noEndpoints', 'c')],
|
|
82
|
+
checks: { noEndpoints: check('noEndpoints', true), runAsRoot: check('runAsRoot', false), unused: check('unused', true) },
|
|
83
|
+
groups: [{ findings: [] }],
|
|
84
|
+
groupedChecks: [],
|
|
85
|
+
}
|
|
86
|
+
const out = projectAuditBadges(full)
|
|
87
|
+
expect(Object.keys(out).sort()).toEqual(['checks', 'findings'])
|
|
88
|
+
expect(out.findings.map((f) => f.name)).toEqual(['a', 'c'])
|
|
89
|
+
expect(Object.keys(out.checks)).toEqual(['noEndpoints'])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('tolerates an empty audit', () => {
|
|
93
|
+
expect(projectAuditBadges({ findings: null as never, checks: {} })).toEqual({ findings: [], checks: {} })
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('useAudit', () => {
|
|
98
|
+
it('marks the badges query stale with every full scan, so Checks and badges agree', async () => {
|
|
99
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ findings: [], checks: {}, groups: [] }), { status: 200, headers: { 'Content-Type': 'application/json' } })))
|
|
100
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
101
|
+
client.setQueryData(['audit', ['shop'], 'badges'], { findings: [], checks: {} })
|
|
102
|
+
expect(client.getQueryState(['audit', ['shop'], 'badges'])?.isInvalidated).toBe(false)
|
|
103
|
+
function FullAudit() {
|
|
104
|
+
useAudit(['shop'])
|
|
105
|
+
return null
|
|
106
|
+
}
|
|
107
|
+
const root = createRoot(document.createElement('div'))
|
|
108
|
+
await act(async () => {
|
|
109
|
+
root.render(
|
|
110
|
+
<QueryClientProvider client={client}>
|
|
111
|
+
<ClusterConnectedContext.Provider value={true}>
|
|
112
|
+
<FullAudit />
|
|
113
|
+
</ClusterConnectedContext.Provider>
|
|
114
|
+
</QueryClientProvider>,
|
|
115
|
+
)
|
|
116
|
+
})
|
|
117
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 0)) })
|
|
118
|
+
act(() => root.unmount())
|
|
119
|
+
expect(client.getQueryState(['audit', ['shop'], 'badges'])?.isInvalidated).toBe(true)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('still marks badges stale when the page is left before the full scan arrives', async () => {
|
|
123
|
+
let respond: (r: Response) => void = () => {}
|
|
124
|
+
vi.stubGlobal('fetch', vi.fn(() => new Promise<Response>((resolve) => { respond = resolve })))
|
|
125
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
126
|
+
client.setQueryData(['audit', ['shop'], 'badges'], { findings: [], checks: {} })
|
|
127
|
+
function FullAudit() {
|
|
128
|
+
useAudit(['shop'])
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
const root = createRoot(document.createElement('div'))
|
|
132
|
+
await act(async () => {
|
|
133
|
+
root.render(
|
|
134
|
+
<QueryClientProvider client={client}>
|
|
135
|
+
<ClusterConnectedContext.Provider value={true}>
|
|
136
|
+
<FullAudit />
|
|
137
|
+
</ClusterConnectedContext.Provider>
|
|
138
|
+
</QueryClientProvider>,
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
act(() => root.unmount())
|
|
142
|
+
await act(async () => {
|
|
143
|
+
respond(new Response(JSON.stringify({ findings: [], checks: {}, groups: [] }), { status: 200, headers: { 'Content-Type': 'application/json' } }))
|
|
144
|
+
await new Promise((r) => setTimeout(r, 0))
|
|
145
|
+
})
|
|
146
|
+
expect(client.getQueryState(['audit', ['shop'], 'badges'])?.isInvalidated).toBe(true)
|
|
47
147
|
})
|
|
48
148
|
})
|
|
@@ -0,0 +1,118 @@
|
|
|
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, expect, it, vi } from 'vitest'
|
|
6
|
+
import { ClusterConnectedContext } from '../context/clusterConnected'
|
|
7
|
+
import { useAudit, useAuditBadges } from './client'
|
|
8
|
+
import { setApiBase } from './config'
|
|
9
|
+
|
|
10
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
11
|
+
const badgeKey = ['audit', ['shop'], 'badges']
|
|
12
|
+
const fullKey = ['audit', ['shop']]
|
|
13
|
+
let roots: Root[] = []
|
|
14
|
+
let clients: QueryClient[] = []
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
act(() => { for (const root of roots) root.unmount() })
|
|
17
|
+
for (const client of clients) client.clear()
|
|
18
|
+
roots = []
|
|
19
|
+
clients = []
|
|
20
|
+
setApiBase('/api')
|
|
21
|
+
vi.unstubAllGlobals()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Holds each response until the test releases it, so the badge and full
|
|
25
|
+
// queries can finish in any order.
|
|
26
|
+
function setup() {
|
|
27
|
+
const requests: { url: string; respond: (scan: string) => void; signal?: AbortSignal | null }[] = []
|
|
28
|
+
vi.stubGlobal('fetch', vi.fn((input: RequestInfo | URL, init?: RequestInit) => new Promise<Response>((resolve) => {
|
|
29
|
+
requests.push({ url: String(input), signal: init?.signal, respond(scan) {
|
|
30
|
+
resolve(new Response(JSON.stringify({ findings: [{ checkID: 'test', name: scan }], checks: { test: { badgeWorthy: true } }, groups: [], scan }), { status: 200, headers: { 'Content-Type': 'application/json' } }))
|
|
31
|
+
} })
|
|
32
|
+
})))
|
|
33
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: Infinity } } })
|
|
34
|
+
clients.push(client)
|
|
35
|
+
const root = createRoot(document.createElement('div'))
|
|
36
|
+
roots.push(root)
|
|
37
|
+
function Full() { useAudit(['shop']); return null }
|
|
38
|
+
function Badges({ enabled }: { enabled: boolean }) { useAuditBadges(['shop'], { enabled }); return null }
|
|
39
|
+
async function render(full = true, enabled = true, key = 'A') {
|
|
40
|
+
await act(async () => {
|
|
41
|
+
root.render(<QueryClientProvider client={client}><ClusterConnectedContext.Provider value={true}>
|
|
42
|
+
<Badges key={`badges-${key}`} enabled={enabled} />
|
|
43
|
+
{full && <Full key={`full-${key}`} />}
|
|
44
|
+
</ClusterConnectedContext.Provider></QueryClientProvider>)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
async function respond(index: number, scan: string) {
|
|
48
|
+
await act(async () => { requests[index].respond(scan); await new Promise(r => setTimeout(r, 0)) })
|
|
49
|
+
}
|
|
50
|
+
return { requests, client, root, render, respond }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// The badges and the full audit are separate queries over the same scan. A
|
|
55
|
+
// newer full scan must leave the badges on a scan at least as new, never an
|
|
56
|
+
// older one, and never one from before a context switch.
|
|
57
|
+
it('restarts the first active badges request, rejects its late result, and does not loop on rerender', async () => {
|
|
58
|
+
const h = setup()
|
|
59
|
+
await h.render()
|
|
60
|
+
expect(h.requests.map(r => r.url)).toEqual(['/api/audit?include=badges&namespaces=shop', '/api/audit?namespaces=shop'])
|
|
61
|
+
await h.respond(1, 'new-full')
|
|
62
|
+
expect(h.requests).toHaveLength(3)
|
|
63
|
+
expect(h.requests[0].signal?.aborted).toBe(true)
|
|
64
|
+
expect(h.requests[2].signal?.aborted).toBe(false)
|
|
65
|
+
expect(h.client.getQueryState(badgeKey)).toMatchObject({ data: undefined, status: 'pending', fetchStatus: 'fetching' })
|
|
66
|
+
await h.respond(0, 'old-badges')
|
|
67
|
+
expect(h.client.getQueryData(badgeKey)).toBeUndefined()
|
|
68
|
+
await h.respond(2, 'new-badges')
|
|
69
|
+
expect(h.client.getQueryData(badgeKey)).toMatchObject({ findings: [{ name: 'new-badges' }] })
|
|
70
|
+
expect(h.client.getQueryData(fullKey)).toMatchObject({ scan: 'new-full' })
|
|
71
|
+
for (let i = 0; i < 5; i++) await h.render()
|
|
72
|
+
expect(h.requests).toHaveLength(3)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('refreshes active badges after leaving Checks mid-fetch', async () => {
|
|
76
|
+
const h = setup()
|
|
77
|
+
await h.render()
|
|
78
|
+
await h.render(false)
|
|
79
|
+
await h.respond(1, 'full-after-leaving')
|
|
80
|
+
expect(h.requests).toHaveLength(3)
|
|
81
|
+
await h.respond(2, 'new-badges')
|
|
82
|
+
await h.respond(0, 'old-badges')
|
|
83
|
+
expect(h.client.getQueryData(badgeKey)).toMatchObject({ findings: [{ name: 'new-badges' }] })
|
|
84
|
+
expect(h.client.getQueryData(fullKey)).toMatchObject({ scan: 'full-after-leaving' })
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('does not recreate removed queries when an old full response arrives', async () => {
|
|
88
|
+
const h = setup()
|
|
89
|
+
await h.render()
|
|
90
|
+
act(() => h.root.render(null))
|
|
91
|
+
h.client.removeQueries()
|
|
92
|
+
await h.respond(1, 'old-cluster-full')
|
|
93
|
+
await h.respond(0, 'old-cluster-badges')
|
|
94
|
+
expect(h.client.getQueryCache().getAll()).toHaveLength(0)
|
|
95
|
+
expect(h.requests).toHaveLength(2)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('an old full response can restart current-cluster badges but cannot write old-cluster data', async () => {
|
|
99
|
+
const h = setup()
|
|
100
|
+
setApiBase('/c/A/api')
|
|
101
|
+
await h.render()
|
|
102
|
+
act(() => h.root.render(null))
|
|
103
|
+
h.client.removeQueries()
|
|
104
|
+
setApiBase('/c/B/api')
|
|
105
|
+
await h.render(false, true, 'B')
|
|
106
|
+
expect(h.requests).toHaveLength(3)
|
|
107
|
+
expect(h.requests[2].url).toBe('/c/B/api/audit?include=badges&namespaces=shop')
|
|
108
|
+
await h.respond(1, 'A-full')
|
|
109
|
+
expect(h.requests).toHaveLength(4)
|
|
110
|
+
expect(h.requests[3].url).toBe('/c/B/api/audit?include=badges&namespaces=shop')
|
|
111
|
+
await h.respond(0, 'A-badges')
|
|
112
|
+
await h.respond(2, 'B-cancelled-badges')
|
|
113
|
+
expect(h.client.getQueryData(fullKey)).toBeUndefined()
|
|
114
|
+
expect(h.client.getQueryData(badgeKey)).toBeUndefined()
|
|
115
|
+
await h.respond(3, 'B-fresh-badges')
|
|
116
|
+
expect(h.client.getQueryData(badgeKey)).toMatchObject({ findings: [{ name: 'B-fresh-badges' }] })
|
|
117
|
+
expect(h.requests).toHaveLength(4)
|
|
118
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ApiError, backoffRefetchInterval, capabilitiesRefetchInterval, namespacesRefetchInterval } from "./client";
|
|
3
|
+
|
|
4
|
+
describe("backoffRefetchInterval", () => {
|
|
5
|
+
it("doubles from 5s to a 60s cap across consecutive failed answers, and resets on a good one", () => {
|
|
6
|
+
const query = {};
|
|
7
|
+
const seq = (answers: Array<[number, boolean]>) => answers.map(([at, failing]) => backoffRefetchInterval(query, at, failing, false));
|
|
8
|
+
expect(seq([[1, true], [2, true], [3, true], [4, true], [5, true], [6, true]])).toEqual([5000, 10_000, 20_000, 40_000, 60_000, 60_000]);
|
|
9
|
+
expect(seq([[7, false], [8, true]])).toEqual([false, 5000]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("counts an answer once, however often React Query asks for the interval", () => {
|
|
13
|
+
const query = {};
|
|
14
|
+
expect([1, 1, 1].map((at) => backoffRefetchInterval(query, at, true, false))).toEqual([5000, 5000, 5000]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("keeps a separate count per query", () => {
|
|
18
|
+
const a = {};
|
|
19
|
+
const b = {};
|
|
20
|
+
backoffRefetchInterval(a, 1, true, false);
|
|
21
|
+
backoffRefetchInterval(a, 2, true, false);
|
|
22
|
+
expect(backoffRefetchInterval(b, 1, true, false)).toBe(5000);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const caps = (dataUpdatedAt: number, checksIncomplete?: boolean) => ({ state: { dataUpdatedAt, data: { checksIncomplete } } });
|
|
27
|
+
|
|
28
|
+
describe("capabilitiesRefetchInterval", () => {
|
|
29
|
+
it("backs off while access checks keep erroring, so a struggling authorizer isn't asked 12x as often", () => {
|
|
30
|
+
const query = caps(1, true);
|
|
31
|
+
expect(capabilitiesRefetchInterval(query, 60_000)).toBe(5000);
|
|
32
|
+
query.state.dataUpdatedAt = 2;
|
|
33
|
+
expect(capabilitiesRefetchInterval(query, 60_000)).toBe(10_000);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("keeps the settled cadence once every check answered, and for older Radars that never send the flag", () => {
|
|
37
|
+
expect(capabilitiesRefetchInterval(caps(1, false), 60_000)).toBe(60_000);
|
|
38
|
+
expect(capabilitiesRefetchInterval(caps(1), false)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const ns = (status: string, error: unknown, errorUpdatedAt: number, dataUpdatedAt = 0) => ({ state: { status, error, errorUpdatedAt, dataUpdatedAt } });
|
|
43
|
+
|
|
44
|
+
describe("namespacesRefetchInterval", () => {
|
|
45
|
+
it("asks again with back-off while Radar couldn't read the list", () => {
|
|
46
|
+
const query = ns("error", new ApiError("Radar couldn't list namespaces", 500), 1);
|
|
47
|
+
expect(namespacesRefetchInterval(query)).toBe(5000);
|
|
48
|
+
query.state.errorUpdatedAt = 2;
|
|
49
|
+
query.state.error = new ApiError("permission check failed", 503);
|
|
50
|
+
expect(namespacesRefetchInterval(query)).toBe(10_000);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("doesn't poll a denial or a list it has", () => {
|
|
54
|
+
expect(namespacesRefetchInterval(ns("error", new ApiError("insufficient permissions", 403), 1))).toBe(false);
|
|
55
|
+
expect(namespacesRefetchInterval(ns("success", null, 0, 1))).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("doesn't poll the 503 Radar answers while the cluster is disconnected", () => {
|
|
59
|
+
expect(namespacesRefetchInterval(ns("error", new ApiError("Not connected to cluster", 503), 1), false)).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|