fix(puzzles): merge anon progress, rehydrate completion, recover orphaned draft (#1650) - #1663
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thexsuaa-gated save endpoints, so on login the server grid (missing them) overwrote everything.Fix: replace
shouldMigratewithmergeProgress(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
solvedwas 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.getProgressnow returns acompletedflag derived from the non-supersededPUZZLETaskRecord(srv/puzzle-service.{cds,js}); the solver re-hydratessolvedand 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_EXISTSAn 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_EXISTS409s (e.g. locked by another user) still surface as errors.Tests
hugo-apps/src/puzzle/__tests__/progress.test.ts—mergeProgress(migrate, preserve local-only, server-wins-conflict, no-op, corrupt JSON).test/unit/puzzle-service-complete.test.js—getProgressreportscompletedtrue/false.test/unit/puzzle-draft-save.test.js(new) — 409 recovery, happy update/create paths, non-409 + non-DRAFT_ALREADY_EXISTSre-throw.node_modulesimport gaps (graphologyinapp/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 throughbuild:island-manifest. This PR is code only.