Files
hermes-webui/tests/test_issue1116_composer_placeholder.py
T
nesquena-hermes fc0152b2fc v0.50.223: model picker, idle retry, drag-drop, CSP, clipboard copy (#1127)
* 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>
2026-04-26 15:29:02 -07:00

61 lines
2.8 KiB
Python

"""Tests for #1116 — composer placeholder reflects active profile name."""
import re
def _src(name: str) -> str:
with open(f"static/{name}") as f:
return f.read()
class TestComposerPlaceholderProfile:
"""applyBotName() should use the profile name when activeProfile is set."""
def test_applyBotName_uses_profile_name(self):
"""applyBotName must check S.activeProfile and prefer it over global bot_name."""
src = _src("boot.js")
assert "S.activeProfile" in src, \
"applyBotName must reference S.activeProfile"
# Should fall back to _botName when activeProfile is 'default'
assert "S.activeProfile!=='default'" in src, \
"applyBotName must skip 'default' profile (use bot_name instead)"
def test_applyBotName_capitalises_profile_name(self):
"""Profile name should be capitalised (first letter uppercase)."""
src = _src("boot.js")
m = re.search(r'function applyBotName\(\)\{.*?\n\}', src, re.DOTALL)
assert m, "applyBotName function must exist"
body = m.group(0)
assert "charAt(0).toUpperCase()" in body, \
"applyBotName must capitalise first letter of profile name"
def test_applyBotName_falls_back_to_bot_name(self):
"""When no active profile, must fall back to window._botName."""
src = _src("boot.js")
m = re.search(r'function applyBotName\(\)\{.*?\n\}', src, re.DOTALL)
assert m, "applyBotName function must exist"
body = m.group(0)
assert "window._botName||'Hermes'" in body, \
"applyBotName must fall back to window._botName or 'Hermes'"
def test_switchToProfile_calls_applyBotName(self):
"""switchToProfile() must call applyBotName() after switching."""
src = _src("panels.js")
assert "function switchToProfile" in src, \
"switchToProfile function must exist"
# Find the function block (starts with 'async function switchToProfile')
m = re.search(r'async function switchToProfile\s*\(', src)
assert m, "switchToProfile must be an async function"
# Get everything after the function declaration (enough context)
after = src[m.start():m.start()+5000]
assert "applyBotName" in after, \
"switchToProfile must call applyBotName after profile switch"
def test_placeholder_uses_name_variable(self):
"""The composer placeholder must use the resolved name variable."""
src = _src("boot.js")
m = re.search(r'function applyBotName\(\)\{.*?\n\}', src, re.DOTALL)
assert m, "applyBotName function must exist"
body = m.group(0)
assert re.search(r"msg\.placeholder\s*=\s*.*Message.*name", body), \
"applyBotName must set composer placeholder to 'Message <name>…'"