Skip to content

fix: validate required registry fields after runtime merge#762

Merged
harlan-zw merged 4 commits into
nuxt:mainfrom
tsukiyama-3:fix/registry-required-fields-runtime-config
May 14, 2026
Merged

fix: validate required registry fields after runtime merge#762
harlan-zw merged 4 commits into
nuxt:mainfrom
tsukiyama-3:fix/registry-required-fields-runtime-config

Conversation

@tsukiyama-3
Copy link
Copy Markdown
Contributor

🔗 Linked issue

#761

📚 Description

Required-field validation during module setup compared the Valibot schema to the normalized [input] from scripts.registry only.

IDs and similar fields are often supplied only through runtimeConfig.public.scripts and/or NUXT_PUBLIC_SCRIPTS_*, merged into public.scripts earlier in this module (registryWithDefaults + defu). After that merge, the effective config already includes id, but the check still complained.

The WARN now inspects each script’s merged object in runtimeConfig.public.scripts, dropping scriptOptions keys that aren’t part of script input schema. Behaviour at runtime is unchanged; this only aligns dev warnings with documented env/runtime configuration.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 10, 2026

@tsukiyama-3 is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 10, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@762

commit: c1c0d5a

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b965d953-8471-4155-a746-6fe33b5cf131

📥 Commits

Reviewing files that changed from the base of the PR and between c15e0d8 and c1c0d5a.

📒 Files selected for processing (2)
  • packages/script/src/module.ts
  • test/unit/setup.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/script/src/module.ts
  • test/unit/setup.test.ts

📝 Walkthrough

Walkthrough

The change modifies required-field validation for auto-loading registry scripts in the Nuxt scripts module. Instead of checking the raw registry input, the validation now derives an "effective input" from the runtime configuration's public scripts entry (excluding scriptOptions), and falls back to the normalized registry input when unavailable. A new exported helper findMissingRequiredFields implements this logic and unit tests were added to cover its behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: validating required fields after the runtime configuration merge, which is the core fix.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem with required-field validation and how the PR addresses it by inspecting merged runtime config.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Pull the post-merge required-field check out of setup() into a pure
helper so it's unit-testable, and cover the runtimeConfig/env merge
case from nuxt#761.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/unit/setup.test.ts (1)

168-170: ⚡ Quick win

Add test case for scriptOptions alongside valid required fields.

The current test verifies that scriptOptions alone doesn't satisfy requirements, but a more realistic scenario would include scriptOptions mixed with valid fields. This would confirm the filtering logic correctly ignores scriptOptions while recognizing required fields.

✅ Suggested additional test
   it('ignores `scriptOptions` carried on the merged entry', () => {
     expect(findMissingRequiredFields(['id'], {}, { scriptOptions: { bundle: true } })).toEqual(['id'])
   })
+
+  it('correctly filters scriptOptions while recognizing valid fields in merged entry', () => {
+    expect(findMissingRequiredFields(['id'], {}, { id: 'G-123', scriptOptions: { bundle: true } })).toEqual([])
+  })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/setup.test.ts` around lines 168 - 170, Add a new unit test that
ensures findMissingRequiredFields correctly ignores scriptOptions when valid
required fields are present: call findMissingRequiredFields with required key
['id'] and a merged entry object that contains both id (e.g. '123') and
scriptOptions (e.g. { bundle: true }) and assert the result is an empty array;
this verifies the function recognizes the valid id while filtering out
scriptOptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit/setup.test.ts`:
- Around line 176-178: The test duplicates an earlier case; remove or revise it:
either delete the redundant it(...) that calls findMissingRequiredFields(['id'],
{ id: 'G-123' }, undefined), or change it to a meaningful fallback scenario (for
example call findMissingRequiredFields(['id'], { id: 'G-123' }, { }) or { id:
undefined } to assert that raw input is used when merged config exists but lacks
the field). Update the test description to reflect the new intent and keep
references to findMissingRequiredFields and the specific inputs in the revised
assertion.

---

Nitpick comments:
In `@test/unit/setup.test.ts`:
- Around line 168-170: Add a new unit test that ensures
findMissingRequiredFields correctly ignores scriptOptions when valid required
fields are present: call findMissingRequiredFields with required key ['id'] and
a merged entry object that contains both id (e.g. '123') and scriptOptions (e.g.
{ bundle: true }) and assert the result is an empty array; this verifies the
function recognizes the valid id while filtering out scriptOptions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: edb849a4-6fea-4a67-a6dc-40a159c43a31

📥 Commits

Reviewing files that changed from the base of the PR and between 4d34141 and c15e0d8.

📒 Files selected for processing (2)
  • packages/script/src/module.ts
  • test/unit/setup.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/script/src/module.ts

Comment thread test/unit/setup.test.ts Outdated
@harlan-zw harlan-zw changed the title fix(module): validate required registry fields after runtime merge fix: validate required registry fields after runtime merge May 14, 2026
@harlan-zw harlan-zw merged commit 6129314 into nuxt:main May 14, 2026
10 of 11 checks passed
@harlan-zw
Copy link
Copy Markdown
Collaborator

Thanks!

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