@eloxiv/testing 0.0.0-stage → 0.1.1

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 (1006) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Admin.d.ts +20 -0
  4. package/dist/Admin.d.ts.map +1 -0
  5. package/dist/Admin.js +61 -0
  6. package/dist/Admin.js.map +1 -0
  7. package/dist/Agent.d.ts +97 -0
  8. package/dist/Agent.d.ts.map +1 -0
  9. package/dist/Agent.js +210 -0
  10. package/dist/Agent.js.map +1 -0
  11. package/dist/AgentSurface.d.ts +20 -0
  12. package/dist/AgentSurface.d.ts.map +1 -0
  13. package/dist/AgentSurface.js +36 -0
  14. package/dist/AgentSurface.js.map +1 -0
  15. package/dist/Embedder.d.ts +21 -0
  16. package/dist/Embedder.d.ts.map +1 -0
  17. package/dist/Embedder.js +54 -0
  18. package/dist/Embedder.js.map +1 -0
  19. package/dist/EvalMain.d.ts +2 -0
  20. package/dist/EvalMain.d.ts.map +1 -0
  21. package/dist/EvalMain.js +80 -0
  22. package/dist/EvalMain.js.map +1 -0
  23. package/dist/Evals.d.ts +95 -0
  24. package/dist/Evals.d.ts.map +1 -0
  25. package/dist/Evals.js +389 -0
  26. package/dist/Evals.js.map +1 -0
  27. package/dist/Kernel.d.ts +88 -0
  28. package/dist/Kernel.d.ts.map +1 -0
  29. package/dist/Kernel.js +108 -0
  30. package/dist/Kernel.js.map +1 -0
  31. package/dist/Launch.d.ts +86 -0
  32. package/dist/Launch.d.ts.map +1 -0
  33. package/dist/Launch.js +370 -0
  34. package/dist/Launch.js.map +1 -0
  35. package/dist/Locks.d.ts +39 -0
  36. package/dist/Locks.d.ts.map +1 -0
  37. package/dist/Locks.js +94 -0
  38. package/dist/Locks.js.map +1 -0
  39. package/dist/Routes.d.ts +19 -0
  40. package/dist/Routes.d.ts.map +1 -0
  41. package/dist/Routes.js +38 -0
  42. package/dist/Routes.js.map +1 -0
  43. package/dist/ScriptedChatModel.d.ts +51 -0
  44. package/dist/ScriptedChatModel.d.ts.map +1 -0
  45. package/dist/ScriptedChatModel.js +135 -0
  46. package/dist/ScriptedChatModel.js.map +1 -0
  47. package/dist/SmtpSink.d.ts +36 -0
  48. package/dist/SmtpSink.d.ts.map +1 -0
  49. package/dist/SmtpSink.js +185 -0
  50. package/dist/SmtpSink.js.map +1 -0
  51. package/dist/System.d.ts +271 -0
  52. package/dist/System.d.ts.map +1 -0
  53. package/dist/System.js +908 -0
  54. package/dist/System.js.map +1 -0
  55. package/dist/TcpProxy.d.ts +17 -0
  56. package/dist/TcpProxy.d.ts.map +1 -0
  57. package/dist/TcpProxy.js +100 -0
  58. package/dist/TcpProxy.js.map +1 -0
  59. package/dist/auth/TrustedProxyAuth.d.ts +28 -0
  60. package/dist/auth/TrustedProxyAuth.d.ts.map +1 -0
  61. package/dist/auth/TrustedProxyAuth.js +128 -0
  62. package/dist/auth/TrustedProxyAuth.js.map +1 -0
  63. package/dist/conformance/ActionConsent.d.ts +3 -0
  64. package/dist/conformance/ActionConsent.d.ts.map +1 -0
  65. package/dist/conformance/ActionConsent.js +347 -0
  66. package/dist/conformance/ActionConsent.js.map +1 -0
  67. package/dist/conformance/ActionRegistry.d.ts +64 -0
  68. package/dist/conformance/ActionRegistry.d.ts.map +1 -0
  69. package/dist/conformance/ActionRegistry.js +136 -0
  70. package/dist/conformance/ActionRegistry.js.map +1 -0
  71. package/dist/conformance/Actor.d.ts +43 -0
  72. package/dist/conformance/Actor.d.ts.map +1 -0
  73. package/dist/conformance/Actor.js +171 -0
  74. package/dist/conformance/Actor.js.map +1 -0
  75. package/dist/conformance/AgentReference.d.ts +30 -0
  76. package/dist/conformance/AgentReference.d.ts.map +1 -0
  77. package/dist/conformance/AgentReference.js +137 -0
  78. package/dist/conformance/AgentReference.js.map +1 -0
  79. package/dist/conformance/AgentResources.d.ts +3 -0
  80. package/dist/conformance/AgentResources.d.ts.map +1 -0
  81. package/dist/conformance/AgentResources.js +454 -0
  82. package/dist/conformance/AgentResources.js.map +1 -0
  83. package/dist/conformance/AgentRuntime.d.ts +3 -0
  84. package/dist/conformance/AgentRuntime.d.ts.map +1 -0
  85. package/dist/conformance/AgentRuntime.js +302 -0
  86. package/dist/conformance/AgentRuntime.js.map +1 -0
  87. package/dist/conformance/AgentSubject.d.ts +87 -0
  88. package/dist/conformance/AgentSubject.d.ts.map +1 -0
  89. package/dist/conformance/AgentSubject.js +18 -0
  90. package/dist/conformance/AgentSubject.js.map +1 -0
  91. package/dist/conformance/Approvals.d.ts +3 -0
  92. package/dist/conformance/Approvals.d.ts.map +1 -0
  93. package/dist/conformance/Approvals.js +258 -0
  94. package/dist/conformance/Approvals.js.map +1 -0
  95. package/dist/conformance/Audit.d.ts +3 -0
  96. package/dist/conformance/Audit.d.ts.map +1 -0
  97. package/dist/conformance/Audit.js +221 -0
  98. package/dist/conformance/Audit.js.map +1 -0
  99. package/dist/conformance/CalendarProvider.d.ts +4 -0
  100. package/dist/conformance/CalendarProvider.d.ts.map +1 -0
  101. package/dist/conformance/CalendarProvider.js +108 -0
  102. package/dist/conformance/CalendarProvider.js.map +1 -0
  103. package/dist/conformance/CapabilityKit.d.ts +191 -0
  104. package/dist/conformance/CapabilityKit.d.ts.map +1 -0
  105. package/dist/conformance/CapabilityKit.js +375 -0
  106. package/dist/conformance/CapabilityKit.js.map +1 -0
  107. package/dist/conformance/ClientSDK.d.ts +78 -0
  108. package/dist/conformance/ClientSDK.d.ts.map +1 -0
  109. package/dist/conformance/ClientSDK.js +163 -0
  110. package/dist/conformance/ClientSDK.js.map +1 -0
  111. package/dist/conformance/CollabDocument.d.ts +3 -0
  112. package/dist/conformance/CollabDocument.d.ts.map +1 -0
  113. package/dist/conformance/CollabDocument.js +934 -0
  114. package/dist/conformance/CollabDocument.js.map +1 -0
  115. package/dist/conformance/CollabReference.d.ts +8 -0
  116. package/dist/conformance/CollabReference.d.ts.map +1 -0
  117. package/dist/conformance/CollabReference.js +138 -0
  118. package/dist/conformance/CollabReference.js.map +1 -0
  119. package/dist/conformance/CollabSubject.d.ts +68 -0
  120. package/dist/conformance/CollabSubject.d.ts.map +1 -0
  121. package/dist/conformance/CollabSubject.js +2 -0
  122. package/dist/conformance/CollabSubject.js.map +1 -0
  123. package/dist/conformance/Command.d.ts +3 -0
  124. package/dist/conformance/Command.d.ts.map +1 -0
  125. package/dist/conformance/Command.js +73 -0
  126. package/dist/conformance/Command.js.map +1 -0
  127. package/dist/conformance/Connections.d.ts +4 -0
  128. package/dist/conformance/Connections.d.ts.map +1 -0
  129. package/dist/conformance/Connections.js +308 -0
  130. package/dist/conformance/Connections.js.map +1 -0
  131. package/dist/conformance/ConnectionsReference.d.ts +56 -0
  132. package/dist/conformance/ConnectionsReference.d.ts.map +1 -0
  133. package/dist/conformance/ConnectionsReference.js +74 -0
  134. package/dist/conformance/ConnectionsReference.js.map +1 -0
  135. package/dist/conformance/ConnectorReference.d.ts +86 -0
  136. package/dist/conformance/ConnectorReference.d.ts.map +1 -0
  137. package/dist/conformance/ConnectorReference.js +185 -0
  138. package/dist/conformance/ConnectorReference.js.map +1 -0
  139. package/dist/conformance/ContextAccounting.d.ts +8 -0
  140. package/dist/conformance/ContextAccounting.d.ts.map +1 -0
  141. package/dist/conformance/ContextAccounting.js +125 -0
  142. package/dist/conformance/ContextAccounting.js.map +1 -0
  143. package/dist/conformance/Daemon.d.ts +150 -0
  144. package/dist/conformance/Daemon.d.ts.map +1 -0
  145. package/dist/conformance/Daemon.js +718 -0
  146. package/dist/conformance/Daemon.js.map +1 -0
  147. package/dist/conformance/DaemonReference.d.ts +15 -0
  148. package/dist/conformance/DaemonReference.d.ts.map +1 -0
  149. package/dist/conformance/DaemonReference.js +163 -0
  150. package/dist/conformance/DaemonReference.js.map +1 -0
  151. package/dist/conformance/DbTx.d.ts +17 -0
  152. package/dist/conformance/DbTx.d.ts.map +1 -0
  153. package/dist/conformance/DbTx.js +184 -0
  154. package/dist/conformance/DbTx.js.map +1 -0
  155. package/dist/conformance/DecisionTokens.d.ts +3 -0
  156. package/dist/conformance/DecisionTokens.d.ts.map +1 -0
  157. package/dist/conformance/DecisionTokens.js +551 -0
  158. package/dist/conformance/DecisionTokens.js.map +1 -0
  159. package/dist/conformance/Delegation.d.ts +3 -0
  160. package/dist/conformance/Delegation.d.ts.map +1 -0
  161. package/dist/conformance/Delegation.js +149 -0
  162. package/dist/conformance/Delegation.js.map +1 -0
  163. package/dist/conformance/DeskReference.d.ts +21 -0
  164. package/dist/conformance/DeskReference.d.ts.map +1 -0
  165. package/dist/conformance/DeskReference.js +47 -0
  166. package/dist/conformance/DeskReference.js.map +1 -0
  167. package/dist/conformance/DeviceControl.d.ts +3 -0
  168. package/dist/conformance/DeviceControl.d.ts.map +1 -0
  169. package/dist/conformance/DeviceControl.js +579 -0
  170. package/dist/conformance/DeviceControl.js.map +1 -0
  171. package/dist/conformance/Directory.d.ts +36 -0
  172. package/dist/conformance/Directory.d.ts.map +1 -0
  173. package/dist/conformance/Directory.js +253 -0
  174. package/dist/conformance/Directory.js.map +1 -0
  175. package/dist/conformance/DirectoryProvider.d.ts +4 -0
  176. package/dist/conformance/DirectoryProvider.d.ts.map +1 -0
  177. package/dist/conformance/DirectoryProvider.js +58 -0
  178. package/dist/conformance/DirectoryProvider.js.map +1 -0
  179. package/dist/conformance/DocumentSource.d.ts +4 -0
  180. package/dist/conformance/DocumentSource.d.ts.map +1 -0
  181. package/dist/conformance/DocumentSource.js +43 -0
  182. package/dist/conformance/DocumentSource.js.map +1 -0
  183. package/dist/conformance/EndpointReference.d.ts +40 -0
  184. package/dist/conformance/EndpointReference.d.ts.map +1 -0
  185. package/dist/conformance/EndpointReference.js +67 -0
  186. package/dist/conformance/EndpointReference.js.map +1 -0
  187. package/dist/conformance/Files.d.ts +40 -0
  188. package/dist/conformance/Files.d.ts.map +1 -0
  189. package/dist/conformance/Files.js +592 -0
  190. package/dist/conformance/Files.js.map +1 -0
  191. package/dist/conformance/FilesReference.d.ts +31 -0
  192. package/dist/conformance/FilesReference.d.ts.map +1 -0
  193. package/dist/conformance/FilesReference.js +116 -0
  194. package/dist/conformance/FilesReference.js.map +1 -0
  195. package/dist/conformance/FilesSubject.d.ts +46 -0
  196. package/dist/conformance/FilesSubject.d.ts.map +1 -0
  197. package/dist/conformance/FilesSubject.js +3 -0
  198. package/dist/conformance/FilesSubject.js.map +1 -0
  199. package/dist/conformance/Flags.d.ts +3 -0
  200. package/dist/conformance/Flags.d.ts.map +1 -0
  201. package/dist/conformance/Flags.js +183 -0
  202. package/dist/conformance/Flags.js.map +1 -0
  203. package/dist/conformance/Host.d.ts +64 -0
  204. package/dist/conformance/Host.d.ts.map +1 -0
  205. package/dist/conformance/Host.js +152 -0
  206. package/dist/conformance/Host.js.map +1 -0
  207. package/dist/conformance/HttpApi.d.ts +5 -0
  208. package/dist/conformance/HttpApi.d.ts.map +1 -0
  209. package/dist/conformance/HttpApi.js +131 -0
  210. package/dist/conformance/HttpApi.js.map +1 -0
  211. package/dist/conformance/InboxReference.d.ts +28 -0
  212. package/dist/conformance/InboxReference.d.ts.map +1 -0
  213. package/dist/conformance/InboxReference.js +331 -0
  214. package/dist/conformance/InboxReference.js.map +1 -0
  215. package/dist/conformance/InboxSubject.d.ts +92 -0
  216. package/dist/conformance/InboxSubject.d.ts.map +1 -0
  217. package/dist/conformance/InboxSubject.js +16 -0
  218. package/dist/conformance/InboxSubject.js.map +1 -0
  219. package/dist/conformance/Ingestion.d.ts +10 -0
  220. package/dist/conformance/Ingestion.d.ts.map +1 -0
  221. package/dist/conformance/Ingestion.js +335 -0
  222. package/dist/conformance/Ingestion.js.map +1 -0
  223. package/dist/conformance/Ingress.d.ts +62 -0
  224. package/dist/conformance/Ingress.d.ts.map +1 -0
  225. package/dist/conformance/Ingress.js +346 -0
  226. package/dist/conformance/Ingress.js.map +1 -0
  227. package/dist/conformance/Invocation.d.ts +3 -0
  228. package/dist/conformance/Invocation.d.ts.map +1 -0
  229. package/dist/conformance/Invocation.js +665 -0
  230. package/dist/conformance/Invocation.js.map +1 -0
  231. package/dist/conformance/IsolationMatrix.d.ts +60 -0
  232. package/dist/conformance/IsolationMatrix.d.ts.map +1 -0
  233. package/dist/conformance/IsolationMatrix.js +196 -0
  234. package/dist/conformance/IsolationMatrix.js.map +1 -0
  235. package/dist/conformance/LiveConnection.d.ts +72 -0
  236. package/dist/conformance/LiveConnection.d.ts.map +1 -0
  237. package/dist/conformance/LiveConnection.js +125 -0
  238. package/dist/conformance/LiveConnection.js.map +1 -0
  239. package/dist/conformance/LocalClient.d.ts +70 -0
  240. package/dist/conformance/LocalClient.d.ts.map +1 -0
  241. package/dist/conformance/LocalClient.js +576 -0
  242. package/dist/conformance/LocalClient.js.map +1 -0
  243. package/dist/conformance/Locale.d.ts +28 -0
  244. package/dist/conformance/Locale.d.ts.map +1 -0
  245. package/dist/conformance/Locale.js +115 -0
  246. package/dist/conformance/Locale.js.map +1 -0
  247. package/dist/conformance/MachineIdentity.d.ts +39 -0
  248. package/dist/conformance/MachineIdentity.d.ts.map +1 -0
  249. package/dist/conformance/MachineIdentity.js +595 -0
  250. package/dist/conformance/MachineIdentity.js.map +1 -0
  251. package/dist/conformance/MailProvider.d.ts +4 -0
  252. package/dist/conformance/MailProvider.d.ts.map +1 -0
  253. package/dist/conformance/MailProvider.js +167 -0
  254. package/dist/conformance/MailProvider.js.map +1 -0
  255. package/dist/conformance/Memory.d.ts +10 -0
  256. package/dist/conformance/Memory.d.ts.map +1 -0
  257. package/dist/conformance/Memory.js +179 -0
  258. package/dist/conformance/Memory.js.map +1 -0
  259. package/dist/conformance/Messaging.d.ts +49 -0
  260. package/dist/conformance/Messaging.d.ts.map +1 -0
  261. package/dist/conformance/Messaging.js +117 -0
  262. package/dist/conformance/Messaging.js.map +1 -0
  263. package/dist/conformance/Metering.d.ts +26 -0
  264. package/dist/conformance/Metering.d.ts.map +1 -0
  265. package/dist/conformance/Metering.js +236 -0
  266. package/dist/conformance/Metering.js.map +1 -0
  267. package/dist/conformance/ModelProvider.d.ts +32 -0
  268. package/dist/conformance/ModelProvider.d.ts.map +1 -0
  269. package/dist/conformance/ModelProvider.js +100 -0
  270. package/dist/conformance/ModelProvider.js.map +1 -0
  271. package/dist/conformance/ModuleManifest.d.ts +9 -0
  272. package/dist/conformance/ModuleManifest.d.ts.map +1 -0
  273. package/dist/conformance/ModuleManifest.js +542 -0
  274. package/dist/conformance/ModuleManifest.js.map +1 -0
  275. package/dist/conformance/NotebookAgent.d.ts +32 -0
  276. package/dist/conformance/NotebookAgent.d.ts.map +1 -0
  277. package/dist/conformance/NotebookAgent.js +31 -0
  278. package/dist/conformance/NotebookAgent.js.map +1 -0
  279. package/dist/conformance/NotificationChannel.d.ts +40 -0
  280. package/dist/conformance/NotificationChannel.d.ts.map +1 -0
  281. package/dist/conformance/NotificationChannel.js +78 -0
  282. package/dist/conformance/NotificationChannel.js.map +1 -0
  283. package/dist/conformance/Notifications.d.ts +3 -0
  284. package/dist/conformance/Notifications.d.ts.map +1 -0
  285. package/dist/conformance/Notifications.js +240 -0
  286. package/dist/conformance/Notifications.js.map +1 -0
  287. package/dist/conformance/OAuthClient.d.ts +123 -0
  288. package/dist/conformance/OAuthClient.d.ts.map +1 -0
  289. package/dist/conformance/OAuthClient.js +204 -0
  290. package/dist/conformance/OAuthClient.js.map +1 -0
  291. package/dist/conformance/Outbox.d.ts +3 -0
  292. package/dist/conformance/Outbox.d.ts.map +1 -0
  293. package/dist/conformance/Outbox.js +266 -0
  294. package/dist/conformance/Outbox.js.map +1 -0
  295. package/dist/conformance/PlatformReference.d.ts +5 -0
  296. package/dist/conformance/PlatformReference.d.ts.map +1 -0
  297. package/dist/conformance/PlatformReference.js +66 -0
  298. package/dist/conformance/PlatformReference.js.map +1 -0
  299. package/dist/conformance/PlatformSubject.d.ts +45 -0
  300. package/dist/conformance/PlatformSubject.d.ts.map +1 -0
  301. package/dist/conformance/PlatformSubject.js +3 -0
  302. package/dist/conformance/PlatformSubject.js.map +1 -0
  303. package/dist/conformance/Privacy.d.ts +3 -0
  304. package/dist/conformance/Privacy.d.ts.map +1 -0
  305. package/dist/conformance/Privacy.js +437 -0
  306. package/dist/conformance/Privacy.js.map +1 -0
  307. package/dist/conformance/Progress.d.ts +3 -0
  308. package/dist/conformance/Progress.d.ts.map +1 -0
  309. package/dist/conformance/Progress.js +153 -0
  310. package/dist/conformance/Progress.js.map +1 -0
  311. package/dist/conformance/Push.d.ts +38 -0
  312. package/dist/conformance/Push.d.ts.map +1 -0
  313. package/dist/conformance/Push.js +649 -0
  314. package/dist/conformance/Push.js.map +1 -0
  315. package/dist/conformance/PushReference.d.ts +3 -0
  316. package/dist/conformance/PushReference.d.ts.map +1 -0
  317. package/dist/conformance/PushReference.js +97 -0
  318. package/dist/conformance/PushReference.js.map +1 -0
  319. package/dist/conformance/QuerySurface.d.ts +9 -0
  320. package/dist/conformance/QuerySurface.d.ts.map +1 -0
  321. package/dist/conformance/QuerySurface.js +349 -0
  322. package/dist/conformance/QuerySurface.js.map +1 -0
  323. package/dist/conformance/Readiness.d.ts +23 -0
  324. package/dist/conformance/Readiness.d.ts.map +1 -0
  325. package/dist/conformance/Readiness.js +110 -0
  326. package/dist/conformance/Readiness.js.map +1 -0
  327. package/dist/conformance/Reference.d.ts +17 -0
  328. package/dist/conformance/Reference.d.ts.map +1 -0
  329. package/dist/conformance/Reference.js +246 -0
  330. package/dist/conformance/Reference.js.map +1 -0
  331. package/dist/conformance/Release.d.ts +73 -0
  332. package/dist/conformance/Release.d.ts.map +1 -0
  333. package/dist/conformance/Release.js +556 -0
  334. package/dist/conformance/Release.js.map +1 -0
  335. package/dist/conformance/ReleaseReference.d.ts +5 -0
  336. package/dist/conformance/ReleaseReference.d.ts.map +1 -0
  337. package/dist/conformance/ReleaseReference.js +124 -0
  338. package/dist/conformance/ReleaseReference.js.map +1 -0
  339. package/dist/conformance/ResultRendering.d.ts +3 -0
  340. package/dist/conformance/ResultRendering.d.ts.map +1 -0
  341. package/dist/conformance/ResultRendering.js +120 -0
  342. package/dist/conformance/ResultRendering.js.map +1 -0
  343. package/dist/conformance/Sandbox.d.ts +58 -0
  344. package/dist/conformance/Sandbox.d.ts.map +1 -0
  345. package/dist/conformance/Sandbox.js +213 -0
  346. package/dist/conformance/Sandbox.js.map +1 -0
  347. package/dist/conformance/SandboxReference.d.ts +3 -0
  348. package/dist/conformance/SandboxReference.d.ts.map +1 -0
  349. package/dist/conformance/SandboxReference.js +44 -0
  350. package/dist/conformance/SandboxReference.js.map +1 -0
  351. package/dist/conformance/Scheduler.d.ts +106 -0
  352. package/dist/conformance/Scheduler.d.ts.map +1 -0
  353. package/dist/conformance/Scheduler.js +576 -0
  354. package/dist/conformance/Scheduler.js.map +1 -0
  355. package/dist/conformance/ScreenContext.d.ts +84 -0
  356. package/dist/conformance/ScreenContext.d.ts.map +1 -0
  357. package/dist/conformance/ScreenContext.js +290 -0
  358. package/dist/conformance/ScreenContext.js.map +1 -0
  359. package/dist/conformance/Search.d.ts +3 -0
  360. package/dist/conformance/Search.d.ts.map +1 -0
  361. package/dist/conformance/Search.js +333 -0
  362. package/dist/conformance/Search.js.map +1 -0
  363. package/dist/conformance/Secrets.d.ts +8 -0
  364. package/dist/conformance/Secrets.d.ts.map +1 -0
  365. package/dist/conformance/Secrets.js +231 -0
  366. package/dist/conformance/Secrets.js.map +1 -0
  367. package/dist/conformance/SecretsReference.d.ts +44 -0
  368. package/dist/conformance/SecretsReference.d.ts.map +1 -0
  369. package/dist/conformance/SecretsReference.js +73 -0
  370. package/dist/conformance/SecretsReference.js.map +1 -0
  371. package/dist/conformance/ServicesReference.d.ts +8 -0
  372. package/dist/conformance/ServicesReference.d.ts.map +1 -0
  373. package/dist/conformance/ServicesReference.js +273 -0
  374. package/dist/conformance/ServicesReference.js.map +1 -0
  375. package/dist/conformance/ServicesSubject.d.ts +104 -0
  376. package/dist/conformance/ServicesSubject.d.ts.map +1 -0
  377. package/dist/conformance/ServicesSubject.js +2 -0
  378. package/dist/conformance/ServicesSubject.js.map +1 -0
  379. package/dist/conformance/Settings.d.ts +3 -0
  380. package/dist/conformance/Settings.d.ts.map +1 -0
  381. package/dist/conformance/Settings.js +177 -0
  382. package/dist/conformance/Settings.js.map +1 -0
  383. package/dist/conformance/Sharing.d.ts +3 -0
  384. package/dist/conformance/Sharing.d.ts.map +1 -0
  385. package/dist/conformance/Sharing.js +368 -0
  386. package/dist/conformance/Sharing.js.map +1 -0
  387. package/dist/conformance/ShellSubject.d.ts +29 -0
  388. package/dist/conformance/ShellSubject.d.ts.map +1 -0
  389. package/dist/conformance/ShellSubject.js +13 -0
  390. package/dist/conformance/ShellSubject.js.map +1 -0
  391. package/dist/conformance/SignOutRace.d.ts +23 -0
  392. package/dist/conformance/SignOutRace.d.ts.map +1 -0
  393. package/dist/conformance/SignOutRace.js +49 -0
  394. package/dist/conformance/SignOutRace.js.map +1 -0
  395. package/dist/conformance/Slot.d.ts +3 -0
  396. package/dist/conformance/Slot.d.ts.map +1 -0
  397. package/dist/conformance/Slot.js +79 -0
  398. package/dist/conformance/Slot.js.map +1 -0
  399. package/dist/conformance/Space.d.ts +63 -0
  400. package/dist/conformance/Space.d.ts.map +1 -0
  401. package/dist/conformance/Space.js +294 -0
  402. package/dist/conformance/Space.js.map +1 -0
  403. package/dist/conformance/StorageAdapter.d.ts +76 -0
  404. package/dist/conformance/StorageAdapter.d.ts.map +1 -0
  405. package/dist/conformance/StorageAdapter.js +181 -0
  406. package/dist/conformance/StorageAdapter.js.map +1 -0
  407. package/dist/conformance/StorageBackend.d.ts +23 -0
  408. package/dist/conformance/StorageBackend.d.ts.map +1 -0
  409. package/dist/conformance/StorageBackend.js +274 -0
  410. package/dist/conformance/StorageBackend.js.map +1 -0
  411. package/dist/conformance/Subject.d.ts +198 -0
  412. package/dist/conformance/Subject.d.ts.map +1 -0
  413. package/dist/conformance/Subject.js +26 -0
  414. package/dist/conformance/Subject.js.map +1 -0
  415. package/dist/conformance/Sync.d.ts +3 -0
  416. package/dist/conformance/Sync.d.ts.map +1 -0
  417. package/dist/conformance/Sync.js +190 -0
  418. package/dist/conformance/Sync.js.map +1 -0
  419. package/dist/conformance/Telemetry.d.ts +3 -0
  420. package/dist/conformance/Telemetry.d.ts.map +1 -0
  421. package/dist/conformance/Telemetry.js +218 -0
  422. package/dist/conformance/Telemetry.js.map +1 -0
  423. package/dist/conformance/ThemeTokens.d.ts +22 -0
  424. package/dist/conformance/ThemeTokens.d.ts.map +1 -0
  425. package/dist/conformance/ThemeTokens.js +121 -0
  426. package/dist/conformance/ThemeTokens.js.map +1 -0
  427. package/dist/conformance/ToolSource.d.ts +5 -0
  428. package/dist/conformance/ToolSource.d.ts.map +1 -0
  429. package/dist/conformance/ToolSource.js +520 -0
  430. package/dist/conformance/ToolSource.js.map +1 -0
  431. package/dist/conformance/Versioning.d.ts +3 -0
  432. package/dist/conformance/Versioning.d.ts.map +1 -0
  433. package/dist/conformance/Versioning.js +160 -0
  434. package/dist/conformance/Versioning.js.map +1 -0
  435. package/dist/conformance/View.d.ts +3 -0
  436. package/dist/conformance/View.d.ts.map +1 -0
  437. package/dist/conformance/View.js +121 -0
  438. package/dist/conformance/View.js.map +1 -0
  439. package/dist/conformance/WorkItems.d.ts +3 -0
  440. package/dist/conformance/WorkItems.d.ts.map +1 -0
  441. package/dist/conformance/WorkItems.js +152 -0
  442. package/dist/conformance/WorkItems.js.map +1 -0
  443. package/dist/conformance/Workflow.d.ts +63 -0
  444. package/dist/conformance/Workflow.d.ts.map +1 -0
  445. package/dist/conformance/Workflow.js +235 -0
  446. package/dist/conformance/Workflow.js.map +1 -0
  447. package/dist/conformance/acme/chatlog.d.ts +591 -0
  448. package/dist/conformance/acme/chatlog.d.ts.map +1 -0
  449. package/dist/conformance/acme/chatlog.js +101 -0
  450. package/dist/conformance/acme/chatlog.js.map +1 -0
  451. package/dist/conformance/acme/connector.d.ts +12 -0
  452. package/dist/conformance/acme/connector.d.ts.map +1 -0
  453. package/dist/conformance/acme/connector.js +123 -0
  454. package/dist/conformance/acme/connector.js.map +1 -0
  455. package/dist/conformance/acme/migrations/0000_messages.sql +8 -0
  456. package/dist/conformance/archive/app.d.ts +728 -0
  457. package/dist/conformance/archive/app.d.ts.map +1 -0
  458. package/dist/conformance/archive/app.js +30 -0
  459. package/dist/conformance/archive/app.js.map +1 -0
  460. package/dist/conformance/archive/contract.d.ts +467 -0
  461. package/dist/conformance/archive/contract.d.ts.map +1 -0
  462. package/dist/conformance/archive/contract.js +187 -0
  463. package/dist/conformance/archive/contract.js.map +1 -0
  464. package/dist/conformance/archive/memo.sync.gen.d.ts +148 -0
  465. package/dist/conformance/archive/memo.sync.gen.d.ts.map +1 -0
  466. package/dist/conformance/archive/memo.sync.gen.js +23 -0
  467. package/dist/conformance/archive/memo.sync.gen.js.map +1 -0
  468. package/dist/conformance/archive/migrations/archive/0000_archive.sql +9 -0
  469. package/dist/conformance/archive/migrations/memo/0000_memo.sql +6 -0
  470. package/dist/conformance/archive/schema.d.ts +185 -0
  471. package/dist/conformance/archive/schema.d.ts.map +1 -0
  472. package/dist/conformance/archive/schema.js +22 -0
  473. package/dist/conformance/archive/schema.js.map +1 -0
  474. package/dist/conformance/archive/server.d.ts +273 -0
  475. package/dist/conformance/archive/server.d.ts.map +1 -0
  476. package/dist/conformance/archive/server.js +127 -0
  477. package/dist/conformance/archive/server.js.map +1 -0
  478. package/dist/conformance/archive/sync.gen.d.ts +319 -0
  479. package/dist/conformance/archive/sync.gen.d.ts.map +1 -0
  480. package/dist/conformance/archive/sync.gen.js +29 -0
  481. package/dist/conformance/archive/sync.gen.js.map +1 -0
  482. package/dist/conformance/atlas/app.d.ts +3 -0
  483. package/dist/conformance/atlas/app.d.ts.map +1 -0
  484. package/dist/conformance/atlas/app.js +15 -0
  485. package/dist/conformance/atlas/app.js.map +1 -0
  486. package/dist/conformance/atlas/contract.d.ts +489 -0
  487. package/dist/conformance/atlas/contract.d.ts.map +1 -0
  488. package/dist/conformance/atlas/contract.js +114 -0
  489. package/dist/conformance/atlas/contract.js.map +1 -0
  490. package/dist/conformance/crm/app.d.ts +304 -0
  491. package/dist/conformance/crm/app.d.ts.map +1 -0
  492. package/dist/conformance/crm/app.js +95 -0
  493. package/dist/conformance/crm/app.js.map +1 -0
  494. package/dist/conformance/crm/contract.d.ts +586 -0
  495. package/dist/conformance/crm/contract.d.ts.map +1 -0
  496. package/dist/conformance/crm/contract.js +153 -0
  497. package/dist/conformance/crm/contract.js.map +1 -0
  498. package/dist/conformance/crm/migrations/crm/0000_crm.sql +18 -0
  499. package/dist/conformance/crm/migrations/team/0000_team.sql +6 -0
  500. package/dist/conformance/crm/schema.d.ts +261 -0
  501. package/dist/conformance/crm/schema.d.ts.map +1 -0
  502. package/dist/conformance/crm/schema.js +25 -0
  503. package/dist/conformance/crm/schema.js.map +1 -0
  504. package/dist/conformance/crm/sync.gen.d.ts +188 -0
  505. package/dist/conformance/crm/sync.gen.d.ts.map +1 -0
  506. package/dist/conformance/crm/sync.gen.js +25 -0
  507. package/dist/conformance/crm/sync.gen.js.map +1 -0
  508. package/dist/conformance/desk/contract.d.ts +306 -0
  509. package/dist/conformance/desk/contract.d.ts.map +1 -0
  510. package/dist/conformance/desk/contract.js +56 -0
  511. package/dist/conformance/desk/contract.js.map +1 -0
  512. package/dist/conformance/desk/migrations/0000_notes.sql +7 -0
  513. package/dist/conformance/desk/server.d.ts +231 -0
  514. package/dist/conformance/desk/server.d.ts.map +1 -0
  515. package/dist/conformance/desk/server.js +123 -0
  516. package/dist/conformance/desk/server.js.map +1 -0
  517. package/dist/conformance/drafts/migrations/0000_drafts.sql +8 -0
  518. package/dist/conformance/drafts/module.d.ts +571 -0
  519. package/dist/conformance/drafts/module.d.ts.map +1 -0
  520. package/dist/conformance/drafts/module.js +190 -0
  521. package/dist/conformance/drafts/module.js.map +1 -0
  522. package/dist/conformance/fixture/app.d.ts +24 -0
  523. package/dist/conformance/fixture/app.d.ts.map +1 -0
  524. package/dist/conformance/fixture/app.js +26 -0
  525. package/dist/conformance/fixture/app.js.map +1 -0
  526. package/dist/conformance/fixture/docs/bad-sync.d.ts +105 -0
  527. package/dist/conformance/fixture/docs/bad-sync.d.ts.map +1 -0
  528. package/dist/conformance/fixture/docs/bad-sync.js +22 -0
  529. package/dist/conformance/fixture/docs/bad-sync.js.map +1 -0
  530. package/dist/conformance/fixture/docs/contract.d.ts +1091 -0
  531. package/dist/conformance/fixture/docs/contract.d.ts.map +1 -0
  532. package/dist/conformance/fixture/docs/contract.js +277 -0
  533. package/dist/conformance/fixture/docs/contract.js.map +1 -0
  534. package/dist/conformance/fixture/docs/migrations/0000_docs.sql +9 -0
  535. package/dist/conformance/fixture/docs/migrations/0001_seen.sql +12 -0
  536. package/dist/conformance/fixture/docs/migrations/0002_attachment.sql +6 -0
  537. package/dist/conformance/fixture/docs/policy.cedar +110 -0
  538. package/dist/conformance/fixture/docs/schema.d.ts +308 -0
  539. package/dist/conformance/fixture/docs/schema.d.ts.map +1 -0
  540. package/dist/conformance/fixture/docs/schema.js +36 -0
  541. package/dist/conformance/fixture/docs/schema.js.map +1 -0
  542. package/dist/conformance/fixture/docs/server.d.ts +552 -0
  543. package/dist/conformance/fixture/docs/server.d.ts.map +1 -0
  544. package/dist/conformance/fixture/docs/server.js +192 -0
  545. package/dist/conformance/fixture/docs/server.js.map +1 -0
  546. package/dist/conformance/fixture/docs/sync.d.ts +402 -0
  547. package/dist/conformance/fixture/docs/sync.d.ts.map +1 -0
  548. package/dist/conformance/fixture/docs/sync.gen.d.ts +574 -0
  549. package/dist/conformance/fixture/docs/sync.gen.d.ts.map +1 -0
  550. package/dist/conformance/fixture/docs/sync.gen.js +48 -0
  551. package/dist/conformance/fixture/docs/sync.gen.js.map +1 -0
  552. package/dist/conformance/fixture/docs/sync.js +23 -0
  553. package/dist/conformance/fixture/docs/sync.js.map +1 -0
  554. package/dist/conformance/fixture/peer/migrations/0000_peer.sql +8 -0
  555. package/dist/conformance/fixture/peer/module.d.ts +306 -0
  556. package/dist/conformance/fixture/peer/module.d.ts.map +1 -0
  557. package/dist/conformance/fixture/peer/module.js +44 -0
  558. package/dist/conformance/fixture/peer/module.js.map +1 -0
  559. package/dist/conformance/fixture/release/blocking/0000_item.sql +3 -0
  560. package/dist/conformance/fixture/release/blocking/0001_wait.sql +2 -0
  561. package/dist/conformance/fixture/release/blocking-renamed/0000_item.sql +3 -0
  562. package/dist/conformance/fixture/release/blocking-renamed/0001_wait.sql +5 -0
  563. package/dist/conformance/fixture/release/broken/0000_item.sql +3 -0
  564. package/dist/conformance/fixture/release/broken/0001_extra.sql +3 -0
  565. package/dist/conformance/fixture/release/broken/0002_label.sql +3 -0
  566. package/dist/conformance/fixture/release/drift/escalate/0000_item.sql +5 -0
  567. package/dist/conformance/fixture/release/drift/escalate/0001_escalate.sql +8 -0
  568. package/dist/conformance/fixture/release/drift/v1/0000_item.sql +5 -0
  569. package/dist/conformance/fixture/release/escape/0000_item.sql +3 -0
  570. package/dist/conformance/fixture/release/escape/0001_escape.sql +5 -0
  571. package/dist/conformance/fixture/release/misnamed/0000_item.sql +3 -0
  572. package/dist/conformance/fixture/release/misnamed/0001_misname.sql +10 -0
  573. package/dist/conformance/fixture/release/module.d.ts +1878 -0
  574. package/dist/conformance/fixture/release/module.d.ts.map +1 -0
  575. package/dist/conformance/fixture/release/module.js +102 -0
  576. package/dist/conformance/fixture/release/module.js.map +1 -0
  577. package/dist/conformance/fixture/release/outside/0000_item.sql +3 -0
  578. package/dist/conformance/fixture/release/outside/0001_extra.sql +3 -0
  579. package/dist/conformance/fixture/release/outside/0002_index.sql +4 -0
  580. package/dist/conformance/fixture/release/outside/0003_later.sql +1 -0
  581. package/dist/conformance/fixture/release/renamed/0000_item.sql +3 -0
  582. package/dist/conformance/fixture/release/renamed/0001_misname.sql +10 -0
  583. package/dist/conformance/fixture/release/renamed/0002_restore.sql +1 -0
  584. package/dist/conformance/fixture/release/rogue/0000_item.sql +3 -0
  585. package/dist/conformance/fixture/release/rogue/0001_extra.sql +3 -0
  586. package/dist/conformance/fixture/release/rogue/0002_definer.sql +1 -0
  587. package/dist/conformance/fixture/release/slow/0000_item.sql +5 -0
  588. package/dist/conformance/fixture/release/undeclared/0000_item.sql +3 -0
  589. package/dist/conformance/fixture/release/undeclared/0001_extra.sql +3 -0
  590. package/dist/conformance/fixture/release/undeclared/0002_index.sql +1 -0
  591. package/dist/conformance/fixture/release/v1/0000_item.sql +3 -0
  592. package/dist/conformance/fixture/release/v2/0000_item.sql +3 -0
  593. package/dist/conformance/fixture/release/v2/0001_extra.sql +3 -0
  594. package/dist/conformance/fixture/release/v2/0002_label.sql +3 -0
  595. package/dist/conformance/fixture/release/viewed-retyped/0000_item.sql +3 -0
  596. package/dist/conformance/fixture/release/viewed-retyped/0001_retype.sql +1 -0
  597. package/dist/conformance/kit-hash.d.ts +8 -0
  598. package/dist/conformance/kit-hash.d.ts.map +1 -0
  599. package/dist/conformance/kit-hash.js +20 -0
  600. package/dist/conformance/kit-hash.js.map +1 -0
  601. package/dist/conformance/ledger/contract.d.ts +380 -0
  602. package/dist/conformance/ledger/contract.d.ts.map +1 -0
  603. package/dist/conformance/ledger/contract.js +81 -0
  604. package/dist/conformance/ledger/contract.js.map +1 -0
  605. package/dist/conformance/ledger/migrations/0000_entries.sql +8 -0
  606. package/dist/conformance/ledger/server.d.ts +312 -0
  607. package/dist/conformance/ledger/server.d.ts.map +1 -0
  608. package/dist/conformance/ledger/server.js +152 -0
  609. package/dist/conformance/ledger/server.js.map +1 -0
  610. package/dist/conformance/library/app.d.ts +616 -0
  611. package/dist/conformance/library/app.d.ts.map +1 -0
  612. package/dist/conformance/library/app.js +35 -0
  613. package/dist/conformance/library/app.js.map +1 -0
  614. package/dist/conformance/library/contract.d.ts +377 -0
  615. package/dist/conformance/library/contract.d.ts.map +1 -0
  616. package/dist/conformance/library/contract.js +63 -0
  617. package/dist/conformance/library/contract.js.map +1 -0
  618. package/dist/conformance/library/migrations/0000_library.sql +14 -0
  619. package/dist/conformance/library/schema.d.ts +174 -0
  620. package/dist/conformance/library/schema.d.ts.map +1 -0
  621. package/dist/conformance/library/schema.js +24 -0
  622. package/dist/conformance/library/schema.js.map +1 -0
  623. package/dist/conformance/library/server.d.ts +191 -0
  624. package/dist/conformance/library/server.d.ts.map +1 -0
  625. package/dist/conformance/library/server.js +52 -0
  626. package/dist/conformance/library/server.js.map +1 -0
  627. package/dist/conformance/library/sync.gen.d.ts +519 -0
  628. package/dist/conformance/library/sync.gen.d.ts.map +1 -0
  629. package/dist/conformance/library/sync.gen.js +42 -0
  630. package/dist/conformance/library/sync.gen.js.map +1 -0
  631. package/dist/conformance/locale/catalog.d.ts +93 -0
  632. package/dist/conformance/locale/catalog.d.ts.map +1 -0
  633. package/dist/conformance/locale/catalog.js +104 -0
  634. package/dist/conformance/locale/catalog.js.map +1 -0
  635. package/dist/conformance/notebook/app.d.ts +1039 -0
  636. package/dist/conformance/notebook/app.d.ts.map +1 -0
  637. package/dist/conformance/notebook/app.js +88 -0
  638. package/dist/conformance/notebook/app.js.map +1 -0
  639. package/dist/conformance/notebook/evals/pages.evals.json +94 -0
  640. package/dist/conformance/notebook/migrations/0000_notebook.sql +10 -0
  641. package/dist/conformance/notebook/module.d.ts +717 -0
  642. package/dist/conformance/notebook/module.d.ts.map +1 -0
  643. package/dist/conformance/notebook/module.js +188 -0
  644. package/dist/conformance/notebook/module.js.map +1 -0
  645. package/dist/conformance/pad/app.d.ts +9 -0
  646. package/dist/conformance/pad/app.d.ts.map +1 -0
  647. package/dist/conformance/pad/app.js +13 -0
  648. package/dist/conformance/pad/app.js.map +1 -0
  649. package/dist/conformance/pad/contract.d.ts +281 -0
  650. package/dist/conformance/pad/contract.d.ts.map +1 -0
  651. package/dist/conformance/pad/contract.js +66 -0
  652. package/dist/conformance/pad/contract.js.map +1 -0
  653. package/dist/conformance/pad/migrations/pad/0000_pad.sql +8 -0
  654. package/dist/conformance/pad/migrations/pad/0001_live_copy.sql +2 -0
  655. package/dist/conformance/pad/schema.d.ts +127 -0
  656. package/dist/conformance/pad/schema.d.ts.map +1 -0
  657. package/dist/conformance/pad/schema.js +17 -0
  658. package/dist/conformance/pad/schema.js.map +1 -0
  659. package/dist/conformance/pad/server.d.ts +149 -0
  660. package/dist/conformance/pad/server.d.ts.map +1 -0
  661. package/dist/conformance/pad/server.js +81 -0
  662. package/dist/conformance/pad/server.js.map +1 -0
  663. package/dist/conformance/purchases/app.d.ts +480 -0
  664. package/dist/conformance/purchases/app.d.ts.map +1 -0
  665. package/dist/conformance/purchases/app.js +32 -0
  666. package/dist/conformance/purchases/app.js.map +1 -0
  667. package/dist/conformance/purchases/contract.d.ts +720 -0
  668. package/dist/conformance/purchases/contract.d.ts.map +1 -0
  669. package/dist/conformance/purchases/contract.js +148 -0
  670. package/dist/conformance/purchases/contract.js.map +1 -0
  671. package/dist/conformance/purchases/migrations/0000_purchases.sql +17 -0
  672. package/dist/conformance/purchases/server.d.ts +250 -0
  673. package/dist/conformance/purchases/server.d.ts.map +1 -0
  674. package/dist/conformance/purchases/server.js +85 -0
  675. package/dist/conformance/purchases/server.js.map +1 -0
  676. package/dist/conformance/studio/app.d.ts +996 -0
  677. package/dist/conformance/studio/app.d.ts.map +1 -0
  678. package/dist/conformance/studio/app.js +251 -0
  679. package/dist/conformance/studio/app.js.map +1 -0
  680. package/dist/conformance/studio/contract.d.ts +1318 -0
  681. package/dist/conformance/studio/contract.d.ts.map +1 -0
  682. package/dist/conformance/studio/contract.js +280 -0
  683. package/dist/conformance/studio/contract.js.map +1 -0
  684. package/dist/conformance/studio/migrations/billing/0000_billing.sql +6 -0
  685. package/dist/conformance/studio/migrations/journal/0000_journal.sql +9 -0
  686. package/dist/conformance/studio/migrations/mailbox/0000_mailbox.sql +7 -0
  687. package/dist/conformance/studio/migrations/tasks/0000_tasks.sql +7 -0
  688. package/dist/conformance/workshop/app.d.ts +8 -0
  689. package/dist/conformance/workshop/app.d.ts.map +1 -0
  690. package/dist/conformance/workshop/app.js +13 -0
  691. package/dist/conformance/workshop/app.js.map +1 -0
  692. package/dist/conformance/workshop/migrations/0000_notes.sql +7 -0
  693. package/dist/conformance/workshop/module.d.ts +407 -0
  694. package/dist/conformance/workshop/module.d.ts.map +1 -0
  695. package/dist/conformance/workshop/module.js +71 -0
  696. package/dist/conformance/workshop/module.js.map +1 -0
  697. package/dist/fakes/AcmeFake.d.ts +46 -0
  698. package/dist/fakes/AcmeFake.d.ts.map +1 -0
  699. package/dist/fakes/AcmeFake.js +131 -0
  700. package/dist/fakes/AcmeFake.js.map +1 -0
  701. package/dist/fakes/ApnsFake.d.ts +79 -0
  702. package/dist/fakes/ApnsFake.d.ts.map +1 -0
  703. package/dist/fakes/ApnsFake.js +220 -0
  704. package/dist/fakes/ApnsFake.js.map +1 -0
  705. package/dist/fakes/FcmFake.d.ts +46 -0
  706. package/dist/fakes/FcmFake.d.ts.map +1 -0
  707. package/dist/fakes/FcmFake.js +185 -0
  708. package/dist/fakes/FcmFake.js.map +1 -0
  709. package/dist/fakes/GoogleFake.d.ts +221 -0
  710. package/dist/fakes/GoogleFake.d.ts.map +1 -0
  711. package/dist/fakes/GoogleFake.js +1035 -0
  712. package/dist/fakes/GoogleFake.js.map +1 -0
  713. package/dist/fakes/HttpApiFake.d.ts +22 -0
  714. package/dist/fakes/HttpApiFake.d.ts.map +1 -0
  715. package/dist/fakes/HttpApiFake.js +74 -0
  716. package/dist/fakes/HttpApiFake.js.map +1 -0
  717. package/dist/fakes/McpFake.d.ts +80 -0
  718. package/dist/fakes/McpFake.d.ts.map +1 -0
  719. package/dist/fakes/McpFake.js +312 -0
  720. package/dist/fakes/McpFake.js.map +1 -0
  721. package/dist/fakes/MicrosoftGraphFake.d.ts +254 -0
  722. package/dist/fakes/MicrosoftGraphFake.d.ts.map +1 -0
  723. package/dist/fakes/MicrosoftGraphFake.js +850 -0
  724. package/dist/fakes/MicrosoftGraphFake.js.map +1 -0
  725. package/dist/fakes/S3Fake.d.ts +29 -0
  726. package/dist/fakes/S3Fake.d.ts.map +1 -0
  727. package/dist/fakes/S3Fake.js +347 -0
  728. package/dist/fakes/S3Fake.js.map +1 -0
  729. package/dist/fakes/Server.d.ts +137 -0
  730. package/dist/fakes/Server.d.ts.map +1 -0
  731. package/dist/fakes/Server.js +357 -0
  732. package/dist/fakes/Server.js.map +1 -0
  733. package/dist/fakes/SignInProviderFake.d.ts +21 -0
  734. package/dist/fakes/SignInProviderFake.d.ts.map +1 -0
  735. package/dist/fakes/SignInProviderFake.js +56 -0
  736. package/dist/fakes/SignInProviderFake.js.map +1 -0
  737. package/dist/fakes/SlackFake.d.ts +136 -0
  738. package/dist/fakes/SlackFake.d.ts.map +1 -0
  739. package/dist/fakes/SlackFake.js +787 -0
  740. package/dist/fakes/SlackFake.js.map +1 -0
  741. package/dist/fakes/Store.d.ts +40 -0
  742. package/dist/fakes/Store.d.ts.map +1 -0
  743. package/dist/fakes/Store.js +82 -0
  744. package/dist/fakes/Store.js.map +1 -0
  745. package/dist/fakes/TelemetryFakes.d.ts +77 -0
  746. package/dist/fakes/TelemetryFakes.d.ts.map +1 -0
  747. package/dist/fakes/TelemetryFakes.js +121 -0
  748. package/dist/fakes/TelemetryFakes.js.map +1 -0
  749. package/dist/fakes/TestCa.d.ts +11 -0
  750. package/dist/fakes/TestCa.d.ts.map +1 -0
  751. package/dist/fakes/TestCa.js +115 -0
  752. package/dist/fakes/TestCa.js.map +1 -0
  753. package/dist/fakes/WorkOsFake.d.ts +40 -0
  754. package/dist/fakes/WorkOsFake.d.ts.map +1 -0
  755. package/dist/fakes/WorkOsFake.js +103 -0
  756. package/dist/fakes/WorkOsFake.js.map +1 -0
  757. package/dist/index.d.ts +10 -0
  758. package/dist/index.d.ts.map +1 -0
  759. package/dist/index.js +10 -0
  760. package/dist/index.js.map +1 -0
  761. package/dist/make/reference.d.ts +520 -0
  762. package/dist/make/reference.d.ts.map +1 -0
  763. package/dist/make/reference.js +182 -0
  764. package/dist/make/reference.js.map +1 -0
  765. package/dist/make/sources.d.ts +48 -0
  766. package/dist/make/sources.d.ts.map +1 -0
  767. package/dist/make/sources.js +806 -0
  768. package/dist/make/sources.js.map +1 -0
  769. package/package.json +77 -3
  770. package/src/Admin.ts +82 -0
  771. package/src/Agent.ts +289 -0
  772. package/src/AgentSurface.ts +51 -0
  773. package/src/Embedder.ts +69 -0
  774. package/src/EvalMain.ts +81 -0
  775. package/src/Evals.ts +490 -0
  776. package/src/Kernel.ts +228 -0
  777. package/src/Launch.ts +428 -0
  778. package/src/Locks.ts +123 -0
  779. package/src/Routes.ts +65 -0
  780. package/src/ScriptedChatModel.ts +189 -0
  781. package/src/SmtpSink.ts +205 -0
  782. package/src/System.ts +1075 -0
  783. package/src/TcpProxy.ts +102 -0
  784. package/src/auth/TrustedProxyAuth.ts +173 -0
  785. package/src/conformance/ActionConsent.ts +437 -0
  786. package/src/conformance/ActionRegistry.ts +174 -0
  787. package/src/conformance/Actor.ts +216 -0
  788. package/src/conformance/AgentReference.ts +171 -0
  789. package/src/conformance/AgentResources.ts +548 -0
  790. package/src/conformance/AgentRuntime.ts +388 -0
  791. package/src/conformance/AgentSubject.ts +103 -0
  792. package/src/conformance/Approvals.ts +363 -0
  793. package/src/conformance/Audit.ts +257 -0
  794. package/src/conformance/CalendarProvider.ts +156 -0
  795. package/src/conformance/CapabilityKit.ts +564 -0
  796. package/src/conformance/ClientSDK.ts +233 -0
  797. package/src/conformance/CollabDocument.ts +1203 -0
  798. package/src/conformance/CollabReference.ts +152 -0
  799. package/src/conformance/CollabSubject.ts +64 -0
  800. package/src/conformance/Command.ts +75 -0
  801. package/src/conformance/Connections.ts +357 -0
  802. package/src/conformance/ConnectionsReference.ts +172 -0
  803. package/src/conformance/ConnectorReference.ts +280 -0
  804. package/src/conformance/ContextAccounting.ts +169 -0
  805. package/src/conformance/Daemon.ts +936 -0
  806. package/src/conformance/DaemonReference.ts +189 -0
  807. package/src/conformance/DbTx.ts +253 -0
  808. package/src/conformance/DecisionTokens.ts +652 -0
  809. package/src/conformance/Delegation.ts +177 -0
  810. package/src/conformance/DeskReference.ts +73 -0
  811. package/src/conformance/DeviceControl.ts +700 -0
  812. package/src/conformance/Directory.ts +315 -0
  813. package/src/conformance/DirectoryProvider.ts +72 -0
  814. package/src/conformance/DocumentSource.ts +62 -0
  815. package/src/conformance/EndpointReference.ts +117 -0
  816. package/src/conformance/Files.ts +685 -0
  817. package/src/conformance/FilesReference.ts +154 -0
  818. package/src/conformance/FilesSubject.ts +50 -0
  819. package/src/conformance/Flags.ts +215 -0
  820. package/src/conformance/Host.ts +197 -0
  821. package/src/conformance/HttpApi.ts +169 -0
  822. package/src/conformance/InboxReference.ts +401 -0
  823. package/src/conformance/InboxSubject.ts +101 -0
  824. package/src/conformance/Ingestion.ts +425 -0
  825. package/src/conformance/Ingress.ts +498 -0
  826. package/src/conformance/Invocation.ts +780 -0
  827. package/src/conformance/IsolationMatrix.ts +215 -0
  828. package/src/conformance/LiveConnection.ts +197 -0
  829. package/src/conformance/LocalClient.ts +707 -0
  830. package/src/conformance/Locale.ts +141 -0
  831. package/src/conformance/MachineIdentity.ts +828 -0
  832. package/src/conformance/MailProvider.ts +217 -0
  833. package/src/conformance/Memory.ts +223 -0
  834. package/src/conformance/Messaging.ts +185 -0
  835. package/src/conformance/Metering.ts +293 -0
  836. package/src/conformance/ModelProvider.ts +139 -0
  837. package/src/conformance/ModuleManifest.ts +630 -0
  838. package/src/conformance/NotebookAgent.ts +41 -0
  839. package/src/conformance/NotificationChannel.ts +122 -0
  840. package/src/conformance/Notifications.ts +316 -0
  841. package/src/conformance/OAuthClient.ts +240 -0
  842. package/src/conformance/Outbox.ts +342 -0
  843. package/src/conformance/PlatformReference.ts +73 -0
  844. package/src/conformance/PlatformSubject.ts +50 -0
  845. package/src/conformance/Privacy.ts +577 -0
  846. package/src/conformance/Progress.ts +244 -0
  847. package/src/conformance/Push.ts +820 -0
  848. package/src/conformance/PushReference.ts +101 -0
  849. package/src/conformance/QuerySurface.ts +408 -0
  850. package/src/conformance/Readiness.ts +157 -0
  851. package/src/conformance/Reference.ts +326 -0
  852. package/src/conformance/Release.ts +690 -0
  853. package/src/conformance/ReleaseReference.ts +179 -0
  854. package/src/conformance/ResultRendering.ts +149 -0
  855. package/src/conformance/Sandbox.ts +313 -0
  856. package/src/conformance/SandboxReference.ts +52 -0
  857. package/src/conformance/Scheduler.ts +764 -0
  858. package/src/conformance/ScreenContext.ts +402 -0
  859. package/src/conformance/Search.ts +419 -0
  860. package/src/conformance/Secrets.ts +277 -0
  861. package/src/conformance/SecretsReference.ts +131 -0
  862. package/src/conformance/ServicesReference.ts +330 -0
  863. package/src/conformance/ServicesSubject.ts +105 -0
  864. package/src/conformance/Settings.ts +204 -0
  865. package/src/conformance/Sharing.ts +486 -0
  866. package/src/conformance/ShellSubject.ts +47 -0
  867. package/src/conformance/SignOutRace.ts +77 -0
  868. package/src/conformance/Slot.ts +84 -0
  869. package/src/conformance/Space.ts +432 -0
  870. package/src/conformance/StorageAdapter.ts +253 -0
  871. package/src/conformance/StorageBackend.ts +327 -0
  872. package/src/conformance/Subject.ts +208 -0
  873. package/src/conformance/Sync.ts +215 -0
  874. package/src/conformance/Telemetry.ts +287 -0
  875. package/src/conformance/ThemeTokens.ts +163 -0
  876. package/src/conformance/ToolSource.ts +632 -0
  877. package/src/conformance/Versioning.ts +199 -0
  878. package/src/conformance/View.ts +143 -0
  879. package/src/conformance/WorkItems.ts +186 -0
  880. package/src/conformance/Workflow.ts +304 -0
  881. package/src/conformance/acme/chatlog.ts +115 -0
  882. package/src/conformance/acme/connector.ts +151 -0
  883. package/src/conformance/acme/migrations/0000_messages.sql +8 -0
  884. package/src/conformance/archive/app.ts +33 -0
  885. package/src/conformance/archive/contract.ts +191 -0
  886. package/src/conformance/archive/memo.sync.gen.ts +25 -0
  887. package/src/conformance/archive/migrations/archive/0000_archive.sql +9 -0
  888. package/src/conformance/archive/migrations/memo/0000_memo.sql +6 -0
  889. package/src/conformance/archive/schema.ts +25 -0
  890. package/src/conformance/archive/server.ts +146 -0
  891. package/src/conformance/archive/sync.gen.ts +32 -0
  892. package/src/conformance/atlas/app.ts +16 -0
  893. package/src/conformance/atlas/contract.ts +118 -0
  894. package/src/conformance/crm/app.ts +107 -0
  895. package/src/conformance/crm/contract.ts +163 -0
  896. package/src/conformance/crm/migrations/crm/0000_crm.sql +18 -0
  897. package/src/conformance/crm/migrations/team/0000_team.sql +6 -0
  898. package/src/conformance/crm/schema.ts +28 -0
  899. package/src/conformance/crm/sync.gen.ts +27 -0
  900. package/src/conformance/desk/contract.ts +61 -0
  901. package/src/conformance/desk/migrations/0000_notes.sql +7 -0
  902. package/src/conformance/desk/server.ts +131 -0
  903. package/src/conformance/drafts/migrations/0000_drafts.sql +8 -0
  904. package/src/conformance/drafts/module.ts +211 -0
  905. package/src/conformance/fixture/app.ts +37 -0
  906. package/src/conformance/fixture/docs/bad-sync.ts +34 -0
  907. package/src/conformance/fixture/docs/contract.ts +297 -0
  908. package/src/conformance/fixture/docs/migrations/0000_docs.sql +9 -0
  909. package/src/conformance/fixture/docs/migrations/0001_seen.sql +12 -0
  910. package/src/conformance/fixture/docs/migrations/0002_attachment.sql +6 -0
  911. package/src/conformance/fixture/docs/policy.cedar +110 -0
  912. package/src/conformance/fixture/docs/schema.ts +41 -0
  913. package/src/conformance/fixture/docs/server.ts +292 -0
  914. package/src/conformance/fixture/docs/sync.gen.ts +54 -0
  915. package/src/conformance/fixture/docs/sync.ts +24 -0
  916. package/src/conformance/fixture/peer/migrations/0000_peer.sql +8 -0
  917. package/src/conformance/fixture/peer/module.ts +51 -0
  918. package/src/conformance/fixture/release/blocking/0000_item.sql +3 -0
  919. package/src/conformance/fixture/release/blocking/0001_wait.sql +2 -0
  920. package/src/conformance/fixture/release/blocking-renamed/0000_item.sql +3 -0
  921. package/src/conformance/fixture/release/blocking-renamed/0001_wait.sql +5 -0
  922. package/src/conformance/fixture/release/broken/0000_item.sql +3 -0
  923. package/src/conformance/fixture/release/broken/0001_extra.sql +3 -0
  924. package/src/conformance/fixture/release/broken/0002_label.sql +3 -0
  925. package/src/conformance/fixture/release/drift/escalate/0000_item.sql +5 -0
  926. package/src/conformance/fixture/release/drift/escalate/0001_escalate.sql +8 -0
  927. package/src/conformance/fixture/release/drift/v1/0000_item.sql +5 -0
  928. package/src/conformance/fixture/release/escape/0000_item.sql +3 -0
  929. package/src/conformance/fixture/release/escape/0001_escape.sql +5 -0
  930. package/src/conformance/fixture/release/misnamed/0000_item.sql +3 -0
  931. package/src/conformance/fixture/release/misnamed/0001_misname.sql +10 -0
  932. package/src/conformance/fixture/release/module.ts +119 -0
  933. package/src/conformance/fixture/release/outside/0000_item.sql +3 -0
  934. package/src/conformance/fixture/release/outside/0001_extra.sql +3 -0
  935. package/src/conformance/fixture/release/outside/0002_index.sql +4 -0
  936. package/src/conformance/fixture/release/outside/0003_later.sql +1 -0
  937. package/src/conformance/fixture/release/renamed/0000_item.sql +3 -0
  938. package/src/conformance/fixture/release/renamed/0001_misname.sql +10 -0
  939. package/src/conformance/fixture/release/renamed/0002_restore.sql +1 -0
  940. package/src/conformance/fixture/release/rogue/0000_item.sql +3 -0
  941. package/src/conformance/fixture/release/rogue/0001_extra.sql +3 -0
  942. package/src/conformance/fixture/release/rogue/0002_definer.sql +1 -0
  943. package/src/conformance/fixture/release/slow/0000_item.sql +5 -0
  944. package/src/conformance/fixture/release/undeclared/0000_item.sql +3 -0
  945. package/src/conformance/fixture/release/undeclared/0001_extra.sql +3 -0
  946. package/src/conformance/fixture/release/undeclared/0002_index.sql +1 -0
  947. package/src/conformance/fixture/release/v1/0000_item.sql +3 -0
  948. package/src/conformance/fixture/release/v2/0000_item.sql +3 -0
  949. package/src/conformance/fixture/release/v2/0001_extra.sql +3 -0
  950. package/src/conformance/fixture/release/v2/0002_label.sql +3 -0
  951. package/src/conformance/fixture/release/viewed-retyped/0000_item.sql +3 -0
  952. package/src/conformance/fixture/release/viewed-retyped/0001_retype.sql +1 -0
  953. package/src/conformance/kit-hash.ts +18 -0
  954. package/src/conformance/ledger/contract.ts +92 -0
  955. package/src/conformance/ledger/migrations/0000_entries.sql +8 -0
  956. package/src/conformance/ledger/server.ts +174 -0
  957. package/src/conformance/library/app.ts +38 -0
  958. package/src/conformance/library/contract.ts +66 -0
  959. package/src/conformance/library/migrations/0000_library.sql +14 -0
  960. package/src/conformance/library/schema.ts +27 -0
  961. package/src/conformance/library/server.ts +65 -0
  962. package/src/conformance/library/sync.gen.ts +47 -0
  963. package/src/conformance/locale/catalog.ts +111 -0
  964. package/src/conformance/notebook/app.ts +115 -0
  965. package/src/conformance/notebook/evals/pages.evals.json +94 -0
  966. package/src/conformance/notebook/migrations/0000_notebook.sql +10 -0
  967. package/src/conformance/notebook/module.ts +215 -0
  968. package/src/conformance/notebook/skills/meeting-notes.md +4 -0
  969. package/src/conformance/pad/app.ts +21 -0
  970. package/src/conformance/pad/contract.ts +69 -0
  971. package/src/conformance/pad/migrations/pad/0000_pad.sql +8 -0
  972. package/src/conformance/pad/migrations/pad/0001_live_copy.sql +2 -0
  973. package/src/conformance/pad/schema.ts +18 -0
  974. package/src/conformance/pad/server.ts +102 -0
  975. package/src/conformance/purchases/app.ts +34 -0
  976. package/src/conformance/purchases/contract.ts +161 -0
  977. package/src/conformance/purchases/migrations/0000_purchases.sql +17 -0
  978. package/src/conformance/purchases/server.ts +95 -0
  979. package/src/conformance/replica-search.mjs +22 -0
  980. package/src/conformance/studio/app.ts +298 -0
  981. package/src/conformance/studio/contract.ts +319 -0
  982. package/src/conformance/studio/migrations/billing/0000_billing.sql +6 -0
  983. package/src/conformance/studio/migrations/journal/0000_journal.sql +9 -0
  984. package/src/conformance/studio/migrations/mailbox/0000_mailbox.sql +7 -0
  985. package/src/conformance/studio/migrations/tasks/0000_tasks.sql +7 -0
  986. package/src/conformance/workshop/app.ts +14 -0
  987. package/src/conformance/workshop/migrations/0000_notes.sql +7 -0
  988. package/src/conformance/workshop/module.ts +79 -0
  989. package/src/fakes/AcmeFake.ts +182 -0
  990. package/src/fakes/ApnsFake.ts +245 -0
  991. package/src/fakes/FcmFake.ts +231 -0
  992. package/src/fakes/GoogleFake.ts +1346 -0
  993. package/src/fakes/HttpApiFake.ts +116 -0
  994. package/src/fakes/McpFake.ts +355 -0
  995. package/src/fakes/MicrosoftGraphFake.ts +1191 -0
  996. package/src/fakes/S3Fake.ts +376 -0
  997. package/src/fakes/Server.ts +445 -0
  998. package/src/fakes/SignInProviderFake.ts +70 -0
  999. package/src/fakes/SlackFake.ts +893 -0
  1000. package/src/fakes/Store.ts +96 -0
  1001. package/src/fakes/TelemetryFakes.ts +197 -0
  1002. package/src/fakes/TestCa.ts +166 -0
  1003. package/src/fakes/WorkOsFake.ts +136 -0
  1004. package/src/index.ts +9 -0
  1005. package/src/make/reference.ts +259 -0
  1006. package/src/make/sources.ts +836 -0
