@cnc-tools/storm 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (513) hide show
  1. package/bin/node-version.js +24 -0
  2. package/bin/storm.js +16 -0
  3. package/dist/application.d.ts +13 -0
  4. package/dist/application.js +23 -0
  5. package/dist/bin/storm.d.ts +1 -0
  6. package/dist/bin/storm.js +45 -0
  7. package/dist/build-info.js +3 -0
  8. package/dist/closed-terminal.d.ts +7 -0
  9. package/dist/closed-terminal.js +18 -0
  10. package/dist/combine-errors.d.ts +11 -0
  11. package/dist/combine-errors.js +19 -0
  12. package/dist/commands/dashboard.d.ts +11 -0
  13. package/dist/commands/dashboard.js +18 -0
  14. package/dist/commands/run/cleanup.d.ts +135 -0
  15. package/dist/commands/run/cleanup.js +171 -0
  16. package/dist/commands/run/command.d.ts +327 -0
  17. package/dist/commands/run/command.js +620 -0
  18. package/dist/commands/run/job-summary.d.ts +6 -0
  19. package/dist/commands/run/job-summary.js +31 -0
  20. package/dist/commands/run/live-view.d.ts +22 -0
  21. package/dist/commands/run/live-view.js +395 -0
  22. package/dist/commands/run/metadata.d.ts +47 -0
  23. package/dist/commands/run/metadata.js +83 -0
  24. package/dist/commands/run/mint-failed.d.ts +11 -0
  25. package/dist/commands/run/mint-failed.js +33 -0
  26. package/dist/commands/run/outcomes.d.ts +307 -0
  27. package/dist/commands/run/outcomes.js +332 -0
  28. package/dist/commands/run/progress.d.ts +44 -0
  29. package/dist/commands/run/progress.js +277 -0
  30. package/dist/commands/run/redaction.d.ts +15 -0
  31. package/dist/commands/run/redaction.js +40 -0
  32. package/dist/commands/run/run-collector.d.ts +30 -0
  33. package/dist/commands/run/run-collector.js +73 -0
  34. package/dist/commands/run/run-record.d.ts +144 -0
  35. package/dist/commands/run/run-record.js +96 -0
  36. package/dist/commands/run/tests-summary.d.ts +34 -0
  37. package/dist/commands/run/tests-summary.js +141 -0
  38. package/dist/commands/run/text.d.ts +22 -0
  39. package/dist/commands/run/text.js +74 -0
  40. package/dist/commands/run/view.d.ts +35 -0
  41. package/dist/commands/run/view.js +163 -0
  42. package/dist/commands/run/waterfall.d.ts +25 -0
  43. package/dist/commands/run/waterfall.js +108 -0
  44. package/dist/commands/run/worker-chart.d.ts +79 -0
  45. package/dist/commands/run/worker-chart.js +313 -0
  46. package/dist/commands/runs/facts.d.ts +150 -0
  47. package/dist/commands/runs/facts.js +292 -0
  48. package/dist/commands/runs/list/command.d.ts +86 -0
  49. package/dist/commands/runs/list/command.js +36 -0
  50. package/dist/commands/runs/list/metadata.d.ts +22 -0
  51. package/dist/commands/runs/list/metadata.js +19 -0
  52. package/dist/commands/runs/list/outcomes.d.ts +74 -0
  53. package/dist/commands/runs/list/outcomes.js +89 -0
  54. package/dist/commands/runs/logs/command.d.ts +72 -0
  55. package/dist/commands/runs/logs/command.js +51 -0
  56. package/dist/commands/runs/logs/metadata.d.ts +22 -0
  57. package/dist/commands/runs/logs/metadata.js +22 -0
  58. package/dist/commands/runs/logs/outcomes.d.ts +55 -0
  59. package/dist/commands/runs/logs/outcomes.js +77 -0
  60. package/dist/commands/runs/metadata.d.ts +3 -0
  61. package/dist/commands/runs/metadata.js +3 -0
  62. package/dist/commands/runs/past-run.d.ts +72 -0
  63. package/dist/commands/runs/past-run.js +99 -0
  64. package/dist/commands/runs/show/command.d.ts +176 -0
  65. package/dist/commands/runs/show/command.js +76 -0
  66. package/dist/commands/runs/show/metadata.d.ts +25 -0
  67. package/dist/commands/runs/show/metadata.js +22 -0
  68. package/dist/commands/runs/show/outcomes.d.ts +164 -0
  69. package/dist/commands/runs/show/outcomes.js +317 -0
  70. package/dist/config/by-name.d.ts +24 -0
  71. package/dist/config/by-name.js +26 -0
  72. package/dist/config/errors.d.ts +58 -0
  73. package/dist/config/errors.js +101 -0
  74. package/dist/config/gateways.d.ts +32 -0
  75. package/dist/config/gateways.js +1 -0
  76. package/dist/config/index.d.ts +9 -0
  77. package/dist/config/index.js +12 -0
  78. package/dist/config/live/config-gateway.d.ts +6 -0
  79. package/dist/config/live/config-gateway.js +71 -0
  80. package/dist/config/load.d.ts +54 -0
  81. package/dist/config/load.js +175 -0
  82. package/dist/config/resolve.d.ts +49 -0
  83. package/dist/config/resolve.js +94 -0
  84. package/dist/config/resource-config.d.ts +132 -0
  85. package/dist/config/resource-config.js +19 -0
  86. package/dist/config/schema.d.ts +64 -0
  87. package/dist/config/schema.js +57 -0
  88. package/dist/config/set.d.ts +16 -0
  89. package/dist/config/set.js +55 -0
  90. package/dist/config/settings-file.d.ts +41 -0
  91. package/dist/config/settings-file.js +72 -0
  92. package/dist/config-file/define.d.ts +37 -0
  93. package/dist/config-file/define.js +9 -0
  94. package/dist/config-file/toolchain.d.ts +9 -0
  95. package/dist/config-file/toolchain.js +41 -0
  96. package/dist/context.d.ts +86 -0
  97. package/dist/context.js +43 -0
  98. package/dist/core/command-provider.d.ts +126 -0
  99. package/dist/core/command-provider.js +13 -0
  100. package/dist/core/command-slots.d.ts +67 -0
  101. package/dist/core/command-slots.js +136 -0
  102. package/dist/core/events.d.ts +128 -0
  103. package/dist/core/events.js +15 -0
  104. package/dist/core/gateways.d.ts +249 -0
  105. package/dist/core/gateways.js +1 -0
  106. package/dist/core/index.d.ts +20 -0
  107. package/dist/core/index.js +18 -0
  108. package/dist/core/keyed.d.ts +12 -0
  109. package/dist/core/keyed.js +24 -0
  110. package/dist/core/lane.d.ts +46 -0
  111. package/dist/core/lane.js +5 -0
  112. package/dist/core/limit.d.ts +9 -0
  113. package/dist/core/limit.js +29 -0
  114. package/dist/core/live/command-gateway.d.ts +11 -0
  115. package/dist/core/live/command-gateway.js +83 -0
  116. package/dist/core/live/job-summary-gateway.d.ts +5 -0
  117. package/dist/core/live/job-summary-gateway.js +20 -0
  118. package/dist/core/live/progress-terminal.d.ts +20 -0
  119. package/dist/core/live/progress-terminal.js +173 -0
  120. package/dist/core/live/run-directory-gateway.d.ts +24 -0
  121. package/dist/core/live/run-directory-gateway.js +437 -0
  122. package/dist/core/mint.d.ts +10 -0
  123. package/dist/core/mint.js +14 -0
  124. package/dist/core/payload.d.ts +26 -0
  125. package/dist/core/payload.js +33 -0
  126. package/dist/core/presentation.d.ts +87 -0
  127. package/dist/core/presentation.js +5 -0
  128. package/dist/core/presentations.d.ts +56 -0
  129. package/dist/core/presentations.js +66 -0
  130. package/dist/core/provider.d.ts +69 -0
  131. package/dist/core/provider.js +5 -0
  132. package/dist/core/resource.d.ts +262 -0
  133. package/dist/core/resource.js +6 -0
  134. package/dist/core/resources.d.ts +131 -0
  135. package/dist/core/resources.js +254 -0
  136. package/dist/core/run-directory.d.ts +69 -0
  137. package/dist/core/run-directory.js +94 -0
  138. package/dist/core/run-state.d.ts +152 -0
  139. package/dist/core/run-state.js +313 -0
  140. package/dist/core/run.d.ts +187 -0
  141. package/dist/core/run.js +321 -0
  142. package/dist/core/state-directory.d.ts +19 -0
  143. package/dist/core/state-directory.js +29 -0
  144. package/dist/core/timeline.d.ts +63 -0
  145. package/dist/core/timeline.js +97 -0
  146. package/dist/core/timing.d.ts +22 -0
  147. package/dist/core/timing.js +26 -0
  148. package/dist/credential/credential.d.ts +46 -0
  149. package/dist/credential/credential.js +80 -0
  150. package/dist/credential/diagnosis.d.ts +18 -0
  151. package/dist/credential/diagnosis.js +99 -0
  152. package/dist/credential/gateways.d.ts +109 -0
  153. package/dist/credential/gateways.js +1 -0
  154. package/dist/credential/index.d.ts +7 -0
  155. package/dist/credential/index.js +7 -0
  156. package/dist/credential/live/github-actions-token-gateway.d.ts +15 -0
  157. package/dist/credential/live/github-actions-token-gateway.js +43 -0
  158. package/dist/credential/live/github-actions-token-response.d.ts +19 -0
  159. package/dist/credential/live/github-actions-token-response.js +49 -0
  160. package/dist/credential/live/vercel-cli-gateway.d.ts +9 -0
  161. package/dist/credential/live/vercel-cli-gateway.js +64 -0
  162. package/dist/credential/live/vercel-output.d.ts +60 -0
  163. package/dist/credential/live/vercel-output.js +122 -0
  164. package/dist/credential/live/vercel-process.d.ts +14 -0
  165. package/dist/credential/live/vercel-process.js +3 -0
  166. package/dist/credential/settle.d.ts +31 -0
  167. package/dist/credential/settle.js +49 -0
  168. package/dist/credential/source.d.ts +110 -0
  169. package/dist/credential/source.js +114 -0
  170. package/dist/help-logo.d.ts +11 -0
  171. package/dist/help-logo.js +56 -0
  172. package/dist/presentation.d.ts +26 -0
  173. package/dist/presentation.js +21 -0
  174. package/dist/resources/github/cleanup.d.ts +23 -0
  175. package/dist/resources/github/cleanup.js +39 -0
  176. package/dist/resources/github/command.d.ts +74 -0
  177. package/dist/resources/github/command.js +117 -0
  178. package/dist/resources/github/config.d.ts +16 -0
  179. package/dist/resources/github/config.js +37 -0
  180. package/dist/resources/github/events.d.ts +26 -0
  181. package/dist/resources/github/events.js +2 -0
  182. package/dist/resources/github/fixture-repo.d.ts +69 -0
  183. package/dist/resources/github/fixture-repo.js +60 -0
  184. package/dist/resources/github/gateways.d.ts +62 -0
  185. package/dist/resources/github/gateways.js +1 -0
  186. package/dist/resources/github/index.d.ts +12 -0
  187. package/dist/resources/github/index.js +15 -0
  188. package/dist/resources/github/live/fixture-repo-gateway.d.ts +12 -0
  189. package/dist/resources/github/live/fixture-repo-gateway.js +92 -0
  190. package/dist/resources/github/live/gateways.d.ts +6 -0
  191. package/dist/resources/github/live/gateways.js +13 -0
  192. package/dist/resources/github/presentation.d.ts +13 -0
  193. package/dist/resources/github/presentation.js +43 -0
  194. package/dist/resources/github/provider.d.ts +66 -0
  195. package/dist/resources/github/provider.js +58 -0
  196. package/dist/resources/github/resource-provider.d.ts +6 -0
  197. package/dist/resources/github/resource-provider.js +20 -0
  198. package/dist/resources/github/resource.d.ts +33 -0
  199. package/dist/resources/github/resource.js +12 -0
  200. package/dist/resources/testserver/cleanup.d.ts +14 -0
  201. package/dist/resources/testserver/cleanup.js +22 -0
  202. package/dist/resources/testserver/command.d.ts +322 -0
  203. package/dist/resources/testserver/command.js +245 -0
  204. package/dist/resources/testserver/commands/app.d.ts +18 -0
  205. package/dist/resources/testserver/commands/app.js +3 -0
  206. package/dist/resources/testserver/commands/create/command.d.ts +136 -0
  207. package/dist/resources/testserver/commands/create/command.js +158 -0
  208. package/dist/resources/testserver/commands/create/metadata.d.ts +31 -0
  209. package/dist/resources/testserver/commands/create/metadata.js +45 -0
  210. package/dist/resources/testserver/commands/create/outcomes.d.ts +111 -0
  211. package/dist/resources/testserver/commands/create/outcomes.js +172 -0
  212. package/dist/resources/testserver/commands/list/command.d.ts +60 -0
  213. package/dist/resources/testserver/commands/list/command.js +56 -0
  214. package/dist/resources/testserver/commands/list/metadata.d.ts +9 -0
  215. package/dist/resources/testserver/commands/list/metadata.js +9 -0
  216. package/dist/resources/testserver/commands/list/outcomes.d.ts +54 -0
  217. package/dist/resources/testserver/commands/list/outcomes.js +152 -0
  218. package/dist/resources/testserver/config.d.ts +18 -0
  219. package/dist/resources/testserver/config.js +77 -0
  220. package/dist/resources/testserver/credential-facts.d.ts +80 -0
  221. package/dist/resources/testserver/credential-facts.js +83 -0
  222. package/dist/resources/testserver/events.d.ts +59 -0
  223. package/dist/resources/testserver/events.js +4 -0
  224. package/dist/resources/testserver/index.d.ts +16 -0
  225. package/dist/resources/testserver/index.js +24 -0
  226. package/dist/resources/testserver/lane.d.ts +28 -0
  227. package/dist/resources/testserver/lane.js +139 -0
  228. package/dist/resources/testserver/live/gateways.d.ts +6 -0
  229. package/dist/resources/testserver/live/gateways.js +26 -0
  230. package/dist/resources/testserver/options.d.ts +5 -0
  231. package/dist/resources/testserver/options.js +5 -0
  232. package/dist/resources/testserver/pool/channels.d.ts +80 -0
  233. package/dist/resources/testserver/pool/channels.js +48 -0
  234. package/dist/resources/testserver/pool/create.d.ts +48 -0
  235. package/dist/resources/testserver/pool/create.js +45 -0
  236. package/dist/resources/testserver/pool/directory.d.ts +4 -0
  237. package/dist/resources/testserver/pool/directory.js +5 -0
  238. package/dist/resources/testserver/pool/gateways.d.ts +190 -0
  239. package/dist/resources/testserver/pool/gateways.js +1 -0
  240. package/dist/resources/testserver/pool/host.d.ts +8 -0
  241. package/dist/resources/testserver/pool/host.js +21 -0
  242. package/dist/resources/testserver/pool/index.d.ts +9 -0
  243. package/dist/resources/testserver/pool/index.js +10 -0
  244. package/dist/resources/testserver/pool/inspect.d.ts +53 -0
  245. package/dist/resources/testserver/pool/inspect.js +45 -0
  246. package/dist/resources/testserver/pool/lease.d.ts +84 -0
  247. package/dist/resources/testserver/pool/lease.js +125 -0
  248. package/dist/resources/testserver/pool/live/pool-records.d.ts +17 -0
  249. package/dist/resources/testserver/pool/live/pool-records.js +70 -0
  250. package/dist/resources/testserver/pool/live/pool-store-gateway.d.ts +12 -0
  251. package/dist/resources/testserver/pool/live/pool-store-gateway.js +435 -0
  252. package/dist/resources/testserver/pool/staleness.d.ts +16 -0
  253. package/dist/resources/testserver/pool/staleness.js +27 -0
  254. package/dist/resources/testserver/presentation.d.ts +9 -0
  255. package/dist/resources/testserver/presentation.js +217 -0
  256. package/dist/resources/testserver/provider.d.ts +177 -0
  257. package/dist/resources/testserver/provider.js +254 -0
  258. package/dist/resources/testserver/ran.d.ts +87 -0
  259. package/dist/resources/testserver/ran.js +140 -0
  260. package/dist/resources/testserver/resource-provider.d.ts +12 -0
  261. package/dist/resources/testserver/resource-provider.js +38 -0
  262. package/dist/resources/testserver/resource.d.ts +32 -0
  263. package/dist/resources/testserver/resource.js +10 -0
  264. package/dist/resources/testserver/run-sandbox.d.ts +13 -0
  265. package/dist/resources/testserver/run-sandbox.js +6 -0
  266. package/dist/resources/testserver/sandbox/channels.d.ts +12 -0
  267. package/dist/resources/testserver/sandbox/channels.js +21 -0
  268. package/dist/resources/testserver/sandbox/create-failure.d.ts +35 -0
  269. package/dist/resources/testserver/sandbox/create-failure.js +65 -0
  270. package/dist/resources/testserver/sandbox/create.d.ts +29 -0
  271. package/dist/resources/testserver/sandbox/create.js +37 -0
  272. package/dist/resources/testserver/sandbox/gateways.d.ts +150 -0
  273. package/dist/resources/testserver/sandbox/gateways.js +1 -0
  274. package/dist/resources/testserver/sandbox/index.d.ts +6 -0
  275. package/dist/resources/testserver/sandbox/index.js +7 -0
  276. package/dist/resources/testserver/sandbox/live/builds-response.d.ts +9 -0
  277. package/dist/resources/testserver/sandbox/live/builds-response.js +27 -0
  278. package/dist/resources/testserver/sandbox/live/control-plane-gateway.d.ts +17 -0
  279. package/dist/resources/testserver/sandbox/live/control-plane-gateway.js +133 -0
  280. package/dist/resources/testserver/sandbox/live/create-response.d.ts +35 -0
  281. package/dist/resources/testserver/sandbox/live/create-response.js +78 -0
  282. package/dist/resources/testserver/sandbox/live/fetch-failure.d.ts +24 -0
  283. package/dist/resources/testserver/sandbox/live/fetch-failure.js +45 -0
  284. package/dist/resources/testserver/sandbox/live/health-check-gateway.d.ts +11 -0
  285. package/dist/resources/testserver/sandbox/live/health-check-gateway.js +36 -0
  286. package/dist/resources/testserver/sandbox/live/sse.d.ts +12 -0
  287. package/dist/resources/testserver/sandbox/live/sse.js +32 -0
  288. package/dist/resources.d.ts +452 -0
  289. package/dist/resources.js +88 -0
  290. package/dist/runner/base.d.ts +40 -0
  291. package/dist/runner/base.js +52 -0
  292. package/dist/runner/context.d.ts +13 -0
  293. package/dist/runner/context.js +9 -0
  294. package/dist/runner/events.d.ts +179 -0
  295. package/dist/runner/events.js +16 -0
  296. package/dist/runner/gateways.d.ts +351 -0
  297. package/dist/runner/gateways.js +3 -0
  298. package/dist/runner/index.d.ts +19 -0
  299. package/dist/runner/index.js +18 -0
  300. package/dist/runner/live/checkout-gateway.d.ts +3 -0
  301. package/dist/runner/live/checkout-gateway.js +206 -0
  302. package/dist/runner/live/git-output.d.ts +14 -0
  303. package/dist/runner/live/git-output.js +32 -0
  304. package/dist/runner/live/sandbox-errors.d.ts +7 -0
  305. package/dist/runner/live/sandbox-errors.js +21 -0
  306. package/dist/runner/live/sandbox-gateway.d.ts +7 -0
  307. package/dist/runner/live/sandbox-gateway.js +427 -0
  308. package/dist/runner/live/snapshot-cache-gateway.d.ts +12 -0
  309. package/dist/runner/live/snapshot-cache-gateway.js +104 -0
  310. package/dist/runner/live/snapshot-records.d.ts +11 -0
  311. package/dist/runner/live/snapshot-records.js +57 -0
  312. package/dist/runner/live/terminal.d.ts +16 -0
  313. package/dist/runner/live/terminal.js +37 -0
  314. package/dist/runner/live/user.d.ts +2 -0
  315. package/dist/runner/live/user.js +11 -0
  316. package/dist/runner/output.d.ts +23 -0
  317. package/dist/runner/output.js +58 -0
  318. package/dist/runner/prepare.d.ts +67 -0
  319. package/dist/runner/prepare.js +59 -0
  320. package/dist/runner/ready.d.ts +68 -0
  321. package/dist/runner/ready.js +159 -0
  322. package/dist/runner/recipe.d.ts +126 -0
  323. package/dist/runner/recipe.js +302 -0
  324. package/dist/runner/remote-command.d.ts +77 -0
  325. package/dist/runner/remote-command.js +127 -0
  326. package/dist/runner/scope.d.ts +58 -0
  327. package/dist/runner/scope.js +117 -0
  328. package/dist/runner/snapshot-build.d.ts +33 -0
  329. package/dist/runner/snapshot-build.js +112 -0
  330. package/dist/runner/snapshot-cache.d.ts +84 -0
  331. package/dist/runner/snapshot-cache.js +126 -0
  332. package/dist/runner/snapshot-key.d.ts +52 -0
  333. package/dist/runner/snapshot-key.js +91 -0
  334. package/dist/runner/steps.d.ts +41 -0
  335. package/dist/runner/steps.js +49 -0
  336. package/dist/sdk/container/api-request.d.ts +32 -0
  337. package/dist/sdk/container/api-request.js +46 -0
  338. package/dist/sdk/container/container.d.ts +144 -0
  339. package/dist/sdk/container/container.js +346 -0
  340. package/dist/sdk/container/feature-flags.d.ts +37 -0
  341. package/dist/sdk/container/feature-flags.js +118 -0
  342. package/dist/sdk/container/gateways.d.ts +108 -0
  343. package/dist/sdk/container/gateways.js +1 -0
  344. package/dist/sdk/container/index.d.ts +5 -0
  345. package/dist/sdk/container/index.js +5 -0
  346. package/dist/sdk/container/live/container-gateway.d.ts +17 -0
  347. package/dist/sdk/container/live/container-gateway.js +114 -0
  348. package/dist/sdk/factories/build.d.ts +66 -0
  349. package/dist/sdk/factories/build.js +98 -0
  350. package/dist/sdk/factories/definition.d.ts +28 -0
  351. package/dist/sdk/factories/definition.js +16 -0
  352. package/dist/sdk/factories/definitions.d.ts +166 -0
  353. package/dist/sdk/factories/definitions.js +235 -0
  354. package/dist/sdk/factories/gateways.d.ts +25 -0
  355. package/dist/sdk/factories/gateways.js +1 -0
  356. package/dist/sdk/factories/index.d.ts +5 -0
  357. package/dist/sdk/factories/index.js +5 -0
  358. package/dist/sdk/factories/live/factory-gateway.d.ts +10 -0
  359. package/dist/sdk/factories/live/factory-gateway.js +29 -0
  360. package/dist/sdk/index.d.ts +7 -0
  361. package/dist/sdk/index.js +15 -0
  362. package/dist/sdk/payload/index.d.ts +2 -0
  363. package/dist/sdk/payload/index.js +4 -0
  364. package/dist/sdk/payload/payload.d.ts +47 -0
  365. package/dist/sdk/payload/payload.js +74 -0
  366. package/dist/sdk/payload/test-events.d.ts +102 -0
  367. package/dist/sdk/payload/test-events.js +59 -0
  368. package/dist/sdk/proxy/exchange.d.ts +58 -0
  369. package/dist/sdk/proxy/exchange.js +173 -0
  370. package/dist/sdk/proxy/faulted-exchange.d.ts +10 -0
  371. package/dist/sdk/proxy/faulted-exchange.js +106 -0
  372. package/dist/sdk/proxy/faults.d.ts +133 -0
  373. package/dist/sdk/proxy/faults.js +147 -0
  374. package/dist/sdk/proxy/index.d.ts +3 -0
  375. package/dist/sdk/proxy/index.js +3 -0
  376. package/dist/sdk/proxy/proxy.d.ts +93 -0
  377. package/dist/sdk/proxy/proxy.js +99 -0
  378. package/dist/sdk/proxy/records.d.ts +56 -0
  379. package/dist/sdk/proxy/records.js +56 -0
  380. package/dist/sdk/records/body.d.ts +89 -0
  381. package/dist/sdk/records/body.js +236 -0
  382. package/dist/sdk/records/index.d.ts +2 -0
  383. package/dist/sdk/records/index.js +4 -0
  384. package/dist/sdk/records/records.d.ts +49 -0
  385. package/dist/sdk/records/records.js +16 -0
  386. package/dist/sdk/seed/index.d.ts +1 -0
  387. package/dist/sdk/seed/index.js +3 -0
  388. package/dist/sdk/seed/seed.d.ts +221 -0
  389. package/dist/sdk/seed/seed.js +171 -0
  390. package/dist/sdk/testserver/clock.d.ts +8 -0
  391. package/dist/sdk/testserver/clock.js +10 -0
  392. package/dist/sdk/testserver/failure.d.ts +73 -0
  393. package/dist/sdk/testserver/failure.js +61 -0
  394. package/dist/sdk/testserver/index.d.ts +5 -0
  395. package/dist/sdk/testserver/index.js +8 -0
  396. package/dist/sdk/testserver/live/connect-failure.d.ts +7 -0
  397. package/dist/sdk/testserver/live/connect-failure.js +30 -0
  398. package/dist/sdk/testserver/live/request.d.ts +69 -0
  399. package/dist/sdk/testserver/live/request.js +89 -0
  400. package/dist/sdk/testserver/service-ids.d.ts +19 -0
  401. package/dist/sdk/testserver/service-ids.js +77 -0
  402. package/dist/sdk/testserver/test-id.d.ts +15 -0
  403. package/dist/sdk/testserver/test-id.js +28 -0
  404. package/dist/story/align.d.ts +37 -0
  405. package/dist/story/align.js +39 -0
  406. package/dist/story/artifact.d.ts +60 -0
  407. package/dist/story/artifact.js +93 -0
  408. package/dist/story/definition.d.ts +52 -0
  409. package/dist/story/definition.js +9 -0
  410. package/dist/story/diff.d.ts +9 -0
  411. package/dist/story/diff.js +97 -0
  412. package/dist/story/errors.d.ts +14 -0
  413. package/dist/story/errors.js +21 -0
  414. package/dist/story/gateways.d.ts +74 -0
  415. package/dist/story/gateways.js +3 -0
  416. package/dist/story/host.d.ts +27 -0
  417. package/dist/story/host.js +97 -0
  418. package/dist/story/index.d.ts +7 -0
  419. package/dist/story/index.js +9 -0
  420. package/dist/story/json.d.ts +16 -0
  421. package/dist/story/json.js +59 -0
  422. package/dist/story/live/artifact-gateway.d.ts +2 -0
  423. package/dist/story/live/artifact-gateway.js +82 -0
  424. package/dist/story/mode.d.ts +17 -0
  425. package/dist/story/mode.js +21 -0
  426. package/dist/story/orphans.d.ts +17 -0
  427. package/dist/story/orphans.js +15 -0
  428. package/dist/story/report.d.ts +30 -0
  429. package/dist/story/report.js +118 -0
  430. package/dist/story/run.d.ts +49 -0
  431. package/dist/story/run.js +160 -0
  432. package/dist/story/sequence.d.ts +30 -0
  433. package/dist/story/sequence.js +74 -0
  434. package/dist/story/settle.d.ts +94 -0
  435. package/dist/story/settle.js +70 -0
  436. package/dist/time/duration.d.ts +19 -0
  437. package/dist/time/duration.js +37 -0
  438. package/dist/time/index.d.ts +2 -0
  439. package/dist/time/index.js +4 -0
  440. package/dist/time/time.d.ts +15 -0
  441. package/dist/time/time.js +23 -0
  442. package/dist/vercel-cli/ansi.d.ts +13 -0
  443. package/dist/vercel-cli/ansi.js +32 -0
  444. package/dist/vercel-cli/arguments.d.ts +25 -0
  445. package/dist/vercel-cli/arguments.js +78 -0
  446. package/dist/vercel-cli/auth-config.d.ts +43 -0
  447. package/dist/vercel-cli/auth-config.js +36 -0
  448. package/dist/vercel-cli/clock.d.ts +9 -0
  449. package/dist/vercel-cli/clock.js +10 -0
  450. package/dist/vercel-cli/config-files.d.ts +24 -0
  451. package/dist/vercel-cli/config-files.js +40 -0
  452. package/dist/vercel-cli/context.d.ts +12 -0
  453. package/dist/vercel-cli/context.js +12 -0
  454. package/dist/vercel-cli/driver.d.ts +218 -0
  455. package/dist/vercel-cli/driver.js +364 -0
  456. package/dist/vercel-cli/entry.d.ts +8 -0
  457. package/dist/vercel-cli/entry.js +13 -0
  458. package/dist/vercel-cli/environment.d.ts +33 -0
  459. package/dist/vercel-cli/environment.js +72 -0
  460. package/dist/vercel-cli/errors.d.ts +8 -0
  461. package/dist/vercel-cli/errors.js +8 -0
  462. package/dist/vercel-cli/gateways.d.ts +103 -0
  463. package/dist/vercel-cli/gateways.js +4 -0
  464. package/dist/vercel-cli/index.d.ts +10 -0
  465. package/dist/vercel-cli/index.js +15 -0
  466. package/dist/vercel-cli/invocation.d.ts +234 -0
  467. package/dist/vercel-cli/invocation.js +397 -0
  468. package/dist/vercel-cli/keys.d.ts +14 -0
  469. package/dist/vercel-cli/keys.js +12 -0
  470. package/dist/vercel-cli/live/config-files.d.ts +28 -0
  471. package/dist/vercel-cli/live/config-files.js +66 -0
  472. package/dist/vercel-cli/live/process-gateway.d.ts +14 -0
  473. package/dist/vercel-cli/live/process-gateway.js +178 -0
  474. package/dist/vercel-cli/redaction.d.ts +13 -0
  475. package/dist/vercel-cli/redaction.js +22 -0
  476. package/dist/vercel-cli/report.d.ts +22 -0
  477. package/dist/vercel-cli/report.js +110 -0
  478. package/dist/vercel-cli/verbose.d.ts +7 -0
  479. package/dist/vercel-cli/verbose.js +24 -0
  480. package/dist/version.d.ts +20 -0
  481. package/dist/version.js +57 -0
  482. package/dist/vitest/config.d.ts +51 -0
  483. package/dist/vitest/config.js +61 -0
  484. package/dist/vitest/container-scope.d.ts +108 -0
  485. package/dist/vitest/container-scope.js +234 -0
  486. package/dist/vitest/diagnostics.d.ts +146 -0
  487. package/dist/vitest/diagnostics.js +306 -0
  488. package/dist/vitest/fixtures.d.ts +64 -0
  489. package/dist/vitest/fixtures.js +172 -0
  490. package/dist/vitest/gateways.d.ts +47 -0
  491. package/dist/vitest/gateways.js +3 -0
  492. package/dist/vitest/index.d.ts +3 -0
  493. package/dist/vitest/index.js +9 -0
  494. package/dist/vitest/list-output.d.ts +3 -0
  495. package/dist/vitest/list-output.js +19 -0
  496. package/dist/vitest/live/list-gateway.d.ts +7 -0
  497. package/dist/vitest/live/list-gateway.js +60 -0
  498. package/dist/vitest/ownership.d.ts +29 -0
  499. package/dist/vitest/ownership.js +68 -0
  500. package/dist/vitest/plan.d.ts +33 -0
  501. package/dist/vitest/plan.js +73 -0
  502. package/dist/vitest/sandbox.d.ts +16 -0
  503. package/dist/vitest/sandbox.js +35 -0
  504. package/dist/vitest/test-events.d.ts +41 -0
  505. package/dist/vitest/test-events.js +92 -0
  506. package/dist/vitest/test-results.d.ts +84 -0
  507. package/dist/vitest/test-results.js +160 -0
  508. package/dist/vitest/types.d.ts +68 -0
  509. package/dist/vitest/types.js +4 -0
  510. package/package.json +123 -4
  511. package/skills/overview.md +32 -0
  512. package/skills/read-run-output.md +65 -0
  513. package/README.md +0 -3
@@ -0,0 +1,125 @@
1
+ import { isStaleLease, minutesLeft } from "./staleness.js";
2
+ /**
3
+ * Leases up to `count` usable pool entries matching `match`. It lists the pool, reclaims stale leases,
4
+ * health-checks every free matching entry in parallel, then reads the clock again to judge each entry's time
5
+ * left. It drops the expired entries and the failed ones without `minTimeLeftMinutes` left, and leases usable
6
+ * ones freshest first. Before each lease attempt it reads the clock again: an entry that has fallen below
7
+ * `minTimeLeftMinutes` is skipped and kept, and each lease starts at its attempt's clock read. An entry
8
+ * another run leases or drops first is skipped for the next. Only a pool that can't be listed stops it.
9
+ */
10
+ export async function leaseUsable(context, request) {
11
+ const listed = await context.pool.listEntries();
12
+ if (!listed.ok)
13
+ return listed;
14
+ const now = context.clock.now();
15
+ const storeFailures = [];
16
+ const stale = listed.value.entries.filter((listedEntry) => listedEntry.lease !== undefined && isStaleLease(listedEntry.lease, listedEntry.entry.ttlMinutes, now));
17
+ const reclaims = await Promise.all(stale.map(async ({ host, entry }) => ({
18
+ host,
19
+ outcome: await context.pool.reclaim(host, (lease) => isStaleLease(lease, entry.ttlMinutes, now)),
20
+ })));
21
+ const reclaimed = [];
22
+ for (const { host, outcome } of reclaims) {
23
+ if (outcome.kind === "reclaimed")
24
+ reclaimed.push(host);
25
+ if (outcome.kind === "failed")
26
+ storeFailures.push(outcome.failure);
27
+ }
28
+ const reclaimedSet = new Set(reclaimed);
29
+ const candidates = listed.value.entries.filter((listedEntry) => (listedEntry.lease === undefined || reclaimedSet.has(listedEntry.host)) && matches(listedEntry, request.match));
30
+ const healthChecked = await Promise.all(candidates.map(async (candidate) => ({
31
+ candidate,
32
+ health: await context.healthChecks.check({ testserverUrl: candidate.entry.testserverUrl }),
33
+ })));
34
+ const checkedAt = context.clock.now();
35
+ const checked = healthChecked.map(({ candidate, health }) => {
36
+ const left = minutesLeft(candidate.entry, checkedAt);
37
+ return {
38
+ host: candidate.host,
39
+ entry: candidate.entry,
40
+ minutesLeft: left,
41
+ health,
42
+ verdict: verdict(health, left, request.minTimeLeftMinutes),
43
+ };
44
+ });
45
+ const drops = await Promise.all(checked
46
+ .filter((entry) => entry.verdict === "expired" || entry.verdict === "drop-due")
47
+ .map(async ({ host }) => ({ host, outcome: await context.pool.dropEntry(host) })));
48
+ const dropped = [];
49
+ for (const { host, outcome } of drops) {
50
+ if (outcome.kind === "dropped")
51
+ dropped.push(host);
52
+ if (outcome.kind === "failed")
53
+ storeFailures.push(outcome.failure);
54
+ }
55
+ const usable = checked
56
+ .filter((entry) => entry.verdict === "usable")
57
+ .toSorted((a, b) => b.minutesLeft - a.minutesLeft);
58
+ const leased = [];
59
+ const belowMinimumAtLease = [];
60
+ let lostRaces = 0;
61
+ for (const candidate of usable) {
62
+ if (leased.length >= request.count)
63
+ break;
64
+ const at = context.clock.now();
65
+ if (minutesLeft(candidate.entry, at) < request.minTimeLeftMinutes) {
66
+ belowMinimumAtLease.push(candidate.host);
67
+ continue;
68
+ }
69
+ const outcome = await context.pool.lease(candidate.host, { startedAt: at.toISOString() });
70
+ if (outcome.kind === "leased")
71
+ leased.push({ host: candidate.host, entry: candidate.entry });
72
+ if (outcome.kind === "held")
73
+ lostRaces += 1;
74
+ if (outcome.kind === "failed")
75
+ storeFailures.push(outcome.failure);
76
+ }
77
+ return {
78
+ ok: true,
79
+ report: {
80
+ leased,
81
+ checked,
82
+ reclaimed,
83
+ dropped,
84
+ lostRaces,
85
+ belowMinimumAtLease,
86
+ unreadable: listed.value.unreadable,
87
+ storeFailures,
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * Releases this process's leases on `hosts`, in parallel, and returns the releases that failed. A release
93
+ * that finds another run holding the lease guard fails at the guard: its lease stays until this process
94
+ * exits, after which a reclaim frees it.
95
+ */
96
+ export async function releaseLeases(context, hosts) {
97
+ const released = await Promise.all(hosts.map((host) => context.pool.release(host)));
98
+ return released.flatMap((outcome) => {
99
+ switch (outcome.kind) {
100
+ case "failed":
101
+ return [outcome.failure];
102
+ case "guarded":
103
+ return [{ path: outcome.guard, message: "another storm run holds this lease's guard" }];
104
+ case "released":
105
+ case "not-held":
106
+ return [];
107
+ }
108
+ });
109
+ }
110
+ function matches(listed, match) {
111
+ return "resolvedBuild" in match
112
+ ? listed.entry.resolvedBuild === match.resolvedBuild
113
+ : listed.entry.requestedBuild === match.requestedBuild;
114
+ }
115
+ function verdict(health, left, minTimeLeft) {
116
+ const enough = left >= minTimeLeft;
117
+ switch (health.kind) {
118
+ case "answers":
119
+ return enough ? "usable" : "kept-unused";
120
+ case "expired":
121
+ return "expired";
122
+ case "failed":
123
+ return enough ? "kept" : "drop-due";
124
+ }
125
+ }
@@ -0,0 +1,17 @@
1
+ import type { ChannelResolution, LeaseRecord, PoolEntry } from "../gateways.ts";
2
+ export type ParsedRecord<T> = {
3
+ readonly ok: true;
4
+ readonly value: T;
5
+ } | {
6
+ readonly ok: false;
7
+ readonly reason: string;
8
+ };
9
+ /** The pool entry an entry file holds, or why it holds none. */
10
+ export declare function parseEntry(text: string): ParsedRecord<PoolEntry>;
11
+ /** The lease a lease file holds, or why it holds none. */
12
+ export declare function parseLease(text: string): ParsedRecord<LeaseRecord>;
13
+ /** The channel resolutions `channels.json` holds, or why it holds none. */
14
+ export declare function parseChannels(text: string): ParsedRecord<Readonly<Record<string, ChannelResolution>>>;
15
+ export declare function entryText(entry: PoolEntry): string;
16
+ export declare function leaseText(lease: LeaseRecord): string;
17
+ export declare function channelsText(channels: Readonly<Record<string, ChannelResolution>>): string;
@@ -0,0 +1,70 @@
1
+ // The pool's file formats. Each file carries `version: 1`; a reader rejects a version it doesn't know.
2
+ import { z } from "zod";
3
+ const isoTime = z.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
4
+ const entrySchema = z.object({
5
+ version: z.literal(1),
6
+ testserverUrl: z.string().min(1),
7
+ logViewerUrl: z.string().min(1),
8
+ createdAt: isoTime,
9
+ ttlMinutes: z.number().int().positive(),
10
+ requestedBuild: z.string().min(1),
11
+ resolvedBuild: z.string().min(1),
12
+ });
13
+ const leaseSchema = z.object({
14
+ version: z.literal(1),
15
+ pid: z.number().int().positive(),
16
+ hostname: z.string(),
17
+ startedAt: isoTime,
18
+ });
19
+ const channelsSchema = z.object({
20
+ version: z.literal(1),
21
+ channels: z.record(z.string(), z.object({ build: z.string().min(1), learnedAt: isoTime })),
22
+ });
23
+ /** The pool entry an entry file holds, or why it holds none. */
24
+ export function parseEntry(text) {
25
+ const parsed = parseVersioned(text, entrySchema);
26
+ if (!parsed.ok)
27
+ return parsed;
28
+ const { version: _version, ...entry } = parsed.value;
29
+ return { ok: true, value: entry };
30
+ }
31
+ /** The lease a lease file holds, or why it holds none. */
32
+ export function parseLease(text) {
33
+ const parsed = parseVersioned(text, leaseSchema);
34
+ if (!parsed.ok)
35
+ return parsed;
36
+ const { version: _version, ...lease } = parsed.value;
37
+ return { ok: true, value: lease };
38
+ }
39
+ /** The channel resolutions `channels.json` holds, or why it holds none. */
40
+ export function parseChannels(text) {
41
+ const parsed = parseVersioned(text, channelsSchema);
42
+ return parsed.ok ? { ok: true, value: parsed.value.channels } : parsed;
43
+ }
44
+ export function entryText(entry) {
45
+ return `${JSON.stringify({ version: 1, ...entry }, null, 2)}\n`;
46
+ }
47
+ export function leaseText(lease) {
48
+ return `${JSON.stringify({ version: 1, ...lease }, null, 2)}\n`;
49
+ }
50
+ export function channelsText(channels) {
51
+ return `${JSON.stringify({ version: 1, channels }, null, 2)}\n`;
52
+ }
53
+ function parseVersioned(text, schema) {
54
+ let json;
55
+ try {
56
+ json = JSON.parse(text);
57
+ }
58
+ catch {
59
+ return { ok: false, reason: "not JSON" };
60
+ }
61
+ const version = typeof json === "object" && json !== null ? json.version : undefined;
62
+ if (version !== 1)
63
+ return { ok: false, reason: `unknown version ${JSON.stringify(version) ?? "(none)"}` };
64
+ const parsed = schema.safeParse(json);
65
+ if (parsed.success)
66
+ return { ok: true, value: parsed.data };
67
+ const issue = parsed.error.issues[0];
68
+ const where = issue === undefined || issue.path.length === 0 ? "the record" : issue.path.join(".");
69
+ return { ok: false, reason: `${where}: ${issue?.message ?? "invalid"}` };
70
+ }
@@ -0,0 +1,12 @@
1
+ import type { PoolStoreGateway } from "../gateways.ts";
2
+ export interface LivePoolStoreOptions {
3
+ /** The pool directory, `$XDG_STATE_HOME/storm/pool`. */
4
+ readonly directory: string;
5
+ }
6
+ /** The pool in `options.directory`, held by this process (`process.pid` on `os.hostname()`). */
7
+ export declare function livePoolStoreGateway(options: LivePoolStoreOptions): PoolStoreGateway;
8
+ /**
9
+ * A pool that can't be found, because neither `XDG_STATE_HOME` nor `HOME` names a place for it. Every
10
+ * operation fails with `reason`, at `location`.
11
+ */
12
+ export declare function unavailablePoolStoreGateway(location: string, reason: string): PoolStoreGateway;
@@ -0,0 +1,435 @@
1
+ // The pool on disk:
2
+ //
3
+ // entries/<host>.json one pool entry per Testserver sandbox
4
+ // leases/<host>.json the lease on it, if any
5
+ // leases/<host>.guard/ the lease guard, while a run releases, reclaims, or drops that lease
6
+ // channels.json the channel resolutions
7
+ //
8
+ // Entries and `channels.json` are written to a temp file and renamed into place. A lease is written to a temp
9
+ // file in `leases/` and hard-linked into place, so it exists complete or not at all, and `EEXIST` means
10
+ // another holder has it. Taking a lease needs no lease guard, since a hard link never replaces a lease.
11
+ // Removing one does: only the run that made `leases/<host>.guard/` with `mkdir` removes `leases/<host>.json`,
12
+ // and no run takes another's lease guard over. Files are mode 0600 and directories 0700.
13
+ import { randomBytes } from "node:crypto";
14
+ import { link, mkdir, open, readdir, readFile, rename, rmdir, stat, unlink, writeFile } from "node:fs/promises";
15
+ import { hostname as osHostname } from "node:os";
16
+ import { basename, dirname, join } from "node:path";
17
+ import { isSafeHost, sandboxHost } from "../host.js";
18
+ import { channelsText, entryText, leaseText, parseChannels, parseEntry, parseLease } from "./pool-records.js";
19
+ const DIRECTORY_MODE = 0o700;
20
+ const FILE_MODE = 0o600;
21
+ /** The pool in `options.directory`, held by this process (`process.pid` on `os.hostname()`). */
22
+ export function livePoolStoreGateway(options) {
23
+ const store = new LivePoolStore(options.directory, { pid: process.pid, hostname: osHostname() });
24
+ return {
25
+ prepare: () => store.prepare(),
26
+ listEntries: () => store.listEntries(),
27
+ addEntry: (entry, addOptions) => store.addEntry(entry, addOptions),
28
+ lease: (host, leaseOptions) => store.lease(host, leaseOptions),
29
+ release: (host) => store.release(host),
30
+ reclaim: (host, isStale) => store.reclaim(host, isStale),
31
+ dropEntry: (host) => store.dropEntry(host),
32
+ readChannelResolutions: () => store.readChannelResolutions(),
33
+ writeChannelResolution: (channel, resolution) => store.writeChannelResolution(channel, resolution),
34
+ };
35
+ }
36
+ /**
37
+ * A pool that can't be found, because neither `XDG_STATE_HOME` nor `HOME` names a place for it. Every
38
+ * operation fails with `reason`, at `location`.
39
+ */
40
+ export function unavailablePoolStoreGateway(location, reason) {
41
+ const failure = { path: location, message: reason };
42
+ const fail = async () => ({ ok: false, failure });
43
+ const failed = async () => ({ kind: "failed", failure });
44
+ return {
45
+ prepare: fail,
46
+ listEntries: fail,
47
+ addEntry: fail,
48
+ lease: failed,
49
+ release: failed,
50
+ reclaim: failed,
51
+ dropEntry: failed,
52
+ readChannelResolutions: fail,
53
+ writeChannelResolution: fail,
54
+ };
55
+ }
56
+ class LivePoolStore {
57
+ #directory;
58
+ #entries;
59
+ #leases;
60
+ #channels;
61
+ #self;
62
+ constructor(directory, self) {
63
+ this.#directory = directory;
64
+ this.#entries = join(directory, "entries");
65
+ this.#leases = join(directory, "leases");
66
+ this.#channels = join(directory, "channels.json");
67
+ this.#self = self;
68
+ }
69
+ async prepare() {
70
+ return await this.#makeDirectories();
71
+ }
72
+ async listEntries() {
73
+ const directory = this.#directory;
74
+ const entryNames = await listNames(this.#entries);
75
+ if (!entryNames.ok)
76
+ return entryNames;
77
+ const leaseNames = await listNames(this.#leases);
78
+ if (!leaseNames.ok)
79
+ return leaseNames;
80
+ const leaseSet = new Set(leaseNames.value);
81
+ const entries = [];
82
+ const unreadable = [];
83
+ for (const name of entryNames.value.filter(isRecordName).toSorted()) {
84
+ const file = join(this.#entries, name);
85
+ const host = name.slice(0, -".json".length);
86
+ if (!isSafeHost(host)) {
87
+ unreadable.push({ file, reason: "its name isn't a Testserver sandbox's host" });
88
+ continue;
89
+ }
90
+ const text = await readText(file);
91
+ if (!text.ok)
92
+ return text;
93
+ if (text.value === undefined)
94
+ continue; // Removed since the directory was read.
95
+ const parsed = parseEntry(text.value);
96
+ if (!parsed.ok) {
97
+ unreadable.push({ file, reason: parsed.reason });
98
+ continue;
99
+ }
100
+ if (sandboxHost(parsed.value.testserverUrl) !== host) {
101
+ unreadable.push({ file, reason: `its Testserver URL, ${parsed.value.testserverUrl}, isn't on ${host}` });
102
+ continue;
103
+ }
104
+ let lease;
105
+ if (leaseSet.has(`${host}.json`)) {
106
+ const observed = await this.#observeLease(this.#leasePath(host));
107
+ if (!observed.ok)
108
+ return observed;
109
+ lease = observed.value;
110
+ }
111
+ entries.push({ host, entry: parsed.value, lease, leaseGuard: leaseSet.has(`${host}.guard`) });
112
+ }
113
+ return { ok: true, value: { directory, entries, unreadable } };
114
+ }
115
+ async addEntry(entry, options) {
116
+ const host = sandboxHost(entry.testserverUrl);
117
+ if (host === undefined)
118
+ throw new Error(`addEntry: no safe host in ${entry.testserverUrl}`);
119
+ const made = await this.#makeDirectories();
120
+ if (!made.ok)
121
+ return made;
122
+ if (options.lease !== undefined) {
123
+ const leased = await this.#linkLease(host, options.lease.startedAt);
124
+ if (leased.kind === "failed")
125
+ return { ok: false, failure: leased.failure };
126
+ if (leased.kind === "held")
127
+ return { ok: false, failure: { path: this.#leasePath(host), message: "a lease on this host already exists" } };
128
+ }
129
+ const written = await writeAtomically(this.#entryPath(host), entryText(entry));
130
+ // Undoes the lease this call just created, without the lease guard: its holder runs and it is moments
131
+ // old, so no reclaim judges it stale, and no other run removes it.
132
+ if (!written.ok && options.lease !== undefined)
133
+ await unlink(this.#leasePath(host)).catch(() => { });
134
+ return written;
135
+ }
136
+ async lease(host, options) {
137
+ const made = await this.#makeDirectories();
138
+ if (!made.ok)
139
+ return { kind: "failed", failure: made.failure };
140
+ const leased = await this.#linkLease(host, options.startedAt);
141
+ if (leased.kind !== "leased")
142
+ return leased;
143
+ try {
144
+ await stat(this.#entryPath(host));
145
+ return { kind: "leased" };
146
+ }
147
+ catch (error) {
148
+ // Undoes the lease this call just created, without the lease guard, as `addEntry` does.
149
+ await unlink(this.#leasePath(host)).catch(() => { });
150
+ if (errorCode(error) === "ENOENT")
151
+ return { kind: "gone" };
152
+ return { kind: "failed", failure: failureAt(this.#entryPath(host), error) };
153
+ }
154
+ }
155
+ async release(host) {
156
+ const guarded = await this.#underGuard(host, () => this.#releaseUnderGuard(this.#leasePath(host)));
157
+ if (guarded.kind === "done")
158
+ return guarded.value;
159
+ if (guarded.kind === "no-leases")
160
+ return { kind: "not-held" };
161
+ return guarded;
162
+ }
163
+ async reclaim(host, isStale) {
164
+ const guarded = await this.#underGuard(host, () => this.#reclaimUnderGuard(this.#leasePath(host), isStale));
165
+ if (guarded.kind === "done")
166
+ return guarded.value;
167
+ if (guarded.kind === "guarded")
168
+ return { kind: "guarded" };
169
+ if (guarded.kind === "no-leases")
170
+ return { kind: "gone" };
171
+ return guarded;
172
+ }
173
+ async dropEntry(host) {
174
+ // The lease guard is made in `leases/`, so a pool never written gets its directories, then finds no entry.
175
+ const made = await this.#makeDirectories();
176
+ if (!made.ok)
177
+ return { kind: "failed", failure: made.failure };
178
+ const guarded = await this.#underGuard(host, () => this.#dropUnderGuard(host));
179
+ if (guarded.kind === "done")
180
+ return guarded.value;
181
+ if (guarded.kind === "guarded")
182
+ return { kind: "guarded" };
183
+ if (guarded.kind === "no-leases")
184
+ return { kind: "gone" };
185
+ return guarded;
186
+ }
187
+ async readChannelResolutions() {
188
+ const text = await readText(this.#channels);
189
+ if (!text.ok)
190
+ return text;
191
+ if (text.value === undefined)
192
+ return { ok: true, value: {} };
193
+ const parsed = parseChannels(text.value);
194
+ // An unreadable record only costs a lookup; the next write replaces it.
195
+ return { ok: true, value: parsed.ok ? parsed.value : {} };
196
+ }
197
+ async writeChannelResolution(channel, resolution) {
198
+ const current = await this.readChannelResolutions();
199
+ if (!current.ok)
200
+ return current;
201
+ const made = await this.#makeDirectories();
202
+ if (!made.ok)
203
+ return made;
204
+ const channels = { ...current.value, [channel]: { build: resolution.build, learnedAt: resolution.learnedAt } };
205
+ return await writeAtomically(this.#channels, channelsText(channels));
206
+ }
207
+ /**
208
+ * Takes the lease guard on `host`, runs `work`, then removes the guard. The guard is taken with `mkdir`, so
209
+ * `EEXIST` means another run holds it, and that run's guard is never taken over. A guard left behind when
210
+ * its removal fails is what `pool list` warns about.
211
+ */
212
+ async #underGuard(host, work) {
213
+ const guard = join(this.#leases, `${host}.guard`);
214
+ try {
215
+ await mkdir(guard, { mode: DIRECTORY_MODE });
216
+ }
217
+ catch (error) {
218
+ const code = errorCode(error);
219
+ if (code === "EEXIST")
220
+ return { kind: "guarded", guard };
221
+ if (code === "ENOENT")
222
+ return { kind: "no-leases" };
223
+ return { kind: "failed", failure: failureAt(guard, error) };
224
+ }
225
+ try {
226
+ return { kind: "done", value: await work() };
227
+ }
228
+ finally {
229
+ await rmdir(guard).catch(() => { });
230
+ }
231
+ }
232
+ async #releaseUnderGuard(path) {
233
+ const text = await readText(path);
234
+ if (!text.ok)
235
+ return { kind: "failed", failure: text.failure };
236
+ if (text.value === undefined)
237
+ return { kind: "not-held" };
238
+ const parsed = parseLease(text.value);
239
+ if (!parsed.ok || parsed.value.pid !== this.#self.pid || parsed.value.hostname !== this.#self.hostname)
240
+ return { kind: "not-held" };
241
+ const removed = await removeFile(path);
242
+ return removed.ok ? { kind: "released" } : { kind: "failed", failure: removed.failure };
243
+ }
244
+ /**
245
+ * Leases the entry for `host` to this process first, so no other run leases it while it goes, then removes
246
+ * the entry and that lease. The entry goes first, so no run sees it free in between.
247
+ */
248
+ async #dropUnderGuard(host) {
249
+ const leased = await this.#linkLease(host, new Date().toISOString());
250
+ if (leased.kind !== "leased")
251
+ return leased;
252
+ const entryPath = this.#entryPath(host);
253
+ try {
254
+ await unlink(entryPath);
255
+ }
256
+ catch (error) {
257
+ await unlink(this.#leasePath(host)).catch(() => { });
258
+ if (errorCode(error) === "ENOENT")
259
+ return { kind: "gone" };
260
+ return { kind: "failed", failure: failureAt(entryPath, error) };
261
+ }
262
+ // A lease left behind on no entry leases nothing: no run lists it, and hosts aren't reused.
263
+ await unlink(this.#leasePath(host)).catch(() => { });
264
+ return { kind: "dropped" };
265
+ }
266
+ async #reclaimUnderGuard(path, isStale) {
267
+ const observed = await this.#observeLease(path);
268
+ if (!observed.ok)
269
+ return { kind: "failed", failure: observed.failure };
270
+ if (observed.value === undefined)
271
+ return { kind: "gone" };
272
+ if (!isStale(observed.value))
273
+ return { kind: "not-stale" };
274
+ try {
275
+ await unlink(path);
276
+ return { kind: "reclaimed" };
277
+ }
278
+ catch (error) {
279
+ if (errorCode(error) === "ENOENT")
280
+ return { kind: "gone" };
281
+ return { kind: "failed", failure: failureAt(path, error) };
282
+ }
283
+ }
284
+ /**
285
+ * Links a new lease for this process into place: `leased`, or `held` when a lease is already there
286
+ * (`EEXIST`). The temp file is in `leases/`, because a hard link can't cross file systems.
287
+ */
288
+ async #linkLease(host, startedAt) {
289
+ const path = this.#leasePath(host);
290
+ const temp = tempPath(this.#leases, `${host}.json`);
291
+ const record = { pid: this.#self.pid, hostname: this.#self.hostname, startedAt };
292
+ try {
293
+ await writeFile(temp, leaseText(record), { mode: FILE_MODE, flag: "wx" });
294
+ }
295
+ catch (error) {
296
+ return { kind: "failed", failure: failureAt(temp, error) };
297
+ }
298
+ try {
299
+ await link(temp, path);
300
+ return { kind: "leased" };
301
+ }
302
+ catch (error) {
303
+ if (errorCode(error) === "EEXIST")
304
+ return { kind: "held" };
305
+ return { kind: "failed", failure: failureAt(path, error) };
306
+ }
307
+ finally {
308
+ await unlink(temp).catch(() => { });
309
+ }
310
+ }
311
+ /** The lease at `path` as observed now, or `undefined` when there is none. */
312
+ async #observeLease(path) {
313
+ let handle;
314
+ try {
315
+ handle = await open(path, "r");
316
+ }
317
+ catch (error) {
318
+ if (errorCode(error) === "ENOENT")
319
+ return { ok: true, value: undefined };
320
+ return { ok: false, failure: failureAt(path, error) };
321
+ }
322
+ try {
323
+ const { mtime } = await handle.stat();
324
+ return { ok: true, value: this.#observe(parseLease(await handle.readFile("utf8")), mtime) };
325
+ }
326
+ catch (error) {
327
+ return { ok: false, failure: failureAt(path, error) };
328
+ }
329
+ finally {
330
+ await handle.close().catch(() => { });
331
+ }
332
+ }
333
+ /**
334
+ * A lease as observed. A lease file storm can't read names no holder (`holder` is `undefined`), so it is
335
+ * judged by age alone, from the file's modification time.
336
+ */
337
+ #observe(parsed, mtime) {
338
+ if (!parsed.ok)
339
+ return { holder: undefined, startedAt: mtime.toISOString() };
340
+ const { pid, hostname, startedAt } = parsed.value;
341
+ return { holder: { pid, hostname, alive: hostname === this.#self.hostname ? isAlive(pid) : undefined }, startedAt };
342
+ }
343
+ async #makeDirectories() {
344
+ for (const directory of [this.#entries, this.#leases]) {
345
+ try {
346
+ await mkdir(directory, { recursive: true, mode: DIRECTORY_MODE });
347
+ }
348
+ catch (error) {
349
+ return { ok: false, failure: failureAt(directory, error) };
350
+ }
351
+ }
352
+ return { ok: true };
353
+ }
354
+ #entryPath(host) {
355
+ return join(this.#entries, `${host}.json`);
356
+ }
357
+ #leasePath(host) {
358
+ return join(this.#leases, `${host}.json`);
359
+ }
360
+ }
361
+ /**
362
+ * Whether process `pid` on this host is running. Only `ESRCH` proves it isn't: `EPERM` means it runs under
363
+ * another user.
364
+ */
365
+ function isAlive(pid) {
366
+ try {
367
+ process.kill(pid, 0);
368
+ return true;
369
+ }
370
+ catch (error) {
371
+ return errorCode(error) !== "ESRCH";
372
+ }
373
+ }
374
+ /** A pool record's file name: `<name>.json`, not a hidden temp file. */
375
+ function isRecordName(name) {
376
+ return name.endsWith(".json") && !name.startsWith(".");
377
+ }
378
+ /** The names in `directory`; none when it doesn't exist. */
379
+ async function listNames(directory) {
380
+ try {
381
+ return { ok: true, value: await readdir(directory) };
382
+ }
383
+ catch (error) {
384
+ if (errorCode(error) === "ENOENT")
385
+ return { ok: true, value: [] };
386
+ return { ok: false, failure: failureAt(directory, error) };
387
+ }
388
+ }
389
+ /** The text of `path`, or `undefined` when it doesn't exist. */
390
+ async function readText(path) {
391
+ try {
392
+ return { ok: true, value: await readFile(path, "utf8") };
393
+ }
394
+ catch (error) {
395
+ if (errorCode(error) === "ENOENT")
396
+ return { ok: true, value: undefined };
397
+ return { ok: false, failure: failureAt(path, error) };
398
+ }
399
+ }
400
+ /** Removes `path`; one already gone is fine. */
401
+ async function removeFile(path) {
402
+ try {
403
+ await unlink(path);
404
+ return { ok: true };
405
+ }
406
+ catch (error) {
407
+ if (errorCode(error) === "ENOENT")
408
+ return { ok: true };
409
+ return { ok: false, failure: failureAt(path, error) };
410
+ }
411
+ }
412
+ /** Writes `text` to a temp file beside `path`, then renames it into place. */
413
+ async function writeAtomically(path, text) {
414
+ const temp = tempPath(dirname(path), basename(path));
415
+ try {
416
+ await writeFile(temp, text, { mode: FILE_MODE, flag: "wx" });
417
+ await rename(temp, path);
418
+ return { ok: true };
419
+ }
420
+ catch (error) {
421
+ await unlink(temp).catch(() => { });
422
+ return { ok: false, failure: failureAt(path, error) };
423
+ }
424
+ }
425
+ /** A hidden temp file name in `directory` for `name`, unique to this process and call. */
426
+ function tempPath(directory, name) {
427
+ return join(directory, `.${name}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
428
+ }
429
+ function errorCode(error) {
430
+ const code = typeof error === "object" && error !== null ? error.code : undefined;
431
+ return typeof code === "string" ? code : undefined;
432
+ }
433
+ function failureAt(path, error) {
434
+ return { path, message: error instanceof Error ? error.message : String(error) };
435
+ }
@@ -0,0 +1,16 @@
1
+ import type { ObservedLease, PoolEntry } from "./gateways.ts";
2
+ /**
3
+ * Whether a lease is stale: its holder is known to have died (`holder.alive === false`, which only a holder on
4
+ * this host can show), or it is older than its entry's TTL, `ttlMinutes`. A lease is always taken after its
5
+ * Testserver sandbox was created, so a lease older than the TTL outlived its Testserver sandbox, whoever holds it;
6
+ * the age rule also covers a reused pid, a holder on another host, and a lease file that can't be read, which has
7
+ * no holder and is judged by age from the file's modification time.
8
+ */
9
+ export declare function isStaleLease(lease: ObservedLease, ttlMinutes: number, now: Date): boolean;
10
+ /** A pool entry's lease state: `free` with no lease, else `leased`, or `stale` by `isStaleLease`. */
11
+ export type LeaseState = "free" | "leased" | "stale";
12
+ export declare function leaseState(lease: ObservedLease | undefined, ttlMinutes: number, now: Date): LeaseState;
13
+ /** The whole minutes a pool entry's Testserver sandbox has left by its TTL, rounded down; negative once past it. */
14
+ export declare function minutesLeft(entry: PoolEntry, now: Date): number;
15
+ /** The whole minutes since `since` (an ISO string), rounded down. */
16
+ export declare function minutesSince(since: string, now: Date): number;