Testing an ARPG that agents wrote

561 tests and 346,430 assertions covering procgen over hundreds of seeds, balance tables that fail the build and sim tests on the real World, plus browser and forty-client load harnesses.

Eight procedurally generated maps in a grid, one per biome from Act 1 fields to the Act 6 mirror halls, rendered as top-down previews with roads, exits and spawn points
Contents
  1. Where the tests live
  2. Procgen: determinism is the contract
  3. Connectivity over many seeds
  4. Generation has a time budget
  5. Balance tables that fail the build
  6. The rift tier curve
  7. Sim tests drive the real World
  8. Browser verification with bx and in-page controllers
  9. Headless load harnesses
  10. Budgets, in one place
  11. What the suite doesn't cover
  12. Related posts

About 105,000 lines of TypeScript went in on one day from a dozen parallel agents, and nobody reads all of it line by line, including me. Two things do the reading: the type checker (strict, noUncheckedIndexedAccess, no any) and the tests.

bun run test
 561 pass
 0 fail
 346430 expect() calls
Ran 561 tests across 47 files. [46.34s]

Around the suite: bx browser verification, headless load harnesses, and asserted perf budgets.

Where the tests live

Area Files What they pin down
shared/combat 5 formulas, and balance tables per act, class and level
shared/items 4 rolls, affixes, inventory footprints, drops
server/game/sim 4 the real World: combat, loot, XP, quests, bosses, act mechanics
server/game (+ rooms, pets, endgame, companions, admin) 9 hub eviction, parties, persistence, event fan-out, AI companions
shared/endgame 2 difficulties, sockets, runewords, the rift tier curve
shared/procgen, shared/nav, shared/world 3 determinism, connectivity, structure, generation time
src/game/input, src/game/ui 9 gamepad and touch logic, menu navigation, chat commands
everything else 11 housing, pets, item catalog, admin, routers, protocol

Game rules are plain objects in shared/ and server/game/sim/ with no sockets, DOM or Three.js, so nearly everything tests as a pure function or a tick() loop.

Procgen: determinism is the contract

Maps never cross the wire, so server and clients must build byte-identical tiles (procedural worlds):

shared/rng.tsTypeScript
// Deterministic, seedable PRNG shared by client and server.
// Procgen MUST only use this (never Math.random) so both sides build identical maps.

The test doesn't trust the rule. Every sample zone at three seeds, compared on tiles, variants, props and a JSON snapshot; two different seeds must differ, so a generator ignoring its seed fails too:

shared/procgen/procgen.test.tsTypeScript
describe('determinism', () => {
  for (const input of SAMPLE_INPUTS) {
    test(input.id, () => {
      for (const seed of [1, 42, 0xdeadbeef]) {
        const a = generateZone({ ...input, seed })
        const b = generateZone({ ...input, seed })
        expect(Buffer.from(a.tiles).equals(Buffer.from(b.tiles))).toBe(true)
        expect(Buffer.from(a.variant).equals(Buffer.from(b.variant))).toBe(true)
        expect(a.props).toEqual(b.props)
        expect(snapshot(a)).toBe(snapshot(b))
      }
      if (input.kind !== 'town') {
        const c = generateZone({ ...input, seed: 2 })
        const d = generateZone({ ...input, seed: 3 })
        expect(Buffer.from(c.tiles).equals(Buffer.from(d.tiles))).toBe(false)
      }
    })
  }
})

Connectivity over many seeds

A level that's usually fine is broken: some seed walls off the exit. 50 seeds per sample through validateZone:

shared/procgen/procgen.test.tsTypeScript
describe(`connectivity over ${SEEDS} seeds`, () => {   // SEEDS = 50
  for (const input of SAMPLE_INPUTS) {
    test(input.id, () => {
      const failures: string[] = []
      for (let s = 0; s < SEEDS; s++) {
        const seed = (s * 2654435761) >>> 0
        const map = generateZone({ ...input, seed })
        const v = validateZone(map)
        if (!v.ok) failures.push(`seed ${seed}: ${v.problems.join('; ')}`)
        if (map.spawns.length > 0) expect(v.spawnsReachable).toBe(v.spawnsTotal)
      }
      expect(failures).toEqual([])
    })
  }
})

A second file runs every real ZoneDef in all six acts through zoneGenInputFor on eight seeds, checking biome, exit ids and validity, so a new zone was tested before anyone visited it.

