* fix(#604): model picker shows all configured providers Two fixes to ensure the model picker surface every provider a user has configured: 1. Added env var detection for XAI_API_KEY (→ x-ai) and MISTRAL_API_KEY (→ mistralai). Previously these providers were only detectable via hermes auth or credential pool, not via environment variables. 2. Added config.yaml providers section scanning. Users who configure providers in config.yaml (e.g. providers.anthropic.api_key) without setting the corresponding env var will now see those providers in the model picker. Only providers with known model catalogs are added. - Added 12 regression tests * fix(#1112): allow Google Fonts in CSP style-src and font-src Mermaid themes inject @import for fonts.googleapis.com at render time. CSP style-src blocked these requests, causing console violations. - Add https://fonts.googleapis.com to style-src (CSS stylesheets) - Add https://fonts.gstatic.com to font-src (WOFF2/WOFF font files) - Add 3 regression tests + verify existing CSP tests still pass * fix(#1118): retry api() calls on network errors after long idle After a long idle period, the browser's TCP keep-alive connection to the server can become stale. The next fetch() throws a TypeError (network failure), causing 'Failed to load session' instead of transparently reconnecting. - Added retry loop in api() (workspace.js): up to 3 attempts - Only retries on TypeError (network failures), NOT on HTTP errors (4xx/5xx) - 401 redirects still fire immediately - Added 6 regression tests * feat(#1116): composer placeholder reflects active profile name When a named profile is active (not 'default'), the composer placeholder and title bar show the profile name (capitalised) instead of the global bot_name. Falls back to bot_name/'Hermes' for the default profile. - boot.js: applyBotName() checks S.activeProfile before _botName - panels.js: switchToProfile() calls applyBotName() after switch - Added 5 regression tests * feat(#1097): drag and drop workspace files into chat composer Files and folders in the workspace file tree are now draggable. Dropping them into the composer inserts @path reference at cursor position. OS file drag-and-drop (attach files) still works. - ui.js: _renderTreeItems sets draggable + dragstart with ws-path - panels.js: drop handler checks for application/ws-path first, inserts @path with smart spacing and cursor positioning - Added 9 regression tests * fix(#1096): copy buttons work — add clipboard-write Permissions-Policy Copy buttons on messages and code blocks were silently failing because the Permissions-Policy header did not include clipboard-write=(self). Firefox blocks navigator.clipboard.writeText() without explicit permission. - api/helpers.py: add clipboard-write=(self) to Permissions-Policy - ui.js: _copyText now catches clipboard API errors and falls back to execCommand('copy'). _fallbackCopy extracted as separate function with proper focus() call and visible-but-hidden positioning (not -9999px) - Added 8 regression tests * chore: CHANGELOG for v0.50.223 --------- Co-authored-by: bergeouss <bergeouss@users.noreply.github.com> Co-authored-by: nesquena-hermes <nesquena-hermes@users.noreply.github.com>
103 lines
No EOL
4.1 KiB
Python
103 lines
No EOL
4.1 KiB
Python
"""Tests for #1096 — copy buttons work via Permissions-Policy + fallback."""
|
|
import re
|
|
|
|
|
|
def _src(name: str) -> str:
|
|
with open(f"static/{name}") as f:
|
|
return f.read()
|
|
|
|
|
|
def _py_src() -> str:
|
|
with open("api/helpers.py") as f:
|
|
return f.read()
|
|
|
|
|
|
class TestClipboardPermissions:
|
|
"""Permissions-Policy must allow clipboard-write for the origin."""
|
|
|
|
def test_permissions_policy_includes_clipboard_write(self):
|
|
"""Permissions-Policy header must include clipboard-write=(self)."""
|
|
src = _py_src()
|
|
# Match the Permissions-Policy value string (may span lines)
|
|
m = re.search(r"Permissions-Policy',\s*'(.*?)'", src, re.DOTALL)
|
|
assert m, "Permissions-Policy header value must exist"
|
|
assert "clipboard-write=(self)" in m.group(1), \
|
|
"Permissions-Policy must include clipboard-write=(self)"
|
|
|
|
|
|
class TestCopyTextFunction:
|
|
"""_copyText must use clipboard API with fallback to execCommand."""
|
|
|
|
def test_copyText_uses_clipboard_api(self):
|
|
"""_copyText must call navigator.clipboard.writeText."""
|
|
src = _src("ui.js")
|
|
assert "navigator.clipboard.writeText(text)" in src, \
|
|
"_copyText must use Clipboard API"
|
|
|
|
def test_copyText_has_fallback(self):
|
|
"""_copyText must fall back to execCommand if clipboard API fails."""
|
|
src = _src("ui.js")
|
|
assert "function _fallbackCopy" in src, \
|
|
"Must have a separate _fallbackCopy function"
|
|
# Clipboard API call must .catch() to fallback
|
|
m = re.search(r"navigator\.clipboard\.writeText\(text\)", src)
|
|
assert m, "Must call clipboard API"
|
|
after = src[m.start():m.start() + 300]
|
|
assert "_fallbackCopy" in after, \
|
|
"clipboard.writeText must .catch() → _fallbackCopy"
|
|
|
|
def test_fallbackCopy_uses_execCommand(self):
|
|
"""_fallbackCopy must use document.execCommand('copy')."""
|
|
src = _src("ui.js")
|
|
assert "document.execCommand('copy')" in src, \
|
|
"_fallbackCopy must use execCommand('copy')"
|
|
|
|
def test_fallbackCopy_focuses_textarea(self):
|
|
"""_fallbackCopy must explicitly focus textarea before select()."""
|
|
src = _src("ui.js")
|
|
# Find _fallbackCopy function
|
|
m = re.search(r"function _fallbackCopy", src)
|
|
assert m, "_fallbackCopy function must exist"
|
|
fn = src[m.start():m.start() + 600]
|
|
assert "ta.focus()" in fn, \
|
|
"Must call .focus() on textarea before .select()"
|
|
|
|
def test_fallbackCopy_not_offscreen(self):
|
|
"""_fallbackCopy textarea must NOT be positioned at -9999px (fails in some browsers)."""
|
|
src = _src("ui.js")
|
|
m = re.search(r"function _fallbackCopy", src)
|
|
fn = src[m.start():m.start() + 600]
|
|
assert "-9999" not in fn, \
|
|
"Textarea must not be positioned at -9999px (offscreen select fails)"
|
|
|
|
def test_copyMsg_copies_raw_text(self):
|
|
"""copyMsg must extract text from data-raw-text attribute."""
|
|
src = _src("ui.js")
|
|
assert "closest('[data-raw-text]')" in src, \
|
|
"copyMsg must find nearest element with data-raw-text"
|
|
assert "dataset.rawText" in src, \
|
|
"copyMsg must read rawText from dataset"
|
|
|
|
|
|
class TestCodeCopyButton:
|
|
"""Code block copy button must also use _copyText."""
|
|
|
|
def test_code_copy_uses_copyText(self):
|
|
"""Code copy button onclick must call _copyText."""
|
|
src = _src("ui.js")
|
|
# Find addCopyButtons function
|
|
m = re.search(r"function addCopyButtons", src)
|
|
assert m, "addCopyButtons must exist"
|
|
fn = src[m.start():m.start() + 800]
|
|
assert "_copyText" in fn, \
|
|
"Code copy button must use _copyText function"
|
|
assert "codeEl.textContent" in fn, \
|
|
"Code copy must copy the code element's textContent"
|
|
|
|
class TestCopyFailedI18n:
|
|
|
|
def test_copy_failed_in_all_locales(self):
|
|
"""copy_failed key must exist in all locale blocks (currently 7 with Korean)."""
|
|
i18n = _src('i18n.js')
|
|
count = i18n.count('copy_failed')
|
|
assert count >= 6, f'Expected copy_failed in at least 6 locale blocks, found {count}' |