Skip to content

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.

ci: fix typecheck (#6841)

Myles Scolnick4a27dec97030
diff --git a/frontend/src/components/editor/cell/useRunCells.ts b/frontend/src/components/editor/cell/useRunCells.ts
index 3b635702a3..13599f3bc1 100644
--- a/frontend/src/components/editor/cell/useRunCells.ts
+++ b/frontend/src/components/editor/cell/useRunCells.ts
@@ -61,6 +61,10 @@ export function useRunCells() {
}
const notebook = getNotebook();
+
+ // Set a flag that a user has manually run at least one cell.
+ setHasRunAnyCell(true);
+
return runCells({ cellIds, sendRun, prepareForRun, notebook });
});
@@ -107,9 +111,6 @@ export async function runCells({
prepareForRun({ cellId });
}
- // Set a flag that a user has manually run at least one cell.
- setHasRunAnyCell(true);
-
// Send the run request to the Kernel
await sendRun({ cellIds: cellIds, codes: codes }).catch((error) => {
Logger.error(error);
diff --git a/frontend/src/components/editor/output/__tests__/traceback.test.tsx b/frontend/src/components/editor/output/__tests__/traceback.test.tsx
index 559b563e48..8bada803bf 100644
--- a/frontend/src/components/editor/output/__tests__/traceback.test.tsx
+++ b/frontend/src/components/editor/output/__tests__/traceback.test.tsx
@@ -1,10 +1,12 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { render } from "@testing-library/react";
-import { beforeEach, describe, expect, test, vi } from "vitest";
+import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import { Tracebacks } from "@/__mocks__/tracebacks";
import { TooltipProvider } from "@/components/ui/tooltip";
import type { CellId } from "@/core/cells/ids";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
import { renderHTML } from "@/plugins/core/RenderHTML";
import {
MarimoTracebackOutput,
@@ -17,6 +19,7 @@ const cellId = "1" as CellId;
describe("traceback component", () => {
beforeEach(() => {
vi.resetAllMocks();
+ store.set(initialModeAtom, "edit");
});
test("extracts cell-link", () => {
@@ -58,6 +61,10 @@ describe("traceback component", () => {
});
describe("traceback replacement", () => {
+ beforeAll(() => {
+ store.set(initialModeAtom, "edit");
+ });
+
test("replaces File with Cell", () => {
const traceback = renderHTML({
html: Tracebacks.assertion,
diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsx
index e13c4c33f4..144c9a2d52 100644
--- a/frontend/src/plugins/core/RenderHTML.tsx
+++ b/frontend/src/plugins/core/RenderHTML.tsx
@@ -141,11 +141,17 @@ const CopyableCode = ({ children }: { children: ReactNode }) => {
export const renderHTML = ({ html, additionalReplacements = [] }: Options) => {
return (
- <RenderHTML html={html} additionalReplacements={additionalReplacements} />
+ <RenderHTMLComponent
+ html={html}
+ additionalReplacements={additionalReplacements}
+ />
);
};
-const RenderHTML = ({ html, additionalReplacements = [] }: Options) => {
+const RenderHTMLComponent = ({
+ html,
+ additionalReplacements = [],
+}: Options) => {
const shouldSanitizeHtml = useSanitizeHtml();
const sanitizedHtml = useMemo(() => {
if (shouldSanitizeHtml) {
@@ -154,6 +160,10 @@ const RenderHTML = ({ html, additionalReplacements = [] }: Options) => {
return html;
}, [html, shouldSanitizeHtml]);
+ return parseHtml({ html: sanitizedHtml, additionalReplacements });
+};
+
+function parseHtml({ html, additionalReplacements = [] }: Options) {
const renderFunctions: ReplacementFn[] = [
replaceValidTags,
replaceValidIframes,
@@ -167,7 +177,7 @@ const RenderHTML = ({ html, additionalReplacements = [] }: Options) => {
removeWrappingHtmlTags,
];
- return parse(sanitizedHtml, {
+ return parse(html, {
replace: (domNode: DOMNode, index: number) => {
for (const renderFunction of renderFunctions) {
const replacement = renderFunction(domNode, index);
@@ -187,4 +197,8 @@ const RenderHTML = ({ html, additionalReplacements = [] }: Options) => {
return reactNode as JSX.Element;
},
});
+}
+
+export const visibleForTesting = {
+ parseHtml,
};
diff --git a/frontend/src/plugins/core/__test__/RenderHTML.test.ts b/frontend/src/plugins/core/__test__/RenderHTML.test.ts
index abd2a23957..e016996172 100644
--- a/frontend/src/plugins/core/__test__/RenderHTML.test.ts
+++ b/frontend/src/plugins/core/__test__/RenderHTML.test.ts
@@ -1,11 +1,13 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { describe, expect, test } from "vitest";
-import { renderHTML } from "../RenderHTML";
+import { visibleForTesting } from "../RenderHTML";
-describe("RenderHTML", () => {
+const { parseHtml } = visibleForTesting;
+
+describe("parseHtml", () => {
test("renders HTML", () => {
const html = "<h1>Hello</h1>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<h1>
Hello
</h1>
@@ -14,7 +16,7 @@ describe("RenderHTML", () => {
test("no closing HTML", () => {
const html = "<h1>Hello";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<h1>
Hello
</h1>
@@ -23,7 +25,7 @@ describe("RenderHTML", () => {
test("script", () => {
const html = "<h1>Hello</h1><script>alert('hi')</script>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
[
<h1>
Hello
@@ -41,7 +43,7 @@ describe("RenderHTML", () => {
test("iframe", () => {
const html = '<iframe src="https://example.com" "crossorigin"></iframe>';
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<div
dangerouslySetInnerHTML={
{
@@ -55,7 +57,7 @@ describe("RenderHTML", () => {
test("codehilite with copy button", () => {
const html =
'<div class="codehilite"><pre><code>console.log("Hello");</code></pre></div>';
- const result = renderHTML({ html });
+ const result = parseHtml({ html });
// Check that the result is wrapped in a CopyableCode component
expect(result).toMatchInlineSnapshot(`
@@ -75,18 +77,18 @@ describe("RenderHTML", () => {
test("custom tags - valid", () => {
let html = "<foobar></foobar>";
- expect(renderHTML({ html })).toMatchInlineSnapshot("<foobar />");
+ expect(parseHtml({ html })).toMatchInlineSnapshot("<foobar />");
html = "<foobar2></foobar2>";
- expect(renderHTML({ html })).toMatchInlineSnapshot("<foobar2 />");
+ expect(parseHtml({ html })).toMatchInlineSnapshot("<foobar2 />");
html = "<marimo-slider></marimo-slider>";
- expect(renderHTML({ html })).toMatchInlineSnapshot("<marimo-slider />");
+ expect(parseHtml({ html })).toMatchInlineSnapshot("<marimo-slider />");
});
test("custom tags - invalid", () => {
let html = "<c&></c&> lorem";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
[
<React.Fragment />,
" lorem",
@@ -94,28 +96,28 @@ describe("RenderHTML", () => {
`);
html = "<p><[email protected]></p>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<p>
<React.Fragment />
</p>
`);
html = "<p><1></p>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<p>
&lt;1&gt;
</p>
`);
html = "<p><1/></p>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<p>
&lt;1/&gt;
</p>
`);
html = "<p><a:b></a:b></p>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<p>
<React.Fragment />
</p>
@@ -124,7 +126,7 @@ describe("RenderHTML", () => {
test("removes body tags but preserves children", () => {
const html = "<body><h1>Hello</h1><p>World</p></body>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<React.Fragment>
<h1>
Hello
@@ -138,7 +140,7 @@ describe("RenderHTML", () => {
test("removes nested body tags", () => {
const html = "<div><body><span>Content</span></body></div>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<div>
<React.Fragment>
<span>
@@ -152,7 +154,7 @@ describe("RenderHTML", () => {
test("removes html tags but preserves children", () => {
const html =
"<html><head><title>Test</title></head><body><p>Content</p></body></html>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<React.Fragment>
<head>
<title>
@@ -170,7 +172,7 @@ describe("RenderHTML", () => {
test("removes nested html tags", () => {
const html = "<div><html><span>Content</span></html></div>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<div>
<React.Fragment>
<span>
@@ -183,7 +185,7 @@ describe("RenderHTML", () => {
test("remove nested body in html", () => {
const html = "<html><body><span>Content</span></body></html>";
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
<React.Fragment>
<React.Fragment>
<span>
@@ -195,11 +197,11 @@ describe("RenderHTML", () => {
});
});
-describe("RenderHTML with < nad >", () => {
+describe("parseHtml with < nad >", () => {
const html =
'thread <unnamed> panicked at "assertion failed: `(left == right)`"';
test("<unnamed>", () => {
- expect(renderHTML({ html })).toMatchInlineSnapshot(`
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
[
"thread ",
<unnamed>
@@ -211,7 +213,7 @@ describe("RenderHTML with < nad >", () => {
test("<unnamed> sanitized", () => {
const sanitized = html.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
- expect(renderHTML({ html: sanitized })).toMatchInlineSnapshot(
+ expect(parseHtml({ html: sanitized })).toMatchInlineSnapshot(
`"thread <unnamed> panicked at "assertion failed: \`(left == right)\`""`,
);
});
diff --git a/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
index 31a1192fb5..1f951e3ee2 100644
--- a/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
+++ b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
@@ -1,7 +1,9 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { render } from "@testing-library/react";
-import { describe, expect, it } from "vitest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
import type { IPluginProps } from "../../types";
import { DateTimePickerPlugin } from "../DateTimePickerPlugin";
@@ -13,6 +15,11 @@ interface DateTimeData {
}
describe("DateTimePickerPlugin", () => {
+ beforeEach(() => {
+ vi.resetAllMocks();
+ store.set(initialModeAtom, "edit");
+ });
+
it("should render when initial value is not provided", () => {
const plugin = new DateTimePickerPlugin();
// Create a host element as required by IPluginProps
diff --git a/frontend/src/plugins/impl/__tests__/DropdownPlugin.test.tsx b/frontend/src/plugins/impl/__tests__/DropdownPlugin.test.tsx
index b3ec9a0402..39e7684d6c 100644
--- a/frontend/src/plugins/impl/__tests__/DropdownPlugin.test.tsx
+++ b/frontend/src/plugins/impl/__tests__/DropdownPlugin.test.tsx
@@ -3,6 +3,8 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { beforeAll, describe, expect, it, vi } from "vitest";
import type { z } from "zod";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
import type { IPluginProps } from "../../types";
import { DropdownPlugin } from "../DropdownPlugin";
@@ -24,6 +26,10 @@ beforeAll(() => {
});
describe("DropdownPlugin", () => {
+ beforeAll(() => {
+ store.set(initialModeAtom, "edit");
+ });
+
describe("searchable dropdown", () => {
it("renders SearchableSelect when searchable is true", () => {
const plugin = new DropdownPlugin();
diff --git a/frontend/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts b/frontend/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts
index da34742231..0d52be6773 100644
--- a/frontend/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts
+++ b/frontend/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts
@@ -1,11 +1,18 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import { expect, it } from "vitest";
+import { beforeEach, expect, it, vi } from "vitest";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
import { multiselectFilterFn } from "../multiselectFilterFn";
function filterOptions(filter: string, items: string[]) {
return items.filter((option) => multiselectFilterFn(option, filter));
}
+beforeEach(() => {
+ vi.resetAllMocks();
+ store.set(initialModeAtom, "edit");
+});
+
it("can filter to relevant words", () => {
const options = ["a", "b", "c", "foo", "bar", "foo bar", "foobar"];
diff --git a/frontend/src/plugins/impl/__tests__/NumberPlugin.test.tsx b/frontend/src/plugins/impl/__tests__/NumberPlugin.test.tsx
index 606375a64c..a9197b7cc4 100644
--- a/frontend/src/plugins/impl/__tests__/NumberPlugin.test.tsx
+++ b/frontend/src/plugins/impl/__tests__/NumberPlugin.test.tsx
@@ -3,12 +3,15 @@
import { act, render } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { z } from "zod";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
import type { IPluginProps } from "../../types";
import { NumberPlugin } from "../NumberPlugin";
describe("NumberPlugin", () => {
beforeEach(() => {
vi.useFakeTimers();
+ store.set(initialModeAtom, "edit");
});
afterEach(() => {