@skyhook-io/radar-app 1.22.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +131 -38
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/RadarApp.tsx +5 -0
  6. package/src/api/agentSandbox.ts +259 -0
  7. package/src/api/client.autoPromConnect.test.tsx +43 -0
  8. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  9. package/src/api/client.ts +128 -25
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/prometheusCharts.ts +5 -0
  15. package/src/api/radarFeatures.test.ts +9 -0
  16. package/src/api/radarFeatures.ts +13 -0
  17. package/src/api/substrateWorkspace.test.ts +72 -0
  18. package/src/api/substrateWorkspace.ts +1394 -0
  19. package/src/api/vulnerabilities.ts +207 -9
  20. package/src/api/workloadSource.test.tsx +1172 -0
  21. package/src/api/workloadSource.ts +408 -0
  22. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  23. package/src/components/APIUnreachableBanner.tsx +20 -0
  24. package/src/components/CloudConnectFlow.tsx +46 -7
  25. package/src/components/CloudFunnelButton.test.tsx +193 -7
  26. package/src/components/CloudFunnelButton.tsx +127 -32
  27. package/src/components/ConnectionErrorView.test.tsx +63 -2
  28. package/src/components/ConnectionErrorView.tsx +88 -68
  29. package/src/components/SelfManagedStart.tsx +12 -2
  30. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  31. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  32. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  33. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  34. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  35. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  36. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  37. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  38. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  39. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  40. package/src/components/agentsandbox/data.ts +135 -0
  41. package/src/components/agentsandbox/host.test.ts +27 -0
  42. package/src/components/agentsandbox/host.tsx +85 -0
  43. package/src/components/agentsandbox/labels.test.ts +42 -0
  44. package/src/components/agentsandbox/labels.ts +146 -0
  45. package/src/components/agentsandbox/listFilters.ts +85 -0
  46. package/src/components/agentsandbox/lists.ts +52 -0
  47. package/src/components/agentsandbox/routes.ts +23 -0
  48. package/src/components/agentsandbox/shared.tsx +321 -0
  49. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  50. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  51. package/src/components/agentsandbox/workspace.tsx +258 -0
  52. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  53. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  54. package/src/components/applications/ApplicationsView.tsx +156 -3
  55. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  56. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  57. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  58. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  59. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  60. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  61. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  62. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  63. package/src/components/cloudHints/cloudHints.ts +131 -0
  64. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  65. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  66. package/src/components/cloudHints/cloudLinks.ts +31 -0
  67. package/src/components/cloudHints/hintStorage.ts +28 -0
  68. package/src/components/cnpg/CNPGView.tsx +4 -7
  69. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  70. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  71. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  72. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  73. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  74. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  75. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  76. package/src/components/diagnose/Home.test.tsx +6 -0
  77. package/src/components/diagnose/Home.tsx +10 -3
  78. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  79. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  80. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  81. package/src/components/diagnose/InvestigationView.tsx +120 -23
  82. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  83. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  84. package/src/components/diagnose/investigationState.ts +9 -0
  85. package/src/components/diagnose/parts.test.tsx +11 -3
  86. package/src/components/diagnose/toolCallLabel.ts +3 -0
  87. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  88. package/src/components/home/ActivitySummary.tsx +3 -8
  89. package/src/components/home/ClusterHealthCard.tsx +91 -17
  90. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  91. package/src/components/home/HomeAgentBlock.tsx +2 -0
  92. package/src/components/home/HomeView.tsx +9 -29
  93. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  94. package/src/components/home/MCPSetupDialog.tsx +6 -2
  95. package/src/components/home/McpCloudLine.test.tsx +162 -0
  96. package/src/components/home/McpCloudLine.tsx +95 -0
  97. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  98. package/src/components/home/TopologyPreview.test.tsx +31 -30
  99. package/src/components/home/TopologyPreview.tsx +19 -28
  100. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  101. package/src/components/home/mcpToolCatalog.ts +7 -7
  102. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  103. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  104. package/src/components/issues/IssuesPane.tsx +181 -23
  105. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  106. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  107. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  108. package/src/components/issues/sinceLastVisit.ts +439 -0
  109. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  110. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  111. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  112. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  113. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  114. package/src/components/kagent/KagentLists.tsx +412 -0
  115. package/src/components/kagent/KagentOverview.tsx +234 -0
  116. package/src/components/kagent/KagentPages.tsx +690 -0
  117. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  118. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  119. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  120. package/src/components/kagent/KagentView.tsx +109 -0
  121. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  122. package/src/components/kagent/host.tsx +144 -0
  123. package/src/components/kagent/routes.ts +31 -0
  124. package/src/components/kagent/shared.tsx +336 -0
  125. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  126. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  127. package/src/components/kagent/workspace.fixtures.ts +108 -0
  128. package/src/components/kagent/workspaceRoute.ts +18 -0
  129. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  130. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  131. package/src/components/resource/PrometheusCharts.tsx +10 -1
  132. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  133. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  134. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  135. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  136. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  137. package/src/components/resources/ResourcesView.tsx +2 -6
  138. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  139. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  140. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  141. package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
  142. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  143. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  144. package/src/components/settings/SettingsDialog.tsx +84 -16
  145. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  146. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  147. package/src/components/settings/SubstrateSettings.tsx +544 -0
  148. package/src/components/settings/settings-state.test.ts +21 -3
  149. package/src/components/settings/settings-state.ts +13 -3
  150. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  151. package/src/components/share/ShareLinkButton.tsx +391 -0
  152. package/src/components/share/openShareInCloud.test.ts +29 -0
  153. package/src/components/share/openShareInCloud.ts +10 -0
  154. package/src/components/share/shareLink.test.ts +129 -0
  155. package/src/components/share/shareLink.ts +175 -0
  156. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  157. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  158. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  159. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  160. package/src/components/substrate/SubstrateActors.tsx +612 -0
  161. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  162. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  163. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  164. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  165. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  166. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  167. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  168. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  169. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  170. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  171. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  172. package/src/components/substrate/SubstrateView.tsx +173 -0
  173. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  174. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  175. package/src/components/substrate/attention.ts +81 -0
  176. package/src/components/substrate/contextPin.tsx +69 -0
  177. package/src/components/substrate/host.tsx +83 -0
  178. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  179. package/src/components/substrate/readings.test.ts +484 -0
  180. package/src/components/substrate/readings.ts +997 -0
  181. package/src/components/substrate/routes.ts +103 -0
  182. package/src/components/substrate/shared.tsx +426 -0
  183. package/src/components/substrate/substrate.fixtures.ts +325 -0
  184. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  185. package/src/components/substrate/workspaceRoute.ts +23 -0
  186. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  187. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  188. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  189. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  190. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  191. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  192. package/src/components/traffic/TrafficGraph.tsx +17 -14
  193. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  194. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  195. package/src/components/traffic/TrafficView.tsx +26 -56
  196. package/src/components/traffic/trafficFilters.test.ts +61 -1
  197. package/src/components/traffic/trafficFilters.ts +68 -8
  198. package/src/components/velero/VeleroOverview.tsx +2 -2
  199. package/src/components/velero/VeleroView.tsx +3 -6
  200. package/src/components/vulnerabilities/columns.tsx +132 -0
  201. package/src/components/vulnerabilities/filters.tsx +317 -0
  202. package/src/components/vulnerabilities/owner.test.ts +54 -0
  203. package/src/components/vulnerabilities/owner.tsx +163 -0
  204. package/src/components/vulnerabilities/parts.test.ts +126 -12
  205. package/src/components/vulnerabilities/parts.tsx +612 -52
  206. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  207. package/src/components/vulnerabilities/traffic.tsx +40 -0
  208. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  209. package/src/components/workload/WorkloadView.tsx +119 -14
  210. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  211. package/src/components/workspace/layout.tsx +13 -7
  212. package/src/components/workspace/sidebar.test.ts +48 -0
  213. package/src/components/workspace/sidebar.ts +73 -3
  214. package/src/components/workspace/table.ts +2 -1
  215. package/src/context/ConnectionContext.tsx +24 -5
  216. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  217. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  218. package/src/context/DiagnoseCustomization.tsx +20 -2
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/hooks/useEventSource.test.tsx +275 -4
  222. package/src/hooks/useEventSource.ts +278 -51
  223. package/src/index.ts +1 -0
  224. package/src/integrations/resourceHost.ts +12 -6
  225. package/src/integrations/resourceHosts.test.tsx +27 -1
  226. package/src/integrations/resourceHosts.tsx +15 -7
  227. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  228. package/src/integrations/sidebarWorkspaces.ts +41 -0
  229. package/src/integrations/workspaceRoute.ts +1 -1
  230. package/src/integrations/workspaceRoutes.ts +7 -1
  231. package/src/integrations/workspaceScreens.tsx +6 -0
  232. package/src/utils/navigation.test.ts +1 -6
  233. package/src/utils/navigation.ts +9 -44
  234. package/src/utils/network-policy-navigation.test.ts +21 -36
