Commit 53f36b5
committed
feat: time-aware Valhalla routing, /match endpoint, OSRM traffic stub
- Always send Valhalla `date_time` on `/route` and `/optimized_route` (default `{type:0}` "now") so the engine honours time-conditional OSM access tags (school zones, restricted hours, ferry schedules) and is wired for predicted-speed lookups once historical-traffic tiles land. Expose `departAt` / `arriveBy` (ISO-8601 wall-clock) on `/directions`, `/directions/optimize`, `useDirections`, and `useOptimizeRoute`. The provider models `date_time` as a discriminated union so a future caller can't construct `{type:1}` without `value`, and throws if both fields are pinned.
- Add a `supportsTimeAware` flag on `RoutingProvider` (Valhalla `true`, OSRM unset) and a `requireTimeAware` filter on `getRoutingProviders` / `getOptimizeProvider`. When the caller pins a wall-clock, the orchestrator drops time-agnostic providers from the chain and the route handler returns 503 ("No time-aware routing provider available…") instead of silently falling back to OSRM and ignoring the time. The cross-mode optimize fallback is suppressed under `requireTimeAware` for the same reason.
- Cache TTL now varies on time-presence: 1h for explicit `departAt`/`arriveBy` requests (deterministic), 5min for implicit "now" (so cached answers don't drift once Valhalla starts honouring time bands). The `Cache-Control` response header tracks the same window.
- Add `POST /api/integrations/routing/match` backed by Valhalla `trace_attributes` (Meili HMM matcher) — snaps a recorded GPS trace to the road graph and returns per-edge OSM way ids, surface, speed, names, plus per-point match info. Trace cap of 10 000 points (~1 Hz × 2.7 h drive); ISO timestamps on input points are converted to unix-epoch seconds for the engine. `MatchResult` / `MatchEdge` / `MatchPoint` types and an optional `getMatch?` method on `RoutingProvider` live in `integrations/routing/types.ts`. `distanceAlongEdgeRatio` is intentionally passed through as Valhalla's 0–1 ratio (consumers multiply by `edges[edgeIndex].length` for metres) — earlier draft mistakenly converted as if it were km.
- OSRM build pipeline now creates an empty `data/osrm-graph/segment-speeds.csv` and threads `--segment-speed-file` into `osrm-customize`, so swapping in a populated CSV becomes a config change rather than a pipeline rewrite. The CSV's content hash is folded into the build cache key (rebuild triggered when traffic data changes even if the PBF is identical). `clearPreviousOsrmGraph` is annotated to flag that the CSV is intentionally preserved across rebuilds. Runtime side (`osrm-routed --algorithm mld`) was already MLD; this completes the wiring for Tier 3 #8 live-traffic work.
- Pull validators into `integrations/routing/validation.ts`: `parseTravelMode` (case-insensitive, returns 400 on `mode=banana` instead of 503) and `parseDateTime` (regex prefix + numeric range + `Date.UTC` round-trip so Feb 31 / Apr 31 are rejected and Feb 29 only validates in leap years). Both used consistently by `/directions`, `/directions/optimize`, and `/match`. Add `routingMatch` entry to `packages/core/src/api/endpoints.ts` so future hooks don't hardcode the path.
- Tests: 7 new Valhalla `date_time` tests across `getRoute` + `optimizeRoute`, 10 new `getMatch` tests (request shape, edge km→m, matched-point ratio pass-through, ISO→epoch), 4 new orchestrator tests for the `requireTimeAware` filter (including the no-cross-mode-fallback guard), 13 new validator tests covering leap years and calendar-impossible dates, 2 new `osrm-graph` tests (segment-speed flag threading + CSV-triggered rebuild). 1444/1444 vitest pass; `pnpm turbo run check-types` clean across all 8 targets; `pnpm exec biome check` clean on every touched file.1 parent 22f6498 commit 53f36b5
13 files changed
Lines changed: 1143 additions & 39 deletions
File tree
- apps/api/src/services/__tests__
- integrations
- routing-valhalla
- routing
- __tests__
- packages
- cli
- __tests__
- src/lib
- core/src
- api
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
350 | 392 | | |
351 | 393 | | |
352 | 394 | | |
| |||
489 | 531 | | |
490 | 532 | | |
491 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
492 | 740 | | |
493 | 741 | | |
0 commit comments