import re from pathlib import Path ROOT = Path(__file__).resolve().parents[2] WEB = ROOT / "apps" / "web-console" def source(name: str) -> str: return (WEB / name).read_text(encoding="utf-8") def test_shadcn_semantic_theme_tokens_drive_the_console() -> None: styles = source("styles.css") console = source("console-v2.css") speech = source("speech-input.css") expected_tokens = { "--background: oklch(0.968 0.019 244)", "--foreground: oklch(0.29 0.042 252)", "--card-foreground: oklch(0.34 0.032 250)", "--primary: oklch(0.57 0.19 258)", "--primary-foreground: oklch(0.99 0.004 245)", "--destructive: oklch(0.61 0.19 24)", "--sidebar-primary: oklch(0.57 0.19 258)", "--background: oklch(0.2 0.035 252)", "--foreground: oklch(0.94 0.02 245)", "--primary: oklch(0.7 0.15 252)", "--sidebar-primary: oklch(0.7 0.15 252)", } token_lines = {line.strip() for line in styles.replace(";", "").splitlines()} assert expected_tokens <= token_lines assert ".dark {" in styles assert "--v2-accent: var(--primary)" in console assert "--v2-sidebar: var(--sidebar)" in console assert "color: var(--destructive)" in speech def test_theme_asset_versions_are_consistent_with_the_pwa_shell() -> None: html = source("index.html") service_worker = source("service-worker.js") for asset in ( "/styles.css?v=dual-seat-23", "/console-v2.css?v=delivery-state-69", "/self-extension.css?v=pet-settings-49", "/speech-input.css?v=sensevoice-7", "/codepen-glass-theme.css?v=creative-cloud-2", ): assert asset in html assert f'"{asset}"' in service_worker assert 'const CACHE_VERSION = "cognitive-agent-pad-v302"' in service_worker def test_reference_glass_theme_covers_the_complete_workspace() -> None: html = source("index.html") theme = source("codepen-glass-theme.css") app = source("app.js") assert '' in html assert 'const key = "cognitive-agent.glass-theme"' in html assert 'id="glassThemeToggle"' in html assert 'data-theme-icon="sun"' in html assert 'data-theme-icon="moon"' in html assert 'const GLASS_THEME_STORAGE_KEY = "cognitive-agent.glass-theme"' in app assert "localStorage.setItem(GLASS_THEME_STORAGE_KEY, normalized)" in app assert "document.cookie = `${GLASS_THEME_STORAGE_KEY}=${normalized}" in app assert 'new CustomEvent("cognitive-agent:theme-change"' in app for contract in ( "--glass-shell:", "--glass-panel:", "--glass-card:", "backdrop-filter: blur(22px) saturate(1.25)", ".main-panel > .v2-mode-rail", "#assistantDrawer", ".joint-twin-shell > .twin-band", "#v2ExtensionPanel .v2-extension-sync-mount", ".v2-pet-card", ".v2-pet-presence-card", ".v2-pet-settings-dialog", ".mode-gallery", ".v2-nfc-dialog", ".energy-monitor-page", ): assert contract in theme assert 'html[data-glass-theme="light"] body.console-v2' in theme assert ".glass-theme-toggle" in theme assert "width: 100vw !important" in theme assert "height: 100dvh !important" in theme assert "margin: 0 !important" in theme assert "border: 0 !important" in theme assert "border-radius: 0 !important" in theme def test_vehicle_twin_icons_and_nested_overlays_use_semantic_tokens() -> None: styles = source("styles.css") console = source("console-v2.css") extension = source("self-extension.css") expected_console_rules = { ".console-v2 .v2-twin-hotspot-label", ".console-v2 .v2-twin-device-popover", ".console-v2 .v2-reasoning-field", ".console-v2 .device-power-drawer", ".console-v2 .v2-sync-log li[data-log-status=\"error\"] > span", "background: var(--primary)", "background: var(--popover)", } expected_overlay_rules = { ".mode-gallery-backdrop", ".mode-editor-backdrop", ".gesture-drawer", "background: var(--card)", "border-color: var(--border)", } expected_extension_rules = { ".v2-extension-dialog::backdrop", ".v2-gscu-tcp-dialog", ".v2-nfc-dialog", ".v2-extension-toast.error", ".console-v2 #v2ExtensionPanel .v2-extension-gateway > button", "background: var(--destructive)", } assert all(rule in console for rule in expected_console_rules) assert all(rule in styles for rule in expected_overlay_rules) assert all(rule in extension for rule in expected_extension_rules) def test_operator_controls_share_status_and_typography_tokens() -> None: html = source("index.html") styles = source("styles.css") console = source("console-v2.css") script = source("console-v2.js") for token in ( "--status-online:", "--status-offline:", "--status-info:", "--status-success:", "--status-warning:", "--status-error:", "--heading-foreground:", "--body-foreground:", "--subtle-foreground:", "--text-caption:", "--text-control:", "--text-input:", "--text-label:", ): assert token in styles assert '