feat: Add shapes.txt validator#2123
feat: Add shapes.txt validator#2123cswilson252 wants to merge 24 commits intoMobilityData:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new validator intended to warn when shapes.txt is missing unless the feed appears to use zone-based or fixed-stop DRT (per #1792).
Changes:
- Introduces
MissingShapesFileValidatorand a corresponding test class. - Adds unit tests covering shapes present + DRT present scenarios (and a no-shapes/no-DRT scenario).
- Adds an extra import in
ShapeUsageValidator.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingShapesFileValidator.java | New multi-file validator for warning on missing shapes.txt unless DRT indicators are present. |
| main/src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingShapesFileValidatorTest.java | New unit tests for the validator behavior. |
| main/src/main/java/org/mobilitydata/gtfsvalidator/validator/ShapeUsageValidator.java | Adds an import for a nested notice type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
i'm a bit stuck as to why the test failure is happening |
| for (GtfsStopTime stopTime : stopTimeTable.getEntities()) { | ||
| noticeContainer.addValidationNotice( | ||
| new MissingRecommendedFileNotice("shapes.txt")); | ||
| // This is a feed-level warning; emit it at most once. | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop looks unnecessary, and the noticeContainer.addValidationNotice method is called once and immediately after the break exits.
Also, if stop_times.txt is empty or missing, the loop body never runs, and no notice is emitted, even when it should be.
| assertThat(missingRecommendedFileNoticesCount).isAtLeast(1); | ||
| } | ||
|
|
||
| private static List<ValidationNotice> generateNotices( |
There was a problem hiding this comment.
testNoShapesFileAndNoDrtPresent fails because generateNotices() ignores the shapeContainer parameter. It always builds the shape container via forEntities(shapes,), which gives status PARSABLE_HEADERS_AND_ROWS, not MISSING_FILE. So isMissingFile() always returns false, and no notice is ever emitted.
| } | ||
|
|
||
| @Override | ||
| public void validate(NoticeContainer noticeContainer) { |
There was a problem hiding this comment.
[Suggestion] Reuse FeedMetadata logic instead of re-implementing it
The DRT detection logic already exists in FeedMetadata:
- hasAtLeastOneTripWithOnlyLocationId(), zone-based DRT check
- hasAtLeastOneTripWithOnlyLocationGroupId() + hasAtLeastOneRecordInFile(), fixed-stops DRT check (mirrors loadFixedStopsDemandResponseTransit)
To reuse them in MissingShapesFileValidator, these three methods need to be made public static and their signatures updated to accept the individual table containers directly (e.g. GtfsStopTimeTableContainer and GtfsLocationGroupsTableContainer).
This avoids duplicating the DRT detection logic and ensures the validator stays consistent with how features are detected elsewhere in the codebase. It would also make the validate() method read clearly:
boolean hasZoneBasedDrt = FeedMetadata.hasAtLeastOneTripWithOnlyLocationId(stopTimeTable);
boolean hasFixedStopsDrt = FeedMetadata.hasAtLeastOneRecordInFile(locationGroupsTable)
&& FeedMetadata.hasAtLeastOneTripWithOnlyLocationGroupId(stopTimeTable);
if (shapeTable.isMissingFile() && !hasZoneBasedDrt && !hasFixedStopsDrt) {
noticeContainer.addValidationNotice(new MissingRecommendedFileNotice("shapes.txt"));
}
Alternative: add hasZoneBasedDemandResponseService and hasFixedStopsDemandResponseService to FeedMetadata
|
|
||
| @Override | ||
| public void validate(NoticeContainer noticeContainer) { | ||
| Boolean missingShapes = shapeTable.isMissingFile(); |
There was a problem hiding this comment.
If the file is present, we can add a return statement to save execution time.
Summary:
Add validator that checks if either a shapes.txt and/or a fixed or zone-based DRT service is present (as per #1792)
DRT functionality added as per this reference
Fixes #1792
Expected behavior:
Validator will print WARNING if shapes.txt and signs of a DRT feature are not found.
Please make sure these boxes are checked before submitting your pull request - thanks!
gradle testto make sure you didn't break anything