@skyhook-io/radar-app 1.19.0 → 1.20.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 (198) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -5
  3. package/src/App.tsx +37 -9
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +353 -64
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.ts +4 -0
  15. package/src/api/helmInventory.test.tsx +108 -0
  16. package/src/api/radarFeatures.render.test.tsx +33 -1
  17. package/src/api/radarFeatures.test.ts +47 -0
  18. package/src/api/radarFeatures.ts +42 -1
  19. package/src/api/rbac.settled.test.tsx +42 -0
  20. package/src/api/rbac.test.ts +18 -0
  21. package/src/api/rbac.ts +37 -7
  22. package/src/api/traffic.ts +9 -4
  23. package/src/api/usage-data.fixtures.ts +3 -1
  24. package/src/api/usage-data.test.tsx +134 -0
  25. package/src/api/usage-data.ts +35 -7
  26. package/src/api/workloadPodsPolling.test.ts +26 -0
  27. package/src/components/CloudConnectFlow.test.tsx +86 -0
  28. package/src/components/CloudConnectFlow.tsx +65 -27
  29. package/src/components/CloudFunnelButton.test.tsx +140 -5
  30. package/src/components/CloudFunnelButton.tsx +50 -9
  31. package/src/components/ConnectionErrorView.test.tsx +34 -0
  32. package/src/components/ConnectionErrorView.tsx +35 -11
  33. package/src/components/ContextSwitcher.tsx +5 -2
  34. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  35. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  38. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  39. package/src/components/capacity/CapacityDemand.tsx +3 -2
  40. package/src/components/capacity/demandSummary.test.ts +38 -0
  41. package/src/components/capacity/shared.tsx +12 -1
  42. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  43. package/src/components/cost/CostTrendChart.tsx +2 -0
  44. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  45. package/src/components/cost/source.test.ts +5 -0
  46. package/src/components/cost/source.ts +11 -0
  47. package/src/components/curl/ServiceCurlAvailability.test.tsx +32 -0
  48. package/src/components/curl/ServiceCurlButton.tsx +2 -2
  49. package/src/components/diagnose/AIMarkdown.tsx +3 -0
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
  52. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  53. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  54. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  55. package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
  56. package/src/components/diagnose/DiagnoseContext.tsx +68 -2
  57. package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
  58. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  59. package/src/components/diagnose/Home.test.tsx +26 -0
  60. package/src/components/diagnose/Home.tsx +20 -1
  61. package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
  62. package/src/components/diagnose/InvestigationView.tsx +94 -26
  63. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  64. package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
  65. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  66. package/src/components/diagnose/NextStepJump.tsx +75 -0
  67. package/src/components/diagnose/QuestionComposer.tsx +8 -0
  68. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  69. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  70. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  71. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  72. package/src/components/diagnose/investigationCase.test.tsx +50 -1
  73. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  74. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +72 -0
  75. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
  76. package/src/components/diagnose/investigationEvidence/adapters/helm.ts +51 -16
  77. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  78. package/src/components/diagnose/investigationEvidence/adapters/listings.ts +34 -4
  79. package/src/components/diagnose/investigationEvidence/adapters/resource.ts +3 -2
  80. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  81. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  82. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  83. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  84. package/src/components/diagnose/investigationState.ts +28 -0
  85. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  86. package/src/components/diagnose/lastInvestigation.ts +58 -0
  87. package/src/components/diagnose/launch.test.ts +125 -1
  88. package/src/components/diagnose/launch.ts +57 -10
  89. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  90. package/src/components/execution/BatchExecutionView.tsx +24 -11
  91. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  92. package/src/components/execution/JobSetAdmission.tsx +18 -3
  93. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  94. package/src/components/execution/runState.test.ts +14 -0
  95. package/src/components/execution/runState.ts +8 -0
  96. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  97. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  98. package/src/components/gitops/GitOpsView.tsx +86 -17
  99. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  100. package/src/components/gitops/destination-toast.test.ts +1 -1
  101. package/src/components/gitops/destination-toast.ts +2 -2
  102. package/src/components/helm/HelmDrawerFrame.tsx +101 -0
  103. package/src/components/helm/HelmDrawerRouting.test.tsx +86 -0
  104. package/src/components/helm/HelmReleaseDrawer.tsx +23 -86
  105. package/src/components/helm/HelmView.tsx +213 -71
  106. package/src/components/helm/ObservedHelmNotice.tsx +146 -0
  107. package/src/components/helm/ObservedHelmRelease.test.tsx +261 -0
  108. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +80 -0
  109. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +228 -0
  110. package/src/components/helm/OwnedResources.tsx +4 -2
  111. package/src/components/home/ClusterHealthCard.restricted.test.tsx +76 -0
  112. package/src/components/home/ClusterHealthCard.tsx +28 -5
  113. package/src/components/home/HelmSummary.tsx +23 -4
  114. package/src/components/home/HelmSummary.unread.test.ts +16 -0
  115. package/src/components/home/HomeAgentBlock.test.tsx +31 -3
  116. package/src/components/home/HomeAgentBlock.tsx +20 -4
  117. package/src/components/home/HomeDiagramCard.tsx +47 -0
  118. package/src/components/home/HomeView.tsx +81 -41
  119. package/src/components/home/MCPSetupDialog.test.tsx +126 -10
  120. package/src/components/home/MCPSetupDialog.tsx +33 -5
  121. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  122. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  123. package/src/components/home/TopologyPreview.test.tsx +73 -0
  124. package/src/components/home/TopologyPreview.tsx +120 -233
  125. package/src/components/home/TrafficSummary.test.tsx +63 -0
  126. package/src/components/home/TrafficSummary.tsx +135 -138
  127. package/src/components/home/mcpToolCatalog.ts +67 -14
  128. package/src/components/issues/IssuesPane.test.ts +11 -0
  129. package/src/components/issues/IssuesPane.tsx +15 -5
  130. package/src/components/issues/uncheckedSources.test.ts +22 -1
  131. package/src/components/issues/uncheckedSources.ts +21 -0
  132. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  133. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  134. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  135. package/src/components/kueue/useRelatedReads.ts +205 -0
  136. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  137. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  138. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  139. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  140. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  141. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  142. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  143. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  144. package/src/components/logs/rayClusterPods.ts +32 -0
  145. package/src/components/outageSince.test.ts +21 -0
  146. package/src/components/outageSince.ts +10 -0
  147. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  148. package/src/components/resource/PrometheusCharts.tsx +3 -40
  149. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  150. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  151. package/src/components/resources/crd/host.tsx +14 -0
  152. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  153. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  154. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  155. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  156. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  157. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  158. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  159. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  160. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  161. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  162. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  163. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  164. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  165. package/src/components/resources/renderers/ServiceRenderer.test.tsx +15 -2
  166. package/src/components/resources/renderers/ServiceRenderer.tsx +1 -1
  167. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +160 -0
  168. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +128 -0
  169. package/src/components/traffic/TrafficView.tsx +3 -3
  170. package/src/components/ui/command-items-crd.test.tsx +23 -0
  171. package/src/components/ui/command-items.ts +2 -1
  172. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  173. package/src/components/useContextSwitchFlow.tsx +21 -4
  174. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  175. package/src/components/whats-new/WhatsNew.tsx +5 -1
  176. package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
  177. package/src/components/whats-new/releaseNotes.ts +77 -4
  178. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  179. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  180. package/src/components/workload/WorkloadView.test.ts +10 -1
  181. package/src/components/workload/WorkloadView.tsx +85 -98
  182. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  183. package/src/components/workload/issueResourceOpener.ts +17 -0
  184. package/src/context/ConnectionContext.tsx +133 -60
  185. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  186. package/src/context/ContextSwitchContext.tsx +14 -1
  187. package/src/context/DiagnoseCustomization.tsx +3 -0
  188. package/src/context/clusterConnected.ts +10 -0
  189. package/src/contexts/CapabilitiesContext.tsx +8 -4
  190. package/src/hooks/useElementSize.ts +30 -0
  191. package/src/hooks/useResolvedGitOpsOwner.test.ts +22 -0
  192. package/src/hooks/useResolvedGitOpsOwner.ts +6 -3
  193. package/src/integrations/resourceHost.test.tsx +1 -0
  194. package/src/integrations/resourceHost.ts +5 -1
  195. package/src/integrations/resourceHosts.test.tsx +21 -4
  196. package/src/integrations/resourceHosts.tsx +17 -0
  197. package/src/main.tsx +5 -0
  198. package/src/utils/related-findings.ts +46 -0
