@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev394

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 (166) hide show
  1. package/dist/{ConnectedDataExplorerComponent-BpCrAeX0.js → ConnectedDataExplorerComponent-1DGGwl88.js} +9 -9
  2. package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DDIASniH.js} +6 -6
  3. package/dist/{abnfDiagram-VCTEODGH-ZqNgGZlz.js → abnfDiagram-VCTEODGH-CeQEbVik.js} +2 -2
  4. package/dist/{any-language-editor-CFbAr7vc.js → any-language-editor-C_s_ZoaK.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-BEUaR96d.js → architectureDiagram-5GKGNRK7-C8xUpTAb.js} +1 -1
  6. package/dist/{assertNever-5uYEbJc8.js → assertNever-DXGfUmPW.js} +2 -2
  7. package/dist/assets/__vite-browser-external-C9HF3uHE.js +1 -0
  8. package/dist/assets/worker-B4Cpvr8b.js +171 -0
  9. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-B6bY_0LF.js} +774 -774
  10. package/dist/{check-BbhVyViy.js → check-ywinAQy6.js} +1 -1
  11. package/dist/{chunk-IMKFNOWR-BdEPmWQI.js → chunk-IMKFNOWR-DY7AWyNi.js} +1 -1
  12. package/dist/{chunk-SHT3W25Y-IvvXM3xf.js → chunk-SHT3W25Y-D4epY9MY.js} +1 -1
  13. package/dist/{chunk-SVP7TREG-C_qpJUv1.js → chunk-SVP7TREG-CKsl2Q6r.js} +1 -1
  14. package/dist/{chunk-TICWLB2K-C4agYVWP.js → chunk-TICWLB2K-CMsD2y0F.js} +1 -1
  15. package/dist/{classDiagram-ZZMXUADV-CT2iq8uF.js → classDiagram-ZZMXUADV-C4FsLnvt.js} +2 -2
  16. package/dist/{classDiagram-v2-VYDZK3BY-Coe_dD0r.js → classDiagram-v2-VYDZK3BY-BJRuFZeI.js} +2 -2
  17. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-CByYqwFv.js} +13 -13
  18. package/dist/{common-Ces9ooG_.js → common-KkgATX2Y.js} +4918 -4910
  19. package/dist/{config-DJ8M-gPL.js → config-DOwBtRkI.js} +3 -3
  20. package/dist/{copy-icon-xWvA8ybp.js → copy-icon-BKcX0ltw.js} +2 -2
  21. package/dist/{createReducer-fp0gX_9U.js → createReducer-Bjx6kuxh.js} +1 -1
  22. package/dist/{cynefinDiagram-5FMLGOSQ-D0LKziUu.js → cynefinDiagram-5FMLGOSQ-DyI_lSsn.js} +1 -1
  23. package/dist/{dagre-GXQ25YYZ-Cmgziaw8.js → dagre-GXQ25YYZ-Buoy6sX-.js} +1 -1
  24. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-BHrTJhN3.js} +1 -1
  25. package/dist/{diagram-S7CK7UJ4-D-lZsALU.js → diagram-S7CK7UJ4-CbSD1DUy.js} +1 -1
  26. package/dist/{diagram-UQ7AKVKN-TcbdsFoT.js → diagram-UQ7AKVKN-Dapj2rQm.js} +1 -1
  27. package/dist/{diagram-VX7I27RA-D5BqZi1q.js → diagram-VX7I27RA-CxA3txtC.js} +1 -1
  28. package/dist/{diagram-Z3DM3KII-MNc7jqvr.js → diagram-Z3DM3KII-BEZqz916.js} +1 -1
  29. package/dist/{dialog-Cm0VGdxc.js → dialog-mwa6XN15.js} +2 -2
  30. package/dist/{dropdown-menu-DfamXjVI.js → dropdown-menu-CmgUseHo.js} +5 -5
  31. package/dist/duckdb-keywords-CdzX4o33.js +3 -0
  32. package/dist/{ebnfDiagram-PWID7BFC-Cxt6ywyX.js → ebnfDiagram-PWID7BFC-Dmw-1JV3.js} +2 -2
  33. package/dist/{erDiagram-RLTQ6QDP-BLF-askI.js → erDiagram-RLTQ6QDP-DZpG4cbm.js} +1 -1
  34. package/dist/{error-banner-k06CAftu.js → error-banner-CHPLqogX.js} +1 -1
  35. package/dist/{error-entries-rtPWQkJk.js → error-entries-Bk96zt4w.js} +825 -690
  36. package/dist/{feedback-button-i960qUnq.js → feedback-button-2FaWjlaR.js} +12 -12
  37. package/dist/{flowDiagram-HODETNUW-CsLw2mWn.js → flowDiagram-HODETNUW-B02oHnBv.js} +2 -2
  38. package/dist/{formats-DQ-qq-dU.js → formats-BDqe9cfr.js} +1 -1
  39. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-B9Yq6Wg1.js} +11 -11
  40. package/dist/{glide-utils-CHrghEu-.js → glide-utils-DYKWS2YV.js} +2 -2
  41. package/dist/{globals-DKkjIolp.js → globals-S4D5AVKN.js} +3 -3
  42. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-BauFF9F_.js} +4842 -4821
  43. package/dist/{infoDiagram-27XIBGKW-CdSApBWg.js → infoDiagram-27XIBGKW-BPbQHO9m.js} +1 -1
  44. package/dist/{ishikawaDiagram-5VMMS53U-BnzQ8SI5.js → ishikawaDiagram-5VMMS53U-DmnKSNi7.js} +1 -1
  45. package/dist/{kanban-definition-UXKFOSKX-D2llTpeX.js → kanban-definition-UXKFOSKX-u5PZbsBe.js} +1 -1
  46. package/dist/main.js +6236 -6175
  47. package/dist/{mermaid-BcNMyKmf.js → mermaid-ffopDjig.js} +34 -34
  48. package/dist/{mindmap-definition-YA3MSWOX-uoEsfD5R.js → mindmap-definition-YA3MSWOX-CX187lhP.js} +1 -1
  49. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-l7DB2HCO.js} +1 -1
  50. package/dist/{pegDiagram-XKGWAZYB-DTWrE0S4.js → pegDiagram-XKGWAZYB-Bj6HGPak.js} +2 -2
  51. package/dist/{pencil-weySvN0N.js → pencil-CijoRsa3.js} +1 -1
  52. package/dist/{pieDiagram-E7YTZNPT-COME2oGN.js → pieDiagram-E7YTZNPT-C_wIgDJM.js} +1 -1
  53. package/dist/{process-output-DNxpsd4n.js → process-output-Deae7dX1.js} +4 -4
  54. package/dist/{railroadDiagram-O6MQD6OU-CUeFcNTY.js → railroadDiagram-O6MQD6OU-CwoJvnvC.js} +2 -2
  55. package/dist/{requirementDiagram-BXWQKSXE-BUR4lDZG.js → requirementDiagram-BXWQKSXE-C8JuhLLL.js} +1 -1
  56. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-VR4UzAUv.js} +37 -37
  57. package/dist/{select-Ca-POp4c.js → select-DW32QOzC.js} +4 -4
  58. package/dist/{sequenceDiagram-WJ2MYXX4-CSPmml3q.js → sequenceDiagram-WJ2MYXX4-RbrRdoiV.js} +1 -1
  59. package/dist/{spec-BgSMwzks.js → spec-Ww0JjShW.js} +4 -4
  60. package/dist/{stateDiagram-D77RDMKH-BDUC8Pi9.js → stateDiagram-D77RDMKH-DWdIvCnU.js} +2 -2
  61. package/dist/{stateDiagram-v2-MP3YSRHH-BH-qyk8a.js → stateDiagram-v2-MP3YSRHH-BG0j9crW.js} +2 -2
  62. package/dist/{static-state-Cqzv5X7B.js → static-state-CnQdTBTW.js} +1 -1
  63. package/dist/style.css +1 -1
  64. package/dist/{swimlanes-42K2YHIH-CLE9Kiir.js → swimlanes-42K2YHIH-B6zUw4gq.js} +1 -1
  65. package/dist/{swimlanesDiagram-VR7AAH4N-Cv8kWAeA.js → swimlanesDiagram-VR7AAH4N-DjVEnsIG.js} +2 -2
  66. package/dist/{timeline-definition-24CTP7MA-fbRGX21i.js → timeline-definition-24CTP7MA-DSAxwqnC.js} +1 -1
  67. package/dist/{toast-0xspcdmv.js → toast-Crofa36R.js} +3 -3
  68. package/dist/{tooltip-BwlFTaNy.js → tooltip-Bg-SDCwa.js} +1 -1
  69. package/dist/{use-restore-focus-fKgXR0nb.js → use-restore-focus-CE9Sflmg.js} +1298 -1283
  70. package/dist/{useDateFormatter-B7LvPmsw.js → useDateFormatter-D5fsC9ot.js} +2 -2
  71. package/dist/{useDeepCompareMemoize-OhBYt-q2.js → useDeepCompareMemoize-Bvrue1iy.js} +1 -1
  72. package/dist/{useLifecycle-D9xcFAIN.js → useLifecycle-Ctr5lECo.js} +1 -1
  73. package/dist/{vega-component-Chak9Aon.js → vega-component-DQZhTzVQ.js} +6 -6
  74. package/dist/{vennDiagram-4TSXK5OY-BzKtg8gL.js → vennDiagram-4TSXK5OY-FAGYRdBj.js} +1 -1
  75. package/dist/{wardleyDiagram-VM6X3IG4-R0SgDvz1.js → wardleyDiagram-VM6X3IG4-BlB973r1.js} +1 -1
  76. package/dist/{xychartDiagram-S5SC5T6Z-DRskTHEM.js → xychartDiagram-S5SC5T6Z-CywvmjIK.js} +1 -1
  77. package/package.json +2 -2
  78. package/src/__mocks__/executions.ts +48 -8
  79. package/src/__mocks__/notebook.ts +20 -42
  80. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  81. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  82. package/src/components/app-config/ai-config.tsx +20 -24
  83. package/src/components/app-config/model-discovery.tsx +118 -184
  84. package/src/components/app-config/model-provider-config.ts +25 -0
  85. package/src/components/editor/Output.tsx +5 -4
  86. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  87. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  88. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  89. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  90. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  91. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  92. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  93. package/src/components/editor/notebook-cell.tsx +15 -10
  94. package/src/components/editor/output/console/process-output.ts +4 -2
  95. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  96. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  97. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  98. package/src/components/editor/renderers/types.ts +2 -2
  99. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  100. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  101. package/src/components/scratchpad/scratchpad.tsx +6 -2
  102. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  103. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  104. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  105. package/src/components/slides/slide-cell-view.tsx +1 -3
  106. package/src/components/slides/slide.tsx +3 -3
  107. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  108. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  109. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  110. package/src/core/ai/context/providers/cell-output.ts +11 -6
  111. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  112. package/src/core/cells/__tests__/cells.test.ts +40 -292
  113. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  114. package/src/core/cells/__tests__/harness.ts +14 -12
  115. package/src/core/cells/__tests__/layout.test.ts +20 -26
  116. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  117. package/src/core/cells/__tests__/session.test.ts +26 -146
  118. package/src/core/cells/actions.ts +49 -9
  119. package/src/core/cells/cell.ts +0 -13
  120. package/src/core/cells/cells.ts +53 -62
  121. package/src/core/cells/focus.ts +6 -1
  122. package/src/core/cells/layout.ts +2 -3
  123. package/src/core/cells/outputs.ts +2 -2
  124. package/src/core/cells/session.ts +3 -38
  125. package/src/core/cells/types.ts +6 -8
  126. package/src/core/cells/utils.ts +4 -3
  127. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  128. package/src/core/config/config-schema.ts +15 -0
  129. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  130. package/src/core/errors/error-entries.ts +21 -11
  131. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  132. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  133. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  134. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  135. package/src/core/executions/__tests__/output.test.ts +87 -3
  136. package/src/core/executions/__tests__/select.test.ts +17 -10
  137. package/src/core/executions/atoms.ts +73 -15
  138. package/src/core/executions/freshness.ts +1 -1
  139. package/src/core/executions/hooks.ts +18 -8
  140. package/src/core/executions/index.ts +6 -0
  141. package/src/core/executions/output.ts +122 -38
  142. package/src/core/executions/select.ts +2 -2
  143. package/src/core/export/__tests__/hooks.test.ts +20 -29
  144. package/src/core/export/hooks.ts +7 -9
  145. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  146. package/src/core/islands/__tests__/main.test.ts +17 -0
  147. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  148. package/src/core/islands/components/output-wrapper.tsx +15 -20
  149. package/src/core/islands/iframe-resizer.ts +38 -0
  150. package/src/core/islands/main.ts +3 -0
  151. package/src/core/lifecycle/render-policy.ts +7 -4
  152. package/src/core/network/__tests__/ai.test.ts +41 -0
  153. package/src/core/network/ai.ts +12 -0
  154. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  155. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  156. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  157. package/src/core/notebook/replica/index.ts +1 -1
  158. package/src/core/notebook/replica/replica.ts +19 -4
  159. package/src/core/notebook/replica/resources/executions.ts +100 -9
  160. package/src/core/notebook/replica/resources/results.ts +46 -31
  161. package/src/core/transports/__tests__/static.test.ts +5 -3
  162. package/src/stories/cell.stories.tsx +40 -30
  163. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
  164. package/dist/assets/__vite-browser-external-C5NhJPNJ.js +0 -1
  165. package/dist/assets/worker-D-n8vtGi.js +0 -171
  166. package/dist/duckdb-keywords-BGArYVVK.js +0 -3