Three Storm Coast maps from seeds 1, 2 and 3: the same coastline rules, different roads, lakes and cliffs
bun scripts/procgen-preview.ts a4_storm_coast --seeds 1,2,3. Same generator and rules, three seeds, three maps, each validated connected

Structural assertions:

  • Mirror halls are bilaterally symmetric
  • The Gloam Heart spirals in to its seat
  • Ice is walkable; abyss blocks walking, not sight
  • No pack within 16 tiles of an arrival point or waypoint
  • Every dungeon entrance room has a free-standing light
  • Rift floors are valid for every dungeon biome at any seed, depth and size
The Gloam Heart dungeon preview: a spiral of corridors winding inward to the throne
a6_gloam_heart_2, seed 1. 'The gloam heart spirals in to its seat' is an assertion, and this is what it asserts

Generation has a time budget

Generation is load time on server and client. The largest version of every map (wilderness 180×180, dungeons 140×140), five runs, median under 50 ms:

shared/procgen/procgen.test.tsTypeScript
test('generation < 50 ms for the largest maps', () => {
  // … wilderness at 180×180, dungeons at 140×140, every town
  for (const input of big) {
    generateZone({ ...input, seed: 999 }) // warm-up
    const times: number[] = []
    for (let s = 0; s < 5; s++) {
      const t0 = performance.now()
      generateZone({ ...input, seed: 1000 + s })
      times.push(performance.now() - t0)
    }
    times.sort((a, b) => a - b)
    const median = times[2] ?? 0
    expect(median).toBeLessThan(50)
  }
})
Median generation time per wilderness zone at 180×180: 16.4 ms to 37.0 ms, all under the 50 ms line
The heaviest map is Shipwreck Shoals at 37 ms (sea, shoals and wrecks). Dungeons are 2–5 ms, towns 1–2 ms

Balance tables that fail the build

Every balance claim prints its table and asserts a band, using the server's own deriveStats, monsterStats and hit formulas, hundreds of swings per pairing:

shared/combat/balanceEarly.test.ts (output, trimmed)
L1 (life: warden 79, stalker 61, emberwright 52) — landed hits to die / seconds vs one monster | time to kill it with the starting skill:
│ monster       │ mlvl │ warden              │ stalker            │ emberwright        │
│ zombie        │ 2    │ 40h 95s | ttk 3.3s  │ 31h 56s | ttk 3.0s │ 27h 45s | ttk 2.8s │
│ blightwolf    │ 2    │ 30h 36s | ttk 3.3s  │ 23h 22s | ttk 3.0s │ 20h 19s | ttk 2.5s │
│ bog_slime     │ 2    │ 27h 67s | ttk 5.8s  │ 21h 39s | ttk 6.1s │ 18h 31s | ttk 4.7s │
│ gloam_cultist │ 4    │ 23h 51s | ttk 7.3s  │ 18h 32s | ttk 6.9s │ 15h 27s | ttk 3.7s │
│ ghoul         │ 6    │ 13h 17s | ttk 11.7s │ 10h 11s | ttk 12.0s│ 9h 9s | ttk 4.5s   │
│ crypt_golem   │ 12   │ 4h 9s | ttk 405.4s  │ 3h 6s | ttk 380.6s │ 3h 5s | ttk 45.5s  │

Assertions are in player terms:

shared/combat/balanceEarly.test.tsTypeScript
test('a L1 hero in the starting kit takes 15+ landed hits from Blighted Fields trash (warden 25+)', () => {
  const bad: string[] = []
  for (const cls of CLS) {
    const floor = cls === 'warden' ? 25 : 15
    for (const m of FIELDS_TRASH) {
      const h = hitsToDie(BUILDS[cls][1], m, FIELDS.level)
      if (h.landed < floor) bad.push(`${m} vs ${cls}@1: ${h.landed.toFixed(1)} landed hits (< ${floor})`)
    }
  }
  expect(bad).toEqual([])
})
  • Whole pack: life plus one minor potion covers a full pack fought one at a time with margin ≥ 1.1, and the hero survives at least 4 s under it
  • Mid-Act 1 stays dangerous, so the first-zone fix can't trivialize the act
  • Collect, then assert: every failure goes into bad before one expect, so a red run lists everything out of band at once

Acts 2–3 and 4–6 follow the same pattern, bosses included:

