@whyour/qinglong 2.21.0 → 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.
Files changed (279) 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 +4 -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/releases/2.22.0-validation.md +49 -0
  19. package/docs/releases/2.22.0.md +54 -0
  20. package/ecosystem.config.js +10 -1
  21. package/package.json +11 -6
  22. package/sample/config.sample.sh +17 -2
  23. package/sample/notify.js +118 -0
  24. package/sample/notify.py +93 -0
  25. package/scripts/benchmark-execution.cjs +96 -0
  26. package/scripts/write-build-info.cjs +27 -0
  27. package/shell/api.sh +41 -14
  28. package/shell/check.sh +59 -19
  29. package/shell/lang/en.sh +6 -0
  30. package/shell/lang/zh.sh +6 -0
  31. package/shell/node_path_cache.sh +128 -0
  32. package/shell/otask.sh +10 -1
  33. package/shell/preload/sitecustomize.js +5 -1
  34. package/shell/share.sh +26 -9
  35. package/shell/start.sh +6 -3
  36. package/shell/task.sh +13 -3
  37. package/shell/update.sh +65 -4
  38. package/static/build/api/clientIp.js +42 -0
  39. package/static/build/api/config.js +8 -16
  40. package/static/build/api/cron.js +39 -3
  41. package/static/build/api/dashboard.js +50 -6
  42. package/static/build/api/env.js +2 -2
  43. package/static/build/api/health.js +2 -2
  44. package/static/build/api/index.js +4 -0
  45. package/static/build/api/log.js +39 -19
  46. package/static/build/api/retention.js +63 -0
  47. package/static/build/api/script.js +23 -22
  48. package/static/build/api/subscription.js +16 -2
  49. package/static/build/api/system.js +31 -9
  50. package/static/build/api/user.js +75 -15
  51. package/static/build/app.js +63 -54
  52. package/static/build/bootstrap/database.js +51 -0
  53. package/static/build/config/const.js +2 -0
  54. package/static/build/config/grpcCerts.js +4 -4
  55. package/static/build/config/index.js +0 -4
  56. package/static/build/config/share.js +5 -4
  57. package/static/build/config/util.js +136 -41
  58. package/static/build/data/cron.js +1 -0
  59. package/static/build/data/notify.js +18 -1
  60. package/static/build/data/sock.js +1 -0
  61. package/static/build/loaders/app.js +8 -6
  62. package/static/build/loaders/db.js +5 -35
  63. package/static/build/loaders/deps.js +30 -22
  64. package/static/build/loaders/express.js +44 -32
  65. package/static/build/loaders/initData.js +10 -7
  66. package/static/build/loaders/initFile.js +1 -1
  67. package/static/build/loaders/initTask.js +3 -2
  68. package/static/build/loaders/server.js +1 -1
  69. package/static/build/loaders/sock.js +72 -6
  70. package/static/build/middlewares/monitoring.js +12 -33
  71. package/static/build/middlewares/protectedPathCase.js +17 -0
  72. package/static/build/protos/api.js +78 -2
  73. package/static/build/protos/cron.js +21 -4
  74. package/static/build/protos/health.js +1 -1
  75. package/static/build/schedule/addCron.js +76 -10
  76. package/static/build/schedule/api.js +5 -2
  77. package/static/build/schedule/client.js +38 -6
  78. package/static/build/schedule/delCron.js +11 -1
  79. package/static/build/schedule/health.js +72 -7
  80. package/static/build/services/config.js +5 -42
  81. package/static/build/services/cron.js +353 -164
  82. package/static/build/services/dependence.js +66 -18
  83. package/static/build/services/grpc.js +2 -2
  84. package/static/build/services/health.js +4 -7
  85. package/static/build/services/http.js +9 -3
  86. package/static/build/services/log.js +2 -3
  87. package/static/build/services/metrics.js +46 -14
  88. package/static/build/services/notify.js +73 -5
  89. package/static/build/services/retention.js +123 -0
  90. package/static/build/services/schedule.js +57 -33
  91. package/static/build/services/script.js +4 -5
  92. package/static/build/services/subscription.js +57 -34
  93. package/static/build/services/system.js +49 -11
  94. package/static/build/services/user.js +244 -31
  95. package/static/build/shared/auth.js +22 -3
  96. package/static/build/shared/authMutation.js +17 -0
  97. package/static/build/shared/childProcess.js +82 -0
  98. package/static/build/shared/clientIp.js +27 -0
  99. package/static/build/shared/errors.js +9 -0
  100. package/static/build/shared/fileAccess.js +60 -0
  101. package/static/build/shared/i18n.js +62 -4
  102. package/static/build/shared/logReader.js +85 -0
  103. package/static/build/shared/logStreamManager.js +80 -60
  104. package/static/build/shared/pLimit.js +3 -2
  105. package/static/build/shared/password.js +30 -0
  106. package/static/build/shared/retention.js +58 -0
  107. package/static/build/shared/runCron.js +28 -15
  108. package/static/build/shared/schedulerMutationLock.js +44 -0
  109. package/static/build/shared/schedulerReadiness.js +82 -0
  110. package/static/build/shared/schemaMigrations.js +58 -0
  111. package/static/build/shared/startupProcess.js +48 -0
  112. package/static/build/shared/store.js +7 -0
  113. package/static/build/shared/trustProxy.js +119 -0
  114. package/static/build/validation/schedule.js +12 -3
  115. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  116. package/static/dist/2031.6af40025.async.js +1 -0
  117. package/static/dist/2693.51c2636b.async.js +1 -0
  118. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  119. package/static/dist/2901.2ca95295.async.js +1 -0
  120. package/static/dist/445.a65ff63b.async.js +1 -0
  121. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  122. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  123. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  124. package/static/dist/6212.9e6d9913.async.js +1 -0
  125. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  126. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  127. package/static/dist/7231.f7e5b668.async.js +1 -0
  128. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  129. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  130. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  131. package/static/dist/8844.a0fef08e.async.js +1 -0
  132. package/static/dist/index.html +2 -2
  133. package/static/dist/layouts__index.633d3553.async.js +1 -0
  134. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  135. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  136. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  137. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  138. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  139. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  140. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  141. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  142. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  143. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  144. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  145. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  146. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  147. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  148. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  149. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  150. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  151. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  152. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  153. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  154. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  155. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  156. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  157. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  158. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  159. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  160. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  161. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  162. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  163. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  164. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  165. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  166. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  167. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  168. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  169. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  170. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  171. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  172. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  173. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  174. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  175. package/static/dist/{umi.ca04a019.js → umi.fc019050.js} +1 -1
  176. package/test/back/auth-security.test.cjs +74 -0
  177. package/test/back/build-provenance.test.cjs +150 -0
  178. package/test/back/cron-log-name.test.cjs +110 -0
  179. package/test/back/cron-validation.test.cjs +45 -0
  180. package/test/back/dashboard-failures.test.cjs +173 -0
  181. package/test/back/database-bootstrap.test.cjs +193 -0
  182. package/test/back/dependence-cache-status.test.cjs +125 -0
  183. package/test/back/deprecated-file-routes.test.cjs +82 -0
  184. package/test/back/ecosystem.test.cjs +28 -0
  185. package/test/back/env-name-parsing.test.cjs +96 -0
  186. package/test/back/execution-lifecycle.test.cjs +236 -0
  187. package/test/back/file-access-security.test.cjs +47 -0
  188. package/test/back/fileTreeListing.test.cjs +57 -0
  189. package/test/back/grpc-cron-response.test.cjs +60 -0
  190. package/test/back/http-exclusive-listen.test.cjs +31 -0
  191. package/test/back/http-security.test.cjs +213 -0
  192. package/test/back/listen-security.test.cjs +67 -0
  193. package/test/back/log-path-security.test.cjs +158 -0
  194. package/test/back/logReader.test.cjs +72 -0
  195. package/test/back/manual-execution.test.cjs +85 -0
  196. package/test/back/manual-stop-claim.test.cjs +220 -0
  197. package/test/back/metrics.test.cjs +34 -0
  198. package/test/back/monitoring.test.cjs +73 -0
  199. package/test/back/node-path-cache.test.cjs +173 -0
  200. package/test/back/node-path-lock.test.cjs +178 -0
  201. package/test/back/npm-publication.test.cjs +70 -0
  202. package/test/back/primary-apm.test.cjs +24 -0
  203. package/test/back/process-exit-state.test.cjs +81 -0
  204. package/test/back/process-stop-signal.test.cjs +77 -0
  205. package/test/back/protected-path-case.test.cjs +58 -0
  206. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  207. package/test/back/retention.test.cjs +131 -0
  208. package/test/back/role-loading.test.cjs +118 -0
  209. package/test/back/schedule-health.test.cjs +86 -0
  210. package/test/back/scheduler-file-lock.test.cjs +51 -0
  211. package/test/back/scheduler-mutation.test.cjs +312 -0
  212. package/test/back/scheduler-readiness.test.cjs +85 -0
  213. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  214. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  215. package/test/back/schema-migrations.test.cjs +127 -0
  216. package/test/back/shell-api-parsing.test.cjs +184 -0
  217. package/test/back/sock-polling.test.cjs +297 -0
  218. package/test/back/sock-security.test.cjs +72 -0
  219. package/test/back/start-env-preservation.test.cjs +53 -0
  220. package/test/back/stop-failure-feedback.test.cjs +158 -0
  221. package/test/back/stop-race.test.cjs +167 -0
  222. package/test/back/subscription-cleanup.test.cjs +53 -0
  223. package/test/back/subscription-stop-state.test.cjs +66 -0
  224. package/test/back/system-dependence-cache.test.cjs +126 -0
  225. package/test/back/task-time.test.cjs +116 -0
  226. package/test/back/user-api.test.cjs +99 -0
  227. package/test/back/user-security.test.cjs +248 -0
  228. package/test/back/worker-apm.test.cjs +84 -0
  229. package/test/back/wpush-grpc.test.cjs +115 -0
  230. package/test/front/cron-log-pagination.test.cjs +214 -0
  231. package/test/front/http-auth.test.cjs +152 -0
  232. package/test/front/http-error.test.cjs +29 -0
  233. package/test/helpers/load-security-module.cjs +42 -0
  234. package/version.yaml +19 -34
  235. package/CLAUDE.md +0 -43
  236. package/static/dist/1147.c420132e.async.js +0 -1
  237. package/static/dist/134.54df9e38.async.js +0 -1
  238. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  239. package/static/dist/2286.164bb089.async.js +0 -1
  240. package/static/dist/3191.63263871.async.js +0 -1
  241. package/static/dist/4902.555f92ab.async.js +0 -1
  242. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  243. package/static/dist/6431.c50479be.async.js +0 -1
  244. package/static/dist/8826.2447a104.async.js +0 -1
  245. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  246. package/static/dist/preload_helper.0431c0f3.js +0 -1
  247. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  248. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  249. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  250. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  251. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  252. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  253. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  254. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  255. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  256. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  257. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  258. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  259. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  260. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  261. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  262. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  263. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  264. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  265. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  266. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  267. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  268. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  269. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  270. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  271. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  272. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  273. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  274. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  275. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  276. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  277. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  278. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  279. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
