0baa9ab2ed
spec 2026-10-19 §4: 路径模式(/t/<slug>/static/widget.js)下从 script.src 剥尾推导 basePath,brand/avatar 三分支/WS 四处端点构造统一加前缀; Host 模式 indexOf 命中在 0 → basePath="" 端点零变化。 test_theme_static.py 头像锚定守卫随构造更新(wsBase + basePath + …, 语义不变:绝对锚定 + 禁相对路径)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
"""widget.js 静态守卫(spec 2026-10-19 §4):脚本地址自推导 basePath,
|
|
三类端点构造(brand/avatar/WS)统一带前缀;Host 模式前缀为空串零变化。
|
|
|
|
路径模式(/t/<slug>/static/widget.js)下脚本地址自携带租户路径,剥掉
|
|
/static/widget.js 尾部即得 basePath;Host 模式 pathname 以 /static/
|
|
开头(indexOf 命中在 0)→ basePath="" 所有端点与现状零差异。守卫三点:
|
|
推导逻辑在场、四处端点构造不再出现裸拼接、默认头像路径同走前缀。
|
|
"""
|
|
from pathlib import Path
|
|
|
|
STATIC = Path(__file__).resolve().parent.parent / "static"
|
|
|
|
|
|
def read(rel):
|
|
return (STATIC / rel).read_text(encoding="utf-8")
|
|
|
|
|
|
def test_有_basepath_推导():
|
|
src = read("widget.js")
|
|
assert 'indexOf("/static/widget.js")' in src # 从 script.src 剥尾推导
|
|
|
|
|
|
def test_端点构造全部走_basePath():
|
|
src = read("widget.js")
|
|
# 不允许再出现裸 wsBase + "/api/ 或 wsHost + "/ws/(必须经 basePath)
|
|
assert 'wsBase + "/api/' not in src
|
|
assert 'wsHost + "/ws/' not in src
|
|
assert "wsBase + basePath" in src
|
|
|
|
|
|
def test_默认头像路径带前缀():
|
|
src = read("widget.js")
|
|
assert "wsBase + basePath + DEFAULT_AVATAR_PATH" in src
|