@marimo-team/islands 0.26.1-dev83 → 0.26.1-dev84

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 (80) hide show
  1. package/dist/{ConnectedDataExplorerComponent-yQVBQBUW.js → ConnectedDataExplorerComponent-CO9uVewH.js} +12 -12
  2. package/dist/{ErrorBoundary-DqCVIA2k.js → ErrorBoundary-T8CwNebX.js} +18 -18
  3. package/dist/{abnfDiagram-VCTEODGH-Ck_lXwQR.js → abnfDiagram-VCTEODGH-Ba0MYVW8.js} +2 -2
  4. package/dist/{any-language-editor-Cx4idbgX.js → any-language-editor-BNe8do3C.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-XeVhic7Z.js → architectureDiagram-5GKGNRK7-7MqAehef.js} +1 -1
  6. package/dist/{assertNever-473SFxLt.js → assertNever-5vhHGKOK.js} +2 -2
  7. package/dist/{chat-ui-D1mRz9h6.js → chat-ui-CjZbdpzb.js} +18 -18
  8. package/dist/{check-DmTIavbZ.js → check-DUIc04aK.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-DdQni67K.js → chunk-IMKFNOWR-CAWA0HGB.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-BdK-vMct.js → chunk-SHT3W25Y-BIwVQjG5.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-cpFZk4Ca.js → chunk-SVP7TREG-Cux251TB.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-DDgQFRgT.js → chunk-TICWLB2K-DJVQ6khO.js} +1 -1
  13. package/dist/{classDiagram-ZZMXUADV-DeojX9X4.js → classDiagram-ZZMXUADV-Cwve77ev.js} +2 -2
  14. package/dist/{classDiagram-v2-VYDZK3BY-DPfTAiQ6.js → classDiagram-v2-VYDZK3BY-BAeHKXmD.js} +2 -2
  15. package/dist/{code-visibility-Bg6LdTgJ.js → code-visibility-BBgRhs2A.js} +17 -17
  16. package/dist/{common-BXohsH8R.js → common-BF30ifb8.js} +3138 -3130
  17. package/dist/{config-D-lhQq-h.js → config-CShkLThS.js} +35 -33
  18. package/dist/{copy-icon-DuxRkh7T.js → copy-icon-CmNLxT5_.js} +2 -2
  19. package/dist/{createReducer-D3pBhIVD.js → createReducer-BUQhgLOI.js} +5 -5
  20. package/dist/{cynefinDiagram-5FMLGOSQ-DyY9TvuI.js → cynefinDiagram-5FMLGOSQ-t4eEkPJh.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-BPCOgtKg.js → dagre-GXQ25YYZ-IuZuI28B.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-A_0tSQlT.js → data-grid-overlay-editor-ChntsIBb.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-KaF-C6kd.js → diagram-S7CK7UJ4-D8R5Q_ok.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-DkeqoSvK.js → diagram-UQ7AKVKN-BGuMPsr-.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-DExolTAf.js → diagram-VX7I27RA-BkTtpO8P.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-BioFuBF3.js → diagram-Z3DM3KII-C0__Mxfm.js} +1 -1
  27. package/dist/{dialog-CvyFEwby.js → dialog-BvjfalZ9.js} +30 -30
  28. package/dist/{dropdown-menu-BiXHfje7.js → dropdown-menu-D0DeN-aL.js} +637 -637
  29. package/dist/{ebnfDiagram-PWID7BFC-BSb9k1ed.js → ebnfDiagram-PWID7BFC-CSESPZoz.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-PWA30a_r.js → erDiagram-RLTQ6QDP-DsDTtabH.js} +1 -1
  31. package/dist/{error-banner-B9HQMSaH.js → error-banner-CXLjTW24.js} +60 -65
  32. package/dist/{error-entries-P6Qpq6wP.js → error-entries-CsXAdy1j.js} +112 -112
  33. package/dist/{feedback-button-DSC9SNgL.js → feedback-button-nmOvfn22.js} +7 -7
  34. package/dist/{flowDiagram-HODETNUW-BPtD__Zz.js → flowDiagram-HODETNUW-qxDPYbfV.js} +2 -2
  35. package/dist/{formats-BF95BoCT.js → formats-BRDSQgKN.js} +1 -1
  36. package/dist/{glide-data-editor-NVoO9114.js → glide-data-editor-SkR9hqZZ.js} +11 -11
  37. package/dist/{glide-utils-iHKKQPJ8.js → glide-utils-CD8BaFTm.js} +2 -2
  38. package/dist/{globals-L7tZEIcx.js → globals-BjiU5aEs.js} +3 -3
  39. package/dist/{html-to-image-DhrFZL7t.js → html-to-image-CwpapHNl.js} +1059 -1059
  40. package/dist/{infoDiagram-27XIBGKW-SJuilBEE.js → infoDiagram-27XIBGKW-B5hq8RM_.js} +1 -1
  41. package/dist/{ishikawaDiagram-5VMMS53U-DjzyxMr8.js → ishikawaDiagram-5VMMS53U-DkHc_9ET.js} +1 -1
  42. package/dist/{kanban-definition-UXKFOSKX-D2_qopGt.js → kanban-definition-UXKFOSKX-CqkTFXmU.js} +1 -1
  43. package/dist/main.js +423 -423
  44. package/dist/{mermaid-DcowNmCx.js → mermaid-pmVHDUQA.js} +34 -34
  45. package/dist/{mindmap-definition-YA3MSWOX-pEra10M0.js → mindmap-definition-YA3MSWOX-D6cNa__z.js} +1 -1
  46. package/dist/{number-overlay-editor-CjeU_gt8.js → number-overlay-editor-GjrMTG9X.js} +1 -1
  47. package/dist/{pegDiagram-XKGWAZYB-CHOPKVOf.js → pegDiagram-XKGWAZYB-CmWJX_s1.js} +2 -2
  48. package/dist/{pencil-FAv6JUvp.js → pencil-CxMgOe04.js} +1 -1
  49. package/dist/{pieDiagram-E7YTZNPT-yGDhsyEN.js → pieDiagram-E7YTZNPT-CAQAxHah.js} +1 -1
  50. package/dist/{process-output-CBPqVQBu.js → process-output-ztSj9cDn.js} +4 -4
  51. package/dist/{railroadDiagram-O6MQD6OU-CeKEPdyc.js → railroadDiagram-O6MQD6OU-jlSsiQg3.js} +2 -2
  52. package/dist/{requirementDiagram-BXWQKSXE-DSAbAzKe.js → requirementDiagram-BXWQKSXE-DkDjfPhn.js} +1 -1
  53. package/dist/{reveal-component-D8H5fBkv.js → reveal-component-BrZbx6s7.js} +11 -11
  54. package/dist/{select-BszV-bbI.js → select-CEnB18uc.js} +350 -350
  55. package/dist/{sequenceDiagram-WJ2MYXX4-DVhWj_9H.js → sequenceDiagram-WJ2MYXX4-DLywsGCW.js} +1 -1
  56. package/dist/{spec-CRfw-lOm.js → spec-Dz-Avv1m.js} +4 -4
  57. package/dist/{stateDiagram-D77RDMKH-CDQ2MltG.js → stateDiagram-D77RDMKH-DUmlKwYU.js} +2 -2
  58. package/dist/{stateDiagram-v2-MP3YSRHH-BQmvwBaz.js → stateDiagram-v2-MP3YSRHH-D646KiXs.js} +2 -2
  59. package/dist/{static-state-BtDNJuc2.js → static-state-DhVFm8Z6.js} +6 -6
  60. package/dist/{swimlanes-42K2YHIH-DLOUTCEL.js → swimlanes-42K2YHIH-L7B1GphF.js} +1 -1
  61. package/dist/{swimlanesDiagram-VR7AAH4N-BVKrkNJ6.js → swimlanesDiagram-VR7AAH4N-DEu2wxtC.js} +2 -2
  62. package/dist/{timeline-definition-24CTP7MA-Cb2JoCSd.js → timeline-definition-24CTP7MA-DDPyx1yG.js} +1 -1
  63. package/dist/{toast-QsOAIPfq.js → toast-BTjH6fIf.js} +187 -187
  64. package/dist/{tooltip-BQZ-Bm6h.js → tooltip-DyLdBIM4.js} +73 -73
  65. package/dist/{use-restore-focus-DT1TZACX.js → use-restore-focus-DJ_-uSn_.js} +1340 -1339
  66. package/dist/{useDateFormatter-D3gyMY-g.js → useDateFormatter-HpKD0jEC.js} +2 -2
  67. package/dist/{useDeepCompareMemoize-CO6rO5Mq.js → useDeepCompareMemoize-CHx-NxMl.js} +1 -1
  68. package/dist/{useLifecycle-C9UTzCY8.js → useLifecycle-tPpAt-OE.js} +1 -1
  69. package/dist/{vega-component-i5lZ23n7.js → vega-component-BxJFcD2G.js} +6 -6
  70. package/dist/{vennDiagram-4TSXK5OY-Cm3EcCcP.js → vennDiagram-4TSXK5OY-CRwWeb7g.js} +1 -1
  71. package/dist/{wardleyDiagram-VM6X3IG4-DjlUs2CC.js → wardleyDiagram-VM6X3IG4-DVlG9eoq.js} +1 -1
  72. package/dist/{xychartDiagram-S5SC5T6Z-DxNDul9l.js → xychartDiagram-S5SC5T6Z-CM32AISp.js} +1 -1
  73. package/package.json +1 -1
  74. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +240 -93
  75. package/src/components/editor/errors/send-error-report-button.tsx +139 -41
  76. package/src/core/notebook/replica/__tests__/fixtures.ts +1 -0
  77. package/src/core/notebook/replica/backend.ts +4 -1
  78. package/src/core/session/active-notebook.ts +6 -0
  79. package/src/core/transports/__tests__/static.test.ts +21 -18
  80. package/src/core/transports/static.ts +1 -0
