aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 2ca665d99cb769051aceeeee1e2e19f2e490a68d
parent a40d4c097c8d178e823e919719a5430d4de14dea
Author: anon <anon@example.com>
Date:   Fri, 16 Oct 2026 21:37:07 +0000

Make Go tests self-contained and validate clean-clone handoff

Diffstat:
Mdocs/repository-packaging.md | 27+++++++++++++++++++++++++++
Mserver/npcs_test.go | 37++++++++++++-------------------------
Aserver/testdata/README.md | 9+++++++++
Aserver/testdata/npc-populations.json | 253+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Makefile.wasm | 6+++---
Mtools/README.md | 10++++++++--
Mtools/client/package_runtime.py | 1+
7 files changed, 313 insertions(+), 30 deletions(-)

diff --git a/docs/repository-packaging.md b/docs/repository-packaging.md @@ -36,6 +36,11 @@ Go 1.24 or newer and a compatible browser are sufficient. The first Go build may download the small Go module dependencies. Open `http://127.0.0.1:8080/wasm/`. The server stays on loopback; run it on the laptop where the browser is running. +`go test ./server` prepares bundled inputs if necessary and then runs against +temporary copies, away from saved characters. The authored NPC population +expectations are checked in under `server/testdata/`; the full extraction +catalog and Python data tools are not required for Go tests. + The checked-in browser build is about 46 MiB compressed. Runtime data occupies about 906 MiB compressed, split into 48 MiB parts so no individual blob is huge. This includes all portable 14.9.1 playfields, audio, textures, fonts/configuration, @@ -55,6 +60,28 @@ Allow roughly 4 GiB for a normal checkout, Git history and unpacked runtime data, before browser caches. Compiler tools and intermediate build objects add several more GiB only on client build machines. +## Handoff verification + +A separate normal clone with no `toolchains/`, `src/build/`, local game assets +or saved characters started with `go run ./server`. First-run verification and +extraction completed in about six seconds. The unpacked checkout, including Git, +occupied 3.7 GiB. The published page rendered Bronto Burger and opened inventory +and the world map. Its WASM response supplied gzip, `application/wasm` and the +required isolation headers. + +An uncommitted scene-test page using the same published JS/WASM pair verified +a two-second forward hold: the server position changed from +`[960, 16.375, 510]` to `[958.25, 16.375, 508.25]`, with the character connected. +The audio check recorded 5,509,120 PCM frames and peak amplitude 1. Browser +warning/error checks were empty. This is a Bronto Burger handoff check, not a +validation of all playfields. + +The Go suite passed in that clone in 55.659 seconds using the checked-in NPC +expectations. Running it concurrently with browser startup had exceeded an +existing five-second socket deadline; the successful run used an idle browser. +Test deadlines were not relaxed. Temporary test servers and browser tabs were +stopped afterward. + ## Updating published files `make wasm -j8` builds dependencies and the client, then publishes the matching diff --git a/server/npcs_test.go b/server/npcs_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + _ "embed" "encoding/binary" "encoding/json" "net" @@ -11,11 +12,17 @@ import ( "time" ) +//go:embed testdata/npc-populations.json +var authoredPopulations []byte + func TestMain(m *testing.M) { // Keep persistence tests away from the developer's live user file. if err := os.Chdir(".."); err != nil { panic(err) } + if err := prepareRuntime(); err != nil { + panic(err) + } directory, err := os.MkdirTemp("", "ao-tests-") if err != nil { panic(err) @@ -25,7 +32,7 @@ func TestMain(m *testing.M) { panic(err) } } - for _, name := range []string{"data/npc_spawns.yaml", "data/terrain.bin", "data/zone_links.yaml", "data/npc-spawns.json"} { + for _, name := range []string{"data/npc_spawns.yaml", "data/terrain.bin", "data/zone_links.yaml"} { contents, err := os.ReadFile(name) if err != nil { panic(err) @@ -131,18 +138,11 @@ func TestPopulationsAreSharedAndZoneScoped(t *testing.T) { } func TestEveryAuthoredPopulationIsSent(t *testing.T) { - data, err := os.ReadFile("data/npc-spawns.json") - if err != nil { - t.Fatal(err) - } var catalog []struct { Playfield uint32 - Districts []struct { - SpawnGroups []struct{ Count int } `json:"spawn_groups"` - FixedSpawns []json.RawMessage `json:"fixed_spawns"` - } + Count int } - if err := json.Unmarshal(data, &catalog); err != nil { + if err := json.Unmarshal(authoredPopulations, &catalog); err != nil { t.Fatal(err) } world := newTestServer(t) @@ -150,19 +150,6 @@ func TestEveryAuthoredPopulationIsSent(t *testing.T) { var guard, highLevel []byte for _, playfield := range catalog { - if playfield.Playfield == 100 || playfield.Playfield == 102 || playfield.Playfield == 103 || playfield.Playfield == 1410 { - continue - } - requested := 0 - for _, district := range playfield.Districts { - requested += len(district.FixedSpawns) - for _, group := range district.SpawnGroups { - requested += group.Count - } - } - if requested == 0 { - continue - } player := world.newCharacter() player.playfield = playfield.Playfield client, connection := net.Pipe() @@ -189,8 +176,8 @@ func TestEveryAuthoredPopulationIsSent(t *testing.T) { } } client.Close() - if count != requested { - t.Fatalf("playfield %d: got %d NPCs, disc requests %d", playfield.Playfield, count, requested) + if count != playfield.Count { + t.Fatalf("playfield %d: got %d NPCs, disc requests %d", playfield.Playfield, count, playfield.Count) } total += count populated++ diff --git a/server/testdata/README.md b/server/testdata/README.md @@ -0,0 +1,9 @@ +# Server test fixtures + +`npc-populations.json` records the authored population count for each of the +251 playfields covered by `TestEveryAuthoredPopulationIsSent` (68,609 NPCs). +These are fixed expected values from the original extracted spawn catalog, +independent of the editable `data/npc_spawns.yaml` used by the server. +The full extraction is unnecessary for ordinary Go tests. + +Source: `data/npc-spawns.json`, SHA-256 `eeb2b86e4bed223eb06e8d52cd31bafe94747a64b6def122f71496fe7d15bf93`. diff --git a/server/testdata/npc-populations.json b/server/testdata/npc-populations.json @@ -0,0 +1,253 @@ +[ + {"playfield": 120, "count": 118}, + {"playfield": 125, "count": 219}, + {"playfield": 127, "count": 324}, + {"playfield": 500, "count": 8}, + {"playfield": 505, "count": 1807}, + {"playfield": 540, "count": 47}, + {"playfield": 545, "count": 82}, + {"playfield": 550, "count": 1015}, + {"playfield": 551, "count": 2063}, + {"playfield": 560, "count": 2011}, + {"playfield": 565, "count": 2794}, + {"playfield": 566, "count": 37}, + {"playfield": 567, "count": 2145}, + {"playfield": 570, "count": 2922}, + {"playfield": 585, "count": 2071}, + {"playfield": 586, "count": 304}, + {"playfield": 590, "count": 2260}, + {"playfield": 595, "count": 2347}, + {"playfield": 600, "count": 1990}, + {"playfield": 605, "count": 2277}, + {"playfield": 610, "count": 1578}, + {"playfield": 615, "count": 2359}, + {"playfield": 620, "count": 2335}, + {"playfield": 625, "count": 1973}, + {"playfield": 630, "count": 2410}, + {"playfield": 635, "count": 1823}, + {"playfield": 640, "count": 50}, + {"playfield": 646, "count": 1842}, + {"playfield": 647, "count": 1793}, + {"playfield": 650, "count": 1509}, + {"playfield": 655, "count": 2147}, + {"playfield": 665, "count": 3164}, + {"playfield": 670, "count": 2139}, + {"playfield": 685, "count": 1357}, + {"playfield": 687, "count": 389}, + {"playfield": 695, "count": 2151}, + {"playfield": 696, "count": 941}, + {"playfield": 700, "count": 34}, + {"playfield": 705, "count": 85}, + {"playfield": 710, "count": 55}, + {"playfield": 716, "count": 1797}, + {"playfield": 717, "count": 1467}, + {"playfield": 730, "count": 14}, + {"playfield": 735, "count": 37}, + {"playfield": 740, "count": 37}, + {"playfield": 760, "count": 2592}, + {"playfield": 790, "count": 1437}, + {"playfield": 791, "count": 509}, + {"playfield": 795, "count": 2170}, + {"playfield": 800, "count": 267}, + {"playfield": 896, "count": 7}, + {"playfield": 950, "count": 50}, + {"playfield": 952, "count": 58}, + {"playfield": 954, "count": 88}, + {"playfield": 1004, "count": 35}, + {"playfield": 1136, "count": 1}, + {"playfield": 1137, "count": 1}, + {"playfield": 1183, "count": 1}, + {"playfield": 1184, "count": 1}, + {"playfield": 1185, "count": 1}, + {"playfield": 1186, "count": 1}, + {"playfield": 1187, "count": 2}, + {"playfield": 1651, "count": 2}, + {"playfield": 1826, "count": 2}, + {"playfield": 1833, "count": 36}, + {"playfield": 1836, "count": 13}, + {"playfield": 1840, "count": 6}, + {"playfield": 1846, "count": 3}, + {"playfield": 1862, "count": 166}, + {"playfield": 1886, "count": 1}, + {"playfield": 1887, "count": 1}, + {"playfield": 1891, "count": 1}, + {"playfield": 1892, "count": 3}, + {"playfield": 1893, "count": 3}, + {"playfield": 1902, "count": 2}, + {"playfield": 1913, "count": 6}, + {"playfield": 1931, "count": 253}, + {"playfield": 1933, "count": 49}, + {"playfield": 1941, "count": 194}, + {"playfield": 1943, "count": 45}, + {"playfield": 2001, "count": 1}, + {"playfield": 2002, "count": 1}, + {"playfield": 2003, "count": 1}, + {"playfield": 2004, "count": 1}, + {"playfield": 2005, "count": 1}, + {"playfield": 2010, "count": 1}, + {"playfield": 2011, "count": 1}, + {"playfield": 2012, "count": 1}, + {"playfield": 2013, "count": 1}, + {"playfield": 2020, "count": 1}, + {"playfield": 2021, "count": 1}, + {"playfield": 2022, "count": 1}, + {"playfield": 2023, "count": 1}, + {"playfield": 2030, "count": 1}, + {"playfield": 2031, "count": 1}, + {"playfield": 2032, "count": 1}, + {"playfield": 2033, "count": 1}, + {"playfield": 2034, "count": 1}, + {"playfield": 2040, "count": 1}, + {"playfield": 2041, "count": 1}, + {"playfield": 2042, "count": 1}, + {"playfield": 2043, "count": 1}, + {"playfield": 2050, "count": 1}, + {"playfield": 2051, "count": 1}, + {"playfield": 2052, "count": 1}, + {"playfield": 2053, "count": 1}, + {"playfield": 2060, "count": 1}, + {"playfield": 2061, "count": 1}, + {"playfield": 2062, "count": 1}, + {"playfield": 2063, "count": 1}, + {"playfield": 2064, "count": 1}, + {"playfield": 2070, "count": 1}, + {"playfield": 2071, "count": 1}, + {"playfield": 2072, "count": 1}, + {"playfield": 2073, "count": 1}, + {"playfield": 2096, "count": 1}, + {"playfield": 3000, "count": 1}, + {"playfield": 3001, "count": 1}, + {"playfield": 3002, "count": 1}, + {"playfield": 3003, "count": 1}, + {"playfield": 3004, "count": 1}, + {"playfield": 3005, "count": 1}, + {"playfield": 3006, "count": 1}, + {"playfield": 3007, "count": 1}, + {"playfield": 3008, "count": 1}, + {"playfield": 3009, "count": 1}, + {"playfield": 3010, "count": 1}, + {"playfield": 3011, "count": 1}, + {"playfield": 3012, "count": 1}, + {"playfield": 3013, "count": 1}, + {"playfield": 3014, "count": 1}, + {"playfield": 3015, "count": 1}, + {"playfield": 3016, "count": 1}, + {"playfield": 3017, "count": 1}, + {"playfield": 3018, "count": 1}, + {"playfield": 3019, "count": 1}, + {"playfield": 3020, "count": 1}, + {"playfield": 3021, "count": 1}, + {"playfield": 3022, "count": 1}, + {"playfield": 3023, "count": 1}, + {"playfield": 3024, "count": 1}, + {"playfield": 3025, "count": 1}, + {"playfield": 3026, "count": 1}, + {"playfield": 3027, "count": 1}, + {"playfield": 3028, "count": 1}, + {"playfield": 3029, "count": 1}, + {"playfield": 3030, "count": 1}, + {"playfield": 3031, "count": 1}, + {"playfield": 3032, "count": 1}, + {"playfield": 3033, "count": 1}, + {"playfield": 3034, "count": 1}, + {"playfield": 3035, "count": 1}, + {"playfield": 3036, "count": 1}, + {"playfield": 3037, "count": 1}, + {"playfield": 3038, "count": 1}, + {"playfield": 3039, "count": 1}, + {"playfield": 3040, "count": 1}, + {"playfield": 3041, "count": 1}, + {"playfield": 3042, "count": 1}, + {"playfield": 3043, "count": 1}, + {"playfield": 3044, "count": 1}, + {"playfield": 3045, "count": 1}, + {"playfield": 3046, "count": 1}, + {"playfield": 3047, "count": 1}, + {"playfield": 3048, "count": 1}, + {"playfield": 3049, "count": 1}, + {"playfield": 3050, "count": 1}, + {"playfield": 3051, "count": 1}, + {"playfield": 3052, "count": 1}, + {"playfield": 3053, "count": 1}, + {"playfield": 3054, "count": 1}, + {"playfield": 3055, "count": 1}, + {"playfield": 3056, "count": 1}, + {"playfield": 3057, "count": 1}, + {"playfield": 3058, "count": 1}, + {"playfield": 3059, "count": 1}, + {"playfield": 3060, "count": 1}, + {"playfield": 3061, "count": 1}, + {"playfield": 3062, "count": 1}, + {"playfield": 3063, "count": 1}, + {"playfield": 3064, "count": 1}, + {"playfield": 3065, "count": 1}, + {"playfield": 3066, "count": 1}, + {"playfield": 3067, "count": 1}, + {"playfield": 3068, "count": 1}, + {"playfield": 3069, "count": 1}, + {"playfield": 3070, "count": 1}, + {"playfield": 3071, "count": 1}, + {"playfield": 3080, "count": 1}, + {"playfield": 3081, "count": 1}, + {"playfield": 3082, "count": 1}, + {"playfield": 3083, "count": 1}, + {"playfield": 3084, "count": 1}, + {"playfield": 3085, "count": 1}, + {"playfield": 3086, "count": 1}, + {"playfield": 3087, "count": 1}, + {"playfield": 3088, "count": 1}, + {"playfield": 3089, "count": 1}, + {"playfield": 3100, "count": 1}, + {"playfield": 3101, "count": 1}, + {"playfield": 3102, "count": 1}, + {"playfield": 3103, "count": 1}, + {"playfield": 3104, "count": 1}, + {"playfield": 3105, "count": 1}, + {"playfield": 3106, "count": 1}, + {"playfield": 3107, "count": 1}, + {"playfield": 3108, "count": 1}, + {"playfield": 3109, "count": 1}, + {"playfield": 3110, "count": 1}, + {"playfield": 3111, "count": 1}, + {"playfield": 3112, "count": 1}, + {"playfield": 3113, "count": 1}, + {"playfield": 3114, "count": 1}, + {"playfield": 3115, "count": 1}, + {"playfield": 3116, "count": 1}, + {"playfield": 3117, "count": 1}, + {"playfield": 3120, "count": 1}, + {"playfield": 3121, "count": 1}, + {"playfield": 3122, "count": 1}, + {"playfield": 3123, "count": 1}, + {"playfield": 3124, "count": 1}, + {"playfield": 3125, "count": 1}, + {"playfield": 3126, "count": 1}, + {"playfield": 3127, "count": 1}, + {"playfield": 3128, "count": 1}, + {"playfield": 3129, "count": 1}, + {"playfield": 3130, "count": 1}, + {"playfield": 3131, "count": 1}, + {"playfield": 3132, "count": 1}, + {"playfield": 3133, "count": 1}, + {"playfield": 3134, "count": 1}, + {"playfield": 3135, "count": 1}, + {"playfield": 3136, "count": 1}, + {"playfield": 3137, "count": 1}, + {"playfield": 3138, "count": 1}, + {"playfield": 3139, "count": 1}, + {"playfield": 3140, "count": 1}, + {"playfield": 3141, "count": 1}, + {"playfield": 3142, "count": 1}, + {"playfield": 3143, "count": 1}, + {"playfield": 3144, "count": 1}, + {"playfield": 3145, "count": 1}, + {"playfield": 3146, "count": 1}, + {"playfield": 3147, "count": 1}, + {"playfield": 3148, "count": 1}, + {"playfield": 3149, "count": 1}, + {"playfield": 4102, "count": 2}, + {"playfield": 4107, "count": 1}, + {"playfield": 4121, "count": 22}, + {"playfield": 4604, "count": 20}, + {"playfield": 4805, "count": 64} +] diff --git a/src/Makefile.wasm b/src/Makefile.wasm @@ -11,11 +11,11 @@ OBJECTS := $(patsubst %.c,build/wasm/objects/%.o,$(GAME_SOURCES) $(DATA_SOURCES) .DEFAULT_GOAL := all .PHONY: all objects -all: build/wasm/web/game.js build/wasm/web/index.html +all: build/wasm/web/game.js build/wasm/web/game.wasm build/wasm/web/index.html -build/wasm/web/game.js: $(OBJECTS) runtime/browser_network.js runtime/browser_host.js runtime/browser_audio.js Makefile.wasm +build/wasm/web/game.js build/wasm/web/game.wasm &: $(OBJECTS) runtime/browser_network.js runtime/browser_host.js runtime/browser_audio.js ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a Makefile.wasm @mkdir -p $(@D) - $(CC) $(CFLAGS) $(PORT_FLAGS) $(OBJECTS) ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a -sUSE_MPG123=1 -sWASMFS -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=8 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT -sJSPI -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=268435456 -sSTACK_SIZE=8388608 --js-library runtime/browser_network.js --js-library runtime/browser_host.js --js-library runtime/browser_audio.js -o $@ + $(CC) $(CFLAGS) $(PORT_FLAGS) $(OBJECTS) ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a -sUSE_MPG123=1 -sWASMFS -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=8 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT -sJSPI -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=268435456 -sSTACK_SIZE=8388608 --js-library runtime/browser_network.js --js-library runtime/browser_host.js --js-library runtime/browser_audio.js -o build/wasm/web/game.js build/wasm/web/index.html: browser/index.html @mkdir -p $(@D) diff --git a/tools/README.md b/tools/README.md @@ -23,6 +23,12 @@ and the C toolchain; normal server builds need Go. explicit list of data/configuration paths in the local Windows runtime. It refuses an existing destination and rejects executable content before copying. It is a one-time asset preparation step, not a build dependency. +- `client/publish_wasm.py`: publishes a completed browser build into `client/`, + with deterministic gzip compression and build/file identities. `make wasm` + runs this after the client build. +- `client/package_runtime.py`: packages only the required portable assets and + server data into `runtime/`. Go unpacks it on first run; normal server work + needs neither the packager nor the extraction tools. - `client/audit_linux_imports.gdb.py`: queries the compiled resolver to refresh `docs/linux-import-coverage.json`. An adapter being present does not imply every possible argument is implemented. @@ -85,5 +91,5 @@ commands. Read the associated report before reusing a historical script. `tools/data/extract_playfields.py` and `extract_terrain.py` use the archived 11.0 data source; they are provenance tools, not part of the Debian startup. -The preserved 13.2 zone-link extractor is archived as well. Existing extracted -server data must be copied when moving machines. +The preserved 13.2 zone-link extractor is archived as well. The current required +server data is included in `runtime/`; extraction is not part of a fresh setup. diff --git a/tools/client/package_runtime.py b/tools/client/package_runtime.py @@ -51,3 +51,4 @@ for path in destination.glob('runtime.tar.gz.*'): (destination / 'manifest.json').write_text(json.dumps({'parts': parts}, indent=2) + '\n') print('Packaged %d files in %d parts, %d compressed bytes' % ( len(files), len(parts), (work / 'runtime.tar.gz').stat().st_size)) +(work / 'runtime.tar.gz').unlink()