@skyhook-io/radar-app 1.18.2 → 1.20.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 (228) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -6
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.test.ts +33 -2
  15. package/src/api/diagnose.ts +97 -3
  16. package/src/api/radarFeatures.render.test.tsx +33 -1
  17. package/src/api/radarFeatures.test.ts +47 -0
  18. package/src/api/radarFeatures.ts +41 -1
  19. package/src/api/rbac.settled.test.tsx +42 -0
  20. package/src/api/rbac.test.ts +18 -0
  21. package/src/api/rbac.ts +37 -7
  22. package/src/api/traffic.ts +9 -4
  23. package/src/api/usage-data.fixtures.ts +3 -1
  24. package/src/api/usage-data.test.tsx +134 -0
  25. package/src/api/usage-data.ts +35 -7
  26. package/src/api/workloadPodsPolling.test.ts +26 -0
  27. package/src/components/CloudConnectFlow.test.tsx +86 -0
  28. package/src/components/CloudConnectFlow.tsx +65 -27
  29. package/src/components/CloudFunnelButton.test.tsx +140 -5
  30. package/src/components/CloudFunnelButton.tsx +50 -9
  31. package/src/components/ConnectionErrorView.test.tsx +34 -0
  32. package/src/components/ConnectionErrorView.tsx +35 -11
  33. package/src/components/ContextSwitcher.tsx +5 -2
  34. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  35. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  38. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  39. package/src/components/capacity/CapacityDemand.tsx +3 -2
  40. package/src/components/capacity/demandSummary.test.ts +38 -0
  41. package/src/components/capacity/shared.tsx +12 -1
  42. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  43. package/src/components/cost/CostTrendChart.tsx +2 -0
  44. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  45. package/src/components/cost/source.test.ts +5 -0
  46. package/src/components/cost/source.ts +11 -0
  47. package/src/components/diagnose/AIMarkdown.tsx +4 -1
  48. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  49. package/src/components/diagnose/AgentControls.tsx +53 -6
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
  52. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  53. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  54. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  55. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  56. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  57. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  58. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  59. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  60. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  61. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  62. package/src/components/diagnose/DiagnoseContext.tsx +272 -10
  63. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  64. package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
  65. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  66. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  67. package/src/components/diagnose/Home.test.tsx +208 -5
  68. package/src/components/diagnose/Home.tsx +187 -36
  69. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  70. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  71. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  72. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  73. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  74. package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
  75. package/src/components/diagnose/InvestigationView.tsx +249 -54
  76. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  77. package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
  78. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  79. package/src/components/diagnose/NextStepJump.tsx +75 -0
  80. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  81. package/src/components/diagnose/QuestionComposer.tsx +495 -0
  82. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  83. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  84. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  85. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  86. package/src/components/diagnose/assessmentCopy.ts +5 -0
  87. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  88. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  89. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  90. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  91. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  92. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  93. package/src/components/diagnose/investigationCase.ts +33 -1
  94. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  95. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  96. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
  97. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  98. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  99. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  100. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  101. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  102. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  103. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  104. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  105. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  106. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  107. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  108. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  109. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  110. package/src/components/diagnose/investigationEvidence/types.ts +7 -0
  111. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  112. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  113. package/src/components/diagnose/investigationFocus.ts +132 -0
  114. package/src/components/diagnose/investigationState.ts +28 -0
  115. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  116. package/src/components/diagnose/lastInvestigation.ts +58 -0
  117. package/src/components/diagnose/launch.test.ts +125 -1
  118. package/src/components/diagnose/launch.ts +57 -10
  119. package/src/components/diagnose/parts.test.tsx +20 -0
  120. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  121. package/src/components/diagnose/questionSuggestions.ts +150 -0
  122. package/src/components/diagnose/storyParts.test.tsx +13 -0
  123. package/src/components/diagnose/target.test.ts +143 -2
  124. package/src/components/diagnose/target.ts +109 -7
  125. package/src/components/diagnose/testdata/story-runs.json +474 -0
  126. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  127. package/src/components/diagnose/verdictText.test.tsx +87 -0
  128. package/src/components/diagnose/verdictText.ts +68 -0
  129. package/src/components/execution/BatchExecutionView.tsx +24 -11
  130. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  131. package/src/components/execution/JobSetAdmission.tsx +18 -3
  132. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  133. package/src/components/execution/runState.test.ts +14 -0
  134. package/src/components/execution/runState.ts +8 -0
  135. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  136. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  137. package/src/components/gitops/GitOpsView.tsx +86 -17
  138. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  139. package/src/components/gitops/destination-toast.test.ts +1 -1
  140. package/src/components/gitops/destination-toast.ts +2 -2
  141. package/src/components/home/ClusterHealthCard.tsx +13 -39
  142. package/src/components/home/HomeAgentBlock.test.tsx +141 -0
  143. package/src/components/home/HomeAgentBlock.tsx +103 -0
  144. package/src/components/home/HomeDiagramCard.tsx +47 -0
  145. package/src/components/home/HomeView.tsx +86 -47
  146. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  147. package/src/components/home/MCPSetupDialog.tsx +30 -5
  148. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  149. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  150. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  151. package/src/components/home/RadarVersionLine.tsx +3 -28
  152. package/src/components/home/TopologyPreview.test.tsx +73 -0
  153. package/src/components/home/TopologyPreview.tsx +120 -233
  154. package/src/components/home/TrafficSummary.test.tsx +63 -0
  155. package/src/components/home/TrafficSummary.tsx +135 -138
  156. package/src/components/home/mcpToolCatalog.ts +23 -10
  157. package/src/components/issues/IssuesPane.test.ts +11 -0
  158. package/src/components/issues/IssuesPane.tsx +15 -5
  159. package/src/components/issues/uncheckedSources.test.ts +20 -1
  160. package/src/components/issues/uncheckedSources.ts +18 -0
  161. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  162. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  163. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  164. package/src/components/kueue/useRelatedReads.ts +205 -0
  165. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  166. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  167. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  168. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  169. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  170. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  171. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  172. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  173. package/src/components/logs/rayClusterPods.ts +32 -0
  174. package/src/components/outageSince.test.ts +21 -0
  175. package/src/components/outageSince.ts +10 -0
  176. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  177. package/src/components/resource/PrometheusCharts.tsx +3 -40
  178. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  179. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  180. package/src/components/resources/crd/host.tsx +14 -0
  181. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  182. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  183. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  184. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  185. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  186. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  187. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  188. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  189. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  190. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  191. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  192. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  193. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  194. package/src/components/traffic/TrafficView.tsx +3 -3
  195. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  196. package/src/components/ui/Omnibar.tsx +47 -3
  197. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  198. package/src/components/ui/RadarOmnibar.tsx +11 -0
  199. package/src/components/ui/command-items-crd.test.tsx +23 -0
  200. package/src/components/ui/command-items.ts +2 -1
  201. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  202. package/src/components/useContextSwitchFlow.tsx +21 -4
  203. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  204. package/src/components/whats-new/WhatsNew.tsx +5 -1
  205. package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
  206. package/src/components/whats-new/releaseNotes.ts +136 -4
  207. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  208. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  209. package/src/components/workload/WorkloadView.test.ts +10 -1
  210. package/src/components/workload/WorkloadView.tsx +85 -98
  211. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  212. package/src/components/workload/issueResourceOpener.ts +17 -0
  213. package/src/context/ConnectionContext.tsx +133 -60
  214. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  215. package/src/context/ContextSwitchContext.tsx +14 -1
  216. package/src/context/DiagnoseCustomization.tsx +3 -0
  217. package/src/context/clusterConnected.ts +10 -0
  218. package/src/contexts/CapabilitiesContext.tsx +6 -4
  219. package/src/hooks/useAgentSignin.test.tsx +190 -0
  220. package/src/hooks/useAgentSignin.ts +160 -0
  221. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  222. package/src/hooks/useElementSize.ts +30 -0
  223. package/src/integrations/resourceHost.test.tsx +1 -0
  224. package/src/integrations/resourceHost.ts +5 -1
  225. package/src/integrations/resourceHosts.test.tsx +21 -4
  226. package/src/integrations/resourceHosts.tsx +12 -0
  227. package/src/main.tsx +5 -0
  228. package/src/utils/related-findings.ts +46 -0
@@ -0,0 +1,248 @@
1
+ // @vitest-environment jsdom
2
+ import { act, type ReactNode } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
+ import { MemoryRouter } from "react-router-dom";
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
+
8
+ import type {
9
+ DiagnoseStreamEvent,
10
+ Diagnosis,
11
+ RunSummary,
12
+ } from "../../api/diagnose";
13
+ import events from "./exampleInvestigation.events.json";
14
+ import {
15
+ EXAMPLE_INVESTIGATION_RUN,
16
+ exampleInvestigationOffered,
17
+ } from "./exampleInvestigation";
18
+ import { isInvestigationEvidenceRef } from "./investigationEvidence/identity";
19
+ import { projectInvestigationEvidence } from "./investigationEvidence";
20
+ import { resolveInvestigationCase } from "./investigationCase";
21
+ import { upsertTool, type Turn } from "./parts";
22
+ import { InvestigationView } from "./InvestigationView";
23
+
24
+ vi.mock("./DiagnoseContext", () => ({
25
+ useDiagnose: () => ({
26
+ refreshRuns: vi.fn(),
27
+ openInvestigation: vi.fn(),
28
+ openQuestion: vi.fn(),
29
+ startError: null,
30
+ startRefusal: null,
31
+ dismissError: vi.fn(),
32
+ // An agent that could apply and explain: the example must still offer neither.
33
+ agents: [
34
+ {
35
+ name: "claude",
36
+ label: "Claude Code",
37
+ path: "",
38
+ version: "",
39
+ present: true,
40
+ supported: true,
41
+ apply: true,
42
+ verification: true,
43
+ assessmentExplanations: true,
44
+ },
45
+ ],
46
+ }),
47
+ }));
48
+ vi.mock("../../context/ThemeContext", () => ({
49
+ useTheme: () => ({ theme: "light", setTheme: vi.fn(), toggleTheme: vi.fn() }),
50
+ }));
51
+ vi.mock("../ui/Tooltip", () => ({
52
+ Tooltip: ({ children }: { children: ReactNode }) => children,
53
+ }));
54
+
55
+ const transcript = events as unknown as DiagnoseStreamEvent[];
56
+ const fixture = JSON.stringify(events) + JSON.stringify(EXAMPLE_INVESTIGATION_RUN);
57
+
58
+ describe("the bundled example's data", () => {
59
+ it("carries none of the values it was recorded with", () => {
60
+ for (const leaked of [
61
+ "radar-test",
62
+ "nonprod",
63
+ "wg-",
64
+ "+03:00",
65
+ "10.0.27.",
66
+ "toolu_01",
67
+ "sessionId",
68
+ "costUsd",
69
+ "ownerPid",
70
+ ]) {
71
+ expect(fixture).not.toContain(leaked);
72
+ }
73
+ expect(fixture).not.toMatch(/\b\d{12}\b/);
74
+ expect(fixture).not.toMatch(/[\w.+-]+@[\w-]+\.[\w.]+/);
75
+ });
76
+
77
+ it("ends in a complete verdict whose citations all land on a card", () => {
78
+ let timeline: Turn["timeline"] = [];
79
+ let diagnosis: Diagnosis | undefined;
80
+ for (const event of transcript) {
81
+ if (event.type === "step" && event.step)
82
+ timeline = upsertTool(timeline, event.step, false);
83
+ if (event.type === "done") diagnosis = event.diagnosis;
84
+ }
85
+ expect(transcript.some((event) => event.type === "error")).toBe(false);
86
+ expect(diagnosis?.summary).toBeTruthy();
87
+ const refs = timeline.flatMap((item) =>
88
+ item.kind === "tool" && item.evidenceRef ? [item.evidenceRef] : [],
89
+ );
90
+ expect(refs).toHaveLength(2);
91
+ for (const ref of refs) expect(isInvestigationEvidenceRef(ref)).toBe(true);
92
+ for (const ref of diagnosis!.rootCauseEvidence!.refs!)
93
+ expect(refs).toContain(ref);
94
+
95
+ const projection = projectInvestigationEvidence(
96
+ [{ timeline }],
97
+ EXAMPLE_INVESTIGATION_RUN,
98
+ );
99
+ const investigationCase = resolveInvestigationCase(
100
+ projection,
101
+ diagnosis!,
102
+ 0,
103
+ );
104
+ expect(investigationCase.items).toHaveLength(diagnosis!.evidence!.length);
105
+ for (const item of investigationCase.items)
106
+ expect(item.placement).toBe("card");
107
+ });
108
+ });
109
+
110
+ describe("exampleInvestigationOffered", () => {
111
+ const run = (patch: Partial<RunSummary> = {}): RunSummary => ({
112
+ ...EXAMPLE_INVESTIGATION_RUN,
113
+ id: "run-1",
114
+ ...patch,
115
+ });
116
+ const offered = (
117
+ runs: RunSummary[],
118
+ { runsLoaded = true, setupPending = false, needsConsent = false } = {},
119
+ ) =>
120
+ exampleInvestigationOffered({ runs, runsLoaded, setupPending, needsConsent });
121
+
122
+ it("is offered only while the user has no investigations of their own", () => {
123
+ expect(offered([])).toBe(true);
124
+ expect(offered([run()])).toBe(false);
125
+ expect(offered([run({ ownedByMe: true })])).toBe(false);
126
+ expect(offered([run()], { runsLoaded: false, setupPending: true })).toBe(
127
+ false,
128
+ );
129
+ });
130
+
131
+ it("does not count automatic runs or runs others shared", () => {
132
+ expect(
133
+ offered([run({ trigger: "background" }), run({ ownedByMe: false })]),
134
+ ).toBe(true);
135
+ });
136
+
137
+ it("waits for the history before claiming it is empty", () => {
138
+ expect(offered([], { runsLoaded: false })).toBe(false);
139
+ });
140
+
141
+ it("is offered on the setup step, where no history is fetched", () => {
142
+ expect(offered([], { runsLoaded: false, setupPending: true })).toBe(true);
143
+ });
144
+
145
+ it("is not offered while a start waits for consent", () => {
146
+ expect(offered([], { needsConsent: true })).toBe(false);
147
+ });
148
+ });
149
+
150
+ describe("InvestigationView showing the example", () => {
151
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
152
+ let root: Root;
153
+ let container: HTMLDivElement;
154
+ const fetchMock = vi.fn();
155
+
156
+ beforeEach(() => {
157
+ vi.stubGlobal("fetch", fetchMock);
158
+ // jsdom has no EventSource: a server subscription would throw.
159
+ vi.stubGlobal(
160
+ "ResizeObserver",
161
+ class {
162
+ observe() {}
163
+ unobserve() {}
164
+ disconnect() {}
165
+ },
166
+ );
167
+ vi.stubGlobal("matchMedia", (query: string) => ({
168
+ matches: false,
169
+ media: query,
170
+ addEventListener() {},
171
+ removeEventListener() {},
172
+ addListener() {},
173
+ removeListener() {},
174
+ }));
175
+ container = document.createElement("div");
176
+ document.body.appendChild(container);
177
+ root = createRoot(container);
178
+ });
179
+
180
+ afterEach(() => {
181
+ act(() => root.unmount());
182
+ container.remove();
183
+ vi.unstubAllGlobals();
184
+ fetchMock.mockReset();
185
+ });
186
+
187
+ async function renderExample(onCloseExample = vi.fn()) {
188
+ const client = new QueryClient();
189
+ await act(async () => {
190
+ root.render(
191
+ <QueryClientProvider client={client}>
192
+ <MemoryRouter>
193
+ <InvestigationView
194
+ run={EXAMPLE_INVESTIGATION_RUN}
195
+ agentLabel="Claude Code"
196
+ maximized
197
+ example
198
+ onCloseExample={onCloseExample}
199
+ />
200
+ </MemoryRouter>
201
+ </QueryClientProvider>,
202
+ );
203
+ });
204
+ await vi.waitFor(() =>
205
+ expect(container.textContent).toContain(
206
+ "A direct edit set guestbook-ui to a nonexistent image tag",
207
+ ),
208
+ );
209
+ return onCloseExample;
210
+ }
211
+
212
+ it("labels it as an example and renders its findings from the bundle", async () => {
213
+ await renderExample();
214
+ const label = container.querySelector("[data-investigation-example]");
215
+ expect(label?.textContent).toContain("Example");
216
+ expect(label?.textContent).toContain("test cluster");
217
+ expect(container.textContent).toContain("Next steps");
218
+ // Nothing about the example is read from the server or the cluster.
219
+ expect(
220
+ fetchMock.mock.calls
221
+ .map((call) => String(call[0]))
222
+ .filter((url) => /diagnose|resources|guestbook/.test(url)),
223
+ ).toEqual([]);
224
+ });
225
+
226
+ it("offers nothing that acts on it or sends it anywhere", async () => {
227
+ await renderExample();
228
+ expect(container.querySelector("textarea")).toBeNull();
229
+ const buttons = [...container.querySelectorAll("button")].map(
230
+ (button) =>
231
+ `${button.textContent ?? ""} ${button.getAttribute("aria-label") ?? ""}`,
232
+ );
233
+ for (const label of buttons) {
234
+ expect(label).not.toMatch(
235
+ /copy|apply|send|follow-up|investigate again|check status|explain/i,
236
+ );
237
+ }
238
+ });
239
+
240
+ it("closes from its label", async () => {
241
+ const onClose = await renderExample();
242
+ const close = [...container.querySelectorAll("button")].find(
243
+ (button) => button.textContent === "Close example",
244
+ );
245
+ act(() => close!.click());
246
+ expect(onClose).toHaveBeenCalledOnce();
247
+ });
248
+ });
@@ -0,0 +1,121 @@
1
+ // A finished investigation bundled with Radar, so someone who has never run one
2
+ // can see what it produces before installing an agent or consenting to
3
+ // anything. It is a real run from a test cluster with its identifying values
4
+ // replaced; it replays through the same view as a saved run, from this bundle
5
+ // rather than the server, so it works against any Radar a host embeds.
6
+ import { createContext, useContext } from "react";
7
+ import type {
8
+ DiagnoseStreamEvent,
9
+ RunSummary,
10
+ SubscribeHandlers,
11
+ } from "../../api/diagnose";
12
+
13
+ // Never issued by a server: Radar's run ids are `run-<hex>`.
14
+ export const EXAMPLE_INVESTIGATION_ID = "example";
15
+
16
+ export function isExampleInvestigation(id: string | null | undefined): boolean {
17
+ return id === EXAMPLE_INVESTIGATION_ID;
18
+ }
19
+
20
+ // Offered only until the user has investigations of their own: automatic runs
21
+ // and runs others shared with them don't count, as in the history list's
22
+ // grouping. On the setup step no history is fetched, and with no agent there is
23
+ // none of theirs to show. Not while a start waits for consent: that start owns
24
+ // the pane.
25
+ export function exampleInvestigationOffered(input: {
26
+ runs: readonly RunSummary[];
27
+ runsLoaded: boolean;
28
+ setupPending: boolean;
29
+ needsConsent: boolean;
30
+ }): boolean {
31
+ const own = input.runs.filter(
32
+ (run) => run.trigger !== "background" && run.ownedByMe !== false,
33
+ );
34
+ return (
35
+ !input.needsConsent &&
36
+ own.length === 0 &&
37
+ (input.runsLoaded || input.setupPending)
38
+ );
39
+ }
40
+
41
+ export const EXAMPLE_INVESTIGATION_RUN: RunSummary = {
42
+ id: EXAMPLE_INVESTIGATION_ID,
43
+ kind: "Deployment",
44
+ group: "apps",
45
+ namespace: "guestbook",
46
+ name: "guestbook-ui",
47
+ context: "sample-cluster",
48
+ agent: "claude",
49
+ profile: "safeguarded",
50
+ managedBy: "Argo CD",
51
+ health: {
52
+ health: "healthy",
53
+ issueCount: 1,
54
+ highestSeverity: "critical",
55
+ topReason: "ErrImagePull",
56
+ issues: [
57
+ {
58
+ severity: "critical",
59
+ reason: "ErrImagePull",
60
+ message:
61
+ 'rpc error: code = NotFound desc = failed to pull and unpack image "gcr.io/google-samples/gb-frontend:v99-missing": failed to resolve reference "gcr.io/google-samples/gb-frontend:v99-missing": gcr.io/google-samples/gb-fr…',
62
+ },
63
+ ],
64
+ auditCount: 11,
65
+ auditSeverity: "high",
66
+ topFinding: "privilegeEscalation",
67
+ auditFindings: [
68
+ {
69
+ severity: "high",
70
+ reason: "privilegeEscalation",
71
+ message: 'Container "guestbook-ui" allows privilege escalation',
72
+ },
73
+ {
74
+ severity: "medium",
75
+ reason: "automountServiceAccountToken",
76
+ message: "Service account token is auto-mounted",
77
+ },
78
+ ],
79
+ },
80
+ status: "done",
81
+ preview:
82
+ "A direct edit set guestbook-ui to a nonexistent image tag; the new pod can't start and the rollout is stuck on the old pod.",
83
+ createdAt: "2026-10-08T10:45:35Z",
84
+ updatedAt: "2026-10-08T10:46:41Z",
85
+ canContinue: false,
86
+ };
87
+
88
+ // Replays the bundled transcript with the same handler contract as
89
+ // subscribeRun: replay start, every event with its sequence, then the replay
90
+ // boundary. Loaded on demand so the transcript stays out of the main bundle.
91
+ export function replayExampleInvestigation(
92
+ handlers: SubscribeHandlers,
93
+ ): () => void {
94
+ let cancelled = false;
95
+ void import("./exampleInvestigation.events.json").then(
96
+ ({ default: events }) => {
97
+ if (cancelled) return;
98
+ handlers.onReplayStart?.();
99
+ (events as unknown as DiagnoseStreamEvent[]).forEach((event, index) => {
100
+ if (!cancelled) handlers.onEvent(event, index + 1);
101
+ });
102
+ if (!cancelled) handlers.onEvent({ type: "replay_complete" });
103
+ },
104
+ () => {
105
+ if (!cancelled) handlers.onClosed?.("unavailable");
106
+ },
107
+ );
108
+ return () => {
109
+ cancelled = true;
110
+ };
111
+ }
112
+
113
+ const ExampleInvestigationContext = createContext(false);
114
+ export const ExampleInvestigationProvider =
115
+ ExampleInvestigationContext.Provider;
116
+
117
+ // Copy buttons read this: the example is for looking at, and a copied
118
+ // command or verdict would carry sample values somewhere they could be acted on.
119
+ export function useInExampleInvestigation(): boolean {
120
+ return useContext(ExampleInvestigationContext);
121
+ }
@@ -0,0 +1,328 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+
4
+ import type {
5
+ DiagnosisEvidenceItem,
6
+ DiagnosisRuledOut,
7
+ } from "../../api/diagnose";
8
+ import { InvestigationEvidencePane } from "./InvestigationEvidencePane";
9
+ import { resolveInvestigationCase } from "./investigationCase";
10
+ import {
11
+ projectInvestigationEvidence,
12
+ type InvestigationEvidenceTarget,
13
+ type InvestigationEvidenceTimelineItem,
14
+ } from "./investigationEvidence";
15
+ import runs from "./testdata/story-runs.json";
16
+
17
+ // Recorded investigations against the test cluster's fixtures: every Radar
18
+ // tool call of the run as the UI received it, and the final verdict.
19
+ interface RecordedRun {
20
+ target: InvestigationEvidenceTarget;
21
+ timeline: InvestigationEvidenceTimelineItem[];
22
+ diagnosis: {
23
+ evidence: DiagnosisEvidenceItem[];
24
+ report: string;
25
+ ruledOut?: DiagnosisRuledOut[];
26
+ };
27
+ }
28
+ const recorded = runs as unknown as Record<string, RecordedRun>;
29
+
30
+ function resolve(run: RecordedRun) {
31
+ const projection = projectInvestigationEvidence(
32
+ [{ timeline: run.timeline }],
33
+ run.target,
34
+ );
35
+ return {
36
+ projection,
37
+ investigationCase: resolveInvestigationCase(projection, run.diagnosis, 0),
38
+ };
39
+ }
40
+
41
+ function renderPane(run: RecordedRun) {
42
+ const { projection, investigationCase } = resolve(run);
43
+ return renderToStaticMarkup(
44
+ <InvestigationEvidencePane
45
+ projection={projection}
46
+ investigationCase={investigationCase}
47
+ story={{ report: run.diagnosis.report, evidence: run.diagnosis.evidence }}
48
+ collecting={false}
49
+ animateGroupIds={new Set()}
50
+ onViewSource={() => {}}
51
+ onViewActivity={() => {}}
52
+ />,
53
+ );
54
+ }
55
+
56
+ describe("a Pod cited for the agent's own Prometheus query", () => {
57
+ // Both runs cite their restart-count query as evidence 2, naming the one
58
+ // Pod the query selects (`pod=~"^(<pod>)$"`) rather than the Deployment.
59
+ const cases = [
60
+ ["run-7885e0cdb0", "api-7c6f9c7bb9-p9czp"],
61
+ ["run-01f749634a", "batch-worker-74b5656749-phx2t"],
62
+ ] as const;
63
+
64
+ it.each(cases)("%s pins the citation to the query's chart", (id, pod) => {
65
+ const run = recorded[id];
66
+ expect(run.diagnosis.evidence[2].subject).toMatchObject({
67
+ kind: "Pod",
68
+ name: pod,
69
+ observation: "metrics",
70
+ });
71
+ const item = resolve(run).investigationCase.items.find(
72
+ (candidate) => candidate.index === 2,
73
+ );
74
+ expect(item?.placement).toBe("card");
75
+ expect(item?.source.tool).toBe("query_prometheus");
76
+ expect(item?.observation?.data).toMatchObject({
77
+ type: "metrics",
78
+ origin: "query",
79
+ });
80
+ });
81
+
82
+ it.each(cases)("%s loses no cited result in the story", (id) => {
83
+ const html = renderPane(recorded[id]);
84
+ expect(html).not.toContain("could not be shown here");
85
+ expect(html).not.toContain("data-story-lost-support");
86
+ });
87
+
88
+ it("does not pin a Pod the query does not select", () => {
89
+ const run = recorded["run-7885e0cdb0"];
90
+ const other = {
91
+ ...run,
92
+ diagnosis: {
93
+ ...run.diagnosis,
94
+ evidence: run.diagnosis.evidence.map((entry, index) =>
95
+ index === 2 && entry.subject
96
+ ? { ...entry, subject: { ...entry.subject, name: "api-other" } }
97
+ : entry,
98
+ ),
99
+ },
100
+ };
101
+ const item = resolve(other).investigationCase.items.find(
102
+ (candidate) => candidate.index === 2,
103
+ );
104
+ expect(item?.placement).toBe("source");
105
+ });
106
+ });
107
+
108
+ describe("a Pod cited for a target query that selects a sibling", () => {
109
+ it("does not pin the sibling to the target's chart", () => {
110
+ const run = recorded["run-7885e0cdb0"];
111
+ // `deployment="api"` makes the query target-scoped while the pod
112
+ // matcher names a Pod nothing established as the target's own.
113
+ const timeline = run.timeline.map((item) => {
114
+ if (item.kind !== "tool" || item.tool !== "query_prometheus") return item;
115
+ const result = JSON.parse(item.result ?? "{}");
116
+ result.selectors = [
117
+ {
118
+ metric: "kube_pod_container_status_restarts_total",
119
+ matchers: [
120
+ { label: "namespace", op: "=", value: "gl-crash-config" },
121
+ { label: "deployment", op: "=", value: "api" },
122
+ { label: "pod", op: "=", value: "sibling-0" },
123
+ ],
124
+ },
125
+ ];
126
+ return { ...item, result: JSON.stringify(result) };
127
+ });
128
+ const evidence = run.diagnosis.evidence.map((entry, index) =>
129
+ index === 2 && entry.subject
130
+ ? { ...entry, subject: { ...entry.subject, name: "sibling-0" } }
131
+ : entry,
132
+ );
133
+ const { projection, investigationCase } = resolve({
134
+ ...run,
135
+ timeline,
136
+ diagnosis: { ...run.diagnosis, evidence },
137
+ });
138
+ const chart = projection.groups
139
+ .flatMap((group) => group.observations)
140
+ .find((observation) => observation.source.tool === "query_prometheus");
141
+ expect(chart?.relevance).toBe("target");
142
+ const item = investigationCase.items.find(
143
+ (candidate) => candidate.index === 2,
144
+ );
145
+ expect(item?.placement).toBe("source");
146
+ });
147
+ });
148
+
149
+ describe("a Pod cited for a diagnose bundle's chart", () => {
150
+ // The herring run rules out memory pressure on the bundle's memory chart,
151
+ // naming the Deployment's one Pod: `{kind: Pod, observation:
152
+ // "metrics:memory"}` against charts that state the Deployment.
153
+ const run = recorded["run-01f749634a"];
154
+ const itemThree = (candidate: RecordedRun) =>
155
+ resolve(candidate).investigationCase.items.find((item) => item.index === 3);
156
+ // Rewrites the diagnose payload, the source of both the charts and the
157
+ // pods Radar establishes as the target's own.
158
+ const withDiagnose = (
159
+ edit: (payload: Record<string, unknown>) => void,
160
+ ): RecordedRun => ({
161
+ ...run,
162
+ timeline: run.timeline.map((item) => {
163
+ if (item.kind !== "tool" || item.tool !== "diagnose") return item;
164
+ const payload = JSON.parse(item.result ?? "{}");
165
+ edit(payload);
166
+ return { ...item, result: JSON.stringify(payload) };
167
+ }),
168
+ });
169
+
170
+ it("pins the citation to the chart its category names when the target has one Pod", () => {
171
+ expect(run.diagnosis.evidence[3].subject).toMatchObject({
172
+ kind: "Pod",
173
+ name: "batch-worker-74b5656749-phx2t",
174
+ observation: "metrics:memory",
175
+ });
176
+ const item = itemThree(run);
177
+ expect(item?.placement).toBe("card");
178
+ expect(item?.source.tool).toBe("diagnose");
179
+ expect(item?.groupId).toBe(
180
+ resolve(run).projection.groups.find(
181
+ (group) =>
182
+ group.kind === "metrics" &&
183
+ group.identity.endsWith(":memory") &&
184
+ group.latest.source.tool === "diagnose",
185
+ )?.id,
186
+ );
187
+ });
188
+
189
+ it("does not pin one Pod of a target with two", () => {
190
+ const twoPods = withDiagnose((payload) => {
191
+ payload.pods = 2;
192
+ payload.podNames = [
193
+ "batch-worker-74b5656749-phx2t",
194
+ "batch-worker-74b5656749-zzzzz",
195
+ ];
196
+ (payload.metrics as { pods: number }).pods = 2;
197
+ });
198
+ expect(resolve(twoPods).projection.targetPods).toHaveLength(2);
199
+ expect(itemThree(twoPods)?.placement).toBe("source");
200
+ });
201
+
202
+ it("does not pin a Pod when the bundle's pod list was cut short", () => {
203
+ const truncated = withDiagnose((payload) => {
204
+ payload.podNamesTruncated = true;
205
+ });
206
+ expect(itemThree(truncated)?.placement).toBe("source");
207
+ });
208
+
209
+ it("keeps the citation pinned when a later turn diagnoses a replacement Pod", () => {
210
+ // A follow-up reads the workload again after its Pod was replaced. The
211
+ // first chart still covered only the first Pod, so the first assessment's
212
+ // citation stays on that read, now a revision under the newer chart.
213
+ const diagnose = run.timeline.find(
214
+ (item) => item.kind === "tool" && item.tool === "diagnose",
215
+ )!;
216
+ const payload = JSON.parse(
217
+ (diagnose as { result?: string }).result ?? "{}",
218
+ );
219
+ payload.podNames = ["batch-worker-74b5656749-new01"];
220
+ const later = {
221
+ ...diagnose,
222
+ id: "toolu_followup_diagnose",
223
+ result: JSON.stringify(payload),
224
+ evidenceRef: undefined,
225
+ } as InvestigationEvidenceTimelineItem;
226
+ const projection = projectInvestigationEvidence(
227
+ [{ timeline: run.timeline }, { timeline: [later] }],
228
+ run.target,
229
+ );
230
+ expect(projection.targetPods).toHaveLength(2);
231
+ const item = resolveInvestigationCase(
232
+ projection,
233
+ run.diagnosis,
234
+ 0,
235
+ ).items.find((candidate) => candidate.index === 3);
236
+ expect(item?.placement).toBe("revision");
237
+ expect(item?.observation?.source.id).toBe(item?.source.id);
238
+ });
239
+
240
+ it("does not pin a Pod to a chart that summed more than one", () => {
241
+ const summedTwo = withDiagnose((payload) => {
242
+ (payload.metrics as { pods: number }).pods = 2;
243
+ });
244
+ expect(itemThree(summedTwo)?.placement).toBe("source");
245
+ });
246
+
247
+ it("does not pin a Pod the target does not have", () => {
248
+ const other: RecordedRun = {
249
+ ...run,
250
+ diagnosis: {
251
+ ...run.diagnosis,
252
+ evidence: run.diagnosis.evidence.map((entry, index) =>
253
+ index === 3 && entry.subject
254
+ ? {
255
+ ...entry,
256
+ subject: { ...entry.subject, name: "batch-worker-other" },
257
+ }
258
+ : entry,
259
+ ),
260
+ },
261
+ };
262
+ expect(itemThree(other)?.placement).toBe("source");
263
+ });
264
+
265
+ it("does not pick one of the bundle's charts for a Pod citation without a category", () => {
266
+ const bare: RecordedRun = {
267
+ ...run,
268
+ diagnosis: {
269
+ ...run.diagnosis,
270
+ evidence: run.diagnosis.evidence.map((entry, index) =>
271
+ index === 3 && entry.subject
272
+ ? {
273
+ ...entry,
274
+ subject: { ...entry.subject, observation: "metrics" },
275
+ }
276
+ : entry,
277
+ ),
278
+ },
279
+ };
280
+ expect(itemThree(bare)?.placement).toBe("source");
281
+ });
282
+ });
283
+
284
+ describe("a healthy verdict's Pod citations (run-40c65bb5ed)", () => {
285
+ // boutique/adservice: one ready Pod. The agent rules out restarts on its own
286
+ // 7-day query and resource pressure on the bundle's memory chart, naming
287
+ // the Pod both times.
288
+ const run = recorded["run-40c65bb5ed"];
289
+
290
+ it("places both citations and keeps both ruled-out hypotheses", () => {
291
+ const { investigationCase } = resolve(run);
292
+ const byIndex = (index: number) =>
293
+ investigationCase.items.find((item) => item.index === index);
294
+ expect(byIndex(2)).toMatchObject({
295
+ placement: "card",
296
+ source: { tool: "query_prometheus" },
297
+ });
298
+ expect(byIndex(3)).toMatchObject({
299
+ placement: "card",
300
+ source: { tool: "diagnose" },
301
+ });
302
+ expect(byIndex(3)?.observation?.data).toMatchObject({
303
+ type: "metrics",
304
+ origin: "diagnose",
305
+ label: "Memory working set",
306
+ });
307
+ expect(investigationCase.ruledOut.map((entry) => entry.hypothesis)).toEqual(
308
+ [
309
+ "Crash loop or OOM-kill restarts",
310
+ "Container pressing against its memory/CPU limits",
311
+ ],
312
+ );
313
+ });
314
+
315
+ it("loses no cited result in the story", () => {
316
+ const html = renderPane(run);
317
+ expect(html).not.toContain("could not be shown here");
318
+ expect(html).not.toContain("data-story-lost-support");
319
+ });
320
+ });
321
+
322
+ describe("run-8b924c437a", () => {
323
+ it("places every story citation", () => {
324
+ const html = renderPane(recorded["run-8b924c437a"]);
325
+ expect(html).not.toContain("could not be shown here");
326
+ expect(html).not.toContain("data-story-lost-support");
327
+ });
328
+ });