package/src/System.ts ADDED
@@ -0,0 +1,1075 @@
1
+ /**
2
+ * Starts a whole Eloxiv system for tests, benchmarks and `mise run dev`:
3
+ * a database (on the mise-managed PostgreSQL), the app's kernel server and
4
+ * zero-cache, each as a child process. Runs on Bun and Node.
5
+ */
6
+ import { spawn, spawnSync, type ChildProcess } from "node:child_process"
7
+ import { createHash, randomUUID } from "node:crypto"
8
+ import {
9
+ existsSync,
10
+ mkdirSync,
11
+ readdirSync,
12
+ readFileSync,
13
+ realpathSync,
14
+ rmSync,
15
+ statSync,
16
+ writeFileSync,
17
+ } from "node:fs"
18
+ import { createServer } from "node:net"
19
+ import { tmpdir } from "node:os"
20
+ import { basename, delimiter, join } from "node:path"
21
+ import { pathToFileURL } from "node:url"
22
+ import { launch, launchSignal, type Launch } from "./Launch.ts"
23
+
24
+ /**
25
+ * `@eloxiv/contracts`' `DEV_ZERO_API_KEY`, the key the test kernels (development) take from zero-cache. Written here,
26
+ * not imported: this file imports no workspace package by name, since the desktop lanes, the managed-PostgreSQL and
27
+ * live jobs load it by path without the source condition (or a build). `zero-cvr-erasure.test.ts` sends the contracts'
28
+ * constant to a zero-cache started here, so the two cannot drift apart unnoticed.
29
+ */
30
+ const DEV_ZERO_API_KEY = "eloxiv-dev-zero-api-key"
31
+
32
+ export { launch, launchSignal, reapLaunches, stopLaunches, type Launch } from "./Launch.ts"
33
+
34
+ /**
35
+ * How often (seconds) zero-cache, as the harness and `mise run dev` start it, re-validates each connection's
36
+ * credentials with the kernel: the bound on how long a signed-out session's replica keeps receiving rows
37
+ * (docs/contracts/sync.md). Deployments set `ZERO_AUTH_REVALIDATE_INTERVAL_SECONDS` to this or less.
38
+ */
39
+ export const ZERO_REVALIDATE_SECONDS = 10
40
+
41
+ export type Runtime = "bun" | "node"
42
+
43
+ /** The runtime under test: `ELOXIV_RUNTIME`, else the runtime running this code. */
44
+ export const defaultRuntime = (): Runtime =>
45
+ (process.env["ELOXIV_RUNTIME"] as Runtime | undefined) ?? ("Bun" in globalThis ? "bun" : "node")
46
+
47
+ export interface SystemOptions {
48
+ /** App root containing `server/main.ts` and `eloxiv.sync.ts`. */
49
+ readonly appDir: string
50
+ /** Database name; created by the app's `setup` command. */
51
+ readonly database: string
52
+ readonly kernelPort: number
53
+ readonly zeroPort: number
54
+ /** Runtime for the kernel server (default: bun). zero-cache always runs on Node. */
55
+ readonly runtime?: Runtime | undefined
56
+ /** Run `setup` and `seed` first (default: true). */
57
+ readonly prepare?: boolean | undefined
58
+ /**
59
+ * Prepare in the kernel's own process (`server/main.ts prepare-and-serve`) instead of a separate `prepare`
60
+ * process before it: one start-up instead of two. The app's entry must support the command.
61
+ */
62
+ readonly prepareInKernel?: boolean | undefined
63
+ /** Start zero-cache (default: true). */
64
+ readonly sync?: boolean | undefined
65
+ /** Keep zero-cache's SQLite replica between runs (default: start from a fresh replica). */
66
+ readonly keepReplica?: boolean | undefined
67
+ /** Extra environment for the kernel. */
68
+ readonly env?: Readonly<Record<string, string>> | undefined
69
+ /** Extra environment for zero-cache (`ZERO_MUTATE_URL` through a test's relay, say). */
70
+ readonly zeroEnv?: Readonly<Record<string, string>> | undefined
71
+ /** Repository root (for node_modules/.bin and .eloxiv). */
72
+ readonly root: string
73
+ readonly log?: ((line: string) => void) | undefined
74
+ /**
75
+ * Budget for the whole startup (prepare, kernel, zero-cache), in ms (default 80 s). Every step fails with its
76
+ * output before this, so a caller's own timeout (Vitest's hook timeout is 120 s) never fires first and hides it.
77
+ */
78
+ readonly startupTimeoutMs?: number | undefined
79
+ /** Abandons the startup when it aborts: what started is stopped and the startup fails. */
80
+ readonly signal?: AbortSignal | undefined
81
+ }
82
+
83
+ export interface RunningSystem {
84
+ readonly kernelUrl: string
85
+ readonly zeroUrl: string
86
+ readonly databaseUrl: string
87
+ readonly processes: ReadonlyArray<{ readonly name: string; readonly child: ChildProcess }>
88
+ /** What startup did and when (`+<ms> ms <step>`), for reports and benchmarks. */
89
+ readonly steps: ReadonlyArray<string>
90
+ readonly stop: () => Promise<void>
91
+ }
92
+
93
+ /** A port the operating system has free now (it hands the same few out again soon after: Linux prefers some). */
94
+ /**
95
+ * The operating system's ephemeral port range: where it picks the local port of every outgoing connection (each
96
+ * PostgreSQL client's, each fetch's), and where `listen(0)` picks too. Linux's from /proc; elsewhere the IANA range
97
+ * macOS and Windows use.
98
+ */
99
+ export const ephemeralPorts = (): { readonly low: number; readonly high: number } => {
100
+ try {
101
+ const [low, high] = readFileSync("/proc/sys/net/ipv4/ip_local_port_range", "utf8").trim().split(/\s+/).map(Number)
102
+ if (low !== undefined && high !== undefined && low > 0 && high >= low) return { low, high }
103
+ } catch {
104
+ // not Linux
105
+ }
106
+ return { low: 49152, high: 65535 }
107
+ }
108
+
109
+ /** Whether `port` can be listened on now, on every interface (zero-cache and the kernel listen on `::`). */
110
+ const canListen = (port: number, host: string) =>
111
+ new Promise<boolean>((resolve) => {
112
+ const server = createServer()
113
+ // In use (or not ours to take) is no; a host without IPv6 has nothing on `::` to collide with.
114
+ server.once("error", (error: NodeJS.ErrnoException) =>
115
+ resolve(error.code === "EAFNOSUPPORT" || error.code === "EADDRNOTAVAIL"),
116
+ )
117
+ server.listen({ port, host, exclusive: true }, () => server.close(() => resolve(true)))
118
+ })
119
+
120
+ /**
121
+ * A port nothing listens on, below the ephemeral range. A port in that range, free when handed out, can become an
122
+ * outgoing connection's local port before the child process listens on it (a test run makes thousands of
123
+ * PostgreSQL connections): zero-cache's change-streamer then failed with EADDRINUSE (Bun suite, 2026-11-10).
124
+ * Outgoing connections never take a port below the range.
125
+ */
126
+ const unusedPort = async (): Promise<number> => {
127
+ const { low } = ephemeralPorts()
128
+ const from = Math.max(1024, low - 12_000)
129
+ for (let attempt = 0; attempt < 200; attempt++) {
130
+ const port = from + Math.floor(Math.random() * (low - from))
131
+ // Both stacks: `::` (with IPv4 mapped) where IPv6 exists, and the IPv4 loopback in any case.
132
+ if ((await canListen(port, "127.0.0.1")) && (await canListen(port, "::"))) return port
133
+ }
134
+ throw new Error(`No port below the ephemeral range (${from} to ${low - 1}) is free`)
135
+ }
136
+
137
+ /**
138
+ * Where `freePort` reserves the ports it hands out, for every process on the machine: `ELOXIV_PORTS_DIR` (the
139
+ * Vitest global setup sets it to the machine's temporary directory, as it gives each run a `TMPDIR` of its own).
140
+ */
141
+ const reservationsDir = () => process.env["ELOXIV_PORTS_DIR"] ?? join(tmpdir(), "eloxiv-ports")
142
+ /** How long a port stays reserved: longer than any server takes to start listening on it. */
143
+ const RESERVED_MS = 180_000
144
+ let pruned = false
145
+
146
+ /**
147
+ * A free TCP port, so a server's URL (which Better Auth trusts as an origin) is known before it listens. The
148
+ * port is free when it is handed out but nothing holds it until the caller's server listens, which for a child
149
+ * process (zero-cache, a kernel) takes seconds; the operating system hands the same ports out again soon (300
150
+ * calls returned 3 to 8 repeats), so another test's server could take it first, and a readiness check then
151
+ * talked to that server. Each port handed out is therefore reserved, for every process on the machine (other
152
+ * Vitest workers, other suites), for `RESERVED_MS`.
153
+ */
154
+ export const freePort = async (): Promise<number> => {
155
+ const reservations = reservationsDir()
156
+ if (!pruned) {
157
+ // Once per process: reservations of windows no one looks at any more go (and files of an earlier layout, by
158
+ // age), so the directory does not grow with every run.
159
+ pruned = true
160
+ mkdirSync(reservations, { recursive: true })
161
+ const current = windowOf(Date.now())
162
+ for (const name of readdirSync(reservations)) {
163
+ try {
164
+ const window = /^\d+@(\d+)$/.exec(name)?.[1]
165
+ const lapsed =
166
+ window !== undefined
167
+ ? Number(window) < current - 2
168
+ : Date.now() - statSync(join(reservations, name)).mtimeMs > RESERVED_MS
169
+ if (lapsed) rmSync(join(reservations, name), { force: true })
170
+ } catch {
171
+ // another process pruned it
172
+ }
173
+ }
174
+ }
175
+ for (let attempt = 0; attempt < 1_000; attempt++) {
176
+ const port = await unusedPort()
177
+ if (reservePort(port)) return port
178
+ }
179
+ throw new Error("No free port could be reserved")
180
+ }
181
+
182
+ /** The window of `RESERVED_MS` that `time` falls in: a reservation is made in one, and holds through the next. */
183
+ const windowOf = (time: number) => Math.floor(time / RESERVED_MS)
184
+
185
+ /**
186
+ * Reserve `port` for this process, for every process on the machine; false when another holds it. A reservation
187
+ * is the file `<port>@<window>`, created exclusively, and holds its port against reservations made in the window
188
+ * before and after it, so for at least `RESERVED_MS`. No process ever removes another's reservation, so none can
189
+ * remove one that was just made (taking over a lapsed one by removing it and creating a fresh one let two processes
190
+ * hold one port). A process creates its own and only then looks at the neighbouring windows: of two that reserve
191
+ * the port in adjacent windows, the one that looks last sees the other and withdraws its own (both may withdraw;
192
+ * both never keep it). Old windows are pruned (`freePort`), which races with nothing: no one creates them or
193
+ * looks at them.
194
+ */
195
+ export const reservePort = (port: number): boolean => {
196
+ const reservations = reservationsDir()
197
+ mkdirSync(reservations, { recursive: true })
198
+ const window = windowOf(Date.now())
199
+ const mine = join(reservations, `${port}@${window}`)
200
+ try {
201
+ writeFileSync(mine, String(process.pid), { flag: "wx" })
202
+ } catch (error) {
203
+ if ((error as NodeJS.ErrnoException).code === "EEXIST") return false
204
+ throw error
205
+ }
206
+ if (
207
+ existsSync(join(reservations, `${port}@${window - 1}`)) ||
208
+ existsSync(join(reservations, `${port}@${window + 1}`))
209
+ ) {
210
+ rmSync(mine, { force: true })
211
+ return false
212
+ }
213
+ return true
214
+ }
215
+
216
+ const PG_PORT = process.env["PGPORT"] ?? "54329"
217
+ /**
218
+ * The local superuser's password, for a cluster that asks for one (an app's own server with `scram-sha-256`, as
219
+ * docs/getting-started.md starts it): libpq's `PGPASSWORD`, which psql reads itself and the kernel's driver does not.
220
+ */
221
+ const PG_PASSWORD = process.env["PGPASSWORD"]
222
+ /**
223
+ * The role setup runs as, and the cluster: by default the local cluster's superuser. `ELOXIV_TEST_ADMIN_URL` names
224
+ * another (its path is the admin database), for the managed-host runs: the local emulation of Neon's privilege
225
+ * model (`tools/scripts/neon-emulate.sh`, an ordinary role with Neon's grants) or a real Neon branch. Everything the
226
+ * tests start, setup and zero-cache included, then runs as that role, never as a superuser.
227
+ */
228
+ const ADMIN_URL = process.env["ELOXIV_TEST_ADMIN_URL"]
229
+ /** The test admin database URL for `database` (default: the admin URL's own database, `postgres` locally). */
230
+ export const adminUrl = (database?: string) => {
231
+ if (ADMIN_URL === undefined) {
232
+ const user =
233
+ PG_PASSWORD === undefined || PG_PASSWORD === "" ? "postgres" : `postgres:${encodeURIComponent(PG_PASSWORD)}`
234
+ return `postgres://${user}@localhost:${PG_PORT}/${database ?? "postgres"}`
235
+ }
236
+ const url = new URL(ADMIN_URL)
237
+ if (database !== undefined) url.pathname = `/${database}`
238
+ return url.toString()
239
+ }
240
+ /** Whether the tests run on a managed-host profile (`ELOXIV_TEST_ADMIN_URL`): no superuser anywhere. */
241
+ export const managedHostProfile = (): boolean => ADMIN_URL !== undefined
242
+ /**
243
+ * Whether the test host lets the setup role create event triggers: a superuser's cluster and Neon (`ELOXIV_TEST_HOST=
244
+ * neon`) do; the local emulation of Neon's privileges, on vanilla PostgreSQL, does not.
245
+ */
246
+ export const testHostHasEventTriggers = (): boolean =>
247
+ !managedHostProfile() || process.env["ELOXIV_TEST_HOST"] === "neon"
248
+ /**
249
+ * `ms` scaled by `ELOXIV_TEST_TIMEOUT_SCALE` (default 1): a run against a remote database (a real Neon branch from
250
+ * far away) takes many round trips longer than one against the local cluster.
251
+ */
252
+ export const slow = (ms: number): number => ms * Number(process.env["ELOXIV_TEST_TIMEOUT_SCALE"] ?? "1")
253
+ /** The role setup runs as in tests (the admin URL's user). */
254
+ export const adminRole = (): string => decodeURIComponent(new URL(adminUrl()).username)
255
+ export const kernelDatabaseUrl = (database: string) => {
256
+ if (ADMIN_URL === undefined) return `postgres://eloxiv_kernel:eloxiv_kernel@localhost:${PG_PORT}/${database}`
257
+ const url = new URL(ADMIN_URL)
258
+ url.username = "eloxiv_kernel"
259
+ url.password = process.env["ELOXIV_TEST_KERNEL_PASSWORD"] ?? "eloxiv_kernel"
260
+ url.pathname = `/${database}`
261
+ return url.toString()
262
+ }
263
+
264
+ export const runtimeCommand = (runtime: Runtime, script: string, args: ReadonlyArray<string> = []) =>
265
+ runtime === "bun"
266
+ ? { command: "bun", args: ["--conditions=@eloxiv/source", script, ...args] }
267
+ : { command: realNode(), args: ["--conditions=@eloxiv/source", script, ...args] }
268
+
269
+ /**
270
+ * The app id zero-cache runs with for `database` (`ZERO_APP_ID`), which names its schemas `<app id>` and
271
+ * `<app id>_<n>`: one per database, so tests sharing the cluster never share zero-cache's state, and prefixed, so it
272
+ * never names the kernel's schemas (`eloxiv`, `eloxiv_*`), Better Auth's or a module's. It was the database's name:
273
+ * the development database, `eloxiv`, then had zero-cache's `permissions` table in the kernel's schema, and every
274
+ * `mise run dev` after the first failed setup ("the kernel's schemas were changed outside setup").
275
+ *
276
+ * At most 47 characters, so every name zero-cache makes from it fits PostgreSQL's 63 bytes (its replication slots,
277
+ * `<app id>_0_<13 digits>`, are the longest; setup refuses longer, `zeroSchemaProblems`): a longer database name keeps
278
+ * its first 33 characters and adds 8 hexadecimal digits of its hash, so two names never share an app id by being cut.
279
+ */
280
+ export const zeroAppIdFor = (database: string) => {
281
+ const full = `zero_${database.replace(/[^a-z0-9_]/g, "_")}`
282
+ if (full.length <= 47) return full
283
+ return `${full.slice(0, 38)}_${createHash("sha256").update(database).digest("hex").slice(0, 8)}`
284
+ }
285
+
286
+ export const kernelEnv = (options: Pick<SystemOptions, "database" | "kernelPort" | "env">) => ({
287
+ ELOXIV_DATABASE_URL: kernelDatabaseUrl(options.database),
288
+ ELOXIV_ADMIN_DATABASE_URL: adminUrl(),
289
+ ELOXIV_PORT: String(options.kernelPort),
290
+ ELOXIV_BASE_URL: `http://localhost:${options.kernelPort}`,
291
+ // The app id zero-cache runs with (zeroCacheEnv): its shard schema is the one sync's push may write, and setup
292
+ // refuses a module that takes its schemas.
293
+ ELOXIV_ZERO_APP_ID: zeroAppIdFor(options.database),
294
+ // zero-cache's CVR database (zeroCvrDatabaseFor), where an erasure purges the person's client view records.
295
+ ...(() => {
296
+ const cvr = zeroCvrDatabaseFor(options.database)
297
+ return cvr === undefined ? {} : { ELOXIV_ZERO_CVR_URL: adminUrl(cvr) }
298
+ })(),
299
+ // Tests and benchmarks sign in far more often than a person: high limits (the limiter stays on). The dev
300
+ // server sets production's.
301
+ ELOXIV_AUTH_RATE_LIMIT_MAX: "1000000",
302
+ ELOXIV_SIGN_IN_LIMIT: "1000000",
303
+ ...options.env,
304
+ })
305
+
306
+ /**
307
+ * Signal a process started with `detached: true` and everything it started: on Unix it leads its own process
308
+ * group. Windows has neither process groups nor SIGTERM for console programs, so the tree is ended with
309
+ * `taskkill /T /F` whatever the signal. Never throws.
310
+ */
311
+ export const killTree = (pid: number, signal: "SIGTERM" | "SIGKILL") => {
312
+ try {
313
+ if (process.platform === "win32") spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" })
314
+ else process.kill(-pid, signal)
315
+ } catch {
316
+ // already gone
317
+ }
318
+ }
319
+
320
+ /** The most output `run` keeps: its last 8 MiB (the answers callers parse are far smaller). */
321
+ const RUN_OUTPUT_BYTES = 8 * 1024 * 1024
322
+
323
+ /**
324
+ * Run a command to completion; rejects with its output on a non-zero exit, or
325
+ * when it has not finished after `timeoutMs` (default 120 s) or `signal` aborts:
326
+ * the command and its children are killed and the rejection carries what it
327
+ * printed (its last 8 MiB). `owned`: it runs as a launch (Launch.ts), so its whole
328
+ * tree is also stopped when the test file ends or its parent dies; for commands
329
+ * that start a kernel (`prepareDatabase`), not for `psql`.
330
+ */
331
+ export const run = (
332
+ command: string,
333
+ args: ReadonlyArray<string>,
334
+ options: {
335
+ readonly cwd: string
336
+ readonly env?: Record<string, string>
337
+ readonly timeoutMs?: number
338
+ readonly signal?: AbortSignal | undefined
339
+ readonly owned?: boolean | undefined
340
+ },
341
+ ): Promise<string> =>
342
+ new Promise((resolve, reject) => {
343
+ const timeoutMs = options.timeoutMs ?? 120_000
344
+ const owned =
345
+ options.owned === true
346
+ ? launch(basename(command), command, args, {
347
+ cwd: options.cwd,
348
+ env: options.env ?? {},
349
+ signal: launchSignal(options.signal),
350
+ maxOutputBytes: RUN_OUTPUT_BYTES,
351
+ })
352
+ : undefined
353
+ // Its own process group, so a timeout can stop it and anything it started.
354
+ const child =
355
+ owned?.child ??
356
+ spawn(command, args, {
357
+ cwd: options.cwd,
358
+ env: { ...process.env, ...options.env },
359
+ detached: true,
360
+ windowsHide: true,
361
+ })
362
+ const chunks: Array<Buffer> = []
363
+ let bytes = 0
364
+ let dropped = 0
365
+ const keep = (data: Buffer) => {
366
+ chunks.push(data)
367
+ bytes += data.length
368
+ while (bytes > RUN_OUTPUT_BYTES && chunks.length > 1) {
369
+ const first = chunks.shift()!
370
+ bytes -= first.length
371
+ dropped += first.length
372
+ }
373
+ }
374
+ if (owned === undefined) {
375
+ child.stdout?.on("data", keep)
376
+ child.stderr?.on("data", keep)
377
+ }
378
+ const output = () =>
379
+ owned !== undefined
380
+ ? owned.output.text()
381
+ : (dropped > 0 ? `[${dropped} earlier bytes of output dropped]\n` : "") + Buffer.concat(chunks).toString()
382
+ const kill = () => {
383
+ if (owned !== undefined) void owned.stop().catch(() => {})
384
+ else if (child.pid !== undefined) killTree(child.pid, "SIGKILL")
385
+ }
386
+ const onAbort = () => {
387
+ kill()
388
+ reject(new Error(`${command} ${args.join(" ")} abandoned; its output:\n${output()}`))
389
+ }
390
+ if (options.signal?.aborted) onAbort()
391
+ options.signal?.addEventListener("abort", onAbort, { once: true })
392
+ const timer = setTimeout(() => {
393
+ kill()
394
+ reject(new Error(`${command} ${args.join(" ")} did not finish within ${timeoutMs} ms; its output:\n${output()}`))
395
+ }, timeoutMs)
396
+ const done = () => {
397
+ clearTimeout(timer)
398
+ options.signal?.removeEventListener("abort", onAbort)
399
+ }
400
+ child.on("error", (error) => {
401
+ done()
402
+ reject(error)
403
+ })
404
+ // Owned, its output is read to the end (`close`), and what it left is stopped and its record removed.
405
+ child.on(owned === undefined ? "exit" : "close", (code: number | null) => {
406
+ done()
407
+ if (owned !== undefined) void owned.stop().catch(() => {})
408
+ if (code === 0) resolve(output())
409
+ else reject(new Error(`${command} ${args.join(" ")} exited ${code}\n${output()}`))
410
+ })
411
+ })
412
+
413
+ /**
414
+ * Poll `check` until it resolves true or `timeoutMs` passes. A single check that
415
+ * does not settle (for example a request the server never answers) counts as
416
+ * not ready once the deadline passes, so this always returns or throws in time.
417
+ */
418
+ export const waitFor = async (what: string, check: () => Promise<boolean>, timeoutMs = 30_000, intervalMs = 100) => {
419
+ const deadline = Date.now() + timeoutMs
420
+ for (;;) {
421
+ let timer: ReturnType<typeof setTimeout> | undefined
422
+ const late = new Promise<boolean>((resolve) => {
423
+ timer = setTimeout(() => resolve(false), Math.max(0, deadline - Date.now()) + 50)
424
+ })
425
+ try {
426
+ if (await Promise.race([check(), late])) return
427
+ } catch {
428
+ // not ready yet
429
+ } finally {
430
+ clearTimeout(timer)
431
+ }
432
+ if (Date.now() > deadline) throw new Error(`Timed out after ${timeoutMs} ms waiting for ${what}`)
433
+ await new Promise((r) => setTimeout(r, intervalMs))
434
+ }
435
+ }
436
+
437
+ /**
438
+ * The real Node binary. `bun --bun` puts a `node` shim that is Bun itself first
439
+ * on PATH; zero-cache needs real Node (Bun cannot load its native SQLite binding).
440
+ */
441
+ export const realNode = (): string => {
442
+ for (const dir of (process.env["PATH"] ?? "").split(delimiter)) {
443
+ const candidate = join(dir, process.platform === "win32" ? "node.exe" : "node")
444
+ if (existsSync(candidate) && !basename(realpathSync(candidate)).startsWith("bun")) return candidate
445
+ }
446
+ throw new Error("Node.js not found on PATH (zero-cache requires Node)")
447
+ }
448
+
449
+ /**
450
+ * Ready when the URL answers 200 (a starting kernel answers 503; any other answer is not the kernel's `/health`,
451
+ * such as the 404 Bun's server gave before the kernel's handler was served). Each probe gives up after 2 s.
452
+ */
453
+ const httpOk = (url: string) => async () => {
454
+ const response = await fetch(url, { signal: AbortSignal.timeout(2_000) })
455
+ await response.body?.cancel()
456
+ return response.status === 200
457
+ }
458
+
459
+ /** zero-cache's own readiness answer at `/` (it sends "OK" only once ready): no other server passes for it. */
460
+ const zeroCacheReady = (url: string) => async () => {
461
+ const response = await fetch(url, { signal: AbortSignal.timeout(2_000) })
462
+ return response.status === 200 && (await response.text()) === "OK"
463
+ }
464
+
465
+ /**
466
+ * Wait until `child`'s server passes `check`, failing as soon as the child exits: a server that could not listen
467
+ * (its port taken) is reported with its output, not waited for, and never mistaken for whatever holds the port.
468
+ */
469
+ const waitForChild = async (what: string, child: ChildProcess, check: () => Promise<boolean>, timeoutMs: number) => {
470
+ const exited = () => child.exitCode !== null || child.signalCode !== null
471
+ await waitFor(what, async () => exited() || (await check()), timeoutMs)
472
+ if (exited())
473
+ throw new Error(`${what}: the process exited (${child.exitCode ?? child.signalCode}) before it was ready`)
474
+ }
475
+
476
+ /** A system's process: a launch, its output kept to the last 200 lines and 64 KiB (for a failed startup's report). */
477
+ const startProcess = (
478
+ name: string,
479
+ command: string,
480
+ args: ReadonlyArray<string>,
481
+ options: {
482
+ cwd: string
483
+ env: Record<string, string>
484
+ log?: ((line: string) => void) | undefined
485
+ signal: AbortSignal
486
+ about?: string
487
+ },
488
+ ) => launch(name, command, args, { ...options, maxOutputBytes: 64 * 1024, maxOutputLines: 200 })
489
+
490
+ /** A zero-cache launch's processes, noted in its output once it is ready (pids by role). */
491
+ const noteReady = (zero: Launch) => zero.note(`zero-cache ready: ${zero.members()}`)
492
+
493
+ /**
494
+ * The database zero-cache keeps its client view records (CVR) in, on the local cluster: `<database>_cvr`; on a
495
+ * managed host's profile, none (they stay in the app's database, as zero-cache's default).
496
+ *
497
+ * zero-cache creates its CVR tables at every start on a fresh database. In the app's database each of those
498
+ * statements fires zero-cache's own DDL event triggers, which compute the whole published schema: about 75 ms a
499
+ * statement for the example app, against 1 to 3 ms, and about 1.1 s of every cold start (zero-cache, not the
500
+ * kernel, is the critical path). Its change log stays in the app's database, where the kernel's erasure reaches it.
501
+ */
502
+ export const zeroCvrDatabaseFor = (database: string): string | undefined => {
503
+ if (managedHostProfile()) return undefined
504
+ const cvr = `${database}_cvr`
505
+ if (new TextEncoder().encode(cvr).length > 63) {
506
+ throw new Error(`Database name ${database} leaves no room for zero-cache's ${cvr} (PostgreSQL's 63 bytes)`)
507
+ }
508
+ return cvr
509
+ }
510
+
511
+ /** How the parent records its CVR database's token (a line of its comment), and how the CVR database is tagged. */
512
+ const CVR_TOKEN = "eloxiv zero-cache CVR token "
513
+ const cvrTag = (parent: string, token: string) => `eloxiv zero-cache CVR of ${parent}, token ${token}`
514
+
515
+ /**
516
+ * SQL answering whether `cvr` is the CVR database the harness made for `parent`: the parent records a token, and
517
+ * `cvr` carries the tag naming the parent and that token. Anything else (no such database, untagged, tagged for
518
+ * another parent or with another token, or a parent that recorded none) is not.
519
+ */
520
+ const isOurCvr = (parent: string, cvr: string) => `SELECT EXISTS (
521
+ SELECT 1 FROM pg_catalog.pg_database c, pg_catalog.pg_database p,
522
+ LATERAL (SELECT substring(pg_catalog.shobj_description(p.oid, 'pg_database')
523
+ FROM '${CVR_TOKEN}([0-9a-f-]+)') AS token) recorded
524
+ WHERE c.datname = '${cvr}' AND p.datname = '${parent}' AND recorded.token IS NOT NULL
525
+ AND position(format('eloxiv zero-cache CVR of %s, token %s', p.datname, recorded.token)
526
+ IN coalesce(pg_catalog.shobj_description(c.oid, 'pg_database'), '')) > 0)`
527
+
528
+ const psqlAnswer = async (root: string, statement: string) =>
529
+ (await run("psql", ["-X", "-At", adminUrl(), "-c", statement], { cwd: root, timeoutMs: 30_000 })).trim()
530
+
531
+ /**
532
+ * Make zero-cache's CVR database for `database` (on the local cluster), or use the one the harness made for it.
533
+ * Made, it is tagged with the parent's name and a random token (with the test run's tag, so the run drops it), and
534
+ * the token is recorded on the parent (a line of its comment). A database of that name the harness did not make for
535
+ * this parent is never used: this refuses, naming it. Never on a managed host's profile.
536
+ */
537
+ export const ensureZeroCvrDatabase = async (database: string, root: string) => {
538
+ const cvr = zeroCvrDatabaseFor(database)
539
+ if (cvr === undefined) return
540
+ if (!/^[a-z0-9_]+$/.test(database)) throw new Error(`Unsafe database name ${database}`)
541
+ const run_ = process.env["ELOXIV_DATABASE_COMMENT"]
542
+ const deadline = Date.now() + 5_000
543
+ for (;;) {
544
+ if ((await psqlAnswer(root, isOurCvr(database, cvr))) === "t") return
545
+ const exists =
546
+ (await psqlAnswer(root, `SELECT count(*) FROM pg_catalog.pg_database WHERE datname = '${cvr}'`)) !== "0"
547
+ if (exists) {
548
+ // Another start may be between making it and tagging it: wait a moment before refusing.
549
+ if (Date.now() < deadline) {
550
+ await new Promise((resolve) => setTimeout(resolve, 100))
551
+ continue
552
+ }
553
+ throw new Error(
554
+ `Not using ${cvr} for zero-cache's client view records of ${database}: a database of that name exists that ` +
555
+ `the harness did not make for ${database}. Rename or drop it yourself; nothing was changed.`,
556
+ )
557
+ }
558
+ const token = randomUUID()
559
+ const tag = `${run_ === undefined ? "" : `${run_}\n`}${cvrTag(database, token)}`
560
+ try {
561
+ await run("psql", ["-X", "-q", "-v", "ON_ERROR_STOP=1", adminUrl(), "-c", `CREATE DATABASE "${cvr}"`], {
562
+ cwd: root,
563
+ timeoutMs: 30_000,
564
+ })
565
+ } catch {
566
+ continue // made meanwhile by another start: look again
567
+ }
568
+ await run(
569
+ "psql",
570
+ [
571
+ "-X",
572
+ "-q",
573
+ "-v",
574
+ "ON_ERROR_STOP=1",
575
+ adminUrl(),
576
+ "-c",
577
+ `COMMENT ON DATABASE "${cvr}" IS '${tag.replaceAll("'", "''")}'`,
578
+ "-c",
579
+ // The parent's comment keeps what it said (the run's tag), with this token in place of any earlier one.
580
+ `DO $$ DECLARE kept text := regexp_replace(coalesce(pg_catalog.shobj_description(
581
+ (SELECT oid FROM pg_catalog.pg_database WHERE datname = '${database}'), 'pg_database'), ''),
582
+ '\\n?${CVR_TOKEN}[0-9a-f-]+', '', 'g');
583
+ BEGIN
584
+ EXECUTE format('COMMENT ON DATABASE %I IS %L', '${database}',
585
+ CASE WHEN kept = '' THEN '${CVR_TOKEN}${token}' ELSE kept || E'\\n${CVR_TOKEN}${token}' END);
586
+ END $$`,
587
+ ],
588
+ { cwd: root, timeoutMs: 30_000 },
589
+ )
590
+ }
591
+ }
592
+
593
+ /**
594
+ * zero-cache's settings for a database whose kernel is at `kernelUrl`: the ones every development and test
595
+ * system uses (see docs/scaffold.md, known gap 5).
596
+ */
597
+ export const zeroCacheEnv = (options: {
598
+ readonly database: string
599
+ readonly replicaDir: string
600
+ readonly kernelUrl: string
601
+ readonly port: number
602
+ /**
603
+ * The internal change-streamer's port (zero-cache's default is `port + 1`, which nothing reserves: with a
604
+ * free `port` picked by the operating system, another process can already hold the next one).
605
+ */
606
+ readonly changeStreamerPort?: number | undefined
607
+ }): Record<string, string> => ({
608
+ ...(options.changeStreamerPort === undefined
609
+ ? {}
610
+ : { ZERO_CHANGE_STREAMER_PORT: String(options.changeStreamerPort) }),
611
+ // In UTC: zero-cache reads its change stream as text, and drops the seconds of an offset (Baghdad's +02:57:36
612
+ // before 1918, Amsterdam's +00:19:32 before 1937), which a session in another zone prints for old instants.
613
+ ZERO_UPSTREAM_DB: (() => {
614
+ const url = new URL(adminUrl(options.database))
615
+ url.searchParams.set("TimeZone", "UTC")
616
+ return url.toString()
617
+ })(),
618
+ // Its client view records in their own database (`zeroCvrDatabaseFor`; `ensureZeroCvrDatabase` makes it).
619
+ ...(() => {
620
+ const cvr = zeroCvrDatabaseFor(options.database)
621
+ return cvr === undefined ? {} : { ZERO_CVR_DB: adminUrl(cvr) }
622
+ })(),
623
+ ZERO_REPLICA_FILE: join(options.replicaDir, "replica.db"),
624
+ // zero-cache's workers make temporary directories (`sync-worker-*`, `mutagen-*`) that a stopped or killed
625
+ // zero-cache leaves behind: keep them with its replica, which goes with the database (`dropDatabase`). Windows
626
+ // takes its temporary directory from TEMP and TMP (a Windows run of zero-handoff.test.ts left four behind).
627
+ TMPDIR: options.replicaDir,
628
+ TEMP: options.replicaDir,
629
+ TMP: options.replicaDir,
630
+ ZERO_QUERY_URL: `${options.kernelUrl}/zero/query`,
631
+ ZERO_MUTATE_URL: `${options.kernelUrl}/zero/mutate`,
632
+ // The key zero-cache sends with each push and query: the test kernels' (development) one, so pushes claim their
633
+ // groups and the kernel takes the group and user each call names as zero-cache's.
634
+ ZERO_MUTATE_API_KEY: DEV_ZERO_API_KEY,
635
+ ZERO_QUERY_API_KEY: DEV_ZERO_API_KEY,
636
+ ZERO_APP_PUBLICATIONS: "eloxiv_sync",
637
+ // The client names its organisation in this header; the kernel checks membership.
638
+ ZERO_QUERY_ALLOWED_CLIENT_HEADERS: "x-eloxiv-org",
639
+ // A push names its organisation and the client's version as action calls do (the kernel checks both).
640
+ ZERO_MUTATE_ALLOWED_CLIENT_HEADERS: "x-eloxiv-org,x-eloxiv-client-version",
641
+ // Writes reach the database only through actions (`/zero/mutate`): zero-cache's own CRUD writes, which it
642
+ // would run as its superuser under Zero's permissions instead of Eloxiv's policy, are refused outright.
643
+ ZERO_ENABLE_CRUD_MUTATIONS: "false",
644
+ ZERO_APP_ID: zeroAppIdFor(options.database),
645
+ ZERO_PORT: String(options.port),
646
+ ZERO_ADMIN_PASSWORD: "eloxiv-dev",
647
+ ZERO_LOG_LEVEL: process.env["ZERO_LOG_LEVEL"] ?? "warn",
648
+ // One view-syncer process is plenty for development and tests; the default is one per core.
649
+ ZERO_NUM_SYNC_WORKERS: process.env["ZERO_NUM_SYNC_WORKERS"] ?? "1",
650
+ // Readiness otherwise waits for a replication-lag report: every 10 s by default, and even at a
651
+ // short interval zero-cache adds up to ±1 s of jitter, which made cold start vary by ~1.5 s.
652
+ // A single local replica needs no lag gating, so development and tests turn reporting off (0).
653
+ ZERO_REPLICATION_LAG_REPORT_INTERVAL_MS: process.env["ZERO_REPLICATION_LAG_REPORT_INTERVAL_MS"] ?? "0",
654
+ // How often zero-cache asks the kernel whether a connected client's credentials are still valid: a session
655
+ // signed out or expired keeps its replica connected at most this long (Zero's default is 300 s; zero-cache gives
656
+ // the kernel no handle to close or re-validate one connection, so this interval is the bound). Directory
657
+ // changes do not wait for it: they are evaluated live (docs/contracts/sync.md, guarantee 6).
658
+ ZERO_AUTH_REVALIDATE_INTERVAL_SECONDS:
659
+ process.env["ZERO_AUTH_REVALIDATE_INTERVAL_SECONDS"] ?? String(ZERO_REVALIDATE_SECONDS),
660
+ ZERO_ENABLE_TELEMETRY: "false",
661
+ // zero-cache's cost-based planner can take seconds over the permission filters the kernel generates (each a
662
+ // tree of correlated EXISTS subqueries, one per policy reference and directory fact): one generated case of
663
+ // the sync property test (59 subqueries, six rows) took 13 s to plan before its replica hydrated. Without it,
664
+ // zero-cache runs the subqueries as written, and these filters read few rows (docs/scaffold.md, known gap 5).
665
+ ZERO_ENABLE_QUERY_PLANNER: process.env["ZERO_ENABLE_QUERY_PLANNER"] ?? "false",
666
+ // A V8 heap limit for zero-cache alone, which every worker it forks inherits (NODE_OPTIONS): a zero-cache that
667
+ // grew to 4.2 GB in a test run (docs/scaffold.md, "Process lifetime") fails at the limit instead.
668
+ ...zeroHeapOptions(),
669
+ })
670
+
671
+ /**
672
+ * zero-cache's V8 heap limit in MiB: `ELOXIV_ZERO_HEAP_MB`, default 512 (a test or development zero-cache stays far
673
+ * below it); 0 sets none. Limits each process's JavaScript heap, not native memory nor the whole tree.
674
+ */
675
+ export const zeroHeapMb = (): number => Number(process.env["ELOXIV_ZERO_HEAP_MB"] ?? "512")
676
+
677
+ const zeroHeapOptions = (): Record<string, string> => {
678
+ const mb = zeroHeapMb()
679
+ if (!(mb > 0)) return {}
680
+ const inherited = process.env["NODE_OPTIONS"]
681
+ return { NODE_OPTIONS: `${inherited === undefined ? "" : `${inherited} `}--max-old-space-size=${mb}` }
682
+ }
683
+
684
+ /**
685
+ * zero-cache alone, for a kernel the test runs itself (for example `startKernel` in process), on a fresh
686
+ * replica (or the one a previous zero-cache left, `keepReplica`). Resolves once it answers; `stop` ends it, `output` is what it printed.
687
+ */
688
+ export const startZeroCache = async (options: {
689
+ readonly root: string
690
+ readonly database: string
691
+ readonly kernelUrl: string
692
+ readonly port: number
693
+ /** Settings to add or replace (for example a shorter revalidation interval). */
694
+ readonly env?: Readonly<Record<string, string>>
695
+ /** Resume from the replica a previous zero-cache left for this database (default: start a fresh one). */
696
+ readonly keepReplica?: boolean
697
+ /**
698
+ * Run every zero-cache worker in one process (`SINGLE_PROCESS=1`, its runner called directly: the CLI exits at
699
+ * once in this mode). Only for the handoff test: every setup here runs zero-cache's CLI, as several processes.
700
+ */
701
+ readonly singleProcess?: boolean
702
+ /** Abandons the startup when it aborts (it also stops when the test file ends: `stopLaunches`). */
703
+ readonly signal?: AbortSignal | undefined
704
+ }) => {
705
+ const signal = launchSignal(options.signal)
706
+ const replicaDir = join(options.root, ".eloxiv", "zero", options.database)
707
+ if (options.keepReplica !== true) rmSync(replicaDir, { recursive: true, force: true })
708
+ mkdirSync(replicaDir, { recursive: true })
709
+ await ensureZeroCvrDatabase(options.database, options.root)
710
+ const changeStreamerPort = await freePort()
711
+ const zeroDir = realpathSync(join(options.root, "node_modules", "@rocicorp", "zero"))
712
+ const args =
713
+ options.singleProcess === true
714
+ ? [
715
+ "-e",
716
+ `import(${JSON.stringify(pathToFileURL(join(zeroDir, "out", "zero-cache", "src", "server", "runner", "run-worker.js")).href)}).then(({ runWorker }) => runWorker(null, process.env))`,
717
+ ]
718
+ : [zeroCacheEntry(options.root)]
719
+ const env = {
720
+ ...zeroCacheEnv({ ...options, replicaDir, changeStreamerPort }),
721
+ ...(options.singleProcess === true ? { SINGLE_PROCESS: "1" } : {}),
722
+ ...options.env,
723
+ }
724
+ // Its output kept to the last 1 MiB (zero-cache logs at warn: far less in any test).
725
+ const zero = launch("zero", realNode(), args, {
726
+ cwd: options.root,
727
+ env,
728
+ signal,
729
+ maxOutputBytes: 1024 * 1024,
730
+ about: zeroAbout(options.database, env),
731
+ })
732
+ try {
733
+ await waitForChild("zero-cache", zero.child, zeroCacheReady(`http://localhost:${options.port}/`), slow(60_000))
734
+ noteReady(zero)
735
+ } catch (error) {
736
+ await zero.stop().catch((stopError: Error) => zero.note(stopError.message))
737
+ throw new Error(`${(error as Error).message}\n${zero.output.text()}`, { cause: error })
738
+ }
739
+ return { url: `http://localhost:${options.port}`, stop: zero.stop, output: () => zero.output.text() }
740
+ }
741
+
742
+ /** A zero-cache launch, for its notes: its database, app id, heap limit and replica. */
743
+ const zeroAbout = (database: string, env: Record<string, string>) =>
744
+ `zero-cache for database ${database}, app id ${env["ZERO_APP_ID"]}, ` +
745
+ `heap limit ${/--max-old-space-size=(\d+)/.exec(env["NODE_OPTIONS"] ?? "")?.[1] ?? "none"} MiB, ` +
746
+ `replica ${env["ZERO_REPLICA_FILE"]}`
747
+
748
+ /** zero-cache's entry script, run directly with real Node. */
749
+ export const zeroCacheEntry = (root: string) =>
750
+ join(realpathSync(join(root, "node_modules", "@rocicorp", "zero")), "out", "zero", "src", "cli.js")
751
+
752
+ /** Prepare the database: roles, schemas, migrations, publication, demo data. Fails with its output after `timeoutMs`. */
753
+ export const prepareDatabase = async (
754
+ options: Pick<SystemOptions, "appDir" | "database" | "kernelPort" | "env" | "runtime">,
755
+ timeoutMs = 60_000,
756
+ signal?: AbortSignal,
757
+ ) => {
758
+ const env = kernelEnv(options)
759
+ const runtime = options.runtime ?? defaultRuntime()
760
+ const { command, args } = runtimeCommand(runtime, "server/main.ts", ["prepare"])
761
+ // Owned: the kernel it runs is stopped with the test file or a dead parent, like the system's own processes.
762
+ await run(command, args, { cwd: options.appDir, env, timeoutMs, signal, owned: true })
763
+ }
764
+
765
+ /** What PostgreSQL is doing: sessions (with their waits and blockers) and replication slots. For failure reports. */
766
+ export const postgresDiagnostics = async (root: string) => {
767
+ const queries = [
768
+ `SELECT pid, datname, usename, application_name, backend_type, state, wait_event_type, wait_event,
769
+ date_trunc('second', now() - xact_start) AS xact_age, pg_blocking_pids(pid) AS blocked_by, left(query, 160) AS query
770
+ FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND backend_type IN ('client backend', 'walsender')
771
+ ORDER BY xact_start NULLS LAST`,
772
+ `SELECT slot_name, database, active, active_pid FROM pg_replication_slots`,
773
+ ]
774
+ try {
775
+ return await run("psql", ["-X", adminUrl(), ...queries.flatMap((q) => ["-c", q])], { cwd: root, timeoutMs: 10_000 })
776
+ } catch (error) {
777
+ return `(PostgreSQL diagnostics unavailable: ${(error as Error).message})`
778
+ }
779
+ }
780
+
781
+ export const startSystem = async (options: SystemOptions): Promise<RunningSystem> => {
782
+ const runtime = options.runtime ?? defaultRuntime()
783
+ const env = kernelEnv(options)
784
+ const started = Date.now()
785
+ const deadline = started + (options.startupTimeoutMs ?? 80_000)
786
+ const remaining = (cap: number) => Math.max(1_000, Math.min(cap, deadline - Date.now()))
787
+ // What startup did and when, for the failure report.
788
+ const steps: Array<string> = []
789
+ const step = (what: string) => steps.push(`+${Date.now() - started} ms ${what}`)
790
+ const processes: Array<Launch> = []
791
+ const kernelUrl = `http://localhost:${options.kernelPort}`
792
+ const zeroUrl = `http://localhost:${options.zeroPort}`
793
+ // Every process is owned from the moment it starts: a startup abandoned (the signal, or the test file's end)
794
+ // stops what started, and launches nothing more.
795
+ const signal = launchSignal(options.signal)
796
+ const stop = async () => {
797
+ const failed = (await Promise.allSettled(processes.map((p) => p.stop()))).filter((r) => r.status === "rejected")
798
+ if (failed.length > 0)
799
+ throw new AggregateError(
800
+ failed.map((f) => f.reason),
801
+ "System processes survived their stop",
802
+ )
803
+ }
804
+ const abandoned = new Promise<never>((_, reject) => {
805
+ const onAbort = () => reject(new Error(`startup abandoned: ${(signal.reason as Error | undefined)?.message}`))
806
+ if (signal.aborted) onAbort()
807
+ else signal.addEventListener("abort", onAbort, { once: true })
808
+ })
809
+ abandoned.catch(() => {})
810
+ const startup = async () => {
811
+ // On a database that is already set up, zero-cache can start while `prepare` runs: it needs only the
812
+ // publication. On a fresh database it waits for `prepare` to create it. With `prepareInKernel`, the kernel
813
+ // process prepares the database itself before it serves (one start-up instead of two).
814
+ const inKernel = options.prepare !== false && options.prepareInKernel === true
815
+ step("prepare started")
816
+ // Before setup looks at the database: what an earlier zero-cache left under another app id refuses the start.
817
+ // On a kept replica (development, `mise run dev`), inactive replication slots are named, never dropped: a slot
818
+ // nobody reads holds back WAL without end (`eloxiv doctor` says how to drop one).
819
+ const [publication, inactive] = await Promise.all([
820
+ inspectDatabase(options.database, options.root),
821
+ options.keepReplica === true
822
+ ? inactiveSlots(options.database, options.root).catch(() => [] as ReadonlyArray<ReplicationSlot>)
823
+ : Promise.resolve([] as ReadonlyArray<ReplicationSlot>),
824
+ ])
825
+ if (inactive.length > 0)
826
+ options.log?.(
827
+ `Inactive replication slots (they hold back WAL until dropped; see eloxiv doctor): ${inactive
828
+ .map((slot) => `${slot.slotName} ${Math.round(slot.retainedBytes / 1024 / 1024)} MiB`)
829
+ .join(", ")}`,
830
+ )
831
+ const prepared =
832
+ options.prepare !== false && !inKernel
833
+ ? prepareDatabase(options, remaining(60_000), signal).then(() => void step("prepare finished"))
834
+ : Promise.resolve()
835
+ // Surface a failed prepare even while zero-cache starts (it is awaited below).
836
+ prepared.catch(() => {})
837
+ const zeroEarly = options.sync !== false && publication
838
+ step(`publication ${zeroEarly ? "exists: zero-cache starts now" : "missing: zero-cache waits for prepare"}`)
839
+ const changeStreamerPort = options.sync !== false ? await freePort() : undefined
840
+ // zero-cache's CVR database, made while the rest starts (it is new only on a database's first start).
841
+ // On a database that exists (zero-cache starts now), made while the rest starts; otherwise once prepare made it.
842
+ const cvrReady = zeroEarly ? ensureZeroCvrDatabase(options.database, options.root) : undefined
843
+ cvrReady?.catch(() => {})
844
+ const startZero = async () => {
845
+ await (cvrReady ?? ensureZeroCvrDatabase(options.database, options.root))
846
+ const zeroDir = join(options.root, ".eloxiv", "zero", options.database)
847
+ if (options.keepReplica !== true) rmSync(zeroDir, { recursive: true, force: true })
848
+ mkdirSync(zeroDir, { recursive: true })
849
+ step("zero-cache started")
850
+ const env = {
851
+ ...zeroCacheEnv({
852
+ database: options.database,
853
+ replicaDir: zeroDir,
854
+ kernelUrl,
855
+ port: options.zeroPort,
856
+ changeStreamerPort,
857
+ }),
858
+ ...options.zeroEnv,
859
+ }
860
+ processes.push(
861
+ startProcess("zero", realNode(), [zeroCacheEntry(options.root)], {
862
+ cwd: options.root,
863
+ log: options.log,
864
+ env,
865
+ signal,
866
+ about: zeroAbout(options.database, env),
867
+ }),
868
+ )
869
+ }
870
+ if (zeroEarly) await startZero()
871
+ await prepared
872
+ if (options.sync !== false && !zeroEarly && !inKernel) await startZero()
873
+ const { command, args } = runtimeCommand(runtime, "server/main.ts", inKernel ? ["prepare-and-serve"] : [])
874
+ step("kernel started")
875
+ const kernel = startProcess("kernel", command, args, {
876
+ cwd: options.appDir,
877
+ env,
878
+ log: options.log,
879
+ signal,
880
+ about: `kernel (${runtime}) for database ${options.database}`,
881
+ })
882
+ processes.push(kernel)
883
+ await waitForChild(
884
+ "kernel /health",
885
+ kernel.child,
886
+ httpOk(`${kernelUrl}/health`),
887
+ remaining(inKernel ? 90_000 : 30_000),
888
+ )
889
+ step("kernel ready")
890
+ if (options.sync !== false && !zeroEarly && inKernel) await startZero()
891
+ if (options.sync !== false) {
892
+ const zero = processes.find((p) => p.name === "zero")!
893
+ await waitForChild("zero-cache", zero.child, zeroCacheReady(`${zeroUrl}/`), remaining(60_000))
894
+ noteReady(zero)
895
+ step("zero-cache ready")
896
+ }
897
+ }
898
+ // Abandoned, the startup's own steps may still fail later: nothing awaits them then.
899
+ const pending = startup()
900
+ pending.catch(() => {})
901
+ try {
902
+ await Promise.race([pending, abandoned])
903
+ } catch (error) {
904
+ step(`failed: ${(error as Error).message.split("\n")[0]}`)
905
+ const report = [
906
+ `System startup failed for ${options.database} (${runtime}).`,
907
+ `Steps:\n${steps.join("\n")}`,
908
+ ...processes.map(
909
+ (p) =>
910
+ `[${p.name}] exit ${p.child.exitCode ?? p.child.signalCode ?? "still running"}; last output:\n${p.output.text()}`,
911
+ ),
912
+ ].join("\n\n")
913
+ // Stopped before the diagnostics (which can take seconds), so nothing outlives a failed startup.
914
+ await stop().catch((stopError: Error) => step(`stop failed: ${stopError.message}`))
915
+ const fullReport = `${report}\n\nPostgreSQL:\n${await postgresDiagnostics(options.root)}`
916
+ console.error(fullReport)
917
+ throw new Error(`${(error as Error).message}\n\n${fullReport}`, { cause: error })
918
+ }
919
+ return { kernelUrl, zeroUrl, databaseUrl: kernelDatabaseUrl(options.database), processes, steps, stop }
920
+ }
921
+
922
+ /**
923
+ * What a zero-cache that ran with the app id `app` left in the database, as one text (empty when nothing): its shard
924
+ * schemas (`<app>_0` and its CDC and CVR stores), its `permissions` table in `<app>`, its publications and its
925
+ * replication slots. Read only: nothing is ever removed (see `inspectDatabase`).
926
+ */
927
+ const leftoversOf = (app: string) => {
928
+ if (!/^[a-z0-9_]+$/.test(app)) throw new Error(`Unsafe app id ${app}`)
929
+ const like = (prefix: string) => `${prefix.replaceAll("_", "\\_")}%`
930
+ return `SELECT coalesce(string_agg(found, ', '), '') FROM (
931
+ SELECT format('schema %I', nspname) AS found FROM pg_catalog.pg_namespace
932
+ WHERE nspname IN ('${app}_0', '${app}_0/cdc', '${app}_0/cvr')
933
+ AND (to_regclass('"${app}_0"."shardConfig"') IS NOT NULL OR nspname <> '${app}_0')
934
+ UNION ALL
935
+ SELECT format('table %I.permissions', '${app}') WHERE to_regclass('"${app}".permissions') IS NOT NULL
936
+ UNION ALL
937
+ SELECT format('publication %I', pubname) FROM pg_catalog.pg_publication WHERE pubname LIKE '${like(`_${app}_`)}'
938
+ UNION ALL
939
+ SELECT format('replication slot %I', slot_name) FROM pg_catalog.pg_replication_slots
940
+ WHERE database = current_database() AND (slot_name = '${app}_0' OR slot_name LIKE '${like(`${app}_0_`)}')
941
+ ) AS left_behind`
942
+ }
943
+
944
+ /**
945
+ * Before a system starts on `database`: refuse to start when a zero-cache that ran under an app id the harness used
946
+ * to give it (the database's name, and `eloxiv`, under which zero-cache put its objects in the kernel's own schema)
947
+ * left its objects there, naming them; otherwise report whether the sync publication is in place. One `psql`, as it
948
+ * is on the cold start. False when the database does not exist.
949
+ *
950
+ * Nothing is removed, ever: three rounds of proving what zero-cache made (its owner, its tables' kinds, nothing
951
+ * outside depending on it) still let a same-owner table in its schema, and a cast outside it on its type, go with
952
+ * the drop. The developer removes them: `mise run db:reset` for the development database, or by hand.
953
+ */
954
+ export const inspectDatabase = async (database: string, root: string) => {
955
+ const former = database.replace(/[^a-z0-9_]/g, "_")
956
+ const apps = [...new Set(["eloxiv", former])].filter((app) => app !== zeroAppIdFor(database))
957
+ let out: string
958
+ try {
959
+ out = await run(
960
+ "psql",
961
+ [
962
+ "-X",
963
+ "-q",
964
+ "-At",
965
+ "-v",
966
+ "ON_ERROR_STOP=1",
967
+ adminUrl(database),
968
+ ...apps.flatMap((app) => ["-c", leftoversOf(app)]),
969
+ "-c",
970
+ "SELECT count(*) FROM pg_publication WHERE pubname = 'eloxiv_sync'",
971
+ ],
972
+ { cwd: root, timeoutMs: 10_000 },
973
+ )
974
+ } catch (error) {
975
+ const message = (error as Error).message
976
+ // A database not created yet: nothing left behind, and no publication.
977
+ if (message.includes(`database "${database}" does not exist`)) return false
978
+ const lines = message.split("\n").filter((line) => /^(psql:.*)?(ERROR|DETAIL|HINT|CONTEXT):\s+/.test(line))
979
+ throw new Error(`${database}: ${lines.join("\n").replace(/^.*?ERROR:\s+/, "") || message.slice(0, 2_000)}`, {
980
+ cause: error,
981
+ })
982
+ }
983
+ // One line per query, in order (a leftover query's empty answer is an empty line); psql ends with a newline.
984
+ const lines = out.split("\n")
985
+ if (lines.at(-1) === "") lines.pop()
986
+ const publications = lines.at(-1)?.trim()
987
+ const left = apps.map((app, i) => ({ app, found: (lines[i] ?? "").trim() })).filter((l) => l.found !== "")
988
+ if (left.length > 0) {
989
+ throw new Error(
990
+ `${database}: ${left.map((l) => `a zero-cache that ran under the app id ${l.app} left ${l.found}`).join("; ")}. ` +
991
+ `The harness does not remove these (it cannot prove they are only zero-cache's). Run \`mise run db:reset\` for ` +
992
+ `the development database (it deletes and recreates the local cluster), or drop them yourself. Nothing was removed.`,
993
+ )
994
+ }
995
+ return publications === "1"
996
+ }
997
+
998
+ /** A replication slot, as `pg_replication_slots` reports it, with the WAL it holds back. */
999
+ export interface ReplicationSlot {
1000
+ readonly slotName: string
1001
+ readonly database: string | null
1002
+ readonly slotType: string
1003
+ readonly plugin: string | null
1004
+ readonly active: boolean
1005
+ readonly retainedBytes: number
1006
+ }
1007
+
1008
+ /** `database`'s inactive replication slots, with the WAL each holds back (named at a development start). */
1009
+ export const inactiveSlots = async (database: string, root: string): Promise<ReadonlyArray<ReplicationSlot>> => {
1010
+ const answer = await run(
1011
+ "psql",
1012
+ [
1013
+ "-X",
1014
+ "-At",
1015
+ "-v",
1016
+ "ON_ERROR_STOP=1",
1017
+ adminUrl(database),
1018
+ "-c",
1019
+ `SELECT coalesce(json_agg(json_build_object('slotName', slot_name, 'database', database, 'slotType', slot_type,
1020
+ 'plugin', plugin, 'active', active,
1021
+ 'retainedBytes', coalesce(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn), 0))), '[]')
1022
+ FROM pg_catalog.pg_replication_slots WHERE database = current_database() AND NOT active`,
1023
+ ],
1024
+ { cwd: root, timeoutMs: 30_000 },
1025
+ )
1026
+ return JSON.parse(answer.trim()) as ReadonlyArray<ReplicationSlot>
1027
+ }
1028
+
1029
+ /** Drop a test database, including any replication slots zero-cache created for it. */
1030
+ export const dropDatabase = async (database: string, root: string) => {
1031
+ if (!/^[a-z0-9_]+$/.test(database)) throw new Error(`Unsafe database name ${database}`)
1032
+ // A replication client cut off can reconnect (a zero-cache's workers outlive the process `stop` waits for, for a
1033
+ // moment), and a terminated walsender releases its slot only as it exits; a slot still active fails the drop
1034
+ // ("used by an active logical replication slot"). So: no new connections, then terminate everything on the
1035
+ // database and wait until none of its slots is active, then drop the slots and the database.
1036
+ const statements = [
1037
+ // ALTER DATABASE, which the database's owner may run (no superuser on a managed host's profile). Not on an
1038
+ // invalid database (`datconnlimit` -2, PostgreSQL 16 on: a DROP DATABASE cut off part way, as psql's timeout
1039
+ // does under load), which takes no connections and refuses ALTER DATABASE with a FATAL error, so every later
1040
+ // drop failed and the database outlived the run; DROP DATABASE is the one thing it allows.
1041
+ `DO $$
1042
+ BEGIN
1043
+ IF EXISTS (SELECT 1 FROM pg_database WHERE datname = '${database}' AND datconnlimit <> -2) THEN
1044
+ ALTER DATABASE "${database}" WITH ALLOW_CONNECTIONS false;
1045
+ END IF;
1046
+ END $$`,
1047
+ `DO $$
1048
+ DECLARE
1049
+ deadline constant timestamptz := clock_timestamp() + interval '20 seconds';
1050
+ BEGIN
1051
+ LOOP
1052
+ PERFORM pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '${database}' AND pid <> pg_backend_pid();
1053
+ PERFORM pg_terminate_backend(active_pid) FROM pg_replication_slots WHERE database = '${database}' AND active;
1054
+ EXIT WHEN NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE database = '${database}' AND active)
1055
+ OR clock_timestamp() > deadline;
1056
+ PERFORM pg_sleep(0.05);
1057
+ END LOOP;
1058
+ END $$`,
1059
+ `SELECT pg_drop_replication_slot(slot_name) FROM pg_replication_slots WHERE database = '${database}' AND NOT active`,
1060
+ `DROP DATABASE IF EXISTS "${database}" WITH (FORCE)`,
1061
+ ]
1062
+ // zero-cache's CVR database goes with its parent only when the harness made it for this parent (`isOurCvr`).
1063
+ const cvr = zeroCvrDatabaseFor(database)
1064
+ const ownCvr = cvr !== undefined && (await psqlAnswer(root, isOurCvr(database, cvr)).catch(() => "f")) === "t"
1065
+ if (ownCvr) statements.push(`DROP DATABASE IF EXISTS "${cvr}" WITH (FORCE)`)
1066
+ try {
1067
+ await run("psql", ["-q", adminUrl(), ...statements.flatMap((s) => ["-c", s])], { cwd: root, timeoutMs: 30_000 })
1068
+ } catch (error) {
1069
+ throw new Error(
1070
+ `Dropping ${database} failed: ${(error as Error).message}\n\nPostgreSQL:\n${await postgresDiagnostics(root)}`,
1071
+ { cause: error },
1072
+ )
1073
+ }
1074
+ rmSync(join(root, ".eloxiv", "zero", database), { recursive: true, force: true })
1075
+ }