Skip to content

Add property-based tests for produce#60

Merged
Korijn merged 1 commit into
masterfrom
claude/produce-property-tests
Jul 13, 2026
Merged

Add property-based tests for produce#60
Korijn merged 1 commit into
masterfrom
claude/produce-property-tests

Conversation

@Korijn

@Korijn Korijn commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Extends the Hypothesis suite (tests/test_properties.py currently covers diff/apply/to_json) with a dedicated module, tests/test_produce_properties.py, that fuzzes produce() 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:

  • a proxy-wrapped draft, via produce(), and
  • a plain reference copy, mutated directly.

Because 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 result be 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

  • Transparency — mutating through the proxies yields the same final state as the same mutations on a plain copy.
  • Forward fidelity — the emitted patches, applied to the original base, reproduce the result.
  • Reverse round-trip — the reverse patches, applied to the result, restore the base.
  • Purity — with in_place=False, the base is left untouched.
  • in_place=True parity — mutating the base directly yields the same result and the same patches as the copying path.
  • Agreement with diffproduce's patches and diff(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 of patchdiff/ is unaffected).
  • New tests run cleanly across repeated runs and with --hypothesis-seed=random.
  • uv run ruff check / ruff format --check / uv run ty check all pass.

Test-only change; no runtime code is touched.


Generated by Claude Code

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
@Korijn
Korijn merged commit a1c650d into master Jul 13, 2026
11 checks passed
@Korijn
Korijn deleted the claude/produce-property-tests branch July 13, 2026 11:51
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