@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.
Files changed (362) hide show
  1. package/.dockerignore +13 -0
  2. package/.env.example +7 -0
  3. package/AGENTS.md +2 -2
  4. package/README-en.md +24 -0
  5. package/README.md +24 -0
  6. package/back/protos/api.proto +9 -1
  7. package/back/protos/cron.proto +8 -1
  8. package/deploy/kubernetes/README.md +81 -0
  9. package/deploy/kubernetes/base/kustomization.yaml +5 -0
  10. package/deploy/kubernetes/base/qinglong.yaml +95 -0
  11. package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
  12. package/docker/Dockerfile +31 -12
  13. package/docker/Dockerfile.310 +31 -12
  14. package/docker/Dockerfile.debian +22 -14
  15. package/docker/Dockerfile.debian310 +24 -14
  16. package/docker/build-manifest.cjs +28 -0
  17. package/docker/verify-build.cjs +49 -0
  18. package/docs/development/node-cron-migration.md +49 -0
  19. package/docs/development/task-startup.md +78 -0
  20. package/docs/releases/2.22.0-validation.md +49 -0
  21. package/docs/releases/2.22.0.md +62 -0
  22. package/docs/releases/2.23.0.md +33 -0
  23. package/docs/script-history.md +53 -0
  24. package/ecosystem.config.js +10 -1
  25. package/package.json +19 -13
  26. package/sample/config.sample.sh +17 -2
  27. package/sample/notify.js +118 -0
  28. package/sample/notify.py +93 -0
  29. package/scripts/benchmark-execution.cjs +96 -0
  30. package/scripts/benchmark-script-history.cjs +39 -0
  31. package/scripts/publish-static.sh +34 -0
  32. package/scripts/sync-static.sh +20 -0
  33. package/scripts/wait-for-mirror.sh +214 -0
  34. package/scripts/write-build-info.cjs +27 -0
  35. package/shell/api.sh +96 -83
  36. package/shell/check.sh +59 -19
  37. package/shell/lang/en.sh +6 -0
  38. package/shell/lang/zh.sh +6 -0
  39. package/shell/node_path_cache.sh +136 -0
  40. package/shell/otask.sh +17 -10
  41. package/shell/preload/sitecustomize.js +11 -3
  42. package/shell/preload/sitecustomize.py +4 -2
  43. package/shell/share.sh +27 -10
  44. package/shell/start.sh +6 -3
  45. package/shell/task-timeout.sh +63 -0
  46. package/shell/task.sh +21 -9
  47. package/shell/update.sh +104 -98
  48. package/shell/upgrade.cjs +8 -0
  49. package/static/build/api/clientIp.js +42 -0
  50. package/static/build/api/config.js +9 -21
  51. package/static/build/api/cron.js +39 -3
  52. package/static/build/api/dashboard.js +50 -6
  53. package/static/build/api/env.js +17 -16
  54. package/static/build/api/health.js +2 -2
  55. package/static/build/api/index.js +4 -0
  56. package/static/build/api/log.js +39 -19
  57. package/static/build/api/open.js +2 -1
  58. package/static/build/api/retention.js +63 -0
  59. package/static/build/api/script.js +172 -25
  60. package/static/build/api/subscription.js +19 -8
  61. package/static/build/api/system.js +66 -12
  62. package/static/build/api/user.js +75 -15
  63. package/static/build/app.js +63 -54
  64. package/static/build/bootstrap/database.js +51 -0
  65. package/static/build/config/const.js +2 -0
  66. package/static/build/config/grpcCerts.js +93 -44
  67. package/static/build/config/index.js +0 -4
  68. package/static/build/config/share.js +5 -4
  69. package/static/build/config/subscription.js +19 -11
  70. package/static/build/config/util.js +142 -45
  71. package/static/build/data/cron.js +1 -0
  72. package/static/build/data/notify.js +18 -1
  73. package/static/build/data/sock.js +1 -0
  74. package/static/build/loaders/app.js +8 -6
  75. package/static/build/loaders/db.js +5 -35
  76. package/static/build/loaders/deps.js +30 -22
  77. package/static/build/loaders/express.js +46 -32
  78. package/static/build/loaders/initData.js +26 -33
  79. package/static/build/loaders/initFile.js +1 -1
  80. package/static/build/loaders/initTask.js +14 -3
  81. package/static/build/loaders/server.js +1 -1
  82. package/static/build/loaders/sock.js +72 -6
  83. package/static/build/middlewares/monitoring.js +12 -33
  84. package/static/build/middlewares/protectedPathCase.js +17 -0
  85. package/static/build/middlewares/uniqueConstraintError.js +15 -0
  86. package/static/build/protos/api.js +78 -2
  87. package/static/build/protos/cron.js +83 -5
  88. package/static/build/protos/health.js +1 -1
  89. package/static/build/schedule/addCron.js +67 -19
  90. package/static/build/schedule/api.js +5 -2
  91. package/static/build/schedule/client.js +56 -6
  92. package/static/build/schedule/delCron.js +11 -1
  93. package/static/build/schedule/health.js +72 -7
  94. package/static/build/schedule/setConcurrency.js +27 -0
  95. package/static/build/services/config.js +5 -43
  96. package/static/build/services/cron.js +389 -174
  97. package/static/build/services/dependence.js +66 -18
  98. package/static/build/services/env.js +1 -1
  99. package/static/build/services/grpc.js +4 -3
  100. package/static/build/services/health.js +4 -7
  101. package/static/build/services/http.js +9 -3
  102. package/static/build/services/log.js +2 -3
  103. package/static/build/services/metrics.js +46 -14
  104. package/static/build/services/notify.js +73 -5
  105. package/static/build/services/open.js +106 -31
  106. package/static/build/services/retention.js +123 -0
  107. package/static/build/services/schedule.js +77 -43
  108. package/static/build/services/script.js +4 -5
  109. package/static/build/services/scriptHistory.js +30 -0
  110. package/static/build/services/sshKey.js +39 -14
  111. package/static/build/services/subscription.js +161 -87
  112. package/static/build/services/system.js +116 -43
  113. package/static/build/services/user.js +255 -37
  114. package/static/build/shared/auth.js +22 -3
  115. package/static/build/shared/authMutation.js +17 -0
  116. package/static/build/shared/childProcess.js +82 -0
  117. package/static/build/shared/clientIp.js +27 -0
  118. package/static/build/shared/cronCommand.js +17 -0
  119. package/static/build/shared/cronSchedule.js +101 -0
  120. package/static/build/shared/cronScheduler.js +73 -0
  121. package/static/build/shared/errors.js +9 -0
  122. package/static/build/shared/fileAccess.js +60 -0
  123. package/static/build/shared/i18n.js +63 -4
  124. package/static/build/shared/logPath.js +15 -0
  125. package/static/build/shared/logReader.js +85 -0
  126. package/static/build/shared/logStreamManager.js +80 -60
  127. package/static/build/shared/loginThrottle.js +45 -0
  128. package/static/build/shared/pLimit.js +22 -8
  129. package/static/build/shared/password.js +30 -0
  130. package/static/build/shared/retention.js +58 -0
  131. package/static/build/shared/runCron.js +39 -17
  132. package/static/build/shared/schedulerMutationLock.js +44 -0
  133. package/static/build/shared/schedulerReadiness.js +82 -0
  134. package/static/build/shared/schemaMigrations.js +58 -0
  135. package/static/build/shared/scriptHistory.js +445 -0
  136. package/static/build/shared/shellQuote.js +11 -0
  137. package/static/build/shared/startupProcess.js +48 -0
  138. package/static/build/shared/store.js +7 -0
  139. package/static/build/shared/subscriptionMutationLock.js +34 -0
  140. package/static/build/shared/subscriptionPath.js +41 -0
  141. package/static/build/shared/subscriptionStorage.js +98 -0
  142. package/static/build/shared/trustProxy.js +119 -0
  143. package/static/build/shared/utils.js +2 -1
  144. package/static/build/token.js +3 -14
  145. package/static/build/validation/schedule.js +6 -12
  146. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  147. package/static/dist/2031.6af40025.async.js +1 -0
  148. package/static/dist/2693.51c2636b.async.js +1 -0
  149. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  150. package/static/dist/2901.2ca95295.async.js +1 -0
  151. package/static/dist/292.264757f0.async.js +1 -0
  152. package/static/dist/3512.95e41255.async.js +1 -0
  153. package/static/dist/445.a65ff63b.async.js +1 -0
  154. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  155. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  156. package/static/dist/6212.9e6d9913.async.js +1 -0
  157. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  158. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  159. package/static/dist/7231.f7e5b668.async.js +1 -0
  160. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  161. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  162. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  163. package/static/dist/8844.a0fef08e.async.js +1 -0
  164. package/static/dist/index.html +2 -2
  165. package/static/dist/layouts__index.633d3553.async.js +1 -0
  166. package/static/dist/preload_helper.01fcd534.js +1 -0
  167. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  168. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  169. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  170. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  171. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  172. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  173. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  174. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  175. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  176. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  177. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  178. package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
  179. package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
  180. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  181. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  182. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  183. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  184. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  185. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  186. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  187. package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
  188. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
  189. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
  190. package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
  191. package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
  192. package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
  193. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  194. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
  195. package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
  196. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  197. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  198. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  199. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  200. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  201. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  202. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  203. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  204. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  205. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  206. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  207. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  208. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  209. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  210. package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
  211. package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
  212. package/test/back/advisory-input-security.test.cjs +416 -0
  213. package/test/back/auth-security.test.cjs +74 -0
  214. package/test/back/build-provenance.test.cjs +150 -0
  215. package/test/back/code-scanning-security.test.cjs +189 -0
  216. package/test/back/cron-log-name.test.cjs +110 -0
  217. package/test/back/cron-macros.test.cjs +51 -0
  218. package/test/back/cron-schedule-compatibility.test.cjs +69 -0
  219. package/test/back/cron-scheduler-routing.test.cjs +59 -0
  220. package/test/back/cron-validation.test.cjs +45 -0
  221. package/test/back/dashboard-failures.test.cjs +173 -0
  222. package/test/back/database-bootstrap.test.cjs +193 -0
  223. package/test/back/dependence-cache-status.test.cjs +125 -0
  224. package/test/back/deprecated-file-routes.test.cjs +82 -0
  225. package/test/back/draft-path-security.test.cjs +235 -0
  226. package/test/back/ecosystem.test.cjs +28 -0
  227. package/test/back/env-import-security.test.cjs +91 -0
  228. package/test/back/env-name-parsing.test.cjs +96 -0
  229. package/test/back/execution-lifecycle.test.cjs +236 -0
  230. package/test/back/file-access-scope.test.cjs +180 -0
  231. package/test/back/file-access-security.test.cjs +47 -0
  232. package/test/back/fileTreeListing.test.cjs +57 -0
  233. package/test/back/grpc-cron-response.test.cjs +60 -0
  234. package/test/back/grpc-mtls-security.test.cjs +136 -0
  235. package/test/back/http-exclusive-listen.test.cjs +31 -0
  236. package/test/back/http-security.test.cjs +313 -0
  237. package/test/back/legacy-cron-recovery.test.cjs +76 -0
  238. package/test/back/linux-mirror-result.test.cjs +176 -0
  239. package/test/back/listen-security.test.cjs +68 -0
  240. package/test/back/log-path-security.test.cjs +158 -0
  241. package/test/back/logReader.test.cjs +72 -0
  242. package/test/back/manual-execution.test.cjs +85 -0
  243. package/test/back/manual-stop-claim.test.cjs +220 -0
  244. package/test/back/metrics.test.cjs +34 -0
  245. package/test/back/mirror-status.test.cjs +257 -0
  246. package/test/back/monitoring.test.cjs +73 -0
  247. package/test/back/node-cron-migration.test.cjs +65 -0
  248. package/test/back/node-path-cache.test.cjs +202 -0
  249. package/test/back/node-path-lock.test.cjs +182 -0
  250. package/test/back/npm-publication.test.cjs +70 -0
  251. package/test/back/preload-lazy-notify.test.cjs +168 -0
  252. package/test/back/primary-apm.test.cjs +24 -0
  253. package/test/back/process-exit-state.test.cjs +81 -0
  254. package/test/back/process-stop-signal.test.cjs +77 -0
  255. package/test/back/protected-path-case.test.cjs +58 -0
  256. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  257. package/test/back/queued-cron-invalidation.test.cjs +98 -0
  258. package/test/back/restart-instance-recovery.test.cjs +116 -0
  259. package/test/back/retention.test.cjs +131 -0
  260. package/test/back/role-loading.test.cjs +118 -0
  261. package/test/back/schedule-health.test.cjs +86 -0
  262. package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
  263. package/test/back/scheduler-concurrency.test.cjs +411 -0
  264. package/test/back/scheduler-file-lock.test.cjs +51 -0
  265. package/test/back/scheduler-mutation.test.cjs +312 -0
  266. package/test/back/scheduler-readiness.test.cjs +85 -0
  267. package/test/back/scheduler-reconciliation.test.cjs +206 -0
  268. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  269. package/test/back/schema-migrations.test.cjs +127 -0
  270. package/test/back/script-file-access.test.cjs +210 -0
  271. package/test/back/script-history-api.test.cjs +551 -0
  272. package/test/back/script-history.test.cjs +383 -0
  273. package/test/back/shell-api-parsing.test.cjs +184 -0
  274. package/test/back/shell-translation-output.test.cjs +16 -0
  275. package/test/back/shell-upgrade.test.cjs +312 -0
  276. package/test/back/shellApiToken.test.cjs +151 -0
  277. package/test/back/sock-polling.test.cjs +297 -0
  278. package/test/back/sock-security.test.cjs +72 -0
  279. package/test/back/ssh-config-home.test.cjs +113 -0
  280. package/test/back/start-env-preservation.test.cjs +53 -0
  281. package/test/back/static-mirror-trigger.test.cjs +441 -0
  282. package/test/back/static-mirror.test.cjs +179 -0
  283. package/test/back/stop-failure-feedback.test.cjs +158 -0
  284. package/test/back/stop-race.test.cjs +171 -0
  285. package/test/back/subscription-cleanup.test.cjs +53 -0
  286. package/test/back/subscription-mutation-lock.test.cjs +83 -0
  287. package/test/back/subscription-review-regression.test.cjs +607 -0
  288. package/test/back/subscription-stop-state.test.cjs +66 -0
  289. package/test/back/subscription-storage-regression.test.cjs +553 -0
  290. package/test/back/system-dependence-cache.test.cjs +127 -0
  291. package/test/back/system-export-history.test.cjs +119 -0
  292. package/test/back/systemTokenRenewal.test.cjs +497 -0
  293. package/test/back/task-shell-lifecycle.test.cjs +194 -0
  294. package/test/back/task-time.test.cjs +116 -0
  295. package/test/back/unique-constraint-error.test.cjs +72 -0
  296. package/test/back/upgrade-guards.test.cjs +285 -0
  297. package/test/back/upgrade-lifecycle.test.cjs +288 -0
  298. package/test/back/upgrade-transaction.test.cjs +133 -0
  299. package/test/back/user-api.test.cjs +99 -0
  300. package/test/back/user-security.test.cjs +349 -0
  301. package/test/back/worker-apm.test.cjs +84 -0
  302. package/test/back/wpush-grpc.test.cjs +116 -0
  303. package/test/fixtures/legacy-cron.json +1371 -0
  304. package/test/front/cron-log-pagination.test.cjs +214 -0
  305. package/test/front/diff-file-routing.test.cjs +126 -0
  306. package/test/front/http-auth.test.cjs +152 -0
  307. package/test/front/http-error.test.cjs +29 -0
  308. package/test/front/script-history-save.test.cjs +121 -0
  309. package/test/helpers/load-security-module.cjs +42 -0
  310. package/test/helpers/upgrade-fixture.cjs +30 -0
  311. package/version.yaml +14 -34
  312. package/CLAUDE.md +0 -43
  313. package/static/dist/1147.c420132e.async.js +0 -1
  314. package/static/dist/134.54df9e38.async.js +0 -1
  315. package/static/dist/2096.6d98fd12.async.js +0 -1
  316. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  317. package/static/dist/2286.164bb089.async.js +0 -1
  318. package/static/dist/3191.63263871.async.js +0 -1
  319. package/static/dist/4859.6592cebb.async.js +0 -1
  320. package/static/dist/4902.555f92ab.async.js +0 -1
  321. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  322. package/static/dist/6431.c50479be.async.js +0 -1
  323. package/static/dist/6707.801b886b.async.js +0 -1
  324. package/static/dist/8826.2447a104.async.js +0 -1
  325. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  326. package/static/dist/preload_helper.0431c0f3.js +0 -1
  327. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  328. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  329. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  330. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  331. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  332. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  333. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  334. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  335. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  336. package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
  337. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  338. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  339. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  340. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  341. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  342. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  343. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  344. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  345. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  346. package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
  347. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  348. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  349. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  350. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  351. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  352. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  353. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  354. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  355. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  356. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  357. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  358. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  359. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  360. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  361. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
  362. /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
@@ -0,0 +1,607 @@
1
+ const assert = require('node:assert/strict');
2
+ const test = require('node:test');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const os = require('node:os');
6
+ const { execFileSync } = require('node:child_process');
7
+ const ts = require('typescript');
8
+ const load = require('../helpers/load-security-module.cjs');
9
+ const paths = load(path.resolve('back/shared/subscriptionPath.ts'));
10
+ const { formatUrl, formatCommand } = load(
11
+ path.resolve('back/config/subscription.ts'),
12
+ );
13
+
14
+ function temporary(t) {
15
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-sub-review-'));
16
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
17
+ return root;
18
+ }
19
+
20
+ function privateSubscription(alias, id = 1) {
21
+ return {
22
+ id,
23
+ type: 'private-repo',
24
+ pull_type: 'ssh-key',
25
+ alias,
26
+ url: 'git@example.com:owner/repo.git',
27
+ pull_option: { private_key: 'fixture-key' },
28
+ };
29
+ }
30
+
31
+ function sshService(root, warnings = []) {
32
+ const Ssh = load(path.resolve('back/services/sshKey.ts'), {
33
+ typedi: { Service: () => (x) => x, Inject: () => () => {} },
34
+ '../config': { sshdPath: root },
35
+ '../config/util': {
36
+ fileExist: async (p) => fs.existsSync(p),
37
+ rmPath: (p) => fs.promises.rm(p, { recursive: true, force: true }),
38
+ },
39
+ }).default;
40
+ return Object.assign(Object.create(Ssh.prototype), {
41
+ sshPath: root,
42
+ logger: { error() {}, warn: (...args) => warnings.push(args) },
43
+ });
44
+ }
45
+
46
+ test('aliases generated by the frontend for valid branches remain accepted', () => {
47
+ const text = fs.readFileSync(
48
+ path.resolve('src/pages/subscription/modal.tsx'),
49
+ 'utf8',
50
+ );
51
+ const source = text.slice(
52
+ text.indexOf('const formatAlias ='),
53
+ text.indexOf('\n\n const IntervalSelect'),
54
+ );
55
+ const js = ts.transpileModule(source, {
56
+ compilerOptions: { target: ts.ScriptTarget.ES2020 },
57
+ }).outputText;
58
+ const formatAlias = new Function(
59
+ 'repoUrlRegx',
60
+ 'fileUrlRegx',
61
+ 'type',
62
+ js + '\nreturn formatAlias;',
63
+ )(
64
+ /([^\/\:]+\/[^\/]+)(?=\.git)/,
65
+ /([^\/\:]+\/[^\/\.]+)\.[a-z]+/,
66
+ 'public-repo',
67
+ );
68
+ for (const branch of [
69
+ 'main',
70
+ 'release+hotfix',
71
+ 'feature/foo',
72
+ 'feature/foo/bar',
73
+ 'release@v2',
74
+ 'release#v2',
75
+ ]) {
76
+ const alias = formatAlias('https://example.com/owner/repo.git', branch);
77
+ assert.equal(alias, `owner_repo_${branch}`);
78
+ assert.doesNotThrow(() => paths.assertSubscriptionAlias(alias));
79
+ }
80
+ });
81
+
82
+ test('nested aliases stay inside the root and cannot claim internal SSH names', (t) => {
83
+ const root = temporary(t);
84
+ const scripts = path.join(root, 'scripts');
85
+ fs.mkdirSync(scripts);
86
+ assert.equal(
87
+ paths.resolveSubscriptionPath(scripts, 'owner_repo_feature/foo'),
88
+ path.join(scripts, 'owner_repo_feature/foo'),
89
+ );
90
+ fs.symlinkSync(root, path.join(scripts, 'escape'));
91
+ assert.throws(() => paths.resolveSubscriptionPath(scripts, 'escape/outside'));
92
+ for (const alias of [
93
+ '.',
94
+ '..',
95
+ '../outside',
96
+ '/outside',
97
+ 'x/../outside',
98
+ 'x/./a',
99
+ 'x//a',
100
+ 'x/',
101
+ 'x\\a',
102
+ 'x\0a',
103
+ 'x\nHost *',
104
+ 'x y',
105
+ '~global_secret',
106
+ '~sub_' + 'a'.repeat(64),
107
+ ]) {
108
+ assert.throws(() => paths.assertSubscriptionAlias(alias), alias);
109
+ }
110
+ assert.throws(() => paths.assertSubscriptionAlias('a'.repeat(201)));
111
+ });
112
+
113
+ test('SSH URL, key and configuration use the same stable name for nested aliases', async (t) => {
114
+ const root = temporary(t);
115
+ const ssh = sshService(root);
116
+ const docs = [
117
+ privateSubscription('owner_repo_release+hotfix'),
118
+ privateSubscription('owner_repo_feature/foo', 2),
119
+ privateSubscription('owner_repo_feature_foo', 3),
120
+ privateSubscription('owner_repo.config', 4),
121
+ ];
122
+ const snapshot = structuredClone(docs);
123
+ await ssh.setSshConfig(docs);
124
+ assert.deepEqual(docs, snapshot);
125
+ const mapped = paths.getSubscriptionSshAlias(docs[1].alias);
126
+ assert.match(mapped, /^~sub_[a-f0-9]{64}$/);
127
+ assert.notEqual(mapped, paths.getSubscriptionSshAlias(docs[2].alias));
128
+ assert.equal(paths.getSubscriptionSshAlias(docs[0].alias), docs[0].alias);
129
+ for (const doc of docs) {
130
+ const name = paths.getSubscriptionSshAlias(doc.alias);
131
+ const key = path.join(root, name);
132
+ const config = path.join(root, `${name}.config`);
133
+ assert.equal(fs.readFileSync(key, 'utf8').trim(), 'fixture-key');
134
+ assert.equal(fs.statSync(key).mode & 0o777, 0o400);
135
+ assert.equal(fs.statSync(config).mode & 0o777, 0o600);
136
+ assert.ok(fs.readFileSync(config, 'utf8').startsWith(`Host ${name}\n`));
137
+ assert.equal(formatUrl(doc).url, `git@${name}:owner/repo.git`);
138
+ const parsed = execFileSync('ssh', ['-G', '-F', config, name], {
139
+ encoding: 'utf8',
140
+ stdio: ['ignore', 'pipe', 'pipe'],
141
+ });
142
+ assert.match(parsed, /^hostname example\.com$/m);
143
+ assert.ok(parsed.includes(`identityfile ${key}\n`));
144
+ }
145
+ await ssh.removeSSHKey(docs[1].alias, 'example.com');
146
+ assert.equal(fs.existsSync(path.join(root, mapped)), false);
147
+ assert.equal(fs.existsSync(path.join(root, `${mapped}.config`)), false);
148
+ await ssh.addSSHKey('replacement', docs[1].alias, 'example.com');
149
+ assert.equal(
150
+ fs.readFileSync(path.join(root, mapped), 'utf8').trim(),
151
+ 'replacement',
152
+ );
153
+ });
154
+
155
+ test('startup retains historical aliases and isolates bad rows and asynchronous scheduling failures', async (t) => {
156
+ const root = temporary(t);
157
+ const warnings = [];
158
+ const ssh = sshService(root, warnings);
159
+ const docs = [
160
+ privateSubscription('owner_repo_release+hotfix', 1),
161
+ privateSubscription('owner_repo_feature/foo', 2),
162
+ privateSubscription('../outside', 3),
163
+ {
164
+ id: 4,
165
+ type: 'public-repo',
166
+ alias: 'failed-job',
167
+ url: 'https://example.com/repo.git',
168
+ },
169
+ {
170
+ id: 5,
171
+ type: 'public-repo',
172
+ alias: 'healthy-job',
173
+ url: 'https://example.com/repo.git',
174
+ },
175
+ ];
176
+ const registered = [];
177
+ const types = Object.fromEntries(
178
+ ['system', 'schedule', 'subscription', 'ssh'].map((key) => [key, class {}]),
179
+ );
180
+ const services = new Map([
181
+ [types.system, { getSystemConfig: async () => ({}) }],
182
+ [
183
+ types.schedule,
184
+ { cancelIntervalTask: async () => {}, createIntervalTask: () => {} },
185
+ ],
186
+ [types.ssh, ssh],
187
+ [
188
+ types.subscription,
189
+ {
190
+ setSshConfig: () => ssh.setSshConfig(docs),
191
+ list: async () => docs.map((doc) => ({ ...doc, get: () => doc })),
192
+ handleTask: async (doc) => {
193
+ if (doc.id === 4) throw new Error('unavailable scheduler');
194
+ registered.push(doc.id);
195
+ },
196
+ },
197
+ ],
198
+ ]);
199
+ const initTask = load(path.resolve('back/loaders/initTask.ts'), {
200
+ '../config': { rootPath: root },
201
+ '../config/util': { fileExist: async () => false },
202
+ '../shared/i18n': { t: (x) => x },
203
+ './logger': { warn: (...args) => warnings.push(args) },
204
+ '../services/system': types.system,
205
+ '../services/schedule': types.schedule,
206
+ '../services/subscription': types.subscription,
207
+ '../services/sshKey': types.ssh,
208
+ typedi: { Container: { get: (key) => services.get(key) } },
209
+ }).default;
210
+ await initTask();
211
+ assert.deepEqual(registered, [1, 2, 5]);
212
+ assert.equal(warnings.length, 3);
213
+ assert.equal(
214
+ fs.existsSync(path.join(root, 'owner_repo_release+hotfix.config')),
215
+ true,
216
+ );
217
+ });
218
+
219
+ test('subscription create and update preserve branch aliases without rewriting records', async (t) => {
220
+ const root = temporary(t);
221
+ const Subscription = load(path.resolve('back/services/subscription.ts'), {
222
+ '../config': { logPath: root, scriptPath: root },
223
+ '../data/subscription': {
224
+ Subscription: class {
225
+ constructor(value) {
226
+ Object.assign(this, value);
227
+ }
228
+ },
229
+ SubscriptionModel: {},
230
+ },
231
+ '../data/cron': {},
232
+ '../config/util': {},
233
+ '../config/const': {},
234
+ '../shared/i18n': { t: (x) => x, tf: (x) => x },
235
+ '../shared/pLimit': {},
236
+ './schedule': {},
237
+ './sock': {},
238
+ './sshKey': {},
239
+ './cron': {},
240
+ }).default;
241
+ const service = new Subscription({}, {}, {}, {}, {});
242
+ const tasks = [];
243
+ service.insert = async (value) => ({ ...value, get: () => value });
244
+ service.getDb = async () => ({ id: 1, alias: 'owner_repo_release+hotfix' });
245
+ service.updateDb = async (value) => value;
246
+ service.handleTask = async (doc) => tasks.push(doc.alias);
247
+ service.setSshConfig = async () => {};
248
+ for (const alias of ['owner_repo_release+hotfix', 'owner_repo_feature/foo']) {
249
+ await service.create({ id: 1, alias });
250
+ await service.update({ id: 1, alias });
251
+ }
252
+ assert.deepEqual(tasks, [
253
+ 'owner_repo_release+hotfix',
254
+ 'owner_repo_release+hotfix',
255
+ 'owner_repo_feature/foo',
256
+ 'owner_repo_feature/foo',
257
+ ]);
258
+ });
259
+
260
+ function shellFunction(name) {
261
+ const source = fs.readFileSync(path.resolve('shell/update.sh'), 'utf8');
262
+ const start = source.indexOf(`${name}() {`);
263
+ assert.ok(start >= 0);
264
+ return source.slice(start, source.indexOf('\n}', start) + 2);
265
+ }
266
+
267
+ function updateFixture(t) {
268
+ const root = temporary(t);
269
+ const template = path.join(root, 'template');
270
+ for (const dir of ['template', 'repo', 'scripts', 'lists'])
271
+ fs.mkdirSync(path.join(root, dir));
272
+ for (const file of ['keep.js', 'keep.py', 'omit.js', 'other.txt', 'dep.js'])
273
+ fs.writeFileSync(path.join(template, file), file);
274
+ for (const file of ['notify.js', 'notify.py', 'crontab'])
275
+ fs.writeFileSync(path.join(root, file), '');
276
+ const helpers = [
277
+ 'update_repo',
278
+ 'diff_scripts',
279
+ 'gen_list_repo',
280
+ 'get_uniq_path',
281
+ ]
282
+ .map(shellFunction)
283
+ .join('\n');
284
+ return {
285
+ root,
286
+ run: (extensions, dependence = 'dep') => {
287
+ const doc = {
288
+ id: 1,
289
+ type: 'public-repo',
290
+ alias: 'owner_repo',
291
+ url: 'https://example.invalid/owner/repo.git',
292
+ whitelist: 'keep',
293
+ blacklist: 'omit',
294
+ dependences: dependence,
295
+ extensions,
296
+ autoAddCron: false,
297
+ autoDelCron: false,
298
+ };
299
+ const code = `dir_repo="$QA_ROOT/repo"; dir_scripts="$QA_ROOT/scripts"; dir_list_tmp="$QA_ROOT/lists"
300
+ file_notify_js="$QA_ROOT/notify.js"; file_notify_py="$QA_ROOT/notify.py"; list_crontab_user="$QA_ROOT/crontab"
301
+ cmd_task=task; file_extensions='js py'
302
+ ${helpers}
303
+ t() { :; }; make_dir() { mkdir -p "$1"; }; diff_cron() { :; }
304
+ git_clone_scripts() { mkdir -p "$2"; cp "$QA_ROOT/template/"* "$2/"; exit_status=0; }
305
+ ql() { get_uniq_path "$2" "$6"; update_repo "${'${@:2}'}"; }
306
+ ${formatCommand(doc)}`;
307
+ execFileSync('/bin/bash', ['-c', code], {
308
+ env: { ...process.env, QA_ROOT: root },
309
+ encoding: 'utf8',
310
+ timeout: 5000,
311
+ });
312
+ return path.join(root, 'scripts', 'owner_repo');
313
+ },
314
+ };
315
+ }
316
+
317
+ test('real repository update supports extension separators, filtering and dependency copies', (t) => {
318
+ for (const extension of ['js|py', 'js py', 'js\tpy', 'js\npy', '']) {
319
+ const f = updateFixture(t);
320
+ const scripts = f.run(extension);
321
+ assert.deepEqual(fs.readdirSync(scripts).sort(), [
322
+ 'dep.js',
323
+ 'keep.js',
324
+ 'keep.py',
325
+ 'notify.js',
326
+ 'notify.py',
327
+ ]);
328
+ assert.deepEqual(
329
+ fs
330
+ .readFileSync(
331
+ path.join(f.root, 'lists', 'owner_repo_scripts.list'),
332
+ 'utf8',
333
+ )
334
+ .trim()
335
+ .split('\n')
336
+ .sort(),
337
+ ['owner_repo/keep.js', 'owner_repo/keep.py'],
338
+ );
339
+ }
340
+ });
341
+
342
+ test('real repository update never evaluates extension input, including dependency discovery', (t) => {
343
+ const f = updateFixture(t);
344
+ const marker = path.join(f.root, 'executed');
345
+ const payloads = [
346
+ 'js|$(touch${IFS}' + marker + ')',
347
+ 'js|`touch${IFS}' + marker + '`',
348
+ 'js|py";touch${IFS}' + marker + ';#',
349
+ 'js|$(touch${IFS}' + marker + ')\npy',
350
+ ];
351
+ for (const payload of payloads) {
352
+ const scripts = f.run(payload);
353
+ assert.equal(fs.existsSync(marker), false, payload);
354
+ assert.equal(
355
+ fs.readFileSync(path.join(scripts, 'keep.js'), 'utf8'),
356
+ 'keep.js',
357
+ );
358
+ assert.equal(
359
+ fs.readFileSync(path.join(scripts, 'dep.js'), 'utf8'),
360
+ 'dep.js',
361
+ );
362
+ }
363
+ });
364
+
365
+ test('force deletion supports historical nested aliases while preserving outside targets', async (t) => {
366
+ const root = temporary(t);
367
+ const config = {
368
+ scriptPath: path.join(root, 'scripts'),
369
+ repoPath: path.join(root, 'repo'),
370
+ };
371
+ const alias = 'owner_repo_feature/foo';
372
+ for (const dir of [config.scriptPath, config.repoPath]) {
373
+ fs.mkdirSync(path.join(dir, alias), { recursive: true });
374
+ fs.writeFileSync(path.join(dir, alias, 'file'), 'fixture');
375
+ }
376
+ const outside = path.join(root, 'outside');
377
+ fs.mkdirSync(outside);
378
+ fs.writeFileSync(path.join(outside, 'file'), 'keep');
379
+ let destroyed = 0;
380
+ const doc = { id: 1, alias, get: () => doc };
381
+ const Subscription = load(path.resolve('back/services/subscription.ts'), {
382
+ '../config': config,
383
+ '../data/subscription': {
384
+ SubscriptionModel: {
385
+ findAll: async () => [doc],
386
+ destroy: async () => destroyed++,
387
+ },
388
+ },
389
+ '../data/cron': { CrontabModel: { findAll: async () => [] } },
390
+ '../config/util': {
391
+ rmPath: (p) => fs.promises.rm(p, { recursive: true, force: true }),
392
+ },
393
+ '../config/const': {},
394
+ '../shared/i18n': { t: (x) => x, tf: (x) => x },
395
+ '../shared/pLimit': {},
396
+ './schedule': {},
397
+ './sock': {},
398
+ './sshKey': {},
399
+ './cron': {},
400
+ }).default;
401
+ const service = new Subscription({}, {}, {}, {}, {});
402
+ service.handleTask = async () => {};
403
+ service.setSshConfig = async () => {};
404
+ await service.remove([1], { force: true });
405
+ assert.equal(destroyed, 1);
406
+ for (const dir of [config.scriptPath, config.repoPath])
407
+ assert.equal(fs.existsSync(path.join(dir, alias)), false);
408
+ fs.symlinkSync(outside, path.join(config.scriptPath, 'escape'));
409
+ doc.alias = 'escape/file';
410
+ await assert.rejects(
411
+ service.remove([1], { force: true }),
412
+ /Invalid subscription path/,
413
+ );
414
+ assert.equal(destroyed, 1);
415
+ assert.equal(fs.readFileSync(path.join(outside, 'file'), 'utf8'), 'keep');
416
+ assert.equal(paths.getSubscriptionSshAlias('仓库-main'), '仓库-main');
417
+ });
418
+
419
+ function cancellationFixture(t, subscriptions) {
420
+ const root = temporary(t);
421
+ const events = [];
422
+ const docs = subscriptions.map((value) => {
423
+ const doc = { ...value };
424
+ doc.get = () => ({ ...doc });
425
+ return doc;
426
+ });
427
+ const Subscription = load(path.resolve('back/services/subscription.ts'), {
428
+ '../config': { scriptPath: root, repoPath: root },
429
+ '../data/subscription': {
430
+ SubscriptionModel: {
431
+ findAll: async ({ where }) =>
432
+ docs.filter((doc) => !where.id || where.id.includes(doc.id)),
433
+ destroy: async ({ where }) => events.push(['destroy', where.id]),
434
+ update: async (value, { where }) => {
435
+ for (const doc of docs) {
436
+ if (where.id.includes(doc.id)) Object.assign(doc, value);
437
+ }
438
+ },
439
+ },
440
+ },
441
+ '../data/cron': {},
442
+ '../config/util': { rmPath: async () => events.push(['removeFile']) },
443
+ '../config/const': {},
444
+ '../shared/i18n': { t: (x) => x, tf: (x) => x },
445
+ '../shared/pLimit': {},
446
+ './schedule': {},
447
+ './sock': {},
448
+ './sshKey': {},
449
+ './cron': {},
450
+ }).default;
451
+ const schedule = {
452
+ cancelCronTask: (doc) => events.push(['cancelCron', doc.id]),
453
+ cancelIntervalTask: (doc) => events.push(['cancelInterval', doc.id]),
454
+ createCronTask: async (doc, callbacks, immediately) =>
455
+ events.push(['createCron', doc.command, immediately]),
456
+ createIntervalTask: async (doc, interval, immediately) =>
457
+ events.push(['createInterval', doc.command, interval, immediately]),
458
+ };
459
+ const service = new Subscription(
460
+ {}, schedule, {}, { removeSSHKey: async () => {} }, {},
461
+ );
462
+ service.setSshConfig = async () => {};
463
+ return { service, docs, events };
464
+ }
465
+
466
+ async function sshLifecycleFixture(t, initial) {
467
+ const root = temporary(t);
468
+ const ssh = sshService(root);
469
+ let docs = [{ ...initial, get() { return { ...this }; } }];
470
+ const SubscriptionService = load(path.resolve('back/services/subscription.ts'), {
471
+ '../config': { scriptPath: root, repoPath: root },
472
+ '../data/subscription': {
473
+ Subscription: class { constructor(value) { Object.assign(this, value); } },
474
+ SubscriptionModel: {
475
+ findAll: async () => docs,
476
+ destroy: async () => { docs = []; },
477
+ },
478
+ },
479
+ '../data/cron': { CrontabModel: { findAll: async () => [] } },
480
+ '../config/util': {
481
+ rmPath: (p) => fs.promises.rm(p, { recursive: true, force: true }),
482
+ },
483
+ '../config/const': {},
484
+ '../shared/i18n': { t: (x) => x, tf: (x) => x },
485
+ '../shared/pLimit': {},
486
+ './schedule': {}, './sock': {}, './sshKey': {}, './cron': {},
487
+ }).default;
488
+ const service = new SubscriptionService({}, {}, {}, ssh, {});
489
+ service.handleTask = async () => {};
490
+ service.getDb = async () => ({ ...docs[0] });
491
+ service.updateDb = async (value) => {
492
+ Object.assign(docs[0], value);
493
+ return { ...docs[0] };
494
+ };
495
+ await service.setSshConfig();
496
+ return { service, root };
497
+ }
498
+
499
+ test('editing an SSH subscription removes the old alias key and configuration', async (t) => {
500
+ const initial = privateSubscription('owner_repo_main');
501
+ const f = await sshLifecycleFixture(t, initial);
502
+ const alias = 'owner_repo_feature/中文';
503
+ await f.service.update({ ...initial, alias });
504
+ const mapped = paths.getSubscriptionSshAlias(alias);
505
+ assert.equal(fs.existsSync(path.join(f.root, initial.alias)), false);
506
+ assert.equal(fs.existsSync(path.join(f.root, initial.alias + '.config')), false);
507
+ assert.equal(fs.readFileSync(path.join(f.root, mapped), 'utf8').trim(), 'fixture-key');
508
+ assert.ok(fs.existsSync(path.join(f.root, mapped + '.config')));
509
+ });
510
+
511
+ test('switching an SSH subscription to a public repository removes obsolete credentials', async (t) => {
512
+ const initial = privateSubscription('owner_repo.config');
513
+ const f = await sshLifecycleFixture(t, initial);
514
+ await f.service.update({ ...initial, type: 'public-repo' });
515
+ assert.deepEqual(fs.readdirSync(f.root), []);
516
+ });
517
+
518
+ test('ordinary and forced subscription deletion remove the current SSH key and configuration', async (t) => {
519
+ for (const force of [false, true]) {
520
+ const initial = privateSubscription('owner_repo_feature/中文');
521
+ const f = await sshLifecycleFixture(t, initial);
522
+ await f.service.remove([initial.id], { force });
523
+ assert.deepEqual(fs.readdirSync(f.root), []);
524
+ }
525
+ });
526
+
527
+ test('ordinary deletion cancels invalid historical SSH subscriptions by ID', async (t) => {
528
+ for (const schedule_type of ['crontab', 'interval']) {
529
+ const f = cancellationFixture(t, [
530
+ {
531
+ ...privateSubscription('../outside'),
532
+ schedule_type,
533
+ interval_schedule: { type: 'hours', value: 1 },
534
+ },
535
+ ]);
536
+ await f.service.remove([1], { force: false });
537
+ assert.deepEqual(f.events, [
538
+ [schedule_type === 'crontab' ? 'cancelCron' : 'cancelInterval', 1],
539
+ ['destroy', [1]],
540
+ ]);
541
+ }
542
+ });
543
+
544
+ test('invalid historical SSH rows do not block mixed batch deletion or disabling', async (t) => {
545
+ const docs = [
546
+ { ...privateSubscription('healthy', 1), schedule_type: 'crontab' },
547
+ { ...privateSubscription('../outside', 2), schedule_type: 'crontab' },
548
+ {
549
+ ...privateSubscription('old alias', 3),
550
+ schedule_type: 'interval',
551
+ interval_schedule: { type: 'hours', value: 1 },
552
+ },
553
+ ];
554
+ const cancellations = [
555
+ ['cancelCron', 1],
556
+ ['cancelCron', 2],
557
+ ['cancelInterval', 3],
558
+ ];
559
+ const removed = cancellationFixture(t, docs);
560
+ await removed.service.remove([1, 2, 3], {});
561
+ assert.deepEqual(removed.events, [...cancellations, ['destroy', [1, 2, 3]]]);
562
+ const disabled = cancellationFixture(t, docs);
563
+ await disabled.service.disabled([1, 2, 3]);
564
+ assert.deepEqual(disabled.events, cancellations);
565
+ assert.ok(disabled.docs.every((doc) => doc.is_disabled === 1));
566
+ });
567
+
568
+ test('cancellation bypass leaves alias validation for creation and forced deletion intact', async (t) => {
569
+ const doc = {
570
+ ...privateSubscription('../outside'),
571
+ schedule_type: 'crontab',
572
+ };
573
+ const f = cancellationFixture(t, [doc]);
574
+ await assert.rejects(f.service.handleTask(doc), /Invalid subscription alias/);
575
+ await assert.rejects(f.service.create(doc), /Invalid subscription alias/);
576
+ await assert.rejects(f.service.enabled([1]), /Invalid subscription alias/);
577
+ await assert.rejects(
578
+ f.service.remove([1], { force: true }),
579
+ /Invalid subscription alias/,
580
+ );
581
+ assert.deepEqual(f.events, []);
582
+ });
583
+
584
+ test('valid subscription scheduling still creates quoted commands for both schedule types', async (t) => {
585
+ for (const schedule_type of ['crontab', 'interval']) {
586
+ const doc = {
587
+ ...privateSubscription('owner_repo_feature/foo'),
588
+ schedule_type,
589
+ interval_schedule: { type: 'hours', value: 1 },
590
+ };
591
+ const f = cancellationFixture(t, [doc]);
592
+ await f.service.handleTask(doc, true, true);
593
+ const command = formatCommand(doc);
594
+ assert.deepEqual(
595
+ f.events,
596
+ schedule_type === 'crontab'
597
+ ? [
598
+ ['cancelCron', 1],
599
+ ['createCron', command, true],
600
+ ]
601
+ : [
602
+ ['cancelInterval', 1],
603
+ ['createInterval', command, { hours: 1 }, true],
604
+ ],
605
+ );
606
+ }
607
+ });
@@ -0,0 +1,66 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const { Sequelize, DataTypes } = require('sequelize');
4
+ const load = require('../helpers/load-security-module.cjs');
5
+
6
+ async function fixture(t, onKill = async () => {}) {
7
+ const db = new Sequelize({
8
+ dialect: 'sqlite',
9
+ storage: ':memory:',
10
+ logging: false,
11
+ });
12
+ t.after(() => db.close());
13
+ const rows = db.define('Subscription', {
14
+ pid: DataTypes.INTEGER,
15
+ status: DataTypes.INTEGER,
16
+ });
17
+ await db.sync();
18
+ await rows.create({ id: 1, pid: 101, status: 0 });
19
+ const Service = load('back/services/subscription.ts', {
20
+ '../config': {},
21
+ '../data/cron': {},
22
+ '../config/const': {},
23
+ '../data/subscription': {
24
+ SubscriptionModel: rows,
25
+ SubscriptionStatus: { idle: 1 },
26
+ },
27
+ '../config/util': { killTask: async () => onKill(rows) },
28
+ '../config/subscription': {},
29
+ '../shared/i18n': {},
30
+ '../shared/pLimit': {},
31
+ '../shared/logReader': {},
32
+ '../shared/logStreamManager': {},
33
+ './schedule': {},
34
+ './sock': {},
35
+ './sshKey': {},
36
+ './cron': {},
37
+ }).default;
38
+ return { rows, service: new Service({ error() {} }, {}, {}, {}, {}) };
39
+ }
40
+
41
+ test('successful subscription stop clears the stored PID', async (t) => {
42
+ const f = await fixture(t);
43
+ await f.service.stop([1]);
44
+ const row = await f.rows.findByPk(1);
45
+ assert.equal(row.status, 1);
46
+ assert.equal(row.pid, null);
47
+ });
48
+
49
+ test('subscription stop does not overwrite a replacement process started during termination', async (t) => {
50
+ const f = await fixture(t, async (rows) => {
51
+ await rows.update({ pid: 202, status: 0 }, { where: { id: 1 } });
52
+ });
53
+ await f.service.stop([1]);
54
+ const row = await f.rows.findByPk(1);
55
+ assert.equal(row.status, 0);
56
+ assert.equal(row.pid, 202);
57
+ });
58
+
59
+ test('subscription stop cancels a queued row without a PID', async (t) => {
60
+ const f = await fixture(t, () => assert.fail('queued row has no process'));
61
+ await f.rows.update({ pid: null, status: 3 }, { where: { id: 1 } });
62
+ await f.service.stop([1]);
63
+ const row = await f.rows.findByPk(1);
64
+ assert.equal(row.status, 1);
65
+ assert.equal(row.pid, null);
66
+ });