@skyhook-io/radar-app 1.18.0 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +2 -3
- package/src/App.tsx +43 -12
- package/src/api/client.deleteResource.test.tsx +111 -0
- package/src/api/client.gitops-destination.test.tsx +55 -0
- package/src/api/client.resource-list.test.ts +76 -0
- package/src/api/client.resourceAudit.test.tsx +57 -0
- package/src/api/client.resourcePath.test.ts +107 -0
- package/src/api/client.ts +197 -57
- package/src/api/quotas.ts +9 -20
- package/src/api/radarFeatures.ts +2 -0
- package/src/api/resourceLists.test.ts +84 -0
- package/src/api/resourceLists.ts +71 -0
- package/src/components/capacity/CapacityDemand.tsx +6 -3
- package/src/components/capacity/CapacityOverview.tsx +14 -7
- package/src/components/capacity/CapacityPoolDetail.tsx +7 -5
- package/src/components/capacity/ClusterSchedulingCard.tsx +3 -3
- package/src/components/capacity/shared.tsx +9 -5
- package/src/components/cnpg/CNPGOverview.tsx +4 -1
- package/src/components/cnpg/CNPGView.tsx +1 -0
- package/src/components/cnpg/actions/useCNPGWriteGuard.tsx +1 -0
- package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
- package/src/components/compare/CompareViewRoute.tsx +5 -1
- package/src/components/compare/useCompareCandidates.ts +1 -1
- package/src/components/compare/useCompareLauncher.tsx +4 -2
- package/src/components/diagnose/ApplyDialog.test.tsx +10 -0
- package/src/components/diagnose/ApplyDialog.tsx +8 -1
- package/src/components/diagnose/AssessmentCard.tsx +60 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +5 -0
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +62 -2
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +6 -5
- package/src/components/diagnose/InvestigationView.tsx +47 -13
- package/src/components/diagnose/StoryExcerpt.tsx +24 -5
- package/src/components/diagnose/assessmentCopy.ts +11 -0
- package/src/components/diagnose/investigationEvidence/adapters/changes.ts +36 -1
- package/src/components/diagnose/investigationEvidence/adapters/crossplane.test.tsx +85 -0
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +1 -0
- package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
- package/src/components/diagnose/investigationEvidence/adapters/testdata/crossplane-paused-get-resource.json +28 -0
- package/src/components/diagnose/investigationEvidence/bodies/index.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
- package/src/components/diagnose/investigationEvidence/bodies/workload.tsx +5 -1
- package/src/components/diagnose/investigationEvidence/builder.ts +16 -2
- package/src/components/diagnose/investigationEvidence/cardParts.tsx +7 -2
- package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/observations.ts +8 -3
- package/src/components/diagnose/investigationEvidence/projection.test.ts +81 -4
- package/src/components/diagnose/investigationEvidence/types.ts +15 -0
- package/src/components/diagnose/investigationEvidencePresentation.test.ts +36 -2
- package/src/components/diagnose/investigationEvidencePresentation.ts +33 -8
- package/src/components/diagnose/storyParts.test.tsx +53 -0
- package/src/components/diagnose/toolCallLabel.test.ts +9 -0
- package/src/components/diagnose/toolCallLabel.ts +2 -0
- package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
- package/src/components/execution/BatchExecutionView.tsx +6 -4
- package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
- package/src/components/gitops/GitOpsView.tsx +62 -40
- package/src/components/gitops/useDestinationCluster.ts +2 -1
- package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
- package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
- package/src/components/helm/ChartBrowser.tsx +9 -8
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -2
- package/src/components/helm/HelmView.tsx +34 -23
- package/src/components/helm/InstallWizard.tsx +6 -2
- package/src/components/helm/TrackChartSourceDialog.render.test.tsx +269 -96
- package/src/components/helm/TrackChartSourceDialog.tsx +607 -104
- package/src/components/helm/ValuesViewer.test.tsx +1 -0
- package/src/components/helm/ValuesViewer.tsx +4 -2
- package/src/components/home/ClusterHealthCard.tsx +28 -21
- package/src/components/home/MCPSetupDialog.test.tsx +27 -2
- package/src/components/home/MCPSetupDialog.tsx +14 -2
- package/src/components/home/mcpToolCatalog.ts +39 -2
- package/src/components/issues/IssuesPane.render.test.tsx +5 -5
- package/src/components/nav/PrimaryNavRail.tsx +34 -2
- package/src/components/product-hunt/ProductHuntNotice.render.test.tsx +120 -0
- package/src/components/product-hunt/ProductHuntNotice.test.ts +121 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +202 -0
- package/src/components/product-hunt/launchWindow.ts +78 -0
- package/src/components/product-hunt/useProductHuntRailEntry.test.tsx +76 -0
- package/src/components/product-hunt/useProductHuntRailEntry.ts +27 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
- package/src/components/resource/PrometheusCharts.tsx +2 -2
- package/src/components/resources/CompositeRenderer.tsx +4 -0
- package/src/components/resources/ResourcesView.tsx +30 -68
- package/src/components/resources/renderers/PodRenderer.tsx +4 -1
- package/src/components/settings/LocalConnectionSettings.tsx +1 -0
- package/src/components/settings/MyPermissionsDialog.tsx +12 -9
- package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
- package/src/components/traffic/TrafficSourcePill.tsx +111 -0
- package/src/components/traffic/TrafficView.tsx +9 -55
- package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
- package/src/components/ui/Omnibar.note.test.tsx +141 -0
- package/src/components/ui/Omnibar.tsx +82 -18
- package/src/components/ui/RadarOmnibar.test.tsx +201 -0
- package/src/components/ui/RadarOmnibar.tsx +39 -4
- package/src/components/ui/SearchSyntaxHelp.test.tsx +39 -0
- package/src/components/ui/SearchSyntaxHelp.tsx +23 -2
- package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
- package/src/components/ui/UpdateNotification.test.tsx +4 -1
- package/src/components/ui/UpdateNotification.tsx +61 -10
- package/src/components/ui/omnibar-match.test.ts +15 -8
- package/src/components/ui/omnibar-match.ts +11 -6
- package/src/components/ui/searchCoverage.fixtures.ts +16 -0
- package/src/components/ui/searchCoverageNote.test.ts +245 -0
- package/src/components/ui/searchCoverageNote.ts +222 -0
- package/src/components/usage-data/UsageDataPrompt.tsx +19 -1
- package/src/components/whats-new/WhatsNew.test.ts +10 -0
- package/src/components/whats-new/WhatsNew.tsx +5 -4
- package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
- package/src/components/whats-new/releaseNotes.ts +57 -5
- package/src/components/workload/WorkloadView.tsx +18 -6
- package/src/components/workspace/layout.tsx +2 -1
- package/src/contexts/CapabilitiesContext.tsx +1 -0
- package/src/hooks/useGitOpsWriteGuard.test.tsx +126 -2
- package/src/hooks/useGitOpsWriteGuard.ts +25 -3
- package/src/hooks/useResolvedGitOpsOwner.ts +14 -9
- package/src/hooks/useResourceCounts.ts +2 -0
- package/src/index.css +87 -4
- package/src/index.ts +7 -0
- package/src/utils/artifacthub.test.ts +18 -0
- package/src/utils/artifacthub.ts +9 -0
|
@@ -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
|
+
}
|
|
@@ -4,6 +4,7 @@ import { BarChart3, X } from 'lucide-react'
|
|
|
4
4
|
import { useMarkUsagePromptShown, useSetUsageData, type UsageDataStatus } from '../../api/usage-data'
|
|
5
5
|
import { useVersionCheck } from '../../api/client'
|
|
6
6
|
import { isUpdateDismissed } from '../ui/UpdateNotification'
|
|
7
|
+
import { launchNoticeHoldsCorner, resolveLaunch } from '../product-hunt/launchWindow'
|
|
7
8
|
import { UsageDataAnswered, UsageDataBlurb } from './UsageDataAsk'
|
|
8
9
|
import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
|
|
9
10
|
import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
|
|
@@ -13,6 +14,14 @@ import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../ut
|
|
|
13
14
|
export const FIRST_RUN_PROMPT_DELAY_MS = 15_000
|
|
14
15
|
const THANKS_MS = 4_000
|
|
15
16
|
|
|
17
|
+
// The server stops offering the prompt the moment it is shown, so other corner
|
|
18
|
+
// cards read whether it is on screen from here instead.
|
|
19
|
+
let promptOnScreen = false
|
|
20
|
+
export const USAGE_PROMPT_VISIBILITY_EVENT = 'radar:usage-prompt-visibility'
|
|
21
|
+
export function usagePromptOnScreen(): boolean {
|
|
22
|
+
return promptOnScreen
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
// The update notice uses the same corner. One nudge at a time.
|
|
17
26
|
export function updateNoticeVisible(latest: string | undefined, updateAvailable: boolean | undefined): boolean {
|
|
18
27
|
return !!updateAvailable && !!latest && !isUpdateDismissed(latest)
|
|
@@ -64,7 +73,7 @@ export function UsageDataPrompt({ status }: { status: UsageDataStatus | undefine
|
|
|
64
73
|
const eligible = shouldShowFirstRunPrompt({
|
|
65
74
|
status,
|
|
66
75
|
ready,
|
|
67
|
-
updateNoticeShowing: updateNoticeVisible(versionInfo?.latestVersion, versionInfo?.updateAvailable),
|
|
76
|
+
updateNoticeShowing: updateNoticeVisible(versionInfo?.latestVersion, versionInfo?.updateAvailable) || launchNoticeHoldsCorner(resolveLaunch(versionInfo?.productHuntLaunch), Date.now()),
|
|
68
77
|
})
|
|
69
78
|
useEffect(() => {
|
|
70
79
|
if (eligible && !recorded.current) {
|
|
@@ -81,6 +90,15 @@ export function UsageDataPrompt({ status }: { status: UsageDataStatus | undefine
|
|
|
81
90
|
}, [answer])
|
|
82
91
|
|
|
83
92
|
const show = latched && !dismissed && cardStillAsking(status, answer)
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!show) return
|
|
95
|
+
promptOnScreen = true
|
|
96
|
+
window.dispatchEvent(new Event(USAGE_PROMPT_VISIBILITY_EVENT))
|
|
97
|
+
return () => {
|
|
98
|
+
promptOnScreen = false
|
|
99
|
+
window.dispatchEvent(new Event(USAGE_PROMPT_VISIBILITY_EVENT))
|
|
100
|
+
}
|
|
101
|
+
}, [show])
|
|
84
102
|
const { shouldRender, isOpen } = useAnimatedUnmount(show, overlayExitMs('menu'))
|
|
85
103
|
if (!shouldRender) return null
|
|
86
104
|
|
|
@@ -110,6 +110,14 @@ describe('composeReleaseNotes', () => {
|
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
describe('whatsNewToOpen', () => {
|
|
113
|
+
it.each(['v1.18.0', 'v1.18.1'])('announces the shipped v1.18 notes on upgrade to %s', version => {
|
|
114
|
+
const notes = whatsNewToOpen(version, 'v1.17.0', true)
|
|
115
|
+
expect(notes?.versions).toEqual(['v1.18.0'])
|
|
116
|
+
expect(notes?.score).toBeGreaterThanOrEqual(AUTO_OPEN_SCORE)
|
|
117
|
+
expect(whatsNewToOpen(version, 'v1.18.0', true)).toBeNull()
|
|
118
|
+
expect(whatsNewToOpen(version, null, false)).toBeNull()
|
|
119
|
+
})
|
|
120
|
+
|
|
113
121
|
it('opens when the unseen releases show enough, and not for a quiet release', () => {
|
|
114
122
|
const list = [entry('v1.15.0', [9, 8, 7, 7, 7]), entry('v1.16.0', [6, 5, 4])]
|
|
115
123
|
expect(whatsNewToOpen('v1.15.0', 'v1.14.1', true, list)?.score).toBe(38)
|
|
@@ -141,6 +149,8 @@ describe('nextSeenVersion', () => {
|
|
|
141
149
|
describe('release notes lookup', () => {
|
|
142
150
|
it('matches an exact version with or without the v prefix', () => {
|
|
143
151
|
expect(releaseNotesFor('2.0.0', catalog)?.version).toBe('v2.0.0')
|
|
152
|
+
expect(releaseNotesFor('v2.0', catalog)?.version).toBe('v2.0.0')
|
|
153
|
+
expect(releaseNotesFor('2.0', catalog)?.version).toBe('v2.0.0')
|
|
144
154
|
expect(releaseNotesFor(undefined, catalog)).toBeUndefined()
|
|
145
155
|
})
|
|
146
156
|
|
|
@@ -142,7 +142,8 @@ interface DialogView {
|
|
|
142
142
|
/**
|
|
143
143
|
* Opens after an upgrade when the releases the user hasn't seen have enough to
|
|
144
144
|
* show; otherwise the nav rail's unread dot carries them.
|
|
145
|
-
* `?whats-new`
|
|
145
|
+
* `?whats-new` previews the newest authored release; `?whats-new=v1.15`
|
|
146
|
+
* (or `v1.15.0`) selects a release, and
|
|
146
147
|
* `&whats-new-from=v1.14.0` previews it as composed for an upgrade from that version.
|
|
147
148
|
*/
|
|
148
149
|
export function WhatsNew({ onNavigate, usageData }: WhatsNewProps) {
|
|
@@ -205,16 +206,16 @@ export function WhatsNew({ onNavigate, usageData }: WhatsNewProps) {
|
|
|
205
206
|
|
|
206
207
|
useEffect(() => {
|
|
207
208
|
if (previewParam === null) return
|
|
208
|
-
const
|
|
209
|
+
const single = releaseNotesFor(previewParam) ?? RELEASE_NOTES[0]
|
|
210
|
+
const target = single?.version
|
|
209
211
|
if (!target) return
|
|
210
212
|
const upgrade = previewFrom ? unreadReleases(target, previewFrom, true) : []
|
|
211
213
|
if (upgrade.length > 0) {
|
|
212
214
|
show({ notes: composeReleaseNotes(upgrade), since: previewFrom, to: target, acknowledges: false })
|
|
213
215
|
return
|
|
214
216
|
}
|
|
215
|
-
const single = releaseNotesFor(previewParam) ?? latestReleaseNotesFor(currentVersion) ?? RELEASE_NOTES[0]
|
|
216
217
|
if (single) show({ notes: composeReleaseNotes([single]), since: null, to: single.version, acknowledges: false })
|
|
217
|
-
}, [previewParam, previewFrom,
|
|
218
|
+
}, [previewParam, previewFrom, show])
|
|
218
219
|
|
|
219
220
|
useEffect(() => {
|
|
220
221
|
if (!state || lastSeen === undefined || previewParam !== null || decidedRef.current) return
|
|
@@ -127,6 +127,16 @@ async function clickGotIt() {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
describe('WhatsNew', () => {
|
|
130
|
+
it.each(['v1.18.0', 'v1.18.1'])('opens the shipped notes on Home after upgrading to %s', async version => {
|
|
131
|
+
setCatalog(...SHIPPED)
|
|
132
|
+
serverState = { currentVersion: version, storage: 'server', seenVersion: 'v1.17.0', priorInstall: true }
|
|
133
|
+
await render('/')
|
|
134
|
+
expect(dialog()?.textContent).toContain("What's new in Radar v1.18")
|
|
135
|
+
await clickGotIt()
|
|
136
|
+
expect(seenPosts).toEqual([version])
|
|
137
|
+
expect(status.current.unread).toBe(false)
|
|
138
|
+
})
|
|
139
|
+
|
|
130
140
|
it('auto-opens on Home after an upgrade and records the running version on close', async () => {
|
|
131
141
|
serverState = { currentVersion: 'v1.15.2', storage: 'server', seenVersion: 'v1.14.1', priorInstall: true }
|
|
132
142
|
await render('/')
|
|
@@ -290,6 +300,16 @@ describe('WhatsNew', () => {
|
|
|
290
300
|
expect(seenPosts).toEqual([])
|
|
291
301
|
})
|
|
292
302
|
|
|
303
|
+
it.each(['', '=v1.18', '=1.18', '=v1.18.0'])('previews v1.18 on a Git development build with ?whats-new%s', async suffix => {
|
|
304
|
+
setCatalog(...SHIPPED)
|
|
305
|
+
serverState = { currentVersion: 'v1.17.0-113-gb49561b78', storage: 'server', seenVersion: 'v1.17.0', priorInstall: true }
|
|
306
|
+
await render(`/resources/pods?whats-new${suffix}`)
|
|
307
|
+
expect(dialog()?.textContent).toContain("What's new in Radar v1.18")
|
|
308
|
+
expect(dialog()?.textContent).toContain(SHIPPED[0].highlights[0].title)
|
|
309
|
+
await clickGotIt()
|
|
310
|
+
expect(seenPosts).toEqual([])
|
|
311
|
+
})
|
|
312
|
+
|
|
293
313
|
it('records nothing when previewing the running release', async () => {
|
|
294
314
|
serverState = { currentVersion: 'v1.15.0', storage: 'server', seenVersion: 'v1.14.1', priorInstall: true }
|
|
295
315
|
await render('/resources/pods?whats-new')
|