aorecomp

Anarchy Online classic in the browser

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


commit bdd18afae1c40076ebd98fe900f4c1076df1dcda
parent d6d7ee1b43808a853a6746cd87cb3437defbbf57
Author: anon <anon@example.com>
Date:   Thu,  5 Nov 2026 00:14:41 +0000

Maintain native bulk reclaim and cold recovery checks

Diffstat:
MDEVELOPERS.md | 8++++++++
MTODO.md | 8+++++++-
Mdocs/inventory.md | 21+++++++++++++++++++++
Aserver/browser_bulk_reclaim_test.go | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_bulk_reclaim.mjs | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 316 insertions(+), 1 deletion(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -589,6 +589,14 @@ Pre-attack and post-kill captures retain native and live server poses beside their wire events. Funded health supplies, further levels, full inventory and actual death/reclaim remain broader regression work. +`AO_GAME_TEST=1 go test ./server -run '^TestBrowserBulkReclaimColdRecovery$' -count=1 -timeout=7m -v` +runs the short controlled 24-entry reclaim checkpoint. Two fresh native clients +load pending reclaim from a closed database, then use the real booth, scrolling +and collection. Empty-slot retries, observer privacy, page replay and a second +closed-database restart conserve exact identities, charges and loaded ammunition. +This isolates transfer/recovery; it does not earn progression or measure death +and reclaim timing. See [bulk reclaim](docs/inventory.md#bulk-reclaim-after-cold-loading). + `TestBrowserStarterMissionTargets` walks a normally created starter through its training exit to Backyard1. It checks the distinct booth56001, entrance56006 and scene-door51005 identities sharing a numeric ID, then uses the actual booth and diff --git a/TODO.md b/TODO.md @@ -5031,7 +5031,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. original server/database and connects two fresh WASM clients to the restored server through normal password login. `TestBrowserStarterColdRecovery` verifies that stage with controlled current-schema profiles; it is not fresh earned - progression. Finish the remaining checkpoint phases without re-earning levels + progression. `TestBrowserBulkReclaimColdRecovery` maintains the separate + 24-entry reclaim checkpoint: real scrolling/collection, empty-slot retries, + observer privacy and page/fresh-server replay preserve every physical item, + charge and loaded round. This controlled fixture uses production retention + rules, not an earned death or a new timing measurement. Actual death and + creature-equipment acquisition still need integration with the maintained loop. + Finish the remaining checkpoint phases without re-earning levels merely to reach their conditions. Keep this gate open until they are maintained. Initial baseline: two Neutral Enforcers created through Options with their issued loadouts; ordinary right-click equips the same starter Baseballbat diff --git a/docs/inventory.md b/docs/inventory.md @@ -1022,3 +1022,24 @@ exhausted. That failed fetch emitted an `Event` error. The page now retains the script for later workers. The same Chromium outage test created the extra worker without that error, reconnected automatically, rendered the world and accepted movement input. + +### Bulk reclaim after cold loading + +`TestBrowserBulkReclaimColdRecovery` maintains the larger transfer case recorded +in the [earned level-ten run](mission-levels.md#native-earned-level-ten), using +a short current-schema controlled fixture. Production retention rules keep a +worn bat and a NoDrop item while moving 24 ordinary instances to reclaim. Those +entries include a QL75 weapon with 13 loaded rounds, a 100-round ammunition stack +and a QL2 laboratory with 17 charges. This fixture grants its initial conditions +and expires the availability clock; it does not repeat or establish earned death, +period loot selection, resurrection or reclaim timing. + +The database closes before two fresh WASM clients connect. Real booth use and a +wheel gesture reach the private scrollable window; each displayed source is +collected once. The original client automatically scrolls to earlier populated +rows as later rows empty. Two empty-cell clicks and an empty close/reopen create +no items. Page replay and another closed-database restart retain all 33 physical +identities: 26 owner items and seven unchanged observer items. Native/server +slot, endpoint, QL and count comparisons accompany exact server ammunition and +wallet checks. The observer receives no private reclaim packet. This necessary +regression leaves the broader earned-loop and equipment-loss audits open. diff --git a/server/browser_bulk_reclaim_test.go b/server/browser_bulk_reclaim_test.go @@ -0,0 +1,159 @@ +package main + +import ( + "cmp" + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserBulkReclaimColdRecovery(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused 24-entry reclaim check") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/bulk-reclaim", time.Now().Format("20060102-150405")) + world := newTestServer(t) + before := make(map[uint32]playerInventory) + for _, name := range []string{"Bulkowner", "Bulkwatch"} { + player := world.newCharacter() + player.name, player.level, player.appearance = name, 10, 0x515 + player.playfield, player.position = 705, [3]float32{598, 16.9, 329} + player.rotation = [4]float32{0, .70710677, 0, .70710677} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(name))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + templates := []uint32{42640, 42640, 42640, 42640, 42640, 42640, 42640} + if player.id == 1 { + templates = []uint32{121564, 121567, 124261, 21609, 25812} + for range 21 { + templates = append(templates, 42640) + } + } + for _, template := range templates { + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + if player.id == 1 { + inventory.Credits = 1319 + inventory.Items[0].Slot = 6 + for index := 1; index < len(inventory.Items); index++ { + inventory.Items[index].Slot = uint32(63 + index) + } + inventory.Items[2].Quality, inventory.Items[2].Ammo = 75, 13 + inventory.Items[3].Count, inventory.Items[4].Count = 100, 17 + inventory.Items[4].Quality = 2 + } + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + before[player.id] = inventory + } + player := world.characters[1] + // Use production retention rules with an expired controlled availability clock. + player.collectReclaim(time.Now().Add(-76 * time.Second).UTC()) + if len(player.inventory.Items) != 2 || len(player.inventory.Reclaim) != 24 { + t.Fatal("fixture must retain worn/NoDrop items and put 24 ordinary instances in reclaim") + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + player.inventory.LastID = world.nextItem + for id, inventory := range before { + inventory.LastID = world.nextItem + before[id] = inventory + } + closeTestSessions(t, world) + if err := world.db.Close(); err != nil { + t.Fatal(err) + } + world = newServerForTest(t) + if !reflect.DeepEqual(world.characters[1].inventory, player.inventory) { + t.Fatal("cold loading changed pending reclaim") + } + + for _, phase := range []string{"collect", "cold"} { + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + player := world.browserCharacter_locked(r) + items := make([][7]uint32, 0, len(player.inventory.Items)) + for _, item := range player.inventory.Items { + low, high := item.templateIDs() + items = append(items, [7]uint32{item.ID, item.Type, item.Slot, item.Quality, uint32(item.Count), low, high}) + } + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "items": items, "nextItem": world.nextItem}) + }) + host := httptest.NewServer(mux) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_bulk_reclaim.mjs"), host.URL, filepath.Join(output, phase), phase) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + cancel() + host.Close() + closeTestSessions(t, world) + t.Logf("Browser artifacts: %s/%s", output, phase) + if err != nil { + t.Fatal(err) + } + + for id, inventory := range before { + if phase == "collect" && id == 1 { + actual := world.characters[id].inventory + if len(actual.Items) != 26 { + t.Fatal("collection lost an instance", len(actual.Items)) + } + for _, item := range actual.Items { + index := slices.IndexFunc(inventory.Items, func(expected ownedItem) bool { return item.ID == expected.ID }) + if index < 0 || item.ID > 2 && (item.Slot < 65 || item.Slot > 88) { + t.Fatal("collection changed identity or placement", item) + } + expected := inventory.Items[index] + if item.ID > 2 { + expected.Slot = item.Slot + } + if item != expected { + t.Fatal("collection changed item properties", item, expected) + } + } + inventory.Items = slices.Clone(actual.Items) + slices.SortFunc(inventory.Items, func(a, b ownedItem) int { return cmp.Compare(a.ID, b.ID) }) + before[id] = inventory + } + actual := world.characters[id].inventory + actual.Items = slices.Clone(actual.Items) + slices.SortFunc(actual.Items, func(a, b ownedItem) int { return cmp.Compare(a.ID, b.ID) }) + if !reflect.DeepEqual(actual, inventory) { + t.Fatal("collection/replay changed an identity, slot, charge, loaded round or wallet", id) + } + } + if world.nextItem != 33 { + t.Fatal("collection/replay allocated an item", world.nextItem) + } + if err := world.db.Close(); err != nil { + t.Fatal(err) + } + if phase == "collect" { + world = newServerForTest(t) + } + } +} diff --git a/tools/client/test_bulk_reclaim.mjs b/tools/client/test_bulk_reclaim.mjs @@ -0,0 +1,121 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output, phase] = process.argv.slice(2); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ + '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +const games = []; +const evidence = {}; +const state = async game => (await game.page.request.get(url + '/test-state')).json(); +const source = snapshot => snapshot.grids.flatMap(grid => grid.cells).filter(cell => + cell.identity[0] === 106 && !cell.dummy); +const compare = async game => { + const server = await state(game); + const expected = server.items.map(([id, type, slot, quality, count, low, high]) => + [id, type, slot >= 64 ? slot - 16 : slot, quality, count, low, high]).sort((a, b) => a[0] - b[0]); + const actual = game.local().inventory.map(item => + [item.id, item.type, item.slot, item.quality, item.count, ...item.templates]).sort((a, b) => a[0] - b[0]); + assert.deepEqual(actual, expected); + assert.equal(game.local().stats[61], server.inventory.Credits); + assert.equal(server.nextItem, 33); + return server; +}; +try { + for (const name of ['Bulkowner', 'Bulkwatch']) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: name, url}]); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + evidence[name] = await compare(game); + } + const [owner, observer] = games; + const initial = evidence.Bulkowner.inventory; + if (phase === 'collect') { + assert.equal(initial.Reclaim.length, 24); + assert.equal(initial.Items.length, 2); + const [x, y] = await owner.pick(51059, 3221881537); + await owner.click(x, y, 'right'); + await owner.wait('24-entry private reclaim opens', snapshot => source(snapshot).length > 0); + await owner.save(output + '/opened'); + const pending = new Map(initial.Reclaim.map((entry, slot) => [slot, entry.Item])); + evidence.collected = []; + const firstRow = owner.state.grids.find(grid => grid.cells.some(cell => cell.identity[0] === 106)).firstRow; + assert(firstRow > 0); + const point = await owner.point(80, 70); + await owner.page.mouse.move(point.x, point.y); + await owner.page.mouse.wheel(0, -100); + await owner.wait('native reclaim scrolls to earlier rows', snapshot => snapshot.grids.some(grid => + grid.cells.some(cell => cell.identity[0] === 106) && grid.firstRow < firstRow)); + evidence.scrolls = 1; + let lastCell; + for (let index = 0; index < 24; ++index) { + let cell = source(owner.state).find(cell => pending.has(cell.identity[1])); + if (!cell) { + // Advance upward if the remaining fixed slots are outside the visible rows. + const previous = source(owner.state).map(cell => cell.identity[1]).join(','); + const point = await owner.point(80, 70); + await owner.page.mouse.move(point.x, point.y); + await owner.page.mouse.wheel(0, -100); + ++evidence.scrolls; + await owner.wait('earlier reclaim rows become visible', snapshot => source(snapshot).some(cell => + pending.has(cell.identity[1])) && source(snapshot).map(cell => cell.identity[1]).join(',') !== previous); + cell = source(owner.state).find(cell => pending.has(cell.identity[1])); + } + assert(cell); + const slot = cell.identity[1]; + const item = pending.get(slot); + await owner.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); + await owner.wait('exact reclaim instance arrives', snapshot => owner.local(snapshot).inventory.some(proxy => + proxy.id === item.ID && proxy.type === item.Type)); + const after = await state(owner); + const taken = after.inventory.Items.find(candidate => candidate.ID === item.ID); + assert.deepEqual({...taken, Slot: item.Slot}, item); + assert.equal(after.inventory.Reclaim?.length ?? 0, 23 - index); + pending.delete(slot); + evidence.collected.push({slot, item: taken}); + lastCell = cell; + } + assert(evidence.scrolls > 0, 'bulk reclaim must exercise its native scrollable window'); + evidence.after = await compare(owner); + assert.equal(evidence.after.inventory.Reclaim, null); + for (let index = 0; index < 2; ++index) { + await owner.click((lastCell.bounds[0] + lastCell.bounds[2]) / 2, (lastCell.bounds[1] + lastCell.bounds[3]) / 2); + assert.deepEqual(await state(owner), evidence.after); + } + await owner.click(170, 8); + await owner.click(x, y, 'right'); + await owner.wait('empty reclaim window reopens', snapshot => snapshot.regions.some(region => + region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); + assert.equal(source(owner.state).length, 0); + assert.deepEqual(await state(owner), evidence.after); + await owner.save(output + '/collected'); + await owner.page.reload(); + await owner.ready(); + evidence.reconnected = await compare(owner); + assert.deepEqual(evidence.reconnected, evidence.after); + } else { + assert.equal(initial.Reclaim, null); + assert.equal(initial.Items.length, 26); + evidence.after = await compare(owner); + } + assert.deepEqual(await compare(observer), evidence.Bulkwatch); + assert(!observer.events.some(event => event.opcode === '52213420')); + assert.equal(evidence.after.inventory.Items.find(item => item.ID === 3).Ammo, 13); + assert.equal(evidence.after.inventory.Items.find(item => item.ID === 4).Count, 100); + assert.equal(evidence.after.inventory.Items.find(item => item.ID === 5).Count, 17); + for (const game of games) assert.deepEqual(game.errors, []); + console.log('PASS:', phase, '24 exact reclaim identities, charges, loaded rounds, private observer and fresh-client recovery'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + for (let index = 0; index < games.length; ++index) await games[index].save(output + '/final-' + index); + } finally { await browser.close(); } +}