@marimo-team/frontend 0.25.3-dev141 → 0.25.3-dev3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.25.3-dev141",
3
+ "version": "0.25.3-dev3",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -183,7 +183,9 @@
183
183
  "preview:islands": "cross-env VITE_MARIMO_VERSION='0.4.6' VITE_MARIMO_ISLANDS=true vite --config islands/vite.config.mts build",
184
184
  "storybook": "storybook dev -p 6006",
185
185
  "build-storybook": "storybook build",
186
- "sync-katex-css": "node --experimental-strip-types scripts/sync-katex-css.ts"
186
+ "sync-katex-css": "node --experimental-strip-types scripts/sync-katex-css.ts",
187
+ "codegen": "node --experimental-strip-types scripts/generate-host-protocol.ts",
188
+ "codegen:check": "node --experimental-strip-types scripts/generate-host-protocol.ts --check"
187
189
  },
188
190
  "peerDependencies": {
189
191
  "react": "^17 || ^18 || ^19",
@@ -212,6 +214,7 @@
212
214
  "jsdom": "^24.1.3",
213
215
  "msw": "^2.15.0",
214
216
  "npm-run-all2": "^6.2.6",
217
+ "orval": "8.40.0",
215
218
  "oxc-transform-react": "0.145.0",
216
219
  "oxfmt": "^0.68.0",
217
220
  "oxlint": "^1.83.0",
@@ -0,0 +1,100 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import NodeChildProcess from "node:child_process";
4
+ import NodeFs from "node:fs";
5
+ import NodeOs from "node:os";
6
+ import NodePath from "node:path";
7
+ import NodeUrl from "node:url";
8
+ import { expect, it } from "vitest";
9
+ import { z } from "zod";
10
+
11
+ it("enforces host dependencies for runtime and type imports", () => {
12
+ const frontend = NodeUrl.fileURLToPath(
13
+ new NodeUrl.URL("../../", import.meta.url),
14
+ );
15
+ const directory = NodeFs.mkdtempSync(
16
+ NodePath.join(NodeOs.tmpdir(), "host-imports-"),
17
+ );
18
+ const files = {
19
+ "src/core/host/allowed.ts": `
20
+ import { atom } from "jotai/vanilla";
21
+ import { z } from "zod";
22
+ import { Logger } from "@/utils/Logger";
23
+ import type { Document } from "./document";
24
+ export * from "@/core/host/events";
25
+ type Event = import("./events").NotebookEvent;
26
+ void import("./protocol");
27
+ `,
28
+ "src/core/host/protocol.ts": `
29
+ import type { NotificationMessage as A } from "../kernel/messages";
30
+ import { type NotificationMessage as B } from "@/core/kernel/messages";
31
+ import { NotificationMessage as C } from "../kernel/messages";
32
+ import type { NotificationPayload } from "../kernel/messages";
33
+ `,
34
+ "src/core/host/forbidden.ts": `
35
+ import { useEffect } from "react";
36
+ import type { NotificationMessage } from "../kernel/messages";
37
+ export * from "../kernel/messages";
38
+ export { Logger } from "@/utils/Logger/../other";
39
+ void import("../kernel/messages");
40
+ type Message = import("../kernel/messages").NotificationMessage;
41
+ const module = require("../kernel/messages");
42
+ void import(module);
43
+ import "./__tests__/allowed";
44
+ import "./allowed.test";
45
+ `,
46
+ "src/core/host/__tests__/allowed.ts": `import { useEffect } from "react";`,
47
+ "src/core/host/allowed.test.ts": `import { useEffect } from "react";`,
48
+ "src/core/host/allowed.spec.ts": `import { useEffect } from "react";`,
49
+ "src/core/websocket/allowed.ts": `import { useEffect } from "react";`,
50
+ };
51
+ try {
52
+ for (const [path, source] of Object.entries(files)) {
53
+ const destination = NodePath.join(directory, path);
54
+ NodeFs.mkdirSync(NodePath.dirname(destination), { recursive: true });
55
+ NodeFs.writeFileSync(destination, source);
56
+ }
57
+ const result = NodeChildProcess.spawnSync(
58
+ NodePath.join(frontend, "node_modules/.bin/oxlint"),
59
+ [
60
+ "--config",
61
+ NodePath.join(frontend, ".oxlintrc.json"),
62
+ "--format",
63
+ "json",
64
+ directory,
65
+ ],
66
+ { cwd: frontend, encoding: "utf8" },
67
+ );
68
+ const report = z
69
+ .object({
70
+ diagnostics: z.array(
71
+ z.object({
72
+ severity: z.string(),
73
+ filename: z.string(),
74
+ labels: z.array(z.object({ span: z.object({ line: z.number() }) })),
75
+ }),
76
+ ),
77
+ })
78
+ .parse(JSON.parse(result.stdout));
79
+ const errors = report.diagnostics.filter(
80
+ (diagnostic) => diagnostic.severity === "error",
81
+ );
82
+ expect(
83
+ errors
84
+ .map((error) => ({
85
+ file: NodePath.basename(error.filename),
86
+ line: error.labels[0].span.line,
87
+ }))
88
+ .toSorted((a, b) => a.file.localeCompare(b.file) || a.line - b.line),
89
+ ).toEqual([
90
+ ...[2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((line) => ({
91
+ file: "forbidden.ts",
92
+ line,
93
+ })),
94
+ ...[2, 3, 4, 5].map((line) => ({ file: "protocol.ts", line })),
95
+ ]);
96
+ expect(result.status).toBe(1);
97
+ } finally {
98
+ NodeFs.rmSync(directory, { recursive: true, force: true });
99
+ }
100
+ });
@@ -0,0 +1,6 @@
1
+ # Host core
2
+
3
+ Production code may import host modules, `jotai/vanilla`, `zod`, and
4
+ `@/utils/Logger`. Enforced by `marimo/host-imports`. Tests are exempt.
5
+
6
+ Define interfaces here and inject application behavior through adapters.
@@ -0,0 +1,214 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import NodeFs from "node:fs";
4
+ import NodeUrl from "node:url";
5
+ import { describe, expect, expectTypeOf, it } from "vitest";
6
+ import * as Protocol from "../protocol";
7
+
8
+ const fixtures = new NodeUrl.URL(
9
+ "../../../../../protocols/host/fixtures/",
10
+ import.meta.url,
11
+ );
12
+
13
+ function readFixture(name: string): unknown {
14
+ return JSON.parse(
15
+ NodeFs.readFileSync(new NodeUrl.URL(name, fixtures), "utf8"),
16
+ );
17
+ }
18
+
19
+ const records = {
20
+ "record.json": Protocol.HostRecord,
21
+ "cell.json": Protocol.Cell,
22
+ "analysis.json": Protocol.Analysis,
23
+ "diagnostic.json": Protocol.Error,
24
+ "edit.json": Protocol.EditRequest,
25
+ "edit-conflict-request.json": Protocol.EditRequest,
26
+ "edit-response.json": Protocol.EditResponse,
27
+ "execution-restored.json": Protocol.Execution,
28
+ "run-cells-request.json": Protocol.RunRequest,
29
+ };
30
+
31
+ describe("host protocol fixtures", () => {
32
+ it.each(Object.entries(records))("parses %s unchanged", (name, schema) => {
33
+ const input = readFixture(name);
34
+ const original = structuredClone(input);
35
+ expect(schema.parse(input)).toEqual(original);
36
+ expect(input).toEqual(original);
37
+ });
38
+
39
+ it.each(NodeFs.readdirSync(new NodeUrl.URL("problems/", fixtures)))(
40
+ "parses problem %s",
41
+ (name) => {
42
+ const input = readFixture(`problems/${name}`);
43
+ expect(Protocol.Problem.parse(input)).toEqual(input);
44
+ },
45
+ );
46
+
47
+ it.each(NodeFs.readdirSync(fixtures).filter((name) => name.endsWith(".sse")))(
48
+ "parses events in %s unchanged",
49
+ (name) => {
50
+ const stream = NodeFs.readFileSync(
51
+ new NodeUrl.URL(name, fixtures),
52
+ "utf8",
53
+ );
54
+ let count = 0;
55
+ for (const frame of stream.split(/\r?\n\r?\n/)) {
56
+ const event = /^event: (.+)$/m.exec(frame)?.[1];
57
+ if (!event && !/^data:/m.test(frame)) {
58
+ continue;
59
+ }
60
+ const data = frame
61
+ .split(/\r?\n/)
62
+ .filter((line) => line.startsWith("data:"))
63
+ .map((line) => line.slice(5).trimStart())
64
+ .join("\n");
65
+ const id = /^id: (.+)$/m.exec(frame)?.[1];
66
+ const payload: unknown = JSON.parse(data);
67
+ const input = { event, data: payload, ...(id ? { id } : {}) };
68
+ const original = structuredClone(input);
69
+ expect(Protocol.Event.parse(input)).toEqual(original);
70
+ expect(input).toEqual(original);
71
+ count += 1;
72
+ }
73
+ expect(count).toBeGreaterThan(0);
74
+ },
75
+ );
76
+ });
77
+
78
+ describe("host protocol bindings", () => {
79
+ it("preserves native marimo payloads without interpreting them", () => {
80
+ expectTypeOf<Protocol.MarimoEvent["data"]["marimo"]>().toBeUnknown();
81
+ const input = {
82
+ event: "marimo",
83
+ id: "42",
84
+ data: {
85
+ marimo: {
86
+ future_payload: { value: Number.NaN },
87
+ },
88
+ },
89
+ };
90
+ expect(Protocol.Event.parse(input)).toEqual(input);
91
+ });
92
+
93
+ it("accepts additive fields and preserves arbitrary notebook settings", () => {
94
+ const cell = Protocol.Cell.parse(readFixture("cell.json"));
95
+ const input = {
96
+ ...cell,
97
+ future: { enabled: true },
98
+ config: { ...cell.config, future: 42 },
99
+ };
100
+ const original = structuredClone(input);
101
+ expect(Protocol.Cell.parse(input)).toEqual(cell);
102
+ expect(input).toEqual(original);
103
+
104
+ const { document } = Protocol.EditResponse.parse(
105
+ readFixture("edit-response.json"),
106
+ );
107
+ const configured = {
108
+ ...document,
109
+ app_config: { extension: { values: [1, null, false] } },
110
+ };
111
+ expect(Protocol.Document.parse(configured)).toEqual(configured);
112
+ });
113
+
114
+ it("applies the defaults declared for cell inputs", () => {
115
+ expect(
116
+ Protocol.CellInput.parse({ id: "c3", code: "x = 1", config: {} }),
117
+ ).toEqual({
118
+ id: "c3",
119
+ code: "x = 1",
120
+ name: "_",
121
+ config: {
122
+ column: null,
123
+ disabled: false,
124
+ hide_code: false,
125
+ expand_output: false,
126
+ },
127
+ });
128
+ });
129
+
130
+ it.each(["run_id", "runtime_id", "caused_by"] as const)(
131
+ "requires the nullable execution field %s",
132
+ (field) => {
133
+ const execution = Protocol.Execution.parse(
134
+ readFixture("execution-restored.json"),
135
+ );
136
+ const missing = Object.fromEntries(
137
+ Object.entries(execution).filter(([key]) => key !== field),
138
+ );
139
+ expect(Protocol.Execution.safeParse(missing).success).toBe(false);
140
+ expect(
141
+ Protocol.Execution.safeParse({ ...execution, [field]: null }).success,
142
+ ).toBe(true);
143
+ },
144
+ );
145
+
146
+ it("preserves snapshot metadata omissions and validates live timestamps", () => {
147
+ const cell = Protocol.Cell.parse(readFixture("cell.json"));
148
+ expect(Protocol.CellMessage.parse({ cell })).toEqual({ cell });
149
+ const message = { cell, time: "2026-01-01T12:00:00+05:30" };
150
+ expect(Protocol.CellMessage.parse(message)).toEqual(message);
151
+ for (const time of [
152
+ null,
153
+ "yesterday",
154
+ "2026-02-30T12:00:00Z",
155
+ "2026-01-01T12:00:00",
156
+ ]) {
157
+ expect(Protocol.CellMessage.safeParse({ cell, time }).success).toBe(
158
+ false,
159
+ );
160
+ }
161
+ });
162
+
163
+ it("rejects invalid cell fields without coercing their values", () => {
164
+ const cell = Protocol.Cell.parse(readFixture("cell.json"));
165
+ for (const patch of [
166
+ { id: "" },
167
+ { code: 42 },
168
+ { etag: 42 },
169
+ { version: "2" },
170
+ { version: 0 },
171
+ { version: 1.5 },
172
+ { config: { ...cell.config, disabled: "false" } },
173
+ ]) {
174
+ expect(Protocol.Cell.safeParse({ ...cell, ...patch }).success).toBe(
175
+ false,
176
+ );
177
+ }
178
+ const result = Protocol.Cell.safeParse({ ...cell, code: 42 });
179
+ expect(result.success).toBe(false);
180
+ if (result.success) {
181
+ throw new Error("Expected an invalid cell");
182
+ }
183
+ expect(result.error.issues).toEqual([
184
+ expect.objectContaining({ path: ["code"], code: "invalid_type" }),
185
+ ]);
186
+ });
187
+
188
+ it("requires the fields of the selected change kind", () => {
189
+ const change = { kind: "delete_cell", id: "c3", base_etag: "*" };
190
+ expect(Protocol.Change.parse(change)).toEqual(change);
191
+ expect(
192
+ Protocol.Change.safeParse({ kind: "delete_cell", id: "c3" }).success,
193
+ ).toBe(false);
194
+ expect(
195
+ Protocol.Change.safeParse({ ...change, kind: "unknown" }).success,
196
+ ).toBe(false);
197
+ });
198
+
199
+ it("requires custom payloads while allowing any JSON value", () => {
200
+ for (const data of [
201
+ null,
202
+ false,
203
+ 42,
204
+ "text",
205
+ { nested: [1, null, false] },
206
+ ]) {
207
+ const custom = { type: "example.event", data };
208
+ expect(Protocol.Custom.parse(custom)).toEqual(custom);
209
+ }
210
+ expect(Protocol.Custom.safeParse({ type: "example.event" }).success).toBe(
211
+ false,
212
+ );
213
+ });
214
+ });