Skip to content

Improve utility scripts with modern dependencies and enhanced features#7461

Merged
DennisOSRM merged 6 commits intomasterfrom
improve-scripts
Apr 10, 2026
Merged

Improve utility scripts with modern dependencies and enhanced features#7461
DennisOSRM merged 6 commits intomasterfrom
improve-scripts

Conversation

@DennisOSRM
Copy link
Copy Markdown
Collaborator

Changes

osm2cucumber.js

  • Replace xml2js with fast-xml-parser for better performance and simpler API
  • Update attribute access from .$ to @_ prefix format

osrm-runner.js

  • Add --verbose flag to optionally print CSV output (stats always shown)
  • Extract URL path portions from full URLs in query files
  • Add query statistics: total, successful/failed count, and response time metrics (min/max/avg/median)

poly2req.js

  • Add comprehensive CLI argument support (--help, --type, --host, --port, etc.)
  • Support predefined bounding boxes (planet, us, germany, dc) + custom .poly files
  • Output queries in CSV-quoted format for compatibility with osrm-runner.js
  • Default to germany region if no bbox specified
  • Add colorized help banner

- osm2cucumber.js: Switch from xml2js to fast-xml-parser for better performance
- osrm-runner.js: Add verbose flag, URL path extraction, and query statistics (min/max/avg/median)
- poly2req.js: Add CLI argument support with help, support multiple query types/regions, output CSV-quoted format

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 10, 2026 17:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes and extends the repository’s Node.js utility scripts used for generating OSRM query inputs, running query benchmarks, and converting OSM extracts to Cucumber scenarios, alongside dependency/lockfile updates to support these changes.

Changes:

  • Enhances poly2req.js with a real CLI (help/options), predefined bounding boxes, and CSV-quoted output intended to feed osrm-runner.js.
  • Extends osrm-runner.js with a --verbose mode, URL→path normalization for query files, and aggregate query timing statistics.
  • Updates osm2cucumber.js to parse OSM XML via fast-xml-parser instead of xml2js and bumps various npm lockfile entries.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

File Description
scripts/poly2req.js Adds CLI parsing + bbox presets and emits CSV-quoted query URLs
scripts/osrm-runner.js Adds verbose output toggle, extracts path from full URLs, and prints summary stats
scripts/osm2cucumber.js Switches XML parsing implementation to fast-xml-parser
package-lock.json Updates lockfile for dependency/version/engine changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/osm2cucumber.js
Comment thread scripts/poly2req.js Outdated
Comment thread scripts/poly2req.js
Comment on lines 115 to 136
function makeQuery(coords) {
let coords_string = coords.map((c) => coord_templates[VERSION].replace('{lon}', c[0]).replace('{lat}', c[1])).join(coords_separators[VERSION]);
return url_templates[VERSION].replace('{coords}', coords_string).replace('{port}', PORT);
const coords_string = coords.map((c) => coord_template.replace('{lon}', c[0]).replace('{lat}', c[1])).join(coords_separator);
const path = url_templates[options.type].replace('{coords}', coords_string);
return `http://${options.host}:${options.port}${path}`;
}

// Generate queries based on distance or waypoint count
if (axis == 'distance')
// Output in CSV format (quoted) for compatibility with osrm-runner.js
if (options.axis == 'distance')
{
for (let i = 0; i < NUM_REQUEST; ++i)
for (let i = 0; i < options.number; ++i)
{
let coords = [];
for (let j = 0; j < NUM_COORDS; ++j)
for (let j = 0; j < options.coords; ++j)
{
coords.push(getRandomCoordinate());
}
console.log(makeQuery(coords));
console.log(`"${makeQuery(coords)}"`);
}
}
else if (axis == 'waypoints')
else if (options.axis == 'waypoints')
{
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.type and options.axis are used as unchecked selectors (url_templates[options.type], branching on options.axis). If a user passes an unexpected value, this can throw (or silently produce no output). Consider validating these options against the allowed set and exiting with a clear error + usage.

Copilot uses AI. Check for mistakes.
Comment thread scripts/osrm-runner.js
Comment on lines +153 to +166
// Collect all results for statistics
const all_results = [];
let completed_queries = 0;

queries.forEach(query => {
run_query(query, options.filter, (query, code, ttfb, total, results) => {
const data = results ? JSON.stringify(results[0]) : '';
const record = [[query, code, ttfb, total, data]];
process.stdout.write(csv_stringify(record));
const record = {
query,
code,
ttfb: ttfb ?? 0,
total: total ?? 0,
data
};
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when --verbose is not set, the runner collects and stores data (JSON string) for every query. For large query sets this can be a significant memory hit. Consider only serializing/storing data when options.verbose is true, and otherwise keep only the fields needed for statistics.

Copilot uses AI. Check for mistakes.
Comment thread scripts/osrm-runner.js
Comment on lines +157 to +181
queries.forEach(query => {
run_query(query, options.filter, (query, code, ttfb, total, results) => {
const data = results ? JSON.stringify(results[0]) : '';
const record = [[query, code, ttfb, total, data]];
process.stdout.write(csv_stringify(record));
const record = {
query,
code,
ttfb: ttfb ?? 0,
total: total ?? 0,
data
};
all_results.push(record);
completed_queries++;

// When all queries are done, print statistics and CSV output
if (completed_queries === queries.length) {
print_statistics(all_results);

// Output CSV data only if verbose flag is set
if (options.verbose) {
const csv_records = all_results.map(r => [r.query, r.code, r.ttfb, r.total, r.data]);
process.stdout.write(csv_stringify(csv_records));
}
}
});
});
});
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If queries.length === 0 (empty/invalid queries file, or all rows filtered out), the forEach body never runs and statistics are never printed. Handle the empty case explicitly (print stats showing 0 total, and exit with a non-zero status if appropriate).

Copilot uses AI. Check for mistakes.
Comment thread scripts/osrm-runner.js Outdated
Comment thread scripts/osrm-runner.js
Comment on lines 129 to +141
// Load queries from file or generate random coordinate-based queries
let queries = [];
if (options.hasOwnProperty('queries-files')) {
queries = fs.readFileSync(options['queries-files'])
.toString()
.split('\n')
.map(r => { const match = /^"([^\"]+)"/.exec(r); return match ? match[1] : null; })
.filter(q => q);
.filter(q => q)
.map(q => {
// If query is a full URL, extract just the path portion
const url_match = /^https?:\/\/[^\/]+(\/.*?)$/.exec(q);
return url_match ? url_match[1] : q;
});
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --queries-files help text says "queries in the first row", but this parser expects one query per line and extracts the first quoted field on each line. Consider aligning the option description and/or supporting a real CSV parser if the input is intended to be CSV with multiple columns.

Copilot uses AI. Check for mistakes.
DennisOSRM and others added 5 commits April 10, 2026 20:43
Allow passing a .poly file or named bbox as a positional argument,
restoring the previous usage: scripts/poly2req.js ./test/data/monaco.poly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix ne bounding box init to [-Infinity, -Infinity] to handle negative coords
- Fix --path option description: v2 -> v1 to match actual default
- Add fast-xml-parser to devDependencies for osm2cucumber.js

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@DennisOSRM DennisOSRM merged commit f2adcec into master Apr 10, 2026
23 checks passed
@DennisOSRM DennisOSRM deleted the improve-scripts branch April 10, 2026 21:04
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.

2 participants