Skip to content

Add Python Hypothesis emit kit#1632

Merged
TSavo merged 1 commit into
mainfrom
codex/python-hypothesis-parity-20260529
May 29, 2026
Merged

Add Python Hypothesis emit kit#1632
TSavo merged 1 commit into
mainfrom
codex/python-hypothesis-parity-20260529

Conversation

@TSavo
Copy link
Copy Markdown
Owner

@TSavo TSavo commented May 29, 2026

Summary

  • add provekit-emit-python-hypothesis as a separate Python emitter artifact
  • register the python-hypothesis emit surface through project config and manifest
  • emit native Hypothesis tests using @given(data=st.data()) for supported normalized predicates
  • report unsupported predicates honestly with incomplete status

Verification

  • PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=implementations/python/provekit-emit-python-hypothesis/src python3 -m pytest -p no:cacheprovider implementations/python/provekit-emit-python-hypothesis/tests implementations/python/provekit-emit-python-pytest/tests -q
  • TOML parse check for implementations/python/.provekit/config.toml, implementations/python/.provekit/emit/python-hypothesis/manifest.toml, and implementations/python/provekit-emit-python-hypothesis/pyproject.toml
  • git diff --check

Known Gap

  • This PR adds the Hypothesis emitter only. A Hypothesis lifter is still a separate parity gap.

Summary by CodeRabbit

  • New Features
    • Python Hypothesis emitter plugin now available for generating property-based tests.
    • Supports comparison predicates (equality, inequality, ordering) and option/None checks.
    • Features JSON-RPC interface with integrated test execution and validation capabilities.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4dae068-103d-44a4-a81c-59639d9fd120

📥 Commits

Reviewing files that changed from the base of the PR and between d4e1453 and b90ea50.

📒 Files selected for processing (11)
  • implementations/python/.provekit/config.toml
  • implementations/python/.provekit/emit/python-hypothesis/manifest.toml
  • implementations/python/provekit-emit-python-hypothesis/README.md
  • implementations/python/provekit-emit-python-hypothesis/pyproject.toml
  • implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/__init__.py
  • implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/__main__.py
  • implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/emitter.py
  • implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/plugin_memento.py
  • implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/rpc.py
  • implementations/python/provekit-emit-python-hypothesis/tests/test_emitter.py
  • implementations/python/provekit-emit-python-hypothesis/tests/test_rpc.py

Walkthrough

This PR introduces a complete Python Hypothesis emitter plugin for Provekit. It converts neutral predicate specifications into Hypothesis-based property tests, handling binary comparisons and option checks. The implementation includes plugin registration, core transformation logic with strategy-backed variable binding, plugin metadata/capabilities, a JSON-RPC server interface, and comprehensive tests validating both the emitter and RPC dispatch behavior.

Changes

Python Hypothesis Emitter Plugin

Layer / File(s) Summary
Configuration and package setup
implementations/python/.provekit/config.toml, implementations/python/.provekit/emit/python-hypothesis/manifest.toml, implementations/python/provekit-emit-python-hypothesis/pyproject.toml, implementations/python/provekit-emit-python-hypothesis/README.md, implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/__init__.py, implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/__main__.py
Provekit registration declares the python-hypothesis emit plugin via config and manifest TOML files; Python package is configured with hatchling, console entry point to __main__:main, runtime dependencies (blake3, hypothesis), and pytest discovery; __init__.py re-exports emitter types, __main__.py wires the --rpc CLI flag to the RPC server.
Hypothesis emitter core logic
implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/emitter.py, implementations/python/provekit-emit-python-hypothesis/tests/test_emitter.py
EmitPlan normalizes contract/function/parameter/predicate metadata; Emission holds generated source, CID, emitted/unsupported predicate heads, and completion status. emit() iterates predicates, extracts heads, and dispatches to binary (eq/ne/lt/gt/le/ge) or option (none/some) renderers; each generates a @given(data=st.data()) Hypothesis test function. _assign_var_var and _assign_var_const build constrained integer strategies; _render_option handles None/non-None unions. Tests verify dependent integer draws, ge/le to bounded strategy translation, unsupported predicate gaps, and subprocess pytest execution.
Plugin memento and capabilities
implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/plugin_memento.py
Declares plugin identity (version 0.1.0, PEP 1.7.0 protocol), JSON canonicalization for deterministic hashing, and BLAKE3-512 CID computation. plugin_content(), plugin_header(), and plugin_memento() construct the complete capability declaration including supported predicate list and target framework (Python/Hypothesis).
JSON-RPC server and dispatch
implementations/python/provekit-emit-python-hypothesis/src/provekit_emit_python_hypothesis/rpc.py
run_rpc() reads newline-delimited JSON from stdin, dispatches to describe (returns memento), invoke (builds plan and returns emission), check (runs pytest and captures stdout/stderr/exit code), or shutdown; error handling returns JSON-RPC error codes for parse failures (-32700) and unexpected exceptions (-32603).
Emitter and RPC tests
implementations/python/provekit-emit-python-hypothesis/tests/test_emitter.py, implementations/python/provekit-emit-python-hypothesis/tests/test_rpc.py
Unit tests validate emitted source structure, dependent integer draws, predicate-to-strategy mapping, and unsupported predicate handling; RPC tests verify describe response shape, invoke emission output/metadata, unsupported gap reporting, shutdown behavior, and parameter validation errors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Whiskers twitch with property-test delight,
Neutral predicates spin into Hypothesis bright,
@given decorators dance, strategies aligned,
Blake3 hashes bind the plugin's design—
A JSON-RPC rabbit hole, tests shine so fine!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/python-hypothesis-parity-20260529

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98be04f8fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const_eval: Callable[[Any, Any], bool],
) -> bool:
if left.has_const and right.has_const:
return bool(const_eval(left.const_value, right.const_value))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return a gap for invalid constant comparisons

When both operands are literal constants, this eagerly calls the Python comparison operator; for otherwise accepted literals whose ordering is undefined in Python, such as concept:lt with None and 1 or a string and an integer, operator.lt raises TypeError. That escapes emit() and becomes a JSON-RPC internal error instead of the unsupported-predicate gap this emitter uses for unrenderable predicate slices, so a single mixed-type constant predicate can abort the whole emit request.

Useful? React with 👍 / 👎.

@TSavo TSavo force-pushed the codex/python-hypothesis-parity-20260529 branch from 98be04f to b90ea50 Compare May 29, 2026 19:04
@TSavo TSavo merged commit 1890ff8 into main May 29, 2026
2 of 6 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