@@ -3,7 +3,12 @@
3
3
  import { notebookAtom } from "@/core/cells/cells";
4
4
  import type { CellId } from "@/core/cells/ids";
5
5
  import { displayCellName } from "@/core/cells/names";
6
- import type { MarimoError, OutputMessage } from "@/core/kernel/messages";
6
+ import {
7
+ type CellError,
8
+ type CellOutput,
9
+ cellOutputAtom,
10
+ } from "@/core/executions";
11
+ import type { OutputMessage } from "@/core/kernel/messages";
7
12
  import { isErrorMime, isMarimoErrorsMime, isTracebackMime } from "@/core/mime";
8
13
  import type { JotaiStore } from "@/core/state/jotai";
9
14
  import { logNever } from "@/utils/assertNever";
@@ -13,12 +18,12 @@ export interface CellErrorEntry {
13
18
  cellId: CellId;
14
19
  cellName: string;
15
20
  cellCode: string;
16
- errorData: MarimoError[];
21
+ errorData: CellError[];
17
22
  tracebackHtml?: string;
18
23
  }
19
24
 
20
25
  function parseCellErrorOutput(
21
- output: OutputMessage,
26
+ output: CellOutput,
22
27
  ): Pick<CellErrorEntry, "errorData" | "tracebackHtml"> | null {
23
28
  if (isMarimoErrorsMime(output.mimetype)) {
24
29
  if (!Array.isArray(output.data)) {
@@ -43,7 +48,7 @@ function parseCellErrorOutput(
43
48
  return null;
44
49
  }
45
50
 
46
- function errorDataHasTraceback(errorData: MarimoError[]): boolean {
51
+ function errorDataHasTraceback(errorData: readonly CellError[]): boolean {
47
52
  return errorData.some((error) => "traceback" in error && error.traceback);
48
53
  }
49
54
 
@@ -81,9 +86,8 @@ export function getCellErrorEntries(store: JotaiStore): CellErrorEntry[] {
81
86
  const entries: CellErrorEntry[] = [];
82
87
 
83
88
  for (const [cellIndex, cellId] of cellIds.entries()) {
84
- const cell = cellRuntime[cellId];
85
- const output = cell.output;
86
- if (!output || !isErrorMime(output.mimetype)) {
89
+ const output = store.get(cellOutputAtom(cellId));
90
+ if (output === null || !isErrorMime(output.mimetype)) {
87
91
  continue;
88
92
  }
89
93
 
@@ -93,7 +97,7 @@ export function getCellErrorEntries(store: JotaiStore): CellErrorEntry[] {
93
97
  }
94
98
 
95
99
  const cellName = displayCellName(cellData[cellId].name, cellIndex);
96
- // The source that raised, since the cell may have been edited since.
100
+ // The source that raised, while the host still has it.
97
101
  const cellCode = output.code ?? cellData[cellId].code;
98
102
 
99
103
  entries.push({
@@ -101,14 +105,20 @@ export function getCellErrorEntries(store: JotaiStore): CellErrorEntry[] {
101
105
  cellName,
102
106
  cellCode,
103
107
  errorData: parsed.errorData,
104
- tracebackHtml: resolveTracebackHtml(parsed, cell.consoleOutputs),
108
+ tracebackHtml: resolveTracebackHtml(
109
+ parsed,
110
+ cellRuntime[cellId].consoleOutputs,
111
+ ),
105
112
  });
106
113
  }
107
114
 
108
115
  return entries;
109
116
  }
110
117
 
111
- export function describeError(error: MarimoError): string {
118
+ export function describeError(error: CellError): string {
119
+ if (error.type === "diagnostic") {
120
+ return error.msg;
121
+ }
112
122
  if (error.type === "setup-refs") {
113
123
  return "The setup cell cannot have references";
114
124
  }
@@ -155,7 +165,7 @@ export function describeError(error: MarimoError): string {
155
165
  return "Unknown error";
156
166
  }
157
167
 
158
- export function formatSingleError(error: MarimoError): string {
168
+ export function formatSingleError(error: CellError): string {
159
169
  let text = describeError(error);
160
170
  if ("traceback" in error && error.traceback) {
161
171
  text += `\n\nTraceback:\n${parseHtmlContent(error.traceback)}`;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type * as Protocol from "@marimo-team/client/protocol";
4
4
  import { describe, expect, it } from "vitest";
5
- import type { Execution, Executions } from "@/core/notebook/replica";
5
+ import type { Execution, Executions, Result } from "@/core/notebook/replica";
6
6
  import { type CellFreshnessInputs, freshnessOf } from "../freshness";
7
7
 
8
8
  const T0 = "2026-10-01T09:20:11Z";
@@ -77,6 +77,7 @@ function execution(
77
77
  ): Execution {
78
78
  return {
79
79
  record: rec,
80
+ outputVersion: 0,
80
81
  items: new Map(),
81
82
  variables: new Map(variables.map((v) => [v.id, v])),
82
83
  };
@@ -93,6 +94,8 @@ function inputs({
93
94
  results?: Protocol.Execution[];
94
95
  }): CellFreshnessInputs {
95
96
  const stream: Executions = {
97
+ results: new Map(),
98
+ scratch: null,
96
99
  runs: new Map(),
97
100
  executions: new Map(executions.map((e) => [e.record.id, e])),
98
101
  latest: new Map(
@@ -101,17 +104,17 @@ function inputs({
101
104
  ),
102
105
  ),
103
106
  };
104
- const retained = new Map<Protocol.CellId, Protocol.Execution | null>(
107
+ const retained = new Map<Protocol.CellId, Result | null>(
105
108
  cells.map((c) => [c.id, null]),
106
109
  );
107
110
  for (const result of results) {
108
111
  if (result.cell_id !== null) {
109
- retained.set(result.cell_id, result);
112
+ retained.set(result.cell_id, { record: result, outputVersion: 0 });
110
113
  }
111
114
  }
112
115
  return {
113
116
  cells: new Map(cells.map((c) => [c.id, c])),
114
- executions: stream,
117
+ executions: { ...stream, results: retained },
115
118
  results: retained,
116
119
  };
117
120
  }
@@ -143,7 +143,11 @@ describe("useCellOutput", () => {
143
143
  expect(result.current).toBeNull();
144
144
 
145
145
  act(() => {
146
- store.set(replica.notebookAtom, MockExecutions.notebook("n2"));
146
+ const document = documentOf();
147
+ store.set(replica.documentAtom, {
148
+ ...document,
149
+ revision: { ...document.revision, notebook_id: "n2" },
150
+ });
147
151
  });
148
152
  expect(result.current?.data).toBe("c1 value");
149
153
  });
@@ -53,6 +53,8 @@ function setup(runs: Protocol.Run[]) {
53
53
  runs: new Map(runs.map((run) => [run.id, run])),
54
54
  executions: new Map(),
55
55
  latest: new Map(),
56
+ results: new Map(),
57
+ scratch: null,
56
58
  });
57
59
  return { store, replica, interrupt };
58
60
  }
@@ -0,0 +1,201 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ // @vitest-environment jsdom
3
+
4
+ import type { NotebookTransport } from "@marimo-team/client";
5
+ import type * as Protocol from "@marimo-team/client/protocol";
6
+ import { createStore } from "jotai";
7
+ import { describe, expect, it, onTestFinished, vi } from "vitest";
8
+ import { MockExecutions } from "@/__mocks__/executions";
9
+ import { cellId } from "@/__tests__/branded";
10
+ import { createNotebookReplica } from "@/core/notebook/replica";
11
+ import {
12
+ fakeBackend,
13
+ fixtureMessages,
14
+ } from "@/core/notebook/replica/__tests__/fixtures";
15
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
16
+ import { Deferred } from "@/utils/Deferred";
17
+ import { cellOutputAtom, clearCellOutputs } from "../atoms";
18
+ import { scratchOutputView } from "../output";
19
+
20
+ const C1 = cellId("c1");
21
+ const value = (data: string): Protocol.Outcome => ({
22
+ kind: "value",
23
+ display: { mimetype: "text/plain", data },
24
+ });
25
+
26
+ async function setup() {
27
+ const connected = new Deferred<Parameters<NotebookTransport>[1]>();
28
+ const backend = fakeBackend({
29
+ transport: ({ signal }, handlers) =>
30
+ new Promise<void>((resolve) => {
31
+ handlers.open();
32
+ connected.resolve(handlers);
33
+ signal.addEventListener("abort", () => resolve(), { once: true });
34
+ }),
35
+ });
36
+ const store = createStore();
37
+ const replica = createNotebookReplica(store);
38
+ store.set(activeNotebookReplicaAtom, replica);
39
+ const disconnect = replica.connect(backend, { onNotification: vi.fn() });
40
+ onTestFinished(disconnect);
41
+ const { message } = await connected.promise;
42
+ let cursor = 100;
43
+ const emit = (execution: Protocol.Execution) =>
44
+ message({ event: "execution", id: String(++cursor), data: { execution } });
45
+ const remove = (execution: Protocol.Execution) =>
46
+ message({
47
+ event: "execution.removed",
48
+ id: String(++cursor),
49
+ data: { id: execution.id, time: MockExecutions.T1 },
50
+ });
51
+ const snapshot = (records: Protocol.Execution[], notebookId = "n1") => {
52
+ message({ event: "reset", data: {} });
53
+ fixtureMessages("notebook-events.sse")
54
+ .filter(({ event }) => ["notebook", "document", "cell"].includes(event))
55
+ .forEach((event) =>
56
+ message(
57
+ JSON.parse(
58
+ JSON.stringify(event).replaceAll(
59
+ '"n1"',
60
+ JSON.stringify(notebookId),
61
+ ),
62
+ ),
63
+ ),
64
+ );
65
+ records.forEach(emit);
66
+ message({ event: "ready", id: String(++cursor), data: {} });
67
+ };
68
+ return { store, replica, emit, remove, snapshot, message, disconnect };
69
+ }
70
+
71
+ describe("output lifetime", () => {
72
+ it("keeps a cleared output hidden through reset and disconnect", async () => {
73
+ const { store, snapshot, message, disconnect } = await setup();
74
+ const result = MockExecutions.completed(C1, { outcome: value("A") });
75
+ snapshot([result]);
76
+ clearCellOutputs(store, [C1]);
77
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
78
+
79
+ message({ event: "reset", data: {} });
80
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
81
+ snapshot([result]);
82
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
83
+ disconnect();
84
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
85
+ });
86
+ it("keeps a changed display visible after its execution retires", async () => {
87
+ const { store, replica, emit, remove, snapshot } = await setup();
88
+ const result = MockExecutions.completed(C1, { outcome: value("A") });
89
+ snapshot([result]);
90
+ clearCellOutputs(store, [C1]);
91
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
92
+
93
+ emit({ ...result, outcome: value("B") });
94
+ emit({ ...result, outcome: value("A") });
95
+ // No reader needs to observe the intermediate display for it to count.
96
+ snapshot([{ ...result, outcome: value("A") }]);
97
+ remove(result);
98
+ const running = MockExecutions.running(C1);
99
+ emit(running);
100
+ expect(store.get(replica.executionsAtom).executions.has(result.id)).toBe(
101
+ false,
102
+ );
103
+ expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
104
+ snapshot([running]);
105
+ expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
106
+ });
107
+
108
+ it("keeps a clear through completion and retirement, until a newer result", async () => {
109
+ const { store, emit, remove, snapshot } = await setup();
110
+ const running = MockExecutions.running(C1);
111
+ snapshot([running]);
112
+ emit({ ...running, outcome: value("A") });
113
+ clearCellOutputs(store, [C1]);
114
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
115
+
116
+ const completed = {
117
+ ...running,
118
+ status: "completed" as const,
119
+ completed_at: MockExecutions.T1,
120
+ outcome: value("A"),
121
+ };
122
+ emit(completed);
123
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
124
+ snapshot([completed]);
125
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
126
+ remove(completed);
127
+ const next = MockExecutions.running(C1);
128
+ emit(next);
129
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
130
+ snapshot([next]);
131
+ expect(store.get(cellOutputAtom(C1))).toBeNull();
132
+ emit({ ...next, outcome: value("A") });
133
+ expect(store.get(cellOutputAtom(C1))?.data).toBe("A");
134
+ });
135
+ it("keeps the scratch display after its execution expires", async () => {
136
+ const { store, replica, emit, remove, snapshot } = await setup();
137
+ const scratch = MockExecutions.completed("scratch", {
138
+ cell_id: null,
139
+ outcome: value("scratch result"),
140
+ });
141
+ snapshot([scratch]);
142
+ const before = scratchOutputView(store.get(replica.executionsAtom));
143
+ expect(before?.data).toBe("scratch result");
144
+ remove(scratch);
145
+ expect(store.get(replica.executionsAtom).executions.size).toBe(0);
146
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toEqual(
147
+ before,
148
+ );
149
+ snapshot([]);
150
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toEqual(
151
+ before,
152
+ );
153
+
154
+ const next = {
155
+ ...MockExecutions.running("scratch"),
156
+ cell_id: null,
157
+ started_at: "2026-10-01T09:22:00Z",
158
+ };
159
+ emit(next);
160
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toEqual(
161
+ before,
162
+ );
163
+ emit({ ...next, outcome: value("next") });
164
+ expect(scratchOutputView(store.get(replica.executionsAtom))?.data).toBe(
165
+ "next",
166
+ );
167
+ emit({
168
+ ...next,
169
+ status: "completed",
170
+ completed_at: "2026-10-01T09:22:01Z",
171
+ outcome: value("next"),
172
+ });
173
+ remove(next);
174
+ expect(scratchOutputView(store.get(replica.executionsAtom))?.data).toBe(
175
+ "next",
176
+ );
177
+ snapshot([], "n2");
178
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toBeNull();
179
+ });
180
+
181
+ it("keeps scratch output cleared when an empty execution expires", async () => {
182
+ const { store, replica, emit, remove, snapshot } = await setup();
183
+ snapshot([
184
+ MockExecutions.completed("scratch", {
185
+ cell_id: null,
186
+ outcome: value("old"),
187
+ }),
188
+ ]);
189
+ const cleared = MockExecutions.completed("scratch", {
190
+ cell_id: null,
191
+ outcome: { kind: "value", display: null },
192
+ completed_at: "2026-10-01T09:22:00Z",
193
+ });
194
+ emit(cleared);
195
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toBeNull();
196
+ remove(cleared);
197
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toBeNull();
198
+ snapshot([]);
199
+ expect(scratchOutputView(store.get(replica.executionsAtom))).toBeNull();
200
+ });
201
+ });
@@ -4,6 +4,7 @@ import type * as Protocol from "@marimo-team/client/protocol";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { MockExecutions } from "@/__mocks__/executions";
6
6
  import { cellId } from "@/__tests__/branded";
7
+ import { cell } from "@/core/notebook/document/__tests__/fixtures";
7
8
  import {
8
9
  type CellOutputInputs,
9
10
  cellError,
@@ -15,6 +16,8 @@ const C1 = cellId("c1");
15
16
  const C2 = cellId("c2");
16
17
 
17
18
  const HTML: Protocol.DisplayData = { mimetype: "text/html", data: "<b>1</b>" };
19
+ /** After every time the execution mocks use. */
20
+ const LATER = "2026-10-01T09:30:00Z";
18
21
 
19
22
  function hostError(overrides: Partial<Protocol.Error>): Protocol.Error {
20
23
  return {
@@ -33,9 +36,10 @@ function hostError(overrides: Partial<Protocol.Error>): Protocol.Error {
33
36
  function inputs(
34
37
  records: Protocol.Execution[],
35
38
  cleared: CellOutputInputs["cleared"] = new Map(),
39
+ cells: CellOutputInputs["cells"] = new Map(),
36
40
  ): CellOutputInputs {
37
41
  const { executions, results } = MockExecutions.inputs(records);
38
- return { executions, results, cleared };
42
+ return { executions, results, cleared, cells };
39
43
  }
40
44
 
41
45
  describe("cellOutputView", () => {
@@ -70,7 +74,7 @@ describe("cellOutputView", () => {
70
74
  kind: "error",
71
75
  error: hostError({
72
76
  traceback: { mimetype: "text/plain", data: "Traceback..." },
73
- related: [{ cell_id: C2, range: null, message: "raised" }],
77
+ related: [{ cell_id: C2, range: null, message: "Raised it" }],
74
78
  }),
75
79
  },
76
80
  }),
@@ -124,6 +128,23 @@ describe("cellOutputView", () => {
124
128
  ]);
125
129
  });
126
130
 
131
+ it("takes down a did-not-run notice once the cell runs", () => {
132
+ const skipped = MockExecutions.completed(C1, {
133
+ outcome: {
134
+ kind: "skipped",
135
+ reason: "upstream-stopped",
136
+ message: "An ancestor stopped",
137
+ related: [{ cell_id: C2, range: null, message: "stopped" }],
138
+ },
139
+ });
140
+ expect(
141
+ cellOutputView(inputs([skipped, MockExecutions.queued(C1)]), C1),
142
+ ).not.toBeNull();
143
+ expect(
144
+ cellOutputView(inputs([skipped, MockExecutions.running(C1)]), C1),
145
+ ).toBeNull();
146
+ });
147
+
127
148
  it("prefers the running execution's value so far over the retained result", () => {
128
149
  const previous = MockExecutions.completed(C1, {
129
150
  outcome: { kind: "value", display: HTML },
@@ -180,11 +201,35 @@ describe("cellOutputView", () => {
180
201
  ]);
181
202
  });
182
203
 
204
+ it("carries the source that ran while the confirmed cell still has it", () => {
205
+ const ran = MockExecutions.failed(C1, {}, { code_fingerprint: "ran" });
206
+ const same = new Map([
207
+ [C1, cell(C1, "1 / 0", { code_fingerprint: "ran" })],
208
+ ]);
209
+ expect(cellOutputView(inputs([ran], new Map(), same), C1)?.code).toBe(
210
+ "1 / 0",
211
+ );
212
+
213
+ const edited = new Map([
214
+ [C1, cell(C1, "1 / 1", { code_fingerprint: "edited" })],
215
+ ]);
216
+ expect(
217
+ cellOutputView(inputs([ran], new Map(), edited), C1)?.code,
218
+ ).toBeUndefined();
219
+
220
+ const withheld = new Map([
221
+ [C1, cell(C1, "", { code: null, code_fingerprint: "ran" })],
222
+ ]);
223
+ expect(
224
+ cellOutputView(inputs([ran], new Map(), withheld), C1)?.code,
225
+ ).toBeUndefined();
226
+ });
227
+
183
228
  it("hides a cleared result until a newer one lands", () => {
184
229
  const first = MockExecutions.completed(C1, {
185
230
  outcome: { kind: "value", display: HTML },
186
231
  });
187
- const cleared = new Map([[C1, first.id]]);
232
+ const cleared = new Map([[C1, { execution: first.id, version: 0 }]]);
188
233
  expect(cellOutputView(inputs([first], cleared), C1)).toBeNull();
189
234
 
190
235
  const second = MockExecutions.completed(C1, {
@@ -192,6 +237,19 @@ describe("cellOutputView", () => {
192
237
  });
193
238
  expect(cellOutputView(inputs([second], cleared), C1)).not.toBeNull();
194
239
  });
240
+
241
+ it("keeps a cleared running display hidden when it completes", () => {
242
+ const running = MockExecutions.completed(C1, {
243
+ status: "running",
244
+ completed_at: null,
245
+ outcome: { kind: "value", display: HTML },
246
+ });
247
+ const cleared = new Map([[C1, { execution: running.id, version: 0 }]]);
248
+ expect(cellOutputView(inputs([running], cleared), C1)).toBeNull();
249
+
250
+ const finished = { ...running, status: "completed" as const };
251
+ expect(cellOutputView(inputs([finished], cleared), C1)).toBeNull();
252
+ });
195
253
  });
196
254
 
197
255
  describe("cellError", () => {
@@ -263,4 +321,30 @@ describe("scratchOutputView", () => {
263
321
  "so far",
264
322
  );
265
323
  });
324
+
325
+ it("keeps the previous output until a newer run has one to show", () => {
326
+ const done = MockExecutions.completed("scratch", {
327
+ cell_id: null,
328
+ outcome: { kind: "value", display: HTML },
329
+ });
330
+ const silent = {
331
+ ...MockExecutions.running("scratch-2"),
332
+ cell_id: null,
333
+ started_at: LATER,
334
+ };
335
+ expect(scratchOutputView(inputs([done, silent]).executions)?.data).toBe(
336
+ "<b>1</b>",
337
+ );
338
+
339
+ // Interrupted before it started, so it has no start time to order by.
340
+ const interrupted = {
341
+ ...MockExecutions.interrupted("scratch-3"),
342
+ cell_id: null,
343
+ started_at: null,
344
+ completed_at: LATER,
345
+ };
346
+ expect(
347
+ scratchOutputView(inputs([done, interrupted]).executions)?.data,
348
+ ).toEqual([{ type: "interruption" }]);
349
+ });
266
350
  });
@@ -37,7 +37,12 @@ function record(
37
37
  }
38
38
 
39
39
  function execution(overrides: Partial<Protocol.Execution> & { id: string }) {
40
- return { record: record(overrides), items: new Map(), variables: new Map() };
40
+ return {
41
+ record: record(overrides),
42
+ outputVersion: 0,
43
+ items: new Map(),
44
+ variables: new Map(),
45
+ };
41
46
  }
42
47
 
43
48
  function run(
@@ -76,6 +81,8 @@ function inputs({
76
81
  blocked?: ReadonlySet<string>;
77
82
  }): CellExecutionInputs {
78
83
  const stream: Executions = {
84
+ scratch: null,
85
+ results,
79
86
  runs: new Map(runs.map((r) => [r.id, r])),
80
87
  executions: new Map(executions.map((e) => [e.record.id, e])),
81
88
  latest: new Map(
@@ -128,7 +135,7 @@ describe("cellExecutionView", () => {
128
135
  completed_at: null,
129
136
  }),
130
137
  ],
131
- results: new Map([["c1", record({ id: "e0" })]]),
138
+ results: new Map([["c1", execution({ id: "e0" })]]),
132
139
  });
133
140
  expect(cellExecutionView(running, "c1")).toEqual({
134
141
  status: "running",
@@ -159,7 +166,7 @@ describe("cellExecutionView", () => {
159
166
  cellExecutionView(
160
167
  inputs({
161
168
  executions: [execution({ id: "e1", outcome })],
162
- results: new Map([["c1", record({ id: "e1", outcome })]]),
169
+ results: new Map([["c1", execution({ id: "e1", outcome })]]),
163
170
  }),
164
171
  "c1",
165
172
  );
@@ -199,7 +206,7 @@ describe("cellExecutionView", () => {
199
206
  it("reads as queued from a request the stream has not shown a run for", () => {
200
207
  const requested = inputs({
201
208
  executions: [execution({ id: "e1" })],
202
- results: new Map([["c1", record({ id: "e1" })]]),
209
+ results: new Map([["c1", execution({ id: "e1" })]]),
203
210
  requested: new Set(["c1"]),
204
211
  });
205
212
  expect(cellExecutionView(requested, "c1").status).toBe("queued");
@@ -210,7 +217,7 @@ describe("cellExecutionView", () => {
210
217
  });
211
218
 
212
219
  it("reads as queued from an unfinished run that names the cell until it is planned", () => {
213
- const result = new Map([["c1", record({ id: "e1" })]]);
220
+ const result = new Map([["c1", execution({ id: "e1" })]]);
214
221
  const accepted = inputs({
215
222
  runs: [run(["c1"], "queued", "run-2")],
216
223
  executions: [execution({ id: "e1" })],
@@ -237,7 +244,7 @@ describe("cellExecutionView", () => {
237
244
  const done = inputs({
238
245
  runs: [run(["c1", "c2"], "running", "run-2")],
239
246
  executions: [execution({ id: "e2", run_id: "run-2" })],
240
- results: new Map([["c1", record({ id: "e2", run_id: "run-2" })]]),
247
+ results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
241
248
  });
242
249
  expect(cellExecutionView(done, "c1").status).toBe("idle");
243
250
  expect(cellExecutionView(done, "c1").outcome).toBe("value");
@@ -246,7 +253,7 @@ describe("cellExecutionView", () => {
246
253
  // The stream let the execution go while its run goes on with other cells.
247
254
  const retained = inputs({
248
255
  runs: [run(["c1", "c2"], "running", "run-2")],
249
- results: new Map([["c1", record({ id: "e2", run_id: "run-2" })]]),
256
+ results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
250
257
  });
251
258
  expect(cellExecutionView(retained, "c1").status).toBe("idle");
252
259
  expect(cellExecutionView(retained, "c2").status).toBe("queued");
@@ -255,7 +262,7 @@ describe("cellExecutionView", () => {
255
262
  const again = inputs({
256
263
  runs: [run(["c1"], "running", "run-2"), run(["c1"], "queued", "run-3")],
257
264
  executions: [execution({ id: "e2", run_id: "run-2" })],
258
- results: new Map([["c1", record({ id: "e2", run_id: "run-2" })]]),
265
+ results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
259
266
  });
260
267
  expect(cellExecutionView(again, "c1").status).toBe("queued");
261
268
 
@@ -282,7 +289,7 @@ describe("cellExecutionView", () => {
282
289
  it("shows a blocked cell as disabled transitively, with its last outcome", () => {
283
290
  const view = cellExecutionView(
284
291
  inputs({
285
- results: new Map([["c1", record({ id: "e1" })]]),
292
+ results: new Map([["c1", execution({ id: "e1" })]]),
286
293
  blocked: new Set(["c1"]),
287
294
  }),
288
295
  "c1",
@@ -313,7 +320,7 @@ describe("notebook-level views", () => {
313
320
  }),
314
321
  ],
315
322
  runs: [run(["c1", "c2", "c5"], "running"), run(["c5"], "queued", "run-2")],
316
- results: new Map([["c5", record({ id: "e5", cell_id: "c5" })]]),
323
+ results: new Map([["c5", execution({ id: "e5", cell_id: "c5" })]]),
317
324
  requested: new Set(["c2", "c4"]),
318
325
  });
319
326