@marimo-team/islands 0.26.1-dev20 → 0.26.1-dev25
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/{ConnectedDataExplorerComponent-CR9WyiEc.js → ConnectedDataExplorerComponent-jtTaDisw.js} +16 -16
- package/dist/{ErrorBoundary-Cx-CwafE.js → ErrorBoundary-Bs2ehxEI.js} +6 -6
- package/dist/{abnfDiagram-VCTEODGH-DGAbsdXT.js → abnfDiagram-VCTEODGH-cUj3Gnnh.js} +2 -2
- package/dist/{any-language-editor-DzGF1ll-.js → any-language-editor-BHgkY7jY.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-D4DnIo7R.js → architectureDiagram-5GKGNRK7-CIAZgn9d.js} +1 -1
- package/dist/{assertNever-CqwxSD_2.js → assertNever-BHnIohkX.js} +13 -13
- package/dist/{chat-ui-qZdDDrzU.js → chat-ui-DOvIzlMA.js} +46 -46
- package/dist/{check-D9vf6LYF.js → check-LtjuWmNn.js} +1 -1
- package/dist/{chunk-IMKFNOWR-Bc_i6jWx.js → chunk-IMKFNOWR-CB9N3qYR.js} +1 -1
- package/dist/{chunk-SHT3W25Y-CGML5pnF.js → chunk-SHT3W25Y-D9njV7TI.js} +1 -1
- package/dist/{chunk-SVP7TREG-ZpeFKfFT.js → chunk-SVP7TREG-CUCE0BFm.js} +1 -1
- package/dist/{chunk-TICWLB2K-C6cLmcg8.js → chunk-TICWLB2K-iQB6ttkI.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV--q40NTXr.js → classDiagram-ZZMXUADV-BI1VBNIo.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-Dt_Pp94L.js → classDiagram-v2-VYDZK3BY-BYL3asWh.js} +2 -2
- package/dist/{code-visibility-CVfXV6fG.js → code-visibility-BnMkbydx.js} +19 -19
- package/dist/{common-BXRJCkJO.js → common-CQur5dRA.js} +156 -156
- package/dist/{config-B8JCQMby.js → config-DL9e-OWE.js} +3 -3
- package/dist/{copy-icon-BLig0ZKb.js → copy-icon-rYV2znAe.js} +2 -2
- package/dist/{createReducer-BIUQ3TbG.js → createReducer-BdiSrxHu.js} +5 -5
- package/dist/{cynefinDiagram-5FMLGOSQ-2FtF_-cc.js → cynefinDiagram-5FMLGOSQ-DpGtYvnZ.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-Cymu2SPS.js → dagre-GXQ25YYZ-B5GDC2kN.js} +1 -1
- package/dist/{data-grid-overlay-editor-Mbtx3F9C.js → data-grid-overlay-editor-BXEY35Xl.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-OwDa8kAa.js → diagram-S7CK7UJ4-B2T25t1t.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-CzRDwZwd.js → diagram-UQ7AKVKN-Dy3B5L_z.js} +1 -1
- package/dist/{diagram-VX7I27RA-XRIcgMDs.js → diagram-VX7I27RA-tOptWvNh.js} +1 -1
- package/dist/{diagram-Z3DM3KII-DdRDYAs6.js → diagram-Z3DM3KII-DsgZAokO.js} +1 -1
- package/dist/{dialog-DGh2HNAO.js → dialog-vs6x3On9.js} +19 -19
- package/dist/{dropdown-menu-ChH3oiqI.js → dropdown-menu-DYN2RV5d.js} +193 -193
- package/dist/{ebnfDiagram-PWID7BFC-CZMNMGNP.js → ebnfDiagram-PWID7BFC-CGWECzS1.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-ByxHAN4b.js → erDiagram-RLTQ6QDP-CZLi87y3.js} +1 -1
- package/dist/{error-banner-BvRaQnGH.js → error-banner-D-AC7pQx.js} +70 -70
- package/dist/{error-entries-DhI0hGvj.js → error-entries-CncQR572.js} +443 -436
- package/dist/{feedback-button-zx4NcNDn.js → feedback-button-BAOp7zqu.js} +120 -120
- package/dist/{flowDiagram-HODETNUW-BQpzWx5O.js → flowDiagram-HODETNUW-CS86WYbX.js} +2 -2
- package/dist/{formats-BxP8k8Un.js → formats-BUFLQJXY.js} +1 -1
- package/dist/{glide-data-editor-CvezoJKg.js → glide-data-editor-Ce94qTW7.js} +11 -11
- package/dist/{glide-utils-bKdvDwwo.js → glide-utils-CZ-O-CB_.js} +2 -2
- package/dist/{globals-CQuPaxzy.js → globals-Uqg4j5z5.js} +3 -3
- package/dist/{html-to-image-B803aaWE.js → html-to-image-BU7H-AM1.js} +4323 -4318
- package/dist/{infoDiagram-27XIBGKW-C9EWHkak.js → infoDiagram-27XIBGKW-C9JBFfpC.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-D67SGFvp.js → ishikawaDiagram-5VMMS53U-Eh3iuw2D.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-CTMTiazR.js → kanban-definition-UXKFOSKX-DYtuVwYD.js} +1 -1
- package/dist/main.js +401 -400
- package/dist/{mermaid-DE_tvTGF.js → mermaid--k1o49nH.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-LzNgDy8O.js → mindmap-definition-YA3MSWOX-Dn1Cnqys.js} +1 -1
- package/dist/{number-overlay-editor-DxM7vsCk.js → number-overlay-editor-Br_Vp3Ws.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-DFMS6feI.js → pegDiagram-XKGWAZYB-DiY7rITR.js} +2 -2
- package/dist/{pencil-CHkdsX07.js → pencil-AWgwbH4D.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-C0MSBop-.js → pieDiagram-E7YTZNPT-BL6InbDs.js} +1 -1
- package/dist/{process-output-CnCLfvnL.js → process-output-xJm8T5-E.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-mbdav2pV.js → railroadDiagram-O6MQD6OU-DterenMu.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-C1HNBBO6.js → requirementDiagram-BXWQKSXE-Vb5_9LHC.js} +1 -1
- package/dist/{reveal-component-BefmhjJF.js → reveal-component-B7TgfbYJ.js} +1008 -1008
- package/dist/{select-CvorIE3l.js → select-CKLRKIzB.js} +298 -298
- package/dist/{sequenceDiagram-WJ2MYXX4-D6gBHifq.js → sequenceDiagram-WJ2MYXX4-BWsq8hMt.js} +1 -1
- package/dist/{spec-ayzaXGVq.js → spec-C4uOz0Em.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-Bx-fTtRZ.js → stateDiagram-D77RDMKH-nfKKy6aQ.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-Cec8T2yO.js → stateDiagram-v2-MP3YSRHH-DMUHA_9A.js} +2 -2
- package/dist/{static-state-CqwW3B_X.js → static-state-DZ1nSa6e.js} +9 -9
- package/dist/{swimlanes-42K2YHIH-C2bAgnov.js → swimlanes-42K2YHIH-N4qHIMoc.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js → swimlanesDiagram-VR7AAH4N-DQpDDjQb.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-DTJ0Rx8X.js → timeline-definition-24CTP7MA-Od8dY9F5.js} +1 -1
- package/dist/{toast-6V8Og7d5.js → toast-bhZHUEal.js} +187 -187
- package/dist/{tooltip-D0h-ZJ6j.js → tooltip-DSWC_Td_.js} +40 -40
- package/dist/{use-restore-focus-BFvwj2Hj.js → use-restore-focus-ocw7t85i.js} +1371 -1373
- package/dist/{useDateFormatter-D6o9PsWt.js → useDateFormatter-BiDS8uXQ.js} +2 -2
- package/dist/{useDeepCompareMemoize-D-Pbv7dN.js → useDeepCompareMemoize-BsaXfZ8C.js} +1 -1
- package/dist/{useLifecycle-CE0yGTMF.js → useLifecycle-CCV7yZ-v.js} +1 -1
- package/dist/{vega-component-DTf7GHQe.js → vega-component-DpTyTrz3.js} +6 -6
- package/dist/{vennDiagram-4TSXK5OY-lIM3SAjl.js → vennDiagram-4TSXK5OY-Di3T2YMb.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-Bw_t7uvA.js → wardleyDiagram-VM6X3IG4-CKOF5DTi.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-BXwkLYKj.js → xychartDiagram-S5SC5T6Z-GYLPWSeb.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +27 -5
- package/src/__tests__/branded.ts +4 -0
- package/src/__tests__/notebook-analysis.ts +48 -0
- package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
- package/src/components/editor/cell/__tests__/useRunCells.test.tsx +2 -2
- package/src/components/editor/navigation/__tests__/navigation.test.ts +0 -4
- package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
- package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
- package/src/core/cells/__tests__/pending-delete-service.test.tsx +4 -11
- package/src/core/cells/__tests__/runs.test.ts +11 -11
- package/src/core/cells/add-missing-import.ts +2 -3
- package/src/core/cells/runs.ts +6 -4
- package/src/core/cells/session.ts +4 -1
- package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
- package/src/core/codemirror/code-lens/__tests__/extension.test.ts +8 -13
- package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
- package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -13
- package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +16 -35
- package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
- package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +8 -14
- package/src/core/datasets/__tests__/data-source.test.ts +15 -17
- package/src/core/datasets/data-source-connections.ts +8 -11
- package/src/core/datasets/state.ts +7 -12
- package/src/core/executions/__tests__/atoms.test.ts +2 -2
- package/src/core/executions/__tests__/freshness.test.ts +10 -5
- package/src/core/executions/__tests__/interrupt.test.ts +3 -1
- package/src/core/executions/__tests__/output-lifecycle.test.ts +3 -3
- package/src/core/executions/__tests__/output.test.ts +2 -2
- package/src/core/executions/__tests__/run.test.ts +2 -2
- package/src/core/executions/__tests__/select.test.ts +10 -10
- package/src/core/executions/atoms.ts +2 -1
- package/src/core/executions/freshness.ts +2 -2
- package/src/core/islands/bootstrap.ts +0 -2
- package/src/core/notebook/replica/__tests__/executions.test.ts +13 -9
- package/src/core/notebook/replica/__tests__/replica.test.ts +7 -2
- package/src/core/notebook/replica/replica.ts +11 -2
- package/src/core/notebook/replica/resources/executions.ts +29 -20
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +192 -1
- package/src/core/session/useNotebookSession.tsx +37 -37
- package/src/core/storage/__tests__/state.test.ts +6 -9
- package/src/core/storage/state.ts +5 -8
- package/src/core/transports/__tests__/static.test.ts +2 -1
- package/src/core/variables/state.ts +73 -68
- package/src/core/variables/types.ts +2 -2
- package/src/core/wasm/bridge.ts +5 -4
- package/src/core/variables/__tests__/state.test.ts +0 -148
|
@@ -37,7 +37,7 @@ vi.mock("@/core/runtime/config", async () => {
|
|
|
37
37
|
|
|
38
38
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
39
39
|
import { Deferred } from "@/utils/Deferred";
|
|
40
|
-
import { cellId } from "@/__tests__/branded";
|
|
40
|
+
import { cellId, variableName } from "@/__tests__/branded";
|
|
41
41
|
import { alertAtom, getPackageAlert } from "@/core/alerts/state";
|
|
42
42
|
import { stagedAICellsAtom } from "@/core/ai/staged-cells";
|
|
43
43
|
import { cellRuntimeAtom } from "@/core/cells/cells";
|
|
@@ -59,7 +59,10 @@ import {
|
|
|
59
59
|
cell,
|
|
60
60
|
CONFIG,
|
|
61
61
|
document as documentOf,
|
|
62
|
+
withCells,
|
|
62
63
|
} from "@/core/notebook/document/__tests__/fixtures";
|
|
64
|
+
import { variablesAtom } from "@/core/variables/state";
|
|
65
|
+
import { storageNamespacesAtom } from "@/core/storage/state";
|
|
63
66
|
import { initialRunCompletedAtom } from "../../kernel/state";
|
|
64
67
|
import { connectionAtom, startupProgressAtom } from "../../network/connection";
|
|
65
68
|
import { generateSessionId } from "../../kernel/session";
|
|
@@ -75,6 +78,7 @@ import {
|
|
|
75
78
|
import { MockExecutions } from "@/__mocks__/executions";
|
|
76
79
|
import { VirtualFileTracker } from "@/core/static/virtual-file-tracker";
|
|
77
80
|
import { useNotebookSession } from "../useNotebookSession";
|
|
81
|
+
import type { CellAnalysis } from "@marimo-team/client/protocol";
|
|
78
82
|
import { type NotebookTransport, StreamStopped } from "@marimo-team/client";
|
|
79
83
|
|
|
80
84
|
const C1 = cellId("c1");
|
|
@@ -442,6 +446,193 @@ describe("useNotebookSession messages", () => {
|
|
|
442
446
|
expect(blocked().size).toBe(0);
|
|
443
447
|
});
|
|
444
448
|
|
|
449
|
+
function publishDocument(document: ReturnType<typeof documentOf>) {
|
|
450
|
+
for (const cell of document.cells.values()) {
|
|
451
|
+
receive({ event: "cell", data: { cell } });
|
|
452
|
+
}
|
|
453
|
+
receive({ event: "document", data: { document: document.revision } });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function analyzeVariables(
|
|
457
|
+
document: ReturnType<typeof documentOf>,
|
|
458
|
+
cells: Record<string, CellAnalysis>,
|
|
459
|
+
) {
|
|
460
|
+
receive({
|
|
461
|
+
event: "analysis",
|
|
462
|
+
data: {
|
|
463
|
+
analysis: {
|
|
464
|
+
notebook_id: document.revision.notebook_id,
|
|
465
|
+
document_etag: document.revision.etag,
|
|
466
|
+
cells,
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
it("joins analysis to its defining cell's binding across updates, removal, and edits", () => {
|
|
473
|
+
const document = documentOf();
|
|
474
|
+
receive({
|
|
475
|
+
event: "notebook",
|
|
476
|
+
data: { notebook: MockExecutions.notebook() },
|
|
477
|
+
});
|
|
478
|
+
publishDocument(document);
|
|
479
|
+
const execution = MockExecutions.completed("c1");
|
|
480
|
+
const variable = {
|
|
481
|
+
id: "bound-x",
|
|
482
|
+
execution_id: execution.id,
|
|
483
|
+
name: "x",
|
|
484
|
+
type: "int",
|
|
485
|
+
preview: "1",
|
|
486
|
+
revision: { execution_id: execution.id, update: 0 },
|
|
487
|
+
};
|
|
488
|
+
receive({ event: "execution", data: { execution } });
|
|
489
|
+
receive({ event: "variable", data: { variable } });
|
|
490
|
+
expect(store.get(variablesAtom)).toEqual({});
|
|
491
|
+
receive({ event: "ready", data: {}, id: "1" });
|
|
492
|
+
const x = { name: "x", declaredBy: ["c1"], usedBy: [] };
|
|
493
|
+
expect(store.get(variablesAtom)).toEqual({
|
|
494
|
+
x: { ...x, dataType: "int", value: "1" },
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
analyzeVariables(document, {
|
|
498
|
+
c2: { defs: ["pending"], refs: ["x"], diagnostics: [] },
|
|
499
|
+
c1: { defs: ["x", "pending"], refs: [], diagnostics: [] },
|
|
500
|
+
});
|
|
501
|
+
const declarations = {
|
|
502
|
+
x: { ...x, usedBy: ["c2"] },
|
|
503
|
+
pending: { name: "pending", declaredBy: ["c2", "c1"], usedBy: [] },
|
|
504
|
+
};
|
|
505
|
+
expect(store.get(variablesAtom)).toEqual({
|
|
506
|
+
...declarations,
|
|
507
|
+
x: { ...declarations.x, dataType: "int", value: "1" },
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const updated = {
|
|
511
|
+
...variable,
|
|
512
|
+
preview: "2",
|
|
513
|
+
revision: { ...variable.revision, update: 1 },
|
|
514
|
+
};
|
|
515
|
+
receive({ event: "variable", data: { variable: updated } });
|
|
516
|
+
const variables = store.get(variablesAtom);
|
|
517
|
+
expect(variables).toEqual({
|
|
518
|
+
...declarations,
|
|
519
|
+
x: { ...declarations.x, dataType: "int", value: "2" },
|
|
520
|
+
});
|
|
521
|
+
receive({ event: "execution", data: { execution } });
|
|
522
|
+
expect(store.get(variablesAtom)).toBe(variables);
|
|
523
|
+
receive({ event: "variable.removed", data: { id: variable.id } });
|
|
524
|
+
expect(store.get(variablesAtom)).toEqual(declarations);
|
|
525
|
+
|
|
526
|
+
receive({ event: "variable", data: { variable } });
|
|
527
|
+
const moved = withCells(document, {
|
|
528
|
+
c1: cell("c1", ""),
|
|
529
|
+
c2: cell("c2", "x = 3"),
|
|
530
|
+
});
|
|
531
|
+
publishDocument(moved);
|
|
532
|
+
const duringEdit = { ...variable, name: "new_name", id: "bound-new" };
|
|
533
|
+
receive({ event: "variable", data: { variable: duringEdit } });
|
|
534
|
+
expect(store.get(variablesAtom)[variableName("new_name")]).toEqual({
|
|
535
|
+
name: "new_name",
|
|
536
|
+
declaredBy: ["c1"],
|
|
537
|
+
usedBy: [],
|
|
538
|
+
dataType: "int",
|
|
539
|
+
value: "1",
|
|
540
|
+
});
|
|
541
|
+
analyzeVariables(moved, {
|
|
542
|
+
c1: { defs: [], refs: [], diagnostics: [] },
|
|
543
|
+
c2: { defs: ["x"], refs: [], diagnostics: [] },
|
|
544
|
+
});
|
|
545
|
+
expect(store.get(variablesAtom)[variableName("new_name")]).toEqual({
|
|
546
|
+
name: "new_name",
|
|
547
|
+
declaredBy: [],
|
|
548
|
+
usedBy: [],
|
|
549
|
+
dataType: "int",
|
|
550
|
+
value: "1",
|
|
551
|
+
});
|
|
552
|
+
receive({ event: "variable.removed", data: { id: duringEdit.id } });
|
|
553
|
+
expect(store.get(variablesAtom)).toEqual({
|
|
554
|
+
x: { name: "x", declaredBy: ["c2"], usedBy: [] },
|
|
555
|
+
});
|
|
556
|
+
const beforeReset = store.get(variablesAtom);
|
|
557
|
+
receive({ event: "reset", data: {} });
|
|
558
|
+
expect(store.get(variablesAtom)).toEqual(beforeReset);
|
|
559
|
+
receive({
|
|
560
|
+
event: "notebook",
|
|
561
|
+
data: { notebook: MockExecutions.notebook("n2") },
|
|
562
|
+
});
|
|
563
|
+
publishDocument(documentOf("n2"));
|
|
564
|
+
receive({ event: "ready", data: {}, id: "2" });
|
|
565
|
+
expect(store.get(variablesAtom)).toEqual({});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("keeps a live variable and its namespace through an incomplete edit", () => {
|
|
569
|
+
const document = documentOf();
|
|
570
|
+
const discover = () =>
|
|
571
|
+
act(() =>
|
|
572
|
+
connection(fake).send({
|
|
573
|
+
op: "storage-namespaces",
|
|
574
|
+
namespaces: ["x", "z"].map((name) => ({
|
|
575
|
+
name: variableName(name),
|
|
576
|
+
displayName: name,
|
|
577
|
+
protocol: "s3",
|
|
578
|
+
rootPath: "",
|
|
579
|
+
backendType: "obstore",
|
|
580
|
+
storageEntries: [],
|
|
581
|
+
})),
|
|
582
|
+
} satisfies NotificationPayload["data"]),
|
|
583
|
+
);
|
|
584
|
+
const namespaces = () =>
|
|
585
|
+
store.get(storageNamespacesAtom).map((ns) => ns.name);
|
|
586
|
+
receive({
|
|
587
|
+
event: "notebook",
|
|
588
|
+
data: { notebook: MockExecutions.notebook() },
|
|
589
|
+
});
|
|
590
|
+
publishDocument(document);
|
|
591
|
+
receive({ event: "ready", data: {}, id: "1" });
|
|
592
|
+
// Discovery can precede the binding from the same execution.
|
|
593
|
+
discover();
|
|
594
|
+
const execution = MockExecutions.completed("c1");
|
|
595
|
+
const variable = {
|
|
596
|
+
id: "bound-x",
|
|
597
|
+
execution_id: execution.id,
|
|
598
|
+
name: "x",
|
|
599
|
+
type: "S3Store",
|
|
600
|
+
preview: "s3://bucket",
|
|
601
|
+
revision: { execution_id: execution.id, update: 0 },
|
|
602
|
+
};
|
|
603
|
+
receive({ event: "execution", data: { execution } });
|
|
604
|
+
receive({ event: "variable", data: { variable } });
|
|
605
|
+
analyzeVariables(document, {
|
|
606
|
+
c1: { defs: ["x"], refs: [], diagnostics: [] },
|
|
607
|
+
});
|
|
608
|
+
const beforeEdit = store.get(variablesAtom);
|
|
609
|
+
const edited = withCells(document, { c1: cell("c1", "x = (") });
|
|
610
|
+
publishDocument(edited);
|
|
611
|
+
analyzeVariables(edited, { c1: { defs: [], refs: [], diagnostics: [] } });
|
|
612
|
+
expect(namespaces()).toEqual(["x", "z"]);
|
|
613
|
+
expect(store.get(variablesAtom)).toEqual({
|
|
614
|
+
x: {
|
|
615
|
+
name: "x",
|
|
616
|
+
declaredBy: [],
|
|
617
|
+
usedBy: [],
|
|
618
|
+
dataType: "S3Store",
|
|
619
|
+
value: "s3://bucket",
|
|
620
|
+
},
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
publishDocument(document);
|
|
624
|
+
analyzeVariables(document, {
|
|
625
|
+
c1: { defs: ["x"], refs: [], diagnostics: [] },
|
|
626
|
+
});
|
|
627
|
+
expect(namespaces()).toEqual(["x", "z"]);
|
|
628
|
+
expect(store.get(variablesAtom)).toEqual(beforeEdit);
|
|
629
|
+
receive({ event: "variable.removed", data: { id: variable.id } });
|
|
630
|
+
expect(namespaces()).toEqual(["z"]);
|
|
631
|
+
expect(store.get(variablesAtom)).toEqual({
|
|
632
|
+
x: { name: "x", declaredBy: ["c1"], usedBy: [] },
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
|
|
445
636
|
it("records completion of the initial run", () => {
|
|
446
637
|
const notification = {
|
|
447
638
|
op: "completed-run",
|
|
@@ -73,8 +73,7 @@ import {
|
|
|
73
73
|
ListStorageEntries,
|
|
74
74
|
} from "../storage/request-registry";
|
|
75
75
|
import { useStorageActions } from "../storage/state";
|
|
76
|
-
import {
|
|
77
|
-
import type { VariableName } from "../variables/types";
|
|
76
|
+
import { variableBindingsAtom } from "../variables/state";
|
|
78
77
|
import {
|
|
79
78
|
activeDocumentModelAtom,
|
|
80
79
|
confirmedDocumentAtom,
|
|
@@ -99,10 +98,9 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
99
98
|
const { reconcileStagedCells } = useStagedAICellsActions();
|
|
100
99
|
const { addExecution } = useRunsActions();
|
|
101
100
|
const setInitialRunCompleted = useSetAtom(initialRunCompletedAtom);
|
|
102
|
-
const {
|
|
103
|
-
|
|
104
|
-
const {
|
|
105
|
-
const { addDataSourceConnection, filterDataSourcesFromVariables } =
|
|
101
|
+
const { addColumnPreview, addDatasets, removeDatasetsForVariables } =
|
|
102
|
+
useDatasetsActions();
|
|
103
|
+
const { addDataSourceConnection, removeConnectionsForVariables } =
|
|
106
104
|
useDataSourceActions();
|
|
107
105
|
const { setLayoutData } = useLayoutActions();
|
|
108
106
|
const [connection, setConnection] = useAtom(connectionAtom);
|
|
@@ -121,10 +119,8 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
121
119
|
const transportType = useAtomValue(connectionTransportTypeAtom);
|
|
122
120
|
const setCacheInfo = useSetAtom(cacheInfoAtom);
|
|
123
121
|
const setKernelStartupError = useSetAtom(kernelStartupErrorAtom);
|
|
124
|
-
const {
|
|
125
|
-
|
|
126
|
-
filterFromVariables: filterStorageFromVariables,
|
|
127
|
-
} = useStorageActions();
|
|
122
|
+
const { setNamespaces: setStorageNamespaces, removeNamespacesForVariables } =
|
|
123
|
+
useStorageActions();
|
|
128
124
|
|
|
129
125
|
const handleNotification = (msg: NotificationPayload) => {
|
|
130
126
|
switch (msg.data.op) {
|
|
@@ -227,33 +223,6 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
227
223
|
case "pdb-output":
|
|
228
224
|
showCommandOutput(msg.data);
|
|
229
225
|
return;
|
|
230
|
-
case "variables":
|
|
231
|
-
const variableNames = msg.data.variables.map((v) => v.name);
|
|
232
|
-
setVariables(
|
|
233
|
-
msg.data.variables.map((v) => ({
|
|
234
|
-
name: v.name,
|
|
235
|
-
declaredBy: v.declared_by,
|
|
236
|
-
usedBy: v.used_by,
|
|
237
|
-
})),
|
|
238
|
-
);
|
|
239
|
-
filterDatasetsFromVariables(variableNames);
|
|
240
|
-
filterDataSourcesFromVariables(variableNames);
|
|
241
|
-
filterStorageFromVariables(variableNames);
|
|
242
|
-
return;
|
|
243
|
-
case "variable-values":
|
|
244
|
-
setMetadata([
|
|
245
|
-
...(msg.data.removed ?? []).map((v) => ({
|
|
246
|
-
name: v.name as VariableName,
|
|
247
|
-
dataType: undefined,
|
|
248
|
-
value: undefined,
|
|
249
|
-
})),
|
|
250
|
-
...msg.data.variables.map((v) => ({
|
|
251
|
-
name: v.name as VariableName,
|
|
252
|
-
dataType: v.datatype,
|
|
253
|
-
value: v.value,
|
|
254
|
-
})),
|
|
255
|
-
]);
|
|
256
|
-
return;
|
|
257
226
|
case "alert":
|
|
258
227
|
toast({
|
|
259
228
|
title: msg.data.title,
|
|
@@ -447,6 +416,37 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
447
416
|
},
|
|
448
417
|
});
|
|
449
418
|
|
|
419
|
+
// Discovery can precede a binding. Remove only resources whose binding disappeared.
|
|
420
|
+
useLayoutEffect(() => {
|
|
421
|
+
let previous = store.get(variableBindingsAtom);
|
|
422
|
+
return store.sub(variableBindingsAtom, () => {
|
|
423
|
+
const current = store.get(variableBindingsAtom);
|
|
424
|
+
const removed = new Set<string>();
|
|
425
|
+
for (const [cellId, bindings] of previous ?? []) {
|
|
426
|
+
const next = current?.get(cellId);
|
|
427
|
+
if (bindings === next) {
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
for (const [id, binding] of bindings) {
|
|
431
|
+
if (!next?.has(id)) {
|
|
432
|
+
removed.add(binding.name);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
previous = current;
|
|
437
|
+
if (removed.size > 0) {
|
|
438
|
+
removeDatasetsForVariables(removed);
|
|
439
|
+
removeConnectionsForVariables(removed);
|
|
440
|
+
removeNamespacesForVariables(removed);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}, [
|
|
444
|
+
store,
|
|
445
|
+
removeDatasetsForVariables,
|
|
446
|
+
removeConnectionsForVariables,
|
|
447
|
+
removeNamespacesForVariables,
|
|
448
|
+
]);
|
|
449
|
+
|
|
450
450
|
const documentModel = useMemo(
|
|
451
451
|
() =>
|
|
452
452
|
createDocumentModel({
|
|
@@ -350,16 +350,13 @@ describe("storage state", () => {
|
|
|
350
350
|
});
|
|
351
351
|
});
|
|
352
352
|
|
|
353
|
-
describe("
|
|
353
|
+
describe("removeNamespacesForVariables", () => {
|
|
354
354
|
it("should keep namespaces whose variable is still in scope", () => {
|
|
355
355
|
const ns1 = makeNamespace({ name: variableName("var_a") });
|
|
356
356
|
const ns2 = makeNamespace({ name: variableName("var_b") });
|
|
357
357
|
actions.setNamespaces({ namespaces: [ns1, ns2] });
|
|
358
358
|
|
|
359
|
-
actions.
|
|
360
|
-
variableName("var_a"),
|
|
361
|
-
variableName("var_b"),
|
|
362
|
-
]);
|
|
359
|
+
actions.removeNamespacesForVariables(new Set(["unrelated"]));
|
|
363
360
|
|
|
364
361
|
expect(state.namespaces).toEqual([ns1, ns2]);
|
|
365
362
|
});
|
|
@@ -369,17 +366,17 @@ describe("storage state", () => {
|
|
|
369
366
|
const ns2 = makeNamespace({ name: variableName("var_b") });
|
|
370
367
|
actions.setNamespaces({ namespaces: [ns1, ns2] });
|
|
371
368
|
|
|
372
|
-
actions.
|
|
369
|
+
actions.removeNamespacesForVariables(new Set(["var_b"]));
|
|
373
370
|
|
|
374
371
|
expect(state.namespaces).toEqual([ns1]);
|
|
375
372
|
});
|
|
376
373
|
|
|
377
|
-
it("should remove
|
|
374
|
+
it("should remove namespaces for each removed binding", () => {
|
|
378
375
|
const ns1 = makeNamespace({ name: variableName("var_a") });
|
|
379
376
|
const ns2 = makeNamespace({ name: variableName("var_b") });
|
|
380
377
|
actions.setNamespaces({ namespaces: [ns1, ns2] });
|
|
381
378
|
|
|
382
|
-
actions.
|
|
379
|
+
actions.removeNamespacesForVariables(new Set(["var_a", "var_b"]));
|
|
383
380
|
|
|
384
381
|
expect(state.namespaces).toEqual([]);
|
|
385
382
|
});
|
|
@@ -395,7 +392,7 @@ describe("storage state", () => {
|
|
|
395
392
|
entries: [entry],
|
|
396
393
|
});
|
|
397
394
|
|
|
398
|
-
actions.
|
|
395
|
+
actions.removeNamespacesForVariables(new Set(["ns"]));
|
|
399
396
|
|
|
400
397
|
// Namespace removed, but entries remain (they are keyed independently)
|
|
401
398
|
expect(state.namespaces).toEqual([]);
|
|
@@ -5,7 +5,6 @@ import { useCallback, useRef, useState } from "react";
|
|
|
5
5
|
import { useAsyncData } from "@/hooks/useAsyncData";
|
|
6
6
|
import { createReducerAndAtoms } from "@/utils/createReducer";
|
|
7
7
|
import type { NotificationMessageData } from "../kernel/messages";
|
|
8
|
-
import type { VariableName } from "../variables/types";
|
|
9
8
|
import {
|
|
10
9
|
ListStorageEntries,
|
|
11
10
|
type StorageEntriesResult,
|
|
@@ -97,13 +96,11 @@ const {
|
|
|
97
96
|
};
|
|
98
97
|
},
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
return { ...state, namespaces };
|
|
99
|
+
removeNamespacesForVariables: (state, removed: ReadonlySet<string>) => {
|
|
100
|
+
const namespaces = state.namespaces.filter((ns) => !removed.has(ns.name));
|
|
101
|
+
return namespaces.length === state.namespaces.length
|
|
102
|
+
? state
|
|
103
|
+
: { ...state, namespaces };
|
|
107
104
|
},
|
|
108
105
|
});
|
|
109
106
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { createNotebookReducer, NotebookEvents } from "@marimo-team/client";
|
|
4
4
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
5
5
|
import { afterEach, assert, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { runId } from "@/__tests__/branded";
|
|
6
7
|
import type { NotebookBackend } from "../../notebook/replica";
|
|
7
8
|
import { document as documentResource } from "../../notebook/replica/resources/document";
|
|
8
9
|
import { executions } from "../../notebook/replica/resources/executions";
|
|
@@ -110,7 +111,7 @@ describe("static notebook backend", () => {
|
|
|
110
111
|
const cell = source.cells[0];
|
|
111
112
|
const execution: Protocol.ExecutionOutput = {
|
|
112
113
|
id: "embedded:result",
|
|
113
|
-
run_id: "embedded:run",
|
|
114
|
+
run_id: runId("embedded:run"),
|
|
114
115
|
runtime_id: "embedded",
|
|
115
116
|
caused_by_id: null,
|
|
116
117
|
cell_id: cell.id,
|
|
@@ -1,81 +1,86 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
3
|
+
import type { CellAnalysis } from "@marimo-team/client/protocol";
|
|
4
|
+
import { atom, useAtomValue } from "jotai";
|
|
5
|
+
import type { CellId } from "../cells/ids";
|
|
6
|
+
import {
|
|
7
|
+
activeNotebookReplicaAtom,
|
|
8
|
+
confirmedDocumentAtom,
|
|
9
|
+
notebookAnalysisAtom,
|
|
10
|
+
} from "../session/active-notebook";
|
|
11
|
+
import { Objects } from "@/utils/objects";
|
|
12
|
+
import type { VariableName, Variables } from "./types";
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
/** Null until the host has analyzed a revision of this notebook. */
|
|
15
|
+
const declaredVariablesAtom = atom((get): Variables | null => {
|
|
16
|
+
const analysis = get(notebookAnalysisAtom);
|
|
17
|
+
if (analysis === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
10
20
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (const variable of variables) {
|
|
22
|
-
newVariables[variable.name] = {
|
|
23
|
-
...oldVariables[variable.name],
|
|
24
|
-
...variable,
|
|
25
|
-
};
|
|
21
|
+
const declarations: Variables = Object.create(null);
|
|
22
|
+
const cells = Objects.entries<CellId, CellAnalysis>(analysis.cells);
|
|
23
|
+
for (const [cellId, cell] of cells) {
|
|
24
|
+
for (const name of cell.defs as VariableName[]) {
|
|
25
|
+
const variable = (declarations[name] ??= {
|
|
26
|
+
name,
|
|
27
|
+
declaredBy: [],
|
|
28
|
+
usedBy: [],
|
|
29
|
+
});
|
|
30
|
+
variable.declaredBy.push(cellId);
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (const variable of variables) {
|
|
32
|
-
newVariables[variable.name] = {
|
|
33
|
-
...newVariables[variable.name],
|
|
34
|
-
...variable,
|
|
35
|
-
};
|
|
32
|
+
}
|
|
33
|
+
for (const [cellId, cell] of cells) {
|
|
34
|
+
for (const name of cell.refs as VariableName[]) {
|
|
35
|
+
declarations[name]?.usedBy.push(cellId);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
}
|
|
38
|
+
return declarations;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const variableBindingsAtom = atom((get) => {
|
|
42
|
+
const replica = get(activeNotebookReplicaAtom);
|
|
43
|
+
return replica && get(replica.shownDocumentAtom)
|
|
44
|
+
? get(replica.executionsAtom).variables
|
|
45
|
+
: null;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const analysisMatchesDocumentAtom = atom((get) => {
|
|
49
|
+
const document = get(confirmedDocumentAtom);
|
|
50
|
+
return (
|
|
51
|
+
document !== null &&
|
|
52
|
+
get(notebookAnalysisAtom)?.document_etag === document.revision.etag
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const EMPTY: Variables = Object.freeze(Object.create(null));
|
|
57
|
+
|
|
58
|
+
export const variablesAtom = atom((get): Variables => {
|
|
59
|
+
const declarations = get(declaredVariablesAtom);
|
|
60
|
+
const bindings = get(variableBindingsAtom);
|
|
61
|
+
if (!bindings?.size) {
|
|
62
|
+
return declarations ?? EMPTY;
|
|
63
|
+
}
|
|
64
|
+
const current = get(analysisMatchesDocumentAtom);
|
|
65
|
+
const variables: Variables = Object.assign(Object.create(null), declarations);
|
|
66
|
+
for (const [cellId, items] of bindings) {
|
|
67
|
+
for (const item of items.values()) {
|
|
68
|
+
const name = item.name as VariableName;
|
|
69
|
+
const declaration = declarations?.[name];
|
|
70
|
+
const owner = declaration?.declaredBy.includes(cellId)
|
|
71
|
+
? declaration
|
|
72
|
+
: undefined;
|
|
73
|
+
if (current && declaration && !owner) {
|
|
50
74
|
continue;
|
|
51
75
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
value,
|
|
56
|
-
dataType: dataType,
|
|
76
|
+
variables[name] = {
|
|
77
|
+
...(owner ?? { name, declaredBy: current ? [] : [cellId], usedBy: [] }),
|
|
78
|
+
dataType: item.type,
|
|
79
|
+
value: item.preview,
|
|
57
80
|
};
|
|
58
81
|
}
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
}
|
|
83
|
+
return variables;
|
|
61
84
|
});
|
|
62
85
|
|
|
63
|
-
/**
|
|
64
|
-
* React hook to get the variables state.
|
|
65
|
-
*/
|
|
66
86
|
export const useVariables = () => useAtomValue(variablesAtom);
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* React hook to get the variables actions.
|
|
70
|
-
*/
|
|
71
|
-
export function useVariablesActions() {
|
|
72
|
-
return useActions();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { variablesAtom };
|
|
76
|
-
|
|
77
|
-
export const exportedForTesting = {
|
|
78
|
-
reducer,
|
|
79
|
-
createActions,
|
|
80
|
-
initialState,
|
|
81
|
-
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { TypedString } from "@/utils/typed";
|
|
4
4
|
import type { CellId } from "../cells/ids";
|
|
5
5
|
|
|
6
|
-
export type VariableName =
|
|
6
|
+
export type VariableName = TypedString<"VariableName">;
|
|
7
7
|
|
|
8
8
|
export interface Variable {
|
|
9
9
|
name: VariableName;
|
package/src/core/wasm/bridge.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
/* oxlint-disable typescript/no-explicit-any */
|
|
3
3
|
|
|
4
|
+
import type { RunOutput } from "@marimo-team/client/protocol";
|
|
4
5
|
import { createRPCRequestHandler } from "rpc-anywhere";
|
|
5
6
|
import { toast } from "@/components/ui/use-toast";
|
|
6
7
|
import { userConfigAtom } from "@/core/config/config";
|
|
@@ -349,10 +350,10 @@ export class PyodideBridge implements RunRequests, EditRequests {
|
|
|
349
350
|
if (replica === null) {
|
|
350
351
|
return false;
|
|
351
352
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
);
|
|
353
|
+
const runs: ReadonlyMap<string, RunOutput> = store.get(
|
|
354
|
+
replica.executionsAtom,
|
|
355
|
+
).runs;
|
|
356
|
+
return runs.get(runId)?.state.status === "running";
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
public sendRename: EditRequests["sendRename"] = async ({ filename }) => {
|