@oj-module/cli 0.2.18 → 0.2.23

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 (345) hide show
  1. package/devkit/README.md +4 -4
  2. package/devkit/SKILL.md +41 -37
  3. package/devkit/framework-dev.md +6 -5
  4. package/devkit/manual.md +352 -168
  5. package/devkit/menu-rules.md +3 -3
  6. package/devkit/module-dev-and-cdn-playground.md +31 -22
  7. package/devkit/sql-builder-missing-capabilities-pr.md +11 -6
  8. package/package.json +2 -2
  9. package/shell-dist/assets/runtime.js +59 -34
  10. package/shell-dist/index.html +2 -2
  11. package/shell-dist/versions.json +3 -3
  12. package/src/__tests__/build-backend.test.ts +54 -0
  13. package/src/__tests__/init-packagejson.test.ts +29 -0
  14. package/src/__tests__/layout.test.ts +176 -0
  15. package/src/__tests__/module-list.test.ts +66 -0
  16. package/src/__tests__/oj-caps.test.ts +114 -0
  17. package/src/alias-paths.ts +102 -0
  18. package/src/args.ts +54 -4
  19. package/src/build.ts +41 -9
  20. package/src/builtin.ts +93 -0
  21. package/src/bundle.ts +254 -38
  22. package/src/config.ts +82 -9
  23. package/src/contract/__tests__/market-client.integration.test.ts +14 -14
  24. package/src/contract/check.ts +56 -28
  25. package/src/contract/emit-stub.ts +21 -9
  26. package/src/contract/handler-scan.ts +19 -10
  27. package/src/contract/run.ts +14 -4
  28. package/src/dev.ts +80 -9
  29. package/src/index.ts +27 -7
  30. package/src/info.ts +69 -10
  31. package/src/init.ts +114 -28
  32. package/src/layout.ts +282 -24
  33. package/src/lifecycle/__tests__/args.test.ts +20 -0
  34. package/src/lifecycle/__tests__/builtin.test.ts +97 -0
  35. package/src/lifecycle/__tests__/bundle.test.ts +184 -6
  36. package/src/lifecycle/__tests__/manifest-contract.test.ts +2 -2
  37. package/src/lifecycle/__tests__/new.test.ts +129 -0
  38. package/src/lifecycle/__tests__/smoke.test.ts +2 -1
  39. package/src/manifest-contract.ts +16 -3
  40. package/src/market/__tests__/bootstrap.test.ts +17 -9
  41. package/src/market/bootstrap.ts +30 -17
  42. package/src/market/publish.ts +10 -2
  43. package/src/new.ts +208 -0
  44. package/src/oj-caps.ts +133 -0
  45. package/src/oj.ts +27 -4
  46. package/src/preview-config.ts +1 -1
  47. package/src/preview.ts +2 -1
  48. package/src/site.ts +2 -2
  49. package/src/usage.ts +24 -12
  50. package/src/vendor.ts +5 -1
  51. package/templates/{api/config.yaml → config.yaml} +13 -8
  52. package/templates/global.d.ts +7 -6
  53. package/templates/init.include.yaml +41 -36
  54. package/templates/package.json +3 -1
  55. package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/installer.ts +4 -0
  56. package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/smoke.ts +21 -2
  57. package/templates/{api/src/_platform → src/_platform/api}/fixtures/l1-test-user.sql +4 -5
  58. package/templates/{api/src/_platform → src/_platform/api}/market/api.ts +25 -15
  59. package/templates/src/_platform/api/seed.mysql.sql +16 -0
  60. package/templates/src/_platform/api/seed.pg.sql +16 -0
  61. package/templates/{api/src/_platform → src/_platform/api}/seed.sql +16 -5
  62. package/templates/{api/src/_platform → src/_platform/api}/solutions/api.ts +7 -3
  63. package/templates/{api/src/auth → src/auth/api}/_shared/login-throttle.ts +2 -2
  64. package/templates/{api/src/auth → src/auth/api}/_shared/session.ts +2 -2
  65. package/templates/{api/src/auth → src/auth/api}/api.ts +1 -1
  66. package/templates/{api/src/auth → src/auth/api}/ldap-login/api.ts +1 -1
  67. package/templates/src/auth/api/manifest.yaml +6 -0
  68. package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/InstallDialog.test.tsx +53 -1
  69. package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/marketClient.fake.ts +6 -0
  70. package/templates/{web/src/oj-market → src/oj-market/web}/api/client.ts +5 -0
  71. package/templates/{web/src/oj-market → src/oj-market/web}/api/context.ts +2 -2
  72. package/templates/{web/src/oj-market → src/oj-market/web}/api/defaultClient.ts +7 -1
  73. package/templates/src/oj-market/web/components/InstallDialog.tsx +194 -0
  74. package/templates/{web/src/oj-market → src/oj-market/web}/components/RollbackDialog.tsx +7 -3
  75. package/templates/{web/src/oj-market → src/oj-market/web}/components/UninstallConfirm.tsx +18 -7
  76. package/templates/{web/src/oj-market → src/oj-market/web}/hooks/useMarket.ts +29 -12
  77. package/templates/{web/src/oj-market → src/oj-market/web}/locales/en-US.json +10 -1
  78. package/templates/{web/src/oj-market → src/oj-market/web}/locales/zh-CN.json +10 -1
  79. package/templates/{web/src/oj-market → src/oj-market/web}/types.ts +15 -2
  80. package/templates/{api/src/system → src/system/api}/login-methods/api.ts +2 -2
  81. package/templates/src/system/api/manifest.yaml +6 -0
  82. package/templates/{api/src/system → src/system/api}/oplog/api.ts +4 -4
  83. package/templates/{api/src/system → src/system/api}/permissions/api.ts +3 -3
  84. package/templates/{api/src/system → src/system/api}/roles/api.ts +3 -3
  85. package/templates/{api/src/system → src/system/api}/roles/bindings/api.ts +3 -3
  86. package/templates/{api/src/system → src/system/api}/settings/api.ts +3 -3
  87. package/templates/{api/src/system → src/system/api}/users/api.ts +3 -3
  88. package/templates/{api/src/system → src/system/api}/users/forbidden/api.ts +3 -3
  89. package/templates/{api/src/system → src/system/api}/users/password/api.ts +3 -3
  90. package/templates/{api/src/system → src/system/api}/users/roles/api.ts +3 -3
  91. package/templates/{web/src/system → src/system/web}/locales/en-US.json +1 -1
  92. package/templates/{web/src/system → src/system/web}/locales/zh-CN.json +1 -1
  93. package/templates/src/tsconfig.json +16 -0
  94. package/templates/{api/tests → tests}/auth-ldap.spec.ts +2 -2
  95. package/templates/{api/tests → tests}/auth-session.spec.ts +3 -3
  96. package/templates/{api/tests → tests}/auth-throttle.spec.ts +1 -1
  97. package/templates/tests/fixture.ts +434 -0
  98. package/templates/{api/tests → tests}/guard.spec.ts +1 -1
  99. package/templates/{api/tests → tests}/l1-builder.test.ts +2 -2
  100. package/templates/{api/tests → tests}/lifecycle/atomic-state.spec.ts +3 -3
  101. package/templates/{api/tests → tests}/lifecycle/bootstrap.spec.ts +8 -4
  102. package/templates/{api/tests → tests}/lifecycle/deploy-smoke.spec.ts +31 -8
  103. package/templates/{api/tests → tests}/lifecycle/installer.spec.ts +15 -15
  104. package/templates/{api/tests → tests}/lifecycle/market-api.spec.ts +30 -29
  105. package/templates/{api/tests → tests}/lifecycle/migrate.spec.ts +6 -6
  106. package/templates/{api/tests → tests}/lifecycle/preflight.spec.ts +4 -4
  107. package/templates/{api/tests → tests}/lifecycle/register.spec.ts +1 -1
  108. package/templates/{api/tests → tests}/lifecycle/semver.spec.ts +1 -1
  109. package/templates/{api/tests → tests}/lifecycle/sha384.spec.ts +1 -1
  110. package/templates/{api/tests → tests}/lifecycle/sig-fixtures.spec.ts +1 -1
  111. package/templates/{api/tests → tests}/lifecycle/solutions-api.spec.ts +1 -1
  112. package/templates/{api/tests → tests}/lifecycle/steps-fs.spec.ts +12 -12
  113. package/templates/{api/tests → tests}/lifecycle/text-edit.spec.ts +1 -1
  114. package/templates/{api/tests → tests}/lifecycle/tgz-guard.spec.ts +1 -1
  115. package/templates/{api/tests → tests}/lifecycle/trust.spec.ts +5 -5
  116. package/templates/{api/tests → tests}/lifecycle/uninstall.spec.ts +7 -7
  117. package/templates/{api/tests → tests}/lifecycle/verify-checks.spec.ts +9 -6
  118. package/templates/{api/tests → tests}/lifecycle/verify-report.spec.ts +7 -5
  119. package/templates/{api/tests → tests}/query-utils.spec.ts +1 -1
  120. package/templates/{api/tests → tests}/rbac-audit.spec.ts +1 -1
  121. package/templates/{api/tests → tests}/rbac-contacts.spec.ts +2 -2
  122. package/templates/{api/tests → tests}/rbac-guard.spec.ts +1 -1
  123. package/templates/{api/tests → tests}/rbac-roles.spec.ts +2 -2
  124. package/templates/{api/tests → tests}/rbac-seed.spec.ts +13 -11
  125. package/templates/{api/tests → tests}/rbac-settings.spec.ts +2 -2
  126. package/templates/{api/tests → tests}/rbac-solution-perms.spec.ts +1 -1
  127. package/templates/{api/tests → tests}/rbac-users.spec.ts +3 -3
  128. package/templates/tests/seed-role-accounts.spec.ts +87 -0
  129. package/templates/tsconfig.json +5 -1
  130. package/templates/tsconfig.paths.json +19 -0
  131. package/templates/types/oj-modules.d.ts +17 -0
  132. package/templates/vitest.config.ts +22 -0
  133. package/templates/web.config.ts +23 -13
  134. package/vendor/host-versions.json +3 -3
  135. package/templates/api/src/_platform/seed.mysql.sql +0 -8
  136. package/templates/api/src/_platform/seed.pg.sql +0 -8
  137. package/templates/api/src/auth/manifest.yaml +0 -5
  138. package/templates/api/src/system/manifest.yaml +0 -5
  139. package/templates/api/tests/fixture.ts +0 -58
  140. package/templates/api/tsconfig.json +0 -8
  141. package/templates/api/vitest.config.ts +0 -12
  142. package/templates/logs/task-events.jsonl +0 -0
  143. package/templates/web/src/oj-market/components/InstallDialog.tsx +0 -112
  144. /package/templates/{api/.ojm-api-exempt.json → .ojm-api-exempt.json} +0 -0
  145. /package/templates/{api/seed.mysql.sql → seed.mysql.sql} +0 -0
  146. /package/templates/{api/seed.pg.sql → seed.pg.sql} +0 -0
  147. /package/templates/{api/src/_platform → src/_platform/api}/README.md +0 -0
  148. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/atomic.ts +0 -0
  149. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/history.ts +0 -0
  150. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/lock.ts +0 -0
  151. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/semver.ts +0 -0
  152. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/sha384.ts +0 -0
  153. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/state.ts +0 -0
  154. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/deploy-web.ts +0 -0
  155. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/download.ts +0 -0
  156. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/extract.ts +0 -0
  157. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/migrate.ts +0 -0
  158. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/preflight.ts +0 -0
  159. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/register.ts +0 -0
  160. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/reload.ts +0 -0
  161. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/steps/verify.ts +0 -0
  162. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/tasks.ts +0 -0
  163. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/text-edit.ts +0 -0
  164. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/tgz-guard.ts +0 -0
  165. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/trust.ts +0 -0
  166. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/types.ts +0 -0
  167. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/uninstall.ts +0 -0
  168. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/verify-checks.ts +0 -0
  169. /package/templates/{api/src/_platform → src/_platform/api}/_lifecycle/verify-report.ts +0 -0
  170. /package/templates/{api/src/_platform → src/_platform/api}/_shared/respond.ts +0 -0
  171. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/domain/contacts.ts +0 -0
  172. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/domain/roles.ts +0 -0
  173. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/domain/settings.ts +0 -0
  174. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/domain/solution-perms.ts +0 -0
  175. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/domain/users.ts +0 -0
  176. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/access.ts +0 -0
  177. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/audit.ts +0 -0
  178. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/guard.ts +0 -0
  179. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/oplog.ts +0 -0
  180. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/query.ts +0 -0
  181. /package/templates/{api/src/_platform → src/_platform/api}/_shared/service/infra/rate.ts +0 -0
  182. /package/templates/{api/src/_platform → src/_platform/api}/_shared/site-facade.ts +0 -0
  183. /package/templates/{api/src/_platform → src/_platform/api}/contacts/api.ts +0 -0
  184. /package/templates/{api/src/_platform → src/_platform/api}/contacts/detail/api.ts +0 -0
  185. /package/templates/{api/src/_platform → src/_platform/api}/manifest.yaml +0 -0
  186. /package/templates/{api/src/_platform → src/_platform/api}/market/bootstrap.ts +0 -0
  187. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0001__create_users.mysql.sql +0 -0
  188. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0001__create_users.pg.sql +0 -0
  189. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0001__create_users.sql +0 -0
  190. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0002__add_users_avatar_base64.mysql.sql +0 -0
  191. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0002__add_users_avatar_base64.sql +0 -0
  192. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0003__users_source_display_name.mysql.sql +0 -0
  193. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0003__users_source_display_name.sql +0 -0
  194. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0004__sys_rbac.mysql.sql +0 -0
  195. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0004__sys_rbac.pg.sql +0 -0
  196. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0004__sys_rbac.sql +0 -0
  197. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0005__users_must_change.mysql.sql +0 -0
  198. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0005__users_must_change.sql +0 -0
  199. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0006__users_is_forbidden.mysql.sql +0 -0
  200. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0006__users_is_forbidden.sql +0 -0
  201. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0007__users_email.sql +0 -0
  202. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0008__sys_refresh_token.mysql.sql +0 -0
  203. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0008__sys_refresh_token.pg.sql +0 -0
  204. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0008__sys_refresh_token.sql +0 -0
  205. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0009__sys_throttle.mysql.sql +0 -0
  206. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0009__sys_throttle.pg.sql +0 -0
  207. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0009__sys_throttle.sql +0 -0
  208. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0010__sys_solution_route.mysql.sql +0 -0
  209. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0010__sys_solution_route.pg.sql +0 -0
  210. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0010__sys_solution_route.sql +0 -0
  211. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0011__sys_setting_group_label.mysql.sql +0 -0
  212. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0011__sys_setting_group_label.sql +0 -0
  213. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0012__market_history.mysql.sql +0 -0
  214. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0012__market_history.pg.sql +0 -0
  215. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0012__market_history.sql +0 -0
  216. /package/templates/{api/src/_platform → src/_platform/api}/migrations/0013__users_profile.sql +0 -0
  217. /package/templates/{api/src/_platform → src/_platform/api}/schema.yaml +0 -0
  218. /package/templates/{web/src/_platform → src/_platform/web}/__client/api.schemas.ts +0 -0
  219. /package/templates/{web/src/_platform → src/_platform/web}/__client/api.ts +0 -0
  220. /package/templates/{web/src/about → src/about/web}/entry.ts +0 -0
  221. /package/templates/{web/src/about → src/about/web}/locales/en-US.json +0 -0
  222. /package/templates/{web/src/about → src/about/web}/locales/zh-CN.json +0 -0
  223. /package/templates/{web/src/about → src/about/web}/pages/constants.ts +0 -0
  224. /package/templates/{web/src/about → src/about/web}/pages/index.tsx +0 -0
  225. /package/templates/{web/src/access → src/access/web}/entry.ts +0 -0
  226. /package/templates/{web/src/access → src/access/web}/locales/en-US.json +0 -0
  227. /package/templates/{web/src/access → src/access/web}/locales/zh-CN.json +0 -0
  228. /package/templates/{web/src/access → src/access/web}/pages/access-mode/index.tsx +0 -0
  229. /package/templates/{web/src/access → src/access/web}/pages/admin-visible/index.tsx +0 -0
  230. /package/templates/{web/src/access → src/access/web}/pages/button-control/index.tsx +0 -0
  231. /package/templates/{web/src/access → src/access/web}/pages/common-visible/index.tsx +0 -0
  232. /package/templates/{web/src/access → src/access/web}/pages/page-control/index.tsx +0 -0
  233. /package/templates/{api/src/auth → src/auth/api}/_shared/ldap-login.ts +0 -0
  234. /package/templates/{api/src/auth → src/auth/api}/_shared/ldap.ts +0 -0
  235. /package/templates/{web/src/auth → src/auth/web}/__client/api.schemas.ts +0 -0
  236. /package/templates/{web/src/auth → src/auth/web}/__client/api.ts +0 -0
  237. /package/templates/{api/src/demo → src/demo/api}/manifest.yaml +0 -0
  238. /package/templates/{api/src/demo → src/demo/api}/migrations/0001__create_todos.sql +0 -0
  239. /package/templates/{api/src/demo → src/demo/api}/schema.yaml +0 -0
  240. /package/templates/{api/src/demo → src/demo/api}/seed.sql +0 -0
  241. /package/templates/{api/src/demo → src/demo/api}/todos/api.ts +0 -0
  242. /package/templates/{web/src/demo → src/demo/web}/__client/api.schemas.ts +0 -0
  243. /package/templates/{web/src/demo → src/demo/web}/__client/api.ts +0 -0
  244. /package/templates/{web/src/demo → src/demo/web}/entry.ts +0 -0
  245. /package/templates/{web/src/demo → src/demo/web}/locales/en-US.json +0 -0
  246. /package/templates/{web/src/demo → src/demo/web}/locales/zh-CN.json +0 -0
  247. /package/templates/{web/src/demo → src/demo/web}/pages/index.tsx +0 -0
  248. /package/templates/{web/src/exception → src/exception/web}/entry.ts +0 -0
  249. /package/templates/{web/src/exception → src/exception/web}/locales/en-US.json +0 -0
  250. /package/templates/{web/src/exception → src/exception/web}/locales/zh-CN.json +0 -0
  251. /package/templates/{web/src/exception → src/exception/web}/pages/403/index.tsx +0 -0
  252. /package/templates/{web/src/exception → src/exception/web}/pages/404/index.tsx +0 -0
  253. /package/templates/{web/src/exception → src/exception/web}/pages/500/index.tsx +0 -0
  254. /package/templates/{web/src/exception → src/exception/web}/pages/unknown-component/index.tsx +0 -0
  255. /package/templates/{api/src/home → src/home/api}/line/api.ts +0 -0
  256. /package/templates/{api/src/home → src/home/api}/manifest.yaml +0 -0
  257. /package/templates/{api/src/home → src/home/api}/migrations/0001__create_home_tables.sql +0 -0
  258. /package/templates/{api/src/home → src/home/api}/pie/api.ts +0 -0
  259. /package/templates/{api/src/home → src/home/api}/schema.yaml +0 -0
  260. /package/templates/{api/src/home → src/home/api}/seed.sql +0 -0
  261. /package/templates/{web/src/home → src/home/web}/__client/api.schemas.ts +0 -0
  262. /package/templates/{web/src/home → src/home/web}/__client/api.ts +0 -0
  263. /package/templates/{web/src/home → src/home/web}/entry.ts +0 -0
  264. /package/templates/{web/src/home → src/home/web}/locales/en-US.json +0 -0
  265. /package/templates/{web/src/home → src/home/web}/locales/zh-CN.json +0 -0
  266. /package/templates/{web/src/home → src/home/web}/pages/components/bar-chart.tsx +0 -0
  267. /package/templates/{web/src/home → src/home/web}/pages/components/card-list.tsx +0 -0
  268. /package/templates/{web/src/home → src/home/web}/pages/components/line-chart.tsx +0 -0
  269. /package/templates/{web/src/home → src/home/web}/pages/components/pie-chart.tsx +0 -0
  270. /package/templates/{web/src/home → src/home/web}/pages/index.tsx +0 -0
  271. /package/templates/{web/src/login → src/login/web}/entry.ts +0 -0
  272. /package/templates/{web/src/login → src/login/web}/locales/en-US.json +0 -0
  273. /package/templates/{web/src/login → src/login/web}/locales/zh-CN.json +0 -0
  274. /package/templates/{web/src/login → src/login/web}/pages/change-password.tsx +0 -0
  275. /package/templates/{web/src/login → src/login/web}/pages/login.tsx +0 -0
  276. /package/templates/{api/src/notification → src/notification/api}/_shared/notify.ts +0 -0
  277. /package/templates/{api/src/notification → src/notification/api}/api.ts +0 -0
  278. /package/templates/{api/src/notification → src/notification/api}/del/api.ts +0 -0
  279. /package/templates/{api/src/notification → src/notification/api}/manifest.yaml +0 -0
  280. /package/templates/{api/src/notification → src/notification/api}/migrations/0001__create_notifications.sql +0 -0
  281. /package/templates/{api/src/notification → src/notification/api}/migrations/0002__notifications_user.sql +0 -0
  282. /package/templates/{api/src/notification → src/notification/api}/migrations/0003__notifications_broadcast.sql +0 -0
  283. /package/templates/{api/src/notification → src/notification/api}/migrations/0004__notifications_broadcast_hidden.sql +0 -0
  284. /package/templates/{api/src/notification → src/notification/api}/schema.yaml +0 -0
  285. /package/templates/{api/src/notification → src/notification/api}/seed.sql +0 -0
  286. /package/templates/{web/src/notification → src/notification/web}/__client/api.schemas.ts +0 -0
  287. /package/templates/{web/src/notification → src/notification/web}/__client/api.ts +0 -0
  288. /package/templates/{web/src/notification → src/notification/web}/entry.ts +0 -0
  289. /package/templates/{web/src/notification → src/notification/web}/locales/en-US.json +0 -0
  290. /package/templates/{web/src/notification → src/notification/web}/locales/zh-CN.json +0 -0
  291. /package/templates/{web/src/notification → src/notification/web}/pages/center/index.tsx +0 -0
  292. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/CardGrid.test.tsx +0 -0
  293. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/HistoryDrawer.test.tsx +0 -0
  294. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/RollbackDialog.test.tsx +0 -0
  295. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/UninstallConfirm.test.tsx +0 -0
  296. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/poll.test.ts +0 -0
  297. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/render.tsx +0 -0
  298. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/runtime-stub.ts +0 -0
  299. /package/templates/{web/src/oj-market → src/oj-market/web}/__tests__/semver.test.ts +0 -0
  300. /package/templates/{web/src/oj-market → src/oj-market/web}/api/MarketClientProvider.tsx +0 -0
  301. /package/templates/{web/src/oj-market → src/oj-market/web}/components/CardGrid.tsx +0 -0
  302. /package/templates/{web/src/oj-market → src/oj-market/web}/components/CardItem.tsx +0 -0
  303. /package/templates/{web/src/oj-market → src/oj-market/web}/components/DetailDrawer.tsx +0 -0
  304. /package/templates/{web/src/oj-market → src/oj-market/web}/components/HistoryDrawer.tsx +0 -0
  305. /package/templates/{web/src/oj-market → src/oj-market/web}/entry.ts +0 -0
  306. /package/templates/{web/src/oj-market → src/oj-market/web}/pages/MarketApp.tsx +0 -0
  307. /package/templates/{web/src/oj-market → src/oj-market/web}/utils/poll.ts +0 -0
  308. /package/templates/{web/src/oj-market → src/oj-market/web}/utils/semver.ts +0 -0
  309. /package/templates/{web/src/outside → src/outside/web}/entry.ts +0 -0
  310. /package/templates/{web/src/outside → src/outside/web}/locales/en-US.json +0 -0
  311. /package/templates/{web/src/outside → src/outside/web}/locales/zh-CN.json +0 -0
  312. /package/templates/{api/src/personal-center → src/personal-center/api}/manifest.yaml +0 -0
  313. /package/templates/{api/src/personal-center → src/personal-center/api}/profile/api.ts +0 -0
  314. /package/templates/{api/src/personal-center → src/personal-center/api}/upload/api.ts +0 -0
  315. /package/templates/{web/src/personal-center → src/personal-center/web}/__client/api.schemas.ts +0 -0
  316. /package/templates/{web/src/personal-center → src/personal-center/web}/__client/api.ts +0 -0
  317. /package/templates/{web/src/personal-center → src/personal-center/web}/entry.ts +0 -0
  318. /package/templates/{web/src/personal-center → src/personal-center/web}/locales/en-US.json +0 -0
  319. /package/templates/{web/src/personal-center → src/personal-center/web}/locales/zh-CN.json +0 -0
  320. /package/templates/{web/src/personal-center → src/personal-center/web}/pages/my-profile/index.tsx +0 -0
  321. /package/templates/{web/src/route-nest → src/route-nest/web}/entry.ts +0 -0
  322. /package/templates/{web/src/route-nest → src/route-nest/web}/locales/en-US.json +0 -0
  323. /package/templates/{web/src/route-nest → src/route-nest/web}/locales/zh-CN.json +0 -0
  324. /package/templates/{web/src/route-nest → src/route-nest/web}/pages/menu1/menu1-1/index.tsx +0 -0
  325. /package/templates/{web/src/route-nest → src/route-nest/web}/pages/menu1/menu1-2/index.tsx +0 -0
  326. /package/templates/{web/src/route-nest → src/route-nest/web}/pages/menu2/index.tsx +0 -0
  327. /package/templates/{web/src → src}/styles.css +0 -0
  328. /package/templates/{web/src/system → src/system/web}/__client/api.schemas.ts +0 -0
  329. /package/templates/{web/src/system → src/system/web}/__client/api.ts +0 -0
  330. /package/templates/{web/src/system → src/system/web}/entry.ts +0 -0
  331. /package/templates/{web/src/system → src/system/web}/pages/errors.ts +0 -0
  332. /package/templates/{web/src/system → src/system/web}/pages/forbidden.tsx +0 -0
  333. /package/templates/{web/src/system → src/system/web}/pages/login-methods/index.tsx +0 -0
  334. /package/templates/{web/src/system → src/system/web}/pages/oplog/index.tsx +0 -0
  335. /package/templates/{web/src/system → src/system/web}/pages/roles/index.tsx +0 -0
  336. /package/templates/{web/src/system → src/system/web}/pages/settings/index.tsx +0 -0
  337. /package/templates/{web/src/system → src/system/web}/pages/users/index.tsx +0 -0
  338. /package/templates/{web/src/system → src/system/web}/pages/users/roles.tsx +0 -0
  339. /package/templates/{api/src/web → src/web/api}/get-async-routes/api.ts +0 -0
  340. /package/templates/{api/src/web → src/web/api}/hello/api.ts +0 -0
  341. /package/templates/{api/src/web → src/web/api}/manifest.yaml +0 -0
  342. /package/templates/{api/src/web → src/web/api}/user-info/api.ts +0 -0
  343. /package/templates/{web/src → src/web}/web/__client/api.schemas.ts +0 -0
  344. /package/templates/{web/src → src/web}/web/__client/api.ts +0 -0
  345. /package/templates/{api/tests → tests}/rbac-tables.spec.ts +0 -0
@@ -5,7 +5,7 @@
5
5
  /* eslint-disable test/prefer-lowercase-title -- AC 编号是验收锚点,保留大写 */
6
6
  import { afterEach, beforeAll, describe, expect, it } from "vitest";
7
7
 
8
- import { loginBlocked, loginFailed, loginSucceeded, resetLoginThrottle } from "../src/_platform/_shared/service/infra/rate";
8
+ import { loginBlocked, loginFailed, loginSucceeded, resetLoginThrottle } from "../src/_platform/api/_shared/service/infra/rate";
9
9
  import { installDb } from "./fixture";
10
10
 
11
11
  let dbo: ReturnType<typeof installDb>;
@@ -0,0 +1,434 @@
1
+ // 后端 BDD 夹具:node:sqlite 内存库 + **真实迁移文件**建表,装到 globalThis.db——
2
+ // 与 oj 运行时注入的全局同名同面,service 代码不改一行即可被测。
3
+ // 夹具直接读 src/<模块>/api/migrations/*.sql,与迁移不可能漂移(沿用 oj-wiki 先例)。
4
+ //
5
+ // **构造器垫片(db.table / listTables)**:oj 的构造器是二进制内的 Rust 实现,Node 侧无可复用
6
+ // 模块,故这里按手册契约(oj-api-dev api-manual「查询构造器」)写一层**最小 JS 渲染层**——
7
+ // 只覆盖模板后端真正用到的面:select(含聚合 / distinct / lit)/ as / join(列对列 + 列对值)/
8
+ // where / whereIf / groupBy / orderBy / limit / offset / union / insert(含 orIgnore、returning)/ update /
9
+ // delete / truncate / all / run / listTables。子集外的调用**直接报「未实现」**,不静默返回空结果
10
+ // (静默空值会把「垫片缺能力」伪装成「业务没数据」,是最难查的一类假绿)。
11
+ //
12
+ // 已知边界(模板当前用不到,不模拟):租户/归属守卫(`tenant_id` 注入、`owner_of`)——模板是单租户,
13
+ // 开启多租户后本夹具必先补这两条,否则守卫失效也会绿。
14
+ //
15
+ // 分工不变:
16
+ // · L2(本目录 *.spec.ts):构造器渲染出**语义等价**的 SQL 后在真 sqlite 上跑——服务层行为、
17
+ // 参数化、AND 串联、IN/LIKE 转义、聚合分组、limit/offset 都在这一层钉。
18
+ // · L1(同目录 *.test.ts,`oj test` 收集):真 v8 + 真构造器,守 oj 的方言渲染(样板见
19
+ // tests/l1-builder.test.ts;方法论见 devkit oj-test-guide.md)。
20
+ import { createRequire } from "node:module";
21
+
22
+ const req = createRequire(import.meta.url);
23
+ const { DatabaseSync } = req("node:sqlite");
24
+ const { readdirSync, readFileSync, existsSync } = req("node:fs");
25
+ const { join, dirname } = req("node:path");
26
+ const { fileURLToPath } = req("node:url");
27
+
28
+ const SRC = join(dirname(fileURLToPath(import.meta.url)), "..", "src");
29
+
30
+ export const ADMIN = 1;
31
+
32
+ /** 标识符加引号(保留字列名如 `order` / `group` / `count` 全按字面量处理;`表.列` 逐段加) */
33
+ function quoteIdent(name: string): string {
34
+ return name.split(".").map(p => `"${p.replace(/"/g, "\"\"")}"`).join(".");
35
+ }
36
+
37
+ /** LIKE 转义符:与 oj 同口径(`!`),`contains`/`startswith`/`endswith` 自动转义 `%` `_` `!` */
38
+ const LIKE_ESCAPE = "!";
39
+
40
+ function escapeLike(value: string): string {
41
+ return value.replace(/[!%_]/g, c => `${LIKE_ESCAPE}${c}`);
42
+ }
43
+
44
+ const COMPARE_OPS: Record<string, string> = { eq: "=", ne: "<>", gt: ">", gte: ">=", lt: "<", lte: "<=" };
45
+
46
+ interface Compiled { sql: string, params: unknown[] }
47
+
48
+ /** 条件树 → SQL 片段(叶子 {field, op, value};组 {and}/{or}/{not}) */
49
+ function compileWhere(cond: any): Compiled {
50
+ if (cond && typeof cond === "object" && "field" in cond) {
51
+ const field = quoteIdent(String(cond.field));
52
+ const op = String(cond.op ?? "eq").toLowerCase();
53
+ const value = cond.value;
54
+ if (op === "isnull")
55
+ return { sql: `${field} IS NULL`, params: [] };
56
+ if (op === "in") {
57
+ const list = Array.isArray(value) ? value : [value];
58
+ // 与 oj 同口径:空数组早抛(`IN ()` 是永久假谓词,静默 0 行与「无匹配」不可区分;
59
+ // 动态过滤请走 whereIf,它会跳过空数组)
60
+ if (list.length === 0)
61
+ throw new Error("[fixture] in needs non-empty array");
62
+ return { sql: `${field} IN (${list.map(() => "?").join(", ")})`, params: list };
63
+ }
64
+ if (op === "contains" || op === "startswith" || op === "endswith") {
65
+ const escaped = escapeLike(String(value));
66
+ const pattern = op === "contains" ? `%${escaped}%` : op === "startswith" ? `${escaped}%` : `%${escaped}`;
67
+ return { sql: `${field} LIKE ? ESCAPE '${LIKE_ESCAPE}'`, params: [pattern] };
68
+ }
69
+ if (op === "like") {
70
+ // `like` 的模式由调用方负责成形;`escape` 逃生舱(白名单 ! / | ~ # @)原样渲染
71
+ const esc = cond.escape as string | undefined;
72
+ return esc
73
+ ? { sql: `${field} LIKE ? ESCAPE '${esc}'`, params: [value] }
74
+ : { sql: `${field} LIKE ?`, params: [value] };
75
+ }
76
+ const sqlOp = COMPARE_OPS[op];
77
+ if (!sqlOp)
78
+ throw new Error(`[fixture] db.table 的 where op 未实现:${op}`);
79
+ return { sql: `${field} ${sqlOp} ?`, params: [value] };
80
+ }
81
+ if (cond && typeof cond === "object" && Array.isArray(cond.and)) {
82
+ const parts = cond.and.map(compileWhere);
83
+ return { sql: parts.map(p => `(${p.sql})`).join(" AND "), params: parts.flatMap(p => p.params) };
84
+ }
85
+ if (cond && typeof cond === "object" && Array.isArray(cond.or)) {
86
+ const parts = cond.or.map(compileWhere);
87
+ return { sql: parts.map(p => `(${p.sql})`).join(" OR "), params: parts.flatMap(p => p.params) };
88
+ }
89
+ if (cond && typeof cond === "object" && cond.not) {
90
+ const part = compileWhere(cond.not);
91
+ return { sql: `NOT (${part.sql})`, params: part.params };
92
+ }
93
+ throw new Error(`[fixture] db.table 的 where 条件形状未实现:${JSON.stringify(cond)}`);
94
+ }
95
+
96
+ interface SelectItem { fn?: string, field?: string, as?: string, distinct?: boolean, lit?: unknown }
97
+ type Col = string | SelectItem;
98
+
99
+ interface QueryState {
100
+ table: string
101
+ alias: string | null
102
+ cols: Col[] | null
103
+ distinct: boolean
104
+ joins: Array<{ table: string, on: any[], kind: "inner" | "left", alias: string | null }>
105
+ wheres: any[]
106
+ having: any[]
107
+ groups: string[]
108
+ orders: Array<{ field: string, dir?: string | null }>
109
+ limit: number | null
110
+ offset: number | null
111
+ verb: "select" | "insert" | "update" | "delete" | "truncate"
112
+ values: unknown
113
+ sets: unknown
114
+ orIgnore: boolean
115
+ returning: string[] | null
116
+ union: { other: FakeQuery, kind: "all" | "distinct" } | null
117
+ }
118
+
119
+ /**
120
+ * 最小构造器:命令式链式调用(每个方法返回自身,与 oj 的 builder 一致——业务代码里
121
+ * `const q = db.table(...).where(...)` 后接 `q.union(...)` 的写法依赖这个语义)。
122
+ */
123
+ class FakeQuery {
124
+ private readonly s: QueryState;
125
+
126
+ constructor(private readonly dbo: any, table: string, seed?: Partial<QueryState>) {
127
+ this.s = {
128
+ table,
129
+ alias: null,
130
+ cols: null,
131
+ distinct: false,
132
+ joins: [],
133
+ wheres: [],
134
+ having: [],
135
+ groups: [],
136
+ orders: [],
137
+ limit: null,
138
+ offset: null,
139
+ verb: "select",
140
+ values: null,
141
+ sets: null,
142
+ orIgnore: false,
143
+ returning: null,
144
+ union: null,
145
+ ...seed,
146
+ };
147
+ }
148
+
149
+ /** 基表别名(列限定写 `b.col`;只影响 select/join 渲染) */
150
+ as(alias: string): this {
151
+ this.s.alias = alias;
152
+ return this;
153
+ }
154
+
155
+ select(cols: Col[]): this {
156
+ this.s.cols = cols;
157
+ return this;
158
+ }
159
+
160
+ distinct(): this {
161
+ this.s.distinct = true;
162
+ return this;
163
+ }
164
+
165
+ join(table: string, on: any[], kind: "inner" | "left" = "inner", alias?: string): this {
166
+ this.s.joins.push({ table, on, kind, alias: alias ?? null });
167
+ return this;
168
+ }
169
+
170
+ where(cond: any): this {
171
+ this.s.wheres.push(cond);
172
+ return this;
173
+ }
174
+
175
+ /** 条件化 where:`undefined`/`null`/`false`/空数组整条跳过(`0` 与 `""` 是合法值,保留) */
176
+ whereIf(test: unknown, cond: any): this {
177
+ const skip = test === undefined || test === null || test === false || (Array.isArray(test) && test.length === 0);
178
+ if (!skip)
179
+ this.s.wheres.push(cond);
180
+ return this;
181
+ }
182
+
183
+ having(cond: any): this {
184
+ this.s.having.push(cond);
185
+ return this;
186
+ }
187
+
188
+ groupBy(cols: string[]): this {
189
+ this.s.groups.push(...cols);
190
+ return this;
191
+ }
192
+
193
+ orderBy(items: Array<{ field: string, dir?: string | null }>): this {
194
+ this.s.orders.push(...items);
195
+ return this;
196
+ }
197
+
198
+ limit(n: number): this {
199
+ this.s.limit = n;
200
+ return this;
201
+ }
202
+
203
+ offset(n: number): this {
204
+ this.s.offset = n;
205
+ return this;
206
+ }
207
+
208
+ /** 合并两条 select(UNION [ALL]);外层 orderBy/limit/offset 作用于合并结果 */
209
+ union(other: FakeQuery, kind: "all" | "distinct" = "distinct"): this {
210
+ this.s.union = { other, kind };
211
+ return this;
212
+ }
213
+
214
+ insert(values: unknown): this {
215
+ this.s.verb = "insert";
216
+ this.s.values = values;
217
+ return this;
218
+ }
219
+
220
+ update(sets: unknown): this {
221
+ this.s.verb = "update";
222
+ this.s.sets = sets;
223
+ return this;
224
+ }
225
+
226
+ delete(): this {
227
+ this.s.verb = "delete";
228
+ return this;
229
+ }
230
+
231
+ truncate(): this {
232
+ this.s.verb = "truncate";
233
+ return this;
234
+ }
235
+
236
+ orIgnore(): this {
237
+ this.s.orIgnore = true;
238
+ return this;
239
+ }
240
+
241
+ /** insert 取回列(`run()` 改返回行数组,不返回行数);select/update/delete 不接受 */
242
+ returning(cols: string[]): this {
243
+ if (this.s.verb !== "insert")
244
+ throw new Error(`[fixture] ${this.s.verb} does not accept returning`);
245
+ this.s.returning = cols;
246
+ return this;
247
+ }
248
+
249
+ async all(): Promise<Array<Record<string, unknown>>> {
250
+ const { sql, params } = this.compile();
251
+ return this.dbo.prepare(sql).all(...params);
252
+ }
253
+
254
+ async run(): Promise<number | Array<Record<string, unknown>>> {
255
+ const { sql, params } = this.compile();
256
+ const stmt = this.dbo.prepare(sql);
257
+ if (this.s.returning)
258
+ return stmt.all(...params);
259
+ return Number(stmt.run(...params).changes);
260
+ }
261
+
262
+ /** 编译成 {sql, params}(供 union 复用内层 select) */
263
+ compile(inner = false): Compiled {
264
+ const s = this.s;
265
+ if (s.verb === "insert")
266
+ return this.compileInsert();
267
+ if (s.verb === "update")
268
+ return this.compileUpdate();
269
+ if (s.verb === "delete")
270
+ return this.compileDelete();
271
+ if (s.verb === "truncate")
272
+ return { sql: `DELETE FROM ${quoteIdent(s.table)}`, params: [] };
273
+ return this.compileSelect(inner);
274
+ }
275
+
276
+ private compileInsert(): Compiled {
277
+ const rows = (Array.isArray(this.s.values) ? this.s.values : [this.s.values]) as Array<Record<string, unknown>>;
278
+ if (rows.length === 0)
279
+ throw new Error("[fixture] insert 至少需要一行");
280
+ const cols = Object.keys(rows[0]!);
281
+ for (const r of rows) {
282
+ if (Object.keys(r).length !== cols.length)
283
+ throw new Error("[fixture] insert 多行的键集必须一致");
284
+ }
285
+ const params: unknown[] = [];
286
+ const tuple = `(${cols.map(() => "?").join(", ")})`;
287
+ for (const r of rows)
288
+ params.push(...cols.map(c => r[c]));
289
+ const tail = this.s.returning ? ` RETURNING ${this.s.returning.map(quoteIdent).join(", ")}` : "";
290
+ return {
291
+ sql: `INSERT${this.s.orIgnore ? " OR IGNORE" : ""} INTO ${quoteIdent(this.s.table)} (${cols.map(quoteIdent).join(", ")}) VALUES ${rows.map(() => tuple).join(", ")}${tail}`,
292
+ params,
293
+ };
294
+ }
295
+
296
+ private compileUpdate(): Compiled {
297
+ const sets = this.s.sets as Record<string, unknown>;
298
+ const cols = Object.keys(sets);
299
+ const params = cols.map(c => sets[c]);
300
+ const where = this.compileWhereClause(params);
301
+ return {
302
+ sql: `UPDATE ${quoteIdent(this.s.table)} SET ${cols.map(c => `${quoteIdent(c)} = ?`).join(", ")}${where.sql}`,
303
+ params: where.params,
304
+ };
305
+ }
306
+
307
+ private compileDelete(): Compiled {
308
+ const where = this.compileWhereClause([]);
309
+ return { sql: `DELETE FROM ${quoteIdent(this.s.table)}${where.sql}`, params: where.params };
310
+ }
311
+
312
+ /** where 子句(追加进既有 params,返回拼接后的片段) */
313
+ private compileWhereClause(params: unknown[]): Compiled {
314
+ if (this.s.wheres.length === 0)
315
+ return { sql: "", params };
316
+ const parts = this.s.wheres.map(compileWhere);
317
+ return {
318
+ sql: ` WHERE ${parts.map(p => `(${p.sql})`).join(" AND ")}`,
319
+ params: [...params, ...parts.flatMap(p => p.params)],
320
+ };
321
+ }
322
+
323
+ private compileSelect(inner: boolean): Compiled {
324
+ const s = this.s;
325
+ const cols = this.compileCols();
326
+ const params: unknown[] = cols.params;
327
+ const from = `${quoteIdent(s.table)}${s.alias ? ` AS ${quoteIdent(s.alias)}` : ""}`;
328
+ const joins = s.joins.map((j) => {
329
+ const on = j.on.map((c) => {
330
+ if (c && c.right !== undefined)
331
+ return { sql: `${quoteIdent(String(c.left))} = ${quoteIdent(String(c.right))}`, params: [] };
332
+ const sqlOp = COMPARE_OPS[String(c.op ?? "eq").toLowerCase()];
333
+ if (!sqlOp)
334
+ throw new Error(`[fixture] join ON 只支持比较类 op,收到:${c.op}`);
335
+ return { sql: `${quoteIdent(String(c.left))} ${sqlOp} ?`, params: [c.value] };
336
+ });
337
+ params.push(...on.flatMap(o => o.params));
338
+ return `${j.kind === "left" ? "LEFT JOIN" : "JOIN"} ${quoteIdent(j.table)}${j.alias ? ` AS ${quoteIdent(j.alias)}` : ""} ON ${on.map(o => o.sql).join(" AND ")}`;
339
+ });
340
+ const where = this.compileWhereClause(params);
341
+ let sql = `SELECT ${s.distinct ? "DISTINCT " : ""}${cols.sql} FROM ${from}${joins.length ? ` ${joins.join(" ")}` : ""}${where.sql}`;
342
+ let allParams = where.params;
343
+ if (s.groups.length) {
344
+ sql += ` GROUP BY ${s.groups.map(quoteIdent).join(", ")}`;
345
+ if (s.having.length) {
346
+ const hv = this.s.having.map(compileWhere);
347
+ sql += ` HAVING ${hv.map(h => `(${h.sql})`).join(" AND ")}`;
348
+ allParams = [...allParams, ...hv.flatMap(h => h.params)];
349
+ }
350
+ }
351
+ if (s.union) {
352
+ const left = s.union.kind === "all" ? " UNION ALL " : " UNION ";
353
+ const right = s.union.other.compile(true);
354
+ sql = `(${sql})${left}(${right.sql})`;
355
+ allParams = [...allParams, ...right.params];
356
+ }
357
+ if (!inner) {
358
+ if (s.orders.length)
359
+ sql += ` ORDER BY ${s.orders.map(o => `${quoteIdent(o.field)}${o.dir === "desc" ? " DESC" : o.dir === "asc" ? " ASC" : ""}`).join(", ")}`;
360
+ if (s.limit !== null)
361
+ sql += ` LIMIT ${Number(s.limit)}`;
362
+ if (s.offset !== null)
363
+ sql += ` OFFSET ${Number(s.offset)}`;
364
+ }
365
+ return { sql, params: allParams };
366
+ }
367
+
368
+ private compileCols(): Compiled {
369
+ const cols = this.s.cols;
370
+ if (!cols || cols.length === 0)
371
+ return { sql: "*", params: [] };
372
+ const params: unknown[] = [];
373
+ const parts = cols.map((c) => {
374
+ if (typeof c === "string")
375
+ return c === "*" ? "*" : quoteIdent(c);
376
+ if (c.lit !== undefined) {
377
+ params.push(c.lit);
378
+ return c.as ? `? AS ${quoteIdent(c.as)}` : "?";
379
+ }
380
+ if (!c.fn)
381
+ throw new Error(`[fixture] select 列形状未实现:${JSON.stringify(c)}`);
382
+ const inner = `${c.distinct && c.fn === "count" ? "DISTINCT " : ""}${c.field ? quoteIdent(c.field) : "*"}`;
383
+ return `${c.fn.toUpperCase()}(${inner})${c.as ? ` AS ${quoteIdent(c.as)}` : ""}`;
384
+ });
385
+ return { sql: parts.join(", "), params };
386
+ }
387
+ }
388
+
389
+ /** listTables:sqlite_master 自省(排除 `sqlite_*` 内部表,前缀按字面量匹配) */
390
+ const SQL_LIST_TABLES = "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite\\_%' ESCAPE '\\'";
391
+
392
+ function listTables(dbo: any, prefix?: string): string[] {
393
+ const sql = `${SQL_LIST_TABLES}${prefix ? ` AND name LIKE ? ESCAPE '${LIKE_ESCAPE}'` : ""} ORDER BY name`;
394
+ const stmt = dbo.prepare(sql);
395
+ const rows = (prefix ? stmt.all(`${escapeLike(prefix)}%`) : stmt.all()) as Array<{ name: string }>;
396
+ return rows.map(r => r.name);
397
+ }
398
+
399
+ /** 建内存库 + 注入全局;返回 DatabaseSync 供用例直插数据/断言。 */
400
+ export function installDb(): any {
401
+ const dbo = new DatabaseSync(":memory:");
402
+ // 重放 src 下全部模块的迁移(方言专属文件除外)
403
+ for (const mod of readdirSync(SRC)) {
404
+ const dir = join(SRC, mod, "api", "migrations");
405
+ if (!existsSync(dir))
406
+ continue;
407
+ for (const f of readdirSync(dir).filter((f: string) => f.endsWith(".sql") && !/\.(?:mysql|pg)\.sql$/.test(f)).sort())
408
+ dbo.exec(readFileSync(join(dir, f), "utf8"));
409
+ }
410
+
411
+ dbo.prepare("INSERT INTO users (id, username, password_hash) VALUES (?, ?, 'x')").run(ADMIN, "admin");
412
+
413
+ const query = async (sql: string, params: unknown[] = []) => dbo.prepare(sql).all(...(params as never[]));
414
+ const exec = async (sql: string, params: unknown[] = []) => Number(dbo.prepare(sql).run(...(params as never[])).changes);
415
+ const table = (name: string) => new FakeQuery(dbo, name);
416
+ const txInstance = { query, exec, table, listTables: (prefix?: string) => listTables(dbo, prefix), isTx: true };
417
+ // db.tx 镜像运行时面:BEGIN/COMMIT/ROLLBACK 包裹回调(versions.ts 注释同语义)
418
+ const tx = async (fn: (t: typeof txInstance) => unknown) => {
419
+ dbo.exec("BEGIN");
420
+ try {
421
+ const r = await fn(txInstance);
422
+ dbo.exec("COMMIT");
423
+ return r;
424
+ }
425
+ catch (e) {
426
+ dbo.exec("ROLLBACK");
427
+ throw e;
428
+ }
429
+ };
430
+
431
+ const g = globalThis as any;
432
+ g.db = { query, exec, tx, table, listTables: (prefix?: string) => listTables(dbo, prefix), dialect: () => "sqlite" };
433
+ return dbo;
434
+ }
@@ -3,7 +3,7 @@
3
3
  // (真实迁移建表 / 运行时全局 db 同面 / 事务往返)——S0 spike 的「一条真实判权 AC + 形态证明」。
4
4
  import { beforeAll, describe, expect, it } from "vitest";
5
5
 
6
- import { decideAccess, moduleOf } from "../src/_platform/_shared/service/infra/guard";
6
+ import { decideAccess, moduleOf } from "../src/_platform/api/_shared/service/infra/guard";
7
7
  import { ADMIN, installDb } from "./fixture";
8
8
 
9
9
  const as = (roles: string[], bindings: Record<string, string[]> = {}) => ({ roles, bindings });
@@ -11,8 +11,8 @@
11
11
  // ③ notification:join ON 值条件 + UNION ALL + 字面量列 {lit,as} 的真渲染(场景 41 同款)。
12
12
  //
13
13
  // 登录账号:fixtures 的 l1tester(src/_platform/fixtures/l1-test-user.sql,仅 oj test 灌入)。
14
- // 不用 seed 的 admin:其 must_change=1(判权端点恒 403)且初始口令 123456 会随用户
15
- // 首登改密漂移——L1 绑 admin 曾实测 401。l1tester 为 additive 专用账号(must_change=0)。
14
+ // 不用 seed 的 admin 等开发账号:初始口令 123456 会随用户在 dev 库改密漂移——
15
+ // L1 绑 seed 账号曾实测 401。l1tester 为 additive 专用账号(must_change=0)。
16
16
  //
17
17
  // 运行:cd packages/cli/templates/api && ~/.local/share/oj/oj test -c config.yaml -d src -t tests
18
18
 
@@ -4,14 +4,14 @@
4
4
  // 只保证读回自己写出的内容;任何不符格式的字节一律视为损坏 → 空状态,损坏上下文并入
5
5
  // 读结果(corruptNote 出口,禁 console——release isolate console 抛 BadResource,Finding A)。
6
6
  // fs 依赖经 globalThis.fs 注入(平台 isolate 注入 FsApi;测试注入 node:fs/promises 适配)。
7
- import type { FsFace } from "../../src/_platform/_lifecycle/atomic";
7
+ import type { FsFace } from "../../src/_platform/api/_lifecycle/atomic";
8
8
  import * as fsp from "node:fs/promises";
9
9
  import { tmpdir } from "node:os";
10
10
  import { join } from "node:path";
11
11
 
12
12
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
13
- import { atomicWriteText } from "../../src/_platform/_lifecycle/atomic";
14
- import { createStateStore } from "../../src/_platform/_lifecycle/state";
13
+ import { atomicWriteText } from "../../src/_platform/api/_lifecycle/atomic";
14
+ import { createStateStore } from "../../src/_platform/api/_lifecycle/state";
15
15
 
