@skyhook-io/radar-app 1.17.1 → 1.18.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 (146) hide show
  1. package/README.md +6 -0
  2. package/package.json +10 -11
  3. package/src/App.tsx +36 -36
  4. package/src/api/client.gitops-destination.test.tsx +55 -0
  5. package/src/api/client.gitopsPoll.test.ts +99 -0
  6. package/src/api/client.helmPreview.test.tsx +48 -0
  7. package/src/api/client.resource-list.test.ts +76 -0
  8. package/src/api/client.resourceAvailability.test.ts +24 -0
  9. package/src/api/client.ts +396 -105
  10. package/src/api/client.workloadRuns.test.ts +53 -0
  11. package/src/api/config.test.ts +23 -1
  12. package/src/api/config.ts +7 -3
  13. package/src/api/diagnose.ts +4 -1
  14. package/src/api/drain-plan.test.ts +70 -40
  15. package/src/api/policy.ts +5 -5
  16. package/src/api/quotas.ts +9 -20
  17. package/src/api/radarFeatures.ts +3 -0
  18. package/src/api/resourceLists.test.ts +84 -0
  19. package/src/api/resourceLists.ts +71 -0
  20. package/src/api/traffic.scope.render.test.tsx +60 -0
  21. package/src/api/traffic.ts +3 -1
  22. package/src/components/cnpg/CNPGSummaryHost.tsx +4 -3
  23. package/src/components/cnpg/CNPGView.tsx +1 -0
  24. package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
  25. package/src/components/compare/CompareViewRoute.tsx +5 -1
  26. package/src/components/compare/useCompareCandidates.ts +1 -1
  27. package/src/components/compare/useCompareLauncher.tsx +4 -2
  28. package/src/components/diagnose/DiagnoseSurface.tsx +3 -3
  29. package/src/components/diagnose/InvestigationChangesEvidence.test.tsx +352 -0
  30. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +101 -0
  31. package/src/components/diagnose/InvestigationView.tsx +2 -1
  32. package/src/components/diagnose/StoryExcerpt.tsx +24 -5
  33. package/src/components/diagnose/investigationEvidence/adapters/changes.test.ts +123 -0
  34. package/src/components/diagnose/investigationEvidence/adapters/changes.ts +192 -3
  35. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +73 -51
  36. package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
  37. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +64 -2
  38. package/src/components/diagnose/investigationEvidence/adapters/resource.test.ts +37 -0
  39. package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
  40. package/src/components/diagnose/investigationEvidence/adapters/testdata/get-changes-created.json +323 -0
  41. package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
  42. package/src/components/diagnose/investigationEvidence/bodies/streams.tsx +144 -15
  43. package/src/components/diagnose/investigationEvidence/builder.ts +13 -1
  44. package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
  45. package/src/components/diagnose/investigationEvidence/observations.ts +21 -0
  46. package/src/components/diagnose/investigationEvidence/parse.ts +57 -1
  47. package/src/components/diagnose/investigationEvidence/projection.test.ts +131 -1
  48. package/src/components/diagnose/investigationEvidence/types.ts +26 -0
  49. package/src/components/diagnose/investigationEvidencePresentation.test.ts +18 -0
  50. package/src/components/diagnose/investigationState.test.ts +36 -1
  51. package/src/components/diagnose/investigationState.ts +8 -0
  52. package/src/components/diagnose/launch.ts +2 -2
  53. package/src/components/diagnose/toolCallLabel.test.ts +9 -0
  54. package/src/components/diagnose/toolCallLabel.ts +2 -0
  55. package/src/components/dock/BottomDock.tsx +6 -3
  56. package/src/components/dock/WorkloadLogsTab.tsx +3 -0
  57. package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
  58. package/src/components/execution/BatchExecutionView.render.test.tsx +29 -1
  59. package/src/components/execution/BatchExecutionView.tsx +28 -11
  60. package/src/components/execution/cluster-template-runs.render.test.tsx +42 -0
  61. package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
  62. package/src/components/gitops/GitOpsView.tsx +69 -40
  63. package/src/components/gitops/useDestinationCluster.ts +2 -1
  64. package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
  65. package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
  66. package/src/components/helm/ChartBrowser.tsx +5 -4
  67. package/src/components/helm/HelmReleaseDrawer.tsx +139 -55
  68. package/src/components/helm/HelmReleaseNotes.test.tsx +42 -0
  69. package/src/components/helm/HelmReleaseNotes.tsx +26 -0
  70. package/src/components/helm/OwnedResources.tsx +2 -2
  71. package/src/components/helm/TrackChartSourceDialog.render.test.tsx +295 -50
  72. package/src/components/helm/TrackChartSourceDialog.test.ts +3 -2
  73. package/src/components/helm/TrackChartSourceDialog.tsx +614 -85
  74. package/src/components/helm/ValuesDiffPreview.tsx +4 -1
  75. package/src/components/home/ClusterHealthCard.tsx +4 -4
  76. package/src/components/home/CostCard.test.tsx +100 -0
  77. package/src/components/home/CostCard.tsx +2 -2
  78. package/src/components/home/HelmSummary.tsx +2 -2
  79. package/src/components/home/HomeView.tsx +15 -6
  80. package/src/components/home/MCPSetupDialog.test.tsx +30 -0
  81. package/src/components/home/MCPSetupDialog.tsx +13 -6
  82. package/src/components/home/ProblemsPanel.test.tsx +1 -0
  83. package/src/components/home/mcpToolCatalog.ts +28 -2
  84. package/src/components/issues/IssuesPane.render.test.tsx +21 -0
  85. package/src/components/issues/IssuesPane.tsx +31 -7
  86. package/src/components/issues/UncheckedSourceHelp.test.tsx +42 -0
  87. package/src/components/issues/UncheckedSourceHelp.tsx +24 -0
  88. package/src/components/issues/uncheckedSources.test.ts +43 -0
  89. package/src/components/issues/uncheckedSources.ts +58 -5
  90. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +4 -2
  91. package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
  92. package/src/components/resource/PrometheusCharts.tsx +2 -2
  93. package/src/components/resources/ImageFilesystemModal.test.tsx +68 -0
  94. package/src/components/resources/ImageFilesystemModal.tsx +11 -4
  95. package/src/components/resources/PodFilesystemModal.tsx +2 -2
  96. package/src/components/resources/ResourcesView.scope.render.test.tsx +58 -0
  97. package/src/components/resources/ResourcesView.tsx +46 -69
  98. package/src/components/resources/renderers/FluxHelmReleaseRenderer.test.tsx +111 -0
  99. package/src/components/resources/renderers/FluxHelmReleaseRenderer.tsx +67 -0
  100. package/src/components/resources/renderers/KyvernoPolicyCoverage.scope.render.test.tsx +64 -0
  101. package/src/components/resources/renderers/KyvernoPolicyCoverage.tsx +6 -7
  102. package/src/components/resources/renderers/PodRenderer.tsx +4 -1
  103. package/src/components/settings/MyPermissionsDialog.tsx +12 -9
  104. package/src/components/settings/SettingsDialog.tsx +21 -15
  105. package/src/components/traffic/TrafficFilterSidebar.test.tsx +77 -0
  106. package/src/components/traffic/TrafficFilterSidebar.tsx +42 -31
  107. package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
  108. package/src/components/traffic/TrafficSourcePill.tsx +111 -0
  109. package/src/components/traffic/TrafficView.tsx +21 -67
  110. package/src/components/traffic/trafficFilters.test.ts +20 -1
  111. package/src/components/traffic/trafficFilters.ts +13 -0
  112. package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
  113. package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
  114. package/src/components/ui/Omnibar.note.test.tsx +141 -0
  115. package/src/components/ui/Omnibar.tsx +89 -14
  116. package/src/components/ui/RadarOmnibar.test.tsx +183 -0
  117. package/src/components/ui/RadarOmnibar.tsx +38 -4
  118. package/src/components/ui/Toast.tsx +1 -1
  119. package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
  120. package/src/components/ui/UpdateNotification.test.tsx +2 -1
  121. package/src/components/ui/UpdateNotification.tsx +29 -5
  122. package/src/components/ui/omnibar-match.test.ts +37 -0
  123. package/src/components/ui/omnibar-match.ts +23 -0
  124. package/src/components/ui/searchCoverage.fixtures.ts +16 -0
  125. package/src/components/ui/searchCoverageNote.test.ts +245 -0
  126. package/src/components/ui/searchCoverageNote.ts +222 -0
  127. package/src/components/whats-new/WhatsNew.test.ts +10 -0
  128. package/src/components/whats-new/WhatsNew.tsx +5 -4
  129. package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
  130. package/src/components/whats-new/releaseNotes.ts +57 -5
  131. package/src/components/workload/CronJobSchedulingEvidence.test.tsx +35 -0
  132. package/src/components/workload/CronJobSchedulingEvidence.tsx +37 -0
  133. package/src/components/workload/NodeDrainStatus.test.tsx +253 -0
  134. package/src/components/workload/NodeDrainStatus.tsx +55 -0
  135. package/src/components/workload/WorkloadView.tsx +43 -5
  136. package/src/context/ConnectionContext.test.ts +27 -1
  137. package/src/context/ConnectionContext.tsx +17 -7
  138. package/src/hooks/useResourceCounts.ts +2 -0
  139. package/src/index.css +2 -4
  140. package/src/index.ts +7 -0
  141. package/src/integrations/resourceHosts.test.tsx +1 -0
  142. package/src/integrations/resourceHosts.tsx +2 -0
  143. package/src/utils/artifacthub.test.ts +18 -0
  144. package/src/utils/artifacthub.ts +9 -0
  145. package/src/utils/navigation.ts +14 -0
  146. package/src/utils/wails-clipboard.ts +4 -2