@@ -0,0 +1,74 @@
1
+ const assert = require('node:assert/strict');
2
+ const test = require('node:test');
3
+ const path = require('node:path');
4
+ const jwt = require('jsonwebtoken');
5
+ const load = require('../helpers/load-security-module.cjs');
6
+ const { isValidToken } = load(
7
+ path.join(__dirname, '../../back/shared/auth.ts'),
8
+ );
9
+ const { hashPassword, verifyPassword } = load(
10
+ path.join(__dirname, '../../back/shared/password.ts'),
11
+ );
12
+ const secret = 'security-test-secret';
13
+ const token = (payload = {}, options = {}) =>
14
+ jwt.sign(payload, secret, {
15
+ algorithm: 'HS384',
16
+ expiresIn: '1h',
17
+ ...options,
18
+ });
19
+ const info = (value) => ({ token: value, tokens: {} });
20
+
21
+ test('valid legacy and platform sessions retain compatibility', () => {
22
+ const value = token();
23
+ for (const auth of [
24
+ info(value),
25
+ { tokens: { desktop: value } },
26
+ { tokens: { desktop: [{ value }] } },
27
+ ]) {
28
+ assert.equal(isValidToken(auth, value, 'desktop', secret), true);
29
+ }
30
+ assert.equal(
31
+ isValidToken({ tokens: { mobile: value } }, value, 'desktop', secret),
32
+ false,
33
+ );
34
+ });
35
+
36
+ test('session membership never bypasses JWT signature, expiry, algorithm or nbf', () => {
37
+ const values = [
38
+ token({}, { expiresIn: -1 }),
39
+ token({}, { algorithm: 'HS256' }),
40
+ token({ nbf: Math.floor(Date.now() / 1000) + 60 }),
41
+ jwt.sign({}, 'wrong-secret', { algorithm: 'HS384', expiresIn: '1h' }),
42
+ jwt.sign({}, secret, { algorithm: 'HS384' }),
43
+ 'not-a-token',
44
+ ];
45
+ for (const value of values)
46
+ assert.equal(isValidToken(info(value), value, 'desktop', secret), false);
47
+ assert.equal(isValidToken({ tokens: {} }, token(), 'desktop', secret), false);
48
+ assert.equal(isValidToken(null, token(), 'desktop', secret), false);
49
+ assert.equal(isValidToken(info(''), '', 'desktop', secret), false);
50
+ });
51
+
52
+ test('platform token metadata can shorten but cannot extend JWT expiration', () => {
53
+ const value = token();
54
+ assert.equal(
55
+ isValidToken(
56
+ { tokens: { desktop: [{ value, expiration: 1 }] } },
57
+ value,
58
+ 'desktop',
59
+ secret,
60
+ ),
61
+ false,
62
+ );
63
+ });
64
+
65
+ test('passwords are salted and legacy plaintext can migrate without changing the password', async () => {
66
+ const first = await hashPassword('owner-password');
67
+ const second = await hashPassword('owner-password');
68
+ assert.notEqual(first, second);
69
+ assert.equal(await verifyPassword('owner-password', first), true);
70
+ assert.equal(await verifyPassword('wrong-password', first), false);
71
+ assert.equal(await verifyPassword(first, first), false);
72
+ assert.equal(await verifyPassword('old-password', 'old-password'), true);
73
+ assert.equal(await verifyPassword('wrong', 'old-password'), false);
74
+ });
@@ -0,0 +1,150 @@
1
+ const assert = require('node:assert/strict');
2
+ const test = require('node:test');
3
+ const fs = require('node:fs');
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+ const { execFileSync, spawnSync } = require('node:child_process');
7
+
8
+ test('build verification accepts matching source and rejects stale or dirty artifacts', (t) => {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-build-source-'));
10
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
11
+ const git = (...args) =>
12
+ execFileSync('git', args, { cwd: dir, stdio: 'pipe' });
13
+ git('init');
14
+ git('config', 'user.name', 'Build test');
15
+ git('config', 'user.email', 'build-test@example.invalid');
16
+ fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), 'lockfileVersion: 6.0\n');
17
+ fs.writeFileSync(path.join(dir, '.gitignore'), 'static/\n');
18
+ git('add', '.');
19
+ git('commit', '-m', 'fixture');
20
+ fs.mkdirSync(path.join(dir, 'static/build'), { recursive: true });
21
+ fs.mkdirSync(path.join(dir, 'static/dist'), { recursive: true });
22
+ fs.writeFileSync(path.join(dir, 'static/build/app.js'), '');
23
+ fs.writeFileSync(path.join(dir, 'static/dist/index.html'), '');
24
+ const write = path.resolve('scripts/write-build-info.cjs');
25
+ const verify = path.resolve('docker/verify-build.cjs');
26
+ execFileSync(process.execPath, [write], { cwd: dir });
27
+ execFileSync(process.execPath, [verify], { cwd: dir });
28
+ const manifestPath = path.join(dir, 'static/build-info.json');
29
+ const manifest = JSON.parse(fs.readFileSync(manifestPath));
30
+ for (const invalid of [
31
+ { ...manifest, sourceCommit: '0'.repeat(40) },
32
+ { ...manifest, dirty: true },
33
+ { ...manifest, lockfileSha256: '0'.repeat(64) },
34
+ ]) {
35
+ fs.writeFileSync(manifestPath, JSON.stringify(invalid));
36
+ assert.notEqual(
37
+ spawnSync(process.execPath, [verify], { cwd: dir }).status,
38
+ 0,
39
+ );
40
+ }
41
+ });
42
+
43
+ test('release images receive the same-run artifact and verify it before use', () => {
44
+ const yaml = require('js-yaml');
45
+ const workflow = yaml.load(
46
+ fs.readFileSync('.github/workflows/build-docker-image.yml', 'utf8'),
47
+ );
48
+ assert.equal(workflow.jobs['build-static'].needs, 'validate');
49
+ const upload = workflow.jobs['build-static'].steps.find(step => step.uses?.startsWith('actions/upload-artifact@'));
50
+ assert.equal(upload.with['include-hidden-files'], true);
51
+ for (const name of [
52
+ 'build-alpine',
53
+ 'build-debian',
54
+ 'build-alpine310',
55
+ 'build-debian310',
56
+ ]) {
57
+ const job = workflow.jobs[name];
58
+ assert.equal(job.needs, 'build-static');
59
+ const download = job.steps.find((step) =>
60
+ step.uses?.startsWith('actions/download-artifact@'),
61
+ );
62
+ assert.equal(download.with.name, 'qinglong-static-${{ github.sha }}');
63
+ assert.equal(download.with.path, 'static/');
64
+ const build = job.steps.find((step) =>
65
+ step.uses?.startsWith('docker/build-push-action@'),
66
+ );
67
+ assert.match(
68
+ build.with['build-args'],
69
+ /SOURCE_COMMIT=\$\{\{ github.sha \}\}/,
70
+ );
71
+ const dockerfile = fs.readFileSync(build.with.file, 'utf8');
72
+ assert.doesNotMatch(dockerfile, /git clone.*qinglong-static/);
73
+ assert.match(
74
+ dockerfile,
75
+ /git fetch --depth=1 origin "\$\{SOURCE_COMMIT\}"/,
76
+ );
77
+ assert.match(dockerfile, /node \/tmp\/verify-build.cjs/);
78
+ }
79
+ });
80
+
81
+ test('complete artifact manifests reject changed, missing, extra files and untracked build inputs', (t) => {
82
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-build-manifest-'));
83
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
84
+ const git = (...args) =>
85
+ execFileSync('git', args, { cwd: dir, stdio: 'pipe' });
86
+ git('init');
87
+ git('config', 'user.name', 'Build test');
88
+ git('config', 'user.email', 'build-test@example.invalid');
89
+ fs.writeFileSync(path.join(dir, '.gitignore'), 'static/\n');
90
+ fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), 'lockfileVersion: 6.0\n');
91
+ git('add', '.');
92
+ git('commit', '-m', 'fixture');
93
+ const artifacts = [
94
+ 'build/app.js',
95
+ 'build/services/http.js',
96
+ 'dist/index.html',
97
+ 'dist/chunks/main.js',
98
+ 'dist/assets/main.css',
99
+ 'dist/.well-known/config',
100
+ ];
101
+ for (const file of artifacts) {
102
+ fs.mkdirSync(path.dirname(path.join(dir, 'static', file)), {
103
+ recursive: true,
104
+ });
105
+ fs.writeFileSync(path.join(dir, 'static', file), file);
106
+ }
107
+ const write = path.resolve('scripts/write-build-info.cjs');
108
+ const verify = path.resolve('docker/verify-build.cjs');
109
+ const run = (script) =>
110
+ spawnSync(process.execPath, [script], { cwd: dir, encoding: 'utf8' });
111
+ assert.equal(run(write).status, 0);
112
+ const manifestFile = path.join(dir, 'static/build-info.json');
113
+ const original = fs.readFileSync(manifestFile, 'utf8');
114
+ assert.deepEqual(
115
+ Object.keys(JSON.parse(original).files).sort(),
116
+ artifacts.sort(),
117
+ );
118
+ assert.equal(run(write).status, 0);
119
+ assert.equal(fs.readFileSync(manifestFile, 'utf8'), original);
120
+ assert.equal(run(verify).status, 0);
121
+ for (const name of [
122
+ 'build/services/http.js',
123
+ 'dist/chunks/main.js',
124
+ 'dist/assets/main.css',
125
+ 'dist/.well-known/config',
126
+ ]) {
127
+ const file = path.join(dir, 'static', name);
128
+ fs.writeFileSync(file, 'stale');
129
+ assert.notEqual(run(verify).status, 0);
130
+ fs.unlinkSync(file);
131
+ assert.notEqual(run(verify).status, 0);
132
+ fs.writeFileSync(file, name);
133
+ assert.equal(run(verify).status, 0);
134
+ }
135
+ const extra = path.join(dir, 'static/build/stale.js');
136
+ fs.writeFileSync(extra, 'extra');
137
+ assert.notEqual(run(verify).status, 0);
138
+ fs.unlinkSync(extra);
139
+ const source = path.join(dir, 'custom.config.js');
140
+ fs.writeFileSync(source, 'untracked build input');
141
+ assert.equal(run(write).status, 0);
142
+ assert.equal(JSON.parse(fs.readFileSync(manifestFile)).dirty, true);
143
+ assert.notEqual(run(verify).status, 0);
144
+ fs.unlinkSync(source);
145
+ assert.equal(run(write).status, 0);
146
+ assert.equal(run(verify).status, 0);
147
+ fs.symlinkSync(path.join(dir, 'pnpm-lock.yaml'), extra);
148
+ assert.notEqual(run(write).status, 0);
149
+ assert.notEqual(run(verify).status, 0);
150
+ });
@@ -0,0 +1,110 @@
1
+ const assert = require('node:assert/strict');
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const test = require('node:test');
5
+ const ts = require('typescript');
6
+ const loadModule = require('../helpers/load-security-module.cjs');
7
+
8
+ const { commonCronSchema } = loadModule(
9
+ path.join(__dirname, '../../back/validation/schedule.ts'),
10
+ { '../config': { logPath: '/ql/data/log/' } },
11
+ );
12
+
13
+ // Execute the actual form validator without mounting the entire task modal.
14
+ const source = ts.createSourceFile(
15
+ 'modal.tsx',
16
+ fs.readFileSync(
17
+ path.join(__dirname, '../../src/pages/crontab/modal.tsx'),
18
+ 'utf8',
19
+ ),
20
+ ts.ScriptTarget.Latest,
21
+ true,
22
+ ts.ScriptKind.TSX,
23
+ );
24
+ let validateForm;
25
+ function visit(node) {
26
+ if (
27
+ ts.isJsxOpeningElement(node) &&
28
+ node.attributes.properties.some(
29
+ (attr) =>
30
+ ts.isJsxAttribute(attr) &&
31
+ attr.name.text === 'name' &&
32
+ attr.initializer?.text === 'log_name',
33
+ )
34
+ ) {
35
+ const rules = node.attributes.properties.find(
36
+ (attr) => ts.isJsxAttribute(attr) && attr.name.text === 'rules',
37
+ );
38
+ const validator = rules.initializer.expression.elements[0].properties.find(
39
+ (property) => property.name.text === 'validator',
40
+ ).initializer;
41
+ const { outputText } = ts.transpileModule(
42
+ `const validate = ${validator.getText(source)};`,
43
+ { compilerOptions: { target: ts.ScriptTarget.ES2017 } },
44
+ );
45
+ validateForm = new Function('intl', `${outputText}\nreturn validate;`)({
46
+ get: (key) => key,
47
+ });
48
+ }
49
+ ts.forEachChild(node, visit);
50
+ }
51
+ visit(source);
52
+ assert.equal(typeof validateForm, 'function');
53
+
54
+ test('form and API accept Chinese log names and existing supported names', async () => {
55
+ for (const value of [
56
+ '',
57
+ null,
58
+ undefined,
59
+ '测试',
60
+ '任务_測試-2026.log',
61
+ '分组/每日签到/',
62
+ '𠮷/扩展汉字',
63
+ 'legacy_name-123.log',
64
+ 'legacy/path/',
65
+ '/ql/data/log/中文日志',
66
+ '/dev/null',
67
+ '中'.repeat(100),
68
+ ]) {
69
+ await validateForm(undefined, value);
70
+ assert.equal(
71
+ commonCronSchema.log_name.validate(value).error,
72
+ undefined,
73
+ value,
74
+ );
75
+ }
76
+ });
77
+
78
+ test('form and API still reject unsafe relative names and excessive length', async () => {
79
+ for (const value of [
80
+ '.',
81
+ '..',
82
+ '../测试',
83
+ '测试/../日志',
84
+ '测试/./日志',
85
+ '测试//日志',
86
+ '测试\\日志',
87
+ '测试 日志',
88
+ '测试;echo',
89
+ '测试$(id)',
90
+ '测试`id`',
91
+ '测试\n日志',
92
+ '测试\0日志',
93
+ '测试😀',
94
+ '中'.repeat(101),
95
+ ]) {
96
+ await assert.rejects(validateForm(undefined, value), undefined, value);
97
+ assert.ok(commonCronSchema.log_name.validate(value).error, value);
98
+ }
99
+ });
100
+
101
+ test('API restricts absolute log paths to the configured directory or /dev/null', () => {
102
+ for (const value of [
103
+ '/tmp/测试',
104
+ '/ql/data/log/../测试',
105
+ '/ql/data/log-other/测试',
106
+ ]) {
107
+ const { error } = commonCronSchema.log_name.validate(value);
108
+ assert.equal(error.details[0].type, 'string.unsafePath', value);
109
+ }
110
+ });
@@ -0,0 +1,45 @@
1
+ const assert = require('node:assert/strict');
2
+ const test = require('node:test');
3
+
4
+ const configPath = require.resolve('../../back/config');
5
+ require.cache[configPath] = {
6
+ id: configPath,
7
+ filename: configPath,
8
+ loaded: true,
9
+ exports: { __esModule: true, default: { logPath: '/ql/data/log' } },
10
+ children: [],
11
+ paths: [],
12
+ };
13
+
14
+ const { commonCronSchema } = require('../../back/validation/schedule');
15
+ const { Joi } = require('celebrate');
16
+
17
+ const schema = Joi.object(commonCronSchema);
18
+
19
+ test('cron validation accepts leading-zero schedules and legacy null labels', () => {
20
+ const result = schema.validate({
21
+ name: 'legacy cron',
22
+ command: 'task legacy.js',
23
+ schedule: '01 7 * * *',
24
+ labels: null,
25
+ });
26
+
27
+ assert.equal(result.error, undefined);
28
+ });
29
+
30
+ test('cron validation identifies invalid fields', () => {
31
+ const result = schema.validate(
32
+ {
33
+ name: 'invalid cron',
34
+ command: 'task invalid.js',
35
+ schedule: '01 7 * * *',
36
+ allow_multiple_instances: '',
37
+ },
38
+ { abortEarly: false },
39
+ );
40
+
41
+ assert.deepEqual(
42
+ [...new Set(result.error.details.map((detail) => detail.path.join('.')))],
43
+ ['allow_multiple_instances'],
44
+ );
45
+ });
@@ -0,0 +1,173 @@
1
+ require('ts-node/register/transpile-only');
2
+ const assert = require('node:assert/strict');
3
+ const { test } = require('node:test');
4
+ const { Sequelize, DataTypes } = require('sequelize');
5
+ const dayjs = require('dayjs');
6
+ const express = require('express');
7
+
8
+ test('today result lists include mixed and deleted tasks and exclude other dates', async (t) => {
9
+ const db = new Sequelize({
10
+ dialect: 'sqlite',
11
+ storage: ':memory:',
12
+ logging: false,
13
+ });
14
+ t.after(() => db.close());
15
+ const crons = db.define('Cron', {
16
+ name: DataTypes.STRING,
17
+ command: DataTypes.STRING,
18
+ });
19
+ const stats = db.define('Stat', {
20
+ ref_id: DataTypes.INTEGER,
21
+ date: DataTypes.STRING,
22
+ fail_count: DataTypes.INTEGER,
23
+ success_count: DataTypes.INTEGER,
24
+ });
25
+ const replacements = {
26
+ '../../back/data/cron': { CrontabModel: crons },
27
+ '../../back/data/cronStats': { CrontabStatModel: stats },
28
+ '../../back/data/runningInstance': {},
29
+ '../../back/shared/i18n': { tf: (format, id) => format.replace('%s', id) },
30
+ };
31
+ for (const [modulePath, exports] of Object.entries(replacements)) {
32
+ const resolved = require.resolve(modulePath);
33
+ const original = require.cache[resolved];
34
+ require.cache[resolved] = {
35
+ id: resolved,
36
+ filename: resolved,
37
+ loaded: true,
38
+ exports,
39
+ };
40
+ t.after(() => {
41
+ if (original) require.cache[resolved] = original;
42
+ else delete require.cache[resolved];
43
+ });
44
+ }
45
+ await db.sync();
46
+ await crons.bulkCreate([
47
+ { id: 1, name: 'Recovered task', command: 'task recovered.js' },
48
+ { id: 2, name: '', command: 'task unnamed.js' },
49
+ { id: 3, name: 'Successful task', command: 'task success.js' },
50
+ ]);
51
+ const today = dayjs().format('YYYY-MM-DD');
52
+ await stats.bulkCreate([
53
+ { ref_id: 1, date: today, fail_count: 2, success_count: 1 },
54
+ { ref_id: 2, date: today, fail_count: 1, success_count: 0 },
55
+ { ref_id: 3, date: today, fail_count: 0, success_count: 4 },
56
+ { ref_id: 4, date: today, fail_count: 3, success_count: 2 },
57
+ {
58
+ ref_id: 3,
59
+ date: dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
60
+ fail_count: 10,
61
+ success_count: 20,
62
+ },
63
+ ]);
64
+ const router = express.Router();
65
+ require('../../back/api/dashboard').default(router);
66
+ const dashboard = router.stack.find(
67
+ (layer) => layer.name === 'router',
68
+ ).handle;
69
+ const handler = dashboard.stack.find(
70
+ (layer) => layer.route?.path === '/failures',
71
+ ).route.stack[0].handle;
72
+ const successHandler = dashboard.stack.find(
73
+ (layer) => layer.route?.path === '/successes',
74
+ ).route.stack[0].handle;
75
+ let response;
76
+ await handler(
77
+ {},
78
+ {
79
+ send: (value) => {
80
+ response = value;
81
+ },
82
+ },
83
+ (error) => {
84
+ throw error;
85
+ },
86
+ );
87
+ assert.deepEqual(response, {
88
+ code: 200,
89
+ data: [
90
+ { id: 4, name: '任务#4', command: '', failCount: 3, deleted: true },
91
+ {
92
+ id: 1,
93
+ name: 'Recovered task',
94
+ command: 'task recovered.js',
95
+ failCount: 2,
96
+ deleted: false,
97
+ },
98
+ {
99
+ id: 2,
100
+ name: 'task unnamed.js',
101
+ command: 'task unnamed.js',
102
+ failCount: 1,
103
+ deleted: false,
104
+ },
105
+ ],
106
+ });
107
+ await successHandler(
108
+ {},
109
+ {
110
+ send: (value) => {
111
+ response = value;
112
+ },
113
+ },
114
+ (error) => {
115
+ throw error;
116
+ },
117
+ );
118
+ assert.deepEqual(response, {
119
+ code: 200,
120
+ data: [
121
+ {
122
+ id: 3,
123
+ name: 'Successful task',
124
+ command: 'task success.js',
125
+ successCount: 4,
126
+ deleted: false,
127
+ },
128
+ { id: 4, name: '任务#4', command: '', successCount: 2, deleted: true },
129
+ {
130
+ id: 1,
131
+ name: 'Recovered task',
132
+ command: 'task recovered.js',
133
+ successCount: 1,
134
+ deleted: false,
135
+ },
136
+ ],
137
+ });
138
+ await stats.destroy({ where: {} });
139
+ await successHandler(
140
+ {},
141
+ {
142
+ send: (value) => {
143
+ response = value;
144
+ },
145
+ },
146
+ (error) => {
147
+ throw error;
148
+ },
149
+ );
150
+ assert.deepEqual(response, { code: 200, data: [] });
151
+ await handler(
152
+ {},
153
+ {
154
+ send: (value) => {
155
+ response = value;
156
+ },
157
+ },
158
+ (error) => {
159
+ throw error;
160
+ },
161
+ );
162
+ assert.deepEqual(response, { code: 200, data: [] });
163
+ await stats.drop();
164
+ let forwarded;
165
+ await handler(
166
+ {},
167
+ { send: () => assert.fail('must forward database errors') },
168
+ (error) => {
169
+ forwarded = error;
170
+ },
171
+ );
172
+ assert.ok(forwarded instanceof Error);
173
+ });