@kabmo-labs/kabmo 0.34.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +435 -432
  3. package/dist/client/static/js/{CsvGrid-vze4m5ag.js → CsvGrid-1h3bcak7.js} +2 -2
  4. package/dist/client/static/js/{DocxView-jbf21gmh.js → DocxView-ndca8jch.js} +3 -3
  5. package/dist/client/static/js/{DrawioView-b52qybx5.js → DrawioView-kpzd6y0b.js} +2 -2
  6. package/dist/client/static/js/{ImageView-mdgzj8px.js → ImageView-79prn3dg.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-3c49dvtt.js → LayoutWrapper-v2wn2sb2.js} +2 -2
  8. package/dist/client/static/js/{Modal-sqp864vd.js → Modal-99j0zz3z.js} +16 -16
  9. package/dist/client/static/js/{PdfView-g06rxqb1.js → PdfView-2rjd87ay.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-521adxyr.js → SessionsView-t7f3s71b.js} +1 -1
  11. package/dist/client/static/js/{SheetView-h8xmsz7q.js → SheetView-ehb976st.js} +4 -4
  12. package/dist/client/static/js/{SvgPreview-1j4jvcvz.js → SvgPreview-de2bbba6.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-pasxh4b6.js → abnfDiagram-O67JEVCF-nx9jzn7m.js} +1 -1
  14. package/dist/client/static/js/architecture-7GRP2DOG-aqft2erp.js +1 -0
  15. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-ms14g0bm.js → architectureDiagram-NJMV4G6O-170v67rr.js} +2 -2
  16. package/dist/client/static/js/{blockDiagram-BEXU5L5S-ycn78fcq.js → blockDiagram-BEXU5L5S-16q285n1.js} +2 -2
  17. package/dist/client/static/js/{c4Diagram-YGBWAQC7-vn2gpjfm.js → c4Diagram-YGBWAQC7-rn3qt45h.js} +1 -1
  18. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-fyrm1pr5.js → classDiagram-v2-NBCMYWYE-r26wg74e.js} +3 -3
  19. package/dist/client/static/js/{cose-bilkent-JH36ORCC-ea5nwvgq.js → cose-bilkent-JH36ORCC-82kwe7ha.js} +1 -1
  20. package/dist/client/static/js/css-r2nhvzff.js +1 -0
  21. package/dist/client/static/js/cynefin-OW5HDTMX-v2sz60t6.js +1 -0
  22. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-j6bsjpre.js → cynefinDiagram-VND7K2PF-tcxdn6pa.js} +1 -1
  23. package/dist/client/static/js/{dagre-6A5THRUB-4smdkwv8.js → dagre-6A5THRUB-g833ata3.js} +2 -2
  24. package/dist/client/static/js/{diagram-22UHCM2B-9sm4kqwc.js → diagram-22UHCM2B-f1fq8xec.js} +4 -4
  25. package/dist/client/static/js/{diagram-3UASUU5V-2h3qxaed.js → diagram-3UASUU5V-6j2w016f.js} +1 -1
  26. package/dist/client/static/js/{diagram-ATOU4E4O-1981bc94.js → diagram-ATOU4E4O-6t2qxsk4.js} +1 -1
  27. package/dist/client/static/js/{diagram-CDSNMT55-3vgsxavc.js → diagram-CDSNMT55-7abar8s7.js} +1 -1
  28. package/dist/client/static/js/{diagram-MLGK6HIB-c9gf2r3f.js → diagram-MLGK6HIB-s68rgy16.js} +1 -1
  29. package/dist/client/static/js/{diagram-MPIPVDR6-gjqeq92d.js → diagram-MPIPVDR6-azgkm6w8.js} +1 -1
  30. package/dist/client/static/js/{dockerfile-8v935dkn.js → dockerfile-47e33kqa.js} +1 -1
  31. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-4vbsgh99.js → ebnfDiagram-ZINNZB2B-esrjz750.js} +1 -1
  32. package/dist/client/static/js/{elixir-vcbg60wv.js → elixir-rpa1g4gy.js} +1 -1
  33. package/dist/client/static/js/{elk-276RUBZZ-nca3t891.js → elk-276RUBZZ-fhr4b4jj.js} +1 -1
  34. package/dist/client/static/js/{erDiagram-OPXOYQCR-5kfkev03.js → erDiagram-OPXOYQCR-5r3fmdnz.js} +2 -2
  35. package/dist/client/static/js/{erlang-qt876zrq.js → erlang-bh5cbm8m.js} +1 -1
  36. package/dist/client/static/js/eventmodeling-NTZA5JFV-8qbefe4m.js +1 -0
  37. package/dist/client/static/js/flowDiagram-KWPJA3E3-krsvgcq7.js +1 -0
  38. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-mxc73wmq.js → ganttDiagram-FUAMR5RP-j4pf6rdn.js} +2 -2
  39. package/dist/client/static/js/gitGraph-4MIJSDKK-9bx1a38k.js +1 -0
  40. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-7en3ag0e.js → gitGraphDiagram-X574FWY7-x5epk0gr.js} +1 -1
  41. package/dist/client/static/js/graphql-xnpp5gn9.js +1 -0
  42. package/dist/client/static/js/html-pv88ny12.js +1 -0
  43. package/dist/client/static/js/{index-j51d5a5m.js → index-0b1kwsam.js} +28 -28
  44. package/dist/client/static/js/{index-52rqxgya.js → index-3kgrcaq1.js} +1 -1
  45. package/dist/client/static/js/{index-vhqe0y82.js → index-3vdmwpbh.js} +2 -2
  46. package/dist/client/static/js/{index-g2dyfze9.js → index-40ve7zzv.js} +1 -1
  47. package/dist/client/static/js/{index-eyfcm0cy.js → index-44qrckd2.js} +1 -1
  48. package/dist/client/static/js/{index-qckv9nte.js → index-55pqvh82.js} +2 -2
  49. package/dist/client/static/js/{index-r014brzs.js → index-5kjpacvd.js} +1 -1
  50. package/dist/client/static/js/{index-ev3yt353.js → index-5rzk1226.js} +1 -1
  51. package/dist/client/static/js/{index-p0nz38bm.js → index-60ceydzn.js} +1 -1
  52. package/dist/client/static/js/{index-ybm2x4vh.js → index-63c6t75t.js} +1 -1
  53. package/dist/client/static/js/{index-ahv9y42z.js → index-63jbb4kf.js} +2 -2
  54. package/dist/client/static/js/{index-nccwxv0s.js → index-6xzfta4b.js} +1 -1
  55. package/dist/client/static/js/{index-cgzrpvzj.js → index-75haaj8g.js} +169 -169
  56. package/dist/client/static/js/{index-ag2rmtas.js → index-7r1hw2gd.js} +1 -1
  57. package/dist/client/static/js/{index-hf52f59k.js → index-8cy3x2y8.js} +2 -2
  58. package/dist/client/static/js/{index-vy6termr.js → index-8e15fzax.js} +1 -1
  59. package/dist/client/static/js/{index-rzxcj7cg.js → index-97t3mv1v.js} +1 -1
  60. package/dist/client/static/js/{index-km2zb6wk.js → index-982jyfsb.js} +2 -2
  61. package/dist/client/static/js/{index-jsyekbx9.js → index-9gf8b73w.js} +1 -1
  62. package/dist/client/static/js/{index-s7gkkkyz.js → index-a293pdg7.js} +2 -2
  63. package/dist/client/static/js/{index-dbe6afkf.js → index-af24nes6.js} +2 -2
  64. package/dist/client/static/js/{index-ptcwae2n.js → index-b48p8d1j.js} +2 -2
  65. package/dist/client/static/js/{index-cd65zqba.js → index-be6gevq8.js} +1 -1
  66. package/dist/client/static/js/{index-231241f4.js → index-c09a5s1n.js} +9 -9
  67. package/dist/client/static/js/{index-fvmfge3p.js → index-c1j0xb0w.js} +1 -1
  68. package/dist/client/static/js/{index-fta1y9pc.js → index-ctgefatv.js} +10 -10
  69. package/dist/client/static/js/{index-7a64yjrm.js → index-d2km9egp.js} +4 -4
  70. package/dist/client/static/js/index-dh1vd0d9.js +1 -0
  71. package/dist/client/static/js/{index-j0r5hj0j.js → index-dmgawfhw.js} +2 -2
  72. package/dist/client/static/js/{index-1ksg88qf.js → index-h1e1abpt.js} +2 -2
  73. package/dist/client/static/js/{index-4g46wbdw.js → index-htt8qxm3.js} +1 -1
  74. package/dist/client/static/js/{index-c3ek61zv.js → index-k1xt92h4.js} +1 -1
  75. package/dist/client/static/js/{index-f7jhhqtk.js → index-ktvbsj6w.js} +1 -1
  76. package/dist/client/static/js/{index-a0fmsv1d.js → index-ky0prc71.js} +6 -6
  77. package/dist/client/static/js/{index-2svnq5gg.js → index-mm1rf116.js} +1 -1
  78. package/dist/client/static/js/{index-h5bn97p6.js → index-nws03exw.js} +1 -1
  79. package/dist/client/static/js/{index-xx6mqpxm.js → index-pyx8n25s.js} +2 -2
  80. package/dist/client/static/js/{index-rs80cwsv.js → index-q5t4sy22.js} +3 -3
  81. package/dist/client/static/js/{index-76zb4m0n.js → index-r8pckaqe.js} +2 -2
  82. package/dist/client/static/js/{index-4qwzxj81.js → index-sar2ggde.js} +1 -1
  83. package/dist/client/static/js/{index-1b0t1428.js → index-skm6k5w2.js} +3 -3
  84. package/dist/client/static/js/{index-b29afsjh.js → index-v5t761a1.js} +1 -1
  85. package/dist/client/static/js/{index-7y6rpsrp.js → index-v8qd8ypc.js} +2 -2
  86. package/dist/client/static/js/{index-354mqqra.js → index-w3n97x4b.js} +2 -2
  87. package/dist/client/static/js/{index-0vm41je9.js → index-ydvfc9td.js} +1 -1
  88. package/dist/client/static/js/{index-ptcrwswj.js → index-ye450a7z.js} +1 -1
  89. package/dist/client/static/js/{index-rytaa8ca.js → index-z6g74h7g.js} +2 -2
  90. package/dist/client/static/js/{index-sd66wv26.js → index-zdtsvnpq.js} +2 -2
  91. package/dist/client/static/js/{index-pm6xxwz1.js → index-zp73zexp.js} +2 -2
  92. package/dist/client/static/js/info-A6RAGUB7-j51t7jhh.js +1 -0
  93. package/dist/client/static/js/{infoDiagram-VRGFBTTK-sef80132.js → infoDiagram-VRGFBTTK-ktc8nb8g.js} +1 -1
  94. package/dist/client/static/js/ini-ygfyhprj.js +1 -0
  95. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-yhvepp1q.js → ishikawaDiagram-OU5B5YK6-n3dk6227.js} +2 -2
  96. package/dist/client/static/js/java-gm49vw59.js +1 -0
  97. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-5w77y95w.js → journeyDiagram-ZHPQQLJL-f0p1h8qn.js} +3 -3
  98. package/dist/client/static/js/jsx-ksxw1byz.js +1 -0
  99. package/dist/client/static/js/{julia-d4j6wgvf.js → julia-73zjh2w6.js} +1 -1
  100. package/dist/client/static/js/{kanban-definition-PNTS6WVX-02znqtna.js → kanban-definition-PNTS6WVX-7jdt7dv1.js} +2 -2
  101. package/dist/client/static/js/lua-53gzb9bx.js +1 -0
  102. package/dist/client/static/js/markdown-tk3cd3vs.js +1 -0
  103. package/dist/client/static/js/{mermaid.core-a6e6vck4.js → mermaid.core-e8rzrjt9.js} +6 -6
  104. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-y4n74q9x.js → mindmap-definition-NLK3R4M7-7shv6ge0.js} +2 -2
  105. package/dist/client/static/js/one-dark-pro-39bt34v9.js +1 -0
  106. package/dist/client/static/js/one-light-xec0sehr.js +1 -0
  107. package/dist/client/static/js/packet-AYTQ26CC-n83gfj2g.js +1 -0
  108. package/dist/client/static/js/{pegDiagram-GJSIUBJH-pr7ehgzb.js → pegDiagram-GJSIUBJH-17ak2zx3.js} +1 -1
  109. package/dist/client/static/js/{perl-srptw5vm.js → perl-8z46dmze.js} +1 -1
  110. package/dist/client/static/js/{php-n89g3fk7.js → php-6qvnp2t6.js} +1 -1
  111. package/dist/client/static/js/pie-WAS4IAKB-5c5pctwz.js +1 -0
  112. package/dist/client/static/js/{pieDiagram-5QR66LMP-39wpsk08.js → pieDiagram-5QR66LMP-at4x1g4q.js} +2 -2
  113. package/dist/client/static/js/properties-2tcybqjk.js +1 -0
  114. package/dist/client/static/js/python-qph3dntq.js +1 -0
  115. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-esm913km.js → quadrantDiagram-O4NWA36T-apzhwrn4.js} +1 -1
  116. package/dist/client/static/js/r-gd26x93y.js +1 -0
  117. package/dist/client/static/js/radar-RG4KPBEZ-52e5n99a.js +1 -0
  118. package/dist/client/static/js/railroad-74A4TZTK-44nqxxpy.js +1 -0
  119. package/dist/client/static/js/railroad-abnf-HS5TGJTU-25jxgwg7.js +1 -0
  120. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-64pqpf2y.js +1 -0
  121. package/dist/client/static/js/railroad-peg-WCYAUIDC-0p5sxzpx.js +1 -0
  122. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-wy2mgya6.js → railroadDiagram-XR7U4H2S-rw8cj5f3.js} +1 -1
  123. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-6z9xdgbq.js → requirementDiagram-PLB6GJNP-qyrse7mb.js} +1 -1
  124. package/dist/client/static/js/{ruby-r81ytgcm.js → ruby-qy8mhstq.js} +1 -1
  125. package/dist/client/static/js/{rust-frn3szvc.js → rust-fpshqnk0.js} +1 -1
  126. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-rtmxk3ys.js → sankeyDiagram-IPEJSGJF-254qr59q.js} +1 -1
  127. package/dist/client/static/js/{sass-9bxped7y.js → sass-kbwea482.js} +1 -1
  128. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-awzcrafg.js → sequenceDiagram-PO4LG4MO-y9xjxfc5.js} +3 -3
  129. package/dist/client/static/js/{sizeCapture-INFHLROL-03gy196j.js → sizeCapture-INFHLROL-sc5e60t3.js} +1 -1
  130. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-an8v3q5n.js → stateDiagram-v2-GCMORJYK-r134s4xr.js} +2 -2
  131. package/dist/client/static/js/{swimlanes-2SLR337P-n9yb4wcs.js → swimlanes-2SLR337P-xc7rbawt.js} +1 -1
  132. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-kdcdamkj.js +8 -0
  133. package/dist/client/static/js/{timeline-definition-EJHVYXUP-jceb575g.js → timeline-definition-EJHVYXUP-cgjd8shk.js} +2 -2
  134. package/dist/client/static/js/treeView-Q6P3EWNA-8j14nnd1.js +1 -0
  135. package/dist/client/static/js/treemap-WGGIJYW6-esf993kk.js +1 -0
  136. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-888h3100.js → usecaseDiagram-POWQR4AR-9qsmjhm6.js} +4 -4
  137. package/dist/client/static/js/{vennDiagram-UO4OBE2U-wbfz0rzv.js → vennDiagram-UO4OBE2U-4grw9awx.js} +1 -1
  138. package/dist/client/static/js/{vue-c0rtg1wf.js → vue-j8vb9d7r.js} +1 -1
  139. package/dist/client/static/js/wardley-WFR3VGLG-v4dxm2sb.js +1 -0
  140. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-rn8c5qf9.js → wardleyDiagram-VNRHLVJA-8gxy0wat.js} +1 -1
  141. package/dist/client/static/js/xml-0py2vkw7.js +1 -0
  142. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-8sn1apt6.js → xychartDiagram-PMCCYNJV-5sh7tdrx.js} +2 -2
  143. package/dist/client/static/js/yaml-vghdz0f0.js +1 -0
  144. package/package.json +1 -1
  145. package/src/client/components/settings/categories/ConnectSettings.tsx +8 -1
  146. package/src/client/components/settings/categories/connect-settings/CloudflareConfig.test.tsx +84 -0
  147. package/src/client/components/settings/categories/connect-settings/CloudflareConfig.tsx +68 -0
  148. package/src/client/components/settings/categories/connect-settings/PairDialog.test.tsx +159 -0
  149. package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +40 -7
  150. package/src/client/components/workspace/git-panel/init-state.test.ts +5 -0
  151. package/src/client/hooks/chat/composer/speech-to-text.ts +24 -17
  152. package/src/client/hooks/connect/use-connect-status.ts +44 -19
  153. package/src/client/hooks/connect/use-pairing.ts +5 -0
  154. package/src/client/hooks/editor/file-actions.ts +3 -11
  155. package/src/client/hooks/editor/font.test.ts +2 -1
  156. package/src/client/hooks/editor/use-file-transfer.ts +2 -1
  157. package/src/client/lib/browser/download.ts +22 -0
  158. package/src/client/lib/notifications/watch.ts +4 -1
  159. package/src/server/lib/connect/cloudflared-config.server.ts +236 -0
  160. package/src/server/lib/connect/cloudflared-config.test.ts +245 -0
  161. package/src/server/lib/connect/cloudflared.lifecycle.test.ts +116 -15
  162. package/src/server/lib/connect/cloudflared.server.ts +53 -66
  163. package/src/server/lib/connect/pairing.server.ts +33 -0
  164. package/src/server/lib/connect/qr-png.server.test.ts +93 -0
  165. package/src/server/lib/connect/qr-png.server.ts +119 -0
  166. package/src/server/lib/connect/status.server.ts +10 -4
  167. package/src/server/routes/connect/index.ts +2 -0
  168. package/src/server/routes/connect/pair-qr.test.ts +72 -0
  169. package/src/server/routes/connect/pair-qr.ts +44 -0
  170. package/src/server/routes/connect/pair.ts +8 -2
  171. package/src/server/routes/connect/tunnels.test.ts +141 -0
  172. package/src/server/routes/connect/tunnels.ts +32 -7
  173. package/src/server/routes/notifications/stream.ts +11 -2
  174. package/src/shared/lib/connect/types.ts +7 -0
  175. package/src/shared/lib/dictation/capture-failure.test.ts +46 -0
  176. package/src/shared/lib/dictation/capture-failure.ts +36 -0
  177. package/dist/client/static/js/architecture-7GRP2DOG-fc9kmq1w.js +0 -1
  178. package/dist/client/static/js/css-6vj0d308.js +0 -1
  179. package/dist/client/static/js/cynefin-OW5HDTMX-a4t8992q.js +0 -1
  180. package/dist/client/static/js/eventmodeling-NTZA5JFV-18bdrkv5.js +0 -1
  181. package/dist/client/static/js/flowDiagram-KWPJA3E3-fg0yqx0h.js +0 -1
  182. package/dist/client/static/js/gitGraph-4MIJSDKK-8fa6y40p.js +0 -1
  183. package/dist/client/static/js/graphql-n43pd5fs.js +0 -1
  184. package/dist/client/static/js/html-dbrwss36.js +0 -1
  185. package/dist/client/static/js/index-6sf2vsp2.js +0 -1
  186. package/dist/client/static/js/info-A6RAGUB7-3hk844f7.js +0 -1
  187. package/dist/client/static/js/ini-j5dyq6gm.js +0 -1
  188. package/dist/client/static/js/java-g4dgwbfd.js +0 -1
  189. package/dist/client/static/js/jsx-7t5ecz9s.js +0 -1
  190. package/dist/client/static/js/lua-1g6w30de.js +0 -1
  191. package/dist/client/static/js/markdown-afx21x8c.js +0 -1
  192. package/dist/client/static/js/one-dark-pro-vwhfpzr8.js +0 -1
  193. package/dist/client/static/js/one-light-y5t9x6zh.js +0 -1
  194. package/dist/client/static/js/packet-AYTQ26CC-4nj2yy10.js +0 -1
  195. package/dist/client/static/js/pie-WAS4IAKB-k7rde3f9.js +0 -1
  196. package/dist/client/static/js/properties-thd83wey.js +0 -1
  197. package/dist/client/static/js/python-264ns4xw.js +0 -1
  198. package/dist/client/static/js/r-qw82kkv9.js +0 -1
  199. package/dist/client/static/js/radar-RG4KPBEZ-513dpw4f.js +0 -1
  200. package/dist/client/static/js/railroad-74A4TZTK-9bqnst9c.js +0 -1
  201. package/dist/client/static/js/railroad-abnf-HS5TGJTU-7367d5bv.js +0 -1
  202. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-b806b1mj.js +0 -1
  203. package/dist/client/static/js/railroad-peg-WCYAUIDC-5a67rwf8.js +0 -1
  204. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-nx5nfnf0.js +0 -8
  205. package/dist/client/static/js/treeView-Q6P3EWNA-kcy40evb.js +0 -1
  206. package/dist/client/static/js/treemap-WGGIJYW6-fsrvqxf4.js +0 -1
  207. package/dist/client/static/js/wardley-WFR3VGLG-36dmxww4.js +0 -1
  208. package/dist/client/static/js/xml-dz51p1m3.js +0 -1
  209. package/dist/client/static/js/yaml-2cfkd30t.js +0 -1
  210. package/src/server/lib/connect/cloudflared.server.test.ts +0 -65