shared/combat/balanceActs456.test.tsTypeScript
test('the nine act 4–6 bosses take a solo player about one to five minutes', () => {
  const fights = [
    ['captain_vane', 50], ['drowned_choir', 50], ['leviathan', 50], ['glacier_wyrm', 60], ['frost_titan', 60], ['winter_queen', 60],
    ['the_architect', 70], ['hollow_saint', 70], ['the_unmaker', 70],
  ]
  for (const [boss, plvl] of fights) {
    const zone = ZONES.find((z) => z.boss?.monster === boss)
    const mlvl = zone?.level ?? 1
    for (const cls of CLASSES) {
      const b = { ...BUILDS[cls][plvl], level: Math.max(plvl, mlvl - 2) }
      const r = simulate(b, boss, mlvl, 'boss', 30)
      // the finale is meant to be the longest fight in the game
      const max = boss === 'the_unmaker' ? 420 : 300
      if (r.seconds < 25 || r.seconds > max) bad.push(`${cls} vs ${boss}: ${Math.round(r.seconds)}s`)
    }
  }
  expect(bad).toEqual([])
})

Others check that monsters threaten but never one-shot a geared hero of their stage, and that XP carries a hero from ~45 to ~75 across Acts 4–6, with 75–99 as a long chase. Formulas: combat math.

The rift tier curve

Each tier is measured at its target level against its real pool and guardians; bands at five checkpoints, strictly worse past 25:

shared/endgame/riftBalance.test.tsTypeScript
band(1, 2.5, 10)   // comfortable for a fresh 40
band(5, 3.5, 6)
band(10, 7.5, 5)   // Act 6 for a geared ~72
band(15, 10, 4.5)
band(25, 16, 3, 18) // a level-90 challenge
// and past that it keeps getting worse until it is out of reach
for (const cls of CLASSES) {
  const a = got.get(`25|${cls}`)
  const c = got.get(`40|${cls}`)
  const e = got.get(`55|${cls}`)
  if (!a || !c || !e) continue
    if (!(c.ttk > a.ttk && e.ttk > c.ttk)) bad.push(`${cls}: ttk not rising past T25`)
  if (!(e.hits < a.hits)) bad.push(`${cls}: danger not rising past T25`)
  if (!(e.ttk > 25 || e.hits < 2.5)) bad.push(`${cls}: T55 still playable at 99 (ttk ${e.ttk.toFixed(1)}s, ${e.hits.toFixed(1)} hits)`)
}
Two line charts across tiers 1 to 55: a monster's landed hits to kill the hero fall for all three classes, and the hero's time to kill rises
Straight from the table riftBalance.test.ts prints. The Warden stays the tankiest at every tier, which the test comments call out

The same file checks that Nightmare Act 1 is about as dangerous for a fresh level-75 as Normal Acts 5–6. It exists because the first Nightmare (+30 flat levels) left Act 1 trivial for exactly that hero.

Sim tests drive the real World

A test builds a real World from a real zone and seed, adds real players from starting saves, and calls the same runCommand a socket would (the sim):

server/game/sim/sim.test.tsTypeScript
function world(zoneId: string, populate = false): World {
  return new World({ zoneId, seed: 1234, rngSeed: 99, populate })
}
 
function run(w: World, ms: number, until?: () => boolean): void {
  for (let t = 0; t < ms; t += DT) {
    w.tick(DT)
    if (until?.()) return
  }
}
 
test('crossing a life threshold enters the next phase, yells and summons adds', () => {
  const w = world('a1_hollow_graveyard')
  const spot = openRow(w, 8)
  player(w, 'warden', spot)
  const boss = monster(w, 'gravekeeper_mordrin', spot.x + 6, spot.y, 'boss')
  run(w, 500)
  const before = w.monsters.size
  boss.hp = boss.hpMax * 0.4
  run(w, 1500, () => boss.phase === 1)
  expect(boss.phase).toBe(1)
  expect(boss.dmgMult).toBeGreaterThan(1)
  expect(w.monsters.size).toBe(before + 4)
  const evs = w.drainEvents()
  expect(evs.some((e) => isEvent(e.ev, 'fx') && e.ev.payload.kind === 'boss_phase')).toBe(true)
})

No mocks. The sim suite covers:

  • Combat, loot, XP, kill-count quest progress
  • Walls stopping projectiles; knockback
  • Instanced loot staying with its owner; hand-dropped items taken by another player exactly once
  • Every Act 4–6 mechanic: tide, frostbite and warmth, the Choir's shared pool, the Architect's and Unmaker's tiles, mirror knights
  • Budget: 200 monsters plus ten players in the Blighted Fields tick under 50 ms

Room-level tests cover concurrency: hub eviction order on a second-tab login, party names across zone changes, companion targeting and respawns, the fan-out byte budget.

