Add property-based tests for produce#60
Merged
Merged
Conversation
Extend the Hypothesis suite to cover produce() directly. A deterministic interpreter replays a generated "program" of random mutations against both a proxy-wrapped draft (via produce) and a plain reference copy, asserting: - transparency: proxy mutations compute the same state as plain mutations - forward fidelity: emitted patches carry the base to the result - reverse round-trip: reverse patches restore the base - purity: in_place=False leaves the base untouched - in_place=True parity: same result and patches as the copying path - agreement with diff: produce's and diff's patches reach the same result Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016Mu9vEBwU4fQLi8ZgkgdS2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the Hypothesis suite (
tests/test_properties.pycurrently coversdiff/apply/to_json) with a dedicated module,tests/test_produce_properties.py, that fuzzesproduce()directly.produce()is the most intricate part of the codebase — an Immer-style proxy layer with parent-link path tracking, detach semantics, and location memoization — and the existing produce tests spot-check individual proxy methods one at a time. These property tests exercise the proxies under arbitrary sequences of mutations against arbitrary nested drafts and pin the invariants that must hold for every recipe.Approach
A deterministic interpreter replays a Hypothesis-generated "program" (a list of integer choices) against two structures in lockstep:
produce(), andBecause equivalent operations keep both structures identical step-for-step, the interpreter navigates to corresponding nodes and makes the same choices on both sides — which is what lets the produced
resultbe compared against the reference directly. The generated recipes cover dict (__setitem__,__delitem__,pop,setdefault,update), list (append,insert,__setitem__,__delitem__,pop,reverse), and set (add,discard,update) mutations, at arbitrary depth. Set operations are restricted to value-driven ones, since selecting an existing member by position would diverge between two unordered sets.Invariants asserted
patches, applied to the original base, reproduce the result.reversepatches, applied to the result, restore the base.in_place=False, the base is left untouched.in_place=Trueparity — mutating the base directly yields the same result and the same patches as the copying path.diff—produce's patches anddiff(base, result)both carry the base to the same result.Verification
uv run pytest— 411 passed, 62 skipped (3 new; no source changes, so 100% coverage ofpatchdiff/is unaffected).--hypothesis-seed=random.uv run ruff check/ruff format --check/uv run ty checkall pass.Test-only change; no runtime code is touched.
Generated by Claude Code