@@ -0,0 +1,236 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The cloudflared config: where it is, what it says, and the copy cloudflared
8
+ * actually runs.
9
+ *
10
+ * Two facts decide the tunnel's destination. The config path is a stored
11
+ * preference (page), an environment override (`CLOUDFLARED_CONFIG`) or the
12
+ * documented default; the ingress `service:` is what cloudflared dials, and it
13
+ * must be THIS instance's port or a second Kabmo silently gets the first one's
14
+ * traffic. `--url` cannot fix that — see `deriveCloudflaredRunConfig`.
15
+ */
16
+
17
+ import fs from 'fs';
18
+ import os from 'os';
19
+ import path from 'path';
20
+ import { getDb } from '@/server/db.server';
21
+ import { readSettingsJson, writeSettingsJson } from '@/server/lib/db/settings-store';
22
+
23
+ /** `app_settings` key holding the config path chosen on the Connect page. */
24
+ const CLOUDFLARE_CONFIG_KEY = 'connect.cloudflareConfigPath';
25
+
26
+ export interface CloudflaredConfig {
27
+ /** The tunnel name or UUID from `tunnel:`. */
28
+ tunnel: string | null;
29
+ /** The first public hostname in the ingress list. */
30
+ hostname: string | null;
31
+ }
32
+
33
+ /** Where cloudflared looks for its config, honouring the documented override. */
34
+ export function cloudflaredConfigPath(): string {
35
+ const override = (Bun.env.CLOUDFLARED_CONFIG ?? '').trim();
36
+ if (override) return override;
37
+ return path.join(os.homedir(), '.cloudflared', 'config.yml');
38
+ }
39
+
40
+ function expandHome(value: string): string {
41
+ if (value === '~') return os.homedir();
42
+ if (value.startsWith('~/')) return path.join(os.homedir(), value.slice(2));
43
+ return value;
44
+ }
45
+
46
+ /**
47
+ * The config the Connect page and the start path agree on.
48
+ *
49
+ * A path saved on the page wins over `CLOUDFLARED_CONFIG`, which wins over
50
+ * `~/.cloudflared/config.yml`. The page allows the override because a config
51
+ * kept outside the home directory (a secret store, a work profile) is a normal
52
+ * setup, and editing an environment variable before every start is not.
53
+ */
54
+ export async function resolveCloudflaredConfigPath(): Promise<string> {
55
+ const db = await getDb();
56
+ const stored = await readSettingsJson<unknown>(db, CLOUDFLARE_CONFIG_KEY, null);
57
+ if (typeof stored === 'string' && stored.trim()) return stored.trim();
58
+ return cloudflaredConfigPath();
59
+ }
60
+
61
+ export interface SaveConfigOutcome {
62
+ ok: boolean;
63
+ /** The path now in effect, when the save succeeded. */
64
+ path: string | null;
65
+ reason: string | null;
66
+ }
67
+
68
+ /**
69
+ * Persist a config path after proving cloudflared could run from it.
70
+ *
71
+ * A saved path that is missing or has no ingress hostname would put a dead
72
+ * switch on the page, so the write is refused with the reason the reader can
73
+ * act on. An empty string resets to the environment/default path.
74
+ */
75
+ export async function saveCloudflaredConfigPath(raw: unknown): Promise<SaveConfigOutcome> {
76
+ if (typeof raw !== 'string') {
77
+ return { ok: false, path: null, reason: 'Expected a config path.' };
78
+ }
79
+ const db = await getDb();
80
+ const trimmed = raw.trim();
81
+ if (!trimmed) {
82
+ await writeSettingsJson(db, CLOUDFLARE_CONFIG_KEY, null);
83
+ return { ok: true, path: cloudflaredConfigPath(), reason: null };
84
+ }
85
+
86
+ const expanded = expandHome(trimmed);
87
+ if (!path.isAbsolute(expanded)) {
88
+ return { ok: false, path: null, reason: 'The config path must be absolute.' };
89
+ }
90
+ const resolved = path.resolve(expanded);
91
+ let isFile = false;
92
+ try {
93
+ isFile = fs.statSync(resolved).isFile();
94
+ } catch {
95
+ return { ok: false, path: null, reason: `No config file at ${resolved}.` };
96
+ }
97
+ if (!isFile) {
98
+ return { ok: false, path: null, reason: `${resolved} is not a file.` };
99
+ }
100
+
101
+ const config = readCloudflaredConfig(resolved);
102
+ if (!config) {
103
+ return {
104
+ ok: false,
105
+ path: null,
106
+ reason: `${resolved} is not a cloudflared config: it has no tunnel: or ingress: entry.`,
107
+ };
108
+ }
109
+ if (!config.hostname) {
110
+ return {
111
+ ok: false,
112
+ path: null,
113
+ reason: `The config at ${resolved} has no ingress hostname, so there is no public URL to show.`,
114
+ };
115
+ }
116
+
117
+ await writeSettingsJson(db, CLOUDFLARE_CONFIG_KEY, resolved);
118
+ return { ok: true, path: resolved, reason: null };
119
+ }
120
+
121
+ /**
122
+ * Read the two facts this page needs out of the YAML.
123
+ *
124
+ * A line scan rather than a YAML parser: the file is written by
125
+ * `cloudflared tunnel create` and by hand, and the only fields read here are a
126
+ * top-level `tunnel:` and the first `hostname:` under `ingress:`. Pulling in a
127
+ * parser for two scalars would be a dependency the rest of the server does not
128
+ * have, and a malformed file must degrade to "not configured" rather than throw.
129
+ */
130
+ export function readCloudflaredConfig(file: string): CloudflaredConfig | null {
131
+ let text: string;
132
+ try {
133
+ text = fs.readFileSync(file, 'utf8');
134
+ } catch {
135
+ return null;
136
+ }
137
+
138
+ let tunnel: string | null = null;
139
+ let hostname: string | null = null;
140
+ let inIngress = false;
141
+ for (const rawLine of text.split('\n')) {
142
+ const line = rawLine.replace(/\s+#.*$/, '');
143
+ if (/^tunnel:\s*/.test(line)) {
144
+ tunnel = line.replace(/^tunnel:\s*/, '').trim().replace(/^["']|["']$/g, '') || null;
145
+ continue;
146
+ }
147
+ if (/^ingress:\s*$/.test(line)) {
148
+ inIngress = true;
149
+ continue;
150
+ }
151
+ if (inIngress && /^\S/.test(line)) {
152
+ // A new top-level key ends the ingress block.
153
+ inIngress = false;
154
+ }
155
+ if (inIngress && hostname === null) {
156
+ const match = /^\s*-\s*hostname:\s*(\S+)/.exec(line) ?? /^\s*hostname:\s*(\S+)/.exec(line);
157
+ if (match?.[1]) hostname = match[1].replace(/^["']|["']$/g, '');
158
+ }
159
+ }
160
+
161
+ if (!tunnel && !hostname) return null;
162
+ return { tunnel, hostname };
163
+ }
164
+
165
+ /**
166
+ * The config cloudflared actually runs with, pointed at this instance's port.
167
+ *
168
+ * `--url` does NOT override an `ingress:` block: cloudflared parses the config's
169
+ * rules first and only falls back to the CLI origin when `ingress` is empty
170
+ * (`ingress.ParseIngressFromConfigAndCLI`). Kabmo refuses a config without an
171
+ * ingress hostname, so every config it accepts would ignore `--url` and send
172
+ * traffic to whatever `service:` names — often a different port or a different
173
+ * app. The first rule that names a hostname therefore gets its `service:`
174
+ * rewritten in a runtime copy; the user's file is never touched.
175
+ *
176
+ * Returns null when there is no ingress rule with a hostname to rewrite.
177
+ */
178
+ export function deriveCloudflaredRunConfig(text: string, port: number): string | null {
179
+ const lines = text.split('\n');
180
+ const ingressAt = lines.findIndex((line) => /^ingress:\s*$/.test(line.replace(/\s+#.*$/, '')));
181
+ if (ingressAt === -1) return null;
182
+
183
+ // A new top-level key ends the ingress block.
184
+ let end = lines.length;
185
+ for (let i = ingressAt + 1; i < lines.length; i++) {
186
+ if (/^\S/.test(lines[i])) {
187
+ end = i;
188
+ break;
189
+ }
190
+ }
191
+
192
+ // Only items at the first rule's indentation start a new rule; a nested
193
+ // `ipRules:` list under `originRequest` must not cut the rule in two.
194
+ const itemPattern = /^(\s*)-\s/;
195
+ const items: Array<{ at: number; indent: string }> = [];
196
+ for (let i = ingressAt + 1; i < end; i++) {
197
+ const item = itemPattern.exec(lines[i]);
198
+ if (item) items.push({ at: i, indent: item[1] });
199
+ }
200
+ if (items.length === 0) return null;
201
+ const ruleIndent = items[0].indent;
202
+ const starts = items.filter((item) => item.indent === ruleIndent).map((item) => item.at);
203
+
204
+ const hostnamePattern = /^(\s*)(-\s*)?hostname:\s*(\S+)/;
205
+ const servicePattern = /^(\s*)service:\s*/;
206
+ for (let rule = 0; rule < starts.length; rule++) {
207
+ const from = starts[rule];
208
+ const to = rule + 1 < starts.length ? starts[rule + 1] : end;
209
+ let hostnameAt = -1;
210
+ for (let i = from; i < to; i++) {
211
+ if (hostnamePattern.test(lines[i])) {
212
+ hostnameAt = i;
213
+ break;
214
+ }
215
+ }
216
+ if (hostnameAt === -1) continue;
217
+
218
+ const copy = lines.slice();
219
+ for (let i = from; i < to; i++) {
220
+ const service = servicePattern.exec(lines[i]);
221
+ if (!service) continue;
222
+ const cr = lines[i].endsWith('\r') ? '\r' : '';
223
+ copy[i] = `${service[1]}service: http://127.0.0.1:${port}${cr}`;
224
+ return copy.join('\n');
225
+ }
226
+
227
+ // The rule has a hostname but no service of its own: add one beside it.
228
+ const hostname = hostnamePattern.exec(lines[hostnameAt]) as RegExpExecArray;
229
+ const indent = hostname[1] + (hostname[2] ? ' ' : '');
230
+ const cr = lines[hostnameAt].endsWith('\r') ? '\r' : '';
231
+ copy.splice(hostnameAt + 1, 0, `${indent}service: http://127.0.0.1:${port}${cr}`);
232
+ return copy.join('\n');
233
+ }
234
+
235
+ return null;
236
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The cloudflared config: the scan, the derived run copy, and the saved path.
8
+ *
9
+ * Three load-bearing claims. A config with an ingress block but no hostname is
10
+ * "not configured", because reporting it would put a URL on the page that does
11
+ * not resolve. The derived copy rewrites the FIRST hostname rule and only that
12
+ * one — the catch-all 404 rule must stay, or cloudflared refuses to start. And a
13
+ * saved path is written only after it names a runnable config, so the page never
14
+ * shows a path the tunnel cannot use.
15
+ */
16
+
17
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
18
+ import fs from 'fs';
19
+ import os from 'os';
20
+ import path from 'path';
21
+ import {
22
+ cloudflaredConfigPath,
23
+ deriveCloudflaredRunConfig,
24
+ readCloudflaredConfig,
25
+ resolveCloudflaredConfigPath,
26
+ saveCloudflaredConfigPath,
27
+ } from '@/server/lib/connect/cloudflared-config.server';
28
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
29
+
30
+ const dirs: string[] = [];
31
+
32
+ function tempDir(): string {
33
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cf-'));
34
+ dirs.push(dir);
35
+ return dir;
36
+ }
37
+
38
+ function writeConfig(text: string): string {
39
+ const file = path.join(tempDir(), 'config.yml');
40
+ fs.writeFileSync(file, text);
41
+ return file;
42
+ }
43
+
44
+ const VALID = [
45
+ 'tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef',
46
+ 'credentials-file: /home/me/.cloudflared/6ff42ae2.json',
47
+ '',
48
+ 'ingress:',
49
+ ' - hostname: kabmo.example.com',
50
+ ' service: http://localhost:3000',
51
+ ' - service: http_status:404',
52
+ '',
53
+ ].join('\n');
54
+
55
+ afterEach(() => {
56
+ for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
57
+ });
58
+
59
+ describe('readCloudflaredConfig', () => {
60
+ test('reads the tunnel name and the first ingress hostname', () => {
61
+ expect(readCloudflaredConfig(writeConfig(VALID))).toEqual({
62
+ tunnel: '6ff42ae2-765d-4adf-8112-31c55c1551ef',
63
+ hostname: 'kabmo.example.com',
64
+ });
65
+ });
66
+
67
+ test('strips quotes around a value', () => {
68
+ const file = writeConfig(['tunnel: "my-tunnel"', 'ingress:', ' - hostname: "a.example.com"'].join('\n'));
69
+ expect(readCloudflaredConfig(file)).toEqual({ tunnel: 'my-tunnel', hostname: 'a.example.com' });
70
+ });
71
+
72
+ test('answers null for a file with neither field', () => {
73
+ expect(readCloudflaredConfig(writeConfig('metrics: 127.0.0.1:20241\n'))).toBeNull();
74
+ });
75
+
76
+ test('answers null for a missing file', () => {
77
+ expect(readCloudflaredConfig(path.join(os.tmpdir(), 'kabmo-does-not-exist.yml'))).toBeNull();
78
+ });
79
+
80
+ test('does not read a hostname from outside the ingress block', () => {
81
+ const file = writeConfig(['tunnel: t', 'hostname: not-ingress.example.com', 'ingress:', ' - service: http_status:404'].join('\n'));
82
+ expect(readCloudflaredConfig(file)).toEqual({ tunnel: 't', hostname: null });
83
+ });
84
+ });
85
+
86
+ describe('deriveCloudflaredRunConfig', () => {
87
+ test('rewrites the first hostname rule to this port and keeps the fallback rule', () => {
88
+ const derived = deriveCloudflaredRunConfig(VALID, 5173);
89
+
90
+ expect(derived).not.toBeNull();
91
+ expect(derived).toContain(' service: http://127.0.0.1:5173');
92
+ expect(derived).not.toContain('http://localhost:3000');
93
+ expect(derived).toContain(' - service: http_status:404');
94
+ expect(derived).toContain('credentials-file: /home/me/.cloudflared/6ff42ae2.json');
95
+ expect(derived).toContain('tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef');
96
+ });
97
+
98
+ test('adds a service to a hostname rule that has none', () => {
99
+ const derived = deriveCloudflaredRunConfig(
100
+ ['ingress:', ' - hostname: kabmo.example.com', ' - service: http_status:404'].join('\n'),
101
+ 4100,
102
+ );
103
+
104
+ expect(derived?.split('\n')).toEqual([
105
+ 'ingress:',
106
+ ' - hostname: kabmo.example.com',
107
+ ' service: http://127.0.0.1:4100',
108
+ ' - service: http_status:404',
109
+ ]);
110
+ });
111
+
112
+ test('skips a leading rule without a hostname', () => {
113
+ const derived = deriveCloudflaredRunConfig(
114
+ [
115
+ 'ingress:',
116
+ ' - service: http_status:404',
117
+ ' - hostname: a.example.com',
118
+ ' service: http://localhost:1',
119
+ ].join('\n'),
120
+ 4200,
121
+ );
122
+
123
+ expect(derived?.split('\n')[1]).toBe(' - service: http_status:404');
124
+ expect(derived).toContain(' service: http://127.0.0.1:4200');
125
+ expect(derived).not.toContain('http://localhost:1');
126
+ });
127
+
128
+ test('leaves an originRequest block under the rule intact', () => {
129
+ const derived = deriveCloudflaredRunConfig(
130
+ [
131
+ 'ingress:',
132
+ ' - hostname: a.example.com',
133
+ ' service: http://localhost:1',
134
+ ' originRequest:',
135
+ ' noTLSVerify: true',
136
+ ' - service: http_status:404',
137
+ ].join('\n'),
138
+ 4300,
139
+ );
140
+
141
+ expect(derived).toContain(' noTLSVerify: true');
142
+ });
143
+
144
+ test('does not mistake a nested list for the next ingress rule', () => {
145
+ const derived = deriveCloudflaredRunConfig(
146
+ [
147
+ 'ingress:',
148
+ ' - hostname: a.example.com',
149
+ ' originRequest:',
150
+ ' ipRules:',
151
+ ' - prefix: 10.0.0.0/8',
152
+ ' ports: [80]',
153
+ ' service: http://localhost:1',
154
+ ' - service: http_status:404',
155
+ ].join('\n'),
156
+ 4350,
157
+ );
158
+
159
+ expect(derived).toContain(' service: http://127.0.0.1:4350');
160
+ expect(derived).not.toContain('http://localhost:1');
161
+ expect(derived).toContain(' - prefix: 10.0.0.0/8');
162
+ });
163
+
164
+ test('answers null without an ingress block', () => {
165
+ expect(deriveCloudflaredRunConfig('tunnel: t\n', 4400)).toBeNull();
166
+ });
167
+
168
+ test('answers null when the ingress block has no hostname', () => {
169
+ expect(deriveCloudflaredRunConfig('ingress:\n - service: http_status:404\n', 4500)).toBeNull();
170
+ });
171
+ });
172
+
173
+ describe('the saved config path', () => {
174
+ let previousEnv: string | undefined;
175
+
176
+ beforeEach(async () => {
177
+ previousEnv = Bun.env.CLOUDFLARED_CONFIG;
178
+ await isolateDb();
179
+ });
180
+
181
+ afterEach(async () => {
182
+ if (previousEnv === undefined) delete Bun.env.CLOUDFLARED_CONFIG;
183
+ else Bun.env.CLOUDFLARED_CONFIG = previousEnv;
184
+ await releaseDb();
185
+ });
186
+
187
+ test('falls back to CLOUDFLARED_CONFIG until a path is saved', async () => {
188
+ const file = writeConfig(VALID);
189
+ Bun.env.CLOUDFLARED_CONFIG = file;
190
+
191
+ expect(cloudflaredConfigPath()).toBe(file);
192
+ expect(await resolveCloudflaredConfigPath()).toBe(file);
193
+ });
194
+
195
+ test('a saved path wins over the environment', async () => {
196
+ const file = writeConfig(VALID);
197
+ Bun.env.CLOUDFLARED_CONFIG = path.join(os.tmpdir(), 'not-this-one.yml');
198
+
199
+ const saved = await saveCloudflaredConfigPath(file);
200
+
201
+ expect(saved).toEqual({ ok: true, path: path.resolve(file), reason: null });
202
+ expect(await resolveCloudflaredConfigPath()).toBe(path.resolve(file));
203
+ });
204
+
205
+ test('an empty string clears the saved path', async () => {
206
+ const file = writeConfig(VALID);
207
+ Bun.env.CLOUDFLARED_CONFIG = file;
208
+ await saveCloudflaredConfigPath(writeConfig(VALID));
209
+
210
+ expect(await saveCloudflaredConfigPath(' ')).toEqual({ ok: true, path: file, reason: null });
211
+ expect(await resolveCloudflaredConfigPath()).toBe(file);
212
+ });
213
+
214
+ test('refuses a relative path', async () => {
215
+ expect(await saveCloudflaredConfigPath('config.yml')).toEqual({
216
+ ok: false,
217
+ path: null,
218
+ reason: 'The config path must be absolute.',
219
+ });
220
+ });
221
+
222
+ test('refuses a file that does not exist', async () => {
223
+ const missing = path.join(os.tmpdir(), 'kabmo-no-config-here.yml');
224
+ const outcome = await saveCloudflaredConfigPath(missing);
225
+
226
+ expect(outcome.ok).toBe(false);
227
+ expect(outcome.reason).toContain(missing);
228
+ });
229
+
230
+ test('refuses a config without an ingress hostname', async () => {
231
+ const file = writeConfig('tunnel: t\ningress:\n - service: http_status:404\n');
232
+ const outcome = await saveCloudflaredConfigPath(file);
233
+
234
+ expect(outcome.ok).toBe(false);
235
+ expect(outcome.reason).toContain('no ingress hostname');
236
+ });
237
+
238
+ test('refuses a non-string path', async () => {
239
+ expect(await saveCloudflaredConfigPath(42)).toEqual({
240
+ ok: false,
241
+ path: null,
242
+ reason: 'Expected a config path.',
243
+ });
244
+ });
245
+ });
@@ -9,9 +9,9 @@
9
9
  * A real named tunnel needs an account, a domain and a credentials file, so the
10
10
  * start path is unreachable on a machine that has none — which is exactly the
11
11
  * path that would otherwise ship untested. The stand-in is a script that stays
12
- * alive, which is all `startCloudflared` requires: it records the process, derives
13
- * the public URL from the config's hostname, and reports liveness from the
14
- * process's own exit code.
12
+ * alive and records its argv and the config it was handed: the start path must
13
+ * spawn `tunnel --config <runtime copy> run`, the copy must name THIS port, and
14
+ * the copy must be gone once the tunnel stops.
15
15
  */
16
16
 
17
17
  import { afterEach, describe, expect, test } from 'bun:test';
@@ -32,25 +32,84 @@ const posixOnly = process.platform !== 'win32';
32
32
 
33
33
  const dirs: string[] = [];
34
34
 
35
- function fakeCloudflared(): string {
36
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cf-bin-'));
35
+ function tempDir(): string {
36
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-cf-'));
37
37
  dirs.push(dir);
38
- const file = path.join(dir, 'cloudflared');
39
- // Stays alive until killed, like the real `tunnel run`.
40
- fs.writeFileSync(file, '#!/bin/sh\nexec sleep 30\n');
41
- fs.chmodSync(file, 0o755);
38
+ return dir;
39
+ }
40
+
41
+ const CONFIG = [
42
+ 'tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef',
43
+ 'credentials-file: /home/me/.cloudflared/6ff42ae2.json',
44
+ '',
45
+ 'ingress:',
46
+ ' - hostname: kabmo.example.com',
47
+ ' service: http://localhost:3000',
48
+ ' - service: http_status:404',
49
+ '',
50
+ ].join('\n');
51
+
52
+ function writeConfig(text: string): string {
53
+ const file = path.join(tempDir(), 'config.yml');
54
+ fs.writeFileSync(file, text);
42
55
  return file;
43
56
  }
44
57
 
58
+ /** Stays alive until killed, like the real `tunnel run`, and records its argv. */
59
+ function fakeCloudflared(): { binary: string; argsFile: string; configFile: string } {
60
+ const dir = tempDir();
61
+ const binary = path.join(dir, 'cloudflared');
62
+ const argsFile = path.join(dir, 'args.txt');
63
+ const configFile = path.join(dir, 'handed-config.yml');
64
+ fs.writeFileSync(
65
+ binary,
66
+ [
67
+ '#!/bin/sh',
68
+ `args="${argsFile}"`,
69
+ `cfg="${configFile}"`,
70
+ ': > "$args.tmp"',
71
+ 'while [ $# -gt 0 ]; do',
72
+ ' printf \'%s\\n\' "$1" >> "$args.tmp"',
73
+ ' if [ "$1" = "--config" ]; then',
74
+ ' shift',
75
+ ' printf \'%s\\n\' "$1" >> "$args.tmp"',
76
+ ' cp "$1" "$cfg" 2>/dev/null',
77
+ ' fi',
78
+ ' shift',
79
+ 'done',
80
+ // Rename, so the reader never sees a half-written file.
81
+ 'mv "$args.tmp" "$args"',
82
+ 'exec sleep 30',
83
+ '',
84
+ ].join('\n'),
85
+ );
86
+ fs.chmodSync(binary, 0o755);
87
+ return { binary, argsFile, configFile };
88
+ }
89
+
90
+ async function waitForFile(file: string): Promise<void> {
91
+ if (fs.existsSync(file)) return;
92
+ const signal = AbortSignal.timeout(2_000);
93
+ try {
94
+ for await (const event of fs.promises.watch(path.dirname(file), { signal })) {
95
+ void event;
96
+ if (fs.existsSync(file)) return;
97
+ }
98
+ } catch (error) {
99
+ if (signal.aborted) throw new Error(`Timed out waiting for ${file}`);
100
+ throw error;
101
+ }
102
+ }
103
+
45
104
  afterEach(() => {
46
105
  for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
47
106
  });
48
107
 
49
108
  describe('cloudflared lifecycle', () => {
50
109
  test.skipIf(!posixOnly)('starting records the public URL and reports the process alive', async () => {
51
- const binary = fakeCloudflared();
110
+ const { binary } = fakeCloudflared();
52
111
  const port = 39_101;
53
- const outcome = await startCloudflared(binary, '/tmp/config.yml', 'kabmo.example.com', port);
112
+ const outcome = await startCloudflared(binary, writeConfig(CONFIG), 'kabmo.example.com', port);
54
113
 
55
114
  expect(outcome.ok).toBe(true);
56
115
  expect(outcome.url).toBe('https://kabmo.example.com');
@@ -62,11 +121,39 @@ describe('cloudflared lifecycle', () => {
62
121
  expect(runningTunnelUrl(port)).toBeNull();
63
122
  });
64
123
 
124
+ test.skipIf(!posixOnly)('runs a runtime copy pointed at this port, not the file on disk', async () => {
125
+ const { binary, argsFile, configFile } = fakeCloudflared();
126
+ const source = writeConfig(CONFIG);
127
+ const port = 39_105;
128
+
129
+ await startCloudflared(binary, source, 'kabmo.example.com', port);
130
+ await waitForFile(argsFile);
131
+
132
+ const args = fs.readFileSync(argsFile, 'utf8').trim().split('\n');
133
+ expect(args.slice(0, 2)).toEqual(['tunnel', '--config']);
134
+ const runtimePath = args[2];
135
+ expect(args.slice(3)).toEqual(['run']);
136
+ expect(args).not.toContain('--url');
137
+ expect(runtimePath).not.toBe(source);
138
+ expect(fs.existsSync(runtimePath)).toBe(true);
139
+
140
+ const handed = fs.readFileSync(configFile, 'utf8');
141
+ expect(handed).toContain(`service: http://127.0.0.1:${port}`);
142
+ expect(handed).not.toContain('http://localhost:3000');
143
+ expect(handed).toContain('credentials-file: /home/me/.cloudflared/6ff42ae2.json');
144
+ // The user's file is never modified.
145
+ expect(fs.readFileSync(source, 'utf8')).toBe(CONFIG);
146
+
147
+ stopCloudflared(port);
148
+ expect(fs.existsSync(path.dirname(runtimePath))).toBe(false);
149
+ });
150
+
65
151
  test.skipIf(!posixOnly)('starting twice for one port reuses the running tunnel', async () => {
66
- const binary = fakeCloudflared();
152
+ const { binary } = fakeCloudflared();
153
+ const config = writeConfig(CONFIG);
67
154
  const port = 39_102;
68
- await startCloudflared(binary, '/tmp/config.yml', 'a.example.com', port);
69
- const second = await startCloudflared(binary, '/tmp/config.yml', 'b.example.com', port);
155
+ await startCloudflared(binary, config, 'a.example.com', port);
156
+ const second = await startCloudflared(binary, config, 'b.example.com', port);
70
157
 
71
158
  // The second call must not spawn a second process, and must not claim a
72
159
  // different hostname than the one actually running.
@@ -74,13 +161,27 @@ describe('cloudflared lifecycle', () => {
74
161
  stopCloudflared(port);
75
162
  });
76
163
 
164
+ test('a config with no ingress hostname is refused instead of spawned', async () => {
165
+ const { binary } = fakeCloudflared();
166
+ const outcome = await startCloudflared(
167
+ binary,
168
+ writeConfig('tunnel: t\ningress:\n - service: http_status:404\n'),
169
+ 'x.example.com',
170
+ 39_106,
171
+ );
172
+
173
+ expect(outcome.ok).toBe(false);
174
+ expect(outcome.reason).toContain('no ingress rule');
175
+ expect(cloudflaredAlive(39_106)).toBe(false);
176
+ });
177
+
77
178
  test('stopping a tunnel that was never started is not an error', () => {
78
179
  expect(stopCloudflared(39_103)).toEqual({ ok: true, reason: null });
79
180
  expect(cloudflaredAlive(39_103)).toBe(false);
80
181
  });
81
182
 
82
183
  test('a binary that cannot be spawned reports the reason', async () => {
83
- const outcome = await startCloudflared('/nonexistent/cloudflared', '/tmp/config.yml', 'x.example.com', 39_104);
184
+ const outcome = await startCloudflared('/nonexistent/cloudflared', writeConfig(CONFIG), 'x.example.com', 39_104);
84
185
  expect(outcome.ok).toBe(false);
85
186
  expect(outcome.reason).toBeTruthy();
86
187
  expect(cloudflaredAlive(39_104)).toBe(false);