@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,416 @@
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 vm = require('node:vm');
7
+ const { execFileSync } = require('node:child_process');
8
+ const load = require('../helpers/load-security-module.cjs');
9
+ const decorators = { Service: () => (x) => x, Inject: () => () => {} };
10
+ const logger = { info() {}, warn() {}, error() {} };
11
+ const translate = { t: (x) => x, tf: (x) => x };
12
+ function temporary(t) {
13
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-advisory-'));
14
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
15
+ return dir;
16
+ }
17
+
18
+ test('environment values remain literal when the generated JavaScript loads', async () => {
19
+ const output = {};
20
+ const Env = load(path.resolve('back/services/env.ts'), {
21
+ typedi: decorators,
22
+ '../config': { envFile: 'sh', jsEnvFile: 'js', pyEnvFile: 'py' },
23
+ '../data/env': { EnvStatus: { normal: 0 } },
24
+ '../data': {},
25
+ '../shared/utils': {
26
+ writeFileWithLock: async (file, text) => (output[file] = text),
27
+ },
28
+ }).default;
29
+ const service = new Env(logger);
30
+ const values = [
31
+ '${globalThis.injected = true}',
32
+ 'quotes\'"` \\ newline\n中文\u2028',
33
+ '${1 + 2}',
34
+ ];
35
+ service.envs = async () =>
36
+ values.map((value, i) => ({ name: `VALUE_${i}`, value }));
37
+ await service.set_envs();
38
+ const context = { process: { env: {} } };
39
+ vm.runInNewContext(output.js, context);
40
+ assert.equal(context.injected, undefined);
41
+ values.forEach((value, i) =>
42
+ assert.equal(context.process.env[`VALUE_${i}`], value),
43
+ );
44
+ });
45
+
46
+ test('subscription shell parameters round trip without expansion or command substitution', () => {
47
+ const { formatCommand } = load(path.resolve('back/config/subscription.ts'));
48
+ const payload =
49
+ 'a $(printf INJECTED) `printf INJECTED` " ; echo BAD; # \' 中文\nnext';
50
+ for (const type of ['file', 'repo']) {
51
+ const fields =
52
+ type === 'file'
53
+ ? ['url', 'proxy']
54
+ : [
55
+ 'url',
56
+ 'whitelist',
57
+ 'blacklist',
58
+ 'dependences',
59
+ 'branch',
60
+ 'extensions',
61
+ 'proxy',
62
+ ];
63
+ for (const field of fields) {
64
+ const doc = {
65
+ id: 12,
66
+ type,
67
+ url: 'https://example.invalid/repo',
68
+ [field]: payload,
69
+ };
70
+ const command = formatCommand(doc);
71
+ const stdout = execFileSync('/bin/bash', [
72
+ '-c',
73
+ `ql() { printf '%s\\0' "$@"; }; ${command}`,
74
+ ]);
75
+ const args = stdout.toString().split('\0').slice(0, -1);
76
+ assert.equal(
77
+ args[fields.indexOf(field) + 1],
78
+ payload,
79
+ `${type}:${field}`,
80
+ );
81
+ assert.equal(args[0], type === 'file' ? 'raw' : 'repo');
82
+ assert.equal(args.length, fields.length + 3);
83
+ }
84
+ }
85
+ });
86
+
87
+ test('SSH alias traversal and symlinks cannot write or remove outside files', async (t) => {
88
+ const base = temporary(t);
89
+ const root = path.join(base, 'ssh');
90
+ fs.mkdirSync(root);
91
+ const outside = path.join(base, 'outside');
92
+ fs.writeFileSync(outside, 'keep');
93
+ fs.symlinkSync(outside, path.join(root, 'link'));
94
+ const Ssh = load(path.resolve('back/services/sshKey.ts'), {
95
+ typedi: decorators,
96
+ '../config': { sshdPath: root },
97
+ '../config/util': {
98
+ rmPath: (p) => fs.promises.rm(p, { recursive: true, force: true }),
99
+ },
100
+ '../shared/utils': {
101
+ writeFileWithLock: (p, value) => fs.promises.writeFile(p, value),
102
+ },
103
+ }).default;
104
+ const service = Object.assign(Object.create(Ssh.prototype), {
105
+ sshPath: root,
106
+ logger,
107
+ });
108
+ for (const alias of [
109
+ '../outside',
110
+ '..',
111
+ '.',
112
+ '/tmp/outside',
113
+ 'link',
114
+ 'x\nHost *',
115
+ ]) {
116
+ await service.generatePrivateKeyFile(alias, 'overwrite');
117
+ await service.removePrivateKeyFile(alias);
118
+ await assert.rejects(service.generateSingleSshConfig(alias, 'github.com'));
119
+ assert.equal(fs.readFileSync(outside, 'utf8'), 'keep');
120
+ }
121
+ await service.generatePrivateKeyFile('仓库-main', 'private-key');
122
+ await service.generateSingleSshConfig(
123
+ '仓库-main',
124
+ 'github.com',
125
+ '127.0.0.1:1080',
126
+ );
127
+ assert.equal(
128
+ fs.readFileSync(path.join(root, '仓库-main'), 'utf8').trim(),
129
+ 'private-key',
130
+ );
131
+ await service.generatePrivateKeyFile('~global_default', 'global-key');
132
+ await service.generateGlobalSshConfig('~global_default');
133
+ assert.match(
134
+ fs.readFileSync(path.join(root, '~global_default.config'), 'utf8'),
135
+ /Host \*/,
136
+ );
137
+ await assert.rejects(
138
+ service.generateSingleSshConfig('safe', 'host\nProxyCommand bad'),
139
+ );
140
+ await assert.rejects(
141
+ service.generateSingleSshConfig('safe', 'host', '$(printf BAD)'),
142
+ );
143
+ });
144
+
145
+ function cronService(config, updates = []) {
146
+ const Cron = load(path.resolve('back/services/cron.ts'), {
147
+ typedi: decorators,
148
+ '../config': config,
149
+ '../data/cron': {
150
+ CrontabStatus: { running: 0, idle: 1, queued: 3 },
151
+ CrontabModel: { update: async (v) => updates.push(v) },
152
+ },
153
+ '../data/runningInstance': { RunningInstanceModel: {}, InstanceStatus: {} },
154
+ '../config/util': { fileExist: async (p) => fs.existsSync(p) },
155
+ '../config/const': {},
156
+ '../schedule/client': {},
157
+ '../shared/pLimit': {},
158
+ '../shared/utils': {},
159
+ '../shared/i18n': translate,
160
+ '../shared/logStreamManager': {},
161
+ '../shared/cronSchedule': {},
162
+ }).default;
163
+ return new Cron(logger);
164
+ }
165
+ function subscriptionService(config, model = {}) {
166
+ const Subscription = load(path.resolve('back/services/subscription.ts'), {
167
+ typedi: decorators,
168
+ '../config': config,
169
+ '../data/subscription': {
170
+ SubscriptionModel: model,
171
+ SubscriptionStatus: {},
172
+ },
173
+ '../data/cron': {},
174
+ '../config/util': { fileExist: async (p) => fs.existsSync(p) },
175
+ '../config/const': {},
176
+ '../shared/i18n': translate,
177
+ '../shared/pLimit': {},
178
+ '../shared/logStreamManager': {},
179
+ './schedule': {},
180
+ './sock': {},
181
+ './sshKey': {},
182
+ './cron': {},
183
+ }).default;
184
+ return new Subscription(logger, {}, {}, {}, {});
185
+ }
186
+
187
+ test('stored cron/subscription paths cannot read or enumerate outside the log root', async (t) => {
188
+ const base = temporary(t);
189
+ const root = path.join(base, 'log');
190
+ fs.mkdirSync(root);
191
+ fs.mkdirSync(path.join(base, 'outside'));
192
+ const secret = path.join(base, 'outside', 'secret');
193
+ fs.writeFileSync(secret, 'SECRET');
194
+ fs.symlinkSync(path.dirname(secret), path.join(root, 'escape'));
195
+ fs.writeFileSync(path.join(root, 'normal.log'), 'NORMAL');
196
+ const updates = [];
197
+ const cron = cronService({ logPath: root }, updates);
198
+ const subscription = subscriptionService(
199
+ { logPath: root },
200
+ { update: async (v) => updates.push(v) },
201
+ );
202
+ for (const log_path of [secret, '../outside/secret', 'escape/secret']) {
203
+ cron.getDb = subscription.getDb = async () => ({ log_path, status: 1 });
204
+ await assert.rejects(cron.log(1), /outside the log directory/);
205
+ await assert.rejects(cron.logs(1), /outside the log directory/);
206
+ await assert.rejects(subscription.logs(1), /outside the log directory/);
207
+ await assert.rejects(
208
+ cron.status({ ids: [1], status: 0, log_path }),
209
+ /outside the log directory/,
210
+ );
211
+ await assert.rejects(
212
+ subscription.status({ ids: [1], status: 0, log_path }),
213
+ /outside the log directory/,
214
+ );
215
+ }
216
+ assert.equal(updates.length, 0);
217
+ cron.getDb = subscription.getDb = async () => ({
218
+ log_path: 'normal.log',
219
+ status: 1,
220
+ });
221
+ assert.equal((await cron.log(1)).content, 'NORMAL');
222
+ assert.ok((await cron.logs(1)).some((x) => x.filename === 'normal.log'));
223
+ assert.ok(
224
+ (await subscription.logs(1)).some((x) => x.filename === 'normal.log'),
225
+ );
226
+ });
227
+
228
+ test('subscription aliases are checked before persistence and forced deletion', async (t) => {
229
+ const base = temporary(t);
230
+ for (const dir of ['scripts', 'repo']) fs.mkdirSync(path.join(base, dir));
231
+ let writes = 0;
232
+ const service = subscriptionService(
233
+ {
234
+ scriptPath: path.join(base, 'scripts'),
235
+ repoPath: path.join(base, 'repo'),
236
+ },
237
+ {
238
+ findAll: async () => [{ alias: '../victim' }],
239
+ destroy: async () => writes++,
240
+ },
241
+ );
242
+ service.insert = service.updateDb = async () => writes++;
243
+ await assert.rejects(
244
+ service.create({ alias: '../victim' }),
245
+ /Invalid subscription alias/,
246
+ );
247
+ await assert.rejects(
248
+ service.update({ alias: '../victim' }),
249
+ /Invalid subscription alias/,
250
+ );
251
+ await assert.rejects(
252
+ service.remove([1], { force: true }),
253
+ /Invalid subscription alias/,
254
+ );
255
+ assert.equal(writes, 0);
256
+ });
257
+
258
+ function systemService(config, overrides = {}) {
259
+ const System = load(path.resolve('back/services/system.ts'), {
260
+ typedi: decorators,
261
+ '../config': config,
262
+ '../config/const': {},
263
+ '../data/dependence': {
264
+ DependenceModel: { findAll: async () => [] },
265
+ DependenceTypes: {},
266
+ DependenceStatus: {},
267
+ },
268
+ '../data/system': {},
269
+ '../shared/pLimit': {},
270
+ '../schedule/client': {},
271
+ '../shared/i18n': { ...translate, setLang() {} },
272
+ './notify': {},
273
+ './schedule': {},
274
+ './sock': {},
275
+ '../config/util': {},
276
+ ...overrides,
277
+ }).default;
278
+ return new System(logger, {}, {});
279
+ }
280
+
281
+ test('backup rejects unrecognized paths before spawning; valid export uses argv without a shell', async (t) => {
282
+ const base = temporary(t);
283
+ const calls = [];
284
+ const service = systemService(
285
+ {
286
+ dataPath: path.join(base, 'data'),
287
+ dataTgzFile: path.join(base, 'backup file.tgz'),
288
+ },
289
+ {
290
+ child_process: {
291
+ execFile: (...args) => {
292
+ calls.push(args.slice(0, -1));
293
+ args.at(-1)(null, '', '');
294
+ },
295
+ },
296
+ '../config/util': {
297
+ promiseExec: () => assert.fail('must not invoke shell'),
298
+ },
299
+ },
300
+ );
301
+ let downloaded = false;
302
+ const res = {
303
+ status() {
304
+ return this;
305
+ },
306
+ send(body) {
307
+ return body;
308
+ },
309
+ download() {
310
+ downloaded = true;
311
+ },
312
+ };
313
+ for (const entry of [
314
+ '$(printf BAD)',
315
+ '../outside',
316
+ '/etc',
317
+ 'scripts;echo BAD',
318
+ '--checkpoint-action=exec=bad',
319
+ ]) {
320
+ assert.equal((await service.exportData(res, [entry])).code, 400);
321
+ }
322
+ assert.equal(calls.length, 0);
323
+ await service.exportData(res, ['base', 'scripts', 'config', 'scripts']);
324
+ assert.equal(calls.length, 1);
325
+ assert.equal(calls[0][0], 'tar');
326
+ assert.deepEqual(calls[0][1].slice(2), [
327
+ '--',
328
+ 'data/db',
329
+ 'data/upload',
330
+ 'data/scripts',
331
+ 'data/config',
332
+ ]);
333
+ assert.equal(calls[0][2].shell, undefined);
334
+ assert.equal(downloaded, true);
335
+ });
336
+
337
+ test('proxy, language and mirror settings stay literal at their shell boundaries', async (t) => {
338
+ const base = temporary(t);
339
+ const commands = [];
340
+ const service = systemService(
341
+ {
342
+ dependenceProxyFile: path.join(base, 'proxy.sh'),
343
+ langEnvFile: path.join(base, 'lang.sh'),
344
+ },
345
+ {
346
+ '../config/util': {
347
+ promiseExec: async (command) => commands.push(command),
348
+ },
349
+ },
350
+ );
351
+ service.getSystemConfig = async () => ({ info: {} });
352
+ service.updateAuthDb = async () => {};
353
+ service.scheduleService = { runTask: (command) => commands.push(command) };
354
+ const value = 'x\'$(printf BAD)`printf BAD`"; echo BAD; #';
355
+ await service.updateDependenceProxy({ dependenceProxy: value });
356
+ await service.updateLanguage({ lang: value });
357
+ const stdout = execFileSync('/bin/bash', [
358
+ '-c',
359
+ 'source "$1"; source "$2"; printf "%s\\0%s" "$http_proxy" "$QL_LANG"',
360
+ 'bash',
361
+ path.join(base, 'proxy.sh'),
362
+ path.join(base, 'lang.sh'),
363
+ ]).toString();
364
+ assert.equal(stdout, value + '\0' + value);
365
+ await service.updatePythonMirror({ pythonMirror: value });
366
+ await service.updateNodeMirror({ nodeMirror: value });
367
+ for (const command of commands) {
368
+ const stdout = execFileSync('/bin/bash', [
369
+ '-c',
370
+ `pip3() { printf '%s\\0' "$@"; }; pnpm() { printf '%s\\0' "$@"; }; ${command}`,
371
+ ]).toString();
372
+ assert.equal(stdout.split('\0').at(-2), value);
373
+ }
374
+ assert.equal((await service.reloadSystem('$(printf BAD)')).code, 400);
375
+ });
376
+
377
+ test('the ignored-log sentinel remains supported without exposing device files', async (t) => {
378
+ const root = temporary(t);
379
+ const cron = cronService({ logPath: root });
380
+ cron.getDb = async () => ({ log_path: '/dev/null', log_name: '/dev/null' });
381
+ assert.equal((await cron.log(1)).status, 'ignored');
382
+ assert.deepEqual(await cron.logs(1), []);
383
+ await cron.status({ ids: [], status: 0, log_path: '/dev/null' });
384
+ await assert.rejects(
385
+ cron.status({ ids: [], status: 0, log_path: '/dev/zero' }),
386
+ );
387
+ });
388
+
389
+ test('normal backup creates an archive containing the selected data directories', async (t) => {
390
+ const base = temporary(t);
391
+ const dataPath = path.join(base, 'data');
392
+ for (const name of ['db', 'upload', 'scripts'])
393
+ fs.mkdirSync(path.join(dataPath, name), { recursive: true });
394
+ fs.writeFileSync(path.join(dataPath, 'scripts/example.js'), 'literal script');
395
+ const dataTgzFile = path.join(base, 'backup with spaces.tgz');
396
+ const service = systemService({ dataPath, dataTgzFile });
397
+ let downloaded;
398
+ await service.exportData(
399
+ {
400
+ download(file) {
401
+ downloaded = file;
402
+ },
403
+ send(error) {
404
+ assert.fail(JSON.stringify(error));
405
+ },
406
+ },
407
+ ['scripts'],
408
+ );
409
+ assert.equal(downloaded, dataTgzFile);
410
+ const content = execFileSync('tar', [
411
+ '-xzOf',
412
+ dataTgzFile,
413
+ 'data/scripts/example.js',
414
+ ]).toString();
415
+ assert.equal(content, 'literal script');
416
+ });
@@ -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
+ });