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

@@ -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"] = [