@marimo-team/islands 0.25.3-dev447 → 0.25.3-dev455
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-EIKYL5I7.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-y-sxdqzm.js} +7 -7
- package/dist/{common-BDo_Jwoz.js → common-CN0Vi2sf.js} +4902 -4893
- package/dist/{data-grid-overlay-editor-CpHB_knU.js → data-grid-overlay-editor-DS87hE3v.js} +1 -1
- package/dist/{error-entries-CWdDf7iZ.js → error-entries-BG7ifiDg.js} +1368 -996
- package/dist/{feedback-button-B_Wmi4to.js → feedback-button-BLEwyTRA.js} +129 -129
- package/dist/{glide-data-editor-CMiIW5WP.js → glide-data-editor-Bmv61gX_.js} +3 -3
- package/dist/{globals-DaC3pk9F.js → globals-CIXjTv9d.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-TNyxrFMM.js} +1 -1
- package/dist/{process-output-hcyVRJCC.js → process-output-B8HPq5iZ.js} +2 -2
- package/dist/{reveal-component-CTmvBdvu.js → reveal-component-Ds7he0Dj.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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { cellId } from "@/__tests__/branded";
|
|
5
|
-
import type {
|
|
6
|
-
import { invariant } from "@/utils/invariant";
|
|
5
|
+
import type { Execution } from "@marimo-team/client/protocol";
|
|
7
6
|
import {
|
|
8
7
|
exportedForTesting,
|
|
9
8
|
MAX_CODE_LENGTH,
|
|
@@ -14,445 +13,143 @@ import {
|
|
|
14
13
|
|
|
15
14
|
const { reducer, initialState, isPureMarkdown } = exportedForTesting;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
payload: {
|
|
41
|
-
cellNotification: cellNotification,
|
|
42
|
-
code: "print('Hello World')",
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
state = initialState();
|
|
16
|
+
const queued = {
|
|
17
|
+
id: "e1",
|
|
18
|
+
run_id: "r1",
|
|
19
|
+
runtime_id: "runtime",
|
|
20
|
+
caused_by: null,
|
|
21
|
+
cell_id: "cell",
|
|
22
|
+
code: null,
|
|
23
|
+
code_fingerprint: "fp",
|
|
24
|
+
depends_on: {},
|
|
25
|
+
status: "queued",
|
|
26
|
+
outcome: null,
|
|
27
|
+
started_at: null,
|
|
28
|
+
completed_at: null,
|
|
29
|
+
} satisfies Execution;
|
|
30
|
+
|
|
31
|
+
function observe(
|
|
32
|
+
state: RunsState,
|
|
33
|
+
changes: Partial<Execution> = {},
|
|
34
|
+
code = "print(1)",
|
|
35
|
+
) {
|
|
36
|
+
return reducer(state, {
|
|
37
|
+
type: "addExecution",
|
|
38
|
+
payload: { record: { ...queued, ...changes }, code, receivedAt: 99 },
|
|
49
39
|
});
|
|
40
|
+
}
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
type: "addCellNotification",
|
|
99
|
-
payload: {
|
|
100
|
-
cellNotification: {
|
|
101
|
-
run_id: runId2,
|
|
102
|
-
cell_id: cellId("cell2"),
|
|
103
|
-
timestamp,
|
|
104
|
-
status: "queued",
|
|
105
|
-
},
|
|
106
|
-
code: "console.log('Run 2');",
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const nextState = reducer(intermediateState, {
|
|
111
|
-
type: "removeRun",
|
|
112
|
-
payload: runId1,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(nextState.runIds).toEqual([runId2]);
|
|
116
|
-
expect(nextState.runMap.has(runId1)).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should update an existing run with a new cell operation", () => {
|
|
120
|
-
const state = addQueuedCell();
|
|
121
|
-
|
|
122
|
-
const runStartTimestamp = timestamp + 1000;
|
|
123
|
-
const updatedState = reducer(state, {
|
|
124
|
-
type: "addCellNotification",
|
|
125
|
-
payload: {
|
|
126
|
-
cellNotification: {
|
|
127
|
-
run_id: runId,
|
|
128
|
-
cell_id: testCellId,
|
|
129
|
-
timestamp: timestamp + 1000,
|
|
130
|
-
status: "running",
|
|
131
|
-
},
|
|
132
|
-
code: "console.log('Hello World');",
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
expect(updatedState.runIds).toEqual([runId]);
|
|
137
|
-
expect(first(updatedState.runMap.get(runId)?.cellRuns).status).toBe(
|
|
138
|
-
"running",
|
|
139
|
-
);
|
|
140
|
-
expect(first(updatedState.runMap.get(runId)?.cellRuns).startTime).toBe(
|
|
141
|
-
runStartTimestamp,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const successState = reducer(updatedState, {
|
|
145
|
-
type: "addCellNotification",
|
|
146
|
-
payload: {
|
|
147
|
-
cellNotification: {
|
|
148
|
-
run_id: runId,
|
|
149
|
-
cell_id: testCellId,
|
|
150
|
-
timestamp: runStartTimestamp + 5000,
|
|
151
|
-
status: "idle",
|
|
42
|
+
describe("execution traces", () => {
|
|
43
|
+
it("derives the same trace from live transitions and a retained completion", () => {
|
|
44
|
+
const started_at = "1970-01-01T00:01:40Z";
|
|
45
|
+
const completed = {
|
|
46
|
+
started_at,
|
|
47
|
+
completed_at: "1970-01-01T00:01:42Z",
|
|
48
|
+
status: "completed",
|
|
49
|
+
outcome: { kind: "interrupted" },
|
|
50
|
+
} satisfies Partial<Execution>;
|
|
51
|
+
const runId = "r1" as RunId;
|
|
52
|
+
const running = observe(observe(initialState()), {
|
|
53
|
+
started_at,
|
|
54
|
+
status: "running",
|
|
55
|
+
});
|
|
56
|
+
for (const state of [
|
|
57
|
+
observe(running, completed),
|
|
58
|
+
observe(initialState(), completed),
|
|
59
|
+
]) {
|
|
60
|
+
expect(state.runMap.get(runId)?.cellRuns.get(cellId("cell"))).toEqual({
|
|
61
|
+
cellId: "cell",
|
|
62
|
+
executionId: "e1",
|
|
63
|
+
code: "print(1)",
|
|
64
|
+
startTime: 100,
|
|
65
|
+
elapsedTime: 2,
|
|
66
|
+
status: "interrupted",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
expect(
|
|
70
|
+
observe(running, {
|
|
71
|
+
...completed,
|
|
72
|
+
outcome: { kind: "value", display: null },
|
|
73
|
+
})
|
|
74
|
+
.runMap.get(runId)
|
|
75
|
+
?.cellRuns.get(cellId("cell"))?.status,
|
|
76
|
+
).toBe("success");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it.each(["upstream-stopped", "superseded"])(
|
|
80
|
+
"shows %s as skipped",
|
|
81
|
+
(reason) => {
|
|
82
|
+
const state = observe(initialState(), {
|
|
83
|
+
status: "completed",
|
|
84
|
+
outcome: {
|
|
85
|
+
kind: "skipped",
|
|
86
|
+
reason,
|
|
87
|
+
related: [],
|
|
88
|
+
message: "Did not run",
|
|
152
89
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
it("should limit the number of runs to MAX_RUNS", () => {
|
|
170
|
-
for (let i = 1; i <= MAX_RUNS + 1; i++) {
|
|
171
|
-
state = reducer(state, {
|
|
172
|
-
type: "addCellNotification",
|
|
90
|
+
});
|
|
91
|
+
expect(
|
|
92
|
+
state.runMap.get("r1" as RunId)?.cellRuns.get(cellId("cell"))?.status,
|
|
93
|
+
).toBe("skipped");
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
it("keeps known source only for the execution that ran it", () => {
|
|
98
|
+
const state = observe(initialState());
|
|
99
|
+
for (const [id, preview] of [
|
|
100
|
+
["e1", "print(1)"],
|
|
101
|
+
["e2", ""],
|
|
102
|
+
]) {
|
|
103
|
+
const next = reducer(state, {
|
|
104
|
+
type: "addExecution",
|
|
173
105
|
payload: {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
timestamp: timestamp,
|
|
178
|
-
status: "queued",
|
|
179
|
-
},
|
|
180
|
-
code: "console.log('Hello World');",
|
|
106
|
+
record: { ...queued, id },
|
|
107
|
+
code: undefined,
|
|
108
|
+
receivedAt: 100,
|
|
181
109
|
},
|
|
182
110
|
});
|
|
111
|
+
expect(
|
|
112
|
+
next.runMap.get("r1" as RunId)?.cellRuns.get(cellId("cell"))?.code,
|
|
113
|
+
).toBe(preview);
|
|
183
114
|
}
|
|
184
|
-
|
|
185
|
-
expect(state.runIds.length).toBe(MAX_RUNS);
|
|
186
|
-
expect(state.runMap.size).toBe(MAX_RUNS);
|
|
187
|
-
|
|
188
|
-
// Oldest run should be removed
|
|
189
|
-
expect(state.runIds).not.toContain("run1");
|
|
190
|
-
expect(state.runMap.has("run1" as RunId)).toBe(false);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("should truncate code to MAX_CODE_LENGTH", () => {
|
|
194
|
-
const longCode = "a".repeat(MAX_CODE_LENGTH + 10);
|
|
195
|
-
const truncatedCode = longCode.slice(0, MAX_CODE_LENGTH);
|
|
196
|
-
|
|
197
|
-
const nextState = reducer(state, {
|
|
198
|
-
type: "addCellNotification",
|
|
199
|
-
payload: {
|
|
200
|
-
cellNotification: {
|
|
201
|
-
run_id: runId,
|
|
202
|
-
cell_id: testCellId,
|
|
203
|
-
timestamp,
|
|
204
|
-
status: "queued",
|
|
205
|
-
},
|
|
206
|
-
code: longCode,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
expect(first(nextState.runMap.get(runId)?.cellRuns).code).toBe(
|
|
211
|
-
truncatedCode,
|
|
212
|
-
);
|
|
213
115
|
});
|
|
214
116
|
|
|
215
|
-
it("
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
expect(errorState.runIds).toEqual([runId]);
|
|
238
|
-
expect(first(errorState.runMap.get(runId)?.cellRuns).status).toBe("error");
|
|
239
|
-
expect(first(errorState.runMap.get(runId)?.cellRuns).elapsedTime).toBe(
|
|
240
|
-
errorTimestamp - timestamp,
|
|
241
|
-
);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("should update the run status to error when marimo-error occurs", () => {
|
|
245
|
-
const state = addQueuedCell();
|
|
246
|
-
|
|
247
|
-
const errorTimestamp = timestamp + 2000;
|
|
248
|
-
const errorState = reducer(state, {
|
|
249
|
-
type: "addCellNotification",
|
|
250
|
-
payload: {
|
|
251
|
-
cellNotification: {
|
|
252
|
-
run_id: runId,
|
|
253
|
-
cell_id: testCellId,
|
|
254
|
-
timestamp: errorTimestamp,
|
|
255
|
-
status: "running",
|
|
256
|
-
output: {
|
|
257
|
-
channel: "marimo-error",
|
|
258
|
-
data: "Error occurred",
|
|
259
|
-
mimetype: "text/plain",
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
code: "console.log('Hello World');",
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
expect(errorState.runIds).toEqual([runId]);
|
|
267
|
-
expect(first(errorState.runMap.get(runId)?.cellRuns).status).toBe("error");
|
|
268
|
-
expect(first(errorState.runMap.get(runId)?.cellRuns).elapsedTime).toBe(
|
|
269
|
-
errorTimestamp - timestamp,
|
|
117
|
+
it("keeps bounded history and code previews", () => {
|
|
118
|
+
let state = initialState();
|
|
119
|
+
for (let i = 0; i <= MAX_RUNS; i++) {
|
|
120
|
+
state = observe(
|
|
121
|
+
state,
|
|
122
|
+
{ run_id: String(i) },
|
|
123
|
+
"x".repeat(MAX_CODE_LENGTH + 1),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
expect(state.runMap.size).toBe(MAX_RUNS);
|
|
127
|
+
expect(state.runIds[0]).toBe(String(MAX_RUNS));
|
|
128
|
+
expect(state.runMap.has("0" as RunId)).toBe(false);
|
|
129
|
+
expect(
|
|
130
|
+
state.runMap.get(state.runIds[0])?.cellRuns.get(cellId("cell"))?.code
|
|
131
|
+
.length,
|
|
132
|
+
).toBe(MAX_CODE_LENGTH);
|
|
133
|
+
expect(
|
|
134
|
+
reducer(state, { type: "removeRun", payload: state.runIds[0] }).runIds
|
|
135
|
+
.length,
|
|
136
|
+
).toBe(MAX_RUNS - 1);
|
|
137
|
+
expect(reducer(state, { type: "clearRuns", payload: undefined })).toEqual(
|
|
138
|
+
initialState(),
|
|
270
139
|
);
|
|
271
140
|
});
|
|
272
141
|
|
|
273
|
-
it("
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
code: "console.log('Hello World');",
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
const finalState = reducer(erroredState, {
|
|
292
|
-
type: "addCellNotification",
|
|
293
|
-
payload: {
|
|
294
|
-
cellNotification: {
|
|
295
|
-
run_id: runId,
|
|
296
|
-
cell_id: testCellId,
|
|
297
|
-
timestamp: timestamp + 2000,
|
|
298
|
-
status: "running", // shouldn't happen
|
|
299
|
-
},
|
|
300
|
-
code: "console.log('Hello World');",
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
expect(finalState.runIds).toEqual([runId]);
|
|
305
|
-
expect(first(finalState.runMap.get(runId)?.cellRuns).status).toBe("error");
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("should order runs from newest to oldest", () => {
|
|
309
|
-
const runId2 = "run2" as RunId;
|
|
310
|
-
const runId3 = "run3" as RunId;
|
|
311
|
-
const timestamp = Date.now();
|
|
312
|
-
|
|
313
|
-
let intermediateState = addQueuedCell();
|
|
314
|
-
|
|
315
|
-
intermediateState = reducer(intermediateState, {
|
|
316
|
-
type: "addCellNotification",
|
|
317
|
-
payload: {
|
|
318
|
-
cellNotification: {
|
|
319
|
-
run_id: runId2,
|
|
320
|
-
cell_id: cellId("cell2"),
|
|
321
|
-
timestamp: timestamp + 1000,
|
|
322
|
-
status: "queued",
|
|
323
|
-
},
|
|
324
|
-
code: "console.log('Run 2');",
|
|
325
|
-
},
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
const finalState = reducer(intermediateState, {
|
|
329
|
-
type: "addCellNotification",
|
|
330
|
-
payload: {
|
|
331
|
-
cellNotification: {
|
|
332
|
-
run_id: runId3,
|
|
333
|
-
cell_id: cellId("cell3"),
|
|
334
|
-
timestamp: timestamp + 2000,
|
|
335
|
-
status: "queued",
|
|
336
|
-
},
|
|
337
|
-
code: "console.log('Run 3');",
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
expect(finalState.runIds).toEqual([runId3, runId2, runId]);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("should create a new run object when adding a cell operation", () => {
|
|
345
|
-
const state1 = addQueuedCell();
|
|
346
|
-
const run1 = state1.runMap.get(runId);
|
|
347
|
-
|
|
348
|
-
const state2 = reducer(state1, {
|
|
349
|
-
type: "addCellNotification",
|
|
350
|
-
payload: {
|
|
351
|
-
cellNotification: {
|
|
352
|
-
run_id: runId,
|
|
353
|
-
cell_id: cellId("cell2"),
|
|
354
|
-
timestamp: timestamp + 1000,
|
|
355
|
-
status: "queued",
|
|
356
|
-
},
|
|
357
|
-
code: "print('Another cell')",
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
const run2 = state2.runMap.get(runId);
|
|
362
|
-
expect(run2).not.toBe(run1);
|
|
363
|
-
expect(run2?.cellRuns).not.toBe(run1?.cellRuns);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it("should create new run object when updating cell status", () => {
|
|
367
|
-
const state1 = addQueuedCell();
|
|
368
|
-
const run1 = state1.runMap.get(runId);
|
|
369
|
-
|
|
370
|
-
const state2 = reducer(state1, {
|
|
371
|
-
type: "addCellNotification",
|
|
372
|
-
payload: {
|
|
373
|
-
cellNotification: {
|
|
374
|
-
run_id: runId,
|
|
375
|
-
cell_id: testCellId,
|
|
376
|
-
timestamp: timestamp + 1000,
|
|
377
|
-
status: "running",
|
|
378
|
-
},
|
|
379
|
-
code: code,
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
const run2 = state2.runMap.get(runId);
|
|
384
|
-
expect(run2).not.toBe(run1);
|
|
385
|
-
expect(run2?.cellRuns).not.toBe(run1?.cellRuns);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it("should skip markdown for first run", () => {
|
|
389
|
-
const markdownState = reducer(state, {
|
|
390
|
-
type: "addCellNotification",
|
|
391
|
-
payload: {
|
|
392
|
-
cellNotification: {
|
|
393
|
-
run_id: runId,
|
|
394
|
-
cell_id: testCellId,
|
|
395
|
-
timestamp,
|
|
396
|
-
status: "queued",
|
|
397
|
-
},
|
|
398
|
-
code: 'mo.md("""# Hello""")',
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
expect(markdownState.runIds).toEqual([]);
|
|
403
|
-
expect(markdownState.runMap.size).toBe(0);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("should not skip markdown if first run was not markdown", () => {
|
|
407
|
-
// Add non-markdown run first
|
|
408
|
-
let nextState = reducer(state, {
|
|
409
|
-
type: "addCellNotification",
|
|
410
|
-
payload: {
|
|
411
|
-
cellNotification: {
|
|
412
|
-
run_id: runId,
|
|
413
|
-
cell_id: testCellId,
|
|
414
|
-
timestamp,
|
|
415
|
-
status: "queued",
|
|
416
|
-
},
|
|
417
|
-
code: "print('hello')",
|
|
418
|
-
},
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
// Add markdown run second
|
|
422
|
-
nextState = reducer(nextState, {
|
|
423
|
-
type: "addCellNotification",
|
|
424
|
-
payload: {
|
|
425
|
-
cellNotification: {
|
|
426
|
-
run_id: runId,
|
|
427
|
-
cell_id: cellId("cell2"),
|
|
428
|
-
timestamp: timestamp + 1000,
|
|
429
|
-
status: "queued",
|
|
430
|
-
},
|
|
431
|
-
code: 'mo.md("""# Hello""")',
|
|
432
|
-
},
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
expect(nextState.runIds).toEqual([runId]);
|
|
436
|
-
expect(nextState.runMap.size).toBe(1);
|
|
437
|
-
expect(nextState.runMap.get(runId)?.cellRuns.size).toBe(2);
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
describe("isPureMarkdown", () => {
|
|
442
|
-
it("should return true for pure markdown", () => {
|
|
443
|
-
expect(isPureMarkdown("mo.md(r'''")).toBe(true);
|
|
444
|
-
expect(isPureMarkdown('mo.md(r"""')).toBe(true);
|
|
445
|
-
expect(isPureMarkdown("mo.md('''")).toBe(true);
|
|
446
|
-
expect(isPureMarkdown('mo.md("""')).toBe(true);
|
|
447
|
-
|
|
448
|
-
expect(isPureMarkdown("mo.md(\nr'''")).toBe(true);
|
|
449
|
-
expect(isPureMarkdown('mo.md(\nr"""')).toBe(true);
|
|
450
|
-
expect(isPureMarkdown("mo.md(\n'''")).toBe(true);
|
|
451
|
-
expect(isPureMarkdown('mo.md(\n"""')).toBe(true);
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
it("should return false for non-markdown", () => {
|
|
455
|
-
expect(isPureMarkdown("mo.md(f'''")).toBe(false);
|
|
456
|
-
expect(isPureMarkdown('mo.md(f"""')).toBe(false);
|
|
142
|
+
it("omits scratch, unowned executions, and runs containing only markdown", () => {
|
|
143
|
+
const initial = initialState();
|
|
144
|
+
expect(observe(initial, { cell_id: null })).toBe(initial);
|
|
145
|
+
expect(observe(initial, { run_id: null })).toBe(initial);
|
|
146
|
+
const markdown = 'mo.md("""hello""")';
|
|
147
|
+
expect(isPureMarkdown(markdown)).toBe(true);
|
|
148
|
+
expect(observe(initial, {}, markdown)).toBe(initial);
|
|
149
|
+
expect(
|
|
150
|
+
observe(observe(initial), { cell_id: "md" }, markdown).runMap.get(
|
|
151
|
+
"r1" as RunId,
|
|
152
|
+
)?.cellRuns.size,
|
|
153
|
+
).toBe(2);
|
|
457
154
|
});
|
|
458
155
|
});
|
|
@@ -359,8 +359,8 @@ describe("readExport", () => {
|
|
|
359
359
|
appConfig: {},
|
|
360
360
|
});
|
|
361
361
|
invariant(state.snapshot, "no snapshot");
|
|
362
|
-
expect(state.cellRuntime[CELL_1].
|
|
363
|
-
expect(state.cellRuntime[CELL_1].
|
|
362
|
+
expect(state.cellRuntime[CELL_1].embeddedConsole[0].code).toBe(code);
|
|
363
|
+
expect(state.cellRuntime[CELL_1].embeddedConsole[0]).toMatchObject({
|
|
364
364
|
traceback_format: "text",
|
|
365
365
|
data: "ValueError: cached <failure>",
|
|
366
366
|
});
|
|
@@ -392,7 +392,7 @@ describe("readExport", () => {
|
|
|
392
392
|
});
|
|
393
393
|
|
|
394
394
|
it("handles console outputs in session cell", () => {
|
|
395
|
-
const
|
|
395
|
+
const embeddedConsole = [
|
|
396
396
|
{
|
|
397
397
|
type: "stream",
|
|
398
398
|
name: "stdout",
|
|
@@ -407,7 +407,7 @@ describe("readExport", () => {
|
|
|
407
407
|
} as const,
|
|
408
408
|
];
|
|
409
409
|
const session = createSession([
|
|
410
|
-
createSessionCell("cell-1", [],
|
|
410
|
+
createSessionCell("cell-1", [], embeddedConsole),
|
|
411
411
|
]);
|
|
412
412
|
const result = readExport({
|
|
413
413
|
session: session,
|
|
@@ -417,7 +417,7 @@ describe("readExport", () => {
|
|
|
417
417
|
});
|
|
418
418
|
|
|
419
419
|
invariant(result.snapshot, "no snapshot");
|
|
420
|
-
expect(result.cellRuntime[CELL_1].
|
|
420
|
+
expect(result.cellRuntime[CELL_1].embeddedConsole).toEqual([
|
|
421
421
|
{
|
|
422
422
|
channel: "stdout",
|
|
423
423
|
data: "Hello stdout",
|
|
@@ -621,7 +621,7 @@ describe("readExport", () => {
|
|
|
621
621
|
version: 1,
|
|
622
622
|
});
|
|
623
623
|
// Null result means no output.
|
|
624
|
-
expect(result.cellRuntime[CELL_1].
|
|
624
|
+
expect(result.cellRuntime[CELL_1].embeddedConsole).toEqual([]);
|
|
625
625
|
});
|
|
626
626
|
|
|
627
627
|
it("creates state when cell order differs but same cells", () => {
|
|
@@ -718,7 +718,7 @@ describe("readExport", () => {
|
|
|
718
718
|
});
|
|
719
719
|
|
|
720
720
|
invariant(result.snapshot, "no snapshot");
|
|
721
|
-
expect(result.cellRuntime[CELL_1].
|
|
721
|
+
expect(result.cellRuntime[CELL_1].embeddedConsole).toEqual([]);
|
|
722
722
|
});
|
|
723
723
|
|
|
724
724
|
it("handles session cell with empty console array", () => {
|
|
@@ -731,7 +731,7 @@ describe("readExport", () => {
|
|
|
731
731
|
});
|
|
732
732
|
|
|
733
733
|
invariant(result.snapshot, "no snapshot");
|
|
734
|
-
expect(result.cellRuntime[CELL_1].
|
|
734
|
+
expect(result.cellRuntime[CELL_1].embeddedConsole).toEqual([]);
|
|
735
735
|
});
|
|
736
736
|
|
|
737
737
|
it("handles session cell with multiple outputs (uses first one)", () => {
|
|
@@ -1167,7 +1167,7 @@ describe("readExport", () => {
|
|
|
1167
1167
|
expect(cellIn(result, "cell-3").code).toBe("x = mo.ui.slider(0, 10)");
|
|
1168
1168
|
|
|
1169
1169
|
// cell-1: No matching session cell (hash is null), gets stub session cell
|
|
1170
|
-
expect(result.cellRuntime[cellId("cell-1")].
|
|
1170
|
+
expect(result.cellRuntime[cellId("cell-1")].embeddedConsole).toEqual([]);
|
|
1171
1171
|
|
|
1172
1172
|
// cell-2: Matches session cell-1 by hash (moMd), gets its output
|
|
1173
1173
|
|