Shared trip: one itinerary per server (data/trip.json, GET/PUT /api/trip, routed server-side), the route panel edits it when logged in and polls other screens' changes in without moving the camera; the GNSS simulation skips trips under 1 km and starts elsewhere when it can't get on from a road island; the car's server updates itself from a topbar button (SELF_UPDATE=1: newer main with CI passed → bin/update-maptool.sh via maptool-update.path); Android Auto and the trip's next steps in TODO
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-30 19:19:37 +01:00
1 parent 5f4c7c6ee8
commit 17891c53b5
16 files changed
+513 -5

No files matched your search

+10 -1
View File
@@ -30,7 +30,7 @@ class GnssSimTest < Minitest::Test
(@tried ||= []) << position
raise Maptool::Routing::RouteError, "no road" if @tried.size == 1
{ geometry: { coordinates: [position, position] }, properties: {} }
{ geometry: { coordinates: [position, position] }, properties: { distance_km: 5 } }
end
end
@@ -41,4 +41,13 @@ class GnssSimTest < Minitest::Test
assert position[0].between?(17.0, 18.0) && position[1].between?(48.0, 49.0)
assert_equal position, route[:geometry][:coordinates].first
end
def test_a_route_under_a_km_is_another_try_and_none_at_all_an_error
lengths = [0.0, 0.2, 3.0]
router = ->(*) { { geometry: { coordinates: [[1, 2], [1, 3]] }, properties: { distance_km: lengths.shift } } }
sim = Maptool::GnssSim.new("http://valhalla", router: router)
assert_equal 3.0, sim.random_route([1, 2])[:properties][:distance_km]
lengths = [0.0] * 5
assert_raises(Maptool::Routing::RouteError) { sim.random_route([1, 2]) }
end
end
+38
View File
@@ -0,0 +1,38 @@
require_relative "test_helper"
require "tmpdir"
require_relative "../lib/maptool/trip"
class TripTest < Minitest::Test
def test_an_update_routes_bumps_the_version_and_survives_a_restart
Dir.mktmpdir do |dir|
path = File.join(dir, "trip.json")
store = Maptool::TripStore.new(path)
assert_equal 0, store.get[:version]
points = [{ lngLat: [17.1, 48.1], name: "Home" }, { lngLat: [17.2, 48.2] }]
calls = []
router = ->(locations, vehicle, avoid) { calls << [locations, vehicle, avoid]; { type: "Feature", km: 1 } }
trip = store.update(points: points, vehicle: "camper", avoid: { tolls: true }, editing: nil, &router)
assert_equal [1, { type: "Feature", km: 1 }], trip.values_at(:version, :route)
assert_equal [[[[17.1, 48.1], [17.2, 48.2]], "camper", { tolls: true }]], calls
# only a name/nav changed: no routing, the route stays
points[1] = { lngLat: [17.2, 48.2], name: "Camp", nav: true }
trip = store.update(points: points, vehicle: "camper", avoid: { tolls: true }, editing: nil, &router)
assert_equal [2, 1, "Camp"], [trip[:version], calls.size, trip[:points][1][:name]]
reloaded = Maptool::TripStore.new(path).get
assert_equal [2, { type: "Feature", km: 1 }, "Camp"], [reloaded[:version], reloaded[:route], reloaded[:points][1][:name]]
end
end
def test_a_routing_error_is_kept_with_the_points_and_tried_again_next_time
Dir.mktmpdir do |dir|
store = Maptool::TripStore.new(File.join(dir, "trip.json"))
points = [{ lngLat: [1, 2] }, { lngLat: [3, 4] }]
trip = store.update(points: points, vehicle: nil, avoid: {}, editing: nil) { raise Maptool::Routing::RouteError, "no route" }
assert_equal [nil, "no route", 2], [trip[:route], trip[:error], trip[:points].size]
trip = store.update(points: points, vehicle: nil, avoid: {}, editing: nil) { :routed }
assert_equal [:routed, nil], trip.values_at(:route, :error)
end
end
end
+34
View File
@@ -0,0 +1,34 @@
require_relative "test_helper"
require "tmpdir"
require_relative "../lib/maptool/updater"
class UpdaterTest < Minitest::Test
def setup
Maptool::Updater.reset!
end
def test_latest_is_mains_commit_and_its_ci_state_cached_until_checked_again
calls = []
fetch = lambda do |url|
calls << url
url.end_with?("/branches/main") ? { "commit" => { "id" => "a" * 40 } } : { "state" => "success" }
end
assert_equal({ sha: "a" * 40, ci: "success" }, Maptool::Updater.latest("https://git", "r/m", fetch: fetch))
assert_equal ["https://git/api/v1/repos/r/m/branches/main", "https://git/api/v1/repos/r/m/commits/#{'a' * 40}/status"], calls
Maptool::Updater.latest("https://git", "r/m", fetch: fetch)
assert_equal 2, calls.size # cached
end
def test_gitea_out_of_reach_is_no_answer_not_an_error
assert_nil Maptool::Updater.latest("https://git", "r/m", fetch: ->(_) { raise SocketError })
end
def test_a_request_holds_a_full_commit_only
Dir.mktmpdir do |dir|
assert_raises(ArgumentError) { Maptool::Updater.request(dir, "abc; rm -rf /") }
Maptool::Updater.request(dir, "b" * 40)
assert_equal "b" * 40, JSON.parse(File.read(File.join(dir, "update", "request.json")))["sha"]
assert_nil Maptool::Updater.status(dir)
end
end
end