@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,478 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { renderToStaticMarkup } from 'react-dom/server'
4
+ import { MemoryRouter } from 'react-router-dom'
5
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6
+ import { describe, expect, it, vi } from 'vitest'
7
+ import type { SubstrateActorDetail, SubstrateActorLogs, SubstrateRef, SubstrateTemplate } from '../../api/substrateWorkspace'
8
+ import { ApiError } from '../../api/client'
9
+ import { KubectlTargetContext } from './shared'
10
+ import { decodeDrawerTrail } from '../../utils/drawer-trail'
11
+ import { actorDetail, counts, workspace } from './substrate.fixtures'
12
+
13
+ type Read<T> = { data?: T; error: unknown; isLoading: boolean; isRefetchError: boolean; dataUpdatedAt: number; isFetching?: boolean; refetch?: () => void }
14
+
15
+ const state = vi.hoisted(() => ({
16
+ context: 'cluster-B',
17
+ template: undefined as unknown as Read<SubstrateTemplate>,
18
+ actor: undefined as unknown as Read<SubstrateActorDetail>,
19
+ logs: undefined as SubstrateActorLogs | undefined,
20
+ logOptions: undefined as { tailLines?: number; pollMs?: number | false } | undefined,
21
+ reads: [] as string[],
22
+ workspace: undefined as unknown,
23
+ }))
24
+
25
+ vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: state.context } }) }))
26
+ vi.mock('../../api/client', async (importOriginal) => ({
27
+ ...(await importOriginal<typeof import('../../api/client')>()),
28
+ useContexts: () => ({ data: [{ name: 'cluster-A' }, { name: 'cluster-B' }] }),
29
+ usePrometheusStatus: () => ({ data: { connected: false } }),
30
+ }))
31
+ vi.mock('../useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ requestSwitch: vi.fn(), confirmDialog: null }) }))
32
+ vi.mock('../workload/WorkloadView', () => ({ WorkloadView: () => <div>WorkerPool controls for the active cluster</div> }))
33
+ vi.mock('../../api/substrateWorkspace', async (importOriginal) => ({
34
+ ...(await importOriginal<typeof import('../../api/substrateWorkspace')>()),
35
+ useSubstrateTemplate: (ref: SubstrateRef | null) => {
36
+ if (ref) state.reads.push(`template ${ref.name}`)
37
+ return ref ? state.template : { data: undefined, error: null, isLoading: false, isRefetchError: false, dataUpdatedAt: 0 }
38
+ },
39
+ useSubstrateActor: (ref: SubstrateRef | null) => {
40
+ if (ref) state.reads.push(`actor ${ref.name}`)
41
+ return ref ? state.actor : { data: undefined, error: null, isLoading: false, isRefetchError: false, dataUpdatedAt: 0 }
42
+ },
43
+ useSubstrateActorLogs: (_: unknown, options: typeof state.logOptions) => {
44
+ state.logOptions = options
45
+ return { data: state.logs, error: null, isLoading: !state.logs }
46
+ },
47
+ useSubstrateWorkspace: () => ({ data: state.workspace }),
48
+ useSubstratePool: () => ({ data: undefined, error: null, isLoading: true }),
49
+ }))
50
+
51
+ const { SubstrateTemplatePage } = await import('./SubstrateTemplates')
52
+ const { SubstratePoolPage } = await import('./SubstratePoolPage')
53
+ const { SubstrateActorPage } = await import('./SubstrateActorPage')
54
+ const { actorDrawerParams, resourceDrawerParams } = await import('./SubstrateView')
55
+
56
+ const text = (html: string) => html.replace(/&#x27;/g, "'").replace(/&quot;/g, '"').replace(/&amp;/g, '&').replace(/<\/?span[^>]*>/g, '')
57
+ const render = (node: React.ReactNode, route: string) =>
58
+ text(renderToStaticMarkup(<QueryClientProvider client={new QueryClient()}><MemoryRouter initialEntries={[route]}><KubectlTargetContext.Provider value={{ context: 'cluster-B', kubeconfig: '/home/user/.kube/demo' }}>{node}</KubectlTargetContext.Provider></MemoryRouter></QueryClientProvider>))
59
+
60
+ const ready = workspace().pools[0]
61
+ function template(name: string): SubstrateTemplate {
62
+ return {
63
+ apiTier: workspace().apiTier,
64
+ template: { atespace: 'team', name, golden: { state: 'ready' }, matchingPools: [{ namespace: ready.namespace, name: ready.name }], matchingPoolsComplete: true, preferredFidelity: 'memory' },
65
+ coverage: { templates: { state: 'full' }, actors: { state: 'full' }, workers: { state: 'full' }, pools: { state: 'full' } },
66
+ } as unknown as SubstrateTemplate
67
+ }
68
+ const ok = <T,>(data: T): Read<T> => ({ data, error: null, isLoading: false, isRefetchError: false, dataUpdatedAt: Date.now() - 120_000 })
69
+ const failed = <T,>(data: T, error: unknown): Read<T> => ({ data, error, isLoading: false, isRefetchError: true, dataUpdatedAt: Date.now() - 120_000 })
70
+ const apiError = (status: number, code: string) => new ApiError(`${code} from Substrate`, status, { error: `${code} from Substrate`, error_code: code })
71
+
72
+ describe('a detail page pinned to another context', () => {
73
+ it('shows the WorkerPool page’s mismatch screen instead of mounting the active cluster’s controls', () => {
74
+ const html = render(<SubstratePoolPage pool={{ namespace: 'agents', name: 'pool' }} onOpenResource={() => {}} />, '/substrate/workerpools/agents/pool?ctx=cluster-A')
75
+ expect(html).toContain('pool is not in cluster-B')
76
+ expect(html).toContain('Switch back to cluster-A')
77
+ expect(html).not.toContain('WorkerPool controls for the active cluster')
78
+ })
79
+
80
+ it('shows the template page’s mismatch screen and reads nothing', () => {
81
+ state.reads = []
82
+ state.template = ok(template('template-from-B'))
83
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'template' }} onOpenSubject={() => {}} />, '/substrate/templates/team/template?ctx=cluster-A')
84
+ expect(html).toContain('template is not in cluster-B')
85
+ expect(html).not.toContain('template-from-B')
86
+ expect(state.reads).toEqual([])
87
+ })
88
+
89
+ it('reads nothing for an actor page pinned to another context', () => {
90
+ state.reads = []
91
+ state.actor = ok(actorDetail())
92
+ const html = render(<SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?ctx=cluster-A')
93
+ expect(html).toContain('lit-review-0193 is not in cluster-B')
94
+ expect(state.reads).toEqual([])
95
+ })
96
+
97
+ it('opens the page when the pin matches', () => {
98
+ state.template = ok(template('template'))
99
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'template' }} onOpenSubject={() => {}} />, '/substrate/templates/team/template?ctx=cluster-B')
100
+ expect(html).toContain('At a glance')
101
+ })
102
+ })
103
+
104
+ describe('a failed template', () => {
105
+ it('says what a failed build means once, in the banner, not again in At a glance', () => {
106
+ const t = template('broken')
107
+ ;(t.template as any).golden = { state: 'failed', error: 'killed for exceeding its memory limit' }
108
+ state.template = ok(t)
109
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'broken' }} onOpenSubject={() => {}} />, '/substrate/templates/team/broken?ctx=cluster-B')
110
+ expect(html).toContain('Startup snapshot failed')
111
+ expect(html).toContain('New actors without a seed tag start from a cold boot.')
112
+ expect(html).toContain('Failed · cold startup')
113
+ expect(html.split('does not retry').length - 1).toBe(1)
114
+ })
115
+
116
+ it('takes the cause-specific remedy from Substrate’s own row for it, with the reason code stripped', () => {
117
+ const t = template('broken')
118
+ ;(t.template as any).golden = { state: 'failed', error: 'GoldenActorCrashed: golden actor crashed: killed for exceeding its memory limit' }
119
+ state.template = ok(t)
120
+ const golden = { id: 'g', rule: 'goldenSnapshotFailed', severity: 'warning', title: 't', reading: 'Its golden actor was killed for exceeding its memory limit before the snapshot was taken. Substrate does not retry a failed build. Substrate’s message: golden actor crashed: killed for exceeding its memory limit.', nextStep: 'Recreate the template with a higher memory limit.', command: 'kubectl ate get actor-template broken -a team -o yaml', subject: { kind: 'ActorTemplate', atespace: 'team', name: 'broken' }, count: 1 }
121
+ state.workspace = { ...workspace(), needsAttention: [golden] }
122
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'broken' }} onOpenSubject={() => {}} />, '/substrate/templates/team/broken?ctx=cluster-B')
123
+ expect(html).toContain('Next step: Recreate the template with a higher memory limit.')
124
+ expect(html).toContain('golden actor crashed: killed for exceeding its memory limit')
125
+ expect(html).not.toContain('GoldenActorCrashed:')
126
+ // The cause leads once; Substrate's own words and the no-retry note fold under Details, after the step.
127
+ expect(html.split('killed for exceeding its memory limit before').length - 1).toBe(1)
128
+ expect(html.indexOf('Its golden actor was killed')).toBeLessThan(html.indexOf('Next step:'))
129
+ expect(html.indexOf('Details')).toBeGreaterThan(html.indexOf('Next step: Recreate'))
130
+ expect(html.indexOf('golden actor crashed: killed')).toBeGreaterThan(html.indexOf('Details'))
131
+ state.workspace = undefined
132
+ })
133
+ })
134
+
135
+ describe('a crashed golden-build actor', () => {
136
+ it('gives its template’s step, with no revert or move', () => {
137
+ state.context = 'cluster-B'
138
+ const golden = { id: 'goldenSnapshotFailed:research/langgraph-research', rule: 'goldenSnapshotFailed', severity: 'warning', title: 't', reading: 'r', nextStep: 'Recreate the template with a higher memory limit; templates can’t be edited.', subject: { kind: 'ActorTemplate', atespace: 'research', name: 'langgraph-research' }, count: 1 }
139
+ state.actor = ok(actorDetail({ attention: [golden] } as Partial<SubstrateActorDetail>))
140
+ const html = render(<SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?ctx=cluster-B')
141
+ expect(html).toContain('This actor built research / langgraph-research’s golden snapshot')
142
+ expect(html).toContain('Recreate the template with a higher memory limit')
143
+ expect(html).not.toContain('kubectl ate revert')
144
+ expect(html).not.toContain('kubectl ate update')
145
+ expect(html.split('Recreate the template with a higher memory limit').length - 1).toBe(1)
146
+ })
147
+ })
148
+
149
+ describe('a template whose actors crashed', () => {
150
+ it('says how many of its actors crashed and why, beside the memory it sets', () => {
151
+ const t = template('langgraph-research')
152
+ t.template.memoryBytes = 2 * 1024 ** 3
153
+ t.template.cpuMillicores = 2000
154
+ t.template.attentionCount = 11
155
+ t.template.actors = counts({ crashed: 11, running: 30 })
156
+ state.template = ok(t)
157
+ const crash = { id: 'c', rule: 'crashedActors', severity: 'critical', title: 't', reading: 'r', nextStep: 'Fix it.', subject: { kind: 'Actors', filter: { state: 'crashed' } }, count: 15,
158
+ groups: [{ subject: { kind: 'ActorTemplate', atespace: 'team', name: 'langgraph-research' }, count: 11, cause: 'memoryLimit', nextStep: 'Create a template with a higher memory limit. Revert the actors, update their templates once suspended, then resume.', command: 'kubectl ate revert actor <name> -a <atespace>', thenCommand: 'kubectl ate update actor <name> -a <atespace> --template <new-template>' }] }
159
+ state.workspace = { ...workspace(), needsAttention: [crash] }
160
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'langgraph-research' }} onOpenSubject={() => {}} />, '/substrate/templates/team/langgraph-research?ctx=cluster-B')
161
+ expect(html).toContain('11 reported crashed →')
162
+ expect(html).toContain('Killed over the 2Gi memory limit per actor')
163
+ expect(html).toContain('Create a template with a higher memory limit.')
164
+ expect(html).toContain('Golden snapshot ready')
165
+ expect(html).toContain('2 CPU · 2Gi')
166
+ expect(html).toMatch(/Crash recovery steps.*?inert=.*?Create a template.*?Copy command/)
167
+ expect(html.match(/aria-label="Copy command"/g)?.length).toBe(2)
168
+ state.workspace = undefined
169
+ })
170
+ })
171
+
172
+ describe('a template whose golden actor and actors were both killed over its memory limit', () => {
173
+ const move = 'kubectl ate update actor <name> -a <atespace> --template <new-template>'
174
+ const revert = 'kubectl ate revert actor <name> -a <atespace>'
175
+ const crashRow = (count: number) => ({ id: 'c', rule: 'crashedActors', severity: 'critical', title: 't', reading: 'r', nextStep: 'Fix it.', subject: { kind: 'Actors', filter: { state: 'crashed' } }, count,
176
+ groups: [{ subject: { kind: 'ActorTemplate', atespace: 'sandbox-dev', name: 'mcp-browser' }, count, cause: 'memoryLimit', nextStep: 'Revert the actors, move them to a template with more memory and identical volumes, mounts and snapshot location, then resume. Snapshots may keep only volumes.', command: revert, thenCommand: move }] })
177
+ const goldenRow = { id: 'g', rule: 'goldenSnapshotFailed', severity: 'warning', title: 't', reading: 'Its golden actor was killed for exceeding its memory limit before the snapshot was taken. Substrate does not retry a failed build.', nextStep: 'Recreate the template with a higher memory limit; templates can’t be edited.', subject: { kind: 'ActorTemplate', atespace: 'sandbox-dev', name: 'mcp-browser' }, count: 1 }
178
+ const page = (cause: 'memoryLimit' | undefined, count: number) => {
179
+ const t = template('mcp-browser')
180
+ ;(t.template as any).atespace = 'sandbox-dev'
181
+ ;(t.template as any).golden = { state: 'failed', error: 'GoldenActorCrashed: golden actor crashed: killed for exceeding its memory limit', cause }
182
+ state.template = ok(t)
183
+ state.workspace = { ...workspace(), needsAttention: [crashRow(count), goldenRow] }
184
+ try {
185
+ return render(<SubstrateTemplatePage template={{ atespace: 'sandbox-dev', name: 'mcp-browser' }} onOpenSubject={() => {}} />, '/substrate/templates/sandbox-dev/mcp-browser?ctx=cluster-B')
186
+ } finally {
187
+ state.workspace = undefined
188
+ }
189
+ }
190
+ const words = (html: string) => html.replace(/<[^>]+>/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/\s+/g, ' ')
191
+
192
+ it('uses one startup callout for the joint recovery plan and folds the commands in order', () => {
193
+ const html = page('memoryLimit', 1)
194
+ const w = words(html)
195
+ expect(w.indexOf('Startup snapshot failed')).toBeLessThan(w.indexOf('At a glance'))
196
+ expect(html).not.toContain('bg-red-50')
197
+ const plan = 'Recreate with more memory and identical volumes, mounts and snapshot location. Revert the actor, move it over, then resume. The move may keep only volumes.'
198
+ expect(w).toContain(`Next step: ${plan}`)
199
+ expect(w.split('Next step:').length - 1).toBe(1)
200
+ expect(w).not.toContain('Recreate the template with a higher memory limit; templates can’t be edited.')
201
+ expect(w.indexOf(plan)).toBeLessThan(w.indexOf(revert))
202
+ expect(w.indexOf(revert)).toBeLessThan(w.indexOf(move))
203
+ expect(html).toMatch(/Crash recovery steps.*?inert=.*?Copy command/)
204
+ })
205
+
206
+ it('keeps the actor remedy separately folded when the startup build failed for another reason', () => {
207
+ const w = words(page(undefined, 3))
208
+ expect(w).toContain('Revert the actors, move them to a template with more memory and identical volumes, mounts and snapshot location, then resume.')
209
+ expect(w).toContain('Next step: Recreate the template with a higher memory limit; templates can’t be edited.')
210
+ expect(w.indexOf('Startup snapshot failed')).toBeLessThan(w.indexOf('Crash recovery steps'))
211
+ })
212
+
213
+ it('offers no command, and keeps the server’s step, when kagent runs some of its crashed actors', () => {
214
+ const t = template('mcp-browser')
215
+ ;(t.template as any).atespace = 'sandbox-dev'
216
+ ;(t.template as any).golden = { state: 'failed', error: 'GoldenActorCrashed: golden actor crashed: killed for exceeding its memory limit', cause: 'memoryLimit' }
217
+ state.template = ok(t)
218
+ const step = 'Revert the actors, move them to a template with more memory and identical volumes, mounts and snapshot location, then resume. Snapshots may keep only volumes. Recover the kagent sessions among them through kagent instead (RevertSession, or delete the chat).'
219
+ const row = crashRow(2)
220
+ row.groups = [{ subject: { kind: 'ActorTemplate', atespace: 'sandbox-dev', name: 'mcp-browser' }, count: 2, cause: 'memoryLimit', nextStep: step, kagent: true } as any]
221
+ state.workspace = { ...workspace(), needsAttention: [row, goldenRow] } as any
222
+ try {
223
+ const w = words(render(<SubstrateTemplatePage template={{ atespace: 'sandbox-dev', name: 'mcp-browser' }} onOpenSubject={() => {}} />, '/substrate/templates/sandbox-dev/mcp-browser?ctx=cluster-B'))
224
+ expect(w).toContain(step)
225
+ expect(w).not.toContain(move)
226
+ expect(w).not.toContain(revert)
227
+ expect(w).not.toContain('Recreate with more memory')
228
+ } finally {
229
+ state.workspace = undefined
230
+ }
231
+ })
232
+
233
+ it('defines the startup snapshot in At a glance', () => {
234
+ const t = template('mcp-browser')
235
+ ;(t.template as any).golden = { state: 'failed', error: 'x' }
236
+ state.template = ok(t)
237
+ const raw = renderToStaticMarkup(<QueryClientProvider client={new QueryClient()}><MemoryRouter initialEntries={['/substrate/templates/team/mcp-browser?ctx=cluster-B']}><SubstrateTemplatePage template={{ atespace: 'team', name: 'mcp-browser' }} onOpenSubject={() => {}} /></MemoryRouter></QueryClientProvider>)
238
+ expect(raw).toMatch(/decoration-dotted[^>]*>Startup snapshot<\/span>/)
239
+ })
240
+ })
241
+
242
+ describe('a template’s banners', () => {
243
+ it('uses the strongest template finding for the callout and header', () => {
244
+ const t = template('stranded')
245
+ ;(t.template as any).matchingPools = []
246
+ ;(t.template as any).golden = { state: 'failed', error: 'x' }
247
+ state.template = ok(t)
248
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'stranded' }} onOpenSubject={() => {}} />, '/substrate/templates/team/stranded?ctx=cluster-B')
249
+ const banner = (title: string) => html.slice(html.lastIndexOf('<div class="p-3 border rounded-lg', html.indexOf(title)), html.indexOf(title))
250
+ expect(banner('No worker pool matches')).toContain('status-alert')
251
+ expect(html).not.toContain('bg-amber-50')
252
+ expect(html).toContain('Failed · cold startup')
253
+ expect(html).not.toContain('bg-red-50')
254
+ })
255
+ })
256
+
257
+ describe('a detail read whose refresh failed', () => {
258
+ it('keeps the template with a stale notice saying how old it is when the refresh failed for a passing reason', () => {
259
+ state.template = failed(template('template'), apiError(502, 'unreachable'))
260
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'template' }} onOpenSubject={() => {}} />, '/substrate/templates/team/template?ctx=cluster-B')
261
+ expect(html).toContain('At a glance')
262
+ expect(html).toContain('Last refresh failed: unreachable from Substrate')
263
+ expect(html).toContain('showing data from 2m ago')
264
+ })
265
+
266
+ it('drops the kept template when Substrate says it is gone or no longer readable', () => {
267
+ state.template = failed(template('template'), apiError(404, 'notFound'))
268
+ let html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'template' }} onOpenSubject={() => {}} />, '/substrate/templates/team/template?ctx=cluster-B')
269
+ expect(html).toContain('Substrate has no template template')
270
+ expect(html).not.toContain('At a glance')
271
+ state.template = failed(template('template'), apiError(403, 'denied'))
272
+ html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'template' }} onOpenSubject={() => {}} />, '/substrate/templates/team/template?ctx=cluster-B')
273
+ expect(html).toContain('Substrate denied reading template')
274
+ })
275
+
276
+ it('drops the kept actor on a definitive failure and marks it stale otherwise', () => {
277
+ state.actor = failed(actorDetail(), apiError(404, 'notFound'))
278
+ let html = render(<SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?ctx=cluster-B')
279
+ expect(html).toContain('Substrate has no actor lit-review-0193')
280
+ expect(html).not.toContain('At a glance')
281
+ state.actor = failed(actorDetail(), apiError(502, 'unreachable'))
282
+ html = render(<SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?ctx=cluster-B')
283
+ expect(html).toContain('At a glance')
284
+ expect(html).toContain('Last refresh failed: unreachable from Substrate')
285
+ })
286
+ })
287
+
288
+ describe('an actor’s snapshots', () => {
289
+ const page = (snapshots: NonNullable<SubstrateActorDetail['actor']['snapshots']>) => {
290
+ const detail = actorDetail()
291
+ state.actor = ok(actorDetail({ actor: { ...detail.actor, snapshots }, row: { ...detail.row, resumeGeneration: snapshots.find((s) => s.durable === 'completed')?.generation } }))
292
+ return render(<SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?tab=snapshots&ctx=cluster-B')
293
+ }
294
+
295
+ it('says where each copy is kept, durable or only on its node, never "stored" twice', () => {
296
+ const html = page([
297
+ { generation: 6, fidelity: 'memory', owner: 'actor', durable: 'pending', locality: 'ip-10-0-17-21.ec2.internal' },
298
+ { generation: 5, fidelity: 'memory', owner: 'actor', durable: 'completed' },
299
+ { generation: 4, fidelity: 'rootfs', owner: 'actor', durable: 'none', locality: 'ip-10-0-17-21.ec2.internal' },
300
+ ])
301
+ expect(html).toContain('Where it is kept')
302
+ expect(html.indexOf('Resume source')).toBeLessThan(html.indexOf('Where it is kept'))
303
+ expect(html).toContain('Generation 5 · memory · Durable copy')
304
+ expect(html).not.toContain('>Stored<')
305
+ expect(html).toContain('Only on its nodeUpload pending. Recorded locality:')
306
+ expect(html).toContain('Durable copyUploaded to object storage.')
307
+ expect(html).toContain('No durable copy recorded. Recorded locality:')
308
+ // The hostname stays one unbroken token.
309
+ const raw = renderToStaticMarkup(<QueryClientProvider client={new QueryClient()}><MemoryRouter initialEntries={['/substrate/actors/research/lit-review-0193?tab=snapshots&ctx=cluster-B']}><SubstrateActorPage actor={{ atespace: 'research', name: 'lit-review-0193' }} onOpenSubject={() => {}} /></MemoryRouter></QueryClientProvider>)
310
+ expect(raw).toMatch(/<button[^>]*>.*?class="inline-block whitespace-nowrap">ip-10-0-17-21\.ec2\.internal<\/span><\/button>/)
311
+ // Substrate records no upload time, so none is invented.
312
+ expect(html).not.toMatch(/uploaded \d|upload(ed)? at/i)
313
+ })
314
+
315
+ it('says why earlier generations are absent only from what Substrate’s record holds, and nothing when none are', () => {
316
+ const missing = page([{ generation: 6, fidelity: 'memory', owner: 'actor', durable: 'completed' }])
317
+ expect(missing).toContain('Substrate’s record of an actor lists only its active and in-progress generations, so 5 earlier generations are not listed.')
318
+ expect(missing).not.toContain('pruned')
319
+ const whole = page([{ generation: 2, fidelity: 'memory', owner: 'actor', durable: 'completed' }, { generation: 1, fidelity: 'memory', owner: 'actor', durable: 'completed' }])
320
+ expect(whole).not.toContain('earlier generation')
321
+ })
322
+ })
323
+
324
+ describe('actor log availability', () => {
325
+ function logs(reasonCode: SubstrateActorLogs['reasonCode']) {
326
+ const detail = actorDetail()
327
+ state.actor = ok(detail)
328
+ state.logs = {
329
+ actor: detail.actor, state: 'crashed', origin: 'lastNode', reasonCode, node: 'former-node',
330
+ source: 'all', lines: [], searched: [], scanned: 0, windowFull: false,
331
+ }
332
+ try {
333
+ return render(<SubstrateActorPage actor={detail.actor} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?tab=logs&ctx=cluster-B')
334
+ } finally {
335
+ state.logs = undefined
336
+ }
337
+ }
338
+
339
+ it('polls only with an assigned worker Pod and namespace', () => {
340
+ logs('noMatch')
341
+ expect(state.logOptions).toMatchObject({ tailLines: 500, pollMs: false })
342
+
343
+ const detail = actorDetail()
344
+ state.actor = ok({
345
+ ...detail,
346
+ actor: { ...detail.actor, assignment: { worker: 'w', pool: 'pool', pod: 'worker', namespace: 'agents', node: 'node' } },
347
+ })
348
+ render(<SubstrateActorPage actor={detail.actor} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?tab=logs&ctx=cluster-B')
349
+ expect(state.logOptions?.tailLines).toBe(500)
350
+ expect(state.logOptions?.pollMs).toBeUndefined()
351
+ })
352
+
353
+ it('gives one unavailable card and an external query when the recorded node is gone', () => {
354
+ const html = logs('nodeGone')
355
+ expect(html.match(/Worker logs unavailable/g)).toHaveLength(1)
356
+ expect(html).toContain('former-node, is gone from the cluster')
357
+ expect(html).toContain('ate.actor.name="lit-review-0193" ate.atespace="research"')
358
+ expect(html).not.toContain('Log source')
359
+ expect(html).not.toContain('No matching log lines')
360
+ })
361
+
362
+ it('keeps source controls when the log was read and returned no matches', () => {
363
+ const html = logs('noMatch')
364
+ expect(html).toContain('No matching log lines')
365
+ expect(html).toContain('Container output')
366
+ expect(html).not.toContain('Worker logs unavailable')
367
+ })
368
+ })
369
+
370
+ describe('one drawer at a time', () => {
371
+ it('opens a resource from the actor drawer in one update that drops the actor', () => {
372
+ const before = new URLSearchParams('actor=team%2Falice&tab=x')
373
+ const after = resourceDrawerParams(before, { kind: 'Pod', namespace: 'agents', name: 'worker-0' })
374
+ expect(after.has('actor')).toBe(false)
375
+ expect(decodeDrawerTrail(after.get('drawer'))).toMatchObject([{ kind: 'Pod', namespace: 'agents', name: 'worker-0' }])
376
+ expect(after.get('tab')).toBe('x')
377
+ })
378
+
379
+ it('opens an actor in one update that drops the resource drawer', () => {
380
+ const after = actorDrawerParams(new URLSearchParams('drawer=Pod%3Aagents%3Aworker-0'), { atespace: 'team', name: 'alice' })
381
+ expect(after.has('drawer')).toBe(false)
382
+ expect(after.get('actor')).toBe('team/alice')
383
+ })
384
+ })
385
+
386
+ describe('the screen gate on a Radar without the Substrate workspace', () => {
387
+ it('shows the upgrade note, not a generic failure', async () => {
388
+ const { SubstrateScreenGate } = await import('./shared')
389
+ const { RadarFeatureUnsupportedError } = await import('../../api/radarFeatures')
390
+ const error = new RadarFeatureUnsupportedError('substrateWorkspace', { currentVersion: '1.0.0' })
391
+ const query = { data: undefined, error, isLoading: false, isFetching: false, refetch: vi.fn(), isRefetchError: false, dataUpdatedAt: 0 }
392
+ const html = render(<SubstrateScreenGate query={query} discoveryPending={false} discovered>{() => <div>Workspace</div>}</SubstrateScreenGate>, '/substrate')
393
+ expect(html).toContain('Agent Substrate needs a newer Radar on this cluster')
394
+ expect(html).not.toContain('Agent Substrate unavailable')
395
+ })
396
+ })
397
+
398
+ describe('An in-cluster Radar or Radar Hub whose operator turned the API off', () => {
399
+ it('says so on Templates and Workers, not an error', async () => {
400
+ const { SubstrateTemplatesScreen } = await import('./SubstrateTemplates')
401
+ const { SubstrateWorkersScreen } = await import('./SubstrateWorkers')
402
+ const { notConnectedWorkspace, apiDisabledTier, status: statusOf } = await import('./substrate.fixtures')
403
+ const ws = notConnectedWorkspace(apiDisabledTier)
404
+ const st = statusOf({ apiTier: apiDisabledTier, canConfigure: false })
405
+ for (const html of [
406
+ render(<SubstrateTemplatesScreen workspace={ws} status={st} />, '/substrate/templates'),
407
+ render(<SubstrateWorkersScreen workspace={ws} status={st} onOpenSubject={() => {}} />, '/substrate/workers'),
408
+ ]) {
409
+ expect(html).toContain('Turned off for this Radar')
410
+ expect(html).toContain('>Connection settings</button>')
411
+ expect(html).not.toContain('couldn’t read')
412
+ }
413
+ })
414
+
415
+ it('reads a template page refused because the API is off as that, with what to ask for', () => {
416
+ state.template = failed(template('stale-template'), apiError(403, 'apiDisabled'))
417
+ const html = render(<SubstrateTemplatePage template={{ atespace: 'team', name: 'x' }} onOpenSubject={() => {}} />, '/substrate/templates/team/x?ctx=cluster-B')
418
+ expect(html).toContain('Turned off for this Radar')
419
+ expect(html).toContain('substrate.api.enabled')
420
+ expect(html).not.toContain('At a glance')
421
+ expect(html).not.toContain('stale-template')
422
+ })
423
+ })
424
+
425
+ it('uses template-local coverage while the workspace loads and keeps configuration on Spec', () => {
426
+ state.context = 'cluster-B'
427
+ state.workspace = undefined
428
+ const t = template('template')
429
+ t.template.actors = counts({})
430
+ t.template.attentionCount = 0
431
+ t.spec = { containers: [{ name: 'only-on-spec', image: 'example/image' }], volumes: [], snapshot: { preferredFidelity: 'memory', golden: 'enabled' } }
432
+ const page = <SubstrateTemplatePage template={t.template} onOpenSubject={() => {}} />
433
+ state.template = ok(t)
434
+ const overview = render(page, '/substrate/templates/team/template')
435
+ expect(overview).toContain('0 need attention')
436
+ expect(overview).toContain('New actors start from the golden snapshot')
437
+ expect(overview).not.toContain('only-on-spec')
438
+ expect(render(page, '/substrate/templates/team/template?tab=spec')).toContain('only-on-spec')
439
+ t.coverage.actors = { state: 'partial' }
440
+ const partial = render(page, '/substrate/templates/team/template')
441
+ expect(partial).not.toContain('≥0')
442
+ expect(partial).not.toContain('0 actors')
443
+ expect(partial).toContain('Unknown')
444
+ })
445
+
446
+ it('puts the actor template and resource facts in one grid and shows the matched pool verdict', () => {
447
+ state.context = 'cluster-B'
448
+ const ws = workspace()
449
+ state.workspace = ws
450
+ const detail = actorDetail({ matchingPools: [ws.pools[0]], matchingPoolsComplete: true })
451
+ state.actor = ok(detail)
452
+ const page = render(<SubstrateActorPage actor={detail.actor} onOpenSubject={() => {}} />, '/substrate/actors/research/lit-review-0193?tab=spec')
453
+ const doc = new DOMParser().parseFromString(page, 'text/html')
454
+ const fields = [...doc.querySelectorAll('dt')]
455
+ expect(fields.find((field) => field.textContent === 'Template')?.parentElement).toBe(fields.find((field) => field.textContent === 'CPU')?.parentElement)
456
+ expect(doc.querySelector('button[aria-label^="agent-ns/agent-pool · Short of workers"]')?.textContent).toBe('agent-pool')
457
+ })
458
+
459
+ describe('a kagent Agent’s template', () => {
460
+ const words = (html: string) => html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ')
461
+ it('names its Agent and never says to recreate a template kagent owns and rebuilds', () => {
462
+ const t = template('k8s-helper-aa5e9426eb2e')
463
+ ;(t.template as any).atespace = 'kagent'
464
+ ;(t.template as any).golden = { state: 'failed', error: 'GoldenActorCrashed: exit 1' }
465
+ ;(t.template as any).kagent = { kind: 'agentSession', agent: { namespace: 'kagent', name: 'k8s-helper' }, newSessions: true, desired: true }
466
+ state.template = ok(t)
467
+ state.workspace = { ...workspace(), needsAttention: [] }
468
+ try {
469
+ const w = words(render(<SubstrateTemplatePage template={{ atespace: 'kagent', name: 'k8s-helper-aa5e9426eb2e' }} onOpenSubject={() => {}} />, '/substrate/templates/kagent/k8s-helper-aa5e9426eb2e?ctx=cluster-B'))
470
+ expect(w).toContain('kagent/k8s-helper')
471
+ expect(w).toContain('template for the revision new sessions start on')
472
+ expect(w).toContain('Fix the cause on Agent kagent/k8s-helper: kagent owns this template and rebuilds it itself.')
473
+ expect(w).not.toContain('recreate the template')
474
+ } finally {
475
+ state.workspace = undefined
476
+ }
477
+ })
478
+ })