Skip to content

The agent that grows with you

test: cover customCSS parsing, RPC payload, and style lifecycle

David Metcalfe37ee28d78968
diff --git a/apps/desktop/src/themes/backend-sync.test.ts b/apps/desktop/src/themes/backend-sync.test.ts
index a12a74419dc..b40d43da45b 100644
--- a/apps/desktop/src/themes/backend-sync.test.ts
+++ b/apps/desktop/src/themes/backend-sync.test.ts
@@ -1,12 +1,20 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
-import { $backendThemes, $pendingSkinApply, __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'
+import {
+ $backendCustomCSS,
+ $backendThemes,
+ $pendingSkinApply,
+ __resetBackendSkinSync,
+ ingestBackendSkin,
+} from './backend-sync'
const skin = (name: string) => ({
name,
colors: { background: '#101020', ui_accent: '#ff33aa', banner_text: '#eeeeee' }
})
+const skinWithCSS = (name: string, customCSS: string) => ({ ...skin(name), customCSS })
+
describe('ingestBackendSkin', () => {
beforeEach(() => {
window.localStorage.clear()
@@ -87,6 +95,50 @@ describe('ingestBackendSkin', () => {
expect($pendingSkinApply.get()).toBe('mono')
})
+ it('carries customCSS for a built-in-named user skin without shadowing the palette', () => {
+ ingestBackendSkin(skinWithCSS('mono', '.chat-input { font-size: 16px; }'), { apply: true })
+
+ expect($backendThemes.get().mono).toBeUndefined() // palette policy preserved
+ expect($pendingSkinApply.get()).toBe('mono')
+ expect($backendCustomCSS.get().mono).toBe('.chat-input { font-size: 16px; }')
+ })
+
+ it('keys default-named skin CSS under the resolved desktop default', () => {
+ ingestBackendSkin(skinWithCSS('default', 'body { background: red; }'), { apply: true })
+
+ expect($backendThemes.get().default).toBeUndefined()
+ // setTheme normalizes `default` → DEFAULT_SKIN_NAME ('nous'), so the CSS
+ // must be findable under that name when the theme is derived.
+ expect($backendCustomCSS.get().nous).toBe('body { background: red; }')
+ })
+
+ it('clears customCSS when a built-in-named skin drops the field', () => {
+ ingestBackendSkin(skinWithCSS('mono', 'a { color: red; }'), { apply: true })
+ expect($backendCustomCSS.get().mono).toBe('a { color: red; }')
+
+ // Same skin, CSS removed from the YAML — the entry must go so stale rules
+ // don't linger after the next apply.
+ ingestBackendSkin(skin('mono'), { apply: true })
+
+ expect($backendCustomCSS.get().mono).toBeUndefined()
+ })
+
+ it('does not populate the CSS store for non-built-in skins (converter carries it)', () => {
+ ingestBackendSkin(skinWithCSS('neon', 'a { color: red; }'), { apply: true })
+
+ expect($backendCustomCSS.get()).toEqual({})
+ expect($backendThemes.get().neon?.customCSS).toBe('a { color: red; }')
+ })
+
+ it('reset clears the custom CSS store', () => {
+ ingestBackendSkin(skinWithCSS('mono', 'a {}'), { apply: false })
+ expect($backendCustomCSS.get().mono).toBe('a {}')
+
+ __resetBackendSkinSync()
+
+ expect($backendCustomCSS.get()).toEqual({})
+ })
+
it('ignores empty payloads', () => {
ingestBackendSkin(undefined, { apply: true })
ingestBackendSkin({ name: '' }, { apply: true })
diff --git a/apps/desktop/src/themes/context.test.tsx b/apps/desktop/src/themes/context.test.tsx
index 08e70668dec..28389e33ae2 100644
--- a/apps/desktop/src/themes/context.test.tsx
+++ b/apps/desktop/src/themes/context.test.tsx
@@ -5,6 +5,9 @@ import { __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'
import { skinPref, ThemeProvider, useTheme } from './context'
import { everforestTheme } from './presets'
+import { $backendThemes, __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'
+import { ThemeProvider } from './context'
+
// The live-authoring loop: Hermes writes/edits one skin file and every surface
// repaints. An in-place edit keeps the NAME — only the palette moves.
const bloomberg = (foreground: string) => ({
@@ -14,6 +17,9 @@ const bloomberg = (foreground: string) => ({
const cssVar = (name: string) => window.document.documentElement.style.getPropertyValue(name)
+const customStyleEl = () =>
+ window.document.getElementById('hermes-desktop-custom-css') as HTMLStyleElement | null
+
describe('ThemeProvider ← backend skin sync', () => {
beforeEach(() => {
window.localStorage.clear()
@@ -76,6 +82,8 @@ describe('ThemeProvider ← backend skin sync', () => {
it('paints a persisted backend skin once the connect-time seed makes it resolvable', () => {
window.localStorage.setItem('hermes-desktop-theme-v2', 'bloomberg')
+
+ it('injects customCSS from an applied backend skin', () => {
render(
<ThemeProvider>
<div />
@@ -231,5 +239,87 @@ describe('ThemeProvider highlight preview', () => {
act(() => ctx.previewTheme('does-not-exist', 'dark'))
expect(cssVar('--theme-foreground')).toBe(painted)
+
+ act(() =>
+ ingestBackendSkin({ ...bloomberg('#ff9f0a'), customCSS: '.chat-input { font-size: 16px; }' }, { apply: true })
+ )
+
+ expect(customStyleEl()?.textContent).toBe('.chat-input { font-size: 16px; }')
+ })
+
+ it('replaces customCSS in the SAME <style> tag when the active skin changes', () => {
+ render(
+ <ThemeProvider>
+ <div />
+ </ThemeProvider>
+ )
+
+ act(() => ingestBackendSkin({ ...bloomberg('#ff9f0a'), customCSS: 'a { color: red; }' }, { apply: true }))
+ const first = customStyleEl()
+ expect(first?.textContent).toBe('a { color: red; }')
+
+ act(() =>
+ ingestBackendSkin(
+ { name: 'forest', colors: { background: '#001100', ui_text: '#66ff66' }, customCSS: 'b { color: blue; }' },
+ { apply: true }
+ )
+ )
+
+ const second = customStyleEl()
+ expect(second).not.toBeNull()
+ expect(second?.id).toBe(first?.id) // one tag reused — no accumulation
+ expect(second?.textContent).toBe('b { color: blue; }')
+ })
+
+ it('removes the style tag when switching to a CSS-less skin', () => {
+ render(
+ <ThemeProvider>
+ <div />
+ </ThemeProvider>
+ )
+
+ act(() => ingestBackendSkin({ ...bloomberg('#ff9f0a'), customCSS: 'a { color: red; }' }, { apply: true }))
+ expect(customStyleEl()).not.toBeNull()
+
+ act(() => ingestBackendSkin(bloomberg('#00ff00'), { apply: true }))
+
+ expect(customStyleEl()).toBeNull()
+ })
+
+ it('applies customCSS for a built-in-named user skin without shadowing the built-in palette', () => {
+ render(
+ <ThemeProvider>
+ <div />
+ </ThemeProvider>
+ )
+
+ act(() =>
+ ingestBackendSkin(
+ { name: 'mono', colors: { background: '#ff00ff', ui_text: '#00ff00' }, customCSS: '.status-bar { background: black; }' },
+ { apply: true }
+ )
+ )
+
+ // The user's CSS lands…
+ expect(customStyleEl()?.textContent).toBe('.status-bar { background: black; }')
+ // …but the palette policy still holds: the backend theme is never
+ // registered under a built-in name, so the painted background is the
+ // desktop's built-in mono, not the user YAML's #ff00ff.
+ expect($backendThemes.get().mono).toBeUndefined()
+ expect(cssVar('--theme-background-seed')).not.toBe('#ff00ff')
+ })
+
+ it('applies customCSS from a default-named user skin under the desktop default', () => {
+ render(
+ <ThemeProvider>
+ <div />
+ </ThemeProvider>
+ )
+
+ act(() =>
+ ingestBackendSkin({ name: 'default', colors: { background: '#123456' }, customCSS: '.chat-input { font-size: 18px; }' }, { apply: true })
+ )
+
+ expect(customStyleEl()?.textContent).toBe('.chat-input { font-size: 18px; }')
})
})
diff --git a/tests/hermes_cli/test_skin_engine.py b/tests/hermes_cli/test_skin_engine.py
index ea5441fe6c1..20e0b3bebf8 100644
--- a/tests/hermes_cli/test_skin_engine.py
+++ b/tests/hermes_cli/test_skin_engine.py
@@ -114,6 +114,54 @@ class TestUserSkins:
assert pirate["source"] == "user"
+class TestCustomCSS:
+ """customCSS passthrough: parsed from user YAML, whitespace-stripped,
+ capped at 32 KiB, empty when the field is absent."""
+
+ def _load(self, tmp_path, monkeypatch, **skin_data):
+ from hermes_cli.skin_engine import load_skin
+
+ skins_dir = tmp_path / "skins"
+ skins_dir.mkdir()
+ import yaml
+
+ data = {"name": "styled", "colors": {"background": "#101010"}}
+ data.update(skin_data)
+ (skins_dir / "styled.yaml").write_text(yaml.dump(data), encoding="utf-8")
+ monkeypatch.setattr("hermes_cli.skin_engine._skins_dir", lambda: skins_dir)
+ return load_skin("styled")
+
+ def test_user_skin_custom_css_passthrough(self, tmp_path, monkeypatch):
+ skin = self._load(tmp_path, monkeypatch, customCSS=".chat-input { font-size: 16px; }")
+
+ assert skin.custom_css == ".chat-input { font-size: 16px; }"
+
+ def test_user_skin_custom_css_whitespace_stripped(self, tmp_path, monkeypatch):
+ skin = self._load(tmp_path, monkeypatch, customCSS="\n .status-bar { background: black; } \n")
+
+ assert skin.custom_css == ".status-bar { background: black; }"
+
+ def test_user_skin_custom_css_empty_when_missing(self, tmp_path, monkeypatch):
+ skin = self._load(tmp_path, monkeypatch)
+
+ assert skin.custom_css == ""
+
+ def test_user_skin_custom_css_capped_at_32_ki_b(self, tmp_path, monkeypatch):
+ skin = self._load(tmp_path, monkeypatch, customCSS="x" * 40000)
+
+ assert len(skin.custom_css) == 32768
+
+ def test_builtin_skin_has_no_custom_css(self, tmp_path, monkeypatch):
+ from hermes_cli.skin_engine import load_skin
+
+ skins_dir = tmp_path / "skins"
+ skins_dir.mkdir()
+ monkeypatch.setattr("hermes_cli.skin_engine._skins_dir", lambda: skins_dir)
+
+ assert load_skin("default").custom_css == ""
+ assert load_skin("mono").custom_css == ""
+
+
class TestDisplayIntegration:
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index 0f95eb1bff6..65dc0328655 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -1422,7 +1422,7 @@ def test_skin_live_switch_end_to_end(server, tmp_path, monkeypatch):
(tmp_path / "skins").mkdir()
(tmp_path / "skins" / "midnight.yaml").write_text(
- "name: midnight\ndescription: t\ncolors:\n banner_title: '#00ffcc'\n background: '#001010'\n"
+ "name: midnight\ndescription: t\ncolors:\n banner_title: '#00ffcc'\n background: '#001010'\ncustomCSS: |\n .chat-input { font-size: 16px; }\n"
)
monkeypatch.setattr(skin_engine, "get_hermes_home", lambda: tmp_path)
monkeypatch.setattr(server, "_hermes_home", tmp_path)
@@ -1446,6 +1446,9 @@ def test_skin_live_switch_end_to_end(server, tmp_path, monkeypatch):
assert [ev for ev, _ in emitted] == ["skin.changed"]
assert emitted[0][1]["name"] == "midnight"
assert emitted[0][1]["colors"]["banner_title"] == "#00ffcc"
+ # customCSS rides the same payload end-to-end: parsed from the YAML,
+ # stripped, and emitted by resolve_skin().
+ assert emitted[0][1]["customCSS"] == ".chat-input { font-size: 16px; }"
def test_broadcast_skin_if_changed_on_any_signature_move(server, monkeypatch):