@speedkit/cli 4.50.5 → 4.51.0-run-control.2

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 (432) hide show
  1. package/README.md +1425 -14
  2. package/dist/base/run-control-command.d.ts +15 -0
  3. package/dist/base/run-control-command.js +20 -0
  4. package/dist/build-info.json +6 -0
  5. package/dist/commands/diff.d.ts +7 -1
  6. package/dist/commands/diff.js +9 -3
  7. package/dist/commands/login.d.ts +3 -0
  8. package/dist/commands/login.js +14 -3
  9. package/dist/commands/onboarding/browser/click.d.ts +75 -0
  10. package/dist/commands/onboarding/browser/click.js +19 -0
  11. package/dist/commands/onboarding/browser/emulate.d.ts +105 -0
  12. package/dist/commands/onboarding/browser/emulate.js +26 -0
  13. package/dist/commands/onboarding/browser/navigate.d.ts +75 -0
  14. package/dist/commands/onboarding/browser/navigate.js +19 -0
  15. package/dist/commands/onboarding/browser/panel.d.ts +63 -0
  16. package/dist/commands/onboarding/browser/panel.js +12 -0
  17. package/dist/commands/onboarding/browser/reinstall-sw.d.ts +63 -0
  18. package/dist/commands/onboarding/browser/reinstall-sw.js +14 -0
  19. package/dist/commands/onboarding/browser/reset.d.ts +71 -0
  20. package/dist/commands/onboarding/browser/reset.js +18 -0
  21. package/dist/commands/onboarding/browser/screenshot.d.ts +77 -0
  22. package/dist/commands/onboarding/browser/screenshot.js +19 -0
  23. package/dist/commands/onboarding/browser/state.d.ts +63 -0
  24. package/dist/commands/onboarding/browser/state.js +12 -0
  25. package/dist/commands/onboarding/browser/tabs.d.ts +58 -0
  26. package/dist/commands/onboarding/browser/tabs.js +16 -0
  27. package/dist/commands/onboarding/cache/clear.d.ts +58 -0
  28. package/dist/commands/onboarding/cache/clear.js +12 -0
  29. package/dist/commands/onboarding/cache/errors.d.ts +58 -0
  30. package/dist/commands/onboarding/cache/errors.js +12 -0
  31. package/dist/commands/onboarding/cache/evict.d.ts +62 -0
  32. package/dist/commands/onboarding/cache/evict.js +15 -0
  33. package/dist/commands/onboarding/cache/get.d.ts +85 -0
  34. package/dist/commands/onboarding/cache/get.js +17 -0
  35. package/dist/commands/onboarding/cache/list.d.ts +58 -0
  36. package/dist/commands/onboarding/cache/list.js +15 -0
  37. package/dist/commands/onboarding/cache/prewarm.d.ts +73 -0
  38. package/dist/commands/onboarding/cache/prewarm.js +20 -0
  39. package/dist/commands/onboarding/cache/refresh.d.ts +62 -0
  40. package/dist/commands/onboarding/cache/refresh.js +18 -0
  41. package/dist/commands/onboarding/cdp.d.ts +81 -0
  42. package/dist/commands/onboarding/cdp.js +18 -0
  43. package/dist/commands/onboarding/debug/arm.d.ts +83 -0
  44. package/dist/commands/onboarding/debug/arm.js +19 -0
  45. package/dist/commands/onboarding/debug/await.d.ts +71 -0
  46. package/dist/commands/onboarding/debug/await.js +18 -0
  47. package/dist/commands/onboarding/debug/disarm.d.ts +63 -0
  48. package/dist/commands/onboarding/debug/disarm.js +12 -0
  49. package/dist/commands/onboarding/debug/eval.d.ts +75 -0
  50. package/dist/commands/onboarding/debug/eval.js +16 -0
  51. package/dist/commands/onboarding/debug/release.d.ts +63 -0
  52. package/dist/commands/onboarding/debug/release.js +12 -0
  53. package/dist/commands/onboarding/debug/resume.d.ts +63 -0
  54. package/dist/commands/onboarding/debug/resume.js +12 -0
  55. package/dist/commands/onboarding/debug/status.d.ts +63 -0
  56. package/dist/commands/onboarding/debug/status.js +12 -0
  57. package/dist/commands/onboarding/debug/step.d.ts +67 -0
  58. package/dist/commands/onboarding/debug/step.js +15 -0
  59. package/dist/commands/onboarding/files/list.d.ts +58 -0
  60. package/dist/commands/onboarding/files/list.js +12 -0
  61. package/dist/commands/onboarding/files/read.d.ts +73 -0
  62. package/dist/commands/onboarding/files/read.js +16 -0
  63. package/dist/commands/onboarding/files/rebuild.d.ts +63 -0
  64. package/dist/commands/onboarding/files/rebuild.js +18 -0
  65. package/dist/commands/onboarding/files/validate.d.ts +58 -0
  66. package/dist/commands/onboarding/files/validate.js +12 -0
  67. package/dist/commands/onboarding/fouc.d.ts +77 -0
  68. package/dist/commands/onboarding/fouc.js +16 -0
  69. package/dist/commands/onboarding/inject/add.d.ts +89 -0
  70. package/dist/commands/onboarding/inject/add.js +17 -0
  71. package/dist/commands/onboarding/inject/clear.d.ts +63 -0
  72. package/dist/commands/onboarding/inject/clear.js +12 -0
  73. package/dist/commands/onboarding/inject/list.d.ts +63 -0
  74. package/dist/commands/onboarding/inject/list.js +12 -0
  75. package/dist/commands/onboarding/inject/read.d.ts +75 -0
  76. package/dist/commands/onboarding/inject/read.js +18 -0
  77. package/dist/commands/onboarding/inject/recipes.d.ts +63 -0
  78. package/dist/commands/onboarding/inject/recipes.js +12 -0
  79. package/dist/commands/onboarding/inject/remove.d.ts +67 -0
  80. package/dist/commands/onboarding/inject/remove.js +15 -0
  81. package/dist/commands/onboarding/list.d.ts +13 -0
  82. package/dist/commands/onboarding/list.js +12 -0
  83. package/dist/commands/onboarding/logs.d.ts +41 -0
  84. package/dist/commands/onboarding/logs.js +257 -0
  85. package/dist/commands/onboarding/navwalk.d.ts +95 -0
  86. package/dist/commands/onboarding/navwalk.js +19 -0
  87. package/dist/commands/onboarding/response.d.ts +67 -0
  88. package/dist/commands/onboarding/response.js +18 -0
  89. package/dist/commands/onboarding/rum/beacons.d.ts +75 -0
  90. package/dist/commands/onboarding/rum/beacons.js +16 -0
  91. package/dist/commands/onboarding/rum/get.d.ts +77 -0
  92. package/dist/commands/onboarding/rum/get.js +18 -0
  93. package/dist/commands/onboarding/rum/key.d.ts +67 -0
  94. package/dist/commands/onboarding/rum/key.js +13 -0
  95. package/dist/commands/onboarding/rum/previous.d.ts +63 -0
  96. package/dist/commands/onboarding/rum/previous.js +12 -0
  97. package/dist/commands/onboarding/status.d.ts +13 -0
  98. package/dist/commands/onboarding/status.js +17 -0
  99. package/dist/commands/onboarding/stop.d.ts +13 -0
  100. package/dist/commands/onboarding/stop.js +17 -0
  101. package/dist/commands/onboarding/todo.d.ts +58 -0
  102. package/dist/commands/onboarding/todo.js +12 -0
  103. package/dist/commands/onboarding/viewport.d.ts +101 -0
  104. package/dist/commands/onboarding/viewport.js +18 -0
  105. package/dist/commands/onboarding/watch.d.ts +93 -0
  106. package/dist/commands/onboarding/watch.js +16 -0
  107. package/dist/commands/onboarding.d.ts +26 -0
  108. package/dist/commands/onboarding.js +221 -4
  109. package/dist/commands/origin-request.d.ts +4 -0
  110. package/dist/commands/origin-request.js +4 -0
  111. package/dist/commands/spec/onboarding.spec.d.ts +1 -0
  112. package/dist/commands/spec/onboarding.spec.js +127 -0
  113. package/dist/services/cli/build-info.d.ts +33 -0
  114. package/dist/services/cli/build-info.js +63 -0
  115. package/dist/services/cli/cli-environment-factory.d.ts +3 -0
  116. package/dist/services/cli/cli-environment-factory.js +1 -0
  117. package/dist/services/cli/cli-service-build-context.d.ts +3 -0
  118. package/dist/services/cli/cli-service-factory.js +1 -1
  119. package/dist/services/cli/cli-service-model.d.ts +29 -10
  120. package/dist/services/cli/cli-service.d.ts +60 -11
  121. package/dist/services/cli/cli-service.js +196 -32
  122. package/dist/services/cli/index.d.ts +2 -0
  123. package/dist/services/cli/index.js +2 -0
  124. package/dist/services/cli/sink.d.ts +47 -0
  125. package/dist/services/cli/sink.js +31 -0
  126. package/dist/services/cli/spec/build-identity.spec.d.ts +1 -0
  127. package/dist/services/cli/spec/build-identity.spec.js +85 -0
  128. package/dist/services/cli/spec/build-info.spec.d.ts +1 -0
  129. package/dist/services/cli/spec/build-info.spec.js +10 -0
  130. package/dist/services/cli/spec/cli-service-log.spec.d.ts +1 -0
  131. package/dist/services/cli/spec/cli-service-log.spec.js +133 -0
  132. package/dist/services/cli/spec/cli-service.spec.js +113 -50
  133. package/dist/services/cli/spec/memory-cli.d.ts +9 -0
  134. package/dist/services/cli/spec/memory-cli.js +9 -0
  135. package/dist/services/diff/config-at-ref.d.ts +20 -0
  136. package/dist/services/diff/config-at-ref.js +33 -0
  137. package/dist/services/diff/diff-service-build-context.d.ts +12 -0
  138. package/dist/services/diff/diff-service-build-context.js +45 -1
  139. package/dist/services/diff/diff-service-factory.d.ts +2 -0
  140. package/dist/services/diff/diff-service-factory.js +65 -25
  141. package/dist/services/diff/diff-service.d.ts +11 -0
  142. package/dist/services/diff/diff-service.js +37 -11
  143. package/dist/services/diff/page-source.d.ts +12 -0
  144. package/dist/services/diff/page-source.js +16 -11
  145. package/dist/services/diff/run-runtime-config.d.ts +33 -0
  146. package/dist/services/diff/run-runtime-config.js +74 -0
  147. package/dist/services/diff/sinks/tool-diff-sink.d.ts +3 -2
  148. package/dist/services/diff/sinks/tool-diff-sink.js +3 -2
  149. package/dist/services/diff/spec/config-at-ref.spec.d.ts +1 -0
  150. package/dist/services/diff/spec/config-at-ref.spec.js +46 -0
  151. package/dist/services/diff/spec/diff-service-build-context.spec.js +19 -0
  152. package/dist/services/diff/spec/diff-service.spec.js +95 -0
  153. package/dist/services/diff/spec/run-runtime-config.spec.d.ts +1 -0
  154. package/dist/services/diff/spec/run-runtime-config.spec.js +87 -0
  155. package/dist/services/git/git-repository.d.ts +2 -0
  156. package/dist/services/git/git-repository.js +6 -0
  157. package/dist/services/integration-api/customer-config-flags.js +1 -0
  158. package/dist/services/onboarding/browse/browse-service.d.ts +13 -1
  159. package/dist/services/onboarding/browse/browse-service.js +40 -7
  160. package/dist/services/onboarding/browser/answer-dialogs.d.ts +12 -0
  161. package/dist/services/onboarding/browser/answer-dialogs.js +25 -0
  162. package/dist/services/onboarding/browser/baqend-response.d.ts +17 -1
  163. package/dist/services/onboarding/browser/baqend-response.js +23 -0
  164. package/dist/services/onboarding/browser/console-log.d.ts +9 -0
  165. package/dist/services/onboarding/browser/console-log.js +27 -0
  166. package/dist/services/onboarding/browser/emulate-device.d.ts +12 -1
  167. package/dist/services/onboarding/browser/emulate-device.js +33 -6
  168. package/dist/services/onboarding/browser/executable/executable-validator.js +4 -2
  169. package/dist/services/onboarding/browser/extension/extension-bridge.js +5 -3
  170. package/dist/services/onboarding/browser/extension/extension-downloader.js +17 -8
  171. package/dist/services/onboarding/browser/extension/extension-validator.js +9 -4
  172. package/dist/services/onboarding/browser/launch-browser.d.ts +2 -1
  173. package/dist/services/onboarding/browser/launch-browser.js +3 -1
  174. package/dist/services/onboarding/control/body-inspect.d.ts +24 -0
  175. package/dist/services/onboarding/control/body-inspect.js +106 -0
  176. package/dist/services/onboarding/control/browser-session.d.ts +535 -0
  177. package/dist/services/onboarding/control/browser-session.js +1300 -0
  178. package/dist/services/onboarding/control/config-validation.d.ts +17 -0
  179. package/dist/services/onboarding/control/config-validation.js +46 -0
  180. package/dist/services/onboarding/control/control-protocol.d.ts +1428 -0
  181. package/dist/services/onboarding/control/control-protocol.js +58 -0
  182. package/dist/services/onboarding/control/control-server.d.ts +292 -0
  183. package/dist/services/onboarding/control/control-server.js +1629 -0
  184. package/dist/services/onboarding/control/debug-session.d.ts +219 -0
  185. package/dist/services/onboarding/control/debug-session.js +897 -0
  186. package/dist/services/onboarding/control/fouc.d.ts +23 -0
  187. package/dist/services/onboarding/control/fouc.js +151 -0
  188. package/dist/services/onboarding/control/index.d.ts +4 -0
  189. package/dist/services/onboarding/control/index.js +4 -0
  190. package/dist/services/onboarding/control/navigate-wait.d.ts +33 -0
  191. package/dist/services/onboarding/control/navigate-wait.js +56 -0
  192. package/dist/services/onboarding/control/navwalk.d.ts +65 -0
  193. package/dist/services/onboarding/control/navwalk.js +248 -0
  194. package/dist/services/onboarding/control/preload-registry.d.ts +150 -0
  195. package/dist/services/onboarding/control/preload-registry.js +829 -0
  196. package/dist/services/onboarding/control/response-explainer.d.ts +24 -0
  197. package/dist/services/onboarding/control/response-explainer.js +257 -0
  198. package/dist/services/onboarding/control/rum.d.ts +8 -0
  199. package/dist/services/onboarding/control/rum.js +220 -0
  200. package/dist/services/onboarding/control/service-worker-tracker.d.ts +68 -0
  201. package/dist/services/onboarding/control/service-worker-tracker.js +120 -0
  202. package/dist/services/onboarding/control/viewport.d.ts +45 -0
  203. package/dist/services/onboarding/control/viewport.js +344 -0
  204. package/dist/services/onboarding/control/watch.d.ts +26 -0
  205. package/dist/services/onboarding/control/watch.js +157 -0
  206. package/dist/services/onboarding/dashboard/diff-against-current-page.js +3 -1
  207. package/dist/services/onboarding/dashboard/index.js +7 -2
  208. package/dist/services/onboarding/fetch-event-handler.d.ts +24 -5
  209. package/dist/services/onboarding/fetch-event-handler.js +103 -32
  210. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +11 -2
  211. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +14 -0
  212. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +30 -0
  213. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +13 -0
  214. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +28 -1
  215. package/dist/services/onboarding/file-events/file-watcher.d.ts +42 -1
  216. package/dist/services/onboarding/file-events/file-watcher.js +117 -12
  217. package/dist/services/onboarding/inject/inject-service.js +1 -1
  218. package/dist/services/onboarding/onboarding-model.d.ts +30 -0
  219. package/dist/services/onboarding/onboarding-model.js +12 -1
  220. package/dist/services/onboarding/onboarding-service-build-context.d.ts +4 -0
  221. package/dist/services/onboarding/onboarding-service-build-context.js +7 -1
  222. package/dist/services/onboarding/onboarding-service-factory.d.ts +17 -1
  223. package/dist/services/onboarding/onboarding-service-factory.js +150 -23
  224. package/dist/services/onboarding/onboarding-service.d.ts +40 -1
  225. package/dist/services/onboarding/onboarding-service.js +136 -23
  226. package/dist/services/onboarding/request-cache/asset-key.d.ts +61 -0
  227. package/dist/services/onboarding/request-cache/asset-key.js +115 -0
  228. package/dist/services/onboarding/request-cache/cache.d.ts +62 -5
  229. package/dist/services/onboarding/request-cache/cache.js +128 -17
  230. package/dist/services/onboarding/spec/browser/answer-dialogs.spec.d.ts +1 -0
  231. package/dist/services/onboarding/spec/browser/answer-dialogs.spec.js +66 -0
  232. package/dist/services/onboarding/spec/browser/console-log.spec.d.ts +1 -0
  233. package/dist/services/onboarding/spec/browser/console-log.spec.js +42 -0
  234. package/dist/services/onboarding/spec/control/browser-session.spec.d.ts +1 -0
  235. package/dist/services/onboarding/spec/control/browser-session.spec.js +651 -0
  236. package/dist/services/onboarding/spec/control/control-server.spec.d.ts +1 -0
  237. package/dist/services/onboarding/spec/control/control-server.spec.js +371 -0
  238. package/dist/services/onboarding/spec/control/debug-session.spec.d.ts +1 -0
  239. package/dist/services/onboarding/spec/control/debug-session.spec.js +751 -0
  240. package/dist/services/onboarding/spec/control/fakes.d.ts +31 -0
  241. package/dist/services/onboarding/spec/control/fakes.js +66 -0
  242. package/dist/services/onboarding/spec/control/fouc.spec.d.ts +1 -0
  243. package/dist/services/onboarding/spec/control/fouc.spec.js +167 -0
  244. package/dist/services/onboarding/spec/control/navigate-wait.spec.d.ts +1 -0
  245. package/dist/services/onboarding/spec/control/navigate-wait.spec.js +47 -0
  246. package/dist/services/onboarding/spec/control/navwalk.spec.d.ts +1 -0
  247. package/dist/services/onboarding/spec/control/navwalk.spec.js +222 -0
  248. package/dist/services/onboarding/spec/control/preload-registry.spec.d.ts +1 -0
  249. package/dist/services/onboarding/spec/control/preload-registry.spec.js +432 -0
  250. package/dist/services/onboarding/spec/control/response-explainer.spec.d.ts +1 -0
  251. package/dist/services/onboarding/spec/control/response-explainer.spec.js +324 -0
  252. package/dist/services/onboarding/spec/control/rum.spec.d.ts +1 -0
  253. package/dist/services/onboarding/spec/control/rum.spec.js +222 -0
  254. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.d.ts +1 -0
  255. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.js +193 -0
  256. package/dist/services/onboarding/spec/control/viewport.spec.d.ts +1 -0
  257. package/dist/services/onboarding/spec/control/viewport.spec.js +200 -0
  258. package/dist/services/onboarding/spec/control/watch.spec.d.ts +1 -0
  259. package/dist/services/onboarding/spec/control/watch.spec.js +187 -0
  260. package/dist/services/onboarding/spec/fetch-event-handler.spec.d.ts +1 -0
  261. package/dist/services/onboarding/spec/fetch-event-handler.spec.js +219 -0
  262. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.d.ts +1 -0
  263. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.js +41 -0
  264. package/dist/services/onboarding/spec/onboarding-model.spec.js +39 -3
  265. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +25 -1
  266. package/dist/services/onboarding/spec/request-cache/cache.spec.d.ts +1 -0
  267. package/dist/services/onboarding/spec/request-cache/cache.spec.js +107 -0
  268. package/dist/services/onboarding/spec/todo-collector.spec.d.ts +1 -0
  269. package/dist/services/onboarding/spec/todo-collector.spec.js +136 -0
  270. package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.d.ts +1 -0
  271. package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.js +65 -0
  272. package/dist/services/onboarding/todo-collector.d.ts +7 -2
  273. package/dist/services/onboarding/todo-collector.js +49 -12
  274. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +38 -0
  275. package/dist/services/onboarding/virtual-orestes-app/index.js +113 -27
  276. package/dist/services/origin-request/asset-variations.d.ts +14 -0
  277. package/dist/services/origin-request/asset-variations.js +11 -4
  278. package/dist/services/origin-request/origin-fetcher.d.ts +7 -0
  279. package/dist/services/origin-request/origin-fetcher.js +43 -5
  280. package/dist/services/origin-request/origin-request-service-build-context.d.ts +17 -0
  281. package/dist/services/origin-request/origin-request-service-build-context.js +8 -0
  282. package/dist/services/origin-request/origin-request-service-factory.d.ts +0 -5
  283. package/dist/services/origin-request/origin-request-service-factory.js +2 -30
  284. package/dist/services/origin-request/origin-request-service.d.ts +121 -6
  285. package/dist/services/origin-request/origin-request-service.js +273 -49
  286. package/dist/services/origin-request/runtime-config-source.d.ts +6 -0
  287. package/dist/services/origin-request/runtime-config-source.js +15 -4
  288. package/dist/services/origin-request/spec/asset-variations.spec.js +20 -0
  289. package/dist/services/origin-request/spec/origin-request-service.spec.js +329 -6
  290. package/dist/services/query-builder/rules/rule-match.d.ts +35 -0
  291. package/dist/services/query-builder/rules/rule-match.js +70 -0
  292. package/dist/services/query-builder/spec/rules/rule-match.spec.d.ts +1 -0
  293. package/dist/services/query-builder/spec/rules/rule-match.spec.js +121 -0
  294. package/dist/services/run-control/browser/run-browser-contexts.d.ts +557 -0
  295. package/dist/services/run-control/browser/run-browser-contexts.js +91 -0
  296. package/dist/services/run-control/browser/run-browser-service-factory.d.ts +5 -0
  297. package/dist/services/run-control/browser/run-browser-service-factory.js +7 -0
  298. package/dist/services/run-control/browser/run-browser-service.d.ts +68 -0
  299. package/dist/services/run-control/browser/run-browser-service.js +206 -0
  300. package/dist/services/run-control/cache/run-cache-contexts.d.ts +349 -0
  301. package/dist/services/run-control/cache/run-cache-contexts.js +51 -0
  302. package/dist/services/run-control/cache/run-cache-service-factory.d.ts +6 -0
  303. package/dist/services/run-control/cache/run-cache-service-factory.js +12 -0
  304. package/dist/services/run-control/cache/run-cache-service.d.ts +35 -0
  305. package/dist/services/run-control/cache/run-cache-service.js +151 -0
  306. package/dist/services/run-control/control-client.d.ts +36 -0
  307. package/dist/services/run-control/control-client.js +147 -0
  308. package/dist/services/run-control/debug/run-debug-contexts.d.ts +416 -0
  309. package/dist/services/run-control/debug/run-debug-contexts.js +47 -0
  310. package/dist/services/run-control/debug/run-debug-service-factory.d.ts +5 -0
  311. package/dist/services/run-control/debug/run-debug-service-factory.js +7 -0
  312. package/dist/services/run-control/debug/run-debug-service.d.ts +39 -0
  313. package/dist/services/run-control/debug/run-debug-service.js +164 -0
  314. package/dist/services/run-control/files/run-files-contexts.d.ts +238 -0
  315. package/dist/services/run-control/files/run-files-contexts.js +26 -0
  316. package/dist/services/run-control/files/run-files-service-factory.d.ts +5 -0
  317. package/dist/services/run-control/files/run-files-service-factory.js +7 -0
  318. package/dist/services/run-control/files/run-files-service.d.ts +29 -0
  319. package/dist/services/run-control/files/run-files-service.js +120 -0
  320. package/dist/services/run-control/index.d.ts +32 -0
  321. package/dist/services/run-control/index.js +31 -0
  322. package/dist/services/run-control/inject/run-inject-contexts.d.ts +319 -0
  323. package/dist/services/run-control/inject/run-inject-contexts.js +38 -0
  324. package/dist/services/run-control/inject/run-inject-service-factory.d.ts +5 -0
  325. package/dist/services/run-control/inject/run-inject-service-factory.js +7 -0
  326. package/dist/services/run-control/inject/run-inject-service.d.ts +31 -0
  327. package/dist/services/run-control/inject/run-inject-service.js +227 -0
  328. package/dist/services/run-control/live-run.d.ts +37 -0
  329. package/dist/services/run-control/live-run.js +56 -0
  330. package/dist/services/run-control/probe/run-probe-contexts.d.ts +333 -0
  331. package/dist/services/run-control/probe/run-probe-contexts.js +73 -0
  332. package/dist/services/run-control/probe/run-probe-service-factory.d.ts +5 -0
  333. package/dist/services/run-control/probe/run-probe-service-factory.js +7 -0
  334. package/dist/services/run-control/probe/run-probe-service.d.ts +54 -0
  335. package/dist/services/run-control/probe/run-probe-service.js +194 -0
  336. package/dist/services/run-control/rum/run-rum-contexts.d.ts +216 -0
  337. package/dist/services/run-control/rum/run-rum-contexts.js +34 -0
  338. package/dist/services/run-control/rum/run-rum-service-factory.d.ts +5 -0
  339. package/dist/services/run-control/rum/run-rum-service-factory.js +7 -0
  340. package/dist/services/run-control/rum/run-rum-service.d.ts +36 -0
  341. package/dist/services/run-control/rum/run-rum-service.js +122 -0
  342. package/dist/services/run-control/run-answer.d.ts +28 -0
  343. package/dist/services/run-control/run-answer.js +58 -0
  344. package/dist/services/run-control/run-control-context.d.ts +102 -0
  345. package/dist/services/run-control/run-control-context.js +36 -0
  346. package/dist/services/run-control/run-control-flags.d.ts +12 -0
  347. package/dist/services/run-control/run-control-flags.js +22 -0
  348. package/dist/services/run-control/run-control-model.d.ts +9 -0
  349. package/dist/services/run-control/run-control-model.js +1 -0
  350. package/dist/services/run-control/run-control-service-factory.d.ts +14 -0
  351. package/dist/services/run-control/run-control-service-factory.js +26 -0
  352. package/dist/services/run-control/session/run-session-contexts.d.ts +25 -0
  353. package/dist/services/run-control/session/run-session-contexts.js +20 -0
  354. package/dist/services/run-control/session/run-session-service-factory.d.ts +8 -0
  355. package/dist/services/run-control/session/run-session-service-factory.js +18 -0
  356. package/dist/services/run-control/session/run-session-service.d.ts +32 -0
  357. package/dist/services/run-control/session/run-session-service.js +151 -0
  358. package/dist/services/run-control/spec/browser/run-browser-service.spec.d.ts +1 -0
  359. package/dist/services/run-control/spec/browser/run-browser-service.spec.js +327 -0
  360. package/dist/services/run-control/spec/cache/run-cache-service.spec.d.ts +1 -0
  361. package/dist/services/run-control/spec/cache/run-cache-service.spec.js +454 -0
  362. package/dist/services/run-control/spec/debug/run-debug-service.spec.d.ts +1 -0
  363. package/dist/services/run-control/spec/debug/run-debug-service.spec.js +113 -0
  364. package/dist/services/run-control/spec/files/run-files-service.spec.d.ts +1 -0
  365. package/dist/services/run-control/spec/files/run-files-service.spec.js +234 -0
  366. package/dist/services/run-control/spec/inject/run-inject-service.spec.d.ts +1 -0
  367. package/dist/services/run-control/spec/inject/run-inject-service.spec.js +251 -0
  368. package/dist/services/run-control/spec/live-run-fixture.d.ts +32 -0
  369. package/dist/services/run-control/spec/live-run-fixture.js +109 -0
  370. package/dist/services/run-control/spec/probe/run-probe-service.spec.d.ts +1 -0
  371. package/dist/services/run-control/spec/probe/run-probe-service.spec.js +108 -0
  372. package/dist/services/run-control/spec/rum/run-rum-service.spec.d.ts +1 -0
  373. package/dist/services/run-control/spec/rum/run-rum-service.spec.js +47 -0
  374. package/dist/services/run-control/spec/run-answer.spec.d.ts +1 -0
  375. package/dist/services/run-control/spec/run-answer.spec.js +57 -0
  376. package/dist/services/run-control/spec/session/run-session-service.spec.d.ts +1 -0
  377. package/dist/services/run-control/spec/session/run-session-service.spec.js +150 -0
  378. package/dist/services/run-log/crash-mirror.d.ts +31 -0
  379. package/dist/services/run-log/crash-mirror.js +69 -0
  380. package/dist/services/run-log/index.d.ts +11 -0
  381. package/dist/services/run-log/index.js +11 -0
  382. package/dist/services/run-log/jsonl-appender.d.ts +46 -0
  383. package/dist/services/run-log/jsonl-appender.js +91 -0
  384. package/dist/services/run-log/log-event-model.d.ts +104 -0
  385. package/dist/services/run-log/log-event-model.js +56 -0
  386. package/dist/services/run-log/log-query-service-factory.d.ts +11 -0
  387. package/dist/services/run-log/log-query-service-factory.js +14 -0
  388. package/dist/services/run-log/log-query-service.d.ts +59 -0
  389. package/dist/services/run-log/log-query-service.js +111 -0
  390. package/dist/services/run-log/log-reader.d.ts +84 -0
  391. package/dist/services/run-log/log-reader.js +180 -0
  392. package/dist/services/run-log/log-summary.d.ts +72 -0
  393. package/dist/services/run-log/log-summary.js +208 -0
  394. package/dist/services/run-log/redaction.d.ts +34 -0
  395. package/dist/services/run-log/redaction.js +124 -0
  396. package/dist/services/run-log/request-log.d.ts +82 -0
  397. package/dist/services/run-log/request-log.js +69 -0
  398. package/dist/services/run-log/request-summary.d.ts +76 -0
  399. package/dist/services/run-log/request-summary.js +0 -0
  400. package/dist/services/run-log/run-log.d.ts +61 -0
  401. package/dist/services/run-log/run-log.js +102 -0
  402. package/dist/services/run-log/spec/log-query-service.spec.d.ts +1 -0
  403. package/dist/services/run-log/spec/log-query-service.spec.js +197 -0
  404. package/dist/services/run-log/spec/log-reader.spec.d.ts +1 -0
  405. package/dist/services/run-log/spec/log-reader.spec.js +109 -0
  406. package/dist/services/run-log/spec/log-summary.spec.d.ts +1 -0
  407. package/dist/services/run-log/spec/log-summary.spec.js +153 -0
  408. package/dist/services/run-log/spec/redaction.spec.d.ts +1 -0
  409. package/dist/services/run-log/spec/redaction.spec.js +61 -0
  410. package/dist/services/run-log/spec/request-log.spec.d.ts +1 -0
  411. package/dist/services/run-log/spec/request-log.spec.js +101 -0
  412. package/dist/services/run-log/spec/request-summary.spec.d.ts +1 -0
  413. package/dist/services/run-log/spec/request-summary.spec.js +171 -0
  414. package/dist/services/run-log/spec/run-log.spec.d.ts +1 -0
  415. package/dist/services/run-log/spec/run-log.spec.js +122 -0
  416. package/dist/services/run-registry/exit-classification.d.ts +39 -0
  417. package/dist/services/run-registry/exit-classification.js +42 -0
  418. package/dist/services/run-registry/index.d.ts +3 -0
  419. package/dist/services/run-registry/index.js +3 -0
  420. package/dist/services/run-registry/process-identity.d.ts +28 -0
  421. package/dist/services/run-registry/process-identity.js +80 -0
  422. package/dist/services/run-registry/run-registry-model.d.ts +128 -0
  423. package/dist/services/run-registry/run-registry-model.js +16 -0
  424. package/dist/services/run-registry/run-registry.d.ts +155 -0
  425. package/dist/services/run-registry/run-registry.js +430 -0
  426. package/dist/services/run-registry/spec/exit-classification.spec.d.ts +1 -0
  427. package/dist/services/run-registry/spec/exit-classification.spec.js +82 -0
  428. package/dist/services/run-registry/spec/run-registry.spec.d.ts +1 -0
  429. package/dist/services/run-registry/spec/run-registry.spec.js +526 -0
  430. package/dist/services/setup/os/tool-registry.js +2 -2
  431. package/oclif.manifest.json +3409 -288
  432. package/package.json +20 -2
