Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 13, 2025

Summary by CodeRabbit

  • New Features
    • Added scope-level whitelisting for large packages. Scopes can now be designated as permitted for accessing and fetching large packages and files, streamlining permission management for repositories that handle large-scale packages without requiring individual package-level configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@fengmk2 fengmk2 requested review from Copilot and elrrrrrrr December 13, 2025 12:34
@fengmk2 fengmk2 self-assigned this Dec 13, 2025
@fengmk2 fengmk2 added the enhancement New feature or request label Dec 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Walkthrough

A single file is modified to introduce scope-level whitelisting for large packages in Unpkg. The implementation adds an allowLargeScopes field tracked from the manifest, updates the whitelist flow, and modifies access checks to short-circuit when a scope matches the new whitelist, while preserving existing per-package large-package handling.

Changes

Cohort / File(s) Summary
Large Scopes Whitelist Support
app/core/service/PackageVersionFileService.ts
Adds allowLargeScopes field to track scope-level large package permissions. Manifest update path now reads and stores allowLargeScopes. The isAllowLargePackageVersion check short-circuits to true if package scope is listed in the whitelist. Existing per-package/scope large-package handling via allowLargePackages remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the allowLargeScopes field is correctly initialized and maintained throughout the whitelist update flow
  • Check the short-circuit logic in isAllowLargePackageVersion to ensure scope matching is accurate and takes precedence appropriately
  • Confirm backward compatibility β€” ensure existing allowLargePackages checks function as before for packages not matched by the new scope whitelist

Poem

🐰 A scope-wide gate now guards the way,
Large packages dance in grand display,
The whitelist grows with nested care,
Where scopes and sizes both declare!

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The PR title 'fix: support allow large check from scopes level' directly describes the main change: adding support for large scopes in the Unpkg whitelist, which is the core modification in PackageVersionFileService.ts.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch allow-large-scopes

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to how 'large packages' are managed within the system. Previously, allowances for large packages were handled on an individual package basis. With this change, the system now supports whitelisting entire package scopes, simplifying the configuration and management of large packages, especially for monorepos or organizations with many packages under specific namespaces. This improves flexibility and reduces maintenance overhead for package version file services.

Highlights

  • New Whitelist Property: A new private property, #unpkgWhiteListAllowLargeScopes, has been introduced to manage whitelisted scopes for packages that are allowed to be 'large'.
  • Configuration Update: The updateUnpkgWhiteList method now initializes the #unpkgWhiteListAllowLargeScopes property by reading the manifest.allowLargeScopes configuration, enabling dynamic updates to the whitelist.
  • Scope-Level Large Package Check: The isAllowLargePackage method has been updated to first check if a package's scope is present in the #unpkgWhiteListAllowLargeScopes, providing a more granular and efficient way to allow large packages at the scope level.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with πŸ‘ and πŸ‘Ž on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new feature to whitelist large packages by scope. This is implemented by adding a new private property, #unpkgWhiteListAllowLargeScopes, to the PackageVersionFileService class. This property is initialized from manifest.allowLargeScopes during the updateUnpkgWhiteList method. A check is then added to allow large packages if their scope is present in this new whitelist. There were no review comments provided.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (3)
app/core/service/PackageVersionFileService.ts (3)

61-63: Prefer Set over string[] for large-scope whitelist lookups.
includes() is O(n) and this check can be on a hot path; Set#has() is O(1) and avoids accidental duplicates.

-  // allow large package scopes, e.g. ['@foo', '@bar']
-  #unpkgWhiteListAllowLargeScopes: string[] = [];
+  // allow large package scopes, e.g. ['@foo', '@bar']
+  #unpkgWhiteListAllowLargeScopes = new Set<string>();

90-129: Log message doesn’t reflect the new β€œlarge scopes” whitelist + consider narrowing any here.
You now track allowLargeScopes, but the info log still only reports β€œlarge packages”, so operators can’t confirm scope rollout from logs. Also, the repeated as any casts make schema drift easy to miss.

