@skyhook-io/radar-app 1.20.3 → 1.21.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/package.json +10 -9
- package/src/App.tsx +67 -15
- 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.ts +129 -5
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/radarFeatures.ts +11 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +377 -0
- package/src/api/vulnerabilities.ts +313 -0
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +35 -5
- package/src/components/audit/ChecksViewTabs.tsx +12 -1
- package/src/components/audit/Java4ShellPanel.test.tsx +31 -0
- package/src/components/audit/Java4ShellPanel.tsx +313 -0
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +944 -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/diagnose/diagnoseEvidenceTypes.ts +2 -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/gitops/FluxOperatorCard.test.tsx +37 -0
- package/src/components/gitops/FluxOperatorCard.tsx +27 -0
- package/src/components/gitops/GitOpsView.rowsSummary.test.tsx +59 -0
- package/src/components/gitops/GitOpsView.tsx +8 -5
- package/src/components/gitops/gitopsRowEvents.test.ts +48 -0
- package/src/components/gitops/gitopsRowEvents.ts +31 -0
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmView.tsx +20 -16
- package/src/components/helm/OwnedResources.tsx +4 -3
- package/src/components/home/ClusterHealthCard.tsx +3 -1
- 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 +15 -2
- 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/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/ResourcesView.tsx +12 -6
- 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 +3 -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 +46 -129
- package/src/components/traffic/trafficFilters.test.ts +172 -1
- package/src/components/traffic/trafficFilters.ts +139 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +31 -2
- package/src/components/ui/UpdateNotification.tsx +34 -17
- package/src/components/ui/command-items.ts +24 -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 +158 -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/VeleroRunArtifacts.test.tsx +241 -0
- package/src/components/velero/VeleroRunArtifacts.tsx +112 -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/VeleroRunVolumes.test.tsx +247 -0
- package/src/components/velero/VeleroRunVolumes.tsx +122 -0
- package/src/components/velero/VeleroSchedulePause.test.tsx +211 -0
- package/src/components/velero/VeleroSchedulePause.tsx +191 -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 +92 -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 +179 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/whats-new/WhatsNewDialog.test.tsx +6 -4
- package/src/components/whats-new/releaseNotes.ts +67 -1
- package/src/components/workload/WorkloadView.tsx +64 -27
- 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/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 +14 -2
- package/src/integrations/resourceHosts.tsx +22 -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/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.1",
|
|
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
|
@@ -26,6 +26,7 @@ import { CostView } from './components/cost/CostView'
|
|
|
26
26
|
import { AuditView } from './components/audit/AuditView'
|
|
27
27
|
import { IssuesPane } from './components/issues/IssuesPane'
|
|
28
28
|
import { GitOpsView } from './components/gitops/GitOpsView'
|
|
29
|
+
import { gitopsTableChange } from './components/gitops/gitopsRowEvents'
|
|
29
30
|
import { ApplicationsView } from './components/applications/ApplicationsView'
|
|
30
31
|
import { HelmReleaseDrawer } from './components/helm/HelmReleaseDrawer'
|
|
31
32
|
import { PortForwardProvider, PortForwardIndicator, PortForwardPanel } from './components/portforward/PortForwardManager'
|
|
@@ -38,7 +39,7 @@ import { CloudFunnelButton } from './components/CloudFunnelButton'
|
|
|
38
39
|
import { useNavCustomization } from './context/NavCustomization'
|
|
39
40
|
import type { FleetTakeoverTarget } from './context/NavCustomization'
|
|
40
41
|
import { PrimaryNavRail } from './components/nav/PrimaryNavRail'
|
|
41
|
-
import { resourceExpandedPath, resourceKindListTitle } from './integrations/resourceHosts'
|
|
42
|
+
import { resourceExpandedPath, resourceKindListNamespaceFilterTooltip, resourceKindListTitle, useResourceHostFeatures } from './integrations/resourceHosts'
|
|
42
43
|
import { workspaceContextSwitchSearch, workspaceForPath, workspaceForView, workspaceLabels } from './integrations/workspaceRoutes'
|
|
43
44
|
import { WorkspaceScreen } from './integrations/workspaceScreens'
|
|
44
45
|
import { currentPageLabel } from './utils/page-links'
|
|
@@ -53,9 +54,11 @@ import { NoClusterAccessBanner } from './components/NoClusterAccessBanner'
|
|
|
53
54
|
import { CapabilitiesProvider, useCapabilitiesContext } from './contexts/CapabilitiesContext'
|
|
54
55
|
import { RadarUpgradeProvider } from './context/RadarUpgrade'
|
|
55
56
|
import { UserMenu } from './components/UserMenu'
|
|
57
|
+
import { COMMUNITY_SLACK_URL } from './components/community'
|
|
56
58
|
import { ErrorBoundary } from './components/ui/ErrorBoundary'
|
|
57
59
|
import { UpdateNotification } from './components/ui/UpdateNotification'
|
|
58
60
|
import { openWhatsNew, useWhatsNewStatus, WhatsNew } from './components/whats-new/WhatsNew'
|
|
61
|
+
import { AboutDialog, type AboutInfo } from './desktop/AboutDialog'
|
|
59
62
|
import { useUsageData, useUsageRecording } from './api/usage-data'
|
|
60
63
|
import { UsageDataPrompt } from './components/usage-data/UsageDataPrompt'
|
|
61
64
|
import { ProductHuntNotice } from './components/product-hunt/ProductHuntNotice'
|
|
@@ -63,7 +66,7 @@ import { useProductHuntRailEntry } from './components/product-hunt/useProductHun
|
|
|
63
66
|
import { ShortcutHelpOverlay } from './components/ui/ShortcutHelpOverlay'
|
|
64
67
|
import { DiagnosticsOverlay, type DiagnosticsFocus } from './components/ui/DiagnosticsOverlay'
|
|
65
68
|
import { useEventSource } from './hooks/useEventSource'
|
|
66
|
-
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useSwitchContext, useAuthMe,
|
|
69
|
+
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useSwitchContext, useAuthMe, useAuditBadges, useClusterInfo, useCapabilities } from './api/client'
|
|
67
70
|
import { buildAuditSeverityMap } from './utils/auditBadges'
|
|
68
71
|
import { isInNamespaceScope, scopeNodesToNamespaces } from './utils/topology-namespace'
|
|
69
72
|
import { routePath, apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, stripBasename } from './api/config'
|
|
@@ -133,7 +136,7 @@ const FLEET_MODE_KINDS = new Set<NodeKind>([
|
|
|
133
136
|
|
|
134
137
|
// Convert API resource name back to topology node ID prefix
|
|
135
138
|
// Extended MainView type that includes traffic and cost
|
|
136
|
-
type ExtendedMainView = MainView | 'traffic' | 'cost' | 'capacity' | 'cnpg' | 'workload' | 'checks' | 'gitops' | 'compare' | 'helmCompare' | 'issues' | 'applications' | 'investigations'
|
|
139
|
+
type ExtendedMainView = MainView | 'traffic' | 'cost' | 'capacity' | 'cnpg' | 'velero' | 'workload' | 'checks' | 'gitops' | 'compare' | 'helmCompare' | 'issues' | 'applications' | 'investigations'
|
|
137
140
|
|
|
138
141
|
// Views that have been laid out for phone width (640px and below). The rest
|
|
139
142
|
// keep their desktop width on a phone and scroll sideways; add a view here in
|
|
@@ -197,6 +200,8 @@ const CRASH_LABELS = {
|
|
|
197
200
|
// browsing filter.
|
|
198
201
|
// - A cluster-scoped resource kind (Nodes, PVs, ClusterRoles…) has no
|
|
199
202
|
// namespace at all.
|
|
203
|
+
// - A kind whose own list ignores the filter (Velero's lists read every
|
|
204
|
+
// installation, since Velero keeps its objects in its own namespace).
|
|
200
205
|
// The pick itself is preserved so it re-applies when the user returns to a
|
|
201
206
|
// namespaced view.
|
|
202
207
|
function namespaceFilterDisabled(
|
|
@@ -204,6 +209,7 @@ function namespaceFilterDisabled(
|
|
|
204
209
|
pathname: string,
|
|
205
210
|
search = '',
|
|
206
211
|
apiResources?: APIResource[],
|
|
212
|
+
kindListTooltip?: (kind: { name: string; group: string }) => string | undefined,
|
|
207
213
|
): { disabled: boolean; tooltip?: string } {
|
|
208
214
|
if (
|
|
209
215
|
view === 'cost' &&
|
|
@@ -233,6 +239,8 @@ function namespaceFilterDisabled(
|
|
|
233
239
|
const kindSlug = segments[1]
|
|
234
240
|
const group = new URLSearchParams(search).get('apiGroup') || ''
|
|
235
241
|
const match = kindSlug ? findAPIResourceForRoute(apiResources, kindSlug, group) : undefined
|
|
242
|
+
const listTooltip = match ? kindListTooltip?.({ name: match.name, group: match.group }) : undefined
|
|
243
|
+
if (listTooltip) return { disabled: true, tooltip: listTooltip }
|
|
236
244
|
if (match && !match.namespaced) {
|
|
237
245
|
return {
|
|
238
246
|
disabled: true,
|
|
@@ -288,6 +296,7 @@ function radarPageTitle(pathname: string, search = '', apiResources?: APIResourc
|
|
|
288
296
|
}
|
|
289
297
|
|
|
290
298
|
if (view === 'checks' && pathSegments[1] === 'upgrade') return 'Upgrade impact'
|
|
299
|
+
if (view === 'checks' && pathSegments[1] === 'vulnerabilities') return 'Vulnerabilities'
|
|
291
300
|
|
|
292
301
|
// The landing view reads "Overview" rather than "Home" in the tab.
|
|
293
302
|
const workspace = workspaceForView(view)
|
|
@@ -439,6 +448,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
439
448
|
const mainView = getViewFromPath(location.pathname)
|
|
440
449
|
const activeWorkspace = workspaceForView(mainView)
|
|
441
450
|
const upgradeReadinessRoute = location.pathname.startsWith('/checks/upgrade')
|
|
451
|
+
// Checks sub-routes a Cloud host's fleet Checks pages don't have, so they
|
|
452
|
+
// render here even when the host takes over /checks.
|
|
453
|
+
const localChecksRoute = upgradeReadinessRoute || location.pathname.startsWith('/checks/vulnerabilities')
|
|
442
454
|
|
|
443
455
|
// Opt-in usage data. Embedded hosts own their own consent, so Radar never asks there.
|
|
444
456
|
const usageData = useUsageData(!navCustomization.embedded)
|
|
@@ -450,7 +462,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
450
462
|
|
|
451
463
|
// View-aware namespace scope: disabled on cluster-scoped surfaces so the
|
|
452
464
|
// chip isn't a dead control next to the cluster switcher.
|
|
453
|
-
|
|
465
|
+
// A kind whose own list ignores the filter (Velero's) disables it too, once that list is what shows.
|
|
466
|
+
const hostFeatures = useResourceHostFeatures()
|
|
467
|
+
const { isPending: capabilitiesPending } = useCapabilities()
|
|
468
|
+
const namespaceFilter = namespaceFilterDisabled(mainView, location.pathname, location.search, navApiResources,
|
|
469
|
+
(kind) => resourceKindListNamespaceFilterTooltip(kind, hostFeatures, capabilitiesPending))
|
|
454
470
|
|
|
455
471
|
// One URL-derived tab title for every view (see radarPageTitle). Driving it
|
|
456
472
|
// from the URL — not the mounted component. Off unless the host opts in
|
|
@@ -587,7 +603,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
587
603
|
// The host's URL for the CURRENT view, if taken over. Drives the redirect
|
|
588
604
|
// effect and the "Opening…" splash.
|
|
589
605
|
const viewTakeoverHref =
|
|
590
|
-
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !
|
|
606
|
+
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !localChecksRoute
|
|
591
607
|
? takeover[mainView]
|
|
592
608
|
: undefined
|
|
593
609
|
useEffect(() => {
|
|
@@ -649,6 +665,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
649
665
|
return () => window.removeEventListener('radar:open-settings', handler)
|
|
650
666
|
}, [openSettings])
|
|
651
667
|
|
|
668
|
+
// Help → About Radar in the Windows desktop app (cmd/desktop/menu.go).
|
|
669
|
+
const [aboutInfo, setAboutInfo] = useState<AboutInfo | null>(null)
|
|
670
|
+
useEffect(() => {
|
|
671
|
+
const handler = (e: Event) => setAboutInfo((e as CustomEvent<AboutInfo>).detail)
|
|
672
|
+
window.addEventListener('radar:open-about', handler)
|
|
673
|
+
return () => window.removeEventListener('radar:open-about', handler)
|
|
674
|
+
}, [])
|
|
675
|
+
|
|
652
676
|
// Listen for "open-local-terminal" DOM event — the AI surface is portaled above
|
|
653
677
|
// the DockProvider, so it can't call useOpenLocalTerminal directly; it dispatches
|
|
654
678
|
// this instead (mirrors the open-settings pattern).
|
|
@@ -916,7 +940,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
916
940
|
gitops: 'g o', checks: 'g u', cost: 'g c', capacity: 'g p',
|
|
917
941
|
// Non-rail views (reachable via deep links / actions, not the rail) get no
|
|
918
942
|
// dedicated mnemonic — listed for exhaustiveness so the type stays total.
|
|
919
|
-
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '',
|
|
943
|
+
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '', velero: '',
|
|
920
944
|
}
|
|
921
945
|
const views = Object.keys(VIEW_SHORTCUT_KEYS).filter(
|
|
922
946
|
(v): v is ExtendedMainView => VIEW_SHORTCUT_KEYS[v as ExtendedMainView] !== '',
|
|
@@ -1035,7 +1059,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1035
1059
|
const hideGroupHeader = namespaces.length === 1 && effectiveGroupingMode === 'namespace'
|
|
1036
1060
|
|
|
1037
1061
|
// Fetch available namespaces
|
|
1038
|
-
const { data: availableNamespaces } = useNamespaces()
|
|
1062
|
+
const { data: availableNamespaces, error: availableNamespacesError } = useNamespaces()
|
|
1039
1063
|
|
|
1040
1064
|
// This tab's namespace pick plus the picker's source list (see
|
|
1041
1065
|
// utils/namespacePick). Loaded eagerly so the picker can render its current
|
|
@@ -1126,10 +1150,13 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1126
1150
|
timer: number | null
|
|
1127
1151
|
}>({ changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null })
|
|
1128
1152
|
const cnpgInvalidationPendingRef = useRef(false)
|
|
1153
|
+
const veleroInvalidationPendingRef = useRef(false)
|
|
1129
1154
|
const slowInvalidationRef = useRef<{
|
|
1130
1155
|
updatedKinds: Set<string> // update-only churn → throttled list + dashboard
|
|
1156
|
+
gitopsRowsChanged: boolean // Argo/Flux row and source kinds → GitOps table rows
|
|
1157
|
+
gitopsCountsChanged: boolean // add/delete in a GitOps group → GitOps table totals
|
|
1131
1158
|
timer: number | null
|
|
1132
|
-
}>({ updatedKinds: new Set(), timer: null })
|
|
1159
|
+
}>({ updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null })
|
|
1133
1160
|
const timelineInvalidationRef = useRef<{ timer: number | null }>({ timer: null })
|
|
1134
1161
|
|
|
1135
1162
|
const handleK8sEvent = useCallback((event: K8sEvent) => {
|
|
@@ -1158,6 +1185,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1158
1185
|
const applicationWorkload = ['deployments', 'statefulsets', 'daemonsets', 'rollouts'].includes(kind)
|
|
1159
1186
|
|
|
1160
1187
|
if (event.group?.endsWith('.cnpg.io')) cnpgInvalidationPendingRef.current = true
|
|
1188
|
+
if (event.group === 'velero.io') veleroInvalidationPendingRef.current = true
|
|
1161
1189
|
|
|
1162
1190
|
const fast = fastInvalidationRef.current
|
|
1163
1191
|
fast.changedKinds.add(kind)
|
|
@@ -1173,6 +1201,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1173
1201
|
|
|
1174
1202
|
const slow = slowInvalidationRef.current
|
|
1175
1203
|
if (!structural || applicationWorkload) slow.updatedKinds.add(kind)
|
|
1204
|
+
const gitops = gitopsTableChange(event.kind, event.group, event.operation)
|
|
1205
|
+
if (gitops.rows) slow.gitopsRowsChanged = true
|
|
1206
|
+
if (gitops.counts) slow.gitopsCountsChanged = true
|
|
1176
1207
|
|
|
1177
1208
|
// FAST tier — membership-sensitive + cheap, bounded 3s latency.
|
|
1178
1209
|
if (fast.timer === null) {
|
|
@@ -1212,13 +1243,18 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1212
1243
|
cnpgInvalidationPendingRef.current = false
|
|
1213
1244
|
queryClient.invalidateQueries({ queryKey: ['cnpg', 'workspace'] })
|
|
1214
1245
|
}
|
|
1246
|
+
if (veleroInvalidationPendingRef.current) {
|
|
1247
|
+
veleroInvalidationPendingRef.current = false
|
|
1248
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'workspace'] })
|
|
1249
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'schedule-activity'] })
|
|
1250
|
+
}
|
|
1215
1251
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1216
1252
|
}, 3000)
|
|
1217
1253
|
}
|
|
1218
1254
|
|
|
1219
1255
|
// SLOW tier — throttle expensive status churn. Workload membership changes
|
|
1220
1256
|
// also pass through here so the Applications refetch lands after its cache TTL.
|
|
1221
|
-
if ((!structural || applicationWorkload) && slow.timer === null) {
|
|
1257
|
+
if ((!structural || applicationWorkload || gitops.rows || gitops.counts) && slow.timer === null) {
|
|
1222
1258
|
slow.timer = window.setTimeout(() => {
|
|
1223
1259
|
const s = slowInvalidationRef.current
|
|
1224
1260
|
for (const k of s.updatedKinds) {
|
|
@@ -1227,8 +1263,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1227
1263
|
if ([...s.updatedKinds].some((k) => ['deployments', 'statefulsets', 'daemonsets', 'rollouts'].includes(k))) {
|
|
1228
1264
|
queryClient.invalidateQueries({ queryKey: ['applications'] })
|
|
1229
1265
|
}
|
|
1266
|
+
if (s.gitopsRowsChanged) queryClient.invalidateQueries({ queryKey: ['gitops-rows-main'] })
|
|
1267
|
+
if (s.gitopsCountsChanged) queryClient.invalidateQueries({ queryKey: ['gitops-resource-counts'] })
|
|
1230
1268
|
queryClient.invalidateQueries({ queryKey: ['dashboard'] }) // health reflects status updates
|
|
1231
|
-
slowInvalidationRef.current = { updatedKinds: new Set(), timer: null }
|
|
1269
|
+
slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
|
|
1232
1270
|
}, 15000)
|
|
1233
1271
|
}
|
|
1234
1272
|
}, [queryClient])
|
|
@@ -1242,7 +1280,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1242
1280
|
if (slowInvalidationRef.current.timer !== null) clearTimeout(slowInvalidationRef.current.timer)
|
|
1243
1281
|
if (timelineInvalidationRef.current.timer !== null) clearTimeout(timelineInvalidationRef.current.timer)
|
|
1244
1282
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1245
|
-
slowInvalidationRef.current = { updatedKinds: new Set(), timer: null }
|
|
1283
|
+
slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
|
|
1246
1284
|
timelineInvalidationRef.current = { timer: null }
|
|
1247
1285
|
}, [])
|
|
1248
1286
|
|
|
@@ -1264,7 +1302,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1264
1302
|
if (slowInvalidationRef.current.timer !== null) clearTimeout(slowInvalidationRef.current.timer)
|
|
1265
1303
|
if (timelineInvalidationRef.current.timer !== null) clearTimeout(timelineInvalidationRef.current.timer)
|
|
1266
1304
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1267
|
-
slowInvalidationRef.current = { updatedKinds: new Set(), timer: null }
|
|
1305
|
+
slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
|
|
1268
1306
|
timelineInvalidationRef.current = { timer: null }
|
|
1269
1307
|
|
|
1270
1308
|
// Close any open drawers/overlays — old cluster's resources don't exist on the new one
|
|
@@ -1776,7 +1814,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1776
1814
|
// backend stamps on each node (data.auditKey). Only badge-worthy findings
|
|
1777
1815
|
// reach the graph; the raw auditDanger/auditWarning property names remain at
|
|
1778
1816
|
// this compatibility boundary while the node presents them as High/Medium.
|
|
1779
|
-
|
|
1817
|
+
// Only badge-worthy findings, small next to the full scan (they grow with
|
|
1818
|
+
// broken references, not with the cluster), so they stay loaded app-wide: a
|
|
1819
|
+
// view that badges resources has them on arrival.
|
|
1820
|
+
const audit = useAuditBadges(namespaces)
|
|
1780
1821
|
const auditSeverityMap = useMemo(
|
|
1781
1822
|
() => buildAuditSeverityMap(audit.data?.findings, audit.data?.checks),
|
|
1782
1823
|
[audit.data?.findings, audit.data?.checks],
|
|
@@ -1859,6 +1900,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1859
1900
|
accountSlot={<UserMenu variant="rail" pinned={navRailEffectivePinned} />}
|
|
1860
1901
|
whatsNew={whatsNewStatus.available ? { unread: whatsNewStatus.unread, onOpen: openWhatsNew } : undefined}
|
|
1861
1902
|
productHunt={productHuntRailEntry}
|
|
1903
|
+
communityUrl={COMMUNITY_SLACK_URL}
|
|
1862
1904
|
/>
|
|
1863
1905
|
)}
|
|
1864
1906
|
{/* `relative` makes this column the containing block for the absolute
|
|
@@ -1963,6 +2005,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1963
2005
|
onToggleTheme={toggleTheme}
|
|
1964
2006
|
onShowDiagnostics={() => setShowDiagnostics(true)}
|
|
1965
2007
|
onShowWhatsNew={whatsNewStatus.available ? openWhatsNew : undefined}
|
|
2008
|
+
onOpenCommunity={() => openExternal(COMMUNITY_SLACK_URL)}
|
|
1966
2009
|
onOpenResource={(hit) => navigateToResourceList(searchHitToSelectedResource(hit))}
|
|
1967
2010
|
/>
|
|
1968
2011
|
</div>
|
|
@@ -2211,6 +2254,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2211
2254
|
<div className="relative">
|
|
2212
2255
|
<LargeClusterNamespacePicker
|
|
2213
2256
|
namespaces={availableNamespaces}
|
|
2257
|
+
error={availableNamespacesError?.message}
|
|
2214
2258
|
onSelect={(ns) => {
|
|
2215
2259
|
setNamespaces([ns])
|
|
2216
2260
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2342,6 +2386,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2342
2386
|
initialTimeRange={(searchParams.get('time') as '5m' | '30m' | '1h' | '6h' | '24h' | 'all') || undefined}
|
|
2343
2387
|
requiresNamespaceFilter={topology?.requiresNamespaceFilter && namespaces.length === 0}
|
|
2344
2388
|
availableNamespaces={availableNamespaces}
|
|
2389
|
+
availableNamespacesError={availableNamespacesError?.message}
|
|
2345
2390
|
onNamespaceSelect={(ns) => {
|
|
2346
2391
|
setNamespaces([ns])
|
|
2347
2392
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2436,7 +2481,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2436
2481
|
|
|
2437
2482
|
{/* Checks detail view. Cloud can take over fleet best practices while
|
|
2438
2483
|
the target-specific upgrade route continues to render locally. */}
|
|
2439
|
-
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') ||
|
|
2484
|
+
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') || localChecksRoute) && (
|
|
2440
2485
|
<AuditView
|
|
2441
2486
|
namespaces={namespaces}
|
|
2442
2487
|
onNavigateToResource={navigateToResourceList}
|
|
@@ -2624,7 +2669,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2624
2669
|
{helpOverlay.shouldRender && <ShortcutHelpOverlay isOpen={helpOverlay.isOpen} onClose={() => setShowHelp(false)} currentView={mainView} />}
|
|
2625
2670
|
|
|
2626
2671
|
{/* Diagnostics overlay */}
|
|
2627
|
-
{diagnosticsOverlay.shouldRender && <DiagnosticsOverlay isOpen={diagnosticsOverlay.isOpen} focus={diagnosticsFocus} onClose={() => { setShowDiagnostics(false); setDiagnosticsFocus(undefined) }} />}
|
|
2672
|
+
{diagnosticsOverlay.shouldRender && <DiagnosticsOverlay isOpen={diagnosticsOverlay.isOpen} focus={diagnosticsFocus} communityUrl={embedded ? undefined : COMMUNITY_SLACK_URL} onClose={() => { setShowDiagnostics(false); setDiagnosticsFocus(undefined) }} />}
|
|
2673
|
+
|
|
2674
|
+
<AboutDialog
|
|
2675
|
+
info={aboutInfo}
|
|
2676
|
+
onClose={() => setAboutInfo(null)}
|
|
2677
|
+
onShowWhatsNew={whatsNewStatus.available ? openWhatsNew : undefined}
|
|
2678
|
+
onReportIssue={() => { setDiagnosticsFocus(undefined); setShowDiagnostics(true) }}
|
|
2679
|
+
/>
|
|
2628
2680
|
|
|
2629
2681
|
{/* Settings dialog — My permissions is rendered inline in its own section */}
|
|
2630
2682
|
<SettingsDialog
|
|
@@ -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
|
+
})
|