@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.
Files changed (78) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +0 -1
  3. package/src/api/diagnose.test.ts +33 -2
  4. package/src/api/diagnose.ts +93 -3
  5. package/src/api/radarFeatures.ts +1 -0
  6. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  7. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  8. package/src/components/diagnose/AgentControls.tsx +53 -6
  9. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  10. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  11. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  12. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  13. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  14. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  15. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  16. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  17. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  18. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  19. package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
  20. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  21. package/src/components/diagnose/Home.test.tsx +182 -5
  22. package/src/components/diagnose/Home.tsx +168 -36
  23. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  24. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  25. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  26. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  27. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  28. package/src/components/diagnose/InvestigationEvidenceSections.tsx +5 -1
  29. package/src/components/diagnose/InvestigationView.tsx +156 -29
  30. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  31. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  32. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  33. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  34. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  35. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  36. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  37. package/src/components/diagnose/assessmentCopy.ts +5 -0
  38. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  39. package/src/components/diagnose/investigationCase.ts +33 -1
  40. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  41. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  42. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  43. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  44. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  45. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  46. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  47. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  48. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  49. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  51. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  52. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  53. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  54. package/src/components/diagnose/investigationFocus.ts +132 -0
  55. package/src/components/diagnose/parts.test.tsx +20 -0
  56. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  57. package/src/components/diagnose/questionSuggestions.ts +150 -0
  58. package/src/components/diagnose/storyParts.test.tsx +13 -0
  59. package/src/components/diagnose/target.test.ts +143 -2
  60. package/src/components/diagnose/target.ts +109 -7
  61. package/src/components/diagnose/testdata/story-runs.json +474 -0
  62. package/src/components/diagnose/verdictText.test.tsx +87 -0
  63. package/src/components/diagnose/verdictText.ts +68 -0
  64. package/src/components/home/ClusterHealthCard.tsx +13 -39
  65. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  66. package/src/components/home/HomeAgentBlock.tsx +94 -0
  67. package/src/components/home/HomeView.tsx +5 -6
  68. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  69. package/src/components/home/RadarVersionLine.tsx +3 -28
  70. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  71. package/src/components/ui/Omnibar.tsx +47 -3
  72. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  73. package/src/components/ui/RadarOmnibar.tsx +11 -0
  74. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  75. package/src/components/whats-new/releaseNotes.ts +60 -1
  76. package/src/hooks/useAgentSignin.test.tsx +190 -0
  77. package/src/hooks/useAgentSignin.ts +160 -0
  78. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
@@ -14,19 +14,43 @@ import {
14
14
  pluralToKind,
15
15
  } from "@skyhook-io/k8s-ui/utils/navigation";
16
16
  import { parseContextName } from "../../utils/context-name";
17
- import { formatInvestigationTarget } from "./target";
17
+ import {
18
+ formatInvestigationTitle,
19
+ formatQuestionScope,
20
+ isQuestionOnly,
21
+ } from "./target";
18
22
  import { Tooltip } from "../ui/Tooltip";
23
+ import { QuestionComposer } from "./QuestionComposer";
24
+ import { plainVerdictText } from "./verdictText";
25
+
26
+ function daysBefore(date: Date, now: Date): number {
27
+ const start = (d: Date) =>
28
+ new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
29
+ return Math.round((start(now) - start(date)) / 86_400_000);
30
+ }
19
31
 
