fix: close remaining CAD delivery review gaps

This commit is contained in:
2026-07-11 15:26:43 +08:00
parent 6c1336fa59
commit c12d1d57cb
11 changed files with 464 additions and 93 deletions

View File

@@ -213,6 +213,59 @@ def test_offline_viewer_without_real_browser_report_is_blocked(tmp_path: Path) -
assert any(item["name"] == "offline:browser-smoke" and item["status"] == "SKIP" for item in report["checks"])
def test_offline_viewer_escapes_html_and_inline_script_data(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path)
document = json.loads(spec.read_text(encoding="utf-8"))
document["project"]["name"] = '<Tower & Co></script><script>alert("title")</script>'
document["floors"]["F1"]["name"] = '首层</script><script>alert("floor")</script>'
document["categories"]["walls"]["label"] = "墙<&>"
spec.write_text(json.dumps(document), encoding="utf-8")
offline = tmp_path / "viewer.html"
proc = run(
sys.executable,
"scripts/write_offline_viewer.py",
"--spec",
str(spec),
"--glb",
str(glb),
"--out",
str(offline),
"--subtitle",
"<unsafe & subtitle>",
)
assert proc.returncode == 0, proc.stderr
text = offline.read_text(encoding="utf-8")
assert "&lt;Tower &amp; Co&gt;&lt;/script&gt;" in text
assert "&lt;unsafe &amp; subtitle&gt;" in text
assert '首层<\\/script><script>alert(\\"floor\\")<\\/script>' in text
assert '首层</script><script>alert("floor")</script>' not in text
def test_web_variant_entry_requires_a_nonempty_file(tmp_path: Path) -> None:
import verify_delivery
web = tmp_path / "web"
for relative in (
"index.html",
"app.js",
"styles.css",
"model.glb",
"node_modules/three/build/three.module.js",
"node_modules/lucide/dist/umd/lucide.js",
):
target = web / relative
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(
"window.__renders; invalidate(); DRACOLoader; restoreStateFromHash; switchVariant", encoding="utf-8"
)
(web / "model_metadata.json").write_text(json.dumps({"model_variants": [{"key": "standard", "file": ""}]}))
checks: list[dict] = []
verify_delivery.inspect_web(web, checks)
variant_check = next(item for item in checks if item["name"] == "web:variants")
assert variant_check["status"] == "FAIL"
assert "<missing file>" in variant_check["detail"]
def test_strict_delivery_requires_a_render(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path)
source_report = source_report_fixture(tmp_path)