@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
@@ -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` (or `?whats-new=v1.15.0`) opens it on demand for previews, and
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 target = releaseNotesFor(previewParam)?.version ?? currentVersion ?? RELEASE_NOTES[0]?.version
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, currentVersion, show])
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')
@@ -1,5 +1,5 @@
1
1
  import type { LucideIcon } from 'lucide-react'
2
- import { Bot, Database, GitCompareArrows, HardDrive, Hourglass, Layers, Network, RefreshCcw, Scale, ScrollText, SlidersHorizontal, Undo2 } from 'lucide-react'
2
+ import { Bot, Database, GitCompareArrows, HardDrive, Hourglass, Layers, Network, RefreshCcw, Scale, ScrollText, Search, SlidersHorizontal, Undo2 } from 'lucide-react'
3
3
  import { compareVersions } from '../../utils/version'
4
4
 
5
5
  export interface ReleaseHighlight {
@@ -41,12 +41,65 @@ export interface ReleaseNotes {
41
41
 
42
42
  export const CHANGELOG_URL = 'https://radarhq.io/changelog'
43
43
 
44
+ // Read .agents/skills/whats-new/SKILL.md before authoring or regrouping notes.
44
45
  // One entry per release that has something to announce. A user sees the
45
46
  // entries for the releases they haven't seen yet, composed into one dialog, so
46
47
  // a patch upgrade, or one that skips releases, still gets them. Every minor and
47
48
  // major release must have its own entry: scripts/check-whats-new.sh refuses to
48
49
  // release one without it.
49
50
  export const RELEASE_NOTES: ReleaseNotes[] = [
51
+ {
52
+ version: 'v1.18.0',
53
+ highlights: [
54
+ {
55
+ id: 'trivy-cve-search',
56
+ icon: Search,
57
+ title: 'Investigate CVEs across your cluster',
58
+ description: 'Search Trivy findings by CVE, package or image, including in resource tables. MCP agents can inventory declared runtime versions.',
59
+ leadDescription: 'With Trivy Operator installed, search globally or within report tables by CVE, package, failed check ID or image to find matching scan reports, then open a report for installed and fixed package versions. Partial searches say what could not be checked. MCP agents can also inventory runtime versions declared by running images and compare supported versions with a fixed release. Missing or unreadable declarations stay unknown; image metadata does not verify a fix.',
60
+ importance: 8,
61
+ },
62
+ {
63
+ id: 'mcp-guidance-waits-controls',
64
+ icon: Bot,
65
+ title: 'More capable agents through MCP',
66
+ description: 'MCP agents get built-in tool guidance and can wait for rollouts, readiness or deletion. An optional read-only mode exposes only read tools.',
67
+ importance: 5,
68
+ },
69
+ {
70
+ id: 'investigation-change-evidence',
71
+ icon: GitCompareArrows,
72
+ title: 'See more of what changed',
73
+ description: 'Investigations show more spec edits, NetworkPolicy changes, Secret rotations and stale env readers, and flag incomplete history.',
74
+ importance: 5,
75
+ },
76
+ {
77
+ id: 'workload-blockers',
78
+ icon: Network,
79
+ title: 'Better issue detection and warnings',
80
+ description: 'Issues catch more network, storage and scheduling problems, add diagnostic context, and flag checks that could not complete.',
81
+ importance: 5,
82
+ path: '/issues',
83
+ cta: 'Open Issues',
84
+ },
85
+ {
86
+ id: 'log-viewer-improvements',
87
+ icon: ScrollText,
88
+ title: 'Log viewer improvements',
89
+ description: 'Keep your place in fast-moving logs, select text without auto-scroll, and wait for containers to start with clearer status messages.',
90
+ importance: 4,
91
+ },
92
+ ],
93
+ improvements: [
94
+ 'Resource tables remember your column order for each kind',
95
+ 'Open terminals and browse files in native sidecars',
96
+ 'Node drains keep results visible and name remaining Pods',
97
+ 'Audits recognize shared Pod CPU and memory budgets',
98
+ 'Helm upgrades need a confirmed source; find public sources on ArtifactHub',
99
+ 'Prometheus reconnects automatically when it appears',
100
+ 'Argo CD views confirm when a local resource is missing',
101
+ ],
102
+ },
50
103
  {
51
104
  version: 'v1.17.0',
52
105
  highlights: [
@@ -217,7 +270,7 @@ export function releaseNotesFor(
217
270
  ): ReleaseNotes | undefined {
218
271
  if (!version) return undefined
219
272
  const normalized = version.startsWith('v') ? version : `v${version}`
220
- return catalog.find(notes => notes.version === normalized)
273
+ return catalog.find(notes => notes.version === normalized || releaseLine(notes.version) === normalized)
221
274
  }
222
275
 
223
276
  /** The release line a catalog entry covers, e.g. v1.15 for v1.15.0: its patches show the same notes. */
@@ -264,9 +317,8 @@ export function unreadReleases(
264
317
  export const RELEASE_WEIGHTS = [1, 0.75, 0.5]
265
318
  export const MAX_CARDS = 5
266
319
  export const MAX_LINES = 8
267
- // The dialog opens by itself only when the cards it shows add up to this.
268
- // A release of mostly 4-6s stays behind the unread dot; one with a few solid
269
- // features, or a skipped release with them, opens it.
320
+ // A fuller set of useful improvements can merit an announcement even without
321
+ // a single release-defining feature.
270
322
  export const AUTO_OPEN_SCORE = 25
271
323
 
272
324
  export interface ComposedHighlight extends ReleaseHighlight {
@@ -0,0 +1,35 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { CronJobSchedulingContext, CronJobSchedulingDetails } from './CronJobSchedulingEvidence'
4
+ import type { CronJobSchedulingEvidence } from '../../api/client'
5
+
6
+ const report: CronJobSchedulingEvidence = {
7
+ uid: 'current-cronjob', state: 'reported', reason: 'InvalidSchedule',
8
+ message: 'original report from Kubernetes', last_reported_at: '2026-10-21T08:00:00Z',
9
+ }
10
+
11
+ describe('CronJob scheduling evidence', () => {
12
+ it('does not duplicate an operational report with a second notice', () => {
13
+ expect(renderToStaticMarkup(<CronJobSchedulingContext evidence={report} onViewTimeline={() => {}} />)).toBe('')
14
+ })
15
+ it('makes an edited future schedule neutral and keeps its evidence accessible', () => {
16
+ const html = renderToStaticMarkup(<CronJobSchedulingContext evidence={{ ...report, state: 'configuration_changed', configuration_changed_at: '2026-10-21T08:05:00Z' }} onViewTimeline={() => {}} />)
17
+ expect(html).toContain('Schedule changed after this error')
18
+ expect(html).toContain('Kubernetes has not recorded a scheduled run since the change.')
19
+ expect(html).toContain('Earlier report')
20
+ expect(html).toContain(report.message)
21
+ expect(html).toContain('View timeline')
22
+ expect(html).not.toContain('Operational issues')
23
+ expect(html).not.toContain('Warning')
24
+ })
25
+ it('does not call incomplete history recovery or a confirmed current failure', () => {
26
+ const html = renderToStaticMarkup(<CronJobSchedulingContext evidence={{ ...report, state: 'history_incomplete', history_incomplete: true }} onViewTimeline={() => {}} />)
27
+ expect(html).toContain('Scheduling history is incomplete')
28
+ expect(html).toContain('cannot establish whether it still applies')
29
+ })
30
+ it('provides the report date and existing timeline navigation in expanded evidence', () => {
31
+ const html = renderToStaticMarkup(<CronJobSchedulingDetails evidence={report} onViewTimeline={() => {}} />)
32
+ expect(html).toContain('Last reported')
33
+ expect(html).toContain('View timeline')
34
+ })
35
+ })
@@ -0,0 +1,37 @@
1
+ import { Clock, Info } from 'lucide-react'
2
+ import { AlertBanner, CardSection, Disclosure, TimeValue } from '@skyhook-io/k8s-ui'
3
+ import type { CronJobSchedulingEvidence } from '../../api/client'
4
+
5
+ type EvidenceProps = { evidence: CronJobSchedulingEvidence; onViewTimeline: () => void }
6
+
7
+ export function CronJobSchedulingDetails({ evidence, onViewTimeline }: EvidenceProps) {
8
+ return (
9
+ <CardSection icon={Clock} label="Scheduling evidence">
10
+ <p className="text-sm text-theme-text-secondary">Last reported: <TimeValue timestamp={evidence.last_reported_at} />.</p>
11
+ {evidence.configuration_changed_at && <p className="text-sm text-theme-text-secondary">Scheduling settings changed: <TimeValue timestamp={evidence.configuration_changed_at} />.</p>}
12
+ {evidence.history_incomplete && <p className="text-sm text-theme-text-secondary">Some history is unavailable. The report's current relevance cannot be fully verified.</p>}
13
+ <button type="button" onClick={onViewTimeline} className="self-start text-left text-sm font-medium text-accent-text hover:underline">View timeline</button>
14
+ </CardSection>
15
+ )
16
+ }
17
+
18
+ export function CronJobSchedulingContext({ evidence, onViewTimeline }: { evidence?: CronJobSchedulingEvidence; onViewTimeline: () => void }) {
19
+ if (!evidence || evidence.state === 'reported') return null
20
+ const changed = evidence.state === 'configuration_changed'
21
+ return (
22
+ <AlertBanner
23
+ variant="info"
24
+ icon={Info}
25
+ title={changed ? 'Schedule changed after this error' : 'Scheduling history is incomplete'}
26
+ message={changed ? 'Kubernetes has not recorded a scheduled run since the change.' : 'A scheduling error was reported, but retained history cannot establish whether it still applies.'}
27
+ className="mb-0"
28
+ >
29
+ <Disclosure summary="Earlier report" className="mt-2" summaryClassName="text-xs text-theme-text-secondary">
30
+ <div className="mt-3 space-y-3">
31
+ <pre className="whitespace-pre-wrap break-words rounded bg-theme-elevated p-3 text-xs text-theme-text-secondary">{evidence.message}</pre>
32
+ <CronJobSchedulingDetails evidence={evidence} onViewTimeline={onViewTimeline} />
33
+ </div>
34
+ </Disclosure>
35
+ </AlertBanner>
36
+ )
37
+ }
@@ -0,0 +1,253 @@
1
+ // @vitest-environment jsdom
2
+ import { act, useEffect } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
+ import { afterEach, beforeEach, expect, it, vi } from 'vitest'
6
+ import { NodeDrainStatus } from './NodeDrainStatus'
7
+ import { useDrainNode, useSetActiveNamespace, nodeDrainActivityKey, type NodeDrainActivity, type NamespaceScope } from '../../api/client'
8
+ import { setApiBase } from '../../api/config'
9
+ import { refreshQueriesAfterReconnect } from '../../context/ConnectionContext'
10
+
11
+ let host: HTMLDivElement
12
+ let root: Root
13
+ let client: QueryClient
14
+ let start: () => Promise<unknown>
15
+ let respond: (response: Response) => void
16
+ let reject: (error: Error) => void
17
+
18
+ function Harness({ uid = 'node-uid', visible = true }: { uid?: string; visible?: boolean }) {
19
+ const { mutateAsync } = useDrainNode(uid)
20
+ useEffect(() => {
21
+ start = () => mutateAsync({ name: 'worker' }).catch(() => undefined)
22
+ }, [mutateAsync])
23
+ return visible ? <NodeDrainStatus name="worker" nodeUID={uid} /> : null
24
+ }
25
+
26
+ async function render(uid = 'node-uid', visible = true) {
27
+ await act(async () => {
28
+ root.render(<QueryClientProvider client={client}><Harness uid={uid} visible={visible} /></QueryClientProvider>)
29
+ })
30
+ }
31
+
32
+ async function flush() {
33
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)) })
34
+ }
35
+
36
+ beforeEach(() => {
37
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
38
+ setApiBase('/api')
39
+ host = document.createElement('div')
40
+ document.body.append(host)
41
+ root = createRoot(host)
42
+ client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
43
+ vi.stubGlobal('fetch', vi.fn(() => new Promise<Response>((resolve, fail) => { respond = resolve; reject = fail })))
44
+ })
45
+
46
+ afterEach(() => {
47
+ act(() => root.unmount())
48
+ client.clear()
49
+ host.remove()
50
+ vi.useRealTimers()
51
+ vi.unstubAllGlobals()
52
+ setApiBase('/api')
53
+ })
54
+
55
+ it('retains completion when the view changes before the request finishes', async () => {
56
+ await render()
57
+ expect(host.textContent).toBe('')
58
+ let pending: Promise<unknown> | undefined
59
+ await act(async () => { pending = start() })
60
+ await flush()
61
+ expect(host.textContent).toContain('Drain in progress')
62
+ expect(host.textContent).toContain('2m 0s')
63
+ await render('', false)
64
+ await act(async () => {
65
+ respond(Response.json({ outcome: 'complete', evictedPods: ['shop/web'], waitedForDeletion: true }))
66
+ await pending
67
+ })
68
+ await flush()
69
+ await render()
70
+ expect(host.textContent).toContain('Drain complete: 1 pod removed')
71
+ expect(host.textContent).toContain('Last drain in this tab:')
72
+ expect(host.textContent).toContain('The node was left cordoned.')
73
+ expect(host.textContent).not.toContain('The node remains cordoned.')
74
+ expect(host.querySelector('time')?.dateTime).toBeTruthy()
75
+ expect(fetch).toHaveBeenCalledTimes(1)
76
+ await act(async () => { pending = start() })
77
+ await flush()
78
+ expect(host.textContent).toContain('Drain in progress')
79
+ await act(async () => { respond(Response.json({ outcome: 'complete' })); await pending })
80
+ await flush()
81
+ expect(host.textContent).toContain('Nothing to evict')
82
+ })
83
+
84
+ it('retains pending state on return and isolates node UID and API base', async () => {
85
+ await render()
86
+ let pending: Promise<unknown> | undefined
87
+ await act(async () => { pending = start() })
88
+ await flush()
89
+ await render('replacement-uid')
90
+ expect(host.textContent).toBe('')
91
+ setApiBase('/c/other/api')
92
+ await render()
93
+ expect(host.textContent).toBe('')
94
+ setApiBase('/api')
95
+ await render()
96
+ expect(host.textContent).toContain('Drain in progress')
97
+ await act(async () => {
98
+ respond(Response.json({ outcome: 'incomplete', skippedPods: [{ namespace: 'shop', name: 'bare', expectedSkip: false, reason: 'protected' }] }))
99
+ await pending
100
+ })
101
+ await flush()
102
+ expect(host.textContent).toContain('Drain incomplete: 1 pod left on the node')
103
+ })
104
+
105
+ it('preserves request failure as uncertainty without inheriting automatic mutation retries', async () => {
106
+ vi.stubGlobal('crypto', undefined)
107
+ client.setDefaultOptions({ mutations: { retry: 1 } })
108
+ await render()
109
+ let pending: Promise<unknown> | undefined
110
+ await act(async () => { pending = start() })
111
+ await act(async () => { reject(new Error('Connection lost')); await pending })
112
+ await flush()
113
+ expect(host.textContent).toContain('Could not confirm drain completion')
114
+ expect(host.textContent).toContain('Connection lost')
115
+ expect(host.textContent).toContain('does not confirm whether evictions ran')
116
+ expect(fetch).toHaveBeenCalledTimes(1)
117
+ })
118
+
119
+ it('dismisses the recorded result and retains it past the normal cache lifetime until then', async () => {
120
+ await render()
121
+ let pending: Promise<unknown> | undefined
122
+ await act(async () => { pending = start() })
123
+ await act(async () => { respond(Response.json({ outcome: 'complete' })); await pending })
124
+ await flush()
125
+ await render('', false)
126
+ vi.useFakeTimers()
127
+ await act(async () => { await vi.advanceTimersByTimeAsync(10 * 60 * 1000) })
128
+ await render()
129
+ expect(host.textContent).toContain('Nothing to evict')
130
+ await act(async () => { host.querySelector<HTMLButtonElement>('button')?.click(); await vi.advanceTimersByTimeAsync(0) })
131
+ expect(host.textContent).toBe('')
132
+ await render('', false)
133
+ await render()
134
+ expect(host.textContent).toBe('')
135
+ })
136
+
137
+ it('retains a running drain and its final result across a same-context reconnect', async () => {
138
+ client.setQueryData(['cluster-info'], { context: 'same' })
139
+ const invalidate = vi.spyOn(client, 'invalidateQueries')
140
+ await render()
141
+ let pending: Promise<unknown> | undefined
142
+ await act(async () => { pending = start() })
143
+ await act(async () => { refreshQueriesAfterReconnect(client, 'same', 'same') })
144
+ await flush()
145
+ expect(host.textContent).toContain('Drain in progress')
146
+ await act(async () => { respond(Response.json({ outcome: 'complete' })); await pending })
147
+ await flush()
148
+ expect(host.textContent).toContain('Nothing to evict')
149
+ expect(invalidate).toHaveBeenCalledWith({ queryKey: ['topology'] })
150
+ })
151
+
152
+ it('refreshes the node when cluster-info first arrives during a drain', async () => {
153
+ const invalidate = vi.spyOn(client, 'invalidateQueries')
154
+ await render()
155
+ let pending: Promise<unknown> | undefined
156
+ await act(async () => { pending = start() })
157
+ await act(async () => {
158
+ client.setQueryData(['cluster-info'], { context: 'first-load' })
159
+ respond(Response.json({ outcome: 'complete' }))
160
+ await pending
161
+ })
162
+ await flush()
163
+ expect(host.textContent).toContain('Nothing to evict')
164
+ expect(invalidate).toHaveBeenCalledWith({ queryKey: ['resource', 'nodes', '', 'worker'] })
165
+ })
166
+
167
+ it('records completion for the original API base without showing it on another host', async () => {
168
+ await render()
169
+ let pending: Promise<unknown> | undefined
170
+ await act(async () => { pending = start() })
171
+ setApiBase('/c/other/api')
172
+ await render()
173
+ await act(async () => { respond(Response.json({ outcome: 'complete' })); await pending })
174
+ await flush()
175
+ expect(host.textContent).toBe('')
176
+ setApiBase('/api')
177
+ await render()
178
+ expect(host.textContent).toContain('Nothing to evict')
179
+ })
180
+
181
+ it('keeps cluster-scoped drain activity when changing the namespace inventory', async () => {
182
+ let change: (() => Promise<unknown>) | undefined
183
+ function Switch() {
184
+ const { mutateAsync } = useSetActiveNamespace()
185
+ useEffect(() => { change = () => mutateAsync({ namespaces: ['team-a'] }) }, [mutateAsync])
186
+ return <NodeDrainStatus name="worker" nodeUID="node-uid" />
187
+ }
188
+ client.setQueryData(nodeDrainActivityKey('/api', 'worker', 'node-uid'), {
189
+ status: 'pending', startedAt: Date.now(), timeoutSeconds: 120, requestId: 1,
190
+ })
191
+ client.setQueryData(['resources', 'pods'], ['old-pod'])
192
+ await act(async () => {
193
+ root.render(<QueryClientProvider client={client}><Switch /></QueryClientProvider>)
194
+ })
195
+ let pending: Promise<unknown> | undefined
196
+ await act(async () => { pending = change?.() })
197
+ const scope: NamespaceScope = {
198
+ actives: ['team-a'], kubeconfigNamespace: '', mode: 'namespace',
199
+ accessibleNamespaces: ['team-a'], deniedNamespaces: [], authoritative: true,
200
+ canClearNamespace: false, cacheScoped: true, namespaceRescope: true,
201
+ }
202
+ await act(async () => {
203
+ respond(Response.json(scope))
204
+ await pending
205
+ })
206
+ await flush()
207
+ expect(host.textContent).toContain('Drain in progress')
208
+ expect(client.getQueryData(['resources', 'pods'])).toBeUndefined()
209
+ })
210
+
211
+ it('does not recreate a result after the context cache was cleared', async () => {
212
+ await render()
213
+ let pending: Promise<unknown> | undefined
214
+ await act(async () => { pending = start() })
215
+ await render('', false)
216
+ client.removeQueries()
217
+ await act(async () => { respond(Response.json({ outcome: 'complete' })); await pending })
218
+ await render()
219
+ expect(host.textContent).toBe('')
220
+ })
221
+
222
+ it('does not let an older response replace the latest drain result', async () => {
223
+ await render()
224
+ let first: Promise<unknown> | undefined
225
+ let second: Promise<unknown> | undefined
226
+ await act(async () => { first = start() })
227
+ const respondFirst = respond
228
+ await act(async () => { second = start() })
229
+ await act(async () => {
230
+ respond(Response.json({ outcome: 'incomplete', pendingPods: ['shop/web'] }))
231
+ await second
232
+ })
233
+ await flush()
234
+ await act(async () => {
235
+ respondFirst(Response.json({ outcome: 'complete' }))
236
+ await first
237
+ })
238
+ await flush()
239
+ expect(host.textContent).toContain('Drain incomplete: 1 pod left on the node')
240
+ expect(host.textContent).not.toContain('Nothing to evict')
241
+ })
242
+
243
+ it('shows elapsed time and overdue response guidance without inventing a completed outcome', async () => {
244
+ vi.useFakeTimers()
245
+ const activity: NodeDrainActivity = { status: 'pending', startedAt: Date.now(), timeoutSeconds: 120, requestId: 1 }
246
+ client.setQueryData(nodeDrainActivityKey('/api', 'worker', 'node-uid'), activity)
247
+ await render()
248
+ await act(async () => { await vi.advanceTimersByTimeAsync(126_000) })
249
+ expect(host.textContent).toContain('Elapsed 2m 6s')
250
+ expect(host.textContent).toContain("Still waiting for Radar's response")
251
+ expect(host.textContent).toContain('Drain in progress')
252
+ expect(host.querySelector('button')).toBeNull()
253
+ })
@@ -0,0 +1,55 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { Clock, X } from 'lucide-react'
3
+ import { AlertBanner } from '@skyhook-io/k8s-ui'
4
+ import { useNodeDrainActivity } from '../../api/client'
5
+
6
+ function duration(milliseconds: number): string {
7
+ const seconds = Math.max(0, Math.floor(milliseconds / 1000))
8
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`
9
+ }
10
+
11
+ export function NodeDrainStatus({ name, nodeUID }: { name: string; nodeUID: string }) {
12
+ const { activity, dismiss } = useNodeDrainActivity(name, nodeUID)
13
+ const [now, setNow] = useState(Date.now)
14
+ const pending = activity?.status === 'pending'
15
+ useEffect(() => {
16
+ if (!pending) return
17
+ const timer = window.setInterval(() => setNow(Date.now()), 1000)
18
+ return () => window.clearInterval(timer)
19
+ }, [pending, activity?.startedAt])
20
+
21
+ if (!activity) return null
22
+ if (activity.status === 'pending') {
23
+ const elapsed = now - activity.startedAt
24
+ return (
25
+ <section aria-label="Drain progress">
26
+ <AlertBanner variant="info" icon={Clock} title="Drain in progress">
27
+ <p>Requesting evictions and waiting for pod deletion.</p>
28
+ <p className="mt-1">Elapsed {duration(elapsed)}. Shared eviction and deletion deadline: {duration(activity.timeoutSeconds * 1000)}. A final verification check can take up to 5 seconds more.</p>
29
+ {elapsed > (activity.timeoutSeconds + 5) * 1000 && (
30
+ <p className="mt-1">Still waiting for Radar's response. Check the connection and the node's pods before retrying or taking it down.</p>
31
+ )}
32
+ <p className="mt-1">You can leave this page and return while this tab stays open.</p>
33
+ </AlertBanner>
34
+ </section>
35
+ )
36
+ }
37
+
38
+ return (
39
+ <section aria-label="Last drain in this tab">
40
+ <AlertBanner
41
+ variant={activity.summary.type}
42
+ title={activity.summary.title}
43
+ action={(
44
+ <button type="button" aria-label="Dismiss drain result" onClick={dismiss} className="text-theme-text-secondary hover:text-theme-text-primary p-1 rounded focus-visible:outline focus-visible:outline-2">
45
+ <X className="w-4 h-4" />
46
+ </button>
47
+ )}
48
+ >
49
+ <p className="text-xs mt-1">Last drain in this tab: <time dateTime={new Date(activity.finishedAt).toISOString()}>{new Date(activity.finishedAt).toLocaleString()}</time>. Duration {duration(activity.finishedAt - activity.startedAt)}.</p>
50
+ <p className="text-xs mt-2 whitespace-pre-line break-words">{activity.summary.detail}</p>
51
+ <p className="text-xs mt-2">Recorded result. Later node or workload changes are not reflected here. Reloading or switching contexts clears this tab's record.</p>
52
+ </AlertBanner>
53
+ </section>
54
+ )
55
+ }