step 10.2: done
This commit is contained in:
@@ -7,16 +7,16 @@
|
||||
> - Keep Session Log entries to one or two lines.
|
||||
|
||||
## Current Focus
|
||||
- **Phase:** 10.1
|
||||
- **Step:** 10.2 — Fix expedition CLAIM overwriting XP
|
||||
- **Phase:** 10.2
|
||||
- **Step:** 10.3 — Make expeditions testable (inject time/rng)
|
||||
- **Blocked?** No
|
||||
- **Last verified working command:** `npm test` — 178/178 passing (85 unit + 93 integration incl. 2 new 10.1 tests), 2026-10-22 step 10.1
|
||||
- **Last verified working command:** `npm test` — 182/182 passing (85 unit + 97 integration incl. 4 new 10.2 tests), 2026-10-22 step 10.2
|
||||
|
||||
## Project Health
|
||||
| Item | State |
|
||||
|---|---|
|
||||
| App starts (`npm start`) | ✅ smoke-tested: register → create hero → 12 hunts → level-up (real seeded zones) |
|
||||
| Tests pass (`npm test`) | ✅ 178/178 (85 unit + 93 integration incl. 2 new 10.1 tests) |
|
||||
| Tests pass (`npm test`) | ✅ 182/182 (85 unit + 97 integration incl. 4 new 10.2 tests) |
|
||||
| Migrations run clean on empty DB | ✅ 001_users, 002_characters, 003_content (also seeds zones/monsters/items), 004_inventory, 006_logs (005 reserved for expeditions) |
|
||||
| Can register + login | ✅ verified by tests |
|
||||
| Data persists across restart | ⚠️ sessions use the real SQLite store (also in tests); a restart test is still missing |
|
||||
@@ -141,8 +141,9 @@
|
||||
- [x] **10.1** Fix expedition START corrupting energy. In `startExpedition` (`src/services/expeditionService.js`) the transaction function's parameters are in a different order than the call, so the DB gets `energy = def.energy_cost` and `energy_updated_at = endsAt`. Fix so the DB stores `energy - cost` and the timestamp returned by `computeEnergy`.
|
||||
*Acceptance:* test: hero energy 100, start the 10-energy expedition → DB `energy` is 90 and `energy_updated_at` is NOT in the future; `GET /api/character` shows 90; response energy equals DB energy. Test also starting at energy 55 → 45.
|
||||
*Verified:* 2 new integration tests (DB-level assertions) + 14 existing expedition tests pass; transaction params `(cid, ne, eat, defid, sat, endAt)` now match call `(characterId, newEnergy, updatedAtMs, defId, startedAt, endsAt)`.
|
||||
- [ ] **10.2** Fix expedition CLAIM overwriting XP. Claim must ADD the reward to current XP, run `checkLevelUp`, ADD (not overwrite) unspent points, and heal to the new max HP on level-up. Extract ONE shared function (e.g. `applyXpGain` in `src/game/leveling.js` or a small progression service) and use it from BOTH `huntService` and `expeditionService`.
|
||||
- [x] **10.2** Fix expedition CLAIM overwriting XP. Claim must ADD the reward to current XP, run `checkLevelUp`, ADD (not overwrite) unspent points, and heal to the new max HP on level-up. Extract ONE shared function (e.g. `applyXpGain` in `src/game/leveling.js` or a small progression service) and use it from BOTH `huntService` and `expeditionService`.
|
||||
*Acceptance:* tests: xp 80 + reward 30 at level 1 → level 2, xp 10, unspent_points +3; xp 0 + 30 → xp 30, level 1; a reward spanning two levels → both levels gained, points +6; double claim still rejected; gold added correctly. Existing hunt tests still pass.
|
||||
*Verified:* 4 new integration tests (XP add vs overwrite, level-up on claim with XP remainder + stat points + HP heal, two-level span with +6 points, double-claim rejection, gold add); shared `applyXpGain` in `leveling.js` used by both huntService and expeditionService; huntService refactored to use `applyXpGain` instead of inline `checkLevelUp`; 182/182 tests pass.
|
||||
- [ ] **10.3** Make expeditions testable: use `time.now()` and an injectable `rng` (no `Date.now()` / `Math.random()` in `expeditionService.js`).
|
||||
*Acceptance:* test with a fixed rng asserts the exact gold reward; a test using `time.setNow` proves claim is rejected before `ends_at` and accepted after.
|
||||
### B. Accounts & navigation
|
||||
|
||||
Reference in New Issue
Block a user