fix: close audited CAD delivery gate gaps

This commit is contained in:
2026-07-10 15:58:51 +08:00
parent a761175c09
commit 6c1336fa59
15 changed files with 713 additions and 124 deletions

View File

@@ -30,8 +30,8 @@ git clone ... tools/cad-building-showcase # 克隆到项目内任意位置(
```markdown ```markdown
## CAD → 3D 展示模型 ## CAD → 3D 展示模型
处理 DWG/DXF 转 3D/Web 展示任务时,必须先完整阅读 处理 DWG/DXF 转 3D/Web 展示任务时,必须先完整阅读
tools/cad-building-showcase/SKILL.md 并遵守其中 One-Shot Definition of Done tools/cad-building-showcase/SKILL.md 并遵守其中 Hard Definition of Done:
七条门禁:门禁失败即停下修复,绝不绕过;改动任何脚本后必须跑 门禁失败即停下修复,绝不绕过;改动任何脚本后必须跑
`pytest tools/cad-building-showcase/tests/test_contracts.py tools/cad-building-showcase/tests/test_delivery.py` `pytest tools/cad-building-showcase/tests/test_contracts.py tools/cad-building-showcase/tests/test_delivery.py`
与 `python3 tools/cad-building-showcase/tests/test_extraction_pipeline.py` 且全绿。 与 `python3 tools/cad-building-showcase/tests/test_extraction_pipeline.py` 且全绿。
``` ```

View File

@@ -60,10 +60,11 @@ Read only the branches needed for the current task:
`python3 scripts/cad_showcase.py run --dxf-dir <dxf> --config <config> --source-report <cad_read_report.json> --scope-manifest <scope_manifest.json> --out-dir <out> --name <name> --frames <frames.json> --backend trimesh`. `python3 scripts/cad_showcase.py run --dxf-dir <dxf> --config <config> --source-report <cad_read_report.json> --scope-manifest <scope_manifest.json> --out-dir <out> --name <name> --frames <frames.json> --backend trimesh`.
- Use `--backend blender` when `.blend` and Blender preview are required. - Use `--backend blender` when `.blend` and Blender preview are required.
- Never pass `--no-strict-gates` to proceed toward delivery. - Never pass `--no-strict-gates` to proceed toward delivery.
- Treat audit `WARN` and `SKIP` as `BLOCKED`, not success. Continue only with an explicit `--waiver 'audit:<gate>=<evidence-based reason>'`; retain it in final evidence. - Treat applicable audit `WARN`/`SKIP` as `BLOCKED`, not success. `NOT_APPLICABLE` means the optional check was not armed and is non-blocking. Continue past WARN/SKIP only with an explicit `--waiver 'audit:<gate>=<evidence-based reason>'`; retain it in final evidence.
- A waiver must be explicitly approved by the user. The Agent must not invent one, and must never use one when the user says “no waivers/不要豁免”. - A waiver must be explicitly approved by the user. The Agent must not invent one, and must never use one when the user says “no waivers/不要豁免”.
- Search all source sheets for economic-index tables, storey labels, and elevation ladders before declaring area/storey evidence absent. If a typical plan represents repeated floors, instantiate the source-supported repetitions; a final full-building model may not jump from F2 directly to F16. - Search all source sheets for economic-index tables, storey labels, and elevation ladders before declaring area/storey evidence absent. If a typical plan represents repeated floors, instantiate the source-supported repetitions; a final full-building model may not jump from F2 directly to F16.
- Open the SVG overlays. Iterate if red/unclassified geometry forms walls, glazing, columns, beams, grids, stairs, slabs, roofs, or whole building wings. - Open the SVG overlays. Iterate if red/unclassified geometry forms walls, glazing, columns, beams, grids, stairs, slabs, roofs, or whole building wings.
- Treat every geometry-loss warning from derive (`isolated_cluster`, `unsupported_roof`, `floor_order`, `topless_group`) as a stop condition. Tune the config or restore/model the geometry; do not accept a successful exit code with these warnings.
5. Verify actual deliverables. 5. Verify actual deliverables.
- Require `verify_showcase.py --strict` and `verify_delivery.py` to pass. - Require `verify_showcase.py --strict` and `verify_delivery.py` to pass.
@@ -80,7 +81,7 @@ Read only the branches needed for the current task:
Do not hand over a model unless every applicable item has evidence: Do not hand over a model unless every applicable item has evidence:
1. `cad_read_report.json.gate.status == PASS`; no unresolved conversion/read failure. 1. `cad_read_report.json.gate.status == PASS`; no unresolved conversion/read failure. A reasoned partial `WARN` is usable only with a user-approved `cad_source_report` waiver and must remain visible in evidence.
2. Config and spec pass their versioned JSON Schemas. 2. Config and spec pass their versioned JSON Schemas.
3. Every configured source exists, every floor key is unique, every floor is nonempty, and `floor_order` has no gaps/ghosts. 3. Every configured source exists, every floor key is unique, every floor is nonempty, and `floor_order` has no gaps/ghosts.
4. Multi-frame projects pass `frame_ledger`; every detected plan frame is used or appears in `discarded_frames` with a reason. 4. Multi-frame projects pass `frame_ledger`; every detected plan frame is used or appears in `discarded_frames` with a reason.

View File

@@ -25,14 +25,14 @@ Before modeling, write `scope_manifest.json` from the user request and source in
"mode": "campus", "mode": "campus",
"requested": ["1#", "2#", "3#"], "requested": ["1#", "2#", "3#"],
"buildings": [ "buildings": [
{"id": "1#", "status": "PASS", "artifacts": ["outputs/1/model.glb"]}, {"id": "1#", "status": "PASS", "artifacts": ["../../outputs/1/model.glb"]},
{"id": "2#", "status": "BLOCKED", "reason": "unresolved XREF", "artifacts": []} {"id": "2#", "status": "BLOCKED", "reason": "unresolved XREF", "artifacts": []}
], ],
"site": {"status": "PASS", "artifacts": ["outputs/site_top.png", "outputs/site_manifest.json"]} "site": {"status": "PASS", "artifacts": ["../../outputs/site_top.png", "../../outputs/campus.glb"]}
} }
``` ```
Every `requested` ID must have exactly one ledger entry. `PASS` requires at least one existing non-empty artifact. `BLOCKED` requires a concrete reason and makes the overall campus result `BLOCKED`, not complete. The campus site must likewise be `PASS` with artifacts. Feed the ledger to `cad_showcase.py run --scope-manifest ...` or `verify_delivery.py --scope-manifest ...`. Every `requested` ID must have exactly one ledger entry and there may be no unrequested extras. `PASS` requires at least one verifiable model artifact: a GLB with mesh primitives, a Blender file with a valid header, or a schema-valid `building_spec.json`; an arbitrary non-empty text/JSON file does not satisfy scope. Campus site evidence must include a valid model or readable image. Relative paths resolve from the scope manifest's directory. `BLOCKED` requires a concrete reason and makes the overall campus result `BLOCKED`, not complete. Feed the ledger to `cad_showcase.py run --scope-manifest ...` or `verify_delivery.py --scope-manifest ...`.
## Placement Evidence ## Placement Evidence
@@ -64,6 +64,8 @@ Use `assemble_campus.py` with per-building `rotation_deg` where needed. Require:
- a top-view overlay or render showing each model inside its site outline; - a top-view overlay or render showing each model inside its site outline;
- numeric envelope dimensions and neighbour gaps in the notes/evidence. - numeric envelope dimensions and neighbour gaps in the notes/evidence.
Do not classify a small gap from distance alone. Corroborate a 0.15-0.30m attached-building/expansion-joint interpretation with the neighbour roof shown on the subject building's roof plan and matching floor elevations. A negative gap is always a placement error. A multi-metre hypothesis that pushes either building through the red line is also wrong.
`--allow-overlap` is for a documented shared structure or verified interlocking geometry, not a shortcut around placement bugs. `--allow-overlap` is for a documented shared structure or verified interlocking geometry, not a shortcut around placement bugs.
## Site Context ## Site Context

