@whyour/qinglong 2.21.0 → 2.23.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 +9 -1
- package/back/protos/cron.proto +8 -1
- package/deploy/kubernetes/README.md +81 -0
- package/deploy/kubernetes/base/kustomization.yaml +5 -0
- package/deploy/kubernetes/base/qinglong.yaml +95 -0
- package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
- 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/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +62 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/ecosystem.config.js +10 -1
- package/package.json +19 -13
- package/sample/config.sample.sh +17 -2
- package/sample/notify.js +118 -0
- package/sample/notify.py +93 -0
- package/scripts/benchmark-execution.cjs +96 -0
- package/scripts/benchmark-script-history.cjs +39 -0
- package/scripts/publish-static.sh +34 -0
- package/scripts/sync-static.sh +20 -0
- package/scripts/wait-for-mirror.sh +214 -0
- package/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +96 -83
- 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 +136 -0
- package/shell/otask.sh +17 -10
- package/shell/preload/sitecustomize.js +11 -3
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +27 -10
- package/shell/start.sh +6 -3
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +21 -9
- package/shell/update.sh +104 -98
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +9 -21
- package/static/build/api/cron.js +39 -3
- package/static/build/api/dashboard.js +50 -6
- package/static/build/api/env.js +17 -16
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +39 -19
- package/static/build/api/open.js +2 -1
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +172 -25
- package/static/build/api/subscription.js +19 -8
- package/static/build/api/system.js +66 -12
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +63 -54
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +2 -0
- package/static/build/config/grpcCerts.js +93 -44
- package/static/build/config/index.js +0 -4
- package/static/build/config/share.js +5 -4
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +142 -45
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +18 -1
- package/static/build/data/sock.js +1 -0
- package/static/build/loaders/app.js +8 -6
- package/static/build/loaders/db.js +5 -35
- package/static/build/loaders/deps.js +30 -22
- package/static/build/loaders/express.js +46 -32
- package/static/build/loaders/initData.js +26 -33
- package/static/build/loaders/initFile.js +1 -1
- package/static/build/loaders/initTask.js +14 -3
- package/static/build/loaders/server.js +1 -1
- 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/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/api.js +78 -2
- package/static/build/protos/cron.js +83 -5
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +67 -19
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +56 -6
- package/static/build/schedule/delCron.js +11 -1
- package/static/build/schedule/health.js +72 -7
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +5 -43
- package/static/build/services/cron.js +389 -174
- package/static/build/services/dependence.js +66 -18
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +4 -3
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +9 -3
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +73 -5
- package/static/build/services/open.js +106 -31
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +77 -43
- package/static/build/services/script.js +4 -5
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +161 -87
- package/static/build/services/system.js +116 -43
- package/static/build/services/user.js +255 -37
- package/static/build/shared/auth.js +22 -3
- 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/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +63 -4
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +22 -8
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +39 -17
- 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/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -0
- package/static/build/shared/subscriptionMutationLock.js +34 -0
- package/static/build/shared/subscriptionPath.js +41 -0
- package/static/build/shared/subscriptionStorage.js +98 -0
- package/static/build/shared/trustProxy.js +119 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +6 -12
- 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/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.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/{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.01fcd534.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.0b8cce8c.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.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- 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.afabf073.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
- package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
- package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
- package/static/dist/src__pages__script__saveWithHistory.99ece830.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.d175b154.async.js +1 -0
- 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.30868ba8.async.js +1 -0
- package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-log-name.test.cjs +110 -0
- package/test/back/cron-macros.test.cjs +51 -0
- package/test/back/cron-schedule-compatibility.test.cjs +69 -0
- package/test/back/cron-scheduler-routing.test.cjs +59 -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/draft-path-security.test.cjs +235 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-import-security.test.cjs +91 -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-scope.test.cjs +180 -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/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +313 -0
- package/test/back/legacy-cron-recovery.test.cjs +76 -0
- package/test/back/linux-mirror-result.test.cjs +176 -0
- package/test/back/listen-security.test.cjs +68 -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/mirror-status.test.cjs +257 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +202 -0
- package/test/back/node-path-lock.test.cjs +182 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/preload-lazy-notify.test.cjs +168 -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/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -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-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -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 +206 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- package/test/back/script-file-access.test.cjs +210 -0
- package/test/back/script-history-api.test.cjs +551 -0
- package/test/back/script-history.test.cjs +383 -0
- package/test/back/shell-api-parsing.test.cjs +184 -0
- package/test/back/shell-translation-output.test.cjs +16 -0
- package/test/back/shell-upgrade.test.cjs +312 -0
- package/test/back/shellApiToken.test.cjs +151 -0
- package/test/back/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +171 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +127 -0
- package/test/back/system-export-history.test.cjs +119 -0
- package/test/back/systemTokenRenewal.test.cjs +497 -0
- package/test/back/task-shell-lifecycle.test.cjs +194 -0
- package/test/back/task-time.test.cjs +116 -0
- package/test/back/unique-constraint-error.test.cjs +72 -0
- package/test/back/upgrade-guards.test.cjs +285 -0
- package/test/back/upgrade-lifecycle.test.cjs +288 -0
- package/test/back/upgrade-transaction.test.cjs +133 -0
- package/test/back/user-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +349 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +116 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.c420132e.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/2208.f7ba3dfa.async.js +0 -1
- package/static/dist/2286.164bb089.async.js +0 -1
- package/static/dist/3191.63263871.async.js +0 -1
- package/static/dist/4859.6592cebb.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/6707.801b886b.async.js +0 -1
- package/static/dist/8826.2447a104.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.0431c0f3.js +0 -1
- package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
- package/static/dist/src__pages__crontab__index.fed99fd0.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.b30f2f47.async.js +0 -1
- package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
- package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
- package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
- package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
- package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
- package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
- package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
- package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
- package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
- package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
- package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
- package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
- package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.67406721.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.3562c670.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -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
|
+
});
|