Skip to content

build: generate the flatbuffers JavaScript bundle on demand - #7756

Merged
DennisOSRM merged 1 commit into
Project-OSRM:masterfrom
Arpit-Mahajan09:branch2
Oct 27, 2026
Merged

DennisOSRM merged 1 commit into
Project-OSRM:masterfrom
Arpit-Mahajan09:branch2

Conversation

@Arpit-Mahajan09

Copy link
Copy Markdown
Contributor

Closes #7708. Follows #7707

Changes

  • Deleted features/support/fbresult_generated.js; output now goes to the gitignored features/generated/fbresult.js.
  • features/support/fbresult.js (new): runs scripts/regenerate_fbresult_js.sh, then imports the bundle via top-level await. All importers now use it: nearest.js, and test/nodejs/constants.js
  • scripts/regenerate_fbresult_js.sh:
    • writes a SHA-256 of its inputs (the schemas and the script itself) into the bundle header and exits immediately when that hash still matches, so it is cheap to call on every run and from every parallel worker;
    • writes to a temp file and renames it, so a parallel worker never imports a half-written bundle;
    • looks for flatc in $OSRM_BUILD_DIR first (CI uses build-osrm/), then build*/, then PATH, and prints an actionable message when none is found.
    • npm run regenerate-fbresult now passes --force.
  • .gitignore and eslint.config.js updated for the new path.

Design notes

  • Generation can't happen in a cucumber BeforeAll hook, because the step files use static ESM imports, which resolve before any hook runs. Hence a support module with top-level await.
  • The output lives outside features/support/ on purpose. cucumber.mjs imports everything in that folder, so a stale bundle there could be loaded first, and ESM's module cache would then hand the stale copy to the loader too.
  • --gen-all and running esbuild from the work directory (from build: add a script to regenerate the flatbuffers JavaScript bundle #7707) are unchanged, so the output stays deterministic.

Trade-off (raised in the issue)

Running the cucumber features or node tests now requires flatc, from a configured build, FLATC=/path/to/flatc, or PATH. CI already has it. Someone running the features against a prebuilt binary without a build tree will get the "no flatc found" message.

Testing

  • npm run regenerate-fbresult && npx cucumber-js features/nearest features/testbot/duration_matrix.feature: 42 scenarios / 337 steps pass. This covers fb.table() and the waypoints_grouped field added in feat(nearest): support multiple coordinates for GET and POST #7704.
  • npm run nodejs-tests: 612/612 pass (covers test/nodejs/constants.js).
  • Bundle is up to date → script exits without calling flatc. A schema edit → detected as stale and regenerated. Output is byte-identical across reruns. Missing flatc → clear error from both the script and the loader.
  • npx eslint features/: clean apart from the existing indent error in features/lib/osrm_loader.js, which is also on master.

AI disclosure: this change was developed with help from Claude (Anthropic, Claude Opus 5.5). I have reviewed and tested it and understand it fully.

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.97%. Comparing base (afd7d06) to head (51909b7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7756   +/-   ##
=======================================
  Coverage   91.97%   91.97%           
=======================================
  Files         535      535           
  Lines       42745    42745           
=======================================
+ Hits        39315    39316    +1     
+ Misses       3430     3429    -1     

☔ 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.

@DennisOSRM
DennisOSRM merged commit 012c4f0 into Project-OSRM:master Oct 27, 2026
21 checks passed
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.

Generate the flatbuffers JavaScript bundle on demand instead of committing it

2 participants