@@ -0,0 +1,71 @@
1
+ import { Clock, X } from "lucide-react";
2
+ import { Tooltip } from "../ui/Tooltip";
3
+ import { CloudHintLink } from "../cloudHints/CloudHintLink";
4
+
5
+ export interface SinceLastVisitRowProps {
6
+ count: number;
7
+ /** The list was capped, so more may have started. */
8
+ atLeast: boolean;
9
+ /** When the person last looked at the list, already formatted. */
10
+ lastVisit: string;
11
+ showingOnlyNew: boolean;
12
+ onToggleOnlyNew: () => void;
13
+ /** The Radar Cloud sentence. The caller decides (useCloudHintsEnabled, and no other Cloud line on the page). */
14
+ cloud: boolean;
15
+ onClose: () => void;
16
+ onTurnOff: () => void;
17
+ }
18
+
19
+ // One row above the Issues list on a visit that has issues which started since
20
+ // the last one. Its own job is the count and a filter to those issues; the one
21
+ // Cloud sentence says what Radar can't do here: tell you as they start.
22
+ export function SinceLastVisitRow({ count, atLeast, lastVisit, showingOnlyNew, onToggleOnlyNew, cloud, onClose, onTurnOff }: SinceLastVisitRowProps) {
23
+ const noun = count === 1 && !atLeast ? "issue" : "issues";
24
+ return (
25
+ <div role="note" aria-label="Issues since your last visit" className="flex flex-wrap items-center gap-x-3 gap-y-1.5 rounded-lg border border-theme-border bg-theme-surface px-3 py-2">
26
+ <Clock className="h-4 w-4 shrink-0 text-theme-text-tertiary" aria-hidden />
27
+ <p className="min-w-0 flex-1 text-sm text-theme-text-secondary">
28
+ <span className="font-medium text-theme-text-primary">
29
+ {atLeast ? "At least " : ""}{count} {noun} started since you last checked
30
+ </span>{" "}
31
+ ({lastVisit}).
32
+ {cloud && (
33
+ <>
34
+ {" "}
35
+ <span className="text-theme-text-tertiary">
36
+ <CloudHintLink entry="since-last-visit" />{" "}
37
+ can alert you when an issue starts.
38
+ </span>
39
+ </>
40
+ )}
41
+ </p>
42
+ <div className="flex shrink-0 items-center gap-2">
43
+ <button
44
+ type="button"
45
+ onClick={onToggleOnlyNew}
46
+ aria-pressed={showingOnlyNew}
47
+ className="whitespace-nowrap rounded-md border border-theme-border px-2 py-1 text-xs font-medium text-accent-text transition-colors hover:bg-theme-hover"
48
+ >
49
+ {showingOnlyNew ? "Show all issues" : count === 1 && !atLeast ? "Show only this one" : "Show only these"}
50
+ </button>
51
+ <button
52
+ type="button"
53
+ onClick={onTurnOff}
54
+ className="whitespace-nowrap px-1 text-xs text-theme-text-tertiary transition-colors hover:text-theme-text-primary"
55
+ >
56
+ Don't show again
57
+ </button>
58
+ <Tooltip content="Hide until your next visit" delay={100} wrapperClassName="shrink-0">
59
+ <button
60
+ type="button"
61
+ aria-label="Hide until your next visit"
62
+ onClick={onClose}
63
+ className="rounded-md p-1 text-theme-text-tertiary transition-colors hover:bg-theme-hover hover:text-theme-text-primary"
64
+ >
65
+ <X className="h-3.5 w-3.5" />
66
+ </button>
67
+ </Tooltip>
68
+ </div>
69
+ </div>
70
+ );
71
+ }
@@ -0,0 +1,266 @@
1
+ // @vitest-environment jsdom
2
+ import { afterEach, describe, expect, it, vi } from 'vitest'
3
+ import {
4
+ CLOUD_SENTENCE_VISITS,
5
+ MAX_LISTED_IDS,
6
+ RECORD_MAX_AGE_MS,
7
+ ONSET_MARGIN_MS,
8
+ VISIT_GAP_MS,
9
+ advanceVisit,
10
+ cloudSentenceAllowed,
11
+ formatVisitTime,
12
+ hashId,
13
+ lastLookAt,
14
+ noteCloudSentence,
15
+ noteListed,
16
+ pruneVisitRecords,
17
+ readVisit,
18
+ resetVisitMemory,
19
+ sinceRowShowsCloudLine,
20
+ sinceRowTurnedOff,
21
+ startedSince,
22
+ turnSinceRowOff,
23
+ updateVisit,
24
+ visibilityKey,
25
+ } from './sinceLastVisit'
26
+
27
+ const t0 = Date.parse('2026-11-27T18:40:00Z')
28
+ const all = { namespaces: [] as string[], complete: true, visibility: '' }
29
+ const iso = (ms: number) => new Date(ms).toISOString()
30
+ const none = new Set<string>()
31
+
32
+ describe('visits', () => {
33
+ it('has no anchor on the first visit, so nothing can be new', () => {
34
+ expect(advanceVisit(undefined, t0)).toEqual({ lastActiveAt: t0 })
35
+ })
36
+
37
+ it('compares the next visit with the lists this one showed', () => {
38
+ const open = advanceVisit(advanceVisit(undefined, t0), t0 + VISIT_GAP_MS)
39
+ expect(open).toEqual({ lastActiveAt: t0 + VISIT_GAP_MS })
40
+ const looked = noteListed(open, ['a', 'b'], t0 + 1000, all)
41
+ const back = advanceVisit(looked, t0 + 2 * VISIT_GAP_MS + 1)
42
+ expect(back.anchor).toBe(t0 + 1000)
43
+ expect(back.prev).toEqual([hashId('a'), hashId('b')])
44
+ expect(back.prevCover).toEqual({ vis: '', allAt: t0 + 1000 })
45
+ expect(back.cur).toBeUndefined()
46
+ expect(back.curListedAt).toBeUndefined()
47
+ })
48
+
49
+ it('keeps the last look when a visit never showed the list', () => {
50
+ const looked = advanceVisit(noteListed({ lastActiveAt: t0 }, ['a'], t0, all), t0 + VISIT_GAP_MS + 1)
51
+ const closed = { ...looked, closedAnchor: t0 }
52
+ const skipped = advanceVisit(closed, t0 + 3 * VISIT_GAP_MS)
53
+ expect(skipped).toEqual({ lastActiveAt: t0 + 3 * VISIT_GAP_MS, anchor: t0, prev: [hashId('a')], prevCover: { vis: '', allAt: t0 }, closedAnchor: t0 })
54
+ })
55
+
56
+ it('drops the closed row once a newer look becomes the anchor', () => {
57
+ const r = noteListed({ lastActiveAt: t0, anchor: t0 - 1000, closedAnchor: t0 - 1000 }, ['a'], t0, all)
58
+ expect(advanceVisit(r, t0 + VISIT_GAP_MS + 1).closedAnchor).toBeUndefined()
59
+ })
60
+
61
+ it('records when complete lists last covered each namespace', () => {
62
+ let r = noteListed({ lastActiveAt: t0 }, ['a'], t0, { namespaces: ['db'], complete: true, visibility: '' })
63
+ r = noteListed(r, ['b'], t0 + 1, { namespaces: ['web'], complete: false, visibility: '' })
64
+ r = noteListed(r, ['c'], t0 + 2, { namespaces: ['shop', 'db'], complete: true, visibility: '' })
65
+ expect(r.curCover).toEqual({ vis: '', nsAt: { db: t0 + 2, shop: t0 + 2 } })
66
+ expect(r.cur).toHaveLength(3)
67
+ expect(r.curListedAt).toBe(t0 + 2)
68
+ })
69
+
70
+ it('dates a look by when its list was fetched, never moving it back', () => {
71
+ // A list kept through failed refreshes is shown again later: still the old look.
72
+ let r = noteListed({ lastActiveAt: t0 }, ['a'], t0, all)
73
+ r = noteListed(r, ['a'], t0, all)
74
+ expect(r.curListedAt).toBe(t0)
75
+ expect(r.curCover?.allAt).toBe(t0)
76
+ r = noteListed(r, ['a'], t0 - 5000, { ...all, namespaces: ['db'] })
77
+ expect(r.curListedAt).toBe(t0)
78
+ expect(r.curCover?.nsAt).toEqual({ db: t0 - 5000 })
79
+ })
80
+
81
+ it('stops counting lists as complete past the id cap', () => {
82
+ const ids = Array.from({ length: MAX_LISTED_IDS + 10 }, (_, i) => `issue-${i}`)
83
+ const r = noteListed({ lastActiveAt: t0 }, ids, t0, all)
84
+ expect(r.cur).toHaveLength(MAX_LISTED_IDS)
85
+ expect(r.curCover).toBeUndefined()
86
+ })
87
+ })
88
+
89
+ describe('startedSince', () => {
90
+ const last = { listed: none, cover: { allAt: t0 }, visibility: '' }
91
+ const issue = { id: 'x', namespace: 'db', first_seen: iso(t0 + ONSET_MARGIN_MS + 60_000) }
92
+
93
+ it('counts an issue missing from the last complete list whose known onset is after it', () => {
94
+ expect(startedSince(issue, last)).toBe(true)
95
+ })
96
+
97
+ it('never counts an issue whose onset is unknown', () => {
98
+ expect(startedSince({ id: 'x', namespace: 'db', onset_unknown: true }, last)).toBe(false)
99
+ expect(startedSince({ ...issue, onset_unknown: true }, last)).toBe(false)
100
+ expect(startedSince({ id: 'x', namespace: 'db' }, last)).toBe(false)
101
+ expect(startedSince({ ...issue, first_seen: 'not a time' }, last)).toBe(false)
102
+ })
103
+
104
+ it('never counts a grouped issue when any signal has an unknown onset', () => {
105
+ expect(startedSince({ ...issue, onset_coverage: { known: 2, unknown: 1 } }, last)).toBe(false)
106
+ expect(startedSince({ ...issue, onset_coverage: { known: 3, unknown: 0 } }, last)).toBe(true)
107
+ })
108
+
109
+ it('leaves out issues that started before or just after the last look', () => {
110
+ expect(startedSince({ ...issue, first_seen: iso(t0 - 60_000) }, last)).toBe(false)
111
+ expect(startedSince({ ...issue, first_seen: iso(t0 + ONSET_MARGIN_MS) }, last)).toBe(false)
112
+ })
113
+
114
+ it('leaves out an issue that was on the last list, even with a recent first_seen', () => {
115
+ // An Event's first timestamp restarts while the problem goes on.
116
+ expect(startedSince(issue, { ...last, listed: new Set([hashId('x')]) })).toBe(false)
117
+ })
118
+
119
+ it('leaves out an issue the last lists could not have shown', () => {
120
+ expect(startedSince(issue, { ...last, cover: undefined })).toBe(false)
121
+ expect(startedSince(issue, { ...last, cover: { nsAt: { web: t0 } } })).toBe(false)
122
+ expect(startedSince(issue, { ...last, cover: { nsAt: { db: t0 } } })).toBe(true)
123
+ // Cluster-scoped issues need a list of every namespace.
124
+ expect(startedSince({ ...issue, namespace: undefined }, { ...last, cover: { nsAt: { db: t0 } } })).toBe(false)
125
+ expect(startedSince({ ...issue, namespace: undefined }, last)).toBe(true)
126
+ })
127
+
128
+ it('judges each issue against the latest look that covered it', () => {
129
+ // db looked at 13:00, web at 14:00; a db issue from 13:30 is new.
130
+ const hour = 3600_000
131
+ const cover = { nsAt: { db: t0, web: t0 + hour } }
132
+ const at = iso(t0 + hour / 2)
133
+ expect(startedSince({ id: 'db-1', namespace: 'db', first_seen: at }, { listed: none, cover, visibility: '' })).toBe(true)
134
+ expect(startedSince({ id: 'web-1', namespace: 'web', first_seen: at }, { listed: none, cover, visibility: '' })).toBe(false)
135
+ expect(lastLookAt({ namespace: 'db' }, { allAt: t0 + hour, nsAt: { db: t0 } }, '')).toBe(t0 + hour)
136
+ })
137
+ })
138
+
139
+ describe('visibility', () => {
140
+ const limited = visibilityKey({ state: 'limited', impact: 'Secrets are hidden.' })
141
+ const issue = { id: 'x', namespace: 'db', first_seen: iso(t0 + ONSET_MARGIN_MS + 60_000) }
142
+
143
+ it('compares only lists read with the same permissions', () => {
144
+ const r = noteListed({ lastActiveAt: t0 }, [], t0, { ...all, visibility: limited })
145
+ expect(startedSince(issue, { listed: none, cover: r.curCover, visibility: limited })).toBe(true)
146
+ // Permissions widened since: an issue that was hidden then isn't new now.
147
+ expect(startedSince(issue, { listed: none, cover: r.curCover, visibility: '' })).toBe(false)
148
+ })
149
+
150
+ it('starts the coverage again when permissions change within a visit', () => {
151
+ let r = noteListed({ lastActiveAt: t0 }, [], t0, { ...all, visibility: limited })
152
+ r = noteListed(r, [], t0 + 1, { namespaces: ['db'], complete: true, visibility: '' })
153
+ expect(r.curCover).toEqual({ vis: '', nsAt: { db: t0 + 1 } })
154
+ r = noteListed(r, [], t0 + 2, { ...all, complete: false, visibility: limited })
155
+ expect(r.curCover).toBeUndefined()
156
+ })
157
+ })
158
+
159
+ describe('formatVisitTime', () => {
160
+ it('names the day for the last week and the date before that', () => {
161
+ const at = new Date(2026, 10, 27, 18, 40).getTime()
162
+ expect(formatVisitTime(at, at + 3600_000, 'en-GB')).toBe('today 18:40')
163
+ expect(formatVisitTime(at, at + 2 * 24 * 3600_000, 'en-GB')).toBe('Fri 18:40')
164
+ expect(formatVisitTime(at, at + 9 * 24 * 3600_000, 'en-GB')).toBe('27 Nov, 18:40')
165
+ })
166
+ })
167
+
168
+ describe('cloud line', () => {
169
+ it('shows only with the row and with Cloud enabled', () => {
170
+ expect(sinceRowShowsCloudLine({ rowVisible: true, cloudEnabled: true })).toBe(true)
171
+ expect(sinceRowShowsCloudLine({ rowVisible: true, cloudEnabled: false })).toBe(false)
172
+ expect(sinceRowShowsCloudLine({ rowVisible: false, cloudEnabled: true })).toBe(false)
173
+ })
174
+ })
175
+
176
+ describe('storage', () => {
177
+ afterEach(() => {
178
+ vi.restoreAllMocks()
179
+ window.localStorage.clear()
180
+ resetVisitMemory()
181
+ })
182
+
183
+ it('persists the record and the opt-out', () => {
184
+ updateVisit('k', (r) => advanceVisit(r, t0))
185
+ expect(JSON.parse(window.localStorage.getItem('radar:since-last-visit:k')!)).toEqual({ lastActiveAt: t0 })
186
+ resetVisitMemory()
187
+ expect(readVisit('k')).toEqual({ lastActiveAt: t0 })
188
+ turnSinceRowOff('ana')
189
+ resetVisitMemory()
190
+ expect(sinceRowTurnedOff('ana')).toBe(true)
191
+ // Another person in the same browser still sees the row.
192
+ expect(sinceRowTurnedOff('ben')).toBe(false)
193
+ })
194
+
195
+ it('keeps working in memory when storage is blocked, and forgets on reload', () => {
196
+ vi.spyOn(window, 'localStorage', 'get').mockImplementation(() => {
197
+ throw new DOMException('denied', 'SecurityError')
198
+ })
199
+ updateVisit('k', (r) => noteListed(advanceVisit(r, t0), ['a'], t0, all))
200
+ updateVisit('k', (r) => advanceVisit(r, t0 + VISIT_GAP_MS + 1))
201
+ expect(readVisit('k')?.anchor).toBe(t0)
202
+ updateVisit('k', (r) => (r ? { ...r, closedAnchor: r.anchor } : undefined))
203
+ expect(readVisit('k')?.closedAnchor).toBe(t0)
204
+ turnSinceRowOff('')
205
+ expect(sinceRowTurnedOff('')).toBe(true)
206
+
207
+ resetVisitMemory()
208
+ expect(readVisit('k')).toBeUndefined()
209
+ expect(sinceRowTurnedOff('')).toBe(false)
210
+ })
211
+
212
+ it('keeps an accepted change for the page when a write fails', () => {
213
+ vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
214
+ throw new DOMException('full', 'QuotaExceededError')
215
+ })
216
+ turnSinceRowOff('')
217
+ expect(sinceRowTurnedOff('')).toBe(true)
218
+ })
219
+
220
+ it('drops the stored record when a write fails, so a reload compares nothing', () => {
221
+ updateVisit('k', (r) => noteListed(advanceVisit(r, t0), ['a'], t0, all))
222
+ updateVisit('k', (r) => advanceVisit(r, t0 + VISIT_GAP_MS + 1))
223
+ expect(readVisit('k')?.anchor).toBe(t0)
224
+ vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
225
+ throw new DOMException('full', 'QuotaExceededError')
226
+ })
227
+ updateVisit('k', (r) => noteListed(r!, ['b'], t0 + VISIT_GAP_MS + 2, all))
228
+ expect(readVisit('k')?.cur).toEqual([hashId('b')])
229
+ resetVisitMemory()
230
+ expect(readVisit('k')).toBeUndefined()
231
+ })
232
+
233
+ it('ignores a record it cannot read', () => {
234
+ window.localStorage.setItem('radar:since-last-visit:k', '{"lastActiveAt":"soon"}')
235
+ expect(readVisit('k')).toBeUndefined()
236
+ window.localStorage.setItem('radar:since-last-visit:k', 'not json')
237
+ expect(readVisit('k')).toBeUndefined()
238
+ })
239
+ })
240
+
241
+ describe('housekeeping', () => {
242
+ it('drops records not active for a month, and keeps the rest', () => {
243
+ updateVisit('old', () => ({ lastActiveAt: t0 - RECORD_MAX_AGE_MS - 1 }))
244
+ updateVisit('recent', () => ({ lastActiveAt: t0 - 1000 }))
245
+ turnSinceRowOff('alice')
246
+ noteCloudSentence('alice', t0)
247
+ pruneVisitRecords(t0)
248
+ expect(readVisit('old')).toBeUndefined()
249
+ expect(readVisit('recent')?.lastActiveAt).toBe(t0 - 1000)
250
+ expect(sinceRowTurnedOff('alice')).toBe(true)
251
+ expect(cloudSentenceAllowed('alice', t0)).toBe(true)
252
+ })
253
+
254
+ it('shows the Radar Cloud sentence on the first few visits only', () => {
255
+ const anchors = Array.from({ length: CLOUD_SENTENCE_VISITS }, (_, i) => t0 + i)
256
+ for (const a of anchors) {
257
+ expect(cloudSentenceAllowed('bob', a)).toBe(true)
258
+ noteCloudSentence('bob', a)
259
+ }
260
+ // A visit it already showed on keeps it, for as long as that visit lasts.
261
+ expect(cloudSentenceAllowed('bob', anchors[0])).toBe(true)
262
+ expect(cloudSentenceAllowed('bob', t0 + 100)).toBe(false)
263
+ // Per person.
264
+ expect(cloudSentenceAllowed('carol', t0 + 100)).toBe(true)
265
+ })
266
+ })