Browser verification with bx and in-page controllers

Every agent verified its feature in a real browser through bx with its own named profile and server on an uncommon port; the same recipes run against production. Two profiles are two computers:

verify.md — two-player check (condensed)Shell
bx open <origin>/ --profile deploy           # create or pick a hero, land on /play
bx js "(()=>{window.__gr.actions.useExit('to_fields'); return 'ok'})()" --profile deploy
# → window.__gr.session.room.state.zoneId === 'a1_blighted_fields', ~120 monsters
# attack the nearest monster: window.__gr.actions.attack(<id>) on an interval → it dies
# repeat with --profile deploy2 → same room.roomId, both names in room.state.players
bx console ; bx net --failed                 # (none) on both

GameClient exposes the live game:

src/game/GameClient.tsxTypeScript
window.__gr = { engine, session, store: gameStore, actions: gameActions, bus: gameBus, audio }

That makes in-page bots trivial. The early-game fix was verified with one: a fresh level-1 Emberwright standing and casting in the Blighted Fields got 28 kills in ~100 s with zero deaths, lowest life 18 of 52. Without potions it died after 7 kills. Table and browser agreed.

  • window.__grPad: a virtual gamepad on the real code path (controller and touch)
  • window.__grHousing: drives build mode
  • window.__gr.engine.lookAt: parks the camera for screenshots
  • window.__gr.engine.stats.last: fps, draw calls, triangles; how "every biome at 60 fps" was checked

Headless load harnesses

Script What it is Measures
scripts/bots.ts N guest accounts over real websockets with the real @colyseus/sdk, wandering and fighting in one instance tick avg/p95/max from /api/status, KB/s per client (the bot wraps WebSocket to count bytes)
scripts/showcase.ts 40 level 99 heroes with full kits; a leader marches with A*, and the pack spams class skills the worst case: tick phases, casts per second, bandwidth
scripts/room-perf.ts a regression bench: boots its own non-watching server, runs the showcase pack through fixed scenarios pass/fail against a written budget
scripts/companion-perf.ts socket-free World + RoomCompanions: N owners with 0 or 3 AI companions each the sim and AI cost alone

A written budget makes room-perf.ts a test, not a benchmark:

scripts/room-perf.tsTypeScript
// Room tick regression bench: boots its own server (non-watch, dev mode so `devZone` joins work) on
// an uncommon port, runs the 40-hero headless showcase (scripts/showcase.ts run --camera headless)
// through each scenario, and prints tick avg / p95 / max, the per-phase breakdown
// (rooms/tickProfile.ts via /api/status) and downstream KB/s per client. Stops everything it starts.
// …
// Needs the dev DB (`bun run db:dev`) and the heroes from `bun scripts/showcase.ts prep` on the
// same difficulty. Budget: tick avg ≤ 10 ms, p95 ≤ 35 ms, ≤ ~20 KB/s per client.
Run Tick avg p95 Per client
bots.ts, 40 low-level bots, ~160 monsters 1.2 ms ≤ 4 ms ~10 KB/s
companion-perf.ts, 40 owners + 120 companions 0.29 ms 0.65 ms n/a
showcase.ts, Hollow Sanctum boss, before fan-out rework 12.6 ms 56 ms 42 KB/s
room-perf.ts, same scenario, after 1.6 ms 4.4 ms 19.5 KB/s

Low-level bots barely cast; maxed heroes emit hundreds of events a tick. A load test has to model the most expensive real player, so the showcase pack is now the regression bench (forty players).

Budgets, in one place

Budget Where it's enforced Current
Zone generation < 50 ms median (largest maps) procgen.test.ts 16–37 ms wilderness, 2–5 ms dungeons
200 monsters + 10 players tick < 50 ms sim.test.ts passes
Room tick avg ≤ 10 ms, p95 ≤ 35 ms, ~20 KB/s, 40 heroes room-perf.ts 1.6–1.8 ms avg, ~4.5 ms p95 at bosses
Every biome at 60 fps bx + engine.stats met; the frozen forest's pine wall was thinned to get there
Shipped assets ~15 MB scripts/assets/build.ts reports it 15.0 MB

What the suite doesn't cover

  • Rendering: no pixel diffs; screenshots and the stats handle only
  • End to end: the Playwright suite is a smoke test (landing, 404, guest to /play)
  • Feel: tables prove numbers are in band, not that the band is right. The first-zone band moved after real play showed the old floor was too low.