**Final verification pass — phase 03 `simulation_movement_and_interaction` (all 5 task files already in `complete/`)** - Verified all phase-03 deliverables exist and work: `sim/` kernel (`step`, `state_build`, `rng`, `movement`, `collision`, `interact`, `carry`, `replay`), replay fixtures + 3 committed goldens, `docs/SIMULATION.md`. - `bash .agents/validate.sh` → **passed**: ruff `All checks passed!`, pyright `0 errors`, `undercooked-levels validate` green, full `pytest` **1033 passed** (coverage **99.71%** ≥ 90% floor), slow sim stage green, repo-hygiene clean. - Perf smoke (4 players, 2 000 ticks): mean **0.049 ms/tick, 20 423 ticks/s** — ≥ 10 000 ticks/s criterion met (test lives in `test_perf_smoke.py`, which the gate's slow stage runs; the overview names it `test_replay.py`). - Completion criteria: import `undercooked.sim.step.step` ✅ · `tests/sim` green incl. determinism + goldens ✅ · perf ✅ · constant-change-fails-by-design ✅ (committed-hash equality + mutation test naming first bad tick/field; goldens never rewritten by tests) · `docs/SIMULATION.md` ✅ (constants, 8-step order, purity/determinism, re-bless) · full suite + coverage ✅ · app launches: `/healthz` 200, `/` 200, `/api/levels` serves content ✅ · replay CLI `check walk_solo.json` exit 0 ✅ · no regression in phases 01/02 (their suites green) ✅. - Documentation: README.md — fixed one stale inconsistency (Status opening listed only 01/02 complete with 03 pending; now lists 01–03 complete, next pending `04_kitchen_pipeline_and_scoring`); all other README claims (CLI flags, config table, shell text, replay CLI exit codes) verified against code. AGENTS.md — verified consistent with the project as it stands, no changes needed. - No deviations. Next pending phase: **`04_kitchen_pipeline_and_scoring`**.
104 lines
3.6 KiB
Python
104 lines
3.6 KiB
Python
"""The headless perf smoke (PLAN §10, marked `slow` so the quick loop skips it).
|
|
|
|
Four cooks, 2 000 ticks on the shipped level 1, one direction per cook per tick
|
|
drawn from the sim's own splitmix64 (a fixed seed — the walk is a property of
|
|
the script, not of the machine). The budget is the task's: mean step
|
|
**< 0.2 ms** and total **< 400 ms** — 5 000+ ticks/s, two and a half orders
|
|
of magnitude more than the 20 Hz the rooms run at — and the measured numbers
|
|
are printed in the report so a slow machine shows up in the gate, not as a
|
|
silent failure.
|
|
|
|
The loop times `step()` directly (no hash recording), so the number is the
|
|
kernel's tick cost, exactly what the §10 budget (mean ≤ 2 ms/room) is about;
|
|
`run_script`'s injected `clock` seam is what a full-harness measurement goes
|
|
through instead, and `test_replay.py` pins that seam.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from undercooked.sim.content import load_content
|
|
from undercooked.sim.model import Vec2
|
|
from undercooked.sim.rng import Rng
|
|
from undercooked.sim.state_build import SeatSpec, build_state
|
|
from undercooked.sim.step import STEP_DT, PlayerInput, step
|
|
|
|
pytestmark = [pytest.mark.slow]
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
SHIPPED_LEVELS = REPO_ROOT / "levels"
|
|
|
|
#: The campaign, read once at import (the same seam `test_movement_kernel` uses).
|
|
CAMPAIGN = load_content(SHIPPED_LEVELS, SHIPPED_LEVELS / "recipes.yaml")
|
|
|
|
TICKS = 2000
|
|
SEED = 0x0D1C
|
|
COOKS = 4
|
|
|
|
#: The task's budget: mean step < 0.2 ms, total < 400 ms on the dev machine.
|
|
BUDGET_MEAN_S = 0.0002
|
|
BUDGET_TOTAL_S = 0.4
|
|
|
|
#: The eight compass directions plus standing still, as a fixed tuple so
|
|
#: `Rng.choice` (the sim's own generator) is the only source of variation.
|
|
DIRECTIONS: tuple[Vec2, ...] = (
|
|
Vec2(1, 0),
|
|
Vec2(1, 1),
|
|
Vec2(0, 1),
|
|
Vec2(-1, 1),
|
|
Vec2(-1, 0),
|
|
Vec2(-1, -1),
|
|
Vec2(0, -1),
|
|
Vec2(1, -1),
|
|
Vec2(0, 0),
|
|
)
|
|
|
|
|
|
def seats(cooks: int) -> tuple[SeatSpec, ...]:
|
|
"""Four anonymous seats in seat order; spawns wrap past the second (the
|
|
level has two), with the stack offset `build_state` applies."""
|
|
return tuple(
|
|
SeatSpec(player_id=f"p{index}", seat=index, display_name=f"p{index}")
|
|
for index in range(cooks)
|
|
)
|
|
|
|
|
|
def test_four_cook_kitchen_stays_within_the_perf_budget() -> None:
|
|
level = CAMPAIGN.by_id["01_first_kitchen"]
|
|
state = build_state(level, seats(COOKS), SEED, CAMPAIGN.recipe_book)
|
|
rng = Rng(SEED)
|
|
start = time.perf_counter()
|
|
for tick in range(TICKS):
|
|
inputs = [
|
|
PlayerInput(
|
|
player_id=f"p{seat}",
|
|
seq=tick,
|
|
move=rng.choice(DIRECTIONS),
|
|
received_at_tick=tick,
|
|
)
|
|
for seat in range(COOKS)
|
|
]
|
|
state, _ = step(state, STEP_DT, inputs)
|
|
total = time.perf_counter() - start
|
|
mean = total / TICKS
|
|
print(
|
|
f"perf smoke (level 1, {COOKS} cooks, {TICKS} ticks): "
|
|
f"total {total * 1000:.1f} ms, mean {mean * 1000:.4f} ms/tick, "
|
|
f"{1 / mean:,.0f} ticks/s"
|
|
)
|
|
assert mean < BUDGET_MEAN_S, (
|
|
f"mean step {mean * 1000:.4f} ms is over the {BUDGET_MEAN_S * 1000:.1f} ms budget"
|
|
)
|
|
assert total < BUDGET_TOTAL_S, (
|
|
f"{TICKS} ticks took {total * 1000:.1f} ms, over the {BUDGET_TOTAL_S * 1000:.0f} ms budget"
|
|
)
|
|
# cheap invariants: the walk stayed inside the kitchen, the tick ran to the end
|
|
assert state.tick == TICKS
|
|
for player in state.players:
|
|
assert 0.35 < player.pos.x < level.grid.width - 0.35
|
|
assert 0.35 < player.pos.y < level.grid.height - 0.35
|