@@ -21,12 +21,13 @@ vi.mock('../../api/client', () => ({
21
21
  }))
22
22
 
23
23
  import { UpdateNotification } from './UpdateNotification'
24
+ import { ToastProvider } from './Toast'
24
25
 
25
26
  function renderNotification() {
26
27
  const client = new QueryClient()
27
28
  return renderToString(
28
29
  <QueryClientProvider client={client}>
29
- <UpdateNotification />
30
+ <ToastProvider><UpdateNotification /></ToastProvider>
30
31
  </QueryClientProvider>,
31
32
  )
32
33
  }
@@ -9,7 +9,9 @@ import {
9
9
  useDesktopUpdateStatus,
10
10
  useApplyDesktopUpdate,
11
11
  } from '../../api/client'
12
- import type { DesktopUpdateState } from '../../api/client'
12
+ import type { DesktopUpdateState, VersionInfo } from '../../api/client'
13
+ import { getApiBase } from '../../api/config'
14
+ import { useToast } from './Toast'
13
15
  import { WithTooltip } from './Tooltip'
14
16
  import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
15
17
  import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
@@ -35,6 +37,7 @@ export function UpdateNotification({ placement = 'floating' }: { placement?: 'fl
35
37
  const triggerRef = useRef<HTMLButtonElement>(null)
36
38
  const panelId = useId()
37
39
  const queryClient = useQueryClient()
40
+ const { showToast } = useToast()
38
41
  const { data: capabilities } = useCapabilities()
39
42
  const deploymentMode = capabilities ? (capabilities.deployment?.mode ?? 'local') : undefined
40
43
  const { data: versionInfo } = useVersionCheck()
@@ -58,17 +61,38 @@ export function UpdateNotification({ placement = 'floating' }: { placement?: 'fl
58
61
  return () => document.removeEventListener('pointerdown', closeOutside)
59
62
  }, [expanded])
60
63
 
61
- // Listen for "Check for Updates" menu item in desktop app.
62
64
  useEffect(() => {
65
+ if (inSettings) return
66
+ const id = 'radar-manual-update-check'
63
67
  const handler = () => {
68
+ showToast('Checking for updates…', { id, type: 'info', duration: 0 })
69
+ }
70
+ const resultHandler = (event: Event) => {
71
+ const info = (event as CustomEvent<VersionInfo>).detail
72
+ if (info.error) {
73
+ showToast('Could not check for updates', { id, type: 'error', detail: info.error })
74
+ return
75
+ }
76
+ void queryClient.cancelQueries({ queryKey: ['version-check', getApiBase()], exact: true })
64
77
  setDismissed(false)
65
78
  try { localStorage.removeItem(DISMISSED_KEY) } catch { /* ignore */ }
66
- queryClient.invalidateQueries({ queryKey: ['version-check'] })
79
+ queryClient.setQueryData(['version-check', getApiBase()], info)
80
+ if (info.updateAvailable) {
81
+ showToast(`Radar ${info.latestVersion} is available`, { id, type: 'info' })
82
+ } else if (info.buildChannel === 'development') {
83
+ showToast(`Latest Radar release: ${info.latestVersion}`, { id, type: 'info', detail: 'You are running a development build.' })
84
+ } else {
85
+ showToast("You're up to date", { id, type: 'success', detail: `Radar ${info.currentVersion}` })
86
+ }
67
87
  }
68
88
 
69
89
  window.addEventListener('radar:check-for-updates', handler)
70
- return () => window.removeEventListener('radar:check-for-updates', handler)
71
- }, [queryClient])
90
+ window.addEventListener('radar:update-check-result', resultHandler)
91
+ return () => {
92
+ window.removeEventListener('radar:check-for-updates', handler)
93
+ window.removeEventListener('radar:update-check-result', resultHandler)
94
+ }
95
+ }, [queryClient, inSettings, showToast])
72
96
 
