Repository navigation
refactor(client): centralize id/name lookup predicate (closes #372, #367) - #375
Merged
Merged
Conversation
) Three call sites in mat-vis-client were doing variations of the "match an entry by canonical id OR display name OR normalized id" lookup, with subtle drift: | Site | Pattern | Strength | |-------------------------------------|------------------------|----------| | _scalars_for | inline 3-way (post #371)| strong | | VisAsset._is_scalar_only_entry | inline 2-way | weaker | | _resolve_material_id | by_id+by_name w/ ambig.| separate | The 2-way pattern in `_is_scalar_only_entry` skipped the "normalized id" leg — a silent #367-class gap that would surface the moment a caller constructs `VisAsset(source="physicallybased", material_id="Aluminum")` (substrate id is `"aluminum"`, lowercase). Fix: extract one static predicate `_entry_matches_id_or_name` on MatVisClient. Three-way match (canonical id exact / norm id / norm name). Replace the inline blocks in `_scalars_for` and `_is_scalar_only_entry`. `_resolve_material_id` keeps its own logic (ambiguity detection + typed errors is a different responsibility). Standalone single-file client mirrors the same predicate — drift test (test_standalone_drift.py) keeps both surfaces in sync. Net: 56 lines added, 36 removed. Existing #367/#368/#370 tests cover the matching contract — no new tests needed. Closes #367 in passing (the silent strengthening of `_is_scalar_only_entry` is the missing leg from the pre-#371 surface).
gerchowl
enabled auto-merge (squash)
May 8, 2026 09:34
gerchowl
added a commit
that referenced
this pull request
May 15, 2026
) (#375) Three call sites in mat-vis-client were doing variations of the "match an entry by canonical id OR display name OR normalized id" lookup, with subtle drift: | Site | Pattern | Strength | |-------------------------------------|------------------------|----------| | _scalars_for | inline 3-way (post #371)| strong | | VisAsset._is_scalar_only_entry | inline 2-way | weaker | | _resolve_material_id | by_id+by_name w/ ambig.| separate | The 2-way pattern in `_is_scalar_only_entry` skipped the "normalized id" leg — a silent #367-class gap that would surface the moment a caller constructs `VisAsset(source="physicallybased", material_id="Aluminum")` (substrate id is `"aluminum"`, lowercase). Fix: extract one static predicate `_entry_matches_id_or_name` on MatVisClient. Three-way match (canonical id exact / norm id / norm name). Replace the inline blocks in `_scalars_for` and `_is_scalar_only_entry`. `_resolve_material_id` keeps its own logic (ambiguity detection + typed errors is a different responsibility). Standalone single-file client mirrors the same predicate — drift test (test_standalone_drift.py) keeps both surfaces in sync. Net: 56 lines added, 36 removed. Existing #367/#368/#370 tests cover the matching contract — no new tests needed. Closes #367 in passing (the silent strengthening of `_is_scalar_only_entry` is the missing leg from the pre-#371 surface).
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.
Summary
Built on top of #371's #368/#370 fix.
Why
Before this PR, three substrate-lookup call sites had subtly different versions of the same matching logic:
The 2-way version in `_is_scalar_only_entry` would silently miss `VisAsset(source="physicallybased", material_id="Aluminum")` because the substrate id is `"aluminum"` (lowercase) — exact match fails, the entry name might happen to be `"Aluminum"` (so name match works for this case), but the next physicallybased material whose name doesn't exactly equal the call site's casing would silently miss again.
Centralizing prevents drift: any new substrate lookup site uses one matcher.
Test plan