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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (406) hide show
  1. package/README.md +1369 -10
  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 +6 -1
  6. package/dist/commands/diff.js +9 -3
  7. package/dist/commands/onboarding/browser/click.d.ts +75 -0
  8. package/dist/commands/onboarding/browser/click.js +19 -0
  9. package/dist/commands/onboarding/browser/emulate.d.ts +93 -0
  10. package/dist/commands/onboarding/browser/emulate.js +23 -0
  11. package/dist/commands/onboarding/browser/navigate.d.ts +67 -0
  12. package/dist/commands/onboarding/browser/navigate.js +18 -0
  13. package/dist/commands/onboarding/browser/panel.d.ts +63 -0
  14. package/dist/commands/onboarding/browser/panel.js +12 -0
  15. package/dist/commands/onboarding/browser/reinstall-sw.d.ts +63 -0
  16. package/dist/commands/onboarding/browser/reinstall-sw.js +14 -0
  17. package/dist/commands/onboarding/browser/reset.d.ts +71 -0
  18. package/dist/commands/onboarding/browser/reset.js +18 -0
  19. package/dist/commands/onboarding/browser/screenshot.d.ts +77 -0
  20. package/dist/commands/onboarding/browser/screenshot.js +19 -0
  21. package/dist/commands/onboarding/browser/state.d.ts +63 -0
  22. package/dist/commands/onboarding/browser/state.js +12 -0
  23. package/dist/commands/onboarding/browser/tabs.d.ts +58 -0
  24. package/dist/commands/onboarding/browser/tabs.js +16 -0
  25. package/dist/commands/onboarding/cache/clear.d.ts +58 -0
  26. package/dist/commands/onboarding/cache/clear.js +12 -0
  27. package/dist/commands/onboarding/cache/errors.d.ts +58 -0
  28. package/dist/commands/onboarding/cache/errors.js +12 -0
  29. package/dist/commands/onboarding/cache/evict.d.ts +62 -0
  30. package/dist/commands/onboarding/cache/evict.js +15 -0
  31. package/dist/commands/onboarding/cache/get.d.ts +85 -0
  32. package/dist/commands/onboarding/cache/get.js +17 -0
  33. package/dist/commands/onboarding/cache/list.d.ts +58 -0
  34. package/dist/commands/onboarding/cache/list.js +15 -0
  35. package/dist/commands/onboarding/cache/prewarm.d.ts +73 -0
  36. package/dist/commands/onboarding/cache/prewarm.js +20 -0
  37. package/dist/commands/onboarding/cache/refresh.d.ts +62 -0
  38. package/dist/commands/onboarding/cache/refresh.js +18 -0
  39. package/dist/commands/onboarding/cdp.d.ts +81 -0
  40. package/dist/commands/onboarding/cdp.js +18 -0
  41. package/dist/commands/onboarding/debug/arm.d.ts +77 -0
  42. package/dist/commands/onboarding/debug/arm.js +18 -0
  43. package/dist/commands/onboarding/debug/await.d.ts +71 -0
  44. package/dist/commands/onboarding/debug/await.js +18 -0
  45. package/dist/commands/onboarding/debug/disarm.d.ts +63 -0
  46. package/dist/commands/onboarding/debug/disarm.js +12 -0
  47. package/dist/commands/onboarding/debug/eval.d.ts +75 -0
  48. package/dist/commands/onboarding/debug/eval.js +16 -0
  49. package/dist/commands/onboarding/debug/release.d.ts +63 -0
  50. package/dist/commands/onboarding/debug/release.js +12 -0
  51. package/dist/commands/onboarding/debug/resume.d.ts +63 -0
  52. package/dist/commands/onboarding/debug/resume.js +12 -0
  53. package/dist/commands/onboarding/debug/status.d.ts +63 -0
  54. package/dist/commands/onboarding/debug/status.js +12 -0
  55. package/dist/commands/onboarding/debug/step.d.ts +67 -0
  56. package/dist/commands/onboarding/debug/step.js +15 -0
  57. package/dist/commands/onboarding/files/list.d.ts +58 -0
  58. package/dist/commands/onboarding/files/list.js +12 -0
  59. package/dist/commands/onboarding/files/read.d.ts +73 -0
  60. package/dist/commands/onboarding/files/read.js +16 -0
  61. package/dist/commands/onboarding/files/rebuild.d.ts +63 -0
  62. package/dist/commands/onboarding/files/rebuild.js +18 -0
  63. package/dist/commands/onboarding/files/validate.d.ts +58 -0
  64. package/dist/commands/onboarding/files/validate.js +12 -0
  65. package/dist/commands/onboarding/fouc.d.ts +77 -0
  66. package/dist/commands/onboarding/fouc.js +16 -0
  67. package/dist/commands/onboarding/inject/add.d.ts +89 -0
  68. package/dist/commands/onboarding/inject/add.js +17 -0
  69. package/dist/commands/onboarding/inject/clear.d.ts +63 -0
  70. package/dist/commands/onboarding/inject/clear.js +12 -0
  71. package/dist/commands/onboarding/inject/list.d.ts +63 -0
  72. package/dist/commands/onboarding/inject/list.js +12 -0
  73. package/dist/commands/onboarding/inject/read.d.ts +75 -0
  74. package/dist/commands/onboarding/inject/read.js +18 -0
  75. package/dist/commands/onboarding/inject/recipes.d.ts +63 -0
  76. package/dist/commands/onboarding/inject/recipes.js +12 -0
  77. package/dist/commands/onboarding/inject/remove.d.ts +67 -0
  78. package/dist/commands/onboarding/inject/remove.js +15 -0
  79. package/dist/commands/onboarding/list.d.ts +13 -0
  80. package/dist/commands/onboarding/list.js +12 -0
  81. package/dist/commands/onboarding/logs.d.ts +41 -0
  82. package/dist/commands/onboarding/logs.js +256 -0
  83. package/dist/commands/onboarding/navwalk.d.ts +95 -0
  84. package/dist/commands/onboarding/navwalk.js +19 -0
  85. package/dist/commands/onboarding/response.d.ts +67 -0
  86. package/dist/commands/onboarding/response.js +18 -0
  87. package/dist/commands/onboarding/rum/beacons.d.ts +75 -0
  88. package/dist/commands/onboarding/rum/beacons.js +16 -0
  89. package/dist/commands/onboarding/rum/get.d.ts +77 -0
  90. package/dist/commands/onboarding/rum/get.js +18 -0
  91. package/dist/commands/onboarding/rum/key.d.ts +67 -0
  92. package/dist/commands/onboarding/rum/key.js +13 -0
  93. package/dist/commands/onboarding/rum/previous.d.ts +63 -0
  94. package/dist/commands/onboarding/rum/previous.js +12 -0
  95. package/dist/commands/onboarding/status.d.ts +13 -0
  96. package/dist/commands/onboarding/status.js +17 -0
  97. package/dist/commands/onboarding/todo.d.ts +58 -0
  98. package/dist/commands/onboarding/todo.js +12 -0
  99. package/dist/commands/onboarding/viewport.d.ts +101 -0
  100. package/dist/commands/onboarding/viewport.js +18 -0
  101. package/dist/commands/onboarding/watch.d.ts +93 -0
  102. package/dist/commands/onboarding/watch.js +16 -0
  103. package/dist/commands/onboarding.d.ts +26 -0
  104. package/dist/commands/onboarding.js +220 -3
  105. package/dist/commands/origin-request.d.ts +4 -0
  106. package/dist/commands/origin-request.js +4 -0
  107. package/dist/commands/spec/onboarding.spec.d.ts +1 -0
  108. package/dist/commands/spec/onboarding.spec.js +127 -0
  109. package/dist/services/cli/build-info.d.ts +33 -0
  110. package/dist/services/cli/build-info.js +63 -0
  111. package/dist/services/cli/cli-environment-factory.d.ts +3 -0
  112. package/dist/services/cli/cli-environment-factory.js +1 -0
  113. package/dist/services/cli/cli-service-build-context.d.ts +3 -0
  114. package/dist/services/cli/cli-service-factory.js +1 -1
  115. package/dist/services/cli/cli-service-model.d.ts +29 -10
  116. package/dist/services/cli/cli-service.d.ts +60 -11
  117. package/dist/services/cli/cli-service.js +196 -32
  118. package/dist/services/cli/index.d.ts +2 -0
  119. package/dist/services/cli/index.js +2 -0
  120. package/dist/services/cli/sink.d.ts +47 -0
  121. package/dist/services/cli/sink.js +31 -0
  122. package/dist/services/cli/spec/build-identity.spec.d.ts +1 -0
  123. package/dist/services/cli/spec/build-identity.spec.js +85 -0
  124. package/dist/services/cli/spec/build-info.spec.d.ts +1 -0
  125. package/dist/services/cli/spec/build-info.spec.js +10 -0
  126. package/dist/services/cli/spec/cli-service-log.spec.d.ts +1 -0
  127. package/dist/services/cli/spec/cli-service-log.spec.js +133 -0
  128. package/dist/services/cli/spec/cli-service.spec.js +113 -50
  129. package/dist/services/cli/spec/memory-cli.d.ts +9 -0
  130. package/dist/services/cli/spec/memory-cli.js +9 -0
  131. package/dist/services/diff/config-at-ref.d.ts +20 -0
  132. package/dist/services/diff/config-at-ref.js +33 -0
  133. package/dist/services/diff/diff-service-build-context.d.ts +8 -0
  134. package/dist/services/diff/diff-service-build-context.js +40 -1
  135. package/dist/services/diff/diff-service-factory.d.ts +2 -0
  136. package/dist/services/diff/diff-service-factory.js +48 -20
  137. package/dist/services/diff/diff-service.d.ts +11 -0
  138. package/dist/services/diff/diff-service.js +37 -11
  139. package/dist/services/diff/page-source.d.ts +12 -0
  140. package/dist/services/diff/page-source.js +16 -11
  141. package/dist/services/diff/sinks/tool-diff-sink.d.ts +3 -2
  142. package/dist/services/diff/sinks/tool-diff-sink.js +3 -2
  143. package/dist/services/diff/spec/config-at-ref.spec.d.ts +1 -0
  144. package/dist/services/diff/spec/config-at-ref.spec.js +46 -0
  145. package/dist/services/diff/spec/diff-service-build-context.spec.js +19 -0
  146. package/dist/services/diff/spec/diff-service.spec.js +95 -0
  147. package/dist/services/git/git-repository.d.ts +2 -0
  148. package/dist/services/git/git-repository.js +6 -0
  149. package/dist/services/integration-api/customer-config-flags.js +1 -0
  150. package/dist/services/onboarding/browser/baqend-response.d.ts +17 -1
  151. package/dist/services/onboarding/browser/baqend-response.js +23 -0
  152. package/dist/services/onboarding/browser/console-log.d.ts +9 -0
  153. package/dist/services/onboarding/browser/console-log.js +27 -0
  154. package/dist/services/onboarding/browser/executable/executable-validator.js +4 -2
  155. package/dist/services/onboarding/browser/extension/extension-bridge.js +5 -3
  156. package/dist/services/onboarding/browser/extension/extension-downloader.js +17 -8
  157. package/dist/services/onboarding/browser/extension/extension-validator.js +9 -4
  158. package/dist/services/onboarding/control/body-inspect.d.ts +24 -0
  159. package/dist/services/onboarding/control/body-inspect.js +106 -0
  160. package/dist/services/onboarding/control/browser-session.d.ts +521 -0
  161. package/dist/services/onboarding/control/browser-session.js +1273 -0
  162. package/dist/services/onboarding/control/config-validation.d.ts +17 -0
  163. package/dist/services/onboarding/control/config-validation.js +46 -0
  164. package/dist/services/onboarding/control/control-protocol.d.ts +1390 -0
  165. package/dist/services/onboarding/control/control-protocol.js +69 -0
  166. package/dist/services/onboarding/control/control-server.d.ts +284 -0
  167. package/dist/services/onboarding/control/control-server.js +1609 -0
  168. package/dist/services/onboarding/control/debug-session.d.ts +190 -0
  169. package/dist/services/onboarding/control/debug-session.js +801 -0
  170. package/dist/services/onboarding/control/fouc.d.ts +23 -0
  171. package/dist/services/onboarding/control/fouc.js +151 -0
  172. package/dist/services/onboarding/control/index.d.ts +4 -0
  173. package/dist/services/onboarding/control/index.js +4 -0
  174. package/dist/services/onboarding/control/navwalk.d.ts +65 -0
  175. package/dist/services/onboarding/control/navwalk.js +248 -0
  176. package/dist/services/onboarding/control/preload-registry.d.ts +150 -0
  177. package/dist/services/onboarding/control/preload-registry.js +829 -0
  178. package/dist/services/onboarding/control/response-explainer.d.ts +24 -0
  179. package/dist/services/onboarding/control/response-explainer.js +257 -0
  180. package/dist/services/onboarding/control/rum.d.ts +8 -0
  181. package/dist/services/onboarding/control/rum.js +220 -0
  182. package/dist/services/onboarding/control/service-worker-tracker.d.ts +68 -0
  183. package/dist/services/onboarding/control/service-worker-tracker.js +119 -0
  184. package/dist/services/onboarding/control/viewport.d.ts +45 -0
  185. package/dist/services/onboarding/control/viewport.js +344 -0
  186. package/dist/services/onboarding/control/watch.d.ts +26 -0
  187. package/dist/services/onboarding/control/watch.js +149 -0
  188. package/dist/services/onboarding/dashboard/diff-against-current-page.js +3 -1
  189. package/dist/services/onboarding/dashboard/index.js +7 -2
  190. package/dist/services/onboarding/fetch-event-handler.d.ts +24 -5
  191. package/dist/services/onboarding/fetch-event-handler.js +94 -32
  192. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +11 -2
  193. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +14 -0
  194. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +30 -0
  195. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +13 -0
  196. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +28 -1
  197. package/dist/services/onboarding/file-events/file-watcher.d.ts +42 -1
  198. package/dist/services/onboarding/file-events/file-watcher.js +117 -12
  199. package/dist/services/onboarding/onboarding-model.d.ts +30 -0
  200. package/dist/services/onboarding/onboarding-model.js +10 -0
  201. package/dist/services/onboarding/onboarding-service-build-context.d.ts +4 -0
  202. package/dist/services/onboarding/onboarding-service-build-context.js +6 -0
  203. package/dist/services/onboarding/onboarding-service-factory.d.ts +17 -1
  204. package/dist/services/onboarding/onboarding-service-factory.js +131 -17
  205. package/dist/services/onboarding/onboarding-service.d.ts +40 -1
  206. package/dist/services/onboarding/onboarding-service.js +135 -22
  207. package/dist/services/onboarding/request-cache/asset-key.d.ts +61 -0
  208. package/dist/services/onboarding/request-cache/asset-key.js +115 -0
  209. package/dist/services/onboarding/request-cache/cache.d.ts +62 -5
  210. package/dist/services/onboarding/request-cache/cache.js +128 -17
  211. package/dist/services/onboarding/spec/browser/console-log.spec.d.ts +1 -0
  212. package/dist/services/onboarding/spec/browser/console-log.spec.js +42 -0
  213. package/dist/services/onboarding/spec/control/browser-session.spec.d.ts +1 -0
  214. package/dist/services/onboarding/spec/control/browser-session.spec.js +526 -0
  215. package/dist/services/onboarding/spec/control/control-server.spec.d.ts +1 -0
  216. package/dist/services/onboarding/spec/control/control-server.spec.js +338 -0
  217. package/dist/services/onboarding/spec/control/debug-session.spec.d.ts +1 -0
  218. package/dist/services/onboarding/spec/control/debug-session.spec.js +693 -0
  219. package/dist/services/onboarding/spec/control/fakes.d.ts +31 -0
  220. package/dist/services/onboarding/spec/control/fakes.js +66 -0
  221. package/dist/services/onboarding/spec/control/fouc.spec.d.ts +1 -0
  222. package/dist/services/onboarding/spec/control/fouc.spec.js +167 -0
  223. package/dist/services/onboarding/spec/control/navwalk.spec.d.ts +1 -0
  224. package/dist/services/onboarding/spec/control/navwalk.spec.js +222 -0
  225. package/dist/services/onboarding/spec/control/preload-registry.spec.d.ts +1 -0
  226. package/dist/services/onboarding/spec/control/preload-registry.spec.js +432 -0
  227. package/dist/services/onboarding/spec/control/response-explainer.spec.d.ts +1 -0
  228. package/dist/services/onboarding/spec/control/response-explainer.spec.js +324 -0
  229. package/dist/services/onboarding/spec/control/rum.spec.d.ts +1 -0
  230. package/dist/services/onboarding/spec/control/rum.spec.js +222 -0
  231. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.d.ts +1 -0
  232. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.js +193 -0
  233. package/dist/services/onboarding/spec/control/viewport.spec.d.ts +1 -0
  234. package/dist/services/onboarding/spec/control/viewport.spec.js +200 -0
  235. package/dist/services/onboarding/spec/control/watch.spec.d.ts +1 -0
  236. package/dist/services/onboarding/spec/control/watch.spec.js +172 -0
  237. package/dist/services/onboarding/spec/fetch-event-handler.spec.d.ts +1 -0
  238. package/dist/services/onboarding/spec/fetch-event-handler.spec.js +202 -0
  239. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.d.ts +1 -0
  240. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.js +41 -0
  241. package/dist/services/onboarding/spec/onboarding-model.spec.js +37 -0
  242. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +1 -0
  243. package/dist/services/onboarding/spec/request-cache/cache.spec.d.ts +1 -0
  244. package/dist/services/onboarding/spec/request-cache/cache.spec.js +107 -0
  245. package/dist/services/onboarding/spec/todo-collector.spec.d.ts +1 -0
  246. package/dist/services/onboarding/spec/todo-collector.spec.js +136 -0
  247. package/dist/services/onboarding/todo-collector.d.ts +7 -2
  248. package/dist/services/onboarding/todo-collector.js +49 -12
  249. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +34 -0
  250. package/dist/services/onboarding/virtual-orestes-app/index.js +82 -27
  251. package/dist/services/origin-request/asset-variations.d.ts +14 -0
  252. package/dist/services/origin-request/asset-variations.js +11 -4
  253. package/dist/services/origin-request/origin-fetcher.d.ts +7 -0
  254. package/dist/services/origin-request/origin-fetcher.js +43 -5
  255. package/dist/services/origin-request/origin-request-service-build-context.d.ts +17 -0
  256. package/dist/services/origin-request/origin-request-service-build-context.js +8 -0
  257. package/dist/services/origin-request/origin-request-service-factory.d.ts +0 -5
  258. package/dist/services/origin-request/origin-request-service-factory.js +2 -30
  259. package/dist/services/origin-request/origin-request-service.d.ts +121 -6
  260. package/dist/services/origin-request/origin-request-service.js +273 -49
  261. package/dist/services/origin-request/runtime-config-source.js +9 -4
  262. package/dist/services/origin-request/spec/asset-variations.spec.js +20 -0
  263. package/dist/services/origin-request/spec/origin-request-service.spec.js +329 -6
  264. package/dist/services/query-builder/rules/rule-match.d.ts +35 -0
  265. package/dist/services/query-builder/rules/rule-match.js +70 -0
  266. package/dist/services/query-builder/spec/rules/rule-match.spec.d.ts +1 -0
  267. package/dist/services/query-builder/spec/rules/rule-match.spec.js +121 -0
  268. package/dist/services/run-control/browser/run-browser-contexts.d.ts +541 -0
  269. package/dist/services/run-control/browser/run-browser-contexts.js +78 -0
  270. package/dist/services/run-control/browser/run-browser-service-factory.d.ts +5 -0
  271. package/dist/services/run-control/browser/run-browser-service-factory.js +7 -0
  272. package/dist/services/run-control/browser/run-browser-service.d.ts +64 -0
  273. package/dist/services/run-control/browser/run-browser-service.js +199 -0
  274. package/dist/services/run-control/cache/run-cache-contexts.d.ts +349 -0
  275. package/dist/services/run-control/cache/run-cache-contexts.js +51 -0
  276. package/dist/services/run-control/cache/run-cache-service-factory.d.ts +6 -0
  277. package/dist/services/run-control/cache/run-cache-service-factory.js +12 -0
  278. package/dist/services/run-control/cache/run-cache-service.d.ts +35 -0
  279. package/dist/services/run-control/cache/run-cache-service.js +151 -0
  280. package/dist/services/run-control/control-client.d.ts +36 -0
  281. package/dist/services/run-control/control-client.js +147 -0
  282. package/dist/services/run-control/debug/run-debug-contexts.d.ts +411 -0
  283. package/dist/services/run-control/debug/run-debug-contexts.js +44 -0
  284. package/dist/services/run-control/debug/run-debug-service-factory.d.ts +5 -0
  285. package/dist/services/run-control/debug/run-debug-service-factory.js +7 -0
  286. package/dist/services/run-control/debug/run-debug-service.d.ts +38 -0
  287. package/dist/services/run-control/debug/run-debug-service.js +161 -0
  288. package/dist/services/run-control/files/run-files-contexts.d.ts +238 -0
  289. package/dist/services/run-control/files/run-files-contexts.js +26 -0
  290. package/dist/services/run-control/files/run-files-service-factory.d.ts +5 -0
  291. package/dist/services/run-control/files/run-files-service-factory.js +7 -0
  292. package/dist/services/run-control/files/run-files-service.d.ts +29 -0
  293. package/dist/services/run-control/files/run-files-service.js +120 -0
  294. package/dist/services/run-control/index.d.ts +32 -0
  295. package/dist/services/run-control/index.js +31 -0
  296. package/dist/services/run-control/inject/run-inject-contexts.d.ts +319 -0
  297. package/dist/services/run-control/inject/run-inject-contexts.js +32 -0
  298. package/dist/services/run-control/inject/run-inject-service-factory.d.ts +5 -0
  299. package/dist/services/run-control/inject/run-inject-service-factory.js +7 -0
  300. package/dist/services/run-control/inject/run-inject-service.d.ts +31 -0
  301. package/dist/services/run-control/inject/run-inject-service.js +203 -0
  302. package/dist/services/run-control/live-run.d.ts +37 -0
  303. package/dist/services/run-control/live-run.js +56 -0
  304. package/dist/services/run-control/probe/run-probe-contexts.d.ts +333 -0
  305. package/dist/services/run-control/probe/run-probe-contexts.js +73 -0
  306. package/dist/services/run-control/probe/run-probe-service-factory.d.ts +5 -0
  307. package/dist/services/run-control/probe/run-probe-service-factory.js +7 -0
  308. package/dist/services/run-control/probe/run-probe-service.d.ts +54 -0
  309. package/dist/services/run-control/probe/run-probe-service.js +193 -0
  310. package/dist/services/run-control/rum/run-rum-contexts.d.ts +216 -0
  311. package/dist/services/run-control/rum/run-rum-contexts.js +34 -0
  312. package/dist/services/run-control/rum/run-rum-service-factory.d.ts +5 -0
  313. package/dist/services/run-control/rum/run-rum-service-factory.js +7 -0
  314. package/dist/services/run-control/rum/run-rum-service.d.ts +36 -0
  315. package/dist/services/run-control/rum/run-rum-service.js +122 -0
  316. package/dist/services/run-control/run-answer.d.ts +28 -0
  317. package/dist/services/run-control/run-answer.js +58 -0
  318. package/dist/services/run-control/run-control-context.d.ts +102 -0
  319. package/dist/services/run-control/run-control-context.js +36 -0
  320. package/dist/services/run-control/run-control-flags.d.ts +12 -0
  321. package/dist/services/run-control/run-control-flags.js +22 -0
  322. package/dist/services/run-control/run-control-model.d.ts +9 -0
  323. package/dist/services/run-control/run-control-model.js +1 -0
  324. package/dist/services/run-control/run-control-service-factory.d.ts +14 -0
  325. package/dist/services/run-control/run-control-service-factory.js +26 -0
  326. package/dist/services/run-control/session/run-session-contexts.d.ts +25 -0
  327. package/dist/services/run-control/session/run-session-contexts.js +20 -0
  328. package/dist/services/run-control/session/run-session-service-factory.d.ts +8 -0
  329. package/dist/services/run-control/session/run-session-service-factory.js +18 -0
  330. package/dist/services/run-control/session/run-session-service.d.ts +25 -0
  331. package/dist/services/run-control/session/run-session-service.js +95 -0
  332. package/dist/services/run-control/spec/browser/run-browser-service.spec.d.ts +1 -0
  333. package/dist/services/run-control/spec/browser/run-browser-service.spec.js +327 -0
  334. package/dist/services/run-control/spec/cache/run-cache-service.spec.d.ts +1 -0
  335. package/dist/services/run-control/spec/cache/run-cache-service.spec.js +454 -0
  336. package/dist/services/run-control/spec/debug/run-debug-service.spec.d.ts +1 -0
  337. package/dist/services/run-control/spec/debug/run-debug-service.spec.js +113 -0
  338. package/dist/services/run-control/spec/files/run-files-service.spec.d.ts +1 -0
  339. package/dist/services/run-control/spec/files/run-files-service.spec.js +234 -0
  340. package/dist/services/run-control/spec/inject/run-inject-service.spec.d.ts +1 -0
  341. package/dist/services/run-control/spec/inject/run-inject-service.spec.js +224 -0
  342. package/dist/services/run-control/spec/live-run-fixture.d.ts +32 -0
  343. package/dist/services/run-control/spec/live-run-fixture.js +109 -0
  344. package/dist/services/run-control/spec/probe/run-probe-service.spec.d.ts +1 -0
  345. package/dist/services/run-control/spec/probe/run-probe-service.spec.js +108 -0
  346. package/dist/services/run-control/spec/rum/run-rum-service.spec.d.ts +1 -0
  347. package/dist/services/run-control/spec/rum/run-rum-service.spec.js +47 -0
  348. package/dist/services/run-control/spec/run-answer.spec.d.ts +1 -0
  349. package/dist/services/run-control/spec/run-answer.spec.js +57 -0
  350. package/dist/services/run-control/spec/session/run-session-service.spec.d.ts +1 -0
  351. package/dist/services/run-control/spec/session/run-session-service.spec.js +101 -0
  352. package/dist/services/run-log/crash-mirror.d.ts +31 -0
  353. package/dist/services/run-log/crash-mirror.js +69 -0
  354. package/dist/services/run-log/index.d.ts +11 -0
  355. package/dist/services/run-log/index.js +11 -0
  356. package/dist/services/run-log/jsonl-appender.d.ts +46 -0
  357. package/dist/services/run-log/jsonl-appender.js +91 -0
  358. package/dist/services/run-log/log-event-model.d.ts +104 -0
  359. package/dist/services/run-log/log-event-model.js +56 -0
  360. package/dist/services/run-log/log-query-service-factory.d.ts +11 -0
  361. package/dist/services/run-log/log-query-service-factory.js +14 -0
  362. package/dist/services/run-log/log-query-service.d.ts +59 -0
  363. package/dist/services/run-log/log-query-service.js +111 -0
  364. package/dist/services/run-log/log-reader.d.ts +84 -0
  365. package/dist/services/run-log/log-reader.js +180 -0
  366. package/dist/services/run-log/log-summary.d.ts +72 -0
  367. package/dist/services/run-log/log-summary.js +208 -0
  368. package/dist/services/run-log/redaction.d.ts +34 -0
  369. package/dist/services/run-log/redaction.js +124 -0
  370. package/dist/services/run-log/request-log.d.ts +80 -0
  371. package/dist/services/run-log/request-log.js +69 -0
  372. package/dist/services/run-log/request-summary.d.ts +76 -0
  373. package/dist/services/run-log/request-summary.js +0 -0
  374. package/dist/services/run-log/run-log.d.ts +61 -0
  375. package/dist/services/run-log/run-log.js +102 -0
  376. package/dist/services/run-log/spec/log-query-service.spec.d.ts +1 -0
  377. package/dist/services/run-log/spec/log-query-service.spec.js +197 -0
  378. package/dist/services/run-log/spec/log-reader.spec.d.ts +1 -0
  379. package/dist/services/run-log/spec/log-reader.spec.js +109 -0
  380. package/dist/services/run-log/spec/log-summary.spec.d.ts +1 -0
  381. package/dist/services/run-log/spec/log-summary.spec.js +153 -0
  382. package/dist/services/run-log/spec/redaction.spec.d.ts +1 -0
  383. package/dist/services/run-log/spec/redaction.spec.js +61 -0
  384. package/dist/services/run-log/spec/request-log.spec.d.ts +1 -0
  385. package/dist/services/run-log/spec/request-log.spec.js +101 -0
  386. package/dist/services/run-log/spec/request-summary.spec.d.ts +1 -0
  387. package/dist/services/run-log/spec/request-summary.spec.js +171 -0
  388. package/dist/services/run-log/spec/run-log.spec.d.ts +1 -0
  389. package/dist/services/run-log/spec/run-log.spec.js +122 -0
  390. package/dist/services/run-registry/exit-classification.d.ts +39 -0
  391. package/dist/services/run-registry/exit-classification.js +42 -0
  392. package/dist/services/run-registry/index.d.ts +3 -0
  393. package/dist/services/run-registry/index.js +3 -0
  394. package/dist/services/run-registry/process-identity.d.ts +28 -0
  395. package/dist/services/run-registry/process-identity.js +80 -0
  396. package/dist/services/run-registry/run-registry-model.d.ts +128 -0
  397. package/dist/services/run-registry/run-registry-model.js +16 -0
  398. package/dist/services/run-registry/run-registry.d.ts +150 -0
  399. package/dist/services/run-registry/run-registry.js +409 -0
  400. package/dist/services/run-registry/spec/exit-classification.spec.d.ts +1 -0
  401. package/dist/services/run-registry/spec/exit-classification.spec.js +82 -0
  402. package/dist/services/run-registry/spec/run-registry.spec.d.ts +1 -0
  403. package/dist/services/run-registry/spec/run-registry.spec.js +509 -0
  404. package/dist/services/setup/os/tool-registry.js +2 -2
  405. package/oclif.manifest.json +3293 -272
  406. package/package.json +20 -2