View File

@@ -28,7 +28,7 @@ Tool discovery is environment variable, PATH, then platform defaults:
- Blender: `BLENDER` -> PATH -> macOS/Windows install defaults. - Blender: `BLENDER` -> PATH -> macOS/Windows install defaults.
- ODA: `ODA_CONVERTER` -> PATH -> macOS/Windows install defaults. - ODA: `ODA_CONVERTER` -> PATH -> macOS/Windows install defaults.
ODA requires existing absolute input/output directories. It may show GUI errors while returning no useful stderr; an exit 0 with no output is still a failure. The script stages ASCII file names and verifies produced files. ODA requires existing absolute input/output directories. On macOS the command shape is `ODAFileConverter <abs_in_dir> <abs_out_dir> ACAD2004 DXF 0 1 "*.dwg"`; create both directories first. Bad arguments are often reported only through a GUI dialog, with empty stderr, and the process may return exit 0 while producing nothing. Treat “exit 0 + no DXF” as failure, check the screen for a blocked dialog, and keep the script's ASCII staging plus produced-file verification.
If native converters are unavailable, use the tested WASM bridge: If native converters are unavailable, use the tested WASM bridge:

View File

@@ -185,6 +185,14 @@ Use `origin_strategy: "center"` for large CAD coordinates. It mirrors the A208 p
Use `clip` rectangles for irregular sheet layouts. Use `split_x` plus `side` when a sheet cleanly places plans left/right; this is less likely to accidentally cut off geometry than a tight clip rectangle. Use `clip` rectangles for irregular sheet layouts. Use `split_x` plus `side` when a sheet cleanly places plans left/right; this is less likely to accidentally cut off geometry than a tight clip rectangle.
Arm cross-evidence checks whenever the drawings contain the evidence:
- Copy per-floor areas from the 经济技术指标表/area labels into `declared_areas_m2`; use `declared_area_tolerance` only for a justified source convention. A model area off by roughly 100% usually means two plans or two wings were swallowed into one clip, not balcony noise.
- Copy the above-ground count from 总图 labels or elevation/section ladders into `expected_storeys_above_ground`. When one typical plan represents a range, instantiate those floors and record that they are source-supported repetitions.
- Pass every frame-detector config through `--frames`; list deliberately unused frames in `discarded_frames` with reasons.
These checks report `NOT_APPLICABLE` when no independent evidence exists. That is not proof of correctness; document what was searched before leaving them unarmed.
Keep `expand_blocks` false for the first pass. If the audit shows important geometry in `INSERT`, set `expand_blocks` to `true` or to a list of block-name patterns, then rerun extraction/audit/overlays. When virtual block entities live on layer `0`, `block_insert_layer_fallback: true` lets the parent INSERT layer participate in category matching. Keep `expand_blocks` false for the first pass. If the audit shows important geometry in `INSERT`, set `expand_blocks` to `true` or to a list of block-name patterns, then rerun extraction/audit/overlays. When virtual block entities live on layer `0`, `block_insert_layer_fallback: true` lets the parent INSERT layer participate in category matching.
## 5. Spec Extraction ## 5. Spec Extraction
@@ -203,6 +211,7 @@ Review `building_spec.json` before rendering:
- Segment counts are not dominated by dimensions/hatches/annotations. - Segment counts are not dominated by dimensions/hatches/annotations.
- Footprint polygons exist when slabs/roofs are meant to follow CAD floor plates. - Footprint polygons exist when slabs/roofs are meant to follow CAD floor plates.
- `default_disabled_categories` does not hide `slab` for presentation/digital-twin views. - `default_disabled_categories` does not hide `slab` for presentation/digital-twin views.
- Generated cap edges do not protrude as slab fins. The historical `cap_buffer=1.3m` value fits colonnade/overhang cases; use about `0.1m` for ordinary facade-aligned floors, then confirm front/side views.
## 6. Agent Audit and Overlay Review ## 6. Agent Audit and Overlay Review
@@ -238,6 +247,7 @@ Agent review rules:
- If frequent blocks appear in the audit, inspect block names and decide whether to recursively explode block geometry. - If frequent blocks appear in the audit, inspect block names and decide whether to recursively explode block geometry.
- If hatches carry wall/slab/column information, do not rely only on line extraction. - If hatches carry wall/slab/column information, do not rely only on line extraction.
- Continue only when missing geometry is acceptable for the requested output level. - Continue only when missing geometry is acceptable for the requested output level.
- A floor can be internally self-consistent yet occupy the wrong repeated slot. If wall-profile correlation finds a strong non-zero shift, treat it as the 13号 F3 “错槽” pattern and correct the frame offset rather than trusting envelope centers.
## 7. Blender Generation ## 7. Blender Generation

View File

