Skip to content

Pin mix64, Rng and valueNoise in the determinism test - #21

Merged
dmccoystephenson merged 1 commit into
mainfrom
test/rng-pins
Oct 31, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
test/rng-pins

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle targeting src/colony/rng.h, the source of all randomness in world generation and the tick loop. It had no direct test — a change there was only observable as a moved pinned fingerprint, with no indication of the cause.

A new section, rng: mix64, Rng and valueNoise are pinned and in range, is added to tests/test_determinism.cpp (kept in an existing executable so CMakeLists.txt is untouched):

  • mix64 is pinned against the published SplitMix64 reference outputs for seed 0 (0xe220a8397b1dcdaf, 0x6e789e6aa1b965f4) — an independent reference, not a value read back from this code.
  • The first three Rng{12345}.next() outputs and the resulting state are pinned (the state is what Globals::rng saves), and a copy built from a mid-sequence state is checked to resume identically.
  • range(-3, 3) is checked to be inclusive at both ends over 2,000 draws; below(7) stays in [0, 7) and below(1) is always 0.
  • valueNoise is pinned exactly on the integer lattice (as 53-bit integers after scaling by 2^53, including a negative cell and a second seed), checked to blend to the exact midpoint at x + 0.5, to be continuous across a cell edge, and to stay in [0, 1) over a 40×40 sample including negative coordinates.

These are characterization tests: no production code is changed. The expected integer values were computed independently with Python's arbitrary-precision integers following the same arithmetic as rng.h.

Save-integrity notes: no schema, bridge, strata.ref or component change; the pinned rules fingerprint is unchanged; no existing CHECK is removed.

Test plan

  • CI rules (gcc-13), rules (clang-18), rules (asan-ubsan), rules (msvc) green on the head SHA (this is the anchor — the local sandbox denied cmake/g++, so the change is UNVERIFIED locally)
  • game on Strata (saves soak, headless smoke) green
  • determinism test output shows the new section with ALL PASSED

No tracking issue — the gap was found during triage (no open issues existed).

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Every generated world and every tick draws from rng.h, but nothing tested it
directly: a change there only showed up as a moved fingerprint. The new
section pins mix64 against the published SplitMix64 reference outputs, pins
the first Rng steps (output and saved state), checks that restoring the state
resumes the sequence, that range() is inclusive and below() stays in bounds,
and pins valueNoise on the integer lattice (including negative cells) with
its midpoint blend, continuity and [0, 1) range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for this test-only change adding RNG and value-noise characterization coverage.

No open issues 🎉

What changed in this PR

Adds direct characterization tests for the randomness utilities used by world generation and the tick loop, helping pinpoint causes of determinism regressions. No production code or build configuration changes.

Changes:

  • Pins mix64 outputs and Rng outputs, state transitions, and state restoration.
  • Checks inclusive range() bounds and below() bounds.
  • Pins valueNoise lattice values and checks midpoint interpolation, cell-edge continuity, and output bounds.
File Description
tests/​test_determinism.cpp Adds RNG and value-noise checks to the existing determinism test executable.

Review effort: Balanced

@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head 3c27576):

  • Scope: PASS — one file, tests/test_determinism.cpp, +50/−0; one new section plus the <cmath> and colony/rng.h includes it uses. No production code, CMakeLists.txt, schema or workflow changes.
  • Tests-new: PASS (not applicable as stated) — no new public functions; the section adds the first direct coverage of mix64, Rng::next/below/range and valueNoise.
  • Tests-fix: not applicable — characterization only, no bug fix. Exact pins were computed independently in Python with arbitrary-precision integers; the C++ matching them under GCC 13, Clang 18, ASan+UBSan and MSVC is the cross-check. The two mix64 pins are the published SplitMix64 seed-0 reference outputs, which is independent of this repo's code.
  • Sibling structure: PASS — uses SECTION/CHECK/CHECK_MSG in a braced block like the other sections; placed before the pinned fingerprint section.
  • Sibling renames: PASS — no renames.
  • Docs: PASS — Phase 7 table rows were checked: README.md (no control, flag, rule or mod key changes; the test count it implies is unchanged because no executable was added), manifest.h, schema.h, content/prefabs.usda, mods/*/mod.toml, LICENSE — none are affected by a test-only change. No corrections.
  • Issue resolution: not applicable — no tracking issue (none were open at triage).
  • CI: PASS — every job green on the head SHA: rules (gcc-13), rules (clang-18), rules (asan-ubsan), rules (msvc) (5/5 tests each), game on Strata (saves soak, headless smoke) and game on Strata (Windows, MSVC) (8/8), and the web smoke test. A local build could not run (the sandbox denied cmake/g++), so CI on the head SHA is the only anchor.
  • Privacy: PASS — the diff, title, body and commit name no employer or private repository; the only repositories named are this public one and the Gardener link the dispatch requires.
  • Save integrity: PASS — no component, schema, bridge or strata.ref change; no CHECK removed (the diff has zero deleted lines); the Strata job's saves soak passed anyway.
  • Fingerprint: PASS — 0x011ed2b2f364b21b is unchanged.
  • Schema untouched: PASS — src/colony/schema.h and strata.ref have no diff.
  • Layering: PASS — no src/colony/src/mods change.
  • Docs follow the change: PASS — no user-facing change.

Adversarial note: an exact floating-point equality is used for the lattice and midpoint pins. It holds because at integer coordinates the interpolation weights are exactly 0, and at x + 0.5 smoothstep is exactly 0.5, so no rounding is involved; the build already compiles with -ffp-contract=off. The cell-edge continuity check uses a 1e-6 tolerance because that one does involve rounding.

The Copilot review (COMMENTED, no issues) was received and needs no action.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit c8b4884 into main Oct 31, 2026
8 checks passed
@dmccoystephenson
dmccoystephenson deleted the test/rng-pins branch October 31, 2026 03:34
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