Skip to content

Add Random effect for non-determinism (closes #465, v0.0.115)#492

Merged
aallan merged 6 commits into
mainfrom
random-effect
Apr 20, 2026
Merged

Add Random effect for non-determinism (closes #465, v0.0.115)#492
aallan merged 6 commits into
mainfrom
random-effect

Conversation

@aallan

@aallan aallan commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Summary

New built-in Random effect with three operations. Closes #465.

  • Random.random_int(@Int, @Int) -> @Int — inclusive range [low, high]
  • Random.random_float(@Unit) -> @Float64 — uniform [0.0, 1.0)
  • Random.random_bool(@Unit) -> @Bool — coin flip

Functions drawing random values declare effects(<Random>), making non-determinism visible in the type signature. Mirrors the Http/Inference host-import pattern: ops are tracked via _random_ops_used, dispatched through prefixed WASM imports (vera.random_int etc.), and backed by Python's random module (Python runtime) or Math.random() (browser runtime).

No seeding API yet — handler-based deterministic testing via handle[Random] is explicitly noted as future work.

Why it matters

Unblocks games, simulations, shuffling, Monte Carlo methods, and randomized initial states. Was flagged as "transformative" by the Conway's Life model that drove #463 — needed alongside IO.sleep to go from "dump 20 static frames" to "animated random cellular automaton."

Tests

  • tests/conformance/ch07_random_effect.vera — verify level (no run-level assertions; randomness makes them flaky). Covers signature plumbing.
  • tests/test_codegen.py::TestRandomEffect — 4 tests: inclusive range, singleton range, float in [0, 1), bool distribution (Bernoulli bounded).
  • tests/test_browser.py — 3 parallel browser tests confirming Math.random paths behave in-distribution.

Documentation

Version bump

v0.0.114 → v0.0.115. Tagged on branch; will move to main HEAD after merge.

Test plan

  • mypy vera/ clean
  • pytest tests/ -q — 3,355 passed, 13 skipped (7 new)
  • All pre-commit hooks green (including uv-lock-check from the last PR)
  • vera run on a program using all three Random ops

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Built-in Random effect with operations random_int, random_float, random_bool; IO gains sleep, time and stderr operations.
  • Tests

    • Added runtime and codegen tests validating Random behaviour and distributions.
    • Conformance suite increased to 76 programs (new verify-level case).
  • Chores

    • Release bumped to v0.0.115; package metadata and project docs updated to reflect changes.

New built-in `Random` effect with three operations:

- Random.random_int(@int, @int) -> @int   # inclusive range
- Random.random_float(@Unit) -> @float64  # uniform [0.0, 1.0)
- Random.random_bool(@Unit) -> @Bool      # coin flip

Functions drawing random values declare `effects(<Random>)`, making
non-determinism visible in the type signature.  Mirrors the
Http/Inference host-import effect pattern.

Implementation trail:

- environment.py: new EffectInfo for Random with three OpInfo
  entries using INT/UNIT/FLOAT64/BOOL types.
- codegen/compilability.py: `elif eff.name == "Random"` in the
  effect allowlist (no memory requirement — no allocations or heap
  returns).  Scan adds Random QualifiedCall op names to
  `_random_ops_used`.
- codegen/core.py: new `_random_ops_used: set[str]` field and
  propagation to all four CompileResult construction sites.
- codegen/functions.py: propagate from WasmContext back to core.
- codegen/assembly.py: three import declarations gated on
  `_random_ops_used`:
    (import "vera" "random_int" (func $vera.random_int (param i64 i64) (result i64)))
    (import "vera" "random_float" (func $vera.random_float (result f64)))
    (import "vera" "random_bool" (func $vera.random_bool (result i32)))
- codegen/api.py: host_random_int / host_random_float /
  host_random_bool using Python's `random` module.  Lazy import —
  only pulled in when `random_ops_used` is non-empty.
  CompileResult gains a `random_ops_used` field.
- wasm/calls.py: Random joins `_host_import_qualifiers`; dispatch
  emits `call $vera.random_{int,float,bool}` and tracks via
  `_random_ops_used`.  Op names already begin with `random_`, so no
  double-prefixing like http_/inference_ needed.
- wasm/context.py: `_random_ops_used` set initialized for mixin
  propagation.  `_is_void_expr` explicitly returns False for
  Random qualifiers (all three ops produce values).
- browser/runtime.mjs: three Math.random-backed handlers.
  random_int uses BigInt arithmetic for i64 boundary.

Tests:

- tests/conformance/ch07_random_effect.vera — verify level; covers
  signature plumbing and effect-row carrying without wall-clock
  flake.
- tests/test_codegen.py: TestRandomEffect with 4 tests exercising
  inclusive range, singleton range, float unit interval, and
  bool distribution (Bernoulli bounded away from extremes).
- tests/test_browser.py: 3 parallel browser tests confirming
  Math.random-based paths behave identically (in distribution).

Documentation:

- SKILL.md: new "Random effect" subsection; effects-row example
  list updated.
- spec/07-effects.md: §7.7.4 `Random` added after Diverge; §7.7.1
  IO table updated from 7 → 10 ops (missed when shipping #463).
- spec/12-runtime.md: §12.4.5 Random Operations added with
  §12.4.5.1/2/3 subsections for the three ops; §12.2.2 import
  table gets three new rows.
- FAQ.md: built-in effects list gains `<Random>`.
- Doc-count sweep: 75 → 76 conformance, 3,356 → 3,368 tests, plus
  test-file line drift.

Also bundled: ROADMAP → HISTORY shuffle for #465 (per workflow —
closing PR owns the shuffle).  Version bump 0.0.114 → 0.0.115 in
pyproject.toml, vera/__init__.py, docs/index.html, README.md, and
uv.lock.

Co-Authored-By: Claude <noreply@anthropic.invalid>
@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.95455% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.25%. Comparing base (b23bd56) to head (f1ee528).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
vera/browser/runtime.mjs 73.46% 13 Missing ⚠️
vera/wasm/context.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
- Coverage   90.28%   90.25%   -0.04%     
==========================================
  Files          58       58              
  Lines       20052    20137      +85     
  Branches      228      233       +5     
==========================================
+ Hits        18104    18174      +70     
- Misses       1944     1959      +15     
  Partials        4        4              
Flag Coverage Δ
javascript 51.99% <73.46%> (+0.47%) ⬆️
python 95.07% <94.87%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a built-in Random effect (ops: random_int, random_float, random_bool), bumps package to v0.0.115, increases conformance suite size (75→76), registers and tracks Random through the type environment and compiler, emits WASM host imports, provides Python/browser runtime bindings, and adds tests and docs.

Changes

Cohort / File(s) Summary
Version & Packaging
pyproject.toml, vera/__init__.py
Bumped package version to 0.0.115.
Changelog / History
CHANGELOG.md, HISTORY.md
Added v0.0.115 release entry documenting Random effect and updated compare links.
Documentation & Guides
AGENTS.md, CLAUDE.md, FAQ.md, README.md, SKILL.md, TESTING.md
Updated conformance count (75→76), added Random to effects lists, and documented usage (effects(<Random>)) and examples.
Roadmap / Project Metrics
ROADMAP.md
Removed #465 (Random effect) from near-term queue, reordered items, and updated release/test/commit metrics.
Language Spec — Effects
spec/07-effects.md
Added built-in Random effect declaration; extended IO ops (sleep, time, stderr).
Runtime Spec
spec/12-runtime.md
Documented WASM import signatures and runtime contracts for Random ops and host behaviours.
Type Environment
vera/environment.py
Registered Random effect and three operations in built-in effect registry.
Compiler: Core State
vera/codegen/core.py
Added self._random_ops_used and ensured CompileResult.random_ops_used is propagated on all return paths.
Compiler: API / Execute
vera/codegen/api.py
Added random_ops_used to CompileResult; conditional Python host bindings for vera.random_int/float/bool during execute.
Compiler: Assembly
vera/codegen/assembly.py
Emit conditional WAT imports for random_int, random_float, random_bool when used.
Compiler: Compilability & Scanning
vera/codegen/compilability.py, vera/codegen/functions.py
Whitelisted Random as compilable; scanning records Random.* ops and propagates tracking through function compilation.
WASM Codegen Context & Calls
vera/wasm/context.py, vera/wasm/calls.py
Added _random_ops_used to WasmContext; treat Random calls as non-void, emit call $vera.{op} and avoid $alloc for these ops.
Browser Runtime
vera/browser/runtime.mjs
Added imports.vera.random_int, imports.vera.random_float, imports.vera.random_bool using Math.random() with BigInt/safety checks and validation errors.
Tests: Conformance Manifest
tests/conformance/manifest.json
Added ch07_random_effect verify-level manifest entry covering Random ops.
Tests: Runtime & Codegen
tests/test_browser.py, tests/test_codegen.py
Added browser runtime tests and TestRandomEffect suite verifying ranges, float interval and boolean outcomes; codegen tests check WAT imports and runtime contracts.
Spec / Skill allowlists
scripts/check_spec_examples.py, scripts/check_skill_examples.py
Adjusted allowlist line numbers to reflect doc edits; no logic changes.
Misc. docs & CI text
AGENTS.md, CLAUDE.md, TESTING.md, CHANGELOG.md, ROADMAP.md
Consistent project-metadata updates (counts, refs, CI/conformance wording).

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Compiler as Compiler
    participant Wasm as WasmModule
    participant Host as HostRuntime

    Dev->>Compiler: compile program with effects(<Random>)
    Compiler->>Compiler: record random_ops_used
    Compiler->>Wasm: emit WAT imports for vera.random_*
    Dev->>Wasm: instantiate WasmModule (provide imports)
    Host->>Wasm: provide imports.vera.random_* (Python random / Math.random)
    Wasm->>Host: call vera.random_int/float/bool
    Host-->>Wasm: return random value
    Wasm-->>Dev: program produces non-deterministic output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

compiler, tests, spec, ci, docs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title precisely captures the main change: adding a Random effect for non-determinism with issue closure and version bump.
Linked Issues check ✅ Passed All objectives from #465 are met: Random effect with three ops (random_int inclusive, random_float in [0.0,1.0), random_bool), effects() tracking, host imports via Python/browser runtimes, and per-op usage tracking via _random_ops_used.
Out of Scope Changes check ✅ Passed All changes are scoped to Random effect implementation: specification, codegen wiring, runtime bindings, tests, and documentation. Version bump and test suite metrics are direct consequences.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch random-effect

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ROADMAP.md`:
- Line 11: The ROADMAP.md summary line omits the newly added algebraic effect
Random; update the sentence listing effects to include "Random" among (IO, Http,
State, Exceptions, Async, Inference) so it reads e.g. "(IO, Http, State,
Exceptions, Async, Inference, Random)"; ensure the wording around "algebraic
effects" in the same sentence (the line describing built-in functions and
effects) is adjusted accordingly and remains grammatically correct.

In `@spec/12-runtime.md`:
- Line 406: Update the import declaration so the external import name matches
the function symbol: change the import string that currently says "random_int"
to "random_bool" for the declaration that defines (func $vera.random_bool
(result i32)), ensuring the imported module name "vera" remains unchanged.

In `@tests/test_codegen.py`:
- Around line 10271-10273: The probabilistic assertion should be replaced with a
deterministic seeded run that verifies both outcomes occur: seed the RNG (e.g.,
call random.seed(0) or the appropriate PRNG used by the code) before executing
the function, run execute(result, fn_name="main") multiple times (e.g., 100),
collect the .value results into a set, and assert that both 0 and 1 are present
(e.g., assert {0,1}.issubset(observed) or assert observed == {0,1}) so the test
is stable and still exercises both Bernoulli outcomes (reference: execute(...,
fn_name="main") and the random_bool usage).
- Around line 10220-10221: The test currently only checks len(produced) >= 4
which doesn't verify inclusive-boundary semantics; update the assertion logic in
tests/test_codegen.py to explicitly assert that both boundary values appear by
adding checks that low in produced and high in produced (in addition to the
existing distribution check), referencing the existing variables produced, low,
and high so the test enforces the [low, high] contract.
- Around line 10188-10274: Add per-operation WAT import-gating assertions to
each Random effect test (e.g., test_random_int_in_range,
test_random_int_singleton_range, test_random_float_in_unit_interval,
test_random_bool_produces_both): after calling _compile_ok(source) inspect the
compiled module's WAT (or the string returned on the result object) and assert
that the specific host import for the operation used in that test
(Random.random_int, Random.random_float, or Random.random_bool) is present and
that the other Random operation imports are absent; this ensures
_random_ops_used gating is exercised and prevents emitting unused sibling
imports.

In `@vera/browser/runtime.mjs`:
- Around line 1738-1744: The random_int implementation (imports.vera.random_int)
converts BigInt bounds (lowBig, highBig) to Number which loses precision for
values outside the 53-bit safe-integer range; add a runtime guard that checks
that both lowBig and highBig are within
Number.MIN_SAFE_INTEGER..Number.MAX_SAFE_INTEGER and that highBig >= lowBig, and
if not throw a descriptive Error (e.g. "random_int bounds exceed JavaScript safe
integer range; use smaller bounds or adjust runtime") so callers get a clear
failure instead of silently incorrect span/return values; keep the existing
logic (low/high/span) only when the guard passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e60d4e73-5419-4cb4-b132-f2908befdcd5

📥 Commits

Reviewing files that changed from the base of the PR and between b23bd56 and 0f3049b.

⛔ Files ignored due to path filters (8)
  • docs/SKILL.md is excluded by !docs/**
  • docs/index.html is excluded by !docs/**
  • docs/index.md is excluded by !docs/**
  • docs/llms-full.txt is excluded by !docs/**
  • docs/llms.txt is excluded by !docs/**
  • docs/sitemap.xml is excluded by !docs/**
  • tests/conformance/ch07_random_effect.vera is excluded by !**/*.vera
  • uv.lock is excluded by !**/*.lock, !uv.lock
📒 Files selected for processing (25)
  • AGENTS.md
  • CHANGELOG.md
  • CLAUDE.md
  • FAQ.md
  • HISTORY.md
  • README.md
  • ROADMAP.md
  • SKILL.md
  • TESTING.md
  • pyproject.toml
  • spec/07-effects.md
  • spec/12-runtime.md
  • tests/conformance/manifest.json
  • tests/test_browser.py
  • tests/test_codegen.py
  • vera/__init__.py
  • vera/browser/runtime.mjs
  • vera/codegen/api.py
  • vera/codegen/assembly.py
  • vera/codegen/compilability.py
  • vera/codegen/core.py
  • vera/codegen/functions.py
  • vera/environment.py
  • vera/wasm/calls.py
  • vera/wasm/context.py

Comment thread ROADMAP.md Outdated
Comment thread spec/12-runtime.md
Comment thread tests/test_codegen.py
Comment thread tests/test_codegen.py Outdated
Comment thread tests/test_codegen.py Outdated
Comment thread vera/browser/runtime.mjs
aallan and others added 2 commits April 18, 2026 12:42
The IO operations table at §7.7.1 grew from 7 → 10 rows in this PR
(adding sleep/time/stderr ops listed since #463/v0.0.114).  That
shifted every subsequent line in spec/07-effects.md down by 3,
including two existing allowlisted code blocks:

- effect Diverge {} (line 315 → 318) — empty body needs FRAGMENT
- fn foo calls undefined bar/baz (line 367 → 390) — needs INCOMPLETE

Updated both entries in scripts/check_spec_examples.py.
fix_allowlists.py didn't catch the drift (it only handles a subset
of pattern shifts); manual update.  CI lint's check_spec_examples
.py step now passes locally.

Co-Authored-By: Claude <noreply@anthropic.invalid>
…ing 1)

Part of addressing the #492 review cycle; committed separately so the
branch is in a valid state between sessions.

Remaining findings to address on resume:
- Declined: finding 2 (spec/12 import name already correct; CodeRabbit misread)
- Fix: finding 3 (random_bool test — seed + both-outcomes assertion)
- Fix: finding 4 (random_int test — assert boundary values in produced set)
- Fix: finding 5 (per-test WAT import-gating assertions)
- Fix: finding 6 (browser random_int — BigInt safe-integer range guard)

Co-Authored-By: Claude <noreply@anthropic.invalid>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ROADMAP.md`:
- Line 271: The bold metrics line "**810+ commits, 113 tagged releases, 3,368
tests, 96% coverage, 76 conformance programs, 30 examples, 13 spec chapters.**"
is inconsistent with README.md which reports 115 releases; update the
release-count in that bold stats string to match the canonical count (115) or
replace the hard count with a note like "115 tagged releases (as of v0.0.115)"
to make the source/timestamp explicit so ROADMAP and README remain consistent;
ensure you edit the bold stats text in ROADMAP.md (the shown metrics string)
and, if you choose the note approach, reference v0.0.115 as the datum.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6f6bb4dc-fbd9-478e-9a73-aa25a5c9e329

📥 Commits

Reviewing files that changed from the base of the PR and between be9c942 and 9b64e8c.

📒 Files selected for processing (2)
  • README.md
  • ROADMAP.md

Comment thread ROADMAP.md Outdated
aallan and others added 2 commits April 20, 2026 09:55
Seven findings across two reviews; five fixed, one declined, plus
the CI lint failure resolved.

Fixed:
- ROADMAP "Where we are" paragraph now lists Random in the algebraic
  effects enumeration; mirrored in README's "Key features delivered"
  line so both docs are in sync.
- ROADMAP bottom "**by the numbers**" bold string updated from
  "113 tagged releases" to "115 tagged releases (as of v0.0.115)" —
  matches README's v0.0.115 count and makes the datum explicit.
- random_int test seeded with `random.seed(0)` and now asserts
  `low in produced and high in produced` — explicitly verifies the
  inclusive-range contract rather than just the cardinality of the
  produced set.
- random_bool test also seeded; replaces the probabilistic
  `25 <= total <= 75` bound with a deterministic
  `{0, 1}.issubset(observed)` — no more flake risk.
- All four Random tests gain WAT import-gating assertions: each
  asserts the op-specific `$vera.random_*` import IS present, and
  the other two Random imports are NOT — confirms
  `_random_ops_used` gating works op-by-op and catches regressions
  where all three imports would be emitted unconditionally.
- Browser runtime's `random_int` gains a safe-integer range guard:
  if `lowBig < Number.MIN_SAFE_INTEGER` or `highBig > Number
  .MAX_SAFE_INTEGER`, throws a descriptive Error ("bounds exceed
  JavaScript safe integer range…") instead of silently producing
  wrong values via BigInt→Number precision loss.  Also checks
  `highBig >= lowBig` with its own message.

Declined:
- "spec/12-runtime.md line 406: import says random_int, should say
  random_bool" — file already says "random_bool" in both places
  (verified via `git show 0f3049b:spec/12-runtime.md`); CodeRabbit
  misread the diff.  No change needed.

CI lint fix:
- SKILL.md allowlist line-number drift from the Random section
  insertion: 25 entries past the insertion point shifted by +1 or
  +35 (depending on which hunk they fell after).  `fix_allowlists
  .py --fix` failed to detect the drift (same silent-OK bug as on
  #491).  Manually updated all 25 entries; `check_skill_examples
  .py` now reports all 105 Vera blocks parse or are allowlisted.

Co-Authored-By: Claude <noreply@anthropic.invalid>
Bandit S311 flags `random.randint` / `random.random` as "pseudo-
random generators are not suitable for cryptographic purposes".
True — but the Random effect in #465 is explicitly scoped to
games, simulations, and Monte Carlo (noted in the issue and in
spec §7.7.4).  Cryptographic randomness would warrant a separate
`Crypto` effect with `secrets.randbelow` etc.

Added `# noqa: S311` to the three host functions in
`vera/codegen/api.py` with comments pointing at the design
decision so a future reader doesn't have to re-discover the
scoping.

CI runs `ruff check --select S vera/` which I'd missed locally —
noqa'ing the three sites clears the lint.

Co-Authored-By: Claude <noreply@anthropic.invalid>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
TESTING.md (1)

116-129: ⚠️ Potential issue | 🟡 Minor

Missing skip entry for test_run[ch07_random_effect].

Line 116 states "12 skipped tests", but line 9 reports "13 skipped". The discrepancy is that ch07_random_effect is declared at the verify level (line 112 confirms this), so test_run[ch07_random_effect] should be skipped and listed in the table alongside the other verify-level run skips.

The table currently lists 4 verify-level run skips (ch03_slot_let_chains, ch03_slot_noncommutative, ch07_cross_module_contracts, ch07_io_sleep), but with the addition of ch07_random_effect there should now be 5.

📝 Suggested fix

Update line 116 from "12 skipped tests" to "13 skipped tests", and add this row to the level-limited skips table:

 | `test_run[ch07_io_sleep]` | `ch07_io_sleep.vera` | `verify` | `run` | `verify`-level programs don't get a `run` test |
+| `test_run[ch07_random_effect]` | `ch07_random_effect.vera` | `verify` | `run` | `verify`-level programs don't get a `run` test |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@TESTING.md` around lines 116 - 129, Update the skipped-tests summary and
table to include the missing verify-level run skip for ch07_random_effect:
change the header "12 skipped tests" to "13 skipped tests" and add a table row
for test_run[ch07_random_effect] with Program = ch07_random_effect.vera,
Declared level = verify, Skipped stage = run, Reason = verify-level programs
don't get a `run` test so it appears with the other verify-level run skips.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_codegen.py`:
- Around line 10198-10260: Add a new unit test next to test_random_int_in_range
/ test_random_int_singleton_range that exercises a zero-crossing range (e.g.
low=-2, high=2) and/or a zero singleton (0,0); seed the RNG (random.seed(0)) as
in test_random_int_in_range, compile the same source calling
Random.random_int(low, high), assert WAT imports only include "$vera.random_int"
and not "$vera.random_float" or "$vera.random_bool", then draw multiple times
with execute(result, fn_name="main") to assert every value stays within [low,
high], that both boundaries (when applicable) appear, and that the produced set
meets a minimal distribution check (e.g. len(produced) >= 4 for ranges with
multiple values) so zero-boundary behavior is explicitly covered.

---

Outside diff comments:
In `@TESTING.md`:
- Around line 116-129: Update the skipped-tests summary and table to include the
missing verify-level run skip for ch07_random_effect: change the header "12
skipped tests" to "13 skipped tests" and add a table row for
test_run[ch07_random_effect] with Program = ch07_random_effect.vera, Declared
level = verify, Skipped stage = run, Reason = verify-level programs don't get a
`run` test so it appears with the other verify-level run skips.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1d2e1a2f-ba2a-49fa-9878-8a297c55cad1

📥 Commits

Reviewing files that changed from the base of the PR and between 9b64e8c and d254582.

📒 Files selected for processing (5)
  • ROADMAP.md
  • TESTING.md
  • scripts/check_skill_examples.py
  • tests/test_codegen.py
  • vera/browser/runtime.mjs

Comment thread tests/test_codegen.py
Two findings; both fixed.

Inline finding: add a zero-crossing random_int test.  Prior tests
used all-positive ranges ([5,10], [7,7]) which don't exercise the
signed-integer paths in Python's random.randint, the WASM i64
marshalling, or the browser's BigInt → Number conversion.  New
test_random_int_zero_crossing_range covers low=-2, high=2, seeded,
with:
 - WAT import-gating (only $vera.random_int emitted)
 - every draw inside [low, high]
 - both boundaries produced
 - explicit `assert 0 in produced` — zero value must be reachable
 - distribution sanity (≥4 of 5 values in 100 draws)

Outside-diff finding: TESTING.md Skipped-tests table is missing
test_run[ch07_random_effect], the 13th skip introduced when the
new ch07_random_effect.vera conformance test at verify level was
added.  Updated the intro sentence ("13 skipped tests") and added
the row to the level-limited skips table matching the existing
verify-level pattern.

Also bumped doc counts: test_codegen.py 871→872 tests and
10,803→10,846 lines; TESTING.md summary 3,368→3,369 tests,
3,355→3,356 passed; ROADMAP test-count reference updated.

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan

aallan commented Apr 20, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai Fixed in f1ee528 — TESTING.md Skipped-tests section updated:

  • Header sentence: 12 skipped tests13 skipped tests
  • New table row under Level-limited skips: test_run[ch07_random_effect] / ch07_random_effect.vera / declared level verify / skipped stage run / reason "verify-level programs don't get a run test"

Also reconciled the overview **Tests** row (3,368 → 3,369 total; 3,355 → 3,356 passed) and the test_codegen.py row (871 → 872 tests; 10,803 → 10,846 lines) since the zero-crossing test above bumped both counts.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@aallan All the reconciliations look correct — the 13 skipped tests header, the new test_run[ch07_random_effect] row (verify-level → no run test), the overview Tests row, and the test_codegen.py line/test counts are all consistent with each other and with the additions in this PR. Thanks for the thorough tidy-up.


🧠 Learnings used
Learnt from: aallan
Repo: aallan/vera PR: 492
File: tests/test_codegen.py:10188-10316
Timestamp: 2026-04-20T08:57:53.232Z
Learning: Repo aallan/vera: In tests/test_codegen.py::TestRandomEffect, each Random op test asserts per-operation WAT import-gating — the used "$vera.random_{op}" import is present while the other Random imports are absent. This guards regressions in _random_ops_used.

Learnt from: aallan
Repo: aallan/vera PR: 415
File: TESTING.md:402-413
Timestamp: 2026-03-29T11:10:02.330Z
Learning: In `aallan/vera` `TESTING.md`, the CI Pipeline section states "seven parallel jobs" which refers to the 7 top-level YAML job keys in `.github/workflows/ci.yml` (test, typecheck, lint, security, dependency-audit, sbom, browser-parity). The CI table has 8 rows because the single `test` job is intentionally split into two documentation rows (plain matrix row and a coverage row) for clarity. `check_doc_counts.py` counts and validates 7 YAML job keys. Do NOT flag "seven" as inconsistent with the 8-row table — they are measuring different things by design.

Learnt from: aallan
Repo: aallan/vera PR: 492
File: tests/test_codegen.py:0-0
Timestamp: 2026-04-20T08:58:09.190Z
Learning: Repo aallan/vera — tests/test_codegen.py: In TestRandomEffect, each test asserts per-op WAT import gating for Random: the used import ($vera.random_int, $vera.random_float, or $vera.random_bool) is present in result.wat and the other two Random imports are absent. random_bool also uses a seeded run and asserts both 0 and 1 are observed to avoid probabilistic flakiness.

Learnt from: aallan
Repo: aallan/vera PR: 350
File: tests/test_codegen.py:8630-8633
Timestamp: 2026-03-25T16:32:11.316Z
Learning: Repo aallan/vera PR `#350`: tests/test_codegen.py includes explicit WAT import‑gating coverage for JSON host imports — tests test_json_parse_wat_import, test_json_stringify_wat_import, and test_json_no_imports_when_unused verify that "vera.json_parse"/"vera.json_stringify" imports are emitted only when referenced and absent when unused.

Learnt from: CR
Repo: aallan/vera PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-18T07:10:26.169Z
Learning: Applies to tests/conformance/**/*.vera : All 75 conformance programs in `tests/conformance/` must pass their declared verification level (`parse`, `check`, `verify`, or `run`)

Learnt from: aallan
Repo: aallan/vera PR: 492
File: tests/test_codegen.py:10188-10316
Timestamp: 2026-04-20T08:57:53.232Z
Learning: Repo aallan/vera: tests/test_codegen.py::TestRandomEffect::test_random_bool_produces_both seeds Python's RNG with random.seed(0) and asserts that both 0 and 1 appear across 100 draws using a set check, replacing a probabilistic bound to eliminate flakiness.

Learnt from: aallan
Repo: aallan/vera PR: 357
File: tests/test_codegen.py:9059-9078
Timestamp: 2026-03-26T09:40:51.556Z
Learning: Repo aallan/vera PR `#357`: In tests/test_codegen.py, per-operation import-gating for the Http effect is covered — tests ensure only the used host import ("http_get" or "http_post") appears in WAT and the sibling import is absent. This mirrors the existing JSON import-gating pattern.

Learnt from: aallan
Repo: aallan/vera PR: 491
File: tests/test_codegen.py:0-0
Timestamp: 2026-04-17T21:10:46.688Z
Learning: Repo aallan/vera: For IO.time tests (e.g., tests/test_codegen.py::TestIOOperations::test_io_time_returns_positive_nat), avoid fixed epoch thresholds. Capture host time immediately before and after execute(...), and assert before_ms <= observed_ms <= after_ms to validate wiring without flakiness.

Learnt from: aallan
Repo: aallan/vera PR: 0
File: :0-0
Timestamp: 2026-03-29T17:17:11.974Z
Learning: In `tests/test_codegen.py`, `test_option_unwrap_or_map` (lines ~9936–9949) and `test_option_unwrap_or_set` (lines ~9950–9963) are regular, unconditionally-passing tests with NO `xfail`, `skip`, or `skipif` marks. `grep -rn "xfail" tests/` returns zero results across the entire test suite. The PR `#428` fix resolved the underlying monomorphiser inference gap for opaque i32 handle types (Map, Set) in `option_unwrap_or` generics. Do NOT flag these tests as xfail or claim there is a monomorphiser limitation for Map/Set in this context.

Learnt from: CR
Repo: aallan/vera PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-18T07:09:37.055Z
Learning: Applies to tests/conformance/**/*.vera : All 75 conformance programs in `tests/conformance/` must pass their declared level as specified in `manifest.json`

Learnt from: aallan
Repo: aallan/vera PR: 492
File: tests/test_codegen.py:0-0
Timestamp: 2026-04-20T08:58:26.644Z
Learning: tests/test_codegen.py Random effect tests: For Random.random_int(low, high), seed Python RNG (e.g., random.seed(0)) and assert both inclusive boundaries (low and high) appear at least once over multiple draws, in addition to a len(produced) >= N distribution sanity check, to avoid flakiness and verify [low, high] semantics explicitly.

Learnt from: CR
Repo: aallan/vera PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-18T07:10:26.169Z
Learning: Applies to **/*.vera : Declare all Vera function effects: use `effects(pure)` for pure functions, `effects(<IO>)` for IO, `effects(<Http>)` for network, `effects(<Inference>)` for LLM calls

@aallan aallan merged commit 3cf122a into main Apr 20, 2026
19 checks passed
@aallan aallan deleted the random-effect branch April 20, 2026 09:21
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.

Add Random effect for number generation

1 participant