@skyhook-io/radar-app 1.18.2 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -6
  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 +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.test.ts +33 -2
  15. package/src/api/diagnose.ts +97 -3
  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 +41 -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/diagnose/AIMarkdown.tsx +4 -1
  48. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  49. package/src/components/diagnose/AgentControls.tsx +53 -6
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
  52. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  53. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  54. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  55. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  56. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  57. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  58. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  59. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  60. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  61. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  62. package/src/components/diagnose/DiagnoseContext.tsx +272 -10
  63. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  64. package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
  65. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  66. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  67. package/src/components/diagnose/Home.test.tsx +208 -5
  68. package/src/components/diagnose/Home.tsx +187 -36
  69. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  70. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  71. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  72. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  73. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  74. package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
  75. package/src/components/diagnose/InvestigationView.tsx +249 -54
  76. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  77. package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
  78. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  79. package/src/components/diagnose/NextStepJump.tsx +75 -0
  80. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  81. package/src/components/diagnose/QuestionComposer.tsx +495 -0
  82. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  83. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  84. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  85. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  86. package/src/components/diagnose/assessmentCopy.ts +5 -0
  87. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  88. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  89. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  90. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  91. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  92. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  93. package/src/components/diagnose/investigationCase.ts +33 -1
  94. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  95. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  96. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
  97. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  98. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  99. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  100. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  101. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  102. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  103. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  104. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  105. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  106. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  107. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  108. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  109. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  110. package/src/components/diagnose/investigationEvidence/types.ts +7 -0
  111. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  112. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  113. package/src/components/diagnose/investigationFocus.ts +132 -0
  114. package/src/components/diagnose/investigationState.ts +28 -0
  115. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  116. package/src/components/diagnose/lastInvestigation.ts +58 -0
  117. package/src/components/diagnose/launch.test.ts +125 -1
  118. package/src/components/diagnose/launch.ts +57 -10
  119. package/src/components/diagnose/parts.test.tsx +20 -0
  120. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  121. package/src/components/diagnose/questionSuggestions.ts +150 -0
  122. package/src/components/diagnose/storyParts.test.tsx +13 -0
  123. package/src/components/diagnose/target.test.ts +143 -2
  124. package/src/components/diagnose/target.ts +109 -7
  125. package/src/components/diagnose/testdata/story-runs.json +474 -0
  126. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  127. package/src/components/diagnose/verdictText.test.tsx +87 -0
  128. package/src/components/diagnose/verdictText.ts +68 -0
  129. package/src/components/execution/BatchExecutionView.tsx +24 -11
  130. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  131. package/src/components/execution/JobSetAdmission.tsx +18 -3
  132. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  133. package/src/components/execution/runState.test.ts +14 -0
  134. package/src/components/execution/runState.ts +8 -0
  135. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  136. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  137. package/src/components/gitops/GitOpsView.tsx +86 -17
  138. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  139. package/src/components/gitops/destination-toast.test.ts +1 -1
  140. package/src/components/gitops/destination-toast.ts +2 -2
  141. package/src/components/home/ClusterHealthCard.tsx +13 -39
  142. package/src/components/home/HomeAgentBlock.test.tsx +141 -0
  143. package/src/components/home/HomeAgentBlock.tsx +103 -0
  144. package/src/components/home/HomeDiagramCard.tsx +47 -0
  145. package/src/components/home/HomeView.tsx +86 -47
  146. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  147. package/src/components/home/MCPSetupDialog.tsx +30 -5
  148. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  149. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  150. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  151. package/src/components/home/RadarVersionLine.tsx +3 -28
  152. package/src/components/home/TopologyPreview.test.tsx +73 -0
  153. package/src/components/home/TopologyPreview.tsx +120 -233
  154. package/src/components/home/TrafficSummary.test.tsx +63 -0
  155. package/src/components/home/TrafficSummary.tsx +135 -138
  156. package/src/components/home/mcpToolCatalog.ts +23 -10
  157. package/src/components/issues/IssuesPane.test.ts +11 -0
  158. package/src/components/issues/IssuesPane.tsx +15 -5
  159. package/src/components/issues/uncheckedSources.test.ts +20 -1
  160. package/src/components/issues/uncheckedSources.ts +18 -0
  161. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  162. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  163. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  164. package/src/components/kueue/useRelatedReads.ts +205 -0
  165. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  166. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  167. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  168. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  169. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  170. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  171. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  172. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  173. package/src/components/logs/rayClusterPods.ts +32 -0
  174. package/src/components/outageSince.test.ts +21 -0
  175. package/src/components/outageSince.ts +10 -0
  176. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  177. package/src/components/resource/PrometheusCharts.tsx +3 -40
  178. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  179. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  180. package/src/components/resources/crd/host.tsx +14 -0
  181. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  182. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  183. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  184. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  185. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  186. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  187. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  188. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  189. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  190. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  191. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  192. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  193. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  194. package/src/components/traffic/TrafficView.tsx +3 -3
  195. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  196. package/src/components/ui/Omnibar.tsx +47 -3
  197. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  198. package/src/components/ui/RadarOmnibar.tsx +11 -0
  199. package/src/components/ui/command-items-crd.test.tsx +23 -0
  200. package/src/components/ui/command-items.ts +2 -1
  201. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  202. package/src/components/useContextSwitchFlow.tsx +21 -4
  203. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  204. package/src/components/whats-new/WhatsNew.tsx +5 -1
  205. package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
  206. package/src/components/whats-new/releaseNotes.ts +136 -4
  207. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  208. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  209. package/src/components/workload/WorkloadView.test.ts +10 -1
  210. package/src/components/workload/WorkloadView.tsx +85 -98
  211. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  212. package/src/components/workload/issueResourceOpener.ts +17 -0
  213. package/src/context/ConnectionContext.tsx +133 -60
  214. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  215. package/src/context/ContextSwitchContext.tsx +14 -1
  216. package/src/context/DiagnoseCustomization.tsx +3 -0
  217. package/src/context/clusterConnected.ts +10 -0
  218. package/src/contexts/CapabilitiesContext.tsx +6 -4
  219. package/src/hooks/useAgentSignin.test.tsx +190 -0
  220. package/src/hooks/useAgentSignin.ts +160 -0
  221. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  222. package/src/hooks/useElementSize.ts +30 -0
  223. package/src/integrations/resourceHost.test.tsx +1 -0
  224. package/src/integrations/resourceHost.ts +5 -1
  225. package/src/integrations/resourceHosts.test.tsx +21 -4
  226. package/src/integrations/resourceHosts.tsx +12 -0
  227. package/src/main.tsx +5 -0
  228. package/src/utils/related-findings.ts +46 -0