@@ -1,22 +1,34 @@
1
1
  // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot } from 'react-dom/client'
2
4
  import { renderToStaticMarkup } from 'react-dom/server'
3
- import { describe, expect, it } from 'vitest'
5
+ import { describe, expect, it, vi } from 'vitest'
4
6
  import { MCPSetupDialog } from './MCPSetupDialog'
5
7
  import { mcpEndpointUrl, setBasename } from '../../api/config'
6
8
  import { MCP_TOOL_CATALOG } from './mcpToolCatalog'
7
9
 
10
+ const clipboard = vi.hoisted(() => ({ ok: true, copied: [] as string[] }))
11
+ vi.mock('@skyhook-io/k8s-ui/utils/clipboard', () => ({
12
+ copyText: async (text: string) => {
13
+ if (clipboard.ok) clipboard.copied.push(text)
14
+ return clipboard.ok
15
+ },
16
+ }))
17
+
8
18
  describe('MCP setup in read-only mode', () => {
9
19
  it('generates client configurations for the retained endpoint and hides writes', () => {
10
20
  setBasename('/radar')
11
21
  try {
12
22
  const url = mcpEndpointUrl(true)
13
- const html = renderToStaticMarkup(<MCPSetupDialog open readOnly mcpUrl={url} onClose={() => {}} />)
23
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools readOnly applicationEvidenceAvailable mcpUrl={url} onClose={() => {}} />)
14
24
  expect(html).toContain(`claude mcp add --transport http radar ${url}`)
15
25
  expect(html).toContain(`codex mcp add radar --url ${url}`)
16
26
  expect(html).toContain('/radar/mcp-readonly')
17
27
  expect(html).toContain('list_namespaces')
18
28
  expect(html).not.toContain('apply_resource')
19
29
  expect(html).not.toContain('exec_pod')
30
+ expect(html).not.toContain('curl_service')
31
+ expect(html).not.toContain('collect_application_evidence')
20
32
  expect(html).not.toContain('in_cluster')
21
33
  expect(html).toContain('Read-only mode blocks write tools')
22
34
  } finally {
@@ -25,31 +37,135 @@ describe('MCP setup in read-only mode', () => {
25
37
  })
26
38
 
27
39
  it('explains disabled exec without including it in the available tool count', () => {
28
- const html = renderToStaticMarkup(<MCPSetupDialog open execTools={false} mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
40
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools execTools={false} mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
29
41
  expect(html).toContain('apply_resource')
30
42
  expect(html).toContain('in_cluster')
31
43
  expect(html).toContain('exec_pod')
32
44
  expect(html).toContain('is disabled')
33
45
  expect(html).toContain('--mcp-exec-tools')
34
- expect(html).toContain(`${MCP_TOOL_CATALOG.length - 1} tools`)
46
+ expect(html).toContain(`${MCP_TOOL_CATALOG.length - 3} tools`)
35
47
  })
36
48
 
37
49
  it('does not suggest an unsupported flag when the capability is absent', () => {
38
- const html = renderToStaticMarkup(<MCPSetupDialog open mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
50
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
39
51
  expect(html).not.toContain('exec_pod')
52
+ expect(html).not.toContain('curl_service')
40
53
  expect(html).not.toContain('--mcp-exec-tools')
41
54
  })
42
55
 
43
- it('shows exec and counts it only when enabled', () => {
44
- const html = renderToStaticMarkup(<MCPSetupDialog open execTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
56
+ it('shows exec without enabling HTTP', () => {
57
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools execTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
45
58
  expect(html).toContain('exec_pod')
46
- expect(html).toContain(`${MCP_TOOL_CATALOG.length} tools`)
59
+ expect(html).not.toContain('curl_service')
60
+ expect(html).toContain(`${MCP_TOOL_CATALOG.length - 2} tools`)
47
61
  expect(html.indexOf('exec_pod')).toBeGreaterThan(html.indexOf('get_workload_logs'))
48
62
  })
49
63
 
50
64
  it('hides exec in read-only mode even if exec is requested', () => {
51
- const html = renderToStaticMarkup(<MCPSetupDialog open readOnly execTools mcpUrl={mcpEndpointUrl(true)} onClose={() => {}} />)
65
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools readOnly execTools mcpUrl={mcpEndpointUrl(true)} onClose={() => {}} />)
52
66
  expect(html).not.toContain('exec_pod')
53
- expect(html).toContain(`${MCP_TOOL_CATALOG.filter((tool) => !tool.write).length} tools`)
67
+ expect(html).not.toContain('curl_service')
68
+ expect(html).toContain(`${MCP_TOOL_CATALOG.filter((tool) => !tool.write && !tool.localOnly).length} tools`)
69
+ })
70
+
71
+ it('keeps the full catalog in default mode', () => {
72
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools applicationEvidenceAvailable mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
73
+ expect(html).toContain('apply_resource')
74
+ expect(html).toContain('in_cluster')
75
+ expect(html).toContain('collect_application_evidence')
76
+ })
77
+
78
+ it('hides local-only tools unless the server advertises availability', () => {
79
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
80
+ expect(html).toContain('apply_resource')
81
+ expect(html).not.toContain('collect_application_evidence')
82
+ })
83
+ })
84
+
85
+ describe('MCP setup prompt tip', () => {
86
+ it('tips to name Radar under the client setups, as plain text, without the in-Radar link when no handler is given', () => {
87
+ const host = document.createElement('div')
88
+ host.innerHTML = renderToStaticMarkup(<MCPSetupDialog open helmTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
89
+ const tip = [...host.querySelectorAll('p')].find((p) => p.textContent?.startsWith('Tip:'))
90
+ expect(tip?.textContent).toBe(
91
+ "Tip: name Radar in your prompt so your agent uses Radar instead of kubectl, e.g. Use Radar to find what's broken in my cluster and why.",
92
+ )
93
+ expect(tip!.querySelector('code.inline-code')?.textContent).toBe("Use Radar to find what's broken in my cluster and why.")
94
+ expect(tip!.querySelector('button, pre')).toBeNull()
95
+ expect(tip!.nextElementSibling).toBeNull()
96
+ const html = host.innerHTML
97
+ expect(html.indexOf('Tip:')).toBeGreaterThan(html.indexOf('Connect your AI tool'))
98
+ expect(html.indexOf('Tip:')).toBeLessThan(html.indexOf('list_namespaces'))
99
+ expect(html).not.toContain('investigate from Radar itself')
100
+ })
101
+
102
+ it('closes the dialog, then opens the composer from the in-Radar link', () => {
103
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
104
+ const calls: string[] = []
105
+ const host = document.createElement('div')
106
+ document.body.appendChild(host)
107
+ const root = createRoot(host)
108
+ try {
109
+ act(() => root.render(
110
+ <MCPSetupDialog
111
+ open
112
+ mcpUrl={mcpEndpointUrl()}
113
+ onClose={() => calls.push('close')}
114
+ onInvestigate={() => calls.push('investigate')}
115
+ />,
116
+ ))
117
+ const link = [...host.querySelectorAll('button')].find((b) => /investigate from Radar itself/.test(b.textContent ?? ''))
118
+ expect(link).toBeTruthy()
119
+ act(() => link!.click())
120
+ expect(calls).toEqual(['close', 'investigate'])
121
+ } finally {
122
+ act(() => root.unmount())
123
+ host.remove()
124
+ }
125
+ })
126
+
127
+ it.each([
128
+ [true, 'Copied'],
129
+ [false, 'Copy to clipboard'],
130
+ ])('copies the endpoint and shows the tick only when the copy worked (ok=%s)', async (ok, label) => {
131
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
132
+ clipboard.ok = ok
133
+ clipboard.copied = []
134
+ const host = document.createElement('div')
135
+ document.body.appendChild(host)
136
+ const root = createRoot(host)
137
+ try {
138
+ act(() => root.render(<MCPSetupDialog open helmTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />))
139
+ const endpoint = [...host.querySelectorAll('code')].find((c) => c.textContent === mcpEndpointUrl())!
140
+ const copy = endpoint.closest('.relative')!.querySelector('button')!
141
+ await act(async () => copy.click())
142
+ expect(clipboard.copied).toEqual(ok ? [mcpEndpointUrl()] : [])
143
+ expect(copy.getAttribute('aria-label')).toBe(label)
144
+ } finally {
145
+ act(() => root.unmount())
146
+ host.remove()
147
+ }
54
148
  })
55
149
  })
150
+
151
+ it('shows HTTP independently of exec', () => {
152
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools httpTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
153
+ expect(html).toContain('curl_service')
154
+ expect(html).not.toContain('exec_pod')
155
+ expect(html).toContain(`${MCP_TOOL_CATALOG.length - 2} tools`)
156
+ const readOnly = renderToStaticMarkup(<MCPSetupDialog open helmTools readOnly httpTools mcpUrl={mcpEndpointUrl(true)} onClose={() => {}} />)
157
+ expect(readOnly).not.toContain('curl_service')
158
+ })
159
+
160
+
161
+ it('hides disabled Helm writes while retaining release reads and other writes', () => {
162
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools={false} mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
163
+ expect(html).not.toContain('manage_helm')
164
+ expect(html).toContain('get_helm_release')
165
+ expect(html).toContain('apply_resource')
166
+ })
167
+
168
+ it('shows registered Helm tools independently of target namespace permissions', () => {
169
+ const html = renderToStaticMarkup(<MCPSetupDialog open helmTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
170
+ expect(html).toContain('manage_helm')
171
+ })
@@ -4,28 +4,42 @@ import { apiUrl, getAuthHeaders, getCredentialsMode } from '../../api/config'
4
4
  import { MCP_TOOL_CATALOG } from './mcpToolCatalog'
5
5
  import { Tooltip } from '../ui/Tooltip'
6
6
  import { Disclosure } from '@skyhook-io/k8s-ui/components/ui/Disclosure'
7
+ import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
8
+
9
+ const MCP_EXAMPLE_PROMPT ="Use Radar to find what's broken in my cluster and why."
7
10
 
8
11
  interface MCPSetupDialogProps {
9
12
  open: boolean
10
13
  onClose: () => void
11
14
  readOnly?: boolean
12
15
  execTools?: boolean
16
+ httpTools?: boolean
17
+ /** Whether the native Helm MCP tool is registered; target Kubernetes permissions still required. */
18
+ helmTools?: boolean
19
+ applicationEvidenceAvailable?: boolean
13
20
  mcpUrl: string
21
+ /** Opens Radar's own investigation composer. Omit where investigations can't run. */
22
+ onInvestigate?: () => void
14
23
  }
15
24
 
16
25
  function CopyButton({ text }: { text: string }) {
17
26
  const [copied, setCopied] = useState(false)
18
27
 
19
28
  const handleCopy = () => {
20
- navigator.clipboard.writeText(text)
21
- setCopied(true)
22
- setTimeout(() => setCopied(false), 2000)
29
+ // Plain-HTTP origins and denied permission reject the async Clipboard API;
30
+ // copyText falls back, and the tick must not claim a copy that didn't happen.
31
+ void copyText(text).then((ok) => {
32
+ if (!ok) return
33
+ setCopied(true)
34
+ setTimeout(() => setCopied(false), 2000)
35
+ })
23
36
  }
24
37
 
25
38
  return (
26
39
  <Tooltip content="Copy to clipboard" position="left" wrapperClassName="absolute top-2 right-2">
27
40
  <button
28
41
  onClick={handleCopy}
42
+ aria-label={copied ? 'Copied' : 'Copy to clipboard'}
29
43
  className="p-1.5 rounded-md bg-theme-elevated/50 hover:bg-theme-elevated text-theme-text-tertiary hover:text-theme-text-secondary transition-colors"
30
44
  >
31
45
  {copied ? <Check className="w-3.5 h-3.5 text-green-500" /> : <Copy className="w-3.5 h-3.5" />}
@@ -45,7 +59,7 @@ function CodeBlock({ children }: { children: string }) {
45
59
  )
46
60
  }
47
61
 
48
- export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTools }: MCPSetupDialogProps) {
62
+ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTools, httpTools, helmTools, onInvestigate, applicationEvidenceAvailable = false }: MCPSetupDialogProps) {
49
63
  const dialogRef = useRef<HTMLDivElement>(null)
50
64
  const [isDesktop, setIsDesktop] = useState(false)
51
65
  const [portPinned, setPortPinned] = useState(false)
@@ -119,7 +133,7 @@ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTo
119
133
  const currentPort = Number(window.location.port) || 80
120
134
 
121
135
  const tools = MCP_TOOL_CATALOG
122
- .filter((tool) => (!readOnly || !tool.write) && (tool.name !== 'exec_pod' || execTools))
136
+ .filter((tool) => (!readOnly || !tool.write) && (tool.name !== 'exec_pod' || execTools) && (tool.name !== 'curl_service' || httpTools) && (tool.name !== 'manage_helm' || helmTools) && (!tool.localOnly || (!readOnly && applicationEvidenceAvailable)))
123
137
  .map((tool) => readOnly && tool.name === 'diagnose'
124
138
  ? { ...tool, params: tool.params.filter((param) => param.arg !== 'in_cluster') }
125
139
  : tool)
@@ -321,6 +335,20 @@ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTo
321
335
  </div>
322
336
  </Disclosure>
323
337
  ))}
338
+
339
+ <p className="pt-1 text-xs text-theme-text-tertiary leading-relaxed">
340
+ <span className="font-medium text-theme-text-secondary">Tip:</span> name Radar in your prompt so your
341
+ agent uses Radar instead of kubectl, e.g. <code className="inline-code">{MCP_EXAMPLE_PROMPT}</code>
342
+ </p>
343
+ {onInvestigate && (
344
+ <button
345
+ type="button"
346
+ onClick={() => { onClose(); onInvestigate() }}
347
+ className="text-xs text-accent-text hover:underline underline-offset-2"
348
+ >
349
+ Or investigate from Radar itself →
350
+ </button>
351
+ )}
324
352
  </div>
325
353
 
326
354
  {/* Available tools */}
@@ -0,0 +1,171 @@
1
+ // @vitest-environment jsdom
2
+ import { act, type ReactNode } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import type { Issue } from '@skyhook-io/k8s-ui'
6
+ import { ProblemsPanel } from './HomeView'
7
+ import { IssueDiagnoseButton } from '../diagnose/LocalDiagnoseAction'
8
+ import { HOVER_REVEAL_ACTION, HOVER_REVEAL_HIT, HOVER_REVEAL_REST } from '../../utils/animation'
9
+
10
+ const usage = vi.hoisted(() => ({ recordUsageEvent: vi.fn() }))
11
+ vi.mock('../../api/usage-data', async (importOriginal) => ({
12
+ ...(await importOriginal<object>()),
13
+ recordUsageEvent: usage.recordUsageEvent,
14
+ }))
15
+
16
+ const diagnose = vi.hoisted(() => ({
17
+ setupState: 'ready' as string,
18
+ available: true,
19
+ hosted: false,
20
+ agentLabel: 'Claude Code',
21
+ cliOverride: false,
22
+ openInvestigation: vi.fn(),
23
+ openHome: vi.fn(),
24
+ }))
25
+ vi.mock('../diagnose/DiagnoseContext', () => ({
26
+ useDiagnose: () => diagnose,
27
+ useDiagnoseLayout: () => ({ runningRunIds: new Map(), lastInvestigations: new Map() }),
28
+ }))
29
+ vi.mock('../ui/Tooltip', () => ({ Tooltip: ({ children }: { children: ReactNode }) => children }))
30
+
31
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
32
+
33
+ const classesOf = (fragment: string) => fragment.split(/\s+/).filter(Boolean)
34
+
35
+ const issue: Issue = {
36
+ id: 'deploy-unavailable', severity: 'critical', source: 'problem', category: 'workload', category_group: 'workload', grouping_scope: 'resource',
37
+ kind: 'Deployment', group: 'apps', namespace: 'gl-shop', name: 'checkout', reason: 'Unavailable', message: 'No ready replicas',
38
+ }
39
+ const target = { kind: 'Deployment', group: 'apps', namespace: 'gl-shop', name: 'checkout' }
40
+
41
+ let root: Root
42
+ let container: HTMLDivElement
43
+ const onResourceClick = vi.fn()
44
+
45
+ function render(rowIssue: Issue = issue) {
46
+ act(() => {
47
+ root.render(
48
+ <ProblemsPanel
49
+ issues={[rowIssue]}
50
+ issueCount={1}
51
+ onRetryIssues={() => {}}
52
+ hasData
53
+ isLoading={false}
54
+ isRefreshing={false}
55
+ error={null}
56
+ totalReturned={1}
57
+ onNavigateToIssues={() => {}}
58
+ onResourceClick={onResourceClick}
59
+ />,
60
+ )
61
+ })
62
+ }
63
+
64
+ const buttons = () => Array.from(container.querySelectorAll('button'))
65
+ const investigateButton = () => buttons().find((b) => b.textContent?.trim() === 'Investigate')
66
+
67
+ beforeEach(() => {
68
+ Object.assign(diagnose, { setupState: 'ready', available: true })
69
+ diagnose.openInvestigation.mockReset()
70
+ diagnose.openHome.mockReset()
71
+ onResourceClick.mockReset()
72
+ container = document.createElement('div')
73
+ document.body.appendChild(container)
74
+ root = createRoot(container)
75
+ })
76
+
77
+ afterEach(() => {
78
+ act(() => root.unmount())
79
+ container.remove()
80
+ })
81
+
82
+ describe('Home Active Issues Investigate action', () => {
83
+ it('starts an investigation for the row resource without opening it', () => {
84
+ render()
85
+ const button = investigateButton()
86
+ expect(button).toBeDefined()
87
+ act(() => button!.click())
88
+ expect(diagnose.openInvestigation).toHaveBeenCalledWith(target)
89
+ expect(onResourceClick).not.toHaveBeenCalled()
90
+ })
91
+
92
+ it('still opens the resource from the rest of the row', () => {
93
+ render()
94
+ const row = buttons().find((b) => b.textContent?.includes('checkout'))
95
+ act(() => row!.click())
96
+ expect(onResourceClick).toHaveBeenCalledWith(target)
97
+ expect(diagnose.openInvestigation).not.toHaveBeenCalled()
98
+ })
99
+
100
+ it('does not nest the action inside the row button', () => {
101
+ render()
102
+ expect(investigateButton()!.parentElement!.closest('button')).toBeNull()
103
+ })
104
+
105
+ it.each(['off', 'unknown'])('is absent where investigations cannot run (%s)', (setupState) => {
106
+ diagnose.setupState = setupState
107
+ render()
108
+ expect(investigateButton()).toBeUndefined()
109
+ })
110
+
111
+ it('opens setup instead of starting a run when no agent is ready', () => {
112
+ Object.assign(diagnose, { setupState: 'needs-install', available: false })
113
+ render()
114
+ act(() => investigateButton()!.click())
115
+ expect(diagnose.openHome).toHaveBeenCalled()
116
+ expect(diagnose.openInvestigation).not.toHaveBeenCalled()
117
+ expect(onResourceClick).not.toHaveBeenCalled()
118
+ })
119
+
120
+ const agedIssue = () => ({ ...issue, first_seen: new Date(Date.now() - 3_600_000).toISOString() })
121
+ const ageSlot = () => container.querySelector('.group button .ml-auto')!
122
+
123
+ it('swaps the age slot for the action on hover or keyboard focus, in the same group', () => {
124
+ render(agedIssue())
125
+ const action = investigateButton()!
126
+ const group = action.closest('.group')!
127
+ expect(ageSlot().textContent).toMatch(/\d/)
128
+ for (const c of classesOf(HOVER_REVEAL_REST)) expect(ageSlot().classList).toContain(c)
129
+ const overlay = group.lastElementChild!
130
+ expect(overlay.contains(action)).toBe(true)
131
+ expect(overlay.classList).toContain('absolute')
132
+ for (const c of classesOf(HOVER_REVEAL_ACTION)) expect(overlay.classList).toContain(c)
133
+ // The overlay itself never takes clicks; only the control inside does.
134
+ expect(overlay.classList).toContain('pointer-events-none')
135
+ const hit = action.parentElement!.closest('span:not([aria-hidden])')!
136
+ expect(hit.parentElement).toBe(overlay)
137
+ for (const c of classesOf(HOVER_REVEAL_HIT)) expect(hit.classList).toContain(c)
138
+ // Keyboard reveal keys on :focus-visible, so a row left focused by a click
139
+ // doesn't keep its action shown.
140
+ expect(HOVER_REVEAL_ACTION).toContain('group-has-[:focus-visible]:opacity-100')
141
+ })
142
+
143
+ it('keeps the age slot in place where there is no action to swap in', () => {
144
+ diagnose.setupState = 'off'
145
+ render(agedIssue())
146
+ expect(ageSlot().textContent).toMatch(/\d/)
147
+ expect(ageSlot().classList).not.toContain('group-hover:opacity-0')
148
+ expect(container.querySelector('.group > div')).toBeNull()
149
+ })
150
+ })
151
+
152
+ describe('opening an issue from Home', () => {
153
+ it('opens its resource and counts it once', () => {
154
+ render()
155
+ usage.recordUsageEvent.mockClear()
156
+ const row = buttons().find((b) => b.textContent?.includes('checkout'))!
157
+ act(() => row.click())
158
+ expect(onResourceClick).toHaveBeenCalledTimes(1)
159
+ expect(usage.recordUsageEvent.mock.calls).toEqual([[{ type: 'ui', name: 'issue_action:open' }]])
160
+ })
161
+ })
162
+
163
+ describe('IssueDiagnoseButton size', () => {
164
+ it('keeps the Issues page look by default and shrinks only when compact', () => {
165
+ act(() => root.render(<><IssueDiagnoseButton {...target} /><IssueDiagnoseButton {...target} size="compact" /></>))
166
+ const [regular, compact] = buttons()
167
+ expect(regular.className).toContain('px-2 py-1 text-xs')
168
+ expect(compact.className).toContain('h-4')
169
+ expect(compact.className).not.toContain('py-1 text-xs')
170
+ })
171
+ })
@@ -1,10 +1,12 @@
1
- import { describe, expect, it } from 'vitest'
1
+ import { describe, expect, it, vi } from 'vitest'
2
2
  import { renderToString } from 'react-dom/server'
3
3
  import type { Issue } from '@skyhook-io/k8s-ui'
4
4
  import { ProblemsPanel } from './HomeView'
5
5
  import { uncheckedSourceLines } from '../issues/uncheckedSources'
6
6
  import type { IssuesResponse } from '../../api/client'
7
7
 
8
+ vi.mock('../diagnose/LocalDiagnoseAction', () => ({ IssueDiagnoseButton: () => null, useIssueDiagnoseShown: () => true }))
9
+
8
10
  const line = "Helm releases couldn't be checked, so failed or stuck releases may be missing."
9
11
  const generic = "Some issue checks couldn't run, so issues may be missing."
10
12
  const helm = [{ source: 'helm', reason: 'read_failed' }]
@@ -0,0 +1,73 @@
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 type { Topology } from '../../types'
6
+ import { TopologyPreview } from './TopologyPreview'
7
+
8
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
9
+
10
+ const largeTopology = { nodes: [], edges: [], requiresNamespaceFilter: true } as unknown as Topology
11
+ const smallTopology = {
12
+ nodes: [
13
+ { id: 'deployment/default/web', kind: 'Deployment', name: 'web', status: 'healthy', data: {} },
14
+ { id: 'service/default/web', kind: 'Service', name: 'web', status: 'healthy', data: {} },
15
+ ],
16
+ edges: [{ id: 'e1', source: 'service/default/web', target: 'deployment/default/web', type: 'exposes' }],
17
+ } as unknown as Topology
18
+
19
+ let container: HTMLDivElement
20
+ let root: Root
21
+
22
+ beforeEach(() => {
23
+ container = document.createElement('div')
24
+ document.body.appendChild(container)
25
+ root = createRoot(container)
26
+ })
27
+
28
+ afterEach(() => {
29
+ act(() => root.unmount())
30
+ container.remove()
31
+ })
32
+
33
+ function render(topology: Topology | null, namespaceSelected = false, onNavigate = vi.fn()) {
34
+ act(() => root.render(<TopologyPreview topology={topology} namespaceSelected={namespaceSelected} onNavigate={onNavigate} />))
35
+ return onNavigate
36
+ }
37
+
38
+ const header = () => container.querySelector('button > div > div')!.textContent
39
+
40
+ describe('TopologyPreview', () => {
41
+ it('states the graph counts in the header', () => {
42
+ render(smallTopology)
43
+ expect(header()).toContain('2 resources · 1 relationships')
44
+ expect(container.textContent).toContain('How ingresses, services and workloads connect, grouped by namespace.')
45
+ })
46
+
47
+ it('draws the same picture on a cluster too large to graph, with no counts and no namespaces', () => {
48
+ render(smallTopology)
49
+ const smallDrawing = container.querySelector('svg')!.innerHTML.replace(/_r_\w+_/g, '')
50
+ render(largeTopology)
51
+ expect(header()).toBe('Topology')
52
+ expect(container.querySelector('[data-testid="topology-counts-loading"]')).toBeNull()
53
+ expect(container.querySelector('svg')!.innerHTML.replace(/_r_\w+_/g, '')).toBe(smallDrawing)
54
+ })
55
+
56
+ it('keeps loading while a picked namespace is on its way to the server', () => {
57
+ render(largeTopology, true)
58
+ expect(container.querySelector('[data-testid="topology-counts-loading"]')).not.toBeNull()
59
+ })
60
+
61
+ it('shows an empty scope as an honest zero, and loading before any graph', () => {
62
+ render({ nodes: [], edges: [] } as unknown as Topology)
63
+ expect(header()).toContain('0 resources · 0 relationships')
64
+ render(null)
65
+ expect(container.querySelector('[data-testid="topology-counts-loading"]')).not.toBeNull()
66
+ })
67
+
68
+ it('opens Topology from anywhere on the card', () => {
69
+ const onNavigate = render(largeTopology)
70
+ act(() => container.querySelector('svg')!.dispatchEvent(new MouseEvent('click', { bubbles: true })))
71
+ expect(onNavigate).toHaveBeenCalledTimes(1)
72
+ })
73
+ })