|
6 | 6 | import unittest |
7 | 7 | from pathlib import Path |
8 | 8 | from typing import Literal |
| 9 | +from unittest.mock import patch |
9 | 10 |
|
10 | 11 | from marimo._ast.app_config import _AppConfig |
11 | 12 | from marimo._config.config import ( |
@@ -1115,6 +1116,56 @@ def test_static_malicious_code_content(self) -> None: |
1115 | 1116 |
|
1116 | 1117 | _assert_no_leftover_replacements(result) |
1117 | 1118 |
|
| 1119 | + def test_static_notebook_template_dev_version_in_asset_url(self) -> None: |
| 1120 | + # jsdelivr treats `.dev` as a separate path segment, so dev versions |
| 1121 | + # like "0.16.5.dev6+gabc" must be normalized to "0.16.5-dev6+gabc" |
| 1122 | + # for the CDN URL to resolve. |
| 1123 | + with patch.object(templates, "__version__", "0.16.5.dev6+gabc"): |
| 1124 | + result = templates.static_notebook_template( |
| 1125 | + self.html, |
| 1126 | + self.user_config, |
| 1127 | + self.config_overrides, |
| 1128 | + self.server_token, |
| 1129 | + self.app_config, |
| 1130 | + self.filepath, |
| 1131 | + self.code, |
| 1132 | + hash_code(self.code), |
| 1133 | + self.session_snapshot, |
| 1134 | + self.notebook_snapshot, |
| 1135 | + self.files, |
| 1136 | + ) |
| 1137 | + |
| 1138 | + assert ( |
| 1139 | + "https://cdn.jsdelivr.net/npm/@marimo-team/frontend@0.16.5-dev6+gabc/dist" |
| 1140 | + in result |
| 1141 | + ) |
| 1142 | + assert "@0.16.5.dev6" not in result |
| 1143 | + _assert_no_leftover_replacements(result) |
| 1144 | + |
| 1145 | + def test_static_notebook_template_release_version_in_asset_url( |
| 1146 | + self, |
| 1147 | + ) -> None: |
| 1148 | + with patch.object(templates, "__version__", "0.16.5"): |
| 1149 | + result = templates.static_notebook_template( |
| 1150 | + self.html, |
| 1151 | + self.user_config, |
| 1152 | + self.config_overrides, |
| 1153 | + self.server_token, |
| 1154 | + self.app_config, |
| 1155 | + self.filepath, |
| 1156 | + self.code, |
| 1157 | + hash_code(self.code), |
| 1158 | + self.session_snapshot, |
| 1159 | + self.notebook_snapshot, |
| 1160 | + self.files, |
| 1161 | + ) |
| 1162 | + |
| 1163 | + assert ( |
| 1164 | + "https://cdn.jsdelivr.net/npm/@marimo-team/frontend@0.16.5/dist" |
| 1165 | + in result |
| 1166 | + ) |
| 1167 | + _assert_no_leftover_replacements(result) |
| 1168 | + |
1118 | 1169 |
|
1119 | 1170 | class TestWasmNotebookTemplate(unittest.TestCase): |
1120 | 1171 | def setUp(self) -> None: |
|
0 commit comments