from pathlib import Path import re 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(1 0 0)", "--foreground: oklch(0.145 0.008 326)", "--primary: oklch(0.488 0.243 264.376)", "--primary-foreground: oklch(0.97 0.014 254.604)", "--destructive: oklch(0.577 0.245 27.325)", "--sidebar-primary: oklch(0.546 0.245 262.881)", "--background: oklch(0.145 0.008 326)", "--foreground: oklch(0.985 0 0)", "--primary: oklch(0.424 0.199 265.638)", "--sidebar-primary: oklch(0.623 0.214 259.815)", } 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-21", "/console-v2.css?v=delivery-state-50", "/self-extension.css?v=gscu-tcp-42", "/speech-input.css?v=sensevoice-5", ): assert asset in html assert f'"{asset}"' in service_worker assert 'const CACHE_VERSION = "cognitive-agent-pad-v227"' in service_worker 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:", "--text-caption:", "--text-control:", "--text-input:", "--text-label:", ): assert token in styles assert '
' in html assert 'id="modeRailToggle"' in html assert 'aria-controls="modeRailContent"' in html assert 'id="modeRailContent"' in html assert 'role="region"' in html assert 'aria-label="功能模式列表"' in html assert '自定义' in html assert "模拟下发" in html assert "真实下发" in html assert 'id="simulationMode"' not in html assert 'class="v2-sync-link-stack"' not in script assert '.mode-option[data-connection-state="online"]::after' in styles assert '.mode-option[data-connection-state="offline"]::after' in styles assert "font-size: var(--text-control) !important" in console def test_wired_can_link_requires_real_device_connection_evidence() -> None: app = source("app.js") assert 'runtime?.state_sync?.state === "online"' in app assert '["online", "ready"].includes(runtime?.state_sync?.state)' not in app assert 'wiredCanProbe: { passenger: false, vehicle: false }' in app assert 'updateWiredCanProbe("passenger", true, requestedTransport)' in app assert 'updateWiredCanProbe("vehicle", true, requestedTransport)' in app assert 'updateWiredCanProbe("passenger", false, requestedTransport)' in app assert 'updateWiredCanProbe("vehicle", false, requestedTransport)' in app assert "resetTransportConnectionEvidence();" in app assert 'label.textContent = `${transportLabel} · 信号链路断开`' in app def test_command_fields_use_distinct_semantic_colors() -> None: styles = source("styles.css") console = source("console-v2.css") for token in ( "--command-channel:", "--command-source:", "--command-delivered:", "--command-pending:", "--command-category:", "--command-control:", "--command-frame:", ): assert token in styles for mapping in ( "color: var(--command-channel)", "color: var(--command-source)", "color: var(--command-pending)", "color: var(--command-delivered)", "color: var(--command-category)", "color: var(--command-control)", "color: var(--command-frame)", ): assert mapping in console def test_function_modes_use_an_inline_accessible_collapsible() -> None: html = source("index.html") app = source("app.js") console = source("console-v2.css") assert '
' in html assert 'id="modeRailSelection">常用模式' in html assert 'id="modeGalleryToggle"' in html assert '自定义' in html assert '
.mode-rail-content[hidden]' in console assert ".mode-rail-expanded .main-panel" not in console assert "position: absolute" in console assert "top: calc(100% + 8px)" in console assert "overflow-y: auto" in console assert "scrollbar-gutter: stable" in console def test_vehicle_device_cards_hide_stale_values_without_signal() -> None: console = source("console-v2.js") assert "function normalizeDeviceReadout(value)" in console assert "function deviceFeedbackAvailable(deviceId)" in console assert 'return rows.map(([label]) => [label, "-"])' in console assert 'const waiting = rows.some(([, value]) => value === "-")' in console assert '"cognitive-agent:vehicle-feedback-state"' in console def test_final_theme_layers_do_not_reintroduce_raw_ui_colors() -> None: sections = ( source("styles.css").split("/* Final semantic theme layer", 1)[1], source("console-v2.css").split("/* Final semantic theme cascade", 1)[1], source("self-extension.css").split( "/* Final semantic theme layer for extension surfaces", 1 )[1], ) raw_color = re.compile(r"#[0-9a-fA-F]{3,8}\b|rgba?\(") for section in sections: assert not raw_color.search(section) def test_all_five_output_modules_are_covered_by_the_final_theme_layer() -> None: console = source("console-v2.css") final_layer = console.split("/* Final semantic theme cascade", 1)[1] for selector in ( ".joint-twin-shell.v2-output-page", ".decision-list li", ".result-workspace #panel-config.config-panel", ".plan-panel .frame-summary", ".execution-summary", ): assert selector in final_layer assert "--config-accent: var(--primary)" in final_layer assert "background: var(--card)" in final_layer assert "border-color: var(--border)" in final_layer