32
+ // A header per day gave sparse history one header per row; four buckets keep
33
+ // the list scannable, and rows older than yesterday carry their own date.
20
34
  function historyDay(date: Date, now: Date): string {
21
- if (date.toDateString() === now.toDateString()) return "Today";
22
- const yesterday = new Date(now);
23
- yesterday.setDate(yesterday.getDate() - 1);
24
- if (date.toDateString() === yesterday.toDateString()) return "Yesterday";
25
- return date.toLocaleDateString(undefined, {
35
+ const days = daysBefore(date, now);
36
+ if (days <= 0) return "Today";
37
+ if (days === 1) return "Yesterday";
38
+ if (days < 7) return "Previous 7 days";
39
+ return "Earlier";
40
+ }
41
+
42
+ function historyTime(date: Date, now: Date): string {
43
+ const time = date.toLocaleTimeString(undefined, {
44
+ hour: "numeric",
45
+ minute: "2-digit",
46
+ });
47
+ if (daysBefore(date, now) <= 1) return time;
48
+ const day = date.toLocaleDateString(undefined, {
26
49
  month: "short",
27
50
  day: "numeric",
28
51
  ...(date.getFullYear() === now.getFullYear() ? {} : { year: "numeric" }),
29
52
  });
53
+ return `${day} · ${time}`;
30
54
  }
31
55
 
32
56
  // Relative age makes the list easy to scan; a stable local timestamp makes two
@@ -116,13 +140,25 @@ export function statusWord(status: RunSummary["status"]): {
116
140
  }
117
141
  }
118
142
 
143
+ // The run's latest headline as plain text: rows are too small for the
144
+ // markdown a headline may carry.
119
145
  export function InvestigationHome({
120
146
  agentLabel,
121
147
  onBrowseIssues,
148
+ questions = false,
122
149
  }: {
123
150
  agentLabel: string;
124
151
  onBrowseIssues?: () => void;
152
+ /** The backend opens a run from a question; offer the composer. */
153
+ questions?: boolean;
125
154
  }) {
155
+ if (questions) {
156
+ return (
157
+ <div className="flex min-h-full w-full items-start justify-center px-4 py-10 sm:px-6">
158
+ <QuestionComposer onBrowseIssues={onBrowseIssues} />
159
+ </div>
160
+ );
161
+ }
126
162
  return (
127
163
  <div className="flex min-h-full w-full items-center justify-center px-4 py-8 sm:px-6">
128
164
  <section className="mx-auto max-w-2xl text-center">
@@ -163,6 +199,10 @@ export function RecentList({
163
199
  selectedId,
164
200
  historyDegraded = false,
165
201
  currentContext,
202
+ loaded = true,
203
+ loadFailed = false,
204
+ onRetry,
205
+ questions = false,
166
206
  }: {
167
207
  agentLabel: string;
168
208
  runs: RunSummary[];
@@ -170,6 +210,14 @@ export function RecentList({
170
210
  selectedId?: string | null;
171
211
  historyDegraded?: boolean;
172
212
  currentContext?: string;
213
+ /** The first list response has arrived; until then an empty list means
214
+ * nothing is known yet, not that there are no investigations. */
215
+ loaded?: boolean;
216
+ /** The latest list request failed. */
217
+ loadFailed?: boolean;
218
+ onRetry?: () => void;
219
+ /** Home offers the question composer beside this list. */
220
+ questions?: boolean;
173
221
  }) {
174
222
  const now = new Date();
175
223
  const contexts = new Map(
@@ -183,6 +231,7 @@ export function RecentList({
183
231
  contextsByName.set(parsed.clusterName, names);
184
232
  }
185
233
  for (const r of runs) {
234
+ if (isQuestionOnly(r)) continue;
186
235
  const kind = pluralToKind(r.kind);
187
236
  const groups = groupsByKind.get(kind) ?? new Set<string>();
188
237
  // Match Radar's resource-lane display convention: built-in API groups
@@ -224,25 +273,88 @@ export function RecentList({
224
273
  </div>
225
274
  ) : null;
226
275
 
276
+ if (runs.length === 0 && !loaded) {
277
+ return loadFailed ? (
278
+ <div className="flex flex-col items-center px-4 py-12 text-center">
279
+ <CircleAlert className="mb-3 h-6 w-6 text-theme-text-tertiary" />
280
+ <div className="text-sm font-medium text-theme-text-primary">
281
+ Couldn’t load investigations
282
+ </div>
283
+ <p className="mt-1 max-w-xs text-sm text-theme-text-tertiary">
284
+ Radar keeps retrying while this page is open.
285
+ </p>
286
+ {onRetry && (
287
+ <button
288
+ type="button"
289
+ onClick={onRetry}
290
+ className="mt-3 rounded-md border border-theme-border px-2.5 py-1 text-xs text-theme-text-secondary hover:bg-theme-hover hover:text-theme-text-primary"
291
+ >
292
+ Try again
293
+ </button>
294
+ )}
295
+ </div>
296
+ ) : (
297
+ <div
298
+ role="status"
299
+ aria-label="Loading investigations"
300
+ className="space-y-3 px-2 py-4"
301
+ >
302
+ {[0, 1, 2].map((row) => (
303
+ <div key={row} className="space-y-1.5">
304
+ <div className="h-3.5 w-2/3 animate-pulse rounded bg-theme-hover" />
305
+ <div className="h-3 w-1/3 animate-pulse rounded bg-theme-hover" />
306
+ </div>
307
+ ))}
308
+ </div>
309
+ );
310
+ }
311
+
312
+ // After the first answer a failed refresh keeps the last list, and says so.
313
+ const staleNote =
314
+ loaded && loadFailed ? (
315
+ <div
316
+ role="status"
317
+ className="mb-2 flex items-center justify-between gap-2 rounded-md border border-theme-border px-2.5 py-1.5 text-[11px] leading-snug text-theme-text-secondary"
318
+ >
319
+ <span>Couldn’t refresh investigations; showing the last list.</span>
320
+ {onRetry && (
321
+ <button
322
+ type="button"
323
+ onClick={onRetry}
324
+ className="shrink-0 font-medium text-theme-text-primary hover:underline"
325
+ >
326
+ Try again
327
+ </button>
328
+ )}
329
+ </div>
330
+ ) : null;
331
+
227
332
  if (runs.length === 0) {
228
333
  return (
229
334
  <div>
230
335
  {degradedNote}
336
+ {staleNote}
231
337
  <div className="flex flex-col items-center px-4 py-12 text-center">
232
338
  <Sparkles className="mb-3 h-7 w-7 text-accent" />
233
339
  <div className="text-sm font-medium text-theme-text-primary">
234
340
  No investigations yet
235
341
  </div>
236
- <p className="mt-1 max-w-xs text-sm text-theme-text-tertiary">
237
- Open a resource and use its{" "}
238
- <Sparkles className="inline h-3.5 w-3.5 align-text-bottom text-accent" />{" "}
239
- action to investigate it with {agentLabel} —{" "}
240
- <span className="font-medium text-theme-text-secondary">
241
- Investigate
242
- </span>{" "}
243
- a problem, or just ask about it. Investigations run in the
244
- background and are kept in your history here.
245
- </p>
342
+ {questions ? (
343
+ <p className="mt-1 max-w-xs text-sm text-theme-text-tertiary">
344
+ Investigations run in the background and are kept here.
345
+ </p>
346
+ ) : (
347
+ <p className="mt-1 max-w-xs text-sm text-theme-text-tertiary">
348
+ Open a resource and use its{" "}
349
+ <Sparkles className="inline h-3.5 w-3.5 align-text-bottom text-accent" />{" "}
350
+ action to investigate it with {agentLabel} —{" "}
351
+ <span className="font-medium text-theme-text-secondary">
352
+ Investigate
353
+ </span>{" "}
354
+ a problem, or just ask about it. Investigations run in the
355
+ background and are kept in your history here.
356
+ </p>
357
+ )}
246
358
  </div>
247
359
  </div>
248
360
  );
@@ -251,6 +363,7 @@ export function RecentList({
251
363
  return (
252
364
  <div className="space-y-4">
253
365
  {degradedNote}
366
+ {staleNote}
254
367
  <h2 className="px-2 text-sm font-medium text-theme-text-secondary">
255
368
  Investigations
256
369
  </h2>
@@ -292,12 +405,24 @@ export function RecentList({
292
405
  })
293
406
  ? `${parsed.account} · ${parsed.region}`
294
407
  : r.context;
408
+ const questionOnly = isQuestionOnly(r);
409
+ const title = formatInvestigationTitle(r);
295
410
  const readableKind = pluralToKind(r.kind);
296
- const kind =
297
- groupsByKind.get(readableKind)!.size > 1
298
- ? `${readableKind} · ${r.group || "core"}`
299
- : readableKind;
300
- const initialIssue = r.health?.topReason?.trim();
411
+ const where = questionOnly
412
+ ? formatQuestionScope(r)
413
+ : `${r.namespace ? `${r.namespace} · ` : ""}${
414
+ groupsByKind.get(readableKind)!.size > 1
415
+ ? `${readableKind} · ${r.group || "core"}`
416
+ : readableKind
417
+ }`;
418
+ const askedAbout = questionOnly ? "" : (r.question ?? "");
419
+ // The engineer's question frames a run better than the issue
420
+ // Radar flagged when it started, so a run shows one or the other.
421
+ const found = plainVerdictText(r.preview);
422
+ // What it found says more than what it started from, so the
423
+ // starting issue shows only until there is a finding.
424
+ const initialIssue =
425
+ r.question || found ? undefined : r.health?.topReason?.trim();
301
426
  const isCurrentCluster = currentContext === r.context;
302
427
  const visibility =
303
428
  r.trigger === "background"
@@ -307,7 +432,7 @@ export function RecentList({
307
432
  : r.visibility === "private"
308
433
  ? "Private"
309
434
  : "";
310
- const identity = `${formatInvestigationTarget(r)} · ${r.context}${isCurrentCluster ? " · Current cluster" : ""} · ${label}${visibility ? ` · ${visibility}` : ""} · Started ${new Date(r.createdAt).toLocaleString()}${initialIssue ? ` · Started with ${initialIssue}` : ""}`;
435
+ const identity = `${title}${found ? ` · Found: ${found}` : ""}${askedAbout ? ` · Asked: ${askedAbout}` : ""} · ${r.context}${isCurrentCluster ? " · Current cluster" : ""} · ${label}${visibility ? ` · ${visibility}` : ""} · Started ${new Date(r.createdAt).toLocaleString()}${initialIssue ? ` · Started with ${initialIssue}` : ""}`;
311
436
  return (
312
437
  <button
313
438
  key={r.id}
@@ -322,14 +447,14 @@ export function RecentList({
322
447
  >
323
448
  <span className="flex w-full items-start gap-2">
324
449
  <Tooltip
325
- content={r.name}
450
+ content={title}
326
451
  position="right"
327
452
  delay={600}
328
453
  className="pointer-events-none"
329
454
  wrapperClassName="min-w-0 flex-1"
330
455
  >
331
456
  <span className="min-w-0 flex-1 line-clamp-2 break-words text-sm font-medium leading-5 text-theme-text-primary">
332
- {r.name}
457
+ {questionOnly ? title : r.name}
333
458
  </span>
334
459
  </Tooltip>
335
460
  {(Icon || short) && (
@@ -346,19 +471,18 @@ export function RecentList({
346
471
  </span>
347
472
  )}
348
473
  </span>
349
- <span className="flex w-full items-baseline gap-2 text-xs leading-4 text-theme-text-secondary">
350
- <span className="min-w-0 flex-1 truncate">
351
- {r.namespace ? `${r.namespace} · ` : ""}
352
- {kind}
474
+ {found && (
475
+ <span className="line-clamp-2 w-full break-words text-xs leading-4 text-theme-text-secondary">
476
+ {found}
353
477
  </span>
478
+ )}
479
+ <span className="flex w-full items-baseline gap-2 text-xs leading-4 text-theme-text-tertiary">
480
+ <span className="min-w-0 flex-1 truncate">{where}</span>
354
481
  <time
355
482
  dateTime={r.createdAt}
356
483
  className="shrink-0 tabular-nums text-theme-text-tertiary"
357
484
  >
358
- {new Date(r.createdAt).toLocaleTimeString(undefined, {
359
- hour: "numeric",
360
- minute: "2-digit",
361
- })}
485
+ {historyTime(new Date(r.createdAt), now)}
362
486
  </time>
363
487
  </span>
364
488
  <Tooltip
@@ -374,9 +498,12 @@ export function RecentList({
374
498
  ? `Current cluster: ${parsed.clusterName}`
375
499
  : `Cluster: ${parsed.clusterName}`
376
500
  }
377
- className={`flex w-full items-center gap-1 text-xs leading-4 ${isCurrentCluster ? "text-accent-text" : "text-theme-text-tertiary"}`}
501
+ className="flex w-full items-center gap-1 text-xs leading-4 text-theme-text-tertiary"
378
502
  >
379
- <Server className="h-3 w-3 shrink-0" aria-hidden />
503
+ <Server
504
+ className={`h-3 w-3 shrink-0 ${isCurrentCluster ? "text-accent" : ""}`}
505
+ aria-hidden
506
+ />
380
507
  <span className="min-w-0 flex-1 truncate">
381
508
  {parsed.clusterName}
382
509
  </span>
@@ -388,12 +515,17 @@ export function RecentList({
388
515
  </span>
389
516
  </Tooltip>
390
517
  {collision && qualifier !== parsed.clusterName && (
391
- <span className="w-full break-words text-xs leading-4 text-theme-text-secondary">
518
+ <span className="w-full break-words text-xs leading-4 text-theme-text-tertiary">
392
519
  {qualifier}
393
520
  </span>
394
521
  )}
522
+ {askedAbout && (
523
+ <span className="line-clamp-1 w-full text-xs leading-4 text-theme-text-tertiary">
524
+ Asked: {askedAbout}
525
+ </span>
526
+ )}
395
527
  {initialIssue && (
396
- <span className="line-clamp-1 w-full text-xs leading-4 text-theme-text-secondary">
528
+ <span className="line-clamp-1 w-full text-xs leading-4 text-theme-text-tertiary">
397
529
  Started with {initialIssue}
398
530
  </span>
399
531
  )}
@@ -0,0 +1,246 @@
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
+ import type { RunSummary } from "../../api/diagnose";
6
+ import {
7
+ capacityCluster,
8
+ InvestigationCapacityNotice,
9
+ runsHoldingSlots,
10
+ } from "./InvestigationCapacityNotice";
11
+
12
+ function run(
13
+ id: string,
14
+ name: string,
15
+ status: string,
16
+ createdAt: string,
17
+ ): RunSummary {
18
+ return {
19
+ id,
20
+ kind: "Deployment",
21
+ group: "apps",
22
+ namespace: "prod",
23
+ name,
24
+ context: "test",
25
+ profile: "safeguarded",
26
+ status,
27
+ createdAt,
28
+ updatedAt: createdAt,
29
+ } as RunSummary;
30
+ }
31
+
32
+ const capacity = {
33
+ target: { kind: "Pod", group: "", namespace: "shop", name: "cart-0" },
34
+ limit: 3,
35
+ };
36
+
37
+ const threeRunning = [
38
+ run("c", "checkout", "running", "2026-10-28T10:04:00Z"),
39
+ run("a", "api", "running", "2026-10-28T10:00:00Z"),
40
+ run("done", "old", "completed", "2026-10-28T09:00:00Z"),
41
+ run("b", "billing", "running", "2026-10-28T10:02:00Z"),
42
+ ];
43
+
44
+ describe("runsHoldingSlots", () => {
45
+ it("keeps only live runs, longest-running first", () => {
46
+ expect(runsHoldingSlots(threeRunning).map((r) => r.id)).toEqual([
47
+ "a",
48
+ "b",
49
+ "c",
50
+ ]);
51
+ });
52
+ });
53
+
54
+ describe("capacityCluster", () => {
55
+ it("retries only in the cluster the start was refused in", () => {
56
+ expect(capacityCluster("dev", "dev")).toBe("same");
57
+ expect(capacityCluster("dev", "prod")).toBe("changed");
58
+ // Contexts reloading after a switch: not yet known to be the same.
59
+ expect(capacityCluster("dev", undefined)).toBe("unknown");
60
+ expect(capacityCluster(undefined, "prod")).toBe("same");
61
+ });
62
+ });
63
+
64
+ describe("InvestigationCapacityNotice", () => {
65
+ let container: HTMLDivElement;
66
+ let root: Root;
67
+ const handlers = {
68
+ onOpenRun: vi.fn(),
69
+ onStop: vi.fn(async () => {}),
70
+ onStart: vi.fn(),
71
+ onDismiss: vi.fn(),
72
+ };
73
+
74
+ beforeEach(() => {
75
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
76
+ vi.useFakeTimers();
77
+ vi.setSystemTime(new Date("2026-10-28T10:05:00Z"));
78
+ container = document.createElement("div");
79
+ document.body.appendChild(container);
80
+ root = createRoot(container);
81
+ Object.values(handlers).forEach((h) => h.mockClear());
82
+ });
83
+ afterEach(async () => {
84
+ await act(async () => root.unmount());
85
+ container.remove();
86
+ vi.useRealTimers();
87
+ });
88
+
89
+ const render = (
90
+ runs: RunSummary[],
91
+ {
92
+ runsKnown = true,
93
+ cluster = "same" as "same" | "changed" | "unknown",
94
+ } = {},
95
+ ) =>
96
+ act(async () =>
97
+ root.render(
98
+ <InvestigationCapacityNotice
99
+ capacity={capacity}
100
+ runs={runs}
101
+ runsKnown={runsKnown}
102
+ cluster={cluster}
103
+ {...handlers}
104
+ />,
105
+ ),
106
+ );
107
+ const button = (text: string) =>
108
+ [...container.querySelectorAll("button")].find(
109
+ (b) => b.textContent === text || b.getAttribute("aria-label") === text,
110
+ )!;
111
+
112
+ it("says how many are running and lists each with its elapsed time", async () => {
113
+ await render(threeRunning);
114
+ expect(container.textContent).toContain(
115
+ "3 investigations are already running",
116
+ );
117
+ expect(container.textContent).toContain(
118
+ "Stop one to start Pod shop/cart-0",
119
+ );
120
+ const rows = [...container.querySelectorAll("li")].map(
121
+ (li) => li.textContent,
122
+ );
123
+ expect(rows).toHaveLength(3);
124
+ expect(rows[0]).toContain("Deployment prod/api");
125
+ expect(rows[0]).toContain("Started 5m ago");
126
+ expect(rows[2]).toContain("Started 1m ago");
127
+ expect(button("Start investigation").disabled).toBe(true);
128
+ });
129
+
130
+ it("names question-only runs and starts by their question", async () => {
131
+ const asking = {
132
+ ...run("q", "", "running", "2026-10-28T10:03:00Z"),
133
+ kind: "",
134
+ group: "",
135
+ namespace: "",
136
+ question: "checkout is slow",
137
+ } as RunSummary;
138
+ await act(async () =>
139
+ root.render(
140
+ <InvestigationCapacityNotice
141
+ capacity={{
142
+ target: {
143
+ kind: "",
144
+ group: "",
145
+ namespace: "",
146
+ name: "",
147
+ question: "why is web timing out",
148
+ },
149
+ limit: 3,
150
+ }}
151
+ runs={[...threeRunning.slice(0, 2), asking]}
152
+ runsKnown
153
+ cluster="same"
154
+ {...handlers}
155
+ />,
156
+ ),
157
+ );
158
+ expect(container.textContent).toContain(
159
+ "Stop one to start “why is web timing out”",
160
+ );
161
+ expect(container.textContent).toContain("checkout is slow");
162
+ expect(button("Stop checkout is slow")).toBeDefined();
163
+ });
164
+
165
+ it("opens and stops the run the user picks", async () => {
166
+ handlers.onStop.mockImplementationOnce(() => new Promise<void>(() => {}));
167
+ await render(threeRunning);
168
+ await act(async () => button("Open").click());
169
+ expect(handlers.onOpenRun).toHaveBeenCalledWith("a");
170
+ await act(async () => button("Stop Deployment prod/billing").click());
171
+ expect(handlers.onStop).toHaveBeenCalledWith("b");
172
+ expect(button("Stop Deployment prod/billing").disabled).toBe(true);
173
+ expect(container.textContent).toContain("Stopping…");
174
+ });
175
+
176
+ it("offers the same start once a slot frees, without starting it itself", async () => {
177
+ await render(threeRunning);
178
+ await render(threeRunning.filter((r) => r.id !== "b"));
179
+ expect(container.textContent).toContain("A slot is free");
180
+ expect(handlers.onStart).not.toHaveBeenCalled();
181
+ const start = button("Start investigation");
182
+ expect(start.disabled).toBe(false);
183
+ await act(async () => start.click());
184
+ expect(handlers.onStart).toHaveBeenCalledTimes(1);
185
+ });
186
+
187
+ it("lets a stop that didn't take be tried again", async () => {
188
+ let fail!: () => void;
189
+ handlers.onStop.mockImplementationOnce(
190
+ () =>
191
+ new Promise<void>((_, reject) => (fail = () => reject(new Error("x")))),
192
+ );
193
+ await render(threeRunning);
194
+ const stop = () => button("Stop Deployment prod/api");
195
+ await act(async () => stop().click());
196
+ expect(stop().disabled).toBe(true);
197
+ await act(async () => fail());
198
+ expect(stop().disabled).toBe(false);
199
+ expect(container.textContent).not.toContain("Stopping…");
200
+ });
201
+
202
+ it("claims no free slot before the running list is known", async () => {
203
+ await render([], { runsKnown: false });
204
+ expect(container.textContent).toContain(
205
+ "3 investigations are already running",
206
+ );
207
+ expect(container.textContent).toContain(
208
+ "Loading the running investigations",
209
+ );
210
+ // The server decides; the button must not dead-end on missing data.
211
+ expect(button("Start investigation").disabled).toBe(false);
212
+ });
213
+
214
+ it("won't retry a start after the cluster changed", async () => {
215
+ await render(threeRunning, { cluster: "changed" });
216
+ expect(container.textContent).toContain("The cluster changed");
217
+ expect(button("Start investigation")).toBeUndefined();
218
+ await act(async () => button("Dismiss").click());
219
+ expect(handlers.onDismiss).toHaveBeenCalledTimes(1);
220
+ });
221
+
222
+ it("holds the retry until the current cluster is confirmed", async () => {
223
+ await render(
224
+ threeRunning.filter((r) => r.id !== "b"),
225
+ {
226
+ cluster: "unknown",
227
+ },
228
+ );
229
+ expect(button("Start investigation").disabled).toBe(true);
230
+ });
231
+
232
+ it("says when a stop didn't take", async () => {
233
+ await render(threeRunning);
234
+ await act(async () => button("Stop Deployment prod/api").click());
235
+ // The refreshed list still shows it running.
236
+ await render([...threeRunning]);
237
+ expect(container.textContent).toContain("Radar couldn’t stop it");
238
+ expect(button("Stop Deployment prod/api").disabled).toBe(false);
239
+ });
240
+
241
+ it("cancels the pending start", async () => {
242
+ await render(threeRunning);
243
+ await act(async () => button("Cancel").click());
244
+ expect(handlers.onDismiss).toHaveBeenCalledTimes(1);
245
+ });
246
+ });