-    this.#unpkgWhiteListAllowLargeScopes = manifest.allowLargeScopes ?? ([] as any);
+    this.#unpkgWhiteListAllowLargeScopes = new Set<string>((manifest.allowLargeScopes ?? []) as string[]);
     this.logger.info(
-      '[PackageVersionFileService.updateUnpkgWhiteList] version:%s, total %s packages, %s scopes, %s large packages',
+      '[PackageVersionFileService.updateUnpkgWhiteList] version:%s, total %s packages, %s scopes, %s large packages, %s large scopes',
       whiteListPackageVersion,
       Object.keys(this.#unpkgWhiteListAllowPackages).length,
       this.#unpkgWhiteListAllowScopes.length,
       Object.keys(this.#unpkgWhiteListAllowLargePackages).length,
+      this.#unpkgWhiteListAllowLargeScopes.size,
     );

131-144: Consider converting allowLargeScopes to Set<string> for consistent type usage across the codebase, but the current Array.includes() implementation is functionally correct.

The whitelist membership checks would benefit from using Set for O(1) lookup performance, particularly if whitelist sizes grow. However, this requires updating both the type declaration and the method call:

  • Type: #unpkgWhiteListAllowLargeScopes: Set<string> = new Set();
  • Assignment: this.#unpkgWhiteListAllowLargeScopes = new Set(manifest.allowLargeScopes ?? []);
  • Check: if (this.#unpkgWhiteListAllowLargeScopes.has(pkgScope)) return true;

The current string[] with .includes() is not incorrect, but if converting to Set, ensure consistency with how #unpkgWhiteListAllowScopes and #unpkgWhiteListAllowLargePackages are handled. Regarding scope normalization: pkgScope is already in standard format from upstream callers and getFullname() already handles empty scope cases, so explicit normalization in this method is unnecessary.

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ad669c9 and 05cf085.

πŸ“’ Files selected for processing (1)
  • app/core/service/PackageVersionFileService.ts (3 hunks)
🧰 Additional context used
πŸ““ Path-based instructions (4)
**/*.{js,ts,tsx,jsx}

πŸ“„ CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{js,ts,tsx,jsx}: Use single quotes in JavaScript/TypeScript code (from Prettier configuration)
Use 2-space indentation (from Prettier configuration)
Maintain 120 character line width maximum (from Prettier configuration)
Use trailing commas in ES5 syntax (from Prettier configuration)
Avoid parentheses in arrow functions when possible (from Prettier configuration)
Maximum of 6 function parameters (from Oxlint configuration)
Warn on console usage (from Oxlint configuration)
Disallow anonymous default exports (from Oxlint configuration)
Use ES modules (import/export) syntax throughout

Files:

  • app/core/service/PackageVersionFileService.ts
**/*.{ts,tsx}

πŸ“„ CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use strict TypeScript with comprehensive type definitions - avoid any types, use proper typing or unknown
Export types and interfaces for reusability in TypeScript

Files:

  • app/core/service/PackageVersionFileService.ts
app/core/service/**/*.ts

πŸ“„ CodeRabbit inference engine (.github/copilot-instructions.md)

app/core/service/**/*.ts: Services must implement core business logic without HTTP concerns or direct database access
Services must use @SingletonProto() for service lifecycle management
Services must orchestrate multiple repositories and entities, managing transactions and events

Files:

  • app/core/service/PackageVersionFileService.ts
**/*.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

**/*.ts: Use strict TypeScript with proper typing - avoid any types, use proper typing or unknown instead
Use ES modules with import/export syntax throughout the codebase
Use single quotes (') for strings
Use 2-space indentation
Enforce 120 character line width
Use ES5 trailing commas
Limit functions to a maximum of 6 parameters
Do not use console statements - use logger instead

Files:

  • app/core/service/PackageVersionFileService.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: Agent
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: test on mysql (node@24, shard@2/3, enableJSONBuilder@false)
  • GitHub Check: test on mysql (node@20, shard@0/3, enableJSONBuilder@false)
  • GitHub Check: test on mysql (node@24, shard@1/3, enableJSONBuilder@true)
  • GitHub Check: test on mysql (node@20, shard@0/3, enableJSONBuilder@true)
  • GitHub Check: test on mysql (node@24, shard@0/3, enableJSONBuilder@true)
  • GitHub Check: test on mysql (node@22, shard@1/3, enableJSONBuilder@false)
  • GitHub Check: test on mysql (node@24, shard@2/3, enableJSONBuilder@true)
  • GitHub Check: test on postgresql (node@22, shard@1/3)
  • GitHub Check: test on postgresql (node@22, shard@0/3)
  • GitHub Check: test on postgresql (node@22, shard@2/3)
  • GitHub Check: test on postgresql (node@20, shard@1/3)
  • GitHub Check: test on postgresql (node@24, shard@2/3)
  • GitHub Check: test on postgresql (node@20, shard@2/3)
  • GitHub Check: test on postgresql (node@20, shard@0/3)
  • GitHub Check: test on postgresql (node@24, shard@0/3)
  • GitHub Check: test on postgresql (node@24, shard@1/3)
  • GitHub Check: build-and-push-image

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for allowing large packages at the scope level through the unpkg white list configuration. Previously, only individual packages could be whitelisted for large size allowances via allowLargePackages, but now entire scopes can be whitelisted using the new allowLargeScopes array.

Key changes:

  • Added scope-level large package allowance checking to complement the existing package-level checking
  • Modified the white list loading logic to include the new allowLargeScopes field from the manifest
  • Updated the isAllowLargePackageVersion method to check scopes before checking individual packages
Comments suppressed due to low confidence (1)

app/core/service/PackageVersionFileService.ts:128

  • The logger.info message on line 122-127 should be updated to include the count of allowLargeScopes. The message currently logs "total %s packages, %s scopes, %s large packages" but doesn't include information about the newly introduced allowLargeScopes field. This makes it inconsistent with the data being loaded and harder to debug/monitor the white list configuration.

Consider updating the log message to include the allowLargeScopes count, similar to how allowScopes is logged.

    this.logger.info(
      '[PackageVersionFileService.updateUnpkgWhiteList] version:%s, total %s packages, %s scopes, %s large packages',
      whiteListPackageVersion,
      Object.keys(this.#unpkgWhiteListAllowPackages).length,
      this.#unpkgWhiteListAllowScopes.length,
      Object.keys(this.#unpkgWhiteListAllowLargePackages).length,
    );

Comment on lines +135 to +136
// check allow large scopes
if (this.#unpkgWhiteListAllowLargeScopes.includes(pkgScope)) return true;
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

The new allowLargeScopes feature lacks test coverage. While the isAllowLargePackageVersion method is mocked in some tests, there are no tests that verify the scope-level large package allowance functionality works correctly.

Tests should verify:

  1. Packages from scopes in allowLargeScopes are allowed regardless of size
  2. The scope check happens before the individual package check
  3. The allowLargeScopes field is correctly loaded from the manifest

Looking at the existing test patterns in test/port/controller/PackageVersionFileController/listFiles.test.ts, similar tests should be added for the allowLargeScopes functionality.

Copilot uses AI. Check for mistakes.
@elrrrrrrr elrrrrrrr merged commit ab98ddc into master Dec 13, 2025
42 checks passed
@elrrrrrrr elrrrrrrr deleted the allow-large-scopes branch December 13, 2025 12:43
fengmk2 pushed a commit that referenced this pull request Dec 13, 2025
[skip ci]

## <small>4.16.1 (2025-12-13)</small>

* fix: support allow large check from scopes level (#927) ([ab98ddc](ab98ddc)), closes [#927](#927) [hi#level](https://github.com/hi/issues/level)
@github-actions
Copy link

πŸŽ‰ This PR is included in version 4.16.1 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 95.26%. Comparing base (a631fad) to head (05cf085).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #927      +/-   ##
==========================================
- Coverage   95.37%   95.26%   -0.12%     
==========================================
  Files         197      197              
  Lines       22205    22211       +6     
  Branches     2058     2454     +396     
==========================================
- Hits        21179    21160      -19     
- Misses       1026     1051      +25     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants