from __future__ import annotations import json 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_vue_vite_application_is_the_primary_frontend_entry() -> None: html = source("index.html") main = source("src/main.js") app = source("src/App.vue") package = json.loads(source("package.json")) vite = source("vite.config.js") service_worker = source("service-worker.js") assert '
' in html assert '' in html assert 'import { createApp, nextTick } from "vue"' in main assert 'import App from "./App.vue"' in main assert 'application.mount("#app")' in main assert 'defineOptions({ name: "N7ConsoleApp" })' in app assert 'class="workspace"' in app assert package["dependencies"]["vue"] == "3.5.21" assert package["scripts"]["build"] == "vite build" assert 'import vue from "@vitejs/plugin-vue"' in vite assert 'outDir: outputRoot' in vite assert 'const CACHE_VERSION = "cognitive-agent-pad-v324-firmware-notification"' in service_worker assert "unpkg.com" not in html assert "cdn.jsdelivr.net" not in html def test_python_and_one_click_startup_use_the_vite_distribution() -> None: server = (ROOT / "src" / "cognitive_agent" / "server.py").read_text( encoding="utf-8" ) launcher = (ROOT / "tools" / "start_n7web.py").read_text(encoding="utf-8") assert 'WEB_CONSOLE_DIST_ROOT = WEB_CONSOLE_SOURCE_ROOT / "dist"' in server assert 'if (WEB_CONSOLE_DIST_ROOT / "index.html").is_file()' in server assert 'parser.add_argument(\n "--skip-web-build"' in launcher assert 'commands.append([str(npm), "ci"])' in launcher assert 'commands.append([str(npm), "run", "build"])' in launcher assert "_build_web_console(npm)" in launcher def test_vendored_vue_runtime_and_license_are_present() -> None: runtime = WEB / "vendor" / "vue" / "3.5.21" / "vue.runtime.global.prod.js" license_file = WEB / "vendor" / "vue" / "3.5.21" / "LICENSE" assert runtime.is_file() assert runtime.stat().st_size > 50_000 assert "vue v3.5.21" in runtime.read_text(encoding="utf-8")[:500] assert license_file.is_file() assert "The MIT License" in license_file.read_text(encoding="utf-8") def test_vue_islands_render_modes_and_dispatched_controls() -> None: vue_ui = source("vue-ui.js") app = source("app.js") assistant = source("assistant-chat.js") styles = source("assistant-chat.css") assert 'name: "N7ModeChipRail"' in vue_ui assert 'name: "N7DispatchedControlsCard"' in vue_ui assert 'container.dataset.vueSurface = "mode-chips"' in vue_ui assert 'container.dataset.vueSurface = "dispatched-controls"' in vue_ui assert "renderModeChips" in vue_ui assert "renderDispatchedControls" in vue_ui assert "window.CognitiveAgentVueUI = Object.freeze" in vue_ui assert '"data-mode-run": "true"' in vue_ui assert "function vueModeChipEntries(modes)" in app assert "window.CognitiveAgentVueUI?.renderModeChips?.(" in app assert "window.CognitiveAgentVueUI?.renderDispatchedControls" in assistant assert 'host.className = "assistant-dispatched-controls-vue-host"' in assistant assert "deliveryLabel: String(item.deliveryLabel" in assistant assert "deliveryDetail: String(item.deliveryDetail" in assistant assert "下发状态:" in vue_ui assert ".assistant-dispatched-controls-vue-host" in styles def test_existing_dom_renderers_remain_as_transition_fallbacks() -> None: app = source("app.js") assistant = source("assistant-chat.js") mode_vue_call = app.index("window.CognitiveAgentVueUI?.renderModeChips?.(") mode_fallback = app.index("const runtimeModeIds = new Set", mode_vue_call) assert mode_fallback > mode_vue_call command_vue_call = assistant.index( "window.CognitiveAgentVueUI?.renderDispatchedControls" ) command_fallback = assistant.index( 'document.createElement("details")', command_vue_call ) assert command_fallback > command_vue_call vue_ui = source("vue-ui.js") assert 'from "vue"' in vue_ui assert "renderDispatchedControls: () => false" not in vue_ui assert "renderModeChips: () => false" not in vue_ui