mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-27 04:00:37 +00:00
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:
@@ -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/"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user