@skyhook-io/radar-app 1.21.6 → 1.21.8
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/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -4
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +582 -114
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/NamespaceSwitcher.tsx +6 -2
- package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +127 -173
- package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
- package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/HomeView.tsx +9 -1
- package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +78 -2
- package/src/components/issues/IssuesPane.tsx +49 -6
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/FormSaveActions.tsx +6 -2
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
- package/src/components/settings/OpenObserveSetup.tsx +328 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +103 -16
- package/src/components/workspace/WorkspaceConditions.tsx +56 -0
- package/src/components/workspace/layout.test.tsx +20 -0
- package/src/components/workspace/layout.tsx +1 -1
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +5 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/utils/page-links.ts +15 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { focusManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import type { OwnershipCoverage } from '@skyhook-io/k8s-ui/types'
|
|
7
|
+
import { useResourceWithRelationships } from './client'
|
|
8
|
+
import { getApiBase, setApiBase } from './config'
|
|
9
|
+
|
|
10
|
+
const pending = 'kind_sync_pending'
|
|
11
|
+
const settled = { children: { complete: true } }
|
|
12
|
+
const loading = { children: { complete: false, notChecked: [{ kind: 'Pod', reason: pending }] } }
|
|
13
|
+
|
|
14
|
+
let client: QueryClient
|
|
15
|
+
let host: HTMLDivElement
|
|
16
|
+
let root: ReturnType<typeof createRoot>
|
|
17
|
+
let originalBase: string
|
|
18
|
+
let ownership: Partial<OwnershipCoverage>
|
|
19
|
+
let requests: number[]
|
|
20
|
+
let status: number
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
vi.useFakeTimers()
|
|
24
|
+
vi.setSystemTime(0)
|
|
25
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
26
|
+
client = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false } } })
|
|
27
|
+
host = document.createElement('div')
|
|
28
|
+
root = createRoot(host)
|
|
29
|
+
originalBase = getApiBase()
|
|
30
|
+
ownership = loading
|
|
31
|
+
requests = []
|
|
32
|
+
status = 200
|
|
33
|
+
vi.stubGlobal('fetch', vi.fn(async () => {
|
|
34
|
+
requests.push(Date.now())
|
|
35
|
+
if (status !== 200) return Response.json({ error: 'read failed' }, { status })
|
|
36
|
+
return Response.json({ resource: {}, relationships: { ownership } })
|
|
37
|
+
}))
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
act(() => root.unmount())
|
|
42
|
+
client.clear()
|
|
43
|
+
setApiBase(originalBase)
|
|
44
|
+
focusManager.setFocused(undefined)
|
|
45
|
+
vi.unstubAllGlobals()
|
|
46
|
+
vi.useRealTimers()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const key = ['resource', 'pods', 'shop', 'web', '']
|
|
50
|
+
const eightPolls = [5000, 15_000, 35_000, 65_000, 95_000, 125_000, 155_000, 185_000]
|
|
51
|
+
|
|
52
|
+
function Probe({ poll }: { poll?: boolean }) {
|
|
53
|
+
const result = useResourceWithRelationships('pods', 'shop', 'web', '', { pollPendingOwnership: poll })
|
|
54
|
+
return <span>{result.data?.relationships?.ownership?.children?.complete ? 'complete' : 'partial'}</span>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function observe(poll?: boolean) {
|
|
58
|
+
await act(async () => {
|
|
59
|
+
root.render(<QueryClientProvider client={client}><Probe poll={poll} /></QueryClientProvider>)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function advance(ms: number) {
|
|
64
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(ms) })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
it.each<[string, OwnershipCoverage]>([
|
|
68
|
+
['ownership', { ...settled, unavailableReason: pending }],
|
|
69
|
+
['owner', { ...settled, ownerReason: pending }],
|
|
70
|
+
['manages', { ...settled, manages: { membership: 'unreadable', unavailableReason: pending } }],
|
|
71
|
+
['managers', { ...settled, managers: { notChecked: [{ kind: 'Application', reason: pending }] } }],
|
|
72
|
+
['manager chain stop', {
|
|
73
|
+
...settled,
|
|
74
|
+
manager: {
|
|
75
|
+
state: 'unknown',
|
|
76
|
+
direct: { object: { kind: 'Pod', namespace: 'shop', name: 'web' } },
|
|
77
|
+
chainEnd: 'unfollowed',
|
|
78
|
+
stop: { at: { kind: 'ReplicaSet', namespace: 'shop', name: 'web-rs' }, state: 'unknown', reason: pending },
|
|
79
|
+
},
|
|
80
|
+
}],
|
|
81
|
+
['children', loading],
|
|
82
|
+
])('polls pending %s coverage and stops on an answer containing only other gaps', async (_, initial) => {
|
|
83
|
+
ownership = initial
|
|
84
|
+
await observe(true)
|
|
85
|
+
ownership = { children: { complete: false, notChecked: [{ kind: 'Pod', reason: 'kind_sync_timed_out' }] } }
|
|
86
|
+
await advance(240_000)
|
|
87
|
+
expect(requests).toEqual([0, 5000])
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('stops after eight foreground polls and starts again when the cached resource reopens', async () => {
|
|
91
|
+
await observe(true)
|
|
92
|
+
const query = client.getQueryCache().find({ queryKey: key, exact: true })
|
|
93
|
+
expect(query).toBeDefined()
|
|
94
|
+
await advance(240_000)
|
|
95
|
+
expect(requests).toEqual([0, ...eightPolls])
|
|
96
|
+
|
|
97
|
+
await act(async () => root.render(<QueryClientProvider client={client}>{null}</QueryClientProvider>))
|
|
98
|
+
await advance(1000)
|
|
99
|
+
await observe(true)
|
|
100
|
+
expect(client.getQueryCache().find({ queryKey: key, exact: true })).toBe(query)
|
|
101
|
+
await advance(240_000)
|
|
102
|
+
expect(requests).toEqual([0, ...eightPolls, 241_000, ...eightPolls.map(t => t + 241_000)])
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('gives a new cluster a fresh budget on the same mounted observer and query key', async () => {
|
|
106
|
+
setApiBase('/c/first/api')
|
|
107
|
+
await observe(true)
|
|
108
|
+
const query = client.getQueryCache().find({ queryKey: key, exact: true })
|
|
109
|
+
expect(query).toBeDefined()
|
|
110
|
+
await advance(240_000)
|
|
111
|
+
expect(requests).toEqual([0, ...eightPolls])
|
|
112
|
+
|
|
113
|
+
expect(fetch).toHaveBeenLastCalledWith('/c/first/api/resources/pods/shop/web', expect.anything())
|
|
114
|
+
setApiBase('/c/second/api')
|
|
115
|
+
await observe(true)
|
|
116
|
+
await act(async () => { await client.invalidateQueries({ queryKey: key, exact: true }) })
|
|
117
|
+
expect(client.getQueryCache().find({ queryKey: key, exact: true })).toBe(query)
|
|
118
|
+
await advance(240_000)
|
|
119
|
+
expect(requests).toEqual([0, ...eightPolls, 240_000, ...eightPolls.map(t => t + 240_000)])
|
|
120
|
+
expect(fetch).toHaveBeenLastCalledWith('/c/second/api/resources/pods/shop/web', expect.anything())
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('starts a new episode after the pending gap clears and reappears', async () => {
|
|
124
|
+
await observe(true)
|
|
125
|
+
await advance(240_000)
|
|
126
|
+
ownership = settled
|
|
127
|
+
await act(async () => { await client.invalidateQueries({ queryKey: key }) })
|
|
128
|
+
await advance(60_000)
|
|
129
|
+
expect(requests).toEqual([0, ...eightPolls, 240_000])
|
|
130
|
+
ownership = loading
|
|
131
|
+
await act(async () => { await client.invalidateQueries({ queryKey: key }) })
|
|
132
|
+
await advance(240_000)
|
|
133
|
+
expect(requests).toEqual([0, ...eightPolls, 240_000, 300_000, ...eightPolls.map(t => t + 300_000)])
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('accepts coverage without a children field', async () => {
|
|
137
|
+
ownership = {}
|
|
138
|
+
await observe(true)
|
|
139
|
+
await advance(60_000)
|
|
140
|
+
expect(requests).toEqual([0])
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('only polls while opted in', async () => {
|
|
144
|
+
await observe()
|
|
145
|
+
await advance(240_000)
|
|
146
|
+
expect(requests).toEqual([0])
|
|
147
|
+
await observe(true)
|
|
148
|
+
await advance(5000)
|
|
149
|
+
expect(requests).toEqual([0, 245_000])
|
|
150
|
+
await observe(false)
|
|
151
|
+
await advance(240_000)
|
|
152
|
+
expect(requests).toEqual([0, 245_000])
|
|
153
|
+
await observe(true)
|
|
154
|
+
await advance(240_000)
|
|
155
|
+
expect(requests).toEqual([0, 245_000, ...eightPolls.map(t => t + 485_000)])
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('keeps the remaining attempts across a long background pause and background refetches', async () => {
|
|
159
|
+
await observe(true)
|
|
160
|
+
await advance(5000)
|
|
161
|
+
const beforeBlur = vi.getTimerCount()
|
|
162
|
+
focusManager.setFocused(false)
|
|
163
|
+
// Blur cancels the poll timer, and a hidden view arms none while it waits.
|
|
164
|
+
expect(vi.getTimerCount()).toBe(beforeBlur - 1)
|
|
165
|
+
await advance(300_000)
|
|
166
|
+
expect(vi.getTimerCount()).toBe(0)
|
|
167
|
+
expect(requests).toEqual([0, 5000])
|
|
168
|
+
await act(async () => { await client.invalidateQueries({ queryKey: key }) })
|
|
169
|
+
await observe(true)
|
|
170
|
+
focusManager.setFocused(true)
|
|
171
|
+
await advance(240_000)
|
|
172
|
+
expect(requests).toEqual([0, 5000, 305_000, ...eightPolls.slice(1).map(t => t + 300_000)])
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('shares warmup answers with a passive observer of the same resource', async () => {
|
|
176
|
+
await act(async () => {
|
|
177
|
+
root.render(<QueryClientProvider client={client}><Probe poll /><Probe /></QueryClientProvider>)
|
|
178
|
+
})
|
|
179
|
+
ownership = settled
|
|
180
|
+
await advance(60_000)
|
|
181
|
+
expect(requests).toEqual([0, 5000])
|
|
182
|
+
expect([...host.querySelectorAll('span')].map(node => node.textContent)).toEqual(['complete', 'complete'])
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it.each([403, 404])('drops the stale warmup interval after a %i response', async (errorStatus) => {
|
|
186
|
+
await observe(true)
|
|
187
|
+
status = errorStatus
|
|
188
|
+
await advance(6000)
|
|
189
|
+
expect(requests).toEqual([0, 5000, 6000])
|
|
190
|
+
status = 200
|
|
191
|
+
await advance(59_999)
|
|
192
|
+
expect(requests).toEqual([0, 5000, 6000])
|
|
193
|
+
await advance(1)
|
|
194
|
+
expect(requests).toEqual(errorStatus === 404 ? [0, 5000, 6000, 66_000] : [0, 5000, 6000])
|
|
195
|
+
await advance(5000)
|
|
196
|
+
expect(requests).toEqual(errorStatus === 404 ? [0, 5000, 6000, 66_000, 71_000] : [0, 5000, 6000])
|
|
197
|
+
})
|
|
@@ -20,5 +20,9 @@ describe('prometheusStatusRefetchInterval', () => {
|
|
|
20
20
|
expect(prometheusStatusRefetchInterval({ available: true, connected: true, address: 'http://localhost:1' })).toBe(
|
|
21
21
|
PROM_STATUS_POLL_IDLE_MS,
|
|
22
22
|
)
|
|
23
|
+
// A backend match still running replaces its note when it settles.
|
|
24
|
+
expect(
|
|
25
|
+
prometheusStatusRefetchInterval({ available: true, connected: true, source: { kind: 'openobserve', via: 'local', pending: true } }),
|
|
26
|
+
).toBe(PROM_STATUS_POLL_DISCOVERING_MS)
|
|
23
27
|
})
|
|
24
28
|
})
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { restartErrorMessage } from './client'
|
|
2
|
+
import { restartErrorMessage, restartOutcome } from './client'
|
|
3
|
+
|
|
4
|
+
describe('restartOutcome', () => {
|
|
5
|
+
it('reports a new restart, including from a Radar that returns no changed field', () => {
|
|
6
|
+
expect(restartOutcome({ changed: true, restartedAt: '2026-11-25T10:00:00Z' })).toEqual({ title: 'Workload restarting', repeated: false })
|
|
7
|
+
expect(restartOutcome({ message: 'restarted' })).toEqual({ title: 'Workload restarting', repeated: false })
|
|
8
|
+
expect(restartOutcome(undefined)).toEqual({ title: 'Workload restarting', repeated: false })
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('says a restart was already requested when nothing new was written', () => {
|
|
12
|
+
const at = '2030-01-01T09:30:00Z'
|
|
13
|
+
expect(restartOutcome({ changed: false, restartedAt: at })).toEqual({
|
|
14
|
+
title: 'Restart already requested',
|
|
15
|
+
detail: `Requested for ${new Date(at).toLocaleString()}.`,
|
|
16
|
+
repeated: true,
|
|
17
|
+
})
|
|
18
|
+
expect(restartOutcome({ changed: false })).toEqual({ title: 'Restart already requested', detail: undefined, repeated: true })
|
|
19
|
+
})
|
|
20
|
+
})
|
|
3
21
|
|
|
4
22
|
describe('restartErrorMessage', () => {
|
|
5
23
|
it('points a paused refusal at the Resume rollout button instead of the server text', () => {
|
|
@@ -7,6 +25,23 @@ describe('restartErrorMessage', () => {
|
|
|
7
25
|
expect(msg).toContain('Resume rollout')
|
|
8
26
|
expect(msg).not.toContain('ns/web')
|
|
9
27
|
})
|
|
28
|
+
it.each([
|
|
29
|
+
['workload_changed', 'This workload changed or was replaced since you opened it. Refresh and try again.'],
|
|
30
|
+
['workload_terminating', 'This workload is being deleted and cannot be restarted.'],
|
|
31
|
+
['restart_not_stored', 'Kubernetes admission changed or removed the restart marker.'],
|
|
32
|
+
])('explains %s', (error_code, message) => {
|
|
33
|
+
expect(restartErrorMessage({ error: 'server detail', error_code }, 409)).toBe(message)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it.each(['OnDelete requires manual pod deletion', 'the StatefulSet rolling update partition is 2'])('includes the strategy detail for %s', reason => {
|
|
37
|
+
const error = `the update strategy would not restart all pods: ${reason}`
|
|
38
|
+
expect(restartErrorMessage({ error, error_code: 'restart_not_applicable' }, 409)).toBe(error)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('explains an inapplicable strategy when the server omits the detail', () => {
|
|
42
|
+
expect(restartErrorMessage({ error_code: 'restart_not_applicable' }, 409)).toBe('This workload’s update strategy won’t restart all pods.')
|
|
43
|
+
})
|
|
44
|
+
|
|
10
45
|
it('keeps the server text for every other failure', () => {
|
|
11
46
|
expect(restartErrorMessage({ error: 'deployments.apps "web" not found' }, 404)).toBe('deployments.apps "web" not found')
|
|
12
47
|
expect(restartErrorMessage({}, 500)).toBe('HTTP 500')
|
|
@@ -0,0 +1,133 @@
|
|
|
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, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { isWorkflowStopTargetGone, useStopWorkflow, workflowStopErrorMessage, workflowStopOutcome, type WorkflowStopStrategy } from './client'
|
|
7
|
+
import { showApiNotice, showApiSuccess } from '../components/ui/Toast'
|
|
8
|
+
|
|
9
|
+
vi.mock('../components/ui/Toast', () => ({
|
|
10
|
+
showApiError: vi.fn(),
|
|
11
|
+
showApiSuccess: vi.fn(),
|
|
12
|
+
showApiNotice: vi.fn(),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vi.mocked(showApiNotice).mockClear()
|
|
18
|
+
vi.mocked(showApiSuccess).mockClear()
|
|
19
|
+
})
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.unstubAllGlobals()
|
|
22
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async function stop(response: { status: number; body: unknown }, strategy: WorkflowStopStrategy = 'Stop') {
|
|
26
|
+
const posts: Array<{ url: string; body: unknown; contentType: string | null }> = []
|
|
27
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input, init) => {
|
|
28
|
+
posts.push({ url: String(input), body: init?.body, contentType: new Headers(init?.headers).get('Content-Type') })
|
|
29
|
+
return new Response(JSON.stringify(response.body), { status: response.status, headers: { 'Content-Type': 'application/json' } })
|
|
30
|
+
}))
|
|
31
|
+
const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } })
|
|
32
|
+
const invalidate = vi.spyOn(client, 'invalidateQueries')
|
|
33
|
+
let mutate: (() => Promise<unknown>) | undefined
|
|
34
|
+
function Probe() {
|
|
35
|
+
const m = useStopWorkflow()
|
|
36
|
+
mutate = () => m.mutateAsync({ namespace: 'ci', name: 'build-7', uid: 'uid-1', strategy })
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
const root = createRoot(document.createElement('div'))
|
|
40
|
+
await act(async () => { root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>) })
|
|
41
|
+
let result: unknown
|
|
42
|
+
let error: unknown
|
|
43
|
+
await act(async () => { await mutate!().then(r => { result = r }, e => { error = e }) })
|
|
44
|
+
act(() => root.unmount())
|
|
45
|
+
return { posts, result, error, invalidated: invalidate.mock.calls.map(c => c[0]?.queryKey) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('useStopWorkflow', () => {
|
|
49
|
+
it('sends the reviewed UID and strategy, and no resourceVersion', async () => {
|
|
50
|
+
const { posts } = await stop({ status: 200, body: { shutdown: 'Terminate', changed: true } }, 'Terminate')
|
|
51
|
+
expect(posts).toHaveLength(1)
|
|
52
|
+
expect(posts[0].url).toMatch(/\/workflows\/ci\/build-7\/stop$/)
|
|
53
|
+
expect(posts[0].contentType).toBe('application/json')
|
|
54
|
+
expect(JSON.parse(String(posts[0].body))).toEqual({ uid: 'uid-1', strategy: 'Terminate' })
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('reports a stored Stop as requested and refreshes the Workflow', async () => {
|
|
58
|
+
const { result, invalidated } = await stop({ status: 200, body: { shutdown: 'Stop', changed: true } })
|
|
59
|
+
expect(result).toEqual({ state: 'requested', shutdown: 'Stop' })
|
|
60
|
+
expect(showApiSuccess).toHaveBeenCalledWith('Stop requested', expect.stringContaining('exit handlers'))
|
|
61
|
+
expect(invalidated).toContainEqual(['resource', 'workflows', 'ci', 'build-7'])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('says a run is already stopping when nothing changed', async () => {
|
|
65
|
+
const { result } = await stop({ status: 200, body: { shutdown: 'Stop', changed: false } })
|
|
66
|
+
expect(result).toEqual({ state: 'already', shutdown: 'Stop' })
|
|
67
|
+
expect(showApiNotice).toHaveBeenCalledWith('Workflow is already stopping', undefined, 'info')
|
|
68
|
+
expect(showApiSuccess).not.toHaveBeenCalled()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('says a run is already terminating when a stored Terminate satisfied a Stop', async () => {
|
|
72
|
+
await stop({ status: 200, body: { shutdown: 'Terminate', changed: false } })
|
|
73
|
+
expect(showApiNotice).toHaveBeenCalledWith('Workflow is already terminating', undefined, 'info')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('treats a finished run as an outcome, not a failure, and still refreshes', async () => {
|
|
77
|
+
const { result, error, invalidated } = await stop({ status: 409, body: { error: 'the workflow has already finished', error_code: 'workflow_finished' } })
|
|
78
|
+
expect(error).toBeUndefined()
|
|
79
|
+
expect(result).toEqual({ state: 'finished' })
|
|
80
|
+
expect(showApiNotice).toHaveBeenCalledWith('Workflow already finished', 'Nothing was stopped.', 'info')
|
|
81
|
+
expect(invalidated).toContainEqual(['resource', 'workflows', 'ci', 'build-7'])
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('fails a replaced run with its own message and still refreshes', async () => {
|
|
85
|
+
const { error, invalidated } = await stop({ status: 409, body: { error: 'a different workflow now has this name', error_code: 'workflow_replaced' } })
|
|
86
|
+
expect((error as Error).message).toContain('A different Workflow now has this name')
|
|
87
|
+
expect(invalidated).toContainEqual(['resource', 'workflows', 'ci', 'build-7'])
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('passes other refusals through unchanged', async () => {
|
|
91
|
+
const { error } = await stop({ status: 403, body: { error: 'failed to stop workflow: forbidden' } })
|
|
92
|
+
expect((error as Error).message).toBe('failed to stop workflow: forbidden')
|
|
93
|
+
expect(isWorkflowStopTargetGone(error)).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('marks a replaced or missing run as gone, so the dialog has nothing to retry', async () => {
|
|
97
|
+
const replaced = await stop({ status: 409, body: { error: 'x', error_code: 'workflow_replaced' } })
|
|
98
|
+
expect(isWorkflowStopTargetGone(replaced.error)).toBe(true)
|
|
99
|
+
const missing = await stop({ status: 404, body: { error: 'workflow not found' } })
|
|
100
|
+
expect(isWorkflowStopTargetGone(missing.error)).toBe(true)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('warns, not "already stopping", when admission dropped the requested Stop', async () => {
|
|
104
|
+
// The server compares with the value before the patch: empty then, empty now.
|
|
105
|
+
const { result } = await stop({ status: 200, body: { shutdown: '', changed: false } })
|
|
106
|
+
expect(result).toEqual({ state: 'notStored', shutdown: '' })
|
|
107
|
+
expect(showApiNotice).toHaveBeenCalledWith('Stop not stored', expect.stringContaining('keeps running'), 'warning')
|
|
108
|
+
expect(showApiNotice).not.toHaveBeenCalledWith('Workflow is already stopping', undefined, 'info')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('warns when admission rewrote a Terminate to Stop', async () => {
|
|
112
|
+
const { result } = await stop({ status: 200, body: { shutdown: 'Stop', changed: true } }, 'Terminate')
|
|
113
|
+
expect(result).toEqual({ state: 'notStored', shutdown: 'Stop' })
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('workflowStopOutcome', () => {
|
|
118
|
+
it('reads an existing Terminate as satisfying a Stop', () => {
|
|
119
|
+
expect(workflowStopOutcome('Stop', { shutdown: 'Terminate', changed: false })).toEqual({ state: 'already', shutdown: 'Terminate' })
|
|
120
|
+
})
|
|
121
|
+
it('flags a Stop that admission stored as Terminate', () => {
|
|
122
|
+
expect(workflowStopOutcome('Stop', { shutdown: 'Terminate', changed: true })).toEqual({ state: 'notStored', shutdown: 'Terminate' })
|
|
123
|
+
})
|
|
124
|
+
it('reads an escalation from Stop as requested', () => {
|
|
125
|
+
expect(workflowStopOutcome('Terminate', { shutdown: 'Terminate', changed: true })).toEqual({ state: 'requested', shutdown: 'Terminate' })
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe('workflowStopErrorMessage', () => {
|
|
130
|
+
it('falls back to the status without a server message', () => {
|
|
131
|
+
expect(workflowStopErrorMessage({}, 502)).toBe('HTTP 502')
|
|
132
|
+
})
|
|
133
|
+
})
|
|
@@ -0,0 +1,127 @@
|
|
|
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, beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import type { WorkflowTemplateSubmission } from '@skyhook-io/k8s-ui/utils/workflow-template-submit'
|
|
7
|
+
import { useRadarFeature, useSubmitWorkflowTemplate } from './client'
|
|
8
|
+
import { isRadarFeatureUnsupported } from './radarFeatures'
|
|
9
|
+
import { showApiSuccess } from '../components/ui/Toast'
|
|
10
|
+
|
|
11
|
+
vi.mock('../components/ui/Toast', () => ({
|
|
12
|
+
showApiError: vi.fn(),
|
|
13
|
+
showApiSuccess: vi.fn(),
|
|
14
|
+
showApiNotice: vi.fn(),
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
20
|
+
})
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.unstubAllGlobals()
|
|
23
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
24
|
+
vi.restoreAllMocks()
|
|
25
|
+
vi.mocked(showApiSuccess).mockClear()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const baseSubmission: WorkflowTemplateSubmission = {
|
|
29
|
+
namespace: 'jobs',
|
|
30
|
+
name: 'migrate',
|
|
31
|
+
parameters: { target: 'orders', mode: 'apply' },
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function submit(
|
|
35
|
+
features: Record<string, boolean>,
|
|
36
|
+
postResult: Response | Error = new Response('{"namespace":"jobs","name":"migrate-k2x9q","uid":"run-1"}', { status: 200 }),
|
|
37
|
+
submission: WorkflowTemplateSubmission = baseSubmission,
|
|
38
|
+
) {
|
|
39
|
+
const posts: Array<{ url: string; body: unknown; contentType: string | null }> = []
|
|
40
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input, init) => {
|
|
41
|
+
const url = String(input)
|
|
42
|
+
if (init?.method === 'POST') {
|
|
43
|
+
posts.push({ url, body: JSON.parse(String(init.body)), contentType: new Headers(init.headers).get('Content-Type') })
|
|
44
|
+
if (postResult instanceof Error) throw postResult
|
|
45
|
+
return postResult
|
|
46
|
+
}
|
|
47
|
+
if (url.includes('/capabilities')) return new Response(JSON.stringify({ features }), { status: 200 })
|
|
48
|
+
return new Response('{}', { status: 200 })
|
|
49
|
+
}))
|
|
50
|
+
const client = new QueryClient({ defaultOptions: { mutations: { retry: false }, queries: { retry: false } } })
|
|
51
|
+
const invalidate = vi.spyOn(client, 'invalidateQueries')
|
|
52
|
+
let mutate: (() => Promise<unknown>) | undefined
|
|
53
|
+
let support = ''
|
|
54
|
+
function Probe() {
|
|
55
|
+
const m = useSubmitWorkflowTemplate()
|
|
56
|
+
support = useRadarFeature('workflowTemplateSubmit').support
|
|
57
|
+
mutate = () => m.mutateAsync(submission)
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
const root = createRoot(document.createElement('div'))
|
|
61
|
+
await act(async () => { root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>) })
|
|
62
|
+
await vi.waitFor(() => expect(support).not.toBe('unknown'))
|
|
63
|
+
let result: unknown
|
|
64
|
+
let failure: unknown
|
|
65
|
+
await act(async () => { try { result = await mutate!() } catch (err) { failure = err } })
|
|
66
|
+
const invalidated = invalidate.mock.calls.map(([filters]) => JSON.stringify(filters?.queryKey))
|
|
67
|
+
act(() => root.unmount())
|
|
68
|
+
client.clear()
|
|
69
|
+
return { posts, result, failure, invalidated }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
it('posts parameters and optional run name, and refreshes the runs', async () => {
|
|
73
|
+
const { posts, result, failure, invalidated } = await submit(
|
|
74
|
+
{ workflowTemplateSubmit: true },
|
|
75
|
+
undefined,
|
|
76
|
+
{ ...baseSubmission, runName: 'migrate-k2x9q' },
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
expect(failure).toBeUndefined()
|
|
80
|
+
expect(result).toEqual({ namespace: 'jobs', name: 'migrate-k2x9q', uid: 'run-1' })
|
|
81
|
+
expect(posts).toHaveLength(1)
|
|
82
|
+
expect(posts[0].url).toMatch(/\/api\/workflowtemplates\/jobs\/migrate\/submit$/)
|
|
83
|
+
expect(posts[0].contentType).toBe('application/json')
|
|
84
|
+
expect(posts[0].body).toEqual({
|
|
85
|
+
name: 'migrate-k2x9q',
|
|
86
|
+
parameters: { target: 'orders', mode: 'apply' },
|
|
87
|
+
})
|
|
88
|
+
expect(invalidated).toContain(JSON.stringify(['workload-runs', 'workflowtemplates', 'jobs', 'migrate']))
|
|
89
|
+
expect(showApiSuccess).toHaveBeenCalledWith('Workflow submitted', 'jobs/migrate-k2x9q')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('omits name when no explicit run name is set', async () => {
|
|
93
|
+
const { posts, failure } = await submit({ workflowTemplateSubmit: true })
|
|
94
|
+
|
|
95
|
+
expect(failure).toBeUndefined()
|
|
96
|
+
expect(posts[0].body).toEqual({ parameters: { target: 'orders', mode: 'apply' } })
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('surfaces definite refusals without refreshing the runs', async () => {
|
|
100
|
+
for (const response of [
|
|
101
|
+
new Response('{"error":"parameter \\"target\\" is required","error_code":"invalid_parameters"}', { status: 400 }),
|
|
102
|
+
new Response('{"error":"a Workflow named migrate-k2x9q already exists","error_code":"workflow_name_taken"}', { status: 409 }),
|
|
103
|
+
]) {
|
|
104
|
+
const { failure, invalidated } = await submit({ workflowTemplateSubmit: true }, response)
|
|
105
|
+
expect(failure).toBeInstanceOf(Error)
|
|
106
|
+
expect(invalidated).not.toContain(JSON.stringify(['workload-runs', 'workflowtemplates', 'jobs', 'migrate']))
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('refreshes the runs when a 5xx or network error leaves the outcome ambiguous', async () => {
|
|
111
|
+
for (const err of [
|
|
112
|
+
new Response('{"error":"could not create the workflow"}', { status: 500 }),
|
|
113
|
+
new Response('{"error":"Kubernetes timed out"}', { status: 504 }),
|
|
114
|
+
new TypeError('Failed to fetch'),
|
|
115
|
+
]) {
|
|
116
|
+
const { failure, invalidated } = await submit({ workflowTemplateSubmit: true }, err)
|
|
117
|
+
expect(failure).toBeInstanceOf(Error)
|
|
118
|
+
expect(invalidated).toContain(JSON.stringify(['workload-runs', 'workflowtemplates', 'jobs', 'migrate']))
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('sends nothing to a Radar that predates the route', async () => {
|
|
123
|
+
const { posts, failure } = await submit({ workflowStop: true })
|
|
124
|
+
|
|
125
|
+
expect(posts).toHaveLength(0)
|
|
126
|
+
expect(isRadarFeatureUnsupported(failure, 'workflowTemplateSubmit')).toBe(true)
|
|
127
|
+
})
|