@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.
Files changed (228) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +49 -13
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +151 -27
  9. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/poll.ts +78 -0
  15. package/src/api/prometheusCharts.ts +5 -0
  16. package/src/api/radarFeatures.test.ts +9 -0
  17. package/src/api/radarFeatures.ts +16 -0
  18. package/src/api/substrateWorkspace.test.ts +72 -0
  19. package/src/api/substrateWorkspace.ts +1394 -0
  20. package/src/api/vulnerabilities.ts +207 -9
  21. package/src/api/workloadSource.test.tsx +315 -0
  22. package/src/api/workloadSource.ts +128 -12
  23. package/src/components/CloudConnectFlow.tsx +46 -7
  24. package/src/components/CloudFunnelButton.test.tsx +193 -7
  25. package/src/components/CloudFunnelButton.tsx +128 -32
  26. package/src/components/SelfManagedStart.tsx +12 -2
  27. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  28. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  29. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  30. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  31. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  32. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  33. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  34. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  35. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  36. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  37. package/src/components/agentsandbox/data.ts +135 -0
  38. package/src/components/agentsandbox/host.test.ts +27 -0
  39. package/src/components/agentsandbox/host.tsx +85 -0
  40. package/src/components/agentsandbox/labels.test.ts +42 -0
  41. package/src/components/agentsandbox/labels.ts +146 -0
  42. package/src/components/agentsandbox/listFilters.ts +85 -0
  43. package/src/components/agentsandbox/lists.ts +52 -0
  44. package/src/components/agentsandbox/routes.ts +23 -0
  45. package/src/components/agentsandbox/shared.tsx +321 -0
  46. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  47. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  48. package/src/components/agentsandbox/workspace.tsx +258 -0
  49. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  50. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  51. package/src/components/applications/ApplicationsView.tsx +156 -3
  52. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  53. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  54. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  55. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  56. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  57. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  58. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  59. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  60. package/src/components/cloudHints/cloudHints.ts +131 -0
  61. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  62. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  63. package/src/components/cloudHints/cloudLinks.ts +31 -0
  64. package/src/components/cloudHints/hintStorage.ts +28 -0
  65. package/src/components/cnpg/CNPGView.tsx +4 -7
  66. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  67. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  68. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  69. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  70. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  71. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  72. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  73. package/src/components/helm/HelmView.tsx +4 -3
  74. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  75. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  76. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  77. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  78. package/src/components/home/HomeAgentBlock.tsx +2 -0
  79. package/src/components/home/HomeView.tsx +3 -3
  80. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  81. package/src/components/home/MCPSetupDialog.tsx +6 -2
  82. package/src/components/home/McpCloudLine.test.tsx +162 -0
  83. package/src/components/home/McpCloudLine.tsx +95 -0
  84. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  85. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  86. package/src/components/home/mcpToolCatalog.ts +4 -4
  87. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  88. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  89. package/src/components/issues/IssuesPane.tsx +181 -23
  90. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  91. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  92. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  93. package/src/components/issues/sinceLastVisit.ts +439 -0
  94. package/src/components/issues/uncheckedSources.test.ts +8 -0
  95. package/src/components/issues/uncheckedSources.ts +3 -0
  96. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  97. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  98. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  99. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  100. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  101. package/src/components/kagent/KagentLists.tsx +412 -0
  102. package/src/components/kagent/KagentOverview.tsx +234 -0
  103. package/src/components/kagent/KagentPages.tsx +690 -0
  104. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  105. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  106. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  107. package/src/components/kagent/KagentView.tsx +109 -0
  108. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  109. package/src/components/kagent/host.tsx +144 -0
  110. package/src/components/kagent/routes.ts +31 -0
  111. package/src/components/kagent/shared.tsx +336 -0
  112. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  113. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  114. package/src/components/kagent/workspace.fixtures.ts +108 -0
  115. package/src/components/kagent/workspaceRoute.ts +18 -0
  116. package/src/components/nudges/activeNudges.test.ts +39 -0
  117. package/src/components/nudges/activeNudges.ts +76 -0
  118. package/src/components/poll/OssPoll.tsx +871 -0
  119. package/src/components/poll/mount.test.ts +12 -0
  120. package/src/components/poll/pollCloud.test.ts +23 -0
  121. package/src/components/poll/pollCloud.ts +6 -0
  122. package/src/components/poll/pollDefinition.ts +93 -0
  123. package/src/components/poll/pollFlow.test.ts +140 -0
  124. package/src/components/poll/pollFlow.ts +137 -0
  125. package/src/components/poll/pollSender.test.ts +137 -0
  126. package/src/components/poll/pollSender.ts +76 -0
  127. package/src/components/poll/pollStorage.test.ts +53 -0
  128. package/src/components/poll/pollStorage.ts +77 -0
  129. package/src/components/poll/round.json +350 -0
  130. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  131. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  132. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  133. package/src/components/resource/PrometheusCharts.tsx +10 -1
  134. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  135. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  136. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  137. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  138. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  139. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  140. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  141. package/src/components/resources/ResourcesView.tsx +24 -11
  142. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  143. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  144. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  145. package/src/components/settings/SettingsDialog.tsx +84 -16
  146. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  147. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  148. package/src/components/settings/SubstrateSettings.tsx +544 -0
  149. package/src/components/settings/settings-state.test.ts +21 -3
  150. package/src/components/settings/settings-state.ts +13 -3
  151. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  152. package/src/components/share/ShareLinkButton.tsx +391 -0
  153. package/src/components/share/openShareInCloud.test.ts +29 -0
  154. package/src/components/share/openShareInCloud.ts +10 -0
  155. package/src/components/share/shareLink.test.ts +129 -0
  156. package/src/components/share/shareLink.ts +175 -0
  157. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  158. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  159. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  160. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  161. package/src/components/substrate/SubstrateActors.tsx +612 -0
  162. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  163. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  164. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  165. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  166. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  167. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  168. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  169. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  170. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  171. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  172. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  173. package/src/components/substrate/SubstrateView.tsx +173 -0
  174. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  175. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  176. package/src/components/substrate/attention.ts +81 -0
  177. package/src/components/substrate/contextPin.tsx +69 -0
  178. package/src/components/substrate/host.tsx +83 -0
  179. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  180. package/src/components/substrate/readings.test.ts +484 -0
  181. package/src/components/substrate/readings.ts +997 -0
  182. package/src/components/substrate/routes.ts +103 -0
  183. package/src/components/substrate/shared.tsx +426 -0
  184. package/src/components/substrate/substrate.fixtures.ts +325 -0
  185. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  186. package/src/components/substrate/workspaceRoute.ts +23 -0
  187. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  188. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  189. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  190. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  191. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  192. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  193. package/src/components/traffic/TrafficGraph.tsx +17 -14
  194. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  195. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  196. package/src/components/traffic/TrafficView.tsx +26 -56
  197. package/src/components/traffic/trafficFilters.test.ts +61 -1
  198. package/src/components/traffic/trafficFilters.ts +68 -8
  199. package/src/components/ui/UpdateNotification.tsx +2 -0
  200. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  201. package/src/components/velero/VeleroOverview.tsx +2 -2
  202. package/src/components/velero/VeleroView.tsx +3 -6
  203. package/src/components/vulnerabilities/columns.tsx +132 -0
  204. package/src/components/vulnerabilities/filters.tsx +317 -0
  205. package/src/components/vulnerabilities/owner.test.ts +54 -0
  206. package/src/components/vulnerabilities/owner.tsx +163 -0
  207. package/src/components/vulnerabilities/parts.test.ts +126 -12
  208. package/src/components/vulnerabilities/parts.tsx +612 -52
  209. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  210. package/src/components/vulnerabilities/traffic.tsx +40 -0
  211. package/src/components/whats-new/WhatsNew.tsx +2 -0
  212. package/src/components/whats-new/releaseNotes.ts +75 -1
  213. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  214. package/src/components/workload/WorkloadView.tsx +52 -13
  215. package/src/components/workspace/layout.tsx +13 -7
  216. package/src/components/workspace/sidebar.test.ts +48 -0
  217. package/src/components/workspace/sidebar.ts +73 -3
  218. package/src/components/workspace/table.ts +2 -1
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/integrations/resourceHost.ts +12 -6
  222. package/src/integrations/resourceHosts.test.tsx +27 -1
  223. package/src/integrations/resourceHosts.tsx +15 -7
  224. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  225. package/src/integrations/sidebarWorkspaces.ts +41 -0
  226. package/src/integrations/workspaceRoute.ts +1 -1
  227. package/src/integrations/workspaceRoutes.ts +7 -1
  228. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,544 @@
