Skip to content

test(visual): Bernhard's mat-vis #285 25-material grid + reviewer gate - #223

Merged
gerchowl merged 3 commits into
mainfrom
feature/3.12-visual-285-grid
May 7, 2026
Merged

gerchowl merged 3 commits into
mainfrom
feature/3.12-visual-285-grid

Conversation

@gerchowl

@gerchowl gerchowl commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Comprehensive expansion of the visual-regression test for mat-vis #285. v1 of this PR had a single visual test routed through build123d.export_gltf (which strips materials — separate gap not in scope here). v2 replaces it with 33 parametrized tests across 5 classes that exercise py-mat's substrate → adapter → renderer pipeline directly.

Five test classes

Class Tests Pins
TestBernhardMatVis285_AdapterStructure_Textured 10 (to_threejs / to_gltf × 5 tiers) Adapter API drift + #285 scalar regression at every tier
TestBernhardMatVis285_AdapterStructure_Scalar 10 (to_threejs / to_gltf × 5 physicallybased mats) mat-vis #313 / py-mat #222 scalar-only path
TestBernhardMatVis285_Ktx2Bytes 1 KTX2 magic header at tier="ktx2-1k" (catches PNG-fallback regression)
TestBernhardMatVis285_MtlxExport 1 .mtlx XML parses + <image file=…> resolves on disk
TestBernhardMatVis285_Visual 4 (3 textured tiers + 1 scalar) End-to-end PNG via to_threejs() → JS Three.js (bypasses build123d)

Architecture change vs v1

v1: build_scene → build123d.export_gltf → glTF on disk → Three.js GLTFLoader → screenshot — lost materials at the build123d boundary.

v2: to_threejs(vis) per material → JSON spec → JS-side MeshPhysicalMaterial constructor → Three.js scene → canvas.toDataURL — no glTF middleware, no build123d dependency for the visual test. Texture data URIs fed directly into Three.js TextureLoader. Visual artifact reflects py-mat's actual surface only.

tests/visual_grid_render.html (new): programmatic Three.js viewer. Loads a JSON spec listing material spec dicts; instantiates one MeshPhysicalMaterial per spec; renders 5×5 grid of spheres. Uses Three.js's RoomEnvironment HDRI proxy + FOV-aware camera framing for full-scene visibility.

Reviewer gate (release-please-config.json)

New required checkbox: "Visual regression artifacts inspected — confirm metals look metallic, glass transparent, distinct hues across the grid."

CODEOWNERS auto-requests @gerchowl review on every release-please PR (via ownership of CHANGELOG.md, release-please-config.json, and the visual machinery). For this to block merge rather than just request review, branch protection rule "Require review from Code Owners" must be enabled on main (repo settings change, not code).

