@skyhook-io/radar-app 1.18.2 → 1.19.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/package.json +4 -4
- package/src/App.tsx +0 -1
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +93 -3
- package/src/api/radarFeatures.ts +1 -0
- package/src/components/diagnose/AIMarkdown.tsx +1 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
- 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/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +205 -9
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/Home.test.tsx +182 -5
- package/src/components/diagnose/Home.tsx +168 -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 +5 -1
- package/src/components/diagnose/InvestigationView.tsx +156 -29
- package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +487 -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/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -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/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/types.ts +2 -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/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/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +113 -0
- package/src/components/home/HomeAgentBlock.tsx +94 -0
- package/src/components/home/HomeView.tsx +5 -6
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- 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/whats-new/WhatsNewDialog.test.tsx +3 -3
- package/src/components/whats-new/releaseNotes.ts +60 -1
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
|
@@ -66,6 +66,28 @@ describe("resolveStoryPlacements", () => {
|
|
|
66
66
|
expect(html).toContain('data-story-lost-support="unlinked"');
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it("names which kind of loss each unrendered citation is", () => {
|
|
70
|
+
const html = renderToStaticMarkup(
|
|
71
|
+
<AnalysisStory
|
|
72
|
+
placements={resolveStoryPlacements(
|
|
73
|
+
"One [[radar:evidence=0]]. Two [[radar:evidence=1]]. Three [[radar:evidence=2]].",
|
|
74
|
+
resolver({ 0: "invalid", 1: "unlinked", 2: "unplaced" }),
|
|
75
|
+
)}
|
|
76
|
+
renderPlacement={() => null}
|
|
77
|
+
onReveal={vi.fn()}
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
expect(html).toMatch(
|
|
81
|
+
/data-story-lost-support="invalid"[^>]*>.*?unknown citation/,
|
|
82
|
+
);
|
|
83
|
+
expect(html).toMatch(
|
|
84
|
+
/data-story-lost-support="unlinked"[^>]*>.*?unverified/,
|
|
85
|
+
);
|
|
86
|
+
expect(html).toMatch(
|
|
87
|
+
/data-story-lost-support="unplaced"[^>]*>.*?unclear citation/,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
69
91
|
it("places a card under the paragraph that first mentions it inline, and drops that marker from the sentence", () => {
|
|
70
92
|
const story = resolveStoryPlacements(
|
|
71
93
|
"Envoy boots [[radar:evidence=0]] then hangs on xDS.\n\nLater, see [[radar:evidence=0]] again.",
|
|
@@ -212,7 +212,16 @@ function removeInlineMarker(markdown: string, index: number): string {
|
|
|
212
212
|
return before + after;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
type NamedLoss = Exclude<StoryPlacementLoss, object>;
|
|
216
|
+
|
|
217
|
+
// The chip names which failure it is; the tooltip says what it means.
|
|
218
|
+
const LOSS_LABEL: Record<NamedLoss, string> = {
|
|
219
|
+
invalid: "unknown citation",
|
|
220
|
+
unlinked: "unverified",
|
|
221
|
+
unplaced: "unclear citation",
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const LOSS_COPY: Record<NamedLoss, string> = {
|
|
216
225
|
invalid: "The agent cited a result Radar cannot identify.",
|
|
217
226
|
unlinked: "Radar could not verify this citation against its record.",
|
|
218
227
|
unplaced:
|
|
@@ -269,7 +278,7 @@ function LostSupport({
|
|
|
269
278
|
className="h-3 w-3 shrink-0 text-amber-500"
|
|
270
279
|
aria-hidden
|
|
271
280
|
/>
|
|
272
|
-
|
|
281
|
+
{LOSS_LABEL[reason]}
|
|
273
282
|
</span>
|
|
274
283
|
</Tooltip>
|
|
275
284
|
);
|
|
@@ -325,10 +334,13 @@ export function AnalysisStory({
|
|
|
325
334
|
}: {
|
|
326
335
|
/** Resolved once by the host, which also needs it for its own counts. */
|
|
327
336
|
placements: StoryPlacements;
|
|
328
|
-
/**
|
|
337
|
+
/**
|
|
338
|
+
* Renders the card for a placed item: `compact` when the agent placed it
|
|
339
|
+
* compact or it sits in the collapsed preview, `preview` for the latter.
|
|
340
|
+
*/
|
|
329
341
|
renderPlacement: (
|
|
330
342
|
target: StoryPlacementTarget,
|
|
331
|
-
options: { compact: boolean },
|
|
343
|
+
options: { compact: boolean; preview: boolean },
|
|
332
344
|
) => ReactNode;
|
|
333
345
|
onReveal: (target: StoryPlacementTarget) => void;
|
|
334
346
|
/** Opens a cited call's raw result in Activity when Radar renders no card for it. */
|
|
@@ -443,6 +455,7 @@ export function AnalysisStory({
|
|
|
443
455
|
>
|
|
444
456
|
{renderPlacement(resolution.target, {
|
|
445
457
|
compact: compact || segment.compact === true,
|
|
458
|
+
preview: compact,
|
|
446
459
|
})}
|
|
447
460
|
</div>
|
|
448
461
|
);
|
|
@@ -32,6 +32,7 @@ import type { InvestigationHealthSignal } from "./investigationState";
|
|
|
32
32
|
import { Badge } from "@skyhook-io/k8s-ui";
|
|
33
33
|
import { diagnosisHasStoryShape, storyPlainText } from "./investigationStory";
|
|
34
34
|
import { useDisclosureReveal } from "./useDisclosureReveal";
|
|
35
|
+
import { verdictParts } from "./verdictText";
|
|
35
36
|
import { FollowupAnswer } from "./ActivityTurn";
|
|
36
37
|
import { ApplyOutcomeCard } from "./ApplyDialog";
|
|
37
38
|
import {
|
|
@@ -40,7 +41,12 @@ import {
|
|
|
40
41
|
STEP_KIND_LABEL,
|
|
41
42
|
assessmentCopyText,
|
|
42
43
|
} from "./assessmentCopy";
|
|
43
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
AIMarkdown,
|
|
46
|
+
CopyButton,
|
|
47
|
+
SOFT_INLINE_CODE,
|
|
48
|
+
tidyFences,
|
|
49
|
+
} from "./AIMarkdown";
|
|
44
50
|
import { prettyTool } from "./toolCallLabel";
|
|
45
51
|
|
|
46
52
|
export function ResultCard({
|
|
@@ -278,6 +284,25 @@ const HEALTHY_DEFINITION: Record<
|
|
|
278
284
|
* whenever the agent listed anything, and says so when it listed nothing,
|
|
279
285
|
* because a persuasive story needs its caveats above the fold, not inside it.
|
|
280
286
|
*/
|
|
287
|
+
// A verdict is one sentence of prose with the odd `code` span. Rendering it
|
|
288
|
+
// as full markdown would turn a leading "1." or "#" into a list or heading, so
|
|
289
|
+
// only code spans are rendered, with their contents exactly as written.
|
|
290
|
+
export function VerdictText({ text }: { text: string }) {
|
|
291
|
+
return (
|
|
292
|
+
<>
|
|
293
|
+
{verdictParts(text).map((part, index) =>
|
|
294
|
+
part.code ? (
|
|
295
|
+
<code key={index} className="inline-code">
|
|
296
|
+
{part.text}
|
|
297
|
+
</code>
|
|
298
|
+
) : (
|
|
299
|
+
part.text
|
|
300
|
+
),
|
|
301
|
+
)}
|
|
302
|
+
</>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
281
306
|
function AssessmentHeadline({
|
|
282
307
|
diagnosis,
|
|
283
308
|
tone,
|
|
@@ -315,8 +340,11 @@ function AssessmentHeadline({
|
|
|
315
340
|
return (
|
|
316
341
|
<div data-assessment-headline className="space-y-2">
|
|
317
342
|
<div className="flex items-start justify-between gap-2">
|
|
318
|
-
|
|
319
|
-
|
|
343
|
+
{/* The answer is the largest text in the assessment, above its label. */}
|
|
344
|
+
<p
|
|
345
|
+
className={`text-lg font-semibold leading-snug text-theme-text-primary [overflow-wrap:anywhere] [text-wrap:pretty] ${SOFT_INLINE_CODE}`}
|
|
346
|
+
>
|
|
347
|
+
<VerdictText text={summary} />
|
|
320
348
|
</p>
|
|
321
349
|
<CopyButton
|
|
322
350
|
text={assessmentCopyText(diagnosis, {
|
|
@@ -1076,7 +1104,13 @@ function DiagnosisResult({
|
|
|
1076
1104
|
data-step-precondition
|
|
1077
1105
|
className="mb-1.5 text-[13px] leading-snug text-warning-text"
|
|
1078
1106
|
>
|
|
1079
|
-
Only if
|
|
1107
|
+
{/* The agent writes a full sentence; after "Only if" its first
|
|
1108
|
+
capital drops when it is an ordinary word ("You"), never
|
|
1109
|
+
for a name with more capitals (API, ConfigMap). */}
|
|
1110
|
+
Only if{" "}
|
|
1111
|
+
{step.precondition
|
|
1112
|
+
.replace(/^(if|when|once)\s+/i, "")
|
|
1113
|
+
.replace(/^[A-Z](?=[a-z]+\b)/, (c) => c.toLowerCase())}
|
|
1080
1114
|
</p>
|
|
1081
1115
|
) : null}
|
|
1082
1116
|
{isRec && diagnosis.recommendedReason && (
|
|
@@ -1567,10 +1601,7 @@ export function InconclusiveCard({
|
|
|
1567
1601
|
</div>
|
|
1568
1602
|
<div className="flex items-start gap-1 px-0.5 text-[11px] text-theme-text-tertiary">
|
|
1569
1603
|
<ShieldCheck className="mt-0.5 h-3 w-3 shrink-0" />
|
|
1570
|
-
<span>
|
|
1571
|
-
Try a follow-up with more context, or investigate again after
|
|
1572
|
-
addressing any errors shown in Activity.
|
|
1573
|
-
</span>
|
|
1604
|
+
<span>Try a follow-up with more context, or investigate again.</span>
|
|
1574
1605
|
</div>
|
|
1575
1606
|
<AssessmentDetails
|
|
1576
1607
|
diagnosis={diagnosis}
|
|
@@ -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: "ctx",
|
|
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
|
+
});
|