16
16
  const g = globalThis as any;
17
17
 
@@ -5,14 +5,14 @@
5
5
  // 与 PEM 私钥块实体(header 后跟 ≥100 字符 base64 体;tasks.ts redact 正则与测试假体
6
6
  // 体长 <100 不误伤)双口径扫描。
7
7
  // ③ 集成(market-api.spec):信任库为空 + bootstrapKey 注入 → cdn 安装直达 done 不落 needs_trust。
8
- import type { FsFace } from "../../src/_platform/_lifecycle/atomic";
8
+ import type { FsFace } from "../../src/_platform/api/_lifecycle/atomic";
9
9
  import * as fsp from "node:fs/promises";
10
10
  import { tmpdir } from "node:os";
11
11
  import { dirname, join } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
- import { createTrustStore } from "../../src/_platform/_lifecycle/trust";
15
- import { BOOTSTRAP_KEY, seedBootstrapKey } from "../../src/_platform/market/bootstrap";
14
+ import { createTrustStore } from "../../src/_platform/api/_lifecycle/trust";
15
+ import { BOOTSTRAP_KEY, seedBootstrapKey } from "../../src/_platform/api/market/bootstrap";
16
16
 
17
17
  const g = globalThis as any;
18
18
 
@@ -77,7 +77,11 @@ describe("私钥红线钉测(P2-12:packages/cli 全树零私钥材料)", (
77
77
 
78
78
  async function* walk(root: string): AsyncGenerator<string> {
79
79
  for (const name of await fsp.readdir(root)) {
80
- if (name === "node_modules" || name === "dist" || name.startsWith(".")) {
80
+ // 跳过 node_modules / dist / 点目录(依赖与构建产物);`config` 是 `ojm dev` 缺证时
81
+ // **现场签发**的开发证书目录(模板 .gitignore 的 `config/*.pem` 已挡住、进不了
82
+ // tarball)。本测试钉的是「源码树里没有私钥材料」,不是本地运行时产物——不跳
83
+ // config 会让模板自身跑过一次 dev 就永久变红(连带 `pnpm pack` 也不会带上它们)。
84
+ if (name === "node_modules" || name === "dist" || name === "config" || name.startsWith(".")) {
81
85
  continue;
82
86
  }
83
87
  const p = join(root, name);
@@ -8,19 +8,19 @@
8
8
  // 快照逐数组 ⊇ 声明,少 = 注册丢失判失败)collect-all 全败齐报。
9
9
  // entry 浏览器加载不在安装器验(Node import 必假绿——设计 §4.1),注释钉口径。
10
10
  // fetch/sha384/query/reload 面经 ctx 注入 stub(同 steps-fs 范式),fs 为 globalThis.fs 面。
11
- import type { FsFace } from "../../src/_platform/_lifecycle/atomic";
12
- import type { StateStore } from "../../src/_platform/_lifecycle/state";
13
- import type { DeployWebContext, ModuleEntry } from "../../src/_platform/_lifecycle/steps/deploy-web";
14
- import type { ReloadContext, ReloadFace, ReloadResult } from "../../src/_platform/_lifecycle/steps/reload";
15
- import type { SmokeContext } from "../../src/_platform/_lifecycle/steps/smoke";
11
+ import type { FsFace } from "../../src/_platform/api/_lifecycle/atomic";
12
+ import type { StateStore } from "../../src/_platform/api/_lifecycle/state";
13
+ import type { DeployWebContext, ModuleEntry } from "../../src/_platform/api/_lifecycle/steps/deploy-web";
14
+ import type { ReloadContext, ReloadFace, ReloadResult } from "../../src/_platform/api/_lifecycle/steps/reload";
15
+ import type { SmokeContext } from "../../src/_platform/api/_lifecycle/steps/smoke";
16
16
  import { createHash } from "node:crypto";
17
17
  import * as fsp from "node:fs/promises";
18
18
  import { tmpdir } from "node:os";
19
19
  import { join } from "node:path";
20
20
  import { afterEach, beforeEach, describe, expect, it } from "vitest";
21
- import { deployWeb, posixPath, upsertModulesJson } from "../../src/_platform/_lifecycle/steps/deploy-web";
22
- import { reloadAndAssert } from "../../src/_platform/_lifecycle/steps/reload";
23
- import { probeUrlOf, smoke } from "../../src/_platform/_lifecycle/steps/smoke";
21
+ import { deployWeb, posixPath, upsertModulesJson } from "../../src/_platform/api/_lifecycle/steps/deploy-web";
22
+ import { reloadAndAssert } from "../../src/_platform/api/_lifecycle/steps/reload";
23
+ import { probeUrlOf, smoke } from "../../src/_platform/api/_lifecycle/steps/smoke";
24
24
 
25
25
  const g = globalThis as any;
26
26
 
@@ -326,6 +326,29 @@ describe("smoke 探活(D14/Q-A:health 不强制)", () => {
326
326
  expect(r.ok).toBe(true);
327
327
  });
328
328
 
329
+ it("health 401 且路径属本次新增 anonymous(restart_pending)→ 判通过 + 落待重启提示", async () => {
330
+ await seedDeployed();
331
+ const r = await smoke(smCtx({
332
+ manifest: solManifest({ health: "/demo-solution/ping" }),
333
+ fetch: async () => ({ ok: false, status: 401 }),
334
+ deferredAnonymous: ["/demo-solution/ping"],
335
+ }));
336
+ expect(r.ok).toBe(true);
337
+ expect(r.message).toContain("restart_pending");
338
+ expect(r.message).toContain("重启宿主后生效");
339
+ });
340
+
341
+ it("health 401 但路径不是本次新增(已在配置里)→ 仍判失败(不放宽真失败)", async () => {
342
+ await seedDeployed();
343
+ const r = await smoke(smCtx({
344
+ manifest: solManifest({ health: "/demo-solution/ping" }),
345
+ fetch: async () => ({ ok: false, status: 401 }),
346
+ deferredAnonymous: ["/demo-solution/other"],
347
+ }));
348
+ expect(r.ok).toBe(false);
349
+ expect(r.message).toContain("401");
350
+ });
351
+
329
352
  it("health 非 2xx → 探活失败", async () => {
330
353
  await seedDeployed();
331
354
  const r = await smoke(smCtx({
@@ -12,22 +12,22 @@
12
12
  // 过期(30min)可接管。setEnabled 四处同写(D12/AC-P1-6):锁摘除/恢复 + sidecar + route + modules。
13
13
  // 步骤面全 stub 注入(DIP):fetch/exec/tar/reload 不真跑;register/smoke/audit 走真实内存库夹具。
14
14
  /* eslint-disable test/prefer-lowercase-title -- 任务/AC 编号是验收锚点,保留大写(register.spec 同约定) */
15
- import type { FsFace } from "../../src/_platform/_lifecycle/atomic";
16
- import type { InstallRequest } from "../../src/_platform/_lifecycle/installer";
17
- import type { StateStore } from "../../src/_platform/_lifecycle/state";
18
- import type { ExecFace } from "../../src/_platform/_lifecycle/steps/extract";
15
+ import type { FsFace } from "../../src/_platform/api/_lifecycle/atomic";
16
+ import type { InstallRequest } from "../../src/_platform/api/_lifecycle/installer";
17
+ import type { StateStore } from "../../src/_platform/api/_lifecycle/state";
18
+ import type { ExecFace } from "../../src/_platform/api/_lifecycle/steps/extract";
19
19
  import { createHash } from "node:crypto";
20
20
  import * as fsp from "node:fs/promises";
21
21
  import { tmpdir } from "node:os";
22
22
  import { join } from "node:path";
23
23
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
24
- import { defaultTestKey, nodeVerifyEd25519, signedArchiveFor } from "../../../../src/lifecycle/__tests__/helpers";
25
- import { atomicWriteText } from "../../src/_platform/_lifecycle/atomic";
26
- import { gcVersions, reconcile, runInstall, setEnabled, STAGES } from "../../src/_platform/_lifecycle/installer";
27
- import { acquireTaskLock, commitLockEntry, parseLock, readLock, serializeLock, writeLock } from "../../src/_platform/_lifecycle/lock";
28
- import { createStateStore } from "../../src/_platform/_lifecycle/state";
29
- import { getTask, readTasks, redact, sweepTimedOut, writeTask } from "../../src/_platform/_lifecycle/tasks";
30
- import { createTrustStore } from "../../src/_platform/_lifecycle/trust";
24
+ import { defaultTestKey, nodeVerifyEd25519, signedArchiveFor } from "../../../src/lifecycle/__tests__/helpers";
25
+ import { atomicWriteText } from "../../src/_platform/api/_lifecycle/atomic";
26
+ import { gcVersions, reconcile, runInstall, setEnabled, STAGES } from "../../src/_platform/api/_lifecycle/installer";
27
+ import { acquireTaskLock, commitLockEntry, parseLock, readLock, serializeLock, writeLock } from "../../src/_platform/api/_lifecycle/lock";
28
+ import { createStateStore } from "../../src/_platform/api/_lifecycle/state";
29
+ import { getTask, readTasks, redact, sweepTimedOut, writeTask } from "../../src/_platform/api/_lifecycle/tasks";
30
+ import { createTrustStore } from "../../src/_platform/api/_lifecycle/trust";
31
31
  import { installDb } from "../fixture";
32
32
 
33
33
  const g = globalThis as any;
@@ -532,8 +532,8 @@ describe("U5 取消安装(P3-8):cancel token → h.kill + staging 清场 +
532
532
 
533
533
  describe("第五终态 needs_trust(P2-3,G3 TOFU:未知 key_id 待确认,staging 不清场)", () => {
534
534
  it("未知 key 装 → needs_trust + trust 三元组 + unknown_key 指引;锁/库表/sidecar/审计零改动,staging 留存", async () => {
535
- const { generateKeyPair } = await import("../../../../src/lifecycle/keygen");
536
- const { signedArchiveFor: signFor } = await import("../../../../src/lifecycle/__tests__/helpers");
535
+ const { generateKeyPair } = await import("../../../src/lifecycle/keygen");
536
+ const { signedArchiveFor: signFor } = await import("../../../src/lifecycle/__tests__/helpers");
537
537
  const stranger = signFor(ARCHIVE, "demo-solution", "0.1.0", { keyPair: generateKeyPair(), keyId: "stranger.pub" });
538
538
  const m = manifestFixture("0.1.0");
539
539
  m.archive = { ...m.archive, signature: stranger.sig };
@@ -562,8 +562,8 @@ describe("第五终态 needs_trust(P2-3,G3 TOFU:未知 key_id 待确认,
562
562
  });
563
563
 
564
564
  it("TOFU 全链:确认入信任库(端点同路径 store.add)后原样重试 → done", async () => {
565
- const { generateKeyPair } = await import("../../../../src/lifecycle/keygen");
566
- const { signedArchiveFor: signFor } = await import("../../../../src/lifecycle/__tests__/helpers");
565
+ const { generateKeyPair } = await import("../../../src/lifecycle/keygen");
566
+ const { signedArchiveFor: signFor } = await import("../../../src/lifecycle/__tests__/helpers");
567
567
  const stranger = signFor(ARCHIVE, "demo-solution", "0.1.0", { keyPair: generateKeyPair(), keyId: "stranger.pub" });
568
568
  const m = manifestFixture("0.1.0");
569
569
  m.archive = { ...m.archive, signature: stranger.sig };