Skip to content

[3/n] add stricter typing in JsonPathStack#15

Open
sunshowers wants to merge 6 commits intomainfrom
sunshowers/spr/2n-add-stricter-typing-in-jsonpathstack
Open

[3/n] add stricter typing in JsonPathStack#15
sunshowers wants to merge 6 commits intomainfrom
sunshowers/spr/2n-add-stricter-typing-in-jsonpathstack

Conversation

@sunshowers
Copy link
Copy Markdown
Contributor

A JsonPathStack always 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.

Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1

[skip ci]
@sunshowers sunshowers changed the title [2/n] add stricter typing in JsonPathStack [3/n] add stricter typing in JsonPathStack Feb 6, 2026
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
Copy link
Copy Markdown
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

Didn't look very carefully; please let me know if something needs particular scrutiny

Comment thread src/lib.rs
Comment on lines -70 to -72
pub fn contains_cycle(&self) -> bool {
self.stack.iter().any(|item| item.starts_with(&self.top))
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/path.rs
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'/')
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1c765ad adds a test for it.

@sunshowers sunshowers changed the base branch from sunshowers/spr/main.2n-add-stricter-typing-in-jsonpathstack to main May 5, 2026 01:05
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.
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