1
+ import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from 'react'
2
+ import { clsx } from 'clsx'
3
+ import { CheckCircle2, CircleHelp, XCircle } from 'lucide-react'
4
+ import { AlertBanner, Badge, Collapse, CollapseChevron, ConfirmDialog, Input, toneTextClass } from '@skyhook-io/k8s-ui'
5
+ import {
6
+ substrateErrorCode,
7
+ useSubstrateConnection,
8
+ useSubstrateStatus,
9
+ useUpdateSubstrateConnection,
10
+ type SubstrateAPITier,
11
+ type SubstrateConnection,
12
+ type SubstrateConnectionUpdate,
13
+ type SubstrateLocalConnection,
14
+ type SubstrateManagedConnectionView,
15
+ type SubstrateSettings as SavedSettings,
16
+ type SubstrateStatus,
17
+ } from '../../api/substrateWorkspace'
18
+ import { tierReading } from '../substrate/readings'
19
+ import { CommandChip, Term } from '../substrate/shared'
20
+ import { FormSaveActions, type FormFeedback } from './FormSaveActions'
21
+ import { OperatorManagedNotice } from './OperatorManagedNotice'
22
+
23
+ const INPUT = 'block w-full min-w-0 rounded-md border border-theme-border bg-theme-elevated px-3 py-1.5 font-mono text-sm text-theme-text-primary placeholder:text-theme-text-tertiary focus:border-skyhook-500 focus:outline-none'
24
+ const SHARED_PRINCIPAL_FALLBACK = 'system:serviceaccount:ate-system:ate-client'
25
+ const AUTHZ_DOC = 'https://github.com/agent-substrate/substrate/blob/main/docs/guides/authorization.md#managing-access'
26
+
27
+ export interface SubstrateDraft {
28
+ identity: 'shared' | 'tokenFile'
29
+ tokenFile: string
30
+ /** Comma-separated; for a token that may read some atespaces but not list them. */
31
+ atespaces: string
32
+ endpoint: string
33
+ caFile: string
34
+ serverName: string
35
+ }
36
+
37
+ export function draftOf(settings: SavedSettings | null | undefined): SubstrateDraft {
38
+ return {
39
+ identity: settings?.identity ?? 'tokenFile',
40
+ tokenFile: settings?.tokenFile ?? '',
41
+ atespaces: settings?.atespaces?.join(', ') ?? '',
42
+ endpoint: settings?.endpoint ?? '',
43
+ caFile: settings?.caFile ?? '',
44
+ serverName: settings?.serverName ?? '',
45
+ }
46
+ }
47
+
48
+ /** The settings a draft saves; empty optional fields are left out. */
49
+ export function settingsOf(d: SubstrateDraft): SavedSettings {
50
+ const opt = (v: string) => (v.trim() ? v.trim() : undefined)
51
+ const atespaces = d.atespaces.split(',').map((a) => a.trim()).filter(Boolean)
52
+ return {
53
+ identity: d.identity,
54
+ tokenFile: d.identity === 'tokenFile' ? opt(d.tokenFile) : undefined,
55
+ atespaces: atespaces.length ? atespaces : undefined,
56
+ endpoint: opt(d.endpoint),
57
+ caFile: opt(d.caFile),
58
+ serverName: opt(d.serverName),
59
+ }
60
+ }
61
+
62
+ /**
63
+ * The update a draft saves. `target` and `revision` are the ones the
64
+ * connection view returned, so a save for a context that has since moved, or
65
+ * over a newer save from another Radar, is refused rather than applied.
66
+ */
67
+ export function connectionUpdate(d: SubstrateDraft, view: Pick<SubstrateLocalConnection, 'target' | 'revision'>, confirmDestination = false): SubstrateConnectionUpdate {
68
+ return { target: view.target, revision: view.revision, settings: settingsOf(d), ...(confirmDestination ? { confirmDestination: true } : {}) }
69
+ }
70
+
71
+ function sameDraft(a: SubstrateDraft, b: SubstrateDraft): boolean {
72
+ return JSON.stringify(settingsOf(a)) === JSON.stringify(settingsOf(b))
73
+ }
74
+
75
+ /**
76
+ * Settings → Agent Substrate. A local private Radar edits this context's saved
77
+ * connection here; an in-cluster Radar or Radar Hub shows how the installation
78
+ * reads Substrate and this person's own access, read-only.
79
+ *
80
+ * While the local form has edits, it stays on screen with the connection it was
81
+ * read for, even as the cluster changes or the next view loads: the dialog
82
+ * freezes it, and only "Discard draft and load current cluster" (a new
83
+ * reloadKey upstream) replaces it.
84
+ */
85
+ export function SubstrateSettings({ active, onDirtyChange, onBusyChange }: {
86
+ active: boolean
87
+ onDirtyChange: (dirty: boolean) => void
88
+ onBusyChange: (busy: boolean) => void
89
+ }) {
90
+ // A first read takes seconds: poll faster while it runs, so Connected shows when it lands.
91
+ const [connecting, setConnecting] = useState(false)
92
+ const status = useSubstrateStatus(active, connecting ? { pollMs: 2_000 } : {})
93
+ const connection = useSubstrateConnection(active)
94
+ const [dirty, setDirty] = useState(false)
95
+ const reportDirty = useCallback((d: boolean) => { setDirty(d); onDirtyChange(d) }, [onDirtyChange])
96
+ const latest = connection.data
97
+ const [lastLocal, setLastLocal] = useState<SubstrateLocalConnection | undefined>(latest?.view === 'local' ? latest : undefined)
98
+ useEffect(() => { if (latest?.view === 'local') setLastLocal(latest) }, [latest])
99
+ // The access row reads the polled status; the managed summary refetches when it moves.
100
+ const tier = status.data?.apiTier
101
+ useEffect(() => setConnecting(tier?.state === 'connecting'), [tier?.state])
102
+ const refetch = connection.refetch
103
+ useEffect(() => {
104
+ if (active && latest?.view === 'managed' && tier && (tier.state !== latest.access.state || tier.code !== latest.access.code)) void refetch()
105
+ }, [active, tier, latest, refetch])
106
+
107
+ if (connection.upgrade || status.upgrade) {
108
+ return <p className="text-sm text-theme-text-secondary">{connection.blockedReason ?? status.blockedReason ?? 'Agent Substrate settings need a newer Radar on this cluster.'}</p>
109
+ }
110
+ const keepForm = dirty && lastLocal
111
+ if (connection.isError && !keepForm) {
112
+ return <p role="alert" className="text-sm text-theme-text-secondary">Radar couldn’t read how it connects to Substrate: {connection.error instanceof Error ? connection.error.message : 'unknown error'}.</p>
113
+ }
114
+ if (!latest && !keepForm) {
115
+ return <p className="text-sm text-theme-text-secondary">Loading…</p>
116
+ }
117
+ const notInstalled = status.data?.installed === false
118
+ // A connection saved before Substrate went away stays editable, so it can be disconnected.
119
+ const savedHere = latest?.view === 'local' && latest.saved
120
+ if (!keepForm && notInstalled && !savedHere) {
121
+ return (
122
+ <p className="text-sm text-theme-text-secondary">
123
+ Agent Substrate isn’t installed on this cluster: it doesn’t serve the WorkerPool kind (ate.dev). Radar reads Substrate’s API once it is.
124
+ </p>
125
+ )
126
+ }
127
+ const statusError = status.isError ? (
128
+ <p role="alert" className="text-xs text-theme-text-secondary">
129
+ Radar couldn’t check Substrate’s status on this cluster: {status.error instanceof Error ? status.error.message : 'unknown error'}.
130
+ </p>
131
+ ) : null
132
+ return (
133
+ <div className="space-y-4">
134
+ <p className="text-sm text-theme-text-secondary">
135
+ Substrate keeps actors, templates and workers in its own API, not Kubernetes, and checks its own roles there. Radar reads them, read-only, as the identity below. Pools, worker Pods and Prometheus readings show either way.
136
+ </p>
137
+ {statusError}
138
+ {notInstalled && savedHere && (
139
+ <p className="text-sm text-theme-text-secondary">
140
+ Agent Substrate isn’t installed on this cluster, but a connection to it is still saved here. Disconnect it to remove it.
141
+ </p>
142
+ )}
143
+ {keepForm || latest?.view === 'local' ? (
144
+ <LocalSubstrateForm
145
+ initial={(keepForm ? lastLocal : latest) as SubstrateLocalConnection}
146
+ latest={latest?.view === 'local' ? latest : undefined}
147
+ tier={tier}
148
+ status={status.data}
149
+ onDirtyChange={reportDirty}
150
+ onBusyChange={onBusyChange}
151
+ />
152
+ ) : latest ? (
153
+ <ManagedSubstrateSummary view={latest} tier={tier} />
154
+ ) : null}
155
+ </div>
156
+ )
157
+ }
158
+
159
+ /** This caller's own access in one row: the state, and what to do when it isn't connected. */
160
+ function AccessRow({ tier, label = 'Status' }: { tier: SubstrateAPITier; label?: string }) {
161
+ const r = tierReading(tier, { inSettings: true })
162
+ const connected = tier.state === 'connected'
163
+ return (
164
+ <div className="rounded-md border border-theme-border bg-theme-elevated/40 px-3 py-2 text-sm">
165
+ <div className="flex flex-wrap items-baseline gap-x-2">
166
+ <span className="text-xs font-medium text-theme-text-tertiary">{label}</span>
167
+ <span className={clsx('font-medium', connected ? toneTextClass('healthy') : r.tone === 'unhealthy' ? toneTextClass('unhealthy') : 'text-theme-text-primary')}>
168
+ {connected ? 'Connected' : r.title}
169
+ </span>
170
+ {connected && tier.endpoint && <span className="font-mono text-xs text-theme-text-secondary">{tier.endpoint}</span>}
171
+ </div>
172
+ {!connected && r.detail && <p className="mt-1 text-xs text-theme-text-secondary">{r.detail}</p>}
173
+ {!connected && r.nextStep && (
174
+ <p className="mt-1 text-xs text-theme-text-primary">
175
+ <span className="font-medium">Next step: </span>
176
+ {r.nextStep}
177
+ {r.command && <CommandChip command={r.command} />}
178
+ </p>
179
+ )}
180
+ </div>
181
+ )
182
+ }
183
+
184
+ function Row({ label, children }: { label: ReactNode; children: ReactNode }) {
185
+ return (
186
+ <div className="grid grid-cols-[minmax(8rem,auto)_1fr] gap-x-4 py-1.5 text-sm">
187
+ <dt className="text-theme-text-secondary">{label}</dt>
188
+ <dd className="min-w-0 break-words text-theme-text-primary">{children}</dd>
189
+ </div>
190
+ )
191
+ }
192
+
193
+ /**
194
+ * How an in-cluster Radar or Radar Hub reads Substrate: set by the operator in
195
+ * Helm values, so shown as text, never as disabled inputs.
196
+ */
197
+ function ManagedSubstrateSummary({ view, tier }: { view: SubstrateManagedConnectionView; tier?: SubstrateAPITier }) {
198
+ const m = view.managed
199
+ const access = tier ?? view.access
200
+ return (
201
+ <div className="space-y-4">
202
+ <AccessRow tier={access} label="Your access" />
203
+ <dl className="divide-y divide-theme-border rounded-md border border-theme-border px-3">
204
+ <Row label="Reads Substrate’s API">
205
+ {m.enabled ? 'Yes' : 'No'}
206
+ {!m.enabled && access.reason && <span className="block text-xs text-theme-text-secondary">{access.reason}</span>}
207
+ </Row>
208
+ {m.enabled && (
209
+ <Row label="As">
210
+ <span className="font-mono text-xs">{view.sharedPrincipal || SHARED_PRINCIPAL_FALLBACK}</span>
211
+ <span className="block text-xs text-theme-text-secondary">
212
+ For each signed-in person, with a token created with their own Kubernetes access. Someone whose access can’t create that token sees no actors. On default installs this identity is a Substrate global owner; Radar only reads.
213
+ </span>
214
+ </Row>
215
+ )}
216
+ <Row label="API server"><span className="font-mono text-xs">{m.endpoint}</span></Row>
217
+ <Row label="TLS server name"><span className="font-mono text-xs">{m.serverName}</span></Row>
218
+ <Row label="Certificate checked against">{m.trust === 'caFile' ? 'A CA your operator provided' : 'The cluster’s trust bundle for Substrate'}</Row>
219
+ {m.atespaces && m.atespaces.length > 0 && (
220
+ <Row label={<Term term="atespace">Atespaces</Term>}>
221
+ {m.atespaces.join(', ')}
222
+ <span className="block text-xs text-theme-text-secondary">Read when the identity can’t list atespaces. They don’t limit what it can read.</span>
223
+ </Row>
224
+ )}
225
+ </dl>
226
+ <OperatorManagedNotice helmValue="substrate.api" />
227
+ </div>
228
+ )
229
+ }
230
+
231
+ function ServiceRow({ status, endpoint }: { status?: SubstrateStatus; endpoint?: string }) {
232
+ if (!status) {
233
+ return endpoint ? <p className="text-xs text-theme-text-secondary">Radar dials <span className="font-mono">{endpoint}</span>, set under Advanced.</p> : null
234
+ }
235
+ const { namespace, name, port, found } = status.apiService
236
+ const service = <span className="font-mono">{namespace}/{name}</span>
237
+ const [mark, text] = endpoint
238
+ ? [<CheckCircle2 key="m" className={clsx('h-4 w-4', toneTextClass('healthy'))} />, <>Radar dials <span className="font-mono">{endpoint}</span>, set under Advanced, instead of port-forwarding to Service {service}.</>]
239
+ : found === true
240
+ ? [<CheckCircle2 key="m" className={clsx('h-4 w-4', toneTextClass('healthy'))} />, <>Radar found Service {service}, port {port}, and reaches it by port-forward, as kubectl ate does.</>]
241
+ : found === false
242
+ ? [<XCircle key="m" className={clsx('h-4 w-4', toneTextClass('degraded'))} />, <>There is no Service {service}. If Substrate’s API server runs elsewhere, set its address under Advanced.</>]
243
+ : [<CircleHelp key="m" className="h-4 w-4 text-theme-text-tertiary" />, <>Radar reaches Service {service}, port {port}, by port-forward. You can’t read Services in {namespace}, so Radar can’t check it is there.</>]
244
+ return (
245
+ <div className="flex gap-2 text-xs text-theme-text-secondary">
246
+ <span className="mt-0.5 shrink-0">{mark}</span>
247
+ <span className="min-w-0">{text}</span>
248
+ </div>
249
+ )
250
+ }
251
+
252
+ /** A path input: shown whole on hover, and scrolled to its end, the part that names the file. */
253
+ function PathInput({ id, value, onChange, placeholder }: { id: string; value: string; onChange: (v: string) => void; placeholder: string }) {
254
+ return (
255
+ <Input
256
+ id={id}
257
+ className={INPUT}
258
+ value={value}
259
+ title={value || undefined}
260
+ onChange={(e) => onChange(e.target.value)}
261
+ onBlur={(e) => { e.currentTarget.scrollLeft = e.currentTarget.scrollWidth }}
262
+ placeholder={placeholder}
263
+ spellCheck={false}
264
+ />
265
+ )
266
+ }
267
+
268
+ function Field({ label, hint, id, children }: { label: ReactNode; hint?: string; id: string; children: ReactNode }) {
269
+ return (
270
+ <div>
271
+ <label htmlFor={id} className="block text-xs font-medium text-theme-text-secondary">{label}</label>
272
+ <div className="mt-1">{children}</div>
273
+ {hint && <p className="mt-1 text-xs text-theme-text-tertiary">{hint}</p>}
274
+ </div>
275
+ )
276
+ }
277
+
278
+ /** Why a save didn't take. The server checks the connection before saving, so a failure changed nothing. */
279
+ function saveError(error: unknown): string | undefined {
280
+ if (!error) return undefined
281
+ const code = substrateErrorCode(error)
282
+ if (code === 'targetChanged') return 'Not saved: the cluster changed since you opened this. Review it again for the cluster Radar points at now.'
283
+ if (code === 'conflict') return 'Not saved: the connection was changed elsewhere (another Radar, or the Desktop app) since you opened it. Discard to load it, then edit again.'
284
+ return `Not saved: ${error instanceof Error ? error.message : 'unknown error'}. Nothing changed.`
285
+ }
286
+
287
+ function LocalSubstrateForm({ initial, latest, tier, status, onDirtyChange, onBusyChange }: {
288
+ /** The connection the form is read for at mount. */
289
+ initial: SubstrateLocalConnection
290
+ /** The newest view of the current context; absent while it loads. */
291
+ latest?: SubstrateLocalConnection
292
+ /** The polled access tier, newer than any view's. */
293
+ tier?: SubstrateAPITier
294
+ status?: SubstrateStatus
295
+ onDirtyChange: (dirty: boolean) => void
296
+ onBusyChange: (busy: boolean) => void
297
+ }) {
298
+ const id = useId()
299
+ // The view the draft was started from: its settings, target and revision
300
+ // travel together, so a save is checked against exactly what was reviewed.
301
+ const [base, setBase] = useState(initial)
302
+ const saved = draftOf(base.saved ? base.settings : undefined)
303
+ const [draft, setDraft] = useState<SubstrateDraft>(saved)
304
+ const [advanced, setAdvanced] = useState(() => !!(saved.endpoint || saved.caFile || saved.serverName))
305
+ const [confirm, setConfirm] = useState<'disconnect' | 'destination' | null>(null)
306
+ const [destinationReason, setDestinationReason] = useState('')
307
+ const [feedback, setFeedback] = useState<FormFeedback | undefined>()
308
+ const save = useUpdateSubstrateConnection()
309
+ const dirty = !sameDraft(draft, saved) && !base.targetChanged
310
+ const busy = save.isPending
311
+ const view = base
312
+ const adopt = useCallback((next: SubstrateLocalConnection) => {
313
+ setBase(next)
314
+ setDraft(draftOf(next.saved ? next.settings : undefined))
315
+ }, [])
316
+ // The revision a save just replaced: the query may still hold it for a moment, and it is not newer.
317
+ // Once the query shows anything else, the guard ends: revisions are content hashes, so that same
318
+ // revision can legitimately come back later.
319
+ const replaced = useRef<string | null>(null)
320
+ if (replaced.current && latest && latest.revision !== replaced.current) replaced.current = null
321
+ // A clean form follows the newest view; an edited one keeps its own until saved or discarded. The
322
+ // whole target counts, generations included: the server refuses a save for any other.
323
+ const moved = !!latest && latest.revision !== replaced.current &&
324
+ (latest.revision !== base.revision || JSON.stringify(latest.target) !== JSON.stringify(base.target))
325
+ useEffect(() => { if (moved && !dirty && !busy && latest) adopt(latest) }, [moved, dirty, busy, latest, adopt])
326
+ useEffect(() => onDirtyChange(dirty), [dirty, onDirtyChange])
327
+ useEffect(() => onBusyChange(busy), [busy, onBusyChange])
328
+ // Cleared on unmount only, whatever callbacks the parent passes on the way.
329
+ const callbacks = useRef({ onDirtyChange, onBusyChange })
330
+ callbacks.current = { onDirtyChange, onBusyChange }
331
+ useEffect(() => () => { callbacks.current.onDirtyChange(false); callbacks.current.onBusyChange(false) }, [])
332
+
333
+ const edit = (patch: Partial<SubstrateDraft>) => {
334
+ setFeedback(undefined)
335
+ save.reset()
336
+ setDraft((d) => ({ ...d, ...patch }))
337
+ }
338
+ const principal = view.sharedPrincipal || SHARED_PRINCIPAL_FALLBACK
339
+ const missingToken = draft.identity === 'tokenFile' && !draft.tokenFile.trim()
340
+ const submit = (update: SubstrateConnectionUpdate, done: string) => {
341
+ setFeedback(undefined)
342
+ save.mutate(update, {
343
+ onSuccess: (next: SubstrateConnection) => {
344
+ if (next.view === 'local') {
345
+ replaced.current = base.revision
346
+ adopt(next)
347
+ }
348
+ setFeedback({ tone: 'success', message: done })
349
+ },
350
+ onError: (error) => {
351
+ if (substrateErrorCode(error) === 'confirmDestination') {
352
+ setDestinationReason(error instanceof Error ? error.message : '')
353
+ setConfirm('destination')
354
+ }
355
+ },
356
+ })
357
+ }
358
+ const saveDraft = (confirmDestination = false) => {
359
+ if (missingToken) return
360
+ submit(connectionUpdate(draft, view, confirmDestination), 'Saved. Connection checked; Substrate may still limit what this identity can read.')
361
+ }
362
+ const advancedId = `${id}-advanced`
363
+ const error = substrateErrorCode(save.error) === 'confirmDestination' ? undefined : saveError(save.error)
364
+
365
+ return (
366
+ <form onSubmit={(e) => { e.preventDefault(); if (dirty) saveDraft() }} className="space-y-4">
367
+ <AccessRow tier={tier ?? view.access} />
368
+ {moved && dirty && (
369
+ <p role="status" className="text-xs text-theme-text-secondary">
370
+ This connection changed since you started editing (another Radar, the Desktop app, or the cluster). Saving is refused until you discard your edits and review it again.
371
+ </p>
372
+ )}
373
+ {view.targetChanged && (
374
+ <AlertBanner variant="warning" title="Saved for another cluster" className="">
375
+ <div className="mt-1 space-y-2 text-xs text-theme-text-secondary">
376
+ <p>This connection was saved while context {view.target.context} pointed at another cluster, so Radar doesn’t use it here. Use it for this cluster only if the same identity and API server belong here.</p>
377
+ <div className="flex flex-wrap gap-2">
378
+ <button type="button" disabled={busy} className="btn-secondary px-3 py-1 text-xs" onClick={() => submit({ target: view.target, revision: view.revision, settings: settingsOf(saved), action: 'reconfirm' }, 'Saved for this cluster.')}>
379
+ Use it for this cluster
380
+ </button>
381
+ <button type="button" disabled={busy} className={clsx('btn-secondary px-3 py-1 text-xs', toneTextClass('unhealthy'))} onClick={() => setConfirm('disconnect')}>
382
+ Disconnect API instead
383
+ </button>
384
+ </div>
385
+ </div>
386
+ </AlertBanner>
387
+ )}
388
+ <fieldset disabled={view.targetChanged} className="space-y-2">
389
+ <legend className="mb-1 text-sm font-semibold text-theme-text-primary">Who Radar reads Substrate as</legend>
390
+ <label className="flex items-start gap-2 text-sm">
391
+ <input type="radio" name={`${id}-identity`} className="mt-1" checked={draft.identity === 'tokenFile'} onChange={() => edit({ identity: 'tokenFile' })} />
392
+ <span className="min-w-0">
393
+ <span className="font-medium text-theme-text-primary">A token file</span>{' '}
394
+ <Badge severity="neutral" size="sm">Recommended</Badge>
395
+ <span className="block text-theme-text-secondary">
396
+ A viewer grant from a Substrate owner, in a file on the machine running Radar. Radar saves only the path, and never sends the token to the browser.
397
+ </span>
398
+ </span>
399
+ </label>
400
+ <Collapse open={draft.identity === 'tokenFile'}>
401
+ <div className="space-y-3 pl-6">
402
+ <Field id={`${id}-token`} label="Token file path">
403
+ <PathInput id={`${id}-token`} value={draft.tokenFile} onChange={(v) => edit({ tokenFile: v })} placeholder="~/ate.token" />
404
+ </Field>
405
+ <TokenSetup />
406
+ </div>
407
+ </Collapse>
408
+ <label className="flex items-start gap-2 text-sm">
409
+ <input type="radio" name={`${id}-identity`} className="mt-1" checked={draft.identity === 'shared'} onChange={() => edit({ identity: 'shared' })} />
410
+ <span className="min-w-0">
411
+ <span className="font-medium text-theme-text-primary">Substrate’s shared client</span>
412
+ <span className="block text-theme-text-secondary">
413
+ The identity kubectl ate uses without <span className="font-mono text-[12.5px]">--token-file</span>. Radar creates its token with your Kubernetes access, and Substrate records the reads as it, not you:
414
+ </span>
415
+ <span className="block break-all font-mono text-[12.5px] text-theme-text-secondary">{principal}</span>
416
+ </span>
417
+ </label>
418
+ <Collapse open={draft.identity === 'shared'}>
419
+ <div className="pl-6">
420
+ <AlertBanner variant="warning" title="This identity may be a global owner" className="">
421
+ <div className="mt-1 text-xs text-theme-text-secondary">
422
+ Substrate’s installer makes it an owner of every atespace unless the operators chose other owners. Radar only reads, but anyone who can create its token has every right it has.
423
+ </div>
424
+ </AlertBanner>
425
+ </div>
426
+ </Collapse>
427
+ </fieldset>
428
+ <div className="space-y-2 border-t border-theme-border pt-3">
429
+ <ServiceRow status={status} endpoint={draft.endpoint.trim() || undefined} />
430
+ <button type="button" aria-expanded={advanced} aria-controls={advancedId} onClick={() => setAdvanced((v) => !v)} className="inline-flex items-center gap-1 text-xs font-medium text-accent-text hover:underline">
431
+ <CollapseChevron open={advanced} />
432
+ Advanced: API server address, TLS and atespaces
433
+ </button>
434
+ <Collapse open={advanced} id={advancedId}>
435
+ <fieldset disabled={view.targetChanged} className="grid gap-3 pt-1 sm:grid-cols-2">
436
+ <Field id={`${id}-endpoint`} label="Endpoint" hint="host:port. Radar dials it directly instead of port-forwarding.">
437
+ <Input id={`${id}-endpoint`} className={INPUT} value={draft.endpoint} onChange={(e) => edit({ endpoint: e.target.value })} placeholder="api.example.com:443" spellCheck={false} />
438
+ </Field>
439
+ <Field id={`${id}-sni`} label="TLS server name" hint="Defaults to api.ate-system.svc.">
440
+ <Input id={`${id}-sni`} className={INPUT} value={draft.serverName} onChange={(e) => edit({ serverName: e.target.value })} placeholder="api.ate-system.svc" spellCheck={false} />
441
+ </Field>
442
+ <div className="sm:col-span-2">
443
+ <Field id={`${id}-ca`} label="CA file" hint="PEM. Defaults to the cluster’s trust bundle for Substrate.">
444
+ <PathInput id={`${id}-ca`} value={draft.caFile} onChange={(v) => edit({ caFile: v })} placeholder="/path/to/ca.pem" />
445
+ </Field>
446
+ </div>
447
+ <div className="sm:col-span-2">
448
+ <Field id={`${id}-atespaces`} label={<><Term term="atespace">Atespaces</Term> to read if listing is denied</>} hint="Only used when the identity can’t list atespaces; the rest stay unknown. These names don’t limit what it can read.">
449
+ <Input id={`${id}-atespaces`} className={INPUT} value={draft.atespaces} onChange={(e) => edit({ atespaces: e.target.value })} placeholder="research, support-bots" spellCheck={false} />
450
+ </Field>
451
+ </div>
452
+ </fieldset>
453
+ </Collapse>
454
+ </div>
455
+ {missingToken && dirty && <p className="text-xs text-theme-text-tertiary">Enter the token file’s path to save.</p>}
456
+ <FormSaveActions
457
+ dirty={dirty && !missingToken}
458
+ busy={busy}
459
+ onSave={() => saveDraft()}
460
+ onDiscard={() => { if (latest) adopt(latest); else setDraft(saved); setFeedback(undefined); save.reset() }}
461
+ feedback={feedback}
462
+ error={error}
463
+ />
464
+ {view.saved && !view.targetChanged && (
465
+ <div className="flex justify-end">
466
+ <button type="button" disabled={busy} onClick={() => setConfirm('disconnect')} className={clsx('text-xs hover:underline disabled:opacity-50', toneTextClass('unhealthy'))}>
467
+ Disconnect API
468
+ </button>
469
+ </div>
470
+ )}
471
+ <ConfirmDialog
472
+ open={confirm === 'disconnect'}
473
+ onClose={() => setConfirm(null)}
474
+ onConfirm={() => {
475
+ setConfirm(null)
476
+ submit({ target: view.target, revision: view.revision, settings: { identity: 'none' } }, 'Disconnected. Radar no longer reads Substrate’s API on this cluster.')
477
+ }}
478
+ title="Disconnect from Substrate’s API?"
479
+ message="Radar stops reading actors, templates and workers on this cluster, and forgets the saved settings. It doesn’t revoke the token."
480
+ confirmLabel="Disconnect"
481
+ variant="danger"
482
+ showWarning={false}
483
+ />
484
+ <ConfirmDialog
485
+ open={confirm === 'destination'}
486
+ onClose={() => setConfirm(null)}
487
+ onConfirm={() => {
488
+ setConfirm(null)
489
+ saveDraft(true)
490
+ }}
491
+ title="Send the saved credential to a new address?"
492
+ message={`${destinationReason ? `${destinationReason} ` : ''}Radar will present the same identity to this API server. Continue only if you trust it.`}
493
+ confirmLabel="Send and save"
494
+ variant="warning"
495
+ showWarning={false}
496
+ />
497
+ </form>
498
+ )
499
+ }
500
+
501
+ /**
502
+ * How to get a viewer token, from Substrate's authentication and
503
+ * authorization guides. There is no one-line grant: an owner edits the
504
+ * access policy.
505
+ */
506
+ function TokenSetup() {
507
+ return (
508
+ <Disclosure label="How to get a viewer token">
509
+ <ol className="list-decimal space-y-2 pl-5">
510
+ <li>
511
+ Mint a token for your own ServiceAccount, for example in a namespace set aside for Substrate users (Substrate’s authentication guide, “Your own ServiceAccount”):
512
+ <CommandChip command="kubectl create token -n ate-users <you> --audience api.ate-system.svc > ~/ate.token" />
513
+ The token expires; Radar rereads the file when it reconnects, so write a fresh one there when it does.
514
+ </li>
515
+ <li>
516
+ Ask a Substrate owner to add <span className="font-mono">user:system:serviceaccount:ate-users:&lt;you&gt;</span> as a <span className="font-medium">viewer</span>:
517
+ <ul className="mt-1 list-disc space-y-0.5 pl-4">
518
+ <li>in the global access policy, to see workers and every atespace;</li>
519
+ <li>or in one atespace’s policy, to see its actors and templates only. Workers then stay unread: only a global viewer may list them.</li>
520
+ </ul>
521
+ Have the owner use their credentials to read and update the access policy on the Substrate instance you’re configuring. Use the configured endpoint and trust settings, or the ate-system/api Service on this cluster for a port-forwarded connection.
522
+ See <a href={AUTHZ_DOC} target="_blank" rel="noreferrer" className="text-accent-text hover:underline">Managing access</a> in Substrate’s authorization guide.
523
+ </li>
524
+ </ol>
525
+ </Disclosure>
526
+ )
527
+ }
528
+
529
+ /** Secondary detail under a label that says what it explains; folded until asked for. */
530
+ function Disclosure({ label, children }: { label: string; children: ReactNode }) {
531
+ const [open, setOpen] = useState(false)
532
+ const id = useId()
533
+ return (
534
+ <div>
535
+ <button type="button" aria-expanded={open} aria-controls={id} onClick={() => setOpen((v) => !v)} className="inline-flex items-center gap-1 text-xs font-medium text-accent-text hover:underline">
536
+ <CollapseChevron open={open} />
537
+ {label}
538
+ </button>
539
+ <Collapse open={open} id={id}>
540
+ <div className="pt-1.5 text-xs text-theme-text-secondary">{children}</div>
541
+ </Collapse>
542
+ </div>
543
+ )
544
+ }
@@ -3,6 +3,7 @@ import {
3
3
  costSourceApplyLabel,
4
4
  prometheusHeadersFromRows,
5
5
  pendingSections,
6
+ showsSubstrateSection,
6
7
  shouldShowSettingsFooter,
7
8
  } from "./settings-state";