What flips when mat-vis ships #285 baker fix

  • All 10 structural tests on textured tiers → green (scalar fingerprint detects the fix)
  • All 10 structural tests on scalar-only sources → already green (closed by #225 py-mat-side workaround)
  • All 4 visual PNGs → metals reflective, glass transparent, distinct hues
  • KTX2 + MaterialX tests → already green (verified on mat-vis@dev)

Test plan

  • uv run pytest tests/test_visual_regression.py --collect-only → 33 tests collected
  • uv run ruff check tests/test_visual_regression.py clean
  • uv run ruff format --check tests/test_visual_regression.py clean
  • CODEOWNERS valid (GitHub validates on push)
  • release-please-config.json parses
  • Visual snapshot pipeline verified end-to-end against mat-vis-client@dev in a separate worktree (both pymat-true and pymat-false PNGs rendered correctly via canvas.toDataURL)

Refs build123d#1270, mat-vis #285, mat-vis #294, mat-vis #298, mat-vis #311, mat-vis #313, py-mat #99, py-mat #100, py-mat #220–222

cc @gerchowl (auto-requested via CODEOWNERS once merged)

gerchowl added a commit that referenced this pull request May 7, 2026
Replaces the single TestBernhardMatVis285Grid with a comprehensive
matrix of py-mat's substrate → adapter → renderer pipeline. 33
parametrized tests covering:

## TestBernhardMatVis285_AdapterStructure_Textured (10 tests)

(to_threejs, to_gltf) × (1k, 512, 256, ktx2-1k, ktx2-512). Per-tier
structural validation of the textured 24-material grid: dict shape
right, scalar-fingerprint catches the mat-vis #285 default-grey
regression. Strict-xfail on the scalar count assertion until
substrate re-bakes.

## TestBernhardMatVis285_AdapterStructure_Scalar (10 tests)

(to_threejs, to_gltf) × (Aluminum, Gold, Iron, Copper, Plastic-
Acrylic). Closes the test-coverage gap from mat-vis #313 / py-mat
#222: scalar-only physicallybased path must not raise
MaterialNotStagedError. Strict-xfail.

## TestBernhardMatVis285_Ktx2Bytes (1 test)

At tier='ktx2-1k', texture bytes must start with the KTX2 magic
header (b'\\xabKTX 20\\xbb\\r\\n\\x1a\\n'). Catches a substrate
regression where the KTX2 path silently falls back to PNG.

## TestBernhardMatVis285_MtlxExport (1 test)

Vis.mtlx.export(dir) writes a self-contained .mtlx package; XML
parses, surfacematerial nodes present, every <image file=...>
attribute resolves to a sibling PNG on disk. Doesn't run an
actual MaterialX renderer — that's downstream.

## TestBernhardMatVis285_Visual (4 tests)

Renders Bernhard's grid via headless Three.js — bypassing
build123d's glTF exporter entirely. Material specs come from
to_threejs(vis); JS-side viewer instantiates THREE.MeshPhysical-
Material directly; sphere geometry is created in JS. Isolates
py-mat's surface from any downstream consumer's export-pipeline
gaps.

Parametrized: (textured, 1k/512/256) + (scalar, scalar). Output:
4 PNG artifacts per release + sidecar JSON with stripped scalars
for human review. Strict-xfail until #285 re-bake.

## tests/visual_grid_render.html

New programmatic Three.js viewer. Loads a JSON spec listing
material spec dicts; instantiates one MeshPhysicalMaterial per
spec; renders 5×5 grid of spheres. Bypasses glTF entirely — every
texture data URI from to_threejs() is fed directly into
TextureLoader, no glTF middleware. Uses Three.js's RoomEnvironment
HDRI proxy + FOV-aware camera framing for full-scene visibility.

## Reviewer gate (release-please-config.json)

Existing checklist line still applies — but now the artifacts to
inspect are bernhard_grid_textured_*.png + bernhard_grid_scalar_-
scalar.png across all 4 (scene, tier) combinations.

Refs build123d#1270, mat-vis #285, mat-vis #294, mat-vis #298,
mat-vis #313, mat-vis #340, py-mat #99, py-mat #100, py-mat #220-222
@gerchowl gerchowl mentioned this pull request May 7, 2026
6 tasks
gerchowl added 2 commits May 7, 2026 18:06
…er gate

Three pieces wiring up a hard visual-inspection gate so we can't ship
a release that visually regressed without a human signing off.

## TestBernhardMatVis285Grid

Renders Bernhard's exact 25-material grid from mat-vis #285's repro
snippet — ``Aluminum Brushed``, ``Bronze Oxydized``, ``Stainless
Steel Brushed``, ``Aluminum Corrugated``, ``Aluminum Hexagon``,
``Car Paint``, ``Carbon biColor Coat``, ``Perforated Metal``,
``Chrome``, ``Glass``, ``Red Wine``, ``Gold``, ``TH:`` series, ambientCG
``Metal 007`` / ``Fabric 004`` / ``Metal Plates 006``, polyhaven
flooring + rock wall, physicallybased ``Plastic (Acrylic)``.

Parametrized across three tiers (1k, 512, 256) — same scene at each
texture resolution, so the artifact pair tells reviewers both "scalars
got baked correctly" (metals look metallic at every tier) and "texture
fidelity didn't regress at lower tiers" (no banding / mush).

The actual assertion fingerprints the default-grey regression
documented in mat-vis #285: at least 5 of the rendered materials
must have NON-default scalars (metalness ≠ 0.0 OR roughness ≠ 0.5
OR color ≠ 0xCCCCCC). If everything matches the baker-default
grey-plastic recipe, the test fails — that's the exact failure
mode Bernhard's screenshots showed.

Strict ``xfail`` today (the bug is open upstream); flips green when
mat-vis-client 0.7.x ships PR mat-vis#294's baker fix and py-mat
picks it up via ``>=mat-vis-client``.

## .github/CODEOWNERS

Lists @gerchowl as code owner of:

- ``CHANGELOG.md``, ``.release-please-manifest.json``,
  ``release-please-config.json`` — every release-please PR auto-
  requests his review.
- ``src/pymat/data/**``, ``src/pymat/vis/**`` — vis surface and
  TOML changes that can shift the rendered look.
- The visual-regression machinery
  (``tests/test_visual_regression.py``, ``tests/visual_render.html``,
  ``scripts/generate_previews.py``, the workflow files).

Pair with branch-protection rule "Require review from Code Owners"
on ``main`` for this to actually block merge — CODEOWNERS alone only
auto-assigns the request.

## release-please-config.json

Adds a single line to the release-reviewer checklist:

    - [ ] **Visual regression artifacts inspected** — download the
      latest catalog-previews / visual-regression workflow artifacts
      (incl. ``bernhard_285_grid_*.png`` at all baked tiers); confirm
      metals look metallic, glass transparent, distinct hues across
      the grid. See mat-vis #285 for the failure shape this gate
      exists to catch.

Surgical one-line edit (preserves the existing array formatting +
em-dashes that a json.dump round-trip would mangle).

Closes the verification gap surfaced in build123d#1270: running our
own test suite or Bernhard's integration tests passed cleanly even
while the substrate was visually broken. The combination of the
strict-xfail test (catches it on every run) + the reviewer checklist
+ CODEOWNERS auto-request (catches it before merge) makes the visual
regression first-class in the release flow.
Replaces the single TestBernhardMatVis285Grid with a comprehensive
matrix of py-mat's substrate → adapter → renderer pipeline. 33
parametrized tests covering:

## TestBernhardMatVis285_AdapterStructure_Textured (10 tests)

(to_threejs, to_gltf) × (1k, 512, 256, ktx2-1k, ktx2-512). Per-tier
structural validation of the textured 24-material grid: dict shape
right, scalar-fingerprint catches the mat-vis #285 default-grey
regression. Strict-xfail on the scalar count assertion until
substrate re-bakes.

## TestBernhardMatVis285_AdapterStructure_Scalar (10 tests)

(to_threejs, to_gltf) × (Aluminum, Gold, Iron, Copper, Plastic-
Acrylic). Closes the test-coverage gap from mat-vis #313 / py-mat
#222: scalar-only physicallybased path must not raise
MaterialNotStagedError. Strict-xfail.

## TestBernhardMatVis285_Ktx2Bytes (1 test)

At tier='ktx2-1k', texture bytes must start with the KTX2 magic
header (b'\\xabKTX 20\\xbb\\r\\n\\x1a\\n'). Catches a substrate
regression where the KTX2 path silently falls back to PNG.

## TestBernhardMatVis285_MtlxExport (1 test)

Vis.mtlx.export(dir) writes a self-contained .mtlx package; XML
parses, surfacematerial nodes present, every <image file=...>
attribute resolves to a sibling PNG on disk. Doesn't run an
actual MaterialX renderer — that's downstream.

## TestBernhardMatVis285_Visual (4 tests)

Renders Bernhard's grid via headless Three.js — bypassing
build123d's glTF exporter entirely. Material specs come from
to_threejs(vis); JS-side viewer instantiates THREE.MeshPhysical-
Material directly; sphere geometry is created in JS. Isolates
py-mat's surface from any downstream consumer's export-pipeline
gaps.

Parametrized: (textured, 1k/512/256) + (scalar, scalar). Output:
4 PNG artifacts per release + sidecar JSON with stripped scalars
for human review. Strict-xfail until #285 re-bake.

## tests/visual_grid_render.html

New programmatic Three.js viewer. Loads a JSON spec listing
material spec dicts; instantiates one MeshPhysicalMaterial per
spec; renders 5×5 grid of spheres. Bypasses glTF entirely — every
texture data URI from to_threejs() is fed directly into
TextureLoader, no glTF middleware. Uses Three.js's RoomEnvironment
HDRI proxy + FOV-aware camera framing for full-scene visibility.

## Reviewer gate (release-please-config.json)

Existing checklist line still applies — but now the artifacts to
inspect are bernhard_grid_textured_*.png + bernhard_grid_scalar_-
scalar.png across all 4 (scene, tier) combinations.

Refs build123d#1270, mat-vis #285, mat-vis #294, mat-vis #298,
mat-vis #313, mat-vis #340, py-mat #99, py-mat #100, py-mat #220-222
@gerchowl
gerchowl force-pushed the feature/3.12-visual-285-grid branch from 9c5b607 to 3ad65a1 Compare May 7, 2026 16:06
PR #225's #222 fix (graceful scalar-only sources) cascaded into
PR #223's TestBernhardMatVis285_AdapterStructure_Scalar (10 tests)
and the scalar-only param of TestBernhardMatVis285_Visual — both
were strict-xfail on the assumption that physicallybased path
raises MaterialNotStagedError.

That assumption no longer holds: #225 auto-resolves tier→"scalar"
in __post_init__ and short-circuits Vis._fetch when the source
is scalar-only. The 10 + 1 tests now pass.

Drop the strict-xfail markers:
- TestBernhardMatVis285_AdapterStructure_Scalar — class-level xfail
  removed entirely; tests pass directly.
- TestBernhardMatVis285_Visual.test_grid_renders_at_tier — split
  the xfail per-param via pytest.param(..., marks=...). Textured
  params (1k, 512, 256) keep their strict-xfail until upstream
  re-bakes for #285. The scalar-only param drops the xfail.

Updated docstring on the scalar adapter class to reflect the new
state: upstream mat-vis #313 stays open, but py-mat consumers no
longer hit the symptom thanks to #225's substrate-bypass.
@gerchowl
gerchowl merged commit a2b5be5 into main May 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant