@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.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -6
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +97 -3
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +41 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +4 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +272 -10
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +208 -5
- package/src/components/diagnose/Home.tsx +187 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
- package/src/components/diagnose/InvestigationView.tsx +249 -54
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +495 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +7 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +141 -0
- package/src/components/home/HomeAgentBlock.tsx +103 -0
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +86 -47
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
- package/src/components/whats-new/releaseNotes.ts +136 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useEffect,
|
|
3
|
+
useId,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
type FocusEvent,
|
|
8
|
+
type KeyboardEvent,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { Check, Copy, TerminalSquare } from "lucide-react";
|
|
11
|
+
import { clsx } from "clsx";
|
|
12
|
+
import { copyText } from "@skyhook-io/k8s-ui/utils/clipboard";
|
|
13
|
+
import { useAnimatedUnmount } from "../../hooks/useAnimatedUnmount";
|
|
14
|
+
import {
|
|
15
|
+
TRANSITION_MENU,
|
|
16
|
+
overlayExitMs,
|
|
17
|
+
overlayTransitionStyle,
|
|
18
|
+
} from "../../utils/animation";
|
|
19
|
+
import { type RunSummary } from "../../api/diagnose";
|
|
20
|
+
import { mcpEndpointUrl } from "../../api/config";
|
|
21
|
+
import { useCapabilitiesContext } from "../../contexts/CapabilitiesContext";
|
|
22
|
+
import {
|
|
23
|
+
buildLaunchCommand,
|
|
24
|
+
launchAgentLabel,
|
|
25
|
+
launchTrustHint,
|
|
26
|
+
openInTerminal,
|
|
27
|
+
} from "./launch";
|
|
28
|
+
|
|
29
|
+
const TERMINAL_TITLE = "Radar Investigation";
|
|
30
|
+
|
|
31
|
+
export function useContinueInAgentCommand(
|
|
32
|
+
run: RunSummary | null,
|
|
33
|
+
): string | null {
|
|
34
|
+
const { mcpReadOnly, localShell } = useCapabilitiesContext();
|
|
35
|
+
return run
|
|
36
|
+
? buildLaunchCommand(run, mcpEndpointUrl(mcpReadOnly), localShell)
|
|
37
|
+
: null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function ContinueInAgentButton({
|
|
41
|
+
run,
|
|
42
|
+
command,
|
|
43
|
+
}: {
|
|
44
|
+
run: RunSummary;
|
|
45
|
+
command: string;
|
|
46
|
+
}) {
|
|
47
|
+
const { localTerminal } = useCapabilitiesContext();
|
|
48
|
+
const label = launchAgentLabel(run);
|
|
49
|
+
const trustHint = launchTrustHint(run);
|
|
50
|
+
const [open, setOpen] = useState(false);
|
|
51
|
+
const [copy, setCopy] = useState<"idle" | "copied" | "failed">("idle");
|
|
52
|
+
const { shouldRender, isOpen } = useAnimatedUnmount(
|
|
53
|
+
open,
|
|
54
|
+
overlayExitMs("menu"),
|
|
55
|
+
);
|
|
56
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
57
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
58
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
59
|
+
const menuId = useId();
|
|
60
|
+
const introId = useId();
|
|
61
|
+
const hintId = useId();
|
|
62
|
+
const copyingRef = useRef(false);
|
|
63
|
+
// The menu lives inside the Findings scroller, which clips it: open toward
|
|
64
|
+
// the side with room, and cap the height when neither side has enough.
|
|
65
|
+
const [placement, setPlacement] = useState<{
|
|
66
|
+
up: boolean;
|
|
67
|
+
maxHeight?: number;
|
|
68
|
+
}>({ up: false });
|
|
69
|
+
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
if (!open || !shouldRender) return;
|
|
72
|
+
const trigger = rootRef.current?.getBoundingClientRect();
|
|
73
|
+
const menuHeight = menuRef.current?.scrollHeight ?? 0;
|
|
74
|
+
if (!trigger) return;
|
|
75
|
+
const bounds = rootRef.current
|
|
76
|
+
?.closest("[data-investigation-findings-scroll]")
|
|
77
|
+
?.getBoundingClientRect() ?? { top: 0, bottom: window.innerHeight };
|
|
78
|
+
const below = bounds.bottom - trigger.bottom - 8;
|
|
79
|
+
const above = trigger.top - bounds.top - 8;
|
|
80
|
+
const up = menuHeight > below && above > below;
|
|
81
|
+
const room = up ? above : below;
|
|
82
|
+
setPlacement({ up, maxHeight: menuHeight > room ? room : undefined });
|
|
83
|
+
}, [open, shouldRender]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!open) return;
|
|
87
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
88
|
+
if (!rootRef.current?.contains(event.target as Node)) setOpen(false);
|
|
89
|
+
};
|
|
90
|
+
// Capture phase, consumed: the Escape that closes this menu must not also
|
|
91
|
+
// close the investigation panel.
|
|
92
|
+
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
93
|
+
if (event.key !== "Escape") return;
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
setOpen(false);
|
|
97
|
+
triggerRef.current?.focus();
|
|
98
|
+
};
|
|
99
|
+
// Placement is measured on open, so moving the pane closes the menu.
|
|
100
|
+
const close = () => setOpen(false);
|
|
101
|
+
const onScroll = (event: Event) => {
|
|
102
|
+
if (!menuRef.current?.contains(event.target as Node)) close();
|
|
103
|
+
};
|
|
104
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
105
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
106
|
+
window.addEventListener("scroll", onScroll, true);
|
|
107
|
+
window.addEventListener("resize", close);
|
|
108
|
+
return () => {
|
|
109
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
110
|
+
document.removeEventListener("keydown", onKeyDown, true);
|
|
111
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
112
|
+
window.removeEventListener("resize", close);
|
|
113
|
+
};
|
|
114
|
+
}, [open]);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (open && isOpen) {
|
|
118
|
+
menuRef.current
|
|
119
|
+
?.querySelector<HTMLElement>("button")
|
|
120
|
+
?.focus({ preventScroll: true });
|
|
121
|
+
}
|
|
122
|
+
}, [open, isOpen]);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (copy === "idle") return;
|
|
126
|
+
const t = window.setTimeout(() => setCopy("idle"), 1400);
|
|
127
|
+
return () => window.clearTimeout(t);
|
|
128
|
+
}, [copy]);
|
|
129
|
+
|
|
130
|
+
const toggle = () => {
|
|
131
|
+
setCopy("idle");
|
|
132
|
+
setOpen((v) => !v);
|
|
133
|
+
};
|
|
134
|
+
const runInTerminal = () => {
|
|
135
|
+
setOpen(false);
|
|
136
|
+
openInTerminal(command, TERMINAL_TITLE);
|
|
137
|
+
};
|
|
138
|
+
const copyCommand = () => {
|
|
139
|
+
// The clipboard fallback focuses a temporary textarea outside the menu.
|
|
140
|
+
copyingRef.current = true;
|
|
141
|
+
void copyText(command).then((ok) => {
|
|
142
|
+
copyingRef.current = false;
|
|
143
|
+
setCopy(ok ? "copied" : "failed");
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
// Only focus that lands somewhere else closes the menu. Safari does not
|
|
147
|
+
// focus a clicked button, so a click inside blurs to nothing; clicks outside
|
|
148
|
+
// are the pointerdown listener's job.
|
|
149
|
+
const onFocusLeave = (event: FocusEvent<HTMLDivElement>) => {
|
|
150
|
+
const next = event.relatedTarget as Node | null;
|
|
151
|
+
if (next && !copyingRef.current && !rootRef.current?.contains(next))
|
|
152
|
+
setOpen(false);
|
|
153
|
+
};
|
|
154
|
+
const onMenuKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
155
|
+
const items = Array.from(
|
|
156
|
+
menuRef.current?.querySelectorAll<HTMLElement>("button") ?? [],
|
|
157
|
+
);
|
|
158
|
+
if (items.length === 0) return;
|
|
159
|
+
// Tab moves between the panel's buttons; leaving either end closes it
|
|
160
|
+
// and goes back to the button that opened it.
|
|
161
|
+
if (event.key === "Tab") {
|
|
162
|
+
const edge = event.shiftKey ? items[0] : items[items.length - 1];
|
|
163
|
+
if (document.activeElement !== edge) return;
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
setOpen(false);
|
|
166
|
+
triggerRef.current?.focus();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
const at = items.indexOf(document.activeElement as HTMLElement);
|
|
172
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
173
|
+
items[(at + step + items.length) % items.length].focus();
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// One button that always opens the panel: the hand-off is rare and
|
|
177
|
+
// deliberate, so the panel can say what happens (and warn about Claude
|
|
178
|
+
// Code's trust prompt) before anything runs. Docked, the header is narrow
|
|
179
|
+
// and the label keeps only where it goes.
|
|
180
|
+
return (
|
|
181
|
+
<div
|
|
182
|
+
ref={rootRef}
|
|
183
|
+
onBlur={onFocusLeave}
|
|
184
|
+
className="relative inline-flex shrink-0"
|
|
185
|
+
>
|
|
186
|
+
<button
|
|
187
|
+
ref={triggerRef}
|
|
188
|
+
type="button"
|
|
189
|
+
onClick={toggle}
|
|
190
|
+
aria-haspopup="dialog"
|
|
191
|
+
aria-expanded={open}
|
|
192
|
+
aria-controls={shouldRender ? menuId : undefined}
|
|
193
|
+
aria-label={`Continue in ${label}`}
|
|
194
|
+
className="inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border border-theme-border bg-theme-surface px-2 py-1 text-xs font-medium text-theme-text-primary hover:bg-theme-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
|
|
195
|
+
>
|
|
196
|
+
<TerminalSquare
|
|
197
|
+
className="h-3.5 w-3.5 text-theme-text-tertiary"
|
|
198
|
+
aria-hidden
|
|
199
|
+
/>
|
|
200
|
+
<span>
|
|
201
|
+
<span className="hidden @min-[640px]/diagnose-surface:inline">
|
|
202
|
+
Continue in{" "}
|
|
203
|
+
</span>
|
|
204
|
+
{label}…
|
|
205
|
+
</span>
|
|
206
|
+
</button>
|
|
207
|
+
{shouldRender && (
|
|
208
|
+
<div
|
|
209
|
+
ref={menuRef}
|
|
210
|
+
id={menuId}
|
|
211
|
+
role="dialog"
|
|
212
|
+
aria-label={`Continue in ${label}`}
|
|
213
|
+
aria-describedby={trustHint ? `${introId} ${hintId}` : introId}
|
|
214
|
+
inert={!open}
|
|
215
|
+
onKeyDown={onMenuKeyDown}
|
|
216
|
+
className={clsx(
|
|
217
|
+
"absolute right-0 z-30 w-[min(22rem,calc(100cqw-2rem))] rounded-lg border border-theme-border bg-theme-surface p-3 shadow-theme-lg",
|
|
218
|
+
placement.maxHeight !== undefined && "overflow-y-auto",
|
|
219
|
+
placement.up
|
|
220
|
+
? "bottom-full mb-1 origin-bottom-right"
|
|
221
|
+
: "top-full mt-1 origin-top-right",
|
|
222
|
+
TRANSITION_MENU,
|
|
223
|
+
isOpen
|
|
224
|
+
? "translate-y-0 scale-100 opacity-100"
|
|
225
|
+
: placement.up
|
|
226
|
+
? "translate-y-1 scale-[0.97] opacity-0"
|
|
227
|
+
: "-translate-y-1 scale-[0.97] opacity-0",
|
|
228
|
+
!open && "pointer-events-none",
|
|
229
|
+
)}
|
|
230
|
+
style={{
|
|
231
|
+
...overlayTransitionStyle(isOpen, "menu"),
|
|
232
|
+
maxHeight: placement.maxHeight,
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
<p id={introId} className="text-xs text-theme-text-secondary">
|
|
236
|
+
Resumes this session in {label} with Radar's MCP attached.
|
|
237
|
+
</p>
|
|
238
|
+
{trustHint && (
|
|
239
|
+
<p
|
|
240
|
+
id={hintId}
|
|
241
|
+
data-continue-trust-hint
|
|
242
|
+
className="mt-1 text-xs text-theme-text-tertiary"
|
|
243
|
+
>
|
|
244
|
+
{trustHint}
|
|
245
|
+
</p>
|
|
246
|
+
)}
|
|
247
|
+
{localTerminal && (
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
onClick={runInTerminal}
|
|
251
|
+
className="btn-brand mt-3 inline-flex w-full items-center justify-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
|
|
252
|
+
>
|
|
253
|
+
<TerminalSquare className="h-3.5 w-3.5" aria-hidden />
|
|
254
|
+
Run in Radar terminal
|
|
255
|
+
</button>
|
|
256
|
+
)}
|
|
257
|
+
<p className="mt-3 text-[11px] text-theme-text-tertiary">
|
|
258
|
+
{localTerminal ? "Or paste it" : "Paste it"} where you run {label}:
|
|
259
|
+
</p>
|
|
260
|
+
<div className="mt-1 flex items-start gap-1 rounded-md border border-theme-border bg-theme-base py-1 pl-2 pr-1">
|
|
261
|
+
<code
|
|
262
|
+
data-continue-command
|
|
263
|
+
className="max-h-24 min-w-0 flex-1 overflow-y-auto whitespace-pre-wrap break-all py-0.5 font-mono text-[11px] leading-snug text-theme-text-secondary"
|
|
264
|
+
>
|
|
265
|
+
{command}
|
|
266
|
+
</code>
|
|
267
|
+
<button
|
|
268
|
+
type="button"
|
|
269
|
+
onClick={copyCommand}
|
|
270
|
+
aria-label={
|
|
271
|
+
copy === "copied"
|
|
272
|
+
? "Command copied"
|
|
273
|
+
: copy === "failed"
|
|
274
|
+
? "Copy failed"
|
|
275
|
+
: "Copy command"
|
|
276
|
+
}
|
|
277
|
+
aria-live="polite"
|
|
278
|
+
className={clsx(
|
|
279
|
+
"inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-1 text-[11px] font-medium hover:bg-theme-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50",
|
|
280
|
+
copy === "copied"
|
|
281
|
+
? "text-theme-text-primary"
|
|
282
|
+
: copy === "failed"
|
|
283
|
+
? "text-warning-text"
|
|
284
|
+
: "text-theme-text-tertiary hover:text-theme-text-primary",
|
|
285
|
+
)}
|
|
286
|
+
>
|
|
287
|
+
{copy === "copied" ? (
|
|
288
|
+
<>
|
|
289
|
+
<Check className="h-3.5 w-3.5 text-success" aria-hidden />
|
|
290
|
+
Copied
|
|
291
|
+
</>
|
|
292
|
+
) : copy === "failed" ? (
|
|
293
|
+
"Copy failed"
|
|
294
|
+
) : (
|
|
295
|
+
<Copy className="h-3.5 w-3.5" aria-hidden />
|
|
296
|
+
)}
|
|
297
|
+
</button>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
)}
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, useEffect } from "react";
|
|
3
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { DiagnoseError } from "../../api/diagnose";
|
|
7
|
+
import { DiagnoseProvider, useDiagnose } from "./DiagnoseContext";
|
|
8
|
+
|
|
9
|
+
const api = vi.hoisted(() => ({ createRun: vi.fn() }));
|
|
10
|
+
|
|
11
|
+
vi.mock("../../api/diagnose", async (importOriginal) => ({
|
|
12
|
+
...(await importOriginal<object>()),
|
|
13
|
+
fetchAgents: async () => ({
|
|
14
|
+
enabled: true,
|
|
15
|
+
eligible: true,
|
|
16
|
+
consented: { "claude:safeguarded": true },
|
|
17
|
+
agents: [
|
|
18
|
+
{
|
|
19
|
+
name: "claude",
|
|
20
|
+
label: "Claude Code",
|
|
21
|
+
path: "/bin/claude",
|
|
22
|
+
version: "",
|
|
23
|
+
present: true,
|
|
24
|
+
supported: true,
|
|
25
|
+
profiles: ["safeguarded"],
|
|
26
|
+
consentSurfaces: { safeguarded: "claude:safeguarded" },
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
listRuns: async () => ({ runs: [] }),
|
|
31
|
+
getRun: vi.fn(() => new Promise(() => {})),
|
|
32
|
+
createRun: api.createRun,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
vi.mock("../../api/client", async (importOriginal) => ({
|
|
36
|
+
...(await importOriginal<object>()),
|
|
37
|
+
useContexts: () => ({ data: [{ name: "cluster-a", isCurrent: true }] }),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
41
|
+
let root: Root;
|
|
42
|
+
const probe = {} as { d: ReturnType<typeof useDiagnose> };
|
|
43
|
+
|
|
44
|
+
function Probe() {
|
|
45
|
+
const d = useDiagnose();
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
probe.d = d;
|
|
48
|
+
});
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const flush = () =>
|
|
53
|
+
act(async () => {
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const target = { kind: "Pod", group: "", namespace: "shop", name: "cart-0" };
|
|
58
|
+
const atCapacity = () =>
|
|
59
|
+
new DiagnoseError(409, "3 investigations are already running.", {
|
|
60
|
+
code: "investigations_at_capacity",
|
|
61
|
+
limit: 3,
|
|
62
|
+
context: "cluster-a",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
beforeEach(async () => {
|
|
66
|
+
api.createRun.mockReset();
|
|
67
|
+
localStorage.clear();
|
|
68
|
+
const element = document.createElement("div");
|
|
69
|
+
document.body.appendChild(element);
|
|
70
|
+
root = createRoot(element);
|
|
71
|
+
await act(async () =>
|
|
72
|
+
root.render(
|
|
73
|
+
<DiagnoseProvider browserURLState={false}>
|
|
74
|
+
<Probe />
|
|
75
|
+
</DiagnoseProvider>,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
await flush();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
afterEach(async () => {
|
|
82
|
+
await act(async () => root.unmount());
|
|
83
|
+
document.body.replaceChildren();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("a start refused at capacity", () => {
|
|
87
|
+
it("keeps the refused start so it can be retried", async () => {
|
|
88
|
+
api.createRun.mockRejectedValue(atCapacity());
|
|
89
|
+
await act(async () => probe.d.openInvestigation(target));
|
|
90
|
+
await flush();
|
|
91
|
+
// The start is bound to the cluster it was made in, so a retry can't
|
|
92
|
+
// land on a same-named resource elsewhere.
|
|
93
|
+
expect(probe.d.startCapacity).toEqual({
|
|
94
|
+
target: { ...target, context: "cluster-a" },
|
|
95
|
+
limit: 3,
|
|
96
|
+
context: "cluster-a",
|
|
97
|
+
});
|
|
98
|
+
expect(probe.d.startRefusal).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("does not take over a run the user opened while it was in flight", async () => {
|
|
102
|
+
let refuse!: () => void;
|
|
103
|
+
api.createRun.mockReturnValue(
|
|
104
|
+
new Promise((_, reject) => (refuse = () => reject(atCapacity()))),
|
|
105
|
+
);
|
|
106
|
+
await act(async () => probe.d.openInvestigation(target));
|
|
107
|
+
await act(async () => probe.d.openRun("run-other"));
|
|
108
|
+
await act(async () => refuse());
|
|
109
|
+
await flush();
|
|
110
|
+
expect(probe.d.startCapacity).toBeNull();
|
|
111
|
+
expect(probe.d.activeRunId).toBe("run-other");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { DiagnoseError } from "../../api/diagnose";
|
|
7
|
+
import {
|
|
8
|
+
DiagnoseProvider,
|
|
9
|
+
useDiagnose,
|
|
10
|
+
useDiagnoseLayout,
|
|
11
|
+
} from "./DiagnoseContext";
|
|
12
|
+
import { runTargetKey } from "./target";
|
|
13
|
+
|
|
14
|
+
const api = vi.hoisted(() => ({
|
|
15
|
+
createRun: vi.fn(),
|
|
16
|
+
recordConsent: vi.fn(),
|
|
17
|
+
consented: {} as Record<string, boolean>,
|
|
18
|
+
runs: [] as unknown[],
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
vi.mock("../../api/diagnose", async (importOriginal) => ({
|
|
22
|
+
...(await importOriginal<object>()),
|
|
23
|
+
fetchAgents: async () => ({
|
|
24
|
+
enabled: true,
|
|
25
|
+
eligible: true,
|
|
26
|
+
consented: api.consented,
|
|
27
|
+
agents: [
|
|
28
|
+
{
|
|
29
|
+
name: "claude",
|
|
30
|
+
label: "Claude Code",
|
|
31
|
+
path: "/bin/claude",
|
|
32
|
+
version: "",
|
|
33
|
+
present: true,
|
|
34
|
+
supported: true,
|
|
35
|
+
profiles: ["safeguarded"],
|
|
36
|
+
consentSurfaces: { safeguarded: "claude:safeguarded" },
|
|
37
|
+
questions: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
listRuns: async () => ({ runs: api.runs }),
|
|
42
|
+
getRun: vi.fn(),
|
|
43
|
+
createRun: api.createRun,
|
|
44
|
+
recordConsent: api.recordConsent,
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const cluster = vi.hoisted(() => ({ name: "cluster-a" as string | undefined }));
|
|
48
|
+
vi.mock("../../api/client", async (importOriginal) => ({
|
|
49
|
+
...(await importOriginal<object>()),
|
|
50
|
+
useContexts: () => ({
|
|
51
|
+
data: cluster.name ? [{ name: cluster.name, isCurrent: true }] : undefined,
|
|
52
|
+
}),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
56
|
+
let root: Root;
|
|
57
|
+
let diagnose: ReturnType<typeof useDiagnose>;
|
|
58
|
+
let layout: ReturnType<typeof useDiagnoseLayout>;
|
|
59
|
+
|
|
60
|
+
function capture(seenDiagnose: typeof diagnose, seenLayout: typeof layout) {
|
|
61
|
+
diagnose = seenDiagnose;
|
|
62
|
+
layout = seenLayout;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Probe() {
|
|
66
|
+
capture(useDiagnose(), useDiagnoseLayout());
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const flush = () =>
|
|
71
|
+
act(async () => {
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const question = {
|
|
76
|
+
kind: "",
|
|
77
|
+
group: "",
|
|
78
|
+
namespace: "",
|
|
79
|
+
name: "",
|
|
80
|
+
question: "checkout returns 502s",
|
|
81
|
+
namespaces: ["shop"],
|
|
82
|
+
lookBack: "1h",
|
|
83
|
+
fromComposer: true,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
beforeEach(async () => {
|
|
87
|
+
api.createRun.mockReset();
|
|
88
|
+
api.recordConsent.mockReset();
|
|
89
|
+
api.consented = {};
|
|
90
|
+
api.runs = [];
|
|
91
|
+
cluster.name = "cluster-a";
|
|
92
|
+
localStorage.clear();
|
|
93
|
+
const element = document.createElement("div");
|
|
94
|
+
document.body.appendChild(element);
|
|
95
|
+
root = createRoot(element);
|
|
96
|
+
await act(async () =>
|
|
97
|
+
root.render(
|
|
98
|
+
<DiagnoseProvider browserURLState={false}>
|
|
99
|
+
<Probe />
|
|
100
|
+
</DiagnoseProvider>,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
await flush();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(async () => {
|
|
107
|
+
await act(async () => root.unmount());
|
|
108
|
+
document.body.replaceChildren();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("starting from a question", () => {
|
|
112
|
+
it("never starts a run whose consent was cancelled while being recorded", async () => {
|
|
113
|
+
let recorded!: () => void;
|
|
114
|
+
api.recordConsent.mockReturnValue(
|
|
115
|
+
new Promise<void>((resolve) => (recorded = resolve)),
|
|
116
|
+
);
|
|
117
|
+
await act(async () => diagnose.openInvestigation(question));
|
|
118
|
+
expect(diagnose.needsConsent).toBe(true);
|
|
119
|
+
await act(async () => diagnose.approveConsent());
|
|
120
|
+
await act(async () => diagnose.cancelConsent());
|
|
121
|
+
await act(async () => recorded());
|
|
122
|
+
await flush();
|
|
123
|
+
expect(api.createRun).not.toHaveBeenCalled();
|
|
124
|
+
expect(diagnose.questionDraft?.text).toBe("checkout returns 502s");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("gives a refused start's question back to the composer", async () => {
|
|
128
|
+
api.consented = { "claude:safeguarded": true };
|
|
129
|
+
await act(async () => diagnose.recheckAgents());
|
|
130
|
+
api.createRun.mockRejectedValue(
|
|
131
|
+
new DiagnoseError(409, "too many investigations running"),
|
|
132
|
+
);
|
|
133
|
+
await act(async () => diagnose.openInvestigation(question));
|
|
134
|
+
await flush();
|
|
135
|
+
expect(diagnose.startError).toContain("too many");
|
|
136
|
+
expect(diagnose.questionDraft).toMatchObject({
|
|
137
|
+
text: "checkout returns 502s",
|
|
138
|
+
namespaces: ["shop"],
|
|
139
|
+
restore: true,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("leaves a saved draft alone when a run is started from elsewhere", async () => {
|
|
144
|
+
api.consented = { "claude:safeguarded": true };
|
|
145
|
+
await act(async () => diagnose.recheckAgents());
|
|
146
|
+
await act(async () => diagnose.saveQuestionDraft({ text: "draft B" }));
|
|
147
|
+
api.createRun.mockRejectedValue(new DiagnoseError(409, "refused"));
|
|
148
|
+
await act(async () =>
|
|
149
|
+
diagnose.openInvestigation({ ...question, fromComposer: undefined }),
|
|
150
|
+
);
|
|
151
|
+
await flush();
|
|
152
|
+
expect(diagnose.questionDraft?.text).toBe("draft B");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("hands back an explicit all-namespaces choice as it was", async () => {
|
|
156
|
+
api.consented = { "claude:safeguarded": true };
|
|
157
|
+
await act(async () => diagnose.recheckAgents());
|
|
158
|
+
api.createRun.mockRejectedValue(new DiagnoseError(409, "refused"));
|
|
159
|
+
await act(async () =>
|
|
160
|
+
diagnose.openInvestigation({ ...question, namespaces: [] }),
|
|
161
|
+
);
|
|
162
|
+
await flush();
|
|
163
|
+
expect(diagnose.questionDraft?.namespaces).toEqual([]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("points a resource's running indicator at the live run, a question run included", async () => {
|
|
167
|
+
const run = (id: string, question?: string) => ({
|
|
168
|
+
id,
|
|
169
|
+
kind: "Deployment",
|
|
170
|
+
group: "apps",
|
|
171
|
+
namespace: "shop",
|
|
172
|
+
name: "api",
|
|
173
|
+
context: "cluster-a",
|
|
174
|
+
status: "running",
|
|
175
|
+
question,
|
|
176
|
+
createdAt: "2026-10-28T09:00:00Z",
|
|
177
|
+
updatedAt: "2026-10-28T09:00:00Z",
|
|
178
|
+
});
|
|
179
|
+
const key = runTargetKey("Deployment", "shop", "api", "apps");
|
|
180
|
+
api.runs = [run("asked", "why?")];
|
|
181
|
+
await act(async () => diagnose.refreshRuns());
|
|
182
|
+
await flush();
|
|
183
|
+
expect(layout.runningRunIds.get(key)).toBe("asked");
|
|
184
|
+
api.runs = [run("asked", "why?"), run("plain")];
|
|
185
|
+
await act(async () => diagnose.refreshRuns());
|
|
186
|
+
await flush();
|
|
187
|
+
expect(layout.runningRunIds.get(key)).toBe("plain");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("drops a start waiting on consent when the cluster changes", async () => {
|
|
191
|
+
let recorded!: () => void;
|
|
192
|
+
api.recordConsent.mockReturnValue(
|
|
193
|
+
new Promise<void>((resolve) => (recorded = resolve)),
|
|
194
|
+
);
|
|
195
|
+
await act(async () =>
|
|
196
|
+
diagnose.openInvestigation({
|
|
197
|
+
...question,
|
|
198
|
+
kind: "Deployment",
|
|
199
|
+
group: "apps",
|
|
200
|
+
namespace: "shop",
|
|
201
|
+
name: "api",
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
expect(diagnose.needsConsent).toBe(true);
|
|
205
|
+
await act(async () => diagnose.approveConsent());
|
|
206
|
+
cluster.name = "cluster-b";
|
|
207
|
+
await act(async () =>
|
|
208
|
+
root.render(
|
|
209
|
+
<DiagnoseProvider browserURLState={false}>
|
|
210
|
+
<Probe />
|
|
211
|
+
</DiagnoseProvider>,
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
await act(async () => recorded());
|
|
215
|
+
await flush();
|
|
216
|
+
expect(diagnose.needsConsent).toBe(false);
|
|
217
|
+
expect(api.createRun).not.toHaveBeenCalled();
|
|
218
|
+
expect(diagnose.questionDraft).toMatchObject({
|
|
219
|
+
text: "checkout returns 502s",
|
|
220
|
+
context: "cluster-a",
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("protects a start opened before the cluster was known", async () => {
|
|
225
|
+
const rerender = () =>
|
|
226
|
+
act(async () =>
|
|
227
|
+
root.render(
|
|
228
|
+
<DiagnoseProvider browserURLState={false}>
|
|
229
|
+
<Probe />
|
|
230
|
+
</DiagnoseProvider>,
|
|
231
|
+
),
|
|
232
|
+
);
|
|
233
|
+
cluster.name = undefined;
|
|
234
|
+
await rerender();
|
|
235
|
+
await act(async () => diagnose.openInvestigation(question));
|
|
236
|
+
expect(diagnose.needsConsent).toBe(true);
|
|
237
|
+
cluster.name = "cluster-a";
|
|
238
|
+
await rerender();
|
|
239
|
+
cluster.name = "cluster-b";
|
|
240
|
+
await rerender();
|
|
241
|
+
await flush();
|
|
242
|
+
expect(diagnose.needsConsent).toBe(false);
|
|
243
|
+
expect(diagnose.questionDraft?.context).toBe("cluster-a");
|
|
244
|
+
});
|
|
245
|
+
});
|