Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast, front: forbid zero-length paths in pathfinding endpoint #9931

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

Sh099078
Copy link
Contributor

@Sh099078 Sh099078 commented Dec 3, 2024

Fixes #9444

  • Editoast: immediately return a 422 Unprocessable Content error at deserialization when the endpoint pathfinding/blocks is called with the same origin and destination.
  • Editoast: pathfinding/blocks: fail in post-processing with a new PathfindingInputError::ZeroLengthPath variant when core returns zero-length paths.
  • Front: add a new type of stdcm error type when trying to make an STDCM request with the same origin and destination, update the stdcm inputs validation method.

@github-actions github-actions bot added area:front Work on Standard OSRD Interface modules area:editoast Work on Editoast Service labels Dec 3, 2024
@Sh099078 Sh099078 force-pushed the lf/bugfix-pathfinding branch from 7c7ecdd to 9b5ea0c Compare December 3, 2024 14:17
@Sh099078 Sh099078 self-assigned this Dec 3, 2024
rolling_stock_maximum_speed,
rolling_stock_length,
} = Internal::deserialize(deserializer)?;
if path_items.first() == path_items.last() {
Copy link
Member

Choose a reason for hiding this comment

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

This is not enough to figure out if the path length will be zero. For instance, a UIC+ch could refer to the same OP as a trigram+ch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am missing some knowledge about what a trigram and an UIC represent and how to correlate them. Would you mind to elaborate or hint at some documentation on them ?

Copy link
Member

@emersion emersion Dec 3, 2024

Choose a reason for hiding this comment

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

Sure. There are multiple ways to refer to an operational point in a path:

pub enum OperationalPointIdentifier {

One way is via a UIC code. The UIC code is a worldwide-unique number which identifies a location. For instance, "87686006" is "Paris-Gare-de-Lyon". In France, the UIC is not enough to precisely identify an operational point: there are multiple operational points in "Paris-Gare-de-Lyon". So a secondary code is added to pin down a specific one (often also called "ch" for "code chantier"). For instance, "BV" often refers to the place where the platforms are in a station ("bâtiment voyageur"). Side note, the UIC is made up of two parts, a country prefix ("87" for France) and the rest is called CI ("code immuable", local French code, e.g. "686006").

Another way is via a trigram. It's a 3-letter code. It's essentially another way to write a CI, perhaps easier to remember for humans. For instance, "PLY" is the trigram for "Paris-Gare-de-Lyon".

Yet another way is via an operational point ID. It's just an opaque string identifier (e.g. "1e083f8b-c7db-48f4-bb12-ac3bb21d8963").

So, both of these refer to the same operational point:

OperationalPointDescription {
    trigram: "PLY",
    secondary_code: "BV",
}
OperationalPointUic {
    uic: 686006,
    secondary_code: "BV",
}

In other words, if these are given as input to the pathfinding algorithm, it'll freak out the same way it would if given two exact same path item locations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the explanation ! I added a new error variant ZeroLengthPath that transforms core success responses with zero-length paths into errors instead of checking whether the origin and destination are the same location before executing the pathfinding.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.92%. Comparing base (c155980) to head (30a4ecb).
Report is 1 commits behind head on dev.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9931      +/-   ##
==========================================
+ Coverage   81.78%   81.92%   +0.13%     
==========================================
  Files        1073      768     -305     
  Lines      106553    76891   -29662     
  Branches      726      731       +5     
==========================================
- Hits        87148    62990   -24158     
+ Misses      19366    13862    -5504     
  Partials       39       39              
Flag Coverage Δ
editoast ?
front 89.34% <100.00%> (-0.01%) ⬇️
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.50% <ø> (ø)
tests ?

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

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

@Sh099078 Sh099078 force-pushed the lf/bugfix-pathfinding branch 6 times, most recently from 5564da9 to 4cb44f7 Compare December 5, 2024 23:25
@Sh099078 Sh099078 marked this pull request as ready for review December 6, 2024 00:01
@Sh099078 Sh099078 requested review from a team as code owners December 6, 2024 00:01
Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Nice fix. Thank you.

editoast/src/views/path/pathfinding.rs Outdated Show resolved Hide resolved
front/public/locales/en/stdcm.json Outdated Show resolved Hide resolved
@Sh099078 Sh099078 requested a review from emersion December 6, 2024 10:05
Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Apart from this, looks good!

@SharglutDev
Copy link
Contributor

Note

This will conflict with #9924

@flomonster
Copy link
Contributor

Should we authorize pathfinding that has a total length higher than 0m but between two steps has a length of 0m?

@Sh099078 Sh099078 force-pushed the lf/bugfix-pathfinding branch 2 times, most recently from 858887c to 94aee2d Compare January 14, 2025 10:57
Comment on lines 33 to 40
if (
'uic' in origin &&
'uic' in destination &&
'ch' in origin &&
'ch' in destination &&
origin.uic === destination.uic &&
origin.ch === destination.ch
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use ch in the code (too much sncf) but secondary_code (editoast type).
Both uic and secondary_code are defined if location is defined in StdcmPathStep type.
As we checked l.13 that we don't have any path step without location, we can assert that we will have one at this point.

Suggested change
if (
'uic' in origin &&
'uic' in destination &&
'ch' in origin &&
'ch' in destination &&
origin.uic === destination.uic &&
origin.ch === destination.ch
) {
if (
origin.location!.uic === destination.location!.uic &&
origin.location!.secondary_code === destination.location!.secondary_code
) {

Copy link
Contributor Author

@Sh099078 Sh099078 Jan 14, 2025

Choose a reason for hiding this comment

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

Fixed in df926d1.

I also put the origin / destination check before the pathfinding response check as a bit of a hotfix, otherwise it would return the standard error when pathfinding fails instead of the new error that is more specific. It might be useful to give to checkStdcmConfigErrors more than just a boolean in case of pathfinding failure ? If it also received the error type returned by Editoast, we could directly return the zero_length_path error instead of doing the current check on the front-end side.

Copy link
Contributor

@SharglutDev SharglutDev Jan 15, 2025

Choose a reason for hiding this comment

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

Yep, you're totally right, it should be done here :)
But some errors/warning we want to display doesn't exist on editoast so it won't go away totally.

@Sh099078 Sh099078 force-pushed the lf/bugfix-pathfinding branch from 838a3ea to df926d1 Compare January 14, 2025 15:15
Copy link
Contributor

Choose a reason for hiding this comment

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

We could go a little further and check in useStaticPathfinding.ts (probably going to conflict with 2 other PR atm) if origin and destination are the same to avoid launching the pathfinding. There is a check l.57 where we could do the same thing as here (maybe we can extract this check in a util like in stdcm/utils.index.ts)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added for same origin and destination in 30a4ecb

@Sh099078 Sh099078 force-pushed the lf/bugfix-pathfinding branch from 01850f1 to 30a4ecb Compare January 20, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service area:front Work on Standard OSRD Interface modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0-length paths aren't explicitely forbidden but break most endpoints
6 participants