test: enable test shard (#839)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Improved CI parallelization and shard-aware job naming for faster,
clearer test runs.

* **Bug Fixes**
* More robust handling of binary paths and change-stream edge cases to
reduce rare failures.
* Prevented unintended data mutation and tightened minor
version-handling resilience.

* **Chores**
  * Streamlined test scripts and updated dependency resolution.
* Added Prettier ignore rules, relaxed selected lint rules, and small
build script formatting cleanup.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
MK (fengmk2)
2025-10-07 22:14:14 +08:00
committed by GitHub
parent 2e51399db1
commit 324511d159
12 changed files with 85 additions and 36 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/sh
node -v && npm -v
npm install -g npminstall --registry=https://registry.npmmirror.com \
&& npminstall -c \
node -v && npm -v \
&& npm install -g npminstall --registry=https://registry.npmmirror.com \
&& NODE_DEBUG=egg-bin*,egg/bin* npminstall -c --foreground-scripts \
&& npm run tsc \
&& npmupdate -c --production

View File

@@ -11,7 +11,42 @@ on:
merge_group:
jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout Git Source
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Dependencies
run: npm i -g npminstall && npminstall
- name: Lint
run: npm run lint
- name: Typecheck
run: npm run typecheck
- name: Build
run: npm run tsc && npm run tsc:prod
test-postgresql-fs-nfs:
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
os: [ubuntu-latest]
# 0-based index
shardIndex: [0, 1, 2]
shardTotal: [3]
name: test on postgresql (node@${{ matrix.node-version }}, shard@${{ matrix.shardIndex }}/${{ matrix.shardTotal }})
runs-on: ${{ matrix.os }}
services:
@@ -39,12 +74,6 @@ jobs:
# Opens tcp port 6379 on the host and service container
- 6379:6379
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
os: [ubuntu-latest]
steps:
- name: Checkout Git Source
uses: actions/checkout@v4
@@ -90,6 +119,9 @@ jobs:
POSTGRES_PORT: 5432
CNPMCORE_CONFIG_ENABLE_ES: true
CNPMCORE_CONFIG_ES_CLIENT_NODES: http://localhost:9200
# https://github.com/jamiebuilds/ci-parallel-vars
CI_NODE_INDEX: ${{ matrix.shardIndex }}
CI_NODE_TOTAL: ${{ matrix.shardTotal }}
- name: Code Coverage
uses: codecov/codecov-action@v5
@@ -97,6 +129,17 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
test-mysql57-fs-nfs:
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
os: [ubuntu-latest]
# 0-based index
shardIndex: [0, 1, 2]
shardTotal: [3]
name: test on mysql (node@${{ matrix.node-version }}, shard@${{ matrix.shardIndex }}/${{ matrix.shardTotal }})
runs-on: ${{ matrix.os }}
services:
@@ -115,12 +158,6 @@ jobs:
# Opens tcp port 6379 on the host and service container
- 6379:6379
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
os: [ubuntu-latest]
steps:
- name: Checkout Git Source
uses: actions/checkout@v4
@@ -135,6 +172,10 @@ jobs:
- name: Continuous Integration
run: npm run ci
env:
# https://github.com/jamiebuilds/ci-parallel-vars
CI_NODE_INDEX: ${{ matrix.shardIndex }}
CI_NODE_TOTAL: ${{ matrix.shardTotal }}
- name: Code Coverage
uses: codecov/codecov-action@v5
@@ -142,6 +183,13 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
test-mysql57-s3-nfs:
if: ${{ github.ref_name == 'master' }}
strategy:
fail-fast: false
matrix:
node-version: [20, 22]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
services:
@@ -159,12 +207,6 @@ jobs:
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
node-version: [20, 22]
os: [ubuntu-latest]
steps:
- name: Checkout Git Source
uses: actions/checkout@v4

View File

@@ -16,7 +16,9 @@
"new-cap": "allow",
"class-methods-use-this": "allow",
"import/no-named-export": "allow",
"unicorn/no-array-sort": "allow"
"unicorn/no-array-sort": "allow",
"no-param-reassign": "allow",
"unicorn/prefer-at": "allow"
},
"ignorePatterns": ["index.d.ts"]
}

4
.prettierignore Normal file
View File

@@ -0,0 +1,4 @@
CHANGELOG.md
__snapshots__
pnpm-lock.yaml
node_modules

View File

