test: tighten smd import shape — forbid bare AND root-absolute, require './' relative

The two tests that pin streaming-markdown's import shape were updated
to require the './' relative form and forbid BOTH the bare specifier
(broken by ES spec, #1849) AND the root-absolute form (broken under
subpath deployments like /hermes/). The original tests only forbade
root-absolute, which let the bare-specifier regression land
unnoticed.
This commit is contained in:
nesquena-hermes
2026-05-07 20:42:55 +00:00
parent 94aeb538f2
commit 4ffa40282f
2 changed files with 24 additions and 3 deletions
+14 -2
View File
@@ -108,9 +108,21 @@ class TestIndexHtmlSmdScript:
)
def test_smd_vendor_import_is_mount_agnostic(self):
assert "static/vendor/smd.min.js" in INDEX_HTML, (
"index.html must load the vendored streaming-markdown module"
"""Import must resolve relative to current document, not a bare
specifier (rejected by ES module spec, #1849) and not root-absolute
(escapes /hermes/-style subpath mounts). The `./` form is the only
shape that satisfies both: ES-spec-valid AND mount-agnostic.
"""
assert "from './static/vendor/smd.min.js'" in INDEX_HTML, (
"index.html must use the './static/vendor/smd.min.js' form — "
"bare specifiers are rejected by the ES module spec (#1849) and "
"leading-/ paths break subpath deployments such as /hermes/"
)
# Forbid the bare form (#1849 broke streaming-markdown silently)
assert "import * as smd from 'static/vendor/smd.min.js'" not in INDEX_HTML, (
"bare specifier is rejected by the ES module spec — use './static/...'"
)
# Forbid the root-absolute form (subpath deployments escape the mount)
assert "from '/static/vendor/smd.min.js'" not in INDEX_HTML, (
"streaming-markdown import must not be root-absolute; root-absolute "
"static paths break subpath deployments such as /hermes/"
+10 -1
View File
@@ -56,6 +56,15 @@ def test_direct_frontend_event_sources_are_relative_to_current_mount():
def test_static_vendor_import_is_relative_to_current_mount():
"""Import must use `./static/vendor/smd.min.js` form so the URL resolves
relative to the document URL. Bare specifier (no leading `./` or `/`)
is invalid per ES module spec and breaks markdown streaming silently
(#1849). Root-absolute (`/static/...`) escapes subpath mounts like
`/hermes/`. The `./` form satisfies both constraints.
"""
src = read("static/index.html")
assert "import * as smd from 'static/vendor/smd.min.js'" in src
assert "import * as smd from './static/vendor/smd.min.js'" in src
# Bare specifier — broken per ES module spec (#1849)
assert "import * as smd from 'static/vendor/smd.min.js'" not in src
# Root-absolute — breaks /hermes/ subpath mounts
assert "import * as smd from '/static/vendor/smd.min.js'" not in src