@whyour/qinglong 2.21.0-8 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +13 -0
- package/.env.example +7 -0
- package/AGENTS.md +2 -2
- package/README-en.md +24 -0
- package/README.md +24 -0
- package/back/protos/api.proto +6 -1
- package/back/protos/cron.proto +4 -1
- package/docker/Dockerfile +31 -12
- package/docker/Dockerfile.310 +31 -12
- package/docker/Dockerfile.debian +22 -14
- package/docker/Dockerfile.debian310 +24 -14
- package/docker/build-manifest.cjs +28 -0
- package/docker/verify-build.cjs +49 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +54 -0
- package/ecosystem.config.js +10 -1
- package/package.json +11 -6
- package/sample/config.sample.sh +10 -0
- package/sample/notify.js +54 -0
- package/sample/notify.py +37 -0
- package/scripts/benchmark-execution.cjs +96 -0
- package/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +34 -13
- package/shell/check.sh +59 -19
- package/shell/lang/en.sh +6 -0
- package/shell/lang/zh.sh +6 -0
- package/shell/node_path_cache.sh +128 -0
- package/shell/otask.sh +7 -1
- package/shell/preload/sitecustomize.js +5 -1
- package/shell/share.sh +25 -8
- package/shell/start.sh +6 -3
- package/shell/task.sh +13 -3
- package/shell/update.sh +65 -4
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +8 -16
- package/static/build/api/cron.js +38 -2
- package/static/build/api/dashboard.js +37 -0
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +30 -19
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +23 -22
- package/static/build/api/subscription.js +16 -2
- package/static/build/api/system.js +25 -2
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +54 -45
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +1 -0
- package/static/build/config/share.js +5 -4
- package/static/build/config/util.js +133 -38
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +11 -1
- package/static/build/loaders/app.js +2 -0
- package/static/build/loaders/db.js +3 -33
- package/static/build/loaders/deps.js +29 -0
- package/static/build/loaders/express.js +30 -21
- package/static/build/loaders/initData.js +10 -7
- package/static/build/loaders/sock.js +72 -6
- package/static/build/middlewares/monitoring.js +12 -33
- package/static/build/middlewares/protectedPathCase.js +17 -0
- package/static/build/protos/api.js +56 -2
- package/static/build/protos/cron.js +21 -4
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +9 -0
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +38 -6
- package/static/build/schedule/health.js +72 -7
- package/static/build/services/config.js +5 -42
- package/static/build/services/cron.js +338 -199
- package/static/build/services/dependence.js +47 -0
- package/static/build/services/grpc.js +1 -1
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +8 -2
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +26 -0
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +57 -33
- package/static/build/services/script.js +4 -5
- package/static/build/services/subscription.js +55 -34
- package/static/build/services/system.js +37 -9
- package/static/build/services/user.js +213 -25
- package/static/build/shared/auth.js +18 -5
- package/static/build/shared/authMutation.js +17 -0
- package/static/build/shared/childProcess.js +82 -0
- package/static/build/shared/clientIp.js +27 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +12 -5
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +28 -15
- package/static/build/shared/schedulerMutationLock.js +44 -0
- package/static/build/shared/schedulerReadiness.js +82 -0
- package/static/build/shared/schemaMigrations.js +58 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -0
- package/static/build/shared/trustProxy.js +119 -0
- package/static/build/validation/schedule.js +3 -3
- package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
- package/static/dist/2031.6af40025.async.js +1 -0
- package/static/dist/2693.51c2636b.async.js +1 -0
- package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
- package/static/dist/2901.2ca95295.async.js +1 -0
- package/static/dist/445.a65ff63b.async.js +1 -0
- package/static/dist/4736.1d2b5cb6.async.js +1 -0
- package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
- package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
- package/static/dist/6212.9e6d9913.async.js +1 -0
- package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
- package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
- package/static/dist/7231.f7e5b668.async.js +1 -0
- package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
- package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
- package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
- package/static/dist/8844.a0fef08e.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/layouts__index.633d3553.async.js +1 -0
- package/static/dist/preload_helper.cf7de3fa.js +1 -0
- package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
- package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
- package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
- package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
- package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
- package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
- package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
- package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
- package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
- package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
- package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
- package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
- package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
- package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
- package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
- package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
- package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
- package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
- package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
- package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
- package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
- package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
- package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
- package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
- package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
- package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
- package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
- package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
- package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
- package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
- package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
- package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
- package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
- package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
- package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/cron-log-name.test.cjs +110 -0
- package/test/back/cron-validation.test.cjs +45 -0
- package/test/back/dashboard-failures.test.cjs +173 -0
- package/test/back/database-bootstrap.test.cjs +193 -0
- package/test/back/dependence-cache-status.test.cjs +125 -0
- package/test/back/deprecated-file-routes.test.cjs +82 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-name-parsing.test.cjs +96 -0
- package/test/back/execution-lifecycle.test.cjs +236 -0
- package/test/back/file-access-security.test.cjs +47 -0
- package/test/back/fileTreeListing.test.cjs +57 -0
- package/test/back/grpc-cron-response.test.cjs +60 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +213 -0
- package/test/back/listen-security.test.cjs +67 -0
- package/test/back/log-path-security.test.cjs +158 -0
- package/test/back/logReader.test.cjs +72 -0
- package/test/back/manual-execution.test.cjs +85 -0
- package/test/back/manual-stop-claim.test.cjs +220 -0
- package/test/back/metrics.test.cjs +34 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-path-cache.test.cjs +173 -0
- package/test/back/node-path-lock.test.cjs +178 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/primary-apm.test.cjs +24 -0
- package/test/back/process-exit-state.test.cjs +81 -0
- package/test/back/process-stop-signal.test.cjs +77 -0
- package/test/back/protected-path-case.test.cjs +58 -0
- package/test/back/qlServiceLogCommand.test.cjs +128 -0
- package/test/back/retention.test.cjs +131 -0
- package/test/back/role-loading.test.cjs +118 -0
- package/test/back/schedule-health.test.cjs +86 -0
- package/test/back/scheduler-file-lock.test.cjs +51 -0
- package/test/back/scheduler-mutation.test.cjs +312 -0
- package/test/back/scheduler-readiness.test.cjs +85 -0
- package/test/back/scheduler-reconciliation.test.cjs +152 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- package/test/back/shell-api-parsing.test.cjs +184 -0
- package/test/back/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +167 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/system-dependence-cache.test.cjs +126 -0
- package/test/back/task-time.test.cjs +116 -0
- package/test/back/user-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +248 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +115 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/version.yaml +19 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.62793604.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2208.85285476.async.js +0 -1
- package/static/dist/2286.f371c743.async.js +0 -1
- package/static/dist/3191.545ab873.async.js +0 -1
- package/static/dist/4902.555f92ab.async.js +0 -1
- package/static/dist/5520.ff2cfd6b.async.js +0 -1
- package/static/dist/6431.c50479be.async.js +0 -1
- package/static/dist/8826.db34ad8d.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.3048fe5b.js +0 -1
- package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
- package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
- package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
- package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
- package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
- package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
- package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
- package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
- package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
- package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
- package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
- package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
- package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
- package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
- package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
- package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
- package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
- package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
- package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
- package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
5
|
+
const logger = { debug() {}, warn() {}, error() {} };
|
|
6
|
+
|
|
7
|
+
for (const host of ['127.0.0.1', '::1', '192.0.2.1', '::']) {
|
|
8
|
+
test(`HTTP binding ${host} never broadens an explicit private address`, async () => {
|
|
9
|
+
const Http = load(path.join(__dirname, '../../back/services/http.ts'), {
|
|
10
|
+
'../config': { bindHost: host },
|
|
11
|
+
'../loaders/logger': logger,
|
|
12
|
+
'./metrics': { metricsService: { record() {} } },
|
|
13
|
+
typedi: { Service: () => (x) => x },
|
|
14
|
+
}).HttpServerService;
|
|
15
|
+
const instance = new Http();
|
|
16
|
+
const attempted = [];
|
|
17
|
+
instance.tryListen = async (_app, _port, address) => {
|
|
18
|
+
attempted.push(address);
|
|
19
|
+
throw new Error('unavailable');
|
|
20
|
+
};
|
|
21
|
+
await assert.rejects(instance.initialize({}, 5700));
|
|
22
|
+
assert.deepEqual(attempted, host === '::' ? ['::', '0.0.0.0'] : [host]);
|
|
23
|
+
});
|
|
24
|
+
test(`gRPC binding ${host} never broadens an explicit private address`, async () => {
|
|
25
|
+
const attempted = [];
|
|
26
|
+
const Grpc = load(path.join(__dirname, '../../back/services/grpc.ts'), {
|
|
27
|
+
'../config': { bindHostGrpc: host, grpcPort: 5500 },
|
|
28
|
+
'../loaders/logger': logger,
|
|
29
|
+
'./metrics': { metricsService: { record() {} } },
|
|
30
|
+
typedi: { Service: () => (x) => x },
|
|
31
|
+
'@grpc/grpc-js': {
|
|
32
|
+
Server: class {
|
|
33
|
+
addService() {}
|
|
34
|
+
bindAsync(address, _credentials, cb) {
|
|
35
|
+
attempted.push(address);
|
|
36
|
+
cb(new Error('unavailable'));
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
ServerCredentials: {
|
|
40
|
+
createSsl(_ca, _certs, requireClientCert) {
|
|
41
|
+
assert.equal(requireClientCert, true);
|
|
42
|
+
return {};
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
'../protos/cron': { CronService: {} },
|
|
47
|
+
'../protos/health': { HealthService: {} },
|
|
48
|
+
'../protos/api': { ApiService: {} },
|
|
49
|
+
'../schedule/addCron': {},
|
|
50
|
+
'../schedule/delCron': {},
|
|
51
|
+
'../schedule/health': {},
|
|
52
|
+
'../schedule/api': {},
|
|
53
|
+
'../config/grpcCerts': {
|
|
54
|
+
initGrpcCerts: async () => ({
|
|
55
|
+
caCert: 'test',
|
|
56
|
+
serverCert: 'test',
|
|
57
|
+
serverKey: 'test',
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
}).GrpcServerService;
|
|
61
|
+
await assert.rejects(new Grpc().initialize());
|
|
62
|
+
assert.deepEqual(
|
|
63
|
+
attempted,
|
|
64
|
+
host === '::' ? ['[::]:5500', '0.0.0.0:5500'] : [`${host}:5500`],
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
7
|
+
const { LogStreamManager } = require('../../back/shared/logStreamManager');
|
|
8
|
+
|
|
9
|
+
async function fixture(t) {
|
|
10
|
+
const base = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-log-boundary-'));
|
|
11
|
+
t.after(() => fs.rm(base, { recursive: true, force: true }));
|
|
12
|
+
const root = path.join(base, 'log');
|
|
13
|
+
const outside = path.join(base, 'log-other');
|
|
14
|
+
await fs.mkdir(root);
|
|
15
|
+
await fs.mkdir(outside);
|
|
16
|
+
const victim = path.join(outside, 'victim.log');
|
|
17
|
+
await fs.writeFile(victim, 'unchanged');
|
|
18
|
+
await fs.symlink(outside, path.join(root, 'escape-dir'));
|
|
19
|
+
await fs.symlink(victim, path.join(root, 'escape-file'));
|
|
20
|
+
await fs.symlink(
|
|
21
|
+
path.join(outside, 'missing.log'),
|
|
22
|
+
path.join(root, 'dangling'),
|
|
23
|
+
);
|
|
24
|
+
const invalid = [
|
|
25
|
+
path.join(root, '..', 'log-other', 'new.log'),
|
|
26
|
+
path.join(root, 'escape-dir', 'new.log'),
|
|
27
|
+
path.join(root, 'escape-file'),
|
|
28
|
+
path.join(root, 'dangling'),
|
|
29
|
+
root,
|
|
30
|
+
path.join(root, 'bad\0name'),
|
|
31
|
+
];
|
|
32
|
+
return { root, outside, victim, invalid };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test('log streams reject traversal, sibling prefixes and escaping symlinks before writing', async (t) => {
|
|
36
|
+
const { root, outside, victim, invalid } = await fixture(t);
|
|
37
|
+
const manager = new LogStreamManager(root);
|
|
38
|
+
for (const target of invalid) {
|
|
39
|
+
await assert.rejects(
|
|
40
|
+
manager.write(target, 'overwrite'),
|
|
41
|
+
/outside the log directory/,
|
|
42
|
+
);
|
|
43
|
+
await assert.rejects(
|
|
44
|
+
manager.closeStream(target),
|
|
45
|
+
/outside the log directory/,
|
|
46
|
+
);
|
|
47
|
+
assert.equal(manager.getOpenStreamCount(), 0);
|
|
48
|
+
}
|
|
49
|
+
assert.equal(await fs.readFile(victim, 'utf8'), 'unchanged');
|
|
50
|
+
assert.deepEqual(await fs.readdir(outside), ['victim.log']);
|
|
51
|
+
const folder = path.join(root, '中文 日志');
|
|
52
|
+
await fs.mkdir(folder);
|
|
53
|
+
const log = path.join(folder, 'task.log');
|
|
54
|
+
await Promise.all([
|
|
55
|
+
manager.write(log, '开始\n'),
|
|
56
|
+
manager.write(log, '结束\n'),
|
|
57
|
+
]);
|
|
58
|
+
await manager.closeAll();
|
|
59
|
+
assert.equal(await fs.readFile(log, 'utf8'), '开始\n结束\n');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('log initialization rejects unsafe paths before mkdir or file writes', async (t) => {
|
|
63
|
+
const { root, outside, victim, invalid } = await fixture(t);
|
|
64
|
+
const { handleLogPath } = load(path.resolve('back/config/util.ts'), {
|
|
65
|
+
'./index': { logPath: root },
|
|
66
|
+
'./share': {},
|
|
67
|
+
'../loaders/logger': {},
|
|
68
|
+
'../shared/utils': {
|
|
69
|
+
writeFileWithLock: (file, data) => fs.writeFile(file, data),
|
|
70
|
+
},
|
|
71
|
+
'../data/dependence': { DependenceTypes: {} },
|
|
72
|
+
});
|
|
73
|
+
for (const target of invalid) {
|
|
74
|
+
await assert.rejects(
|
|
75
|
+
handleLogPath(target, 'overwrite'),
|
|
76
|
+
/outside the log directory/,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
await assert.rejects(
|
|
80
|
+
handleLogPath('../log-other/new/sub/task.log', 'overwrite'),
|
|
81
|
+
/outside the log directory/,
|
|
82
|
+
);
|
|
83
|
+
assert.equal(await fs.readFile(victim, 'utf8'), 'unchanged');
|
|
84
|
+
assert.deepEqual(await fs.readdir(outside), ['victim.log']);
|
|
85
|
+
const log = await handleLogPath('中文 日志/nested/task.log', 'initial');
|
|
86
|
+
assert.equal(await fs.readFile(log, 'utf8'), 'initial');
|
|
87
|
+
assert.equal(await handleLogPath(log, 'ignored'), log);
|
|
88
|
+
assert.equal(await fs.readFile(log, 'utf8'), 'initial');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('manual execution rejects escaping log names before creating directories or spawning', async (t) => {
|
|
92
|
+
const { root, outside, victim } = await fixture(t);
|
|
93
|
+
let spawned = 0;
|
|
94
|
+
let releases = 0;
|
|
95
|
+
const errors = [];
|
|
96
|
+
const CronService = load(path.resolve('back/services/cron.ts'), {
|
|
97
|
+
'../config': { logPath: root },
|
|
98
|
+
'../data/cron': {
|
|
99
|
+
CrontabStatus: { queued: 3, idle: 1 },
|
|
100
|
+
CrontabModel: { update: async () => {} },
|
|
101
|
+
},
|
|
102
|
+
'../data/runningInstance': { RunningInstanceModel: {}, InstanceStatus: {} },
|
|
103
|
+
'../config/util': {},
|
|
104
|
+
'../config/const': {},
|
|
105
|
+
'../schedule/client': {},
|
|
106
|
+
'../shared/pLimit': {
|
|
107
|
+
manualRunWithCronLimit: async (fn) => {
|
|
108
|
+
try {
|
|
109
|
+
return await fn();
|
|
110
|
+
} finally {
|
|
111
|
+
releases++;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
'../shared/utils': {},
|
|
116
|
+
'../shared/i18n': { t: (s) => s },
|
|
117
|
+
'../shared/logReader': {},
|
|
118
|
+
'../shared/logStreamManager': {
|
|
119
|
+
logStreamManager: { closeStream: async () => {} },
|
|
120
|
+
},
|
|
121
|
+
'cross-spawn': {
|
|
122
|
+
spawn: () => {
|
|
123
|
+
spawned++;
|
|
124
|
+
throw new Error('must not spawn');
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
}).default;
|
|
128
|
+
const service = new CronService({
|
|
129
|
+
info() {},
|
|
130
|
+
error: (...args) => errors.push(args),
|
|
131
|
+
});
|
|
132
|
+
for (const log_name of [
|
|
133
|
+
'../log-other/new',
|
|
134
|
+
outside,
|
|
135
|
+
'escape-dir/new',
|
|
136
|
+
'dangling',
|
|
137
|
+
'bad\0name',
|
|
138
|
+
]) {
|
|
139
|
+
service.getDb = async () => ({
|
|
140
|
+
id: 1,
|
|
141
|
+
status: 3,
|
|
142
|
+
command: 'ignored',
|
|
143
|
+
log_path: '',
|
|
144
|
+
log_name,
|
|
145
|
+
});
|
|
146
|
+
await service.runSingle(1);
|
|
147
|
+
}
|
|
148
|
+
assert.equal(spawned, 0);
|
|
149
|
+
assert.equal(releases, 5);
|
|
150
|
+
assert.equal(
|
|
151
|
+
errors.filter((args) =>
|
|
152
|
+
args.includes('Log path is outside the log directory'),
|
|
153
|
+
).length,
|
|
154
|
+
5,
|
|
155
|
+
);
|
|
156
|
+
assert.equal(await fs.readFile(victim, 'utf8'), 'unchanged');
|
|
157
|
+
assert.deepEqual(await fs.readdir(outside), ['victim.log']);
|
|
158
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs/promises');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const test = require('node:test');
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
DEFAULT_LOG_CHUNK_BYTES,
|
|
9
|
+
MAX_LOG_CHUNK_BYTES,
|
|
10
|
+
readLogChunk,
|
|
11
|
+
} = require('../../back/shared/logReader');
|
|
12
|
+
|
|
13
|
+
test('log reader defaults to a bounded tail and supports incremental reads', async (t) => {
|
|
14
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-log-reader-'));
|
|
15
|
+
const file = path.join(directory, 'task.log');
|
|
16
|
+
t.after(() => fs.rm(directory, { recursive: true, force: true }));
|
|
17
|
+
|
|
18
|
+
const initial = 'a'.repeat(DEFAULT_LOG_CHUNK_BYTES * 2);
|
|
19
|
+
await fs.writeFile(file, initial);
|
|
20
|
+
|
|
21
|
+
const tail = await readLogChunk(file);
|
|
22
|
+
assert.equal(tail.content.length, DEFAULT_LOG_CHUNK_BYTES);
|
|
23
|
+
assert.equal(tail.offset, DEFAULT_LOG_CHUNK_BYTES);
|
|
24
|
+
assert.equal(tail.nextOffset, initial.length);
|
|
25
|
+
assert.equal(tail.truncated, true);
|
|
26
|
+
|
|
27
|
+
await fs.appendFile(file, 'next');
|
|
28
|
+
const incremental = await readLogChunk(file, { offset: tail.nextOffset });
|
|
29
|
+
assert.equal(incremental.content, 'next');
|
|
30
|
+
assert.equal(incremental.nextOffset, initial.length + 4);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('log reader enforces the maximum chunk size', async (t) => {
|
|
34
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-log-reader-'));
|
|
35
|
+
const file = path.join(directory, 'large.log');
|
|
36
|
+
t.after(() => fs.rm(directory, { recursive: true, force: true }));
|
|
37
|
+
await fs.writeFile(file, 'x'.repeat(MAX_LOG_CHUNK_BYTES + 1024));
|
|
38
|
+
|
|
39
|
+
const chunk = await readLogChunk(file, { limit: Number.MAX_SAFE_INTEGER });
|
|
40
|
+
assert.equal(Buffer.byteLength(chunk.content), MAX_LOG_CHUNK_BYTES);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('log reader preserves UTF-8 characters across byte boundaries', async (t) => {
|
|
44
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-log-reader-'));
|
|
45
|
+
const file = path.join(directory, 'utf8.log');
|
|
46
|
+
t.after(() => fs.rm(directory, { recursive: true, force: true }));
|
|
47
|
+
await fs.writeFile(file, 'a'.repeat(5) + '中文日志');
|
|
48
|
+
|
|
49
|
+
const first = await readLogChunk(file, { offset: 0, limit: 7 });
|
|
50
|
+
const second = await readLogChunk(file, {
|
|
51
|
+
offset: first.nextOffset,
|
|
52
|
+
limit: 7,
|
|
53
|
+
});
|
|
54
|
+
const third = await readLogChunk(file, {
|
|
55
|
+
offset: second.nextOffset,
|
|
56
|
+
limit: 7,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
assert.equal(first.content + second.content + third.content, 'aaaaa中文日志');
|
|
60
|
+
assert.equal((first.content + second.content + third.content).includes('�'), false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('missing logs return an empty chunk', async () => {
|
|
64
|
+
const chunk = await readLogChunk('/path/that/does/not/exist.log');
|
|
65
|
+
assert.deepEqual(chunk, {
|
|
66
|
+
content: '',
|
|
67
|
+
offset: 0,
|
|
68
|
+
nextOffset: 0,
|
|
69
|
+
total: 0,
|
|
70
|
+
truncated: false,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
8
|
+
const { LogStreamManager } = require('../../back/shared/logStreamManager');
|
|
9
|
+
|
|
10
|
+
test(
|
|
11
|
+
'manual execution captures a short child before slow status storage and flushes before release',
|
|
12
|
+
{ timeout: 5000 },
|
|
13
|
+
async (t) => {
|
|
14
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-manual-'));
|
|
15
|
+
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
|
16
|
+
const logs = new LogStreamManager(root);
|
|
17
|
+
const updates = [];
|
|
18
|
+
let active = 0;
|
|
19
|
+
let failSpawn = false;
|
|
20
|
+
const CronService = load(path.resolve('back/services/cron.ts'), {
|
|
21
|
+
'../config': { logPath: root },
|
|
22
|
+
'../data/cron': {
|
|
23
|
+
CrontabStatus: { queued: 3, running: 0, idle: 1 },
|
|
24
|
+
CrontabModel: {
|
|
25
|
+
update: async (data, options) => {
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
27
|
+
updates.push({ data, options });
|
|
28
|
+
return [1];
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
'../data/runningInstance': {
|
|
33
|
+
RunningInstanceModel: {},
|
|
34
|
+
InstanceStatus: {},
|
|
35
|
+
},
|
|
36
|
+
'../config/util': { getUniqPath: async () => 'task' },
|
|
37
|
+
'../config/const': { TASK_PREFIX: 'task ', QL_PREFIX: 'ql ' },
|
|
38
|
+
'../schedule/client': {},
|
|
39
|
+
'../shared/pLimit': {
|
|
40
|
+
manualRunWithCronLimit: async (fn) => {
|
|
41
|
+
active++;
|
|
42
|
+
try {
|
|
43
|
+
return await fn();
|
|
44
|
+
} finally {
|
|
45
|
+
active--;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
'../shared/utils': {},
|
|
50
|
+
'../shared/i18n': { t: (s) => s },
|
|
51
|
+
'../shared/logReader': {},
|
|
52
|
+
'../shared/logStreamManager': { logStreamManager: logs },
|
|
53
|
+
'cross-spawn': {
|
|
54
|
+
spawn: () =>
|
|
55
|
+
failSpawn
|
|
56
|
+
? spawn('true', { shell: '/nonexistent-ql-manual-shell' })
|
|
57
|
+
: spawn(process.execPath, [
|
|
58
|
+
'-e',
|
|
59
|
+
'process.stdout.write("末尾\\n")',
|
|
60
|
+
]),
|
|
61
|
+
},
|
|
62
|
+
}).default;
|
|
63
|
+
const service = new CronService({ info() {}, error() {} });
|
|
64
|
+
service.getDb = async () => ({
|
|
65
|
+
id: 1,
|
|
66
|
+
status: 3,
|
|
67
|
+
command: 'ignored',
|
|
68
|
+
log_path: '',
|
|
69
|
+
});
|
|
70
|
+
service.makeCommand = () => 'ignored';
|
|
71
|
+
await service.runSingle(1);
|
|
72
|
+
const [file] = await fs.readdir(path.join(root, 'task'));
|
|
73
|
+
assert.equal(
|
|
74
|
+
await fs.readFile(path.join(root, 'task', file), 'utf8'),
|
|
75
|
+
'末尾\n',
|
|
76
|
+
);
|
|
77
|
+
assert.equal(logs.getOpenStreamCount(), 0);
|
|
78
|
+
assert.equal(active, 0);
|
|
79
|
+
assert.equal(updates.at(-1).data.status, 1);
|
|
80
|
+
failSpawn = true;
|
|
81
|
+
await service.runSingle(1);
|
|
82
|
+
assert.equal(active, 0);
|
|
83
|
+
assert.equal(updates.at(-1).data.status, 1);
|
|
84
|
+
},
|
|
85
|
+
);
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const { once } = require('node:events');
|
|
8
|
+
const { Sequelize, DataTypes } = require('sequelize');
|
|
9
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
10
|
+
const { killTask } = require('../../back/config/util');
|
|
11
|
+
const { LogStreamManager } = require('../../back/shared/logStreamManager');
|
|
12
|
+
|
|
13
|
+
for (const conflict of ['stop', 'newer-queue', 'stop-requeue']) {
|
|
14
|
+
test(
|
|
15
|
+
`manual startup loses its conditional claim after ${conflict} and terminates the late child`,
|
|
16
|
+
{ timeout: 10000 },
|
|
17
|
+
async (t) => {
|
|
18
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-manual-claim-'));
|
|
19
|
+
const db = new Sequelize({
|
|
20
|
+
dialect: 'sqlite',
|
|
21
|
+
storage: ':memory:',
|
|
22
|
+
logging: false,
|
|
23
|
+
});
|
|
24
|
+
t.after(async () => {
|
|
25
|
+
await db.close();
|
|
26
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
const crons = db.define('Cron', {
|
|
29
|
+
status: DataTypes.INTEGER,
|
|
30
|
+
pid: DataTypes.INTEGER,
|
|
31
|
+
log_path: DataTypes.STRING,
|
|
32
|
+
queued_token: DataTypes.STRING,
|
|
33
|
+
command: DataTypes.STRING,
|
|
34
|
+
});
|
|
35
|
+
const instances = db.define('Instance', {
|
|
36
|
+
cron_id: DataTypes.INTEGER,
|
|
37
|
+
status: DataTypes.INTEGER,
|
|
38
|
+
pid: DataTypes.INTEGER,
|
|
39
|
+
});
|
|
40
|
+
await db.sync();
|
|
41
|
+
await crons.create({
|
|
42
|
+
id: 1,
|
|
43
|
+
status: 3,
|
|
44
|
+
pid: null,
|
|
45
|
+
log_path: 'previous.log',
|
|
46
|
+
command: 'ignored',
|
|
47
|
+
});
|
|
48
|
+
let release,
|
|
49
|
+
entered,
|
|
50
|
+
child,
|
|
51
|
+
released = 0;
|
|
52
|
+
const pending = new Promise((resolve) => (entered = resolve));
|
|
53
|
+
const gate = new Promise((resolve) => (release = resolve));
|
|
54
|
+
const logs = new LogStreamManager(root);
|
|
55
|
+
t.after(() => logs.closeAll());
|
|
56
|
+
const CronService = load('back/services/cron.ts', {
|
|
57
|
+
'../config': { logPath: root },
|
|
58
|
+
'../data/cron': {
|
|
59
|
+
CrontabModel: crons,
|
|
60
|
+
CrontabStatus: { queued: 3, running: 0, idle: 1 },
|
|
61
|
+
},
|
|
62
|
+
'../data/runningInstance': {
|
|
63
|
+
RunningInstanceModel: instances,
|
|
64
|
+
InstanceStatus: { running: 0, stopped: 2 },
|
|
65
|
+
},
|
|
66
|
+
'../config/util': {
|
|
67
|
+
getUniqPath: async () => {
|
|
68
|
+
entered();
|
|
69
|
+
await gate;
|
|
70
|
+
return 'task';
|
|
71
|
+
},
|
|
72
|
+
killTask,
|
|
73
|
+
},
|
|
74
|
+
'../config/const': {},
|
|
75
|
+
'../schedule/client': {},
|
|
76
|
+
'../shared/pLimit': {
|
|
77
|
+
manualRunWithCronLimit: async (fn) => {
|
|
78
|
+
try {
|
|
79
|
+
return await fn();
|
|
80
|
+
} finally {
|
|
81
|
+
released++;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
'../shared/utils': {},
|
|
86
|
+
'../shared/i18n': { t: (s) => s },
|
|
87
|
+
'../shared/logReader': {},
|
|
88
|
+
'../shared/logStreamManager': { logStreamManager: logs },
|
|
89
|
+
'cross-spawn': {
|
|
90
|
+
spawn: () => {
|
|
91
|
+
child = spawn(process.execPath, [
|
|
92
|
+
'-e',
|
|
93
|
+
'setInterval(() => {}, 1000)',
|
|
94
|
+
]);
|
|
95
|
+
t.after(() => {
|
|
96
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
97
|
+
child.kill('SIGKILL');
|
|
98
|
+
});
|
|
99
|
+
return child;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}).default;
|
|
103
|
+
const service = new CronService({ info() {}, error() {} });
|
|
104
|
+
service.getDb = async () =>
|
|
105
|
+
(await crons.findByPk(1)).get({ plain: true });
|
|
106
|
+
service.makeCommand = () => 'ignored';
|
|
107
|
+
const running = service.runSingle(1);
|
|
108
|
+
await pending;
|
|
109
|
+
if (conflict === 'stop-requeue') {
|
|
110
|
+
await service.stop([1]);
|
|
111
|
+
// Queue again through the real API; leave the new runner pending.
|
|
112
|
+
const pendingRuns = [];
|
|
113
|
+
service.runSingle = (id, token) => pendingRuns.push({ id, token });
|
|
114
|
+
await service.run([1]);
|
|
115
|
+
assert.equal(pendingRuns.length, 1);
|
|
116
|
+
assert.equal(
|
|
117
|
+
pendingRuns[0].token,
|
|
118
|
+
(await crons.findByPk(1)).queued_token,
|
|
119
|
+
);
|
|
120
|
+
} else if (conflict === 'stop') await service.stop([1]);
|
|
121
|
+
else await crons.update({ log_path: 'newer.log' }, { where: { id: 1 } });
|
|
122
|
+
release();
|
|
123
|
+
const result = await running;
|
|
124
|
+
assert.match(result.error.message, /stopped or superseded/);
|
|
125
|
+
assert.ok(child.signalCode || child.exitCode !== null);
|
|
126
|
+
assert.throws(() => process.kill(child.pid, 0), { code: 'ESRCH' });
|
|
127
|
+
const row = await crons.findByPk(1);
|
|
128
|
+
assert.equal(row.status, conflict === 'stop' ? 1 : 3);
|
|
129
|
+
assert.equal(
|
|
130
|
+
row.log_path,
|
|
131
|
+
conflict === 'newer-queue' ? 'newer.log' : 'previous.log',
|
|
132
|
+
);
|
|
133
|
+
assert.equal(row.pid, null);
|
|
134
|
+
assert.equal(released, 1);
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
test(
|
|
140
|
+
'verified termination waits for a SIGTERM-resistant target to exit',
|
|
141
|
+
{ timeout: 5000 },
|
|
142
|
+
async (t) => {
|
|
143
|
+
const child = spawn(process.execPath, [
|
|
144
|
+
'-e',
|
|
145
|
+
'process.on("SIGTERM",()=>{}); process.stdout.write("ready"); setInterval(()=>{},1000)',
|
|
146
|
+
]);
|
|
147
|
+
t.after(() => {
|
|
148
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
149
|
+
child.kill('SIGKILL');
|
|
150
|
+
});
|
|
151
|
+
const exited = once(child, 'exit');
|
|
152
|
+
await new Promise((resolve) => child.stdout.once('data', resolve));
|
|
153
|
+
await killTask(child.pid, true);
|
|
154
|
+
// Linux may report an exited zombie before Node reaps our child. Wait for
|
|
155
|
+
// that separate event before requiring the PID to disappear.
|
|
156
|
+
await exited;
|
|
157
|
+
assert.throws(() => process.kill(child.pid, 0), { code: 'ESRCH' });
|
|
158
|
+
assert.equal(child.signalCode, 'SIGKILL');
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
test('a runner waiting for a concurrency slot cannot adopt a newer queued generation', async (t) => {
|
|
163
|
+
const db = new Sequelize({
|
|
164
|
+
dialect: 'sqlite',
|
|
165
|
+
storage: ':memory:',
|
|
166
|
+
logging: false,
|
|
167
|
+
});
|
|
168
|
+
t.after(() => db.close());
|
|
169
|
+
const crons = db.define('Cron', {
|
|
170
|
+
status: DataTypes.INTEGER,
|
|
171
|
+
pid: DataTypes.INTEGER,
|
|
172
|
+
log_path: DataTypes.STRING,
|
|
173
|
+
queued_token: DataTypes.STRING,
|
|
174
|
+
});
|
|
175
|
+
await db.sync();
|
|
176
|
+
await crons.create({ id: 1, status: 1, log_path: 'same.log' });
|
|
177
|
+
const waiting = [];
|
|
178
|
+
const CronService = load('back/services/cron.ts', {
|
|
179
|
+
'../config': {},
|
|
180
|
+
'../data/cron': {
|
|
181
|
+
CrontabModel: crons,
|
|
182
|
+
CrontabStatus: { queued: 3, idle: 1, running: 0 },
|
|
183
|
+
},
|
|
184
|
+
'../data/runningInstance': {
|
|
185
|
+
RunningInstanceModel: { findAll: async () => [] },
|
|
186
|
+
InstanceStatus: { running: 0 },
|
|
187
|
+
},
|
|
188
|
+
'../config/util': {
|
|
189
|
+
getUniqPath: () => assert.fail('stale runner must not prepare a child'),
|
|
190
|
+
},
|
|
191
|
+
'../config/const': {},
|
|
192
|
+
'../schedule/client': {},
|
|
193
|
+
'../shared/pLimit': {
|
|
194
|
+
manualRunWithCronLimit: (fn) => {
|
|
195
|
+
waiting.push(fn);
|
|
196
|
+
return Promise.resolve();
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
'../shared/utils': {},
|
|
200
|
+
'../shared/i18n': {},
|
|
201
|
+
'../shared/logReader': {},
|
|
202
|
+
'../shared/logStreamManager': {},
|
|
203
|
+
'cross-spawn': { spawn: () => assert.fail('stale runner must not spawn') },
|
|
204
|
+
}).default;
|
|
205
|
+
const errors = [];
|
|
206
|
+
const service = new CronService({ error: (...args) => errors.push(args) });
|
|
207
|
+
await service.run([1]);
|
|
208
|
+
const first = (await crons.findByPk(1)).queued_token;
|
|
209
|
+
await service.stop([1]);
|
|
210
|
+
await service.run([1]);
|
|
211
|
+
const second = (await crons.findByPk(1)).queued_token;
|
|
212
|
+
assert.notEqual(first, second);
|
|
213
|
+
assert.equal(waiting.length, 2);
|
|
214
|
+
await waiting[0]();
|
|
215
|
+
const row = await crons.findByPk(1);
|
|
216
|
+
assert.equal(row.status, 3);
|
|
217
|
+
assert.equal(row.queued_token, second);
|
|
218
|
+
assert.equal(row.log_path, 'same.log');
|
|
219
|
+
assert.deepEqual(errors, []);
|
|
220
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
MAX_METRIC_SAMPLES,
|
|
6
|
+
metricsService,
|
|
7
|
+
} = require('../../back/services/metrics');
|
|
8
|
+
|
|
9
|
+
test('metrics keep only the newest bounded samples', () => {
|
|
10
|
+
const sampleCount = MAX_METRIC_SAMPLES * 50;
|
|
11
|
+
for (let index = 0; index < sampleCount; index++) {
|
|
12
|
+
metricsService.record('http_request', index, {
|
|
13
|
+
path: `/health/${index}`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = metricsService.getMetrics('http_request');
|
|
18
|
+
assert.equal(result.count, MAX_METRIC_SAMPLES);
|
|
19
|
+
assert.equal(result.metrics[0].value, sampleCount - MAX_METRIC_SAMPLES);
|
|
20
|
+
assert.equal(result.metrics.at(-1).value, sampleCount - 1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('empty metric queries return finite aggregates', () => {
|
|
24
|
+
const result = metricsService.getMetrics('missing_metric');
|
|
25
|
+
assert.deepEqual(
|
|
26
|
+
{
|
|
27
|
+
count: result.count,
|
|
28
|
+
average: result.average,
|
|
29
|
+
min: result.min,
|
|
30
|
+
max: result.max,
|
|
31
|
+
},
|
|
32
|
+
{ count: 0, average: 0, min: 0, max: 0 },
|
|
33
|
+
);
|
|
34
|
+
});
|