@skyhook-io/radar-app 1.22.2 → 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 (196) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +35 -10
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +122 -24
  9. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  10. package/src/api/diagnose.ts +4 -0
  11. package/src/api/kagent.test.ts +82 -0
  12. package/src/api/kagent.ts +230 -0
  13. package/src/api/prometheusCharts.ts +5 -0
  14. package/src/api/radarFeatures.test.ts +9 -0
  15. package/src/api/radarFeatures.ts +13 -0
  16. package/src/api/substrateWorkspace.test.ts +72 -0
  17. package/src/api/substrateWorkspace.ts +1394 -0
  18. package/src/api/vulnerabilities.ts +207 -9
  19. package/src/api/workloadSource.test.tsx +315 -0
  20. package/src/api/workloadSource.ts +128 -12
  21. package/src/components/CloudConnectFlow.tsx +46 -7
  22. package/src/components/CloudFunnelButton.test.tsx +193 -7
  23. package/src/components/CloudFunnelButton.tsx +127 -32
  24. package/src/components/SelfManagedStart.tsx +12 -2
  25. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  26. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  27. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  28. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  29. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  30. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  31. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  32. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  33. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  34. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  35. package/src/components/agentsandbox/data.ts +135 -0
  36. package/src/components/agentsandbox/host.test.ts +27 -0
  37. package/src/components/agentsandbox/host.tsx +85 -0
  38. package/src/components/agentsandbox/labels.test.ts +42 -0
  39. package/src/components/agentsandbox/labels.ts +146 -0
  40. package/src/components/agentsandbox/listFilters.ts +85 -0
  41. package/src/components/agentsandbox/lists.ts +52 -0
  42. package/src/components/agentsandbox/routes.ts +23 -0
  43. package/src/components/agentsandbox/shared.tsx +321 -0
  44. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  45. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  46. package/src/components/agentsandbox/workspace.tsx +258 -0
  47. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  48. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  49. package/src/components/applications/ApplicationsView.tsx +156 -3
  50. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  51. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  52. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  53. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  54. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  55. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  56. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  57. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  58. package/src/components/cloudHints/cloudHints.ts +131 -0
  59. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  60. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  61. package/src/components/cloudHints/cloudLinks.ts +31 -0
  62. package/src/components/cloudHints/hintStorage.ts +28 -0
  63. package/src/components/cnpg/CNPGView.tsx +4 -7
  64. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  65. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  66. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  67. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  68. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  69. package/src/components/home/HomeAgentBlock.tsx +2 -0
  70. package/src/components/home/HomeView.tsx +3 -3
  71. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  72. package/src/components/home/MCPSetupDialog.tsx +6 -2
  73. package/src/components/home/McpCloudLine.test.tsx +162 -0
  74. package/src/components/home/McpCloudLine.tsx +95 -0
  75. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  76. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  77. package/src/components/home/mcpToolCatalog.ts +4 -4
  78. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  79. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  80. package/src/components/issues/IssuesPane.tsx +181 -23
  81. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  82. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  83. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  84. package/src/components/issues/sinceLastVisit.ts +439 -0
  85. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  86. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  87. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  88. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  89. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  90. package/src/components/kagent/KagentLists.tsx +412 -0
  91. package/src/components/kagent/KagentOverview.tsx +234 -0
  92. package/src/components/kagent/KagentPages.tsx +690 -0
  93. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  94. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  95. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  96. package/src/components/kagent/KagentView.tsx +109 -0
  97. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  98. package/src/components/kagent/host.tsx +144 -0
  99. package/src/components/kagent/routes.ts +31 -0
  100. package/src/components/kagent/shared.tsx +336 -0
  101. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  102. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  103. package/src/components/kagent/workspace.fixtures.ts +108 -0
  104. package/src/components/kagent/workspaceRoute.ts +18 -0
  105. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  106. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  107. package/src/components/resource/PrometheusCharts.tsx +10 -1
  108. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  109. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  110. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  111. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  112. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  113. package/src/components/resources/ResourcesView.tsx +2 -6
  114. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  115. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  116. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  117. package/src/components/settings/SettingsDialog.tsx +84 -16
  118. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  119. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  120. package/src/components/settings/SubstrateSettings.tsx +544 -0
  121. package/src/components/settings/settings-state.test.ts +21 -3
  122. package/src/components/settings/settings-state.ts +13 -3
  123. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  124. package/src/components/share/ShareLinkButton.tsx +391 -0
  125. package/src/components/share/openShareInCloud.test.ts +29 -0
  126. package/src/components/share/openShareInCloud.ts +10 -0
  127. package/src/components/share/shareLink.test.ts +129 -0
  128. package/src/components/share/shareLink.ts +175 -0
  129. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  130. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  131. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  132. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  133. package/src/components/substrate/SubstrateActors.tsx +612 -0
  134. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  135. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  136. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  137. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  138. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  139. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  140. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  141. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  142. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  143. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  144. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  145. package/src/components/substrate/SubstrateView.tsx +173 -0
  146. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  147. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  148. package/src/components/substrate/attention.ts +81 -0
  149. package/src/components/substrate/contextPin.tsx +69 -0
  150. package/src/components/substrate/host.tsx +83 -0
  151. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  152. package/src/components/substrate/readings.test.ts +484 -0
  153. package/src/components/substrate/readings.ts +997 -0
  154. package/src/components/substrate/routes.ts +103 -0
  155. package/src/components/substrate/shared.tsx +426 -0
  156. package/src/components/substrate/substrate.fixtures.ts +325 -0
  157. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  158. package/src/components/substrate/workspaceRoute.ts +23 -0
  159. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  160. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  161. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  162. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  163. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  164. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  165. package/src/components/traffic/TrafficGraph.tsx +17 -14
  166. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  167. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  168. package/src/components/traffic/TrafficView.tsx +26 -56
  169. package/src/components/traffic/trafficFilters.test.ts +61 -1
  170. package/src/components/traffic/trafficFilters.ts +68 -8
  171. package/src/components/velero/VeleroOverview.tsx +2 -2
  172. package/src/components/velero/VeleroView.tsx +3 -6
  173. package/src/components/vulnerabilities/columns.tsx +132 -0
  174. package/src/components/vulnerabilities/filters.tsx +317 -0
  175. package/src/components/vulnerabilities/owner.test.ts +54 -0
  176. package/src/components/vulnerabilities/owner.tsx +163 -0
  177. package/src/components/vulnerabilities/parts.test.ts +126 -12
  178. package/src/components/vulnerabilities/parts.tsx +612 -52
  179. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  180. package/src/components/vulnerabilities/traffic.tsx +40 -0
  181. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  182. package/src/components/workload/WorkloadView.tsx +52 -13
  183. package/src/components/workspace/layout.tsx +13 -7
  184. package/src/components/workspace/sidebar.test.ts +48 -0
  185. package/src/components/workspace/sidebar.ts +73 -3
  186. package/src/components/workspace/table.ts +2 -1
  187. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  188. package/src/contexts/RegistryAccessMode.tsx +25 -0
  189. package/src/integrations/resourceHost.ts +12 -6
  190. package/src/integrations/resourceHosts.test.tsx +27 -1
  191. package/src/integrations/resourceHosts.tsx +15 -7
  192. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  193. package/src/integrations/sidebarWorkspaces.ts +41 -0
  194. package/src/integrations/workspaceRoute.ts +1 -1
  195. package/src/integrations/workspaceRoutes.ts +7 -1
  196. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,77 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { CommandChip, KubectlTargetContext, substrateKubectlTarget } from './shared'
