diff --git a/scripts/cad_showcase.py b/scripts/cad_showcase.py index 0ef3b4f..0ef12c8 100644 --- a/scripts/cad_showcase.py +++ b/scripts/cad_showcase.py @@ -470,16 +470,24 @@ def doctor() -> int: def inspect_command(args: argparse.Namespace) -> int: + # Internal pipeline scripts run from ROOT so their bundled assets and + # schemas have a stable base. User-provided paths, however, are relative + # to the directory where cad_showcase.py was invoked (the Task workdir), + # not to this repository. Resolve them before crossing that cwd boundary. + input_dir = Path(args.input).resolve() + work_dir = Path(args.work).resolve() + output_dir = Path(args.output).resolve() + vendor_dir = Path(args.vendor_dir).resolve() command = python_script( "cad_dxf_report.py", "--input", - args.input, + str(input_dir), "--work", - args.work, + str(work_dir), "--output", - args.output, + str(output_dir), "--vendor-dir", - args.vendor_dir, + str(vendor_dir), "--converter", args.converter, ) @@ -529,6 +537,7 @@ def run_pipeline(args: argparse.Namespace) -> int: 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) + vendor_dir = Path(args.vendor_dir).resolve() try: waivers = parse_waivers(args.waiver) except ValueError as exc: @@ -600,7 +609,7 @@ def run_pipeline(args: argparse.Namespace) -> int: "--out", str(spec), "--vendor-dir", - args.vendor_dir, + str(vendor_dir), ), [spec], forbidden_stderr=DERIVE_FORBIDDEN_WARNINGS, @@ -616,10 +625,10 @@ def run_pipeline(args: argparse.Namespace) -> int: "--out", str(audit), "--vendor-dir", - args.vendor_dir, + str(vendor_dir), ) - if args.frames: - audit_cmd.extend(["--frames", *args.frames]) + if frame_inputs: + audit_cmd.extend(["--frames", *[str(path) for path in frame_inputs]]) pipeline.run("audit", audit_cmd, [audit, audit_md]) audit_report = json.loads(audit.read_text(encoding="utf-8")) invalid_waivers = preflight_waiver_targets(args, report, audit_report, scope_manifest, waivers) @@ -645,7 +654,7 @@ def run_pipeline(args: argparse.Namespace) -> int: "--out-dir", str(overlays), "--vendor-dir", - args.vendor_dir, + str(vendor_dir), ), [overlays], ) diff --git a/tests/test_contracts.py b/tests/test_contracts.py index 4345af6..3c43962 100644 --- a/tests/test_contracts.py +++ b/tests/test_contracts.py @@ -501,6 +501,37 @@ def test_report_empty_input_is_a_hard_failure(tmp_path: Path) -> None: assert "all_sources_converted_and_readable" in proc.stderr +def test_inspect_resolves_relative_paths_from_invocation_directory(tmp_path: Path) -> None: + source_dir = tmp_path / "in" / "cad" + source_dir.mkdir(parents=True) + doc = ezdxf.new("R2010") + doc.modelspace().add_line((0, 0), (1000, 0), dxfattribs={"layer": "WALL"}) + doc.saveas(source_dir / "plan.dxf") + + proc = subprocess.run( + [ + sys.executable, + str(ROOT / "scripts" / "cad_showcase.py"), + "inspect", + "--input", + "in/cad", + "--work", + "out/work", + "--output", + "out/report", + "--no-convert", + ], + cwd=tmp_path, + text=True, + capture_output=True, + ) + + assert proc.returncode == 0, proc.stderr + report = json.loads((tmp_path / "out" / "report" / "cad_read_report.json").read_text(encoding="utf-8")) + assert report["gate"]["status"] == "PASS" + assert (tmp_path / "out" / "work" / "dxf_sanitized" / "plan.dxf").is_file() + + def test_partial_report_requires_and_records_a_reason(tmp_path: Path) -> None: proc = subprocess.run( [