-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: dev
Are you sure you want to change the base?
Conversation
7c7ecdd
to
9b5ea0c
Compare
rolling_stock_maximum_speed, | ||
rolling_stock_length, | ||
} = Internal::deserialize(deserializer)?; | ||
if path_items.first() == path_items.last() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ReportAll modified and coverable lines are covered by tests ✅
❗ 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
5564da9
to
4cb44f7
Compare
There was a problem hiding this 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.
There was a problem hiding this 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!
Note This will conflict with #9924 |
Should we authorize pathfinding that has a total length higher than |
858887c
to
94aee2d
Compare
if ( | ||
'uic' in origin && | ||
'uic' in destination && | ||
'ch' in origin && | ||
'ch' in destination && | ||
origin.uic === destination.uic && | ||
origin.ch === destination.ch | ||
) { |
There was a problem hiding this comment.
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.
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 | |
) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
838a3ea
to
df926d1
Compare
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
01850f1
to
30a4ecb
Compare
Fixes #9444
Editoast: immediately return a422 Unprocessable Content
error at deserialization when the endpointpathfinding/blocks
is called with the same origin and destination.pathfinding/blocks
: fail in post-processing with a newPathfindingInputError::ZeroLengthPath
variant when core returns zero-length paths.