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

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 (101) hide show
  1. package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DNRG0xHi.js} +1 -1
  2. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-CWVNPm2l.js} +769 -769
  3. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-Ca8sDptK.js} +10 -10
  4. package/dist/{common-Ces9ooG_.js → common-B3NYpak4.js} +4910 -4902
  5. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-Cz7uMmtm.js} +1 -1
  6. package/dist/{error-entries-rtPWQkJk.js → error-entries-CnXf4kpP.js} +821 -686
  7. package/dist/{feedback-button-i960qUnq.js → feedback-button-BQbnZsf5.js} +7 -7
  8. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-Bxc30klU.js} +3 -3
  9. package/dist/{globals-DKkjIolp.js → globals-CDatnx0Y.js} +1 -1
  10. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-Bu_-vH_Y.js} +4782 -4765
  11. package/dist/main.js +6233 -6172
  12. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-ChGu5C-s.js} +1 -1
  13. package/dist/{process-output-DNxpsd4n.js → process-output-Rbqr1aYD.js} +2 -2
  14. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-CSxWJFAP.js} +32 -32
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/__mocks__/executions.ts +48 -8
  18. package/src/__mocks__/notebook.ts +20 -42
  19. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  20. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  21. package/src/components/app-config/ai-config.tsx +20 -24
  22. package/src/components/app-config/model-discovery.tsx +118 -184
  23. package/src/components/app-config/model-provider-config.ts +25 -0
  24. package/src/components/editor/Output.tsx +5 -4
  25. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  26. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  27. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  28. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  29. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  30. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  31. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  32. package/src/components/editor/notebook-cell.tsx +15 -10
  33. package/src/components/editor/output/console/process-output.ts +4 -2
  34. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  35. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  36. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  37. package/src/components/editor/renderers/types.ts +2 -2
  38. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  39. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  40. package/src/components/scratchpad/scratchpad.tsx +6 -2
  41. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  42. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  43. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  44. package/src/components/slides/slide-cell-view.tsx +1 -3
  45. package/src/components/slides/slide.tsx +3 -3
  46. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  47. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  48. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  49. package/src/core/ai/context/providers/cell-output.ts +11 -6
  50. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  51. package/src/core/cells/__tests__/cells.test.ts +40 -292
  52. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  53. package/src/core/cells/__tests__/harness.ts +14 -12
  54. package/src/core/cells/__tests__/layout.test.ts +20 -26
  55. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  56. package/src/core/cells/__tests__/session.test.ts +26 -146
  57. package/src/core/cells/actions.ts +49 -9
  58. package/src/core/cells/cell.ts +0 -13
  59. package/src/core/cells/cells.ts +53 -62
  60. package/src/core/cells/focus.ts +6 -1
  61. package/src/core/cells/layout.ts +2 -3
  62. package/src/core/cells/outputs.ts +2 -2
  63. package/src/core/cells/session.ts +3 -38
  64. package/src/core/cells/types.ts +6 -8
  65. package/src/core/cells/utils.ts +4 -3
  66. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  67. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  68. package/src/core/errors/error-entries.ts +21 -11
  69. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  70. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  71. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  72. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  73. package/src/core/executions/__tests__/output.test.ts +87 -3
  74. package/src/core/executions/__tests__/select.test.ts +17 -10
  75. package/src/core/executions/atoms.ts +73 -15
  76. package/src/core/executions/freshness.ts +1 -1
  77. package/src/core/executions/hooks.ts +18 -8
  78. package/src/core/executions/index.ts +6 -0
  79. package/src/core/executions/output.ts +122 -38
  80. package/src/core/executions/select.ts +2 -2
  81. package/src/core/export/__tests__/hooks.test.ts +20 -29
  82. package/src/core/export/hooks.ts +7 -9
  83. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  84. package/src/core/islands/__tests__/main.test.ts +17 -0
  85. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  86. package/src/core/islands/components/output-wrapper.tsx +15 -20
  87. package/src/core/islands/iframe-resizer.ts +38 -0
  88. package/src/core/islands/main.ts +3 -0
  89. package/src/core/lifecycle/render-policy.ts +7 -4
  90. package/src/core/network/__tests__/ai.test.ts +41 -0
  91. package/src/core/network/ai.ts +12 -0
  92. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  93. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  94. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  95. package/src/core/notebook/replica/index.ts +1 -1
  96. package/src/core/notebook/replica/replica.ts +19 -4
  97. package/src/core/notebook/replica/resources/executions.ts +100 -9
  98. package/src/core/notebook/replica/resources/results.ts +46 -31
  99. package/src/core/transports/__tests__/static.test.ts +5 -3
  100. package/src/stories/cell.stories.tsx +40 -30
  101. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
