Skip to content

Add e2e test runner + fix NPC walking, charname, screenshot OOG#5

Merged
jaenster merged 1 commit into
mainfrom
e2e-shopping-runner
May 7, 2026
Merged

Add e2e test runner + fix NPC walking, charname, screenshot OOG#5
jaenster merged 1 commit into
mainfrom
e2e-shopping-runner

Conversation

@jaenster
Copy link
Copy Markdown
Owner

@jaenster jaenster commented May 7, 2026

Summary

  • Real in-game e2e: test runner now uses the full `Game` proxy + drives splash → SP → char select on its own; `pnpm test:e2e` spawns daemon + game and scrapes results.
  • NPC.interact() walks to the target via `findPath` + kolbot single-click-per-node pattern before sending the interact packet — fixes `openTrade`, `heal`, `repair` when the NPC is more than ~10 tiles away.
  • `game.player.charname` reads `pUnitData->szName` for player units (d2bs pattern); `D2CLIENT_GetUnitName` doesn't return the char name for players.
  • `takeScreenshot(name?)` now accepts a filename and works OOG (wired into `hookOogDraw`).
  • 28 new tests: 7 in-game (`scripts/tests/shopping.test.ts`), 21 fast unit (NPC/shopping/potions) backed by a new mock infrastructure (`packages/sdk/test/native-stub.ts` + `mock-game.ts`).

Test plan

  • `pnpm test` — 61/61 SDK + 17/17 scripts unit tests pass
  • `pnpm test:e2e` — 29/29 in-game tests pass against a live wine/D2 1.14d session
  • `zig build -Doptimize=ReleaseSmall` clean for the native DLL

E2E:
- Test runner uses the full Game proxy (items/npcs/move/sendPacket); previously
  ran with a hand-built minimal game stub that couldn't drive shopping flows.
- Runner has its own __onOogTick that drives splash → SP → char select with
  oogSelectChar("EpicSorc"), so e2e is fully autonomous.
- pnpm test:e2e: spawns daemon --tests + run.sh, scrapes aether_log.txt for
  the runner's "Results: X passed" line, exits with status.
- New scripts/tests/shopping.test.ts: 7 in-game tests covering shouldKeep,
  trader visibility, real openTrade (interact + walk + menu) and short-circuit.

NPC walking (Game.moveTo + unit.ts moveToward):
- A single move click is clipped to the viewport, so the player only walked a
  few tiles before stopping. Now we get a path via findPath and walk node by
  node with the kolbot pattern: one click → wait for walk to start → wait for
  walk to finish → re-click if not close enough. Always closes in on the
  actual target.
- NPC.interact() walks before sending the interact packet. Fixes openTrade,
  heal and repair when the NPC is more than ~10 tiles away.

charname binding:
- jsUnitGetName now reads pUnitData->szName for player units (UNIT_PLAYER,
  dwType=0) — D2CLIENT_GetUnitName doesn't return the char name for players.
  Mirrors the d2bs pattern. Monsters/items unchanged.

takeScreenshot:
- Optional name argument (".bmp" appended if missing). Each call overwrites
  the same name; multiple names = multiple files.
- Wired into hookOogDraw so screenshots work on splash, char select, etc.
- .d.ts return type corrected (void, not string).

Carry-over from earlier in the session (referenced for context):
- 8 files used game.player.maxHp (undefined) — replaced with hpmax. This was
  the root cause of PotionDrinker/heal/overlay never firing.
- itemGetLocation no longer flags Inventory items as Cube (removed grid==3
  false-positive — only the page field is authoritative).
- jsNpcMenuByMenuId binding + npcMenuByMenuId(MenuOption.Trade/TradeRepair)
  in NPC.openTrade/repair/openGamble. Replaces fragile menu-index lookup.
- shopping.ts openTradeUI uses game.waitUntil; npc.ts healAtNPC retries up to
  3 times and verifies hp >= hpmax before declaring success.

Test scaffolding:
- packages/sdk/test/native-stub.ts — all 125 native exports as stubs + a
  __mockNative control surface (setUIFlag, setUIFlagAfter, setMenuIdResult
  with side-effect callback, getSentPackets, getMenuIdCalls, getInteracts,
  getCloseCount, reset).
- packages/sdk/test/mock-game.ts — makeMockGame factory + runGenerator driver.
- 21 new fast unit tests across NPC/shopping/potions.

Verified: 61/61 SDK + 17/17 scripts unit tests pass; 29/29 in-game e2e tests
pass against a live wine/D2 1.14d session.
@jaenster jaenster merged commit 4f37859 into main May 7, 2026
1 check failed
@jaenster jaenster deleted the e2e-shopping-runner branch May 7, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant