A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: prevent console crashes when input prompts are interrupted (#10854)
Shahmir Varqhaca1ff1cdcbe3
diff --git a/frontend/src/core/cells/__tests__/cell.test.ts b/frontend/src/core/cells/__tests__/cell.test.tsindex cac5a868ed..a0a7c2ea54 100644--- a/frontend/src/core/cells/__tests__/cell.test.ts+++ b/frontend/src/core/cells/__tests__/cell.test.ts@@ -220,6 +220,67 @@ describe("transitionCell serialization", () => {});describe("transitionCell stdin resolution", () => {+ describe.each([+ {+ name: "interrupted",+ message: {+ output: {+ channel: "marimo-error",+ mimetype: "application/vnd.marimo+error",+ data: [{ type: "interruption" }],+ timestamp: 1,+ },+ } as CellMessage,+ },+ {+ name: "idle",+ message: { status: "idle" } as CellMessage,+ },+ ])("when $name", ({ name, message }) => {+ it.each(["text/plain", "text/password"] as const)(+ "preserves a processed %s prompt",+ (mimetype) => {+ const prompt: OutputMessage = {+ channel: "stdin",+ mimetype,+ data: "Enter a value: ",+ timestamp: 0,+ };+ const waiting = transitionCell(+ createCellRuntimeState({ status: "running" }),+ { console: prompt } as CellMessage,+ );+ const resolved = transitionCell(waiting, message);++ expect(resolved.interrupted).toBe(name === "interrupted");+ expect(resolved.consoleOutputs[0]).toMatchObject({+ ...prompt,+ response: "",+ });+ },+ );++ it.each(["text/plain", "text/password"] as const)(+ "preserves an existing %s response",+ (mimetype) => {+ const prompt = {+ channel: "stdin" as const,+ mimetype,+ data: "Enter a value: ",+ timestamp: 0,+ response: "submitted value",+ };+ const answered = createCellRuntimeState({+ status: "running",+ consoleOutputs: [prompt],+ });+ const resolved = transitionCell(answered, message);++ expect(resolved.consoleOutputs).toEqual([prompt]);+ },+ );+ });+function stdinOutput(): OutputMessage {return {channel: "stdin",diff --git a/frontend/src/core/cells/cell.ts b/frontend/src/core/cells/cell.tsindex 209f0305f8..cf980c29f5 100644--- a/frontend/src/core/cells/cell.ts+++ b/frontend/src/core/cells/cell.ts@@ -126,7 +126,15 @@ export function transitionCell(nextCell.debuggerActive = false;consoleOutputs = consoleOutputs.map((output) => {if (output.channel === "stdin") {- return { ...output, response: output.response ?? "" };+ // StatefulOutputMessage exposes data through a getter, which object+ // spread would omit.+ return {+ channel: output.channel,+ mimetype: output.mimetype,+ data: output.data,+ timestamp: output.timestamp,+ response: output.response ?? "",+ };}return output;});