@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,450 @@
|
|
|
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 type { RunSummary } from "../../api/diagnose";
|
|
7
|
+
import { DiagnoseProvider, useDiagnose } from "./DiagnoseContext";
|
|
8
|
+
import {
|
|
9
|
+
defaultDiagnoseAction,
|
|
10
|
+
IssueDiagnoseButton,
|
|
11
|
+
} from "./LocalDiagnoseAction";
|
|
12
|
+
|
|
13
|
+
const api = vi.hoisted(() => ({
|
|
14
|
+
runs: [] as RunSummary[],
|
|
15
|
+
hosted: false,
|
|
16
|
+
listRuns: vi.fn(),
|
|
17
|
+
recordUsageEvent: vi.fn(),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
vi.mock("../../api/usage-data", async (importOriginal) => ({
|
|
21
|
+
...(await importOriginal<object>()),
|
|
22
|
+
recordUsageEvent: api.recordUsageEvent,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
vi.mock("../../api/diagnose", async (importOriginal) => ({
|
|
26
|
+
...(await importOriginal<object>()),
|
|
27
|
+
fetchAgents: async () => ({
|
|
28
|
+
enabled: true,
|
|
29
|
+
eligible: true,
|
|
30
|
+
consented: { "claude:safeguarded": true },
|
|
31
|
+
agents: [
|
|
32
|
+
{
|
|
33
|
+
name: "claude",
|
|
34
|
+
label: "Claude Code",
|
|
35
|
+
path: "/bin/claude",
|
|
36
|
+
version: "",
|
|
37
|
+
present: true,
|
|
38
|
+
supported: true,
|
|
39
|
+
hosted: api.hosted,
|
|
40
|
+
questions: true,
|
|
41
|
+
profiles: ["safeguarded"],
|
|
42
|
+
consentSurfaces: { safeguarded: "claude:safeguarded" },
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
}),
|
|
46
|
+
listRuns: api.listRuns,
|
|
47
|
+
getRun: vi.fn(() => new Promise(() => {})),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
vi.mock("../../api/client", async (importOriginal) => ({
|
|
51
|
+
...(await importOriginal<object>()),
|
|
52
|
+
useContexts: () => ({ data: [{ name: "cluster-a", isCurrent: true }] }),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
56
|
+
let root: Root;
|
|
57
|
+
const probe = {} as { d: ReturnType<typeof useDiagnose> };
|
|
58
|
+
|
|
59
|
+
function Probe() {
|
|
60
|
+
const d = useDiagnose();
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
probe.d = d;
|
|
63
|
+
});
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const flush = () =>
|
|
68
|
+
act(async () => {
|
|
69
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const ago = (h: number) => new Date(Date.now() - h * 3600_000).toISOString();
|
|
73
|
+
const investigated = (over: Partial<RunSummary> = {}): RunSummary => ({
|
|
74
|
+
id: "run-cart",
|
|
75
|
+
kind: "Deployment",
|
|
76
|
+
group: "apps",
|
|
77
|
+
namespace: "shop",
|
|
78
|
+
name: "cart",
|
|
79
|
+
context: "cluster-a",
|
|
80
|
+
status: "done",
|
|
81
|
+
preview: "Pods crash on a bad flag",
|
|
82
|
+
assessedAt: ago(2),
|
|
83
|
+
createdAt: ago(3),
|
|
84
|
+
updatedAt: ago(2),
|
|
85
|
+
...over,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
async function renderButton(
|
|
89
|
+
health: "problem" | "healthy" = "problem",
|
|
90
|
+
createdAt?: string,
|
|
91
|
+
) {
|
|
92
|
+
await act(async () =>
|
|
93
|
+
root.render(
|
|
94
|
+
<DiagnoseProvider browserURLState={false}>
|
|
95
|
+
<Probe />
|
|
96
|
+
{defaultDiagnoseAction({
|
|
97
|
+
kind: "Deployment",
|
|
98
|
+
group: "apps",
|
|
99
|
+
namespace: "shop",
|
|
100
|
+
name: "cart",
|
|
101
|
+
health,
|
|
102
|
+
createdAt,
|
|
103
|
+
})}
|
|
104
|
+
</DiagnoseProvider>,
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
await flush();
|
|
108
|
+
await flush();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const trigger = () =>
|
|
112
|
+
document.querySelector<HTMLButtonElement>("button[aria-label]")!;
|
|
113
|
+
const dialog = () => document.querySelector('[role="dialog"]');
|
|
114
|
+
const buttonNamed = (text: string) =>
|
|
115
|
+
[...document.querySelectorAll("button")].find((b) => b.textContent === text)!;
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
api.runs = [];
|
|
119
|
+
api.hosted = false;
|
|
120
|
+
api.listRuns.mockReset();
|
|
121
|
+
api.listRuns.mockImplementation(async () => ({ runs: api.runs }));
|
|
122
|
+
localStorage.clear();
|
|
123
|
+
const element = document.createElement("div");
|
|
124
|
+
document.body.appendChild(element);
|
|
125
|
+
root = createRoot(element);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
afterEach(async () => {
|
|
129
|
+
await act(async () => root.unmount());
|
|
130
|
+
document.body.replaceChildren();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("a resource's last investigation", () => {
|
|
134
|
+
it("shows what the earlier investigation found before starting another", async () => {
|
|
135
|
+
api.runs = [investigated()];
|
|
136
|
+
await renderButton("problem");
|
|
137
|
+
const openRun = vi.spyOn(probe.d, "openRun");
|
|
138
|
+
const openInvestigation = vi.spyOn(probe.d, "openInvestigation");
|
|
139
|
+
await act(async () => trigger().click());
|
|
140
|
+
expect(dialog()?.textContent).toContain("Pods crash on a bad flag");
|
|
141
|
+
expect(openInvestigation).not.toHaveBeenCalled();
|
|
142
|
+
await act(async () => buttonNamed("Open investigation").click());
|
|
143
|
+
expect(openRun).toHaveBeenCalledWith("run-cart");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("marks the button with a filled sparkle only when there is history", async () => {
|
|
147
|
+
await renderButton("problem");
|
|
148
|
+
expect(trigger().querySelector("svg")?.getAttribute("fill")).toBe("none");
|
|
149
|
+
api.runs = [investigated()];
|
|
150
|
+
await act(async () => window.dispatchEvent(new Event("focus")));
|
|
151
|
+
await flush();
|
|
152
|
+
expect(trigger().querySelector("svg")?.getAttribute("fill")).toBe(
|
|
153
|
+
"currentColor",
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("keeps the usual action one click further on", async () => {
|
|
158
|
+
api.runs = [investigated()];
|
|
159
|
+
await renderButton("problem");
|
|
160
|
+
const openInvestigation = vi.spyOn(probe.d, "openInvestigation");
|
|
161
|
+
await act(async () => trigger().click());
|
|
162
|
+
await act(async () => buttonNamed("Investigate again").click());
|
|
163
|
+
expect(openInvestigation).toHaveBeenCalledWith({
|
|
164
|
+
kind: "Deployment",
|
|
165
|
+
group: "apps",
|
|
166
|
+
namespace: "shop",
|
|
167
|
+
name: "cart",
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("offers a question on a healthy resource", async () => {
|
|
172
|
+
api.runs = [investigated({ preview: "Healthy" })];
|
|
173
|
+
await renderButton("healthy");
|
|
174
|
+
const openQuestion = vi.spyOn(probe.d, "openQuestion");
|
|
175
|
+
await act(async () => trigger().click());
|
|
176
|
+
expect(dialog()?.textContent).toContain("Healthy");
|
|
177
|
+
await act(async () => buttonNamed("Ask a question").click());
|
|
178
|
+
expect(openQuestion).toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it.each([
|
|
182
|
+
["the object was recreated since", () => [investigated()], ago(1)],
|
|
183
|
+
[
|
|
184
|
+
"it ran on another cluster",
|
|
185
|
+
() => [investigated({ context: "cluster-b" })],
|
|
186
|
+
undefined,
|
|
187
|
+
],
|
|
188
|
+
])("stays out of the way when %s", async (_, runs, createdAt) => {
|
|
189
|
+
api.runs = runs();
|
|
190
|
+
await renderButton("problem", createdAt);
|
|
191
|
+
const openInvestigation = vi.spyOn(probe.d, "openInvestigation");
|
|
192
|
+
await act(async () => trigger().click());
|
|
193
|
+
expect(dialog()).toBeNull();
|
|
194
|
+
expect(openInvestigation).toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("is off for hosted agents, which keep their own shared history", async () => {
|
|
198
|
+
api.hosted = true;
|
|
199
|
+
api.runs = [investigated()];
|
|
200
|
+
await renderButton("problem");
|
|
201
|
+
await act(async () => trigger().click());
|
|
202
|
+
expect(dialog()).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("never opens a live run on another cluster's same-named resource", async () => {
|
|
206
|
+
api.runs = [
|
|
207
|
+
investigated({
|
|
208
|
+
status: "running",
|
|
209
|
+
context: "cluster-b",
|
|
210
|
+
assessedAt: undefined,
|
|
211
|
+
}),
|
|
212
|
+
];
|
|
213
|
+
await renderButton("problem");
|
|
214
|
+
const openRun = vi.spyOn(probe.d, "openRun");
|
|
215
|
+
await act(async () => trigger().click());
|
|
216
|
+
expect(openRun).not.toHaveBeenCalled();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("takes focus, and gives Escape back to the button without closing what's under it", async () => {
|
|
220
|
+
api.runs = [investigated()];
|
|
221
|
+
await renderButton("problem");
|
|
222
|
+
const underneath = vi.fn();
|
|
223
|
+
document.addEventListener("keydown", underneath);
|
|
224
|
+
const button = trigger();
|
|
225
|
+
await act(async () => button.click());
|
|
226
|
+
await flush();
|
|
227
|
+
expect(document.activeElement?.textContent).toBe("Open investigation");
|
|
228
|
+
await act(async () =>
|
|
229
|
+
document.activeElement!.dispatchEvent(
|
|
230
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
|
|
231
|
+
),
|
|
232
|
+
);
|
|
233
|
+
expect(underneath).not.toHaveBeenCalled();
|
|
234
|
+
expect(button.isConnected).toBe(true);
|
|
235
|
+
expect(document.activeElement).toBe(button);
|
|
236
|
+
document.removeEventListener("keydown", underneath);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("still opens a hosted agent's live run, whose cluster label differs", async () => {
|
|
240
|
+
api.hosted = true;
|
|
241
|
+
api.runs = [
|
|
242
|
+
investigated({
|
|
243
|
+
status: "running",
|
|
244
|
+
context: "Prod cluster",
|
|
245
|
+
assessedAt: undefined,
|
|
246
|
+
}),
|
|
247
|
+
];
|
|
248
|
+
await renderButton("healthy");
|
|
249
|
+
const openRun = vi.spyOn(probe.d, "openRun");
|
|
250
|
+
await act(async () => trigger().click());
|
|
251
|
+
expect(openRun).toHaveBeenCalledWith("run-cart");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("ignores a list that resolves after a newer one", async () => {
|
|
255
|
+
api.runs = [investigated()];
|
|
256
|
+
await renderButton("problem");
|
|
257
|
+
let resolveOld!: (v: { runs: RunSummary[] }) => void;
|
|
258
|
+
api.listRuns.mockImplementationOnce(
|
|
259
|
+
() => new Promise((resolve) => (resolveOld = resolve)),
|
|
260
|
+
);
|
|
261
|
+
await act(async () => window.dispatchEvent(new Event("focus")));
|
|
262
|
+
api.runs = [];
|
|
263
|
+
await act(async () => window.dispatchEvent(new Event("focus")));
|
|
264
|
+
await flush();
|
|
265
|
+
await act(async () => resolveOld({ runs: [investigated()] }));
|
|
266
|
+
await flush();
|
|
267
|
+
await act(async () => trigger().click());
|
|
268
|
+
expect(dialog()).toBeNull();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("doesn't reopen the panel by itself after a new run finishes", async () => {
|
|
272
|
+
api.runs = [investigated()];
|
|
273
|
+
await renderButton("problem");
|
|
274
|
+
await act(async () => trigger().click());
|
|
275
|
+
expect(dialog()).not.toBeNull();
|
|
276
|
+
api.runs = [
|
|
277
|
+
investigated({ id: "run-new", status: "running", assessedAt: undefined }),
|
|
278
|
+
investigated(),
|
|
279
|
+
];
|
|
280
|
+
await act(async () => probe.d.refreshRuns());
|
|
281
|
+
await flush();
|
|
282
|
+
api.runs = [
|
|
283
|
+
investigated({ id: "run-new", assessedAt: new Date().toISOString() }),
|
|
284
|
+
investigated(),
|
|
285
|
+
];
|
|
286
|
+
await act(async () => probe.d.refreshRuns());
|
|
287
|
+
await flush();
|
|
288
|
+
await flush();
|
|
289
|
+
expect(dialog()).toBeNull();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("catches up when the window regains focus", async () => {
|
|
293
|
+
await renderButton("problem");
|
|
294
|
+
expect(dialog()).toBeNull();
|
|
295
|
+
api.runs = [investigated()];
|
|
296
|
+
await act(async () => window.dispatchEvent(new Event("focus")));
|
|
297
|
+
await flush();
|
|
298
|
+
await act(async () => trigger().click());
|
|
299
|
+
expect(dialog()?.textContent).toContain("Pods crash on a bad flag");
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe("an issue row's Investigate action", () => {
|
|
304
|
+
const rowToggle = vi.fn();
|
|
305
|
+
async function renderIssueRow(size: "default" | "compact" = "default") {
|
|
306
|
+
rowToggle.mockReset();
|
|
307
|
+
await act(async () =>
|
|
308
|
+
root.render(
|
|
309
|
+
<DiagnoseProvider browserURLState={false}>
|
|
310
|
+
<Probe />
|
|
311
|
+
<div role="button" onClick={rowToggle} className="overflow-hidden">
|
|
312
|
+
<IssueDiagnoseButton
|
|
313
|
+
kind="Deployment"
|
|
314
|
+
group="apps"
|
|
315
|
+
namespace="shop"
|
|
316
|
+
name="cart"
|
|
317
|
+
size={size}
|
|
318
|
+
/>
|
|
319
|
+
</div>
|
|
320
|
+
</DiagnoseProvider>,
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
await flush();
|
|
324
|
+
await flush();
|
|
325
|
+
}
|
|
326
|
+
const issueButton = () =>
|
|
327
|
+
[...document.querySelectorAll("button")].find((b) =>
|
|
328
|
+
b.textContent?.includes("Investigate"),
|
|
329
|
+
)!;
|
|
330
|
+
|
|
331
|
+
it.each(["default", "compact"] as const)(
|
|
332
|
+
"shows the last investigation outside the row, without toggling it (%s)",
|
|
333
|
+
async (size) => {
|
|
334
|
+
api.runs = [investigated()];
|
|
335
|
+
await renderIssueRow(size);
|
|
336
|
+
const openRun = vi.spyOn(probe.d, "openRun");
|
|
337
|
+
await act(async () => issueButton().click());
|
|
338
|
+
// Portaled out of the row, which clips its contents.
|
|
339
|
+
expect(dialog()?.parentElement).toBe(document.body);
|
|
340
|
+
expect(dialog()?.textContent).toContain("Pods crash on a bad flag");
|
|
341
|
+
await act(async () => buttonNamed("Open investigation").click());
|
|
342
|
+
expect(openRun).toHaveBeenCalledWith("run-cart");
|
|
343
|
+
expect(rowToggle).not.toHaveBeenCalled();
|
|
344
|
+
},
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
const investigateEvent = { type: "ui", name: "issue_action:investigate" };
|
|
348
|
+
|
|
349
|
+
it("counts starting an investigation", async () => {
|
|
350
|
+
api.runs = [];
|
|
351
|
+
await renderIssueRow();
|
|
352
|
+
api.recordUsageEvent.mockClear();
|
|
353
|
+
await act(async () => issueButton().click());
|
|
354
|
+
expect(api.recordUsageEvent.mock.calls).toEqual([[investigateEvent]]);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("counts investigating again, not opening the last investigation", async () => {
|
|
358
|
+
api.runs = [investigated()];
|
|
359
|
+
await renderIssueRow();
|
|
360
|
+
api.recordUsageEvent.mockClear();
|
|
361
|
+
await act(async () => issueButton().click());
|
|
362
|
+
expect(api.recordUsageEvent).not.toHaveBeenCalled();
|
|
363
|
+
await act(async () => buttonNamed("Investigate again").click());
|
|
364
|
+
expect(api.recordUsageEvent.mock.calls).toEqual([[investigateEvent]]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("re-investigates from the panel", async () => {
|
|
368
|
+
api.runs = [investigated()];
|
|
369
|
+
await renderIssueRow();
|
|
370
|
+
const openInvestigation = vi.spyOn(probe.d, "openInvestigation");
|
|
371
|
+
await act(async () => issueButton().click());
|
|
372
|
+
await act(async () => buttonNamed("Investigate again").click());
|
|
373
|
+
expect(openInvestigation).toHaveBeenCalledWith({
|
|
374
|
+
kind: "Deployment",
|
|
375
|
+
group: "apps",
|
|
376
|
+
namespace: "shop",
|
|
377
|
+
name: "cart",
|
|
378
|
+
});
|
|
379
|
+
expect(rowToggle).not.toHaveBeenCalled();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("starts straight away when there's nothing recent", async () => {
|
|
383
|
+
api.runs = [];
|
|
384
|
+
await renderIssueRow();
|
|
385
|
+
const openInvestigation = vi.spyOn(probe.d, "openInvestigation");
|
|
386
|
+
await act(async () => issueButton().click());
|
|
387
|
+
expect(dialog()).toBeNull();
|
|
388
|
+
expect(openInvestigation).toHaveBeenCalled();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("tabs out of the panel back to the button", async () => {
|
|
392
|
+
api.runs = [investigated()];
|
|
393
|
+
await renderIssueRow();
|
|
394
|
+
const button = issueButton();
|
|
395
|
+
await act(async () => button.click());
|
|
396
|
+
await flush();
|
|
397
|
+
const last = buttonNamed("Investigate again");
|
|
398
|
+
last.focus();
|
|
399
|
+
await act(async () =>
|
|
400
|
+
last.dispatchEvent(
|
|
401
|
+
new KeyboardEvent("keydown", { key: "Tab", bubbles: true }),
|
|
402
|
+
),
|
|
403
|
+
);
|
|
404
|
+
expect(document.activeElement).toBe(button);
|
|
405
|
+
expect(dialog()?.getAttribute("inert")).not.toBeNull();
|
|
406
|
+
expect(rowToggle).not.toHaveBeenCalled();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("opens above a button near the bottom of the screen", async () => {
|
|
410
|
+
api.runs = [investigated()];
|
|
411
|
+
await renderIssueRow();
|
|
412
|
+
const button = issueButton();
|
|
413
|
+
const rect = vi
|
|
414
|
+
.spyOn(HTMLElement.prototype, "getBoundingClientRect")
|
|
415
|
+
.mockReturnValue({
|
|
416
|
+
top: 700,
|
|
417
|
+
bottom: 720,
|
|
418
|
+
left: 900,
|
|
419
|
+
right: 1000,
|
|
420
|
+
width: 100,
|
|
421
|
+
height: 20,
|
|
422
|
+
x: 900,
|
|
423
|
+
y: 700,
|
|
424
|
+
toJSON: () => ({}),
|
|
425
|
+
});
|
|
426
|
+
const height = vi
|
|
427
|
+
.spyOn(HTMLElement.prototype, "offsetHeight", "get")
|
|
428
|
+
.mockReturnValue(150);
|
|
429
|
+
vi.stubGlobal("innerHeight", 768);
|
|
430
|
+
await act(async () => button.click());
|
|
431
|
+
await flush();
|
|
432
|
+
expect(dialog()!.getAttribute("style")).toContain("top: 544px");
|
|
433
|
+
rect.mockRestore();
|
|
434
|
+
height.mockRestore();
|
|
435
|
+
vi.unstubAllGlobals();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("closes when the list scrolls, keeping keyboard focus on the button", async () => {
|
|
439
|
+
api.runs = [investigated()];
|
|
440
|
+
await renderIssueRow();
|
|
441
|
+
const button = issueButton();
|
|
442
|
+
await act(async () => button.click());
|
|
443
|
+
await flush();
|
|
444
|
+
expect(document.activeElement?.textContent).toBe("Open investigation");
|
|
445
|
+
await act(async () => document.dispatchEvent(new Event("scroll")));
|
|
446
|
+
await flush();
|
|
447
|
+
expect(dialog()?.getAttribute("inert")).not.toBeNull();
|
|
448
|
+
expect(document.activeElement).toBe(button);
|
|
449
|
+
});
|
|
450
|
+
});
|