4
+ import type { SubstrateConnection, SubstrateSettings } from '../../api/substrateWorkspace'
5
+ import { connection, managedConnection } from './substrate.fixtures'
6
+
7
+ const revert = 'kubectl ate revert actor lit-0193 -a research'
8
+ const target = { ...connection().target, context: 'dev-from-other-file', inFileName: 'dev', source: '/home/me/kube configs/staging' }
9
+
10
+ function show(view?: SubstrateConnection, activeContext = target.context) {
11
+ return renderToStaticMarkup(
12
+ <KubectlTargetContext.Provider value={substrateKubectlTarget(view, activeContext)}>
13
+ <CommandChip command={revert} />
14
+ </KubectlTargetContext.Provider>,
15
+ ).replace(/&#x27;/g, "'")
16
+ }
17
+
18
+ function local(settings: SubstrateSettings = { identity: 'shared' }) {
19
+ return connection({ target, saved: true, settings })
20
+ }
21
+
22
+ describe('copyable kubectl ate commands', () => {
23
+ it('waits for the active context’s connection before showing a copy button', () => {
24
+ expect(show()).toBe('')
25
+ expect(show(local(), 'another-context')).toBe('')
26
+ })
27
+
28
+ it('pins a local command to the source file and the name inside that file', () => {
29
+ const html = show(local())
30
+ expect(html).toContain(`${revert} --kubeconfig '/home/me/kube configs/staging' --context dev`)
31
+ expect(html).toContain('aria-label="Copy command"')
32
+ expect(html).not.toContain('--endpoint')
33
+ expect(html).not.toContain('--token-file')
34
+ })
35
+
36
+ it.each(['CAPI', 'relative/kubeconfig', 'C:relative'])('uses guidance for a non-absolute source (%s)', (source) => {
37
+ const html = show(connection({ target: { ...target, source }, saved: true, settings: { identity: 'shared' } }))
38
+ expect(html).toContain('Use kubectl ate with a kubeconfig and context')
39
+ expect(html).not.toContain('--kubeconfig')
40
+ expect(html).not.toContain('Copy command')
41
+ })
42
+
43
+ it.each(['C:\\Users\\me\\config', 'D:/kube/config', '\\\\server\\share\\config'])('accepts an absolute Windows source (%s)', (source) => {
44
+ expect(substrateKubectlTarget(connection({ target: { ...target, source }, saved: true, settings: { identity: 'shared' } }), target.context))
45
+ .toEqual({ context: target.inFileName, kubeconfig: source })
46
+ })
47
+
48
+ it('includes a directly reachable local endpoint and quotes the saved token file path', () => {
49
+ const html = show(local({ identity: 'tokenFile', tokenFile: '/home/me/substrate auth/ate.token', endpoint: '127.0.0.1:18443' }))
50
+ expect(html).toContain('--endpoint 127.0.0.1:18443')
51
+ expect(html).toContain("--token-file '/home/me/substrate auth/ate.token'")
52
+ expect(show(local({ identity: 'tokenFile' }))).not.toContain('--token-file')
53
+ })
54
+
55
+ it.each([{ caFile: '/home/me/ca.pem' }, { serverName: 'ate.example.org' }])('hands off local custom TLS (%j)', (tls) => {
56
+ const html = show(local({ identity: 'shared', endpoint: '127.0.0.1:18443', ...tls }))
57
+ expect(html).toContain('127.0.0.1:18443')
58
+ expect(html).toContain('with the CA and server name')
59
+ expect(html).not.toContain('Copy command')
60
+ expect(html).not.toContain('--endpoint')
61
+ })
62
+
63
+ it('hands off a local cluster DNS endpoint to a machine that can reach it', () => {
64
+ const html = show(local({ identity: 'shared', endpoint: 'api.ate-system.svc:443' }))
65
+ expect(html).toContain('resolve and reach api.ate-system.svc:443')
66
+ expect(html).not.toContain('Copy command')
67
+ })
68
+
69
+ it('names the managed target without copying a cluster-internal endpoint flag', () => {
70
+ const view = managedConnection()
71
+ expect(show(view)).toContain('port-forwards to the ate-system/api Service')
72
+ const html = show({ ...view, managed: { ...view.managed, endpoint: 'other.ate-system.svc:443' } })
73
+ expect(html).toContain('other.ate-system.svc:443')
74
+ expect(html).not.toContain('Copy command')
75
+ expect(html).not.toContain('--endpoint')
76
+ })
77
+ })
@@ -0,0 +1,484 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ COUNTABLE_LIMIT,
4
+ actorStateTone,
5
+ bytesText,
6
+ countText,
7
+ coverageReason,
8
+ cpuText,
9
+ durableText,
10
+ memoryRebuildStep,
11
+ resumesWithText,
12
+ revertCommand,
13
+ segmentCount,
14
+ segmentOfState,
15
+ stateBarSegments,
16
+ poolReadFailure,
17
+ relativeTime,
18
+ servingEvidence,
19
+ splitReading,
20
+ tierReading,
21
+ shortSessionId,
22
+ } from './readings'
23
+ import { ApiError } from '../../api/client'
24
+ import { substrateAttentionCount, substrateScreenCounts } from './attention'
25
+ import { decodeActorParam, encodeActorParam, parseSubstrateRoute, substrateActorPath, substrateActorsPath } from './routes'
26
+ import { segmentStates } from './SubstrateActors'
27
+ import { kagentTemplateText } from './readings'
28
+ import { counts, notConnectedWorkspace, poolShortRow, sharedTier, workspace } from './substrate.fixtures'
29
+
30
+ describe('actor states', () => {
31
+ it('reads suspended as the quietest, a transition in flight in one quiet tone, and a crash as a failure', () => {
32
+ expect(actorStateTone('running')).toBe('healthy')
33
+ expect(actorStateTone('suspended')).toBe('unknown')
34
+ for (const s of ['resuming', 'suspending', 'reverting', 'deleting'] as const) expect(actorStateTone(s)).toBe('neutral')
35
+ expect(actorStateTone('crashed')).toBe('unhealthy')
36
+ expect(actorStateTone('unknown')).toBe('unknown')
37
+ })
38
+
39
+ it('never fills Unknown like Suspended: Unknown keeps Radar’s unknown slate, Suspended a quiet resting fill', async () => {
40
+ const { actorStateFill } = await import('./readings')
41
+ const { toneFillClass } = await import('@skyhook-io/k8s-ui')
42
+ expect(actorStateFill('unknown')).toBe(toneFillClass('unknown'))
43
+ expect(actorStateFill('suspended')).not.toBe(actorStateFill('unknown'))
44
+ // Every state's fill is its own on the bar, the transitions in flight apart, sharing one.
45
+ const states = ['running', 'suspended', 'resuming', 'crashed', 'unknown'] as const
46
+ expect(new Set(states.map(actorStateFill)).size).toBe(states.length)
47
+ for (const s of ['suspending', 'reverting', 'deleting'] as const) expect(actorStateFill(s)).toBe(actorStateFill('resuming'))
48
+ // Drawn: the bar's segments and the legend's dots.
49
+ const { renderToStaticMarkup } = await import('react-dom/server')
50
+ const { createElement } = await import('react')
51
+ const { SubstrateStateBar } = await import('./SubstrateStateBar')
52
+ const html = renderToStaticMarkup(createElement(SubstrateStateBar, { counts: counts({ suspended: 900, unknown: 3, running: 97 }) }))
53
+ const fillOf = (label: string) => new RegExp(`<span aria-hidden="true" class="inline-block h-1.5 w-1.5 rounded-full ([^"]+)"></span>(?:<[^>]+>)*${label} `).exec(html)?.[1]
54
+ expect(fillOf('Suspended')).toBe(actorStateFill('suspended'))
55
+ expect(fillOf('Unknown')).toBe(toneFillClass('unknown'))
56
+ })
57
+
58
+ it('keeps amber for a stuck transition, and says "stuck" in the chip’s words', async () => {
59
+ const { actorStateReading } = await import('./readings')
60
+ const now = Date.parse('2026-11-18T12:00:00Z')
61
+ const ago = (m: number) => new Date(now - m * 60_000).toISOString()
62
+ expect(actorStateReading('resuming', { updateTime: ago(1), now })).toEqual({ label: 'Resuming', severity: 'info' })
63
+ expect(actorStateReading('deleting', { updateTime: ago(51), now })).toMatchObject({ label: 'Deleting · stuck', severity: 'warning' })
64
+ // Without the actor's last change Radar can't judge stuck: the chip stays in flight, never guesses.
65
+ expect(actorStateReading('suspending', { now })).toEqual({ label: 'Suspending', severity: 'info' })
66
+ // A resting state is never stuck, however old.
67
+ expect(actorStateReading('suspended', { updateTime: ago(600), now })).toEqual({ label: 'Suspended', severity: 'neutral' })
68
+ // A worker in trouble names itself first; an unavailable one is at risk (alert), a lost sandbox is lost.
69
+ expect(actorStateReading('running', { impact: { kind: 'unavailable', reading: 'r' }, updateTime: ago(51), now })).toEqual({ label: 'Running · worker unavailable', severity: 'alert', title: 'r' })
70
+ expect(actorStateReading('running', { impact: { kind: 'restarted', reading: 'r' } }).severity).toBe('error')
71
+ expect(actorStateReading('running', { impact: { kind: 'draining', reading: 'r' } }).severity).toBe('warning')
72
+ })
73
+
74
+ it('gives the placement grid the badge’s tones, so its legend and the state bar agree', async () => {
75
+ const { placementTone, workerImpactTone } = await import('./readings')
76
+ for (const s of ['running', 'suspended', 'resuming', 'suspending', 'reverting', 'deleting', 'crashed', 'unknown'] as const) expect(placementTone(s, undefined)).toBe(actorStateTone(s))
77
+ for (const k of ['unavailable', 'draining', 'restarted'] as const) expect(placementTone('running', k)).toBe(workerImpactTone(k))
78
+ // Unavailable and draining read apart: orange and amber.
79
+ expect(placementTone('running', 'unavailable')).toBe('alert')
80
+ expect(placementTone('running', 'draining')).toBe('degraded')
81
+ })
82
+
83
+ it('counts the In progress segment over the four transitions, and leaves unread counts undefined', () => {
84
+ const c = counts({ resuming: 6, suspending: 9, reverting: 2, deleting: 1, running: 3 })
85
+ expect(segmentCount(c, 'inProgress')).toBe(18)
86
+ expect(segmentCount(c, 'all')).toBe(21)
87
+ expect(segmentCount(undefined, 'crashed')).toBeUndefined()
88
+ expect(segmentOfState('reverting')).toBe('inProgress')
89
+ expect(segmentOfState('crashed')).toBe('crashed')
90
+ expect(segmentOfState(null)).toBe('all')
91
+ })
92
+
93
+ it('sends a link’s single transition inside In progress, and all four for the segment itself', () => {
94
+ expect(segmentStates('inProgress', 'resuming')).toEqual(['resuming'])
95
+ expect(segmentStates('inProgress', 'inProgress')).toEqual(['resuming', 'suspending', 'reverting', 'deleting'])
96
+ expect(segmentStates('all', null)).toBeUndefined()
97
+ expect(segmentStates('crashed', null)).toEqual(['crashed'])
98
+ })
99
+
100
+ it('draws one mark per actor up to the countable limit, then proportions', () => {
101
+ const small = stateBarSegments(counts({ running: 3, crashed: 1 }))
102
+ expect(small.countable).toBe(true)
103
+ expect(small.segments.map((s) => s.state)).toEqual(['crashed', 'running'])
104
+ const big = stateBarSegments(counts({ running: COUNTABLE_LIMIT, crashed: 1 }))
105
+ expect(big.countable).toBe(false)
106
+ expect(big.segments[0].share).toBeCloseTo(1 / (COUNTABLE_LIMIT + 1))
107
+ })
108
+ })
109
+
110
+ describe('state reasons', () => {
111
+ it('drops the state word the badge already shows', async () => {
112
+ const { stateExtra } = await import('./readings')
113
+ expect(stateExtra('resuming', 'Resuming for 36m')).toBe('for 36m')
114
+ expect(stateExtra('suspended', 'Upload pending for 36m')).toBe('upload pending for 36m')
115
+ expect(stateExtra('crashed', 'OOMKilled')).toBe('OOMKilled')
116
+ expect(stateExtra('running', undefined)).toBeUndefined()
117
+ })
118
+ })
119
+
120
+ describe('golden snapshots', () => {
121
+ it('reads a build Substrate reports blocked as such', async () => {
122
+ const { goldenReading } = await import('./readings')
123
+ expect(goldenReading({ golden: { state: 'building', blocked: 'noMatchingPool' }, matchingPools: [], matchingPoolsComplete: true }).label).toBe('Can’t build: no pool can run it')
124
+ expect(goldenReading({ golden: { state: 'building' }, matchingPools: null, matchingPoolsComplete: false }).label).toBe('Building')
125
+ expect(goldenReading({ golden: { state: 'failed', error: 'x' }, matchingPools: [], matchingPoolsComplete: true }).label).toBe('Failed')
126
+ })
127
+ })
128
+
129
+ describe('snapshots', () => {
130
+ it('says what a resume does in a sentence that reads on its own', async () => {
131
+ const { resumeSentence } = await import('./readings')
132
+ expect(resumeSentence({ resumeGeneration: 3, newestSnapshot: { generation: 3, durable: 'completed' }, resumesWith: 'memory' })).toBe('Resumes where it left off: the snapshot holds its memory.')
133
+ expect(resumeSentence({ resumeGeneration: 2, newestSnapshot: { generation: 3, durable: 'pending' }, resumesWith: 'memory' })).toContain('It resumes from generation 2: the newest is not stored yet.')
134
+ expect(resumeSentence({ resumesWith: 'cold' })).toBe('Boots fresh: there is no snapshot to resume from.')
135
+ })
136
+
137
+ it('says how each fidelity resumes, and that no snapshot boots fresh', () => {
138
+ expect(resumesWithText('memory')).toBe('resumes where it left off')
139
+ expect(resumesWithText('filesystem')).toContain('saved files')
140
+ expect(resumesWithText('cold')).toBe('boots fresh')
141
+ expect(resumesWithText('unknown')).toContain('unknown')
142
+ })
143
+
144
+ it('names where an unstored snapshot’s files are, never calling it stored', () => {
145
+ expect(durableText({ generation: 1, durable: 'completed' }).text).toBe('stored')
146
+ expect(durableText({ generation: 1, durable: 'pending', locality: 'n1' })).toMatchObject({ text: 'upload pending', tone: 'degraded' })
147
+ expect(durableText({ generation: 1, durable: 'none', locality: 'n1' }).text).toBe('only on n1')
148
+ expect(durableText({ generation: 1, durable: 'none' }).text).toBe('not stored')
149
+ })
150
+
151
+ it('gives the exact kubectl ate revert command', () => {
152
+ expect(revertCommand({ atespace: 'research', name: 'lit-review-0193' })).toBe('kubectl ate revert actor lit-review-0193 -a research')
153
+ })
154
+ })
155
+
156
+ describe('API tier readings', () => {
157
+ it('says what each failure means and what to do', () => {
158
+ expect(tierReading({ state: 'failed', code: 'unreachable', reason: 'dial tcp: connection refused' })).toMatchObject({ title: 'API server unreachable', detail: 'dial tcp: connection refused', tone: 'unhealthy' })
159
+ expect(tierReading({ state: 'failed', code: 'unauthenticated' }).nextStep).toContain('token')
160
+ expect(tierReading({ state: 'failed', code: 'denied' }).nextStep).toContain('viewer role')
161
+ expect(tierReading(sharedTier).detail).toContain('This Radar is shared')
162
+ expect(tierReading({ state: 'notConfigured', code: 'notConfigured' }).title).toBe('Not connected')
163
+ })
164
+
165
+ it('explains a missing user token without suggesting an RBAC grant', () => {
166
+ const reason = 'Sign in with a session that carries a Kubernetes user token.'
167
+ expect(tierReading({ state: 'failed', code: 'userTokenRequired', reason })).toEqual({
168
+ title: 'Sign-in token required', detail: reason, tone: 'unhealthy',
169
+ })
170
+ })
171
+
172
+ it('doesn’t send a reader already in Settings to Settings', () => {
173
+ for (const code of ['notConfigured', 'targetChanged', 'notInstalled', 'tls'] as const) {
174
+ const state = code === 'notConfigured' ? 'notConfigured' : 'failed'
175
+ expect(tierReading({ state, code }).nextStep).toContain('Settings → Agent Substrate')
176
+ expect(tierReading({ state, code }, { inSettings: true }).nextStep ?? '').not.toContain('Settings')
177
+ }
178
+ expect(tierReading({ state: 'notConfigured' }, { inSettings: true }).nextStep).toBeUndefined()
179
+ expect(tierReading({ state: 'failed', code: 'notInstalled' }, { inSettings: true }).nextStep).toContain('under Advanced')
180
+ })
181
+
182
+ it('names denied atespaces and a reached cap', () => {
183
+ expect(coverageReason({ state: 'partial', deniedAtespaces: ['a', 'b'] }, 'actors')).toBe('Substrate denied atespaces a, b')
184
+ expect(coverageReason({ state: 'partial', code: 'capExceeded', cap: 50000 }, 'actors')).toBe('Radar read the first 50000 actors and stopped there')
185
+ })
186
+ })
187
+
188
+ describe('needs-attention severity', () => {
189
+ it('reads the four steps in the house’s tones', async () => {
190
+ const { attentionTone, worstAttentionTone } = await import('./readings')
191
+ expect((['critical', 'alert', 'warning', 'info'] as const).map((severity) => attentionTone({ severity }))).toEqual(['unhealthy', 'alert', 'degraded', 'neutral'])
192
+ expect(worstAttentionTone([{ severity: 'warning' }, { severity: 'alert' }, { severity: 'info' }])).toBe('alert')
193
+ expect(worstAttentionTone([])).toBeUndefined()
194
+ })
195
+
196
+ it('counts an alert row as needing attention, like any but info', () => {
197
+ const data = workspace()
198
+ const alert = { ...poolShortRow, id: 'workerUnavailable:w', rule: 'workerUnavailable' as const, severity: 'alert' as const, subject: { kind: 'Worker' as const, namespace: 'ns', name: 'w' } }
199
+ expect(substrateAttentionCount({ ...data, needsAttention: [...data.needsAttention, alert] }).count).toBe(4)
200
+ expect(substrateScreenCounts({ ...data, needsAttention: [...data.needsAttention, alert] }).workers.count).toBe(1)
201
+ })
202
+ })
203
+
204
+ describe('needs-attention counts', () => {
205
+ it('counts every row, and each screen its own', () => {
206
+ const data = workspace()
207
+ expect(substrateAttentionCount(data)).toMatchObject({ count: 3, lowerBound: false })
208
+ const screens = substrateScreenCounts(data)
209
+ expect(screens.actors).toMatchObject({ count: 14, title: '14 actors need attention.' })
210
+ expect(screens.templates.count).toBe(1)
211
+ expect(screens.pools.count).toBe(1)
212
+ expect(screens.workers.count).toBe(0)
213
+ })
214
+
215
+ it('reads unknown, not zero, while Substrate’s API is not connected', () => {
216
+ const data = notConnectedWorkspace()
217
+ expect(substrateAttentionCount(data).count).toBeNull()
218
+ const screens = substrateScreenCounts(data)
219
+ expect(screens.actors.count).toBeNull()
220
+ expect(screens.actors.title).toContain('not connected')
221
+ // Pools come from Kubernetes too: a short pool still counts, as a lower bound.
222
+ const short = { ...data, needsAttention: [poolShortRow] }
223
+ expect(substrateScreenCounts(short).pools).toMatchObject({ count: 1, lowerBound: true })
224
+ })
225
+
226
+ it('makes a count over a partial read a lower bound', () => {
227
+ const data = workspace({ coverage: { ...workspace().coverage!, actors: { state: 'partial', deniedAtespaces: ['restricted'] } } })
228
+ expect(substrateAttentionCount(data)).toMatchObject({ count: 3, lowerBound: true })
229
+ expect(substrateScreenCounts(data).actors.title).toMatch(/^At least 14 actors need attention/)
230
+ })
231
+ })
232
+
233
+ describe('routes', () => {
234
+ it('parses screens and pages, and builds pinned page links', () => {
235
+ expect(parseSubstrateRoute('/substrate')).toEqual({ screen: 'overview' })
236
+ expect(parseSubstrateRoute('/substrate/actors')).toEqual({ screen: 'actors' })
237
+ expect(parseSubstrateRoute('/substrate/actors/research/lit-review-0193')).toEqual({ screen: 'actors', actor: { atespace: 'research', name: 'lit-review-0193' } })
238
+ expect(parseSubstrateRoute('/substrate/workerpools/agent-ns/agent-pool').pool).toEqual({ namespace: 'agent-ns', name: 'agent-pool' })
239
+ expect(substrateActorPath({ atespace: 'r', name: 'a' }, 'kind-x', 'logs')).toBe('/substrate/actors/r/a?ctx=kind-x&tab=logs')
240
+ expect(substrateActorsPath({ state: 'crashed', template: 'r/t' })).toBe('/substrate/actors?state=crashed&template=r%2Ft')
241
+ })
242
+
243
+ it('round-trips the actor drawer parameter and rejects a partial one', () => {
244
+ expect(decodeActorParam(encodeActorParam({ atespace: 'r', name: 'a' }))).toEqual({ atespace: 'r', name: 'a' })
245
+ expect(decodeActorParam('r/')).toBeNull()
246
+ expect(decodeActorParam(null)).toBeNull()
247
+ })
248
+ })
249
+
250
+ describe('text', () => {
251
+ it('never renders an unread count as zero', () => {
252
+ expect(countText(undefined)).toBe('unknown')
253
+ expect(countText(0)).toBe('0')
254
+ expect(countText(1284)).toBe('1,284')
255
+ })
256
+
257
+ it('writes resources as Kubernetes does', () => {
258
+ expect(bytesText(2 * 1024 ** 3)).toBe('2Gi')
259
+ expect(bytesText(512 * 1024 ** 2)).toBe('512Mi')
260
+ expect(cpuText(2000)).toBe('2')
261
+ expect(cpuText(500)).toBe('500m')
262
+ })
263
+ })
264
+
265
+ describe('the connection settings form', () => {
266
+ it('saves only what was chosen: no token path for the shared identity, no empty optional fields', async () => {
267
+ const { connectionUpdate } = await import('../settings/SubstrateSettings')
268
+ const target = { binding: 'b', context: 'kind-demo', fingerprint: 'f', clientGeneration: 1, operationGeneration: 2 }
269
+ const view = { target, revision: 'r1' }
270
+ expect(connectionUpdate({ identity: 'shared', tokenFile: '/tmp/t', atespaces: '', endpoint: ' ', caFile: '', serverName: '' }, view)).toEqual({ target, revision: 'r1', settings: { identity: 'shared', tokenFile: undefined, atespaces: undefined, endpoint: undefined, caFile: undefined, serverName: undefined } })
271
+ expect(connectionUpdate({ identity: 'tokenFile', tokenFile: ' ~/t ', atespaces: 'research, , support-bots', endpoint: 'h:443', caFile: '/ca.pem', serverName: 'api' }, view)).toEqual({ target, revision: 'r1', settings: { identity: 'tokenFile', tokenFile: '~/t', atespaces: ['research', 'support-bots'], endpoint: 'h:443', caFile: '/ca.pem', serverName: 'api' } })
272
+ })
273
+
274
+ it('asks to send the saved credential to a changed destination only when the user agreed', async () => {
275
+ const { connectionUpdate } = await import('../settings/SubstrateSettings')
276
+ const target = { binding: 'b', context: 'kind-demo', fingerprint: 'f', clientGeneration: 1, operationGeneration: 2 }
277
+ const draft = { identity: 'tokenFile' as const, tokenFile: '~/t', atespaces: '', endpoint: 'h:443', caFile: '', serverName: '' }
278
+ expect(connectionUpdate(draft, { target, revision: 'r1' })).not.toHaveProperty('confirmDestination')
279
+ expect(connectionUpdate(draft, { target, revision: 'r1' }, true)).toMatchObject({ confirmDestination: true })
280
+ })
281
+ })
282
+
283
+ describe('a pool’s read failure', () => {
284
+ it('says an incomplete pool read can’t tell, and only notFound says the pool is gone', () => {
285
+ expect(poolReadFailure(new ApiError('WorkerPools syncing', 503, { error_code: 'incomplete' }), 'agents')).toBe('Radar can’t tell whether this pool exists: it read too little of the WorkerPools or of Substrate’s workers (WorkerPools syncing).')
286
+ expect(poolReadFailure(new ApiError('missing', 404, { error_code: 'notFound' }), 'agents')).toContain('There is no WorkerPool by this name')
287
+ expect(poolReadFailure(new ApiError('dial tcp', 503, { error_code: 'unreachable' }), 'agents')).toBe('Radar couldn’t read the pool from Substrate’s API: dial tcp.')
288
+ })
289
+
290
+ it('distinguishes Kubernetes access from a denied Substrate tier', () => {
291
+ expect(poolReadFailure(new ApiError('Forbidden', 403, { error_code: 'denied' }), 'agents')).toBe('Reading this WorkerPool requires get on workerpools.ate.dev in namespace agents.')
292
+ expect(poolReadFailure(new ApiError('Permission denied', 503, { error_code: 'denied' }), 'agents')).toContain('grant this identity the viewer role')
293
+ expect(poolReadFailure(new ApiError('Token request forbidden.', 403, { error_code: 'mintDenied' }), 'agents')).toContain('create on serviceaccounts/token for ate-client in ate-system')
294
+ })
295
+ })
296
+
297
+ describe('times, readings and evidence', () => {
298
+ it('says every time relatively, past and ahead, never as a timestamp', () => {
299
+ const now = Date.parse('2026-11-18T03:00:00Z')
300
+ expect(relativeTime('2026-11-18T02:48:00Z', now)).toBe('12m ago')
301
+ expect(relativeTime('2026-11-18T03:04:00Z', now)).toBe('in 4m')
302
+ expect(relativeTime('2026-11-18T02:59:58Z', now)).toBe('just now')
303
+ expect(relativeTime('2026-11-16T03:00:00Z', now)).toBe('2d ago')
304
+ // The shared formatter's day starts at 24h, as Go's FormatAgeShort does.
305
+ expect(relativeTime('2026-11-16T15:00:00Z', now)).toBe('1d ago')
306
+ })
307
+
308
+ it('shows a reading’s first sentence whole and keeps the rest for Details', () => {
309
+ expect(splitReading('Substrate places no new actors on it. 3 actors are still assigned.')).toEqual(['Substrate places no new actors on it.', '3 actors are still assigned.'])
310
+ expect(splitReading('One sentence only.')).toEqual(['One sentence only.', undefined])
311
+ expect(splitReading('Version 2.5 of the image is pinned. It never updates.')).toEqual(['Version 2.5 of the image is pinned.', 'It never updates.'])
312
+ })
313
+
314
+ it('reads the newest container line as evidence the actor still runs', () => {
315
+ const now = Date.parse('2026-11-18T03:00:00Z')
316
+ expect(servingEvidence(undefined, now)).toBeUndefined()
317
+ expect(servingEvidence([{ kind: 'worker', time: '2026-11-18T02:59:50Z' }], now)).toEqual({ recent: false, at: undefined })
318
+ expect(servingEvidence([{ kind: 'container', time: '2026-11-18T02:40:00Z' }, { kind: 'container', time: '2026-11-18T02:59:48Z' }], now)).toEqual({ recent: true, at: '2026-11-18T02:59:48Z' })
319
+ expect(servingEvidence([{ kind: 'container', time: '2026-11-18T02:40:00Z' }], now)?.recent).toBe(false)
320
+ })
321
+ })
322
+
323
+ describe('pool slots as utilization', () => {
324
+ it('reads free slots as a neutral fact, and gives emphasis only to a pool that can place nothing new', async () => {
325
+ const { poolReading } = await import('./readings')
326
+ expect(poolReading({ capacity: 'free' })).toMatchObject({ label: 'Free actor slots', severity: 'neutral' })
327
+ // No free slot on any active worker blocks work: the warning of its Needs attention row (poolFull).
328
+ expect(poolReading({ capacity: 'full' })).toMatchObject({ label: 'No free actor slots', severity: 'warning' })
329
+ })
330
+
331
+ it('reads free slots that fit no actor as blocking as a full pool, naming what they lack', async () => {
332
+ const { poolReading } = await import('./readings')
333
+ expect(poolReading({ capacity: 'noRoom', lacking: 'cpu' })).toMatchObject({ label: 'No CPU left for an actor', severity: 'warning' })
334
+ expect(poolReading({ capacity: 'noRoom', lacking: 'memory' }).label).toBe('No memory left for an actor')
335
+ expect(poolReading({ capacity: 'noRoom', lacking: 'cpuAndMemory' }).label).toBe('No CPU or memory left for an actor')
336
+ expect(poolReading({ capacity: 'noRoom', lacking: 'cpu' }).meaning).toContain('new and resuming actors wait for a worker')
337
+ })
338
+
339
+ })
340
+
341
+ describe('the timing that ties a memory-limit kill to the crash', () => {
342
+ it('states how long before the crash the kill came, and only for a kill tied to it', async () => {
343
+ const { killTie, killLineLabel } = await import('./readings')
344
+ const crash = '2026-11-17T15:48:03Z'
345
+ expect(killTie({ current: true, time: '2026-11-17T15:46:03Z' }, crash)).toBe('2m before this crash')
346
+ expect(killTie({ current: true, time: '2026-11-17T15:48:02Z' }, crash)).toBe('1s before this crash')
347
+ expect(killLineLabel({ current: true, time: '2026-11-17T15:46:03Z' }, crash)).toBe('memory-limit kill · 2m before this crash')
348
+ // An earlier run's kill is never tied to this crash, whatever its timing.
349
+ expect(killTie({ current: false, time: '2026-11-17T15:46:03Z' }, crash)).toBeUndefined()
350
+ expect(killLineLabel({ current: false, time: '2026-11-17T15:46:03Z' }, crash)).toBe('memory-limit kill attempt')
351
+ // Without both times there is no evidence to state, so the label claims no tie.
352
+ expect(killTie({ current: true }, crash)).toBeUndefined()
353
+ expect(killLineLabel({ current: true }, undefined)).toBe('memory-limit kill')
354
+ // A kill after the crash ties nothing.
355
+ expect(killTie({ current: true, time: '2026-11-17T15:49:00Z' }, crash)).toBeUndefined()
356
+ })
357
+ })
358
+
359
+ describe('a failed golden snapshot in plain words', () => {
360
+ it('says new actors start from a cold boot, and which ones', async () => {
361
+ const { goldenReading } = await import('./readings')
362
+ const r = goldenReading({ golden: { state: 'failed' } } as Parameters<typeof goldenReading>[0])
363
+ expect(r.meaning).toContain('new actors not seeded from a tag start from a cold boot, not a prepared snapshot')
364
+ expect(r.meaning).not.toContain('default boot cold')
365
+ })
366
+ })
367
+
368
+ describe('pool reading over a partial read of the workers', () => {
369
+ it('uses Kubernetes readiness to explain a shortfall when not every worker was read', async () => {
370
+ const { poolReading } = await import('./readings')
371
+ const placement = { workers: { total: 2, active: 2, draining: 0, unavailable: 0 }, slots: { used: 1, total: 8 }, cpuMillicores: { used: 1, total: 2 }, memoryBytes: { used: 1, total: 2 } }
372
+ const kubernetes = { namespace: 'a', name: 'p', desired: 5, reportedReady: 2, health: 'degraded' as const, healthReason: 'Scaling' }
373
+ expect(poolReading({ capacity: 'short', placement: { ...placement, complete: false }, kubernetes }).label).toBe('Short of workers · 2 of 5 Pods ready')
374
+ expect(poolReading({ capacity: 'short', placement: { ...placement, complete: true }, kubernetes }).label).toBe('Short of workers · 2 of 5 active')
375
+ })
376
+ })
377
+
378
+ describe('one fact once, and a worker that says what happened to its actors', () => {
379
+ it('drops a reading’s sentence that its next step already says', async () => {
380
+ const { withoutRepeats } = await import('./readings')
381
+ expect(withoutRepeats('Placed and checkpointing on its worker. Substrate continues an unfinished suspend only on the next suspend call.', 'Suspend it again: Substrate continues an unfinished suspend only on the next suspend call.'))
382
+ .toBe('Placed and checkpointing on its worker.')
383
+ expect(withoutRepeats('Same as the step.', 'Same as the step.')).toBeUndefined()
384
+ expect(withoutRepeats('Unrelated.', 'Do this.')).toBe('Unrelated.')
385
+ // The same fact in other words is still the same fact.
386
+ expect(withoutRepeats('Checkpointing on worker w-1. An unfinished suspend continues only on the next suspend call. 3 other actors are in the same state.', 'Suspend it again: Substrate continues an unfinished suspend only on the next suspend call.'))
387
+ .toBe('Checkpointing on worker w-1. 3 other actors are in the same state.')
388
+ })
389
+
390
+ it('reads a reconciling worker’s lost sandboxes in its chip’s red, the count left to the line beside it, and a terminating Pod as terminating', async () => {
391
+ const { workerStateReading, workerPodText } = await import('./readings')
392
+ const reading = '3 actors lost their sandboxes when its process restarted; Substrate marks them crashed when it reconciles the worker.'
393
+ // Lost sandboxes are critical, the tone of their Needs attention row; a reconcile that lost none stays amber.
394
+ expect(workerStateReading({ state: 'active', attentionSeverity: 'critical', workerState: { kind: 'reconciling', assigned: 13, lost: 3, reading } })).toMatchObject({ label: 'Active · reconciling', severity: 'error', title: reading })
395
+ expect(workerStateReading({ state: 'active', attentionSeverity: 'warning', workerState: { kind: 'reconciling', assigned: 13, lost: 0, reading } })).toMatchObject({ severity: 'warning' })
396
+ // An unavailable worker is at risk, not lost: orange, as its row reads.
397
+ expect(workerStateReading({ state: 'unavailable' }).severity).toBe('alert')
398
+ expect(workerStateReading({ state: 'unavailable', workerState: { kind: 'reconciling', reading } }).severity).toBe('alert')
399
+ // Actors not read: no count is made up.
400
+ expect(workerStateReading({ state: 'active', workerState: { kind: 'reconciling', reading } })).toMatchObject({ label: 'Active · reconciling', severity: 'warning' })
401
+ expect(workerStateReading({ state: 'active', workerState: { kind: 'reconciling', lost: 3, reading } }).severity).toBe('error')
402
+ expect(workerStateReading({ state: 'active' })).toMatchObject({ label: 'Active', severity: 'success' })
403
+ expect(workerStateReading({ state: 'draining', attentionSeverity: 'info', workerState: { kind: 'draining', assigned: 4, reading: 'Draining…' } })).toMatchObject({ label: 'Draining', title: 'Draining…', severity: 'info' })
404
+ expect(workerStateReading({ state: 'draining' }).severity).toBe('info')
405
+ expect(workerStateReading({ state: 'draining', attentionSeverity: 'warning' }).severity).toBe('warning')
406
+ const { withoutReasonCode } = await import('./readings')
407
+ expect(withoutReasonCode('GoldenActorCrashed: golden actor crashed before its snapshot was taken')).toBe('golden actor crashed before its snapshot was taken')
408
+ expect(withoutReasonCode('killed for exceeding its memory limit')).toBe('killed for exceeding its memory limit')
409
+ expect(workerPodText({ podReady: true, podTerminating: true })).toBe('Pod terminating')
410
+ expect(workerPodText({ podReady: false })).toBe('Pod not ready')
411
+ })
412
+ })
413
+
414
+ describe('tier readings for a Radar Hub owner, who has no form', () => {
415
+ const owner = { mode: 'sharedAsCaller' as const, principal: 'system:serviceaccount:ate-system:ate-client' }
416
+ const noForm = /Advanced|another identity|this machine|Change connection|choose|save/i
417
+
418
+ it('says the shared identity is missing, with a kubectl check', () => {
419
+ const r = tierReading({ state: 'failed', code: 'notInstalled', identity: owner, reason: 'ServiceAccount ate-system/ate-client does not exist.' })
420
+ expect(r).toMatchObject({ detail: 'Substrate’s shared client identity (ate-system/ate-client) doesn’t exist here.', nextStep: 'Check that Substrate is installed in ate-system.', command: 'kubectl -n ate-system get sa ate-client' })
421
+ expect(`${r.detail} ${r.nextStep}`).not.toMatch(noForm)
422
+ })
423
+
424
+ it('says Radar couldn’t reach or verify the API server it dials from inside the cluster, with the server’s reason', () => {
425
+ const tls = tierReading({ state: 'failed', code: 'tls', identity: owner, endpoint: 'api.ate-system.svc:443', reason: 'x509: certificate signed by unknown authority' })
426
+ expect(tls.detail).toBe('Radar couldn’t verify api.ate-system.svc:443 from inside the cluster. x509: certificate signed by unknown authority')
427
+ expect(tls.nextStep).toContain('substrate.api.caConfigMap')
428
+ const down = tierReading({ state: 'failed', code: 'unreachable', identity: owner, endpoint: 'substrate.internal:8443', reason: 'dial tcp: connection refused' })
429
+ expect(down.detail).toBe('Radar couldn’t reach substrate.internal:8443 from inside the cluster. dial tcp: connection refused')
430
+ expect(down.command).toBe('kubectl -n ate-system get pods')
431
+ for (const r of [tls, down]) expect(`${r.detail} ${r.nextStep}`).not.toMatch(noForm)
432
+ })
433
+
434
+ it('tells a token Substrate didn’t accept from a read it denied', () => {
435
+ const rejected = tierReading({ state: 'failed', code: 'unauthenticated', identity: owner })
436
+ expect(rejected.title).toBe('Substrate didn’t accept the shared identity’s token')
437
+ expect(rejected.nextStep).toContain('audience api.ate-system.svc')
438
+ expect(rejected.nextStep).toContain('A role grant won’t fix this')
439
+ const denied = tierReading({ state: 'failed', code: 'denied', identity: owner })
440
+ expect(denied.title).toBe('Substrate refused the shared identity')
441
+ expect(denied.nextStep).toContain('Substrate operator to grant it the viewer role')
442
+ for (const r of [rejected, denied]) expect(`${r.detail} ${r.nextStep}`).not.toMatch(noForm)
443
+ })
444
+
445
+ it('points a local Radar’s readings at its form in Settings', () => {
446
+ expect(tierReading({ state: 'failed', code: 'notInstalled' })).toEqual({ title: 'API server not found', tone: 'unknown', detail: 'Radar has not read Substrate’s API.', nextStep: 'Check that Substrate’s API server runs as Service ate-system/api, or set its endpoint in Settings → Agent Substrate, under Advanced.' })
447
+ expect(tierReading({ state: 'failed', code: 'tls' }).nextStep).toBe('Check the CA file and server name in Settings → Agent Substrate, under Advanced, or that the cluster’s trust bundle for Substrate exists.')
448
+ expect(tierReading({ state: 'failed', code: 'unreachable', reason: 'dial tcp' })).toMatchObject({ title: 'API server unreachable', detail: 'dial tcp' })
449
+ expect(tierReading({ state: 'failed', code: 'unauthenticated' }).nextStep).toBe('Check that the token is current, or choose another identity.')
450
+ expect(tierReading({ state: 'failed', code: 'denied' }).nextStep).toBe('Ask a Substrate owner to grant this identity the viewer role, or choose another identity.')
451
+ })
452
+ })
453
+
454
+ describe('a template’s one memory-limit plan', () => {
455
+ it('orders recovery and names the constraints and snapshot consequences', () => {
456
+ for (const n of [1, 4]) {
457
+ const step = memoryRebuildStep(n)
458
+ expect(step.split(/\s+/).length).toBeLessThanOrEqual(25)
459
+ expect(step).toMatch(/Recreate.*Revert the actors?, move (it|them) over, then resume/)
460
+ expect(step).toContain('identical volumes, mounts and snapshot location')
461
+ expect(step).toContain('The move may keep only volumes.')
462
+ }
463
+ expect(memoryRebuildStep(1)).toContain('the actor, move it')
464
+ expect(memoryRebuildStep(4)).toContain('the actors, move them')
465
+ })
466
+ })
467
+
468
+ describe('shortSessionId', () => {
469
+ it('keeps the random tail, since UUIDv7 sessions started together share their leading digits', () => {
470
+ const a = shortSessionId('01a20561-c838-7e78-8774-cc8f79f013a8')
471
+ const b = shortSessionId('01a20561-16ba-7b0d-b4fd-5d664161cb1b')
472
+ expect(a).toBe('…79f013a8')
473
+ expect(a).not.toBe(b)
474
+ })
475
+ })
476
+
477
+ describe('kagent templates', () => {
478
+ const agent = { namespace: 'kagent', name: 'k8s-helper' }
479
+ it('calls an earlier revision’s template earlier, never current', () => {
480
+ const t = kagentTemplateText({ kind: 'agentSession', agent, earlierRevision: true, revision: 'aa5e9426eb2e' })
481
+ expect(t).toBe('kagent Agent kagent/k8s-helper’s template for an earlier revision (aa5e9426eb2e), before the one new sessions start on')
482
+ expect(kagentTemplateText({ kind: 'agentSession', agent, revision: 'aa5e9426eb2e', newSessions: true })).toContain('the revision new sessions start on')
483
+ })
484
+ })