fix: close audited CAD delivery gate gaps
This commit is contained in:
@@ -508,7 +508,7 @@ def evaluate_gates(
|
||||
]
|
||||
glazing_evidence = locked_glazing_meters >= GATE_GLAZING_MIN_METERS or bool(glazing_named_blocks)
|
||||
if not glazing_evidence:
|
||||
status, detail = "SKIP", "No curtain-wall/glazing evidence in blocks or block names."
|
||||
status, detail = "NOT_APPLICABLE", "No curtain-wall/glazing evidence in blocks or block names."
|
||||
elif spec_glazing_segments > 0:
|
||||
status = "PASS"
|
||||
detail = (
|
||||
@@ -532,7 +532,7 @@ def evaluate_gates(
|
||||
gates.append(
|
||||
{
|
||||
"name": "no_annotation_layers_classified",
|
||||
"status": "FAIL" if annotation_classified else "PASS",
|
||||
"status": "WARN" if annotation_classified else "PASS",
|
||||
"detail": (
|
||||
f"Annotation/identification layers classified as geometry: {', '.join(annotation_classified[:5])}. "
|
||||
"These are tags, not elements; exclude them."
|
||||
@@ -595,7 +595,11 @@ def frame_ledger_gate(config: dict[str, Any], frames: list[dict[str, Any]] | Non
|
||||
`"discarded_frames": [{"name": ..., "reason": ...}]`.
|
||||
"""
|
||||
if not frames:
|
||||
return {"name": "frame_ledger", "status": "SKIP", "detail": "No --frames given; frame ledger not checked."}
|
||||
return {
|
||||
"name": "frame_ledger",
|
||||
"status": "NOT_APPLICABLE",
|
||||
"detail": "No --frames given; frame ledger is not armed for this project.",
|
||||
}
|
||||
discarded = {str(d.get("name", "")) for d in config.get("discarded_frames", [])}
|
||||
cfg_by_file: dict[str, list[dict[str, Any]]] = {}
|
||||
for drawing in config.get("drawings", []) or []:
|
||||
@@ -645,8 +649,8 @@ def declared_area_gate(spec: dict[str, Any], config: dict[str, Any]) -> dict[str
|
||||
if not declared:
|
||||
return {
|
||||
"name": "area_declared",
|
||||
"status": "SKIP",
|
||||
"detail": "No declared_areas_m2 in config; area cross-check not requested.",
|
||||
"status": "NOT_APPLICABLE",
|
||||
"detail": "No declared_areas_m2 in config; area cross-check is not armed.",
|
||||
}
|
||||
tol = float(config.get("declared_area_tolerance", 0.15))
|
||||
problems = []
|
||||
@@ -723,7 +727,7 @@ def vertical_storey_continuity_gate(spec: dict[str, Any]) -> dict[str, Any]:
|
||||
parts.append("unexplained elevation gaps " + ", ".join(z_gaps))
|
||||
return {
|
||||
"name": "vertical_storey_continuity",
|
||||
"status": "FAIL",
|
||||
"status": "WARN",
|
||||
"detail": (
|
||||
"; ".join(parts)
|
||||
+ ". Instantiate source-supported repeated typical floors; do not deliver separated floor islands."
|
||||
@@ -746,8 +750,8 @@ def storey_count_gate(spec: dict[str, Any], config: dict[str, Any]) -> dict[str,
|
||||
if expected is None:
|
||||
return {
|
||||
"name": "storey_count",
|
||||
"status": "SKIP",
|
||||
"detail": "No expected_storeys_above_ground in config; count cross-check not requested.",
|
||||
"status": "NOT_APPLICABLE",
|
||||
"detail": "No expected_storeys_above_ground in config; count cross-check is not armed.",
|
||||
}
|
||||
import re as _re
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import argparse
|
||||
import hashlib
|
||||
import importlib.metadata
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
@@ -30,16 +31,31 @@ def now() -> str:
|
||||
return datetime.now(timezone.utc).isoformat()
|
||||
|
||||
|
||||
def fingerprint(config: Path, source_report: Path, dxf_dir: Path) -> str:
|
||||
DERIVE_FORBIDDEN_WARNINGS = (
|
||||
"WARNING isolated_cluster",
|
||||
"WARNING unsupported_roof",
|
||||
"WARNING floor_order",
|
||||
"WARNING topless_group",
|
||||
)
|
||||
|
||||
|
||||
def fingerprint(
|
||||
config: Path,
|
||||
source_report: Path,
|
||||
dxf_dir: Path,
|
||||
extra_inputs: tuple[Path, ...] = (),
|
||||
) -> str:
|
||||
"""Hash source data and pipeline code so resume cannot reuse stale work."""
|
||||
digest = hashlib.sha256()
|
||||
tracked = [config, source_report, *sorted(dxf_dir.glob("*.dxf"))]
|
||||
tracked = [config, source_report, *extra_inputs, *sorted(dxf_dir.glob("*.dxf"))]
|
||||
tracked.extend(sorted(SCRIPTS.glob("*.py")))
|
||||
tracked.extend(sorted(SCRIPTS.glob("*.mjs")))
|
||||
tracked.extend(sorted((ROOT / "schemas").glob("*.json")))
|
||||
tracked.extend(sorted((ROOT / "assets" / "web-showcase-template").glob("*")))
|
||||
tracked.extend(sorted(path for path in (ROOT / "tools").rglob("*") if path.is_file()))
|
||||
tracked.extend(sorted(path for path in (ROOT / "assets" / "web-showcase-template").rglob("*") if path.is_file()))
|
||||
tracked.extend(sorted(path for path in (ROOT / "assets" / "offline-viewer-libs").rglob("*") if path.is_file()))
|
||||
tracked.extend(path for path in (ROOT / "package.json", ROOT / "package-lock.json") if path.exists())
|
||||
for path in tracked:
|
||||
for path in sorted(set(tracked), key=lambda item: str(item)):
|
||||
if not path.is_file():
|
||||
continue
|
||||
digest.update(str(path.relative_to(ROOT) if path.is_relative_to(ROOT) else path).encode("utf-8"))
|
||||
@@ -64,11 +80,22 @@ class Pipeline:
|
||||
if state_path.exists():
|
||||
try:
|
||||
current = json.loads(state_path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
current = {}
|
||||
except Exception as exc:
|
||||
raise SystemExit(f"Pipeline state is corrupt and was not overwritten: {state_path}: {exc}") from exc
|
||||
else:
|
||||
current = {}
|
||||
if current.get("input_fingerprint") != input_fingerprint:
|
||||
if resume and current:
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "INVALIDATED",
|
||||
"reason": "input fingerprint changed",
|
||||
"state": str(state_path),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
current = {}
|
||||
self.state: dict[str, Any] = {
|
||||
"state_version": 1,
|
||||
@@ -82,7 +109,15 @@ class Pipeline:
|
||||
def save(self) -> None:
|
||||
self.state["updated_at"] = now()
|
||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.path.write_text(json.dumps(self.state, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
temporary = self.path.with_name(f".{self.path.name}.{os.getpid()}.tmp")
|
||||
try:
|
||||
with temporary.open("w", encoding="utf-8") as stream:
|
||||
json.dump(self.state, stream, ensure_ascii=False, indent=2)
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
os.replace(temporary, self.path)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
|
||||
def run(
|
||||
self,
|
||||
@@ -137,6 +172,26 @@ def python_script(name: str, *args: str) -> list[str]:
|
||||
return [sys.executable, str(SCRIPTS / name), *args]
|
||||
|
||||
|
||||
def resolve_executable(name: str) -> str:
|
||||
"""Resolve command shims portably (notably npm.cmd on Windows)."""
|
||||
candidates = [name]
|
||||
if sys.platform == "win32":
|
||||
candidates = [f"{name}.cmd", f"{name}.exe", name]
|
||||
for candidate in candidates:
|
||||
found = shutil.which(candidate)
|
||||
if found:
|
||||
return found
|
||||
raise SystemExit(f"Required executable not found on PATH: {name}")
|
||||
|
||||
|
||||
def npm_command(*args: str) -> list[str]:
|
||||
return [resolve_executable("npm"), *args]
|
||||
|
||||
|
||||
def node_script(path: Path, *args: str) -> list[str]:
|
||||
return [resolve_executable("node"), str(path), *args]
|
||||
|
||||
|
||||
def parse_waivers(values: list[str]) -> dict[str, str]:
|
||||
waivers: dict[str, str] = {}
|
||||
for value in values:
|
||||
@@ -157,7 +212,7 @@ def enforce_audit_gates(pipeline: Pipeline, audit_path: Path, waivers: dict[str,
|
||||
waived = []
|
||||
for gate in report.get("gates", []):
|
||||
status = str(gate.get("status", "FAIL"))
|
||||
if status == "PASS":
|
||||
if status in {"PASS", "NOT_APPLICABLE"}:
|
||||
continue
|
||||
name = f"audit:{gate.get('name', 'unnamed')}"
|
||||
if status in {"WARN", "SKIP"} and name in waivers:
|
||||
@@ -196,21 +251,25 @@ def wait_for_http(url: str, timeout: float = 20.0) -> None:
|
||||
raise RuntimeError(f"Local Web server did not become ready: {last_error}")
|
||||
|
||||
|
||||
def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screenshots: Path) -> None:
|
||||
"""Serve the formal Web bundle and mechanically prove desktop/mobile loading."""
|
||||
def ensure_node_runtime(pipeline: Pipeline, *, browser: bool) -> None:
|
||||
pipeline.run(
|
||||
"node_dependencies",
|
||||
["npm", "install", "--prefix", str(ROOT), "--ignore-scripts"],
|
||||
npm_command("install", "--prefix", str(ROOT), "--ignore-scripts"),
|
||||
[
|
||||
ROOT / "node_modules" / "playwright" / "package.json",
|
||||
ROOT / "node_modules" / "@gltf-transform" / "core" / "package.json",
|
||||
],
|
||||
)
|
||||
pipeline.run(
|
||||
"browser_runtime",
|
||||
[str(ROOT / "node_modules" / ".bin" / "playwright"), "install", "chromium"],
|
||||
[],
|
||||
)
|
||||
if browser:
|
||||
pipeline.run(
|
||||
"browser_runtime",
|
||||
node_script(ROOT / "node_modules" / "playwright" / "cli.js", "install", "chromium"),
|
||||
[],
|
||||
)
|
||||
|
||||
|
||||
def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screenshots: Path) -> None:
|
||||
"""Serve the formal Web bundle and mechanically prove desktop/mobile loading."""
|
||||
report.parent.mkdir(parents=True, exist_ok=True)
|
||||
port = available_port()
|
||||
url = f"http://127.0.0.1:{port}/"
|
||||
@@ -233,16 +292,15 @@ def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screensho
|
||||
wait_for_http(url)
|
||||
pipeline.run(
|
||||
"browser_smoke",
|
||||
[
|
||||
"node",
|
||||
str(SCRIPTS / "web_smoke_test.mjs"),
|
||||
node_script(
|
||||
SCRIPTS / "web_smoke_test.mjs",
|
||||
"--url",
|
||||
url,
|
||||
"--out",
|
||||
str(report),
|
||||
"--screenshots-dir",
|
||||
str(screenshots),
|
||||
],
|
||||
),
|
||||
[report, screenshots],
|
||||
)
|
||||
finally:
|
||||
@@ -258,16 +316,15 @@ def run_offline_browser_smoke(pipeline: Pipeline, viewer: Path, report: Path, sc
|
||||
"""Open the single-file viewer through file:// and prove that its model renders."""
|
||||
pipeline.run(
|
||||
"offline_browser_smoke",
|
||||
[
|
||||
"node",
|
||||
str(SCRIPTS / "offline_viewer_smoke.mjs"),
|
||||
node_script(
|
||||
SCRIPTS / "offline_viewer_smoke.mjs",
|
||||
"--viewer",
|
||||
str(viewer),
|
||||
"--out",
|
||||
str(report),
|
||||
"--screenshot",
|
||||
str(screenshot),
|
||||
],
|
||||
),
|
||||
[report, screenshot],
|
||||
)
|
||||
|
||||
@@ -284,7 +341,10 @@ def doctor() -> int:
|
||||
checks.append({"name": module, "status": "FAIL", "detail": str(exc)})
|
||||
failed = True
|
||||
for executable in ("node", "npm", "dwg2dxf"):
|
||||
path = shutil.which(executable)
|
||||
try:
|
||||
path = resolve_executable(executable)
|
||||
except SystemExit:
|
||||
path = None
|
||||
checks.append({"name": executable, "status": "PASS" if path else "OPTIONAL", "path": path})
|
||||
for executable, resolver in (("ODAFileConverter", oda_converter), ("blender", default_blender)):
|
||||
candidate = resolver()
|
||||
@@ -308,6 +368,10 @@ def inspect_command(args: argparse.Namespace) -> int:
|
||||
"--converter",
|
||||
args.converter,
|
||||
)
|
||||
if args.allow_partial:
|
||||
command.extend(["--allow-partial", "--partial-reason", args.partial_reason])
|
||||
if args.no_convert:
|
||||
command.append("--no-convert")
|
||||
return subprocess.run(command, cwd=ROOT).returncode
|
||||
|
||||
|
||||
@@ -337,7 +401,7 @@ def build_with_trimesh(pipeline: Pipeline, bundle: Path) -> list[Path]:
|
||||
)
|
||||
pipeline.run(
|
||||
f"compress_{key}",
|
||||
["node", str(ROOT / "tools" / "compress.mjs"), str(raw_glb), str(glb)],
|
||||
node_script(ROOT / "tools" / "compress.mjs", str(raw_glb), str(glb)),
|
||||
[glb],
|
||||
)
|
||||
glbs.append(glb)
|
||||
@@ -348,20 +412,40 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
dxf_dir = Path(args.dxf_dir).resolve()
|
||||
config = Path(args.config).resolve()
|
||||
source_report = Path(args.source_report).resolve()
|
||||
scope_manifest = Path(args.scope_manifest).resolve()
|
||||
frame_inputs = tuple(Path(path).resolve() for path in args.frames)
|
||||
try:
|
||||
waivers = parse_waivers(args.waiver)
|
||||
except ValueError as exc:
|
||||
print(f"GATE FAIL [waiver]: {exc}", file=sys.stderr)
|
||||
return 3
|
||||
try:
|
||||
report = json.loads(source_report.read_text(encoding="utf-8"))
|
||||
showcase_schema.validate_source_report(report, dxf_dir)
|
||||
except (OSError, json.JSONDecodeError, showcase_schema.ValidationFailure) as exc:
|
||||
print(f"GATE FAIL [source_report]: {exc}", file=sys.stderr)
|
||||
return 3
|
||||
source_status = str((report.get("gate") or {}).get("status", "FAIL"))
|
||||
if source_status == "WARN" and "cad_source_report" not in waivers:
|
||||
print(
|
||||
"GATE BLOCKED [cad_source_report]: partial source report requires "
|
||||
"--waiver 'cad_source_report=<user-approved reason>'",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 3
|
||||
out_dir = Path(args.out_dir).resolve()
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
waivers = parse_waivers(args.waiver)
|
||||
except ValueError as exc:
|
||||
print(f"GATE FAIL [waiver]: {exc}", file=sys.stderr)
|
||||
return 3
|
||||
pipeline = Pipeline(out_dir / "pipeline_state.json", fingerprint(config, source_report, dxf_dir), args.resume)
|
||||
pipeline = Pipeline(
|
||||
out_dir / "pipeline_state.json",
|
||||
fingerprint(config, source_report, dxf_dir, (scope_manifest, *frame_inputs)),
|
||||
args.resume,
|
||||
)
|
||||
if source_status == "WARN":
|
||||
pipeline.state["source_waiver"] = {
|
||||
"check": "cad_source_report",
|
||||
"reason": waivers["cad_source_report"],
|
||||
}
|
||||
pipeline.save()
|
||||
spec = out_dir / "building_spec.json"
|
||||
audit = out_dir / "extraction_audit.json"
|
||||
audit_md = out_dir / "extraction_audit.md"
|
||||
@@ -380,7 +464,7 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
args.vendor_dir,
|
||||
),
|
||||
[spec],
|
||||
forbidden_stderr=("WARNING topless_group",),
|
||||
forbidden_stderr=DERIVE_FORBIDDEN_WARNINGS,
|
||||
)
|
||||
audit_cmd = python_script(
|
||||
"audit_showcase_extraction.py",
|
||||
@@ -434,15 +518,9 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
if args.blender:
|
||||
variant_cmd.extend(["--blender", args.blender])
|
||||
pipeline.run("variants", variant_cmd, [manifest, bundle / "variant_specs" / "standard.json"])
|
||||
if args.backend == "trimesh" or args.web or args.offline:
|
||||
ensure_node_runtime(pipeline, browser=args.web or args.offline)
|
||||
if args.backend == "trimesh":
|
||||
pipeline.run(
|
||||
"node_dependencies",
|
||||
["npm", "install", "--prefix", str(ROOT), "--ignore-scripts"],
|
||||
[
|
||||
ROOT / "node_modules" / "playwright" / "package.json",
|
||||
ROOT / "node_modules" / "@gltf-transform" / "core" / "package.json",
|
||||
],
|
||||
)
|
||||
glbs = build_with_trimesh(pipeline, bundle)
|
||||
else:
|
||||
glbs = [bundle / "variants" / key / f"{key}.glb" for key in ("overview", "standard", "detail")]
|
||||
@@ -465,7 +543,7 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
if not args.skip_web_deps:
|
||||
pipeline.run(
|
||||
"web_dependencies",
|
||||
["npm", "install", "--prefix", str(web_dir), "--ignore-scripts"],
|
||||
npm_command("install", "--prefix", str(web_dir), "--ignore-scripts"),
|
||||
[web_dir / "node_modules" / "three" / "build" / "three.module.js"],
|
||||
)
|
||||
browser_report = (
|
||||
@@ -495,17 +573,6 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
),
|
||||
[offline],
|
||||
)
|
||||
if not args.web:
|
||||
pipeline.run(
|
||||
"offline_node_dependencies",
|
||||
["npm", "install", "--prefix", str(ROOT), "--ignore-scripts"],
|
||||
[ROOT / "node_modules" / "playwright" / "package.json"],
|
||||
)
|
||||
pipeline.run(
|
||||
"offline_browser_runtime",
|
||||
[str(ROOT / "node_modules" / ".bin" / "playwright"), "install", "chromium"],
|
||||
[],
|
||||
)
|
||||
run_offline_browser_smoke(
|
||||
pipeline,
|
||||
offline,
|
||||
@@ -543,10 +610,14 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
str(preview),
|
||||
"--audit",
|
||||
str(audit),
|
||||
"--require-audit",
|
||||
"--budget-mb",
|
||||
str(args.budget_mb),
|
||||
"--evidence-out",
|
||||
str(evidence),
|
||||
"--scope-manifest",
|
||||
str(scope_manifest),
|
||||
"--require-scope-manifest",
|
||||
)
|
||||
if args.web:
|
||||
verify_cmd.extend(
|
||||
@@ -563,8 +634,6 @@ def run_pipeline(args: argparse.Namespace) -> int:
|
||||
)
|
||||
if args.require_browser_report and not args.web:
|
||||
verify_cmd.append("--require-browser-report")
|
||||
if args.scope_manifest:
|
||||
verify_cmd.extend(["--scope-manifest", str(Path(args.scope_manifest).resolve())])
|
||||
for value in args.waiver:
|
||||
verify_cmd.extend(["--waiver", value])
|
||||
pipeline.run("delivery_verification", verify_cmd, [evidence])
|
||||
@@ -591,6 +660,9 @@ def parser() -> argparse.ArgumentParser:
|
||||
inspect.add_argument("--output", required=True)
|
||||
inspect.add_argument("--vendor-dir", default="work/vendor")
|
||||
inspect.add_argument("--converter", choices=("auto", "libredwg", "oda"), default="auto")
|
||||
inspect.add_argument("--no-convert", action="store_true")
|
||||
inspect.add_argument("--allow-partial", action="store_true")
|
||||
inspect.add_argument("--partial-reason", default="")
|
||||
run = sub.add_parser("run", help="Run extract -> audit -> overlays -> variants -> verify from an approved config")
|
||||
run.add_argument("--dxf-dir", required=True)
|
||||
run.add_argument("--config", required=True)
|
||||
|
||||
@@ -200,12 +200,18 @@ def validate_source_report(report: dict[str, Any], expected_dxf_dir: Path | None
|
||||
gate = report.get("gate") or {}
|
||||
if not isinstance(gate, dict):
|
||||
gate = {}
|
||||
if gate.get("name") != "all_sources_converted_and_readable" or gate.get("status") != "PASS":
|
||||
errors.append(f"gate: all_sources_converted_and_readable must be PASS, got {gate.get('status')!r}")
|
||||
gate_status = gate.get("status")
|
||||
if gate.get("name") != "all_sources_converted_and_readable" or gate_status not in {"PASS", "WARN"}:
|
||||
errors.append(
|
||||
f"gate: all_sources_converted_and_readable must be PASS or a reasoned partial WARN, got {gate_status!r}"
|
||||
)
|
||||
if gate_status == "WARN" and not str(gate.get("partial_reason", "")).strip():
|
||||
errors.append("gate.partial_reason: WARN source reports require a non-empty partial reason")
|
||||
files = report.get("files")
|
||||
if not isinstance(files, list) or not files:
|
||||
errors.append("files: report contains no inspected DXF files")
|
||||
else:
|
||||
readable = 0
|
||||
for index, item in enumerate(files):
|
||||
if not isinstance(item, dict):
|
||||
errors.append(f"files[{index}]: expected an object")
|
||||
@@ -214,11 +220,15 @@ def validate_source_report(report: dict[str, Any], expected_dxf_dir: Path | None
|
||||
entity_count = int(item.get("modelspace_entities", 0) or 0)
|
||||
except (TypeError, ValueError):
|
||||
entity_count = 0
|
||||
if item.get("status") != "ok" or entity_count <= 0:
|
||||
if item.get("status") == "ok" and entity_count > 0:
|
||||
readable += 1
|
||||
elif gate_status == "PASS":
|
||||
errors.append(
|
||||
f"files[{index}]: {item.get('file', '?')} is not readable and nonempty "
|
||||
f"(status={item.get('status')!r}, entities={item.get('modelspace_entities')!r})"
|
||||
)
|
||||
if readable == 0:
|
||||
errors.append("files: partial reports still require at least one readable nonempty DXF")
|
||||
if expected_dxf_dir is not None:
|
||||
reported = Path(str(report.get("dxf_sanitized", "")))
|
||||
if not reported.is_absolute():
|
||||
|
||||
@@ -9,6 +9,7 @@ import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import statistics
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
@@ -123,14 +124,57 @@ def inspect_render(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
from PIL import Image, ImageStat
|
||||
|
||||
image = Image.open(path).convert("RGB")
|
||||
stat = ImageStat.Stat(image.resize((128, 128)))
|
||||
sample = image.resize((128, 128))
|
||||
stat = ImageStat.Stat(sample)
|
||||
spread = max(stat.var)
|
||||
status = "PASS" if image.width >= 320 and image.height >= 240 and spread > 2.0 else "FAIL"
|
||||
pixels = list(sample.getdata())
|
||||
border = []
|
||||
for index in range(128):
|
||||
border.extend((sample.getpixel((index, 0)), sample.getpixel((index, 127))))
|
||||
for index in range(1, 127):
|
||||
border.extend((sample.getpixel((0, index)), sample.getpixel((127, index))))
|
||||
background = tuple(int(statistics.median(pixel[channel] for pixel in border)) for channel in range(3))
|
||||
foreground = [max(abs(pixel[channel] - background[channel]) for channel in range(3)) > 12 for pixel in pixels]
|
||||
occupancy = sum(foreground) / len(foreground)
|
||||
xs = [index % 128 for index, present in enumerate(foreground) if present]
|
||||
ys = [index // 128 for index, present in enumerate(foreground) if present]
|
||||
bbox_w = max(xs) - min(xs) + 1 if xs else 0
|
||||
bbox_h = max(ys) - min(ys) + 1 if ys else 0
|
||||
|
||||
def luminance(pixel: tuple[int, int, int]) -> float:
|
||||
return pixel[0] * 0.2126 + pixel[1] * 0.7152 + pixel[2] * 0.0722
|
||||
|
||||
transitions = 0
|
||||
comparisons = 0
|
||||
for y in range(128):
|
||||
for x in range(128):
|
||||
here = luminance(sample.getpixel((x, y)))
|
||||
if x + 1 < 128:
|
||||
transitions += abs(here - luminance(sample.getpixel((x + 1, y)))) > 45
|
||||
comparisons += 1
|
||||
if y + 1 < 128:
|
||||
transitions += abs(here - luminance(sample.getpixel((x, y + 1)))) > 45
|
||||
comparisons += 1
|
||||
edge_ratio = transitions / comparisons
|
||||
status = (
|
||||
"PASS"
|
||||
if image.width >= 320
|
||||
and image.height >= 240
|
||||
and spread > 2.0
|
||||
and 0.01 <= occupancy <= 0.95
|
||||
and bbox_w >= 24
|
||||
and bbox_h >= 24
|
||||
and edge_ratio < 0.45
|
||||
else "FAIL"
|
||||
)
|
||||
add_check(
|
||||
checks,
|
||||
f"render:{path.name}",
|
||||
status,
|
||||
f"{image.width}x{image.height}, max channel variance {spread:.2f}",
|
||||
(
|
||||
f"{image.width}x{image.height}, variance {spread:.2f}, "
|
||||
f"foreground {occupancy:.1%}, bbox {bbox_w}x{bbox_h}/128, edge ratio {edge_ratio:.3f}"
|
||||
),
|
||||
)
|
||||
except Exception as exc:
|
||||
add_check(checks, f"render:{path.name}", "FAIL", f"Image inspection failed: {exc}")
|
||||
@@ -201,16 +245,73 @@ def inspect_offline(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
add_check(checks, "offline:payload", "FAIL", f"Embedded payload decode failed: {exc}")
|
||||
|
||||
|
||||
WEB_BROWSER_CHECKS = {
|
||||
"desktop:viewport",
|
||||
"desktop:#floor-controls",
|
||||
"desktop:#category-controls",
|
||||
"desktop:#explode",
|
||||
"desktop:#section",
|
||||
"desktop:#snapshot",
|
||||
"desktop:idle-render",
|
||||
"mobile:viewport",
|
||||
"mobile:#floor-controls",
|
||||
"mobile:#category-controls",
|
||||
"mobile:#explode",
|
||||
"mobile:#section",
|
||||
"mobile:#snapshot",
|
||||
"mobile:idle-render",
|
||||
}
|
||||
OFFLINE_BROWSER_CHECKS = {
|
||||
"offline:viewport",
|
||||
"offline:model-ready",
|
||||
"offline:canvas",
|
||||
"offline:render",
|
||||
}
|
||||
|
||||
|
||||
def inspect_browser_report(path: Path, checks: list[dict[str, Any]], name: str = "browser:smoke") -> None:
|
||||
try:
|
||||
report = json.loads(path.read_text(encoding="utf-8"))
|
||||
report_checks = report.get("checks")
|
||||
if not isinstance(report_checks, list) or not report_checks:
|
||||
raise ValueError("checks must be a non-empty list")
|
||||
by_name: dict[str, dict[str, Any]] = {}
|
||||
for item in report_checks:
|
||||
if not isinstance(item, dict) or not isinstance(item.get("name"), str):
|
||||
raise ValueError("every browser check must be an object with a name")
|
||||
if item["name"] in by_name:
|
||||
raise ValueError(f"duplicate browser check: {item['name']}")
|
||||
by_name[item["name"]] = item
|
||||
required = OFFLINE_BROWSER_CHECKS if name == "offline:browser-smoke" else WEB_BROWSER_CHECKS
|
||||
missing = sorted(required - set(by_name))
|
||||
failed = sorted(item_name for item_name, item in by_name.items() if item.get("status") != "PASS")
|
||||
if missing:
|
||||
raise ValueError("missing required checks: " + ", ".join(missing))
|
||||
if failed:
|
||||
raise ValueError("non-PASS checks: " + ", ".join(failed))
|
||||
expected_viewports = (
|
||||
{"offline:viewport": "1440x900 expected 1440x900"}
|
||||
if name == "offline:browser-smoke"
|
||||
else {
|
||||
"desktop:viewport": "1440x900 expected 1440x900",
|
||||
"mobile:viewport": "390x844 expected 390x844",
|
||||
}
|
||||
)
|
||||
for check_name, expected_detail in expected_viewports.items():
|
||||
if by_name[check_name].get("detail") != expected_detail:
|
||||
raise ValueError(f"{check_name} has untrusted viewport evidence: {by_name[check_name].get('detail')!r}")
|
||||
for error_key in ("console_errors", "page_errors", "failed_requests"):
|
||||
if not isinstance(report.get(error_key), list):
|
||||
raise ValueError(f"{error_key} must be a list")
|
||||
passed = (
|
||||
report.get("status") == "PASS"
|
||||
and not report.get("console_errors")
|
||||
and not report.get("page_errors")
|
||||
and not report.get("failed_requests")
|
||||
)
|
||||
detail = report.get("detail") or json.dumps(report, ensure_ascii=False)[:500]
|
||||
detail = f"validated {len(required)}/{len(required)} required checks; " + (
|
||||
report.get("detail") or json.dumps(report, ensure_ascii=False)[:300]
|
||||
)
|
||||
add_check(checks, name, "PASS" if passed else "FAIL", detail)
|
||||
except Exception as exc:
|
||||
add_check(checks, name, "FAIL", f"Browser report invalid: {exc}")
|
||||
@@ -224,7 +325,7 @@ def inspect_audit(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
raise ValueError("audit has no gates")
|
||||
for gate in gates:
|
||||
status = str(gate.get("status", "FAIL"))
|
||||
if status not in {"PASS", "WARN", "SKIP", "FAIL"}:
|
||||
if status not in {"PASS", "WARN", "SKIP", "FAIL", "NOT_APPLICABLE"}:
|
||||
status = "FAIL"
|
||||
add_check(
|
||||
checks,
|
||||
@@ -236,6 +337,47 @@ def inspect_audit(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
add_check(checks, "audit:report", "FAIL", f"Extraction audit invalid: {exc}")
|
||||
|
||||
|
||||
def verifiable_model_artifact(path: Path) -> tuple[bool, str]:
|
||||
"""Reject scope ledgers backed only by arbitrary non-empty files."""
|
||||
try:
|
||||
suffix = path.suffix.lower()
|
||||
if suffix == ".glb":
|
||||
from pygltflib import GLTF2
|
||||
|
||||
model = GLTF2().load(str(path))
|
||||
primitives = sum(len(mesh.primitives) for mesh in model.meshes or [])
|
||||
if primitives <= 0:
|
||||
return False, "GLB has no mesh primitives"
|
||||
return True, f"GLB with {primitives} primitive(s)"
|
||||
if suffix == ".blend":
|
||||
if path.read_bytes()[:7] != b"BLENDER":
|
||||
return False, "invalid Blender header"
|
||||
return True, "Blender scene"
|
||||
if suffix == ".json":
|
||||
document = json.loads(path.read_text(encoding="utf-8"))
|
||||
showcase_schema.validate_spec(document)
|
||||
return True, f"building spec with {len(document['floors'])} floor(s)"
|
||||
return False, f"unsupported model artifact type {suffix or '<none>'}"
|
||||
except Exception as exc:
|
||||
return False, str(exc)
|
||||
|
||||
|
||||
def verifiable_site_artifact(path: Path) -> tuple[bool, str]:
|
||||
model_ok, model_detail = verifiable_model_artifact(path)
|
||||
if model_ok:
|
||||
return True, model_detail
|
||||
try:
|
||||
from PIL import Image
|
||||
|
||||
with Image.open(path) as image:
|
||||
image.verify()
|
||||
if image.width < 320 or image.height < 240:
|
||||
return False, f"site image too small: {image.width}x{image.height}"
|
||||
return True, f"site image {image.width}x{image.height}"
|
||||
except Exception:
|
||||
return False, model_detail
|
||||
|
||||
|
||||
def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
"""Validate a single-building/campus scope ledger against real artifacts."""
|
||||
try:
|
||||
@@ -255,6 +397,8 @@ def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
raise ValueError("requested must be a non-empty list of building IDs")
|
||||
if len(set(requested)) != len(requested):
|
||||
raise ValueError("requested contains duplicate building IDs")
|
||||
if mode == "single" and len(requested) != 1:
|
||||
raise ValueError("single mode requires exactly one requested building ID")
|
||||
if not isinstance(buildings, list):
|
||||
raise ValueError("buildings must be a list")
|
||||
by_id: dict[str, dict[str, Any]] = {}
|
||||
@@ -264,9 +408,17 @@ def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
raise ValueError(f"missing or duplicate building id: {building_id!r}")
|
||||
by_id[building_id] = item
|
||||
missing = [item for item in requested if item not in by_id]
|
||||
if missing:
|
||||
unexpected = sorted(set(by_id) - set(requested))
|
||||
if missing or unexpected:
|
||||
add_check(
|
||||
checks, "scope:inventory", "FAIL", "Requested buildings missing from ledger: " + ", ".join(missing)
|
||||
checks,
|
||||
"scope:inventory",
|
||||
"FAIL",
|
||||
(
|
||||
("Requested buildings missing from ledger: " + ", ".join(missing) if missing else "")
|
||||
+ ("; " if missing and unexpected else "")
|
||||
+ ("Unrequested buildings in ledger: " + ", ".join(unexpected) if unexpected else "")
|
||||
),
|
||||
)
|
||||
else:
|
||||
add_check(
|
||||
@@ -295,19 +447,32 @@ def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
add_check(checks, f"scope:building:{building_id}", "FAIL", "PASS building has no artifacts")
|
||||
continue
|
||||
missing_artifacts = []
|
||||
verified_models = []
|
||||
invalid_models = []
|
||||
for artifact in artifacts:
|
||||
artifact_path = Path(str(artifact))
|
||||
if not artifact_path.is_absolute():
|
||||
artifact_path = path.parent / artifact_path
|
||||
if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0):
|
||||
missing_artifacts.append(str(artifact))
|
||||
continue
|
||||
verified, detail = verifiable_model_artifact(artifact_path)
|
||||
if verified:
|
||||
verified_models.append(f"{artifact}: {detail}")
|
||||
else:
|
||||
invalid_models.append(f"{artifact}: {detail}")
|
||||
failed = bool(missing_artifacts or not verified_models)
|
||||
add_check(
|
||||
checks,
|
||||
f"scope:building:{building_id}",
|
||||
"FAIL" if missing_artifacts else "PASS",
|
||||
"FAIL" if failed else "PASS",
|
||||
"Missing artifacts: " + ", ".join(missing_artifacts)
|
||||
if missing_artifacts
|
||||
else f"{len(artifacts)} declared artifact(s) exist",
|
||||
else (
|
||||
f"{len(verified_models)} verifiable model artifact(s)"
|
||||
if verified_models
|
||||
else "No verifiable GLB/BLEND/building-spec artifact; rejected: " + "; ".join(invalid_models)
|
||||
),
|
||||
)
|
||||
|
||||
site = scope.get("site", {})
|
||||
@@ -321,23 +486,32 @@ def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
|
||||
else:
|
||||
artifacts = site.get("artifacts", [])
|
||||
missing_site = []
|
||||
verified_site = []
|
||||
for artifact in artifacts if isinstance(artifacts, list) else []:
|
||||
artifact_path = Path(str(artifact))
|
||||
if not artifact_path.is_absolute():
|
||||
artifact_path = path.parent / artifact_path
|
||||
if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0):
|
||||
missing_site.append(str(artifact))
|
||||
if not artifacts or missing_site:
|
||||
continue
|
||||
verified, detail = verifiable_site_artifact(artifact_path)
|
||||
if verified:
|
||||
verified_site.append(f"{artifact}: {detail}")
|
||||
if not artifacts or missing_site or not verified_site:
|
||||
add_check(
|
||||
checks,
|
||||
"scope:site",
|
||||
"FAIL",
|
||||
"Campus site has no artifacts"
|
||||
if not artifacts
|
||||
else "Missing site artifacts: " + ", ".join(missing_site),
|
||||
else (
|
||||
"Missing site artifacts: " + ", ".join(missing_site)
|
||||
if missing_site
|
||||
else "Campus site has no verifiable model or image artifact"
|
||||
),
|
||||
)
|
||||
else:
|
||||
add_check(checks, "scope:site", "PASS", f"{len(artifacts)} site artifact(s) exist")
|
||||
add_check(checks, "scope:site", "PASS", f"{len(verified_site)} verified site artifact(s)")
|
||||
except Exception as exc:
|
||||
add_check(checks, "scope:manifest", "FAIL", f"Scope manifest invalid: {exc}")
|
||||
|
||||
@@ -353,7 +527,9 @@ def main() -> int:
|
||||
parser.add_argument("--offline-browser-report")
|
||||
parser.add_argument("--render", nargs="*", default=[])
|
||||
parser.add_argument("--audit")
|
||||
parser.add_argument("--require-audit", action="store_true")
|
||||
parser.add_argument("--scope-manifest")
|
||||
parser.add_argument("--require-scope-manifest", action="store_true")
|
||||
parser.add_argument("--browser-report")
|
||||
parser.add_argument("--require-browser-report", action="store_true")
|
||||
parser.add_argument(
|
||||
@@ -377,11 +553,16 @@ def main() -> int:
|
||||
try:
|
||||
source_report = json.loads(Path(args.source_report).read_text(encoding="utf-8"))
|
||||
showcase_schema.validate_source_report(source_report)
|
||||
source_gate = source_report["gate"]
|
||||
source_status = str(source_gate.get("status", "FAIL"))
|
||||
add_check(
|
||||
checks,
|
||||
"cad_source_report",
|
||||
"PASS",
|
||||
f"Source gate PASS; {len(source_report['files'])} readable DXF file(s)",
|
||||
source_status,
|
||||
(
|
||||
f"Source gate {source_status}; {len(source_report['files'])} inspected DXF file(s)"
|
||||
+ (f"; partial reason: {source_gate.get('partial_reason')}" if source_status == "WARN" else "")
|
||||
),
|
||||
)
|
||||
except Exception as exc:
|
||||
add_check(checks, "cad_source_report", "FAIL", str(exc))
|
||||
@@ -440,8 +621,12 @@ def main() -> int:
|
||||
inspect_web(Path(args.web_dir), checks)
|
||||
if args.audit:
|
||||
inspect_audit(Path(args.audit), checks)
|
||||
elif args.require_audit:
|
||||
add_check(checks, "audit:report", "FAIL", "Required extraction audit was not supplied")
|
||||
if args.scope_manifest:
|
||||
inspect_scope(Path(args.scope_manifest), checks)
|
||||
elif args.require_scope_manifest:
|
||||
add_check(checks, "scope:manifest", "FAIL", "Required scope manifest was not supplied")
|
||||
if args.offline_viewer:
|
||||
inspect_offline(Path(args.offline_viewer), checks)
|
||||
if args.offline_browser_report:
|
||||
|
||||
Reference in New Issue
Block a user