Skip to content

Refactor test output paths and make CliOptions immutable#32

Draft
ppenenko wants to merge 2 commits into
metashade/devfrom
metashade/fix-shader-baseline-copy
Draft

Refactor test output paths and make CliOptions immutable#32
ppenenko wants to merge 2 commits into
metashade/devfrom
metashade/fix-shader-baseline-copy

Conversation

@ppenenko

@ppenenko ppenenko commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Make CliOptions frozen (immutable); move output_dir and flat_layout to RenderEnvironment so each environment owns its paths.
  • Default --output-dir to contrib/ (the common root); environments append renders/, renders/adsk/, tests/metashade_ref/renders/<sub>.
  • Remove --render-output-dir, shader_baseline_dir, _RefDiffer, and _handle_shader_baselines — all now redundant.
  • Collapse OVERRIDE_SUBDIR / OUTPUT_SUBDIR into a single SUBDIR field.
  • Rename self.options to self.cli_options for clarity.

Motivation

The previous output-path plumbing grew organically and accumulated redundant fields (shader_baseline_dir, render_output_dir) and a copy step (_handle_shader_baselines / _RefDiffer) that was a no-op in local dev and caused a PermissionError on Windows when source and destination were the same file.

This refactor makes the path hierarchy explicit:

  1. cli_options.output_dir — CLI root (default contrib/)
  2. Per-environment subdirectory — e.g. renders/, renders/adsk/, tests/metashade_ref/renders/<subdir>
  3. Per-test leaf — appended by get_output_path()

Test plan

  • All 75 Metashade override tests pass (test_render_metashade.py)
  • Full test_render.py suite passes (stdlib + adsk environments)

When output_dir and shader_baseline_dir resolve to the same directory,
shutil.copy2 fails on Windows (PermissionError copying a file onto
itself).  The copy was unnecessary: rendertest already dumps shaders
directly into the baseline directory during local development.  Simplify
the function to only run the _RefDiffer comparison in CI mode (when
render_output_dir is set).

Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the shader-baseline handling in the render test suite by removing the “update mode” baseline-copy path from _handle_shader_baselines, leaving only baseline comparison behavior intended for CI runs.

Changes:

  • Removed the shutil.copy2 update-mode branch from _handle_shader_baselines.
  • Tightened the guard so shader baseline handling only runs when render_output_dir is set (CI mode).
  • Updated the function docstring to reflect CI-only comparison intent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contrib/tests/test_render.py Outdated
Comment on lines +456 to +460
"""Compare dumped shaders against committed baselines in CI mode.

* **Update mode** (no ``render_output_dir``): copy dumped shaders into
the committed baseline directory for ``git diff`` review.
* **CI mode** (``render_output_dir`` set): compare dumped shaders
against the committed baselines and assert on mismatch.
Requires both ``shader_baseline_dir`` and ``render_output_dir`` to be
set. Shaders are dumped directly into the baseline directory during
local development (no copy step needed).
Comment thread contrib/tests/test_render.py Outdated
Comment on lines +462 to +469
if (not result.shader_dump_paths or not opts.shader_baseline_dir
or not opts.render_output_dir):
return
baseline_subdir = opts.shader_baseline_dir / stem
if opts.render_output_dir:
differ = _RefDiffer(baseline_subdir)
for dump_path in result.shader_dump_paths.values():
if (baseline_subdir / dump_path.name).exists():
differ(dump_path)
else:
import shutil
baseline_subdir.mkdir(parents=True, exist_ok=True)
for dump_path in result.shader_dump_paths.values():
shutil.copy2(dump_path, baseline_subdir / dump_path.name)
differ = _RefDiffer(baseline_subdir)
for dump_path in result.shader_dump_paths.values():
if (baseline_subdir / dump_path.name).exists():
differ(dump_path)
- Make CliOptions frozen; move output_dir and flat_layout to
  RenderEnvironment so each environment owns its paths.
- Default --output-dir to contrib/ (the common root); environments
  append renders/, renders/adsk/, tests/metashade_ref/renders/<sub>.
- Remove --render-output-dir, shader_baseline_dir, _RefDiffer, and
  _handle_shader_baselines (all now redundant).
- Collapse OVERRIDE_SUBDIR / OUTPUT_SUBDIR into single SUBDIR field.
- Rename self.options → self.cli_options for clarity.

Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
@ppenenko ppenenko changed the title Remove shader baseline copy step from _handle_shader_baselines Refactor test output paths and make CliOptions immutable Jul 17, 2026
@ppenenko
ppenenko requested a review from Copilot July 17, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment on lines +25 to 28
"""Paths for Metashade reference data, relative to ``--output-dir``."""
ROOT = Path("tests") / "metashade_ref"
LIBRARIES = ROOT / "libraries"
RENDERS = ROOT / "renders"
)

libraries_dir = repo_root / _RefPaths.LIBRARIES
libraries_dir = cli_options.output_dir / _RefPaths.LIBRARIES
Comment on lines +139 to +140
output_dir = cli_options.output_dir / _RefPaths.RENDERS / subdir
output_dir.mkdir(parents=True, exist_ok=True)
Comment on lines +45 to +46
Per-environment settings (``output_dir``, ``flat_layout``) live on
:class:`RenderEnvironment`.
@ppenenko
ppenenko marked this pull request as draft July 17, 2026 14:38
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.

2 participants