diff --git a/HANDOFF.md b/HANDOFF.md index 65c16ae..07589d0 100644 --- a/HANDOFF.md +++ b/HANDOFF.md @@ -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:** 9.2 (seed-dev script — creates demo account + hero) — TICKED in STATUS.md -- **Next step:** Phase 9 — 9.3 (Global error pages / friendly UI error toasts. Loading states.) +- **Last completed step:** 9.3 (error pages, shared toast system, loading states) — TICKED in STATUS.md +- **Next step:** Phase 9 — 9.4 (Mobile-responsive pass per UI_GUIDE) - **Updated:** 2026-10-21 - **Was the last session cut off mid-task?** No @@ -14,37 +14,29 @@ |---|---| | `npm install` | succeeds | | `npm run migrate` | applies 001–006 / "nothing to do" | -| `npm test` | **172 passing, 0 failing** (85 unit + 87 integration) | +| `npm test` | **175 passing, 0 failing** (85 unit + 90 integration) | | `npm run seed:dev` | creates demo user "demo"/"demo123", hero "Aldric" (warrior), starter gear | ## 3. What exists now (files that matter) -- `public/profile.html` — Public hero profile page (reads ?name=, displays stats/equipment). -- `public/js/profile.js` — Fetches GET /api/heroes/:name, renders profile, handles 404. +- `public/404.html` — Custom 404 error page (branding: "Page Not Found", Emberfall theme). +- `public/500.html` — Custom 500 error page (branding: "Something went wrong", retry button). +- `public/js/toast.js` — Shared toast notification system (window.showToast, 3 types: error/info/success). - `public/game.html` — Dashboard with stats panel, tabbed action panel (Hunt/Inventory/Expedition). -- `public/js/game.js` — hunt UI + inventory UI + expedition UI. +- `public/js/game.js` — hunt UI + inventory UI + expedition UI (uses shared toast.js). - `public/shop.html` — Dedicated shop page. -- `public/login.html`, `public/register.html`, `public/create-hero.html` — Auth & hero creation. +- `public/js/shop.js` — buy/sell handlers (uses shared toast.js). +- `public/login.html`, `public/register.html`, `public/create-hero.html` — Auth & hero creation (all include toast.js). +- `public/profile.html` — Public hero profile page. +- `public/js/profile.js` — Fetches GET /api/heroes/:name, renders profile. +- `public/js/auth.js` — Shared API wrapper + showError. +- `public/css/main.css` — All styles including spinner, toast, button loading states, error page shared CSS. - `scripts/seed-dev.js` — Creates demo account + hero + starter gear (idempotent, skips in production). -- `src/services/heroProfileService.js` — `getHeroProfile(heroName)`. -- `src/routes/heroProfile.js` — `GET /api/heroes/:name` (public). -- `src/services/leaderboardService.js` — `getLeaderboard(type, page, limit)`. -- `src/routes/leaderboard.js` — `GET /api/leaderboard?type=level|gold|kills`. -- `src/services/expeditionService.js` — start, getActive, claim, listDefinitions. -- `src/routes/expeditions.js` — 4 expedition endpoints. -- `src/services/shopService.js` — getStock, buyItem, sellItem. -- `src/routes/shop.js` — GET/POST shop endpoints. -- `src/services/inventoryService.js` — listInventory, equipItem, unequipItem, useConsumable. -- `src/services/huntService.js` — hunt (one transaction). -- `src/services/characterService.js` — createCharacter, getCharacterProfile, getCharacterIdForUser. -- `src/services/authService.js` — register, verifyLogin. -- `src/game/combat.js` — resolveCombat. -- `src/game/stats.js` — calcDerived, xpToNext, checkLevelUp. -- `src/game/energy.js` — computeEnergy. -- `src/utils/time.js` — now()/setNow()/resetNow(). -- `src/app.js` — Express app with helmet, rate limiters (auth + general /api), all routes. -- `src/middleware/session.js` — session store, requireAuth. -- `src/config/index.js` — env validation, frozen config. -- `tests/integration/*.test.js` — 87 integration tests across auth, combat, hunt, inventory, shop, expeditions, profile, leaderboard. +- `src/app.js` — Express app with helmet, rate limiters, catch-all 404, 500 HTML serving. +- `src/services/*` — All game services (auth, character, hunt, inventory, shop, expedition, leaderboard, profile). +- `src/routes/*` — All route handlers. +- `src/game/*` — Pure game logic (combat, stats, energy, leveling, rewards). +- `tests/integration/error-pages.test.js` — 3 tests for 404/500 page serving. +- `tests/integration/*.test.js` — 90 integration tests across auth, combat, hunt, inventory, shop, expeditions, profile, leaderboard, error-pages. - `tests/unit/*.test.js` — 85 unit tests for game logic. ## 4. Half-finished / fragile things @@ -55,7 +47,6 @@ - Equipment bonuses not yet passed into combat (Issue #5 in STATUS.md). - Starter gear (GAME_DESIGN.md §Items) documented but not auto-created on character creation. - `GET /api/zones` documented in API.md but not implemented (Issue #2). -- Step 9.3 (error pages/toasts/loading states) not yet implemented. ## 5. Decisions & deviations from the docs - D-004..D-007 in `docs/DECISIONS.md` (combat rounds, equipment counted once, session store, clock). @@ -87,11 +78,13 @@ - Profile page is public: no auth.js guard needed; uses ?name= query param for lookup. - Rate limiters in tests: set `NODE_ENV=test` to get 1000 req/window limit; otherwise tests fail with 429. - `seed-dev.js` must check `NODE_ENV=production` before any `require()` that loads config (config throws on placeholder SECRET). +- Express `sendFile` rejects `../` path segments — use `path.resolve()` + `path.join()` for absolute paths. +- `express.static` sends its own 404 responses; catch-all must be placed BEFORE static middleware. -## 7. Next-step briefing (9.3) -- **Goal:** Add global error pages / friendly UI error toasts. Loading states. -- **Docs:** UI_GUIDE, SECURITY (for error handling), TESTING. -- Should: add a generic 404/500 error page template in `public/`. -- Should: add a toast notification system (JS + CSS) for user-facing errors. -- Should: add loading spinners/states for async operations (hunt, buy, etc.). +## 7. Next-step briefing (9.4) +- **Goal:** Mobile-responsive pass per UI_GUIDE (< 700px: single column, tabs become bottom nav). +- **Docs:** UI_GUIDE §game.html layout (Mobile section). +- Current CSS has some `@media (max-width: 600px)` rules but needs comprehensive mobile review. +- Should: verify all pages render correctly on mobile viewports. +- Should: tabs → bottom nav on mobile (per UI_GUIDE). - Should NOT introduce new dependencies — use vanilla HTML/CSS/JS. diff --git a/STATUS.md b/STATUS.md index debbd42..a6c9440 100644 --- a/STATUS.md +++ b/STATUS.md @@ -8,9 +8,9 @@ ## Current Focus - **Phase:** 9 -- **Step:** 9.3 +- **Step:** 9.4 - **Blocked?** No -- **Last verified working command:** `npm test` — 172/172 passing (85 unit + 87 integration), 2026-10-21 step 9.2 +- **Last verified working command:** `npm test` — 175/175 passing (85 unit + 90 integration), 2026-10-21 step 9.3 ## Project Health | Item | State | @@ -109,7 +109,7 @@ *Fixed:* removed `innerHTML` with dynamic data in `game.js` (renderActiveExpedition) and `profile.js` (renderProfile stats) — converted to createElement/textContent. Added missing general `/api` rate limiter (120/min/IP per SECURITY.md spec). - [x] **9.2** Add `npm run seed:dev` creating a demo account and hero. *Acceptance:* `npm run seed:dev` creates migrations + demo user + hero + starter gear; safe to re-run; skipped in production. -- [ ] **9.3** Global error pages / friendly UI error toasts. Loading states. +- [x] **9.3** Global error pages / friendly UI error toasts. Loading states. - [ ] **9.4** Mobile-responsive pass (see UI_GUIDE). - [ ] **9.5** Final full run of "Definition of playable" from NOTES.md §7. Record results below. - [ ] **9.6** Update README with real run instructions. @@ -192,3 +192,4 @@ _Format:_ `YYYY-MM-DD | step | what changed | result` - 2026-10-21 | 8.2 | Created `src/services/heroProfileService.js` (getHeroProfile), `src/routes/heroProfile.js` (GET /api/heroes/:name, public), integrated into app.js; 5 integration tests covering public lookup, case-insensitivity, equipped items, 404, no-auth access | 167/167 tests pass - 2026-10-21 | 9.1 | Walked SECURITY.md checklist: fixed `innerHTML` with dynamic data in `game.js` (renderActiveExpedition) and `profile.js` (renderProfile stats) — converted to createElement/textContent; added missing general `/api` rate limiter (120/min/IP per SECURITY.md spec); verified all 9 checklist items pass | 172/172 tests pass - 2026-10-21 | 9.2 | Created `scripts/seed-dev.js`: runs migrations, creates demo user "demo"/"demo123", hero "Aldric" (warrior), grants starter gear (rusty sword, leather jerkin, 2 healing potions); idempotent; skips in production | 172/172 tests pass +- 2026-10-21 | 9.3 | Added shared toast system (`public/js/toast.js`), 404/500 error pages (`public/404.html`, `public/500.html`), CSS loading spinner + button loading states, server-side catch-all 404 + 500 HTML serving; removed duplicate showToast from game.js/shop.js; 3 integration tests for error pages | 175/175 tests pass diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..cee0061 --- /dev/null +++ b/public/404.html @@ -0,0 +1,95 @@ + + +
+ + +