Fix save/replay integrity: composite endTurn move, logged auto-passes, always persist

- toSave always returns the state again: the platform keeps no memory between
  requests, so unsaved intermediate moves were discarded outright (auctions
  wedged, purchases lost, bots stuck, drops and settings silently dropped).
- Time farming is prevented structurally instead: buyFactory/buyPopulation/
  buyRobots become TurnBuy steps inside a single composite endTurn move,
  validated atomically via a dry run on a clone. Auction moves stay individual.
- Auto-passed bidders are recorded in the move's info.autoPassed and replayed
  verbatim; the true-value autoPassBids pass cannot be recomputed from a
  stripped log (this desynced replay before).
- Viewer stages purchases locally (draft state, undo) and sends them with
  endTurn; auctions are blocked while buys are staged.
- Harden settings access for pre-0.2 saved states; document the BGS admin-API
  deployment flow in AGENTS.md. Engine 0.4.0 (deployed to prod, hot-swapped).
This commit is contained in:
coyotte508 2026-08-24 13:45:37 +00:00
commit 1dcc7d93a0

View file

@ -91,3 +91,51 @@ pnpm check # fmt:check + lint + tsc + test + build
Run `pnpm check` before committing. Commit with clear messages; do not create PRs
(this repo has no remote).
## Deploying to BGS (prod)
Publishing goes through the BGS admin API with an admin token (`bgs_admin_...`,
sent as `Authorization: Bearer <token>`; only valid under `/api/admin/*` and the
token needs the `gameinfo` grant). Base URL: `https://admin.boardgamers.space/api`.
Never commit a token; take it from the environment (`$BGS_ADMIN_TOKEN`).
Outpost is registered as game `outpost`, version doc `1`, engine entryPoint
`dist/wrapper.js`. Ongoing games are pinned to the _game version integer_ but
hot-swap the _engine package_ on that doc, so re-uploading the engine upgrades
the running games within ~60 s (the game-server install cron). Upgrade the
engine and viewer together — the move format couples them.
```bash
AUTH="Authorization: Bearer $BGS_ADMIN_TOKEN"
BASE=https://admin.boardgamers.space/api/admin/gameinfo/outpost
# 0. Bump packages/engine/package.json version, then:
pnpm check && (cd packages/engine && pnpm pack)
# 1. Engine: raw npm-pack tgz body. Reads name/version from the tarball,
# stores it on S3 and $sets engine.package (incl. url) on the doc itself.
curl -X POST "$BASE/1/engine" -H "$AUTH" \
-H "Content-Type: application/octet-stream" \
--data-binary @packages/engine/outpost-engine-<version>.tgz
# 2. Viewer files: each upload returns { url } (content-hashed, S3).
curl -X POST "$BASE/1/viewer/file?filename=outpost-viewer.iife.js" -H "$AUTH" \
-H "Content-Type: application/octet-stream" \
--data-binary @packages/viewer/dist/outpost-viewer.iife.js
curl -X POST "$BASE/1/viewer/file?filename=outpost-viewer.css" -H "$AUTH" \
-H "Content-Type: application/octet-stream" \
--data-binary @packages/viewer/dist/outpost-viewer.css
# 3. Persist the new viewer URLs: GET the doc, set viewer.url (and
# viewer.dependencies.stylesheets if the css hash changed), drop
# _id/createdAt/updatedAt/meta, PUT it back.
curl "$BASE/1" -H "$AUTH" # read
curl -X PUT "$BASE/1" -H "$AUTH" -H "Content-Type: application/json" \
--data-binary @gameinfo.json # write
# 4. Verify: engine.package.version and viewer.url on the doc.
curl "$BASE/1" -H "$AUTH"
```
Step 1 alone is enough for an engine-only fix (no PUT needed). A brand-new game
version integer (`$BASE/2`) instead leaves ongoing games on the old code forever.