Smart waypoint insertion + route-editor fixes #17

Merged
jmz merged 8 commits from feat/smart-insertion into main 2026-11-01 16:05:52 +00:00
Owner

Smart waypoint insertion (M1, #2) plus the route-editor fixes found while testing it. Base: main (upstream v0.21.2 + fork CI). Behaviour:

  • A plain click on the map appends the point, as upstream does.
  • The "Inserting at nearest point" toggle, or Alt/⌘ + click for a single point, inserts it at the anchor gap where it lengthens the route least (min-detour). A point beyond either end still extends that end.

Commits

  • 6c469f72 chooseInsertionIndex (min-detour index chooser), 8 vitest cases.
  • 1425ae49 Wires it into the map click. Fixes insertIntoRoute at index 0, which used to append instead of prepend.
  • eb369d2d Route-editor fixes:
    • clear the track on anchor removal;
    • correct undo anchor sync;
    • insertAnchorSplit, so a mid-route insert is a single undo step;
    • deleteFromRoute totals.
  • da68d6eb Undo/redo marker sync, and the first anchor is undoable.
  • 6ee8ceb6 Append by default; insert is opt-in (toggle + Alt/⌘-click).
  • f4576f12 Playwright e2e: web/tests/playwright/e2e/trail/route-insertion.spec.ts. Routing is mocked, so no Valhalla is needed.
  • 402280d6 Merge of current main (#37 importer clamp, #38 upstream-sync). No conflicts.
  • f9f8cbf9 Store unit tests: web/src/lib/stores/valhalla_store_insert.test.ts, 6 cases.
    • prepend at 0;
    • append;
    • split as one undo/redo step;
    • totals after a detour split;
    • anchor-only undo;
    • deleteFromRoute totals.

Verified 2026-10-31. All test runs were on the test VM spl-vm03 (NixOS, node 22, Chromium 155), not on the NAS.

  • npm ci, svelte-check: 0 errors, 0 warnings.
  • Full vitest: 52 files / 576 tests passed (11 skipped, as upstream).
  • Mutation check of the new store tests: reverting the index-0 fix and the deleteFromRoute totals fix fails 2 of the 6 cases, as intended.
  • Playwright e2e (route-insertion.spec.ts, 4 tests + auth setup): 5/5 passed. The stack was local: PocketBase built from db/, Meilisearch, and the adapter-node build of web/.
  • Mutation check of the e2e: with insert disabled and the undo marker removal dropped, 3 of the 4 tests fail. Only "append by default" still passes, as it should.
  • Fork CI does not run Playwright. CI on the previous head f4576f12 was green (runs 13683/13685); this push starts CI for f9f8cbf9.

Still for Jörg

  • Manual browser pass (steps in the PR comment).
  • Upstream #10/#13: drafts are in the job's wanderer-p2/upstream-drafts/. Split the feature from the fixes, target upstream dev, and change only en.json.

Tracking #2, #11, #12, #16. Closes nothing yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq

Smart waypoint insertion (M1, #2) plus the route-editor fixes found while testing it. Base: `main` (upstream v0.21.2 + fork CI). Behaviour: - A plain click on the map **appends** the point, as upstream does. - The **"Inserting at nearest point" toggle**, or **Alt/⌘ + click** for a single point, inserts it at the anchor gap where it lengthens the route least (min-detour). A point beyond either end still extends that end. **Commits** - `6c469f72` `chooseInsertionIndex` (min-detour index chooser), 8 vitest cases. - `1425ae49` Wires it into the map click. Fixes `insertIntoRoute` at index 0, which used to append instead of prepend. - `eb369d2d` Route-editor fixes: - clear the track on anchor removal; - correct undo anchor sync; - `insertAnchorSplit`, so a mid-route insert is a single undo step; - `deleteFromRoute` totals. - `da68d6eb` Undo/redo marker sync, and the first anchor is undoable. - `6ee8ceb6` Append by default; insert is opt-in (toggle + Alt/⌘-click). - `f4576f12` Playwright e2e: `web/tests/playwright/e2e/trail/route-insertion.spec.ts`. Routing is mocked, so no Valhalla is needed. - `402280d6` Merge of current `main` (#37 importer clamp, #38 upstream-sync). No conflicts. - `f9f8cbf9` Store unit tests: `web/src/lib/stores/valhalla_store_insert.test.ts`, 6 cases. - prepend at 0; - append; - split as one undo/redo step; - totals after a detour split; - anchor-only undo; - `deleteFromRoute` totals. **Verified 2026-10-31.** All test runs were on the test VM spl-vm03 (NixOS, node 22, Chromium 155), not on the NAS. - `npm ci`, `svelte-check`: 0 errors, 0 warnings. - Full vitest: 52 files / 576 tests passed (11 skipped, as upstream). - Mutation check of the new store tests: reverting the index-0 fix and the `deleteFromRoute` totals fix fails 2 of the 6 cases, as intended. - Playwright e2e (`route-insertion.spec.ts`, 4 tests + auth setup): **5/5 passed**. The stack was local: PocketBase built from `db/`, Meilisearch, and the adapter-node build of `web/`. - Mutation check of the e2e: with insert disabled and the undo marker removal dropped, 3 of the 4 tests fail. Only "append by default" still passes, as it should. - Fork CI does not run Playwright. CI on the previous head f4576f12 was green (runs 13683/13685); this push starts CI for f9f8cbf9. **Still for Jörg** - Manual browser pass (steps in the PR comment). - Upstream #10/#13: drafts are in the job's `wanderer-p2/upstream-drafts/`. Split the feature from the fixes, target upstream `dev`, and change only `en.json`. Tracking #2, #11, #12, #16. Closes nothing yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq
Adds chooseInsertionIndex(anchors, point): scores prepend / each interior
gap / append by route-length increase and returns the least-detour anchor
index, so a clicked point that belongs mid-route is inserted there instead
of always appended. Pure + unit-tested (8 vitest cases); reuses
haversineDistance. Wiring into the map click handler follows separately.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Wire chooseInsertionIndex into the route editor's map-click handler so a
clicked point is placed where it grows total route length the least: a
point that belongs mid-route is inserted between its neighbouring anchors
(re-routing both halves, mirroring the segment-drag path) instead of always
being appended. Points that extend the route still append; k=0 prepends.

Also fixes insertIntoRoute() to splice at index 0 — the `if (index)` guard
treated 0 as falsy and appended; prepend relies on splicing at 0. No
existing caller passes 0.

svelte-check clean (0 errors); route_insertion unit tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
fix(route-editor): clear track on anchor removal, correct undo, tidy totals
Some checks failed
Web CI / test (pull_request) Failing after 9s
5e20f77394
- removeAnchor: clear the track when <2 anchors remain (was leaving a
  dangling segment / stale route line); drop the gpx_data gate that skipped
  the map refresh while drawing; rebuild via setRoute when removing the end
  anchor so the last segment can't dangle.
- Tag anchorsBefore/anchorsAfter on add actions so undo/redo restores the
  anchor list instead of rebuilding from the emptied route (fixes: add two
  points then undo removes both).
- addAnchorSmart: mid-insert uses a single insertAnchorSplit change so undo
  reverts the whole insertion in one step; prepend routes new->start.
- deleteFromRoute: compute totals from the reduced snapshot, not the
  pre-delete route.

svelte-check clean; unit tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
jmz force-pushed feat/smart-insertion from 597185c4a7
Some checks failed
Web CI / test (pull_request) Failing after 2s
to 6ee8ceb695
Some checks failed
CI / go (push) Has been cancelled
CI / web (push) Has been cancelled
2026-10-30 23:34:19 +00:00
Compare
maximus changed target branch from main to main-v0.21.2 2026-10-30 23:34:46 +00:00
Member

Phase-1 catch-up review (upstream v0.21.2)

Rebased onto main-v0.21.2 (= main + merge of upstream v0.21.2 + CI toolchain bump), and the PR base is retargeted to it. The old head is kept as archive/feat-smart-insertion-pre-v0.21.2 (597185c4).

The branch now matches the opt-in design that is live on deploy:

  • 6c469f72 chooseInsertionIndex + 8 vitest cases
  • 1425ae49 click wiring
  • eb369d2d route-editor fixes: clear track on anchor removal, undo anchor sync, insertAnchorSplit, deleteFromRoute totals
  • da68d6eb undo/redo marker sync + undoable first anchor
  • 6ee8ceb6 append by default, opt-in insert (toggle + Alt/⌘-click), cherry-picked from deploy ab00270a

The only conflict was context: deploy's personal-pace state sat next to the insertMode declaration.

Why the last CI failed (597185c4, "Web CI / test"): not the code. Before 2026-10-06 the fork had no .forgejo/workflows, so Forgejo ran upstream's .github/workflows/web.yaml. Its actions/checkout@v6+/setup-node@v6 are runs.using: node24, which the old forgejo-runner v6.3.1 rejected within about 2 s ("must be one of [composite docker node12 node16 node20 go], got node24"). The #37 runs fail with the same log text. The job never reached npm ci. The rebased branch carries .forgejo/workflows/ci.yml (svelte-check + vitest), but it has not run yet: CI on the NAS runner was paused tonight, so the run was cancelled.

Code review (read, not executed):

  • chooseInsertionIndex is correct. The cost model is the added length; ties go to append; prepend is handled; n=0 and n=1 are special-cased.
  • insertIntoRoute index-0 fix (index !== undefined) is correct and needed for prepend.
  • Mid-route insert: two halves are routed in parallel and spliced in as one changeset, then tagLastRouteUndo attaches anchor snapshots, so one undo reverts the whole insert. Correct.
  • applyAnchorSnapshot reconciles markers on undo/redo. Correct.
  • Upstream v0.21.1 (#1370/#1377) now stores drawn routes as one joined trkseg with wanderer:anchor marks and splits it again on edit. The segments made by insertAnchorSplit carry no extensions, so they join and split cleanly.
  • Nit: ⌘ is the Windows key on Windows, and Alt-click is grabbed by some Linux WMs. The toggle covers both cases.

Verdict: needs work before upstreaming. Do not merge into the fork's main. The content is already on deploy, and main stays upstream + CI. Remaining for M1:

  1. CI green on this branch.
  2. An e2e (Playwright) test for the insert toggle and Alt-click.
  3. Split into two upstream PRs (the smart-insertion feature, and the independent route-editor fixes), with AI-assisted disclosure per #10/#13.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs

## Phase-1 catch-up review (upstream v0.21.2) **Rebased** onto `main-v0.21.2` (= `main` + merge of upstream v0.21.2 + CI toolchain bump), and the PR base is retargeted to it. The old head is kept as `archive/feat-smart-insertion-pre-v0.21.2` (597185c4). The branch now matches the **opt-in design** that is live on `deploy`: - `6c469f72` chooseInsertionIndex + 8 vitest cases - `1425ae49` click wiring - `eb369d2d` route-editor fixes: clear track on anchor removal, undo anchor sync, `insertAnchorSplit`, deleteFromRoute totals - `da68d6eb` undo/redo marker sync + undoable first anchor - `6ee8ceb6` **append by default, opt-in insert** (toggle + Alt/⌘-click), cherry-picked from deploy `ab00270a` The only conflict was context: deploy's personal-pace state sat next to the `insertMode` declaration. **Why the last CI failed (597185c4, "Web CI / test"):** not the code. Before 2026-10-06 the fork had no `.forgejo/workflows`, so Forgejo ran upstream's `.github/workflows/web.yaml`. Its `actions/checkout@v6+`/`setup-node@v6` are `runs.using: node24`, which the old forgejo-runner v6.3.1 rejected within about 2 s ("must be one of [composite docker node12 node16 node20 go], got node24"). The #37 runs fail with the same log text. The job never reached `npm ci`. The rebased branch carries `.forgejo/workflows/ci.yml` (svelte-check + vitest), but it has **not run yet**: CI on the NAS runner was paused tonight, so the run was cancelled. **Code review (read, not executed):** - `chooseInsertionIndex` is correct. The cost model is the added length; ties go to append; prepend is handled; n=0 and n=1 are special-cased. - `insertIntoRoute` index-0 fix (`index !== undefined`) is correct and needed for prepend. - Mid-route insert: two halves are routed in parallel and spliced in as one changeset, then `tagLastRouteUndo` attaches anchor snapshots, so one undo reverts the whole insert. Correct. - `applyAnchorSnapshot` reconciles markers on undo/redo. Correct. - Upstream v0.21.1 (#1370/#1377) now stores drawn routes as one joined `trkseg` with `wanderer:anchor` marks and splits it again on edit. The segments made by `insertAnchorSplit` carry no extensions, so they join and split cleanly. - Nit: ⌘ is the Windows key on Windows, and Alt-click is grabbed by some Linux WMs. The toggle covers both cases. **Verdict: needs work before upstreaming. Do not merge into the fork's `main`.** The content is already on `deploy`, and `main` stays upstream + CI. Remaining for M1: 1. CI green on this branch. 2. An e2e (Playwright) test for the insert toggle and Alt-click. 3. Split into two upstream PRs (the smart-insertion feature, and the independent route-editor fixes), with AI-assisted disclosure per #10/#13. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs
test(e2e): cover append-by-default and smart insertion in the route editor
All checks were successful
CI / go (push) Successful in 22m41s
CI / web (push) Successful in 1m52s
f4576f12a6
Drive the trail editor's route drawing in Chromium with routing,
elevation and reverse geocoding mocked in the browser (straight legs),
so it needs no Valhalla or Nominatim:

- a plain click appends to the end of the route;
- with the "insert at nearest" toggle on, a point beside the A-B leg is
  inserted between A and B, while a point beyond the end still appends;
- Alt-click inserts once and the next plain click appends again;
- undo/redo of the split insert, and down to the very first anchor,
  restores the anchor list, its order and the anchor markers on the map.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1AaXnEghenJ4BDxNryKvs
jmz changed target branch from main-v0.21.2 to main 2026-10-31 13:03:44 +00:00
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq
test(route-editor): cover prepend, split insert and undo in the valhalla store
All checks were successful
CI / web (push) Successful in 54s
CI / go (push) Successful in 12m2s
f9f8cbf9af
Unit tests for the store operations behind smart insertion: insertIntoRoute
at index 0 prepends (it used to append), insertAnchorSplit replaces one
segment by two halves in a single undo step and refreshes totals, an
anchor-only change is undoable without touching the route, and
deleteFromRoute recomputes totals from the shortened route.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq
Member

Manual browser test (for Jörg)

The same feature is live on wanderer.ziefle.org: deploy carries it on top of the routing port, where Shift+click means off-road. Run the steps there, or on a local build of this branch.

  1. Open New trail, then Draw a route. Under the button the toggle reads "Adding to end of route", with the hint "Hold Alt / ⌘ while clicking to insert once".
  2. Click A, then B about 2 km apart. Then click C beside the middle of the A–B line. Expected: order A, B, C (appended); the anchor list shows 3 entries.
  3. Press Undo once. Expected: C and its marker disappear, and the A–B track stays.
  4. Turn the toggle on ("Inserting at nearest point"). Click C beside the middle of A–B again. Expected: order A, C, B, with the route re-drawn A→C→B as two legs.
  5. Still in insert mode, click D well beyond B. Expected: D is appended (A, C, B, D).
  6. Turn the toggle off. Alt-click (Mac: ⌥ or ⌘) beside the C–B leg. Expected: inserted between C and B once. Then a plain click → appended.
  7. Undo the Alt-insert. Expected: one undo removes the point, its marker and both half-legs. Redo brings them back.
  8. Keep pressing Undo until the map is empty, the first anchor included. Undo greys out. Redo everything: same order, all markers back.
  9. Loop check: draw a loop that ends near the start, with the toggle off. The last click near A must append, not insert next to A. This misfire is the reason for the append-by-default design.
  10. Remove the last anchor through the anchor list. The dangling leg disappears and the totals update.
  11. Save the trail, reopen the editor, and click once more. The anchors come back from the saved GPX (wanderer:anchor marks) and insertion still works.

Things to watch:

  • On Linux desktops Alt+click may be grabbed by the window manager (window move). The toggle covers that.
  • On Windows, ⌘ is the Windows key.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq

## Manual browser test (for Jörg) The same feature is live on wanderer.ziefle.org: `deploy` carries it on top of the routing port, where Shift+click means off-road. Run the steps there, or on a local build of this branch. 1. Open **New trail**, then **Draw a route**. Under the button the toggle reads **"Adding to end of route"**, with the hint "Hold Alt / ⌘ while clicking to insert once". 2. Click A, then B about 2 km apart. Then click C beside the middle of the A–B line. **Expected:** order A, B, C (appended); the anchor list shows 3 entries. 3. Press **Undo** once. **Expected:** C and its marker disappear, and the A–B track stays. 4. Turn the toggle on ("Inserting at nearest point"). Click C beside the middle of A–B again. **Expected:** order A, C, B, with the route re-drawn A→C→B as two legs. 5. Still in insert mode, click D well beyond B. **Expected:** D is appended (A, C, B, D). 6. Turn the toggle off. **Alt-click** (Mac: ⌥ or ⌘) beside the C–B leg. **Expected:** inserted between C and B once. Then a plain click → appended. 7. Undo the Alt-insert. **Expected:** one undo removes the point, its marker and both half-legs. Redo brings them back. 8. Keep pressing Undo until the map is empty, the first anchor included. Undo greys out. Redo everything: same order, all markers back. 9. Loop check: draw a loop that ends near the start, with the toggle off. The last click near A must **append**, not insert next to A. This misfire is the reason for the append-by-default design. 10. Remove the last anchor through the anchor list. The dangling leg disappears and the totals update. 11. Save the trail, reopen the editor, and click once more. The anchors come back from the saved GPX (`wanderer:anchor` marks) and insertion still works. Things to watch: - On Linux desktops Alt+click may be grabbed by the window manager (window move). The toggle covers that. - On Windows, ⌘ is the Windows key. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq
jmz merged commit f9f8cbf9af into main 2026-11-01 16:05:52 +00:00
jmz deleted branch feat/smart-insertion 2026-11-01 16:05:52 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!17
No description provided.