Skip to content

fix(ipa): correct parent-resource check in resourceBelongsToSingleParent - #1449

Merged
DatMitro merged 1 commit into
mainfrom
CLOUDP-438303
Aug 25, 2026
Merged

DatMitro merged 1 commit into
mainfrom
CLOUDP-438303

Conversation

@DatMitro

@DatMitro DatMitro commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Proposed changes

resourceBelongsToSingleParent normalizes an instance path down to its collection path before checking whether the segment preceding the resource name is a path parameter, but the slice removed two segments instead of one. That left the array still ending in a path parameter and put a plain resource name in the length - 2 slot, so the function returned false for every instance path:

Input (after prefix strip) Before After
/groups/{groupId}/clusters/{clusterId} false true
/groups/{g}/clusters/{c}/processes/{p} false true
/groups/{groupId} throws TypeError: Cannot read properties of undefined (reading 'startsWith') false

The throw happened because the slice emptied the array, so resourcePathSections[length - 2] was undefined and isPathParam called .startsWith on it.

Changes:

  • Drop one segment with pop() instead of two.
  • Simplify the surrounding guards. The two length checks existed only to keep the indexing safe and are subsumed by a single bounds check on the final comparison. Splitting now filters empty segments, matching the idiom already used in isRootLevelResource and longRunningOperations.
  • Export the function so it can be unit tested directly, and add cases for nested collections and instances, root-level rejection, non-parameterized parents, prefix-only paths, and consecutive path params.

No change to rule output. The only caller is isSingletonResource, which always passes a resource collection identifier — a path that by definition does not end in a path parameter — so the affected branch was never taken. This is a latent-correctness fix; the full tools/spectral/ipa suite passes unchanged (127 suites, 811 tests).

Jira ticket: CLOUDP-438303

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Drop one path segment instead of two when normalizing an instance path, export
the function, and add unit tests. No change to rule output.

JIRA: CLOUDP-438303
@DatMitro
DatMitro merged commit bafa44f into main Aug 25, 2026
11 checks passed
@DatMitro
DatMitro deleted the CLOUDP-438303 branch August 25, 2026 12:47
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