@@ -123,7 +123,7 @@ describe("cell reducer", () => {
123
123
  state.cellHandles[cid] = { current: handle };
124
124
  }
125
125
  }
126
- cells = flattenTopLevelNotebookCells(state);
126
+ cells = flattenTopLevelNotebookCells(state, new Map());
127
127
  };
128
128
  const actions = createActions((action) => {
129
129
  state = reducer(state, action);
@@ -272,7 +272,6 @@ describe("cell reducer", () => {
272
272
  timestamp: 2,
273
273
  });
274
274
  const runtime = state.cellRuntime[firstCellId];
275
- expect(runtime.output).toEqual(output);
276
275
  expect(runtime.consoleOutputs[0].code).toBe(code);
277
276
  expect(runtime.consoleOutputs[0].data).toContain("old failure");
278
277
  });
@@ -379,7 +378,6 @@ describe("cell reducer", () => {
379
378
  cellId: firstCellId,
380
379
  });
381
380
  cell = cells[0];
382
- expect(cell.output).not.toBe(null); // keep old output
383
381
  // Queue
384
382
  actions.handleCellMessage({
385
383
  cell_id: firstCellId,
@@ -389,7 +387,6 @@ describe("cell reducer", () => {
389
387
  timestamp: new Date(40).getTime() as Seconds,
390
388
  });
391
389
  cell = cells[0];
392
- expect(cell.output).not.toBe(null); // keep old output
393
390
  // Running
394
391
  actions.handleCellMessage({
395
392
  cell_id: firstCellId,
@@ -399,7 +396,6 @@ describe("cell reducer", () => {
399
396
  timestamp: new Date(50).getTime() as Seconds,
400
397
  });
401
398
  cell = cells[0];
402
- expect(cell.output).not.toBe(null); // keep old output
403
399
  // Receive error
404
400
  actions.handleCellMessage({
405
401
  cell_id: firstCellId,
@@ -416,7 +412,6 @@ describe("cell reducer", () => {
416
412
  timestamp: new Date(61).getTime() as Seconds,
417
413
  });
418
414
  cell = cells[0];
419
- expect(cell.output).not.toBe(null); // keep old output
420
415
  expect(cell).toMatchSnapshot("error response received");
421
416
 
422
417
  // INTERRUPT RESPONSE
@@ -426,7 +421,6 @@ describe("cell reducer", () => {
426
421
  cellId: firstCellId,
427
422
  });
428
423
  cell = cells[0];
429
- expect(cell.output).not.toBe(null); // keep old output
430
424
  // Queue
431
425
  actions.handleCellMessage({
432
426
  cell_id: firstCellId,
@@ -436,7 +430,6 @@ describe("cell reducer", () => {
436
430
  timestamp: new Date(40).getTime() as Seconds,
437
431
  });
438
432
  cell = cells[0];
439
- expect(cell.output).not.toBe(null); // keep old output
440
433
  // Running
441
434
  actions.handleCellMessage({
442
435
  cell_id: firstCellId,
@@ -446,7 +439,6 @@ describe("cell reducer", () => {
446
439
  timestamp: new Date(50).getTime() as Seconds,
447
440
  });
448
441
  cell = cells[0];
449
- expect(cell.output).not.toBe(null); // keep old output
450
442
  // Receive error
451
443
  actions.handleCellMessage({
452
444
  cell_id: firstCellId,
@@ -555,10 +547,6 @@ describe("cell reducer", () => {
555
547
  timestamp: new Date(20).getTime() as Seconds,
556
548
  });
557
549
  cell = cells[0];
558
- // oxlint-disable-next-line typescript/no-explicit-any no-unsafe-optional-chaining
559
- expect((cell.output?.data as any)[0].msg).toBe(
560
- "This cell wasn't run because an ancestor was stopped with `mo.stop`: ",
561
- );
562
550
  expect(cell).toMatchSnapshot("ancestor stopped");
563
551
 
564
552
  // Receive queued message
@@ -581,7 +569,6 @@ describe("cell reducer", () => {
581
569
  timestamp: new Date(40).getTime() as Seconds,
582
570
  });
583
571
  cell = cells[0];
584
- expect(cell.output).toBe(null);
585
572
  expect(cell).toMatchSnapshot("running after stop");
586
573
  });
587
574
 
@@ -920,40 +907,6 @@ describe("cell reducer", () => {
920
907
  `);
921
908
  });
922
909
 
923
- it("can clear output of a single cell", () => {
924
- // Set up initial state with output
925
- actions.handleCellMessage({
926
- cell_id: firstCellId,
927
- output: {
928
- channel: "output",
929
- mimetype: "text/plain",
930
- data: "test output",
931
- timestamp: 0,
932
- },
933
- console: {
934
- channel: "stdout",
935
- mimetype: "text/plain",
936
- data: "console output",
937
- timestamp: 0,
938
- },
939
- status: "idle",
940
- timestamp: new Date(33).getTime() as Seconds,
941
- });
942
-
943
- // Verify initial state has output
944
- let cell = cells[0];
945
- expect(cell.output).not.toBeNull();
946
- expect(cell.consoleOutputs.length).toBe(1);
947
-
948
- // Clear output
949
- actions.clearCellOutput({ cellId: firstCellId });
950
-
951
- // Verify output is cleared
952
- cell = cells[0];
953
- expect(cell.output).toBeNull();
954
- expect(cell.consoleOutputs).toEqual([]);
955
- });
956
-
957
910
  it("can clear console output of a single cell", () => {
958
911
  // Set up initial state with output
959
912
  actions.handleCellMessage({
@@ -987,9 +940,8 @@ describe("cell reducer", () => {
987
940
  timestamp: new Date(34).getTime() as Seconds,
988
941
  });
989
942
 
990
- // Verify initial state has output and console outputs
943
+ // Verify initial state has console outputs
991
944
  let cell = cells[0];
992
- expect(cell.output).not.toBeNull();
993
945
  expect(cell.consoleOutputs.length).toBe(2);
994
946
 
995
947
  // Clear console output
@@ -997,90 +949,11 @@ describe("cell reducer", () => {
997
949
 
998
950
  // Verify only console output is cleared, but stdin is preserved
999
951
  cell = cells[0];
1000
- expect(cell.output).not.toBeNull(); // Output should remain
1001
952
  expect(cell.consoleOutputs.length).toBe(1);
1002
953
  expect(cell.consoleOutputs[0].channel).toBe("stdin");
1003
954
  expect(cell.consoleOutputs[0].data).toBe("stdin prompt");
1004
955
  });
1005
956
 
1006
- it("can clear output of all cells", () => {
1007
- // Create multiple cells with output
1008
- seedCell({ cellId: firstCellId, before: false });
1009
- const secondCellId = state.cellIds[1];
1010
-
1011
- // Add output to both cells
1012
- const outputMessage = {
1013
- output: {
1014
- channel: "output",
1015
- mimetype: "text/plain",
1016
- data: "test output",
1017
- timestamp: 0,
1018
- },
1019
- console: {
1020
- channel: "stdout",
1021
- mimetype: "text/plain",
1022
- data: "console output",
1023
- timestamp: 0,
1024
- },
1025
- status: "idle",
1026
- timestamp: new Date(33).getTime() as Seconds,
1027
- } as const;
1028
-
1029
- actions.handleCellMessage({
1030
- ...outputMessage,
1031
- cell_id: firstCellId,
1032
- });
1033
- actions.handleCellMessage({
1034
- ...outputMessage,
1035
- cell_id: secondCellId,
1036
- });
1037
-
1038
- // Verify initial state has output
1039
- expect(state.cellRuntime[firstCellId].output).not.toBeNull();
1040
- expect(state.cellRuntime[firstCellId].consoleOutputs.length).toBe(1);
1041
- expect(state.cellRuntime[secondCellId].output).not.toBeNull();
1042
- expect(state.cellRuntime[secondCellId].consoleOutputs.length).toBe(1);
1043
-
1044
- // Clear all outputs
1045
- actions.clearAllCellOutputs();
1046
-
1047
- // Verify all outputs are cleared
1048
- expect(state.cellRuntime[firstCellId].output).toBeNull();
1049
- expect(state.cellRuntime[firstCellId].consoleOutputs).toEqual([]);
1050
- expect(state.cellRuntime[secondCellId].output).toBeNull();
1051
- expect(state.cellRuntime[secondCellId].consoleOutputs).toEqual([]);
1052
- });
1053
-
1054
- it("can clear all outputs", () => {
1055
- // Add a cell and give it output
1056
- seedCell({
1057
- cellId: firstCellId,
1058
- before: false,
1059
- });
1060
-
1061
- const cell1Id = cells[0].id;
1062
- const cell2Id = cells[1].id;
1063
-
1064
- // Manually set output for the cells
1065
- state.cellRuntime[cell1Id].output = {
1066
- channel: "output",
1067
- mimetype: "text/plain",
1068
- data: "output1",
1069
- timestamp: 0 as Seconds,
1070
- };
1071
- state.cellRuntime[cell2Id].output = {
1072
- channel: "output",
1073
- mimetype: "text/plain",
1074
- data: "output2",
1075
- timestamp: 0 as Seconds,
1076
- };
1077
-
1078
- actions.clearAllCellOutputs();
1079
-
1080
- expect(state.cellRuntime[cell1Id].output).toBeNull();
1081
- expect(state.cellRuntime[cell2Id].output).toBeNull();
1082
- });
1083
-
1084
957
  describe("releaseCellAtoms", () => {
1085
958
  it("atom families cache atoms until explicitly removed", () => {
1086
959
  const { cellDataAtom, cellRuntimeAtom, cellHandleAtom } =
@@ -1130,162 +1003,60 @@ describe("createTracebackInfoAtom", () => {
1130
1003
  expect(traceback).toBeUndefined();
1131
1004
  });
1132
1005
 
1133
- it("extracts lineno from syntax errors", async () => {
1134
- store.set(
1135
- notebookAtom,
1136
- MockNotebook.notebookState({
1137
- cellData: {
1138
- [cellId("cell1")]: {
1139
- id: cellId("cell1"),
1140
- name: "cell1",
1141
- code: "x = 1",
1142
- },
1143
- },
1144
- cellRuntime: {
1145
- [cellId("cell1")]: {
1146
- output: {
1147
- channel: "marimo-error",
1148
- data: [{ type: "syntax", msg: "Syntax error", lineno: 5 }],
1149
- mimetype: "application/vnd.marimo+error",
1150
- },
1151
- },
1152
- },
1153
- }),
1154
- );
1155
-
1156
- const tracebackAtom = exportedForTesting.createTracebackInfoAtom(
1157
- cellId("cell1"),
1158
- );
1159
- const traceback = store.get(tracebackAtom);
1160
-
1161
- expect(traceback).toBeDefined();
1162
- expect(traceback).toHaveLength(1);
1163
- expect(traceback![0]).toEqual({
1164
- kind: "cell",
1165
- cellId: cellId("cell1"),
1166
- lineNumber: 5,
1167
- });
1168
- });
1169
-
1170
- it("handles syntax errors with lineno = 0", async () => {
1006
+ it("extracts the line of a syntax error the host reports", () => {
1171
1007
  store.set(
1172
1008
  notebookAtom,
1173
1009
  MockNotebook.notebookState({
1174
- cellData: {
1175
- [cellId("cell1")]: {
1176
- id: cellId("cell1"),
1177
- name: "cell1",
1178
- code: "x = 1",
1179
- },
1180
- },
1181
- cellRuntime: {
1182
- [cellId("cell1")]: {
1183
- output: {
1184
- channel: "marimo-error",
1185
- data: [{ type: "syntax", msg: "Syntax error", lineno: 0 }],
1186
- mimetype: "application/vnd.marimo+error",
1187
- },
1188
- },
1189
- },
1010
+ cellData: { [cellId("cell1")]: { code: "x = 1" } },
1190
1011
  }),
1191
1012
  );
1192
-
1193
- const tracebackAtom = exportedForTesting.createTracebackInfoAtom(
1194
- cellId("cell1"),
1195
- );
1196
- const traceback = store.get(tracebackAtom);
1197
- expect(traceback).toBeDefined();
1198
- expect(traceback).toHaveLength(1);
1199
- expect(traceback![0].lineNumber).toBe(0);
1200
- });
1201
-
1202
- it("ignores syntax errors with lineno = null", () => {
1203
- store.set(
1204
- notebookAtom,
1205
- MockNotebook.notebookState({
1206
- cellData: {
1207
- [cellId("cell1")]: {
1208
- id: cellId("cell1"),
1209
- name: "cell1",
1210
- code: "x = 1",
1211
- },
1212
- },
1213
- cellRuntime: {
1214
- [cellId("cell1")]: {
1215
- output: {
1216
- channel: "marimo-error",
1217
- data: [{ type: "syntax", msg: "Syntax error", lineno: null }],
1218
- mimetype: "application/vnd.marimo+error",
1219
- },
1220
- },
1013
+ MockExecutions.seed(store, [
1014
+ MockExecutions.failed(cellId("cell1"), {
1015
+ kind: "invalid-syntax",
1016
+ message: "Syntax error",
1017
+ range: {
1018
+ start: { line: 4, character: 0 },
1019
+ end: { line: 4, character: 0 },
1221
1020
  },
1222
1021
  }),
1223
- );
1022
+ ]);
1224
1023
 
1225
1024
  const tracebackAtom = exportedForTesting.createTracebackInfoAtom(
1226
1025
  cellId("cell1"),
1227
1026
  );
1228
1027
  const traceback = store.get(tracebackAtom);
1229
1028
 
1230
- expect(traceback).toBeUndefined();
1029
+ expect(traceback).toEqual([
1030
+ { kind: "cell", cellId: cellId("cell1"), lineNumber: 5 },
1031
+ ]);
1231
1032
  });
1232
1033
 
1233
- it("handles multiple syntax errors", () => {
1034
+ it("ignores a syntax error without a range", () => {
1234
1035
  store.set(
1235
1036
  notebookAtom,
1236
1037
  MockNotebook.notebookState({
1237
- cellData: {
1238
- [cellId("cell1")]: {
1239
- id: cellId("cell1"),
1240
- name: "cell1",
1241
- code: "x = 1",
1242
- },
1243
- },
1244
- cellRuntime: {
1245
- [cellId("cell1")]: {
1246
- output: {
1247
- channel: "marimo-error",
1248
- data: [
1249
- { type: "syntax", msg: "Syntax error", lineno: 3 },
1250
- { type: "syntax", msg: "Syntax error", lineno: 7 },
1251
- ],
1252
- mimetype: "application/vnd.marimo+error",
1253
- },
1254
- },
1255
- },
1038
+ cellData: { [cellId("cell1")]: { code: "x = 1" } },
1256
1039
  }),
1257
1040
  );
1041
+ MockExecutions.seed(store, [
1042
+ MockExecutions.failed(cellId("cell1"), {
1043
+ kind: "invalid-syntax",
1044
+ message: "Syntax error",
1045
+ }),
1046
+ ]);
1258
1047
 
1259
1048
  const tracebackAtom = exportedForTesting.createTracebackInfoAtom(
1260
1049
  cellId("cell1"),
1261
1050
  );
1262
- const traceback = store.get(tracebackAtom);
1263
- expect(traceback).toBeDefined();
1264
- expect(traceback).toHaveLength(2);
1265
- expect(traceback![0].lineNumber).toBe(3);
1266
- expect(traceback![1].lineNumber).toBe(7);
1051
+
1052
+ expect(store.get(tracebackAtom)).toBeUndefined();
1267
1053
  });
1268
1054
 
1269
1055
  it("returns undefined when cell is queued", async () => {
1270
1056
  store.set(
1271
1057
  notebookAtom,
1272
1058
  MockNotebook.notebookState({
1273
- cellData: {
1274
- [cellId("cell1")]: {
1275
- id: cellId("cell1"),
1276
- name: "cell1",
1277
- code: "x = 1",
1278
- },
1279
- },
1280
- cellRuntime: {
1281
- [cellId("cell1")]: {
1282
- output: {
1283
- channel: "marimo-error",
1284
- data: [{ type: "syntax", msg: "Syntax error", lineno: 1 }],
1285
- mimetype: "application/vnd.marimo+error",
1286
- },
1287
- },
1288
- },
1059
+ cellData: { [cellId("cell1")]: { code: "x = 1" } },
1289
1060
  }),
1290
1061
  );
1291
1062
  MockExecutions.seed(store, [MockExecutions.queued(cellId("cell1"))]);
@@ -1302,22 +1073,7 @@ describe("createTracebackInfoAtom", () => {
1302
1073
  store.set(
1303
1074
  notebookAtom,
1304
1075
  MockNotebook.notebookState({
1305
- cellData: {
1306
- [cellId("cell1")]: {
1307
- id: cellId("cell1"),
1308
- name: "cell1",
1309
- code: "x = 1",
1310
- },
1311
- },
1312
- cellRuntime: {
1313
- [cellId("cell1")]: {
1314
- output: {
1315
- channel: "marimo-error",
1316
- data: [{ type: "syntax", msg: "Syntax error", lineno: 1 }],
1317
- mimetype: "application/vnd.marimo+error",
1318
- },
1319
- },
1320
- },
1076
+ cellData: { [cellId("cell1")]: { code: "x = 1" } },
1321
1077
  }),
1322
1078
  );
1323
1079
  MockExecutions.seed(store, [MockExecutions.running(cellId("cell1"))]);
@@ -1342,14 +1098,7 @@ describe("kernel-ready", () => {
1342
1098
  [CELL_B]: { id: CELL_B, code: "2" },
1343
1099
  },
1344
1100
  cellRuntime: {
1345
- [CELL_A]: {
1346
- output: {
1347
- channel: "output",
1348
- mimetype: "text/plain",
1349
- data: "hydrated-A",
1350
- timestamp: 0,
1351
- },
1352
- },
1101
+ [CELL_A]: { debuggerActive: true },
1353
1102
  [CELL_B]: {
1354
1103
  consoleOutputs: [
1355
1104
  {
@@ -1369,7 +1118,7 @@ describe("kernel-ready", () => {
1369
1118
  payload: undefined,
1370
1119
  });
1371
1120
 
1372
- expect(next.cellRuntime[CELL_A].output).toBeNull();
1121
+ expect(next.cellRuntime[CELL_A].debuggerActive).toBe(false);
1373
1122
  expect(next.cellRuntime[CELL_B].consoleOutputs).toEqual([]);
1374
1123
  });
1375
1124
 
@@ -1378,12 +1127,14 @@ describe("kernel-ready", () => {
1378
1127
  cellData: { [CELL_A]: { id: CELL_A, code: "1" } },
1379
1128
  cellRuntime: {
1380
1129
  [SCRATCH_CELL_ID]: {
1381
- output: {
1382
- channel: "output",
1383
- mimetype: "text/plain",
1384
- data: "scratch",
1385
- timestamp: 0,
1386
- },
1130
+ consoleOutputs: [
1131
+ {
1132
+ channel: "stdout",
1133
+ mimetype: "text/plain",
1134
+ data: "scratch",
1135
+ timestamp: 0,
1136
+ },
1137
+ ],
1387
1138
  },
1388
1139
  },
1389
1140
  });
@@ -1392,7 +1143,7 @@ describe("kernel-ready", () => {
1392
1143
  payload: undefined,
1393
1144
  });
1394
1145
 
1395
- expect(next.cellRuntime[SCRATCH_CELL_ID].output).toBeNull();
1146
+ expect(next.cellRuntime[SCRATCH_CELL_ID].consoleOutputs).toEqual([]);
1396
1147
  });
1397
1148
 
1398
1149
  describe("resetCellRuntimes in WASM", () => {
@@ -1406,15 +1157,13 @@ describe("kernel-ready", () => {
1406
1157
  vi.mocked(isWasm).mockReturnValue(false);
1407
1158
  });
1408
1159
 
1409
- it("keeps hydrated outputs and console", () => {
1160
+ it("keeps hydrated console output and starts the rest over", () => {
1410
1161
  const next = exportedForTesting.reducer(hydratedState(), {
1411
1162
  type: "resetCellRuntimes",
1412
1163
  payload: undefined,
1413
1164
  });
1414
1165
 
1415
- expect(next.cellRuntime[CELL_A].output).toMatchObject({
1416
- data: "hydrated-A",
1417
- });
1166
+ expect(next.cellRuntime[CELL_A].debuggerActive).toBe(false);
1418
1167
  expect(next.cellRuntime[CELL_B].consoleOutputs[0]).toMatchObject({
1419
1168
  data: "hydrated-B-stdout",
1420
1169
  });
@@ -1429,7 +1178,6 @@ describe("kernel-ready", () => {
1429
1178
  payload: undefined,
1430
1179
  });
1431
1180
 
1432
- expect(next.cellRuntime[CELL_A].output).toBeNull();
1433
1181
  expect(next.cellRuntime[CELL_A].consoleOutputs).toEqual([]);
1434
1182
  });
1435
1183
  });
@@ -0,0 +1,151 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { createStore } from "jotai";
4
+ import { describe, expect, it } from "vitest";
5
+ import { MockExecutions } from "@/__mocks__/executions";
6
+ import { MockNotebook } from "@/__mocks__/notebook";
7
+ import { cellId } from "@/__tests__/branded";
8
+ import { cellOutputAtom } from "@/core/executions";
9
+ import {
10
+ cell,
11
+ document,
12
+ withCells,
13
+ } from "@/core/notebook/document/__tests__/fixtures";
14
+ import { executions } from "@/core/notebook/replica/resources/executions";
15
+ import { clearAllCellOutputsAtom, clearCellOutputAtom } from "../actions";
16
+ import { notebookAtom } from "../cells";
17
+ import type { ConsoleOutputMessage } from "../types";
18
+
19
+ const A = cellId("a");
20
+ const B = cellId("b");
21
+ const DOCUMENT = withCells(document(), {
22
+ c1: null,
23
+ c2: null,
24
+ [A]: cell(A, ""),
25
+ [B]: cell(B, ""),
26
+ });
27
+
28
+ const STDOUT: ConsoleOutputMessage = {
29
+ channel: "stdout",
30
+ mimetype: "text/plain",
31
+ data: "printed",
32
+ timestamp: 0,
33
+ id: 1,
34
+ };
35
+ const PROMPT: ConsoleOutputMessage = {
36
+ channel: "stdin",
37
+ mimetype: "text/plain",
38
+ data: "name?",
39
+ timestamp: 0,
40
+ id: 2,
41
+ };
42
+
43
+ function setup() {
44
+ const store = createStore();
45
+ store.set(
46
+ notebookAtom,
47
+ MockNotebook.notebookState({
48
+ cellData: { [A]: {}, [B]: {} },
49
+ cellRuntime: {
50
+ [A]: { consoleOutputs: [STDOUT, PROMPT] },
51
+ [B]: { consoleOutputs: [STDOUT] },
52
+ },
53
+ }),
54
+ );
55
+ MockExecutions.seed(
56
+ store,
57
+ [
58
+ MockExecutions.shown(A, { mimetype: "text/plain", data: "a" }),
59
+ MockExecutions.shown(B, { mimetype: "text/plain", data: "b" }),
60
+ ],
61
+ null,
62
+ DOCUMENT,
63
+ );
64
+ return store;
65
+ }
66
+
67
+ describe("clearCellOutputAtom", () => {
68
+ it("hides the host's output and the console, keeping an unanswered prompt", () => {
69
+ const store = setup();
70
+ store.set(clearCellOutputAtom, { cellId: A });
71
+
72
+ expect(store.get(cellOutputAtom(A))).toBeNull();
73
+ expect(store.get(notebookAtom).cellRuntime[A].consoleOutputs).toEqual([
74
+ PROMPT,
75
+ ]);
76
+ expect(store.get(cellOutputAtom(B))?.data).toBe("b");
77
+ expect(store.get(notebookAtom).cellRuntime[B].consoleOutputs).toEqual([
78
+ STDOUT,
79
+ ]);
80
+ });
81
+ });
82
+
83
+ describe("clearing a running cell", () => {
84
+ it("hides what it shows until it shows something new", () => {
85
+ const store = createStore();
86
+ store.set(
87
+ notebookAtom,
88
+ MockNotebook.notebookState({ cellData: { [A]: {} } }),
89
+ );
90
+ const running = MockExecutions.shown(
91
+ A,
92
+ { mimetype: "text/plain", data: "so far" },
93
+ { status: "running", completed_at: null },
94
+ );
95
+ const replica = MockExecutions.seed(store, [running], null, DOCUMENT);
96
+ store.set(clearCellOutputAtom, { cellId: A });
97
+ expect(store.get(cellOutputAtom(A))).toBeNull();
98
+
99
+ store.set(replica.executionsAtom, (state) =>
100
+ executions.on.execution!(
101
+ state,
102
+ {
103
+ event: "execution",
104
+ id: "more",
105
+ data: {
106
+ execution: {
107
+ ...running,
108
+ outcome: {
109
+ kind: "value",
110
+ display: { mimetype: "text/plain", data: "more" },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ { phase: "live" },
116
+ ),
117
+ );
118
+ expect(store.get(cellOutputAtom(A))?.data).toBe("more");
119
+
120
+ store.set(replica.executionsAtom, (state) =>
121
+ executions.on.execution!(
122
+ state,
123
+ {
124
+ event: "execution",
125
+ id: "again",
126
+ data: { execution: { ...running, outcome: running.outcome } },
127
+ },
128
+ { phase: "live" },
129
+ ),
130
+ );
131
+ expect(store.get(cellOutputAtom(A))?.data).toBe("so far");
132
+ });
133
+ });
134
+
135
+ describe("clearAllCellOutputsAtom", () => {
136
+ it("clears every cell", () => {
137
+ const store = setup();
138
+ const before = store.get(notebookAtom);
139
+ Object.freeze(before.cellRuntime);
140
+ Object.values(before.cellRuntime).forEach(Object.freeze);
141
+ store.set(clearAllCellOutputsAtom);
142
+
143
+ expect(store.get(cellOutputAtom(A))).toBeNull();
144
+ expect(store.get(cellOutputAtom(B))).toBeNull();
145
+ const { cellRuntime } = store.get(notebookAtom);
146
+ expect(cellRuntime[A].consoleOutputs).toEqual([PROMPT]);
147
+ expect(cellRuntime[B].consoleOutputs).toEqual([]);
148
+ expect(before.cellRuntime[A].consoleOutputs).toEqual([STDOUT, PROMPT]);
149
+ expect(before.cellRuntime[B].consoleOutputs).toEqual([STDOUT]);
150
+ });
151
+ });