@skyhook-io/radar-app 1.22.2 → 1.23.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 +8 -8
- package/src/App.tsx +35 -10
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +122 -24
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +315 -0
- package/src/api/workloadSource.ts +128 -12
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +3 -3
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +4 -4
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +52 -13
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
|
@@ -0,0 +1,43 @@
|
|
|
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 { expect, it, vi } from 'vitest'
|
|
6
|
+
import { useAutoPromConnect, type PrometheusStatus } from './client'
|
|
7
|
+
|
|
8
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
9
|
+
|
|
10
|
+
function Probe() {
|
|
11
|
+
useAutoPromConnect()
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
it('sends a discovery that an OpenObserve check canceled once the check ends without charts', async () => {
|
|
16
|
+
let connects = 0
|
|
17
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input) => {
|
|
18
|
+
const url = String(input)
|
|
19
|
+
if (url.includes('/cluster-info')) return new Response(JSON.stringify({ context: 'ctx' }))
|
|
20
|
+
if (url.includes('/prometheus/connect')) {
|
|
21
|
+
connects++
|
|
22
|
+
return new Response(JSON.stringify({ available: false, connected: false }))
|
|
23
|
+
}
|
|
24
|
+
return new Response(JSON.stringify(client.getQueryData(['prometheus-status'])))
|
|
25
|
+
}))
|
|
26
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, refetchInterval: false } } })
|
|
27
|
+
const notConnected: PrometheusStatus = { available: false, connected: false, openobserve: 'local' }
|
|
28
|
+
client.setQueryData(['prometheus-status'], notConnected)
|
|
29
|
+
const root = createRoot(document.createElement('div'))
|
|
30
|
+
await act(async () => root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>))
|
|
31
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 50)) })
|
|
32
|
+
|
|
33
|
+
// The check starts before the delayed first probe is sent, then ends without charts.
|
|
34
|
+
await act(async () => client.setQueryData(['prometheus-status'], { ...notConnected, source: { kind: 'openobserve', via: 'local', pending: true } }))
|
|
35
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 700)) })
|
|
36
|
+
expect(connects).toBe(0)
|
|
37
|
+
await act(async () => client.setQueryData(['prometheus-status'], { ...notConnected, source: { kind: 'openobserve', via: 'local', error: 'unreachable' } }))
|
|
38
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 700)) })
|
|
39
|
+
expect(connects).toBe(1)
|
|
40
|
+
|
|
41
|
+
act(() => root.unmount())
|
|
42
|
+
vi.unstubAllGlobals()
|
|
43
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
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 { expect, it, vi } from 'vitest'
|
|
6
|
+
import { useMetricsRelayCheck, type PrometheusStatus } from './client'
|
|
7
|
+
|
|
8
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
9
|
+
|
|
10
|
+
function Settings({ open }: { open: boolean }) {
|
|
11
|
+
useMetricsRelayCheck(open)
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const relay: PrometheusStatus = { available: true, connected: true, source: { kind: 'openobserve', via: 'local', matchedBy: 'id' } }
|
|
16
|
+
const down: PrometheusStatus = { available: false, connected: false, source: { kind: 'openobserve', via: 'local', matchedBy: 'id', unavailable: true, error: 'OpenObserve unavailable: connection refused' } }
|
|
17
|
+
|
|
18
|
+
async function settle() {
|
|
19
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 20)) })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
it('checks the relay once each time Settings opens and keeps the answer', async () => {
|
|
23
|
+
const checks: string[] = []
|
|
24
|
+
let server = relay
|
|
25
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input) => {
|
|
26
|
+
const url = String(input)
|
|
27
|
+
if (url.includes('check=true')) {
|
|
28
|
+
checks.push(url)
|
|
29
|
+
server = down
|
|
30
|
+
return new Response(JSON.stringify(down))
|
|
31
|
+
}
|
|
32
|
+
return new Response(JSON.stringify(server))
|
|
33
|
+
}))
|
|
34
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, refetchInterval: false } } })
|
|
35
|
+
client.setQueryData(['prometheus-status'], relay)
|
|
36
|
+
const root = createRoot(document.createElement('div'))
|
|
37
|
+
const render = (open: boolean) => act(async () => root.render(<QueryClientProvider client={client}><Settings open={open} /></QueryClientProvider>))
|
|
38
|
+
|
|
39
|
+
await render(false)
|
|
40
|
+
await settle()
|
|
41
|
+
expect(checks).toHaveLength(0)
|
|
42
|
+
|
|
43
|
+
await render(true)
|
|
44
|
+
await settle()
|
|
45
|
+
await render(true)
|
|
46
|
+
await settle()
|
|
47
|
+
expect(checks).toHaveLength(1)
|
|
48
|
+
expect(client.getQueryData<PrometheusStatus>(['prometheus-status'])?.source?.unavailable).toBe(true)
|
|
49
|
+
|
|
50
|
+
await render(false)
|
|
51
|
+
await render(true)
|
|
52
|
+
await settle()
|
|
53
|
+
expect(checks).toHaveLength(2)
|
|
54
|
+
act(() => root.unmount())
|
|
55
|
+
vi.unstubAllGlobals()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('never checks when metrics do not come through a relay', async () => {
|
|
59
|
+
const fetchMock = vi.fn<typeof fetch>(async () => new Response(JSON.stringify({ available: false, connected: false })))
|
|
60
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
61
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, refetchInterval: false } } })
|
|
62
|
+
client.setQueryData(['prometheus-status'], { available: false, connected: false })
|
|
63
|
+
const root = createRoot(document.createElement('div'))
|
|
64
|
+
await act(async () => root.render(<QueryClientProvider client={client}><Settings open /></QueryClientProvider>))
|
|
65
|
+
await settle()
|
|
66
|
+
expect(fetchMock.mock.calls.some(([u]) => String(u).includes('check=true'))).toBe(false)
|
|
67
|
+
act(() => root.unmount())
|
|
68
|
+
vi.unstubAllGlobals()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
function deferred() {
|
|
72
|
+
let resolve!: () => void
|
|
73
|
+
const promise = new Promise<void>((r) => { resolve = r })
|
|
74
|
+
return { promise, resolve }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The check only changes what Radar knows; the status shown is read after it,
|
|
78
|
+
// so a newer status (here, saved settings that dropped OpenObserve) is never
|
|
79
|
+
// replaced by the check's older reply.
|
|
80
|
+
it('reads the status after the check instead of keeping its reply', async () => {
|
|
81
|
+
const answer = deferred()
|
|
82
|
+
const saved: PrometheusStatus = { available: false, connected: false }
|
|
83
|
+
let server = relay
|
|
84
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input) => {
|
|
85
|
+
if (String(input).includes('check=true')) {
|
|
86
|
+
await answer.promise
|
|
87
|
+
return new Response(JSON.stringify(down))
|
|
88
|
+
}
|
|
89
|
+
return new Response(JSON.stringify(server))
|
|
90
|
+
}))
|
|
91
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, refetchInterval: false } } })
|
|
92
|
+
client.setQueryData(['prometheus-status'], relay)
|
|
93
|
+
const root = createRoot(document.createElement('div'))
|
|
94
|
+
await act(async () => root.render(<QueryClientProvider client={client}><Settings open /></QueryClientProvider>))
|
|
95
|
+
await settle()
|
|
96
|
+
|
|
97
|
+
server = saved
|
|
98
|
+
client.setQueryData(['prometheus-status'], saved)
|
|
99
|
+
answer.resolve()
|
|
100
|
+
await settle()
|
|
101
|
+
expect(client.getQueryData(['prometheus-status'])).toEqual(saved)
|
|
102
|
+
act(() => root.unmount())
|
|
103
|
+
vi.unstubAllGlobals()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('closing Settings stops its check, and reopening starts a new one', async () => {
|
|
107
|
+
const signals: AbortSignal[] = []
|
|
108
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input, init) => {
|
|
109
|
+
if (String(input).includes('check=true')) {
|
|
110
|
+
const signal = init?.signal as AbortSignal
|
|
111
|
+
signals.push(signal)
|
|
112
|
+
if (signals.length === 1) {
|
|
113
|
+
await new Promise((_, reject) => signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError'))))
|
|
114
|
+
}
|
|
115
|
+
return new Response(JSON.stringify(down))
|
|
116
|
+
}
|
|
117
|
+
return new Response(JSON.stringify(relay))
|
|
118
|
+
}))
|
|
119
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, refetchInterval: false } } })
|
|
120
|
+
client.setQueryData(['prometheus-status'], relay)
|
|
121
|
+
const root = createRoot(document.createElement('div'))
|
|
122
|
+
const render = (open: boolean) => act(async () => root.render(<QueryClientProvider client={client}><Settings open={open} /></QueryClientProvider>))
|
|
123
|
+
|
|
124
|
+
await render(true)
|
|
125
|
+
await settle()
|
|
126
|
+
await render(false)
|
|
127
|
+
await settle()
|
|
128
|
+
expect(signals[0]?.aborted).toBe(true)
|
|
129
|
+
await render(true)
|
|
130
|
+
await settle()
|
|
131
|
+
expect(signals).toHaveLength(2)
|
|
132
|
+
act(() => root.unmount())
|
|
133
|
+
vi.unstubAllGlobals()
|
|
134
|
+
})
|
package/src/api/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasPrometheusCharts, metricsSourceUnavailable } from './prometheusCharts'
|
|
1
|
+
import { hasPrometheusCharts, metricsSourceChecking, metricsSourceUnavailable } from './prometheusCharts'
|
|
2
2
|
import type { RightsizingRow, WorkloadRightsizingEvidence } from '@skyhook-io/k8s-ui/types/rightsizing'
|
|
3
3
|
import { followSwitch, switchFinished, switchInProgress, type ContextSwitchOperation } from './contextSwitch'
|
|
4
4
|
import { createListRefetchInterval, normalizeResourceList, type ResourceListBody, type ResourceListResult } from './resourceLists'
|
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
YamlDocumentIdentity,
|
|
39
39
|
YamlSchemaLoadResult,
|
|
40
40
|
} from '@skyhook-io/k8s-ui'
|
|
41
|
-
import { focusManager, onlineManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
41
|
+
import { focusManager, onlineManager, useInfiniteQuery, useIsFetching, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
|
|
42
42
|
import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
|
|
43
43
|
import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
|
|
44
44
|
import { applyTabPick, cleanPick, ownsTabPick, pruneTabPick, withActives, writeTabPick } from '../utils/namespacePick'
|
|
@@ -100,6 +100,7 @@ import {
|
|
|
100
100
|
import { useRadarUpgradeHost } from '../context/RadarUpgradeHost'
|
|
101
101
|
import { isGitOpsActionTarget, gitOpsActionPermissions, gitOpsDisabledReasons, type GitOpsActionCapabilities } from './gitOpsPermissions'
|
|
102
102
|
import { apiVersionToGroup } from '../utils/navigation'
|
|
103
|
+
import type { CloudHintEntry } from '../components/cloudHints/cloudHints'
|
|
103
104
|
import { isBadgeWorthy } from '../utils/auditBadges'
|
|
104
105
|
import type { DeploymentMode } from '../types'
|
|
105
106
|
|
|
@@ -599,6 +600,7 @@ import type {
|
|
|
599
600
|
Check,
|
|
600
601
|
Issue,
|
|
601
602
|
IssueRecentChange,
|
|
603
|
+
SchedulingBlockerSummary,
|
|
602
604
|
} from "@skyhook-io/k8s-ui";
|
|
603
605
|
export type DashboardAudit = AuditCardData;
|
|
604
606
|
export type { AuditFinding, ResourceGroup, CheckMeta, Check };
|
|
@@ -870,6 +872,9 @@ export function useUpgradeReadiness(target?: string) {
|
|
|
870
872
|
// that honestly rather than presenting a capped list as if it were complete.
|
|
871
873
|
export interface IssuesResponse {
|
|
872
874
|
issues: Issue[]
|
|
875
|
+
scheduling_blockers?: SchedulingBlockerSummary[]
|
|
876
|
+
scheduling_node_gap?: string
|
|
877
|
+
next_member_after?: string
|
|
873
878
|
total?: number
|
|
874
879
|
total_matched?: number
|
|
875
880
|
recent_changes?: IssueRecentChange[]
|
|
@@ -908,20 +913,38 @@ export interface UncheckedSource {
|
|
|
908
913
|
namespaces?: string[];
|
|
909
914
|
}
|
|
910
915
|
|
|
911
|
-
export function useIssues(namespaces: string[] = [], enabled = true, kind?: string) {
|
|
916
|
+
export function useIssues(namespaces: string[] = [], enabled = true, kind?: string, view?: 'blockers') {
|
|
912
917
|
const params = new URLSearchParams();
|
|
913
918
|
if (namespaces.length) params.set('namespaces', namespaces.join(','));
|
|
914
919
|
if (kind) { params.set('kind', kind); params.set('limit', '1000'); }
|
|
920
|
+
if (view) params.set('view', view);
|
|
915
921
|
const query = params.toString();
|
|
922
|
+
const key = kind ? ["issues", namespaces, kind] : ["issues", namespaces];
|
|
916
923
|
return useQuery<IssuesResponse>({
|
|
917
|
-
queryKey:
|
|
918
|
-
queryFn: () => fetchJSON(`/issues${query ? `?${query}` : ''}
|
|
924
|
+
queryKey: view ? [...key, view] : key,
|
|
925
|
+
queryFn: ({ signal }) => fetchJSON(`/issues${query ? `?${query}` : ''}`, signal),
|
|
919
926
|
staleTime: 30000,
|
|
920
927
|
refetchInterval: ISSUES_REFRESH_INTERVAL_MS,
|
|
921
928
|
enabled,
|
|
922
929
|
});
|
|
923
930
|
}
|
|
924
931
|
|
|
932
|
+
export function useSchedulingBlockerMembers(blocker: SchedulingBlockerSummary, namespaces: string[], enabled: boolean) {
|
|
933
|
+
return useInfiniteQuery({
|
|
934
|
+
queryKey: ["issues", namespaces, "blockers", blocker.id, blocker.affected_workloads],
|
|
935
|
+
queryFn: ({ pageParam, signal }) => {
|
|
936
|
+
const params = new URLSearchParams({ view: "blockers", blocker: blocker.id, limit: "25" });
|
|
937
|
+
if (namespaces.length) params.set("namespaces", namespaces.join(","));
|
|
938
|
+
if (pageParam) params.set("after", pageParam);
|
|
939
|
+
return fetchJSON<IssuesResponse>(`/issues?${params}`, signal);
|
|
940
|
+
},
|
|
941
|
+
initialPageParam: "",
|
|
942
|
+
getNextPageParam: (page) => page.next_member_after,
|
|
943
|
+
staleTime: ISSUES_REFRESH_INTERVAL_MS,
|
|
944
|
+
enabled,
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
925
948
|
export function useResourceAudit(
|
|
926
949
|
kind: string,
|
|
927
950
|
namespace: string,
|
|
@@ -2170,6 +2193,13 @@ function versionCheckQueryOptions(apiBase: string) {
|
|
|
2170
2193
|
};
|
|
2171
2194
|
}
|
|
2172
2195
|
|
|
2196
|
+
/** The connected Radar's version, from the version check the app already runs; undefined until known. */
|
|
2197
|
+
export function useRadarVersion(): string | undefined {
|
|
2198
|
+
const { data } = useQuery<VersionInfo>(versionCheckQueryOptions(getApiBase()))
|
|
2199
|
+
const { radarVersion } = useRadarUpgradeHost()
|
|
2200
|
+
return data?.currentVersion || radarVersion || undefined
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2173
2203
|
export function useVersionCheck() {
|
|
2174
2204
|
const capabilities = useCapabilities()
|
|
2175
2205
|
const apiBase = getApiBase()
|
|
@@ -2569,19 +2599,21 @@ export interface CloudConnectInfo {
|
|
|
2569
2599
|
|
|
2570
2600
|
// Deliberately a bare cross-origin GET: no credentials, no identifiers. The
|
|
2571
2601
|
// Hub learns what any HTTP request reveals plus `about`, below: the lane the
|
|
2572
|
-
// footer renders
|
|
2573
|
-
// about the cluster or the person rides
|
|
2574
|
-
// lane change (a driver install that just
|
|
2575
|
-
// instead of reusing the
|
|
2602
|
+
// footer renders, this deployment's mode, and which in-app hint opened the
|
|
2603
|
+
// dialog, all closed enums, so nothing about the cluster or the person rides
|
|
2604
|
+
// along. Part of the query key so a lane change (a driver install that just
|
|
2605
|
+
// became tunneled, say) or a different hint refetches instead of reusing the
|
|
2606
|
+
// other's copy.
|
|
2576
2607
|
export function useCloudConnectInfo(
|
|
2577
2608
|
apiUrl: string | undefined,
|
|
2578
2609
|
enabled: boolean,
|
|
2579
|
-
about: { lane: "driver" | "wizard"; mode?: DeploymentMode },
|
|
2610
|
+
about: { lane: "driver" | "wizard"; mode?: DeploymentMode; entry?: CloudHintEntry | null },
|
|
2580
2611
|
) {
|
|
2581
2612
|
const params = new URLSearchParams({ lane: about.lane });
|
|
2582
2613
|
if (about.mode) params.set("mode", about.mode);
|
|
2614
|
+
if (about.entry) params.set("entry", about.entry);
|
|
2583
2615
|
return useQuery<CloudConnectInfo>({
|
|
2584
|
-
queryKey: ["cloud-connect-info", apiUrl, about.lane, about.mode],
|
|
2616
|
+
queryKey: ["cloud-connect-info", apiUrl, about.lane, about.mode, about.entry ?? null],
|
|
2585
2617
|
queryFn: async () => {
|
|
2586
2618
|
const res = await fetch(`${apiUrl}/api/connect/info?${params}`, {
|
|
2587
2619
|
credentials: "omit",
|
|
@@ -2667,14 +2699,22 @@ export interface CloudInstallDiscovered {
|
|
|
2667
2699
|
partialScan: boolean
|
|
2668
2700
|
}
|
|
2669
2701
|
|
|
2670
|
-
// Keyed by context: a switch must not describe the previous cluster.
|
|
2671
|
-
|
|
2702
|
+
// Keyed by context: a switch must not describe the previous cluster. The
|
|
2703
|
+
// lookup lists Deployments across the cluster, so a caller that only words a
|
|
2704
|
+
// hint can reuse an answer up to maxAgeMs old. Those answers are cached under
|
|
2705
|
+
// their own key: the Cloud dialog passes none and must never show an old
|
|
2706
|
+
// answer while it asks again.
|
|
2707
|
+
export function useCloudInstallDiscover(
|
|
2708
|
+
enabled: boolean,
|
|
2709
|
+
contextName: string | undefined,
|
|
2710
|
+
{ maxAgeMs = 0 }: { maxAgeMs?: number } = {},
|
|
2711
|
+
) {
|
|
2672
2712
|
return useQuery<CloudInstallDiscovered>({
|
|
2673
|
-
queryKey: ['cloud-install-discover', contextName],
|
|
2713
|
+
queryKey: maxAgeMs > 0 ? ['cloud-install-discover', contextName, 'reusable'] : ['cloud-install-discover', contextName],
|
|
2674
2714
|
queryFn: () => fetchJSON('/cloud/install/discover'),
|
|
2675
2715
|
enabled,
|
|
2676
|
-
staleTime:
|
|
2677
|
-
gcTime:
|
|
2716
|
+
staleTime: maxAgeMs,
|
|
2717
|
+
gcTime: maxAgeMs,
|
|
2678
2718
|
retry: false,
|
|
2679
2719
|
})
|
|
2680
2720
|
}
|
|
@@ -4399,6 +4439,48 @@ export function usePrometheusStatus(enabled = true) {
|
|
|
4399
4439
|
});
|
|
4400
4440
|
}
|
|
4401
4441
|
|
|
4442
|
+
const PROM_STATUS_CHECK_KEY = ["prometheus-status-check"];
|
|
4443
|
+
|
|
4444
|
+
/**
|
|
4445
|
+
* Settings opening on a metrics relay (OpenObserve) asks Radar to send it one
|
|
4446
|
+
* query and wait, so a backend that went down while nothing queried it reads
|
|
4447
|
+
* as unavailable rather than connected. Radar never queries it on its own.
|
|
4448
|
+
*/
|
|
4449
|
+
export function useMetricsRelayCheck(open: boolean) {
|
|
4450
|
+
const queryClient = useQueryClient();
|
|
4451
|
+
const { data: status } = usePrometheusStatus(open);
|
|
4452
|
+
const relay = status?.source?.kind === "openobserve" && !!(status.source.matchedBy || status.source.unavailable);
|
|
4453
|
+
const checked = useRef(false);
|
|
4454
|
+
useEffect(() => {
|
|
4455
|
+
if (!open) {
|
|
4456
|
+
checked.current = false;
|
|
4457
|
+
void queryClient.cancelQueries({ queryKey: PROM_STATUS_CHECK_KEY });
|
|
4458
|
+
return;
|
|
4459
|
+
}
|
|
4460
|
+
if (checked.current || !relay) return;
|
|
4461
|
+
checked.current = true;
|
|
4462
|
+
queryClient
|
|
4463
|
+
.fetchQuery({
|
|
4464
|
+
queryKey: PROM_STATUS_CHECK_KEY,
|
|
4465
|
+
// The check only updates what Radar knows. The status is read after
|
|
4466
|
+
// it rather than taken from its reply, so a newer status this tab
|
|
4467
|
+
// received meanwhile is never replaced by an older one.
|
|
4468
|
+
queryFn: async ({ signal }) => {
|
|
4469
|
+
await fetchJSON("/prometheus/status?check=true", signal);
|
|
4470
|
+
await queryClient.refetchQueries({ queryKey: ["prometheus-status"], exact: true });
|
|
4471
|
+
return true;
|
|
4472
|
+
},
|
|
4473
|
+
staleTime: 0,
|
|
4474
|
+
})
|
|
4475
|
+
.catch(() => {});
|
|
4476
|
+
}, [open, relay, queryClient]);
|
|
4477
|
+
}
|
|
4478
|
+
|
|
4479
|
+
/** A metrics relay check Settings asked for is waiting on its answer. */
|
|
4480
|
+
export function useMetricsRelayChecking(): boolean {
|
|
4481
|
+
return useIsFetching({ queryKey: PROM_STATUS_CHECK_KEY }) > 0;
|
|
4482
|
+
}
|
|
4483
|
+
|
|
4402
4484
|
export interface ArgoStatus {
|
|
4403
4485
|
// configured = a URL or token is set; connected = a probe has landed and the
|
|
4404
4486
|
// client is live. The two differ right after a restart (configured, reconnecting).
|
|
@@ -4521,6 +4603,7 @@ export function useAutoPromConnect(): void {
|
|
|
4521
4603
|
const { data: status, isLoading: statusLoading } = usePrometheusStatus();
|
|
4522
4604
|
const chartsAvailable = hasPrometheusCharts(status);
|
|
4523
4605
|
const sourceUnavailable = metricsSourceUnavailable(status);
|
|
4606
|
+
const sourceChecking = metricsSourceChecking(status);
|
|
4524
4607
|
const attemptedRef = useRef<string | null>(null);
|
|
4525
4608
|
|
|
4526
4609
|
useEffect(() => {
|
|
@@ -4541,6 +4624,9 @@ export function useAutoPromConnect(): void {
|
|
|
4541
4624
|
// An OpenObserve connection that can't answer is the source in use;
|
|
4542
4625
|
// discovering Prometheus would not stand in for it.
|
|
4543
4626
|
if (sourceUnavailable) return;
|
|
4627
|
+
// Until Radar knows whether OpenObserve serves this cluster, discovering
|
|
4628
|
+
// Prometheus would race the answer.
|
|
4629
|
+
if (sourceChecking) return;
|
|
4544
4630
|
if (attemptedRef.current === context) return;
|
|
4545
4631
|
let cached: string | null = null;
|
|
4546
4632
|
try {
|
|
@@ -4554,13 +4640,15 @@ export function useAutoPromConnect(): void {
|
|
|
4554
4640
|
// Cached path probes immediately; first-time path defers briefly so the
|
|
4555
4641
|
// initial UI render isn't competing with the cluster network call.
|
|
4556
4642
|
const delay = cached === "1" ? 0 : PROM_FIRSTLAUNCH_PROBE_DELAY_MS;
|
|
4643
|
+
// The server only reports discovering once the run has started; mark it
|
|
4644
|
+
// now so the view shows progress from the start instead of the manual CTA
|
|
4645
|
+
// until the request lands.
|
|
4646
|
+
queryClient.setQueryData<PrometheusStatus>(["prometheus-status"], (prev) =>
|
|
4647
|
+
prev ? { ...prev, discovering: true } : prev,
|
|
4648
|
+
);
|
|
4649
|
+
let sent = false;
|
|
4557
4650
|
const timeout = window.setTimeout(() => {
|
|
4558
|
-
|
|
4559
|
-
// here first so the view shows progress instead of the manual CTA for the
|
|
4560
|
-
// whole duration of this request.
|
|
4561
|
-
queryClient.setQueryData<PrometheusStatus>(["prometheus-status"], (prev) =>
|
|
4562
|
-
prev ? { ...prev, discovering: true } : prev,
|
|
4563
|
-
);
|
|
4651
|
+
sent = true;
|
|
4564
4652
|
// Direct apiFetch (not via the usePrometheusConnect mutation) so the
|
|
4565
4653
|
// meta-driven toast handler stays silent — the user didn't click anything.
|
|
4566
4654
|
apiFetch(`${getApiBase()}/prometheus/connect?optional=true`, {
|
|
@@ -4592,8 +4680,18 @@ export function useAutoPromConnect(): void {
|
|
|
4592
4680
|
attemptedRef.current = null;
|
|
4593
4681
|
});
|
|
4594
4682
|
}, delay);
|
|
4595
|
-
return () =>
|
|
4596
|
-
|
|
4683
|
+
return () => {
|
|
4684
|
+
window.clearTimeout(timeout);
|
|
4685
|
+
if (sent) return;
|
|
4686
|
+
// Canceled before it was sent (an OpenObserve check began, say): forget
|
|
4687
|
+
// the attempt so the probe runs once this context is eligible again.
|
|
4688
|
+
attemptedRef.current = null;
|
|
4689
|
+
queryClient.setQueryData<PrometheusStatus>(
|
|
4690
|
+
["prometheus-status"],
|
|
4691
|
+
(prev) => (prev?.discovering ? { ...prev, discovering: false } : prev),
|
|
4692
|
+
);
|
|
4693
|
+
};
|
|
4694
|
+
}, [clusterInfo?.context, chartsAvailable, sourceUnavailable, sourceChecking, statusLoading, queryClient]);
|
|
4597
4695
|
}
|
|
4598
4696
|
|
|
4599
4697
|
// Fetch Prometheus metrics for a resource
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, useRef } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { useCloudInstallDiscover } from './client'
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
9
|
+
let root: Root
|
|
10
|
+
let host: HTMLDivElement
|
|
11
|
+
let client: QueryClient
|
|
12
|
+
let calls = 0
|
|
13
|
+
|
|
14
|
+
const firstRenders: string[] = []
|
|
15
|
+
|
|
16
|
+
function Probe({ maxAgeMs }: { maxAgeMs?: number }) {
|
|
17
|
+
const q = useCloudInstallDiscover(true, 'kind-dev', maxAgeMs === undefined ? undefined : { maxAgeMs })
|
|
18
|
+
const shown = q.data ? 'ready' : 'pending'
|
|
19
|
+
// Recorded during the first render itself: read after act() instead, the
|
|
20
|
+
// fetch may already have resolved, depending on how busy the machine is.
|
|
21
|
+
const recorded = useRef(false)
|
|
22
|
+
if (!recorded.current) {
|
|
23
|
+
recorded.current = true
|
|
24
|
+
firstRenders.push(shown)
|
|
25
|
+
}
|
|
26
|
+
return <span>{shown}</span>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function mountProbe(maxAgeMs?: number) {
|
|
30
|
+
await act(async () => {
|
|
31
|
+
root.render(<QueryClientProvider client={client}><Probe maxAgeMs={maxAgeMs} /></QueryClientProvider>)
|
|
32
|
+
})
|
|
33
|
+
await vi.waitFor(() => expect(host.textContent).toBe('ready'))
|
|
34
|
+
await act(async () => root.unmount())
|
|
35
|
+
root = createRoot(host)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
calls = 0
|
|
40
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
41
|
+
host = document.createElement('div')
|
|
42
|
+
document.body.appendChild(host)
|
|
43
|
+
root = createRoot(host)
|
|
44
|
+
vi.stubGlobal('fetch', vi.fn(async () => {
|
|
45
|
+
calls++
|
|
46
|
+
return new Response(JSON.stringify({ connected: [], partialScan: false }), { status: 200 })
|
|
47
|
+
}))
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
client.clear()
|
|
52
|
+
host.remove()
|
|
53
|
+
vi.unstubAllGlobals()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('useCloudInstallDiscover', () => {
|
|
57
|
+
it('reuses a recent answer when the caller allows one', async () => {
|
|
58
|
+
await mountProbe(5 * 60_000)
|
|
59
|
+
await mountProbe(5 * 60_000)
|
|
60
|
+
expect(calls).toBe(1)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('asks again on every mount by default, as the Cloud dialog needs', async () => {
|
|
64
|
+
await mountProbe()
|
|
65
|
+
await mountProbe()
|
|
66
|
+
expect(calls).toBe(2)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('never shows a default caller the cached answer while it asks again', async () => {
|
|
70
|
+
firstRenders.length = 0
|
|
71
|
+
await mountProbe(5 * 60_000)
|
|
72
|
+
await mountProbe()
|
|
73
|
+
expect(calls).toBe(2)
|
|
74
|
+
expect(firstRenders[1]).toBe('pending')
|
|
75
|
+
})
|
|
76
|
+
})
|
package/src/api/diagnose.ts
CHANGED
|
@@ -35,6 +35,10 @@ export interface AgentsResponse {
|
|
|
35
35
|
// "install an agent to enable this" (eligible && !enabled) apart from "not
|
|
36
36
|
// available here" (auth/cloud/--no-mcp). Absent on older servers / embed hosts.
|
|
37
37
|
eligible?: boolean;
|
|
38
|
+
// Why investigations can't run here when not eligible: "shared" for a team
|
|
39
|
+
// installation (auth or operator-managed config), "no-mcp" when the MCP
|
|
40
|
+
// mount is off. Empty when eligible; absent on older servers.
|
|
41
|
+
unavailableReason?: "" | "shared" | "no-mcp";
|
|
38
42
|
// cliOverride: RADAR_AI_CLI_BIN is set, pinning the engine to one CLI. With
|
|
39
43
|
// CLIs detected and investigations still off, that variable is what's broken.
|
|
40
44
|
// Absent on older servers and embed hosts.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
2
|
+
import { QueryClient, useInfiniteQuery, useQuery } from '@tanstack/react-query'
|
|
3
|
+
import { ApiError, fetchJSON } from './client'
|
|
4
|
+
import { useKagentSessionSummary, useKagentWorkspace } from './kagent'
|
|
5
|
+
const state = vi.hoisted(() => ({ workspace: 'supported', context: 'one', base: '/api' }))
|
|
6
|
+
vi.mock('@tanstack/react-query', async (original) => ({ ...(await original<typeof import('@tanstack/react-query')>()), useQuery: vi.fn(() => ({})), useInfiniteQuery: vi.fn(() => ({})) }))
|
|
7
|
+
vi.mock('./config', () => ({ getApiBase: () => state.base }))
|
|
8
|
+
vi.mock('./client', async (original) => ({
|
|
9
|
+
...(await original<typeof import('./client')>()),
|
|
10
|
+
fetchJSON: vi.fn(),
|
|
11
|
+
useClusterInfo: () => ({ data: { context: state.context } }),
|
|
12
|
+
useRadarFeature: (feature: string) => ({
|
|
13
|
+
support: feature === 'kagentWorkspace' ? state.workspace : 'unsupported',
|
|
14
|
+
gatedKey: [],
|
|
15
|
+
guard: (fn: () => unknown) => fn(),
|
|
16
|
+
}),
|
|
17
|
+
}))
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.clearAllMocks()
|
|
20
|
+
state.workspace = 'supported'
|
|
21
|
+
state.context = 'one'
|
|
22
|
+
state.base = '/api'
|
|
23
|
+
})
|
|
24
|
+
it.each(['unsupported', 'unknown'])('gates configuration and runtime on the workspace capability while it is %s', (support) => {
|
|
25
|
+
state.workspace = support
|
|
26
|
+
useKagentWorkspace([])
|
|
27
|
+
expect(vi.mocked(useQuery).mock.calls.at(-1)![0].enabled).toBe(false)
|
|
28
|
+
useKagentSessionSummary([])
|
|
29
|
+
expect(vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].enabled).toBe(false)
|
|
30
|
+
})
|
|
31
|
+
it('keeps retrying pending discovery and keeps the ordinary error budget', () => {
|
|
32
|
+
useKagentWorkspace([])
|
|
33
|
+
const options = vi.mocked(useQuery).mock.calls.at(-1)![0]
|
|
34
|
+
const retry = options.retry as (count: number, error: unknown) => boolean
|
|
35
|
+
const delay = options.retryDelay as (count: number, error: unknown) => number
|
|
36
|
+
const pending = new ApiError('discovery is running', 503, { error_code: 'kind_sync_pending' })
|
|
37
|
+
expect(retry(10, pending)).toBe(true)
|
|
38
|
+
expect(delay(10, pending)).toBe(2000)
|
|
39
|
+
expect(retry(1, new ApiError('unavailable', 503))).toBe(false)
|
|
40
|
+
})
|
|
41
|
+
it('separates namespaces, contexts and API hosts and carries cancellation', async () => {
|
|
42
|
+
useKagentWorkspace(['b', 'a'])
|
|
43
|
+
const first = vi.mocked(useQuery).mock.calls.at(-1)![0]
|
|
44
|
+
await (first.queryFn as (context: { signal: AbortSignal }) => Promise<unknown>)({ signal: new AbortController().signal })
|
|
45
|
+
expect(fetchJSON).toHaveBeenCalledWith('/kagent/workspace?namespaces=a%2Cb', expect.any(AbortSignal))
|
|
46
|
+
state.context = 'two'
|
|
47
|
+
useKagentWorkspace(['a', 'b'])
|
|
48
|
+
expect(vi.mocked(useQuery).mock.calls.at(-1)![0].queryKey).not.toEqual(first.queryKey)
|
|
49
|
+
state.base = '/other'
|
|
50
|
+
useKagentWorkspace(['a', 'b'])
|
|
51
|
+
expect(vi.mocked(useQuery).mock.calls.at(-1)![0].queryKey).not.toEqual(first.queryKey)
|
|
52
|
+
expect(first.placeholderData).toBeUndefined()
|
|
53
|
+
})
|
|
54
|
+
it('pages the fleet summary instead of treating its first 1000 Agents as the fleet', () => {
|
|
55
|
+
useKagentSessionSummary([])
|
|
56
|
+
const options = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0]
|
|
57
|
+
const next = options.getNextPageParam as (lastPage: { offset: number; rows: unknown[]; total: number }) => number | undefined
|
|
58
|
+
expect(next({ offset: 0, rows: Array(1000), total: 1001 })).toBe(1000)
|
|
59
|
+
expect(next({ offset: 1000, rows: [1], total: 1001 })).toBeUndefined()
|
|
60
|
+
expect(next({ offset: 0, rows: [], total: 1001 })).toBeUndefined()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('invalidates session summaries with the saved Substrate connection, only for that API host', async () => {
|
|
64
|
+
const client = new QueryClient()
|
|
65
|
+
useKagentSessionSummary([])
|
|
66
|
+
const first = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].queryKey
|
|
67
|
+
state.base = '/other'
|
|
68
|
+
useKagentSessionSummary([])
|
|
69
|
+
const other = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].queryKey
|
|
70
|
+
client.setQueryData(first, { rows: [] })
|
|
71
|
+
client.setQueryData(other, { rows: [] })
|
|
72
|
+
await client.invalidateQueries({ queryKey: ['substrate', '/api'] })
|
|
73
|
+
expect(client.getQueryState(first)?.isInvalidated).toBe(true)
|
|
74
|
+
expect(client.getQueryState(other)?.isInvalidated).toBe(false)
|
|
75
|
+
client.clear()
|
|
76
|
+
})
|
|
77
|
+
it('enables both workspace endpoints when Radar advertises kagentWorkspace', () => {
|
|
78
|
+
useKagentWorkspace([])
|
|
79
|
+
useKagentSessionSummary([])
|
|
80
|
+
expect(vi.mocked(useQuery).mock.calls.at(-1)![0].enabled).toBe(true)
|
|
81
|
+
expect(vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].enabled).toBe(true)
|
|
82
|
+
})
|