Files
Cognitive_Agent/tests/unit/test_firmware_workbench_frontend_contract.py
T

123 lines
5.3 KiB
Python

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_workbench_is_a_standalone_development_surface() -> None:
html = source("firmware-workbench.html")
script = source("firmware-workbench.js")
assert "座椅固件开发工作台" in html
assert '<textarea id="instructionInput"' in html
assert 'id="startTaskButton"' in html
assert 'id="cancelTaskButton"' in html
assert 'id="pipeline"' in html
assert 'id="logStream"' in html
assert 'id="artifactTableBody"' in html
assert 'id="baselineSelect"' in html
assert 'id="targetCapabilities"' in html
assert "执行摘要" not in html
assert "单屏工作台" not in html
assert "相同指令只会复用同一任务" not in html
assert "固件交付流水线</h2>" not in html
assert html.count("<option") == 1
assert '<option value="time_only">时间控制</option>' in html
for english_label in ("DEVELOPMENT BRIEF", "DELIVERY PIPELINE", "LIVE EXECUTION", "SOFTWARE ARTIFACTS"):
assert english_label not in html
assert "普通聊天" not in html
for stage in ("指令输入", "需求解析", "基线检查", "代码生成", "编译构建", "测试验证", "固件打包", "发布服务器"):
assert stage in script or stage in html
for status in ("等待", "运行中", "待确认", "成功", "失败", "取消", "阻塞"):
assert status in script or status in html
def test_workbench_exposes_artifact_actions_and_always_starts_a_new_task() -> None:
html = source("firmware-workbench.html")
script = source("firmware-workbench.js")
entry = source("firmware-workbench-entry.js")
index = source("index.html")
worker = source("service-worker.js")
vite = source("vite.config.js")
for label in ("查看详情", "能力差异", "代码差异", "验证记录", "下载固件", "发布到服务器", "删除固件产物"):
assert label in script
assert "检测到相同指令" not in script
assert "result.duplicate" not in script
assert "已发布,待车机端下载升级" not in script
assert 'id = "firmwareWorkbenchToggle"' in entry
assert 'className = "firmware-workbench-layer"' in entry
assert "/firmware-workbench-entry.js?v=3" in index
assert "/firmware-workbench-entry.css?v=2" in index
for asset in (
"/firmware-workbench-entry.css?v=2",
"/firmware-workbench-entry.js?v=3",
"/firmware-workbench.html",
"/firmware-workbench-theme.js?v=1",
"/firmware-workbench.css?v=8",
"/firmware-workbench.js?v=5",
):
assert f'"{asset}"' in worker
for runtime_file in (
"firmware-workbench-entry.js",
"firmware-workbench-entry.css",
"firmware-workbench-theme.js",
"firmware-workbench.html",
"firmware-workbench.js",
"firmware-workbench.css",
):
assert f'"{runtime_file}"' in vite
def test_workbench_inherits_live_theme_and_uses_the_larger_dialog_frame() -> None:
html = source("firmware-workbench.html")
entry = source("firmware-workbench-entry.js")
entry_styles = source("firmware-workbench-entry.css")
workbench_styles = source("firmware-workbench.css")
theme = source("firmware-workbench-theme.js")
assert 'content="light dark"' in html
assert 'id="firmwareWorkbenchThemeColor"' in html
assert '/firmware-workbench-theme.js?v=1' in html
assert 'data-glass-theme="dark"' in workbench_styles
assert 'window.parent?.document?.documentElement?.dataset?.glassTheme' in theme
assert 'event.data?.type !== "cognitive-agent:theme-change"' in theme
assert 'window.addEventListener("cognitive-agent:theme-change"' in entry
assert 'attributeFilter: ["data-glass-theme"]' in entry
assert 'width: min(1480px, 100%);' in entry_styles
assert 'height: min(900px, 100%);' in entry_styles
assert 'width: min(1040px, 100%);' in workbench_styles
assert 'max-height: min(820px, calc(100dvh - 48px));' in workbench_styles
def test_peer_dialogs_share_the_expanded_desktop_size_contract() -> None:
gallery = source("styles.css")
energy = source("energy-monitor.css")
extension = source("self-extension.css")
assert 'width: min(1320px, calc(100vw - 32px));' in gallery
assert 'height: min(860px, calc(100dvh - 32px));' in gallery
assert 'width: min(1480px, 100%);' in energy
assert 'height: min(900px, 100%);' in energy
assert 'width: min(780px, calc(100vw - 32px));' in extension
assert 'width: min(960px, calc(100vw - 30px));' in extension
assert 'width: min(1180px, calc(100vw - 28px));' in extension
assert 'width: min(980px, calc(100vw - 32px));' in extension
def test_published_artifacts_expose_the_expanded_right_aligned_notify_action() -> None:
script = source("firmware-workbench.js")
styles = source("firmware-workbench.css")
assert 'artifact.status === "published"' in script
assert 'class="notify-action"' in script
assert 'data-artifact-action="notify"' in script
assert 'margin-left: auto' in styles
assert 'flex: 0 0 42px' in styles
assert 'height: 34px' in styles
assert '.table-actions .notify-action svg { width: 20px; height: 20px;' in styles