aorecomp

Anarchy Online classic in the browser

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


commit f0b7ffe9581f94c7b43ffe0e7b824d88a1cbfde2
parent 3b0bec1bc28cc36a203448e01cda0758e9566ad8
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 06:39:45 +0000

Implement pet wait and replay owner membership after readiness

Diffstat:
MTODO.md | 21++++++++++++++++-----
Mdocs/pet-follow.md | 47++++++++++++++++++++++++++++++++++++++++++-----
Mdocs/pet-owner-protocol.md | 14++++++++++++--
Mdocs/pet-summoning.md | 2+-
Mserver/browser_pet_follow_test.go | 17+++++++++++++----
Mserver/main.go | 11+----------
Mserver/pet_follow.go | 13+++++++++++--
Aserver/pet_wait_test.go | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/pets.go | 14++++++++++++++
Mserver/world_actions.go | 4++++
Mtools/client/test_pet_owner_protocol.mjs | 9+++++++++
Atools/client/test_pet_wait.mjs | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 329 insertions(+), 29 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3144,13 +3144,24 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah Commands/ticks do not write SQLite; unavailable owners and expired pets suspend motion. See [pet follow](docs/pet-follow.md). -- [ ] [P2] Recover remaining pet-follow fidelity. Check: named commands select - only matching owned pets, and obstacle/lost-target routes match the original - NPC breadcrumb behavior. The admitted empty selector targets the owner's set; - shared server route planning does not establish original breadcrumb insertion +- [ ] [P2] Recover named pet-command selection and remaining follow fidelity. + Check: named commands select only matching owned pets, and obstacle/lost-target + routes match the original NPC breadcrumb behavior. The admitted empty selector + targets the owner's set; shared server route planning does not establish + original breadcrumb insertion or loss recovery. Default summon mode and cold-mode policy remain unverified. -- [ ] [P1] Make the pet wait. Check: it stays at the commanded position while its +- [x] [P1] Make the pet wait. Check: it stays at the commanded position while its owner moves, until another valid command changes its behavior. + Original command4 clears follow/route and halts the native controller at its + current pose. Idle/moving Go checks and a two-owner WASM scenario preserve + that pose through movement and both page reloads; explicit follow resumes + without another cost or changes to the other pet. See [pet movement](docs/pet-follow.md). +- [x] [P1] Restore the native pet count after owner-actor replacement. Check: + reloading either of two pet owners keeps both clients' stat458 counts at one + after replay, without changing entities, ownership or cost. Membership now + replays after CharacterReady and effects; early bootstrap alone leaves the + replaced remote actor's count unknown. Public ready-handler ordering and + both native owner/observer reloads pass in the focused wait scenario. - [ ] [P1] Order the pet to attack. Check: it validates the target and begins combat on its own action schedule. - [ ] [P1] Stop a pet's attack. Check: the stop command clears combat and queued diff --git a/docs/pet-follow.md b/docs/pet-follow.md @@ -1,4 +1,4 @@ -# Owned pet follow +# Owned pet follow and wait The original `/pet follow` command now installs its authenticated owner's character as the owned pet's movement target. A short controlled route verifies @@ -35,9 +35,9 @@ Pose corrections use extended action20 (`0x94`), which preserves the target. ## Server behavior and limits -Only the captured all-pets follow request is admitted. Actor identity and the -current ready client must match; named selectors, arguments and other commands -are refused. The server selects entities from its ownership map rather than +Only the captured all-pets follow and wait requests are admitted. Actor identity +and the current ready client must match; named selectors, arguments and other +commands are refused. The server selects entities from its ownership map rather than trusting pet IDs supplied by a client. Dead, expired or other-playfield pets cannot start following. @@ -57,7 +57,21 @@ the original server's disconnect grace period or pet retirement rules. The simple route does not establish original obstacle-following behavior. Server routing currently uses the shared NPC route planner; the exact original breadcrumb insertion, loss recovery and default-on-summon mode remain evidence -gaps. Combat, wait and owner-disconnect lifecycle are separate TODOs. +gaps. Combat and owner-disconnect lifecycle are separate TODOs. + +## Wait + +Original `/pet wait` emits body words `4, 0, 1009, 0, 0`, captured through real +keyboard input in `local/pet-owner-protocol/20261103-221411/`. The shipped +`cd_image/text/help/Pet Commands.txt` describes remaining still. It uses the +same implicit owner set and admission checks as follow; named selectors remain +unsupported. + +Wait clears the logical follow target and pending route, applies native Halt19 +to server motion, and sends FollowTarget with empty identity, control19 and +the commanded pose. It admits an idle pet as well as a moving follower. Owner +movement or page reload does not resume this cleared mode; a subsequent valid +follow command does. No command/tick database writes or new summon costs occur. ## Focused verification @@ -81,3 +95,26 @@ run passes in43.97 seconds in `local/pet-follow/20261103-221049/`, additionally checking the peer pet's unchanged native pose on both clients. All eight saved traces have no client errors or dropped events. Vet, driver syntax checks and the retained evidence validation in `local/pet-follow/validation.json` pass. + +The wait baseline leaves a moving pet following from x2.3 to x28.3, and its +WASM request receives no target-clear controller. The focused Go regression +checks both idle and moving pets, held pose during subsequent ticks, native +target clearing, no cost/database churn and explicit follow resumption. +`TestBrowserPetWait` starts from the same controlled two-owner checkpoint. +Real chat issues follow/wait/follow; real movement leaves the commanded pet +behind, preserving both native replicas and the other owner's pet. Observer +and owner reloads retain the waiting pose before the final follow resumes. + +That scenario also reproduced a persistent remote-owner count failure: +Destroy/SCFU/AddPet before CharacterReady left stat458 at the native unknown +value1234567890. A twelve-second semantic wait confirmed it was not a short +loading interval. The shared owner-state replay now runs after CharacterReady +and equipment/nano effects, with a public ready-handler ordering regression. +The passing native run is `local/pet-wait/20261103-223704/`,35.05 seconds. +Earlier fixture boundaries and rejected replay approaches remain in separate +captures and are not completion evidence. + +The final related Go run passes51 roots/145 results, including the new +ready-handler regression. Vet and driver syntax checks pass. All four final +native traces have no errors or dropped events; exact packets, counts, poses, +source hashes and baseline checks are retained in `local/pet-wait/validation.json`. diff --git a/docs/pet-owner-protocol.md b/docs/pet-owner-protocol.md @@ -1,8 +1,8 @@ # Original pet owner-list protocol This document covers the original transport prerequisite. The server now admits -one [owned summon](pet-summoning.md); broader pet commands and lifecycle fidelity -remain separate work. +one [owned summon](pet-summoning.md) and all-pets [follow/wait](pet-follow.md); +broader commands and lifecycle fidelity remain separate work. ## Original client evidence @@ -23,6 +23,16 @@ and bounded string. Native `/pet report` with no name filter emits body words present. This establishes the request, not a server report response. The same native input captures `/pet follow` as `1, 0, 1009, 0, 0`; the owned server implementation is documented in [pet follow](pet-follow.md). +It captures `/pet wait` as `4, 0, 1009, 0, 0`, now admitted by the same owned +command handler. + +Owner membership replays after CharacterReady and the actor's equipment/nano +effects. A two-owned-pet reload regression shows that early bootstrap AddPet +alone leaves the replaced remote actor's stat458 unknown, even after twelve +seconds. Replaying the original membership after readiness restores both +clients' counts. The server publishes stat251 separately; original AddPet +derives stat458 from the native owner set. See +[the wait/reload regression](pet-follow.md#wait). The NPC full-update reader at `10082da0` reads four compact fields after its flags. Activation at `100821d0` publishes these as stats455,466,512,388. diff --git a/docs/pet-summoning.md b/docs/pet-summoning.md @@ -27,7 +27,7 @@ data, not an original14.9.1 server measurement. The later data's four-point skil requirements are not imported: the original requires eight. Weapon selection, raw combat stats, master/type metadata and exact spawn placement remain open. Player-versus-pet combat remains unsupported. The owned pet separately admits -the original all-pets [follow command](pet-follow.md). +the original all-pets [follow and wait commands](pet-follow.md). TimeExist is interpreted as seconds. A [later compiled nano chart](https://www.slideshare.net/slideshow/nano-formulas/7124531) diff --git a/server/browser_pet_follow_test.go b/server/browser_pet_follow_test.go @@ -14,12 +14,21 @@ import ( ) func TestBrowserPetFollow(t *testing.T) { + runBrowserPetMotion(t, "follow") +} + +func TestBrowserPetWait(t *testing.T) { + runBrowserPetMotion(t, "wait") +} + +func runBrowserPetMotion(t *testing.T, scenario string) { + t.Helper() if os.Getenv("AO_GAME_TEST") != "1" { - t.Skip("set AO_GAME_TEST=1 for native pet follow") + t.Skip("set AO_GAME_TEST=1 for native pet " + scenario) } _, source, _, _ := runtime.Caller(0) root := filepath.Dir(filepath.Dir(source)) - output := filepath.Join(root, "local/pet-follow", time.Now().Format("20060102-150405")) + output := filepath.Join(root, "local/pet-"+scenario, time.Now().Format("20060102-150405")) world := newBrowserPetWorld(t) // Controlled checkpoint: both players have completed the ordinary summon action. for id := uint32(1); id <= 2; id++ { @@ -71,7 +80,7 @@ func TestBrowserPetFollow(t *testing.T) { }() defer func() { cancel(); <-stopped }() - command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pet_follow.mjs"), host.URL, output) + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pet_"+scenario+".mjs"), host.URL, output) command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr err := command.Run() @@ -83,6 +92,6 @@ func TestBrowserPetFollow(t *testing.T) { defer world.mutex.Unlock() if world.characters[1000001].followTarget != 1 || world.characters[1000002].followTarget != 0 || world.characters[1].nano != 25 || world.characters[2].nano != 25 { - t.Fatal("follow changed another owner's pet or charged another summon") + t.Fatal("pet motion changed another owner's pet or charged another summon") } } diff --git a/server/main.go b/server/main.go @@ -408,16 +408,7 @@ func (server *server) serveWorldClient(client *worldClient) error { updates = append(updates, server.chatServerPacket(conn)) } updates = append(updates, fullCharacterPacket(character)) - var petUpdates [][]byte - if len(character.pets) != 0 { - petUpdates = append(petUpdates, petCounterPacket(character)) - for id, pet := range character.pets { - petUpdates = append(petUpdates, petIdentityPacket(0x194e4f76, character.id, id)) - if pet.followTarget != 0 && pet.playfield == character.playfield && !pet.pet.paused { - petUpdates = append(petUpdates, petFollowPacket(pet, character.id)) - } - } - } + petUpdates := petOwnerPackets(character) updates = append(updates, petUpdates...) for _, mission := range character.missions { updates = append(updates, missionJournalPacket(mission, time.Now())) diff --git a/server/pet_follow.go b/server/pet_follow.go @@ -11,9 +11,10 @@ func (server *server) handlePetCommand(client *worldClient, body []byte) error { if len(body) < 36 { return fmt.Errorf("invalid pet command length") } - // Original /pet follow: command 1, no argument, empty encoded selector list. + // Original unfiltered commands: follow=1, wait=4, no argument or named selector. + command := binary.BigEndian.Uint32(body[16:20]) if len(body) != 36 || !client.target || binary.BigEndian.Uint32(body[4:8]) != 50000 || - binary.BigEndian.Uint32(body[8:12]) != client.id || binary.BigEndian.Uint32(body[16:20]) != 1 || + binary.BigEndian.Uint32(body[8:12]) != client.id || command != 1 && command != 4 || binary.BigEndian.Uint32(body[20:24]) != 0 || binary.BigEndian.Uint32(body[24:28]) != 1009 || binary.BigEndian.Uint32(body[28:32]) != 0 || binary.BigEndian.Uint32(body[32:36]) != 0 { return nil @@ -32,6 +33,14 @@ func (server *server) handlePetCommand(client *worldClient, body []byte) error { if pet.health == 0 || pet.playfield != owner.playfield || !now.Before(pet.pet.expiresAt) { continue } + if command == 4 { + pet.followTarget = 0 + pet.pet.paused = false + pet.motion = nil + pet.movement.action(pet, 19) + server.queueCombat_locked(updates, pet, owner, petFollowPacket(pet, 0)) + continue + } pet.geometry = server.geometry pet.followTarget = owner.id pet.pet.paused = false diff --git a/server/pet_wait_test.go b/server/pet_wait_test.go @@ -0,0 +1,95 @@ +package main + +import ( + "encoding/binary" + "testing" + "time" +) + +func TestPetWaitHoldsItsCommandedPositionUntilFollow(t *testing.T) { + for _, scenario := range []string{"idle", "moving"} { + t.Run(scenario, func(t *testing.T) { + world, output := newPetSummonWorld(t) + player, client := world.characters[1], world.clients[1] + world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 0, 0, 53019, 43324})[20:]) + world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond)) + pet := player.pets[1000001] + player.position = [3]float32{20, 0, 0} + now := time.Now() + if scenario == "moving" { + world.handlePetCommand(client, petFollowRequest(1)[20:]) + world.advancePlayerMovement(now.Add(time.Second)) + if pet.movement.speed == 0 { + t.Fatal("fixture pet must be moving before wait") + } + } + start := pet.position + request := petFollowRequest(1)[20:] + binary.BigEndian.PutUint32(request[16:], 4) + output.packets = nil + auditCheckpointWrites(t, world) + + err := world.handlePetCommand(client, request) + player.position = [3]float32{30, 0, 0} + for tick := 1; tick <= 100; tick++ { + world.advancePlayerMovement(now.Add(time.Second + time.Duration(tick)*100*time.Millisecond)) + } + + if err != nil || pet.followTarget != 0 || pet.motion != nil || pet.position != start || + pet.movement.velocity != [3]float32{} || pet.movement.speed != 0 || player.nano != 25 || + len(checkpointWrites(t, world)) != 0 || len(output.packets) != 1 { + t.Fatal("wait did not hold without another cost or tick writes", err, pet.followTarget, start, pet.position, len(output.packets)) + } + packet := output.packets[0] + if binary.BigEndian.Uint32(packet[16:20]) != 0x260f3671 || binary.BigEndian.Uint32(packet[24:28]) != pet.id || + binary.BigEndian.Uint32(packet[29:33]) != 0 || binary.BigEndian.Uint32(packet[33:37]) != 0 || packet[41] != 19 { + t.Fatalf("wait did not clear the native target and halt: %x", packet) + } + if err := world.handlePetCommand(client, petFollowRequest(1)[20:]); err != nil { + t.Fatal(err) + } + world.advancePlayerMovement(now.Add(12 * time.Second)) + if pet.followTarget != 1 || pet.position == start || player.nano != 25 { + t.Fatal("valid follow did not replace wait", pet.followTarget, pet.position) + } + }) + } +} + +func TestPetOwnerReadyReplaysMembershipAfterActorLoading(t *testing.T) { + world, output := newPetSummonWorld(t) + client := world.clients[1] + world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 0, 0, 53019, 43324})[20:]) + world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond)) + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, target: true, ready: true, conn: observer, npcs: map[uint32]bool{1000001: true}} + client.loading = true + output.packets = nil + + err := world.handleCharacterReady(client) + + if err != nil { + t.Fatal(err) + } + for _, packets := range [][][]byte{output.packets, observer.packets} { + ready, linked := false, false + for _, packet := range packets { + key := binary.BigEndian.Uint32(packet[16:20]) + if key == 0x570c2039 { + ready = true + } + if key == 0x194e4f76 { + if !ready || binary.BigEndian.Uint32(packet[24:28]) != 1 || binary.BigEndian.Uint32(packet[33:37]) != 1000001 { + t.Fatalf("pet membership did not follow actor readiness: %x", packet) + } + linked = true + } else if linked { + t.Fatalf("actor replay continued after final pet membership: %x", packet) + } + } + if !linked { + t.Fatal("ready actor did not replay its pet membership") + } + } +} diff --git a/server/pets.go b/server/pets.go @@ -49,6 +49,20 @@ func petCounterPacket(owner *character) []byte { return n3Packet(0x2b333d6e, 50000, owner.id, body) } +func petOwnerPackets(owner *character) [][]byte { + if len(owner.pets) == 0 { + return nil + } + packets := [][]byte{petCounterPacket(owner)} + for id, pet := range owner.pets { + packets = append(packets, petIdentityPacket(0x194e4f76, owner.id, id)) + if pet.followTarget != 0 && pet.playfield == owner.playfield && !pet.pet.paused { + packets = append(packets, petFollowPacket(pet, owner.id)) + } + } + return packets +} + func (server *server) summonPet_locked(caster *character, now time.Time) error { if server.nextNPC == ^uint32(0) || len(caster.pets) != 0 { return fmt.Errorf("pet summon cannot allocate another owned NPC") diff --git a/server/world_actions.go b/server/world_actions.go @@ -64,6 +64,10 @@ func (server *server) handleCharacterReady(client *worldClient) error { replay = append(replay, correction) motion = append(motion, correction) } + // Remote pet-owner state must follow CharacterReady and the actor's effect replay. + pets := petOwnerPackets(player) + replay = append(replay, pets...) + motion = append(motion, pets...) team = server.teamPackets_locked(client.id) server.queueTeamResources_locked(resources, server.characters[client.id]) // Resume the native return request after a disconnect during death. diff --git a/tools/client/test_pet_owner_protocol.mjs b/tools/client/test_pet_owner_protocol.mjs @@ -57,6 +57,15 @@ try { evidence.follow = owner.events.find(event => event.sequence > follow && event.direction === 'framesent' && event.opcode === '6b333303'); const followPacket = Buffer.from(evidence.follow.hex, 'hex'); assert.deepEqual([29, 33, 37, 41, 45].map(offset => followPacket.readUInt32BE(offset)), [1, 0, 1009, 0, 0]); + const wait = owner.sequence; + await owner.key('Enter'); + await owner.page.keyboard.type('/pet wait'); + await owner.key('Enter'); + await owner.wait('native wait request for the owner pet set', () => owner.events.some(event => + event.sequence > wait && event.direction === 'framesent' && event.opcode === '6b333303')); + evidence.wait = owner.events.find(event => event.sequence > wait && event.direction === 'framesent' && event.opcode === '6b333303'); + const waitPacket = Buffer.from(evidence.wait.hex, 'hex'); + assert.deepEqual([29, 33, 37, 41, 45].map(offset => waitPacket.readUInt32BE(offset)), [4, 0, 1009, 0, 0]); assert((await owner.page.request.post(url + '/test-counter')).ok()); await Promise.all(games.map(game => game.wait('packed count is independent from owner list size', () => actor(game, 1).stats[251] === 1))); evidence.counter = counts(); diff --git a/tools/client/test_pet_wait.mjs b/tools/client/test_pet_wait.mjs @@ -0,0 +1,111 @@ +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] = 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 = [], evidence = {commands: [], samples: []}; +const actor = (game, id) => game.state.actors.find(actor => actor.type === 50000 && actor.id === id); +const distance = (first, second) => Math.hypot(...first.map((value, axis) => value - second[axis])); +try { + for (let index = 0; index < 2; index++) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'pet-cast-' + index, url}]); + const page = await context.newPage(), game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + } + const [owner, observer] = games; + const state = async () => (await owner.page.request.get(url + '/test-state')).json(); + const petsReady = game => actor(game, 1000001) && actor(game, 1000002) && + actor(game, 1)?.stats[458] === 1 && actor(game, 2)?.stats[458] === 1; + await Promise.all(games.map(game => game.wait('both owned pets and owner lists visible', () => petsReady(game)))); + evidence.before = await state(); + evidence.peerBefore = games.map(game => actor(game, 1000002).position); + + async function command(text, code, target) { + const sequence = owner.sequence; + await owner.key('Enter'); + await owner.page.keyboard.type('/pet ' + text); + await owner.key('Enter'); + await owner.wait(text + ' receives an owned NPC controller', () => owner.events.some(event => { + if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '260f3671') return false; + const packet = Buffer.from(event.hex, 'hex'); + return packet.readUInt32BE(24) === 1000001 && packet.readUInt32BE(33) === target; + })); + const sent = owner.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '6b333303'); + assert.deepEqual([29, 33, 37, 41, 45].map(offset => Buffer.from(sent.hex, 'hex').readUInt32BE(offset)), [code, 0, 1009, 0, 0]); + evidence.commands.push({text, sent}); + } + + async function observe(label, following) { + const deadline = Date.now() + 12000; + for (;;) { + await Promise.all(games.map(game => game.snapshot())); + const server = await state(), clients = games.map(game => actor(game, 1000001).position); + const counts = games.map(game => [actor(game, 1).stats[458], actor(game, 2).stats[458]]); + const sample = {label, server, clients, counts}; + evidence.samples.push(sample); + assert.deepEqual(server[1].petPosition, evidence.before[1].petPosition); + games.forEach((game, index) => { + assert.deepEqual(actor(game, 1000002).position, evidence.peerBefore[index]); + }); + assert(server.every(owner => owner.nano === 25)); + assert.equal(server[1].follow, 0); + assert.equal(server[0].follow, following ? 1 : 0); + if (!following) assert.deepEqual(server[0].petPosition, evidence.waited[0].petPosition); + if (counts.every(values => values.every(value => value === 1)) && + clients.every(position => distance(position, server[0].petPosition) < (following ? .4 : .15)) && + (!following || distance(server[0].position, server[0].petPosition) < 2.1)) return sample; + assert(Date.now() < deadline, label + ': ' + JSON.stringify(sample)); + } + } + + await command('follow', 1, 1); + const start = owner.local().position; + await owner.hold('KeyW', 'owner walks five metres from the summon checkpoint', snapshot => owner.local(snapshot).position[2] > start[2] + 5); + await command('wait', 4, 0); + evidence.waited = await state(); + evidence.stationary = await observe('wait acknowledged', false); + await Promise.all(games.map((game, index) => game.save(output + '/waiting-' + index))); + const corner = owner.local().position; + await owner.hold('KeyC', 'owner moves four metres away from waiting pet', snapshot => + Math.abs(owner.local(snapshot).position[0] - corner[0]) > 4); + // Wait for the server's compact-coordinate stop update before checking the leg. + const deadline = Date.now() + 5000; + while (distance((await state())[0].position, evidence.waited[0].position) < 4) { + assert(Date.now() < deadline, 'server did not receive the four-metre owner movement'); + await owner.snapshot(); + } + evidence.ownerAway = await observe('owner moves while pet waits', false); + assert(distance(evidence.ownerAway.server[0].position, evidence.waited[0].position) >= 4); + await observer.page.reload(); + await observer.ready(); + await observer.wait('waiting pets and owner lists replay for observer', () => petsReady(observer)); + evidence.observerReplay = await observe('observer replay preserves wait', false); + await owner.page.reload(); + await owner.ready(); + await owner.page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await owner.wait('waiting pets and owner lists replay for owner', () => petsReady(owner)); + const returned = owner.local().position; + await owner.hold('KeyS', 'owner returns four metres while pet remains waiting', snapshot => owner.local(snapshot).position[2] < returned[2] - 4); + evidence.ownerReplay = await observe('owner reload preserves wait', false); + await command('follow', 1, 1); + evidence.final = await observe('valid follow replaces wait', true); + assert(distance(evidence.final.server[0].petPosition, evidence.waited[0].petPosition) > 2); + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: native wait holds the commanded pet pose across owner movement and both reloads, then follow resumes'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); + } finally { await browser.close(); } +}