Skip to content

fix: Pin Spectral rulesets and run local binary in spec validations - #1415

Merged
andmatei merged 8 commits into
mainfrom
sage-bot/CLOUDP-429023/sage-CLOUDP-429023-1785843153209
Aug 5, 2026
Merged

fix: Pin Spectral rulesets and run local binary in spec validations#1415
andmatei merged 8 commits into
mainfrom
sage-bot/CLOUDP-429023/sage-CLOUDP-429023-1785843153209

Conversation

@mongodb-sage-bot

@mongodb-sage-bot mongodb-sage-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

The OpenAPI Spec Release fails in all environments when Spectral crashes
(exit code 2, Cannot read properties of null (reading 'enum')) in the
required-validations job. The release workflows previously used npm install
and npx, allowing the Spectral toolchain to drift from the dependency tree
reviewed in this repository's lockfile.

This change makes the Spectral toolchain reproducible:

  • Pin all directly used Spectral packages, including the upstream-fixed
    @stoplight/spectral-rulesets@1.22.7.
  • Install dependencies with npm ci, so CI strictly honors package-lock.json.
  • Invoke the locally installed Spectral binary through a shared npm script.
  • Remove the obsolete spectral_version workflow input and all of its callers.
  • Add a regression test that verifies the OAS ruleset does not crash when a
    request-body example contains a nested null value.
  • Group the Spectral packages in Dependabot so future toolchain upgrades are
    proposed and validated together.

Jira ticket: CLOUDP-429023

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

Further comments

Stoplight tracked the null crash in
#2959, fixed it in
#2960, and published the
fix in
@stoplight/spectral-rulesets@1.22.7.
The rulesets package is therefore declared directly at the fixed version
instead of being constrained with an npm override.

The query: null value in the chartsDashboards:import example is valid
Charts export behavior, including in version 9 export files. The regression
test intentionally retains this case. Improving the broader, abbreviated MMS
example would be separate contract and documentation work rather than part of
this Spectral fix.


Important

MongoDB Contribution Guidelines

This pull request was generated by sage-bot on behalf of andrei.matei@mongodb.com (ticket assignee). The assignee must self-review the changes before requesting review from another engineer.
The assignee is not allowed to merge their own PR without approval from another engineer.

…idations

## Proposed changes

The OpenAPI Spec Release fails in all environments when Spectral crashes
(exit code 2, "Cannot read properties of null (reading 'enum')") in the
`required-validations` job. The crash is nondeterministic: the release
workflows invoke Spectral via `npx -- @stoplight/spectral-cli@<version>`,
which pins only the CLI and lets its transitive dependencies float on caret
ranges. Depending on whether the npx cache is warm, `@stoplight/spectral-rulesets`
resolves to either 1.21.3 (from the lockfile) or a newer version whose
`duplicated-entry-in-enum` rule dropped the `@ &&` null guard from its JSONPath
`given` expression, causing it to dereference `.enum` on the single `null`
value present in a preview request-body example and abort.

This removes the nondeterminism so the lockfile strictly governs which
rulesets version runs:

- Add npm `overrides` to `package.json` (and the lockfile root) pinning
  `@stoplight/spectral-rulesets`, `@stoplight/spectral-core`, and
  `@stoplight/spectral-functions` so the resolved dependency tree is
  reproducible.
- Invoke the locally installed `./node_modules/.bin/spectral` binary instead
  of `npx -- @stoplight/spectral-cli@<version>` in the lint steps of
  `required-spec-validations.yml` and `optional-spec-validations.yml`, so the
  lockfile (not the npx cache) determines the executed versions.
- Use `npm ci` instead of `npm install` in both workflows so the lockfile is
  honoured strictly.

_Jira ticket:_ CLOUDP-429023

## Checklist

- [ ] I have signed the [MongoDB CLA](https://www.mongodb.com/legal/contributor-agreement)
- [ ] I have added tests that prove my fix is effective or that my feature works

### Changes to Spectral
- [x] I have read the [README](../tools/spectral/README.md) file for Spectral Updates

## Further comments

The `spectral_version` workflow inputs are left in place because caller
workflows (`release-spec.yml`, `release-spec-runner.yml`) still pass them;
removing them is out of scope here.

Follow-ups noted on the ticket remain outside this repository: getting the
meaningless `query: null` removed from the `chartsDashboards:import` preview
example upstream, and reporting the missing null guard in
`duplicated-entry-in-enum` to Stoplight.
@mongodb-sage-bot

Copy link
Copy Markdown
Contributor Author

Sage Bot can help with this pull request. Just @sage-bot in comments and I'll start working on changes in this branch.
Learn more about Sage Bot

@andmatei andmatei changed the title CLOUDP-429023: Pin Spectral rulesets and run local binary in spec validations fix: Pin Spectral rulesets and run local binary in spec validations Aug 4, 2026
@andmatei
andmatei marked this pull request as ready for review August 5, 2026 13:25
@andmatei
andmatei requested a review from a team as a code owner August 5, 2026 13:25
@andmatei
andmatei merged commit 9beffd1 into main Aug 5, 2026
9 checks passed
@andmatei
andmatei deleted the sage-bot/CLOUDP-429023/sage-CLOUDP-429023-1785843153209 branch August 5, 2026 14:20
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