@@ -1,7 +1,7 @@
1
1
  import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { t } from "./react-Bgs_wQh3.js";
3
- import { h as n } from "./tooltip-BQZ-Bm6h.js";
4
- import { C as r } from "./select-BszV-bbI.js";
3
+ import { h as n } from "./tooltip-DyLdBIM4.js";
4
+ import { C as r } from "./select-CEnB18uc.js";
5
5
  var i = n("chart-pie", [["path", {
6
6
  d: "M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",
7
7
  key: "pzmjnu"
@@ -1,6 +1,6 @@
1
1
  import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { t } from "./react-Bgs_wQh3.js";
3
- import { Rt as n } from "./use-restore-focus-DT1TZACX.js";
3
+ import { Bt as n } from "./use-restore-focus-DJ_-uSn_.js";
4
4
  //#region src/utils/semaphore.ts
5
5
  var r = class {
6
6
  maxPermits;
@@ -2,7 +2,7 @@ import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { h as t, i as n } from "./button-Z2R2272J.js";
3
3
  import { t as r } from "./react-Bgs_wQh3.js";
4
4
  import { t as i } from "./compiler-runtime-C5KHtL5D.js";
5
- import { h as a } from "./tooltip-BQZ-Bm6h.js";
5
+ import { h as a } from "./tooltip-DyLdBIM4.js";
6
6
  import { t as o } from "./jsx-runtime-D8btoEHk.js";
7
7
  var s = a("calendar", [
8
8
  ["path", {
@@ -2,18 +2,18 @@ import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { g as t, h as n, m as r, s as i } from "./button-Z2R2272J.js";
3
3
  import { t as a } from "./react-Bgs_wQh3.js";
4
4
  import { t as o } from "./compiler-runtime-C5KHtL5D.js";
5
- import { t as s } from "./tooltip-BQZ-Bm6h.js";
6
- import { l as c, t as l } from "./config-D-lhQq-h.js";
5
+ import { t as s } from "./tooltip-DyLdBIM4.js";
6
+ import { c, t as l } from "./config-CShkLThS.js";
7
7
  import { t as u } from "./jsx-runtime-D8btoEHk.js";
8
- import { d } from "./use-restore-focus-DT1TZACX.js";
9
- import { n as f } from "./error-banner-B9HQMSaH.js";
8
+ import { d } from "./use-restore-focus-DJ_-uSn_.js";
9
+ import { n as f } from "./error-banner-CXLjTW24.js";
10
10
  import { t as p } from "./debounce-DrhhziJv.js";
11
11
  import { t as ee } from "./objects-DCmMvZtn.js";
12
12
  import { t as te } from "./useEvent-BoN7U38T.js";
13
13
  import { a as m, t as h } from "./arrays-DoQ-AILx.js";
14
- import { a as ne, i as re, n as ie, t as g } from "./formats-BF95BoCT.js";
14
+ import { a as ne, i as re, n as ie, t as g } from "./formats-BRDSQgKN.js";
15
15
  import { t as ae } from "./useAsyncData-P5-Oovhq.js";
16
- import { n as _, t as oe } from "./useDeepCompareMemoize-CO6rO5Mq.js";
16
+ import { n as _, t as oe } from "./useDeepCompareMemoize-CHx-NxMl.js";
17
17
  import { W as se, n as ce } from "./vega-loader.browser-Co9gYE8Z.js";
18
18
  import { t as le } from "./react-vega-CGgQEf0O.js";
19
19
  import { a as ue, n as de } from "./loader-qPmiRXZd.js";
@@ -3,7 +3,7 @@ import { t } from "./src-D5uZaZib.js";
3
3
  import { n } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
4
4
  import { $ as r, H as i, K as a, U as o, a as s, b as c, c as l, et as u, f as d, nt as f, tt as p, v as m, w as h, y as g } from "./chunk-DU6HZSFF-4SDIhUTY.js";
5
5
  import { t as _ } from "./rough.esm-CtV9AnV1.js";
6
- import { p as v } from "./mermaid-DcowNmCx.js";
6
+ import { p as v } from "./mermaid-pmVHDUQA.js";
7
7
  //#region ../node_modules/.pnpm/khroma@2.1.0/node_modules/khroma/dist/methods/transparentize.js
8
8
  var y = (e, t) => p(e, "a", -t), b = 1e-10;
9
9
  function x(e, t) {
@@ -2,7 +2,7 @@ import { i as e } from "./chunk-75Z2AOVW-76L6My3P.js";
2
2
  import { n as t } from "./src-D5uZaZib.js";
3
3
  import { n } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
4
4
  import { D as r, H as i, K as a, U as o, a as s, b as c, c as l, v as u, w as d, x as f, y as p } from "./chunk-DU6HZSFF-4SDIhUTY.js";
5
- import { p as m } from "./mermaid-DcowNmCx.js";
5
+ import { p as m } from "./mermaid-pmVHDUQA.js";
6
6
  import { n as h } from "./mermaid-parser.core-DtOnl7m4.js";
7
7
  import { t as g } from "./chunk-JWPE2WC7-DJvv1t8U.js";
8
8
  //#region ../node_modules/.pnpm/mermaid@11.17.2/node_modules/mermaid/dist/chunks/mermaid.core/wardleyDiagram-VM6X3IG4.mjs
@@ -9,7 +9,7 @@ import { n as s } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
9
9
  import { D as c, H as l, K as u, U as d, a as f, b as p, c as m, f as h, v as g, w as _, y as v, z as y } from "./chunk-DU6HZSFF-4SDIhUTY.js";
10
10
  import "./chunk-PWAF6VOD-CRu_RGP2.js";
11
11
  import { t as b } from "./chunk-GMAD6QVW-BJGF8QZL.js";
12
- import { p as x } from "./mermaid-DcowNmCx.js";
12
+ import { p as x } from "./mermaid-pmVHDUQA.js";
13
13
  //#region ../node_modules/.pnpm/d3-scale@4.0.2/node_modules/d3-scale/src/band.js
14
14
  function S() {
15
15
  var e = t().unknown(void 0), r = e.domain, i = e.range, o = 0, s = 1, c, l, u = !1, d = 0, f = 0, p = .5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.26.1-dev83",
3
+ "version": "0.26.1-dev84",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -10,7 +10,7 @@ import {
10
10
  } from "@testing-library/react";
11
11
  import { atom, createStore, Provider } from "jotai";
12
12
  import type React from "react";
13
- import { beforeEach, describe, expect, it, vi } from "vitest";
13
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14
14
  import { MockExecutions } from "@/__mocks__/executions";
15
15
  import { MockNotebook } from "@/__mocks__/notebook";
16
16
  import { cellId } from "@/__tests__/branded";
@@ -33,38 +33,21 @@ import {
33
33
  withCells,
34
34
  } from "@/core/notebook/document/__tests__/fixtures";
35
35
  import type { MarimoError } from "@/core/kernel/messages";
36
- import {
37
- type StableSessionId,
38
- stableSessionIdAtom,
39
- } from "@/core/kernel/session";
40
- import { API } from "@/core/network/api";
41
- import { connectionAtom } from "@/core/network/connection";
42
- import { ConnectionState } from "@/core/session/types";
36
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
37
+ import { createEditorBackend } from "@/core/session/backend";
43
38
  import { Deferred } from "@/utils/Deferred";
44
- import { HTTPError } from "@/utils/errors";
45
39
  import { MarimoErrorOutput } from "../../output/MarimoErrorOutput";
46
40
  import { MarimoTracebackOutput } from "../../output/MarimoTracebackOutput";
47
41
  import { OutputRenderer } from "../../Output";
48
42
  import { SendErrorReportButton } from "../send-error-report-button";
49
43
 
50
44
  vi.mock("@/components/ui/use-toast", () => ({ toast: vi.fn() }));
51
- vi.mock("@/core/network/api", () => ({ API: { post: vi.fn() } }));
52
45
  vi.mock("@/components/editor/chrome/wrapper/useOpenAiAssistant", () => ({
53
46
  useOpenAiAssistant: () => vi.fn(),
54
47
  }));
55
48
 
56
49
  const CELL_ID = cellId("test-cell");
57
- const STABLE_ID = "stable/test" as StableSessionId;
58
- // Hoisted with the module mock below, which reads it as modules load.
59
- const { attachmentsAtom } = await vi.hoisted(async () => {
60
- const { atom } = await import("jotai");
61
- return { attachmentsAtom: atom<Attachment[]>([]) };
62
- });
63
- vi.mock("@/core/session/active-notebook", async (importOriginal) => ({
64
- ...(await importOriginal<typeof import("@/core/session/active-notebook")>()),
65
- // Writable, so the execution mock can give the replica results.
66
- activeNotebookReplicaAtom: atom({ attachmentsAtom }),
67
- }));
50
+ const attachmentsAtom = atom<Attachment[]>([]);
68
51
 
69
52
  const AGENT: Attachment = {
70
53
  id: "a1",
@@ -74,7 +57,15 @@ const AGENT: Attachment = {
74
57
  notebook_id: "nb-test",
75
58
  identity: "pi-thread",
76
59
  };
77
- const ROUTE = "/pair/notebooks/stable%2Ftest/messages";
60
+ const OTHER_AGENT: Attachment = {
61
+ ...AGENT,
62
+ id: "a2",
63
+ identity: "claude-thread",
64
+ name: "Claude Code",
65
+ };
66
+ const NOTEBOOK_URL = "http://localhost/prefix/api/marimo/v1/notebooks/nb-test";
67
+ const fetch =
68
+ vi.fn<(url: RequestInfo | URL, init?: RequestInit) => Promise<Response>>();
78
69
  const MESSAGE = "df is not defined";
79
70
  const CODE = "df.head()";
80
71
  const REPORT: CellOutputMessage<ErrorMessageOutput> = {
@@ -100,35 +91,85 @@ const ERRORS: MarimoError[] = [
100
91
  function renderButton({
101
92
  preview = true,
102
93
  attachments = [AGENT],
103
- stableId = STABLE_ID,
94
+ canEmit = true,
104
95
  content = <SendErrorReportButton getContent={() => REPORT} />,
105
96
  }: {
106
97
  preview?: boolean;
107
98
  attachments?: Attachment[];
108
- stableId?: StableSessionId | null;
99
+ canEmit?: boolean;
109
100
  content?: React.ReactNode;
110
101
  } = {}) {
111
102
  const store = createStore();
112
- store.set(connectionAtom, { state: ConnectionState.OPEN });
113
103
  store.set(pairConfigAtom, { ...PAIR_CONFIG, hostEnabled: preview });
114
104
  store.set(attachmentsAtom, attachments);
115
- store.set(stableSessionIdAtom, stableId);
105
+ const backend = createEditorBackend({
106
+ static: false,
107
+ snapshot: null,
108
+ transportType: "websocket",
109
+ url: () => "ws://localhost/ws",
110
+ headers: () => ({ "Marimo-Server-Token": "test-token" }),
111
+ notebookUrl: (id) => new URL(id, new URL(".", NOTEBOOK_URL)),
112
+ waitUntilReady: async () => undefined,
113
+ checkHealth: async () => true,
114
+ });
115
+ const seed = (...args: Parameters<typeof MockExecutions.seed>) => {
116
+ const replica = MockExecutions.seed(...args);
117
+ store.set(replica.backendAtom, backend);
118
+ store.set(replica.notebookAtom, {
119
+ ...MockExecutions.notebook("nb-test"),
120
+ operations: canEmit ? ["notebook.emit"] : [],
121
+ });
122
+ store.set(activeNotebookReplicaAtom, { ...replica, attachmentsAtom });
123
+ return replica;
124
+ };
125
+ seed(store, []);
116
126
  const wrapper = ({ children }: { children: React.ReactNode }) => (
117
127
  <Provider store={store}>
118
128
  <TooltipProvider>{children}</TooltipProvider>
119
129
  </Provider>
120
130
  );
121
- return { store, ...render(content, { wrapper }) };
131
+ return { store, seed, ...render(content, { wrapper }) };
122
132
  }
123
133
 
124
134
  function send() {
125
135
  fireEvent.click(screen.getByRole("button", { name: "Send error to agent" }));
126
136
  }
127
137
 
138
+ function openRecipients() {
139
+ fireEvent.keyDown(
140
+ screen.getByRole("button", { name: "Send error to agent" }),
141
+ {
142
+ key: "Enter",
143
+ },
144
+ );
145
+ }
146
+
147
+ async function lastRequest() {
148
+ const [url, init] = await waitFor(() => {
149
+ expect(fetch).toHaveBeenCalled();
150
+ return fetch.mock.lastCall!;
151
+ });
152
+ return new Request(url, init);
153
+ }
154
+
155
+ async function sentEvent() {
156
+ return (await lastRequest()).json();
157
+ }
158
+
159
+ function errorEvent(message: unknown, to: string | null = AGENT.identity) {
160
+ return {
161
+ type: "marimo.agents.message.v1",
162
+ data: { message, to, sender: "marimo error report" },
163
+ };
164
+ }
165
+
128
166
  describe("SendErrorReportButton", () => {
129
167
  beforeEach(() => {
130
168
  vi.clearAllMocks();
131
- vi.mocked(API.post).mockResolvedValue("");
169
+ vi.stubGlobal("fetch", fetch);
170
+ fetch
171
+ .mockReset()
172
+ .mockImplementation(async () => new Response(null, { status: 204 }));
132
173
  vi.mocked(toast).mockReturnValue({
133
174
  id: "notice",
134
175
  dismiss: vi.fn(),
@@ -136,6 +177,7 @@ describe("SendErrorReportButton", () => {
136
177
  upsert: vi.fn(),
137
178
  });
138
179
  });
180
+ afterEach(() => vi.unstubAllGlobals());
139
181
 
140
182
  it("hides when host is disabled without building content", () => {
141
183
  const getContent = vi.fn(() => REPORT);
@@ -150,76 +192,180 @@ describe("SendErrorReportButton", () => {
150
192
 
151
193
  it.each([
152
194
  { attachments: [] },
153
- { attachments: [{ ...AGENT, kind: "client" as const }] },
154
- { stableId: null },
155
- ])("disables sending without an agent or stable ID: %j", (options) => {
156
- renderButton(options);
157
- expect(screen.getByRole("button")).toBeDisabled();
158
- send();
159
- expect(API.post).not.toHaveBeenCalled();
195
+ { attachments: [{ ...AGENT, kind: "client" }] },
196
+ {
197
+ attachments: [
198
+ { ...AGENT, identity: null },
199
+ { ...AGENT, id: "a2", identity: "" },
200
+ ],
201
+ },
202
+ { canEmit: false },
203
+ ])("hides without a recipient or emit capability: %j", (options) => {
204
+ const getContent = vi.fn(() => REPORT);
205
+ renderButton({
206
+ ...options,
207
+ content: <SendErrorReportButton getContent={getContent} />,
208
+ });
209
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
210
+ expect(getContent).not.toHaveBeenCalled();
211
+ expect(fetch).not.toHaveBeenCalled();
160
212
  });
161
213
 
162
- it("builds content on click and sends it to all agents", async () => {
214
+ it("publishes to the selected identity after removing duplicate and anonymous attachments", async () => {
163
215
  const getContent = vi.fn(() => REPORT);
164
216
  renderButton({
165
- attachments: [AGENT, { ...AGENT, id: "a2", name: "Claude Code" }],
217
+ attachments: [
218
+ AGENT,
219
+ { ...AGENT, id: "anon", identity: null },
220
+ OTHER_AGENT,
221
+ { ...AGENT, id: "duplicate", name: "Later Pi" },
222
+ ],
166
223
  content: <SendErrorReportButton getContent={getContent} />,
167
224
  });
225
+ openRecipients();
226
+ expect(
227
+ screen.getAllByRole("menuitem").map((item) => item.textContent),
228
+ ).toEqual(["Pi", "Claude Code", "Send to all agents"]);
168
229
  expect(getContent).not.toHaveBeenCalled();
169
- send();
230
+ fireEvent.click(screen.getByRole("menuitem", { name: "Claude Code" }));
231
+ const request = await lastRequest();
232
+ expect(request.url).toBe(`${NOTEBOOK_URL}/emit`);
233
+ expect(request.method).toBe("POST");
234
+ expect(request.headers.get("Marimo-Server-Token")).toBe("test-token");
235
+ expect(request.headers.get("Idempotency-Key")).toMatch(/^[\da-f-]{36}$/);
236
+ expect(await request.json()).toEqual(
237
+ errorEvent(REPORT, OTHER_AGENT.identity),
238
+ );
170
239
  await waitFor(() =>
171
240
  expect(toast).toHaveBeenCalledWith({
172
- title: "Sent to Pi, Claude Code",
241
+ title: "Sent",
173
242
  duration: 3000,
174
243
  }),
175
244
  );
176
- expect(API.post).toHaveBeenCalledWith(ROUTE, REPORT);
245
+ expect(fetch).toHaveBeenCalledOnce();
177
246
  expect(getContent).toHaveBeenCalledOnce();
178
247
  });
179
248
 
249
+ it("distinguishes agents whose names and ID suffixes match", async () => {
250
+ renderButton({
251
+ attachments: [
252
+ { ...AGENT, name: "Lens", identity: "lens-a-thread" },
253
+ { ...OTHER_AGENT, name: "Lens", identity: "lens-b-thread" },
254
+ ],
255
+ });
256
+ openRecipients();
257
+ expect(
258
+ screen.getByRole("menuitem", { name: "Lens (lens-a-thread)" }),
259
+ ).toBeVisible();
260
+ fireEvent.click(
261
+ screen.getByRole("menuitem", { name: "Lens (lens-b-thread)" }),
262
+ );
263
+ expect(await sentEvent()).toEqual(errorEvent(REPORT, "lens-b-thread"));
264
+ });
265
+
266
+ it("publishes a broadcast with a null recipient", async () => {
267
+ renderButton({ attachments: [AGENT, OTHER_AGENT] });
268
+ openRecipients();
269
+ fireEvent.click(
270
+ screen.getByRole("menuitem", { name: "Send to all agents" }),
271
+ );
272
+ expect(await sentEvent()).toEqual(errorEvent(REPORT, null));
273
+ });
274
+
180
275
  it("prevents duplicate sends while a request is pending", async () => {
181
- const deferred = new Deferred<string>();
182
- vi.mocked(API.post).mockReturnValue(deferred.promise);
276
+ const deferred = new Deferred<Response>();
277
+ fetch.mockReturnValue(deferred.promise);
183
278
  renderButton();
184
279
  send();
185
280
  expect(screen.getByRole("button")).toBeDisabled();
186
281
  send();
187
- expect(API.post).toHaveBeenCalledOnce();
188
- await act(async () => deferred.resolve(""));
282
+ expect(fetch).toHaveBeenCalledOnce();
283
+ expect(toast).not.toHaveBeenCalled();
284
+ await act(async () =>
285
+ deferred.resolve(new Response(null, { status: 204 })),
286
+ );
189
287
  expect(screen.getByRole("button")).toBeEnabled();
288
+ expect(toast).toHaveBeenCalledWith({ title: "Sent", duration: 3000 });
190
289
  });
191
290
 
192
- it("disables the button after the last agent disconnects", () => {
291
+ it("hides the button after the last agent disconnects", () => {
193
292
  const { store } = renderButton();
194
293
  act(() => store.set(attachmentsAtom, []));
195
- expect(screen.getByRole("button")).toBeDisabled();
294
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
196
295
  });
197
296
 
198
- it.each([
199
- [new HTTPError(409, "Conflict"), "No agent attached"],
200
- [new HTTPError(500, "Server error"), "Could not send error"],
201
- ])("reports request failures and permits retry", async (error, title) => {
202
- vi.mocked(API.post).mockRejectedValueOnce(error);
203
- renderButton();
297
+ it.each(["host", "network"])(
298
+ "shows a %s error and permits a new send",
299
+ async (failure) => {
300
+ const detail = "Publication failed";
301
+ if (failure === "host") {
302
+ fetch.mockResolvedValueOnce(
303
+ new Response(
304
+ JSON.stringify({
305
+ type: "urn:marimo:problem:internal",
306
+ title: "Internal error",
307
+ status: 500,
308
+ detail,
309
+ }),
310
+ {
311
+ status: 500,
312
+ headers: { "Content-Type": "application/problem+json" },
313
+ },
314
+ ),
315
+ );
316
+ } else {
317
+ fetch.mockRejectedValueOnce(new Error(detail));
318
+ }
319
+ renderButton();
320
+ send();
321
+ const failedId = (await lastRequest()).headers.get("Idempotency-Key");
322
+ await waitFor(() =>
323
+ expect(toast).toHaveBeenCalledWith({
324
+ variant: "danger",
325
+ title: "Could not send error",
326
+ description: detail,
327
+ duration: 5000,
328
+ }),
329
+ );
330
+ expect(toast).toHaveBeenCalledOnce();
331
+ expect(screen.getByRole("button")).toBeEnabled();
332
+ send();
333
+ await waitFor(() =>
334
+ expect(toast).toHaveBeenCalledWith({
335
+ title: "Sent",
336
+ duration: 3000,
337
+ }),
338
+ );
339
+ expect(fetch).toHaveBeenCalledTimes(2);
340
+ const request = await lastRequest();
341
+ expect(request.headers.get("Idempotency-Key")).not.toBe(failedId);
342
+ expect(await request.json()).toEqual(errorEvent(REPORT));
343
+ },
344
+ );
345
+
346
+ it("accepts 65,536 encoded bytes, including UTF-8, quotes, and escapes", async () => {
347
+ const message = `${"é".repeat(32_766)}\n`;
348
+ renderButton({
349
+ content: <SendErrorReportButton getContent={() => message} />,
350
+ });
204
351
  send();
205
- await waitFor(() =>
206
- expect(toast).toHaveBeenCalledWith({
207
- variant: "danger",
208
- title,
209
- description: error.message,
210
- duration: 5000,
211
- }),
212
- );
213
- expect(screen.getByRole("button")).toBeEnabled();
352
+ expect(await sentEvent()).toEqual(errorEvent(message));
353
+ });
354
+
355
+ it("rejects 65,537 encoded bytes before publication", async () => {
356
+ const message = `${"é".repeat(32_766)}\na`;
357
+ renderButton({
358
+ content: <SendErrorReportButton getContent={() => message} />,
359
+ });
214
360
  send();
215
- await waitFor(() =>
216
- expect(toast).toHaveBeenCalledWith({
217
- title: "Sent to Pi",
218
- duration: 3000,
219
- }),
220
- );
221
- expect(API.post).toHaveBeenCalledTimes(2);
222
- expect(API.post).toHaveBeenLastCalledWith(ROUTE, REPORT);
361
+ expect(toast).toHaveBeenCalledWith({
362
+ variant: "danger",
363
+ title: "Could not send error",
364
+ description: "The report exceeds 65,536 bytes as JSON.",
365
+ duration: 5000,
366
+ });
367
+ expect(fetch).not.toHaveBeenCalled();
368
+ expect(screen.getByRole("button")).toBeEnabled();
223
369
  });
224
370
 
225
371
  it("sends captured code and full traceback from the error output", async () => {
@@ -238,8 +384,8 @@ describe("SendErrorReportButton", () => {
238
384
  ),
239
385
  });
240
386
  send();
241
- await waitFor(() =>
242
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
387
+ expect(await sentEvent()).toEqual(
388
+ errorEvent({
243
389
  ...REPORT,
244
390
  output: {
245
391
  type: "error",
@@ -252,7 +398,7 @@ describe("SendErrorReportButton", () => {
252
398
  });
253
399
 
254
400
  it("sends a formatter error beside a normal main output", async () => {
255
- const { store } = renderButton({
401
+ const { store, seed } = renderButton({
256
402
  content: (
257
403
  <OutputRenderer
258
404
  cellId={CELL_ID}
@@ -271,15 +417,15 @@ describe("SendErrorReportButton", () => {
271
417
  cellData: { [CELL_ID]: { code: "later edit" } },
272
418
  }),
273
419
  );
274
- MockExecutions.seed(store, [
420
+ seed(store, [
275
421
  MockExecutions.shown(CELL_ID, {
276
422
  mimetype: "text/plain",
277
423
  data: "<Broken formatter>",
278
424
  }),
279
425
  ]);
280
426
  send();
281
- await waitFor(() =>
282
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
427
+ expect(await sentEvent()).toEqual(
428
+ errorEvent({
283
429
  ...REPORT,
284
430
  output: {
285
431
  type: "error",
@@ -312,8 +458,8 @@ describe("SendErrorReportButton", () => {
312
458
  "<cell>",
313
459
  );
314
460
  send();
315
- await waitFor(() =>
316
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
461
+ expect(await sentEvent()).toEqual(
462
+ errorEvent({
317
463
  ...REPORT,
318
464
  output: {
319
465
  type: "error",
@@ -378,8 +524,8 @@ describe("SendErrorReportButton", () => {
378
524
  content: message && <OutputRenderer cellId={CELL_ID} message={message} />,
379
525
  });
380
526
  send();
381
- await waitFor(() =>
382
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
527
+ expect(await sentEvent()).toEqual(
528
+ errorEvent({
383
529
  ...REPORT,
384
530
  output: {
385
531
  type: "error",
@@ -402,7 +548,7 @@ describe("SendErrorReportButton", () => {
402
548
  };
403
549
  rerender(<SendErrorReportButton getContent={() => updated} />);
404
550
  send();
405
- await waitFor(() => expect(API.post).toHaveBeenCalledWith(ROUTE, updated));
551
+ expect(await sentEvent()).toEqual(errorEvent(updated));
406
552
  });
407
553
 
408
554
  it.each([
@@ -415,7 +561,7 @@ describe("SendErrorReportButton", () => {
415
561
  content: <SendErrorReportButton getContent={() => content} />,
416
562
  });
417
563
  send();
418
- await waitFor(() => expect(API.post).toHaveBeenCalledWith(ROUTE, content));
564
+ expect(await sentEvent()).toEqual(errorEvent(content));
419
565
  });
420
566
 
421
567
  it("sends the source that raised while the host still has it", async () => {
@@ -436,8 +582,8 @@ describe("SendErrorReportButton", () => {
436
582
  <OutputRenderer cellId={CELL_ID} message={message} />
437
583
  ) : null;
438
584
  };
439
- const { store, rerender } = renderButton({ content: <div /> });
440
- const replica = MockExecutions.seed(
585
+ const { store, seed, rerender } = renderButton({ content: <div /> });
586
+ const replica = seed(
441
587
  store,
442
588
  [
443
589
  {
@@ -453,18 +599,19 @@ describe("SendErrorReportButton", () => {
453
599
  );
454
600
  rerender(<StoreOutput />);
455
601
  send();
456
- await waitFor(() => expect(API.post).toHaveBeenCalledWith(ROUTE, REPORT));
602
+ expect(await sentEvent()).toEqual(errorEvent(REPORT));
457
603
 
458
604
  // Once an edit is confirmed, the source that raised is gone.
459
- vi.mocked(API.post).mockClear();
605
+ fetch.mockClear();
460
606
  act(() => {
461
607
  store.set(replica.documentAtom, confirmed("edited"));
462
608
  });
463
609
  send();
464
- await waitFor(() =>
465
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
466
- ...REPORT,
467
- code: undefined,
610
+ expect(await sentEvent()).toEqual(
611
+ errorEvent({
612
+ type: REPORT.type,
613
+ cell_id: CELL_ID,
614
+ output: REPORT.output,
468
615
  }),
469
616
  );
470
617
  });
@@ -505,8 +652,8 @@ describe("SendErrorReportButton", () => {
505
652
  }),
506
653
  );
507
654
  send();
508
- await waitFor(() =>
509
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
655
+ expect(await sentEvent()).toEqual(
656
+ errorEvent({
510
657
  type: "cell-output",
511
658
  cell_id: CELL_ID,
512
659
  code: "x + 1",
@@ -530,8 +677,8 @@ describe("SendErrorReportButton", () => {
530
677
  ),
531
678
  });
532
679
  send();
533
- await waitFor(() =>
534
- expect(API.post).toHaveBeenCalledWith(ROUTE, {
680
+ expect(await sentEvent()).toEqual(
681
+ errorEvent({
535
682
  type: "cell-output",
536
683
  cell_id: CELL_ID,
537
684
  code: "slow()",