Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(combat): lock properties, replay hash, and the timer walk
Property tests use proptest seed 0xC0BA7E57. A three-OS workflow
compares the seeded battle digest. The timer walk reuses a scratch
buffer. The benchmark shard map includes astraweave-combat, which
was why every shard failed validation. Legacy damage paths stay.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 15, 2026
commit 7cf0ba024d5a02cc2677ba13a12093699c92b354
2 changes: 1 addition & 1 deletion .github/scripts/benchmark-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BENCHMARK_SHARD_GROUPS=(
"astraweave-net-ecs astraweave-asset-pipeline astraweave-prompts astraweave-audio"
"astraweave-persistence-ecs astraweave-weaving astraweave-observability astraweave-input"
"astraweave-rag astraweave-llm-eval astraweave-secrets astraweave-physics"
"astraweave-render astraweave-npc astraweave-materials astraweave-gameplay"
"astraweave-render astraweave-npc astraweave-materials astraweave-gameplay astraweave-combat"
"astraweave-scene astraweave-optimization astraweave-director astraweave-nav"
"astraweave-sdk astraweave-coordination astraweave-persona astraweave-behavior"
"astraweave-ui astraweave-pcg astraweave-security astraweave-stress-test"
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/combat-replay.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Combat replay hash

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
hash:
name: Hash (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v5
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

- name: Install Rust
uses: dtolnay/rust-toolchain@1.89.0
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

- name: Baseline CPU
run: |
host=$(rustc -vV | sed -n 's/host: //p')
case "$host" in
*x86_64*) echo 'RUSTFLAGS=-C target-cpu=x86-64' >> "$GITHUB_ENV" ;;
*) echo 'RUSTFLAGS=' >> "$GITHUB_ENV" ;;
esac

- name: Replay hash
run: cargo test -p astraweave-combat --test replay_hash -- --nocapture

- name: Upload
uses: actions/upload-artifact@v4
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
name: replay-hash-${{ runner.os }}
path: target/replay-hash.json
retention-days: 14

compare:
name: Compare three OS
needs: hash
runs-on: ubuntu-latest
steps:
- name: Download
uses: actions/download-artifact@v4
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
pattern: replay-hash-*
path: hashes

- name: Diff the digests
run: |
python3 - << 'PY'
import json, pathlib, sys
files = sorted(pathlib.Path("hashes").rglob("replay-hash.json"))
if len(files) != 3:
print(f"expected 3 replay files, found {len(files)}: {files}")
sys.exit(1)
parsed = []
for path in files:
data = json.loads(path.read_text())
case = next(row for row in data if row["case"] == "combat_resolve")
parsed.append((str(path), case["sha256"]))
print(f"{path}: {case['sha256']}")
digest = parsed[0][1]
bad = [row for row in parsed if row[1] != digest]
if bad:
print("combat_resolve digest differs across OS")
sys.exit(1)
print("combat_resolve matches on all three OS")
PY
1 change: 1 addition & 0 deletions astraweave-combat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ thiserror = { workspace = true }
aw-save = { path = "../persistence/aw-save" }
criterion = { workspace = true }
proptest = "1.5"
sha2 = { workspace = true }
time = { version = "0.3", features = ["macros"] }
uuid = { version = "1", features = ["v4"] }

Expand Down
13 changes: 13 additions & 0 deletions astraweave-combat/benches/resolve_hit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ fn bench_resolve(c: &mut Criterion) {
black_box(resolve_hit(&tables, &atk, &def, 1, &mut rng).unwrap())
})
});
c.bench_function("resolve_hit_batch_10k", |b| {
b.iter(|| {
let mut last = 0i64;
for ordinal in 0..10_000u64 {
let mut rng = hit_rng(1, 9, ordinal, 1);
last = resolve_hit(&tables, &atk, &def, 1, &mut rng)
.unwrap()
.hp_delta
.raw();
}
black_box(last)
})
});
}

criterion_group!(benches, bench_resolve);
Expand Down
23 changes: 8 additions & 15 deletions astraweave-combat/src/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
//! query iteration order. The queue `Vec` is recycled. `resolve_hit` itself
//! does not allocate.

use std::any::TypeId;
use std::sync::Arc;

use astraweave_ecs::{App, Entity, Plugin, Query, World};
use astraweave_ecs::{App, Entity, Plugin, World};

use crate::fixed::Fixed64;
use crate::resolve::{
Expand Down Expand Up @@ -484,20 +485,12 @@ fn decrement_timers(world: &mut World) {
.map(|s| std::mem::take(&mut s.ids))
.unwrap_or_default();
ids.clear();
{
let q = Query::<CImmune>::new(world);
for (entity, _) in q {
ids.push(entity);
}
}
{
let q = Query::<CVitals>::new(world);
for (entity, vitals) in q {
if vitals.stagger_left > 0 {
ids.push(entity);
}
}
}
world
.archetypes()
.append_entities_with_component(TypeId::of::<CImmune>(), &mut ids);
world
.archetypes()
.append_entities_with_component(TypeId::of::<CVitals>(), &mut ids);
ids.sort();
ids.dedup();
for entity in &ids {
Expand Down
2 changes: 2 additions & 0 deletions astraweave-combat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub enum CombatError {

#[cfg(test)]
mod logic_tests;
#[cfg(test)]
mod property_tests;

#[cfg(test)]
mod tests {
Expand Down
26 changes: 0 additions & 26 deletions astraweave-combat/src/logic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,29 +682,3 @@ fn parry_zeroes_damage_and_is_consumed() {
);
assert_eq!(app.world.get::<CImmune>(foe).unwrap().parry_ticks, 0);
}

proptest::proptest! {
#[test]
fn ehp_step_matches_when_k_divides(step in 0i64..4) {
let tables = canonical_tables().unwrap();
let armor = step * 400;
let mods = [];
let def = DefenderView {
hp: Fixed64::from_int(1_000),
hp_max: Fixed64::from_int(1_000),
poise: Fixed64::ZERO,
poise_max: Fixed64::ZERO,
armor,
resists: &[],
evasion_bp: 0,
bulwark_bp: 0,
bulwark_flat: 0,
modifiers: &mods,
block: BlockGate::default(),
immune: ImmuneGate::default(),
};
let ehp = effective_health(&tables, 0, &def, 1, sheet()).unwrap();
let expect = if armor > 1_200 { 4_000 } else { 1_000 + armor * 1_000 / 400 };
assert_eq!(ehp.value, Fixed64::from_int(expect));
}
}
Loading