fix: ignore license change for initial version#2816
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a shared normalizePackageLicense util, replaces ad-hoc license extraction across composables and server endpoints with it, adds an early-return guard in the license-change handler for packages without a previous version, and extends unit tests for badge rendering and license-change comparisons (including object-shaped licences). ChangesLicense normalisation rollout
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Hello! Thank you for opening your first PR to npmx, @charpeni! 🚀 Here’s what will happen next:
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/api/registry/license-change/[...pkg].get.ts (1)
41-49:⚠️ Potential issue | 🟠 Major | ⚡ Quick winValidate
currentVersionIndexbefore array access.The
currentVersionIndexcan be-1in two scenarios: (1) whenversion === 'latest'and theversionsarray is empty, or (2) whenfindIndexfails to locate the requested version. Accessingversions[currentVersionIndex]on line 49 with a negative index violates type-safety. As per coding guidelines, always check when accessing an array value by index.🛡️ Proposed fix to validate currentVersionIndex
const currentVersionIndex = version === 'latest' ? versions.length - 1 : versions.findIndex(v => v.version === version) +if (currentVersionIndex < 0) { + throw createError({ + statusCode: 404, + statusMessage: 'Version not found', + }) +} + const previousVersionIndex = currentVersionIndex - 1 if (previousVersionIndex < 0) { return { change } }🤖 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 `@server/api/registry/license-change/`[...pkg].get.ts around lines 41 - 49, currentVersionIndex can be -1 (empty versions or findIndex miss), so before accessing versions[currentVersionIndex] in the assignment to currentLicense, validate currentVersionIndex is within [0, versions.length-1]; if it's -1 or out of range, set currentLicense to 'UNKNOWN' (or the existing fallback) and proceed—update the logic around the currentVersionIndex calculation and the currentLicense assignment to guard against negative indices and avoid unsafe array access.
🤖 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.
Outside diff comments:
In `@server/api/registry/license-change/`[...pkg].get.ts:
- Around line 41-49: currentVersionIndex can be -1 (empty versions or findIndex
miss), so before accessing versions[currentVersionIndex] in the assignment to
currentLicense, validate currentVersionIndex is within [0, versions.length-1];
if it's -1 or out of range, set currentLicense to 'UNKNOWN' (or the existing
fallback) and proceed—update the logic around the currentVersionIndex
calculation and the currentLicense assignment to guard against negative indices
and avoid unsafe array access.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 250d627f-c1e0-495f-b578-54f044d06a98
📒 Files selected for processing (2)
server/api/registry/license-change/[...pkg].get.tstest/unit/server/api/registry/license-change/pkg.get.spec.ts
🔗 Linked issue
Resolves #2720
🧭 Context
The license-change API reported a license change for a package’s first published version because it compared that version against a missing previous version, which was normalized to
UNKNOWN.📚 Description
This updates the license-change endpoint to return no change when the selected version has no previous version to compare against.
It also adds focused unit coverage for:
Tested with:
pnpm test --project unit test/unit/server/api/registry/license-change/pkg.get.spec.ts