@skyhook-io/radar-app 1.22.2 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/App.tsx +49 -13
- 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 +151 -27
- package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
- 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/poll.ts +78 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +16 -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 +128 -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/helm/HelmDrawerRouting.test.tsx +34 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
- package/src/components/helm/HelmView.tsx +4 -3
- package/src/components/helm/ObservedHelmNotice.tsx +39 -17
- package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
- 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/issues/uncheckedSources.test.ts +8 -0
- package/src/components/issues/uncheckedSources.ts +3 -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/nudges/activeNudges.test.ts +39 -0
- package/src/components/nudges/activeNudges.ts +76 -0
- package/src/components/poll/OssPoll.tsx +871 -0
- package/src/components/poll/mount.test.ts +12 -0
- package/src/components/poll/pollCloud.test.ts +23 -0
- package/src/components/poll/pollCloud.ts +6 -0
- package/src/components/poll/pollDefinition.ts +93 -0
- package/src/components/poll/pollFlow.test.ts +140 -0
- package/src/components/poll/pollFlow.ts +137 -0
- package/src/components/poll/pollSender.test.ts +137 -0
- package/src/components/poll/pollSender.ts +76 -0
- package/src/components/poll/pollStorage.test.ts +53 -0
- package/src/components/poll/pollStorage.ts +77 -0
- package/src/components/poll/round.json +350 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +2 -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/ImageFilesystemModal.test.tsx +21 -1
- package/src/components/resources/ImageFilesystemModal.tsx +42 -3
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +24 -11
- 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/ui/UpdateNotification.tsx +2 -0
- package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
- 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/whats-new/WhatsNew.tsx +2 -0
- package/src/components/whats-new/releaseNotes.ts +75 -1
- 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,210 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { SubstrateSettings } from './SubstrateSettings'
|
|
6
|
+
|
|
7
|
+
// The form's lifecycle: what it saves against, what it keeps across refetches
|
|
8
|
+
// and cluster changes, and which access it shows.
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
const state = vi.hoisted(() => ({
|
|
12
|
+
view: undefined as any,
|
|
13
|
+
status: undefined as any,
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
refetch: vi.fn(),
|
|
16
|
+
dirty: vi.fn(),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
vi.mock('../../api/substrateWorkspace', () => ({
|
|
20
|
+
useSubstrateConnection: () => ({ data: state.view, refetch: state.refetch }),
|
|
21
|
+
useSubstrateStatus: () => state.status,
|
|
22
|
+
useUpdateSubstrateConnection: () => ({ mutate: state.put, reset() {}, isPending: false, error: null }),
|
|
23
|
+
substrateErrorCode: (e: any) => e?.code,
|
|
24
|
+
}))
|
|
25
|
+
vi.mock('../substrate/shared', () => ({
|
|
26
|
+
Term: ({ children }: any) => children,
|
|
27
|
+
CommandChip: () => null,
|
|
28
|
+
}))
|
|
29
|
+
vi.mock('@skyhook-io/k8s-ui', () => ({
|
|
30
|
+
Input: (props: any) => <input {...props} />,
|
|
31
|
+
AlertBanner: ({ children, title }: any) => <div>{title}{children}</div>,
|
|
32
|
+
Badge: ({ children }: any) => <span>{children}</span>,
|
|
33
|
+
Collapse: ({ children }: any) => <div>{children}</div>,
|
|
34
|
+
CollapseChevron: () => null,
|
|
35
|
+
ConfirmDialog: ({ open, onConfirm, confirmLabel }: any) => (open ? <button onClick={onConfirm}>{confirmLabel}</button> : null),
|
|
36
|
+
toneTextClass: () => '',
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
let root: Root
|
|
40
|
+
let host: HTMLDivElement
|
|
41
|
+
const draw = (active = true) => act(async () => root.render(<SubstrateSettings active={active} onDirtyChange={state.dirty} onBusyChange={() => {}} />))
|
|
42
|
+
const input = (placeholder: string) => host.querySelector<HTMLInputElement>(`input[placeholder="${placeholder}"]`)!
|
|
43
|
+
async function type(placeholder: string, value: string) {
|
|
44
|
+
const el = input(placeholder)
|
|
45
|
+
await act(async () => {
|
|
46
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(el, value)
|
|
47
|
+
el.dispatchEvent(new Event('input', { bubbles: true }))
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
const click = (label: string) => act(async () => Array.from(host.querySelectorAll('button')).find((b) => b.textContent === label)!.click())
|
|
51
|
+
|
|
52
|
+
const target = { binding: 'b', context: 'dev', fingerprint: 'fp', clientGeneration: 1, operationGeneration: 1 }
|
|
53
|
+
const localView = (over: any = {}) => ({
|
|
54
|
+
view: 'local', saved: true, targetChanged: false, target, revision: 'r1',
|
|
55
|
+
settings: { identity: 'tokenFile', tokenFile: '/old.token' },
|
|
56
|
+
sharedPrincipal: 'system:serviceaccount:ate-system:ate-client',
|
|
57
|
+
access: { state: 'connected' },
|
|
58
|
+
...over,
|
|
59
|
+
})
|
|
60
|
+
const status = (apiTier: any = { state: 'connected' }) => ({
|
|
61
|
+
data: { installed: true, apiService: { namespace: 'ate-system', name: 'api', port: 443, found: true }, apiTier, coverage: { pools: { state: 'full' } }, canConfigure: true },
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
beforeEach(async () => {
|
|
65
|
+
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
|
|
66
|
+
state.put.mockReset()
|
|
67
|
+
state.refetch.mockReset()
|
|
68
|
+
state.dirty.mockClear()
|
|
69
|
+
state.view = localView()
|
|
70
|
+
state.status = status()
|
|
71
|
+
host = document.createElement('div')
|
|
72
|
+
document.body.append(host)
|
|
73
|
+
root = createRoot(host)
|
|
74
|
+
await draw()
|
|
75
|
+
})
|
|
76
|
+
afterEach(async () => {
|
|
77
|
+
await act(async () => root.unmount())
|
|
78
|
+
host.remove()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('the local Substrate connection form', () => {
|
|
82
|
+
it('saves an edit against the revision it was read at, even after another save lands', async () => {
|
|
83
|
+
await type('research, support-bots', 'research')
|
|
84
|
+
expect(state.dirty).toHaveBeenLastCalledWith(true)
|
|
85
|
+
state.view = localView({ revision: 'r2', settings: { identity: 'tokenFile', tokenFile: '/someone-elses.token' } })
|
|
86
|
+
await draw()
|
|
87
|
+
expect(host.textContent).toContain('This connection changed since you started editing')
|
|
88
|
+
await click('Save changes')
|
|
89
|
+
// The server refuses r1 with conflict; the form never pairs its old draft with r2.
|
|
90
|
+
expect(state.put.mock.calls[0][0]).toMatchObject({ revision: 'r1', settings: { tokenFile: '/old.token', atespaces: ['research'] } })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('loads the other save on Discard', async () => {
|
|
94
|
+
await type('research, support-bots', 'research')
|
|
95
|
+
state.view = localView({ revision: 'r2', settings: { identity: 'tokenFile', tokenFile: '/new.token' } })
|
|
96
|
+
await draw()
|
|
97
|
+
await click('Discard')
|
|
98
|
+
expect(input('~/ate.token').value).toBe('/new.token')
|
|
99
|
+
expect(state.dirty).toHaveBeenLastCalledWith(false)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('follows a newer save when it has no edits', async () => {
|
|
103
|
+
state.view = localView({ revision: 'r2', settings: { identity: 'tokenFile', tokenFile: '/new.token' } })
|
|
104
|
+
await draw()
|
|
105
|
+
expect(input('~/ate.token').value).toBe('/new.token')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('follows a new target generation while clean, and saves against it', async () => {
|
|
109
|
+
state.view = localView({ target: { ...target, clientGeneration: 2, operationGeneration: 2 } })
|
|
110
|
+
await draw()
|
|
111
|
+
await type('research, support-bots', 'research')
|
|
112
|
+
await click('Save changes')
|
|
113
|
+
expect(state.put.mock.calls[0][0].target).toMatchObject({ clientGeneration: 2, operationGeneration: 2 })
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('adopts a later return to the revision a save replaced, once the save was seen', async () => {
|
|
117
|
+
state.put.mockImplementationOnce((_update: unknown, callbacks: any) =>
|
|
118
|
+
callbacks.onSuccess(localView({ revision: 'r2', settings: { identity: 'tokenFile', tokenFile: '/old.token', atespaces: ['research'] } })))
|
|
119
|
+
await type('research, support-bots', 'research')
|
|
120
|
+
await click('Save changes')
|
|
121
|
+
// The query still holds r1 for a moment: not adopted.
|
|
122
|
+
await draw()
|
|
123
|
+
expect(input('research, support-bots').value).toBe('research')
|
|
124
|
+
// It catches up to r2, then another Radar restores r1's contents.
|
|
125
|
+
state.view = localView({ revision: 'r2', settings: { identity: 'tokenFile', tokenFile: '/old.token', atespaces: ['research'] } })
|
|
126
|
+
await draw()
|
|
127
|
+
state.view = localView({ revision: 'r1' })
|
|
128
|
+
await draw()
|
|
129
|
+
expect(input('research, support-bots').value).toBe('')
|
|
130
|
+
await type('research, support-bots', 'support-bots')
|
|
131
|
+
await click('Save changes')
|
|
132
|
+
expect(state.put.mock.calls[1][0].revision).toBe('r1')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('keeps an edited draft on screen while the next cluster’s view loads, and doesn’t adopt it', async () => {
|
|
136
|
+
await type('research, support-bots', 'research')
|
|
137
|
+
state.view = undefined
|
|
138
|
+
await draw()
|
|
139
|
+
expect(input('research, support-bots').value).toBe('research')
|
|
140
|
+
expect(state.dirty).toHaveBeenLastCalledWith(true)
|
|
141
|
+
state.view = localView({ target: { ...target, binding: 'other', context: 'other', fingerprint: 'other-fp' } })
|
|
142
|
+
await draw()
|
|
143
|
+
expect(input('research, support-bots').value).toBe('research')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('shows the polled access, not the one the view was read with', async () => {
|
|
147
|
+
state.view = localView({ access: { state: 'connecting' } })
|
|
148
|
+
state.status = status({ state: 'connected', endpoint: '127.0.0.1:18443' })
|
|
149
|
+
await draw()
|
|
150
|
+
expect(host.textContent).toContain('Connected')
|
|
151
|
+
expect(host.textContent).not.toContain('Connecting')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('says a failed status request failed, and still offers the form', async () => {
|
|
155
|
+
state.status = { isError: true, error: new Error('HTTP 503') }
|
|
156
|
+
await draw()
|
|
157
|
+
expect(host.textContent).toContain('Radar couldn’t check Substrate’s status on this cluster: HTTP 503.')
|
|
158
|
+
expect(host.textContent).toContain('Who Radar reads Substrate as')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('offers Disconnect for a connection saved on a cluster that no longer serves Substrate', async () => {
|
|
162
|
+
state.status = { data: { ...status().data, installed: false } }
|
|
163
|
+
await draw()
|
|
164
|
+
expect(host.textContent).toContain('a connection to it is still saved here')
|
|
165
|
+
expect(host.textContent).toContain('Disconnect API')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('says only that Substrate isn’t installed when nothing is saved here', async () => {
|
|
169
|
+
state.view = localView({ saved: false, settings: null })
|
|
170
|
+
state.status = { data: { ...status().data, installed: false } }
|
|
171
|
+
await draw()
|
|
172
|
+
expect(host.textContent).toContain('Agent Substrate isn’t installed on this cluster')
|
|
173
|
+
expect(host.textContent).not.toContain('Disconnect API')
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('leaves a clean, empty form after a disconnect', async () => {
|
|
177
|
+
state.put.mockImplementationOnce((_update: unknown, callbacks: any) =>
|
|
178
|
+
callbacks.onSuccess(localView({ saved: false, settings: null, revision: 'r2', access: { state: 'notConfigured' } })))
|
|
179
|
+
await click('Disconnect API')
|
|
180
|
+
await click('Disconnect')
|
|
181
|
+
expect(input('~/ate.token').value).toBe('')
|
|
182
|
+
expect(state.dirty).toHaveBeenLastCalledWith(false)
|
|
183
|
+
expect(host.textContent).toContain('Disconnected.')
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('resends the same draft, target and revision with explicit destination consent', async () => {
|
|
187
|
+
await type('api.example.com:443', 'new.example.com:443')
|
|
188
|
+
state.put.mockImplementationOnce((_update: unknown, callbacks: any) => callbacks.onError({ code: 'confirmDestination', message: 'The saved credential would go to a changed address: endpoint 127.0.0.1:18443 → new.example.com:443.' }))
|
|
189
|
+
await click('Save changes')
|
|
190
|
+
const original = state.put.mock.calls[0][0]
|
|
191
|
+
expect(original.confirmDestination).toBeUndefined()
|
|
192
|
+
await click('Send and save')
|
|
193
|
+
expect(state.put.mock.calls[1][0]).toEqual({ ...original, confirmDestination: true })
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('the managed Substrate summary', () => {
|
|
198
|
+
it('refreshes changed access only while the managed settings are active', async () => {
|
|
199
|
+
state.view = {
|
|
200
|
+
view: 'managed', sharedPrincipal: 'system:serviceaccount:ate-system:ate-client', access: { state: 'connecting' },
|
|
201
|
+
managed: { enabled: true, readsAs: 'eachUser', endpoint: 'api.ate-system.svc:443', serverName: 'api.ate-system.svc', trust: 'clusterTrustBundle', helm: { api: 'substrate.api.enabled', endpoint: '', serverName: '', ca: '', atespaces: '' } },
|
|
202
|
+
}
|
|
203
|
+
state.status = status({ state: 'connected' })
|
|
204
|
+
await draw(false)
|
|
205
|
+
expect(state.refetch).not.toHaveBeenCalled()
|
|
206
|
+
await draw()
|
|
207
|
+
expect(state.refetch).toHaveBeenCalledOnce()
|
|
208
|
+
expect(host.textContent).toContain('Connected')
|
|
209
|
+
})
|
|
210
|
+
})
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { SubstrateSettings } from './SubstrateSettings'
|
|
5
|
+
import { apiDisabledTier, connection, managedConnection, mintDeniedTier, sharedTier, status } from '../substrate/substrate.fixtures'
|
|
6
|
+
|
|
7
|
+
const state = vi.hoisted(() => ({
|
|
8
|
+
connection: undefined as unknown,
|
|
9
|
+
status: undefined as unknown,
|
|
10
|
+
upgrade: false,
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
vi.mock('../../api/client', async (importOriginal) => ({
|
|
14
|
+
...(await importOriginal<typeof import('../../api/client')>()),
|
|
15
|
+
usePrometheusStatus: () => ({ data: { connected: true } }),
|
|
16
|
+
}))
|
|
17
|
+
vi.mock('../../api/substrateWorkspace', async (importOriginal) => ({
|
|
18
|
+
...(await importOriginal<typeof import('../../api/substrateWorkspace')>()),
|
|
19
|
+
useSubstrateConnection: () => ({ data: state.connection, isError: false, upgrade: state.upgrade, blockedReason: state.upgrade ? 'Agent Substrate needs a newer Radar on this cluster.' : undefined }),
|
|
20
|
+
useSubstrateStatus: () => ({ data: state.status, isError: false, upgrade: false }),
|
|
21
|
+
useUpdateSubstrateConnection: () => ({ mutate: vi.fn(), reset: vi.fn(), isPending: false, error: null }),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
const text = (html: string) => html.replace(/'/g, "'").replace(/"/g, '"').replace(/&/g, '&')
|
|
25
|
+
|
|
26
|
+
// Status polls the same access the view was read with.
|
|
27
|
+
function render(conn: { access?: unknown }, over: Parameters<typeof status>[0] = {}) {
|
|
28
|
+
state.connection = conn
|
|
29
|
+
state.status = status({ apiTier: conn.access as never, ...over })
|
|
30
|
+
return text(renderToStaticMarkup(
|
|
31
|
+
<MemoryRouter>
|
|
32
|
+
<SubstrateSettings active onDirtyChange={() => {}} onBusyChange={() => {}} />
|
|
33
|
+
</MemoryRouter>,
|
|
34
|
+
))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('Settings → Agent Substrate on a local Radar', () => {
|
|
38
|
+
it('leads with who Radar reads as, recommends a token file, and saves only after an edit', () => {
|
|
39
|
+
const html = render(connection())
|
|
40
|
+
expect(html).toContain('Who Radar reads Substrate as')
|
|
41
|
+
expect(html).toContain('A token file')
|
|
42
|
+
expect(html).toContain('Recommended')
|
|
43
|
+
expect(html).toContain('Radar saves only the path, and never sends the token to the browser.')
|
|
44
|
+
expect(html).toContain('Substrate’s shared client')
|
|
45
|
+
expect(html).toContain('This identity may be a global owner')
|
|
46
|
+
expect(html).toContain('Radar found Service ')
|
|
47
|
+
expect(html).toContain('Advanced: API server address, TLS and atespaces')
|
|
48
|
+
// The fallback atespaces are never offered as a limit on access.
|
|
49
|
+
expect(html).toContain('These names don’t limit what it can read.')
|
|
50
|
+
expect(html.indexOf('Who Radar reads Substrate as')).toBeLessThan(html.indexOf('Advanced: API server address'))
|
|
51
|
+
// Nothing edited: nothing to save, and nothing saved to disconnect.
|
|
52
|
+
expect(html).toMatch(/<button type="button" disabled=""[^>]*>Save changes<\/button>/)
|
|
53
|
+
expect(html).not.toContain('Disconnect API')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('offers Disconnect apart from saving, in the destructive tone, once a connection is saved', async () => {
|
|
57
|
+
const { toneTextClass } = await import('@skyhook-io/k8s-ui')
|
|
58
|
+
const html = render(connection({ saved: true, settings: { identity: 'tokenFile', tokenFile: '/Users/me/.radar/viewer.token', caFile: '/Users/me/.radar/a-long-ca-bundle.pem' } }))
|
|
59
|
+
const at = html.indexOf('>Disconnect API</button>')
|
|
60
|
+
expect(at).toBeGreaterThan(html.indexOf('Save changes'))
|
|
61
|
+
expect(html.slice(html.lastIndexOf('<button', at), at)).toContain(toneTextClass('unhealthy'))
|
|
62
|
+
// A long path is inspectable whole, on hover.
|
|
63
|
+
expect(html).toContain('title="/Users/me/.radar/a-long-ca-bundle.pem"')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('unfolds the shared identity’s warning once that identity is chosen', () => {
|
|
67
|
+
const html = render(connection({ saved: true, settings: { identity: 'shared' } }))
|
|
68
|
+
const at = html.indexOf('This identity may be a global owner')
|
|
69
|
+
const fold = html.lastIndexOf('<div class="relative overflow-hidden"', at)
|
|
70
|
+
expect(html.slice(fold, at)).not.toContain('inert')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('asks to review a connection saved for another cluster before using it here', () => {
|
|
74
|
+
const html = render(connection({ saved: true, targetChanged: true, settings: { identity: 'shared' }, access: { state: 'failed', code: 'targetChanged' } }))
|
|
75
|
+
expect(html).toContain('Saved for another cluster')
|
|
76
|
+
expect(html).toContain('>Use it for this cluster</button>')
|
|
77
|
+
expect(html).toContain('Disconnect API instead')
|
|
78
|
+
expect(html).toMatch(/<fieldset disabled=""/)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('says when Substrate isn’t installed instead of offering a form', () => {
|
|
82
|
+
const html = render(connection(), { installed: false })
|
|
83
|
+
expect(html).toContain('Agent Substrate isn’t installed on this cluster')
|
|
84
|
+
expect(html).not.toContain('Who Radar reads Substrate as')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('says an older Radar can’t serve these settings', () => {
|
|
88
|
+
state.upgrade = true
|
|
89
|
+
const html = render(connection())
|
|
90
|
+
state.upgrade = false
|
|
91
|
+
expect(html).toContain('needs a newer Radar')
|
|
92
|
+
expect(html).not.toContain('Who Radar reads Substrate as')
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe('Settings → Agent Substrate on an in-cluster Radar or Radar Hub', () => {
|
|
97
|
+
it('shows how the installation reads Substrate as text, never as inputs, with the Helm values that set it', () => {
|
|
98
|
+
const html = render(managedConnection(), { canConfigure: false })
|
|
99
|
+
expect(html).toContain('Your access')
|
|
100
|
+
expect(html).toContain('Connected')
|
|
101
|
+
expect(html).toContain('For each signed-in person, with a token created with their own Kubernetes access.')
|
|
102
|
+
expect(html).toContain('api.ate-system.svc:443')
|
|
103
|
+
expect(html).toContain('The cluster’s trust bundle for Substrate')
|
|
104
|
+
expect(html).toContain('Managed by your operator')
|
|
105
|
+
expect(html).toContain('substrate.api')
|
|
106
|
+
expect(html).not.toContain('<input')
|
|
107
|
+
expect(html).not.toContain('Who Radar reads Substrate as')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('tells a person whose access can’t mint the token what to ask for', () => {
|
|
111
|
+
const html = render(managedConnection({ access: mintDeniedTier }), { canConfigure: false })
|
|
112
|
+
expect(html).toContain('Couldn’t create the shared identity’s token')
|
|
113
|
+
expect(html).toContain('kubectl auth can-i create serviceaccounts/ate-client --subresource=token -n ate-system')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('says the operator turned the API off, or that a Radar without sign-in can’t read it', () => {
|
|
117
|
+
const off = render(managedConnection({ access: apiDisabledTier, managed: { ...managedConnection().managed, enabled: false, readsAs: 'none' } }), { canConfigure: false })
|
|
118
|
+
expect(off).toMatch(/Reads Substrate’s API<\/dt><dd[^>]*>No/)
|
|
119
|
+
expect(off).toContain('Turned off for this Radar')
|
|
120
|
+
expect(off).not.toContain('For each signed-in person')
|
|
121
|
+
const noSignIn = render(managedConnection({ access: sharedTier, managed: { ...managedConnection().managed, enabled: false, readsAs: 'none' } }), { canConfigure: false })
|
|
122
|
+
expect(noSignIn).toContain('Needs sign-in')
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('names fallback atespaces only to a connected reader', () => {
|
|
126
|
+
const connected = render(managedConnection({ managed: { ...managedConnection().managed, atespaces: ['research'] } }), { canConfigure: false })
|
|
127
|
+
expect(connected).toContain('research')
|
|
128
|
+
const refused = render(managedConnection({ access: mintDeniedTier }), { canConfigure: false })
|
|
129
|
+
expect(refused).not.toMatch(/Atespaces<\/span>/)
|
|
130
|
+
})
|
|
131
|
+
})
|