Skip to content

refactor(client): centralize id/name lookup predicate (closes #372, #367) - #375

Merged
gerchowl merged 1 commit into
devfrom
refactor/372-entry-match-helper
May 8, 2026
Merged

gerchowl merged 1 commit into
devfrom
refactor/372-entry-match-helper

Conversation

@gerchowl

@gerchowl gerchowl commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extract `_entry_matches_id_or_name` static predicate on `MatVisClient` — three-way name-aware match (canonical id exact / normalized id / normalized name).
  • Refactor `_scalars_for` and `VisAsset._is_scalar_only_entry` to use it (silently strengthens the latter from a 2-way match — fixes a latent _scalars_for should resolve display names (symmetric with fetch_all_textures) #367-class drift).
  • Mirror in standalone single-file client; drift test keeps the surface in sync.
  • `_resolve_material_id` left untouched — different responsibility (by_id + by_name lists for ambiguity detection + typed errors).

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:

Site Pattern Strength
`_scalars_for` inline 3-way (after #371) strong
`VisAsset._is_scalar_only_entry` inline 2-way (no norm-id leg) weaker
`_resolve_material_id` by_id+by_name w/ ambiguity separate

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

  • Full client suite: 451 passed, 29 skipped, 2 xfailed
  • Full baker suite: 604 passed, 16 skipped
  • Live verification against `gerchowl/[email protected]`: `_scalars_for('gpuopen', 'Aluminum Brushed')` and the lowercase variant + UUID all return identical scalars
  • Standalone drift test passes

)

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
gerchowl enabled auto-merge (squash) May 8, 2026 09:34
@github-actions github-actions Bot added the area:client Python/JS/Rust client packages label May 8, 2026
@gerchowl
gerchowl merged commit 09549cf into dev May 8, 2026
4 checks passed
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).
@gerchowl
gerchowl deleted the refactor/372-entry-match-helper branch July 1, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:client Python/JS/Rust client packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant