@skyhook-io/radar-app 1.17.1 → 1.18.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 +9 -9
- package/src/App.tsx +14 -30
- package/src/api/client.gitopsPoll.test.ts +99 -0
- package/src/api/client.helmPreview.test.tsx +48 -0
- package/src/api/client.resourceAvailability.test.ts +24 -0
- package/src/api/client.ts +337 -87
- package/src/api/client.workloadRuns.test.ts +53 -0
- package/src/api/config.test.ts +23 -1
- package/src/api/config.ts +7 -3
- package/src/api/diagnose.ts +4 -1
- package/src/api/drain-plan.test.ts +70 -40
- package/src/api/policy.ts +5 -5
- package/src/api/radarFeatures.ts +1 -0
- package/src/api/traffic.scope.render.test.tsx +60 -0
- package/src/api/traffic.ts +3 -1
- package/src/components/cnpg/CNPGSummaryHost.tsx +4 -3
- package/src/components/diagnose/DiagnoseSurface.tsx +3 -3
- package/src/components/diagnose/InvestigationChangesEvidence.test.tsx +352 -0
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +101 -0
- package/src/components/diagnose/InvestigationView.tsx +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/changes.test.ts +123 -0
- package/src/components/diagnose/investigationEvidence/adapters/changes.ts +192 -3
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +73 -51
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +64 -2
- package/src/components/diagnose/investigationEvidence/adapters/resource.test.ts +37 -0
- package/src/components/diagnose/investigationEvidence/adapters/testdata/get-changes-created.json +323 -0
- package/src/components/diagnose/investigationEvidence/bodies/streams.tsx +144 -15
- package/src/components/diagnose/investigationEvidence/observations.ts +20 -0
- package/src/components/diagnose/investigationEvidence/parse.ts +57 -1
- package/src/components/diagnose/investigationEvidence/projection.test.ts +107 -0
- package/src/components/diagnose/investigationEvidence/types.ts +11 -0
- package/src/components/diagnose/investigationEvidencePresentation.test.ts +18 -0
- package/src/components/diagnose/investigationState.test.ts +36 -1
- package/src/components/diagnose/investigationState.ts +8 -0
- package/src/components/diagnose/launch.ts +2 -2
- package/src/components/dock/BottomDock.tsx +6 -3
- package/src/components/dock/WorkloadLogsTab.tsx +3 -0
- package/src/components/execution/BatchExecutionView.render.test.tsx +29 -1
- package/src/components/execution/BatchExecutionView.tsx +23 -8
- package/src/components/execution/cluster-template-runs.render.test.tsx +42 -0
- package/src/components/gitops/GitOpsView.tsx +7 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +139 -55
- package/src/components/helm/HelmReleaseNotes.test.tsx +42 -0
- package/src/components/helm/HelmReleaseNotes.tsx +26 -0
- package/src/components/helm/OwnedResources.tsx +2 -2
- package/src/components/helm/TrackChartSourceDialog.render.test.tsx +76 -4
- package/src/components/helm/TrackChartSourceDialog.test.ts +3 -2
- package/src/components/helm/TrackChartSourceDialog.tsx +41 -15
- package/src/components/helm/ValuesDiffPreview.tsx +4 -1
- package/src/components/home/ClusterHealthCard.tsx +4 -4
- package/src/components/home/CostCard.test.tsx +100 -0
- package/src/components/home/CostCard.tsx +2 -2
- package/src/components/home/HelmSummary.tsx +2 -2
- package/src/components/home/HomeView.tsx +15 -6
- package/src/components/home/MCPSetupDialog.test.tsx +30 -0
- package/src/components/home/MCPSetupDialog.tsx +13 -6
- package/src/components/home/ProblemsPanel.test.tsx +1 -0
- package/src/components/home/mcpToolCatalog.ts +18 -2
- package/src/components/issues/IssuesPane.render.test.tsx +21 -0
- package/src/components/issues/IssuesPane.tsx +31 -7
- package/src/components/issues/UncheckedSourceHelp.test.tsx +42 -0
- package/src/components/issues/UncheckedSourceHelp.tsx +24 -0
- package/src/components/issues/uncheckedSources.test.ts +43 -0
- package/src/components/issues/uncheckedSources.ts +58 -5
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +4 -2
- package/src/components/resources/ImageFilesystemModal.test.tsx +68 -0
- package/src/components/resources/ImageFilesystemModal.tsx +11 -4
- package/src/components/resources/PodFilesystemModal.tsx +2 -2
- package/src/components/resources/ResourcesView.scope.render.test.tsx +58 -0
- package/src/components/resources/ResourcesView.tsx +18 -3
- package/src/components/resources/renderers/FluxHelmReleaseRenderer.test.tsx +111 -0
- package/src/components/resources/renderers/FluxHelmReleaseRenderer.tsx +67 -0
- package/src/components/resources/renderers/KyvernoPolicyCoverage.scope.render.test.tsx +64 -0
- package/src/components/resources/renderers/KyvernoPolicyCoverage.tsx +6 -7
- package/src/components/settings/SettingsDialog.tsx +21 -15
- package/src/components/traffic/TrafficFilterSidebar.test.tsx +77 -0
- package/src/components/traffic/TrafficFilterSidebar.tsx +42 -31
- package/src/components/traffic/TrafficView.tsx +12 -12
- package/src/components/traffic/trafficFilters.test.ts +20 -1
- package/src/components/traffic/trafficFilters.ts +13 -0
- package/src/components/ui/Omnibar.tsx +13 -2
- package/src/components/ui/Toast.tsx +1 -1
- package/src/components/ui/omnibar-match.test.ts +30 -0
- package/src/components/ui/omnibar-match.ts +18 -0
- package/src/components/workload/CronJobSchedulingEvidence.test.tsx +35 -0
- package/src/components/workload/CronJobSchedulingEvidence.tsx +37 -0
- package/src/components/workload/NodeDrainStatus.test.tsx +253 -0
- package/src/components/workload/NodeDrainStatus.tsx +55 -0
- package/src/components/workload/WorkloadView.tsx +37 -5
- package/src/context/ConnectionContext.test.ts +27 -1
- package/src/context/ConnectionContext.tsx +17 -7
- package/src/integrations/resourceHosts.test.tsx +1 -0
- package/src/integrations/resourceHosts.tsx +2 -0
- package/src/utils/navigation.ts +14 -0
- package/src/utils/wails-clipboard.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyhook-io/radar-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.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",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"react-markdown": "^10.1.0",
|
|
39
39
|
"react-virtuoso": "^4.18.16",
|
|
40
40
|
"remark-gfm": "^4.0.1",
|
|
41
|
-
"shiki": "^4.
|
|
42
|
-
"yaml": "^2.9.
|
|
41
|
+
"shiki": "^4.5.0",
|
|
42
|
+
"yaml": "^2.9.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@skyhook-io/k8s-ui": ">=1.17.1",
|
|
@@ -63,17 +63,17 @@
|
|
|
63
63
|
"@types/node": "^26.6.2",
|
|
64
64
|
"@types/react": "^19.3.0",
|
|
65
65
|
"@types/react-dom": "^19.3.0",
|
|
66
|
-
"@vitejs/plugin-react": "^6.1.
|
|
67
|
-
"@xyflow/react": "^12.
|
|
66
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
67
|
+
"@xyflow/react": "^12.12.0",
|
|
68
68
|
"clsx": "^2.1.1",
|
|
69
69
|
"elkjs": "^0.11.1",
|
|
70
|
-
"eslint": "^10.
|
|
70
|
+
"eslint": "^10.13.0",
|
|
71
71
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
72
72
|
"eslint-plugin-react-refresh": "^0.5.3",
|
|
73
73
|
"globals": "^17.11.0",
|
|
74
74
|
"lucide-react": "^1.48.0",
|
|
75
|
-
"postcss": "^8.5.
|
|
76
|
-
"prettier": "^3.9.
|
|
75
|
+
"postcss": "^8.5.30",
|
|
76
|
+
"prettier": "^3.9.10",
|
|
77
77
|
"react": "^19.3.0",
|
|
78
78
|
"react-dom": "^19.3.0",
|
|
79
79
|
"react-router-dom": "^7.18.4",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"tailwindcss": "^4.3.3",
|
|
82
82
|
"typescript": "^6.0.2",
|
|
83
83
|
"typescript-eslint": "^8.71.0",
|
|
84
|
-
"vite": "^8.3.
|
|
84
|
+
"vite": "^8.3.4"
|
|
85
85
|
},
|
|
86
86
|
"sideEffects": [
|
|
87
87
|
"*.css"
|
package/src/App.tsx
CHANGED
|
@@ -45,7 +45,7 @@ import { navigateFromPrimaryRail } from './components/nav/navigation'
|
|
|
45
45
|
import { useNavRailPinned } from './hooks/useNavRailPinned'
|
|
46
46
|
import { useMediaQuery } from './hooks/useMediaQuery'
|
|
47
47
|
import { ContextSwitchProvider, useContextSwitch } from './context/ContextSwitchContext'
|
|
48
|
-
import { ConnectionProvider, useConnection } from './context/ConnectionContext'
|
|
48
|
+
import { ConnectionProvider, useConnection, refreshQueriesAfterReconnect } from './context/ConnectionContext'
|
|
49
49
|
import { ConnectionErrorView } from './components/ConnectionErrorView'
|
|
50
50
|
import { SyncProgressPanel } from './components/SyncProgressPanel'
|
|
51
51
|
import { NoClusterAccessBanner } from './components/NoClusterAccessBanner'
|
|
@@ -77,7 +77,7 @@ import { SettingsDialog, type SettingsSectionId } from './components/settings/Se
|
|
|
77
77
|
import type { APIResource, TopologyNode, GroupingMode, MainView, SelectedResource, SelectedHelmRelease, NodeKind, TopologyMode, Topology, K8sEvent } from './types'
|
|
78
78
|
import { createViewMemory } from './utils/viewMemory'
|
|
79
79
|
import { createKindFilterStore } from './utils/kindFilterStore'
|
|
80
|
-
import { kindToPluralWithGroup, pluralToKind, openExternal, apiVersionToGroup, relatedResourcePath, searchHitToSelectedResource, withCrossViewParams, writeViewParams, CROSS_VIEW_PARAMS } from './utils/navigation'
|
|
80
|
+
import { kindToPluralWithGroup, pluralToKind, openExternal, apiVersionToGroup, relatedResourcePath, searchHitToSelectedResource, withCrossViewParams, writeViewParams, CROSS_VIEW_PARAMS, namespacesFromSearch } from './utils/navigation'
|
|
81
81
|
import { findSelectedTopologyNode } from './utils/topology-selection'
|
|
82
82
|
import { type OmnibarHandle } from './components/ui/Omnibar'
|
|
83
83
|
import { RadarOmnibar } from './components/ui/RadarOmnibar'
|
|
@@ -416,24 +416,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
416
416
|
}
|
|
417
417
|
}, [navigate])
|
|
418
418
|
|
|
419
|
-
// Parse namespaces from URL (supports both 'namespaces' and legacy 'namespace')
|
|
420
|
-
const parseNamespacesFromURL = (params: URLSearchParams): string[] => {
|
|
421
|
-
// Prefer 'namespaces' (plural, comma-separated)
|
|
422
|
-
const nsParam = params.get('namespaces')
|
|
423
|
-
if (nsParam) {
|
|
424
|
-
return nsParam.split(',').map(s => s.trim()).filter(Boolean)
|
|
425
|
-
}
|
|
426
|
-
// Fall back to 'namespace' (singular) for backward compatibility
|
|
427
|
-
const ns = params.get('namespace')
|
|
428
|
-
if (ns) {
|
|
429
|
-
return [ns]
|
|
430
|
-
}
|
|
431
|
-
return []
|
|
432
|
-
}
|
|
433
|
-
|
|
434
419
|
// Initialize state from URL
|
|
435
420
|
const getInitialState = () => {
|
|
436
|
-
const namespaces =
|
|
421
|
+
const namespaces = namespacesFromSearch(searchParams)
|
|
437
422
|
return {
|
|
438
423
|
namespaces,
|
|
439
424
|
topologyMode: (searchParams.get('mode') as TopologyMode) || 'resources',
|
|
@@ -1236,11 +1221,8 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1236
1221
|
onContextChanged: (context) => {
|
|
1237
1222
|
resetNavigationMap()
|
|
1238
1223
|
|
|
1239
|
-
//
|
|
1240
|
-
|
|
1241
|
-
// removeQueries clears cached data, invalidateQueries triggers refetch
|
|
1242
|
-
queryClient.removeQueries()
|
|
1243
|
-
queryClient.invalidateQueries()
|
|
1224
|
+
// Reconnects also emit context_changed. Preserve only this context's drain record.
|
|
1225
|
+
refreshQueriesAfterReconnect(queryClient, connection.context, context)
|
|
1244
1226
|
|
|
1245
1227
|
// Cancel any pending SSE-driven invalidation — old cluster's events are irrelevant
|
|
1246
1228
|
if (fastInvalidationRef.current.timer !== null) clearTimeout(fastInvalidationRef.current.timer)
|
|
@@ -1442,11 +1424,13 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1442
1424
|
const setActiveNamespace = useSetActiveNamespace()
|
|
1443
1425
|
// Defer the state flip to onSuccess. Setting namespaces to [] before the
|
|
1444
1426
|
// server-side pref has actually been cleared makes React Query refetch
|
|
1445
|
-
// under the new empty key while
|
|
1446
|
-
//
|
|
1447
|
-
//
|
|
1448
|
-
//
|
|
1449
|
-
//
|
|
1427
|
+
// under the new empty key while a Radar that applies the stored pick to
|
|
1428
|
+
// reads naming no namespace (Hub embeds this UI against such Radars) returns
|
|
1429
|
+
// the previous pick's scope, caching stale data under the new key with no
|
|
1430
|
+
// later invalidation.
|
|
1431
|
+
// onSettled would do the same on errors, leaving the UI showing "All
|
|
1432
|
+
// namespaces" while data is still namespace-scoped — onSuccess keeps state
|
|
1433
|
+
// aligned with the server.
|
|
1450
1434
|
//
|
|
1451
1435
|
// Don't touch the URL here either: setSearchParams on a still-set state
|
|
1452
1436
|
// trips the URL→state sync into firing setNamespaces([]) and a duplicate
|
|
@@ -1587,7 +1571,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1587
1571
|
// server while the per-user pick was still narrowed — the picker would
|
|
1588
1572
|
// show the server scope but lists/dashboard would stay on "all namespaces".
|
|
1589
1573
|
useEffect(() => {
|
|
1590
|
-
const urlNamespaces =
|
|
1574
|
+
const urlNamespaces = namespacesFromSearch(searchParams)
|
|
1591
1575
|
debugNamespaceLog('app:url-sync', {
|
|
1592
1576
|
search: searchParams.toString(),
|
|
1593
1577
|
urlNamespaces,
|
|
@@ -2570,7 +2554,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2570
2554
|
{!navCustomization.embedded && <UsageDataPrompt status={usageData.data} />}
|
|
2571
2555
|
|
|
2572
2556
|
{/* Bottom Dock for Terminal/Logs */}
|
|
2573
|
-
<BottomDock />
|
|
2557
|
+
<BottomDock viewNamespaces={namespaces} />
|
|
2574
2558
|
|
|
2575
2559
|
{/* Spacer for dock */}
|
|
2576
2560
|
<DockSpacer />
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ApiError,
|
|
4
|
+
gitopsInsightsRefetchInterval,
|
|
5
|
+
gitopsTreeRefetchInterval,
|
|
6
|
+
} from "./client";
|
|
7
|
+
|
|
8
|
+
type TreeQuery = Parameters<typeof gitopsTreeRefetchInterval>[0];
|
|
9
|
+
type InsightQuery = Parameters<typeof gitopsInsightsRefetchInterval>[0];
|
|
10
|
+
const outage = new TypeError("Failed to fetch");
|
|
11
|
+
const tree = (status: string, data: TreeQuery["state"]["data"], error: unknown = outage): TreeQuery => ({
|
|
12
|
+
state: { status, data, error: status === "error" ? error : null },
|
|
13
|
+
});
|
|
14
|
+
const insight = (status: string, data: InsightQuery["state"]["data"], error: unknown = outage): InsightQuery => ({
|
|
15
|
+
state: { status, data, error: status === "error" ? error : null },
|
|
16
|
+
});
|
|
17
|
+
const gone = new ApiError("Application not found", 404);
|
|
18
|
+
|
|
19
|
+
describe("gitopsTreeRefetchInterval", () => {
|
|
20
|
+
it("asks every 2s while Radar connects to argocd-server", () => {
|
|
21
|
+
expect(gitopsTreeRefetchInterval(tree("success", { healthApiPending: true }))).toBe(2000);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("asks every 30s while Radar retries, no faster than the server re-checks", () => {
|
|
25
|
+
expect(gitopsTreeRefetchInterval(tree("success", { healthApiRetrying: true }))).toBe(30_000);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("stops once health is in", () => {
|
|
29
|
+
expect(gitopsTreeRefetchInterval(tree("success", {}))).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("keeps asking slowly after a failed fetch, so a brief outage doesn't strand the page", () => {
|
|
33
|
+
expect(gitopsTreeRefetchInterval(tree("error", { healthApiRetrying: true }))).toBe(30_000);
|
|
34
|
+
expect(gitopsTreeRefetchInterval(tree("error", { healthApiPending: true }))).toBe(30_000);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("keeps asking through a long Radar or proxy outage", () => {
|
|
38
|
+
expect(gitopsTreeRefetchInterval(tree("error", { healthApiRetrying: true }, new ApiError("Bad Gateway", 502)))).toBe(30_000);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("stops once Radar answers that the Application is gone or can't be read", () => {
|
|
42
|
+
expect(gitopsTreeRefetchInterval(tree("error", { healthApiRetrying: true }, gone))).toBe(false);
|
|
43
|
+
expect(gitopsTreeRefetchInterval(tree("error", { healthApiPending: true }, new ApiError("Forbidden", 403)))).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("does not start polling after a failed fetch of a settled page", () => {
|
|
47
|
+
expect(gitopsTreeRefetchInterval(tree("error", {}))).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("gitopsInsightsRefetchInterval", () => {
|
|
52
|
+
it("asks every 2s while a sync runs", () => {
|
|
53
|
+
expect(
|
|
54
|
+
gitopsInsightsRefetchInterval(
|
|
55
|
+
insight("success", { summary: { operationPhase: "Running" } }),
|
|
56
|
+
),
|
|
57
|
+
).toBe(2000);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("asks every 2s while Radar connects", () => {
|
|
61
|
+
expect(
|
|
62
|
+
gitopsInsightsRefetchInterval(
|
|
63
|
+
insight("success", { capabilities: { argoConnecting: true } }),
|
|
64
|
+
),
|
|
65
|
+
).toBe(2000);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("asks every 30s while Radar retries", () => {
|
|
69
|
+
expect(
|
|
70
|
+
gitopsInsightsRefetchInterval(
|
|
71
|
+
insight("success", { capabilities: { argoRetrying: true } }),
|
|
72
|
+
),
|
|
73
|
+
).toBe(30_000);
|
|
74
|
+
expect(
|
|
75
|
+
gitopsInsightsRefetchInterval(
|
|
76
|
+
insight("success", { summary: { resourceHealthApiRetrying: true } }),
|
|
77
|
+
),
|
|
78
|
+
).toBe(30_000);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("keeps asking slowly after a failed fetch, including during a running sync", () => {
|
|
82
|
+
expect(
|
|
83
|
+
gitopsInsightsRefetchInterval(insight("error", { capabilities: { argoRetrying: true } })),
|
|
84
|
+
).toBe(30_000);
|
|
85
|
+
expect(
|
|
86
|
+
gitopsInsightsRefetchInterval(insight("error", { summary: { operationPhase: "Running" } })),
|
|
87
|
+
).toBe(30_000);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("stops once Radar answers that the Application is gone", () => {
|
|
91
|
+
expect(
|
|
92
|
+
gitopsInsightsRefetchInterval(insight("error", { capabilities: { argoRetrying: true } }, gone)),
|
|
93
|
+
).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("does not poll a settled page", () => {
|
|
97
|
+
expect(gitopsInsightsRefetchInterval(insight("success", {}))).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { HelmSourceSelectionError, useHelmPreviewValues } from './client'
|
|
7
|
+
|
|
8
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals()
|
|
11
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it.each([
|
|
15
|
+
{ code: undefined, sourceError: false },
|
|
16
|
+
{ code: 'release_changing', sourceError: false },
|
|
17
|
+
{ code: 'chart_source_changed', sourceError: true },
|
|
18
|
+
{ code: 'chart_source_required', sourceError: true },
|
|
19
|
+
])('classifies a preview conflict by error code: $code', async ({ code, sourceError }) => {
|
|
20
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(
|
|
21
|
+
JSON.stringify({ error: 'preview conflict', errorCode: code }),
|
|
22
|
+
{ status: 409, headers: { 'Content-Type': 'application/json' } },
|
|
23
|
+
)))
|
|
24
|
+
let mutate: ReturnType<typeof useHelmPreviewValues>['mutateAsync'] | undefined
|
|
25
|
+
function Probe() {
|
|
26
|
+
mutate = useHelmPreviewValues().mutateAsync
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } })
|
|
30
|
+
const root = createRoot(document.createElement('div'))
|
|
31
|
+
try {
|
|
32
|
+
await act(async () => root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>))
|
|
33
|
+
let failure: unknown
|
|
34
|
+
await act(async () => {
|
|
35
|
+
if (!mutate) throw new Error('Preview hook did not mount')
|
|
36
|
+
try {
|
|
37
|
+
await mutate({ namespace: 'default', name: 'demo', values: {} })
|
|
38
|
+
} catch (error) {
|
|
39
|
+
failure = error
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
expect(failure).toBeInstanceOf(Error)
|
|
43
|
+
expect(failure instanceof HelmSourceSelectionError).toBe(sourceError)
|
|
44
|
+
} finally {
|
|
45
|
+
await act(async () => root.unmount())
|
|
46
|
+
client.clear()
|
|
47
|
+
}
|
|
48
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { ApiError, fetchResourceAvailability } from './client'
|
|
3
|
+
|
|
4
|
+
afterEach(() => vi.unstubAllGlobals())
|
|
5
|
+
|
|
6
|
+
describe('resource availability checks', () => {
|
|
7
|
+
it.each([200, 404])('uses a body-free HEAD lookup for resource status %s', async status => {
|
|
8
|
+
const fetch = vi.fn<typeof globalThis.fetch>(async () => new Response(null, { status, headers: { 'X-Radar-Resource-Read': 'true' } }))
|
|
9
|
+
vi.stubGlobal('fetch', fetch)
|
|
10
|
+
expect(await fetchResourceAvailability('secrets', 'apps', 'credentials')).toBe(status === 200 ? 'present' : 'missing')
|
|
11
|
+
expect(fetch).toHaveBeenCalledOnce()
|
|
12
|
+
expect(fetch.mock.calls[0]?.[1]).toMatchObject({ method: 'HEAD' })
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it.each([403, 404, 503])('does not classify an upstream HTTP %s as a missing resource', async status => {
|
|
16
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(null, { status })))
|
|
17
|
+
await expect(fetchResourceAvailability('configmaps', 'apps', 'overrides')).rejects.toBeInstanceOf(ApiError)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it.each([200, 405])('keeps older Radar navigation without claiming availability for HTTP %s', async status => {
|
|
21
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(null, { status })))
|
|
22
|
+
expect(await fetchResourceAvailability('secrets', 'apps', 'credentials')).toBe('unchecked')
|
|
23
|
+
})
|
|
24
|
+
})
|