@@ -0,0 +1,454 @@
1
+ import { expect } from "chai";
2
+ import { afterEach, beforeEach, describe, it } from "mocha";
3
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { BaqendResponse } from "../../../onboarding/browser/baqend-response.js";
7
+ import { Cache } from "../../../onboarding/request-cache/cache.js";
8
+ import { ControlServer } from "../../../onboarding/control/control-server.js";
9
+ import { META_FILE, } from "../../../run-registry/run-registry-model.js";
10
+ import { processStartToken } from "../../../run-registry/process-identity.js";
11
+ import { MemorySink } from "../../../cli/index.js";
12
+ import { memoryCli } from "../../../cli/spec/memory-cli.js";
13
+ import { ControlError } from "../../control-client.js";
14
+ import { RunCacheServiceFactory } from "../../cache/run-cache-service-factory.js";
15
+ /** The smallest FileListInterface a ControlServer needs. */
16
+ function fileList(files = []) {
17
+ return {
18
+ files,
19
+ hasFile: (name) => files.some((file) => file.name === name),
20
+ getByName: (name) => files.find((file) => file.name === name),
21
+ };
22
+ }
23
+ const DEAD_PID = 2_147_483_646;
24
+ /**
25
+ * The whole hop, with nothing faked in between: the factory resolves a run
26
+ * from the registry, opens its control socket, handshakes, and reads the cache
27
+ * a real ControlServer is serving.
28
+ */
29
+ describe("RunCacheService over the control socket", () => {
30
+ let cacheDirectory;
31
+ let controlServer;
32
+ let controller;
33
+ let cache;
34
+ const writeRun = (meta) => {
35
+ const full = {
36
+ customer: "example.com",
37
+ customerPath: "customers/example.com",
38
+ configName: "production",
39
+ pid: DEAD_PID,
40
+ startedAt: new Date().toISOString(),
41
+ status: "finished",
42
+ flags: {
43
+ local: true,
44
+ headless: false,
45
+ useTestConfig: false,
46
+ ignoreContentSecurityPolicy: false,
47
+ },
48
+ cliVersion: "0.0.0",
49
+ ...meta,
50
+ };
51
+ const dir = join(cacheDirectory, "runs", full.id);
52
+ mkdirSync(dir, { recursive: true });
53
+ writeFileSync(join(dir, META_FILE), JSON.stringify(full));
54
+ return dir;
55
+ };
56
+ /** A run that is live, and whose socket is actually being served. */
57
+ const liveRun = async (id, extra = {}) => {
58
+ const dir = writeRun({
59
+ id,
60
+ status: "running",
61
+ pid: process.pid,
62
+ startToken: processStartToken(process.pid) ?? undefined,
63
+ });
64
+ cache = new Cache(memoryCli(), join(dir, "dh-cache"));
65
+ controlServer = new ControlServer(dir, id, {
66
+ cache,
67
+ cli: memoryCli(),
68
+ files: fileList(),
69
+ ...extra,
70
+ });
71
+ controller = new AbortController();
72
+ await controlServer.listen(controller.signal);
73
+ return dir;
74
+ };
75
+ /** Run one op the way a command does, and capture what it said. */
76
+ const run = async (op, json) => {
77
+ const sink = new MemorySink();
78
+ const environment = {
79
+ cli: memoryCli(sink),
80
+ cacheDir: cacheDirectory,
81
+ };
82
+ await op(new RunCacheServiceFactory({
83
+ environment,
84
+ json,
85
+ input: {},
86
+ }).buildService());
87
+ return sink;
88
+ };
89
+ /** What `--json` prints. */
90
+ const answer = async (op) => {
91
+ const sink = await run(op, true);
92
+ expect(sink.lines, "nothing but the document on stdout").to.deep.equal([]);
93
+ return JSON.parse(sink.payloads.join(""));
94
+ };
95
+ /** How the op fails, as the command would report it. */
96
+ const failure = async (op) => {
97
+ try {
98
+ await run(op, true);
99
+ }
100
+ catch (error) {
101
+ const failed = ControlError.from(error);
102
+ expect(failed, String(error)).to.be.instanceOf(ControlError);
103
+ return failed;
104
+ }
105
+ expect.fail("the op should have failed");
106
+ };
107
+ beforeEach(() => {
108
+ cacheDirectory = mkdtempSync(join(tmpdir(), "sk-run-cache-"));
109
+ });
110
+ afterEach(async () => {
111
+ controller?.abort();
112
+ await controlServer?.close();
113
+ controlServer = undefined;
114
+ controller = undefined;
115
+ rmSync(cacheDirectory, { recursive: true, force: true });
116
+ });
117
+ it("should read the cache of a live run", async () => {
118
+ await liveRun("example.com-production-live");
119
+ cache.addEntry("https://myapp.app.baqend.com/v1/asset/https://shop.example.com/p?bqvariation=mobile", new BaqendResponse("<html>hi</html>", "text/html; charset=utf-8"), "<html>hi</html>");
120
+ const body = await answer((cache) => cache.list());
121
+ expect(body.run).to.equal("example.com-production-live");
122
+ const entries = body.entries;
123
+ expect(entries).to.have.lengthOf(1);
124
+ expect(entries[0].originUrl).to.equal("https://shop.example.com/p");
125
+ });
126
+ it("should print a summary and a table for a person", async () => {
127
+ await liveRun("example.com-production-live");
128
+ cache.addEntry("https://myapp.app.baqend.com/v1/asset/https://shop.example.com/p", new BaqendResponse("<html>hi</html>", "text/html; charset=utf-8"), "<html>hi</html>");
129
+ const sink = await run((cache) => cache.list(), false);
130
+ expect(sink.payloads).to.deep.equal([]);
131
+ expect(sink.lines[0]).to.equal("1 cached entry in example.com-production-live");
132
+ expect(sink.lines.join("\n")).to.contain("https://shop.example.com/p");
133
+ });
134
+ describe("get", () => {
135
+ const PAGE = [
136
+ "<html><head>",
137
+ '<script src="https://cdn.example.com/analytics.js"></script>',
138
+ '<script src="https://cdn.example.com/app.js"></script>',
139
+ "</head><body>",
140
+ '<div class="promo">buy</div>',
141
+ "<!-- setAssetList([1,2,3]) -->",
142
+ "</body></html>",
143
+ ].join("\n");
144
+ const cacheThePage = async () => {
145
+ await liveRun("example.com-production-live");
146
+ cache.addEntry("https://myapp.app.baqend.com/v1/asset/https://shop.example.com/p?bqvariation=mobile", new BaqendResponse(PAGE, "text/html; charset=utf-8"), PAGE);
147
+ };
148
+ it("should write the body to a file instead of printing it", async () => {
149
+ await cacheThePage();
150
+ const sink = await run((cache) => cache.get({ key: "shop.example.com/p" }), true);
151
+ const raw = sink.payloads.join("");
152
+ const { entry } = JSON.parse(raw);
153
+ // A cached page runs to megabytes; it belongs in a file, not on stdout.
154
+ expect(raw).to.not.contain("<html>");
155
+ expect(readFileSync(entry.bodyPath, "utf8")).to.equal(PAGE);
156
+ expect(entry.bytes).to.equal(PAGE.length);
157
+ expect(entry.bodySha).to.be.a("string").with.length(16);
158
+ });
159
+ it("should count what a selector matches, which is the actual question", async () => {
160
+ await cacheThePage();
161
+ const { entry } = (await answer((cache) => cache.get({
162
+ key: "shop.example.com/p",
163
+ select: 'script[src*="analytics"]',
164
+ })));
165
+ expect(entry.select.count).to.equal(1);
166
+ expect(entry.select.matches[0]).to.contain("analytics.js");
167
+ // And the summary leads with it, so the answer is the first thing read.
168
+ const sink = await run((cache) => cache.get({
169
+ key: "shop.example.com/p",
170
+ select: 'script[src*="analytics"]',
171
+ }), false);
172
+ expect(sink.lines[0]).to.contain('1 × script[src*="analytics"]');
173
+ });
174
+ it("should report zero matches as zero, not as an error", async () => {
175
+ await cacheThePage();
176
+ const { entry } = (await answer((cache) => cache.get({ key: "shop.example.com/p", select: "iframe" })));
177
+ // "The transform removed it" is a successful answer.
178
+ expect(entry.select.count).to.equal(0);
179
+ });
180
+ it("should grep what a selector cannot reach", async () => {
181
+ await cacheThePage();
182
+ const { entry } = (await answer((cache) => cache.get({ key: "shop.example.com/p", grep: "setAssetList\\(" })));
183
+ expect(entry.grep.count).to.equal(1);
184
+ expect(entry.grep.matches[0].line).to.equal(6);
185
+ });
186
+ it("should refuse a key that matches several entries", async () => {
187
+ await cacheThePage();
188
+ cache.addEntry("https://myapp.app.baqend.com/v1/asset/https://shop.example.com/p?bqvariation=desktop", new BaqendResponse(PAGE, "text/html; charset=utf-8"), PAGE);
189
+ const failed = await failure((cache) => cache.get({ key: "shop.example.com/p" }));
190
+ // Cache.removeEntry matches by substring and surprises people; here an
191
+ // ambiguous key names what it matched instead of picking one.
192
+ expect(failed.code).to.equal("AMBIGUOUS_CACHE_KEY");
193
+ expect(failed.detail.candidates).to.have.lengthOf(2);
194
+ });
195
+ it("should address a homepage by its own url", async () => {
196
+ // A site's homepage is a prefix of every url on the site, so a substring
197
+ // search for it matches the whole cache — and the one entry a caller can
198
+ // actually name becomes the one they cannot reach.
199
+ await liveRun("example.com-production-live");
200
+ const home = "https://myapp.app.baqend.com/v1/asset/https://shop.example.com/";
201
+ cache.addEntry(home, new BaqendResponse(PAGE, "text/html"), PAGE);
202
+ for (const path of ["about", "products", "contact"]) {
203
+ cache.addEntry(`${home}${path}`, new BaqendResponse(PAGE, "text/html"), PAGE);
204
+ }
205
+ const { entry } = (await answer((cache) => cache.get({ key: "https://shop.example.com/" })));
206
+ expect(entry.originUrl).to.equal("https://shop.example.com/");
207
+ });
208
+ it("should say when a refusal listed fewer candidates than it matched", async () => {
209
+ await cacheThePage();
210
+ for (let index = 0; index < 14; index++) {
211
+ cache.addEntry(`https://myapp.app.baqend.com/v1/asset/https://shop.example.com/p?bqvariation=v${index}`, new BaqendResponse(PAGE, "text/html"), PAGE);
212
+ }
213
+ const failed = await failure((cache) => cache.get({ key: "shop.example.com/p?" }));
214
+ expect(failed.code).to.equal("AMBIGUOUS_CACHE_KEY");
215
+ // A list shorter than the count, without saying so, reads as the whole
216
+ // list — `select` and `grep` say it, so this should too.
217
+ expect(failed.detail.truncated).to.equal(true);
218
+ expect(failed.detail.total).to.equal(15); // the 14 here plus the one cacheThePage added
219
+ expect(failed.detail.candidates).to.have.lengthOf(10);
220
+ });
221
+ it("should say when nothing matches the key", async () => {
222
+ await cacheThePage();
223
+ const failed = await failure((cache) => cache.get({ key: "nowhere.example.com" }));
224
+ expect(failed.code).to.equal("NO_SUCH_CACHE_ENTRY");
225
+ });
226
+ it("should report a bad selector without failing the read", async () => {
227
+ await cacheThePage();
228
+ const { entry } = (await answer((cache) => cache.get({ key: "shop.example.com/p", select: "((" })));
229
+ expect(entry.select.error).to.be.a("string");
230
+ expect(entry.bodyPath).to.be.a("string");
231
+ });
232
+ });
233
+ it("should say the cache is gone with the process, not pretend it is empty", async () => {
234
+ writeRun({ id: "example.com-production-done" });
235
+ const failed = await failure((cache) => cache.list());
236
+ expect(failed.code).to.equal("NO_LIVE_RUN");
237
+ // The bodies are still on disk, and that is worth knowing.
238
+ expect(failed.message).to.contain("dh-cache");
239
+ });
240
+ it("should name the candidates rather than guess between live runs", async () => {
241
+ await liveRun("a-production-live");
242
+ writeRun({
243
+ id: "b-production-live",
244
+ status: "running",
245
+ pid: process.pid,
246
+ startToken: processStartToken(process.pid) ?? undefined,
247
+ });
248
+ const failed = await failure((cache) => cache.list());
249
+ expect(failed.code).to.equal("AMBIGUOUS_RUN");
250
+ expect(failed.detail.candidates).to.have.lengthOf(2);
251
+ });
252
+ it("should report a live run whose socket was never opened", async () => {
253
+ writeRun({
254
+ id: "example.com-production-nosocket",
255
+ status: "running",
256
+ pid: process.pid,
257
+ startToken: processStartToken(process.pid) ?? undefined,
258
+ });
259
+ const failed = await failure((cache) => cache.list());
260
+ // A run from a build before the socket existed, or one whose listen failed.
261
+ expect(failed.code).to.equal("NO_CONTROL_SOCKET");
262
+ });
263
+ describe("prewarm", () => {
264
+ const APP_ASSET = "https://myapp.app.baqend.com/v1/asset/";
265
+ /**
266
+ * Stands in for `VirtualOrestesApp.prewarm`: builds the key the real one
267
+ * builds, and caches a body that names the variation so two of them are
268
+ * distinguishable by content rather than only by key.
269
+ */
270
+ const builder = (fails = []) => async (originUrl, variation) => {
271
+ if (fails.includes(variation)) {
272
+ throw new Error(`transform threw for ${variation}`);
273
+ }
274
+ const key = variation === "default"
275
+ ? `${APP_ASSET}${originUrl}`
276
+ : `${APP_ASSET}${originUrl}${originUrl.includes("?") ? "&" : "?"}bqvariation=${variation}`;
277
+ const body = `<html>${variation}</html>`;
278
+ cache.addEntry(key, new BaqendResponse(body, "text/html; charset=utf-8"), body);
279
+ return key;
280
+ };
281
+ it("should build every requested variation into its own file", async () => {
282
+ await liveRun("example.com-production-live", {
283
+ prewarm: builder(),
284
+ origin: "https://shop.example.com",
285
+ });
286
+ const body = await answer((cache) => cache.prewarm({ url: "/p", variations: ["default", "mobile"] }));
287
+ const entries = body.entries;
288
+ // The relative url resolved against the run's origin, and said so.
289
+ expect(body.url).to.equal("https://shop.example.com/p");
290
+ expect(entries).to.have.length(2);
291
+ expect(entries.map((entry) => entry.variation)).to.deep.equal([
292
+ null,
293
+ "mobile",
294
+ ]);
295
+ expect(entries.every((entry) => entry.built)).to.equal(true);
296
+ // Two files, not one — the whole point is that they can be diffed.
297
+ const [plain, mobile] = entries;
298
+ expect(plain.bodyPath).to.not.equal(mobile.bodyPath);
299
+ expect(readFileSync(plain.bodyPath, "utf8")).to.equal("<html>default</html>");
300
+ expect(readFileSync(mobile.bodyPath, "utf8")).to.equal("<html>mobile</html>");
301
+ });
302
+ it("should keep a query parameter, where the service worker would strip it", async () => {
303
+ await liveRun("example.com-production-live", {
304
+ prewarm: builder(),
305
+ origin: "https://shop.example.com",
306
+ });
307
+ for (const url of ["/p", "/p?colour=red"]) {
308
+ await run((cache) => cache.prewarm({ url }), true);
309
+ }
310
+ const listed = await answer((cache) => cache.list());
311
+ // Two entries, because the parameter is part of the identity here. The
312
+ // worker strips it before an asset request exists, so browsing can only
313
+ // ever produce one of these.
314
+ expect(listed.entries.map((entry) => entry.originUrl)).to.deep.equal([
315
+ "https://shop.example.com/p",
316
+ "https://shop.example.com/p?colour=red",
317
+ ]);
318
+ });
319
+ it("should build with --all what the page produced and the config names, not tablet", async () => {
320
+ // illy never produces tablet, and an SSR build for it is one nobody reads.
321
+ await liveRun("example.com-production-live", {
322
+ prewarm: builder(),
323
+ variations: () => ["campaign-a"],
324
+ origin: "https://shop.example.com",
325
+ });
326
+ await builder()("https://shop.example.com/", "mobile");
327
+ const body = await answer((cache) => cache.prewarm({ url: "/p", all: true }));
328
+ expect(body.entries.map((entry) => entry.variation ?? "default")).to.deep.equal(["default", "mobile", "campaign-a"]);
329
+ });
330
+ it("should report one variation failing without losing the others", async () => {
331
+ await liveRun("example.com-production-live", {
332
+ prewarm: builder(["mobile"]),
333
+ origin: "https://shop.example.com",
334
+ });
335
+ const body = await answer((cache) => cache.prewarm({ url: "/p", variations: ["default", "mobile"] }));
336
+ expect(body.entries).to.have.length(1);
337
+ expect(body.failed).to.deep.equal([
338
+ { variation: "mobile", error: "transform threw for mobile" },
339
+ ]);
340
+ });
341
+ it("should say a run without a local cache has nothing to build with", async () => {
342
+ await liveRun("example.com-production-live", {
343
+ origin: "https://shop.example.com",
344
+ });
345
+ const failed = await failure((cache) => cache.prewarm({ url: "/p" }));
346
+ expect(failed.code).to.equal("NO_LOCAL_CACHE");
347
+ });
348
+ it("should not build twice when an entry is already cached", async () => {
349
+ await liveRun("example.com-production-live", {
350
+ prewarm: builder(),
351
+ origin: "https://shop.example.com",
352
+ });
353
+ await run((cache) => cache.prewarm({ url: "/p" }), true);
354
+ const again = await answer((cache) => cache.prewarm({ url: "/p" }));
355
+ expect(again.entries[0], "second call found it already there").to.include({ built: false, alreadyCached: true });
356
+ });
357
+ });
358
+ describe("clear, evict and errors", () => {
359
+ const ASSET = "https://myapp.app.baqend.com/v1/asset/";
360
+ const cacheTwo = async () => {
361
+ await liveRun("example.com-production-live");
362
+ for (const path of ["/p", "/p/detail"]) {
363
+ const body = `<html>${path}</html>`;
364
+ cache.addEntry(`${ASSET}https://shop.example.com${path}`, new BaqendResponse(body, "text/html; charset=utf-8"), body);
365
+ }
366
+ };
367
+ it("should report how many entries a clear dropped", async () => {
368
+ await cacheTwo();
369
+ const body = await answer((cache) => cache.clear());
370
+ expect(body.cleared).to.equal(2);
371
+ const after = await answer((cache) => cache.list());
372
+ expect(after.entries).to.deep.equal([]);
373
+ });
374
+ // The substring match is the surprise this op has to surface: "/p" is a
375
+ // prefix of "/p/detail", so asking to evict one takes both. The point of
376
+ // the test is that the answer says so rather than reporting the one key
377
+ // the caller had in mind.
378
+ it("should name every key a substring evict actually removed", async () => {
379
+ await cacheTwo();
380
+ const body = await answer((cache) => cache.evict("shop.example.com/p"));
381
+ expect(body.removed).to.have.length(2);
382
+ expect(body.remaining).to.equal(0);
383
+ });
384
+ it("should refuse an evict that matched nothing", async () => {
385
+ await cacheTwo();
386
+ const failed = await failure((cache) => cache.evict("nothing-like-this"));
387
+ expect(failed.code).to.equal("NO_SUCH_CACHE_ENTRY");
388
+ });
389
+ it("should list the urls the documentHandler could not build", async () => {
390
+ await liveRun("example.com-production-live", {
391
+ cacheErrors: () => [
392
+ {
393
+ url: "https://shop.example.com/p",
394
+ assetUrl: `${ASSET}https://shop.example.com/p`,
395
+ variation: "mobile",
396
+ error: "transform threw",
397
+ stack: null,
398
+ occurredAt: new Date(0).toISOString(),
399
+ },
400
+ ],
401
+ });
402
+ const body = await answer((cache) => cache.errors());
403
+ expect(body.errors[0].variation).to.equal("mobile");
404
+ });
405
+ it("should say a run without a local cache records no build failures", async () => {
406
+ await liveRun("example.com-production-live");
407
+ const failed = await failure((cache) => cache.errors());
408
+ expect(failed.code).to.equal("NO_LOCAL_CACHE");
409
+ });
410
+ });
411
+ describe("refresh", () => {
412
+ const ASSET = "https://myapp.app.baqend.com/v1/asset/";
413
+ const KEY = `${ASSET}https://shop.example.com/p`;
414
+ /** Rebuilds the one entry, with whatever body the test asks for next. */
415
+ const rebuilder = (bodies) => async () => {
416
+ const body = bodies.shift();
417
+ cache.addEntry(KEY, new BaqendResponse(body, "text/html; charset=utf-8"), body);
418
+ return KEY;
419
+ };
420
+ it("should report that the origin changed when the bytes differ", async () => {
421
+ await liveRun("example.com-production-live", {
422
+ prewarm: rebuilder(["<html>new</html>"]),
423
+ origin: "https://shop.example.com",
424
+ });
425
+ cache.addEntry(KEY, new BaqendResponse("<html>old</html>", "text/html; charset=utf-8"), "<html>old</html>");
426
+ const body = await answer((cache) => cache.refresh());
427
+ expect(body.changed).to.equal(1);
428
+ const [entry] = body.entries;
429
+ expect(entry.changed).to.equal(true);
430
+ expect(entry.previousSha, "the hash it replaced").to.be.a("string");
431
+ });
432
+ // The answer this op exists for, and the one that is easy to get wrong:
433
+ // rebuilding always replaces the entry, so "it was rebuilt" must not be
434
+ // reported as "it changed".
435
+ it("should report no change when the origin serves the same bytes", async () => {
436
+ await liveRun("example.com-production-live", {
437
+ prewarm: rebuilder(["<html>same</html>"]),
438
+ origin: "https://shop.example.com",
439
+ });
440
+ cache.addEntry(KEY, new BaqendResponse("<html>same</html>", "text/html; charset=utf-8"), "<html>same</html>");
441
+ const body = await answer((cache) => cache.refresh());
442
+ expect(body.changed).to.equal(0);
443
+ expect(body.entries[0].changed).to.equal(false);
444
+ });
445
+ it("should refuse to refresh an empty cache", async () => {
446
+ await liveRun("example.com-production-live", {
447
+ prewarm: rebuilder([]),
448
+ origin: "https://shop.example.com",
449
+ });
450
+ const failed = await failure((cache) => cache.refresh());
451
+ expect(failed.code).to.equal("NO_SUCH_CACHE_ENTRY");
452
+ });
453
+ });
454
+ });
@@ -0,0 +1,113 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { expect } from "chai";
3
+ import { afterEach, beforeEach, describe, it } from "mocha";
4
+ import { ServiceWorkerTracker } from "../../../onboarding/control/service-worker-tracker.js";
5
+ import { PreloadRegistry } from "../../../onboarding/control/preload-registry.js";
6
+ import { DebugSession, } from "../../../onboarding/control/debug-session.js";
7
+ import { inertBrowserCapabilities, inertBrowserTransport, } from "../../../onboarding/spec/control/fakes.js";
8
+ import { RunDebugServiceFactory } from "../../debug/run-debug-service-factory.js";
9
+ import { LiveRunFixture, answer, failure, summary, } from "../live-run-fixture.js";
10
+ /**
11
+ * A browser whose page never pauses.
12
+ *
13
+ * The debugger's own behaviour is DebugSession's and specced there. What is
14
+ * under test here is that the four steps of a session — arm, await, eval,
15
+ * resume — work as four separate commands, each its own connection, with the
16
+ * state held by the run in between.
17
+ */
18
+ class QuietBrowser {
19
+ serviceWorkers = new ServiceWorkerTracker();
20
+ preloads = new PreloadRegistry(inertBrowserTransport());
21
+ /** What the page was asked to evaluate, and answers 2 to all of it. */
22
+ evaluated = [];
23
+ debug = new DebugSession({
24
+ ...inertBrowserTransport(),
25
+ send: (async (method, params) => {
26
+ if (method === "Runtime.evaluate" && params?.expression) {
27
+ this.evaluated.push(params.expression);
28
+ return { result: { type: "number", value: 2 } };
29
+ }
30
+ return undefined;
31
+ }),
32
+ }, this.preloads);
33
+ available = true;
34
+ rest = inertBrowserCapabilities();
35
+ resize = this.rest.resize;
36
+ clearResize = this.rest.clearResize;
37
+ collectDocumentRequests = this.rest.collectDocumentRequests;
38
+ reload = this.rest.reload;
39
+ emulate = this.rest.emulate;
40
+ screenshot = this.rest.screenshot;
41
+ tabs = this.rest.tabs;
42
+ click = this.rest.click;
43
+ rawCdp = this.rest.rawCdp;
44
+ async tab() {
45
+ return this;
46
+ }
47
+ url() {
48
+ return "https://shop.example.com/p";
49
+ }
50
+ async evaluate() {
51
+ return undefined;
52
+ }
53
+ async state() {
54
+ return { url: this.url(), serviceWorkers: this.serviceWorkers.state(null) };
55
+ }
56
+ async reset() {
57
+ return { url: this.url(), did: "reset" };
58
+ }
59
+ async reinstallServiceWorker() {
60
+ return { url: this.url(), did: "reinstalled" };
61
+ }
62
+ async navigate(url) {
63
+ return { url, did: `navigated to ${url}` };
64
+ }
65
+ async showPanel() {
66
+ return { url: null, did: "showed the panel" };
67
+ }
68
+ }
69
+ describe("RunDebugService over the control socket", () => {
70
+ let fixture;
71
+ let browser;
72
+ const debugOp = (op) => (sink, json) => op(new RunDebugServiceFactory(fixture.context(sink, json, {})).buildService());
73
+ beforeEach(async () => {
74
+ fixture = new LiveRunFixture();
75
+ browser = new QuietBrowser();
76
+ await fixture.serve("example.com-production-live", { session: browser });
77
+ });
78
+ afterEach(() => fixture.close());
79
+ it("should keep what one command armed for the next to see", async () => {
80
+ await answer(debugOp((debug) => debug.arm({ bps: [1, 3], then: "none" })));
81
+ const status = (await answer(debugOp((debug) => debug.status())));
82
+ expect(status.armed).to.deep.equal([1, 3]);
83
+ });
84
+ it("should say an armed breakpoint waits for the next load", async () => {
85
+ // Arming without loading again is the mistake that reads as a broken
86
+ // breakpoint, so the answer to `arm --then none` says it.
87
+ const line = await summary(debugOp((debug) => debug.arm({ bps: [2], then: "none" })));
88
+ expect(line).to.contain("BP2 armed");
89
+ expect(line).to.contain("nothing will pause until the page loads again");
90
+ });
91
+ it("should answer a wait that nothing ended, rather than time out the socket", async () => {
92
+ await answer(debugOp((debug) => debug.arm({ then: "none" })));
93
+ const data = (await answer(debugOp((debug) => debug.awaitPause(50))));
94
+ expect(data.fired).to.equal(false);
95
+ expect(data.timedOut).to.equal(true);
96
+ });
97
+ it("should read the expression from --file", async () => {
98
+ const file = `${fixture.cacheDirectory}/probe.js`;
99
+ writeFileSync(file, "1 + 1");
100
+ const data = (await answer(debugOp((debug) => debug.eval({ file }))));
101
+ expect(browser.evaluated).to.deep.equal(["1 + 1"]);
102
+ expect(data.value).to.equal(2);
103
+ expect(data.onCallFrame).to.equal(false);
104
+ });
105
+ it("should refuse an expression and --file together", async () => {
106
+ const failed = await failure(debugOp((debug) => debug.eval({ expression: "1", file: "x.js" })));
107
+ expect(failed.code).to.equal("EXPRESSION_REQUIRED");
108
+ });
109
+ it("should say which file it could not read", async () => {
110
+ const failed = await failure(debugOp((debug) => debug.eval({ file: "/nowhere/probe.js" })));
111
+ expect(failed.code).to.equal("NO_SUCH_FILE");
112
+ });
113
+ });