Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should redirect when nfs adapter support url #522

Merged
merged 3 commits into from
Jun 17, 2023

Conversation

hezhengxu2018
Copy link
Collaborator

@hezhengxu2018 hezhengxu2018 commented Jun 17, 2023

will check package version on database before redirect to nfs store url

closes #521

@codecov
Copy link

codecov bot commented Jun 17, 2023

Codecov Report

Merging #522 (7375d74) into master (f64e273) will decrease coverage by 0.08%.
The diff coverage is 84.61%.

@@            Coverage Diff             @@
##           master     #522      +/-   ##
==========================================
- Coverage   97.08%   97.00%   -0.08%     
==========================================
  Files         174      174              
  Lines       16518    16538      +20     
  Branches     2160     2162       +2     
==========================================
+ Hits        16036    16043       +7     
- Misses        482      495      +13     
Impacted Files Coverage Δ
app/core/service/PackageManagerService.ts 98.86% <80.00%> (-0.40%) ⬇️
app/port/controller/AbstractController.ts 98.95% <100.00%> (ø)
...rt/controller/package/DownloadPackageVersionTar.ts 95.89% <100.00%> (+0.11%) ⬆️

... and 2 files with indirect coverage changes

@fengmk2 fengmk2 self-assigned this Jun 17, 2023
@fengmk2 fengmk2 added the bug Something isn't working label Jun 17, 2023
Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

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

+1

@@ -222,6 +242,7 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
.expect(302)
.expect('location', 'https://registry.npmjs.org/foo/-/foo-1.0.404404.tgz?t=123');

mock(app.config.cnpmcore, 'redirectNotFound', false);
// not redirect when package exists
await app.httpRequest()
.get(`/${name}/-/${name}-1.0.404404.tgz`)

Choose a reason for hiding this comment

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

这段代码是一个测试用例,主要负责测试当包版本不存在时的行为。建议在代码审查中注重以下几点:

  1. 确认该测试涵盖了所有可能情况

  2. 检查是否需要提供更多的上下文或者注释来帮助理解该测试

  3. 评估该测试的可读性和可维护性,包括变量和方法命名的清晰度以及代码格式的一致性

  4. 确保在修改代码时更新相应的测试用例,并考虑是否需要新增测试用例

在这个具体的代码片段中,测试增加了针对未发布版本的测试,还模拟了 redirectNotFound 和 url 方法。有两个测试用例被添加到测试套件中,一个测试了包版本不存在时的 404 响应,另一个则确保了当指定源注册表时,CNPM 应该将其重定向到该源。

目前代码看起来没有风险和改进的地方。

@@ -176,6 +177,25 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
});
});

it('should redirect to source registry when package version not exists', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

我补了一个单测

@fengmk2 fengmk2 merged commit 3d6864c into master Jun 17, 2023
@fengmk2 fengmk2 deleted the fix-should-redirect-when-nfs-adapter-support-url branch June 17, 2023 16:02
fengmk2 pushed a commit that referenced this pull request Jun 17, 2023
[skip ci]

## [3.34.2](v3.34.1...v3.34.2) (2023-06-17)

### Bug Fixes

* should redirect when nfs adapter support url ([#522](#522)) ([3d6864c](3d6864c))
@@ -33,15 +33,17 @@ export class DownloadPackageVersionTarController extends AbstractController {
const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion);
const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`;
const downloadUrl = await this.nfsAdapter.getDownloadUrl(storeKey);
// check package version in database
Copy link
Member

Choose a reason for hiding this comment

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

这个改动会导致 registry.npmmirror.com 出现大量 db 查询,我先加一个开关

Copy link
Member

Choose a reason for hiding this comment

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

fengmk2 pushed a commit that referenced this pull request Jun 20, 2023
[skip ci]

## [3.34.4](v3.34.3...v3.34.4) (2023-06-20)

### Bug Fixes

* avoid db query on sync mode all ([#527](#527)) ([49855d9](49855d9)), closes [/github.com//pull/522/files#r1234655574](https://github.com/cnpm//github.com/cnpm/cnpmcore/pull/522/files/issues/r1234655574)
@@ -33,15 +33,17 @@ export class DownloadPackageVersionTarController extends AbstractController {
const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion);
const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`;
Copy link
Contributor

Choose a reason for hiding this comment

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

原来这里已经有跳过 db 直接访问 oss 的逻辑,计算 semver 逻辑里一样可以跳过了。

本来还单性可能 oss path 发生变化的情况。

hezhengxu2018 pushed a commit that referenced this pull request Jun 20, 2023
[skip ci]

## [3.34.4](v3.34.3...v3.34.4) (2023-06-20)

### Bug Fixes

* avoid db query on sync mode all ([#527](#527)) ([49855d9](49855d9)), closes [/github.com//pull/522/files#r1234655574](https://github.com/cnpm//github.com/cnpm/cnpmcore/pull/522/files/issues/r1234655574)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

访问tgz文件时也应该redirectNotFound
3 participants