Skip to content

fix(puzzles): merge anon progress, rehydrate completion, recover orphaned draft (#1650) - #1663

Merged
jung-thomas merged 1 commit into
mainfrom
fix/puzzle-1650
Aug 11, 2026
Merged

fix(puzzles): merge anon progress, rehydrate completion, recover orphaned draft (#1650)#1663
jung-thomas merged 1 commit into
mainfrom
fix/puzzle-1650

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Fixes the three puzzle bugs reported in #1650.

Bug 1 — anonymous answers dropped after signing in

resumeProgress (hugo-apps/src/puzzle/App.vue) did "server wins if the server grid is non-empty", silently discarding answers typed while logged out — those never reach the xsuaa-gated save endpoints, so on login the server grid (missing them) overwrote everything.

Fix: replace shouldMigrate with mergeProgress (lib/progress.ts): the server stays authoritative for cells it holds, but local-only answers (cells the server left blank) are preserved and persisted back.

Bug 2 — completion doesn't survive a page refresh

solved was only ever an in-memory ref; nothing re-read completion on load, so the solved banner + Reset button disappeared after refresh (re-clicking Check re-set it in memory — exactly the reported "Check again gives me credit + Reset").

Fix: PuzzleService.getProgress now returns a completed flag derived from the non-superseded PUZZLE TaskRecord (srv/puzzle-service.{cds,js}); the solver re-hydrates solved and paints the grid green on load (markSolvedFromServer). No answer key is shipped to the client.

Bug 3 — admin save fails with draftEdit HTTP 409: DRAFT_ALREADY_EXISTS

An orphaned edit draft left by a prior session made every subsequent save fail; the controller treated the 409 as fatal.

Fix: extract the draft save orchestration into app/admin/puzzles/webapp/lib/draft-save.js (unit-tested) and recover from that specific 409 by resuming the existing draft (a CAP edit draft shares the active entity's key) — PATCH it with the fresh fields and activate. Non-DRAFT_ALREADY_EXISTS 409s (e.g. locked by another user) still surface as errors.

Tests

  • hugo-apps/src/puzzle/__tests__/progress.test.tsmergeProgress (migrate, preserve local-only, server-wins-conflict, no-op, corrupt JSON).
  • test/unit/puzzle-service-complete.test.jsgetProgress reports completed true/false.
  • test/unit/puzzle-draft-save.test.js (new) — 409 recovery, happy update/create paths, non-409 + non-DRAFT_ALREADY_EXISTS re-throw.
  • Full unit project: 0 test failures (7805 passed). The 14 failed files are pre-existing worktree node_modules import gaps (graphology in app/explore), unrelated to this change.

Not deployed

Frontend + admin-UI changes here — per project rules the island bundle + admin bundle need a full npm run deploy (no --skip-build/-m), and the puzzle island fingerprint goes through build:island-manifest. This PR is code only.

…aned draft (#1650)

Three bugs reported on the Devtoberfest crossword:

1. Anonymous progress dropped on login. resumeProgress did "server wins if
   non-empty", discarding answers typed while logged out (they never reach the
   auth-gated save endpoints). Replace shouldMigrate with mergeProgress, which
   keeps the server authoritative for cells it holds but preserves local-only
   answers, then persists the merged grid.

2. Completion not surviving a refresh. `solved` was never re-read on load, so
   the completed banner + Reset button vanished after reload (re-clicking Check
   re-set it in memory). getProgress now returns a `completed` flag (from the
   non-superseded PUZZLE TaskRecord) and the solver re-hydrates solved state +
   paints the grid green on load.

3. Admin save failed with "draftEdit HTTP 409: DRAFT_ALREADY_EXISTS" when an
   orphaned edit draft lingered from a prior session. Extract the draft save
   flow into lib/draft-save.js (unit-tested) and recover from that specific 409
   by resuming the existing draft (it shares the active entity's key).

Tests: mergeProgress + getProgress(completed) + draft-save 409 recovery; full
unit project green (0 test failures).
@jung-thomas
jung-thomas marked this pull request as ready for review August 11, 2026 18:39
@jung-thomas
jung-thomas merged commit 3778ffb into main Aug 11, 2026
6 checks passed
@jung-thomas
jung-thomas deleted the fix/puzzle-1650 branch August 11, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant