Insulate body-finding behind sp (API-containment increment 1)#51
Open
YLZha wants to merge 1 commit into
Open
Conversation
Part of making the `sp` layer a deliberate insulation boundary: route the raw Fusion-API uses in templates through named helpers so each quirk has ONE implementation site to maintain when the API drifts (instead of N copies across templates). This increment: body-finding. Six templates each carried a private `_all_bodies` / `_find_body` loop over `comp.bRepBodies` + name matching — the exact pattern the audit flagged as fragile (name collisions after mirror/pattern renames, proxy vs native). Added standalone `sp.bodies_in` / `sp.find_body` / `sp.find_bodies` (thin wrappers over the already-canonical `_util` recursive helpers that `DesignContext` uses), and routed drawbore, tusk_tenon, splayed_legs, domino, scarf_joint, bed_rail_fastener through them. No raw `.bRepBodies` iteration remains in those files. Behavior-preserving by construction: `bodies_in` returns the same shallow list as `_all_bodies`; `find_body` is `_find_body_recursive` (checks the component's own bodies first, then descendants — the same fallback the locals already used). The fragile name-based identification now lives in one hardenable place. py_compile clean. The template Fusion fixtures (tests/test_template_*) are the regression guard and should be run in Fusion to confirm. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First increment of option 1 from the API-fragility review: make
spa deliberate insulation boundary so each Fusion-API quirk has one implementation site to maintain across version drift, instead of N copies in templates.This increment: body-finding
Six templates each carried a private
_all_bodies/_find_bodyloop overcomp.bRepBodies+ name matching — the exact pattern the audit flagged as fragile (wrong body picked after a mirror/pattern rename or proxy/native mismatch).sp.bodies_in(comp),sp.find_body(name, comp),sp.find_bodies(pattern, comp)— thin wrappers over the already-canonical_utilrecursive helpers thatDesignContextuses..bRepBodiesiteration remains in those files.The fragile name-based identification now lives in one place — so the later hardening (UUID/feature association instead of name matching) is a single-site change.
Behavior-preserving by construction
bodies_inreturns the same shallow list as the old_all_bodies.find_body=_find_body_recursive(checks the component's own bodies first, then descendants — the same fallback the locals already delegated to)._find_body/_all_bodiessignature (now one-line delegations) → zero call-site churn. scarf_joint/bed_rail had inline loops, replaced directly.Verification
py_compileclean on all 7 files; confirmed no raw.bRepBodiesleft in the migrated templates.tests/test_template_drawbore.py,_splayed_legs,_domino, …) are the real regression guard — they run in Fusion and should be exercised there to confirm (I can't run them offline).Next increments (separate PRs, same pattern)
addTwoPointRectangle→sp.sketch_rect*where parametric matters (skip throwaway cut-tool sketches)Matrix3D/Move → ansprotate/move shimcreateForAssemblyContext→spproxy helper (one place to add the.isValidguard)participantBodiesset →sp.ext_op🤖 Generated with Claude Code