@marimo-team/islands 0.25.3-dev447 → 0.25.3-dev453
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ErrorBoundary-DVbdKroW.js → ErrorBoundary-CIYMOu2p.js} +1 -1
- package/dist/assets/__vite-browser-external-D2z_TiUO.js +1 -0
- package/dist/assets/{worker-BUqfWMtI.js → worker-DLJ9P24O.js} +2 -2
- package/dist/{chat-ui-9oyUBL6M.js → chat-ui-DEHpKH2l.js} +17 -19
- package/dist/{code-visibility-DmsDqWUx.js → code-visibility-BQE60zOk.js} +7 -7
- package/dist/{common-BDo_Jwoz.js → common-DfUux6zJ.js} +4902 -4893
- package/dist/{data-grid-overlay-editor-CpHB_knU.js → data-grid-overlay-editor-B9zW4oN1.js} +1 -1
- package/dist/{error-entries-CWdDf7iZ.js → error-entries-BG7ifiDg.js} +1368 -996
- package/dist/{feedback-button-B_Wmi4to.js → feedback-button-BEUh4iQQ.js} +129 -129
- package/dist/{glide-data-editor-CMiIW5WP.js → glide-data-editor-CbdIXPTZ.js} +3 -3
- package/dist/{globals-DaC3pk9F.js → globals-BkxG-Y8L.js} +1 -1
- package/dist/{html-to-image-CexRSGAZ.js → html-to-image-9HLBGrIx.js} +4115 -4103
- package/dist/main.js +6562 -6671
- package/dist/{number-overlay-editor-Dd4cOJ5I.js → number-overlay-editor-BFzdth50.js} +1 -1
- package/dist/{process-output-hcyVRJCC.js → process-output-B8HPq5iZ.js} +2 -2
- package/dist/{reveal-component-CTmvBdvu.js → reveal-component-DK_-9fAX.js} +166 -167
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +7 -4
- package/src/__mocks__/notebook.ts +20 -4
- package/src/components/editor/cell/DeleteButton.tsx +2 -2
- package/src/components/editor/cell/StopButton.tsx +2 -2
- package/src/components/editor/cell/useRunCells.ts +0 -3
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +1 -1
- package/src/components/editor/notebook-cell.tsx +4 -35
- package/src/components/editor/output/ansi-reduce.ts +124 -61
- package/src/components/editor/output/console/ConsoleOutput.tsx +7 -25
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +15 -44
- package/src/components/editor/renderers/cells-renderer.tsx +2 -5
- package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +1 -1
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +3 -6
- package/src/components/editor/stdin-blocking-alert.tsx +14 -18
- package/src/components/scratchpad/scratchpad.test.tsx +1 -1
- package/src/components/scratchpad/scratchpad.tsx +5 -6
- package/src/components/slides/__tests__/cell-output-block.test.tsx +2 -2
- package/src/components/slides/__tests__/slide-cell-view.test.tsx +2 -2
- package/src/components/tracing/tracing-spec.ts +11 -1
- package/src/components/tracing/tracing.tsx +4 -0
- package/src/core/ai/context/providers/__tests__/cell-output.test.ts +10 -20
- package/src/core/ai/context/providers/__tests__/error.test.ts +5 -27
- package/src/core/ai/context/providers/cell-output.ts +4 -12
- package/src/core/cells/__tests__/cell.test.ts +1 -169
- package/src/core/cells/__tests__/cells.test.ts +32 -709
- package/src/core/cells/__tests__/clear-outputs.test.ts +21 -14
- package/src/core/cells/__tests__/collapseConsoleOutputs.test.ts +71 -2
- package/src/core/cells/__tests__/logs.test.ts +18 -29
- package/src/core/cells/__tests__/runs.test.ts +128 -431
- package/src/core/cells/__tests__/session.test.ts +9 -9
- package/src/core/cells/actions.ts +29 -7
- package/src/core/cells/cell.ts +1 -96
- package/src/core/cells/cells.ts +147 -117
- package/src/core/cells/collapseConsoleOutputs.tsx +71 -40
- package/src/core/cells/command-console.ts +46 -0
- package/src/core/cells/execution-console.ts +230 -0
- package/src/core/cells/focus.ts +9 -29
- package/src/core/cells/logs.ts +10 -2
- package/src/core/cells/runs.ts +62 -118
- package/src/core/cells/session.ts +2 -2
- package/src/core/cells/types.ts +30 -23
- package/src/core/cells/useAnswerPrompt.ts +29 -0
- package/src/core/errors/error-entries.ts +3 -4
- package/src/core/executions/__tests__/atoms.test.ts +6 -20
- package/src/core/executions/__tests__/input.test.ts +3 -3
- package/src/core/executions/__tests__/output-lifecycle.test.ts +2 -8
- package/src/core/executions/atoms.ts +2 -21
- package/src/core/executions/index.ts +2 -1
- package/src/core/executions/input.ts +4 -3
- package/src/core/executions/output.ts +3 -3
- package/src/core/islands/__tests__/bridge.test.ts +59 -0
- package/src/core/islands/bootstrap.ts +29 -12
- package/src/core/islands/bridge.ts +67 -13
- package/src/core/kernel/handlers.ts +2 -21
- package/src/core/kernel/messages.ts +0 -1
- package/src/core/network/types.ts +0 -1
- package/src/core/notebook/document/__tests__/codemirror.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/executions.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +113 -0
- package/src/core/notebook/replica/replica.ts +106 -12
- package/src/core/notebook/replica/resources/executions.ts +57 -4
- package/src/core/session/__tests__/backend.test.ts +2 -4
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +1 -0
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +601 -35
- package/src/core/session/useNotebookReplica.ts +20 -6
- package/src/core/session/useNotebookSession.tsx +63 -33
- package/src/core/static/virtual-file-tracker.ts +26 -8
- package/src/stories/layout/vertical/one-column.stories.tsx +18 -12
- package/dist/assets/__vite-browser-external-CpRgw4M_.js +0 -1
- package/src/components/editor/alerts/stdin-blocking-alert.tsx +0 -68
- package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +0 -703
|
@@ -25,14 +25,12 @@ import { CellId, SCRATCH_CELL_ID } from "@/core/cells/ids";
|
|
|
25
25
|
import { foldAllBulk, unfoldAllBulk } from "@/core/codemirror/editing/commands";
|
|
26
26
|
import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
|
|
27
27
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
28
|
-
import type { OutputMessage } from "@/core/kernel/messages";
|
|
29
28
|
import type { CellConfig } from "@/core/network/types";
|
|
30
|
-
import type { Seconds } from "@/utils/time";
|
|
31
29
|
import {
|
|
32
30
|
exportedForTesting,
|
|
33
|
-
flattenTopLevelNotebookCells,
|
|
34
31
|
type NotebookState,
|
|
35
32
|
notebookAtom,
|
|
33
|
+
renderedNotebookCellsAtom,
|
|
36
34
|
} from "../cells";
|
|
37
35
|
import {
|
|
38
36
|
type CellData,
|
|
@@ -107,7 +105,6 @@ function createEditor(content: string) {
|
|
|
107
105
|
|
|
108
106
|
describe("cell reducer", () => {
|
|
109
107
|
let state: NotebookState;
|
|
110
|
-
let cells: ReturnType<typeof flattenTopLevelNotebookCells>;
|
|
111
108
|
let firstCellId: CellId;
|
|
112
109
|
|
|
113
110
|
const mountEditors = () => {
|
|
@@ -123,7 +120,6 @@ describe("cell reducer", () => {
|
|
|
123
120
|
state.cellHandles[cid] = { current: handle };
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
|
-
cells = flattenTopLevelNotebookCells(state, new Map());
|
|
127
123
|
};
|
|
128
124
|
const actions = createActions((action) => {
|
|
129
125
|
state = reducer(state, action);
|
|
@@ -232,619 +228,6 @@ describe("cell reducer", () => {
|
|
|
232
228
|
`);
|
|
233
229
|
});
|
|
234
230
|
|
|
235
|
-
it("keeps error evidence after an edit and a new queued run", () => {
|
|
236
|
-
const code = "raise ValueError('old failure')";
|
|
237
|
-
const output: OutputMessage = {
|
|
238
|
-
channel: "marimo-error",
|
|
239
|
-
mimetype: "application/vnd.marimo+error",
|
|
240
|
-
data: [
|
|
241
|
-
{
|
|
242
|
-
type: "exception",
|
|
243
|
-
msg: "old failure",
|
|
244
|
-
exception_type: "ValueError",
|
|
245
|
-
raising_cell: null,
|
|
246
|
-
traceback: "<pre>ValueError: old failure</pre>",
|
|
247
|
-
},
|
|
248
|
-
],
|
|
249
|
-
code,
|
|
250
|
-
timestamp: 1,
|
|
251
|
-
};
|
|
252
|
-
actions.handleCellMessage({
|
|
253
|
-
cell_id: firstCellId,
|
|
254
|
-
output,
|
|
255
|
-
console: {
|
|
256
|
-
channel: "stderr",
|
|
257
|
-
mimetype: "application/vnd.marimo+traceback",
|
|
258
|
-
data: "<pre>ValueError: old failure</pre>",
|
|
259
|
-
code,
|
|
260
|
-
timestamp: 1,
|
|
261
|
-
},
|
|
262
|
-
status: "idle",
|
|
263
|
-
timestamp: 1,
|
|
264
|
-
});
|
|
265
|
-
editCode(firstCellId, "print('new code')");
|
|
266
|
-
actions.prepareForRun({ cellId: firstCellId });
|
|
267
|
-
actions.handleCellMessage({
|
|
268
|
-
cell_id: firstCellId,
|
|
269
|
-
output: null,
|
|
270
|
-
console: null,
|
|
271
|
-
status: "queued",
|
|
272
|
-
timestamp: 2,
|
|
273
|
-
});
|
|
274
|
-
const runtime = state.cellRuntime[firstCellId];
|
|
275
|
-
expect(runtime.consoleOutputs[0].code).toBe(code);
|
|
276
|
-
expect(runtime.consoleOutputs[0].data).toContain("old failure");
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("can run cell and receive cell messages", () => {
|
|
280
|
-
// HAPPY PATH
|
|
281
|
-
/////////////////
|
|
282
|
-
// Initial state
|
|
283
|
-
let cell = cells[0];
|
|
284
|
-
expect(cell).toMatchSnapshot("initial state");
|
|
285
|
-
|
|
286
|
-
// Update code
|
|
287
|
-
editCode(firstCellId, "import marimo as mo");
|
|
288
|
-
cell = cells[0];
|
|
289
|
-
expect(cell).toMatchSnapshot("code edited");
|
|
290
|
-
|
|
291
|
-
// Prepare for run
|
|
292
|
-
actions.prepareForRun({
|
|
293
|
-
cellId: firstCellId,
|
|
294
|
-
});
|
|
295
|
-
cell = cells[0];
|
|
296
|
-
expect(cell).toMatchSnapshot("prepared for run");
|
|
297
|
-
|
|
298
|
-
// Receive queued messages
|
|
299
|
-
actions.handleCellMessage({
|
|
300
|
-
cell_id: firstCellId,
|
|
301
|
-
output: undefined,
|
|
302
|
-
console: null,
|
|
303
|
-
status: "queued",
|
|
304
|
-
timestamp: new Date(10).getTime() as Seconds,
|
|
305
|
-
});
|
|
306
|
-
cell = cells[0];
|
|
307
|
-
expect(cell).toMatchSnapshot("queued message received");
|
|
308
|
-
|
|
309
|
-
// Receive running messages
|
|
310
|
-
actions.handleCellMessage({
|
|
311
|
-
cell_id: firstCellId,
|
|
312
|
-
output: undefined,
|
|
313
|
-
console: null,
|
|
314
|
-
status: "running",
|
|
315
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
316
|
-
});
|
|
317
|
-
cell = cells[0];
|
|
318
|
-
expect(cell).toMatchSnapshot("running message received");
|
|
319
|
-
|
|
320
|
-
// Console messages shouldn't transition status
|
|
321
|
-
actions.handleCellMessage({
|
|
322
|
-
cell_id: firstCellId,
|
|
323
|
-
output: undefined,
|
|
324
|
-
console: {
|
|
325
|
-
channel: "stdout",
|
|
326
|
-
mimetype: "text/plain",
|
|
327
|
-
data: "hello!",
|
|
328
|
-
timestamp: 0,
|
|
329
|
-
},
|
|
330
|
-
status: undefined,
|
|
331
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
332
|
-
});
|
|
333
|
-
cell = cells[0];
|
|
334
|
-
expect(cell).toMatchSnapshot("console message received");
|
|
335
|
-
|
|
336
|
-
// Receive output messages
|
|
337
|
-
actions.handleCellMessage({
|
|
338
|
-
cell_id: firstCellId,
|
|
339
|
-
output: {
|
|
340
|
-
channel: "output",
|
|
341
|
-
mimetype: "text/plain",
|
|
342
|
-
data: "ok",
|
|
343
|
-
timestamp: 0,
|
|
344
|
-
},
|
|
345
|
-
console: {
|
|
346
|
-
channel: "stdout",
|
|
347
|
-
mimetype: "text/plain",
|
|
348
|
-
data: "hello!",
|
|
349
|
-
timestamp: 0,
|
|
350
|
-
},
|
|
351
|
-
status: "idle",
|
|
352
|
-
timestamp: new Date(33).getTime() as Seconds,
|
|
353
|
-
});
|
|
354
|
-
cell = cells[0];
|
|
355
|
-
expect(cell).toMatchSnapshot("output received");
|
|
356
|
-
|
|
357
|
-
// EDITING BACK AND FORTH
|
|
358
|
-
/////////////////
|
|
359
|
-
// Update code again
|
|
360
|
-
editCode(firstCellId, "import marimo as mo\nimport numpy");
|
|
361
|
-
cell = cells[0];
|
|
362
|
-
expect(cell).toMatchSnapshot("code edited again");
|
|
363
|
-
|
|
364
|
-
// Update code should be unedited
|
|
365
|
-
editCode(firstCellId, "import marimo as mo");
|
|
366
|
-
cell = cells[0];
|
|
367
|
-
expect(cell).toMatchSnapshot("code reverted");
|
|
368
|
-
|
|
369
|
-
// Update code should be edited again
|
|
370
|
-
editCode(firstCellId, "import marimo as mo\nimport numpy");
|
|
371
|
-
cell = cells[0];
|
|
372
|
-
expect(cell).toMatchSnapshot("code changed after revert");
|
|
373
|
-
|
|
374
|
-
// ERROR RESPONSE
|
|
375
|
-
/////////////////
|
|
376
|
-
// Prepare for run
|
|
377
|
-
actions.prepareForRun({
|
|
378
|
-
cellId: firstCellId,
|
|
379
|
-
});
|
|
380
|
-
cell = cells[0];
|
|
381
|
-
// Queue
|
|
382
|
-
actions.handleCellMessage({
|
|
383
|
-
cell_id: firstCellId,
|
|
384
|
-
output: undefined,
|
|
385
|
-
console: null,
|
|
386
|
-
status: "queued",
|
|
387
|
-
timestamp: new Date(40).getTime() as Seconds,
|
|
388
|
-
});
|
|
389
|
-
cell = cells[0];
|
|
390
|
-
// Running
|
|
391
|
-
actions.handleCellMessage({
|
|
392
|
-
cell_id: firstCellId,
|
|
393
|
-
output: undefined,
|
|
394
|
-
console: null,
|
|
395
|
-
status: "running",
|
|
396
|
-
timestamp: new Date(50).getTime() as Seconds,
|
|
397
|
-
});
|
|
398
|
-
cell = cells[0];
|
|
399
|
-
// Receive error
|
|
400
|
-
actions.handleCellMessage({
|
|
401
|
-
cell_id: firstCellId,
|
|
402
|
-
output: {
|
|
403
|
-
channel: "marimo-error",
|
|
404
|
-
mimetype: "application/vnd.marimo+error",
|
|
405
|
-
data: [
|
|
406
|
-
{ type: "exception", exception_type: "ValueError", msg: "Oh no!" },
|
|
407
|
-
],
|
|
408
|
-
timestamp: 0,
|
|
409
|
-
},
|
|
410
|
-
console: null,
|
|
411
|
-
status: "idle",
|
|
412
|
-
timestamp: new Date(61).getTime() as Seconds,
|
|
413
|
-
});
|
|
414
|
-
cell = cells[0];
|
|
415
|
-
expect(cell).toMatchSnapshot("error response received");
|
|
416
|
-
|
|
417
|
-
// INTERRUPT RESPONSE
|
|
418
|
-
/////////////////
|
|
419
|
-
// Prepare for run
|
|
420
|
-
actions.prepareForRun({
|
|
421
|
-
cellId: firstCellId,
|
|
422
|
-
});
|
|
423
|
-
cell = cells[0];
|
|
424
|
-
// Queue
|
|
425
|
-
actions.handleCellMessage({
|
|
426
|
-
cell_id: firstCellId,
|
|
427
|
-
output: undefined,
|
|
428
|
-
console: null,
|
|
429
|
-
status: "queued",
|
|
430
|
-
timestamp: new Date(40).getTime() as Seconds,
|
|
431
|
-
});
|
|
432
|
-
cell = cells[0];
|
|
433
|
-
// Running
|
|
434
|
-
actions.handleCellMessage({
|
|
435
|
-
cell_id: firstCellId,
|
|
436
|
-
output: undefined,
|
|
437
|
-
console: null,
|
|
438
|
-
status: "running",
|
|
439
|
-
timestamp: new Date(50).getTime() as Seconds,
|
|
440
|
-
});
|
|
441
|
-
cell = cells[0];
|
|
442
|
-
// Receive error
|
|
443
|
-
actions.handleCellMessage({
|
|
444
|
-
cell_id: firstCellId,
|
|
445
|
-
output: {
|
|
446
|
-
channel: "marimo-error",
|
|
447
|
-
mimetype: "application/vnd.marimo+error",
|
|
448
|
-
data: [{ type: "interruption" }],
|
|
449
|
-
timestamp: 0,
|
|
450
|
-
},
|
|
451
|
-
console: null,
|
|
452
|
-
status: "idle",
|
|
453
|
-
timestamp: new Date(61).getTime() as Seconds,
|
|
454
|
-
});
|
|
455
|
-
cell = cells[0];
|
|
456
|
-
expect(cell).toMatchSnapshot("interruption response received");
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it("can run a stale cell", () => {
|
|
460
|
-
// Update code of first cell
|
|
461
|
-
editCode(firstCellId, "import marimo as mo");
|
|
462
|
-
// Add cell
|
|
463
|
-
seedCell({
|
|
464
|
-
cellId: firstCellId,
|
|
465
|
-
before: false,
|
|
466
|
-
});
|
|
467
|
-
const secondCell = cells[1].id;
|
|
468
|
-
// Update code
|
|
469
|
-
editCode(secondCell, "mo.slider()");
|
|
470
|
-
|
|
471
|
-
// Prepare for run
|
|
472
|
-
actions.prepareForRun({
|
|
473
|
-
cellId: secondCell,
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
// Receive queued messages
|
|
477
|
-
actions.handleCellMessage({
|
|
478
|
-
cell_id: secondCell,
|
|
479
|
-
output: undefined,
|
|
480
|
-
console: null,
|
|
481
|
-
status: "queued",
|
|
482
|
-
timestamp: new Date(10).getTime() as Seconds,
|
|
483
|
-
});
|
|
484
|
-
let cell = cells[1];
|
|
485
|
-
expect(cell).toMatchSnapshot("queued message received");
|
|
486
|
-
|
|
487
|
-
// Receive stale message
|
|
488
|
-
actions.handleCellMessage({
|
|
489
|
-
cell_id: secondCell,
|
|
490
|
-
output: undefined,
|
|
491
|
-
console: null,
|
|
492
|
-
status: undefined,
|
|
493
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
494
|
-
});
|
|
495
|
-
cell = cells[1];
|
|
496
|
-
expect(cell).toMatchSnapshot("stale inputs received");
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
it("can run a stopped cell", () => {
|
|
500
|
-
// Update code of first cell
|
|
501
|
-
editCode(firstCellId, "mo.md('This has an ancestor that was stopped')");
|
|
502
|
-
|
|
503
|
-
// Prepare for run
|
|
504
|
-
actions.prepareForRun({
|
|
505
|
-
cellId: firstCellId,
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
// Receive queued messages
|
|
509
|
-
actions.handleCellMessage({
|
|
510
|
-
cell_id: firstCellId,
|
|
511
|
-
output: undefined,
|
|
512
|
-
console: null,
|
|
513
|
-
status: "queued",
|
|
514
|
-
timestamp: new Date(10).getTime() as Seconds,
|
|
515
|
-
});
|
|
516
|
-
let cell = cells[0];
|
|
517
|
-
expect(cell).toMatchSnapshot("queued message received");
|
|
518
|
-
|
|
519
|
-
// Receive idle message
|
|
520
|
-
actions.handleCellMessage({
|
|
521
|
-
cell_id: firstCellId,
|
|
522
|
-
output: undefined,
|
|
523
|
-
console: null,
|
|
524
|
-
status: "idle",
|
|
525
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
526
|
-
});
|
|
527
|
-
cell = cells[0];
|
|
528
|
-
expect(cell).toMatchSnapshot("idle message received");
|
|
529
|
-
|
|
530
|
-
// Receive stop output
|
|
531
|
-
actions.handleCellMessage({
|
|
532
|
-
cell_id: firstCellId,
|
|
533
|
-
output: {
|
|
534
|
-
channel: "marimo-error",
|
|
535
|
-
mimetype: "application/vnd.marimo+error",
|
|
536
|
-
data: [
|
|
537
|
-
{
|
|
538
|
-
msg: "This cell wasn't run because an ancestor was stopped with `mo.stop`: ",
|
|
539
|
-
raising_cell: "2",
|
|
540
|
-
type: "ancestor-stopped",
|
|
541
|
-
},
|
|
542
|
-
],
|
|
543
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
544
|
-
},
|
|
545
|
-
console: null,
|
|
546
|
-
status: "idle",
|
|
547
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
548
|
-
});
|
|
549
|
-
cell = cells[0];
|
|
550
|
-
expect(cell).toMatchSnapshot("ancestor stopped");
|
|
551
|
-
|
|
552
|
-
// Receive queued message
|
|
553
|
-
actions.handleCellMessage({
|
|
554
|
-
cell_id: firstCellId,
|
|
555
|
-
output: undefined,
|
|
556
|
-
console: null,
|
|
557
|
-
status: "queued",
|
|
558
|
-
timestamp: new Date(30).getTime() as Seconds,
|
|
559
|
-
});
|
|
560
|
-
cell = cells[0];
|
|
561
|
-
expect(cell).toMatchSnapshot("queued after stop");
|
|
562
|
-
|
|
563
|
-
// Receive running message
|
|
564
|
-
actions.handleCellMessage({
|
|
565
|
-
cell_id: firstCellId,
|
|
566
|
-
output: undefined,
|
|
567
|
-
console: null,
|
|
568
|
-
status: "running",
|
|
569
|
-
timestamp: new Date(40).getTime() as Seconds,
|
|
570
|
-
});
|
|
571
|
-
cell = cells[0];
|
|
572
|
-
expect(cell).toMatchSnapshot("running after stop");
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
it("can initialize stdin", () => {
|
|
576
|
-
const STDOUT: OutputMessage = {
|
|
577
|
-
channel: "stdout",
|
|
578
|
-
mimetype: "text/plain",
|
|
579
|
-
data: "hello!",
|
|
580
|
-
timestamp: 1,
|
|
581
|
-
};
|
|
582
|
-
const STD_IN_1: OutputMessage = {
|
|
583
|
-
channel: "stdin",
|
|
584
|
-
mimetype: "text/plain",
|
|
585
|
-
data: "what is your name?",
|
|
586
|
-
timestamp: 2,
|
|
587
|
-
};
|
|
588
|
-
const STD_IN_2: OutputMessage = {
|
|
589
|
-
channel: "stdin",
|
|
590
|
-
mimetype: "text/plain",
|
|
591
|
-
data: "how old are you?",
|
|
592
|
-
timestamp: 3,
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
// Initial state
|
|
596
|
-
let cell = cells[0];
|
|
597
|
-
expect(cell.consoleOutputs).toEqual([]);
|
|
598
|
-
expect(cell).toMatchSnapshot("initial state");
|
|
599
|
-
|
|
600
|
-
// Prepare for run
|
|
601
|
-
actions.prepareForRun({
|
|
602
|
-
cellId: firstCellId,
|
|
603
|
-
});
|
|
604
|
-
cell = cells[0];
|
|
605
|
-
expect(cell.consoleOutputs).toEqual([]);
|
|
606
|
-
expect(cell).toMatchSnapshot("prepared for run");
|
|
607
|
-
|
|
608
|
-
// Receive queued messages
|
|
609
|
-
actions.handleCellMessage({
|
|
610
|
-
cell_id: firstCellId,
|
|
611
|
-
output: undefined,
|
|
612
|
-
console: null,
|
|
613
|
-
status: "queued",
|
|
614
|
-
timestamp: new Date(10).getTime() as Seconds,
|
|
615
|
-
});
|
|
616
|
-
cell = cells[0];
|
|
617
|
-
expect(cell).toMatchSnapshot("queued message received");
|
|
618
|
-
|
|
619
|
-
// Receive running messages
|
|
620
|
-
actions.handleCellMessage({
|
|
621
|
-
cell_id: firstCellId,
|
|
622
|
-
output: undefined,
|
|
623
|
-
console: null,
|
|
624
|
-
status: "running",
|
|
625
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
626
|
-
});
|
|
627
|
-
cell = cells[0];
|
|
628
|
-
expect(cell).toMatchSnapshot("running message received");
|
|
629
|
-
|
|
630
|
-
// Add console
|
|
631
|
-
actions.handleCellMessage({
|
|
632
|
-
cell_id: firstCellId,
|
|
633
|
-
output: undefined,
|
|
634
|
-
console: STDOUT,
|
|
635
|
-
status: undefined,
|
|
636
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
637
|
-
});
|
|
638
|
-
cell = cells[0];
|
|
639
|
-
expect(cell).toMatchSnapshot("stdout received");
|
|
640
|
-
|
|
641
|
-
cell = cells[0];
|
|
642
|
-
expect(cell.consoleOutputs[0]).toMatchObject(STDOUT);
|
|
643
|
-
expect(cell).toMatchSnapshot("stdout verified");
|
|
644
|
-
|
|
645
|
-
// Ask via stdin
|
|
646
|
-
actions.handleCellMessage({
|
|
647
|
-
cell_id: firstCellId,
|
|
648
|
-
output: undefined,
|
|
649
|
-
console: STD_IN_1,
|
|
650
|
-
status: undefined,
|
|
651
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
652
|
-
});
|
|
653
|
-
cell = cells[0];
|
|
654
|
-
expect(cell.consoleOutputs[0]).toMatchObject(STDOUT);
|
|
655
|
-
expect(cell.consoleOutputs[1]).toMatchObject(STD_IN_1);
|
|
656
|
-
expect(cell).toMatchSnapshot("stdin requested");
|
|
657
|
-
|
|
658
|
-
// Response to stdin
|
|
659
|
-
actions.setStdinResponse({
|
|
660
|
-
response: "Marimo!",
|
|
661
|
-
cellId: firstCellId,
|
|
662
|
-
outputIndex: 1,
|
|
663
|
-
});
|
|
664
|
-
cell = cells[0];
|
|
665
|
-
expect(cell.consoleOutputs[1]).toMatchObject({
|
|
666
|
-
...STD_IN_1,
|
|
667
|
-
response: "Marimo!",
|
|
668
|
-
});
|
|
669
|
-
expect(cell).toMatchSnapshot("stdin answered");
|
|
670
|
-
|
|
671
|
-
// Ask via stdin, again
|
|
672
|
-
actions.handleCellMessage({
|
|
673
|
-
cell_id: firstCellId,
|
|
674
|
-
output: undefined,
|
|
675
|
-
console: STD_IN_2,
|
|
676
|
-
status: undefined,
|
|
677
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
678
|
-
});
|
|
679
|
-
cell = cells[0];
|
|
680
|
-
expect(cell.consoleOutputs).toMatchObject([
|
|
681
|
-
STDOUT,
|
|
682
|
-
{ ...STD_IN_1, response: "Marimo!" },
|
|
683
|
-
STD_IN_2,
|
|
684
|
-
]);
|
|
685
|
-
expect(cell).toMatchSnapshot("second stdin requested");
|
|
686
|
-
|
|
687
|
-
// Interrupt, so we respond with ""
|
|
688
|
-
actions.handleCellMessage({
|
|
689
|
-
cell_id: firstCellId,
|
|
690
|
-
output: {
|
|
691
|
-
channel: "marimo-error",
|
|
692
|
-
mimetype: "application/vnd.marimo+error",
|
|
693
|
-
data: [{ type: "interruption" }],
|
|
694
|
-
timestamp: 0,
|
|
695
|
-
},
|
|
696
|
-
console: null,
|
|
697
|
-
status: "idle",
|
|
698
|
-
timestamp: new Date(61).getTime() as Seconds,
|
|
699
|
-
});
|
|
700
|
-
cell = cells[0];
|
|
701
|
-
expect(cell.consoleOutputs).toMatchObject([
|
|
702
|
-
STDOUT,
|
|
703
|
-
{ ...STD_IN_1, response: "Marimo!" },
|
|
704
|
-
{ ...STD_IN_2, response: "" },
|
|
705
|
-
]);
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
it("resolves password prompts without retaining the response", () => {
|
|
709
|
-
const prompt: OutputMessage = {
|
|
710
|
-
channel: "stdin",
|
|
711
|
-
mimetype: "text/password",
|
|
712
|
-
data: "Password: ",
|
|
713
|
-
timestamp: 1,
|
|
714
|
-
};
|
|
715
|
-
actions.handleCellMessage({
|
|
716
|
-
cell_id: firstCellId,
|
|
717
|
-
output: undefined,
|
|
718
|
-
console: prompt,
|
|
719
|
-
status: "running",
|
|
720
|
-
timestamp: 1 as Seconds,
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
const secret = "getpass-regression-secret";
|
|
724
|
-
actions.setStdinResponse({
|
|
725
|
-
cellId: firstCellId,
|
|
726
|
-
outputIndex: 0,
|
|
727
|
-
response: secret,
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
expect(cells[0].consoleOutputs).toEqual([
|
|
731
|
-
{ ...prompt, id: 1, response: "" },
|
|
732
|
-
]);
|
|
733
|
-
expect(JSON.stringify(cells[0].consoleOutputs)).not.toContain(secret);
|
|
734
|
-
});
|
|
735
|
-
|
|
736
|
-
it("does not crash when setStdinResponse has out-of-bounds outputIndex", () => {
|
|
737
|
-
const STDOUT: OutputMessage = {
|
|
738
|
-
channel: "stdout",
|
|
739
|
-
mimetype: "text/plain",
|
|
740
|
-
data: "hello!",
|
|
741
|
-
timestamp: 1,
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
// Set the cell to running with a console output
|
|
745
|
-
actions.prepareForRun({ cellId: firstCellId });
|
|
746
|
-
actions.handleCellMessage({
|
|
747
|
-
cell_id: firstCellId,
|
|
748
|
-
output: undefined,
|
|
749
|
-
console: null,
|
|
750
|
-
status: "running",
|
|
751
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
752
|
-
});
|
|
753
|
-
actions.handleCellMessage({
|
|
754
|
-
cell_id: firstCellId,
|
|
755
|
-
output: undefined,
|
|
756
|
-
console: STDOUT,
|
|
757
|
-
status: undefined,
|
|
758
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
// Try to set stdin response with an out-of-bounds index
|
|
762
|
-
// This should not crash - it should return state unchanged
|
|
763
|
-
actions.setStdinResponse({
|
|
764
|
-
response: "test",
|
|
765
|
-
cellId: firstCellId,
|
|
766
|
-
outputIndex: 999,
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
// Cell state should be unchanged
|
|
770
|
-
const cell = cells[0];
|
|
771
|
-
expect(cell.consoleOutputs).toHaveLength(1);
|
|
772
|
-
expect(cell.consoleOutputs[0]).toMatchObject(STDOUT);
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
it("can receive console when the cell is idle and will clear when starts again", () => {
|
|
776
|
-
const OLD_STDOUT: OutputMessage = {
|
|
777
|
-
channel: "stdout",
|
|
778
|
-
mimetype: "text/plain",
|
|
779
|
-
data: "hello!",
|
|
780
|
-
timestamp: 1,
|
|
781
|
-
};
|
|
782
|
-
const STDOUT: OutputMessage = {
|
|
783
|
-
channel: "stdin",
|
|
784
|
-
mimetype: "text/plain",
|
|
785
|
-
data: "hello again!",
|
|
786
|
-
timestamp: 2,
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
// Initial state
|
|
790
|
-
let cell = cells[0];
|
|
791
|
-
expect(cell.consoleOutputs).toEqual([]);
|
|
792
|
-
expect(cell).toMatchSnapshot("initial state");
|
|
793
|
-
|
|
794
|
-
// Add console
|
|
795
|
-
actions.handleCellMessage({
|
|
796
|
-
cell_id: firstCellId,
|
|
797
|
-
output: undefined,
|
|
798
|
-
console: [OLD_STDOUT],
|
|
799
|
-
status: undefined,
|
|
800
|
-
timestamp: new Date(1).getTime() as Seconds,
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
// Prepare for run
|
|
804
|
-
actions.prepareForRun({
|
|
805
|
-
cellId: firstCellId,
|
|
806
|
-
});
|
|
807
|
-
cell = cells[0];
|
|
808
|
-
expect(cell.consoleOutputs).toMatchObject([OLD_STDOUT]); // Old stays there until it starts running
|
|
809
|
-
expect(cell).toMatchSnapshot("prepared for run");
|
|
810
|
-
|
|
811
|
-
// Receive queued messages
|
|
812
|
-
actions.handleCellMessage({
|
|
813
|
-
cell_id: firstCellId,
|
|
814
|
-
output: undefined,
|
|
815
|
-
console: null,
|
|
816
|
-
status: "queued",
|
|
817
|
-
timestamp: new Date(10).getTime() as Seconds,
|
|
818
|
-
});
|
|
819
|
-
cell = cells[0];
|
|
820
|
-
expect(cell.consoleOutputs).toMatchObject([OLD_STDOUT]); // Old stays there until it starts running
|
|
821
|
-
expect(cell).toMatchSnapshot("queued message received");
|
|
822
|
-
|
|
823
|
-
// Receive running messages
|
|
824
|
-
actions.handleCellMessage({
|
|
825
|
-
cell_id: firstCellId,
|
|
826
|
-
output: undefined,
|
|
827
|
-
console: [], // Backend sends an empty array to clearu
|
|
828
|
-
status: "running",
|
|
829
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
830
|
-
});
|
|
831
|
-
cell = cells[0];
|
|
832
|
-
expect(cell.consoleOutputs).toMatchObject([]);
|
|
833
|
-
expect(cell).toMatchSnapshot("console cleared while running");
|
|
834
|
-
|
|
835
|
-
// Add console
|
|
836
|
-
actions.handleCellMessage({
|
|
837
|
-
cell_id: firstCellId,
|
|
838
|
-
output: undefined,
|
|
839
|
-
console: [STDOUT],
|
|
840
|
-
status: "idle",
|
|
841
|
-
timestamp: new Date(22).getTime() as Seconds,
|
|
842
|
-
});
|
|
843
|
-
cell = cells[0];
|
|
844
|
-
expect(cell.consoleOutputs).toMatchObject([STDOUT]);
|
|
845
|
-
expect(cell).toMatchSnapshot("console received while idle");
|
|
846
|
-
});
|
|
847
|
-
|
|
848
231
|
it("can fold and unfold all cells", () => {
|
|
849
232
|
actions.foldAll();
|
|
850
233
|
expect(foldAllBulk).toHaveBeenCalled();
|
|
@@ -872,88 +255,6 @@ describe("cell reducer", () => {
|
|
|
872
255
|
expect(state.cellLogs).toEqual([]);
|
|
873
256
|
});
|
|
874
257
|
|
|
875
|
-
it("can handle multiple console outputs", () => {
|
|
876
|
-
const STDOUT1: OutputMessage = {
|
|
877
|
-
channel: "stdout",
|
|
878
|
-
mimetype: "text/plain",
|
|
879
|
-
data: "output1",
|
|
880
|
-
timestamp: 1,
|
|
881
|
-
};
|
|
882
|
-
const STDOUT2: OutputMessage = {
|
|
883
|
-
channel: "stdout",
|
|
884
|
-
mimetype: "text/plain",
|
|
885
|
-
data: "output2",
|
|
886
|
-
timestamp: 2,
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
actions.handleCellMessage({
|
|
890
|
-
cell_id: firstCellId,
|
|
891
|
-
output: undefined,
|
|
892
|
-
console: [STDOUT1, STDOUT2],
|
|
893
|
-
status: "running",
|
|
894
|
-
timestamp: new Date(20).getTime() as Seconds,
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
const cell = cells[0];
|
|
898
|
-
expect(cell.consoleOutputs).toMatchInlineSnapshot(`
|
|
899
|
-
[
|
|
900
|
-
{
|
|
901
|
-
"channel": "stdout",
|
|
902
|
-
"data": "output1output2",
|
|
903
|
-
"mimetype": "text/plain",
|
|
904
|
-
"timestamp": 1,
|
|
905
|
-
},
|
|
906
|
-
]
|
|
907
|
-
`);
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
it("can clear console output of a single cell", () => {
|
|
911
|
-
// Set up initial state with output
|
|
912
|
-
actions.handleCellMessage({
|
|
913
|
-
cell_id: firstCellId,
|
|
914
|
-
output: {
|
|
915
|
-
channel: "output",
|
|
916
|
-
mimetype: "text/plain",
|
|
917
|
-
data: "test output",
|
|
918
|
-
timestamp: 0,
|
|
919
|
-
},
|
|
920
|
-
console: {
|
|
921
|
-
channel: "stdout",
|
|
922
|
-
mimetype: "text/plain",
|
|
923
|
-
data: "console output",
|
|
924
|
-
timestamp: 0,
|
|
925
|
-
},
|
|
926
|
-
status: "idle",
|
|
927
|
-
timestamp: new Date(33).getTime() as Seconds,
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
// Add a stdin console output that should be preserved
|
|
931
|
-
actions.handleCellMessage({
|
|
932
|
-
cell_id: firstCellId,
|
|
933
|
-
console: {
|
|
934
|
-
channel: "stdin",
|
|
935
|
-
mimetype: "text/plain",
|
|
936
|
-
data: "stdin prompt",
|
|
937
|
-
timestamp: 0,
|
|
938
|
-
},
|
|
939
|
-
status: "idle",
|
|
940
|
-
timestamp: new Date(34).getTime() as Seconds,
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
// Verify initial state has console outputs
|
|
944
|
-
let cell = cells[0];
|
|
945
|
-
expect(cell.consoleOutputs.length).toBe(2);
|
|
946
|
-
|
|
947
|
-
// Clear console output
|
|
948
|
-
actions.clearCellConsoleOutput({ cellId: firstCellId });
|
|
949
|
-
|
|
950
|
-
// Verify only console output is cleared, but stdin is preserved
|
|
951
|
-
cell = cells[0];
|
|
952
|
-
expect(cell.consoleOutputs.length).toBe(1);
|
|
953
|
-
expect(cell.consoleOutputs[0].channel).toBe("stdin");
|
|
954
|
-
expect(cell.consoleOutputs[0].data).toBe("stdin prompt");
|
|
955
|
-
});
|
|
956
|
-
|
|
957
258
|
describe("releaseCellAtoms", () => {
|
|
958
259
|
it("atom families cache atoms until explicitly removed", () => {
|
|
959
260
|
const { cellDataAtom, cellRuntimeAtom, cellHandleAtom } =
|
|
@@ -978,6 +279,28 @@ describe("cell reducer", () => {
|
|
|
978
279
|
});
|
|
979
280
|
});
|
|
980
281
|
|
|
282
|
+
it("keeps layout cells stable when only a notebook log changes", () => {
|
|
283
|
+
const store = createStore();
|
|
284
|
+
const id = cellId("cell1");
|
|
285
|
+
const notebook = MockNotebook.notebookState({ cellData: { [id]: {} } });
|
|
286
|
+
store.set(notebookAtom, notebook);
|
|
287
|
+
const cells = store.get(renderedNotebookCellsAtom);
|
|
288
|
+
expect(cells.map((cell) => cell.id)).toEqual([id]);
|
|
289
|
+
|
|
290
|
+
store.set(notebookAtom, {
|
|
291
|
+
...notebook,
|
|
292
|
+
cellLogs: [
|
|
293
|
+
{
|
|
294
|
+
level: "stderr",
|
|
295
|
+
message: "log",
|
|
296
|
+
timestamp: 0,
|
|
297
|
+
source: { type: "cell", cellId: id },
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
expect(store.get(renderedNotebookCellsAtom)).toBe(cells);
|
|
302
|
+
});
|
|
303
|
+
|
|
981
304
|
describe("createTracebackInfoAtom", () => {
|
|
982
305
|
const store = createStore();
|
|
983
306
|
|
|
@@ -1098,9 +421,9 @@ describe("kernel-ready", () => {
|
|
|
1098
421
|
[CELL_B]: { id: CELL_B, code: "2" },
|
|
1099
422
|
},
|
|
1100
423
|
cellRuntime: {
|
|
1101
|
-
[CELL_A]: {
|
|
424
|
+
[CELL_A]: { serialization: "Valid" },
|
|
1102
425
|
[CELL_B]: {
|
|
1103
|
-
|
|
426
|
+
embeddedConsole: [
|
|
1104
427
|
{
|
|
1105
428
|
channel: "stdout",
|
|
1106
429
|
mimetype: "text/plain",
|
|
@@ -1118,8 +441,8 @@ describe("kernel-ready", () => {
|
|
|
1118
441
|
payload: undefined,
|
|
1119
442
|
});
|
|
1120
443
|
|
|
1121
|
-
expect(next.cellRuntime[CELL_A].
|
|
1122
|
-
expect(next.cellRuntime[CELL_B].
|
|
444
|
+
expect(next.cellRuntime[CELL_A].serialization).toBeUndefined();
|
|
445
|
+
expect(next.cellRuntime[CELL_B].embeddedConsole).toEqual([]);
|
|
1123
446
|
});
|
|
1124
447
|
|
|
1125
448
|
it("resetCellRuntimes starts the scratch cell over too", () => {
|
|
@@ -1127,7 +450,7 @@ describe("kernel-ready", () => {
|
|
|
1127
450
|
cellData: { [CELL_A]: { id: CELL_A, code: "1" } },
|
|
1128
451
|
cellRuntime: {
|
|
1129
452
|
[SCRATCH_CELL_ID]: {
|
|
1130
|
-
|
|
453
|
+
embeddedConsole: [
|
|
1131
454
|
{
|
|
1132
455
|
channel: "stdout",
|
|
1133
456
|
mimetype: "text/plain",
|
|
@@ -1143,7 +466,7 @@ describe("kernel-ready", () => {
|
|
|
1143
466
|
payload: undefined,
|
|
1144
467
|
});
|
|
1145
468
|
|
|
1146
|
-
expect(next.cellRuntime[SCRATCH_CELL_ID].
|
|
469
|
+
expect(next.cellRuntime[SCRATCH_CELL_ID].embeddedConsole).toEqual([]);
|
|
1147
470
|
});
|
|
1148
471
|
|
|
1149
472
|
describe("resetCellRuntimes in WASM", () => {
|
|
@@ -1163,8 +486,8 @@ describe("kernel-ready", () => {
|
|
|
1163
486
|
payload: undefined,
|
|
1164
487
|
});
|
|
1165
488
|
|
|
1166
|
-
expect(next.cellRuntime[CELL_A].
|
|
1167
|
-
expect(next.cellRuntime[CELL_B].
|
|
489
|
+
expect(next.cellRuntime[CELL_A].serialization).toBeUndefined();
|
|
490
|
+
expect(next.cellRuntime[CELL_B].embeddedConsole[0]).toMatchObject({
|
|
1168
491
|
data: "hydrated-B-stdout",
|
|
1169
492
|
});
|
|
1170
493
|
});
|
|
@@ -1178,7 +501,7 @@ describe("kernel-ready", () => {
|
|
|
1178
501
|
payload: undefined,
|
|
1179
502
|
});
|
|
1180
503
|
|
|
1181
|
-
expect(next.cellRuntime[CELL_A].
|
|
504
|
+
expect(next.cellRuntime[CELL_A].embeddedConsole).toEqual([]);
|
|
1182
505
|
});
|
|
1183
506
|
});
|
|
1184
507
|
});
|