step 10.4: done

This commit is contained in:
bepis
2026-10-22 22:55:24 +11:00
parent 441efb06bd
commit 81ad47c138
5 changed files with 187 additions and 16 deletions
+16 -12
View File
@@ -4,8 +4,8 @@
> If this file disagrees with the code, trust the code and fix this file.
## 1. Where we are
- **Last completed step:** 10.3 (Make expeditions testable — inject time/rng) — TICKED in STATUS.md
- **Next step:** Phase 10.4 — Fix `GET /api/auth/me` and `POST /api/auth/login` to return real username and hasHero
- **Last completed step:** 10.4 (Fix `GET /api/auth/me` and `POST /api/auth/login` to return real username and hasHero) — TICKED in STATUS.md
- **Next step:** Phase 10.5 — Add a landing page `public/index.html` (title, one-line tagline, Login/Register buttons; "Play" button if already logged in with a hero). Fix the "Return to Emberfall" links on the 404/500 pages. Add a link-checker test.
- **Updated:** 2026-10-22
- **Was the last session cut off mid-task?** No
@@ -14,7 +14,7 @@
|---|---|
| `npm install` | succeeds |
| `npm run migrate` | applies 001–006 / "nothing to do" |
| `npm test` | **184 passing, 0 failing** (85 unit + 99 integration incl. 2 new 10.3 tests) |
| `npm test` | **187 passing, 0 failing** (85 unit + 99 integration incl. 3 new 10.4 tests) |
| `npm run seed:dev` | creates demo user "demo"/"demo123", hero "Aldric" (warrior), starter gear |
| `npm start` + `curl localhost:3000/api/health` | `{"ok":true}` |
@@ -29,6 +29,8 @@
- `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 uses `data.hasHero` to redirect to `/game.html` or `/create-hero.html`.
- `public/js/create-hero.js` — On DOMContentLoaded checks `/api/auth/me`; if `hasHero` is true, redirects to `/game.html`. Otherwise shows hero creation form.
- `scripts/seed-dev.js` — Creates demo account + hero + starter gear.
- `src/app.js` — Express app with helmet, rate limiters, catch-all 404, 500 HTML serving.
- `src/services/expeditionService.js` — Fixed in 10.1 (energy tx params) + 10.2 (uses `applyXpGain`) + 10.3 (injectable `opts.now`/`opts.rng`).
@@ -37,8 +39,9 @@
- `src/routes/expeditions.js` — Route handler passes `req.body._opts` to `claimExpedition`.
- `src/utils/time.js` — `{ now, setNow, resetNow }` — `const time = require(...)`, not destructured.
- `src/utils/rng.js` — `{ mulberry32, rngInt, rngFloat, rngRange }` — Mulberry32 PRNG.
- `src/routes/auth.js` — `handleRegister` and `handleLogin` now set `req.session.username` in addition to `req.session.userId`. `handleMe` reads `req.session.username`.
- `tests/integration/expeditions.test.js` — 22 expedition tests (incl. 2 new 10.3 tests).
- `tests/integration/*.test.js` — 99 integration tests (incl. 1 e2e).
- `tests/integration/*.test.js` — 102 integration tests (incl. 3 new 10.4 tests).
- `tests/unit/*.test.js` — 85 unit tests.
- `README.md` — Updated with real run instructions, play-through steps, project structure, known issues.
@@ -51,7 +54,7 @@
- Starter gear documented but not auto-created on character creation.
- `GET /api/zones` documented in API.md but not implemented (Issue #2).
- Mobile nav uses emoji icons (⚔️ 🏕️ 🎒) — verify they render acceptably on all platforms.
- **10.4 next:** `GET /api/auth/me` and `POST /api/auth/login` need to return real `username` and correct `hasHero`. Frontend (`login.js`, `create-hero.js`) needs updating for navigation logic.
- **10.5 next:** Need a landing page at `public/index.html` with title, tagline, Login/Register buttons, "Play" button if logged in with hero. Fix "Return to Emberfall" links on 404/500 pages. Add link-checker test.
## 5. Decisions & deviations from the docs
- D-004..D-007 in `docs/DECISIONS.md` (combat rounds, equipment counted once, session store, clock).
@@ -94,12 +97,13 @@
- Character profile response has `energy` at `data.energy.current`, NOT `data.character.energy`.
- **10.3:** `expeditionService.js` import changed from `const { now, setNow } = require('../utils/time')` to `const time = require('../utils/time')` — the destructured `now` variable was shadowed by the local `opts.now ?? time.now()` pattern.
- **10.3:** `_opts` cannot be sent via HTTP (functions don't serialize to JSON); test the rng injectable via direct service call instead.
- **10.4:** `req.session.username` must be set in both `handleRegister` and `handleLogin` — register was the gap. `/me` reads it, so without it username is always empty string.
## 7. Next-step briefing
- **Next step: 10.4** — Fix `GET /api/auth/me` and `POST /api/auth/login`:
- Currently `/me` may return hardcoded/stale username and `hasHero` is always `false`
- Need to store username in session at login/register
- `hasHero` should check if a character row exists for the user
- Frontend: `public/js/login.js` — returning players with a hero go to `/game.html`; without → `/create-hero.html`
- Frontend: `public/js/create-hero.js` — redirect to `/game.html` if hero already exists
- Tests: `/me` before hero → `hasHero:false`, after creating → `hasHero:true`, `username` non-empty
- **Next step: 10.5** — Create `public/index.html` (landing page):
- Title + tagline + Login/Register buttons (when not logged in)
- "Play" button linking to `/game.html` (when logged in with a hero)
- Can use `GET /api/auth/me` to detect logged-in state
- Fix "Return to Emberfall" links on 404.html and 500.html (ensure they point to `/` or `/index.html`)
- Add a link-checker test: read all `public/*.html`, extract local `href`/`src` values, assert each target file exists
- Note: this will also catch `/leaderboard.html` until 10.17 is done — either create a stub page or allow that one known gap