114514
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""训练前端 JS 逻辑回归:用 DOM 桩跑发布的 charts.js/app.js 原文。
|
||||
|
||||
动机:该前端的多数 bug 只在浏览器逻辑里暴露(游标重复追加、classList 取错、
|
||||
字段缺失导致渲染中断),Python 侧测试无法覆盖。这里用服务端真实生成的
|
||||
schema 与示例快照驱动一次完整渲染,有 node 则执行,无 node 自动跳过。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
HARNESS = REPO / "tests" / "js" / "training_ui_harness.cjs"
|
||||
|
||||
|
||||
@pytest.mark.skipif(shutil.which("node") is None, reason="需要 node 环境运行 JS 桩测试")
|
||||
def test_training_ui_frontend_logic(tmp_path):
|
||||
sys.path.insert(0, str(REPO / "src"))
|
||||
from mcm26b.training_ui.demo import DEMO_SCENARIOS, demo_snapshot
|
||||
from mcm26b.training_ui.schema import config_schema
|
||||
|
||||
scenarios = {key: demo_snapshot(scenario=key) for key in DEMO_SCENARIOS}
|
||||
scenarios_path = tmp_path / "scenarios.json"
|
||||
schema_path = tmp_path / "schema.json"
|
||||
scenarios_path.write_text(json.dumps(scenarios, ensure_ascii=False),
|
||||
encoding="utf-8")
|
||||
schema_path.write_text(json.dumps(config_schema(), ensure_ascii=False),
|
||||
encoding="utf-8")
|
||||
|
||||
result = subprocess.run(
|
||||
["node", str(HARNESS)], capture_output=True, text=True, timeout=120,
|
||||
env={**os.environ, "REPO": str(REPO),
|
||||
"DEMO_STATE": str(scenarios_path), "SCHEMA": str(schema_path)})
|
||||
assert result.returncode == 0, \
|
||||
f"训练前端逻辑测试失败:\n{result.stdout}\n{result.stderr}"
|
||||
assert "ALL PASS" in result.stdout
|
||||
Reference in New Issue
Block a user