@skyhook-io/radar-app 1.20.3 → 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 +54 -10
- 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 +7 -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/NamespaceSwitcher.tsx +3 -1
- 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/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/GitOpsView.tsx +1 -1
- 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 +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/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.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
|
@@ -38,7 +38,7 @@ import { CloudFunnelButton } from './components/CloudFunnelButton'
|
|
|
38
38
|
import { useNavCustomization } from './context/NavCustomization'
|
|
39
39
|
import type { FleetTakeoverTarget } from './context/NavCustomization'
|
|
40
40
|
import { PrimaryNavRail } from './components/nav/PrimaryNavRail'
|
|
41
|
-
import { resourceExpandedPath, resourceKindListTitle } from './integrations/resourceHosts'
|
|
41
|
+
import { resourceExpandedPath, resourceKindListNamespaceFilterTooltip, resourceKindListTitle, useResourceHostFeatures } from './integrations/resourceHosts'
|
|
42
42
|
import { workspaceContextSwitchSearch, workspaceForPath, workspaceForView, workspaceLabels } from './integrations/workspaceRoutes'
|
|
43
43
|
import { WorkspaceScreen } from './integrations/workspaceScreens'
|
|
44
44
|
import { currentPageLabel } from './utils/page-links'
|
|
@@ -53,9 +53,11 @@ import { NoClusterAccessBanner } from './components/NoClusterAccessBanner'
|
|
|
53
53
|
import { CapabilitiesProvider, useCapabilitiesContext } from './contexts/CapabilitiesContext'
|
|
54
54
|
import { RadarUpgradeProvider } from './context/RadarUpgrade'
|
|
55
55
|
import { UserMenu } from './components/UserMenu'
|
|
56
|
+
import { COMMUNITY_SLACK_URL } from './components/community'
|
|
56
57
|
import { ErrorBoundary } from './components/ui/ErrorBoundary'
|
|
57
58
|
import { UpdateNotification } from './components/ui/UpdateNotification'
|
|
58
59
|
import { openWhatsNew, useWhatsNewStatus, WhatsNew } from './components/whats-new/WhatsNew'
|
|
60
|
+
import { AboutDialog, type AboutInfo } from './desktop/AboutDialog'
|
|
59
61
|
import { useUsageData, useUsageRecording } from './api/usage-data'
|
|
60
62
|
import { UsageDataPrompt } from './components/usage-data/UsageDataPrompt'
|
|
61
63
|
import { ProductHuntNotice } from './components/product-hunt/ProductHuntNotice'
|
|
@@ -63,7 +65,7 @@ import { useProductHuntRailEntry } from './components/product-hunt/useProductHun
|
|
|
63
65
|
import { ShortcutHelpOverlay } from './components/ui/ShortcutHelpOverlay'
|
|
64
66
|
import { DiagnosticsOverlay, type DiagnosticsFocus } from './components/ui/DiagnosticsOverlay'
|
|
65
67
|
import { useEventSource } from './hooks/useEventSource'
|
|
66
|
-
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useSwitchContext, useAuthMe,
|
|
68
|
+
import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useSwitchContext, useAuthMe, useAuditBadges, useClusterInfo, useCapabilities } from './api/client'
|
|
67
69
|
import { buildAuditSeverityMap } from './utils/auditBadges'
|
|
68
70
|
import { isInNamespaceScope, scopeNodesToNamespaces } from './utils/topology-namespace'
|
|
69
71
|
import { routePath, apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, stripBasename } from './api/config'
|
|
@@ -133,7 +135,7 @@ const FLEET_MODE_KINDS = new Set<NodeKind>([
|
|
|
133
135
|
|
|
134
136
|
// Convert API resource name back to topology node ID prefix
|
|
135
137
|
// Extended MainView type that includes traffic and cost
|
|
136
|
-
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'
|
|
137
139
|
|
|
138
140
|
// Views that have been laid out for phone width (640px and below). The rest
|
|
139
141
|
// keep their desktop width on a phone and scroll sideways; add a view here in
|
|
@@ -197,6 +199,8 @@ const CRASH_LABELS = {
|
|
|
197
199
|
// browsing filter.
|
|
198
200
|
// - A cluster-scoped resource kind (Nodes, PVs, ClusterRoles…) has no
|
|
199
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).
|
|
200
204
|
// The pick itself is preserved so it re-applies when the user returns to a
|
|
201
205
|
// namespaced view.
|
|
202
206
|
function namespaceFilterDisabled(
|
|
@@ -204,6 +208,7 @@ function namespaceFilterDisabled(
|
|
|
204
208
|
pathname: string,
|
|
205
209
|
search = '',
|
|
206
210
|
apiResources?: APIResource[],
|
|
211
|
+
kindListTooltip?: (kind: { name: string; group: string }) => string | undefined,
|
|
207
212
|
): { disabled: boolean; tooltip?: string } {
|
|
208
213
|
if (
|
|
209
214
|
view === 'cost' &&
|
|
@@ -233,6 +238,8 @@ function namespaceFilterDisabled(
|
|
|
233
238
|
const kindSlug = segments[1]
|
|
234
239
|
const group = new URLSearchParams(search).get('apiGroup') || ''
|
|
235
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 }
|
|
236
243
|
if (match && !match.namespaced) {
|
|
237
244
|
return {
|
|
238
245
|
disabled: true,
|
|
@@ -288,6 +295,7 @@ function radarPageTitle(pathname: string, search = '', apiResources?: APIResourc
|
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
if (view === 'checks' && pathSegments[1] === 'upgrade') return 'Upgrade impact'
|
|
298
|
+
if (view === 'checks' && pathSegments[1] === 'vulnerabilities') return 'Vulnerabilities'
|
|
291
299
|
|
|
292
300
|
// The landing view reads "Overview" rather than "Home" in the tab.
|
|
293
301
|
const workspace = workspaceForView(view)
|
|
@@ -439,6 +447,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
439
447
|
const mainView = getViewFromPath(location.pathname)
|
|
440
448
|
const activeWorkspace = workspaceForView(mainView)
|
|
441
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')
|
|
442
453
|
|
|
443
454
|
// Opt-in usage data. Embedded hosts own their own consent, so Radar never asks there.
|
|
444
455
|
const usageData = useUsageData(!navCustomization.embedded)
|
|
@@ -450,7 +461,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
450
461
|
|
|
451
462
|
// View-aware namespace scope: disabled on cluster-scoped surfaces so the
|
|
452
463
|
// chip isn't a dead control next to the cluster switcher.
|
|
453
|
-
|
|
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))
|
|
454
469
|
|
|
455
470
|
// One URL-derived tab title for every view (see radarPageTitle). Driving it
|
|
456
471
|
// from the URL — not the mounted component. Off unless the host opts in
|
|
@@ -587,7 +602,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
587
602
|
// The host's URL for the CURRENT view, if taken over. Drives the redirect
|
|
588
603
|
// effect and the "Opening…" splash.
|
|
589
604
|
const viewTakeoverHref =
|
|
590
|
-
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !
|
|
605
|
+
(mainView === 'issues' || mainView === 'gitops' || mainView === 'checks') && !localChecksRoute
|
|
591
606
|
? takeover[mainView]
|
|
592
607
|
: undefined
|
|
593
608
|
useEffect(() => {
|
|
@@ -649,6 +664,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
649
664
|
return () => window.removeEventListener('radar:open-settings', handler)
|
|
650
665
|
}, [openSettings])
|
|
651
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
|
+
|
|
652
675
|
// Listen for "open-local-terminal" DOM event — the AI surface is portaled above
|
|
653
676
|
// the DockProvider, so it can't call useOpenLocalTerminal directly; it dispatches
|
|
654
677
|
// this instead (mirrors the open-settings pattern).
|
|
@@ -916,7 +939,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
916
939
|
gitops: 'g o', checks: 'g u', cost: 'g c', capacity: 'g p',
|
|
917
940
|
// Non-rail views (reachable via deep links / actions, not the rail) get no
|
|
918
941
|
// dedicated mnemonic — listed for exhaustiveness so the type stays total.
|
|
919
|
-
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '',
|
|
942
|
+
workload: '', compare: '', helmCompare: '', investigations: '', cnpg: '', velero: '',
|
|
920
943
|
}
|
|
921
944
|
const views = Object.keys(VIEW_SHORTCUT_KEYS).filter(
|
|
922
945
|
(v): v is ExtendedMainView => VIEW_SHORTCUT_KEYS[v as ExtendedMainView] !== '',
|
|
@@ -1035,7 +1058,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1035
1058
|
const hideGroupHeader = namespaces.length === 1 && effectiveGroupingMode === 'namespace'
|
|
1036
1059
|
|
|
1037
1060
|
// Fetch available namespaces
|
|
1038
|
-
const { data: availableNamespaces } = useNamespaces()
|
|
1061
|
+
const { data: availableNamespaces, error: availableNamespacesError } = useNamespaces()
|
|
1039
1062
|
|
|
1040
1063
|
// This tab's namespace pick plus the picker's source list (see
|
|
1041
1064
|
// utils/namespacePick). Loaded eagerly so the picker can render its current
|
|
@@ -1126,6 +1149,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1126
1149
|
timer: number | null
|
|
1127
1150
|
}>({ changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null })
|
|
1128
1151
|
const cnpgInvalidationPendingRef = useRef(false)
|
|
1152
|
+
const veleroInvalidationPendingRef = useRef(false)
|
|
1129
1153
|
const slowInvalidationRef = useRef<{
|
|
1130
1154
|
updatedKinds: Set<string> // update-only churn → throttled list + dashboard
|
|
1131
1155
|
timer: number | null
|
|
@@ -1158,6 +1182,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1158
1182
|
const applicationWorkload = ['deployments', 'statefulsets', 'daemonsets', 'rollouts'].includes(kind)
|
|
1159
1183
|
|
|
1160
1184
|
if (event.group?.endsWith('.cnpg.io')) cnpgInvalidationPendingRef.current = true
|
|
1185
|
+
if (event.group === 'velero.io') veleroInvalidationPendingRef.current = true
|
|
1161
1186
|
|
|
1162
1187
|
const fast = fastInvalidationRef.current
|
|
1163
1188
|
fast.changedKinds.add(kind)
|
|
@@ -1212,6 +1237,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1212
1237
|
cnpgInvalidationPendingRef.current = false
|
|
1213
1238
|
queryClient.invalidateQueries({ queryKey: ['cnpg', 'workspace'] })
|
|
1214
1239
|
}
|
|
1240
|
+
if (veleroInvalidationPendingRef.current) {
|
|
1241
|
+
veleroInvalidationPendingRef.current = false
|
|
1242
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'workspace'] })
|
|
1243
|
+
queryClient.invalidateQueries({ queryKey: ['velero', 'schedule-activity'] })
|
|
1244
|
+
}
|
|
1215
1245
|
fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
|
|
1216
1246
|
}, 3000)
|
|
1217
1247
|
}
|
|
@@ -1776,7 +1806,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1776
1806
|
// backend stamps on each node (data.auditKey). Only badge-worthy findings
|
|
1777
1807
|
// reach the graph; the raw auditDanger/auditWarning property names remain at
|
|
1778
1808
|
// this compatibility boundary while the node presents them as High/Medium.
|
|
1779
|
-
|
|
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)
|
|
1780
1813
|
const auditSeverityMap = useMemo(
|
|
1781
1814
|
() => buildAuditSeverityMap(audit.data?.findings, audit.data?.checks),
|
|
1782
1815
|
[audit.data?.findings, audit.data?.checks],
|
|
@@ -1859,6 +1892,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1859
1892
|
accountSlot={<UserMenu variant="rail" pinned={navRailEffectivePinned} />}
|
|
1860
1893
|
whatsNew={whatsNewStatus.available ? { unread: whatsNewStatus.unread, onOpen: openWhatsNew } : undefined}
|
|
1861
1894
|
productHunt={productHuntRailEntry}
|
|
1895
|
+
communityUrl={COMMUNITY_SLACK_URL}
|
|
1862
1896
|
/>
|
|
1863
1897
|
)}
|
|
1864
1898
|
{/* `relative` makes this column the containing block for the absolute
|
|
@@ -1963,6 +1997,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1963
1997
|
onToggleTheme={toggleTheme}
|
|
1964
1998
|
onShowDiagnostics={() => setShowDiagnostics(true)}
|
|
1965
1999
|
onShowWhatsNew={whatsNewStatus.available ? openWhatsNew : undefined}
|
|
2000
|
+
onOpenCommunity={() => openExternal(COMMUNITY_SLACK_URL)}
|
|
1966
2001
|
onOpenResource={(hit) => navigateToResourceList(searchHitToSelectedResource(hit))}
|
|
1967
2002
|
/>
|
|
1968
2003
|
</div>
|
|
@@ -2211,6 +2246,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2211
2246
|
<div className="relative">
|
|
2212
2247
|
<LargeClusterNamespacePicker
|
|
2213
2248
|
namespaces={availableNamespaces}
|
|
2249
|
+
error={availableNamespacesError?.message}
|
|
2214
2250
|
onSelect={(ns) => {
|
|
2215
2251
|
setNamespaces([ns])
|
|
2216
2252
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2342,6 +2378,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2342
2378
|
initialTimeRange={(searchParams.get('time') as '5m' | '30m' | '1h' | '6h' | '24h' | 'all') || undefined}
|
|
2343
2379
|
requiresNamespaceFilter={topology?.requiresNamespaceFilter && namespaces.length === 0}
|
|
2344
2380
|
availableNamespaces={availableNamespaces}
|
|
2381
|
+
availableNamespacesError={availableNamespacesError?.message}
|
|
2345
2382
|
onNamespaceSelect={(ns) => {
|
|
2346
2383
|
setNamespaces([ns])
|
|
2347
2384
|
setActiveNamespace.mutate({ namespaces: [ns] })
|
|
@@ -2436,7 +2473,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2436
2473
|
|
|
2437
2474
|
{/* Checks detail view. Cloud can take over fleet best practices while
|
|
2438
2475
|
the target-specific upgrade route continues to render locally. */}
|
|
2439
|
-
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') ||
|
|
2476
|
+
{!viewsSyncGated && mainView === 'checks' && (!isViewTakenOver('checks') || localChecksRoute) && (
|
|
2440
2477
|
<AuditView
|
|
2441
2478
|
namespaces={namespaces}
|
|
2442
2479
|
onNavigateToResource={navigateToResourceList}
|
|
@@ -2624,7 +2661,14 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2624
2661
|
{helpOverlay.shouldRender && <ShortcutHelpOverlay isOpen={helpOverlay.isOpen} onClose={() => setShowHelp(false)} currentView={mainView} />}
|
|
2625
2662
|
|
|
2626
2663
|
{/* Diagnostics overlay */}
|
|
2627
|
-
{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
|
+
/>
|
|
2628
2672
|
|
|
2629
2673
|
{/* Settings dialog — My permissions is rendered inline in its own section */}
|
|
2630
2674
|
<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
|
+
})
|
|
@@ -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
|
+
});
|