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(server): respect per-notebook inline theme when serving a directory (#10101)
Myles Scolnickd90350f38516
diff --git a/marimo/_server/api/deps.py b/marimo/_server/api/deps.pyindex 4a2df75c67..0abd4d3db9 100644--- a/marimo/_server/api/deps.py+++ b/marimo/_server/api/deps.py@@ -11,6 +11,7 @@ from marimo._server.session_manager import SessionManagerfrom marimo._server.tokens import SkewProtectionTokenfrom marimo._session.model import SessionModefrom marimo._types.ids import SessionId+from marimo._utils.http import HTTPException, HTTPStatusif TYPE_CHECKING:from starlette.applications import Starlette@@ -194,6 +195,20 @@ class AppState(AppStateBase):# create one.# Use this file to override the config manager.def config_manager_at_file(self, path: str) -> MarimoConfigManager:- return super().config_manager.with_overrides(- ScriptConfigManager(path).get_config()+ config_manager = super().config_manager+ # The file key can be relative to the workspace directory, so resolve+ # it to a validated absolute path before reading inline script+ # metadata — otherwise ScriptConfigManager would read relative to the+ # server's cwd. New/unsaved or missing files have no inline config to+ # apply; let other rejections (e.g. path traversal) propagate.+ try:+ resolved = self.session_manager.workspace.resolve(path)+ except HTTPException as e:+ if e.status_code == HTTPStatus.NOT_FOUND:+ return config_manager+ raise+ if resolved is None:+ return config_manager+ return config_manager.with_overrides(+ ScriptConfigManager(resolved).get_config())diff --git a/marimo/_smoke_tests/inline_theme_dark.py b/marimo/_smoke_tests/inline_theme_dark.pynew file mode 100644index 0000000000..3c86e5bd4c--- /dev/null+++ b/marimo/_smoke_tests/inline_theme_dark.py@@ -0,0 +1,38 @@+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "marimo",+# ]+#+# [tool.marimo.display]+# theme = "dark"+# ///+# Copyright 2026 Marimo. All rights reserved.++import marimo++__generated_with = "0.15.5"+app = marimo.App()+++def _():+ import marimo as mo++ return (mo,)+++def _(mo):+ mo.md(+ """+ This notebook sets `theme = "dark"` via inline `[tool.marimo.display]`+ metadata. It should render in dark mode even when opened from a+ directory listing (`marimo run marimo/_smoke_tests`). See #10056.+ """+ )+ return+++if __name__ == "__main__":+ app.run()diff --git a/tests/_server/api/endpoints/test_assets.py b/tests/_server/api/endpoints/test_assets.pyindex 25ce538dc3..f5019f20f5 100644--- a/tests/_server/api/endpoints/test_assets.py+++ b/tests/_server/api/endpoints/test_assets.py@@ -4,10 +4,13 @@ from __future__ import annotationsimport jsonimport osimport shutil+import textwrapfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, castfrom unittest.mock import Mock, patch+import pytest+from marimo._server.api.deps import AppStatefrom marimo._server.api.endpoints.assets import (DEFAULT_NOTEBOOK_NAME,@@ -21,6 +24,7 @@ from marimo._server.workspace import (SingleFileWorkspace,)from marimo._session.model import SessionMode+from marimo._utils.http import HTTPExceptionfrom marimo._utils.marimo_path import MarimoPathfrom tests._server.mocks import (token_header,@@ -239,6 +243,91 @@ def test_index_with_directory_run_mode(assert "<title>marimo</title>" in content+def test_index_with_directory_respects_inline_theme(+ client: TestClient, tmp_path: Path+) -> None:+ # Regression test for #10056: a directory workspace sends a relative file+ # key, and its inline theme must still be applied.+ notebook = tmp_path / "notebook.py"+ notebook.write_text(+ textwrap.dedent(+ """+ # /// script+ # [tool.marimo.display]+ # theme = "dark"+ # ///++ import marimo++ app = marimo.App()+++ @app.cell+ def _():+ import marimo as mo+ return+++ if __name__ == "__main__":+ app.run()+ """+ ).lstrip()+ )++ app_state = AppState.from_app(cast(Any, client.app))+ app_state.session_manager.mode = SessionMode.RUN++ with workspace_scope(+ client, DirectoryWorkspace(str(tmp_path), include_markdown=False)+ ):+ response = client.get("/?file=notebook.py", headers=token_header())+ assert response.status_code == 200, response.text+ assert '"theme": "dark"' in response.text+++def test_config_manager_at_file_directory_keys(+ client: TestClient, tmp_path: Path+) -> None:+ # `config_manager_at_file` resolves relative directory-workspace keys+ # before reading inline metadata, and must not swallow the workspace's+ # path validation.+ notebook = tmp_path / "notebook.py"+ notebook.write_text(+ textwrap.dedent(+ """+ # /// script+ # [tool.marimo.display]+ # theme = "dark"+ # ///++ import marimo++ app = marimo.App()+ """+ ).lstrip()+ )++ app_state = AppState(cast(Any, Mock(app=client.app)))++ with workspace_scope(+ client, DirectoryWorkspace(str(tmp_path), include_markdown=False)+ ):+ # Relative key resolves against the workspace and applies inline config.+ resolved = app_state.config_manager_at_file("notebook.py").get_config()+ assert resolved["display"]["theme"] == "dark"++ # A missing/unsaved file (404) yields base config, no inline overrides.+ missing = app_state.config_manager_at_file(+ "does_not_exist.py"+ ).get_config()+ assert missing["display"]["theme"] != "dark"++ # A rejected path (non-404, e.g. traversal) propagates rather than+ # falling back to reading an unvalidated path.+ with pytest.raises(HTTPException):+ app_state.config_manager_at_file("../../../../etc/passwd")++def test_favicon(client: TestClient) -> None:response = client.get("/favicon.ico")assert response.status_code == 200, response.text