fix: close remaining CAD delivery review gaps
This commit is contained in:
@@ -14,6 +14,8 @@ sys.path.insert(0, str(ROOT / "scripts"))
|
||||
import audit_showcase_extraction # noqa: E402
|
||||
import build_blender_showcase # noqa: E402
|
||||
import cad_showcase # noqa: E402
|
||||
import delivery_waivers # noqa: E402
|
||||
import derive_showcase_spec # noqa: E402
|
||||
import showcase_schema # noqa: E402
|
||||
import spec_to_glb # noqa: E402
|
||||
|
||||
@@ -165,6 +167,122 @@ def test_all_derive_geometry_loss_warnings_are_forbidden() -> None:
|
||||
}
|
||||
|
||||
|
||||
def test_waivers_share_one_implementation_and_reject_not_applicable_targets(tmp_path: Path) -> None:
|
||||
import verify_delivery
|
||||
|
||||
assert cad_showcase.parse_waivers is delivery_waivers.parse_waivers
|
||||
assert verify_delivery.parse_waivers is delivery_waivers.parse_waivers
|
||||
audit = tmp_path / "audit.json"
|
||||
audit.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"gates": [
|
||||
{
|
||||
"name": "frame_ledger",
|
||||
"status": "NOT_APPLICABLE",
|
||||
"detail": "No frame report supplied",
|
||||
}
|
||||
]
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
pipeline = cad_showcase.Pipeline(tmp_path / "state.json", "fingerprint", resume=False)
|
||||
assert not cad_showcase.enforce_audit_gates(
|
||||
pipeline,
|
||||
audit,
|
||||
{"audit:frame_ledger": "pre-approved in case this gate becomes armed"},
|
||||
)
|
||||
state = json.loads((tmp_path / "state.json").read_text(encoding="utf-8"))
|
||||
blocked = state["blocked_gates"]
|
||||
assert blocked[0]["name"] == "waiver:audit:frame_ledger"
|
||||
assert "NOT_APPLICABLE" in blocked[0]["detail"]
|
||||
|
||||
|
||||
def test_audit_waiver_typo_fails_before_downstream_work(tmp_path: Path) -> None:
|
||||
audit = tmp_path / "audit.json"
|
||||
audit.write_text(
|
||||
json.dumps({"gates": [{"name": "floors_aligned", "status": "PASS", "detail": "aligned"}]}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
pipeline = cad_showcase.Pipeline(tmp_path / "state.json", "fingerprint", resume=False)
|
||||
assert not cad_showcase.enforce_audit_gates(
|
||||
pipeline,
|
||||
audit,
|
||||
{"audit:floors_aligend": "typo must not survive to final verification"},
|
||||
)
|
||||
state = json.loads((tmp_path / "state.json").read_text(encoding="utf-8"))
|
||||
assert state["blocked_gates"][0]["name"] == "waiver:audit:floors_aligend"
|
||||
|
||||
|
||||
def test_waiver_preflight_rejects_misspelled_namespace_and_extra_future_waiver(tmp_path: Path) -> None:
|
||||
scope = tmp_path / "scope.json"
|
||||
scope.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"scope_version": 1,
|
||||
"mode": "single",
|
||||
"requested": ["main"],
|
||||
"buildings": [{"id": "main", "status": "PASS", "artifacts": ["future.glb"]}],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
args = cad_showcase.parser().parse_args(
|
||||
[
|
||||
"run",
|
||||
"--dxf-dir",
|
||||
str(tmp_path),
|
||||
"--config",
|
||||
str(tmp_path / "config.json"),
|
||||
"--source-report",
|
||||
str(tmp_path / "source.json"),
|
||||
"--out-dir",
|
||||
str(tmp_path / "out"),
|
||||
"--scope-manifest",
|
||||
str(scope),
|
||||
"--web",
|
||||
]
|
||||
)
|
||||
invalid = cad_showcase.preflight_waiver_targets(
|
||||
args,
|
||||
{"gate": {"status": "PASS"}},
|
||||
{"gates": [{"name": "floors_aligned", "status": "WARN", "detail": "needs evidence"}]},
|
||||
scope,
|
||||
{
|
||||
"audti:floors_aligned": "misspelled namespace",
|
||||
"browser:smoke": "cannot pre-waive a generated PASS check",
|
||||
},
|
||||
)
|
||||
assert {check["name"] for check in invalid} == {
|
||||
"waiver:audti:floors_aligned",
|
||||
"waiver:browser:smoke",
|
||||
}
|
||||
|
||||
|
||||
def test_default_cap_buffer_is_small_and_large_overhang_is_explicit() -> None:
|
||||
pytest.importorskip("shapely")
|
||||
base_floor = {
|
||||
"name": "一层",
|
||||
"z": 0.0,
|
||||
"height": 3.0,
|
||||
"bounds": [0.0, 0.0, 10.0, 10.0],
|
||||
"source_file": "fixture.dxf",
|
||||
"segments": {},
|
||||
"footprint": {"polygons": [[[0, 0], [10, 0], [10, 10], [0, 10]]]},
|
||||
}
|
||||
upper_floor = {**base_floor, "name": "二层", "z": 3.0}
|
||||
floors = {"F1": json.loads(json.dumps(base_floor)), "F2": json.loads(json.dumps(upper_floor))}
|
||||
derive_showcase_spec.compute_caps(floors, {})
|
||||
default_max_x = max(point[0] for polygon in floors["F1"]["caps"][0]["polygons"] for point in polygon)
|
||||
assert default_max_x == pytest.approx(10.1)
|
||||
|
||||
floors = {"F1": json.loads(json.dumps(base_floor)), "F2": json.loads(json.dumps(upper_floor))}
|
||||
derive_showcase_spec.compute_caps(floors, {"cap_buffer": 1.3})
|
||||
colonnade_max_x = max(point[0] for polygon in floors["F1"]["caps"][0]["polygons"] for point in polygon)
|
||||
assert colonnade_max_x == pytest.approx(11.3)
|
||||
|
||||
|
||||
def test_pipeline_fails_on_derive_geometry_loss_warning(tmp_path: Path) -> None:
|
||||
pipeline = cad_showcase.Pipeline(tmp_path / "state.json", "fingerprint", resume=False)
|
||||
command = [
|
||||
@@ -265,6 +383,20 @@ def test_spec_schema_and_backend_group_contract() -> None:
|
||||
assert build_blender_showcase.floor_group("TOWER_A_F3", config) == "A"
|
||||
|
||||
|
||||
def test_normalize_spec_backfills_categories_used_by_legacy_segments() -> None:
|
||||
legacy = minimal_spec()
|
||||
legacy.pop("schema_version")
|
||||
legacy.pop("categories")
|
||||
legacy["floors"]["F1"]["segments"]["legacy_custom"] = [
|
||||
{"start": [0, 0], "end": [0, 1], "width": 0.1, "layer": "OLD", "source_type": "LINE"}
|
||||
]
|
||||
normalized = showcase_schema.normalize_spec(legacy)
|
||||
assert normalized["categories"]["walls"] == {"label": "墙体", "color": "#d4cbb8"}
|
||||
assert normalized["categories"]["slab"] == {"label": "楼板", "color": "#c8ccc2"}
|
||||
assert normalized["categories"]["legacy_custom"] == {"label": "legacy_custom", "color": "#8c9088"}
|
||||
showcase_schema.validate_spec(normalized)
|
||||
|
||||
|
||||
def test_spec_rejects_segment_category_without_metadata() -> None:
|
||||
spec = minimal_spec()
|
||||
spec["floors"]["F1"]["segments"]["unregistered"] = [
|
||||
|
||||
@@ -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 "<Tower & Co></script>" in text
|
||||
assert "<unsafe & subtitle>" 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)
|
||||
|
||||
Reference in New Issue
Block a user