aorecomp

Anarchy Online classic in the browser

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


commit 8449f09587061b9eaa795f89fe550a1b9506e703
parent 008e2aff48a65a765c522eca0b4d2539ad6e5028
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 07:29:51 +0000

Scope fixture lifetimes and repair synthetic weapon modifiers

Diffstat:
MDEVELOPERS.md | 2++
MTODO.md | 15+++++++++++++--
Mserver/briefcase_weapon_test.go | 29+++++++++++++++++------------
Mserver/browser_stream_test.go | 6+++---
Mserver/character_info_test.go | 53+++++++++++++++++++++++++++++------------------------
Mserver/chat_test.go | 32++++++++++++++++++++------------
Mserver/combat_range_test.go | 31+++++++++++++++++++------------
Mserver/combat_test.go | 35++++++++++++++++++++++-------------
Mserver/fast_attack_test.go | 30+++++++++++++++++-------------
Mserver/fling_shot_test.go | 49+++++++++++++++++++++++++++++--------------------
Mserver/map_purchases_test.go | 53+++++++++++++++++++++++++++++------------------------
Mserver/npc_regeneration_test.go | 53+++++++++++++++++++++++++++++++----------------------
Mserver/shop_quality_test.go | 38+++++++++++++++++++++-----------------
Mserver/signed_stats_test.go | 35++++++++++++++++++++---------------
Mserver/stacks_test.go | 59++++++++++++++++++++++++++++++++++-------------------------
Mserver/starter_weapons_test.go | 3++-
Mserver/stats_test.go | 37+++++++++++++++++++++----------------
Mserver/weapon_stats_test.go | 92++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
18 files changed, 380 insertions(+), 272 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -437,6 +437,8 @@ Server fixtures use `newTestServer(t)` for an isolated directory and `newServerForTest(t)` when reloading the current directory. Lazy fixtures register `registerTestDatabaseCleanup(t, world)` before fallible operations. These helpers drain live sessions before closing SQLite at scope exit. +Give independent table cases their own `t.Run` scope so fixture cleanup runs +between rows. For client smoke tests, confirm world loading has completed, open/close inventory (`I`) and map (`P`), move and turn, and inspect the rendered results. diff --git a/TODO.md b/TODO.md @@ -3647,8 +3647,19 @@ with payloads and known client/server provenance. that lifecycle. Nested reload and live-nano regressions reproduce retained connections and late logout writes respectively. Focused lifecycle/race checks and a short two-character WASM bank/page/cold - check pass, returning handles/openers to zero. The instrumented full suite is - still running; evidence: `local/fixture-database-audit/`. + check pass, returning handles/openers to zero. The first full run exposed + synthetic closed queues mistaken for live writers and independent table rows + retaining databases on their parent scope. Cleanup now recognizes initialized + writer completion channels, and twenty independent tables have subtest scopes. + The 13-row briefcase probe peaks at one opener, returning to zero. The + instrumented full retry is running. Evidence: `local/fixture-database-audit/`. +- [x] [P1] Repair malformed synthetic weapon OnWear descriptors in combat + arithmetic fixtures. The original weighted-rating and zero-requirement tests + measure fists after complete-wear admission rejects their incomplete modifier. + Check: preserve expected weapon arithmetic using complete native descriptors, + without loosening wear admission. Both original failures are retained; the + corrected fixtures pass in the 34-root / 144-result ordinary and race checks. + Evidence: `local/fixture-database-audit/`. - [ ] [P3] Reproduce stale shop interaction state after a live control-panel inventory edit. In the restoration smoke run, a nearby original terminal reported "Too far away" after the edit, while a fresh page could use it. diff --git a/server/briefcase_weapon_test.go b/server/briefcase_weapon_test.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/binary" + "fmt" "slices" "testing" "time" @@ -100,18 +101,22 @@ func TestBriefcaseWeaponDamageUsesAuthoredSkillAndEveryOERequirement(t *testing. {120, 100, 32, 81}, {119, 100, 16, 41}, {60, 100, 14, 36}, {59, 100, 0, 0}, {300, 99, 87, 218}, {300, 49, 66, 164}, {300, 14, 22, 56}, } { - world, _ := newRemoteBankWorld(t) - equipTestBriefcase(t, world) - player := world.characters[1] - player.stats.Abilities.Intelligence, player.stats.Abilities.Sense = 1, 1 - player.stats.TradeRepair.Psychology, player.level = scenario.psychology, scenario.level - player.stats.Melee.OneHandEdged, player.stats.Ranged.Pistol = 5000, 5000 - - minimum := player.weaponDamage(world.characters[1000000], false, func(uint32) uint32 { return 0 }) - maximum := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return limit - 1 }) - - if minimum != scenario.minimum || maximum != scenario.maximum || player.attackRating() != int32(scenario.psychology) { - t.Fatalf("Psychology %d level %d: got %d..%d AR%d, want %d..%d", scenario.psychology, scenario.level, minimum, maximum, player.attackRating(), scenario.minimum, scenario.maximum) + if !t.Run(fmt.Sprintf("psychology%d/level%d", scenario.psychology, scenario.level), func(t *testing.T) { + world, _ := newRemoteBankWorld(t) + equipTestBriefcase(t, world) + player := world.characters[1] + player.stats.Abilities.Intelligence, player.stats.Abilities.Sense = 1, 1 + player.stats.TradeRepair.Psychology, player.level = scenario.psychology, scenario.level + player.stats.Melee.OneHandEdged, player.stats.Ranged.Pistol = 5000, 5000 + + minimum := player.weaponDamage(world.characters[1000000], false, func(uint32) uint32 { return 0 }) + maximum := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return limit - 1 }) + + if minimum != scenario.minimum || maximum != scenario.maximum || player.attackRating() != int32(scenario.psychology) { + t.Fatalf("Psychology %d level %d: got %d..%d AR%d, want %d..%d", scenario.psychology, scenario.level, minimum, maximum, player.attackRating(), scenario.minimum, scenario.maximum) + } + }) { + return } } } diff --git a/server/browser_stream_test.go b/server/browser_stream_test.go @@ -33,17 +33,17 @@ func closeTestSessions(t *testing.T, world *server) { stream.close() } - // Retire live world writers before database cleanup, including plain sockets. + // Closed-queue fixtures have no writer completion channel or session to retire. world.mutex.Lock() clients := make(map[uint32]*worldClient) for id, client := range world.clients { - if client.writeWake != nil { + if client.writeDone != nil { clients[id] = client } } chats := make(map[uint32]*chatClient) for id, client := range world.chats { - if client.writeWake != nil { + if client.writeDone != nil { chats[id] = client } } diff --git a/server/character_info_test.go b/server/character_info_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" + "fmt" "testing" ) @@ -180,33 +181,37 @@ func TestCharacterInfoNativeWireDispatch(t *testing.T) { func TestCharacterInfoNPCUsesNativeDefaultsWithoutChangingRecovery(t *testing.T) { for _, fighting := range []uint32{0, 1} { - world, conn := newRangedWorld(t) - npc := world.characters[1000000] - npc.health, npc.level, npc.fighting = 20, 200, fighting - npc.stats.Abilities.Stamina, npc.stats.Abilities.Psychic = 900, 900 - auditCheckpointWrites(t, world) + if !t.Run(fmt.Sprint(fighting), func(t *testing.T) { + world, conn := newRangedWorld(t) + npc := world.characters[1000000] + npc.health, npc.level, npc.fighting = 20, 200, fighting + npc.stats.Abilities.Stamina, npc.stats.Abilities.Psychic = 900, 900 + auditCheckpointWrites(t, world) - for range 2 { - if err := world.handleCharacterInfo(world.clients[1], teamRequest(1, 105, 1000000, 0)); err != nil { - t.Fatal(err) + for range 2 { + if err := world.handleCharacterInfo(world.clients[1], teamRequest(1, 105, 1000000, 0)); err != nil { + t.Fatal(err) + } } - } - if len(conn.packets) != 2 || !bytes.Equal(conn.packets[0], conn.packets[1]) { - t.Fatal("represented NPC did not return a repeatable inspection reply") - } - packet := conn.packets[0] - if binary.BigEndian.Uint32(packet[24:28]) != 1000000 { - t.Fatal("NPC reply used the requester's identity") - } - if got := hex.EncodeToString(packet[29:81]); got != "00ff010101000000000000000000001400000064000000030000001e000000030000001e00000000000000000000000000000000" { - t.Fatal("NPC metadata or raw regeneration inputs changed", got) - } - if npc.health != 20 || npc.fighting != fighting || npc.regenerationSeconds != 0 || !npc.regenerationAt.IsZero() { - t.Fatal("inspection changed the NPC's health or recovery clock") - } - if writes := checkpointWrites(t, world); len(writes) != 0 { - t.Fatal("NPC inspection wrote durable state", writes) + if len(conn.packets) != 2 || !bytes.Equal(conn.packets[0], conn.packets[1]) { + t.Fatal("represented NPC did not return a repeatable inspection reply") + } + packet := conn.packets[0] + if binary.BigEndian.Uint32(packet[24:28]) != 1000000 { + t.Fatal("NPC reply used the requester's identity") + } + if got := hex.EncodeToString(packet[29:81]); got != "00ff010101000000000000000000001400000064000000030000001e000000030000001e00000000000000000000000000000000" { + t.Fatal("NPC metadata or raw regeneration inputs changed", got) + } + if npc.health != 20 || npc.fighting != fighting || npc.regenerationSeconds != 0 || !npc.regenerationAt.IsZero() { + t.Fatal("inspection changed the NPC's health or recovery clock") + } + if writes := checkpointWrites(t, world); len(writes) != 0 { + t.Fatal("NPC inspection wrote durable state", writes) + } + }) { + return } } } diff --git a/server/chat_test.go b/server/chat_test.go @@ -192,14 +192,18 @@ func TestChatRejectsMalformedMessages(t *testing.T) { {0, 65, 0, 12, 0x87, 0, 0, 0, 2, 0, 2, 'h', 'i', 0, 1, 0}, chatPacket(30, appendChatString(appendChatString([]byte{0, 0, 0, 2}, strings.Repeat("x", 4097)), "")), } { - server := chatTestServer(t) - peer := loginChatTest(t, server, 1) + if !t.Run("packet", func(t *testing.T) { + server := chatTestServer(t) + peer := loginChatTest(t, server, 1) - peer.Write(packet) - _, _, err := readChatPacket(peer) + peer.Write(packet) + _, _, err := readChatPacket(peer) - if err != io.EOF { - t.Fatalf("malformed packet did not close connection: %v", err) + if err != io.EOF { + t.Fatalf("malformed packet did not close connection: %v", err) + } + }) { + return } } } @@ -290,14 +294,18 @@ func TestChatRejectsMalformedAuthentication(t *testing.T) { {0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 1, 0, 50}, trailing, } { - server := chatTestServer(t) - peer, done := startChatTest(t, server, 0) + if !t.Run("packet", func(t *testing.T) { + server := chatTestServer(t) + peer, done := startChatTest(t, server, 0) - peer.Write(packet) - _, _, err := readChatPacket(peer) + peer.Write(packet) + _, _, err := readChatPacket(peer) - if err != io.EOF || <-done == nil { - t.Fatalf("malformed authentication was accepted: %v", err) + if err != io.EOF || <-done == nil { + t.Fatalf("malformed authentication was accepted: %v", err) + } + }) { + return } } } diff --git a/server/combat_range_test.go b/server/combat_range_test.go @@ -1,6 +1,9 @@ package main -import "testing" +import ( + "fmt" + "testing" +) func TestCombatMeleeUsesActorExtentsAtThreeDimensionalBoundary(t *testing.T) { for _, scenario := range []struct { @@ -32,19 +35,23 @@ func TestCombatMeleeUsesActorExtentsAtThreeDimensionalBoundary(t *testing.T) { func TestCombatLeetRangeIncludesItsOwnExtentTwice(t *testing.T) { for _, distance := range []float32{10, 10.125} { - world, _ := newCombatWorld(t) - player, npc := world.characters[1], world.characters[1000000] - npc.monsterData = 17655 - world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]) - world.advanceCombat(player.nextAttack) - world.handleCombat(world.clients[1], stopFightPacket(1)[20:]) - player.position[0] = npc.position[0] + distance - before := player.health + if !t.Run(fmt.Sprint(distance), func(t *testing.T) { + world, _ := newCombatWorld(t) + player, npc := world.characters[1], world.characters[1000000] + npc.monsterData = 17655 + world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]) + world.advanceCombat(player.nextAttack) + world.handleCombat(world.clients[1], stopFightPacket(1)[20:]) + player.position[0] = npc.position[0] + distance + before := player.health - world.advanceCombat(npc.nextAttack) + world.advanceCombat(npc.nextAttack) - if (player.health < before) != (distance == 10) || (npc.fighting != 0) != (distance == 10) { - t.Fatalf("Leet 10m range: distance=%v health=%d target=%d", distance, player.health, npc.fighting) + if (player.health < before) != (distance == 10) || (npc.fighting != 0) != (distance == 10) { + t.Fatalf("Leet 10m range: distance=%v health=%d target=%d", distance, player.health, npc.fighting) + } + }) { + return } } } diff --git a/server/combat_test.go b/server/combat_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" + "fmt" "net" "testing" "time" @@ -326,12 +327,16 @@ func TestCombatZoningCancelsOpponentsAndPreservesHealth(t *testing.T) { func TestCombatMalformedPacketsAreRejected(t *testing.T) { for _, packet := range [][]byte{attackPacket(1, 1000000)[:44], stopFightPacket(1)[:39], n3Packet(0x76793f0d, 50000, 1, []byte{0, 0, 0})[:39]} { - world, _ := newCombatWorld(t) + if !t.Run("packet", func(t *testing.T) { + world, _ := newCombatWorld(t) - err := world.handleCombat(world.clients[1], packet[20:]) + err := world.handleCombat(world.clients[1], packet[20:]) - if err == nil || len(world.fighting) != 0 { - t.Fatal("short combat packet was accepted") + if err == nil || len(world.fighting) != 0 { + t.Fatal("short combat packet was accepted") + } + }) { + return } } } @@ -378,17 +383,21 @@ func TestCombatAggDefControlsNativeFistTimings(t *testing.T) { func TestCombatAggDefRejectsInvalidValuesAndReplacedSessions(t *testing.T) { for _, value := range []int32{-101, 101, -2147483648, 2147483647, 75} { - world, conn := newCombatWorld(t) - client := world.clients[1] - if value == 75 { - world.clients[1] = &worldClient{id: 1} - } - request := n3Packet(0x76793f0d, 50000, 1, binary.BigEndian.AppendUint32(nil, uint32(value))) + if !t.Run(fmt.Sprint(value), func(t *testing.T) { + world, conn := newCombatWorld(t) + client := world.clients[1] + if value == 75 { + world.clients[1] = &worldClient{id: 1} + } + request := n3Packet(0x76793f0d, 50000, 1, binary.BigEndian.AppendUint32(nil, uint32(value))) - err := world.handleCombat(client, request[20:]) + err := world.handleCombat(client, request[20:]) - if err != nil || world.characters[1].aggDef != 0 || len(conn.packets) != 0 { - t.Fatalf("invalid slider request accepted: %d, %v", value, err) + if err != nil || world.characters[1].aggDef != 0 || len(conn.packets) != 0 { + t.Fatalf("invalid slider request accepted: %d, %v", value, err) + } + }) { + return } } } diff --git a/server/fast_attack_test.go b/server/fast_attack_test.go @@ -178,21 +178,25 @@ func TestFastAttackFailedOutcomePublishesNothingAndRollsBackItsLock(t *testing.T "CREATE TRIGGER fail_special BEFORE UPDATE ON npcs BEGIN SELECT RAISE(FAIL, 'test NPC failure'); END", "CREATE TRIGGER fail_special BEFORE INSERT ON npc_damage_contributors BEGIN SELECT RAISE(FAIL, 'test contribution failure'); END", } { - world, conn := newFastAttackWorld(t) - if err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]); err != nil { - t.Fatal(err) - } - conn.packets = nil - if _, err := world.db.Exec(statement); err != nil { - t.Fatal(err) - } + if !t.Run(statement, func(t *testing.T) { + world, conn := newFastAttackWorld(t) + if err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + conn.packets = nil + if _, err := world.db.Exec(statement); err != nil { + t.Fatal(err) + } - err := world.handleWeaponSpecial(world.clients[1], fastAttackRequest(1, 1000000)[20:]) - restored := newTestInventoryServer(t) + err := world.handleWeaponSpecial(world.clients[1], fastAttackRequest(1, 1000000)[20:]) + restored := newTestInventoryServer(t) - if err == nil || world.characters[1000000].health != 1000 || len(conn.packets) != 0 || - len(world.characters[1].skillLocks) != 0 || len(restored.characters[1].skillLocks) != 0 { - t.Fatal("failed Fast Attack changed durable/live outcome or published feedback") + if err == nil || world.characters[1000000].health != 1000 || len(conn.packets) != 0 || + len(world.characters[1].skillLocks) != 0 || len(restored.characters[1].skillLocks) != 0 { + t.Fatal("failed Fast Attack changed durable/live outcome or published feedback") + } + }) { + return } } } diff --git a/server/fling_shot_test.go b/server/fling_shot_test.go @@ -4,6 +4,7 @@ import ( "ao/server/gamedata" "bytes" "encoding/binary" + "fmt" "slices" "sync" "testing" @@ -179,13 +180,17 @@ func TestFlingShotRejectsInvalidRequestsWithoutDamageOrLocks(t *testing.T) { func TestFlingShotMalformedLengthReturnsError(t *testing.T) { for _, length := range []int{0, 27, 29} { - world, conn := newRangedWorld(t) - request := append(flingShotRequest(1, 1000000)[20:], 0)[:length] + if !t.Run(fmt.Sprint(length), func(t *testing.T) { + world, conn := newRangedWorld(t) + request := append(flingShotRequest(1, 1000000)[20:], 0)[:length] - err := world.handleWeaponSpecial(world.clients[1], request) + err := world.handleWeaponSpecial(world.clients[1], request) - if err == nil || world.characters[1000000].health != 1000 || len(conn.packets) != 0 { - t.Fatal("malformed special changed game state") + if err == nil || world.characters[1000000].health != 1000 || len(conn.packets) != 0 { + t.Fatal("malformed special changed game state") + } + }) { + return } } } @@ -213,23 +218,27 @@ func TestFlingShotOutcomeFailureRollsBackLockAndNPCState(t *testing.T) { "CREATE TRIGGER fail_outcome BEFORE UPDATE ON npcs BEGIN SELECT RAISE(FAIL, 'test NPC failure'); END", "CREATE TRIGGER fail_outcome BEFORE INSERT ON npc_damage_contributors BEGIN SELECT RAISE(FAIL, 'test contribution failure'); END", } { - world, conn := newRangedWorld(t) - if _, err := world.db.Exec(statement); err != nil { - t.Fatal(err) - } + if !t.Run(statement, func(t *testing.T) { + world, conn := newRangedWorld(t) + if _, err := world.db.Exec(statement); err != nil { + t.Fatal(err) + } - err := world.handleWeaponSpecial(world.clients[1], flingShotRequest(1, 1000000)[20:]) - var health, locks int - if err := world.db.QueryRow("SELECT health FROM characters WHERE id=1000000").Scan(&health); err != nil { - t.Fatal(err) - } - if err := world.db.QueryRow("SELECT count(*) FROM skill_locks").Scan(&locks); err != nil { - t.Fatal(err) - } + err := world.handleWeaponSpecial(world.clients[1], flingShotRequest(1, 1000000)[20:]) + var health, locks int + if err := world.db.QueryRow("SELECT health FROM characters WHERE id=1000000").Scan(&health); err != nil { + t.Fatal(err) + } + if err := world.db.QueryRow("SELECT count(*) FROM skill_locks").Scan(&locks); err != nil { + t.Fatal(err) + } - if err == nil || health != 1000 || locks != 0 || world.characters[1000000].health != 1000 || - len(world.characters[1000000].damageContributors) != 0 || len(world.characters[1].skillLocks) != 0 || len(conn.packets) != 0 { - t.Fatalf("partial special commit escaped rollback: health=%d locks=%d error=%v", health, locks, err) + if err == nil || health != 1000 || locks != 0 || world.characters[1000000].health != 1000 || + len(world.characters[1000000].damageContributors) != 0 || len(world.characters[1].skillLocks) != 0 || len(conn.packets) != 0 { + t.Fatalf("partial special commit escaped rollback: health=%d locks=%d error=%v", health, locks, err) + } + }) { + return } } } diff --git a/server/map_purchases_test.go b/server/map_purchases_test.go @@ -3,6 +3,7 @@ package main import ( "ao/server/gamedata" "encoding/binary" + "fmt" "reflect" "slices" "testing" @@ -32,34 +33,38 @@ func newMapPurchaseWorld(t *testing.T) (*server, *combatTestConn) { func TestMapTerminalsExposeOnlyTheSupportedReaderUpgradeSubset(t *testing.T) { for _, identity := range []uint32{3223848092, 3221750941, 3223913630, 3221685407, 3225552032, 3222602913, 3222537378, 3221226659} { - world, conn := newCombatWorld(t) - player, client := world.characters[1], world.clients[1] - machine, exists := gamedata.ShopMachines[identity] - if !exists { - t.Fatal("missing original map placement", identity) - } - player.playfield, player.position = machine.Playfield, machine.Position - // The original faction action0 does not restrict vending Use action3. - player.appearance = 0x115 - request := shopUseRequest(1) - binary.BigEndian.PutUint32(request[44:48], identity) + if !t.Run(fmt.Sprint(identity), func(t *testing.T) { + world, conn := newCombatWorld(t) + player, client := world.characters[1], world.clients[1] + machine, exists := gamedata.ShopMachines[identity] + if !exists { + t.Fatal("missing original map placement", identity) + } + player.playfield, player.position = machine.Playfield, machine.Position + // The original faction action0 does not restrict vending Use action3. + player.appearance = 0x115 + request := shopUseRequest(1) + binary.BigEndian.PutUint32(request[44:48], identity) - err := world.handleShopUse(client, request) + err := world.handleShopUse(client, request) - expected := []gamedata.ShopItem{{Template: 116683, Quality: 1}, {Template: 116684, Quality: 1}, {Template: 116685, Quality: 1}, {Template: 116692, Quality: 1}, {Template: 116694, Quality: 1}} - if err != nil || client.shop == nil || !slices.Equal(client.shop.stock, expected) || len(conn.packets) != 5 { - t.Fatal("wrong map-terminal catalog", identity, err) - } - packet := conn.packets[2] - if len(packet) != 96 || binary.BigEndian.Uint32(packet[16:20]) != 0x58362220 || binary.BigEndian.Uint32(packet[24:28]) != identity || binary.BigEndian.Uint32(packet[29:33]) != 6054 { - t.Fatal("wrong map ShopUpdate owner/count", identity) - } - for index, entry := range expected { - for field, value := range []uint32{entry.Template, entry.Template, entry.Quality} { - if binary.BigEndian.Uint32(packet[33+12*index+4*field:]) != value { - t.Fatal("wrong fixed upgrade template/quality", identity, index, field) + expected := []gamedata.ShopItem{{Template: 116683, Quality: 1}, {Template: 116684, Quality: 1}, {Template: 116685, Quality: 1}, {Template: 116692, Quality: 1}, {Template: 116694, Quality: 1}} + if err != nil || client.shop == nil || !slices.Equal(client.shop.stock, expected) || len(conn.packets) != 5 { + t.Fatal("wrong map-terminal catalog", identity, err) + } + packet := conn.packets[2] + if len(packet) != 96 || binary.BigEndian.Uint32(packet[16:20]) != 0x58362220 || binary.BigEndian.Uint32(packet[24:28]) != identity || binary.BigEndian.Uint32(packet[29:33]) != 6054 { + t.Fatal("wrong map ShopUpdate owner/count", identity) + } + for index, entry := range expected { + for field, value := range []uint32{entry.Template, entry.Template, entry.Quality} { + if binary.BigEndian.Uint32(packet[33+12*index+4*field:]) != value { + t.Fatal("wrong fixed upgrade template/quality", identity, index, field) + } } } + }) { + return } } for template, stock := range gamedata.ShopStock { diff --git a/server/npc_regeneration_test.go b/server/npc_regeneration_test.go @@ -4,6 +4,7 @@ import ( "ao/server/gamedata" "bytes" "encoding/binary" + "fmt" "testing" "time" ) @@ -45,22 +46,26 @@ func TestNPCRegenerationUsesNativeDefaultsWithoutASpeciesOrLevelGate(t *testing. monster uint32 level uint16 }{{30365, 1}, {17655, 7}, {30365, 300}} { - world, _, start := newNPCRegenerationWorld(t) - npc := world.characters[1000000] - npc.monsterData, npc.level, npc.combatProfile = scenario.monster, scenario.level, nil - - world.advanceRegeneration(start) - world.advanceRegeneration(start.Add(2 * time.Second)) - if npc.health != 21 { - t.Fatalf("unprofiled NPC %d level %d did not recover while idle: %d", scenario.monster, scenario.level, npc.health) - } - npc.fighting = 1 - for second := 4; second <= 60; second += 2 { - world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) - } + if !t.Run(fmt.Sprintf("monster%d/level%d", scenario.monster, scenario.level), func(t *testing.T) { + world, _, start := newNPCRegenerationWorld(t) + npc := world.characters[1000000] + npc.monsterData, npc.level, npc.combatProfile = scenario.monster, scenario.level, nil - if npc.health != 24 || npc.nano != 0 || npc.regenerationSeconds != 60 { - t.Fatalf("unprofiled NPC %d level %d did not retain the native combat recovery phase: %+v", scenario.monster, scenario.level, npc) + world.advanceRegeneration(start) + world.advanceRegeneration(start.Add(2 * time.Second)) + if npc.health != 21 { + t.Fatalf("unprofiled NPC %d level %d did not recover while idle: %d", scenario.monster, scenario.level, npc.health) + } + npc.fighting = 1 + for second := 4; second <= 60; second += 2 { + world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) + } + + if npc.health != 24 || npc.nano != 0 || npc.regenerationSeconds != 60 { + t.Fatalf("unprofiled NPC %d level %d did not retain the native combat recovery phase: %+v", scenario.monster, scenario.level, npc) + } + }) { + return } } } @@ -218,15 +223,19 @@ func TestNPCRegenerationClampsNativeIdleGainBoundaries(t *testing.T) { for _, scenario := range []struct{ maximum, initial, want uint32 }{ {100, 99, 100}, {120, 100, 101}, {121, 100, 101}, {239, 100, 101}, {240, 100, 102}, {480, 478, 480}, } { - world, _, start := newNPCRegenerationWorld(t) - world.characters[1000000].combatProfile = &gamedata.NPCCombatProfile{Health: scenario.maximum} - world.characters[1000000].health = scenario.initial + if !t.Run(fmt.Sprintf("max%d/initial%d", scenario.maximum, scenario.initial), func(t *testing.T) { + world, _, start := newNPCRegenerationWorld(t) + world.characters[1000000].combatProfile = &gamedata.NPCCombatProfile{Health: scenario.maximum} + world.characters[1000000].health = scenario.initial - world.advanceRegeneration(start) - world.advanceRegeneration(start.Add(2 * time.Second)) + world.advanceRegeneration(start) + world.advanceRegeneration(start.Add(2 * time.Second)) - if world.characters[1000000].health != scenario.want { - t.Fatalf("max %d: got %d want %d", scenario.maximum, world.characters[1000000].health, scenario.want) + if world.characters[1000000].health != scenario.want { + t.Fatalf("max %d: got %d want %d", scenario.maximum, world.characters[1000000].health, scenario.want) + } + }) { + return } } } diff --git a/server/shop_quality_test.go b/server/shop_quality_test.go @@ -56,24 +56,28 @@ func TestShopBasicArmorProductionQualityPurchase(t *testing.T) { func TestShopQualityCatalogResolvesBothStoredAnchors(t *testing.T) { for _, anchor := range []uint32{85596, 85595} { - world, conn := newPurchaseWorld(t) - original := gamedata.ShopStock[99491] - gamedata.ShopStock[99491] = []gamedata.ShopItem{{Template: anchor, Quality: 1}, {Template: anchor, Quality: 5}, {Template: anchor, Quality: 200}} - request := shopUseRequest(2) - binary.BigEndian.PutUint32(request[44:48], 3221488799) - conn.packets = nil - - err := world.handleShopUse(world.clients[1], request) - gamedata.ShopStock[99491] = original - - if err != nil || len(conn.packets) != 6 { - t.Fatal("quality catalog failed", err, len(conn.packets)) - } - catalog := conn.packets[3] - for index, expected := range []uint32{4036, 85596, 85596, 1, 85596, 85595, 5, 85595, 85595, 200} { - if binary.BigEndian.Uint32(catalog[29+4*index:]) != expected { - t.Fatalf("anchor %d catalog field %d changed", anchor, index) + if !t.Run(fmt.Sprint(anchor), func(t *testing.T) { + world, conn := newPurchaseWorld(t) + original := gamedata.ShopStock[99491] + gamedata.ShopStock[99491] = []gamedata.ShopItem{{Template: anchor, Quality: 1}, {Template: anchor, Quality: 5}, {Template: anchor, Quality: 200}} + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221488799) + conn.packets = nil + + err := world.handleShopUse(world.clients[1], request) + gamedata.ShopStock[99491] = original + + if err != nil || len(conn.packets) != 6 { + t.Fatal("quality catalog failed", err, len(conn.packets)) + } + catalog := conn.packets[3] + for index, expected := range []uint32{4036, 85596, 85596, 1, 85596, 85595, 5, 85595, 85595, 200} { + if binary.BigEndian.Uint32(catalog[29+4*index:]) != expected { + t.Fatalf("anchor %d catalog field %d changed", anchor, index) + } } + }) { + return } } } diff --git a/server/signed_stats_test.go b/server/signed_stats_test.go @@ -2,6 +2,7 @@ package main import ( "ao/server/gamedata" + "fmt" "testing" "time" ) @@ -176,23 +177,27 @@ func TestSignedLiteracyReachesDurableVendorSale(t *testing.T) { func TestSignedNegativeBodyDevelopmentRegeneratesWithoutUnsignedWrap(t *testing.T) { for _, full := range []bool{false, true} { - world, _, start := newRegenerationWorld(t) - player := world.characters[1] - player.level = 200 - player.activeNanos = syntheticNanoModifiers(t, [][2]int32{{152, -407}}) - if full { - player.health, player.nano = player.maximumHealth(), player.maximumNano() - } + if !t.Run(fmt.Sprint(full), func(t *testing.T) { + world, _, start := newRegenerationWorld(t) + player := world.characters[1] + player.level = 200 + player.activeNanos = syntheticNanoModifiers(t, [][2]int32{{152, -407}}) + if full { + player.health, player.nano = player.maximumHealth(), player.maximumNano() + } - for second := 2; second <= 58; second += 2 { - world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) - } + for second := 2; second <= 58; second += 2 { + world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) + } - if !full && (player.health != 19 || player.nano != 0) { - t.Fatalf("signed recovery changed resources to %d/%d", player.health, player.nano) - } - if full && (player.health != 1010 || player.nano != 831) { - t.Fatalf("negative computed gain drained a full resource: %d/%d", player.health, player.nano) + if !full && (player.health != 19 || player.nano != 0) { + t.Fatalf("signed recovery changed resources to %d/%d", player.health, player.nano) + } + if full && (player.health != 1010 || player.nano != 831) { + t.Fatalf("negative computed gain drained a full resource: %d/%d", player.health, player.nano) + } + }) { + return } } } diff --git a/server/stacks_test.go b/server/stacks_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" + "fmt" "net" "reflect" "slices" @@ -188,18 +189,22 @@ func TestStackJoinPreventsUnsignedShortOverflow(t *testing.T) { {25535, []ownedItem{{ID: 1, Type: 51005, Template: 152030, Quality: 42, Slot: 64, Count: 65535}}}, {25536, []ownedItem{{ID: 1, Type: 51005, Template: 152030, Quality: 42, Slot: 64, Count: 40000}, {ID: 2, Type: 51005, Template: 152030, Quality: 42, Slot: 65, Count: 25536}}}, } { - world, _ := newStackWorld(t) - player := world.characters[1] - player.inventory.Items[0].Count, player.inventory.Items[1].Count = 40000, scenario.second - if err := world.saveInventory_locked(player, player.inventory); err != nil { - t.Fatal(err) - } + if !t.Run(fmt.Sprint(scenario.second), func(t *testing.T) { + world, _ := newStackWorld(t) + player := world.characters[1] + player.inventory.Items[0].Count, player.inventory.Items[1].Count = 40000, scenario.second + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } - err := world.handleInventory(world.clients[1], stackActionPacket(1, 53, 64, 65)[20:]) - restarted := newTestInventoryServer(t).characters[1] + err := world.handleInventory(world.clients[1], stackActionPacket(1, 53, 64, 65)[20:]) + restarted := newTestInventoryServer(t).characters[1] - if err != nil || !reflect.DeepEqual(restarted.inventory.Items, scenario.expected) || world.nextItem != 2 { - t.Fatalf("join overflowed or lost quantity: %+v %v", restarted.inventory, err) + if err != nil || !reflect.DeepEqual(restarted.inventory.Items, scenario.expected) || world.nextItem != 2 { + t.Fatalf("join overflowed or lost quantity: %+v %v", restarted.inventory, err) + } + }) { + return } } } @@ -241,24 +246,28 @@ func TestStackConcurrentRepeatDoesNotDuplicateQuantity(t *testing.T) { {52, 1, []ownedItem{{ID: 1, Type: 51005, Template: 152030, Quality: 42, Slot: 64, Count: 1}, {ID: 2, Type: 51005, Template: 152030, Quality: 42, Slot: 65, Count: 3}, {ID: 3, Type: 51005, Template: 152030, Quality: 42, Slot: 66, Count: 2}}}, {53, 65, []ownedItem{{ID: 1, Type: 51005, Template: 152030, Quality: 42, Slot: 64, Count: 6}}}, } { - world, conn := newStackWorld(t) - request := stackActionPacket(1, scenario.action, 64, scenario.argument)[20:] - errors := make(chan error, 2) - var workers sync.WaitGroup + if !t.Run(fmt.Sprint(scenario.action), func(t *testing.T) { + world, conn := newStackWorld(t) + request := stackActionPacket(1, scenario.action, 64, scenario.argument)[20:] + errors := make(chan error, 2) + var workers sync.WaitGroup - for range 2 { - workers.Go(func() { errors <- world.handleInventory(world.clients[1], request) }) - } - workers.Wait() - close(errors) + for range 2 { + workers.Go(func() { errors <- world.handleInventory(world.clients[1], request) }) + } + workers.Wait() + close(errors) - for err := range errors { - if err != nil { - t.Fatal(err) + for err := range errors { + if err != nil { + t.Fatal(err) + } } - } - if !reflect.DeepEqual(world.characters[1].inventory.Items, scenario.expected) || len(conn.packets) != 1 { - t.Fatalf("repeated stack request duplicated quantity: %+v packets%d", world.characters[1].inventory, len(conn.packets)) + if !reflect.DeepEqual(world.characters[1].inventory.Items, scenario.expected) || len(conn.packets) != 1 { + t.Fatalf("repeated stack request duplicated quantity: %+v packets%d", world.characters[1].inventory, len(conn.packets)) + } + }) { + return } } } diff --git a/server/starter_weapons_test.go b/server/starter_weapons_test.go @@ -392,7 +392,8 @@ func TestZeroWeaponRequirementCannotDivideByZeroAfterSkillLoss(t *testing.T) { original := gamedata.ItemTemplates[123057] weapon := *original stat := int32(103) - functions := []gamedata.ItemFunction{{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &stat}, {Integer: &actual}}}} + functions := []gamedata.ItemFunction{{ID: 53045, HeaderWords: [2]uint32{0, 4}, ArgumentHeader: 9, Target: 2, TickCount: 1, + Arguments: []gamedata.ItemArgument{{Integer: &stat}, {Integer: &actual}}}} weapon.Sections = append(slices.Clone(original.Sections), gamedata.ItemSection{Type: 2, Subtype: 14, Functions: &functions}) gamedata.ItemTemplates[123057] = &weapon t.Cleanup(func() { gamedata.ItemTemplates[123057] = original }) diff --git a/server/stats_test.go b/server/stats_test.go @@ -2,6 +2,7 @@ package main import ( "encoding/binary" + "fmt" "testing" "time" ) @@ -84,22 +85,26 @@ func TestCharacterStatsProfileEditClampsBothResources(t *testing.T) { func TestRegenerationUsesEditedAbilitiesAndBodyDevelopment(t *testing.T) { for _, sitting := range []bool{false, true} { - world, _, start := newRegenerationWorld(t) - world.characters[1].stats = testCharacterStats() - world.characters[1].stats.Abilities.Stamina, world.characters[1].stats.Abilities.Psychic = 60, 120 - world.characters[1].stats.Body.BodyDevelopment, world.characters[1].stats.Body.NanoPool = 200, 100 - world.characters[1].sitting = sitting - - for second := 2; second <= 54; second += 2 { - world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) - } - - health, nano := uint32(25), uint32(10) - if sitting { - health, nano = 42, 22 - } - if world.characters[1].health != health || world.characters[1].nano != nano { - t.Fatalf("edited recovery sitting=%t: %+v", sitting, world.characters[1]) + if !t.Run(fmt.Sprint(sitting), func(t *testing.T) { + world, _, start := newRegenerationWorld(t) + world.characters[1].stats = testCharacterStats() + world.characters[1].stats.Abilities.Stamina, world.characters[1].stats.Abilities.Psychic = 60, 120 + world.characters[1].stats.Body.BodyDevelopment, world.characters[1].stats.Body.NanoPool = 200, 100 + world.characters[1].sitting = sitting + + for second := 2; second <= 54; second += 2 { + world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) + } + + health, nano := uint32(25), uint32(10) + if sitting { + health, nano = 42, 22 + } + if world.characters[1].health != health || world.characters[1].nano != nano { + t.Fatalf("edited recovery sitting=%t: %+v", sitting, world.characters[1]) + } + }) { + return } } } diff --git a/server/weapon_stats_test.go b/server/weapon_stats_test.go @@ -2,6 +2,7 @@ package main import ( "ao/server/gamedata" + "fmt" "slices" "testing" "time" @@ -12,29 +13,34 @@ func TestWeaponRatingTruncatesEachAuthoredWeightBeforeAllOff(t *testing.T) { edged, pistol uint16 rating int32 }{{1, 1, 0}, {5, 9, 15}, {9, 5, 15}, {400, 200, 309}} { - world, _ := newEquipmentWorld(t) - player := world.characters[1] - world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:]) - world.advanceEquipment(world.clients[1].equipment.readyAt) - player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} - player.stats.Melee.OneHandEdged, player.stats.Ranged.Pistol = scenario.edged, scenario.pistol - original := gamedata.ItemTemplates[209283] - weapon := *original - weights := [][2]uint32{{103, 50}, {112, 50}} - kind := uint32(12) - entries := []gamedata.ItemEntry{{Type: &kind, Stats: &weights}} - stat, amount := int32(276), int32(9) - functions := []gamedata.ItemFunction{{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &stat}, {Integer: &amount}}}} - weapon.Sections = []gamedata.ItemSection{{Type: 4, Subtype: 4, Entries: &entries}, {Type: 14, Subtype: 19, Entries: &entries}, {Type: 2, Subtype: 14, Functions: &functions}} - gamedata.ItemTemplates[209283] = &weapon - t.Cleanup(func() { gamedata.ItemTemplates[209283] = original }) + if !t.Run(fmt.Sprintf("edged%d/pistol%d", scenario.edged, scenario.pistol), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:]) + world.advanceEquipment(world.clients[1].equipment.readyAt) + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Melee.OneHandEdged, player.stats.Ranged.Pistol = scenario.edged, scenario.pistol + original := gamedata.ItemTemplates[209283] + weapon := *original + weights := [][2]uint32{{103, 50}, {112, 50}} + kind := uint32(12) + entries := []gamedata.ItemEntry{{Type: &kind, Stats: &weights}} + stat, amount := int32(276), int32(9) + functions := []gamedata.ItemFunction{{ID: 53045, HeaderWords: [2]uint32{0, 4}, ArgumentHeader: 9, Target: 2, TickCount: 1, + Arguments: []gamedata.ItemArgument{{Integer: &stat}, {Integer: &amount}}}} + weapon.Sections = []gamedata.ItemSection{{Type: 4, Subtype: 4, Entries: &entries}, {Type: 14, Subtype: 19, Entries: &entries}, {Type: 2, Subtype: 14, Functions: &functions}} + gamedata.ItemTemplates[209283] = &weapon + t.Cleanup(func() { gamedata.ItemTemplates[209283] = original }) - rating := player.attackRating() + rating := player.attackRating() - if rating != scenario.rating { - t.Fatalf("skills %d/%d: got rating %d, want %d", scenario.edged, scenario.pistol, rating, scenario.rating) + if rating != scenario.rating { + t.Fatalf("skills %d/%d: got rating %d, want %d", scenario.edged, scenario.pistol, rating, scenario.rating) + } + gamedata.ItemTemplates[209283] = original + }) { + return } - gamedata.ItemTemplates[209283] = original } } @@ -43,32 +49,36 @@ func TestWeaponInitiativeUsesAuthoredStatAndNativeDefaults(t *testing.T) { stat uint32 attack, recharge time.Duration }{{118, 1990 * time.Millisecond, 1990 * time.Millisecond}, {119, 1500 * time.Millisecond, time.Second}, {120, time.Second, time.Second}, {0, 1500 * time.Millisecond, time.Second}} { - world, _ := newEquipmentWorld(t) - player := world.characters[1] - world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:]) - world.advanceEquipment(world.clients[1].equipment.readyAt) - player.stats.Speed.MeleeInitiative, player.stats.Speed.RangedInitiative, player.stats.Speed.PhysicalInitiative = 0, 298, 598 - original := gamedata.ItemTemplates[209283] - weapon := *original - weapon.Stats = slices.Clone(original.Stats) - for index, stat := range weapon.Stats { - if stat[0] == 440 { - weapon.Stats[index][1] = scenario.stat - if scenario.stat == 0 { - weapon.Stats = slices.Delete(weapon.Stats, index, index+1) + if !t.Run(fmt.Sprint(scenario.stat), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:]) + world.advanceEquipment(world.clients[1].equipment.readyAt) + player.stats.Speed.MeleeInitiative, player.stats.Speed.RangedInitiative, player.stats.Speed.PhysicalInitiative = 0, 298, 598 + original := gamedata.ItemTemplates[209283] + weapon := *original + weapon.Stats = slices.Clone(original.Stats) + for index, stat := range weapon.Stats { + if stat[0] == 440 { + weapon.Stats[index][1] = scenario.stat + if scenario.stat == 0 { + weapon.Stats = slices.Delete(weapon.Stats, index, index+1) + } + break } - break } - } - gamedata.ItemTemplates[209283] = &weapon - t.Cleanup(func() { gamedata.ItemTemplates[209283] = original }) + gamedata.ItemTemplates[209283] = &weapon + t.Cleanup(func() { gamedata.ItemTemplates[209283] = original }) - attack, recharge := player.attackDelays() + attack, recharge := player.attackDelays() - if attack != scenario.attack || recharge != scenario.recharge { - t.Fatalf("initiative stat %d: got %v/%v, want %v/%v", scenario.stat, attack, recharge, scenario.attack, scenario.recharge) + if attack != scenario.attack || recharge != scenario.recharge { + t.Fatalf("initiative stat %d: got %v/%v, want %v/%v", scenario.stat, attack, recharge, scenario.attack, scenario.recharge) + } + gamedata.ItemTemplates[209283] = original + }) { + return } - gamedata.ItemTemplates[209283] = original } }