Skip to content

fix: route every geocoder lookup through the settings-backed geocoder - #409

Merged
roncodes merged 4 commits into
release/v0.6.74from
fix/geocoder-facade-callers-use-configured-geocoder
Oct 19, 2026
Merged

roncodes merged 4 commits into
release/v0.6.74from
fix/geocoder-facade-callers-use-configured-geocoder

Conversation

@roncodes

@roncodes roncodes commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #408 for fleetbase/fleetbase#723. Stacked on #408: this branch contains its commit, so merge #408 first. After that, this diff shrinks to this PR's own two commits.

Problem

#408 fixed the internal geocoder/query and geocoder/reverse endpoints. Every other caller of the geocoder-laravel facade had the same bug. The facade builds its Google provider from config/geocoder.php when the config loads, which is before the settings-table API key is set. Its Chain provider then swallows the failure, so the lookup returns nothing:

  • Place::createFromGeocodingLookup, getValuesFromGeocodingLookup, createFromCoordinates, insertFromCoordinates
  • PlaceSearch::geocode (the plain-text fallback branch)
  • Api\v1\PlaceController::geocodeAddress (address-only place creation)
  • Api\v1\DriverController (locality and country on driver tracking)

Change

  • New helpers Geocoding::lookupAddress() and Geocoding::lookupCoordinates() use Geocoding::geocoder() with GeocodeQuery::create / ReverseQuery::fromCoordinates and return collect(...->all()), so callers get the same shape as before. A failed lookup still resolves to an empty collection, matching what the facade did. That keeps place creation's raw-address / (0, 0) fallback from turning into a 500 on installs without a Google key. The failure is now logged as a warning instead of hidden.
  • DriverController calls Geocoding::geocoder() directly. Its existing try/catch still reports geocoder failures to Sentry.
  • No facade usage remains in server/src.

config/geocoder.php

I fixed this file rather than deleting it. Removing it would make the facade fall back to the package's default config, which adds a GeoPlugin provider. Code outside fleetops may still resolve app('geocoder').

  • The first GoogleMaps argument is the region, but the file passed the locale. It now passes env('GOOGLE_MAPS_REGION').
  • The cache store was 'geocode', which is not defined anywhere. It is now null, the default store.
  • Neither setting affects fleetops anymore.

Tests

  • Test stand-ins now bind fleetops.geocoder (geocodeQuery / reverseQuery / all) instead of app('geocoder'). The Geocoder::clearResolvedInstances() calls are gone.
  • New tests cover the failure paths that lost coverage once every test injected fleetops.geocoder: building the live Google geocoder, Geocoding::query() rethrowing, the import raw-address fallback, and PlaceSearch's outer guard. The full suite passes locally with the 100% coverage gate.
  • Two tests depended on the keyless geocoder throwing because fleetops.geocoder was unbound. They now bind a geocoder that throws on purpose.
  • New test: lookupAddress / lookupCoordinates return raw addresses, log failures and return empty results, and createFromGeocodingLookup keeps its raw-address fallback.
  • Each touched test file passes on its own with php scripts/pest-runner.php --debug <file> (exit 0). php-cs-fixer is clean.

Follow-up outside this repo

storefront's ServiceQuoteControllerContractsTest and OrderEditorApplyCoverageTest bind app('geocoder') stand-ins for fleetops place creation. They should move to fleetops.geocoder too.

Refs fleetbase/fleetbase#723

The internal geocoder/query and geocoder/reverse endpoints used the
geocoder-laravel facade, whose Google provider is built from
config/geocoder.php when the config loads, before the API key from the
settings table is set. Its Chain provider swallowed the resulting
failure, so both endpoints returned [] while places/lookup, which goes
through Geocoding, resolved the same address.

Route both lookups through Geocoding::geocoder() so they share the
settings-backed API key, region and locale.

Fixes fleetbase/fleetbase#723
@roncodes roncodes mentioned this pull request Oct 19, 2026
@roncodes
roncodes changed the base branch from main to release/v0.6.74 October 19, 2026 04:21
GeocoderController no longer resolves the geocoder-laravel facade, so
the seam test's app('geocoder') stand-in was never consulted and the
unbound fleetops geocoder tried a live Google request.
Place, PlaceSearch and the v1 Place and Driver controllers still called the
geocoder-laravel facade. Its Google provider is built from
config/geocoder.php when the config loads, before the settings-table API key
is set, and its Chain provider swallows the failure, so these lookups
silently returned no results (the same bug #408 fixed for the internal
geocoder endpoints).

They now go through Geocoding::geocoder(). Geocoding::lookupAddress() and
lookupCoordinates() return the raw address results; a failed lookup still
resolves to an empty collection, so place creation keeps its raw-address
fallback, but the failure is now logged instead of hidden. The driver
tracking endpoint keeps calling the geocoder directly so its failures still
reach Sentry.

config/geocoder.php now passes the region where GoogleMaps expects it
(it passed the locale) and uses the default cache store instead of a
'geocode' store that does not exist. It only matters for code outside
fleetops that still uses the facade.

Tests bind 'fleetops.geocoder' stand-ins instead of app('geocoder').

Refs fleetbase/fleetbase#723
With every test injecting fleetops.geocoder, nothing built the live
Google geocoder or reached Geocoding::query()'s rethrow, the import
raw-address fallback, or PlaceSearch's outer guard.
@roncodes
roncodes force-pushed the fix/geocoder-facade-callers-use-configured-geocoder branch from 50006ec to 64cc345 Compare October 19, 2026 04:48
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7887aa5) to head (64cc345).
⚠️ Report is 1 commits behind head on release/v0.6.74.

Additional details and impacted files
@@                 Coverage Diff                 @@
##             release/v0.6.74      #409   +/-   ##
===================================================
  Coverage             100.00%   100.00%           
- Complexity             13591     13596    +5     
===================================================
  Files                    634       634           
  Lines                  49331     49342   +11     
===================================================
+ Hits                   49331     49342   +11     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@roncodes
roncodes merged commit b1b2e61 into release/v0.6.74 Oct 19, 2026
8 checks passed
@roncodes
roncodes deleted the fix/geocoder-facade-callers-use-configured-geocoder branch October 19, 2026 05:49
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