8
9
 
@@ -24,8 +25,8 @@ describe("Prometheus header edits", () => {
24
25
  });
25
26
 
26
27
  describe("Integration settings state", () => {
27
- it.each(['prometheus', 'cost', 'argocd'] as const)("offers discard for a %s draft", (section) => {
28
- expect(pendingSections({ prometheus: false, cost: false, argocd: false, ai: false, [section]: true })).toEqual([section]);
28
+ it.each(['prometheus', 'cost', 'argocd', 'substrate'] as const)("offers discard for a %s draft", (section) => {
29
+ expect(pendingSections({ prometheus: false, cost: false, argocd: false, substrate: false, ai: false, [section]: true })).toEqual([section]);
29
30
  expect(
30
31
  shouldShowSettingsFooter({
31
32
  canEditConfig: true,
@@ -39,7 +40,7 @@ describe("Integration settings state", () => {
39
40
  });
40
41
 
41
42
  it("offers review from other sections and retains the close guard", () => {
42
- expect(pendingSections({ prometheus: true, cost: true, argocd: true, ai: true })).toEqual(['prometheus', 'cost', 'argocd', 'ai']);
43
+ expect(pendingSections({ prometheus: true, cost: true, argocd: true, substrate: true, ai: true })).toEqual(['prometheus', 'cost', 'argocd', 'substrate', 'ai']);
43
44
  expect(
44
45
  shouldShowSettingsFooter({
45
46
  canEditConfig: true,
@@ -65,3 +66,20 @@ describe("Integration settings state", () => {
65
66
  expect(costSourceApplyLabel("prometheus")).toBe("Apply source");
66
67
  });
67
68
  });
69
+
70
+ describe('showsSubstrateSection', () => {
71
+ const base = { supported: true, discovered: false, saved: false, dirty: false }
72
+ it('hides on a cluster that doesn’t serve Substrate', () => {
73
+ expect(showsSubstrateSection(base)).toBe(false)
74
+ })
75
+ it('shows where Substrate is served, or a connection to remove is still saved', () => {
76
+ expect(showsSubstrateSection({ ...base, discovered: true })).toBe(true)
77
+ expect(showsSubstrateSection({ ...base, saved: true })).toBe(true)
78
+ })
79
+ it('hides against a Radar that predates the Substrate views', () => {
80
+ expect(showsSubstrateSection({ ...base, supported: false, discovered: true })).toBe(false)
81
+ })
82
+ it('keeps a section holding a draft, even after a switch to a cluster without Substrate', () => {
83
+ expect(showsSubstrateSection({ ...base, supported: false, dirty: true })).toBe(true)
84
+ })
85
+ })
@@ -5,20 +5,30 @@ export type SettingsSectionId =
5
5
  | 'prometheus'
6
6
  | 'cost'
7
7
  | 'argocd'
8
+ | 'substrate'
8
9
  | 'ai'
9
10
  | 'advanced'
10
11
  | 'privacy'
11
12
 
12
13
  export type IntegrationSectionId = 'prometheus' | 'cost' | 'argocd'
13
14
  // Tabs whose drafts save through their own form, not the startup footer.
14
- export type PendingSectionId = IntegrationSectionId | 'ai'
15
+ export type PendingSectionId = IntegrationSectionId | 'substrate' | 'ai'
15
16
 
16
17
  export const pendingSectionLabels: Record<PendingSectionId, string> = {
17
- prometheus: 'Metrics', cost: 'Cost', argocd: 'Argo CD', ai: 'AI investigations',
18
+ prometheus: 'Metrics', cost: 'Cost', argocd: 'Argo CD', substrate: 'Agent Substrate', ai: 'AI investigations',
19
+ }
20
+
21
+ /**
22
+ * Agent Substrate runs on few clusters, so its section shows only where it can
23
+ * matter: the cluster serves Substrate's API, a connection is still saved for
24
+ * this cluster (so it can be disconnected), or the form holds a draft.
25
+ */
26
+ export function showsSubstrateSection(input: { supported: boolean; discovered: boolean; saved: boolean; dirty: boolean }): boolean {
27
+ return input.dirty || (input.supported && (input.discovered || input.saved))
18
28
  }
19
29
 
20
30
  export function pendingSections(dirty: Record<PendingSectionId, boolean>): PendingSectionId[] {
21
- return (['prometheus', 'cost', 'argocd', 'ai'] as const).filter(section => dirty[section])
31
+ return (['prometheus', 'cost', 'argocd', 'substrate', 'ai'] as const).filter(section => dirty[section])
22
32
  }
23
33
 
24
34
  // AI preferences are open to every user, so an AI draft pending in another tab