9.0 KiB
9.0 KiB
HANDOFF.md — Session Handoff (OVERWRITE at the end of every phase or when context is getting long)
Read order for a new session:
NOTES.md→STATUS.md→ this file → then work. If this file disagrees with the code, trust the code and fix this file.
1. Where we are
- Last completed step: 10.5 (Add landing page, fix "Return to Emberfall" links, add link-checker test) — TICKED in STATUS.md
- Next step: Phase 10.6 — Restore REAL rate limiting (re-enable login/register limiters, mount global /api limiter before auth routes)
- Updated: 2026-10-22
- Was the last session cut off mid-task? No
2. Verified state (run these first)
| Command | Expected |
|---|---|
npm install |
succeeds |
npm run migrate |
applies 001–006 / "nothing to do" |
npm test |
193 passing, 0 failing (85 unit + 108 integration incl. 5 new 10.5 tests) |
npm run seed:dev |
creates demo user "demo"/"demo123", hero "Aldric" (warrior), starter gear |
npm start + curl localhost:3000/ |
200 HTML landing page |
npm start + curl localhost:3000/api/health |
{"ok":true} |
3. What exists now (files that matter)
public/index.html— Landing page (title, tagline, Login/Register buttons; "Play" button when logged in with hero). UsesGET /api/auth/meto detect auth state.public/leaderboard.html— Stub page (placeholder text; real UI in 10.17).public/404.html— Custom 404 error page. "Return to Emberfall" links to/.public/500.html— Custom 500 error page. "Return to Emberfall" links to/.src/app.js— Root route now servesindex.htmlinstead of redirecting to/login.html.tests/integration/link-checker.test.js— Reads allpublic/*.html, extracts localhref/srcvalues, asserts each target file exists. Skips API endpoints.tests/integration/step-10.5.test.js— 5 tests: GET / returns 200 HTML, Play button when logged in with hero, Login/Register when no hero, anonymous shows Login/Register, 404/500 have working links.public/game.html— Dashboard with 3-col grid (stats | action | combat), mobile bottom nav.public/js/game.js— hunt UI + inventory UI + expedition UI + mobile nav init.public/css/main.css— All styles including 3-col desktop grid, mobile bottom nav.public/shop.html/public/js/shop.js— Shop page (buy/sell).public/login.html,public/register.html,public/create-hero.html— Auth & hero creation.public/profile.html/public/js/profile.js— Public hero profile page.public/js/auth.js— Shared API wrapper + showError.public/js/login.js— Login form submits to/api/auth/login; on success usesdata.hasHeroto redirect.public/js/create-hero.js— Checks/api/auth/meon DOMContentLoaded, redirects to/game.htmlifhasHero.public/js/toast.js— Shared toast notification system.src/services/expeditionService.js— Fixed in 10.1 (energy tx params) + 10.2 (usesapplyXpGain) + 10.3 (injectableopts.now/opts.rng).src/services/huntService.js— Refactored in 10.2 to useapplyXpGain.src/game/leveling.js— AddedapplyXpGainshared function.src/utils/time.js—{ now, setNow, resetNow }.src/utils/rng.js—{ mulberry32, rngInt, rngFloat, rngRange }.src/routes/auth.js—handleRegisterandhandleLoginsetreq.session.username.
4. Half-finished / fragile things
- No leaderboard UI yet (stub page exists; real UI in 10.17).
- HP never regenerates naturally; only level-up restores it.
- No restart-persistence test for sessions.
npm run seedscript in package.json points to nonexistentscripts/seed.js.- Equipment bonuses not yet passed into combat (Issue #5 in STATUS.md).
- Starter gear documented but not auto-created on character creation.
GET /api/zonesdocumented in API.md but not implemented (Issue #2).- Mobile nav uses emoji icons (⚔️ 🏕️ 🎒) — verify they render acceptably on all platforms.
- 10.6 next: Need to re-enable real rate limiters in
src/routes/auth.js(currently no-ops), mount global/apilimiter BEFORE auth routes, add test for 429 response. - 10.17 next (after 10.6, 10.7, 10.8–10.13, 10.14–10.16): Real leaderboard UI; remove stub; update link-checker exception.
5. Decisions & deviations from the docs
- D-004..D-007 in
docs/DECISIONS.md(combat rounds, equipment counted once, session store, clock). - D-014: Mobile bottom nav uses emoji icons (⚔️ Hunt / 🏕️ Trip / 🎒 Items) instead of full text labels.
- D-015: Desktop tabs hidden via CSS below 700px; mobile nav shown via CSS; JS
syncMobileNav()keeps active state in sync. - D-016:
applyXpGaininsrc/game/leveling.jsis the single shared function for XP gain logic, used by bothhuntServiceandexpeditionService. - D-017: Landing page
public/index.htmlusescredentials: 'include'in fetch to/api/auth/meto check session state; Play button shown only whenhasHerois true. - D-018: Link-checker test skips API endpoints (
/api/...) since they're not static files.
6. Gotchas learned
npm testmust benode --testwith NO path/glob; files must be named*.test.js.- better-sqlite3-session-store ignores
expired.clear: false; that's why the timer is unref'd. - Statement caches are per-DB-handle (WeakMap) in huntService; copy that pattern for new services.
- Verify test COUNT, not just "all passing".
- Node.js
fetchdoesn't persist cookies across calls — extractSet-Cookieheader and pass manually in integration tests. - SQL
SELECT idfrom inventory returns the auto-increment row id; rename withAS inventory_idwhen you also needitem_id. - Transaction callback args must match the call order exactly. (This is the 10.1 bug — double-check param/call order in every new transaction.)
- Error responses from route-level
AppErrors do NOT includedatafield. setNowaffects ALLnow()calls including those in service logic.- Shop API returns
{ ok: true, data: { stock: [...], character: {...} } }— field isstock, notstocks. - Shop stock items have flat fields (
itemId,buyPrice), not nested (item.id). - New characters have NO inventory items (starter gear not auto-created yet).
- Hero profile endpoint is PUBLIC — no
requireAuthmiddleware. - Profile page is public: no auth.js guard needed; uses ?name= query param for lookup.
- Rate limiters in tests: set
NODE_ENV=testto get 1000 req/window limit; otherwise tests fail with 429. seed-dev.jsmust checkNODE_ENV=productionbefore anyrequire()that loads config (config throws on placeholder SECRET).- Express
sendFilerejects../path segments — usepath.resolve()+path.join()for absolute paths. express.staticsends its own 404 responses; catch-all must be placed BEFORE static middleware.- Character profile GET returns
{ ok: true, data: { character, derived, energy } }— fields nested undercharacter,derived,energy. - Register returns 201 (Created), not 200.
- Character creation returns 201 (Created), not 200.
- Expedition start uses
defIdin request body (notexpeditionId). - Expedition claim uses
expeditionIdin request body. - Expedition start response returns
data.expedition.id— capture this for claim. src/utils/timeexports{ now, setNow, resetNow }directly —const time = require(...), notconst { time }.- Inventory sell endpoint (
POST /api/shop/sell) only acceptsmaterial-type items. handleListInventoryinsrc/routes/inventory.js— parameter name must beres, not_res.- Character profile response has
energyatdata.energy.current, NOTdata.character.energy. - 10.3:
expeditionService.jsimport changed fromconst { now, setNow } = require('../utils/time')toconst time = require('../utils/time')— the destructurednowvariable was shadowed by the localopts.now ?? time.now()pattern. - 10.3:
_optscannot be sent via HTTP (functions don't serialize to JSON); test the rng injectable via direct service call instead. - 10.4:
req.session.usernamemust be set in bothhandleRegisterandhandleLogin— register was the gap./mereads it, so without it username is always empty string. - 10.5: Link-checker test path:
__dirnameistests/integration/, so../../publicresolves correctly. API endpoints (/api/...) must be excluded from link-checking since they're not static files.
7. Next-step briefing
- Next step: 10.6 — Restore REAL rate limiting:
- In
src/routes/auth.js, the login and register limiters are no-ops (real ones commented out). Re-enable them. - Login: 10 requests / 15 min / IP. Register: 5 requests / hour / IP.
- Use standard error envelope:
{ ok: false, error: { code: 'RATE_LIMITED', message: '...' } }, status 429. - Mount global
/apilimiter BEFORE auth routes insrc/app.js(currently after, so it doesn't cover auth). - Limits may be relaxed when
NODE_ENV=test(e.g., 1000 req/window). - Add a test: enable real limiter, send 10 bad logins → 401, 11th → 429 JSON.
- In