@@ -51,6 +51,8 @@ node scripts/web_smoke_test.mjs \
Install Playwright/Chromium first when needed. The script checks real 1440×900/390×844 viewport dimensions, desktop/mobile control visibility, console/page/request failures, and idle render behavior. Feed the report to final verification with `--browser-report`. Supplying `--web-dir` makes the report mandatory: no report is `BLOCKED`, never PASS. Install Playwright/Chromium first when needed. The script checks real 1440×900/390×844 viewport dimensions, desktop/mobile control visibility, console/page/request failures, and idle render behavior. Feed the report to final verification with `--browser-report`. Supplying `--web-dir` makes the report mandatory: no report is `BLOCKED`, never PASS.
The verifier validates the report contract, not just its top-level `status`: all required named checks must exist and be PASS, viewport details must match exactly, and console/page/request arrays must be present and empty. A hand-written `{status: PASS}` report is invalid.
When an execution tool already has a `run_in_background` option, launch `python3 -m http.server ...` as the foreground command of that background process. Do not append shell `&`; the child server can die with the wrapper. Before presenting the viewer, probe the URL and keep that server process alive. Present the formal `web/index.html` URL when Web was requested; `viewer.html` is a separate offline fallback, not a substitute. When an execution tool already has a `run_in_background` option, launch `python3 -m http.server ...` as the foreground command of that background process. Do not append shell `&`; the child server can die with the wrapper. Before presenting the viewer, probe the URL and keep that server process alive. Present the formal `web/index.html` URL when Web was requested; `viewer.html` is a separate offline fallback, not a substitute.
## Strict Evidence Manifest ## Strict Evidence Manifest
@@ -61,6 +63,8 @@ Run `verify_showcase.py --strict` for spec previews and GLB budgets, then:
python3 scripts/verify_delivery.py \ python3 scripts/verify_delivery.py \
--source-report outputs/<project>/cad_read_report.json \ --source-report outputs/<project>/cad_read_report.json \
--spec outputs/<project>/building_spec.json \ --spec outputs/<project>/building_spec.json \
--audit outputs/<project>/extraction_audit.json --require-audit \
--scope-manifest work/<project>/scope_manifest.json --require-scope-manifest \
--variants-manifest outputs/<project>/delivery/variants_manifest.json \ --variants-manifest outputs/<project>/delivery/variants_manifest.json \
--web-dir outputs/<project>/web \ --web-dir outputs/<project>/web \
--offline-viewer outputs/<project>/viewer.html \ --offline-viewer outputs/<project>/viewer.html \
@@ -71,4 +75,4 @@ python3 scripts/verify_delivery.py \
--evidence-out outputs/<project>/evidence_manifest.json --evidence-out outputs/<project>/evidence_manifest.json
``` ```
The verifier checks schema versions, audit gates, optional campus scope, GLB headers/mesh structure/naming/budgets, render dimensions/nonblank variance, Web assets/placeholders/features/variants, offline payload, offline `file://` browser load, and served-Web browser report. Only overall `PASS` is complete. `WARN`/`SKIP` produce overall `BLOCKED` unless the exact check has an explicit `--waiver 'CHECK=REASON'`; `FAIL` cannot be waived. The verifier checks schema versions, audit gates, scope artifacts, GLB headers/mesh structure/naming/budgets, render dimensions/foreground occupancy/noise, Web assets/placeholders/features/variants, offline payload, offline `file://` browser load, and served-Web browser report. Only overall `PASS` is complete. Applicable `WARN`/`SKIP` produce overall `BLOCKED` unless the exact check has an explicit `--waiver 'CHECK=REASON'`; `NOT_APPLICABLE` is recorded but non-blocking, and `FAIL` cannot be waived.

View File

@@ -9,7 +9,7 @@
5. Honesty rules 5. Honesty rules
Prioritized playbook for pushing a working showcase model toward digital-twin Prioritized playbook for pushing a working showcase model toward digital-twin
presentation quality. Apply AFTER the geometry passes the One-Shot Definition presentation quality. Apply AFTER the geometry passes the Hard Definition
of Done — polish never excuses a wrong model. Each item names the code to of Done — polish never excuses a wrong model. Each item names the code to
touch. Ordered by value-per-effort. touch. Ordered by value-per-effort.

View File

@@ -32,7 +32,17 @@
} }
}, },
"layers": {"$ref": "#/$defs/patternMap"}, "layers": {"$ref": "#/$defs/patternMap"},
"categories": {"type": "object"}, "categories": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"label": {"type": "string", "minLength": 1},
"color": {"type": "string", "minLength": 1}
},
"additionalProperties": false
}
},
"exclude_layers": {"$ref": "#/$defs/stringList"}, "exclude_layers": {"$ref": "#/$defs/stringList"},
"default_widths": {"$ref": "#/$defs/numberMap"}, "default_widths": {"$ref": "#/$defs/numberMap"},
"default_disabled_categories": {"$ref": "#/$defs/stringList"}, "default_disabled_categories": {"$ref": "#/$defs/stringList"},

View File

@@ -508,7 +508,7 @@ def evaluate_gates(
] ]
glazing_evidence = locked_glazing_meters >= GATE_GLAZING_MIN_METERS or bool(glazing_named_blocks) glazing_evidence = locked_glazing_meters >= GATE_GLAZING_MIN_METERS or bool(glazing_named_blocks)
if not glazing_evidence: 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: elif spec_glazing_segments > 0:
status = "PASS" status = "PASS"
detail = ( detail = (
@@ -532,7 +532,7 @@ def evaluate_gates(
gates.append( gates.append(
{ {
"name": "no_annotation_layers_classified", "name": "no_annotation_layers_classified",
"status": "FAIL" if annotation_classified else "PASS", "status": "WARN" if annotation_classified else "PASS",
"detail": ( "detail": (
f"Annotation/identification layers classified as geometry: {', '.join(annotation_classified[:5])}. " f"Annotation/identification layers classified as geometry: {', '.join(annotation_classified[:5])}. "
"These are tags, not elements; exclude them." "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": ...}]`. `"discarded_frames": [{"name": ..., "reason": ...}]`.
""" """
if not frames: 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", [])} discarded = {str(d.get("name", "")) for d in config.get("discarded_frames", [])}
cfg_by_file: dict[str, list[dict[str, Any]]] = {} cfg_by_file: dict[str, list[dict[str, Any]]] = {}
for drawing in config.get("drawings", []) or []: 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: if not declared:
return { return {
"name": "area_declared", "name": "area_declared",
"status": "SKIP", "status": "NOT_APPLICABLE",
"detail": "No declared_areas_m2 in config; area cross-check not requested.", "detail": "No declared_areas_m2 in config; area cross-check is not armed.",
} }
tol = float(config.get("declared_area_tolerance", 0.15)) tol = float(config.get("declared_area_tolerance", 0.15))
problems = [] 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)) parts.append("unexplained elevation gaps " + ", ".join(z_gaps))
return { return {
"name": "vertical_storey_continuity", "name": "vertical_storey_continuity",
"status": "FAIL", "status": "WARN",
"detail": ( "detail": (
"; ".join(parts) "; ".join(parts)
+ ". Instantiate source-supported repeated typical floors; do not deliver separated floor islands." + ". 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: if expected is None:
return { return {
"name": "storey_count", "name": "storey_count",
"status": "SKIP", "status": "NOT_APPLICABLE",
"detail": "No expected_storeys_above_ground in config; count cross-check not requested.", "detail": "No expected_storeys_above_ground in config; count cross-check is not armed.",
} }
import re as _re import re as _re

View File

@@ -7,6 +7,7 @@ import argparse
import hashlib import hashlib
import importlib.metadata import importlib.metadata
import json import json
import os
import shutil import shutil
import socket import socket
import subprocess import subprocess
@@ -30,16 +31,31 @@ def now() -> str:
return datetime.now(timezone.utc).isoformat() 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.""" """Hash source data and pipeline code so resume cannot reuse stale work."""
digest = hashlib.sha256() 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("*.py")))
tracked.extend(sorted(SCRIPTS.glob("*.mjs"))) tracked.extend(sorted(SCRIPTS.glob("*.mjs")))
tracked.extend(sorted((ROOT / "schemas").glob("*.json"))) 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()) 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(): if not path.is_file():
continue continue
digest.update(str(path.relative_to(ROOT) if path.is_relative_to(ROOT) else path).encode("utf-8")) 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(): if state_path.exists():
try: try:
current = json.loads(state_path.read_text(encoding="utf-8")) current = json.loads(state_path.read_text(encoding="utf-8"))
except Exception: except Exception as exc:
current = {} raise SystemExit(f"Pipeline state is corrupt and was not overwritten: {state_path}: {exc}") from exc
else: else:
current = {} current = {}
if current.get("input_fingerprint") != input_fingerprint: 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 = {} current = {}
self.state: dict[str, Any] = { self.state: dict[str, Any] = {
"state_version": 1, "state_version": 1,
@@ -82,7 +109,15 @@ class Pipeline:
def save(self) -> None: def save(self) -> None:
self.state["updated_at"] = now() self.state["updated_at"] = now()
self.path.parent.mkdir(parents=True, exist_ok=True) 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( def run(
self, self,
@@ -137,6 +172,26 @@ def python_script(name: str, *args: str) -> list[str]:
return [sys.executable, str(SCRIPTS / name), *args] 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]: def parse_waivers(values: list[str]) -> dict[str, str]:
waivers: dict[str, str] = {} waivers: dict[str, str] = {}
for value in values: for value in values:
@@ -157,7 +212,7 @@ def enforce_audit_gates(pipeline: Pipeline, audit_path: Path, waivers: dict[str,
waived = [] waived = []
for gate in report.get("gates", []): for gate in report.get("gates", []):
status = str(gate.get("status", "FAIL")) status = str(gate.get("status", "FAIL"))
if status == "PASS": if status in {"PASS", "NOT_APPLICABLE"}:
continue continue
name = f"audit:{gate.get('name', 'unnamed')}" name = f"audit:{gate.get('name', 'unnamed')}"
if status in {"WARN", "SKIP"} and name in waivers: 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}") 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: def ensure_node_runtime(pipeline: Pipeline, *, browser: bool) -> None:
"""Serve the formal Web bundle and mechanically prove desktop/mobile loading."""
pipeline.run( pipeline.run(
"node_dependencies", "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" / "playwright" / "package.json",
ROOT / "node_modules" / "@gltf-transform" / "core" / "package.json", ROOT / "node_modules" / "@gltf-transform" / "core" / "package.json",
], ],
) )
pipeline.run( if browser:
"browser_runtime", pipeline.run(
[str(ROOT / "node_modules" / ".bin" / "playwright"), "install", "chromium"], "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) report.parent.mkdir(parents=True, exist_ok=True)
port = available_port() port = available_port()
url = f"http://127.0.0.1:{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) wait_for_http(url)
pipeline.run( pipeline.run(
"browser_smoke", "browser_smoke",
[ node_script(
"node", SCRIPTS / "web_smoke_test.mjs",
str(SCRIPTS / "web_smoke_test.mjs"),
"--url", "--url",
url, url,
"--out", "--out",
str(report), str(report),
"--screenshots-dir", "--screenshots-dir",
str(screenshots), str(screenshots),
], ),
[report, screenshots], [report, screenshots],
) )
finally: 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.""" """Open the single-file viewer through file:// and prove that its model renders."""
pipeline.run( pipeline.run(
"offline_browser_smoke", "offline_browser_smoke",
[ node_script(
"node", SCRIPTS / "offline_viewer_smoke.mjs",
str(SCRIPTS / "offline_viewer_smoke.mjs"),
"--viewer", "--viewer",
str(viewer), str(viewer),
"--out", "--out",
str(report), str(report),
"--screenshot", "--screenshot",
str(screenshot), str(screenshot),
], ),
[report, screenshot], [report, screenshot],
) )
@@ -284,7 +341,10 @@ def doctor() -> int:
checks.append({"name": module, "status": "FAIL", "detail": str(exc)}) checks.append({"name": module, "status": "FAIL", "detail": str(exc)})
failed = True failed = True
for executable in ("node", "npm", "dwg2dxf"): 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}) checks.append({"name": executable, "status": "PASS" if path else "OPTIONAL", "path": path})
for executable, resolver in (("ODAFileConverter", oda_converter), ("blender", default_blender)): for executable, resolver in (("ODAFileConverter", oda_converter), ("blender", default_blender)):
candidate = resolver() candidate = resolver()
@@ -308,6 +368,10 @@ def inspect_command(args: argparse.Namespace) -> int:
"--converter", "--converter",
args.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 return subprocess.run(command, cwd=ROOT).returncode
@@ -337,7 +401,7 @@ def build_with_trimesh(pipeline: Pipeline, bundle: Path) -> list[Path]:
) )
pipeline.run( pipeline.run(
f"compress_{key}", 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], [glb],
) )
glbs.append(glb) glbs.append(glb)
@@ -348,20 +412,40 @@ def run_pipeline(args: argparse.Namespace) -> int:
dxf_dir = Path(args.dxf_dir).resolve() dxf_dir = Path(args.dxf_dir).resolve()
config = Path(args.config).resolve() config = Path(args.config).resolve()
source_report = Path(args.source_report).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: try:
report = json.loads(source_report.read_text(encoding="utf-8")) report = json.loads(source_report.read_text(encoding="utf-8"))
showcase_schema.validate_source_report(report, dxf_dir) showcase_schema.validate_source_report(report, dxf_dir)
except (OSError, json.JSONDecodeError, showcase_schema.ValidationFailure) as exc: except (OSError, json.JSONDecodeError, showcase_schema.ValidationFailure) as exc:
print(f"GATE FAIL [source_report]: {exc}", file=sys.stderr) print(f"GATE FAIL [source_report]: {exc}", file=sys.stderr)
return 3 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 = Path(args.out_dir).resolve()
out_dir.mkdir(parents=True, exist_ok=True) out_dir.mkdir(parents=True, exist_ok=True)
try: pipeline = Pipeline(
waivers = parse_waivers(args.waiver) out_dir / "pipeline_state.json",
except ValueError as exc: fingerprint(config, source_report, dxf_dir, (scope_manifest, *frame_inputs)),
print(f"GATE FAIL [waiver]: {exc}", file=sys.stderr) args.resume,
return 3 )
pipeline = Pipeline(out_dir / "pipeline_state.json", fingerprint(config, source_report, dxf_dir), 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" spec = out_dir / "building_spec.json"
audit = out_dir / "extraction_audit.json" audit = out_dir / "extraction_audit.json"
audit_md = out_dir / "extraction_audit.md" audit_md = out_dir / "extraction_audit.md"
@@ -380,7 +464,7 @@ def run_pipeline(args: argparse.Namespace) -> int:
args.vendor_dir, args.vendor_dir,
), ),
[spec], [spec],
forbidden_stderr=("WARNING topless_group",), forbidden_stderr=DERIVE_FORBIDDEN_WARNINGS,
) )
audit_cmd = python_script( audit_cmd = python_script(
"audit_showcase_extraction.py", "audit_showcase_extraction.py",
@@ -434,15 +518,9 @@ def run_pipeline(args: argparse.Namespace) -> int:
if args.blender: if args.blender:
variant_cmd.extend(["--blender", args.blender]) variant_cmd.extend(["--blender", args.blender])
pipeline.run("variants", variant_cmd, [manifest, bundle / "variant_specs" / "standard.json"]) 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": 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) glbs = build_with_trimesh(pipeline, bundle)
else: else:
glbs = [bundle / "variants" / key / f"{key}.glb" for key in ("overview", "standard", "detail")] 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: if not args.skip_web_deps:
pipeline.run( pipeline.run(
"web_dependencies", "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"], [web_dir / "node_modules" / "three" / "build" / "three.module.js"],
) )
browser_report = ( browser_report = (
@@ -495,17 +573,6 @@ def run_pipeline(args: argparse.Namespace) -> int:
), ),
[offline], [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( run_offline_browser_smoke(
pipeline, pipeline,
offline, offline,
@@ -543,10 +610,14 @@ def run_pipeline(args: argparse.Namespace) -> int:
str(preview), str(preview),
"--audit", "--audit",
str(audit), str(audit),
"--require-audit",
"--budget-mb", "--budget-mb",
str(args.budget_mb), str(args.budget_mb),
"--evidence-out", "--evidence-out",
str(evidence), str(evidence),
"--scope-manifest",
str(scope_manifest),
"--require-scope-manifest",
) )
if args.web: if args.web:
verify_cmd.extend( verify_cmd.extend(
@@ -563,8 +634,6 @@ def run_pipeline(args: argparse.Namespace) -> int:
) )
if args.require_browser_report and not args.web: if args.require_browser_report and not args.web:
verify_cmd.append("--require-browser-report") 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: for value in args.waiver:
verify_cmd.extend(["--waiver", value]) verify_cmd.extend(["--waiver", value])
pipeline.run("delivery_verification", verify_cmd, [evidence]) pipeline.run("delivery_verification", verify_cmd, [evidence])
@@ -591,6 +660,9 @@ def parser() -> argparse.ArgumentParser:
inspect.add_argument("--output", required=True) inspect.add_argument("--output", required=True)
inspect.add_argument("--vendor-dir", default="work/vendor") inspect.add_argument("--vendor-dir", default="work/vendor")
inspect.add_argument("--converter", choices=("auto", "libredwg", "oda"), default="auto") 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 = 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("--dxf-dir", required=True)
run.add_argument("--config", required=True) run.add_argument("--config", required=True)

View File

@@ -200,12 +200,18 @@ def validate_source_report(report: dict[str, Any], expected_dxf_dir: Path | None
gate = report.get("gate") or {} gate = report.get("gate") or {}
if not isinstance(gate, dict): if not isinstance(gate, dict):
gate = {} gate = {}
if gate.get("name") != "all_sources_converted_and_readable" or gate.get("status") != "PASS": gate_status = gate.get("status")
errors.append(f"gate: all_sources_converted_and_readable must be PASS, got {gate.get('status')!r}") 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") files = report.get("files")
if not isinstance(files, list) or not files: if not isinstance(files, list) or not files:
errors.append("files: report contains no inspected DXF files") errors.append("files: report contains no inspected DXF files")
else: else:
readable = 0
for index, item in enumerate(files): for index, item in enumerate(files):
if not isinstance(item, dict): if not isinstance(item, dict):
errors.append(f"files[{index}]: expected an object") 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) entity_count = int(item.get("modelspace_entities", 0) or 0)
except (TypeError, ValueError): except (TypeError, ValueError):
entity_count = 0 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( errors.append(
f"files[{index}]: {item.get('file', '?')} is not readable and nonempty " f"files[{index}]: {item.get('file', '?')} is not readable and nonempty "
f"(status={item.get('status')!r}, entities={item.get('modelspace_entities')!r})" 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: if expected_dxf_dir is not None:
reported = Path(str(report.get("dxf_sanitized", ""))) reported = Path(str(report.get("dxf_sanitized", "")))
if not reported.is_absolute(): if not reported.is_absolute():

View File

@@ -9,6 +9,7 @@ import gzip
import hashlib import hashlib
import json import json
import re import re
import statistics
import sys import sys
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
@@ -123,14 +124,57 @@ def inspect_render(path: Path, checks: list[dict[str, Any]]) -> None:
from PIL import Image, ImageStat from PIL import Image, ImageStat
image = Image.open(path).convert("RGB") 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) 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( add_check(
checks, checks,
f"render:{path.name}", f"render:{path.name}",
status, 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: except Exception as exc:
add_check(checks, f"render:{path.name}", "FAIL", f"Image inspection failed: {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}") 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: def inspect_browser_report(path: Path, checks: list[dict[str, Any]], name: str = "browser:smoke") -> None:
try: try:
report = json.loads(path.read_text(encoding="utf-8")) 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 = ( passed = (
report.get("status") == "PASS" report.get("status") == "PASS"
and not report.get("console_errors") and not report.get("console_errors")
and not report.get("page_errors") and not report.get("page_errors")
and not report.get("failed_requests") 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) add_check(checks, name, "PASS" if passed else "FAIL", detail)
except Exception as exc: except Exception as exc:
add_check(checks, name, "FAIL", f"Browser report invalid: {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") raise ValueError("audit has no gates")
for gate in gates: for gate in gates:
status = str(gate.get("status", "FAIL")) 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" status = "FAIL"
add_check( add_check(
checks, 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}") 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: def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
"""Validate a single-building/campus scope ledger against real artifacts.""" """Validate a single-building/campus scope ledger against real artifacts."""
try: 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") raise ValueError("requested must be a non-empty list of building IDs")
if len(set(requested)) != len(requested): if len(set(requested)) != len(requested):
raise ValueError("requested contains duplicate building IDs") 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): if not isinstance(buildings, list):
raise ValueError("buildings must be a list") raise ValueError("buildings must be a list")
by_id: dict[str, dict[str, Any]] = {} 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}") raise ValueError(f"missing or duplicate building id: {building_id!r}")
by_id[building_id] = item by_id[building_id] = item
missing = [item for item in requested if item not in by_id] 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( 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: else:
add_check( 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") add_check(checks, f"scope:building:{building_id}", "FAIL", "PASS building has no artifacts")
continue continue
missing_artifacts = [] missing_artifacts = []
verified_models = []
invalid_models = []
for artifact in artifacts: for artifact in artifacts:
artifact_path = Path(str(artifact)) artifact_path = Path(str(artifact))
if not artifact_path.is_absolute(): if not artifact_path.is_absolute():
artifact_path = path.parent / artifact_path artifact_path = path.parent / artifact_path
if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0): if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0):
missing_artifacts.append(str(artifact)) 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( add_check(
checks, checks,
f"scope:building:{building_id}", f"scope:building:{building_id}",
"FAIL" if missing_artifacts else "PASS", "FAIL" if failed else "PASS",
"Missing artifacts: " + ", ".join(missing_artifacts) "Missing artifacts: " + ", ".join(missing_artifacts)
if 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", {}) site = scope.get("site", {})
@@ -321,23 +486,32 @@ def inspect_scope(path: Path, checks: list[dict[str, Any]]) -> None:
else: else:
artifacts = site.get("artifacts", []) artifacts = site.get("artifacts", [])
missing_site = [] missing_site = []
verified_site = []
for artifact in artifacts if isinstance(artifacts, list) else []: for artifact in artifacts if isinstance(artifacts, list) else []:
artifact_path = Path(str(artifact)) artifact_path = Path(str(artifact))
if not artifact_path.is_absolute(): if not artifact_path.is_absolute():
artifact_path = path.parent / artifact_path artifact_path = path.parent / artifact_path
if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0): if not artifact_path.exists() or (artifact_path.is_file() and artifact_path.stat().st_size == 0):
missing_site.append(str(artifact)) 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( add_check(
checks, checks,
"scope:site", "scope:site",
"FAIL", "FAIL",
"Campus site has no artifacts" "Campus site has no artifacts"
if not 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: 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: except Exception as exc:
add_check(checks, "scope:manifest", "FAIL", f"Scope manifest invalid: {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("--offline-browser-report")
parser.add_argument("--render", nargs="*", default=[]) parser.add_argument("--render", nargs="*", default=[])
parser.add_argument("--audit") parser.add_argument("--audit")
parser.add_argument("--require-audit", action="store_true")
parser.add_argument("--scope-manifest") parser.add_argument("--scope-manifest")
parser.add_argument("--require-scope-manifest", action="store_true")
parser.add_argument("--browser-report") parser.add_argument("--browser-report")
parser.add_argument("--require-browser-report", action="store_true") parser.add_argument("--require-browser-report", action="store_true")
parser.add_argument( parser.add_argument(
@@ -377,11 +553,16 @@ def main() -> int:
try: try:
source_report = json.loads(Path(args.source_report).read_text(encoding="utf-8")) source_report = json.loads(Path(args.source_report).read_text(encoding="utf-8"))
showcase_schema.validate_source_report(source_report) showcase_schema.validate_source_report(source_report)
source_gate = source_report["gate"]
source_status = str(source_gate.get("status", "FAIL"))
add_check( add_check(
checks, checks,
"cad_source_report", "cad_source_report",
"PASS", source_status,
f"Source gate PASS; {len(source_report['files'])} readable DXF file(s)", (
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: except Exception as exc:
add_check(checks, "cad_source_report", "FAIL", str(exc)) add_check(checks, "cad_source_report", "FAIL", str(exc))
@@ -440,8 +621,12 @@ def main() -> int:
inspect_web(Path(args.web_dir), checks) inspect_web(Path(args.web_dir), checks)
if args.audit: if args.audit:
inspect_audit(Path(args.audit), checks) 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: if args.scope_manifest:
inspect_scope(Path(args.scope_manifest), checks) 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: if args.offline_viewer:
inspect_offline(Path(args.offline_viewer), checks) inspect_offline(Path(args.offline_viewer), checks)
if args.offline_browser_report: if args.offline_browser_report:

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import json import json
import os import os
import shutil
import socket import socket
import subprocess import subprocess
import sys import sys
@@ -50,7 +51,9 @@ def test_served_viewer_in_desktop_and_mobile(tmp_path: Path) -> None:
], ],
check=True, check=True,
) )
subprocess.run(["npm", "install", "--prefix", str(web), "--ignore-scripts"], check=True) npm = shutil.which("npm.cmd" if sys.platform == "win32" else "npm") or shutil.which("npm")
assert npm, "npm executable not found"
subprocess.run([npm, "install", "--prefix", str(web), "--ignore-scripts"], check=True)
with socket.socket() as sock: with socket.socket() as sock:
sock.bind(("127.0.0.1", 0)) sock.bind(("127.0.0.1", 0))
port = sock.getsockname()[1] port = sock.getsockname()[1]

View File

@@ -11,8 +11,8 @@ import ezdxf
ROOT = Path(__file__).resolve().parents[1] ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts")) sys.path.insert(0, str(ROOT / "scripts"))
import build_blender_showcase # noqa: E402
import audit_showcase_extraction # noqa: E402 import audit_showcase_extraction # noqa: E402
import build_blender_showcase # noqa: E402
import cad_showcase # noqa: E402 import cad_showcase # noqa: E402
import showcase_schema # noqa: E402 import showcase_schema # noqa: E402
import spec_to_glb # noqa: E402 import spec_to_glb # noqa: E402
@@ -60,7 +60,7 @@ def test_vertical_storey_continuity_rejects_representative_floor_islands() -> No
spec["floors"]["F2"] = {**spec["floors"]["F1"], "name": "二层", "z": 5.0} spec["floors"]["F2"] = {**spec["floors"]["F1"], "name": "二层", "z": 5.0}
spec["floors"]["F16"] = {**spec["floors"]["F1"], "name": "十六层", "z": 59.6} spec["floors"]["F16"] = {**spec["floors"]["F1"], "name": "十六层", "z": 59.6}
gate = audit_showcase_extraction.vertical_storey_continuity_gate(spec) gate = audit_showcase_extraction.vertical_storey_continuity_gate(spec)
assert gate["status"] == "FAIL" assert gate["status"] == "WARN"
assert "F2->F16" in gate["detail"] assert "F2->F16" in gate["detail"]
@@ -97,16 +97,151 @@ def test_config_rejects_missing_source(tmp_path: Path) -> None:
showcase_schema.validate_config(config, tmp_path) showcase_schema.validate_config(config, tmp_path)
def test_source_report_rejects_partial_gate() -> None: def test_source_report_requires_reason_for_partial_gate() -> None:
report = { report = {
"report_version": 1, "report_version": 1,
"gate": {"name": "all_sources_converted_and_readable", "status": "WARN"}, "gate": {"name": "all_sources_converted_and_readable", "status": "WARN"},
"files": [{"file": "partial.dxf", "status": "ok", "modelspace_entities": 1}], "files": [{"file": "partial.dxf", "status": "ok", "modelspace_entities": 1}],
} }
with pytest.raises(showcase_schema.ValidationFailure, match="must be PASS"): with pytest.raises(showcase_schema.ValidationFailure, match="partial reason"):
showcase_schema.validate_source_report(report) showcase_schema.validate_source_report(report)
def test_source_report_accepts_reasoned_partial_gate() -> None:
report = {
"report_version": 1,
"gate": {
"name": "all_sources_converted_and_readable",
"status": "WARN",
"partial_reason": "One optional elevation DWG is unavailable",
},
"files": [{"file": "partial.dxf", "status": "ok", "modelspace_entities": 1}],
}
assert showcase_schema.validate_source_report(report) == report
def test_unarmed_cross_evidence_gates_are_not_applicable() -> None:
spec = minimal_spec()
assert audit_showcase_extraction.frame_ledger_gate({}, None)["status"] == "NOT_APPLICABLE"
assert audit_showcase_extraction.declared_area_gate(spec, {})["status"] == "NOT_APPLICABLE"
assert audit_showcase_extraction.storey_count_gate(spec, {})["status"] == "NOT_APPLICABLE"
def test_annotation_is_waivable_warn_and_absent_glazing_is_not_applicable() -> None:
report = {
"spec_counts": {"F1": {"glazing": 0}},
"block_locked_layers": [],
"top_insert_names": [],
"classified_layers": [{"layer": "A-ANNO-DIMS"}],
"coverage": {
"block_locked_classifiable_length_meters": 0,
"block_captured_classified_length_meters": 0,
},
}
gates = {
gate["name"]: gate["status"]
for gate in audit_showcase_extraction.evaluate_gates(report, minimal_spec(), {}, None)
}
assert gates["no_annotation_layers_classified"] == "WARN"
assert gates["glazing_captured"] == "NOT_APPLICABLE"
def test_config_rejects_malformed_category_overrides() -> None:
config = {
"config_version": 1,
"drawings": [{"file": "fixture.dxf", "floors": [{"key": "F1"}]}],
"categories": {"walls": "not-an-object"},
}
with pytest.raises(showcase_schema.ValidationFailure, match="categories.walls"):
showcase_schema.validate_config(config)
def test_all_derive_geometry_loss_warnings_are_forbidden() -> None:
assert set(cad_showcase.DERIVE_FORBIDDEN_WARNINGS) == {
"WARNING isolated_cluster",
"WARNING unsupported_roof",
"WARNING floor_order",
"WARNING topless_group",
}
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 = [
sys.executable,
"-c",
"import sys; print('WARNING isolated_cluster F1: dropped geometry', file=sys.stderr)",
]
with pytest.raises(SystemExit):
pipeline.run("derive", command, [], forbidden_stderr=cad_showcase.DERIVE_FORBIDDEN_WARNINGS)
state = json.loads((tmp_path / "state.json").read_text(encoding="utf-8"))
assert state["steps"]["derive"]["status"] == "FAIL"
assert state["steps"]["derive"]["forbidden_stderr_hits"] == ["WARNING isolated_cluster"]
def test_windows_command_resolution_uses_cmd_shims(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(cad_showcase.sys, "platform", "win32")
monkeypatch.setattr(
cad_showcase.shutil,
"which",
lambda candidate: f"C:/tools/{candidate}" if candidate in {"npm.cmd", "node.exe"} else None,
)
assert cad_showcase.npm_command("install")[0] == "C:/tools/npm.cmd"
assert cad_showcase.node_script(Path("smoke.mjs"))[0] == "C:/tools/node.exe"
def test_resume_fingerprint_tracks_tools_offline_libs_and_extra_inputs(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
root = tmp_path / "skill"
scripts = root / "scripts"
dxf_dir = tmp_path / "dxf"
for directory in (
scripts,
root / "schemas",
root / "tools",
root / "assets" / "web-showcase-template",
root / "assets" / "offline-viewer-libs",
dxf_dir,
):
directory.mkdir(parents=True, exist_ok=True)
config = tmp_path / "config.json"
source = tmp_path / "source.json"
frames = tmp_path / "frames.json"
config.write_text("{}", encoding="utf-8")
source.write_text("{}", encoding="utf-8")
frames.write_text("{}", encoding="utf-8")
(dxf_dir / "plan.dxf").write_text("DXF", encoding="utf-8")
(scripts / "step.py").write_text("pass", encoding="utf-8")
compressor = root / "tools" / "compress.mjs"
compressor.write_text("v1", encoding="utf-8")
offline_lib = root / "assets" / "offline-viewer-libs" / "three.min.js"
offline_lib.write_text("v1", encoding="utf-8")
monkeypatch.setattr(cad_showcase, "ROOT", root)
monkeypatch.setattr(cad_showcase, "SCRIPTS", scripts)
first = cad_showcase.fingerprint(config, source, dxf_dir, (frames,))
compressor.write_text("v2", encoding="utf-8")
second = cad_showcase.fingerprint(config, source, dxf_dir, (frames,))
offline_lib.write_text("v2", encoding="utf-8")
third = cad_showcase.fingerprint(config, source, dxf_dir, (frames,))
frames.write_text('{"changed": true}', encoding="utf-8")
fourth = cad_showcase.fingerprint(config, source, dxf_dir, (frames,))
assert len({first, second, third, fourth}) == 4
def test_pipeline_state_is_atomic_and_corruption_is_loud(tmp_path: Path) -> None:
state = tmp_path / "pipeline_state.json"
pipeline = cad_showcase.Pipeline(state, "fingerprint", resume=False)
pipeline.state["proof"] = "saved"
pipeline.save()
assert json.loads(state.read_text(encoding="utf-8"))["proof"] == "saved"
assert not list(tmp_path.glob(".pipeline_state.json.*.tmp"))
state.write_text("{truncated", encoding="utf-8")
with pytest.raises(SystemExit, match="corrupt and was not overwritten"):
cad_showcase.Pipeline(state, "fingerprint", resume=True)
assert state.read_text(encoding="utf-8") == "{truncated"
def test_doctor_uses_platform_tool_resolvers(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys) -> None: def test_doctor_uses_platform_tool_resolvers(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys) -> None:
oda = tmp_path / "ODAFileConverter" oda = tmp_path / "ODAFileConverter"
blender = tmp_path / "blender" blender = tmp_path / "blender"
@@ -143,7 +278,8 @@ def test_report_empty_input_is_a_hard_failure(tmp_path: Path) -> None:
proc = subprocess.run( proc = subprocess.run(
[ [
sys.executable, sys.executable,
str(ROOT / "scripts" / "cad_dxf_report.py"), str(ROOT / "scripts" / "cad_showcase.py"),
"inspect",
"--input", "--input",
str(tmp_path), str(tmp_path),
"--work", "--work",
@@ -162,7 +298,8 @@ def test_partial_report_requires_and_records_a_reason(tmp_path: Path) -> None:
proc = subprocess.run( proc = subprocess.run(
[ [
sys.executable, sys.executable,
str(ROOT / "scripts" / "cad_dxf_report.py"), str(ROOT / "scripts" / "cad_showcase.py"),
"inspect",
"--input", "--input",
str(tmp_path), str(tmp_path),
"--work", "--work",
@@ -331,14 +468,6 @@ def test_orchestrator_runs_resumable_trimesh_pipeline(tmp_path: Path) -> None:
str(out), str(out),
"--name", "--name",
"orchestrator-test", "orchestrator-test",
"--waiver",
"audit:glazing_captured=Synthetic fixture contains no glazing evidence",
"--waiver",
"audit:frame_ledger=Synthetic fixture does not exercise sheet-frame detection",
"--waiver",
"audit:area_declared=Synthetic fixture has no independent declared-area evidence",
"--waiver",
"audit:storey_count=Synthetic fixture has no independent storey-count evidence",
"--budget-mb", "--budget-mb",
"5", "5",
] ]

View File

@@ -60,6 +60,34 @@ def source_report_fixture(tmp_path: Path) -> Path:
return path return path
def browser_report_payload(*, offline: bool = False) -> dict:
if offline:
checks = [
{"name": "offline:viewport", "status": "PASS", "detail": "1440x900 expected 1440x900"},
{"name": "offline:model-ready", "status": "PASS", "detail": "1 mesh(es)"},
{"name": "offline:canvas", "status": "PASS"},
{"name": "offline:render", "status": "PASS", "detail": "1 render(s)"},
]
else:
checks = []
for viewport, detail in (
("desktop", "1440x900 expected 1440x900"),
("mobile", "390x844 expected 390x844"),
):
checks.append({"name": f"{viewport}:viewport", "status": "PASS", "detail": detail})
for selector in ("#floor-controls", "#category-controls", "#explode", "#section", "#snapshot"):
checks.append({"name": f"{viewport}:{selector}", "status": "PASS"})
checks.append({"name": f"{viewport}:idle-render", "status": "PASS", "detail": "3->3"})
return {
"status": "PASS",
"detail": f"{len(checks)}/{len(checks)} checks passed",
"checks": checks,
"console_errors": [],
"page_errors": [],
"failed_requests": [],
}
def test_strict_delivery_passes_for_glb_render_and_offline_viewer(tmp_path: Path) -> None: def test_strict_delivery_passes_for_glb_render_and_offline_viewer(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path) spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png" render = tmp_path / "render.png"
@@ -78,15 +106,7 @@ def test_strict_delivery_passes_for_glb_render_and_offline_viewer(tmp_path: Path
assert proc.returncode == 0, proc.stderr assert proc.returncode == 0, proc.stderr
offline_browser_report = tmp_path / "offline_browser_smoke_report.json" offline_browser_report = tmp_path / "offline_browser_smoke_report.json"
offline_browser_report.write_text( offline_browser_report.write_text(
json.dumps( json.dumps(browser_report_payload(offline=True)),
{
"status": "PASS",
"detail": "4/4 checks passed",
"console_errors": [],
"page_errors": [],
"failed_requests": [],
}
),
encoding="utf-8", encoding="utf-8",
) )
evidence = tmp_path / "evidence.json" evidence = tmp_path / "evidence.json"
@@ -116,6 +136,43 @@ def test_strict_delivery_passes_for_glb_render_and_offline_viewer(tmp_path: Path
assert any(item["name"] == "offline:browser-smoke" and item["status"] == "PASS" for item in report["checks"]) assert any(item["name"] == "offline:browser-smoke" and item["status"] == "PASS" for item in report["checks"])
def test_browser_report_cannot_forge_pass_without_required_checks(tmp_path: Path) -> None:
import verify_delivery
path = tmp_path / "forged.json"
path.write_text(
json.dumps(
{
"status": "PASS",
"checks": [],
"console_errors": [],
"page_errors": [],
"failed_requests": [],
}
),
encoding="utf-8",
)
checks: list[dict] = []
verify_delivery.inspect_browser_report(path, checks)
assert checks[0]["status"] == "FAIL"
assert "non-empty list" in checks[0]["detail"]
def test_render_gate_rejects_high_variance_noise(tmp_path: Path) -> None:
import verify_delivery
noisy = Image.new("RGB", (640, 480))
pixels = noisy.load()
for y in range(noisy.height):
for x in range(noisy.width):
pixels[x, y] = (255, 255, 255) if (x + y) % 2 else (0, 0, 0)
path = tmp_path / "noise.png"
noisy.save(path)
checks: list[dict] = []
verify_delivery.inspect_render(path, checks)
assert checks[0]["status"] == "FAIL"
def test_offline_viewer_without_real_browser_report_is_blocked(tmp_path: Path) -> None: def test_offline_viewer_without_real_browser_report_is_blocked(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path) spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png" render = tmp_path / "render.png"
@@ -216,15 +273,7 @@ def test_web_writer_and_static_delivery_checks(tmp_path: Path) -> None:
assert "browser:smoke" in proc.stderr assert "browser:smoke" in proc.stderr
browser_report = tmp_path / "browser_smoke_report.json" browser_report = tmp_path / "browser_smoke_report.json"
browser_report.write_text( browser_report.write_text(
json.dumps( json.dumps(browser_report_payload()),
{
"status": "PASS",
"detail": "12/12 checks passed",
"console_errors": [],
"page_errors": [],
"failed_requests": [],
}
),
encoding="utf-8", encoding="utf-8",
) )
proc = run( proc = run(
@@ -248,6 +297,44 @@ def test_web_writer_and_static_delivery_checks(tmp_path: Path) -> None:
assert proc.returncode == 0, proc.stderr assert proc.returncode == 0, proc.stderr
def test_reasoned_partial_source_can_only_pass_with_named_waiver(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png"
render_fixture(render)
source_report = source_report_fixture(tmp_path)
source = json.loads(source_report.read_text(encoding="utf-8"))
source["gate"] = {
"name": "all_sources_converted_and_readable",
"status": "WARN",
"detail": "one optional elevation is missing",
"partial_reason": "User approved plan-only delivery",
}
source_report.write_text(json.dumps(source), encoding="utf-8")
evidence = tmp_path / "evidence.json"
base = [
sys.executable,
"scripts/verify_delivery.py",
"--spec",
str(spec),
"--source-report",
str(source_report),
"--glb",
str(glb),
"--render",
str(render),
"--evidence-out",
str(evidence),
]
proc = run(*base)
assert proc.returncode == 3
assert json.loads(evidence.read_text(encoding="utf-8"))["status"] == "BLOCKED"
proc = run(*base, "--waiver", "cad_source_report=User approved plan-only delivery")
assert proc.returncode == 0, proc.stderr
report = json.loads(evidence.read_text(encoding="utf-8"))
source_check = next(item for item in report["checks"] if item["name"] == "cad_source_report")
assert source_check["original_status"] == "WARN"
def test_warn_or_skip_blocks_without_explicit_reasoned_waiver(tmp_path: Path) -> None: def test_warn_or_skip_blocks_without_explicit_reasoned_waiver(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path) spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png" render = tmp_path / "render.png"
@@ -342,6 +429,78 @@ def test_campus_scope_cannot_pass_with_a_missing_requested_building(tmp_path: Pa
assert any(item["name"] == "scope:building:2#" and item["status"] == "WARN" for item in report["checks"]) assert any(item["name"] == "scope:building:2#" and item["status"] == "WARN" for item in report["checks"])
def test_scope_rejects_arbitrary_nonempty_artifact(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png"
render_fixture(render)
source_report = source_report_fixture(tmp_path)
fake = tmp_path / "looks-done.txt"
fake.write_text("not a model", encoding="utf-8")
scope = tmp_path / "scope_manifest.json"
scope.write_text(
json.dumps(
{
"scope_version": 1,
"mode": "single",
"requested": ["11#"],
"buildings": [{"id": "11#", "status": "PASS", "artifacts": [fake.name]}],
}
),
encoding="utf-8",
)
evidence = tmp_path / "evidence.json"
proc = run(
sys.executable,
"scripts/verify_delivery.py",
"--spec",
str(spec),
"--source-report",
str(source_report),
"--glb",
str(glb),
"--render",
str(render),
"--scope-manifest",
str(scope),
"--evidence-out",
str(evidence),
)
assert proc.returncode == 3
report = json.loads(evidence.read_text(encoding="utf-8"))
check = next(item for item in report["checks"] if item["name"] == "scope:building:11#")
assert check["status"] == "FAIL"
assert "No verifiable" in check["detail"]
def test_required_audit_and_scope_cannot_be_omitted(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png"
render_fixture(render)
source_report = source_report_fixture(tmp_path)
evidence = tmp_path / "evidence.json"
proc = run(
sys.executable,
"scripts/verify_delivery.py",
"--spec",
str(spec),
"--source-report",
str(source_report),
"--glb",
str(glb),
"--render",
str(render),
"--require-audit",
"--require-scope-manifest",
"--evidence-out",
str(evidence),
)
assert proc.returncode == 3
failed = {
item["name"] for item in json.loads(evidence.read_text(encoding="utf-8"))["checks"] if item["status"] == "FAIL"
}
assert {"audit:report", "scope:manifest"} <= failed
def test_variants_manifest_requires_metadata_artifact(tmp_path: Path) -> None: def test_variants_manifest_requires_metadata_artifact(tmp_path: Path) -> None:
spec, glb, _metadata = build_fixture(tmp_path) spec, glb, _metadata = build_fixture(tmp_path)
render = tmp_path / "render.png" render = tmp_path / "render.png"