Skip to content

Add regression test: RampedHalfAndHalf initializer does not respect max_depth (#259) - #405

Merged
alcides merged 1 commit into
mainfrom
cursor/rhh-max-depth-regression-test-92b1
Aug 31, 2026
Merged

Add regression test: RampedHalfAndHalf initializer does not respect max_depth (#259)#405
alcides merged 1 commit into
mainfrom
cursor/rhh-max-depth-regression-test-92b1

Conversation

@alcides

@alcides alcides commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a strict-xfail regression test documenting issue #259: RampedHalfAndHalfInitializer accepts a max_depth argument but does not respect it.

No production code is changed in this PR — the test is living evidence of the bug, and will start failing (via xfail(strict=True)) the moment the bug is fixed, prompting removal of the marker.

Root cause (for reference)

RampedHalfAndHalfInitializer.__init__ stores max_depth, but initialize() calls representation.create_genotype(random) without passing a depth-bounded decider, so the representation's default decider is used and max_depth is silently ignored (compare with FullInitializer, which passes its own depth-bounded FullDecider). It also does not do any ramping or grow/full alternation, contrary to its docstring.

How to run

uv run pytest tests/representations/tree_based/initializer_test.py::TestInitializers::test_ramped_half_and_half_respects_max_depth -v

Currently reports XFAIL. To see the underlying failure, remove the xfail marker and run again.

Evidence (assertion output without the xfail marker)

The test builds a tiny recursive grammar (ExprLeaf | Branch(Expr, Expr)), requests a population of 20 from RampedHalfAndHalfInitializer(max_depth=3) with a fixed seed (NativeRandomSource(5)), and asserts every individual's depth is ≤ 3:

E       AssertionError: RampedHalfAndHalfInitializer(max_depth=3) produced trees with depths [9, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 6, 5]
E       assert False

Expected: all depths ≤ 3. Actual: 5 of 20 individuals exceed the limit (depths 4, 5, 5, 6, and 9).

Checks

  • uv run pytest: 520 passed, 8 skipped, 1 xfailed (the new test)
  • ruff check . --fix: all checks passed

Closes nothing; references #259.

Open in Web Open in Cursor 

)

Co-authored-by: Alcides Fonseca <me@alcidesfonseca.com>
@alcides alcides mentioned this pull request Aug 31, 2026
@alcides
alcides marked this pull request as ready for review August 31, 2026 09:15
@alcides
alcides merged commit 8234bf8 into main Aug 31, 2026
8 checks passed
@alcides
alcides deleted the cursor/rhh-max-depth-regression-test-92b1 branch August 31, 2026 09:15
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