@@ -1,22 +1,33 @@
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 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('collect_application_evidence')
20
31
  expect(html).not.toContain('in_cluster')
21
32
  expect(html).toContain('Read-only mode blocks write tools')
22
33
  } finally {
@@ -31,7 +42,7 @@ describe('MCP setup in read-only mode', () => {
31
42
  expect(html).toContain('exec_pod')
32
43
  expect(html).toContain('is disabled')
33
44
  expect(html).toContain('--mcp-exec-tools')
34
- expect(html).toContain(`${MCP_TOOL_CATALOG.length - 1} tools`)
45
+ expect(html).toContain(`${MCP_TOOL_CATALOG.length - 2} tools`)
35
46
  })
36
47
 
37
48
  it('does not suggest an unsupported flag when the capability is absent', () => {
@@ -43,13 +54,92 @@ describe('MCP setup in read-only mode', () => {
43
54
  it('shows exec and counts it only when enabled', () => {
44
55
  const html = renderToStaticMarkup(<MCPSetupDialog open execTools mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
45
56
  expect(html).toContain('exec_pod')
46
- expect(html).toContain(`${MCP_TOOL_CATALOG.length} tools`)
57
+ expect(html).toContain(`${MCP_TOOL_CATALOG.length - 1} tools`)
47
58
  expect(html.indexOf('exec_pod')).toBeGreaterThan(html.indexOf('get_workload_logs'))
48
59
  })
49
60
 
50
61
  it('hides exec in read-only mode even if exec is requested', () => {
51
62
  const html = renderToStaticMarkup(<MCPSetupDialog open readOnly execTools mcpUrl={mcpEndpointUrl(true)} onClose={() => {}} />)
52
63
  expect(html).not.toContain('exec_pod')
53
- expect(html).toContain(`${MCP_TOOL_CATALOG.filter((tool) => !tool.write).length} tools`)
64
+ expect(html).toContain(`${MCP_TOOL_CATALOG.filter((tool) => !tool.write && !tool.localOnly).length} tools`)
65
+ })
66
+
67
+ it('keeps the full catalog in default mode', () => {
68
+ const html = renderToStaticMarkup(<MCPSetupDialog open applicationEvidenceAvailable mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
69
+ expect(html).toContain('apply_resource')
70
+ expect(html).toContain('in_cluster')
71
+ expect(html).toContain('collect_application_evidence')
72
+ })
73
+
74
+ it('hides local-only tools unless the server advertises availability', () => {
75
+ const html = renderToStaticMarkup(<MCPSetupDialog open mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
76
+ expect(html).toContain('apply_resource')
77
+ expect(html).not.toContain('collect_application_evidence')
78
+ })
79
+ })
80
+
81
+ describe('MCP setup prompt tip', () => {
82
+ it('tips to name Radar under the client setups, as plain text, without the in-Radar link when no handler is given', () => {
83
+ const host = document.createElement('div')
84
+ host.innerHTML = renderToStaticMarkup(<MCPSetupDialog open mcpUrl={mcpEndpointUrl()} onClose={() => {}} />)
85
+ const tip = [...host.querySelectorAll('p')].find((p) => p.textContent?.startsWith('Tip:'))
86
+ expect(tip?.textContent).toBe(
87
+ "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.",
88
+ )
89
+ expect(tip!.querySelector('code.inline-code')?.textContent).toBe("Use Radar to find what's broken in my cluster and why.")
90
+ expect(tip!.querySelector('button, pre')).toBeNull()
91
+ expect(tip!.nextElementSibling).toBeNull()
92
+ const html = host.innerHTML
93
+ expect(html.indexOf('Tip:')).toBeGreaterThan(html.indexOf('Connect your AI tool'))
94
+ expect(html.indexOf('Tip:')).toBeLessThan(html.indexOf('list_namespaces'))
95
+ expect(html).not.toContain('investigate from Radar itself')
96
+ })
97
+
98
+ it('closes the dialog, then opens the composer from the in-Radar link', () => {
99
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
100
+ const calls: string[] = []
101
+ const host = document.createElement('div')
102
+ document.body.appendChild(host)
103
+ const root = createRoot(host)
104
+ try {
105
+ act(() => root.render(
106
+ <MCPSetupDialog
107
+ open
108
+ mcpUrl={mcpEndpointUrl()}
109
+ onClose={() => calls.push('close')}
110
+ onInvestigate={() => calls.push('investigate')}
111
+ />,
112
+ ))
113
+ const link = [...host.querySelectorAll('button')].find((b) => /investigate from Radar itself/.test(b.textContent ?? ''))
114
+ expect(link).toBeTruthy()
115
+ act(() => link!.click())
116
+ expect(calls).toEqual(['close', 'investigate'])
117
+ } finally {
118
+ act(() => root.unmount())
119
+ host.remove()
120
+ }
121
+ })
122
+
123
+ it.each([
124
+ [true, 'Copied'],
125
+ [false, 'Copy to clipboard'],
126
+ ])('copies the endpoint and shows the tick only when the copy worked (ok=%s)', async (ok, label) => {
127
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
128
+ clipboard.ok = ok
129
+ clipboard.copied = []
130
+ const host = document.createElement('div')
131
+ document.body.appendChild(host)
132
+ const root = createRoot(host)
133
+ try {
134
+ act(() => root.render(<MCPSetupDialog open mcpUrl={mcpEndpointUrl()} onClose={() => {}} />))
135
+ const endpoint = [...host.querySelectorAll('code')].find((c) => c.textContent === mcpEndpointUrl())!
136
+ const copy = endpoint.closest('.relative')!.querySelector('button')!
137
+ await act(async () => copy.click())
138
+ expect(clipboard.copied).toEqual(ok ? [mcpEndpointUrl()] : [])
139
+ expect(copy.getAttribute('aria-label')).toBe(label)
140
+ } finally {
141
+ act(() => root.unmount())
142
+ host.remove()
143
+ }
54
144
  })
55
145
  })
@@ -4,28 +4,39 @@ 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
+ applicationEvidenceAvailable?: boolean
13
17
  mcpUrl: string
18
+ /** Opens Radar's own investigation composer. Omit where investigations can't run. */
19
+ onInvestigate?: () => void
14
20
  }
15
21
 
16
22
  function CopyButton({ text }: { text: string }) {
17
23
  const [copied, setCopied] = useState(false)
18
24
 
19
25
  const handleCopy = () => {
20
- navigator.clipboard.writeText(text)
21
- setCopied(true)
22
- setTimeout(() => setCopied(false), 2000)
26
+ // Plain-HTTP origins and denied permission reject the async Clipboard API;
27
+ // copyText falls back, and the tick must not claim a copy that didn't happen.
28
+ void copyText(text).then((ok) => {
29
+ if (!ok) return
30
+ setCopied(true)
31
+ setTimeout(() => setCopied(false), 2000)
32
+ })
23
33
  }
24
34
 
25
35
  return (
26
36
  <Tooltip content="Copy to clipboard" position="left" wrapperClassName="absolute top-2 right-2">
27
37
  <button
28
38
  onClick={handleCopy}
39
+ aria-label={copied ? 'Copied' : 'Copy to clipboard'}
29
40
  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
41
  >
31
42
  {copied ? <Check className="w-3.5 h-3.5 text-green-500" /> : <Copy className="w-3.5 h-3.5" />}
@@ -45,7 +56,7 @@ function CodeBlock({ children }: { children: string }) {
45
56
  )
46
57
  }
47
58
 
48
- export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTools }: MCPSetupDialogProps) {
59
+ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTools, onInvestigate, applicationEvidenceAvailable = false }: MCPSetupDialogProps) {
49
60
  const dialogRef = useRef<HTMLDivElement>(null)
50
61
  const [isDesktop, setIsDesktop] = useState(false)
51
62
  const [portPinned, setPortPinned] = useState(false)
@@ -119,7 +130,7 @@ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTo
119
130
  const currentPort = Number(window.location.port) || 80
120
131
 
121
132
  const tools = MCP_TOOL_CATALOG
122
- .filter((tool) => (!readOnly || !tool.write) && (tool.name !== 'exec_pod' || execTools))
133
+ .filter((tool) => (!readOnly || !tool.write) && (tool.name !== 'exec_pod' || execTools) && (!tool.localOnly || (!readOnly && applicationEvidenceAvailable)))
123
134
  .map((tool) => readOnly && tool.name === 'diagnose'
124
135
  ? { ...tool, params: tool.params.filter((param) => param.arg !== 'in_cluster') }
125
136
  : tool)
@@ -321,6 +332,20 @@ export function MCPSetupDialog({ open, onClose, mcpUrl, readOnly = false, execTo
321
332
  </div>
322
333
  </Disclosure>
323
334
  ))}
335
+
336
+ <p className="pt-1 text-xs text-theme-text-tertiary leading-relaxed">
337
+ <span className="font-medium text-theme-text-secondary">Tip:</span> name Radar in your prompt so your
338
+ agent uses Radar instead of kubectl, e.g. <code className="inline-code">{MCP_EXAMPLE_PROMPT}</code>
339
+ </p>
340
+ {onInvestigate && (
341
+ <button
342
+ type="button"
343
+ onClick={() => { onClose(); onInvestigate() }}
344
+ className="text-xs text-accent-text hover:underline underline-offset-2"
345
+ >
346
+ Or investigate from Radar itself →
347
+ </button>
348
+ )}
324
349
  </div>
325
350
 
326
351
  {/* 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' }]
@@ -142,18 +142,4 @@ describe('RadarVersionLine', () => {
142
142
  expect(html).toContain('Open the in-cluster upgrade instructions and apply the change through GitOps')
143
143
  expect(html).not.toContain('Open it to upgrade through GitOps')
144
144
  })
145
-
146
- it('offers What\'s new only when the host can open it', () => {
147
- const upToDate = { ...version, latestVersion: '1.2.3', updateAvailable: false }
148
- expect(renderToString(<RadarVersionLine version={upToDate} />)).not.toContain('What&#x27;s new')
149
- expect(renderToString(<RadarVersionLine version={upToDate} onShowWhatsNew={() => {}} />)).toContain('What&#x27;s new')
150
- expect(renderToString(<RadarVersionLine version={version} onShowWhatsNew={() => {}} />)).toContain('What&#x27;s new')
151
- })
152
-
153
- it('hides upgrade guidance when the host handles upgrades elsewhere', () => {
154
- const html = renderToString(<RadarVersionLine version={version} showUpgrade={false} onShowWhatsNew={() => {}} />)
155
- expect(html).toContain('v1.2.3')
156
- expect(html).not.toContain('available')
157
- expect(html).toContain('What&#x27;s new')
158
- })
159
145
  })
@@ -1,4 +1,4 @@
1
- import { ArrowUpCircle, Megaphone } from 'lucide-react'
1
+ import { ArrowUpCircle } from 'lucide-react'
2
2
  import { gitOpsRouteForResource } from '@skyhook-io/k8s-ui'
3
3
  import type { CloudConnectSelf, VersionInfo } from '../../api/client'
4
4
  import {
@@ -14,10 +14,6 @@ interface RadarVersionLineProps {
14
14
  managerLoading?: boolean
15
15
  onNavigateToHelmRelease?: (namespace: string, release: string) => void
16
16
  onNavigateToGitOps?: (path: string) => void
17
- // Local installs upgrade through the update notification, and this line's
18
- // upgrade link points at in-cluster instructions.
19
- showUpgrade?: boolean
20
- onShowWhatsNew?: () => void
21
17
  }
22
18
 
23
19
  function displayVersion(version: string): string {
@@ -30,33 +26,13 @@ export function RadarVersionLine({
30
26
  managerLoading = false,
31
27
  onNavigateToHelmRelease,
32
28
  onNavigateToGitOps,
33
- showUpgrade: upgradeAllowed = true,
34
- onShowWhatsNew,
35
29
  }: RadarVersionLineProps) {
36
30
  const latestVersion = version.latestVersion
37
31
  const updateStatus = getVersionUpdateStatus(version.currentVersion, latestVersion)
38
- const showUpgrade = upgradeAllowed && version.updateAvailable && !!latestVersion && updateStatus.tier !== 'none'
39
- const whatsNew = onShowWhatsNew && (
40
- <span className="inline-flex items-center gap-1">
41
- <span aria-hidden>·</span>
42
- <button
43
- type="button"
44
- onClick={onShowWhatsNew}
45
- className="inline-flex items-center gap-1 text-accent-text hover:text-accent transition-colors"
46
- >
47
- <Megaphone className="h-3.5 w-3.5 shrink-0" aria-hidden />
48
- What's new
49
- </button>
50
- </span>
51
- )
32
+ const showUpgrade = version.updateAvailable && !!latestVersion && updateStatus.tier !== 'none'
52
33
 
53
34
  if (!showUpgrade) {
54
- return (
55
- <span className="inline-flex flex-wrap items-center gap-x-1">
56
- <span>Radar <span className="font-mono">{displayVersion(version.currentVersion)}</span></span>
57
- {whatsNew}
58
- </span>
59
- )
35
+ return <span>Radar <span className="font-mono">{displayVersion(version.currentVersion)}</span></span>
60
36
  }
61
37
 
62
38
  const controller = manager?.controllerRef
@@ -135,7 +111,6 @@ export function RadarVersionLine({
135
111
  {action}
136
112
  </Tooltip>
137
113
  </span>
138
- {whatsNew}
139
114
  </span>
140
115
  )
141
116
  }
@@ -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
+ })