@skyhook-io/radar-app 1.18.0 → 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 (69) hide show
  1. package/README.md +6 -0
  2. package/package.json +2 -3
  3. package/src/App.tsx +22 -6
  4. package/src/api/client.gitops-destination.test.tsx +55 -0
  5. package/src/api/client.resource-list.test.ts +76 -0
  6. package/src/api/client.ts +61 -20
  7. package/src/api/quotas.ts +9 -20
  8. package/src/api/radarFeatures.ts +2 -0
  9. package/src/api/resourceLists.test.ts +84 -0
  10. package/src/api/resourceLists.ts +71 -0
  11. package/src/components/cnpg/CNPGView.tsx +1 -0
  12. package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
  13. package/src/components/compare/CompareViewRoute.tsx +5 -1
  14. package/src/components/compare/useCompareCandidates.ts +1 -1
  15. package/src/components/compare/useCompareLauncher.tsx +4 -2
  16. package/src/components/diagnose/StoryExcerpt.tsx +24 -5
  17. package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
  18. package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
  19. package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
  20. package/src/components/diagnose/investigationEvidence/builder.ts +13 -1
  21. package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
  22. package/src/components/diagnose/investigationEvidence/observations.ts +1 -0
  23. package/src/components/diagnose/investigationEvidence/projection.test.ts +24 -1
  24. package/src/components/diagnose/investigationEvidence/types.ts +15 -0
  25. package/src/components/diagnose/toolCallLabel.test.ts +9 -0
  26. package/src/components/diagnose/toolCallLabel.ts +2 -0
  27. package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
  28. package/src/components/execution/BatchExecutionView.tsx +6 -4
  29. package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
  30. package/src/components/gitops/GitOpsView.tsx +62 -40
  31. package/src/components/gitops/useDestinationCluster.ts +2 -1
  32. package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
  33. package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
  34. package/src/components/helm/ChartBrowser.tsx +5 -4
  35. package/src/components/helm/TrackChartSourceDialog.render.test.tsx +269 -96
  36. package/src/components/helm/TrackChartSourceDialog.tsx +607 -104
  37. package/src/components/home/mcpToolCatalog.ts +10 -0
  38. package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
  39. package/src/components/resource/PrometheusCharts.tsx +2 -2
  40. package/src/components/resources/ResourcesView.tsx +29 -67
  41. package/src/components/resources/renderers/PodRenderer.tsx +4 -1
  42. package/src/components/settings/MyPermissionsDialog.tsx +12 -9
  43. package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
  44. package/src/components/traffic/TrafficSourcePill.tsx +111 -0
  45. package/src/components/traffic/TrafficView.tsx +9 -55
  46. package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
  47. package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
  48. package/src/components/ui/Omnibar.note.test.tsx +141 -0
  49. package/src/components/ui/Omnibar.tsx +82 -18
  50. package/src/components/ui/RadarOmnibar.test.tsx +183 -0
  51. package/src/components/ui/RadarOmnibar.tsx +38 -4
  52. package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
  53. package/src/components/ui/UpdateNotification.test.tsx +2 -1
  54. package/src/components/ui/UpdateNotification.tsx +29 -5
  55. package/src/components/ui/omnibar-match.test.ts +15 -8
  56. package/src/components/ui/omnibar-match.ts +11 -6
  57. package/src/components/ui/searchCoverage.fixtures.ts +16 -0
  58. package/src/components/ui/searchCoverageNote.test.ts +245 -0
  59. package/src/components/ui/searchCoverageNote.ts +222 -0
  60. package/src/components/whats-new/WhatsNew.test.ts +10 -0
  61. package/src/components/whats-new/WhatsNew.tsx +5 -4
  62. package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
  63. package/src/components/whats-new/releaseNotes.ts +57 -5
  64. package/src/components/workload/WorkloadView.tsx +8 -2
  65. package/src/hooks/useResourceCounts.ts +2 -0
  66. package/src/index.css +2 -4
  67. package/src/index.ts +7 -0
  68. package/src/utils/artifacthub.test.ts +18 -0
  69. package/src/utils/artifacthub.ts +9 -0
@@ -2,16 +2,21 @@
2
2
  import { act, type InputHTMLAttributes, type ReactNode } from 'react'
3
3
  import { createRoot, type Root } from 'react-dom/client'
4
4
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
- import type { ChartSourceStatus, HelmRepository, SourceUpgradeSelection } from '../../types'
5
+ import type { ArtifactHubChart, ChartSourceStatus, HelmRepository, SourceUpgradeSelection } from '../../types'
6
6
  import { TrackChartSourceDialog } from './TrackChartSourceDialog'
7
7
 
8
8
  const state = vi.hoisted(() => ({
9
9
  status: undefined as ChartSourceStatus | undefined,
10
10
  repositories: [] as HelmRepository[],
11
11
  isOwner: true,
12
+ configManaged: false,
13
+ statusFetching: false,
12
14
  featureSupported: true,
13
15
  associateSource: vi.fn(),
14
16
  addRepository: vi.fn(),
17
+ addOCI: vi.fn(),
18
+ searchCharts: [] as ArtifactHubChart[],
19
+ ociSources: [] as string[],
15
20
  }))
16
21
 
17
22
  vi.mock('@skyhook-io/k8s-ui/components/ui/DialogPortal', () => ({
@@ -19,20 +24,22 @@ vi.mock('@skyhook-io/k8s-ui/components/ui/DialogPortal', () => ({
19
24
  }))
20
25
  vi.mock('@skyhook-io/k8s-ui', () => ({
21
26
  Input: (props: InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
27
+ Badge: ({ children }: { children: ReactNode }) => <span>{children}</span>,
22
28
  }))
23
29
  vi.mock('../settings/OperatorManagedNotice', () => ({ OperatorManagedNotice: () => null }))
24
30
  vi.mock('../../api/client', () => {
25
31
  const idle = { mutate: vi.fn(), mutateAsync: vi.fn(), isPending: false }
26
32
  return {
27
33
  useRadarFeature: () => ({ support: state.featureSupported ? 'supported' : 'unsupported' }),
28
- useHelmSourceStatus: () => ({ data: state.status, error: null, refetch: vi.fn() }),
34
+ useHelmSourceStatus: () => ({ data: state.status, error: null, isFetching: state.statusFetching, refetch: vi.fn() }),
29
35
  useHelmRepositories: () => ({ data: state.repositories, isLoading: false }),
30
- useHelmOCISources: () => ({ data: [] }),
36
+ useHelmOCISources: () => ({ data: state.ociSources }),
31
37
  useClusterInfo: () => ({ data: { inCluster: false } }),
32
- useCapabilities: () => ({ data: { configManagement: 'local' } }),
38
+ useCapabilities: () => ({ data: { configManagement: state.configManaged ? 'operator' : 'local' } }),
33
39
  useCloudRole: () => ({ canAtLeast: () => state.isOwner }),
34
40
  useAddHelmRepository: () => ({ mutate: state.addRepository, isPending: false }),
35
- useAddOCISource: () => idle,
41
+ useAddOCISource: () => ({ ...idle, mutate: state.addOCI }),
42
+ useArtifactHubSearch: () => ({ data: { charts: state.searchCharts }, isFetching: false, error: null, refetch: vi.fn() }),
36
43
  useRemoveOCISource: () => idle,
37
44
  useSetHelmSource: () => ({ ...idle, mutate: state.associateSource }),
38
45
  }
@@ -52,10 +59,15 @@ let root: Root
52
59
  beforeEach(() => {
53
60
  state.status = movedMachine
54
61
  state.repositories = []
62
+ state.configManaged = false
63
+ state.statusFetching = false
55
64
  state.isOwner = true
56
65
  state.featureSupported = true
57
66
  state.associateSource.mockReset()
58
67
  state.addRepository.mockReset()
68
+ state.addOCI.mockReset()
69
+ state.searchCharts = []
70
+ state.ociSources = []
59
71
  const element = document.createElement('div')
60
72
  document.body.appendChild(element)
61
73
  root = createRoot(element)
@@ -66,127 +78,288 @@ afterEach(async () => {
66
78
  document.body.replaceChildren()
67
79
  })
68
80
 
69
- async function renderDialog(onSelectUpgradeSource?: (selection: SourceUpgradeSelection) => void) {
70
- await act(async () => root.render(<TrackChartSourceDialog onSelectUpgradeSource={onSelectUpgradeSource} open onClose={() => undefined} chartName="podinfo" namespace="web" releaseName="storefront" />))
81
+ async function renderDialog(onSelectUpgradeSource?: (selection: SourceUpgradeSelection) => void, open = true, onClose = () => undefined) {
82
+ await act(async () => root.render(<TrackChartSourceDialog onSelectUpgradeSource={onSelectUpgradeSource} open={open} onClose={onClose} chartName="podinfo" namespace="web" releaseName="storefront" />))
71
83
  }
72
84
 
73
- function addRecordedButton() {
74
- return Array.from(document.querySelectorAll('button')).find(button => button.textContent?.includes('and use it'))
85
+ function button(text: string) {
86
+ const result = Array.from(document.querySelectorAll('button')).find(item => item.textContent === text)
87
+ if (!result) throw new Error(`Missing button: ${text}`)
88
+ return result
75
89
  }
76
90
 
77
- describe('TrackChartSourceDialog one-click add of the recorded repository', () => {
78
- it('adds the recorded URL under the recorded name when that name is free', async () => {
79
- await renderDialog()
80
- const button = addRecordedButton()
81
- expect(button?.textContent).toBe('Add stefanprodan.github.io/podinfo and use it')
82
- expect(button?.disabled).toBe(false)
83
- expect(document.body.textContent).toContain('Saved in Helm as podinfo, the name it was recorded under.')
84
-
85
- await act(async () => button?.click())
86
- expect(state.addRepository).toHaveBeenCalledWith(
87
- { name: 'podinfo', url: recordedURL, namespace: 'web', releaseName: 'storefront' },
88
- expect.anything(),
89
- )
90
- })
91
-
92
- it('never reuses a recorded name that points at a different repository here', async () => {
93
- state.repositories = [
94
- { name: 'podinfo', url: 'https://impostor.example.test/charts' },
95
- { name: 'podinfo-2', url: 'https://other.example.test' },
96
- ]
97
- await renderDialog()
98
- expect(document.body.textContent).toContain('Saved in Helm as podinfo-3. The name podinfo already points to a different repository here.')
91
+ async function click(text: string) { await act(async () => button(text).click()) }
99
92
 
100
- await act(async () => addRecordedButton()?.click())
101
- expect(state.addRepository).toHaveBeenCalledWith(
102
- { name: 'podinfo-3', url: recordedURL, namespace: 'web', releaseName: 'storefront' },
103
- expect.anything(),
104
- )
93
+ async function fill(input: HTMLInputElement, value: string) {
94
+ await act(async () => {
95
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, value)
96
+ input.dispatchEvent(new Event('input', { bubbles: true }))
105
97
  })
98
+ }
106
99
 
107
- it('is disabled for a non-owner, who is told who can add sources', async () => {
108
- state.isOwner = false
109
- await renderDialog()
110
- expect(addRecordedButton()?.disabled).toBe(true)
111
- expect(document.body.textContent).toContain('Only organization owners can add or remove chart sources.')
112
- })
113
-
114
- it('is not offered when the recorded source is configured, OCI, or not recorded', async () => {
115
- for (const status of [
116
- { ...movedMachine, configured: true },
117
- { recorded: { type: 'oci' as const, reference: 'oci://ghcr.io/example/charts' }, configured: false, available: false },
118
- { configured: false, available: false },
119
- ]) {
120
- state.status = status
121
- await renderDialog()
122
- expect(addRecordedButton()).toBeUndefined()
100
+ async function chooseRecorded() {
101
+ const item = document.querySelector<HTMLButtonElement>(`button[aria-label="Choose configured source: ${recordedURL}"]`)
102
+ expect(item).not.toBeNull()
103
+ await act(async () => item?.click())
104
+ }
105
+
106
+ async function searchPublic() {
107
+ await click('ArtifactHub')
108
+ await click('Search ArtifactHub')
109
+ }
110
+
111
+ async function choosePublic(url: string) {
112
+ const item = document.querySelector<HTMLButtonElement>(`button[aria-label="Choose source: ${url}"]`)
113
+ expect(item).not.toBeNull()
114
+ await act(async () => item?.click())
115
+ }
116
+
117
+ describe('compact source picker', () => {
118
+ it.each(['public HTTP', 'public OCI', 'manual HTTP', 'manual OCI', 'recorded restore', 'source check'])('ignores a stale %s completion after closing and reopening the same release', async scenario => {
119
+ const onClose = vi.fn()
120
+ let complete: () => void = () => { throw new Error('Mutation was not started') }
121
+ const capture = (_input: unknown, callbacks: { onSuccess: (result: { name: string }) => void }) => {
122
+ complete = () => callbacks.onSuccess({ name: 'podinfo' })
123
123
  }
124
+ state.addRepository.mockImplementation(capture)
125
+ state.addOCI.mockImplementation(capture)
126
+ state.associateSource.mockImplementation(capture)
127
+ if (scenario === 'source check') state.status = { ...movedMachine, recorded: undefined, revision: 1, candidates: [{ type: 'repository', reference: 'podinfo', url: recordedURL }] }
128
+ await renderDialog(vi.fn(), true, onClose)
129
+ if (scenario.startsWith('public')) {
130
+ const url = scenario === 'public OCI' ? 'oci://ghcr.io/stefanprodan/charts/podinfo' : recordedURL
131
+ state.searchCharts = [{ packageId: 'podinfo', name: 'podinfo', version: '6.15.0', stars: 0, repository: { name: 'podinfo', url } }]
132
+ await searchPublic()
133
+ await choosePublic(url)
134
+ await click(scenario === 'public OCI' ? 'Register OCI source' : 'Add repository')
135
+ } else if (scenario.startsWith('manual')) {
136
+ await click('Add manually')
137
+ if (scenario === 'manual OCI') {
138
+ await click('OCI registry')
139
+ const input = document.querySelector<HTMLInputElement>('input')
140
+ if (!input) throw new Error('Missing OCI prefix input')
141
+ await fill(input, 'oci://ghcr.io/stefanprodan/charts')
142
+ } else {
143
+ const fields = document.querySelectorAll<HTMLInputElement>('input')
144
+ await fill(fields[0], 'podinfo')
145
+ await fill(fields[1], recordedURL)
146
+ }
147
+ await act(async () => document.querySelector('form')?.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })))
148
+ } else {
149
+ await chooseRecorded()
150
+ await click(scenario === 'recorded restore' ? 'Add repository and use it' : 'Check and record source')
151
+ }
152
+ await renderDialog(vi.fn(), false, onClose)
153
+ await renderDialog(vi.fn(), true, onClose)
154
+ if (document.querySelector('form')) await click('Back to sources')
155
+ await click('Add manually')
156
+ await click('Helm repository')
157
+ const field = document.querySelector<HTMLInputElement>('input')
158
+ if (!field) throw new Error('Missing repository name')
159
+ await fill(field, 'new-session-input')
160
+ await act(async () => complete())
161
+ expect(document.querySelector('form')).not.toBeNull()
162
+ expect(document.querySelector<HTMLInputElement>('input')?.value).toBe('new-session-input')
163
+ expect(onClose).not.toHaveBeenCalled()
164
+ })
165
+ it('shows one source list and keeps setup and search behind their own views', async () => {
166
+ state.status = { ...movedMachine, revision: 1 }
167
+ await renderDialog(vi.fn())
168
+ expect(document.querySelectorAll('button[aria-label^="Choose configured source:"]')).toHaveLength(1)
169
+ expect(document.querySelector('input')).toBeNull()
170
+ expect(document.body.textContent).not.toContain('Search ArtifactHub')
171
+ expect(button('Select for upgrade').disabled).toBe(true)
172
+ await click('Add manually')
173
+ expect(document.querySelectorAll('form')).toHaveLength(1)
174
+ expect(document.querySelector('[role="tablist"]')).toBeNull()
175
+ expect(document.querySelector('[placeholder="Repository name"]')).not.toBeNull()
176
+ expect(document.querySelector('[placeholder^="oci://"]')).toBeNull()
177
+ await click('OCI registry')
178
+ expect(document.querySelector('[placeholder="Repository name"]')).toBeNull()
179
+ expect(document.querySelector('[placeholder^="oci://"]')).not.toBeNull()
124
180
  })
125
- })
126
181
 
182
+ it('restores a recorded source only after selection, retaining the existing associate shortcut', async () => {
183
+ await renderDialog()
184
+ expect(state.addRepository).not.toHaveBeenCalled()
185
+ await chooseRecorded()
186
+ await click('Add repository and use it')
187
+ expect(state.addRepository).toHaveBeenCalledWith({ name: 'podinfo', url: recordedURL, namespace: 'web', releaseName: 'storefront' }, expect.anything())
188
+ })
127
189
 
128
- describe('explicit source choices', () => {
129
- it('keeps the recorded source visible and selects a different publisher without associating it', async () => {
130
- const recorded = { type: 'repository' as const, reference: 'official', url: 'https://official.example.test/charts' }
131
- const other = { type: 'repository' as const, reference: 'other', url: 'https://other.example.test/charts' }
132
- state.status = { recorded, configured: true, available: true, confirmed: true, revision: 4, candidates: [recorded, other], suggestions: [
133
- { source: recorded, current: true, hasInstalledVersion: true, state: 'available' },
134
- { source: other, current: false, hasInstalledVersion: true, state: 'available' },
135
- ] }
136
- const select = vi.fn()
137
- await renderDialog(select)
138
- const choices = Array.from(document.querySelectorAll('button')).filter(button => button.textContent?.includes('Select for upgrade'))
139
- expect(choices).toHaveLength(2)
140
- expect(choices[0].getAttribute('aria-label')).toContain(recorded.url)
141
- expect(choices[1].parentElement?.textContent).toContain('Other source')
142
- await act(async () => choices[1].click())
143
- expect(select).toHaveBeenCalledWith({source: other, expectedRevision: 4, expectedSource: recorded})
190
+ it('picks a free alias and adds without binding when the recorded source needs confirmation', async () => {
191
+ state.status = { ...movedMachine, confirmed: false }
192
+ state.repositories = [{ name: 'podinfo', url: 'https://other.example.test' }]
193
+ await renderDialog()
194
+ await chooseRecorded()
195
+ expect(document.body.textContent).toContain('podinfo-2')
196
+ await click('Add repository')
197
+ expect(state.addRepository).toHaveBeenCalledWith({ name: 'podinfo-2', url: recordedURL }, expect.anything())
144
198
  expect(state.associateSource).not.toHaveBeenCalled()
145
199
  })
146
200
 
147
- it('offers a pruned mirror for an explicit upgrade without claiming it supplied the installed version', async () => {
148
- const mirror = { type: 'repository' as const, reference: 'mirror', url: 'https://mirror.example.test/charts' }
149
- state.status = { configured: false, available: false, confirmed: false, revision: 1, candidates: [], suggestions: [
150
- { source: mirror, current: false, hasInstalledVersion: false, state: 'available' },
201
+ it.each(['owner', 'operator'])('prevents configuration writes when restricted by %s policy', async policy => {
202
+ state.isOwner = policy !== 'owner'
203
+ state.configManaged = policy === 'operator'
204
+ await renderDialog()
205
+ await chooseRecorded()
206
+ expect(button('Add repository and use it').disabled).toBe(true)
207
+ await click('Add manually')
208
+ expect(button('Add repository').disabled).toBe(true)
209
+ expect(document.querySelector<HTMLInputElement>('input')?.disabled).toBe(true)
210
+ await click('OCI registry')
211
+ expect(document.querySelector<HTMLInputElement>('input')?.disabled).toBe(true)
212
+ expect(button('Register OCI source').disabled).toBe(true)
213
+ })
214
+
215
+ it('links the active source tab to its panel and supports keyboard navigation', async () => {
216
+ await renderDialog()
217
+ const tabs = document.querySelectorAll<HTMLButtonElement>('[role="tab"]')
218
+ const panel = document.querySelector('[role="tabpanel"]')
219
+ expect(tabs[0].getAttribute('aria-controls')).toBe(panel?.id)
220
+ expect(panel?.getAttribute('aria-labelledby')).toBe(tabs[0].id)
221
+ await act(async () => tabs[0].dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true })))
222
+ expect(tabs[1].getAttribute('aria-selected')).toBe('true')
223
+ expect(document.activeElement).toBe(tabs[1])
224
+ expect(document.querySelector('[role="tabpanel"]')?.getAttribute('aria-labelledby')).toBe(tabs[1].id)
225
+ await act(async () => tabs[1].dispatchEvent(new KeyboardEvent('keydown', { key: 'Home', bubbles: true })))
226
+ expect(tabs[0].getAttribute('aria-selected')).toBe('true')
227
+ expect(document.activeElement).toBe(tabs[0])
228
+ })
229
+
230
+ it('keeps explicit source selection and revision expectations without associating the release', async () => {
231
+ const current = { type: 'repository' as const, reference: 'current', url: recordedURL }
232
+ const other = { type: 'repository' as const, reference: 'other', url: 'https://other.example.test' }
233
+ state.status = { recorded: current, configured: true, available: true, confirmed: true, revision: 4, suggestions: [
234
+ { source: current, current: true, hasInstalledVersion: true, state: 'available' },
235
+ { source: other, current: false, hasInstalledVersion: false, state: 'available' },
151
236
  ] }
152
237
  const select = vi.fn()
153
238
  await renderDialog(select)
154
- const button = Array.from(document.querySelectorAll('button')).find(item => item.textContent?.includes('Select for upgrade'))
155
- expect(button).toBeDefined()
156
- await act(async () => button?.click())
157
- expect(select).toHaveBeenCalledWith({source: mirror, expectedRevision: 1, expectedSource: null})
239
+ await act(async () => document.querySelector<HTMLButtonElement>(`button[aria-label="Choose configured source: ${other.url}"]`)?.click())
240
+ await click('Select for upgrade')
241
+ expect(select).toHaveBeenCalledWith({ source: other, expectedRevision: 4, expectedSource: current })
158
242
  expect(state.associateSource).not.toHaveBeenCalled()
159
243
  })
160
244
 
161
- it('does not offer source switching on a backend without the capability', async () => {
245
+ it('preserves installed-version verification as a separate selected-source action', async () => {
246
+ const source = { type: 'repository' as const, reference: 'podinfo', url: recordedURL }
247
+ state.status = { configured: false, available: false, confirmed: false, revision: 1, candidates: [source] }
248
+ await renderDialog(vi.fn())
249
+ await chooseRecorded()
250
+ await click('Check and record source')
251
+ expect(state.associateSource).toHaveBeenCalledWith(source, expect.anything())
252
+ })
253
+
254
+ it('allows original-source verification for unchecked OCI and blocks it after a failed source change', async () => {
255
+ const source = { type: 'oci' as const, reference: 'oci://registry.example.test/team/podinfo' }
256
+ state.status = { configured: false, available: false, confirmed: false, revision: 1, suggestions: [{ source, current: false, hasInstalledVersion: false, state: 'unchecked' }] }
257
+ await renderDialog(vi.fn())
258
+ await act(async () => document.querySelector<HTMLButtonElement>('button[aria-label^="Choose configured source:"]')?.click())
259
+ await click('Check and record source')
260
+ expect(state.associateSource).toHaveBeenCalledWith(source, expect.anything())
261
+ state.status = { ...state.status, sourceChangeRequired: true }
262
+ await renderDialog(vi.fn())
263
+ expect(document.body.textContent).not.toContain('Check and record source')
264
+ })
265
+
266
+ it('disables release actions while source status is refreshing', async () => {
267
+ state.status = { ...movedMachine, configured: true, revision: 1 }
268
+ state.statusFetching = true
269
+ await renderDialog(vi.fn())
270
+ await chooseRecorded()
271
+ expect(button('Select for upgrade').disabled).toBe(true)
272
+ })
273
+
274
+ it('does not expose public discovery or source switching on an unsupported backend', async () => {
162
275
  state.featureSupported = false
163
- state.status = { configured: false, available: false, revision: 1, suggestions: [
164
- { source: {type: 'repository', reference: 'mirror', url: 'https://mirror.example.test/charts'}, current: false, hasInstalledVersion: false, state: 'available' },
165
- ] }
166
276
  await renderDialog(vi.fn())
277
+ expect(document.body.textContent).not.toContain('ArtifactHub')
167
278
  expect(document.body.textContent).not.toContain('Select for upgrade')
168
279
  })
280
+
281
+ it('resets a selected source and the active view when the release changes', async () => {
282
+ await renderDialog(vi.fn())
283
+ await chooseRecorded()
284
+ await click('Add manually')
285
+ await act(async () => root.render(<TrackChartSourceDialog open onClose={() => undefined} chartName="podinfo" namespace="web" releaseName="another-release" onSelectUpgradeSource={vi.fn()} />))
286
+ expect(document.querySelector('form')).toBeNull()
287
+ expect(document.querySelector('[aria-pressed="true"]')).toBeNull()
288
+ })
289
+
290
+ it('filters a long configured list without hiding an off-page selection in the action footer', async () => {
291
+ state.status = { configured: false, available: false, revision: 1, suggestions: Array.from({ length: 60 }, (_, i) => ({ source: { type: 'repository' as const, reference: `repo-${i}`, url: `https://repo-${i}.example.test` }, current: false, hasInstalledVersion: true, state: 'available' })) }
292
+ await renderDialog(vi.fn())
293
+ const filter = document.querySelector<HTMLInputElement>('input[aria-label="Filter configured sources"]')
294
+ expect(filter).not.toBeNull()
295
+ expect(document.querySelector('[aria-label="Configured chart sources"]')?.className).toContain('overflow-y-auto')
296
+ await act(async () => document.querySelector<HTMLButtonElement>('button[aria-label^="Choose configured source:"]')?.click())
297
+ expect(button('Select for upgrade').disabled).toBe(false)
298
+ if (!filter) throw new Error('Missing configured-source filter')
299
+ await fill(filter, 'repo-59.')
300
+ expect(document.querySelectorAll('button[aria-label^="Choose configured source:"]')).toHaveLength(1)
301
+ expect(button('Select for upgrade').disabled).toBe(true)
302
+ })
169
303
  })
170
304
 
305
+ describe('public discovery keeps the existing configuration contract', () => {
306
+ const chart: ArtifactHubChart = { packageId: 'podinfo', name: 'podinfo', version: '6.15.0', stars: 0, repository: { name: 'podinfo', url: recordedURL } }
171
307
 
172
- describe('OCI original-source verification', () => {
173
- it('can verify and record an unchecked registered OCI source without upgrading', async () => {
174
- const source = { type: 'oci' as const, reference: 'oci://registry.example.test/team/podinfo' }
175
- state.status = { configured: false, available: false, revision: 1, confirmed: false, candidates: [], suggestions: [
176
- {source, current: false, hasInstalledVersion: false, state: 'unchecked'},
177
- ] }
308
+ it('adds only the selected HTTP result without binding or selecting an upgrade', async () => {
309
+ state.searchCharts = [chart]
310
+ state.repositories = [{ name: 'podinfo', url: 'https://other.example.test' }]
178
311
  const select = vi.fn()
179
312
  await renderDialog(select)
180
- const button = Array.from(document.querySelectorAll('button')).find(item => item.textContent === 'Verify and record original source')
181
- expect(button).toBeDefined()
182
- await act(async () => button?.click())
183
- expect(state.associateSource).toHaveBeenCalledWith(source, expect.anything())
313
+ await searchPublic()
314
+ expect(button('Add repository').disabled).toBe(true)
315
+ await choosePublic(recordedURL)
316
+ await click('Add repository')
317
+ expect(state.addRepository).toHaveBeenCalledWith({ name: 'podinfo-2', url: recordedURL }, expect.anything())
318
+ expect(state.associateSource).not.toHaveBeenCalled()
184
319
  expect(select).not.toHaveBeenCalled()
185
320
  })
186
- })
187
321
 
188
- it('shows the no-source hint when the backend omits empty suggestions', async () => {
189
- state.status = { configured: false, available: false, revision: 1 }
190
- await renderDialog(vi.fn())
191
- expect(document.body.textContent).toContain('No configured sources found. Add a repository or OCI source.')
322
+ it('registers the OCI parent rather than duplicating the chart name', async () => {
323
+ const url = 'oci://ghcr.io/stefanprodan/charts/podinfo'
324
+ state.searchCharts = [{ ...chart, repository: { name: 'podinfo', url } }]
325
+ await renderDialog()
326
+ await searchPublic()
327
+ await choosePublic(url)
328
+ await click('Register OCI source')
329
+ expect(state.addOCI).toHaveBeenCalledWith('oci://ghcr.io/stefanprodan/charts', expect.anything())
330
+ expect(state.associateSource).not.toHaveBeenCalled()
331
+ })
332
+
333
+ it('sends an already configured result back to its existing source instead of adding it again', async () => {
334
+ state.searchCharts = [chart]
335
+ state.repositories = [{ name: 'existing', url: `${recordedURL}/` }]
336
+ await renderDialog()
337
+ await searchPublic()
338
+ await choosePublic(recordedURL)
339
+ await click('Show in My Repos')
340
+ expect(document.querySelector('[role="tab"][aria-selected="true"]')?.textContent).toBe('My Repos')
341
+ expect(state.addRepository).not.toHaveBeenCalled()
342
+ })
343
+
344
+ it('does not let non-owners add a discovered source', async () => {
345
+ state.searchCharts = [chart]
346
+ state.isOwner = false
347
+ await renderDialog()
348
+ await searchPublic()
349
+ await choosePublic(recordedURL)
350
+ expect(button('Add repository').disabled).toBe(true)
351
+ })
352
+
353
+ it('recognizes equivalent OCI hosts while keeping repository path case significant', async () => {
354
+ const url = 'oci://registry.example.test/Team/podinfo'
355
+ state.searchCharts = [{ ...chart, repository: { name: 'podinfo', url } }]
356
+ state.ociSources = ['oci://REGISTRY.example.test/Team/']
357
+ await renderDialog()
358
+ await searchPublic()
359
+ await choosePublic(url)
360
+ expect(button('Show in My Repos')).toBeDefined()
361
+ state.ociSources = ['oci://registry.example.test/team']
362
+ await renderDialog()
363
+ expect(button('Register OCI source')).toBeDefined()
364
+ })
192
365
  })