Files
make-cad/tests/test_ocp_core_no_cadquery.py
NiJingzhe a5e6bf8eb6 feat(core)!: QL-only topology enumeration — remove bare getter list form
Plural topology getters (get_edges/get_faces/get_wires/get_vertices/
get_solids/get_inner_wires/get_edge_occurrences and the Compound
variants) now accept ONLY an index. The no-argument list form raises a
SimpleCADError with migration guidance (enumerate via
ql.<kind>().resolve(shape), pick via get_X(index)). This closes the
selection channel that escapes the graph: Python loops over bare lists
lose the predicate, capture kernel artifacts (the periodic-face seam
edges that broke FCStd translation), and leave no cardinality contract.

- each shape class keeps its enumeration logic as private _iter_<kind>();
  indexed picks record geo-select nodes as before (contract test added);
  Compound getters gain the same indexed recording they lacked
- _TopologySelectionList (the __getitem__ recording vehicle, which also
  made get_X()[i] a silent escape hatch) is retired
- all 109 internal call sites, 165 test call sites, and 31 example call
  sites migrated: SDK/tests use the private channel, user-facing
  examples use ql.<kind>().resolve(...)
- QL _resolve_scope_items switches to the private channel; scene
  contract profile descriptions synced; error strings recommending
  bracket indexing rewritten
- skill docs: strict prohibition added to SKILL.md global rules (new
  rule 6), core README contract statement rewritten, solid/wire/face/
  shell/tagged_mixin pages re-exemplified with QL, geometric-validation
  anti-pattern section updated; mirrors rebuilt via tools/skillbuild.py

Gates: full suite 1418 passed / 5 skipped; translator suites 133 passed;
u_link stage verifiers + render check ALL PASS; scadpkg->FCStd
retranslation verified (5 visible deliverables, 167-object editable
tree).
2026-09-01 02:09:29 +08:00

53 lines
2.0 KiB
Python

from pathlib import Path
import pytest
from simplecadapi import make_box_rsolid, make_line_redge, make_rectangle_rface, extrude_rsolid
from simplecadapi.core import Edge, Face, Solid, Vertex, Wire
def test_core_public_shapes_do_not_expose_cq_accessors():
box = make_box_rsolid(1, 2, 3)
face = box.get_faces(0)
edge = face.get_outer_wire().get_edges(0)
vertex = edge.get_start_vertex()
wire = face.get_outer_wire()
for shape in (box, face, edge, vertex, wire):
assert hasattr(shape, "wrapped")
for forbidden in ("cq_solid", "cq_face", "cq_edge", "cq_vertex", "cq_wire"):
assert not hasattr(shape, forbidden), f"{type(shape).__name__} exposes {forbidden}"
def test_ocp_native_basic_properties():
line = make_line_redge((0, 0, 0), (3, 4, 0))
assert isinstance(line, Edge)
assert line.get_length() == pytest.approx(5.0)
assert line.get_start_vertex().get_coordinates() == pytest.approx((0, 0, 0))
assert line.get_end_vertex().get_coordinates() == pytest.approx((3, 4, 0))
box = make_box_rsolid(1, 2, 3)
assert isinstance(box, Solid)
assert box.get_volume() == pytest.approx(6.0)
assert len(box._iter_faces()) == 6
def test_ocp_native_face_wire_topology_and_extrude():
face = make_rectangle_rface(2, 3)
assert isinstance(face, Face)
assert face.get_area() == pytest.approx(6.0)
assert isinstance(face.get_outer_wire(), Wire)
assert face.get_outer_wire().is_closed()
solid = extrude_rsolid(face, (0, 0, 1), 4)
assert solid.get_volume() == pytest.approx(24.0)
def test_runtime_source_has_no_cadquery_imports_in_runtime_package():
runtime_files = list(Path("src/simplecadapi").rglob("*.py"))
forbidden = ("import cadquery", "from cadquery", "cadquery.occ_impl", ".cq_solid", ".cq_face", ".cq_edge", ".cq_wire", ".cq_vertex")
for path in runtime_files:
text = path.read_text()
for token in forbidden:
assert token not in text, f"{path} contains forbidden CadQuery token {token!r}"