aorecomp

Anarchy Online classic in the browser

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


commit 136e50147c86c416eec98087f3ec00b6f40c6ce5
parent 9a2bfc791073a9fd574ae4c07c0113b8ffa81865
Author: anon <anon@example.com>
Date:   Fri,  6 Nov 2026 04:53:31 +0000

Repair stale server regressions exposed by the timing baseline

Diffstat:
MTODO.md | 36++++++++++++++++++++++++++++++++++++
Mdocs/npc-placement.md | 2+-
Mserver/browser_creation_test.go | 28++++++++++++++++++++++++++--
Mserver/east_wind_mission_test.go | 6+++---
Mserver/fling_crash_test.go | 1+
Mserver/npc_fallback_placement_test.go | 2+-
Mserver/npcs_test.go | 15++++++++++++---
Mserver/scene_geometry_test.go | 4+++-
Mserver/shops_test.go | 10+++++++---
9 files changed, 90 insertions(+), 14 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -274,6 +274,42 @@ rewriting this document does not close them. ## P1: bounded follow-up work +- [x] **Include starter stock in the native socket sale regression.** + The timing baseline finds an unexpected catalog packet because the training + terminal now has seven stock rows. Verify that catalog precedes the trade + window, then retain the sale, zero-cash reset and cold ownership assertions. + November 5: all of those checks pass with the current seven-row catalog. +- [x] **Account for preloaded interiors in the geometry cache regression.** + The timing baseline passes concurrent wall/floor queries but finds 23 cached + surfaces instead of the old one: early shop interiors are now loaded at + startup. Verify the concurrent outdoor queries add exactly one shared cell + while retaining their geometric results and shared water cache. + November 5: the concurrent query and cache-growth assertions pass. +- [x] **Align NPC census checks with admitted creatures and guide outfits.** + The timing baseline finds four newly admitted ROLL fallback actors beyond + the old 23-actor census, and an outfitted guide packet using the current + humanoid layout and original head. Preserve every placement/population + assertion and verify the guide's flags, head, hands and model against that + contract. November 5: all 27 placements and the guide packet checks pass; + placement and appearance behavior are unchanged. +- [x] **Align creation regressions with the current account contract.** + The full-suite timing baseline found obsolete rejection of empty passwords + and of the public `adopted` response field. Preserve credential exclusion + and invalid-input assertions, and verify empty-password creation/login after + restart. November 5: the creation suite passes, including that new restart + check, invalid input, failed writes and concurrent replay. Account behavior + is unchanged. +- [x] **Align East Wind reward checks with the current mission cash policy.** + The timing baseline reproduces old 20-credit expectations for a level-two + production offer that now pays 1000 credits. Verify the promised amount, + failed-write/retry settlement and trained reward ownership after cold loading. + November 5: all reward, failed-write/retry and cold ownership checks pass. +- [x] **Launch crash-recovery children with access to external assets.** + The timing baseline reproduces child startup failure from the isolated test + directory. Preserve the original launch directory for child startup, keeping + each child's database isolated. Verify all eight before/after-commit kills + and their recovery/retry assertions with the default asset provider. + November 5: all eight forced-kill modes now reach and pass those assertions. - [x] **Update the pending-cast admin item-edit regression for live inventory edits.** Carried-kit edits now have passing checks for session/cast preservation, completion or cancellation, failed writes and retry. The separate equipped diff --git a/docs/npc-placement.md b/docs/npc-placement.md @@ -30,7 +30,7 @@ Missing source/geometry and exhausted dry samples retain the existing generated placement; this does not establish support for those unresolved cases. This deterministic sampling is a reconstruction, not the original random spawn -algorithm or a recovered aquatic/flying NPC policy. All 23 currently admitted +algorithm or a recovered aquatic/flying NPC policy. All 23 actors admitted on November 2 fallback combatants pass the production census: distinct positions, dry contact, original district membership and matching home. The focused fixture checks all six placements, immutable raw points, untouched fixed/unreviewed entries, diff --git a/server/browser_creation_test.go b/server/browser_creation_test.go @@ -145,13 +145,14 @@ func TestBrowserCreationCatalogRequiresCookieAndExcludesCredentials(t *testing.T var result struct { Name string `json:"name"` Visitor bool `json:"visitor"` + Adopted bool `json:"adopted"` Heads []gamedata.PlayerHead `json:"heads"` } decoder := json.NewDecoder(response.Body) decoder.DisallowUnknownFields() err := decoder.Decode(&result) - if err != nil || response.Code != 200 || response.Header().Get("Cache-Control") != "no-store" || result.Name != "Visitor1" || !result.Visitor || + if err != nil || response.Code != 200 || response.Header().Get("Cache-Control") != "no-store" || result.Name != "Visitor1" || !result.Visitor || result.Adopted || !reflect.DeepEqual(result.Heads, gamedata.PlayerAppearances.Heads) || unauthorized.Code != 401 { t.Fatalf("creation catalog: %d %v", response.Code, err) } @@ -204,7 +205,7 @@ func TestBrowserCreationRejectsInvalidChoicesWithoutChangingCurrentPlayer(t *tes for _, scenario := range []struct{ field, value string }{ {"head_mesh", ""}, {"head_mesh", "1"}, {"head_mesh", "4294967296"}, {"profession", "0"}, {"profession", "13"}, {"profession", "-1"}, {"side", ""}, {"side", "3"}, {"side", "-1"}, {"build", "3"}, {"build", "normal"}, {"height", "0"}, {"height", "95"}, {"height", "65536"}, - {"name", "Abc"}, {"name", "Abc1"}, {"name", "Alice1a"}, {"name", "Thirteenchars"}, {"name", "Visitor42"}, {"password", ""}, {"password", strings.Repeat("a", 1025)}, + {"name", "Abc"}, {"name", "Abc1"}, {"name", "Alice1a"}, {"name", "Thirteenchars"}, {"name", "Visitor42"}, {"password", strings.Repeat("a", 1025)}, } { t.Run(scenario.field+"="+scenario.value, func(t *testing.T) { fields := creationForm() @@ -219,6 +220,29 @@ func TestBrowserCreationRejectsInvalidChoicesWithoutChangingCurrentPlayer(t *tes } } +func TestBrowserCreationEmptyPasswordSurvivesRestart(t *testing.T) { + world := newTestServer(t) + visitor := accountVisitor(t, world) + fields := creationForm() + fields.Set("password", "") + + created := creationRequest(world, visitor, fields) + if created.Code != http.StatusNoContent { + t.Fatal(created.Code, created.Body) + } + restored := newTestInventoryServer(t) + restored.baseURL = "/" + other := accountVisitor(t, restored) + wrong := accountRequest(restored, other, "login", "Alice", "wrong") + loggedIn := accountRequest(restored, other, "login", "Alice", "") + + if wrong.Code != http.StatusUnauthorized || loggedIn.Code != http.StatusNoContent || + restored.characters[2].name != "Alice" || restored.characters[2].browserTokenHash == world.characters[2].browserTokenHash || + !reflect.DeepEqual(restored.characters[2].inventory.Items, world.characters[2].inventory.Items) { + t.Fatal("empty-password creation lost its login or inventory after restart", wrong.Code, loggedIn.Code) + } +} + func TestBrowserCreationFailureRollsBackAndCanRetry(t *testing.T) { for _, table := range []string{"characters", "players", "items", "item_locations"} { for _, failure := range []string{"ABORT", "IGNORE"} { diff --git a/server/east_wind_mission_test.go b/server/east_wind_mission_test.go @@ -29,7 +29,7 @@ func newEastWindMissionWorld(t *testing.T) (*server, *worldClient, *combatTestCo if err := world.handleMissionOffers(client, missionOffersRequest()); err != nil { t.Fatal(err) } - if client.missionOffer == nil || client.missionOffer.definition.RewardItem != 160216 || client.missionOffer.definition.RewardQuality != 2 { + if client.missionOffer == nil || client.missionOffer.definition.RewardItem != 160216 || client.missionOffer.definition.RewardQuality != 2 || client.missionOffer.definition.Credits != 1000 { t.Fatal("production pool did not advertise the selected period reward") } client.missionOffer.seed = 2 @@ -99,7 +99,7 @@ func TestEastWindMissionRewardFailuresPreserveThePromiseAndRetry(t *testing.T) { cold = reloadMissionEntranceWorld(t) if !cold.missionExpiry[0].completed || cold.nextItem != 4 || len(cold.characters[1].inventory.Items) != 2 || - cold.characters[1].inventory.Credits != 23 || cold.characters[1].inventory.Items[1] != + cold.characters[1].inventory.Credits != 1003 || cold.characters[1].inventory.Items[1] != (ownedItem{ID: 4, Type: 51018, Template: 160216, Quality: 2, Slot: 65, Count: 1}) { t.Fatal("period reward retry duplicated or changed its selected instance or payment") } @@ -131,7 +131,7 @@ func TestEastWindMissionRewardSurvivesHandInTrainingAndColdRecovery(t *testing.T cold := reloadMissionEntranceWorld(t) if len(player.inventory.Items) != 2 || player.inventory.Items[1] != (ownedItem{ID: 4, Type: 51018, Template: 160216, Quality: 2, Slot: 6, Count: 1}) || - player.inventory.Credits != 23 || player.stats.ImprovementPoints != 188 || player.attackRating() != 9 || + player.inventory.Credits != 1003 || player.stats.ImprovementPoints != 188 || player.attackRating() != 9 || cold.characters[1].inventory.Items[1] != player.inventory.Items[1] || cold.characters[1].attackRating() != 9 || cold.characters[1].stats != player.stats || !cold.missionExpiry[0].completed || cold.nextItem != 4 { t.Fatal("mission hand-in, training or cold replay changed the period reward or its accounting") diff --git a/server/fling_crash_test.go b/server/fling_crash_test.go @@ -129,6 +129,7 @@ func TestFlingShotProcessCrashRecovery(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() command := exec.CommandContext(ctx, executable, "-test.run=^TestFlingShotProcessCrashRecovery$") + command.Dir = testLaunchDirectory command.Env = append(os.Environ(), "AO_TEST_FLING_CRASH="+mode, "TMPDIR="+t.TempDir()) command.ExtraFiles = []*os.File{writer} var processOutput bytes.Buffer diff --git a/server/npc_fallback_placement_test.go b/server/npc_fallback_placement_test.go @@ -97,7 +97,7 @@ func TestFallbackNPCPlacementCoversEveryAdmittedProductionActor(t *testing.T) { } } } - if count != 23 { + if count != 27 { t.Fatal("admitted fallback population coverage changed", count) } } diff --git a/server/npcs_test.go b/server/npcs_test.go @@ -15,7 +15,15 @@ import ( //go:embed testdata/npc-populations.json var authoredPopulations []byte +var testLaunchDirectory string + func TestMain(m *testing.M) { + // Child test processes need the launch directory's external assets too. + var err error + testLaunchDirectory, err = os.Getwd() + if err != nil { + panic(err) + } // Keep persistence tests away from the developer's live user files. directory, err := os.MkdirTemp("", "ao-tests-") if err != nil { @@ -176,12 +184,13 @@ func TestEveryAuthoredPopulationIsPreserved(t *testing.T) { t.Fatalf("missing reviewed human NPC: %x", guard) } nameEnd := 70 + int(guard[69]) - headOffset := nameEnd + 19 + int(binary.BigEndian.Uint32(guard[nameEnd+15:nameEnd+19])) - if binary.BigEndian.Uint32(guard[37:41]) != 0x2d1 || binary.BigEndian.Uint32(guard[headOffset:headOffset+4]) != 40681 || + // The outfitted guide uses humanoid initialization with its original head. + headOffset := nameEnd + 39 + int(binary.BigEndian.Uint32(guard[nameEnd+35:nameEnd+39])) + if binary.BigEndian.Uint32(guard[37:41]) != 0x402da || binary.BigEndian.Uint32(guard[headOffset:headOffset+4]) != 40687 || !bytes.Equal(guard[headOffset+43:headOffset+61], []byte("hands\x00\x00\x00\x22\x45\x00\x00\x00\x00\x00\x00\x00\x00")) { t.Fatalf("human NPC head and hand material: %x", guard) } - if binary.BigEndian.Uint32(guard[nameEnd+9:nameEnd+13]) != 26088 { + if binary.BigEndian.Uint32(guard[nameEnd+29:nameEnd+33]) != 26088 { t.Fatal("human NPC did not receive the original Solitus model") } if len(highLevel) < 91 || binary.BigEndian.Uint32(highLevel[37:41])&0x1000 == 0 || binary.BigEndian.Uint16(highLevel[70+int(highLevel[69]):72+int(highLevel[69])]) != 300 { diff --git a/server/scene_geometry_test.go b/server/scene_geometry_test.go @@ -59,6 +59,8 @@ func TestSceneGeometrySharesShippedCellAcrossConcurrentQueries(t *testing.T) { t.Fatal(err) } t.Cleanup(func() { geometry.database.file.Close() }) + // Interior surfaces are already cached; these queries add one outdoor cell. + initialSurfaces := len(geometry.surfaces) grounds, err := readTerrain() if err != nil { t.Fatal(err) @@ -85,7 +87,7 @@ func TestSceneGeometrySharesShippedCellAcrossConcurrentQueries(t *testing.T) { t.Fatal("concurrent archive-backed wall query") } } - if len(geometry.surfaces) != 1 || geometry.surfaces[46203264] == nil { + if len(geometry.surfaces) != initialSurfaces+1 || geometry.surfaces[46203264] == nil { t.Fatal("queries must share the decoded immutable cell", len(geometry.surfaces)) } if len(geometry.waters) != 1 || geometry.waters[705] == nil { diff --git a/server/shops_test.go b/server/shops_test.go @@ -97,7 +97,7 @@ func TestShopNativeSocketUseAndSale(t *testing.T) { request := shopUseRequest(1) connection.Write(targetPacket(n3Packet(0x52526858, 50000, 1, request[16:]))) - for index, key := range []uint32{0x52526858, 0x7f544905, 0x36284f6e, 0x36284f6e} { + for index, key := range []uint32{0x52526858, 0x7f544905, 0x58362220, 0x36284f6e, 0x36284f6e} { packet, err := readPacket(connection) if err != nil { t.Fatal(err) @@ -108,11 +108,15 @@ func TestShopNativeSocketUseAndSale(t *testing.T) { if key == 0x52526858 && binary.BigEndian.Uint32(packet[29:33]) != 1 { t.Fatalf("native shop use was rejected: %x", packet) } - if index == 2 && (binary.BigEndian.Uint32(packet[20:24]) != 51035 || binary.BigEndian.Uint32(packet[24:28]) != 0xc00003b6 || + if key == 0x58362220 && (binary.BigEndian.Uint32(packet[20:24]) != 51035 || binary.BigEndian.Uint32(packet[24:28]) != 0xc00003b6 || + len(packet) != 117 || binary.BigEndian.Uint32(packet[29:33]) != 8072) { + t.Fatalf("starter shop catalog has the wrong owner or stock count: %x", packet) + } + if index == 3 && (binary.BigEndian.Uint32(packet[20:24]) != 51035 || binary.BigEndian.Uint32(packet[24:28]) != 0xc00003b6 || binary.BigEndian.Uint32(packet[37:41]) != 50000 || binary.BigEndian.Uint32(packet[41:45]) != 1) { t.Fatalf("machine trade record was not initialized before the window: %x", packet) } - if index == 3 && (binary.BigEndian.Uint32(packet[20:24]) != 50000 || binary.BigEndian.Uint32(packet[24:28]) != 1 || + if index == 4 && (binary.BigEndian.Uint32(packet[20:24]) != 50000 || binary.BigEndian.Uint32(packet[24:28]) != 1 || binary.BigEndian.Uint32(packet[37:41]) != 51035 || binary.BigEndian.Uint32(packet[41:45]) != 0xc00003b6 || binary.BigEndian.Uint32(packet[45:49]) != 111 || binary.BigEndian.Uint32(packet[49:53]) != 0) { t.Fatalf("player trade window has the wrong partner: %x", packet)