Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail

# Enforce coupling between PRNG algorithm/version and golden regression vector.

PRNG_FILE="crates/rmg-core/src/math/prng.rs"

# Only run if the PRNG file is staged
if ! git diff --cached --name-only | grep -qx "$PRNG_FILE"; then
exit 0
fi

DIFF=$(git diff --cached -- "$PRNG_FILE" || true)

# Heuristics to detect algorithm changes: edits to these functions imply behavior change
if echo "$DIFF" | grep -E '^(\+|-)\s*(fn\s+next_u64|fn\s+from_seed_u64|fn\s+from_seed\(|fn\s+next_int\()' >/dev/null; then
ALGO_CHANGED=1
else
ALGO_CHANGED=0
fi

# Version bump present?
if echo "$DIFF" | grep -E 'PRNG_ALGO_VERSION' >/dev/null; then
VERSION_CHANGED=1
else
VERSION_CHANGED=0
fi

# Golden regression vector updated?
if echo "$DIFF" | grep -E 'next_int_golden_regression|assert_eq!\(values,\s*vec!\[' >/dev/null; then
GOLDEN_CHANGED=1
else
GOLDEN_CHANGED=0
fi

FAIL=0
if [[ "$ALGO_CHANGED" -eq 1 && "$VERSION_CHANGED" -eq 0 ]]; then
echo "pre-commit: PRNG algorithm changed but PRNG_ALGO_VERSION was not bumped." >&2
FAIL=1
fi

if [[ "$VERSION_CHANGED" -eq 1 && "$GOLDEN_CHANGED" -eq 0 ]]; then
echo "pre-commit: PRNG_ALGO_VERSION bumped but golden regression vector was not updated." >&2
FAIL=1
fi

if [[ "$FAIL" -eq 1 ]]; then
echo "pre-commit: Refusing commit. Update algorithm version and golden regression together." >&2
exit 1
fi

exit 0

2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
.
- name: cargo test
run: cargo test
- name: PRNG golden regression (rmg-core)
run: cargo test -p rmg-core --features golden_prng -- tests::next_int_golden_regression

docs:
name: Docs Guard
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SHELL := /bin/bash

.PHONY: hooks
hooks:
@git config core.hooksPath .githooks
@chmod +x .githooks/* 2>/dev/null || true
@echo "[hooks] Installed git hooks from .githooks (core.hooksPath)"

2 changes: 1 addition & 1 deletion crates/rmg-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rmg-cli"
version = "0.1.0"
edition = "2024"
edition = "2021"

[dependencies]
8 changes: 7 additions & 1 deletion crates/rmg-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rmg-core"
version = "0.1.0"
edition = "2024"
edition = "2021"

[dependencies]
blake3 = "1"
Expand All @@ -12,3 +12,9 @@ thiserror = "1"
once_cell = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[features]
default = []
# Optional regression check for PRNG sequences; off by default to avoid
# freezing algorithm choices. Used only in tests guarded with `cfg(feature)`.
golden_prng = []
13 changes: 7 additions & 6 deletions crates/rmg-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,13 @@ fn add_vec(a: [f32; 3], b: [f32; 3]) -> [f32; 3] {

/// Executor that updates the encoded position in the entity payload.
fn motion_executor(store: &mut GraphStore, scope: &NodeId) {
if let Some(record) = store.node_mut(scope)
&& let Some(payload) = &record.payload
&& let Some((position, velocity)) = decode_motion_payload(payload)
{
let updated = encode_motion_payload(add_vec(position, velocity), velocity);
record.payload = Some(updated);
if let Some(record) = store.node_mut(scope) {
if let Some(payload) = &record.payload {
if let Some((position, velocity)) = decode_motion_payload(payload) {
let updated = encode_motion_payload(add_vec(position, velocity), velocity);
record.payload = Some(updated);
}
}
}
}

Expand Down
Loading