73
97
  // Log version check errors for debugging
74
98
  useEffect(() => {
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { contentMatchLabel, partialSearchNotices } from './omnibar-match'
3
+
4
+ const site = (s: string) => ({ token: 't', site: s, score: 12 })
5
+
6
+ describe('contentMatchLabel', () => {
7
+ it('names a match inside Trivy findings', () => {
8
+ expect(contentMatchLabel([site('content:report.vulnerabilities[3]')])).toBe('in findings')
9
+ })
10
+ it('keeps "in spec" for other content', () => {
11
+ expect(contentMatchLabel([site('content:spec.template.spec.containers[0].env[1].value')])).toBe('in spec')
12
+ expect(contentMatchLabel([site('content:report.checks[0]'), site('content:spec.x')])).toBe('in spec')
13
+ })
14
+ it('is empty when any token matched identity', () => {
15
+ expect(contentMatchLabel([site('content:report.vulnerabilities[0]'), site('name')])).toBe('')
16
+ expect(contentMatchLabel([])).toBe('')
17
+ expect(contentMatchLabel(undefined)).toBe('')
18
+ })
19
+ })
20
+
21
+ describe('partialSearchNotices', () => {
22
+ it('says why each part of the search is missing', () => {
23
+ expect(partialSearchNotices({ access_incomplete: true })).toEqual([
24
+ "Couldn't confirm your access to scan reports in some namespaces, so they were left out. Search again to check more.",
25
+ ])
26
+ expect(partialSearchNotices({ incomplete_findings: 'time_limit' })).toEqual([
27
+ "Search ran out of time before checking every scan report's findings. Narrow with ns: to cover the rest.",
28
+ ])
29
+ })
30
+ it('shows both causes when both happened', () => {
31
+ expect(partialSearchNotices({ access_incomplete: true, incomplete_findings: 'time_limit' })).toHaveLength(2)
32
+ })
33
+ it('is empty for a whole result or an older Radar', () => {
34
+ expect(partialSearchNotices({})).toEqual([])
35
+ expect(partialSearchNotices(undefined)).toEqual([])
36
+ })
37
+ })
@@ -0,0 +1,23 @@
1
+ import type { SearchMatchedField } from '../../api/client'
2
+
3
+ // contentMatchLabel names where a hit matched when every token landed in the
4
+ // object's content rather than its name, kind or namespace. Trivy Operator
5
+ // reports keep their findings under `report`, not a spec.
6
+ export function contentMatchLabel(matched: SearchMatchedField[] | undefined): string {
7
+ if (!matched?.length || !matched.every((m) => m.site.startsWith('content:'))) return ''
8
+ return matched.every((m) => m.site.startsWith('content:report.')) ? 'in findings' : 'in spec'
9
+ }
10
+
11
+ // partialSearchNotices explain a result the server says is incomplete, so a
12
+ // missing CVE doesn't read as "not affected". One line per cause; empty when
13
+ // the search was whole.
14
+ export function partialSearchNotices(data: { incomplete_findings?: string; access_incomplete?: boolean } | undefined): string[] {
15
+ const out: string[] = []
16
+ if (data?.access_incomplete) {
17
+ out.push("Couldn't confirm your access to scan reports in some namespaces, so they were left out. Search again to check more.")
18
+ }
19
+ if (data?.incomplete_findings) {
20
+ out.push("Search ran out of time before checking every scan report's findings. Narrow with ns: to cover the rest.")
21
+ }
22
+ return out
23
+ }
@@ -0,0 +1,16 @@
1
+ import type { SearchCoverage } from '@skyhook-io/k8s-ui/types/read-coverage'
2
+ import type { SearchCoverageEntry } from './searchCoverageNote'
3
+
4
+ /** The wire coverage that flattens back to entries, for tests: each gap lists
5
+ * one axis and gives the other as an extent, as Radar sends it. */
6
+ export function coverageOf(entries: SearchCoverageEntry[]): SearchCoverage {
7
+ return {
8
+ status: entries.length ? 'partial' : 'complete',
9
+ gaps: entries.map((e) => {
10
+ if (e.kind !== '*') return { code: e.reason, kinds: { count: 1, names: [{ kind: e.kind, group: e.group || undefined }] }, namespaces: { extent: 'all' } }
11
+ if (e.namespaces) return { code: e.reason, kinds: { extent: 'all' }, namespaces: { count: e.namespaces.length, names: e.namespaces } }
12
+ if (e.count) return { code: e.reason, kinds: { count: e.count }, namespaces: { extent: 'all' } }
13
+ return { code: e.reason, kinds: { extent: 'unknown' }, namespaces: { extent: 'all' } }
14
+ }),
15
+ }
16
+ }
@@ -0,0 +1,245 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { PENDING_RETRY_BUDGET_MS, kindPluralLabel, searchCoverageNote as noteFor, type SearchCoverageEntry } from './searchCoverageNote'
3
+ import { coverageOf } from './searchCoverage.fixtures'
4
+
5
+ const searchCoverageNote = (entries: SearchCoverageEntry[] | undefined, opts: Parameters<typeof noteFor>[1]) => noteFor(entries && coverageOf(entries), opts)
6
+
7
+ const entry = (kind: string, reason: string, group = '', count?: number): SearchCoverageEntry => ({ kind, group, reason, count })
8
+
9
+ describe('searchCoverageNote', () => {
10
+ it('explains an empty search narrowed by kind collection, without an action', () => {
11
+ expect(noteFor({ status: 'complete', narrowedBy: ['kind_collection'], gaps: [] }, { hits: [] })).toEqual({
12
+ text: "Radar doesn't watch every kind; search kind:<name> to include one.",
13
+ })
14
+ expect(noteFor({ status: 'complete', narrowedBy: ['kind_collection'], gaps: [] }, { hits: [{ kind: 'Pod' }] })).toBeUndefined()
15
+ expect(noteFor({ status: 'complete', gaps: [] }, { hits: [] })).toBeUndefined()
16
+ })
17
+
18
+ it.each(['user_access', 'namespace_pin'] as const)('keeps empty %s narrowing quiet', (narrowing) => {
19
+ expect(noteFor({ status: 'complete', narrowedBy: [narrowing], gaps: [] }, { hits: [] })).toBeUndefined()
20
+ })
21
+
22
+ it('explains namespace collection narrowing with or without hits, including combined narrowing', () => {
23
+ for (const narrowedBy of [['namespace_collection'], ['kind_collection', 'namespace_collection'], ['user_access', 'namespace_collection']] as const) {
24
+ const coverage: Parameters<typeof noteFor>[0] = { status: 'complete', narrowedBy: [...narrowedBy], gaps: [] }
25
+ const note = { text: "Radar collects some kinds only in some namespaces; matches for them elsewhere won't show." }
26
+ expect(noteFor(coverage, { hits: [] })).toEqual(note)
27
+ expect(noteFor(coverage, { hits: [{ kind: 'Pod' }] })).toEqual(note)
28
+ }
29
+ })
30
+
31
+ it('suggests a namespace only for a whole namespaced-kind denial', () => {
32
+ const kinds = { count: 1, names: [{ kind: 'Secret' }] }
33
+ expect(noteFor({ status: 'partial', gaps: [{ code: 'user_forbidden', kinds, namespaces: { extent: 'all' } }] }, { query: 'kind:Secret' })?.text)
34
+ .toBe("Your access doesn't include all Secrets. Try narrowing with ns:<namespace>.")
35
+ expect(noteFor({ status: 'partial', gaps: [{ code: 'user_forbidden', kinds, namespaces: { extent: 'unknown' } }] }, {})?.text)
36
+ .toBe("Your access doesn't include all Secrets.")
37
+ expect(noteFor({ status: 'partial', gaps: [{ code: 'user_forbidden', kinds: { count: 1, names: [{ kind: 'Node' }] } }] }, {})?.text)
38
+ .toBe("Your access doesn't include all Nodes.")
39
+ })
40
+
41
+ it('explains a partial namespace without claiming its returned kinds were unsearched', () => {
42
+ const note = noteFor({ status: 'partial', gaps: [{ code: 'radar_namespace_not_collected', kinds: { extent: 'unknown' }, namespaces: { count: 1, names: ['alpha'] } }] }, { hits: [{ kind: 'Pod' }] })
43
+ expect(note?.text).toBe("Some kinds weren't searched in namespace 'alpha': Radar here watches only some namespaces.")
44
+ })
45
+
46
+ it('offers a kind re-check for a broad read error, with an action when supported', () => {
47
+ const failed = [entry('Certificate', 'read_error', 'cert-manager.io')]
48
+ expect(searchCoverageNote(failed, { query: 'renewal' })?.text).toBe("Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check.")
49
+ // Kinds too many to name are counted, with the way to re-check one.
50
+ expect(searchCoverageNote([entry('*', 'read_error', '', 10)], { query: 'renewal' })?.text).toBe("Couldn't read 10 kinds; matches of those kinds may be missing. Search kind:<name> to re-check one.")
51
+ const recheckKind = vi.fn()
52
+ const note = searchCoverageNote(failed, { query: 'renewal', recheckKind })
53
+ expect(note?.text).toBe("Couldn't read Certificate; matches of that kind may be missing. Search")
54
+ expect(note?.action).toMatchObject({ label: 'kind:Certificate', suffix: ' to re-check.', keepOpen: true })
55
+ note?.action?.onSelect()
56
+ expect(recheckKind).toHaveBeenCalledWith('Certificate')
57
+ })
58
+
59
+ it.each(['kind:Certificate renewal', 'K:certificates renewal', 'kind:"Certificate" renewal', '"kind:Certificate" renewal', 'kind:"Certificate'])(
60
+ 'does not suggest naming an already named kind: %s', (query) => {
61
+ expect(searchCoverageNote([entry('Certificate', 'read_error', 'cert-manager.io')], { query, recheckKind: vi.fn() })).toEqual({
62
+ text: "Couldn't read Certificate; matches of that kind may be missing.", action: undefined,
63
+ })
64
+ },
65
+ )
66
+
67
+ it('offers a named-kind re-check for a failed read, unless the query already named it', () => {
68
+ const failed = entry('Certificate', 'read_error', 'cert-manager.io')
69
+ expect(searchCoverageNote([failed], { query: 'renewal' })?.text).toBe("Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check.")
70
+ expect(searchCoverageNote([failed], { query: 'kind:Certificate renewal' })?.text).toBe("Couldn't read Certificate; matches of that kind may be missing.")
71
+ expect(searchCoverageNote([entry('*', 'read_error')], {})?.text).toBe("Couldn't read some kinds; matches of those kinds may be missing.")
72
+ expect(searchCoverageNote([entry('Certificate', 'radar_credentials_rejected')], {})?.action).toBeUndefined()
73
+ })
74
+
75
+ it('uses the first recoverable kind as the example for a folded failure', () => {
76
+ const gaps = [entry('*', 'read_error', '', 4), entry('Certificate', 'read_error'), entry('Issuer', 'read_error')]
77
+ expect(searchCoverageNote(gaps, { query: 'renewal' })?.text).toBe("Couldn't read Certificate, Issuer and 4 more kinds; matches of those kinds may be missing. Search kind:Certificate to re-check.")
78
+ })
79
+
80
+ it('says nothing for an older Radar or a complete search', () => {
81
+ expect(searchCoverageNote(undefined, {})).toBeUndefined()
82
+ expect(searchCoverageNote([], {})).toBeUndefined()
83
+ })
84
+
85
+ it('explains a named kind the caller or Radar cannot read', () => {
86
+ expect(searchCoverageNote([entry('Secret', 'user_forbidden')], {})?.text).toBe("Your access doesn't include all Secrets. Try narrowing with ns:<namespace>.")
87
+ expect(searchCoverageNote([entry('Secret', 'radar_forbidden')], {})?.text).toBe("Radar isn't allowed to read Secrets on this cluster.")
88
+ expect(searchCoverageNote([entry('Role', 'radar_kind_not_collected')], {})?.text).toBe("Radar doesn't watch Roles on this cluster, so they weren't searched.")
89
+ })
90
+
91
+ it('treats an unrecognized kind as not installed or misspelled, unless API groups went undiscovered', () => {
92
+ expect(searchCoverageNote([entry('CiliumNetworkPolicy', 'kind_unknown')], {})?.text).toBe('No kind named CiliumNetworkPolicy here — not installed, or misspelled?')
93
+ expect(searchCoverageNote([entry('Certificate', 'kind_unknown'), entry('*', 'read_error')], {})?.text).toBe("No kind named Certificate found, but some API groups couldn't be read.")
94
+ })
95
+
96
+ it('points an unsearchable kind at its list, as an action when the host can open it', () => {
97
+ const lease = [entry('Lease', 'kind_not_searchable', 'coordination.k8s.io')]
98
+ expect(searchCoverageNote(lease, {})).toEqual({ text: "Leases can't be searched. Open the Leases list instead.", action: undefined })
99
+
100
+ const open = vi.fn()
101
+ const openKindList = vi.fn(() => open)
102
+ const note = searchCoverageNote(lease, { openKindList })
103
+ expect(note?.text).toBe("Leases can't be searched.")
104
+ expect(note?.action?.label).toBe('Open the Leases list instead.')
105
+ expect(openKindList).toHaveBeenCalledWith('Lease', 'coordination.k8s.io')
106
+ note?.action?.onSelect()
107
+ expect(open).toHaveBeenCalledOnce()
108
+ })
109
+
110
+ it('reports loading, then stops promising updates once retries run out', () => {
111
+ const pending = [entry('*', 'kind_sync_pending', '', 37)]
112
+ expect(searchCoverageNote(pending, {})?.text).toBe('Still loading — results may change.')
113
+ expect(searchCoverageNote(pending, { pendingExhausted: true })?.text).toBe('Still loading — try again shortly.')
114
+ })
115
+
116
+ it('does not offer a kind retry for a stalled watch', () => {
117
+ const note = searchCoverageNote([entry('SpStall', 'kind_sync_timed_out', 'stall.sp-live.test')], {})
118
+ expect(note).toEqual({ text: "Couldn't read SpStall; matches of that kind may be missing.", action: undefined })
119
+ })
120
+
121
+ it('names up to three failed kinds and counts the rest', () => {
122
+ const failed = [entry('Certificate', 'kind_sync_timed_out'), entry('Issuer', 'read_error'), entry('*', 'read_error', '', 4)]
123
+ expect(searchCoverageNote(failed, {})?.text).toBe("Couldn't read Certificate, Issuer and 4 more kinds; matches of those kinds may be missing. Search kind:Issuer to re-check.")
124
+ expect(searchCoverageNote([entry('*', 'user_permission_check_failed')], {})?.text).toBe("Couldn't check your access to some kinds.")
125
+ })
126
+
127
+ it('counts same-named kinds of different groups apart', () => {
128
+ const widgets = ['a', 'b', 'c', 'd', 'e'].map((g) => entry('Widget', 'kind_sync_timed_out', `${g}.example.io`))
129
+ expect(searchCoverageNote([...widgets, entry('*', 'kind_sync_timed_out', '', 1)], {})?.text).toBe(
130
+ "Couldn't read Widget (a.example.io), Widget (b.example.io), Widget (c.example.io) and 3 more kinds; matches of those kinds may be missing.",
131
+ )
132
+ })
133
+
134
+ it('names a kind with its group when the hits hold a same-named kind of another group', () => {
135
+ const knative = entry('Certificate', 'kind_sync_timed_out', 'networking.internal.knative.dev')
136
+ expect(searchCoverageNote([knative], {})?.text).toBe("Couldn't read Certificate; matches of that kind may be missing.")
137
+ expect(searchCoverageNote([knative], { hits: [{ kind: 'Certificate', group: 'cert-manager.io' }] })?.text).toBe(
138
+ "Couldn't read Certificate (networking.internal.knative.dev); matches of that kind may be missing.",
139
+ )
140
+ expect(searchCoverageNote([entry('Certificate', 'user_forbidden', 'cert-manager.io')], { hits: [{ kind: 'Certificate', group: 'networking.internal.knative.dev' }] })?.text).toBe(
141
+ "Your access doesn't include all Certificates (cert-manager.io). Try narrowing with ns:<namespace>.",
142
+ )
143
+ })
144
+
145
+ it('says when the findings search ran out of time', () => {
146
+ const text = searchCoverageNote([{ kind: 'VulnerabilityReport', group: 'aquasecurity.github.io', reason: 'findings_scan_incomplete' }], {})?.text
147
+ expect(text).toContain('ran out of time searching the findings of')
148
+ expect(text).toContain('may be in a report it left out')
149
+ })
150
+
151
+ it('keeps CEL object failures out of the findings-scan note', () => {
152
+ expect(noteFor({ status: 'partial', gaps: [{
153
+ code: 'filter_eval_failed', objects: { count: 1, names: [{ kind: 'Pod', namespace: 'shop', name: 'worker' }] },
154
+ }] }, {})).toBeUndefined()
155
+ })
156
+
157
+ it('says why a namespace the query named was not searched', () => {
158
+ const ns = (reason: string, namespaces: string[]) => ({ kind: '*', group: '', reason, namespaces })
159
+ expect(searchCoverageNote([ns('radar_namespace_not_collected', ['rel-owner'])], {})?.text).toBe("Namespace 'rel-owner' wasn't searched: Radar here watches only some namespaces.")
160
+ expect(searchCoverageNote([ns('radar_namespace_not_collected', ['audit', 'billing'])], {})?.text).toBe("Namespaces 'audit' and 'billing' weren't searched: Radar here watches only some namespaces.")
161
+ expect(searchCoverageNote([ns('outside_namespace_pin', ['billing'])], {})?.text).toBe("Namespace 'billing' wasn't searched: Radar is pinned to another namespace.")
162
+ expect(searchCoverageNote([ns('namespace_not_found', ['payments-prd'])], {})?.text).toBe("Namespace 'payments-prd' doesn't exist on this cluster.")
163
+ expect(searchCoverageNote([ns('user_namespace_not_visible', ['payments-prd'])], {})?.text).toBe("Namespace 'payments-prd' wasn't found in what you can see.")
164
+ })
165
+
166
+ it('keeps a read failure visible beside namespace notes', () => {
167
+ const ns = (reason: string, namespaces: string[]) => ({ kind: '*', group: '', reason, namespaces })
168
+ const mixed = [ns('namespace_not_found', ['gone']), ns('radar_namespace_not_collected', ['rel-owner']), entry('SpStall', 'kind_sync_timed_out', 'stall.sp-live.test')]
169
+ expect(searchCoverageNote(mixed, {})?.text).toBe(
170
+ "Couldn't read SpStall; matches of that kind may be missing. Namespace 'gone' doesn't exist on this cluster.",
171
+ )
172
+ })
173
+
174
+ it.each([
175
+ [{ kind: '*', group: '', reason: 'radar_namespace_not_collected', namespaces: ['rel-owner'] }, false],
176
+ [entry('*', 'kind_sync_pending'), true],
177
+ ])('keeps the recovery action with its sentence beside %j', (other, loadingFirst) => {
178
+ const recheckKind = vi.fn()
179
+ const recovery = searchCoverageNote([entry('Certificate', 'read_error')], { recheckKind })!
180
+ const sibling = searchCoverageNote([other], {})!
181
+ const note = searchCoverageNote([entry('Certificate', 'read_error'), other], { recheckKind })!
182
+ const parts = loadingFirst ? [sibling, recovery] : [recovery, sibling]
183
+ expect(note.parts?.map((part) => part.text)).toEqual(parts.map((part) => part.text))
184
+ expect(note.parts?.[loadingFirst ? 1 : 0].action).toMatchObject({ label: 'kind:Certificate', suffix: ' to re-check.', keepOpen: true })
185
+ expect(note.parts?.[loadingFirst ? 0 : 1].action).toBeUndefined()
186
+ const recoveryText = "Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check."
187
+ expect(note.text).toBe(loadingFirst ? `${sibling.text} ${recoveryText}` : `${recoveryText} ${sibling.text}`)
188
+ note.parts?.find((part) => part.action)?.action?.onSelect()
189
+ expect(recheckKind).toHaveBeenCalledWith('Certificate')
190
+ })
191
+
192
+ it('ignores reasons it does not know', () => {
193
+ expect(searchCoverageNote([entry('Widget', 'reason_from_the_future')], {})).toBeUndefined()
194
+ })
195
+
196
+ it('keeps to two sentences, loading first, and keeps the action only when its sentence shows', () => {
197
+ const openKindList = () => () => {}
198
+ const many = [entry('Secret', 'user_forbidden'), entry('Lease', 'kind_not_searchable', 'coordination.k8s.io'), entry('*', 'kind_sync_pending')]
199
+ const note = searchCoverageNote(many, { openKindList })!
200
+ expect(note.text).toBe("Still loading — results may change. Leases can't be searched. Open the Leases list instead.")
201
+ expect(note.parts?.map((part) => part.text)).toEqual(['Still loading — results may change.', "Leases can't be searched."])
202
+ expect(note.parts?.[1].action?.label).toBe('Open the Leases list instead.')
203
+ expect(searchCoverageNote([...many, entry('Deploymnet', 'kind_unknown')], { openKindList })).toEqual({
204
+ text: 'Still loading — results may change. No kind named Deploymnet here — not installed, or misspelled?',
205
+ action: undefined,
206
+ })
207
+ })
208
+ })
209
+
210
+ describe('helpers', () => {
211
+ it('pluralizes kinds for display', () => {
212
+ expect(['Secret', 'Ingress', 'Endpoints', 'NetworkPolicy', 'Lease'].map(kindPluralLabel)).toEqual(['Secrets', 'Ingresses', 'Endpoints', 'NetworkPolicies', 'Leases'])
213
+ })
214
+
215
+ it('re-queries a loading search past the point where Radar gives up on a late-starting kind', () => {
216
+ // A watch can start ~21 s into warm-up and is reported failed 30 s later.
217
+ expect(PENDING_RETRY_BUDGET_MS).toBeGreaterThanOrEqual(60_000)
218
+ })
219
+ })
220
+
221
+
222
+ describe('large named target lists', () => {
223
+ const names = Array.from({ length: 5000 }, (_, i) => `target-${String(i).padStart(4, '0')}`)
224
+ it.each(['user_namespace_not_visible', 'namespace_not_found', 'outside_namespace_pin', 'radar_namespace_not_collected'])(
225
+ 'caps %s namespace prose and preserves structured detail', (reason) => {
226
+ const gaps = [{ kind: '*', group: '', reason, namespaces: names }]
227
+ const text = searchCoverageNote(gaps, {})!.text
228
+ expect(text).toContain("'target-0004' and 4995 more")
229
+ expect(text).not.toContain('target-0005')
230
+ expect(text.length).toBeLessThan(300)
231
+ expect(gaps[0].namespaces).toEqual(names)
232
+ },
233
+ )
234
+ it.each(['kind_unknown', 'user_forbidden', 'radar_forbidden', 'kind_not_watchable', 'kind_not_searchable', 'radar_kind_not_collected'])(
235
+ 'caps %s kind prose and preserves exact entries', (reason) => {
236
+ const gaps = names.map((kind) => entry(kind, reason))
237
+ const text = searchCoverageNote(gaps, {})!.text
238
+ expect(text).toContain('and 4995 more')
239
+ expect(text).not.toContain('target-0005')
240
+ expect(text.length).toBeLessThan(300)
241
+ expect(gaps).toHaveLength(5000)
242
+ expect(gaps[4999].kind).toBe('target-4999')
243
+ },
244
+ )
245
+ })
@@ -0,0 +1,222 @@
1
+ import { englishPlural, isEnglishPlural } from '@skyhook-io/k8s-ui'
2
+ import type { SearchCoverage } from '@skyhook-io/k8s-ui/types/read-coverage'
3
+ import type { OmnibarNote, OmnibarNotePart } from './Omnibar'
4
+
5
+ // While a search reports kinds still loading, the open omnibar re-queries every
6
+ // PENDING_RETRY_MS for at most PENDING_RETRY_BUDGET_MS. Radar reports a kind
7
+ // failed 30 s after its watch starts, and on a collector-limited install a
8
+ // watch can start 20 s or more into warm-up, so the budget outlasts both and
9
+ // the note ends on the outcome rather than "still loading".
10
+ export const PENDING_RETRY_MS = 5000
11
+ export const PENDING_RETRY_BUDGET_MS = 60000
12
+
13
+ const FAILURE_REASONS = new Set(['kind_sync_timed_out', 'read_error', 'radar_credentials_rejected'])
14
+ const MAX_SENTENCES = 2
15
+ const MAX_NAMES = 3
16
+ const MAX_TARGET_NAMES = 5
17
+
18
+ export interface SearchCoverageNoteOptions {
19
+ /** The search's hits: a kind that shares its name with a hit of another
20
+ * API group is named with its group. */
21
+ hits?: { kind: string; group?: string }[]
22
+ query?: string
23
+ recheckKind?: (kind: string) => void
24
+ /** Re-querying a still-loading search ran out of budget. */
25
+ pendingExhausted?: boolean
26
+ /** Returns how to open a kind's resource list, or undefined when the host can't. */
27
+ openKindList?: (kind: string, group: string) => (() => void) | undefined
28
+ }
29
+
30
+ /** One kind or namespace a search couldn't cover, flattened from its gaps: a
31
+ * named kind, or `*` for namespaces, for kinds too many to name (`count`), or
32
+ * for an unknown set of kinds (no count). */
33
+ export interface SearchCoverageEntry {
34
+ kind: string
35
+ group: string
36
+ reason: string
37
+ namespaces?: string[]
38
+ count?: number
39
+ /** A namespace entry whose gap missed only some of the kinds searched. */
40
+ someKinds?: boolean
41
+ wholeNamespaceScope?: boolean
42
+ }
43
+
44
+ /** The entries of a search's coverage; CEL evaluation failures are left to the hits. */
45
+ export function searchCoverageEntries(coverage: SearchCoverage | undefined): SearchCoverageEntry[] {
46
+ const out: SearchCoverageEntry[] = []
47
+ for (const gap of coverage?.gaps ?? []) {
48
+ if (gap.objects) continue
49
+ // A gap lists one axis and gives the other as an extent.
50
+ const kinds = gap.kinds && gap.kinds.extent === undefined ? gap.kinds : undefined
51
+ const namespaces = gap.namespaces && gap.namespaces.extent === undefined ? gap.namespaces : undefined
52
+ if (kinds?.names) {
53
+ for (const k of kinds.names) out.push({ kind: k.kind, group: k.group ?? '', reason: gap.code, wholeNamespaceScope: gap.namespaces?.extent === 'all' })
54
+ } else if (kinds) {
55
+ out.push({ kind: '*', group: '', reason: gap.code, count: kinds.count })
56
+ } else if (namespaces) {
57
+ // A search names every namespace its query asked for.
58
+ out.push({ kind: '*', group: '', reason: gap.code, namespaces: namespaces.names ?? [], someKinds: gap.kinds?.extent !== 'all' })
59
+ } else {
60
+ out.push({ kind: '*', group: '', reason: gap.code })
61
+ }
62
+ }
63
+ return out
64
+ }
65
+
66
+ /** Plural display form of a Kind name ("Secrets", "Ingresses", "Endpoints"). */
67
+ export function kindPluralLabel(kind: string): string {
68
+ return isEnglishPlural(kind) ? kind : englishPlural(kind)
69
+ }
70
+
71
+ function joinNames(names: string[], conj: string): string {
72
+ if (names.length > MAX_TARGET_NAMES) return `${names.slice(0, MAX_TARGET_NAMES).join(', ')} and ${names.length - MAX_TARGET_NAMES} more`
73
+ if (names.length <= 1) return names[0] ?? ''
74
+ return `${names.slice(0, -1).join(', ')} ${conj} ${names[names.length - 1]}`
75
+ }
76
+
77
+ type KindLabel = (entry: SearchCoverageEntry, plural?: boolean) => string
78
+
79
+ // kindLabeler names a kind by its Kind, adding the API group when another kind
80
+ // of the same name but a different group is in the entries or the hits
81
+ // ("Certificate (networking.internal.knative.dev)" beside cert-manager's).
82
+ function kindLabeler(unsearched: SearchCoverageEntry[], hits: { kind: string; group?: string }[]): KindLabel {
83
+ const groups = new Map<string, Set<string>>()
84
+ const add = (kind: string, group: string) => groups.set(kind, (groups.get(kind) ?? new Set()).add(group))
85
+ for (const e of unsearched) if (e.kind !== '*') add(e.kind, e.group)
86
+ for (const h of hits) add(h.kind, h.group ?? '')
87
+ return (e, plural = false) => {
88
+ const name = plural ? kindPluralLabel(e.kind) : e.kind
89
+ return e.group && (groups.get(e.kind)?.size ?? 0) > 1 ? `${name} (${e.group})` : name
90
+ }
91
+ }
92
+
93
+ // The kinds entries name, once each by group and kind.
94
+ function distinctKinds(entries: SearchCoverageEntry[]): SearchCoverageEntry[] {
95
+ return [...new Map(entries.filter((e) => e.kind !== '*').map((e) => [`${e.group}/${e.kind}`, e])).values()]
96
+ }
97
+
98
+ // The kinds a failure reason covers, in prose: up to MAX_NAMES names, then
99
+ // "N more kinds" for the rest (named beyond the cap, or folded into a counted
100
+ // "*" entry), or "some kinds" when a "*" entry carries no count.
101
+ function failedKinds(entries: SearchCoverageEntry[], label: (e: SearchCoverageEntry) => string): { text: string; one: boolean } {
102
+ const names = distinctKinds(entries).map(label)
103
+ const stars = entries.filter((e) => e.kind === '*')
104
+ if (stars.some((e) => !e.count)) return { text: names.length ? `${names.slice(0, MAX_NAMES).join(', ')} and other kinds` : 'some kinds', one: false }
105
+ const more = Math.max(names.length - MAX_NAMES, 0) + stars.reduce((n, e) => n + (e.count ?? 0), 0)
106
+ const shown = names.slice(0, MAX_NAMES)
107
+ if (!more) return { text: joinNames(shown, 'or'), one: shown.length === 1 }
108
+ // Kinds too many to name are only counted.
109
+ if (!shown.length) return { text: `${more} ${more === 1 ? 'kind' : 'kinds'}`, one: more === 1 }
110
+ return { text: `${shown.join(', ')} and ${more} more ${more === 1 ? 'kind' : 'kinds'}`, one: false }
111
+ }
112
+
113
+ // Radar's ⌘K note for one search: what happened to the kinds and namespaces
114
+ // the query named, whether results are still loading, and which kinds failed
115
+ // to read. Broad searches keep access exclusions quiet; namespace collection
116
+ // is always explained, kind collection only for an empty result. Missing
117
+ // coverage gets no note.
118
+ export function searchCoverageNote(coverage: SearchCoverage | undefined, opts: SearchCoverageNoteOptions): OmnibarNote | undefined {
119
+ const unsearched = searchCoverageEntries(coverage)
120
+ if (!unsearched.length) {
121
+ if (coverage?.gaps.length === 0) {
122
+ // Collection limits come from how Radar is installed, and nothing else
123
+ // in the omnibar shows them, so they are said with hits too.
124
+ if (coverage.narrowedBy?.includes('namespace_collection')) {
125
+ return { text: "Radar collects some kinds only in some namespaces; matches for them elsewhere won't show." }
126
+ }
127
+ if (coverage.narrowedBy?.includes('kind_collection') && !opts.hits?.length) {
128
+ return { text: "Radar doesn't watch every kind; search kind:<name> to include one." }
129
+ }
130
+ }
131
+ return undefined
132
+ }
133
+ const label = kindLabeler(unsearched, opts.hits ?? [])
134
+ const named = (reason: string) => distinctKinds(unsearched.filter((e) => e.reason === reason))
135
+ const names = (entries: SearchCoverageEntry[], conj: string, plural = true) => joinNames([...new Set(entries.map((e) => label(e, plural)))], conj)
136
+
137
+ const sentences: OmnibarNotePart[] = []
138
+ const say = (text: string) => sentences.push({ text })
139
+
140
+ if (unsearched.some((e) => e.reason === 'kind_sync_pending')) {
141
+ say(opts.pendingExhausted ? 'Still loading — try again shortly.' : 'Still loading — results may change.')
142
+ }
143
+ const unknown = named('kind_unknown')
144
+ // A read_error "*" without a count beside an unknown kind: some API groups
145
+ // failed discovery, so the kind may exist there.
146
+ const groupsUnread = unknown.length > 0 && unsearched.some((e) => e.kind === '*' && e.reason === 'read_error' && !e.count)
147
+ // Loading and failures lead: they are the facts a retry or a fix can change.
148
+ const failed = unsearched.filter((e) => FAILURE_REASONS.has(e.reason) && !(groupsUnread && e.kind === '*' && !e.count))
149
+ if (failed.length) {
150
+ const { text, one } = failedKinds(failed, (e) => label(e))
151
+ const warning = `Couldn't read ${text}; matches of ${one ? 'that kind' : 'those kinds'} may be missing.`
152
+ const tokens = (opts.query ?? '').match(/(?:[^\s"]|"[^"]*(?:"|$))+/g) ?? []
153
+ const namedKind = tokens.some((token) => /^(kind|k):.+/i.test(token.replaceAll('"', '')))
154
+ const retry = !namedKind && failed.find((e) => e.kind !== '*' && e.reason === 'read_error')
155
+ const unnamedRetry = !namedKind && !retry && failed.some((e) => e.kind === '*' && e.count && e.reason === 'read_error')
156
+ if (unnamedRetry) {
157
+ say(`${warning} Search kind:<name> to re-check one.`)
158
+ } else if (retry) {
159
+ const modifier = `kind:${retry.kind}`
160
+ sentences.push(opts.recheckKind
161
+ ? { text: `${warning} Search`, action: { label: modifier, suffix: ' to re-check.', keepOpen: true, onSelect: () => opts.recheckKind?.(retry.kind) } }
162
+ : { text: `${warning} Search ${modifier} to re-check.` })
163
+ } else {
164
+ say(warning)
165
+ }
166
+ }
167
+ const unchecked = unsearched.filter((e) => e.reason === 'user_permission_check_failed')
168
+ if (unchecked.length) say(`Couldn't check your access to ${failedKinds(unchecked, (e) => label(e, true)).text}.`)
169
+ if (unknown.length) {
170
+ const noun = `No ${unknown.length === 1 ? 'kind' : 'kinds'} named ${names(unknown, 'or', false)}`
171
+ say(groupsUnread ? `${noun} found, but some API groups couldn't be read.` : `${noun} here — not installed, or misspelled?`)
172
+ }
173
+ // Kinds Radar reads directly instead of watching: their list works.
174
+ const unsupported = unsearched.filter((e) => e.kind !== '*' && e.reason === 'kind_not_searchable')
175
+ if (unsupported.length) {
176
+ const first = unsupported[0]
177
+ const pointer = `Open the ${label(first, true)} list instead.`
178
+ const openList = opts.openKindList?.(first.kind, first.group)
179
+ const what = names(unsupported, 'and')
180
+ sentences.push(openList
181
+ ? { text: `${what} can't be searched.`, action: { label: pointer, onSelect: openList } }
182
+ : { text: `${what} can't be searched. ${pointer}` })
183
+ }
184
+ const unwatchable = named('kind_not_watchable')
185
+ if (unwatchable.length) say(`Radar can't collect ${names(unwatchable, 'or')}: the API doesn't support list and watch.`)
186
+ // Namespace entries name the namespaces an ns: term asked for that weren't
187
+ // searched; their reason says why.
188
+ const namespaces = (reasons: string[]) => [...new Set(unsearched.filter((e) => reasons.includes(e.reason)).flatMap((e) => e.namespaces ?? []))].sort()
189
+ const quoted = (list: string[]) => joinNames(list.map((ns) => `'${ns}'`), 'and')
190
+ const namespaceSentence = (list: string[], one: string, many: string) => say(`${list.length === 1 ? 'Namespace' : 'Namespaces'} ${quoted(list)} ${list.length === 1 ? one : many}.`)
191
+ const absent = namespaces(['namespace_not_found'])
192
+ if (absent.length) namespaceSentence(absent, "doesn't exist on this cluster", "don't exist on this cluster")
193
+ const unseen = namespaces(['user_namespace_not_visible'])
194
+ if (unseen.length) namespaceSentence(unseen, "wasn't found in what you can see", "weren't found in what you can see")
195
+ const pinned = namespaces(['outside_namespace_pin'])
196
+ if (pinned.length) namespaceSentence(pinned, "wasn't searched: Radar is pinned to another namespace", "weren't searched: Radar is pinned to another namespace")
197
+ const uncollected = namespaces(['radar_namespace_not_collected'])
198
+ const someKindsUncollected = unsearched.some((e) => e.reason === 'radar_namespace_not_collected' && e.someKinds)
199
+ if (uncollected.length && someKindsUncollected) say(`Some kinds weren't searched in ${uncollected.length === 1 ? 'namespace' : 'namespaces'} ${quoted(uncollected)}: Radar here watches only some namespaces.`)
200
+ else if (uncollected.length) namespaceSentence(uncollected, "wasn't searched: Radar here watches only some namespaces", "weren't searched: Radar here watches only some namespaces")
201
+ const findings = named('findings_scan_incomplete')
202
+ if (findings.length) say(`Radar ran out of time searching the findings of ${names(findings, 'and')}, so a CVE or package missing here may be in a report it left out.`)
203
+ const denied = named('user_forbidden')
204
+ if (denied.length) {
205
+ const suggestion = denied.some((e) => e.wholeNamespaceScope) ? ' Try narrowing with ns:<namespace>.' : ''
206
+ say(`Your access doesn't include all ${names(denied, 'or')}.${suggestion}`)
207
+ }
208
+ const collector = named('radar_forbidden')
209
+ if (collector.length) say(`Radar isn't allowed to read ${names(collector, 'or')} on this cluster.`)
210
+ const unwatched = named('radar_kind_not_collected')
211
+ if (unwatched.length) say(`Radar doesn't watch ${names(unwatched, 'or')} on this cluster, so they weren't searched.`)
212
+
213
+ if (!sentences.length) return undefined
214
+ const shown = sentences.slice(0, MAX_SENTENCES)
215
+ if (shown.length > 1 && shown.some((s) => s.action)) {
216
+ return {
217
+ text: shown.map((s) => `${s.text}${s.action ? ` ${s.action.label}${s.action.suffix ?? ''}` : ''}`).join(' '),
218
+ parts: shown,
219
+ }
220
+ }
221
+ return { text: shown.map((s) => s.text).join(' '), action: shown.find((s) => s.action)?.action }
222
+ }