@marimo-team/islands 0.26.1-dev19 → 0.26.1-dev21
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-CYipPzuL.js → ErrorBoundary-C5X_T831.js} +1 -1
- package/dist/{chat-ui-b1ERxzeA.js → chat-ui-qZdDDrzU.js} +3 -3
- package/dist/{code-visibility-D2uVdtAQ.js → code-visibility-7FxdzbDq.js} +2 -2
- package/dist/{common-d-UA4Z2n.js → common-D-iTRwaQ.js} +3 -3
- package/dist/{data-grid-overlay-editor-BfZIG_OX.js → data-grid-overlay-editor-DoWUW2oW.js} +1 -1
- package/dist/{error-entries-Bl8fzLQc.js → error-entries-DhI0hGvj.js} +448 -450
- package/dist/{feedback-button-Ct0bgfAh.js → feedback-button-OUiV15AL.js} +3 -3
- package/dist/{glide-data-editor-D9EGRA-V.js → glide-data-editor-CFouYM6e.js} +3 -3
- package/dist/{globals-UnK9bjY3.js → globals-B_U6Frqj.js} +1 -1
- package/dist/{html-to-image-D6A1lg0A.js → html-to-image-B803aaWE.js} +1 -1
- package/dist/main.js +3213 -3203
- package/dist/{number-overlay-editor-DMasuqqm.js → number-overlay-editor-CiQQjf9m.js} +1 -1
- package/dist/{process-output-w5omHedc.js → process-output-CnCLfvnL.js} +2 -2
- package/dist/{reveal-component-v6w_cxzA.js → reveal-component-B73BObRc.js} +2 -2
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +20 -19
- package/src/__mocks__/notebook.ts +1 -1
- package/src/__tests__/branded.ts +4 -0
- package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -1
- package/src/components/editor/cell/__tests__/useRunCells.test.tsx +5 -5
- package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +5 -2
- package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
- package/src/core/ai/context/providers/__tests__/error.test.ts +6 -3
- package/src/core/cells/__tests__/actions.test.ts +2 -2
- package/src/core/cells/__tests__/arrange.test.ts +1 -1
- package/src/core/cells/__tests__/harness.ts +9 -7
- package/src/core/cells/__tests__/layout.test.ts +1 -1
- package/src/core/cells/__tests__/runs.test.ts +14 -14
- package/src/core/cells/__tests__/utils.test.ts +3 -2
- package/src/core/cells/actions.ts +6 -6
- package/src/core/cells/cells.ts +1 -1
- package/src/core/cells/document.ts +1 -2
- package/src/core/cells/execution-console.ts +3 -3
- package/src/core/cells/ids.ts +2 -4
- package/src/core/cells/runs.ts +7 -5
- package/src/core/cells/session.ts +8 -5
- package/src/core/executions/__tests__/atoms.test.ts +7 -4
- package/src/core/executions/__tests__/freshness.test.ts +57 -53
- package/src/core/executions/__tests__/interrupt.test.ts +4 -3
- package/src/core/executions/__tests__/output-lifecycle.test.ts +3 -3
- package/src/core/executions/__tests__/output.test.ts +5 -3
- package/src/core/executions/__tests__/run.test.ts +4 -4
- package/src/core/executions/__tests__/select.test.ts +75 -67
- package/src/core/executions/atoms.ts +2 -2
- package/src/core/executions/freshness.ts +5 -5
- package/src/core/executions/output.ts +15 -21
- package/src/core/executions/select.ts +17 -9
- package/src/core/export/__tests__/hooks.test.ts +1 -1
- package/src/core/meta/__tests__/code-visibility.test.tsx +3 -2
- package/src/core/notebook/document/__tests__/codemirror.test.ts +8 -6
- package/src/core/notebook/document/__tests__/draft.test.ts +56 -58
- package/src/core/notebook/document/__tests__/fixtures.ts +8 -7
- package/src/core/notebook/document/__tests__/hooks.test.tsx +39 -35
- package/src/core/notebook/document/__tests__/lifecycle-scenarios.test.ts +8 -5
- package/src/core/notebook/document/__tests__/model.test.ts +8 -5
- package/src/core/notebook/document/__tests__/protocol-fixtures.ts +2 -2
- package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +37 -32
- package/src/core/notebook/document/__tests__/scenarios.test.ts +49 -45
- package/src/core/notebook/document/__tests__/state.test.ts +59 -56
- package/src/core/notebook/document/__tests__/submission.test.ts +15 -12
- package/src/core/notebook/document/__tests__/test-host.ts +3 -2
- package/src/core/notebook/document/__tests__/user.ts +7 -3
- package/src/core/notebook/document/draft.ts +29 -11
- package/src/core/notebook/document/state.ts +7 -6
- package/src/core/notebook/replica/__tests__/document.test.ts +9 -5
- package/src/core/notebook/replica/__tests__/executions.test.ts +16 -11
- package/src/core/notebook/replica/__tests__/fixtures.ts +6 -2
- package/src/core/notebook/replica/__tests__/replica.test.ts +7 -2
- package/src/core/notebook/replica/__tests__/results.test.ts +23 -19
- package/src/core/notebook/replica/execution-state.ts +2 -2
- package/src/core/notebook/replica/replica.ts +2 -2
- package/src/core/notebook/replica/resources/analysis.ts +1 -1
- package/src/core/notebook/replica/resources/document.ts +9 -8
- package/src/core/notebook/replica/resources/executions.ts +2 -2
- package/src/core/notebook/replica/resources/results.ts +2 -2
- package/src/core/saving/__tests__/document.test.tsx +1 -1
- package/src/core/saving/__tests__/state.test.ts +2 -2
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +9 -4
- package/src/core/session/useNotebookReplica.ts +1 -1
- package/src/core/session/useNotebookSession.tsx +1 -1
- package/src/core/transports/__tests__/static.test.ts +3 -2
- package/src/core/transports/static.ts +2 -2
- package/src/core/wasm/bridge.ts +5 -4
|
@@ -10,6 +10,11 @@ import {
|
|
|
10
10
|
} from "../state";
|
|
11
11
|
import { selectCell, selectOrder } from "../select";
|
|
12
12
|
import { cell, document, withCells } from "./fixtures";
|
|
13
|
+
import { cellId } from "@/__tests__/branded";
|
|
14
|
+
|
|
15
|
+
const C1 = cellId("c1");
|
|
16
|
+
const C2 = cellId("c2");
|
|
17
|
+
const C3 = cellId("c3");
|
|
13
18
|
|
|
14
19
|
const lifetimes: AbortController[] = [];
|
|
15
20
|
afterEach(() =>
|
|
@@ -31,7 +36,7 @@ function setup(initial: Document | null = document()) {
|
|
|
31
36
|
store,
|
|
32
37
|
source,
|
|
33
38
|
...model,
|
|
34
|
-
cellAtom: (id: string) => selectCell(model.documentAtom, id),
|
|
39
|
+
cellAtom: (id: string) => selectCell(model.documentAtom, cellId(id)),
|
|
35
40
|
orderAtom: selectOrder(model.documentAtom),
|
|
36
41
|
abort: () => controller.abort(),
|
|
37
42
|
edit: (callback: DocumentEdit) => store.set(model.editAtom, callback),
|
|
@@ -51,7 +56,7 @@ describe("document model", () => {
|
|
|
51
56
|
it("keeps metadata drafts while source is unavailable and follows its return", () => {
|
|
52
57
|
const initial = document();
|
|
53
58
|
const { store, source, cellAtom, changesAtom, edit } = setup(initial);
|
|
54
|
-
edit((tx) => tx.setName(
|
|
59
|
+
edit((tx) => tx.setName(C1, "local name"));
|
|
55
60
|
const hidden = withCells(initial, {
|
|
56
61
|
c1: cell("c1", "", { code: null }),
|
|
57
62
|
});
|
|
@@ -86,10 +91,10 @@ describe("document model", () => {
|
|
|
86
91
|
|
|
87
92
|
it("rebases a local order onto the latest host order and its precondition", () => {
|
|
88
93
|
const { store, source, orderAtom, changesAtom, edit } = setup();
|
|
89
|
-
edit((tx) => tx.setOrder([
|
|
94
|
+
edit((tx) => tx.setOrder([C2, C1]));
|
|
90
95
|
store.set(
|
|
91
96
|
source,
|
|
92
|
-
withCells(document(), { c3: cell("c3", "new") }, [
|
|
97
|
+
withCells(document(), { c3: cell("c3", "new") }, [C1, C3, C2]),
|
|
93
98
|
);
|
|
94
99
|
expect(store.get(orderAtom)).toEqual(["c2", "c1", "c3"]);
|
|
95
100
|
expect(store.get(changesAtom)).toEqual([
|
|
@@ -105,9 +110,7 @@ describe("document model", () => {
|
|
|
105
110
|
"appends a creation when its %s anchor was removed remotely",
|
|
106
111
|
(direction) => {
|
|
107
112
|
const { store, source, orderAtom, changesAtom, edit } = setup();
|
|
108
|
-
edit((tx) =>
|
|
109
|
-
tx.createCell({ id: "c3", code: "" }, { [direction]: "c1" }),
|
|
110
|
-
);
|
|
113
|
+
edit((tx) => tx.createCell({ id: C3, code: "" }, { [direction]: C1 }));
|
|
111
114
|
store.set(source, withCells(document(), { c1: null }));
|
|
112
115
|
expect(store.get(orderAtom)).toEqual(["c2", "c3"]);
|
|
113
116
|
expect(store.get(changesAtom)).toEqual([
|
|
@@ -126,8 +129,8 @@ describe("document model", () => {
|
|
|
126
129
|
|
|
127
130
|
it("brings back a cell deleted earlier in the draft with new content", () => {
|
|
128
131
|
const { store, cellAtom, orderAtom, changesAtom, edit } = setup();
|
|
129
|
-
edit((tx) => tx.deleteCell(
|
|
130
|
-
edit((tx) => tx.createCell({ id:
|
|
132
|
+
edit((tx) => tx.deleteCell(C1));
|
|
133
|
+
edit((tx) => tx.createCell({ id: C1, code: "back" }, { after: C2 }));
|
|
131
134
|
expect(store.get(cellAtom("c1"))?.code).toBe("back");
|
|
132
135
|
expect(store.get(orderAtom)).toEqual(["c2", "c1"]);
|
|
133
136
|
expect(store.get(changesAtom)).toEqual([
|
|
@@ -148,16 +151,16 @@ describe("document model", () => {
|
|
|
148
151
|
it("publishes the visible order when an anchor is deleted later in the draft", () => {
|
|
149
152
|
const { store, orderAtom, changesAtom, edit } = setup();
|
|
150
153
|
edit((tx) => {
|
|
151
|
-
tx.setCode(
|
|
152
|
-
tx.createCell({ id:
|
|
153
|
-
tx.deleteCell(
|
|
154
|
+
tx.setCode(C1, "edited before creation");
|
|
155
|
+
tx.createCell({ id: C3, code: "" }, { after: C1 });
|
|
156
|
+
tx.deleteCell(C1);
|
|
154
157
|
});
|
|
155
158
|
expect(store.get(orderAtom)).toEqual(["c3", "c2"]);
|
|
156
159
|
expect(store.get(changesAtom)).toEqual([
|
|
157
160
|
{ kind: "delete_cell", id: "c1", base_etag: "c1-etag" },
|
|
158
161
|
{
|
|
159
162
|
kind: "create_cell",
|
|
160
|
-
cell: { id:
|
|
163
|
+
cell: { id: C3, code: "", name: "_", config: cell("c3", "").config },
|
|
161
164
|
},
|
|
162
165
|
{ kind: "set_order", base_etag: "order-1", order: ["c3", "c2"] },
|
|
163
166
|
]);
|
|
@@ -166,7 +169,7 @@ describe("document model", () => {
|
|
|
166
169
|
it("does not release a draft because the host caught up", () => {
|
|
167
170
|
const initial = document();
|
|
168
171
|
const { store, source, cellAtom, edit } = setup(initial);
|
|
169
|
-
edit((tx) => tx.setCode(
|
|
172
|
+
edit((tx) => tx.setCode(C1, "local"));
|
|
170
173
|
for (const code of ["local", "later remote edit"]) {
|
|
171
174
|
store.set(source, withCells(initial, { c1: cell("c1", code) }));
|
|
172
175
|
expect(store.get(cellAtom("c1"))?.code).toBe("local");
|
|
@@ -175,10 +178,10 @@ describe("document model", () => {
|
|
|
175
178
|
|
|
176
179
|
it("keeps drafts separate when notebooks reuse cell ids", () => {
|
|
177
180
|
const { store, source, cellAtom, edit } = setup();
|
|
178
|
-
edit((tx) => tx.setCode(
|
|
181
|
+
edit((tx) => tx.setCode(C1, "first notebook"));
|
|
179
182
|
store.set(source, document("n2"));
|
|
180
183
|
expect(store.get(cellAtom("c1"))?.code).toBe("x = 1");
|
|
181
|
-
edit((tx) => tx.setCode(
|
|
184
|
+
edit((tx) => tx.setCode(C1, "second notebook"));
|
|
182
185
|
store.set(source, document("n1"));
|
|
183
186
|
expect(store.get(cellAtom("c1"))?.code).toBe("first notebook");
|
|
184
187
|
store.set(source, document("n2"));
|
|
@@ -188,15 +191,15 @@ describe("document model", () => {
|
|
|
188
191
|
it("does not repeat a satisfied deletion without mounted readers", () => {
|
|
189
192
|
const { store, source, cellAtom, changesAtom, edit } = setup();
|
|
190
193
|
edit((tx) => {
|
|
191
|
-
tx.deleteCell(
|
|
192
|
-
tx.setCode(
|
|
194
|
+
tx.deleteCell(C1);
|
|
195
|
+
tx.setCode(C2, "keep this draft");
|
|
193
196
|
});
|
|
194
197
|
const removed = withCells(document(), { c1: null });
|
|
195
198
|
store.set(source, removed);
|
|
196
199
|
// No reads between snapshots: reconciliation must observe the removal.
|
|
197
200
|
store.set(
|
|
198
201
|
source,
|
|
199
|
-
withCells(removed, { c1: cell("c1", "restored") }, [
|
|
202
|
+
withCells(removed, { c1: cell("c1", "restored") }, [C1, C2]),
|
|
200
203
|
);
|
|
201
204
|
expect(store.get(cellAtom("c1"))?.code).toBe("restored");
|
|
202
205
|
expect(store.get(cellAtom("c2"))?.code).toBe("keep this draft");
|
|
@@ -217,8 +220,8 @@ describe("document model", () => {
|
|
|
217
220
|
it("retains edits when the host removes a cell and blocks partial submissions", () => {
|
|
218
221
|
const { store, source, cellAtom, changesAtom, edit } = setup();
|
|
219
222
|
edit((tx) => {
|
|
220
|
-
tx.setCode(
|
|
221
|
-
tx.setCode(
|
|
223
|
+
tx.setCode(C1, "recover this code");
|
|
224
|
+
tx.setCode(C2, "another edit");
|
|
222
225
|
});
|
|
223
226
|
const removed = withCells(document(), { c1: null });
|
|
224
227
|
store.set(source, removed);
|
|
@@ -241,12 +244,12 @@ describe("document model", () => {
|
|
|
241
244
|
});
|
|
242
245
|
const unsubscribeOrder = store.sub(orderAtom, onOrder);
|
|
243
246
|
edit((tx) => {
|
|
244
|
-
tx.createCell({ id:
|
|
245
|
-
tx.setCode(
|
|
246
|
-
tx.setName(
|
|
247
|
-
tx.updateConfig(
|
|
248
|
-
tx.deleteCell(
|
|
249
|
-
tx.setOrder([
|
|
247
|
+
tx.createCell({ id: C3, code: "3" }, { after: C2 });
|
|
248
|
+
tx.setCode(C3, "updated");
|
|
249
|
+
tx.setName(C3, "example");
|
|
250
|
+
tx.updateConfig(C3, { hide_code: true });
|
|
251
|
+
tx.deleteCell(C1);
|
|
252
|
+
tx.setOrder([C3, C2]);
|
|
250
253
|
expect(store.get(orderAtom)).toEqual(["c1", "c2"]);
|
|
251
254
|
expect(store.get(cellAtom("c3"))).toBeUndefined();
|
|
252
255
|
});
|
|
@@ -262,13 +265,13 @@ describe("document model", () => {
|
|
|
262
265
|
const unsubscribeCell = store.sub(cellAtom("c1"), onCell);
|
|
263
266
|
const unsubscribeOrder = store.sub(orderAtom, onOrder);
|
|
264
267
|
edit((tx) => {
|
|
265
|
-
tx.setCode(
|
|
266
|
-
tx.updateConfig(
|
|
268
|
+
tx.setCode(C1, "x = 1");
|
|
269
|
+
tx.updateConfig(C1, { column: null });
|
|
267
270
|
});
|
|
268
271
|
expect(onCell).not.toHaveBeenCalled();
|
|
269
|
-
edit((tx) => tx.setCode(
|
|
270
|
-
edit((tx) => tx.setCode(
|
|
271
|
-
edit((tx) => tx.setOrder([
|
|
272
|
+
edit((tx) => tx.setCode(C1, "local"));
|
|
273
|
+
edit((tx) => tx.setCode(C1, "local"));
|
|
274
|
+
edit((tx) => tx.setOrder([C1, C2]));
|
|
272
275
|
expect(onCell).toHaveBeenCalledOnce();
|
|
273
276
|
expect(onOrder).not.toHaveBeenCalled();
|
|
274
277
|
unsubscribeCell();
|
|
@@ -279,8 +282,8 @@ describe("document model", () => {
|
|
|
279
282
|
const initial = document();
|
|
280
283
|
const { store, source, cellAtom, orderAtom, edit } = setup(initial);
|
|
281
284
|
edit((tx) => {
|
|
282
|
-
tx.setCode(
|
|
283
|
-
tx.createCell({ id:
|
|
285
|
+
tx.setCode(C1, "local");
|
|
286
|
+
tx.createCell({ id: C3, code: "new" });
|
|
284
287
|
});
|
|
285
288
|
const c1 = cellAtom("c1");
|
|
286
289
|
const first = store.get(c1);
|
|
@@ -294,7 +297,7 @@ describe("document model", () => {
|
|
|
294
297
|
store.sub(orderAtom, onOrder),
|
|
295
298
|
];
|
|
296
299
|
|
|
297
|
-
edit((tx) => tx.setCode(
|
|
300
|
+
edit((tx) => tx.setCode(C2, "other local"));
|
|
298
301
|
const remote = withCells(initial, {
|
|
299
302
|
c1: cell("c1", "remote", { version: 2, etag: "new-etag" }),
|
|
300
303
|
});
|
|
@@ -325,7 +328,7 @@ describe("document model", () => {
|
|
|
325
328
|
config: cell("c1", "").config,
|
|
326
329
|
});
|
|
327
330
|
expect(onFirst).toHaveBeenCalledOnce();
|
|
328
|
-
edit((tx) => tx.setOrder([
|
|
331
|
+
edit((tx) => tx.setOrder([C3, C2, C1]));
|
|
329
332
|
expect(onOrder).toHaveBeenCalledOnce();
|
|
330
333
|
expect(onFirst).toHaveBeenCalledOnce();
|
|
331
334
|
unsubscribe.forEach((fn) => fn());
|
|
@@ -335,14 +338,14 @@ describe("document model", () => {
|
|
|
335
338
|
[
|
|
336
339
|
"a missing placement anchor",
|
|
337
340
|
(tx: DocumentEditor) =>
|
|
338
|
-
tx.createCell({ id:
|
|
341
|
+
tx.createCell({ id: C3, code: "" }, { after: cellId("missing") }),
|
|
339
342
|
"Cell missing does not exist",
|
|
340
343
|
],
|
|
341
344
|
[
|
|
342
345
|
"a deleted placement anchor",
|
|
343
346
|
(tx: DocumentEditor) => {
|
|
344
|
-
tx.deleteCell(
|
|
345
|
-
tx.createCell({ id:
|
|
347
|
+
tx.deleteCell(C2);
|
|
348
|
+
tx.createCell({ id: C3, code: "" }, { before: C2 });
|
|
346
349
|
},
|
|
347
350
|
"Cell c2 does not exist",
|
|
348
351
|
],
|
|
@@ -355,40 +358,40 @@ describe("document model", () => {
|
|
|
355
358
|
],
|
|
356
359
|
[
|
|
357
360
|
"a missing cell",
|
|
358
|
-
(tx: DocumentEditor) => tx.setCode("missing", "code"),
|
|
361
|
+
(tx: DocumentEditor) => tx.setCode(cellId("missing"), "code"),
|
|
359
362
|
"Cell missing does not exist",
|
|
360
363
|
],
|
|
361
364
|
[
|
|
362
365
|
"a deleted cell",
|
|
363
366
|
(tx: DocumentEditor) => {
|
|
364
|
-
tx.deleteCell(
|
|
365
|
-
tx.setName(
|
|
367
|
+
tx.deleteCell(C2);
|
|
368
|
+
tx.setName(C2, "missing");
|
|
366
369
|
},
|
|
367
370
|
"Cell c2 does not exist",
|
|
368
371
|
],
|
|
369
372
|
[
|
|
370
373
|
"a duplicate cell",
|
|
371
|
-
(tx: DocumentEditor) => tx.createCell({ id:
|
|
374
|
+
(tx: DocumentEditor) => tx.createCell({ id: C1, code: "duplicate" }),
|
|
372
375
|
"Cell c1 already exists",
|
|
373
376
|
],
|
|
374
377
|
[
|
|
375
378
|
"an incomplete order",
|
|
376
|
-
(tx: DocumentEditor) => tx.setOrder([
|
|
379
|
+
(tx: DocumentEditor) => tx.setOrder([C1]),
|
|
377
380
|
"Cell order must contain every cell exactly once",
|
|
378
381
|
],
|
|
379
382
|
[
|
|
380
383
|
"a duplicate in the order",
|
|
381
|
-
(tx: DocumentEditor) => tx.setOrder([
|
|
384
|
+
(tx: DocumentEditor) => tx.setOrder([C1, C1]),
|
|
382
385
|
"Cell order must contain every cell exactly once",
|
|
383
386
|
],
|
|
384
387
|
[
|
|
385
388
|
"an unknown cell in the order",
|
|
386
|
-
(tx: DocumentEditor) => tx.setOrder([
|
|
389
|
+
(tx: DocumentEditor) => tx.setOrder([C1, cellId("missing")]),
|
|
387
390
|
"Cell order must contain every cell exactly once",
|
|
388
391
|
],
|
|
389
392
|
[
|
|
390
393
|
"an invalid config",
|
|
391
|
-
(tx: DocumentEditor) => tx.updateConfig(
|
|
394
|
+
(tx: DocumentEditor) => tx.updateConfig(C2, { column: 0.5 }),
|
|
392
395
|
"Invalid input",
|
|
393
396
|
],
|
|
394
397
|
])("rolls back the whole transaction for %s", (_, fail, message) => {
|
|
@@ -397,13 +400,13 @@ describe("document model", () => {
|
|
|
397
400
|
const unsubscribe = store.sub(cellAtom("c1"), onChange);
|
|
398
401
|
expect(() =>
|
|
399
402
|
edit((tx) => {
|
|
400
|
-
tx.setCode(
|
|
403
|
+
tx.setCode(C1, "not committed");
|
|
401
404
|
fail(tx);
|
|
402
405
|
}),
|
|
403
406
|
).toThrow(message);
|
|
404
407
|
expect(store.get(changesAtom)).toEqual([]);
|
|
405
408
|
expect(onChange).not.toHaveBeenCalled();
|
|
406
|
-
edit((tx) => tx.setCode(
|
|
409
|
+
edit((tx) => tx.setCode(C1, "next transaction"));
|
|
407
410
|
expect(store.get(cellAtom("c1"))?.code).toBe("next transaction");
|
|
408
411
|
unsubscribe();
|
|
409
412
|
});
|
|
@@ -413,9 +416,9 @@ describe("document model", () => {
|
|
|
413
416
|
let saved: DocumentEditor | undefined;
|
|
414
417
|
edit((tx) => {
|
|
415
418
|
saved = tx;
|
|
416
|
-
tx.setCode(
|
|
419
|
+
tx.setCode(C1, "committed");
|
|
417
420
|
});
|
|
418
|
-
expect(() => saved?.setCode(
|
|
421
|
+
expect(() => saved?.setCode(C1, "too late")).toThrow("has ended");
|
|
419
422
|
expect(store.get(cellAtom("c1"))?.code).toBe("committed");
|
|
420
423
|
});
|
|
421
424
|
|
|
@@ -423,9 +426,9 @@ describe("document model", () => {
|
|
|
423
426
|
const { store, changesAtom, edit } = setup();
|
|
424
427
|
expect(() =>
|
|
425
428
|
edit(async (tx) => {
|
|
426
|
-
tx.setCode(
|
|
429
|
+
tx.setCode(C1, "before await");
|
|
427
430
|
await Promise.resolve();
|
|
428
|
-
tx.setCode(
|
|
431
|
+
tx.setCode(C1, "after await");
|
|
429
432
|
}),
|
|
430
433
|
).toThrow("must be synchronous");
|
|
431
434
|
await Promise.resolve();
|
|
@@ -436,8 +439,8 @@ describe("document model", () => {
|
|
|
436
439
|
const { store, changesAtom, edit } = setup();
|
|
437
440
|
expect(() =>
|
|
438
441
|
edit((tx) => {
|
|
439
|
-
tx.setCode(
|
|
440
|
-
edit((inner) => inner.setCode(
|
|
442
|
+
tx.setCode(C1, "outer");
|
|
443
|
+
edit((inner) => inner.setCode(C2, "inner"));
|
|
441
444
|
}),
|
|
442
445
|
).toThrow("cannot be nested");
|
|
443
446
|
expect(store.get(changesAtom)).toEqual([]);
|
|
@@ -447,7 +450,7 @@ describe("document model", () => {
|
|
|
447
450
|
const { store, source, changesAtom, edit } = setup();
|
|
448
451
|
expect(() =>
|
|
449
452
|
edit((tx) => {
|
|
450
|
-
tx.setCode(
|
|
453
|
+
tx.setCode(C1, "old notebook");
|
|
451
454
|
store.set(source, document("n2"));
|
|
452
455
|
}),
|
|
453
456
|
).toThrow("changed during the transaction");
|
|
@@ -6,6 +6,9 @@ import type { Document } from "../../replica/resources/document";
|
|
|
6
6
|
import { selectCell } from "../select";
|
|
7
7
|
import { createDocumentState, type DocumentSubmission } from "../state";
|
|
8
8
|
import { cell, document, withCells } from "./fixtures";
|
|
9
|
+
import { cellId } from "@/__tests__/branded";
|
|
10
|
+
|
|
11
|
+
const C1 = cellId("c1");
|
|
9
12
|
|
|
10
13
|
const lifetimes: AbortController[] = [];
|
|
11
14
|
afterEach(() =>
|
|
@@ -27,7 +30,7 @@ function setup() {
|
|
|
27
30
|
store,
|
|
28
31
|
source,
|
|
29
32
|
...model,
|
|
30
|
-
cellAtom: (id: string) => selectCell(model.documentAtom, id),
|
|
33
|
+
cellAtom: (id: string) => selectCell(model.documentAtom, cellId(id)),
|
|
31
34
|
submit() {
|
|
32
35
|
const submission = store.set(model.submitAtom);
|
|
33
36
|
if (submission === null) {
|
|
@@ -59,8 +62,8 @@ describe("document submissions", () => {
|
|
|
59
62
|
});
|
|
60
63
|
store.set(source, hidden);
|
|
61
64
|
store.set(editAtom, (tx) => {
|
|
62
|
-
tx.setCode("c2", "other edit");
|
|
63
|
-
tx.setName(
|
|
65
|
+
tx.setCode(cellId("c2"), "other edit");
|
|
66
|
+
tx.setName(C1, "renamed");
|
|
64
67
|
});
|
|
65
68
|
expect(store.get(changesAtom)).toBeNull();
|
|
66
69
|
expect(store.set(submitAtom)).toBeNull();
|
|
@@ -70,7 +73,7 @@ describe("document submissions", () => {
|
|
|
70
73
|
if (recovery === "host source") {
|
|
71
74
|
store.set(source, withCells(hidden, { c1: cell("c1", code) }));
|
|
72
75
|
} else {
|
|
73
|
-
store.set(editAtom, (tx) => tx.setCode(
|
|
76
|
+
store.set(editAtom, (tx) => tx.setCode(C1, code));
|
|
74
77
|
}
|
|
75
78
|
const sent = submit();
|
|
76
79
|
expect(sent.changes).toEqual([
|
|
@@ -110,13 +113,13 @@ describe("document submissions", () => {
|
|
|
110
113
|
(first) => {
|
|
111
114
|
const { store, source, editAtom, cellAtom, submit, settle } = setup();
|
|
112
115
|
store.set(editAtom, (tx) => {
|
|
113
|
-
tx.setCode(
|
|
114
|
-
tx.createCell({ id: "c3", code: "new" });
|
|
116
|
+
tx.setCode(C1, "sent");
|
|
117
|
+
tx.createCell({ id: cellId("c3"), code: "new" });
|
|
115
118
|
});
|
|
116
119
|
const sent = submit();
|
|
117
120
|
store.set(editAtom, (tx) => {
|
|
118
|
-
tx.setCode(
|
|
119
|
-
tx.deleteCell("c3");
|
|
121
|
+
tx.setCode(C1, "still typing");
|
|
122
|
+
tx.deleteCell(cellId("c3"));
|
|
120
123
|
});
|
|
121
124
|
const onCode = vi.fn();
|
|
122
125
|
const onCreation = vi.fn();
|
|
@@ -145,7 +148,7 @@ describe("document submissions", () => {
|
|
|
145
148
|
it("waits for the response's later revision and follows subsequent host edits", () => {
|
|
146
149
|
const { store, source, editAtom, cellAtom, submitAtom, submit, settle } =
|
|
147
150
|
setup();
|
|
148
|
-
store.set(editAtom, (tx) => tx.setCode(
|
|
151
|
+
store.set(editAtom, (tx) => tx.setCode(C1, "sent"));
|
|
149
152
|
const sent = submit();
|
|
150
153
|
const edited = withCells(document(), { c1: cell("c1", "sent") });
|
|
151
154
|
const response = withCells(edited, { c2: cell("c2", "mirrored update") });
|
|
@@ -164,10 +167,10 @@ describe("document submissions", () => {
|
|
|
164
167
|
|
|
165
168
|
it("invalidates submissions when switching notebooks, retaining each draft", () => {
|
|
166
169
|
const { store, source, editAtom, cellAtom, submit, settle } = setup();
|
|
167
|
-
store.set(editAtom, (tx) => tx.setCode(
|
|
170
|
+
store.set(editAtom, (tx) => tx.setCode(C1, "first"));
|
|
168
171
|
const sent = submit();
|
|
169
172
|
store.set(source, document("n2"));
|
|
170
|
-
store.set(editAtom, (tx) => tx.setCode(
|
|
173
|
+
store.set(editAtom, (tx) => tx.setCode(C1, "second"));
|
|
171
174
|
store.set(source, withCells(document(), { c2: cell("c2", "remote") }));
|
|
172
175
|
settle(sent, withCells(document(), { c1: cell("c1", "first") }));
|
|
173
176
|
expect(store.get(cellAtom("c1"))?.code).toBe("first");
|
|
@@ -178,7 +181,7 @@ describe("document submissions", () => {
|
|
|
178
181
|
it("retries a rejected edit with fresh preconditions and ignores its late reply", () => {
|
|
179
182
|
const { store, source, editAtom, settleAtom, submitAtom, submit, settle } =
|
|
180
183
|
setup();
|
|
181
|
-
store.set(editAtom, (tx) => tx.setCode(
|
|
184
|
+
store.set(editAtom, (tx) => tx.setCode(C1, "local"));
|
|
182
185
|
const sent = submit();
|
|
183
186
|
store.set(settleAtom, sent, null);
|
|
184
187
|
const remote = withCells(document(), {
|
|
@@ -24,7 +24,7 @@ function record(
|
|
|
24
24
|
input: Protocol.CellInput,
|
|
25
25
|
notebookId: Protocol.NotebookId,
|
|
26
26
|
version: number,
|
|
27
|
-
): Protocol.
|
|
27
|
+
): Protocol.CellOutput {
|
|
28
28
|
const cell = Protocol.CellInput.parse(input);
|
|
29
29
|
const config = Protocol.CellConfigInput.parse(cell.config ?? {});
|
|
30
30
|
const code = cell.code.replace(/\r\n?/g, "\n");
|
|
@@ -86,7 +86,8 @@ export function createTestHost(initial: Document) {
|
|
|
86
86
|
document: current.revision,
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
for (const [index,
|
|
89
|
+
for (const [index, input] of changes.entries()) {
|
|
90
|
+
const change = Protocol.Change.parse(input);
|
|
90
91
|
switch (change.kind) {
|
|
91
92
|
case "create_cell":
|
|
92
93
|
case "replace_cell": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import { cellId } from "@/__tests__/branded";
|
|
3
4
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
5
|
import type { createStore } from "jotai/vanilla";
|
|
5
6
|
import type { Placement } from "../draft";
|
|
@@ -21,10 +22,11 @@ export function createUser(
|
|
|
21
22
|
store.set(model.editAtom, (tx) => tx.setCode(id, code));
|
|
22
23
|
},
|
|
23
24
|
changeCells(
|
|
24
|
-
changes: Record<
|
|
25
|
+
changes: Record<string, Partial<Omit<Protocol.CellInput, "id">>>,
|
|
25
26
|
) {
|
|
26
27
|
store.set(model.editAtom, (tx) => {
|
|
27
|
-
for (const [
|
|
28
|
+
for (const [key, patch] of Object.entries(changes)) {
|
|
29
|
+
const id = cellId(key);
|
|
28
30
|
if (patch.code !== undefined) {
|
|
29
31
|
tx.setCode(id, patch.code);
|
|
30
32
|
}
|
|
@@ -38,7 +40,9 @@ export function createUser(
|
|
|
38
40
|
});
|
|
39
41
|
},
|
|
40
42
|
createCell(cell: Protocol.CellInput, placement?: Placement) {
|
|
41
|
-
store.set(model.editAtom, (tx) =>
|
|
43
|
+
store.set(model.editAtom, (tx) =>
|
|
44
|
+
tx.createCell({ ...cell, id: cellId(cell.id) }, placement),
|
|
45
|
+
);
|
|
42
46
|
},
|
|
43
47
|
deleteCell(id: Protocol.CellId) {
|
|
44
48
|
store.set(model.editAtom, (tx) => tx.deleteCell(id));
|
|
@@ -5,11 +5,13 @@ import * as Protocol from "@marimo-team/client/protocol";
|
|
|
5
5
|
|
|
6
6
|
/** The fields a client edits. Null code means the host withheld source. */
|
|
7
7
|
export type EditableCell = Readonly<
|
|
8
|
-
Pick<Protocol.
|
|
8
|
+
Pick<Protocol.CellOutput, "id" | "code" | "name">
|
|
9
9
|
> & {
|
|
10
10
|
readonly config: Readonly<Protocol.CellConfig>;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
export type NewCell = Protocol.CellInput & { id: Protocol.CellId };
|
|
14
|
+
|
|
13
15
|
type CellWithSource = EditableCell & { readonly code: string };
|
|
14
16
|
|
|
15
17
|
/** A confirmed document with a draft applied. */
|
|
@@ -221,6 +223,7 @@ export function editCell(
|
|
|
221
223
|
id: Protocol.CellId,
|
|
222
224
|
edit: CellEdit,
|
|
223
225
|
): Draft {
|
|
226
|
+
checkColumn(edit.config?.column);
|
|
224
227
|
const current = draft.cells.get(id);
|
|
225
228
|
if (current?.kind === "delete") {
|
|
226
229
|
return draft;
|
|
@@ -250,10 +253,10 @@ export function editCell(
|
|
|
250
253
|
*/
|
|
251
254
|
export function createCell(
|
|
252
255
|
draft: Draft,
|
|
253
|
-
input:
|
|
256
|
+
input: NewCell,
|
|
254
257
|
placement: Placement = {},
|
|
255
258
|
): Draft {
|
|
256
|
-
const cell =
|
|
259
|
+
const cell = withDefaults(input);
|
|
257
260
|
const next = withCell(draft, cell.id, { kind: "create", cell, placement });
|
|
258
261
|
return draft.order === null
|
|
259
262
|
? next
|
|
@@ -270,11 +273,11 @@ export function createCell(
|
|
|
270
273
|
export function restoreCell(
|
|
271
274
|
confirmed: Document,
|
|
272
275
|
draft: Draft,
|
|
273
|
-
input:
|
|
276
|
+
input: NewCell,
|
|
274
277
|
placement: Placement = {},
|
|
275
278
|
sent: Draft = EMPTY_DRAFT,
|
|
276
279
|
): Draft {
|
|
277
|
-
const { id, code, name, config } =
|
|
280
|
+
const { id, code, name, config } = withDefaults(input);
|
|
278
281
|
const withdrawn = withCell(draft, id, undefined);
|
|
279
282
|
const next =
|
|
280
283
|
sent.cells.get(id)?.kind === "delete"
|
|
@@ -285,14 +288,29 @@ export function restoreCell(
|
|
|
285
288
|
return sameOrder(order, placed) ? next : setOrder(next, placed);
|
|
286
289
|
}
|
|
287
290
|
|
|
291
|
+
function checkColumn(column: number | null | undefined): void {
|
|
292
|
+
if (column != null && !Number.isSafeInteger(column)) {
|
|
293
|
+
throw new Error("Invalid input: cell column must be an integer");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
288
297
|
/** A cell input with the protocol's defaults filled in. */
|
|
289
|
-
function
|
|
290
|
-
|
|
298
|
+
function withDefaults(input: NewCell): CellWithSource {
|
|
299
|
+
checkColumn(input.config?.column);
|
|
291
300
|
return {
|
|
292
|
-
id:
|
|
293
|
-
code:
|
|
294
|
-
name:
|
|
295
|
-
config:
|
|
301
|
+
id: input.id,
|
|
302
|
+
code: input.code,
|
|
303
|
+
name: input.name ?? Protocol.cellInputNameDefault,
|
|
304
|
+
config: {
|
|
305
|
+
column: input.config?.column ?? Protocol.cellConfigInputColumnDefault,
|
|
306
|
+
disabled:
|
|
307
|
+
input.config?.disabled ?? Protocol.cellConfigInputDisabledDefault,
|
|
308
|
+
hide_code:
|
|
309
|
+
input.config?.hide_code ?? Protocol.cellConfigInputHideCodeDefault,
|
|
310
|
+
expand_output:
|
|
311
|
+
input.config?.expand_output ??
|
|
312
|
+
Protocol.cellConfigInputExpandOutputDefault,
|
|
313
|
+
},
|
|
296
314
|
};
|
|
297
315
|
}
|
|
298
316
|
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type WritableAtom,
|
|
8
8
|
} from "jotai/vanilla";
|
|
9
9
|
import type { Document } from "../replica";
|
|
10
|
-
import * as Protocol from "@marimo-team/client/protocol";
|
|
10
|
+
import type * as Protocol from "@marimo-team/client/protocol";
|
|
11
11
|
import {
|
|
12
12
|
acknowledge,
|
|
13
13
|
type CellEdit,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
editCell,
|
|
20
20
|
EMPTY_DRAFT,
|
|
21
21
|
isEmptyDraft,
|
|
22
|
+
type NewCell,
|
|
22
23
|
type Placement,
|
|
23
24
|
prune,
|
|
24
25
|
setOrder,
|
|
@@ -32,7 +33,7 @@ export interface DocumentEditor {
|
|
|
32
33
|
setName(id: Protocol.CellId, name: string): void;
|
|
33
34
|
updateConfig(id: Protocol.CellId, patch: Partial<Protocol.CellConfig>): void;
|
|
34
35
|
/** Create a cell, or bring back one this draft deletes with this content. */
|
|
35
|
-
createCell(cell:
|
|
36
|
+
createCell(cell: NewCell, placement?: Placement): void;
|
|
36
37
|
deleteCell(id: Protocol.CellId): void;
|
|
37
38
|
/** A permutation of the cells present at this point in the transaction. */
|
|
38
39
|
setOrder(order: readonly Protocol.CellId[]): void;
|
|
@@ -351,11 +352,11 @@ function editDocument(
|
|
|
351
352
|
const editor: DocumentEditor = {
|
|
352
353
|
setCode: (id, code) => updateCell(id, { code }),
|
|
353
354
|
setName: (id, name) => updateCell(id, { name }),
|
|
354
|
-
updateConfig: (id,
|
|
355
|
-
updateCell(id, { config: Protocol.CellConfig.partial().parse(patch) }),
|
|
355
|
+
updateConfig: (id, config) => updateCell(id, { config }),
|
|
356
356
|
createCell: (cell, placement = {}) => {
|
|
357
357
|
assertActive();
|
|
358
|
-
|
|
358
|
+
const { id } = cell;
|
|
359
|
+
if (hasCell(id)) {
|
|
359
360
|
throw new Error(`Cell ${cell.id} already exists`);
|
|
360
361
|
}
|
|
361
362
|
if (placement.after !== undefined && placement.before !== undefined) {
|
|
@@ -365,7 +366,7 @@ function editDocument(
|
|
|
365
366
|
if (anchor !== undefined) {
|
|
366
367
|
requireCell(anchor);
|
|
367
368
|
}
|
|
368
|
-
next = confirmed.cells.has(
|
|
369
|
+
next = confirmed.cells.has(id)
|
|
369
370
|
? restoreCell(confirmed, next, cell, { ...placement }, sent)
|
|
370
371
|
: createCell(next, cell, { ...placement });
|
|
371
372
|
},
|
|
@@ -5,6 +5,10 @@ import type * as Protocol from "@marimo-team/client/protocol";
|
|
|
5
5
|
import { document } from "../resources/document";
|
|
6
6
|
import { createNotebookReducer } from "@marimo-team/client";
|
|
7
7
|
import { fixtureEvents } from "./fixtures";
|
|
8
|
+
import { cellId } from "@/__tests__/branded";
|
|
9
|
+
|
|
10
|
+
const C3 = cellId("c3");
|
|
11
|
+
const FIXTURE_CELL = cellId("k7f2");
|
|
8
12
|
|
|
9
13
|
const reducer = createNotebookReducer({ document });
|
|
10
14
|
const snapshot = fixtureEvents("notebook-events.sse");
|
|
@@ -43,11 +47,11 @@ describe("document resource", () => {
|
|
|
43
47
|
);
|
|
44
48
|
const saved = current(reducer.reduce(changed, save));
|
|
45
49
|
expect(saved?.revision).toEqual(save.data.document);
|
|
46
|
-
expect(saved?.cells.get(
|
|
47
|
-
expect(saved?.cells.has(
|
|
50
|
+
expect(saved?.cells.get(C3)?.code).toBe("x = 22");
|
|
51
|
+
expect(saved?.cells.has(FIXTURE_CELL)).toBe(false);
|
|
48
52
|
expect(saved?.revision.saved_etag).toBe(saved?.revision.etag);
|
|
49
|
-
expect(first?.cells.get(
|
|
50
|
-
expect(first?.cells.has(
|
|
53
|
+
expect(first?.cells.get(C3)?.code).toBe("x = 21");
|
|
54
|
+
expect(first?.cells.has(FIXTURE_CELL)).toBe(true);
|
|
51
55
|
});
|
|
52
56
|
|
|
53
57
|
it("applies order-only changes and distinguishes an empty notebook from no document", () => {
|
|
@@ -117,7 +121,7 @@ describe("document resource", () => {
|
|
|
117
121
|
expect(() =>
|
|
118
122
|
reducer.reduce(state, {
|
|
119
123
|
event: "document",
|
|
120
|
-
data: { document: { ...revision, order: ["missing"] } },
|
|
124
|
+
data: { document: { ...revision, order: [cellId("missing")] } },
|
|
121
125
|
id: "200",
|
|
122
126
|
}),
|
|
123
127
|
).toThrow("Document records do not match");
|