@@ -92,7 +92,7 @@ export class FirefoxBinary extends AbstractBinary {
if (href.startsWith('/')) {
// Extract the last part of the path
const parts = href.split('/').filter(Boolean);
name = parts[parts.length - 1];
name = parts[parts.length - 1] ?? '';
if (href.endsWith('/')) {
name += '/';
}

View File

@@ -54,7 +54,7 @@ export class CnpmjsorgChangesStream extends AbstractChangeStream {
if (results?.length >= limit) {
const [first] = results;
const last = results[results.length - 1];
if (first.gmt_modified === last.gmt_modified) {
if (first.gmt_modified === last?.gmt_modified) {
return await this.tryFetch(registry, since, limit + 1000);
}
}

View File

@@ -15,15 +15,15 @@ export class FixNoPaddingVersionService {
private readonly logger: EggLogger;
async fixPaddingVersion(id?: number): Promise<void> {
// eslint-disable-next-line no-constant-condition
while (true) {
const packageVersions =
await this.packageVersionRepository.findHaveNotPaddingVersion(id);
if (packageVersions.length === 0) {
break;
}
const lastVersion = packageVersions[packageVersions.length - 1];
id =
(packageVersions[packageVersions.length - 1].id as unknown as number) +
(lastVersion.id as unknown as number) +
1;
this.logger.info(
'[FixNoPaddingVersionService] fix padding version ids %j',

View File

@@ -165,6 +165,7 @@ export class PackageVersionFileController extends AbstractController {
ctx.tValidate(Spec, `${fullname}@${versionSpec}`);
ctx.vary(this.config.cnpmcore.cdnVaryHeader);
const [scope, name] = getScopeAndName(fullname);
// oxlint-disable-next-line no-param-reassign
path = `/${path}`;
const packageVersion = await this.#getPackageVersion(
ctx,

View File

@@ -117,6 +117,7 @@ export class SavePackageVersionController extends AbstractController {
this.validateNpmCommand(ctx);
ctx.tValidate(FullPackageRule, pkg);
const { user } = await this.ensurePublishAccess(ctx, fullname, false);
// oxlint-disable-next-line no-param-reassign
fullname = fullname.trim();
if (fullname !== pkg.name) {
throw new UnprocessableEntityError(

View File

@@ -117,7 +117,7 @@ export class ModelConvertor {
entityClazz: EggProtoImplClass<T>,
data?: object
): T {
data = data || {};
const entityData = data ?? {};
const ModelClazz = bone.constructor as EggProtoImplClass;
const metadata = ModelMetadataUtil.getModelMetadata(ModelClazz);
if (!metadata) {
@@ -131,9 +131,9 @@ export class ModelConvertor {
);
const attributeValue =
bone[attributeMeta.propertyName as keyof LeoricBone];
lodashSet(data, entityPropertyName, attributeValue);
lodashSet(entityData, entityPropertyName, attributeValue);
}
const model = Reflect.construct(entityClazz, [data]);
const model = Reflect.construct(entityClazz, [entityData]);
return model;
}
}

View File

@@ -42,11 +42,11 @@
"lint": "oxlint",
"lint:fix": "npm run lint -- --fix",
"typecheck": "tsc --noEmit",
"test:postgresql": "npm run lint && npm run test:local:postgresql",
"test:postgresql": "npm run test:local:postgresql",
"pretest:local:postgresql": "bash prepare-database-postgresql.sh",
"test:local:postgresql": "CNPMCORE_DATABASE_TYPE=PostgreSQL egg-bin test",
"pretest": "npm run clean",
"test": "npm run lint && npm run typecheck && npm run test:local",
"test": "npm run test:local",
"pretest:local": "bash prepare-database-mysql.sh",
"test:local": "egg-bin test",
"pret": "bash prepare-database-mysql.sh",
@@ -55,10 +55,8 @@
"cov": "egg-bin cov",
"precov:postgresql": "bash prepare-database-postgresql.sh",
"cov:postgresql": "CNPMCORE_DATABASE_TYPE=PostgreSQL egg-bin cov",
"preci": "npm run clean && npm run lint && npm run typecheck",
"ci": "npm run cov ",
"postci": "npm run tsc:prod && npm run clean",
"ci:postgresql": "npm run lint && npm run cov:postgresql && npm run tsc:prod && npm run clean",
"ci": "npm run cov",
"ci:postgresql": "npm run cov:postgresql",
"clean": "tsc -b --clean && rm -rf dist *.tsbuildinfo",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc:prod": "npm run clean && tsc -p ./tsconfig.prod.json",
@@ -90,7 +88,7 @@
},
"dependencies": {
"@eggjs/redis": "beta",
"@eggjs/scripts": "^4.0.0",
"@eggjs/scripts": "beta",
"@eggjs/tegg": "beta",
"@eggjs/tegg-aop-plugin": "beta",
"@eggjs/tegg-background-task": "beta",

View File

@@ -1,6 +1,7 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
// leoric only supports ES2021
"target": "ES2021",
"resolveJsonModule": true,
"useUnknownInCatchVariables": false,