From 5c664f23af9fc36bdfd6f8767ee15a6b95d37502 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 16 Oct 2026 13:46:26 +0000 Subject: [PATCH 1/3] feat(aravath): bridge reroute, brush digs, and integer columns The greybox steps the bridge agent after the motor tick and does not edit the motor. Player digs enqueue a DestructionCommand brush and carve from that occupancy. Column tops come from the terrain seed through ColumnFns, leaving FlatColumnBase as the test double. The greybox golden moves from b663da52ea1d566e to 0a576578512f25d2 because the scripted dig and the bridge route are now in the hash. Co-authored-by: Andrew Brown --- aravath_runtime/golden/replay.hash | 2 +- aravath_runtime/src/ground.rs | 71 ++++++++++++++++++----- aravath_runtime/src/sim.rs | 14 +++++ astraweave-destruction/src/column_base.rs | 22 +++++++ astraweave-destruction/src/lib.rs | 24 ++++++++ astraweave-destruction/src/terrain.rs | 36 +++++++++++- 6 files changed, 154 insertions(+), 15 deletions(-) create mode 100644 astraweave-destruction/src/column_base.rs diff --git a/aravath_runtime/golden/replay.hash b/aravath_runtime/golden/replay.hash index 75c945416e..2ec82fc52d 100644 --- a/aravath_runtime/golden/replay.hash +++ b/aravath_runtime/golden/replay.hash @@ -1 +1 @@ -b663da52ea1d566e +0a576578512f25d2 diff --git a/aravath_runtime/src/ground.rs b/aravath_runtime/src/ground.rs index 2ca3d6282c..e5b38bf808 100644 --- a/aravath_runtime/src/ground.rs +++ b/aravath_runtime/src/ground.rs @@ -2,8 +2,13 @@ use std::collections::{HashMap, HashSet}; +use astraweave_destruction::command::{Brush, BrushOp, BrushShape}; +use astraweave_destruction::{ColumnFns, DestructionWorld}; use astraweave_physics::{Layers, PhysicsWorld}; use astraweave_render::mesh::{CpuMesh, MeshVertex as RenderVertex}; +use astraweave_terrain::column_gen::{ + self, biome_at as seed_biome, column_material as seed_material, +}; use astraweave_terrain::{ ChunkCoord, ChunkMesh, ColumnStream, DualContouring, MeshVertex, Voxel, VoxelGrid, }; @@ -11,6 +16,24 @@ use glam::{Vec2, Vec3, Vec4}; use crate::island::{self, biome_at, column_material, Biome, MAT_WOOD}; +fn column_demolition() -> DestructionWorld { + let mut world = DestructionWorld::new(column_gen::FOREST_WORLD_SEED, 0); + world.bind_column_fns(ColumnFns { + top: column_gen::surface_height, + material: seed_column_material, + }); + world +} + +fn seed_column_material(x: i32, y: i32, z: i32) -> u16 { + seed_material( + y, + column_gen::surface_height(x, z), + seed_biome(x, z), + column_gen::on_yaqar_road(x, z), + ) +} + pub struct ChunkPart { pub material: u16, pub mesh: CpuMesh, @@ -65,6 +88,7 @@ pub struct Ground { bodies: HashMap, generated: HashSet, stream: ColumnStream, + demolition: Box, scatter: HashMap>, /// Chunk the ring was built around, plus the radius. A settled player /// whose grid is clean skips the set rebuild. @@ -89,6 +113,7 @@ impl Ground { bodies: HashMap::new(), generated: HashSet::new(), stream: ColumnStream::new(), + demolition: Box::new(column_demolition()), scatter: HashMap::new(), stream_key: None, } @@ -202,22 +227,42 @@ impl Ground { uploads } - /// Write air voxels. Caller runs [`Self::sync_dirty`] afterwards. + /// Dig with a destruction brush. Occupancy is the integer column plus the + /// command log. The voxel grid is the mesh of that occupancy. pub fn dig_sphere(&mut self, center: Vec3, radius: f32) { - let r = radius.ceil() as i32; let origin = IVecFloor::from_vec(center); - for x in -r..=r { - for y in -r..=r { - for z in -r..=r { - let p = Vec3::new( - (origin.x + x) as f32, - (origin.y + y) as f32, - (origin.z + z) as f32, - ); - if p.distance(center) <= radius { - self.grid.set_voxel(p, Voxel::new(0.0, 0)); - self.remember(p, 0.0, 0); + let reach = radius.ceil().max(1.0) as i32; + let brush = Brush { + shape: BrushShape::Sphere, + op: BrushOp::Subtract, + origin: [origin.x, origin.y, origin.z], + radius: reach as u16, + half_extents: [1, 1, 1], + strength: 4, + }; + if self.demolition.apply_brush_now(brush).is_err() { + return; + } + let limit = reach * reach; + for dz in -reach..=reach { + for dy in -reach..=reach { + for dx in -reach..=reach { + if dx * dx + dy * dy + dz * dz > limit { + continue; + } + let x = origin.x + dx; + let y = origin.y + dy; + let z = origin.z + dz; + let seed = column_gen::surface_height(x, z); + let dug = self.demolition.terrain().surface_y(x, z); + let drop = seed.saturating_sub(dug); + let mesh_top = island::surface_height(x, z); + if drop <= 0 || y <= mesh_top.saturating_sub(drop) { + continue; } + let p = Vec3::new(x as f32, y as f32, z as f32); + self.grid.set_voxel(p, Voxel::new(0.0, 0)); + self.remember(p, 0.0, 0); } } } diff --git a/aravath_runtime/src/sim.rs b/aravath_runtime/src/sim.rs index 7be6a00c38..c1a94ab5ae 100644 --- a/aravath_runtime/src/sim.rs +++ b/aravath_runtime/src/sim.rs @@ -113,6 +113,8 @@ pub struct Greybox { /// by asking `catch_up` to spend it. accumulator: f64, pub tick: u64, + /// Bridge collapse and the ford. Does not drive the character motor. + pub bridge: Box, } impl Greybox { @@ -140,6 +142,7 @@ impl Greybox { scars: ScarField::new(), accumulator: 0.0, tick: 0, + bridge: Box::new(crate::bridge_agent::BridgeAgent::new()), } } @@ -167,6 +170,7 @@ impl Greybox { scars: ScarField::new(), accumulator: 0.0, tick: 0, + bridge: Box::new(crate::bridge_agent::BridgeAgent::new()), } } @@ -235,6 +239,8 @@ impl Greybox { self.combat.toggle_lock(&self.physics, &self.player); } self.tick_controls(input.motor); + // Collapse notices update nav tiles. The motor is not called here. + self.bridge.step(self.tick); if input.dig { let uploads = self.dig_ahead(2.5); self.pending_uploads.extend(uploads); @@ -308,6 +314,11 @@ impl Greybox { } hash.u8(loco_tag(self.graph.state)); hash.f32(self.graph.time); + hash.i32(self.bridge.route_x_milli); + hash.bool(self.bridge.setup_ok); + for value in self.bridge.cut_milli { + hash.i32(value); + } hash.u64(self.ground.edits.len() as u64); for edit in &self.ground.edits { hash.i32(edit.x); @@ -834,6 +845,9 @@ mod tests { fn replay_matches_golden_hash() { let sim = play(&recorded_script()); let got = format!("{:016x}", sim.state_hash()); + // Intended move off b663da52ea1d566e to 0a576578512f25d2: the + // scripted dig is a DestructionCommand brush on the integer columns, + // and the hash includes the bridge-collapse route. The motor is unchanged. let golden = include_str!("../golden/replay.hash").trim(); assert_eq!( got, golden, diff --git a/astraweave-destruction/src/column_base.rs b/astraweave-destruction/src/column_base.rs new file mode 100644 index 0000000000..9ed4113c15 --- /dev/null +++ b/astraweave-destruction/src/column_base.rs @@ -0,0 +1,22 @@ +//! Integer column hook for the Aravath ground. +//! +//! The functions are supplied by the caller (`surface_height` and +//! `column_material` from the terrain crate). This crate does not depend on +//! that crate. `FlatColumnBase` stays the unit-test double. + +/// Seed column sampled by function pointer. No heap, no floats. +#[derive(Clone, Copy, Debug)] +pub struct ColumnFns { + pub top: fn(i32, i32) -> i32, + pub material: fn(i32, i32, i32) -> u16, +} + +impl ColumnFns { + pub fn top(self, x: i32, z: i32) -> i32 { + (self.top)(x, z) + } + + pub fn material(self, x: i32, y: i32, z: i32) -> u16 { + (self.material)(x, y, z) + } +} diff --git a/astraweave-destruction/src/lib.rs b/astraweave-destruction/src/lib.rs index a8645f6d22..77172f7494 100644 --- a/astraweave-destruction/src/lib.rs +++ b/astraweave-destruction/src/lib.rs @@ -7,6 +7,7 @@ #![allow(clippy::too_many_arguments, clippy::needless_range_loop)] pub mod budget; +pub mod column_base; pub mod command; pub mod debris; pub mod fracture; @@ -34,6 +35,7 @@ pub use budget::{ DEMOLITION_TICKS as SHOWCASE_TICKS, MAX_BRUSH_CELLS, MAX_LOG_COMMANDS as LATE_JOIN_CAP, MAX_NODES_PER_TICK, MAX_SIM_DEBRIS, SLEEP_TICKS, STRESS_ITERS, }; +pub use column_base::ColumnFns; pub use command::{CommandError as DestructionCommandError, DestructionCommand as Command}; pub use fracture::{bake_bytes, bake_gate, planar_children, BreakRule}; pub use graph::{allows_climb, PieceFlags as FractureFlags}; @@ -198,6 +200,28 @@ impl DestructionWorld { &self.terrain } + /// Seed columns for brush replay. The flat test double stays in place until this is called. + pub fn bind_column_fns(&mut self, fns: ColumnFns) { + self.terrain.set_column_fns(fns); + } + + /// Load the brush chunk, record the command, and apply it on this tick. + pub fn apply_brush_now(&mut self, brush: crate::command::Brush) -> Result<(), CommandError> { + let chunk = ( + brush.origin[0].div_euclid(crate::octree::CHUNK_EXTENT), + brush.origin[2].div_euclid(crate::octree::CHUNK_EXTENT), + ); + self.terrain.load(chunk); + self.enqueue(DestructionCommand { + tick: self.tick, + seq: 0, + entity_id: 0, + kind: CommandKind::Brush(brush), + })?; + self.tick(); + Ok(()) + } + pub fn debris(&self) -> &DebrisPool { &self.debris } diff --git a/astraweave-destruction/src/terrain.rs b/astraweave-destruction/src/terrain.rs index 5732a75c40..2e01836fc9 100644 --- a/astraweave-destruction/src/terrain.rs +++ b/astraweave-destruction/src/terrain.rs @@ -4,6 +4,7 @@ //! does not allocate: edits sit in fixed arrays. The DAG is rebuilt from //! those arrays when the chunk deforms. +use crate::column_base::ColumnFns; use crate::command::{Brush, BrushOp, BrushShape}; use crate::octree::{VoxelDag, CHUNK_EXTENT}; @@ -196,6 +197,8 @@ impl ChunkSlot { pub struct Terrain { base: FlatColumnBase, + /// When set, `surface_y` regenerates the seed column instead of the flat top. + columns: Option, slots: Box<[ChunkSlot; MAX_CHUNKS]>, remesh: [(i32, i32); 8], remesh_len: usize, @@ -205,6 +208,7 @@ impl Terrain { pub fn new(top: i32) -> Self { Self { base: FlatColumnBase { top }, + columns: None, slots: Box::new([ ChunkSlot::empty(), ChunkSlot::empty(), @@ -220,6 +224,11 @@ impl Terrain { self.base.top } + /// Use the caller's integer columns. `None` keeps [`FlatColumnBase`]. + pub fn set_column_fns(&mut self, fns: ColumnFns) { + self.columns = Some(fns); + } + pub fn load(&mut self, chunk: (i32, i32)) { let base = self.base; let slot = self.slot_mut(chunk); @@ -307,7 +316,11 @@ impl Terrain { .filter(|slot| slot.loaded) .map(|slot| slot.occ.height_delta(x, z)) .unwrap_or(0); - self.base.column_top(x, z).saturating_add(delta) + let top = match self.columns { + Some(fns) => fns.top(x, z), + None => self.base.column_top(x, z), + }; + top.saturating_add(delta) } pub fn dag(&self, chunk: (i32, i32)) -> Option<&VoxelDag> { @@ -611,4 +624,25 @@ mod tests { assert!(dag.ready()); assert!(!dag.solid_at(4, 2, 4, |_, _, _| true)); } + + #[test] + fn seeded_columns_replay_the_same_occupancy() { + fn top(x: i32, z: i32) -> i32 { + 6 + (x + z).rem_euclid(3) + } + fn material(_x: i32, y: i32, _z: i32) -> u16 { + u16::from(y <= top(0, 0)) + } + let mut terrain = Terrain::new(0); + terrain.set_column_fns(ColumnFns { top, material }); + let seed = top(4, 4); + terrain.load((0, 0)); + terrain.apply_brush(dig()); + assert!(terrain.surface_y(4, 4) < seed); + let before = terrain.occupancy_bytes((0, 0)); + terrain.unload((0, 0)); + terrain.load((0, 0)); + assert_eq!(terrain.occupancy_bytes((0, 0)), before); + assert_eq!(terrain.surface_y(0, 0), top(0, 0)); + } } From f7bd3382ff92be95f5338cfaca219dddd6c48a67 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 16 Oct 2026 13:52:18 +0000 Subject: [PATCH 2/3] docs(destruction): record column hooks and the greybox brush ColumnFns is the integer-column adapter, and the Aravath dig enqueues a sphere Subtract brush. FlatColumnBase stays the unbound terrain so the destruction replay case is unchanged. Co-authored-by: Andrew Brown --- docs/architecture/destruction.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/architecture/destruction.md b/docs/architecture/destruction.md index 0b1d2dc697..8f6ab422ae 100644 --- a/docs/architecture/destruction.md +++ b/docs/architecture/destruction.md @@ -9,8 +9,8 @@ lifecycle_status: active integration_status: wired summary: "Ordered destruction commands, an 8-iteration load push, and a 300-tick replay case." owns: [astraweave-destruction] -doc_version: "1.2" -last_verified_commit: 7a571045 +doc_version: "1.3" +last_verified_commit: 5c664f23 runtime_edges: - to: astraweave-core note: "The core replay test calls demolition_bytes." @@ -26,10 +26,10 @@ runtime_edges: |---|---| | **System name** | Deterministic destruction | | **Primary crates** | `astraweave-destruction` | -| **Document version** | 1.2 | -| **Last verified against commit** | `7a571045` | -| **Last verified date** | 2026-10-15 | -| **Status** | Active. Headless showcase and the required replay case. The greybox on main (`cdea968c`) still digs with `dig_sphere`, not `DestructionCommand::Brush`. | +| **Document version** | 1.3 | +| **Last verified against commit** | `5c664f23` | +| **Last verified date** | 2026-10-16 | +| **Status** | Active. Headless showcase and the required replay case. The Aravath greybox binds integer columns through `ColumnFns` and digs with `DestructionCommand::Brush`. `FlatColumnBase` remains the terrain when no functions are bound, so the `destruction` replay hash is unchanged. | | **Owner notes** | Design: `docs/current/DESTRUCTION_DESIGN.md`. Survey: `docs/current/DESTRUCTION_ARCHAEOLOGY.md`. `Fixed64` lives in `astraweave-math` (PR #245). | --- @@ -68,7 +68,8 @@ Floats do not enter this pipeline. Rapier is not called. | `DestructionCommand` | One impact, explosion, brush, detach, or anchor | | Tier A | Flood-fill from anchors. Islands with no anchor and without `ANTI_DESTROY` become `DYNAMIC` | | Tier B | Fixed 8-iteration load push. A bond breaks when pushed load exceeds strength minus damage | -| `FlatColumnBase` | Every column has the same integer top. The #215 adapter is not compiled yet | +| `FlatColumnBase` | Every column has the same integer top. Used when `ColumnFns` is unset | +| `ColumnFns` | Caller-supplied `surface` top and material. This crate does not depend on `astraweave-terrain` | | Cosmetic debris | Not represented. Slots are gameplay debris and are hashed | | `GeometryNotice` | Integer box navigation can consume. Reason 2 is a structural collapse | @@ -90,7 +91,7 @@ Floats do not enter this pipeline. Rapier is not called. ### Not touched - `astraweave-physics` `DestructionManager`, `add_destructible_box`, Rapier -- `astraweave-terrain` column generator (PR #215) +- `astraweave-terrain` column generator (the greybox passes function pointers; this crate does not import that crate) - `astraweave-render` passes (PR #216) - `astraweave-combat` (PR #212) @@ -105,7 +106,8 @@ Floats do not enter this pipeline. Rapier is not called. | `astraweave-destruction/src/command.rs` | Command types, validation, canonical bytes | Active | Serde on the command types | | `astraweave-destruction/src/graph.rs` | Nodes, bonds, Tier A, Tier B, climb flags | Active | `Vec` sorted by id. No `HashMap` | | `astraweave-destruction/src/fracture.rs` | Planar cut, seeded Voronoi, `bake_gate` | Active | Bake bytes are the manifest input | -| `astraweave-destruction/src/terrain.rs` | Fixed-capacity brush slab, unload/reload | Active | `i32` height, `i8` density. No map alloc on apply | +| `astraweave-destruction/src/column_base.rs` | `ColumnFns` function pointers | Active | `top` and `material`. No terrain-crate dependency | +| `astraweave-destruction/src/terrain.rs` | Fixed-capacity brush slab, unload/reload | Active | `i32` height, `i8` density. No map alloc on apply. `surface_y` adds the brush delta to `ColumnFns::top` when bound, otherwise to `FlatColumnBase` | | `astraweave-destruction/src/octree.rs` | Sparse voxel DAG for an edited chunk | Active | Shared leaves and branches. Base column fills unedited cells | | `astraweave-destruction/src/jobs.rs` | Two query workers, ordered slot merge | Active | Started in `QueryPool::new`. GPU is not a sim writer | | `astraweave-destruction/src/debris.rs` | 256-slot pool, sleep, eviction | Active | Array, no steady-state alloc | @@ -122,8 +124,8 @@ Floats do not enter this pipeline. Rapier is not called. |---|---|---| | `astraweave-physics` `DestructionManager` | Dormant float toy | Left in place. New calls do not go through it | | `PhysicsWorld::add_destructible_box` | Stub | Not extended | -| Greybox `dig_sphere` / `VoxelEdit` | On main, not this crate | The showcase script is the replacement the demo should call | -| #215 `surface_height` | Not on this branch | `FlatColumnBase` until that PR merges | +| Greybox `dig_sphere` | Calls `apply_brush_now` | Sphere `Subtract` brush, then the island mesh is carved by `seed - surface_y`. A full command log returns before that carve | +| #215 `surface_height` | Bound by the greybox | `column_gen` stays in `astraweave-terrain`. `ColumnFns` is the hook. `FlatColumnBase` stays for the replay case | --- @@ -164,6 +166,7 @@ Floats do not enter this pipeline. Rapier is not called. | 9 | Restoring `persist_bytes` matches the live hash | Yes | `command_log_restores_the_gate_and_the_crater` | | 10 | Parallel occupancy queries match a direct DAG walk | Yes | `parallel_queries_match_the_dag_walk` | | 11 | A collapse notice covers every piece that became `DYNAMIC` this solve, and no piece that was already dynamic | Yes | `collapse_notice_covers_the_dropped_bridge_span` | +| 12 | With `ColumnFns` set, unload then load restores the brush occupancy, and an undug column reports the seed top | Yes | `terrain::tests::seeded_columns_replay_the_same_occupancy` | --- @@ -181,8 +184,8 @@ Caps, not wall-clock gates: 256 debris, 1024 nodes per tick, 8 stress iterations ## 11. Open Questions / Parked Decisions -- **#215 column adapter.** `FlatColumnBase` is the test terrain. After #215 merges, an adapter should call `surface_height` / `column_material` without editing that crate's generator. Tracked in issue #249. -- **Greybox call site.** `aravath_runtime` is on main. The window still calls `dig_sphere`. Replacing that with `DestructionCommand::Brush` is still open. The headless destruction example remains the showcase for this crate. +- **#249 column adapter.** Closed on `5c664f23` for the hook. `ColumnFns::top` is what `surface_y` reads. `ColumnFns::material` is the paired pointer. `rebuild_dag` still fills density overrides only, the same as `TerrainBase::column_material`, which no rebuild calls. The generator, erosion, and scatter in `astraweave-terrain` are not edited here. +- **Greybox brush.** Closed on `5c664f23`. `Ground::dig_sphere` enqueues a sphere `Subtract` brush through `DestructionWorld::apply_brush_now`. The headless `examples/aravath_destruction` binary remains the crate showcase. The visible island hole is the occupancy drop applied to `island::surface_height`, because the streamed voxels are still the island fill. - **Direct stress solve.** A sparse direct solve can replace the 8-iteration push only if it stays integer and ordered. That would change the hash and needs its own review. - **Physics mirror.** Not added. Add `mirror_debris_pose` only when a caller needs a Rapier body it cannot get from the integer query. @@ -199,3 +202,4 @@ Update this trace when the command set, the stress iteration count, the pool siz | 1.0 | 2026-10-15 | Initial trace for the crate, the replay case, and the headless Aravath showcase | | 1.1 | 2026-10-15 | Sparse voxel DAG, ordered query jobs, command-log persistence, weave and navigation notices | | 1.2 | 2026-10-15 | Collapse notices publish the union of newly dynamic piece bounds. Issue #279 | +| 1.3 | 2026-10-16 | `ColumnFns` and `apply_brush_now`. Greybox digs with a brush. `FlatColumnBase` stays the unbound terrain. Issues #249 and #250 | From c2cfb7d29306d7acb03d610eab02c70888279a0c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 16 Oct 2026 14:54:53 +0000 Subject: [PATCH 3/3] fix(author): keep script tests inside the working directory run_author_script rejects files outside the process directory. The mutation tests wrote those scripts under the system temp dir, so every retry failed with an escape error. Co-authored-by: Andrew Brown --- .../mutation_resistant_comprehensive_tests.rs | 91 ++++++++++--------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/astraweave-author/tests/mutation_resistant_comprehensive_tests.rs b/astraweave-author/tests/mutation_resistant_comprehensive_tests.rs index b4f07ca1cc..c0b28705ba 100644 --- a/astraweave-author/tests/mutation_resistant_comprehensive_tests.rs +++ b/astraweave-author/tests/mutation_resistant_comprehensive_tests.rs @@ -4,7 +4,6 @@ //! run_author_script (with a real Rhai script file). use astraweave_author::MapMeta; -use std::io::Write; // ========================================================================= // MapMeta — field access, clone, boundary values @@ -106,29 +105,42 @@ fn map_meta_min_difficulty() { // run_author_script — with a real Rhai file // ========================================================================= +/// The loader rejects paths outside the working directory. Keep the file there. +fn script_in_workdir(name: &str, source: &str) -> (tempfile::TempDir, String) { + let root = std::env::current_dir().expect("workdir"); + let dir = tempfile::tempdir_in(&root).expect("script dir under workdir"); + let file = dir.path().join(name); + std::fs::write(&file, source).expect("write script"); + let rel = file + .strip_prefix(&root) + .expect("script stays under workdir"); + let text = rel + .components() + .map(|component| component.as_os_str().to_string_lossy().into_owned()) + .collect::>() + .join("/"); + (dir, text) +} + #[test] fn run_author_script_simple() { - let dir = tempfile::tempdir().unwrap(); - let script_path = dir.path().join("test.rhai"); - let mut f = std::fs::File::create(&script_path).unwrap(); - write!( - f, + let (_dir, script_path) = script_in_workdir( + "test.rhai", r#" -fn configure(meta) {{ +fn configure(meta) { let traps = meta.difficulty * 2; let terrain_edits = meta.width / 10; let spawns = meta.enemy_count; - let hints = #{{"tip": "use cover"}}; - #{{ + let hints = #{"tip": "use cover"}; + #{ traps: traps, terrain_edits: terrain_edits, spawns: spawns, hints: hints - }} -}} -"# - ) - .unwrap(); + } +} +"#, + ); let meta = MapMeta { width: 100, @@ -137,7 +149,7 @@ fn configure(meta) {{ difficulty: 3, }; let (budget, hints) = - astraweave_author::run_author_script(script_path.to_str().unwrap(), &meta).unwrap(); + astraweave_author::run_author_script(&script_path, &meta).expect("script under workdir"); assert_eq!(budget.traps, 6); // difficulty(3) * 2 assert_eq!(budget.terrain_edits, 10); // width(100) / 10 @@ -147,19 +159,15 @@ fn configure(meta) {{ #[test] fn run_author_script_defaults_on_missing_keys() { - let dir = tempfile::tempdir().unwrap(); - let script_path = dir.path().join("minimal.rhai"); - let mut f = std::fs::File::create(&script_path).unwrap(); - // Return empty map — defaults: traps=1, terrain_edits=2, spawns=1 - write!( - f, + // Empty map — defaults: traps=1, terrain_edits=2, spawns=1 + let (_dir, script_path) = script_in_workdir( + "minimal.rhai", r#" -fn configure(meta) {{ - #{{}} -}} -"# - ) - .unwrap(); +fn configure(meta) { + #{} +} +"#, + ); let meta = MapMeta { width: 10, @@ -168,7 +176,7 @@ fn configure(meta) {{ difficulty: 1, }; let (budget, hints) = - astraweave_author::run_author_script(script_path.to_str().unwrap(), &meta).unwrap(); + astraweave_author::run_author_script(&script_path, &meta).expect("script under workdir"); assert_eq!(budget.traps, 1); // default assert_eq!(budget.terrain_edits, 2); // default @@ -190,29 +198,24 @@ fn run_author_script_nonexistent_file_errors() { #[test] fn run_author_script_meta_fields_passed_correctly() { - let dir = tempfile::tempdir().unwrap(); - let script_path = dir.path().join("echo.rhai"); - let mut f = std::fs::File::create(&script_path).unwrap(); - // Echo back all meta fields as hints so we can verify they arrived - write!( - f, + let (_dir, script_path) = script_in_workdir( + "echo.rhai", r#" -fn configure(meta) {{ - #{{ +fn configure(meta) { + #{ traps: 1, terrain_edits: 2, spawns: 1, - hints: #{{ + hints: #{ w: meta.width, h: meta.height, e: meta.enemy_count, d: meta.difficulty - }} - }} -}} -"# - ) - .unwrap(); + } + } +} +"#, + ); let meta = MapMeta { width: 42, @@ -221,7 +224,7 @@ fn configure(meta) {{ difficulty: 4, }; let (_, hints) = - astraweave_author::run_author_script(script_path.to_str().unwrap(), &meta).unwrap(); + astraweave_author::run_author_script(&script_path, &meta).expect("script under workdir"); assert_eq!(hints["w"], 42); assert_eq!(hints["h"], 99);