@@ -1,11 +1,334 @@
1
1
  import { expect } from "chai";
2
- import { describe, it } from "mocha";
3
- import { OriginRequestService, printable } from "../origin-request-service.js";
4
- describe("OriginRequestService", () => {
5
- it("reports that it sent nothing when the runtime config was not usable", async () => {
6
- const service = new OriginRequestService({ pageUrl: "https://shop.test/" }, {}, undefined);
7
- expect(await service.run()).to.equal(false);
2
+ import { afterEach, describe, it } from "mocha";
3
+ import { MemorySink } from "../../cli/index.js";
4
+ import { setOriginFetchTransport } from "../../../helpers/origin-proxy.js";
5
+ import { OriginRequestService, printable, } from "../origin-request-service.js";
6
+ import { memoryCli } from "../../cli/spec/memory-cli.js";
7
+ const variations = {
8
+ "*": { headers: { cookie: "fmarktcookie=e_2879130" } },
9
+ mobile: { headers: { "user-agent": "SpeedKit-Mobile" } },
10
+ };
11
+ /** Only `getServerConfig` is reached, and only ever as a string. */
12
+ function configApi(body) {
13
+ return {
14
+ getServerConfig: async () => {
15
+ if (body instanceof Error)
16
+ throw body;
17
+ return body;
18
+ },
19
+ };
20
+ }
21
+ function customerConfig(domain = "www.example.com") {
22
+ return { app: "example", domain, origins: [] };
23
+ }
24
+ function service(context, api, customer = customerConfig()) {
25
+ return new OriginRequestService(context, memoryCli(new MemorySink(), true), api, customer);
26
+ }
27
+ const deployed = JSON.stringify({ speedKit: { variations } });
28
+ /**
29
+ * `execute` answers as data so a caller can branch on it, while `run` keeps
30
+ * printing. These cover the outcomes: every one of them is
31
+ * something the caller can act on, and an agent that cannot tell "not logged
32
+ * in" from "that variation does not exist" takes the wrong next step.
33
+ */
34
+ describe("OriginRequestService.execute", () => {
35
+ afterEach(() => {
36
+ setOriginFetchTransport();
8
37
  });
38
+ /** Answers every origin request with `body`, and records what was asked. */
39
+ const stubOrigin = (body = "<html>origin</html>") => {
40
+ const seen = [];
41
+ setOriginFetchTransport(async (url, init) => {
42
+ seen.push({
43
+ url,
44
+ headers: (init?.headers ?? {}),
45
+ });
46
+ return new Response(body, {
47
+ status: 200,
48
+ headers: { "content-type": "text/html", "set-cookie": "session=1" },
49
+ });
50
+ });
51
+ return seen;
52
+ };
53
+ it("should return the resolved request and what the origin answered", async () => {
54
+ const seen = stubOrigin();
55
+ const result = (await service({
56
+ customerPath: "customers/example.com",
57
+ configName: "production",
58
+ pageUrl: "https://www.example.com/plp",
59
+ }, configApi(deployed)).execute());
60
+ expect(result.outcome).to.equal("fetched");
61
+ expect(result.status).to.equal(200);
62
+ expect(result.variation).to.equal("default");
63
+ // The device default first, then the wildcard over it — the order the
64
+ // server applies them in, and the reason `appliedKeys` is reported at all.
65
+ expect(result.appliedKeys).to.deep.equal(["device-default:default", "*"]);
66
+ expect(result.variations).to.have.members(["*", "mobile"]);
67
+ expect(result.requestHeaders.cookie).to.equal("fmarktcookie=e_2879130");
68
+ expect(result.curl).to.contain("https://www.example.com/plp");
69
+ expect(result.setCookie).to.deep.equal(["session=1"]);
70
+ expect(seen).to.have.lengthOf(1);
71
+ expect(seen[0].url).to.equal("https://www.example.com/plp");
72
+ });
73
+ it("should resolve a path against the customer's own domain", async () => {
74
+ const seen = stubOrigin();
75
+ const result = (await service({
76
+ customerPath: "customers/example.com",
77
+ configName: "production",
78
+ pageUrl: "/plp",
79
+ }, configApi(deployed)).execute());
80
+ // `domain` is a bare host in every config_customer, and `new URL` parses
81
+ // the base before the input — so this is the case that used to throw.
82
+ expect(result.requestUrl).to.equal("https://www.example.com/plp");
83
+ expect(seen[0].url).to.equal("https://www.example.com/plp");
84
+ });
85
+ it("should name the variations that exist when the requested one does not", async () => {
86
+ // Not a device default either — `mobile` and `tablet` resolve against the
87
+ // server's own fallbacks whether a config defines them or not.
88
+ const result = await service({
89
+ customerPath: "customers/example.com",
90
+ configName: "production",
91
+ pageUrl: "https://www.example.com/",
92
+ variation: "desktop-fmarkt-variant-e_1907090",
93
+ }, configApi(deployed)).execute();
94
+ expect(result.outcome).to.equal("unknown-variation");
95
+ if (result.outcome !== "unknown-variation")
96
+ throw new Error("unreachable");
97
+ expect(result.requested).to.equal("desktop-fmarkt-variant-e_1907090");
98
+ expect(result.available).to.have.members(["*", "mobile"]);
99
+ // Named separately, because they resolve whether a config defines them or
100
+ // not — a config that defines none would otherwise read as "nothing works".
101
+ expect(result.deviceDefaults).to.have.members([
102
+ "default",
103
+ "mobile",
104
+ "tablet",
105
+ ]);
106
+ });
107
+ it("should report a config it cannot load as something to log in for", async () => {
108
+ const result = await service({
109
+ customerPath: "customers/example.com",
110
+ configName: "production",
111
+ pageUrl: "https://www.example.com/",
112
+ }, configApi(new Error("401 Unauthorized"))).execute();
113
+ expect(result.outcome).to.equal("config-unavailable");
114
+ if (result.outcome !== "config-unavailable")
115
+ throw new Error("unreachable");
116
+ expect(result.message).to.contain("sk login");
117
+ expect(result.cause).to.contain("401");
118
+ });
119
+ it("should request a config that defines no variations with the device defaults", async () => {
120
+ stubOrigin();
121
+ const result = await service({
122
+ customerPath: "customers/example.com",
123
+ configName: "production",
124
+ pageUrl: "https://www.example.com/",
125
+ }, configApi(JSON.stringify({ speedKit: {} }))).execute();
126
+ // The device defaults resolve without any entry, and the server sends
127
+ // the same request: main's 1d7306d7.
128
+ expect(result.outcome).to.equal("fetched");
129
+ });
130
+ it("should take a single origin as the base when the config names no domain", async () => {
131
+ const seen = stubOrigin();
132
+ const result = (await service({
133
+ customerPath: "customers/kubara",
134
+ configName: "proxy",
135
+ pageUrl: "/plp",
136
+ }, configApi(deployed), {
137
+ app: "kubara",
138
+ origins: ["https://www.kubara.jp"],
139
+ }).execute());
140
+ // `domain` is optional and plenty of configs carry only `origins`.
141
+ expect(result.requestUrl).to.equal("https://www.kubara.jp/plp");
142
+ expect(seen[0].url).to.equal("https://www.kubara.jp/plp");
143
+ });
144
+ it("should still name the device defaults when the config defines nothing", async () => {
145
+ // kubara is the real case: `speedKit.variations` is `{}`, and a bare
146
+ // `variations: []` reads as "nothing can be passed" while `default`,
147
+ // `mobile` and `tablet` all resolve.
148
+ const result = await service({ customerPath: "customers/kubara", configName: "proxy", pageUrl: "" }, configApi(JSON.stringify({ speedKit: { variations: {} } }))).listVariations();
149
+ expect(result.outcome).to.equal("variations");
150
+ if (result.outcome !== "variations")
151
+ throw new Error("unreachable");
152
+ expect(result.variations).to.have.lengthOf(0);
153
+ expect(result.deviceDefaults).to.have.members([
154
+ "default",
155
+ "mobile",
156
+ "tablet",
157
+ ]);
158
+ });
159
+ it("should refuse to pick between several origins", async () => {
160
+ const result = await service({
161
+ customerPath: "customers/example.com",
162
+ configName: "production",
163
+ pageUrl: "/plp",
164
+ }, configApi(deployed), {
165
+ app: "example",
166
+ origins: ["https://www.example.com", "https://shop.example.com"],
167
+ }).execute();
168
+ expect(result.outcome).to.equal("bad-url");
169
+ if (result.outcome !== "bad-url")
170
+ throw new Error("unreachable");
171
+ expect(result.message).to.contain("shop.example.com");
172
+ });
173
+ it("should resolve a relative url against a base a run supplied", async () => {
174
+ const seen = stubOrigin();
175
+ const result = (await service({
176
+ customerPath: "customers/gantde",
177
+ configName: "production",
178
+ pageUrl: "/sale",
179
+ base: "https://www.gant.de",
180
+ }, configApi(deployed), {
181
+ app: "gantde",
182
+ origins: ["https://www.gant.se", "https://www.gant.de"],
183
+ }).execute());
184
+ // Twelve origins and no `domain` is gantde, and it is why this refused a
185
+ // path that `sk onboarding response` accepted for the same run.
186
+ expect(result.requestUrl).to.equal("https://www.gant.de/sale");
187
+ expect(seen[0].url).to.equal("https://www.gant.de/sale");
188
+ });
189
+ it("should prefer the run's origin over the config's own domain", async () => {
190
+ const seen = stubOrigin();
191
+ const result = (await service({
192
+ customerPath: "customers/example.com",
193
+ configName: "production",
194
+ pageUrl: "/plp",
195
+ base: "https://staging.example.com",
196
+ }, configApi(deployed), {
197
+ app: "example",
198
+ domain: "www.example.com",
199
+ origins: ["https://www.example.com"],
200
+ }).execute());
201
+ // Someone who started the run with `-d` means that origin, not the one the
202
+ // config calls canonical — the same precedence the control socket uses.
203
+ expect(result.requestUrl).to.equal("https://staging.example.com/plp");
204
+ expect(seen[0].url).to.equal("https://staging.example.com/plp");
205
+ });
206
+ it("should blame the base, not the url, when there is nothing to resolve against", async () => {
207
+ const result = await service({
208
+ customerPath: "customers/example.com",
209
+ configName: "production",
210
+ pageUrl: "/plp",
211
+ }, configApi(deployed), { app: "example", origins: [] }).execute();
212
+ expect(result.outcome).to.equal("bad-url");
213
+ if (result.outcome !== "bad-url")
214
+ throw new Error("unreachable");
215
+ expect(result.base).to.equal(null);
216
+ expect(result.message).to.contain("no customer config was available");
217
+ });
218
+ it("should list the variations without sending anything to the origin", async () => {
219
+ const seen = stubOrigin();
220
+ const result = await service({
221
+ customerPath: "customers/example.com",
222
+ configName: "production",
223
+ pageUrl: "",
224
+ }, configApi(deployed)).listVariations();
225
+ expect(result.outcome).to.equal("variations");
226
+ if (result.outcome !== "variations")
227
+ throw new Error("unreachable");
228
+ expect(result.variations).to.have.members(["*", "mobile"]);
229
+ expect(result.deviceDefaults).to.have.members([
230
+ "default",
231
+ "mobile",
232
+ "tablet",
233
+ ]);
234
+ expect(seen).to.have.lengthOf(0);
235
+ });
236
+ it("should send Speed Kit's device defaults without a customer", async () => {
237
+ const seen = stubOrigin();
238
+ // `sk origin-request --raw <url>`: no customer, so no app and no config API.
239
+ const result = (await new OriginRequestService({
240
+ configName: "production",
241
+ pageUrl: "https://www.example.com/",
242
+ variation: "mobile",
243
+ }, memoryCli(new MemorySink(), true), undefined).execute());
244
+ expect(result.outcome).to.equal("fetched");
245
+ expect(result.variations).to.deep.equal([]);
246
+ expect(result.appliedKeys).to.deep.equal(["device-default:mobile"]);
247
+ expect(seen).to.have.lengthOf(1);
248
+ });
249
+ it("should rewrite the request by the deployed origin map, and hide its credentials", async () => {
250
+ const seen = stubOrigin();
251
+ const result = (await service({ configName: "production", pageUrl: "https://www.example.com/p" }, configApi(JSON.stringify({
252
+ speedKit: {
253
+ variations,
254
+ originMap: {
255
+ "www.example.com": {
256
+ origin: "origin.example.com",
257
+ headers: { "x-bypass": "secret" },
258
+ },
259
+ },
260
+ },
261
+ }))).execute());
262
+ expect(result.originMapKey).to.equal("www.example.com");
263
+ expect(seen[0].url).to.equal("https://origin.example.com/p");
264
+ expect(seen[0].headers["x-bypass"]).to.equal("secret");
265
+ expect(result.requestHeaders["x-bypass"]).to.equal("<from the origin map>");
266
+ expect(result.curl).not.to.contain("secret");
267
+ });
268
+ it("should refuse a variation of an app without a customer", async () => {
269
+ const result = await new OriginRequestService({
270
+ configName: "production",
271
+ pageUrl: "https://www.example.com/",
272
+ variation: "desktop-fmarkt-variant-e_1907090",
273
+ }, memoryCli(new MemorySink(), true), undefined).execute();
274
+ expect(result.outcome).to.equal("unknown-variation");
275
+ });
276
+ });
277
+ describe("OriginRequestService.run", () => {
278
+ afterEach(() => {
279
+ setOriginFetchTransport();
280
+ });
281
+ const page = [
282
+ "<html><head>",
283
+ '<script src="https://cdn.example.com/analytics.js"></script>',
284
+ "</head><body><!-- StoreID: 42 --></body></html>",
285
+ ].join("\n");
286
+ let sent;
287
+ const run = async (context, api = configApi(deployed)) => {
288
+ setOriginFetchTransport(async () => new Response(page, {
289
+ status: 200,
290
+ headers: { "content-type": "text/html" },
291
+ }));
292
+ const sink = new MemorySink();
293
+ sent = await new OriginRequestService({
294
+ customerPath: "customers/example.com",
295
+ configName: "production",
296
+ pageUrl: "https://www.example.com/",
297
+ ...context,
298
+ },
299
+ // Quiet under --json, as the command builds it.
300
+ memoryCli(sink, context.json === true), api, customerConfig()).run();
301
+ return sink;
302
+ };
303
+ it("should put --json on the payload channel, with what --select and --grep found", async () => {
304
+ // What the sk_origin MCP tool offered and the command once did not: "did the
305
+ // origin send it" as a count, readable by a script.
306
+ const sink = await run({
307
+ json: true,
308
+ select: 'script[src*="analytics"]',
309
+ grep: "storeid",
310
+ });
311
+ expect(sink.lines).to.deep.equal([]);
312
+ const body = JSON.parse(sink.payloads.join(""));
313
+ expect(body.select.count).to.equal(1);
314
+ // Case-insensitive, as the flag says.
315
+ expect(body.grep.count).to.equal(1);
316
+ });
317
+ it("should print the selector's count for a person", async () => {
318
+ const sink = await run({ select: "iframe" });
319
+ expect(sink.lines.join("\n")).to.contain('select "iframe" → 0 match(es)');
320
+ });
321
+ it("should report that it sent nothing when the runtime config was not usable", async () => {
322
+ // The command exits 2 on this, so a script does not read a failed login as a success.
323
+ await run({}, configApi(new Error("401 Unauthorized")));
324
+ expect(sent).to.equal(false);
325
+ });
326
+ it("should report that it sent the request", async () => {
327
+ await run({});
328
+ expect(sent).to.equal(true);
329
+ });
330
+ });
331
+ describe("printable", () => {
9
332
  it("prints neither basic auth nor an origin map credential, but keeps plain headers", () => {
10
333
  const headers = printable({
11
334
  Authorization: "Basic dXNlcjpwYXNz",
@@ -0,0 +1,35 @@
1
+ import { NormalizedRule } from "./rule-model.js";
2
+ export interface RuleMatch {
3
+ readonly matched: boolean;
4
+ /**
5
+ * True when the rule carries a criterion this cannot evaluate — a cookie, a
6
+ * device, a storage value. The URL half may match while the whole rule does
7
+ * not, so `matched` is a maximum rather than an answer.
8
+ */
9
+ readonly uncertain: boolean;
10
+ readonly source: string;
11
+ }
12
+ /**
13
+ * Does this rule match this URL, the way the runtime would?
14
+ *
15
+ * The query builder translates rules into SQL. This evaluates one against a
16
+ * single URL, which is the other question a config raises and the one a person
17
+ * actually asks: *why was this page not accelerated*.
18
+ *
19
+ * The matching itself is delegated to `testCondition` from `@speedkit/rules`,
20
+ * the same function the runtime's `ConditionRule.test` calls — and called the
21
+ * same way, **without** a version argument, because `ConditionRule.test` does
22
+ * not pass one either. That is subtle and deliberate: the rule-set version
23
+ * changes which *subject* a pathname condition is tested against, not whether a
24
+ * string is a prefix or an exact match. A reading that applies the version to
25
+ * both would call a v2 config stricter than the browser does.
26
+ *
27
+ * The subjects are computed here rather than through the package's own
28
+ * `destructURL`, which resolves against `location` and therefore cannot run
29
+ * outside a browser. `rule-match.spec.ts` pins all three against the real rule
30
+ * classes, so a change in the runtime fails there rather than in an
31
+ * explanation nobody re-reads.
32
+ */
33
+ export declare function matchRule(rule: NormalizedRule, url: URL): RuleMatch;
34
+ /** Every rule of a set that matches, with the uncertain ones marked. */
35
+ export declare function matchRules(rules: readonly NormalizedRule[], url: URL): RuleMatch[];
@@ -0,0 +1,70 @@
1
+ import { testCondition } from "@speedkit/rules";
2
+ import { resolvedSubject } from "./rule-model.js";
3
+ /**
4
+ * Does this rule match this URL, the way the runtime would?
5
+ *
6
+ * The query builder translates rules into SQL. This evaluates one against a
7
+ * single URL, which is the other question a config raises and the one a person
8
+ * actually asks: *why was this page not accelerated*.
9
+ *
10
+ * The matching itself is delegated to `testCondition` from `@speedkit/rules`,
11
+ * the same function the runtime's `ConditionRule.test` calls — and called the
12
+ * same way, **without** a version argument, because `ConditionRule.test` does
13
+ * not pass one either. That is subtle and deliberate: the rule-set version
14
+ * changes which *subject* a pathname condition is tested against, not whether a
15
+ * string is a prefix or an exact match. A reading that applies the version to
16
+ * both would call a v2 config stricter than the browser does.
17
+ *
18
+ * The subjects are computed here rather than through the package's own
19
+ * `destructURL`, which resolves against `location` and therefore cannot run
20
+ * outside a browser. `rule-match.spec.ts` pins all three against the real rule
21
+ * classes, so a change in the runtime fails there rather than in an
22
+ * explanation nobody re-reads.
23
+ */
24
+ export function matchRule(rule, url) {
25
+ const uncertain = rule.criteriaOutsideTheUrl.length > 0;
26
+ if (rule.matchesNothing) {
27
+ // A rule with an empty condition list matches nothing, whatever it looks
28
+ // like it says. `host: hasWebPSupport ? [] : [...]` is a real config.
29
+ return { matched: false, uncertain: false, source: rule.source };
30
+ }
31
+ for (const condition of rule.conditions) {
32
+ const subject = subjectOf(url, resolvedSubject(condition.subject, rule.ruleSetVersion));
33
+ const patterns = condition.patterns.map((pattern) => pattern.value);
34
+ // Conditions of a rule are AND'd; entries of a condition are OR'd, which
35
+ // is what passing the array to testCondition does.
36
+ if (!testCondition(subject, patterns)) {
37
+ return { matched: false, uncertain: false, source: rule.source };
38
+ }
39
+ }
40
+ // A rule with no conditions at all reaches here and matches, which is right:
41
+ // `matchesNothing` already separated the ones that cannot.
42
+ return { matched: true, uncertain, source: rule.source };
43
+ }
44
+ /** Every rule of a set that matches, with the uncertain ones marked. */
45
+ export function matchRules(rules, url) {
46
+ return rules.map((rule) => matchRule(rule, url)).filter((hit) => hit.matched);
47
+ }
48
+ /**
49
+ * The string the runtime tests a condition against.
50
+ *
51
+ * Mirrors `HostRule`, `PathnameRule` and `UrlRule`. The `url` subject drops the
52
+ * scheme — `stripForRules` in the package — so a condition written as
53
+ * `www.shop.de/checkout` matches, which it would not against `https://…`.
54
+ */
55
+ function subjectOf(url, subject) {
56
+ switch (subject) {
57
+ case "host": {
58
+ return url.host;
59
+ }
60
+ case "path": {
61
+ return url.pathname;
62
+ }
63
+ case "pathWithSearch": {
64
+ return url.pathname + url.search;
65
+ }
66
+ default: {
67
+ return `${url.host}${url.pathname}${url.search}`;
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,121 @@
1
+ import { HostRule, PathnameRule, UrlRule } from "@speedkit/rules";
2
+ import { expect } from "chai";
3
+ import { before, describe, it } from "mocha";
4
+ import { matchRule, matchRules } from "../../rules/rule-match.js";
5
+ function rule(conditions, extra = {}) {
6
+ return {
7
+ conditions: conditions.map((condition) => ({
8
+ subject: condition.subject,
9
+ patterns: condition.patterns.map((value) => value instanceof RegExp
10
+ ? { kind: "regexp", value }
11
+ : { kind: "string", value }),
12
+ })),
13
+ matchesNothing: false,
14
+ criteriaOutsideTheUrl: [],
15
+ ruleSetVersion: 1,
16
+ source: "whitelist[0]",
17
+ ...extra,
18
+ };
19
+ }
20
+ const URL_UNDER_TEST = new URL("https://www.shop.de/shoes/?page=2");
21
+ describe("matchRule against the runtime", () => {
22
+ // The package resolves a request URL against `location`, which only exists
23
+ // in a browser. The real rule classes are used here as the oracle, so they
24
+ // need one.
25
+ before(() => {
26
+ const global = globalThis;
27
+ global.location ??= new URL("https://www.shop.de/");
28
+ });
29
+ const request = () => new Request(URL_UNDER_TEST.href);
30
+ it("should read the host subject the way HostRule does", () => {
31
+ for (const pattern of [/shop\.de$/, /^www\./, /nope/]) {
32
+ expect(matchRule(rule([{ subject: "host", patterns: [pattern] }]), URL_UNDER_TEST).matched).to.equal(new HostRule(pattern).matches(request(), {}));
33
+ }
34
+ });
35
+ it("should read the pathname subject the way PathnameRule does, per version", () => {
36
+ // Version 1 tests path *and* query, version 2 the path alone — so an
37
+ // anchored pattern covers different URLs under each. This is the trap the
38
+ // query builder's own runtime-semantics spec exists for.
39
+ for (const version of [1, 2]) {
40
+ expect(matchRule(rule([{ subject: "pathname", patterns: [/\/$/] }], {
41
+ ruleSetVersion: version,
42
+ }), URL_UNDER_TEST).matched).to.equal(new PathnameRule(/\/$/).matches(request(), { ruleSetVersion: version }));
43
+ }
44
+ });
45
+ it("should read the url subject the way UrlRule does — without the scheme", () => {
46
+ // `stripForRules` drops the scheme, so a condition written as a bare host
47
+ // and path matches. Against `https://…` it would not.
48
+ const pattern = "www.shop.de/shoes";
49
+ expect(matchRule(rule([{ subject: "url", patterns: [pattern] }]), URL_UNDER_TEST)
50
+ .matched).to.equal(new UrlRule(pattern).matches(request(), {}));
51
+ expect(matchRule(rule([{ subject: "url", patterns: [pattern] }]), URL_UNDER_TEST)
52
+ .matched).to.equal(true);
53
+ });
54
+ it("should treat a string as a prefix, whatever the rule-set version", () => {
55
+ // The version changes which subject a pathname condition sees, not whether
56
+ // a string is a prefix — `ConditionRule.test` calls `testCondition` with no
57
+ // version at all. Applying it to both would make a v2 config stricter here
58
+ // than it is in the browser.
59
+ for (const version of [1, 2]) {
60
+ expect(matchRule(rule([{ subject: "pathname", patterns: ["/shoes"] }], {
61
+ ruleSetVersion: version,
62
+ }), URL_UNDER_TEST).matched).to.equal(new PathnameRule("/shoes").matches(request(), {
63
+ ruleSetVersion: version,
64
+ }));
65
+ }
66
+ });
67
+ });
68
+ describe("matchRule semantics", () => {
69
+ it("should AND the conditions of one rule", () => {
70
+ const both = rule([
71
+ { subject: "host", patterns: [/shop\.de/] },
72
+ { subject: "pathname", patterns: ["/shoes"] },
73
+ ]);
74
+ const wrongPath = rule([
75
+ { subject: "host", patterns: [/shop\.de/] },
76
+ { subject: "pathname", patterns: ["/boots"] },
77
+ ]);
78
+ expect(matchRule(both, URL_UNDER_TEST).matched).to.equal(true);
79
+ expect(matchRule(wrongPath, URL_UNDER_TEST).matched).to.equal(false);
80
+ });
81
+ it("should OR the entries of one condition", () => {
82
+ const either = rule([
83
+ { subject: "pathname", patterns: ["/boots", "/shoes"] },
84
+ ]);
85
+ expect(matchRule(either, URL_UNDER_TEST).matched).to.equal(true);
86
+ });
87
+ it("should never match a rule that can never match", () => {
88
+ // `host: hasWebPSupport ? [] : [...]` is a real config, and reading the
89
+ // empty branch as "matches everything" turns a blacklist inside out.
90
+ const empty = rule([], { matchesNothing: true });
91
+ expect(matchRule(empty, URL_UNDER_TEST).matched).to.equal(false);
92
+ });
93
+ it("should mark a rule it cannot fully evaluate as uncertain", () => {
94
+ // A cookie or a device criterion is not in the URL. Saying "matched"
95
+ // without saying "as far as the URL goes" would be a confident wrong
96
+ // answer about why a page was excluded.
97
+ const withCookie = rule([{ subject: "pathname", patterns: ["/shoes"] }], {
98
+ criteriaOutsideTheUrl: ["cookie"],
99
+ });
100
+ const match = matchRule(withCookie, URL_UNDER_TEST);
101
+ expect(match.matched).to.equal(true);
102
+ expect(match.uncertain).to.equal(true);
103
+ });
104
+ it("should not call a rule uncertain when it did not match anyway", () => {
105
+ const withCookie = rule([{ subject: "pathname", patterns: ["/boots"] }], {
106
+ criteriaOutsideTheUrl: ["cookie"],
107
+ });
108
+ expect(matchRule(withCookie, URL_UNDER_TEST).uncertain).to.equal(false);
109
+ });
110
+ it("should return only the matching rules of a set, named", () => {
111
+ const hits = matchRules([
112
+ rule([{ subject: "pathname", patterns: ["/shoes"] }], {
113
+ source: "whitelist[0]",
114
+ }),
115
+ rule([{ subject: "pathname", patterns: ["/boots"] }], {
116
+ source: "whitelist[1]",
117
+ }),
118
+ ], URL_UNDER_TEST);
119
+ expect(hits.map((hit) => hit.source)).to.deep.equal(["whitelist[0]"]);
120
+ });
121
+ });