[3/n] add stricter typing in JsonPathStack#15
Open
sunshowers wants to merge 6 commits intomainfrom
Open
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
ahl
approved these changes
May 2, 2026
Collaborator
ahl
left a comment
There was a problem hiding this comment.
Didn't look very carefully; please let me know if something needs particular scrutiny
sunshowers
commented
May 5, 2026
Comment on lines
-70
to
-72
| pub fn contains_cycle(&self) -> bool { | ||
| self.stack.iter().any(|item| item.starts_with(&self.top)) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Whoops, looks like this would just do a plain-string prefix check. The strings here aren't prefix-free which meant that we'd do something like:
/v1/system/audit-log → AuditLogEntryResultsPage → properties.items.items → AuditLogEntry
and then stop there.
sunshowers
commented
May 5, 2026
Comment on lines
+333
to
+345
| /// Check if `ancestor` is a path-segment-aligned prefix of `path`. | ||
| /// | ||
| /// Returns `true` if `path` starts with `ancestor` and the character | ||
| /// immediately following the prefix (if any) is `/`. This prevents false | ||
| /// matches where schema names share a common string prefix (e.g., `User` | ||
| /// matching `UserProfile`). | ||
| fn is_path_ancestor_of(ancestor: &str, path: &str) -> bool { | ||
| path.starts_with(ancestor) | ||
| && path | ||
| .as_bytes() | ||
| .get(ancestor.len()) | ||
| .is_none_or(|&b| b == b'/') | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This PR fixes the bug discussed in https://github.com/oxidecomputer/drift/pull/15/changes#r3185394321.
Created using spr 1.3.6-beta.1
sunshowers
added a commit
that referenced
this pull request
May 5, 2026
Detect cycles by checking for path segments (with a trailing `/`) rather than just using a raw string prefix. We hit this in Omicron where `AuditLogEntry` was incorrectly detected as a prefix of `AuditLogEntryActor`, hiding incompatible changes. This is a minimal fix that (I believe) is correct given the current structure. I'm reworking this in #15 to have stronger types so we can think about this in a more principled manner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
JsonPathStackalways has an endpoint at the bottom and a series of schemas above that. We're going to rely on this in upcoming work -- express this constraint in the type system.