@marimo-team/islands 0.26.1-dev18 → 0.26.1-dev20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/{ErrorBoundary-BO3Zpp5H.js → ErrorBoundary-Cx-CwafE.js} +1 -1
  2. package/dist/{chat-ui-b1ERxzeA.js → chat-ui-qZdDDrzU.js} +3 -3
  3. package/dist/{code-visibility-CMM88JXK.js → code-visibility-CVfXV6fG.js} +2 -2
  4. package/dist/{common-DPQs9PgT.js → common-BXRJCkJO.js} +3 -3
  5. package/dist/{data-grid-overlay-editor-ByuVzPXI.js → data-grid-overlay-editor-Mbtx3F9C.js} +1 -1
  6. package/dist/{error-entries-Bl8fzLQc.js → error-entries-DhI0hGvj.js} +448 -450
  7. package/dist/{feedback-button-BT4k2_Yi.js → feedback-button-zx4NcNDn.js} +3 -3
  8. package/dist/{glide-data-editor-xhiVBVLv.js → glide-data-editor-CvezoJKg.js} +3 -3
  9. package/dist/{globals-Rngj0Xbq.js → globals-CQuPaxzy.js} +1 -1
  10. package/dist/{html-to-image-D6A1lg0A.js → html-to-image-B803aaWE.js} +1 -1
  11. package/dist/main.js +3211 -3201
  12. package/dist/{number-overlay-editor-wXnPSQsq.js → number-overlay-editor-DxM7vsCk.js} +1 -1
  13. package/dist/{process-output-w5omHedc.js → process-output-CnCLfvnL.js} +2 -2
  14. package/dist/{reveal-component-f1JkdeUt.js → reveal-component-BefmhjJF.js} +2 -2
  15. package/package.json +1 -1
  16. package/src/__mocks__/executions.ts +19 -18
  17. package/src/__mocks__/notebook.ts +1 -1
  18. package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -1
  19. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +3 -3
  20. package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +5 -2
  21. package/src/core/ai/context/providers/__tests__/error.test.ts +6 -3
  22. package/src/core/cells/__tests__/actions.test.ts +2 -2
  23. package/src/core/cells/__tests__/arrange.test.ts +1 -1
  24. package/src/core/cells/__tests__/harness.ts +9 -7
  25. package/src/core/cells/__tests__/layout.test.ts +1 -1
  26. package/src/core/cells/__tests__/runs.test.ts +3 -3
  27. package/src/core/cells/__tests__/utils.test.ts +3 -2
  28. package/src/core/cells/actions.ts +6 -6
  29. package/src/core/cells/cells.ts +1 -1
  30. package/src/core/cells/document.ts +1 -2
  31. package/src/core/cells/execution-console.ts +3 -3
  32. package/src/core/cells/ids.ts +2 -4
  33. package/src/core/cells/runs.ts +2 -2
  34. package/src/core/cells/session.ts +4 -4
  35. package/src/core/executions/__tests__/atoms.test.ts +5 -2
  36. package/src/core/executions/__tests__/freshness.test.ts +56 -52
  37. package/src/core/executions/__tests__/interrupt.test.ts +2 -2
  38. package/src/core/executions/__tests__/output.test.ts +3 -1
  39. package/src/core/executions/__tests__/run.test.ts +2 -2
  40. package/src/core/executions/__tests__/select.test.ts +70 -62
  41. package/src/core/executions/atoms.ts +1 -1
  42. package/src/core/executions/freshness.ts +5 -5
  43. package/src/core/executions/output.ts +15 -21
  44. package/src/core/executions/select.ts +17 -9
  45. package/src/core/export/__tests__/hooks.test.ts +1 -1
  46. package/src/core/meta/__tests__/code-visibility.test.tsx +3 -2
  47. package/src/core/notebook/document/__tests__/codemirror.test.ts +8 -6
  48. package/src/core/notebook/document/__tests__/draft.test.ts +56 -58
  49. package/src/core/notebook/document/__tests__/fixtures.ts +8 -7
  50. package/src/core/notebook/document/__tests__/hooks.test.tsx +39 -35
  51. package/src/core/notebook/document/__tests__/lifecycle-scenarios.test.ts +8 -5
  52. package/src/core/notebook/document/__tests__/model.test.ts +8 -5
  53. package/src/core/notebook/document/__tests__/protocol-fixtures.ts +2 -2
  54. package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +37 -32
  55. package/src/core/notebook/document/__tests__/scenarios.test.ts +49 -45
  56. package/src/core/notebook/document/__tests__/state.test.ts +59 -56
  57. package/src/core/notebook/document/__tests__/submission.test.ts +15 -12
  58. package/src/core/notebook/document/__tests__/test-host.ts +3 -2
  59. package/src/core/notebook/document/__tests__/user.ts +7 -3
  60. package/src/core/notebook/document/draft.ts +29 -11
  61. package/src/core/notebook/document/state.ts +7 -6
  62. package/src/core/notebook/replica/__tests__/document.test.ts +9 -5
  63. package/src/core/notebook/replica/__tests__/executions.test.ts +8 -5
  64. package/src/core/notebook/replica/__tests__/fixtures.ts +6 -2
  65. package/src/core/notebook/replica/__tests__/results.test.ts +23 -19
  66. package/src/core/notebook/replica/execution-state.ts +2 -2
  67. package/src/core/notebook/replica/replica.ts +2 -2
  68. package/src/core/notebook/replica/resources/analysis.ts +1 -1
  69. package/src/core/notebook/replica/resources/document.ts +9 -8
  70. package/src/core/notebook/replica/resources/executions.ts +2 -2
  71. package/src/core/notebook/replica/resources/results.ts +2 -2
  72. package/src/core/saving/__tests__/document.test.tsx +1 -1
  73. package/src/core/saving/__tests__/state.test.ts +2 -2
  74. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +9 -4
  75. package/src/core/session/useNotebookReplica.ts +1 -1
  76. package/src/core/session/useNotebookSession.tsx +1 -1
  77. package/src/core/transports/__tests__/static.test.ts +1 -1
  78. package/src/core/transports/static.ts +2 -2
@@ -15,12 +15,17 @@ import {
15
15
  viewDocument,
16
16
  } from "../draft";
17
17
  import { cell, CONFIG, document, withCells } from "./fixtures";
18
+ import { cellId } from "@/__tests__/branded";
19
+
20
+ const C1 = cellId("c1");
21
+ const C2 = cellId("c2");
22
+ const C3 = cellId("c3");
18
23
 
19
24
  const confirmed = document();
20
25
 
21
26
  function edits(...steps: Parameters<typeof editCell>[3][]): Draft {
22
27
  return steps.reduce(
23
- (draft, edit) => editCell(confirmed, draft, "c1", edit),
28
+ (draft, edit) => editCell(confirmed, draft, C1, edit),
24
29
  EMPTY_DRAFT,
25
30
  );
26
31
  }
@@ -31,7 +36,7 @@ describe("editCell", () => {
31
36
  { code: "a", config: { hide_code: true } },
32
37
  { name: "n", config: { column: 1, hide_code: undefined } },
33
38
  );
34
- expect(viewDocument(confirmed, draft).cells.get("c1")).toEqual({
39
+ expect(viewDocument(confirmed, draft).cells.get(C1)).toEqual({
35
40
  id: "c1",
36
41
  code: "a",
37
42
  name: "n",
@@ -42,7 +47,7 @@ describe("editCell", () => {
42
47
  it("keeps a reversal to the confirmed value as a draft", () => {
43
48
  const draft = edits({ code: "local" }, { code: "x = 1" });
44
49
  const remote = withCells(confirmed, { c1: cell("c1", "earlier edit") });
45
- expect(viewDocument(remote, draft).cells.get("c1")?.code).toBe("x = 1");
50
+ expect(viewDocument(remote, draft).cells.get(C1)?.code).toBe("x = 1");
46
51
  });
47
52
 
48
53
  it("accepts empty strings, false and null while ignoring undefined", () => {
@@ -53,7 +58,7 @@ describe("editCell", () => {
53
58
  config: { column: null, disabled: false, hide_code: undefined },
54
59
  },
55
60
  );
56
- expect(viewDocument(confirmed, draft).cells.get("c1")).toEqual({
61
+ expect(viewDocument(confirmed, draft).cells.get(C1)).toEqual({
57
62
  id: "c1",
58
63
  code: "",
59
64
  name: "_",
@@ -64,27 +69,23 @@ describe("editCell", () => {
64
69
 
65
70
  describe("createCell and deleteCell", () => {
66
71
  it("fills protocol defaults and places the cell in the view", () => {
67
- const atEnd = createCell(EMPTY_DRAFT, { id: "c3", code: "3" });
68
- const after = createCell(
69
- EMPTY_DRAFT,
70
- { id: "c3", code: "3" },
71
- { after: "c1" },
72
- );
72
+ const atEnd = createCell(EMPTY_DRAFT, { id: C3, code: "3" });
73
+ const after = createCell(EMPTY_DRAFT, { id: C3, code: "3" }, { after: C1 });
73
74
  const before = createCell(
74
75
  EMPTY_DRAFT,
75
- { id: "c3", code: "3" },
76
- { before: "c1" },
76
+ { id: C3, code: "3" },
77
+ { before: C1 },
77
78
  );
78
79
  const orphan = createCell(
79
80
  EMPTY_DRAFT,
80
- { id: "c3", code: "3" },
81
- { after: "gone" },
81
+ { id: C3, code: "3" },
82
+ { after: cellId("gone") },
82
83
  );
83
84
  expect(viewDocument(confirmed, atEnd).order).toEqual(["c1", "c2", "c3"]);
84
85
  expect(viewDocument(confirmed, after).order).toEqual(["c1", "c3", "c2"]);
85
86
  expect(viewDocument(confirmed, before).order).toEqual(["c3", "c1", "c2"]);
86
87
  expect(viewDocument(confirmed, orphan).order).toEqual(["c1", "c2", "c3"]);
87
- expect(viewDocument(confirmed, atEnd).cells.get("c3")).toEqual({
88
+ expect(viewDocument(confirmed, atEnd).cells.get(C3)).toEqual({
88
89
  id: "c3",
89
90
  code: "3",
90
91
  name: "_",
@@ -93,25 +94,22 @@ describe("createCell and deleteCell", () => {
93
94
  });
94
95
 
95
96
  it("forgets a created cell when it is deleted", () => {
96
- const draft = deleteCell(
97
- createCell(EMPTY_DRAFT, { id: "c3", code: "" }),
98
- "c3",
99
- );
97
+ const draft = deleteCell(createCell(EMPTY_DRAFT, { id: C3, code: "" }), C3);
100
98
  expect(toChanges(confirmed, draft)).toEqual([]);
101
99
  expect(viewDocument(confirmed, draft).order).toEqual(["c1", "c2"]);
102
100
  });
103
101
 
104
102
  it("restores a deleted cell as an edit at the requested place", () => {
105
- const deleted = deleteCell(EMPTY_DRAFT, "c1");
106
- const back = { id: "c1", code: "back" };
103
+ const deleted = deleteCell(EMPTY_DRAFT, C1);
104
+ const back = { id: C1, code: "back" };
107
105
  const put = {
108
106
  kind: "replace_cell",
109
107
  base_etag: "c1-etag",
110
108
  cell: { ...back, name: "_", config: CONFIG },
111
109
  };
112
- const inPlace = restoreCell(confirmed, deleted, back, { before: "c2" });
113
- const moved = restoreCell(confirmed, deleted, back, { after: "c2" });
114
- expect(viewDocument(confirmed, inPlace).cells.get("c1")?.code).toBe("back");
110
+ const inPlace = restoreCell(confirmed, deleted, back, { before: C2 });
111
+ const moved = restoreCell(confirmed, deleted, back, { after: C2 });
112
+ expect(viewDocument(confirmed, inPlace).cells.get(C1)?.code).toBe("back");
115
113
  expect(viewDocument(confirmed, inPlace).order).toEqual(["c1", "c2"]);
116
114
  expect(toChanges(confirmed, inPlace)).toEqual([put]);
117
115
  expect(viewDocument(confirmed, moved).order).toEqual(["c2", "c1"]);
@@ -122,10 +120,10 @@ describe("createCell and deleteCell", () => {
122
120
  });
123
121
 
124
122
  it("recreates a cell whose deletion is in flight once the host removes it", () => {
125
- const sent = deleteCell(EMPTY_DRAFT, "c1");
126
- const back = { id: "c1", code: "back" };
127
- const draft = restoreCell(confirmed, sent, back, { before: "c2" }, sent);
128
- expect(viewDocument(confirmed, draft).cells.get("c1")?.code).toBe("back");
123
+ const sent = deleteCell(EMPTY_DRAFT, C1);
124
+ const back = { id: C1, code: "back" };
125
+ const draft = restoreCell(confirmed, sent, back, { before: C2 }, sent);
126
+ expect(viewDocument(confirmed, draft).cells.get(C1)?.code).toBe("back");
129
127
  expect(viewDocument(confirmed, draft).order).toEqual(["c1", "c2"]);
130
128
 
131
129
  const removed = withCells(confirmed, { c1: null });
@@ -172,7 +170,7 @@ describe("viewDocument", () => {
172
170
  }),
173
171
  c2: cell("c2", "remote too"),
174
172
  },
175
- ["c2", "c1"],
173
+ [C2, C1],
176
174
  );
177
175
  expect(viewDocument(remote, draft)).toEqual({
178
176
  order: ["c2", "c1"],
@@ -180,13 +178,13 @@ describe("viewDocument", () => {
180
178
  [
181
179
  "c1",
182
180
  {
183
- id: "c1",
181
+ id: C1,
184
182
  code: "local",
185
183
  name: "renamed",
186
184
  config: { ...CONFIG, disabled: true, hide_code: true },
187
185
  },
188
186
  ],
189
- ["c2", remote.cells.get("c2")],
187
+ ["c2", remote.cells.get(C2)],
190
188
  ]),
191
189
  });
192
190
  });
@@ -199,10 +197,10 @@ describe("toChanges", () => {
199
197
  const hidden = withCells(confirmed, {
200
198
  c1: cell("c1", "", { code: null }),
201
199
  });
202
- const created = createCell(EMPTY_DRAFT, { id: "c3", code: "" });
203
- const draft = editCell(hidden, created, "c1", edit);
200
+ const created = createCell(EMPTY_DRAFT, { id: C3, code: "" });
201
+ const draft = editCell(hidden, created, C1, edit);
204
202
  expect(toChanges(hidden, draft)).toBeNull();
205
- expect(viewDocument(hidden, draft).cells.get("c1")?.code).toBeNull();
203
+ expect(viewDocument(hidden, draft).cells.get(C1)?.code).toBeNull();
206
204
  },
207
205
  );
208
206
 
@@ -212,7 +210,7 @@ describe("toChanges", () => {
212
210
  const hidden = withCells(confirmed, {
213
211
  c1: cell("c1", "", { code: null }),
214
212
  });
215
- const draft = editCell(hidden, EMPTY_DRAFT, "c1", {
213
+ const draft = editCell(hidden, EMPTY_DRAFT, C1, {
216
214
  name: "renamed",
217
215
  code,
218
216
  });
@@ -231,10 +229,10 @@ describe("toChanges", () => {
231
229
  c1: cell("c1", "", { code: null }),
232
230
  c2: cell("c2", "", { code: null }),
233
231
  });
234
- expect(toChanges(hidden, deleteCell(EMPTY_DRAFT, "c1"))).toEqual([
232
+ expect(toChanges(hidden, deleteCell(EMPTY_DRAFT, C1))).toEqual([
235
233
  { kind: "delete_cell", id: "c1", base_etag: "c1-etag" },
236
234
  ]);
237
- expect(toChanges(hidden, setOrder(EMPTY_DRAFT, ["c2", "c1"]))).toEqual([
235
+ expect(toChanges(hidden, setOrder(EMPTY_DRAFT, [C2, C1]))).toEqual([
238
236
  { kind: "set_order", base_etag: "order-1", order: ["c2", "c1"] },
239
237
  ]);
240
238
  });
@@ -255,22 +253,22 @@ describe("toChanges", () => {
255
253
  {
256
254
  kind: "replace_cell",
257
255
  base_etag: "c1-etag-2",
258
- cell: { id: "c1", code: "local", name: "renamed", config: CONFIG },
256
+ cell: { id: C1, code: "local", name: "renamed", config: CONFIG },
259
257
  },
260
258
  ]);
261
259
  });
262
260
 
263
261
  it("places a cell before another creation with one order change", () => {
264
- let draft = createCell(EMPTY_DRAFT, { id: "c3", code: "3" });
265
- draft = createCell(draft, { id: "c4", code: "4" }, { before: "c3" });
262
+ let draft = createCell(EMPTY_DRAFT, { id: C3, code: "3" });
263
+ draft = createCell(draft, { id: cellId("c4"), code: "4" }, { before: C3 });
266
264
  expect(toChanges(confirmed, draft)).toEqual([
267
265
  {
268
266
  kind: "create_cell",
269
- cell: { id: "c3", code: "3", name: "_", config: CONFIG },
267
+ cell: { id: C3, code: "3", name: "_", config: CONFIG },
270
268
  },
271
269
  {
272
270
  kind: "create_cell",
273
- cell: { id: "c4", code: "4", name: "_", config: CONFIG },
271
+ cell: { id: cellId("c4"), code: "4", name: "_", config: CONFIG },
274
272
  },
275
273
  {
276
274
  kind: "set_order",
@@ -280,29 +278,29 @@ describe("toChanges", () => {
280
278
  ]);
281
279
  });
282
280
 
283
- it.each([{ after: "c2" }, { before: "c2" }])(
281
+ it.each([{ after: C2 }, { before: C2 }])(
284
282
  "appends when the placement anchor was deleted earlier in the request: %o",
285
283
  (placement) => {
286
- let draft = deleteCell(EMPTY_DRAFT, "c2");
287
- draft = createCell(draft, { id: "c3", code: "3" }, placement);
284
+ let draft = deleteCell(EMPTY_DRAFT, C2);
285
+ draft = createCell(draft, { id: C3, code: "3" }, placement);
288
286
  expect(toChanges(confirmed, draft)).toEqual([
289
287
  { kind: "delete_cell", id: "c2", base_etag: "c2-etag" },
290
288
  {
291
289
  kind: "create_cell",
292
- cell: { id: "c3", code: "3", name: "_", config: CONFIG },
290
+ cell: { id: C3, code: "3", name: "_", config: CONFIG },
293
291
  },
294
292
  ]);
295
293
  },
296
294
  );
297
295
 
298
296
  it("creates, deletes, then sets the reconciled order", () => {
299
- let draft = setOrder(EMPTY_DRAFT, ["c2", "c1"]);
300
- draft = createCell(draft, { id: "c3", code: "3" }, { after: "c2" });
301
- draft = deleteCell(draft, "c1");
297
+ let draft = setOrder(EMPTY_DRAFT, [C2, C1]);
298
+ draft = createCell(draft, { id: C3, code: "3" }, { after: C2 });
299
+ draft = deleteCell(draft, C1);
302
300
  expect(toChanges(confirmed, draft)).toEqual([
303
301
  {
304
302
  kind: "create_cell",
305
- cell: { id: "c3", code: "3", name: "_", config: CONFIG },
303
+ cell: { id: C3, code: "3", name: "_", config: CONFIG },
306
304
  },
307
305
  { kind: "delete_cell", id: "c1", base_etag: "c1-etag" },
308
306
  { kind: "set_order", base_etag: "order-1", order: ["c2", "c3"] },
@@ -316,7 +314,7 @@ describe("acknowledge", () => {
316
314
  code: "sent",
317
315
  config: { hide_code: true, column: 1 },
318
316
  });
319
- const later = editCell(confirmed, sent, "c1", {
317
+ const later = editCell(confirmed, sent, C1, {
320
318
  code: "typed more",
321
319
  config: { column: 2 },
322
320
  });
@@ -324,7 +322,7 @@ describe("acknowledge", () => {
324
322
  c1: cell("c1", "remote", { config: { ...CONFIG, column: 1 } }),
325
323
  });
326
324
  expect(
327
- viewDocument(remote, acknowledge(later, sent)).cells.get("c1"),
325
+ viewDocument(remote, acknowledge(later, sent)).cells.get(C1),
328
326
  ).toEqual({
329
327
  id: "c1",
330
328
  code: "typed more",
@@ -334,22 +332,22 @@ describe("acknowledge", () => {
334
332
  });
335
333
 
336
334
  it("turns an accepted creation into an edit of only the fields changed since", () => {
337
- const sent = createCell(EMPTY_DRAFT, { id: "c3", code: "3" });
338
- const later = editCell(confirmed, sent, "c3", { name: "named" });
335
+ const sent = createCell(EMPTY_DRAFT, { id: C3, code: "3" });
336
+ const later = editCell(confirmed, sent, C3, { name: "named" });
339
337
  const remote = withCells(confirmed, { c3: cell("c3", "remote code") });
340
338
  expect(toChanges(remote, acknowledge(later, sent))).toEqual([
341
339
  {
342
340
  kind: "replace_cell",
343
341
  base_etag: "c3-etag",
344
- cell: { id: "c3", code: "remote code", name: "named", config: CONFIG },
342
+ cell: { id: C3, code: "remote code", name: "named", config: CONFIG },
345
343
  },
346
344
  ]);
347
345
  });
348
346
 
349
347
  it("releases an accepted order but preserves a subsequent reorder", () => {
350
- const sent = setOrder(EMPTY_DRAFT, ["c2", "c1"]);
351
- const later = setOrder(sent, ["c1", "c2"]);
352
- const remote = withCells(confirmed, {}, ["c2", "c1"]);
348
+ const sent = setOrder(EMPTY_DRAFT, [C2, C1]);
349
+ const later = setOrder(sent, [C1, C2]);
350
+ const remote = withCells(confirmed, {}, [C2, C1]);
353
351
  expect(toChanges(remote, acknowledge(sent, sent))).toEqual([]);
354
352
  expect(toChanges(remote, acknowledge(later, sent))).toEqual([
355
353
  {
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import { cellId } from "@/__tests__/branded";
3
4
  import type { Document } from "../../replica/resources/document";
4
5
  import type * as Protocol from "@marimo-team/client/protocol";
5
6
 
@@ -11,12 +12,12 @@ export const CONFIG: Protocol.CellConfig = {
11
12
  };
12
13
 
13
14
  export function cell(
14
- id: Protocol.CellId,
15
+ id: string,
15
16
  code: string,
16
- overrides: Partial<Protocol.Cell> = {},
17
- ): Protocol.Cell {
17
+ overrides: Partial<Protocol.CellOutput> = {},
18
+ ): Protocol.CellOutput {
18
19
  return {
19
- id,
20
+ id: cellId(id),
20
21
  notebook_id: "n1",
21
22
  code,
22
23
  name: "_",
@@ -52,15 +53,15 @@ export function document(notebookId: Protocol.NotebookId = "n1"): Document {
52
53
  /** The document with some cells replaced or removed and the order updated. */
53
54
  export function withCells(
54
55
  base: Document,
55
- changes: Record<Protocol.CellId, Protocol.Cell | null>,
56
+ changes: Record<string, Protocol.CellOutput | null>,
56
57
  order?: readonly Protocol.CellId[],
57
58
  ): Document {
58
59
  const cells = new Map(base.cells);
59
60
  for (const [id, next] of Object.entries(changes)) {
60
61
  if (next === null) {
61
- cells.delete(id);
62
+ cells.delete(cellId(id));
62
63
  } else {
63
- cells.set(id, next);
64
+ cells.set(cellId(id), next);
64
65
  }
65
66
  }
66
67
  const nextOrder = order
@@ -17,6 +17,10 @@ import {
17
17
  import { createDocumentModel, DocumentProvider } from "..";
18
18
  import { cell, CONFIG, document, withCells } from "./fixtures";
19
19
  import { type FakeEdit, fakeBackend } from "../../replica/__tests__/fixtures";
20
+ import { cellId } from "@/__tests__/branded";
21
+
22
+ const C1 = cellId("c1");
23
+ const C2 = cellId("c2");
20
24
 
21
25
  const lifetimes: AbortController[] = [];
22
26
 
@@ -65,13 +69,13 @@ describe("document hooks", () => {
65
69
  const { store, source, wrapper, controller } = setup(document(), edit);
66
70
  const { result, unmount } = renderHook(
67
71
  () => ({
68
- code: useNotebookCellCode("c1"),
72
+ code: useNotebookCellCode(C1),
69
73
  edit: useNotebookDocumentEdit(),
70
74
  sync: useNotebookDocumentSync(),
71
75
  }),
72
76
  { wrapper, reactStrictMode: true },
73
77
  );
74
- act(() => result.current.edit((tx) => tx.setCode("c1", "local")));
78
+ act(() => result.current.edit((tx) => tx.setCode(C1, "local")));
75
79
  expect(result.current.sync.status).toEqual({ status: "pending" });
76
80
  const { flush, retry } = result.current.sync;
77
81
  await act(async () => {
@@ -87,7 +91,7 @@ describe("document hooks", () => {
87
91
  retry,
88
92
  });
89
93
  expect(result.current.code).toBe("local");
90
- act(() => result.current.edit((tx) => tx.setCode("c1", "next")));
94
+ act(() => result.current.edit((tx) => tx.setCode(C1, "next")));
91
95
  await act(async () => {
92
96
  const rejected = (async () => {
93
97
  await expect(flush()).rejects.toThrow("session ended");
@@ -108,9 +112,9 @@ describe("document hooks", () => {
108
112
  const { result } = renderHook(
109
113
  () => {
110
114
  const value = {
111
- code: useNotebookCellCode("c1"),
112
- name: useNotebookCellName("c1"),
113
- config: useNotebookCellConfig("c1"),
115
+ code: useNotebookCellCode(C1),
116
+ name: useNotebookCellName(C1),
117
+ config: useNotebookCellConfig(C1),
114
118
  order: useNotebookCellOrder(),
115
119
  };
116
120
  seen(value);
@@ -123,10 +127,10 @@ describe("document hooks", () => {
123
127
 
124
128
  act(() =>
125
129
  edit((tx) => {
126
- tx.setCode("c1", "edited");
127
- tx.setName("c1", "renamed");
128
- tx.updateConfig("c1", { hide_code: true });
129
- tx.setOrder(["c2", "c1"]);
130
+ tx.setCode(C1, "edited");
131
+ tx.setName(C1, "renamed");
132
+ tx.updateConfig(C1, { hide_code: true });
133
+ tx.setOrder([C2, C1]);
130
134
  }),
131
135
  );
132
136
 
@@ -146,8 +150,8 @@ describe("document hooks", () => {
146
150
  expect(() =>
147
151
  act(() =>
148
152
  edit((tx) => {
149
- tx.setCode("c1", "rolled back");
150
- tx.deleteCell("missing");
153
+ tx.setCode(C1, "rolled back");
154
+ tx.deleteCell(cellId("missing"));
151
155
  }),
152
156
  ),
153
157
  ).toThrow("does not exist");
@@ -162,15 +166,15 @@ describe("document hooks", () => {
162
166
  const onOrder = vi.fn();
163
167
  const onEdit = vi.fn();
164
168
  function Code() {
165
- onCode(useNotebookCellCode("c1"));
169
+ onCode(useNotebookCellCode(C1));
166
170
  return null;
167
171
  }
168
172
  function Name() {
169
- onName(useNotebookCellName("c1"));
173
+ onName(useNotebookCellName(C1));
170
174
  return null;
171
175
  }
172
176
  function Config() {
173
- onConfig(useNotebookCellConfig("c1"));
177
+ onConfig(useNotebookCellConfig(C1));
174
178
  return null;
175
179
  }
176
180
  function Order() {
@@ -199,7 +203,7 @@ describe("document hooks", () => {
199
203
  );
200
204
  clear();
201
205
 
202
- act(() => edit((tx) => tx.setCode("c1", "local")));
206
+ act(() => edit((tx) => tx.setCode(C1, "local")));
203
207
  expect(onCode).toHaveBeenCalledWith("local");
204
208
  expect(onName).not.toHaveBeenCalled();
205
209
  expect(onConfig).not.toHaveBeenCalled();
@@ -207,7 +211,7 @@ describe("document hooks", () => {
207
211
  expect(onEdit).not.toHaveBeenCalled();
208
212
  clear();
209
213
 
210
- act(() => edit((tx) => tx.setCode("c2", "other")));
214
+ act(() => edit((tx) => tx.setCode(C2, "other")));
211
215
  expect(
212
216
  [onCode, onName, onConfig, onOrder, onEdit].map((fn) => fn.mock.calls),
213
217
  ).toEqual([[], [], [], [], []]);
@@ -232,8 +236,8 @@ describe("document hooks", () => {
232
236
 
233
237
  act(() =>
234
238
  edit((tx) => {
235
- tx.updateConfig("c1", { disabled: true });
236
- tx.setOrder(["c2", "c1"]);
239
+ tx.updateConfig(C1, { disabled: true });
240
+ tx.setOrder([C2, C1]);
237
241
  }),
238
242
  );
239
243
  expect(onConfig).toHaveBeenCalledWith({ ...CONFIG, disabled: true });
@@ -250,14 +254,14 @@ describe("document hooks", () => {
250
254
  code: useNotebookCellCode(id),
251
255
  edit: useNotebookDocumentEdit(),
252
256
  }),
253
- { wrapper, initialProps: "c1" },
257
+ { wrapper, initialProps: C1 },
254
258
  );
255
259
  const edit = result.current.edit;
256
- rerender("c2");
260
+ rerender(C2);
257
261
  expect(result.current).toEqual({ code: "y = 2", edit });
258
- act(() => edit((tx) => tx.setCode("c1", "old subscription")));
262
+ act(() => edit((tx) => tx.setCode(C1, "old subscription")));
259
263
  expect(result.current).toEqual({ code: "y = 2", edit });
260
- act(() => edit((tx) => tx.setCode("c2", "new subscription")));
264
+ act(() => edit((tx) => tx.setCode(C2, "new subscription")));
261
265
  expect(result.current).toEqual({ code: "new subscription", edit });
262
266
  });
263
267
 
@@ -266,9 +270,9 @@ describe("document hooks", () => {
266
270
  const { result } = renderHook(
267
271
  () => ({
268
272
  order: useNotebookCellOrder(),
269
- code: useNotebookCellCode("c1"),
270
- name: useNotebookCellName("c1"),
271
- config: useNotebookCellConfig("c1"),
273
+ code: useNotebookCellCode(C1),
274
+ name: useNotebookCellName(C1),
275
+ config: useNotebookCellConfig(C1),
272
276
  edit: useNotebookDocumentEdit(),
273
277
  }),
274
278
  { wrapper },
@@ -292,7 +296,7 @@ describe("document hooks", () => {
292
296
  order: ["c1", "c2"],
293
297
  edit,
294
298
  });
295
- act(() => edit((tx) => tx.setCode("c1", "")));
299
+ act(() => edit((tx) => tx.setCode(C1, "")));
296
300
  expect(result.current.code).toBe("");
297
301
  act(() => store.set(source, null));
298
302
  expect(result.current).toEqual({ ...absent, order: null });
@@ -300,8 +304,8 @@ describe("document hooks", () => {
300
304
  expect(result.current.code).toBe("");
301
305
  act(() =>
302
306
  edit((tx) => {
303
- tx.deleteCell("c1");
304
- tx.deleteCell("c2");
307
+ tx.deleteCell(C1);
308
+ tx.deleteCell(C2);
305
309
  }),
306
310
  );
307
311
  expect(result.current).toEqual({ ...absent, order: [] });
@@ -310,19 +314,19 @@ describe("document hooks", () => {
310
314
  it("preserves drafts across Strict Mode remounts until the session ends", () => {
311
315
  const { wrapper, controller, detached } = setup();
312
316
  const useProbe = () => ({
313
- code: useNotebookCellCode("c1"),
317
+ code: useNotebookCellCode(C1),
314
318
  edit: useNotebookDocumentEdit(),
315
319
  });
316
320
  const first = renderHook(useProbe, { wrapper, reactStrictMode: true });
317
321
  const edit = first.result.current.edit;
318
- act(() => edit((tx) => tx.setCode("c1", "strict mode edit")));
322
+ act(() => edit((tx) => tx.setCode(C1, "strict mode edit")));
319
323
  expect(first.result.current.code).toBe("strict mode edit");
320
324
  first.unmount();
321
325
  expect(detached).not.toHaveBeenCalled();
322
326
 
323
327
  const second = renderHook(useProbe, { wrapper, reactStrictMode: true });
324
328
  expect(second.result.current.code).toBe("strict mode edit");
325
- act(() => edit((tx) => tx.setCode("c1", "same session")));
329
+ act(() => edit((tx) => tx.setCode(C1, "same session")));
326
330
  expect(second.result.current.code).toBe("same session");
327
331
  second.unmount();
328
332
  controller.abort();
@@ -342,7 +346,7 @@ describe("document hooks", () => {
342
346
  const seen = vi.fn();
343
347
  function Probe() {
344
348
  seen({
345
- code: useNotebookCellCode("c1"),
349
+ code: useNotebookCellCode(C1),
346
350
  edit: useNotebookDocumentEdit(),
347
351
  });
348
352
  return null;
@@ -357,7 +361,7 @@ describe("document hooks", () => {
357
361
  const { rerender } = render(tree(first));
358
362
  const oldEdit: ReturnType<typeof useNotebookDocumentEdit> =
359
363
  seen.mock.calls.at(-1)![0].edit;
360
- act(() => oldEdit((tx) => tx.setCode("c1", "first draft")));
364
+ act(() => oldEdit((tx) => tx.setCode(C1, "first draft")));
361
365
  rerender(tree(second));
362
366
  act(() => first.controller.abort());
363
367
  expect(first.detached).toHaveBeenCalledOnce();
@@ -367,7 +371,7 @@ describe("document hooks", () => {
367
371
  } = seen.mock.calls.at(-1)![0];
368
372
  expect(latest.code).toBe("second source");
369
373
  expect(latest.edit).not.toBe(oldEdit);
370
- act(() => latest.edit((tx) => tx.setCode("c1", "second draft")));
374
+ act(() => latest.edit((tx) => tx.setCode(C1, "second draft")));
371
375
  expect(seen.mock.calls.at(-1)![0].code).toBe("second draft");
372
376
  const stale = vi.fn();
373
377
  oldEdit(stale);
@@ -2,12 +2,15 @@
2
2
 
3
3
  import { vi } from "vitest";
4
4
  import { test } from "./scenario-fixture";
5
+ import { cellId } from "@/__tests__/branded";
6
+
7
+ const C3 = cellId("c3");
5
8
 
6
9
  test("closing a session before the scheduled send prevents submission", async ({
7
10
  expect,
8
11
  session: { user, notebook, controller },
9
12
  }) => {
10
- user.changeCode("c3", "local");
13
+ user.changeCode(C3, "local");
11
14
  const reason = new Error("Editing session ended");
12
15
  controller.abort(reason);
13
16
  await vi.advanceTimersByTimeAsync(1000);
@@ -20,7 +23,7 @@ test("closing a session before a queued flush starts prevents submission", async
20
23
  expect,
21
24
  session: { user, notebook, controller },
22
25
  }) => {
23
- user.changeCode("c3", "local");
26
+ user.changeCode(C3, "local");
24
27
  const flushed = user.sync();
25
28
  const reason = new Error("Editing session ended");
26
29
  controller.abort(reason);
@@ -32,7 +35,7 @@ test("closing a session before a queued flush starts prevents submission", async
32
35
  test.for(["request", "confirmation", "retry"] as const)(
33
36
  "closing a session during %s stops synchronization",
34
37
  async (phase, { expect, session: { user, host, notebook, controller } }) => {
35
- user.changeCode("c3", "local");
38
+ user.changeCode(C3, "local");
36
39
  const flushed = user.sync();
37
40
  const request = await host.nextRequest();
38
41
  if (phase === "confirmation") {
@@ -49,9 +52,9 @@ test.for(["request", "confirmation", "retry"] as const)(
49
52
  expect(request.signal.aborted).toBe(true);
50
53
  }
51
54
 
52
- host.changeCell("c1", { code: "later" });
55
+ host.changeCell(cellId("c1"), { code: "later" });
53
56
  host.deliverSnapshot();
54
- user.changeCode("c3", "after closing");
57
+ user.changeCode(C3, "after closing");
55
58
  await vi.advanceTimersByTimeAsync(1000);
56
59
  expect(notebook.edit).toHaveBeenCalledOnce();
57
60
  expect(vi.getTimerCount()).toBe(0);
@@ -10,6 +10,9 @@ import type { Document } from "../../replica/resources/document";
10
10
  import { createDocumentModel } from "../model";
11
11
  import { type FakeEdit, fakeBackend } from "../../replica/__tests__/fixtures";
12
12
  import { cell, document, withCells } from "./fixtures";
13
+ import { cellId } from "@/__tests__/branded";
14
+
15
+ const C1 = cellId("c1");
13
16
 
14
17
  function response(confirmed: Document): ResultOf<"notebook.edit"> {
15
18
  return {
@@ -72,9 +75,9 @@ function setup({ connected = true } = {}) {
72
75
  controller,
73
76
  unmounted,
74
77
  edit: (code: string) =>
75
- store.set(model.editAtom, (tx) => tx.setCode("c1", code)),
78
+ store.set(model.editAtom, (tx) => tx.setCode(C1, code)),
76
79
  status: () => store.get(model.syncStatusAtom),
77
- value: () => store.get(model.documentAtom)?.cells.get("c1"),
80
+ value: () => store.get(model.documentAtom)?.cells.get(C1),
78
81
  };
79
82
  }
80
83
 
@@ -98,7 +101,7 @@ describe("document synchronization", () => {
98
101
  shownDocumentAtom: source,
99
102
  backendAtom: atom(fakeBackend({ edit })),
100
103
  });
101
- store.set(model.editAtom, (tx) => tx.setCode("c1", "local"));
104
+ store.set(model.editAtom, (tx) => tx.setCode(C1, "local"));
102
105
  await expect(model.flush()).rejects.toThrow("not started");
103
106
  expect(store.get(model.documentAtom)).toBeNull();
104
107
  expect(store.get(model.syncStatusAtom)).toEqual({ status: "unavailable" });
@@ -150,7 +153,7 @@ describe("document synchronization", () => {
150
153
  const next = new AbortController();
151
154
  lifetimes.push(next);
152
155
  model.start({ signal: next.signal });
153
- expect(store.get(model.documentAtom)?.cells.get("c1")?.code).toBe("x = 1");
156
+ expect(store.get(model.documentAtom)?.cells.get(C1)?.code).toBe("x = 1");
154
157
  });
155
158
 
156
159
  it("starts again without the drafts of a stopped run", () => {
@@ -164,7 +167,7 @@ describe("document synchronization", () => {
164
167
  lifetimes.push(next);
165
168
  model.start({ signal: next.signal });
166
169
  expect(value()?.code).toBe("x = 1");
167
- store.set(model.editAtom, (tx) => tx.setCode("c1", "restarted"));
170
+ store.set(model.editAtom, (tx) => tx.setCode(C1, "restarted"));
168
171
  expect(value()?.code).toBe("restarted");
169
172
  });
170
173
 
@@ -20,8 +20,8 @@ export function protocolFixture(name: string): unknown {
20
20
  }
21
21
 
22
22
  export function initialDocument(): Document {
23
- const cells = new Map<Protocol.CellId, Protocol.Cell>();
24
- let revision: Protocol.Document | undefined;
23
+ const cells = new Map<Protocol.CellId, Protocol.CellOutput>();
24
+ let revision: Protocol.DocumentOutput | undefined;
25
25
  for (const event of fixtureEvents("notebook-events.sse")) {
26
26
  if (event.event === "ready") {
27
27
  break;