Skip to content

fix(client): scalar-only path — case-insensitive lookup + tier='scalar' sentinel (#368, #370) - #371

Merged
gerchowl merged 1 commit into
devfrom
feature/368-scalar-only-fixes
May 8, 2026
Merged

gerchowl merged 1 commit into
devfrom
feature/368-scalar-only-fixes

Conversation

@gerchowl

@gerchowl gerchowl commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two related bugs in MatVisClient that broke the scalar-only render path. The surface symptom was pymat's tests/test_visual_regression.py::BERNHARD_SCALAR_ONLY case rendering as default-grey, because every PBR scalar was silently dropped for the typical display-name input.

Bug A — #368: _scalars_for was case-sensitive

MatVisClient._scalars_for(source, material_id) compared entry["id"] != material_id directly. Substrate stores normalized lowercase ids ("aluminum"); callers (pymat, downstream tests) routinely pass capitalised display names ("Aluminum", "Plastic (Acrylic)"). Result: silent {} return — every PBR scalar dropped, every scalar-only material rendered as default grey.

Fix: match against the canonical id exactly, OR casefold-normalized id, OR casefold-normalized mat_vis.name. Reuses the existing _normalize_name helper (NFKC + casefold).

Bug B — #370: _resolve_material_id raised for tier="scalar"

_resolve_material_id raised MaterialNotStagedError when tier="scalar" was passed for scalar-only sources (physicallybased + the 18 gpuopen scalar-only entries). "scalar" is the convention sentinel for scalar-only callers (cf. pymat TIERS_SCALAR = ["scalar"]), not a missing bake — the resolver should accept it.

Fix: special-case tier == "scalar" inside the inner _is_staged predicate so the available_tiers membership check is skipped; every entry counts as staged for the sentinel tier. Direct-id, single-name-match, and disambiguation paths all continue to work.

Standalone mirror

Both fixes mirrored to clients/python/mat_vis_client_standalone.py. The tests/test_standalone_drift.py suite stays green.

Tests

Added 9 unit tests in clients/python/tests/test_scalar_only_lookup.py, all using mocked index() returns (no network):

  • _scalars_for("physicallybased", "Aluminum") returns full PBR
  • Lowercase canonical id still works (regression)
  • Display-name lookup with punctuation: "Plastic (Acrylic)" resolves
  • Silent-on-miss contract preserved ({} for unknowns)
  • _resolve_material_id("physicallybased", "Aluminum", "scalar") returns "aluminum"
  • _resolve_material_id("gpuopen", "Chrome", "scalar") returns the UUID
  • Direct lowercase id with tier="scalar" also resolves
  • Regression: tier="1k" still raises MaterialNotStagedError on missing bake
  • Regression: tier="1k" + staged entry still returns canonical id

Suite: 442 → 451 passing in clients/python (29 skipped, 2 xfailed unchanged).

Out of scope

Test plan

  • cd clients/python && uv run pytest --tb=short -q — 451 passing
  • uv run pytest tests/test_standalone_drift.py — drift test green
  • Repo-root uv run pytest tests/ — 604 passing
  • Downstream verification in pymat: BERNHARD_SCALAR_ONLY visual regression should now render with the actual PBR scalars instead of default grey.

…r' sentinel (#368, #370)

Two related bugs broke the scalar-only render path; both surface in
pymat's BERNHARD_SCALAR_ONLY visual regression case (rendered as
default-grey because every PBR scalar was silently dropped).

Bug A (#368): _scalars_for did a case-sensitive entry["id"] !=
material_id comparison. Substrate stores normalized lowercase ids;
callers (pymat, downstream) routinely pass capitalised display names
("Aluminum", "Plastic (Acrylic)"). Result: silent {} return.

Fix: match canonical id exactly OR casefold-normalized id OR
casefold-normalized mat_vis.name, using the existing _normalize_name
helper.

Bug B (#370): _resolve_material_id raised MaterialNotStagedError when
tier="scalar" was passed for scalar-only sources (physicallybased + the
18 gpuopen scalar-only entries). "scalar" is the convention sentinel
(cf. pymat TIERS_SCALAR = ["scalar"]), not a missing bake.

Fix: special-case tier="scalar" inside _is_staged so the membership
check is skipped; every entry counts as staged for the sentinel tier.

Mirrored both fixes to mat_vis_client_standalone.py to keep the
single-file mirror in sync (drift test passes).

Tests (9 new, mocked indexes, no network):
- case-insensitive _scalars_for("physicallybased", "Aluminum")
- lowercase id still works (regression)
- display-name lookup with punctuation ("Plastic (Acrylic)")
- silent-on-miss contract preserved
- _resolve_material_id(..., "Aluminum", "scalar") returns "aluminum"
- gpuopen Chrome scalar-only path returns the UUID
- direct lowercase id with tier="scalar" resolves
- regression: tier="1k" still raises MaterialNotStagedError on missing bake
- regression: tier="1k" + staged entry still returns canonical id

Suite: 442 → 451 passing in clients/python.
@github-actions github-actions Bot added area:testing Test infrastructure, BATS, pytest area:client Python/JS/Rust client packages labels May 8, 2026
@gerchowl
gerchowl merged commit fcc9e27 into dev May 8, 2026
5 checks passed
gerchowl added a commit that referenced this pull request May 8, 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 added a commit that referenced this pull request May 15, 2026
…r' sentinel (#368, #370) (#371)

Two related bugs broke the scalar-only render path; both surface in
pymat's BERNHARD_SCALAR_ONLY visual regression case (rendered as
default-grey because every PBR scalar was silently dropped).

Bug A (#368): _scalars_for did a case-sensitive entry["id"] !=
material_id comparison. Substrate stores normalized lowercase ids;
callers (pymat, downstream) routinely pass capitalised display names
("Aluminum", "Plastic (Acrylic)"). Result: silent {} return.

Fix: match canonical id exactly OR casefold-normalized id OR
casefold-normalized mat_vis.name, using the existing _normalize_name
helper.

Bug B (#370): _resolve_material_id raised MaterialNotStagedError when
tier="scalar" was passed for scalar-only sources (physicallybased + the
18 gpuopen scalar-only entries). "scalar" is the convention sentinel
(cf. pymat TIERS_SCALAR = ["scalar"]), not a missing bake.

Fix: special-case tier="scalar" inside _is_staged so the membership
check is skipped; every entry counts as staged for the sentinel tier.

Mirrored both fixes to mat_vis_client_standalone.py to keep the
single-file mirror in sync (drift test passes).

Tests (9 new, mocked indexes, no network):
- case-insensitive _scalars_for("physicallybased", "Aluminum")
- lowercase id still works (regression)
- display-name lookup with punctuation ("Plastic (Acrylic)")
- silent-on-miss contract preserved
- _resolve_material_id(..., "Aluminum", "scalar") returns "aluminum"
- gpuopen Chrome scalar-only path returns the UUID
- direct lowercase id with tier="scalar" resolves
- regression: tier="1k" still raises MaterialNotStagedError on missing bake
- regression: tier="1k" + staged entry still returns canonical id

Suite: 442 → 451 passing in clients/python.
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 feature/368-scalar-only-fixes 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 area:testing Test infrastructure, BATS, pytest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant