@rocket.chat/houston 0.27.0-next.2 → 2.1.8

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 (291) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +669 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/troubleshooting.md +193 -0
  12. package/data/docs/upgrading.md +84 -0
  13. package/data/docs/voice.md +253 -0
  14. package/data/iam/engineer-policy.json +11 -0
  15. package/data/iam/engineer-rbac.yaml +42 -0
  16. package/data/iam/operator-policy.json +211 -0
  17. package/data/loadtest/badbot.js +22 -0
  18. package/data/loadtest/common.js +168 -0
  19. package/data/loadtest/custom.js +20 -0
  20. package/data/loadtest/journey.js +58 -0
  21. package/data/loadtest/login.js +18 -0
  22. package/data/loadtest/messages.js +13 -0
  23. package/data/loadtest/mixed.js +39 -0
  24. package/data/loadtest/read.js +12 -0
  25. package/data/loadtest/webhook.js +20 -0
  26. package/data/monitoring/houston-logs.json +98 -0
  27. package/data/monitoring/k6-loadtest.json +610 -0
  28. package/data/monitoring/mongodb-exporter.json +3007 -0
  29. package/data/monitoring/node-exporter-full.json +16114 -0
  30. package/data/monitoring/rocketchat-metrics.json +6471 -0
  31. package/data/presets/airgapped.yaml +16 -0
  32. package/data/presets/default.yaml +9 -0
  33. package/data/seed/avatar-0.png +0 -0
  34. package/data/seed/avatar-1.png +0 -0
  35. package/data/seed/avatar-2.png +0 -0
  36. package/data/seed/avatar-3.png +0 -0
  37. package/data/seed/avatar-4.png +0 -0
  38. package/data/seed/avatar-5.png +0 -0
  39. package/data/seed/avatar-6.png +0 -0
  40. package/data/seed/avatar-7.png +0 -0
  41. package/data/seed/seed-metrics.csv +3 -0
  42. package/data/seed/seed-preview.png +0 -0
  43. package/data/seed/seed-report.pdf +32 -0
  44. package/data/seed/seed-runbook.txt +3 -0
  45. package/data/skill/SKILL.md +399 -0
  46. package/data/versions.yaml +55 -0
  47. package/data/voice/freeswitch/drachtio.xml +52 -0
  48. package/data/voice/freeswitch/public.xml +87 -0
  49. package/data/webui/app.css +2003 -0
  50. package/data/webui/index.html +678 -0
  51. package/data/webui/js/api.js +561 -0
  52. package/data/webui/js/boot.js +44 -0
  53. package/data/webui/js/clusters-tail.js +1377 -0
  54. package/data/webui/js/clusters.js +896 -0
  55. package/data/webui/js/create.js +276 -0
  56. package/data/webui/js/detail.js +507 -0
  57. package/data/webui/js/jobs.js +636 -0
  58. package/data/webui/js/logs.js +634 -0
  59. package/data/webui/js/main.js +14 -0
  60. package/data/webui/js/options.js +408 -0
  61. package/data/webui/js/people.js +438 -0
  62. package/data/webui/js/perf.js +303 -0
  63. package/data/webui/js/render.js +438 -0
  64. package/data/webui/js/shared.js +3 -0
  65. package/data/webui/js/state.js +583 -0
  66. package/data/webui/js/theme.js +123 -0
  67. package/data/webui/js/util.js +584 -0
  68. package/dist/cli/app.js +593 -0
  69. package/dist/cli/capabilities.js +76 -0
  70. package/dist/cli/cell-widths.js +495 -0
  71. package/dist/cli/entry.js +10 -0
  72. package/dist/cli/error-panel.js +492 -0
  73. package/dist/cli/handlers/actor.js +84 -0
  74. package/dist/cli/handlers/https.js +614 -0
  75. package/dist/cli/handlers/prompt.js +299 -0
  76. package/dist/cli/handlers/users.js +226 -0
  77. package/dist/cli/handlers.js +3678 -0
  78. package/dist/cli/help.js +183 -0
  79. package/dist/cli/index.js +15 -0
  80. package/dist/cli/perf.js +810 -0
  81. package/dist/cli/render.js +254 -0
  82. package/dist/cli/serve.js +858 -0
  83. package/dist/cli/spec-data.js +2593 -0
  84. package/dist/cli/spec-types.js +8 -0
  85. package/dist/cli/usage-error.js +520 -0
  86. package/dist/cli/wire.js +70 -0
  87. package/dist/core/audit.js +346 -0
  88. package/dist/core/backup-compat.js +85 -0
  89. package/dist/core/backup.js +1639 -0
  90. package/dist/core/cluster.js +1398 -0
  91. package/dist/core/configimport.js +344 -0
  92. package/dist/core/data.js +267 -0
  93. package/dist/core/database-of.js +82 -0
  94. package/dist/core/diagnose.js +159 -0
  95. package/dist/core/doctor.js +1518 -0
  96. package/dist/core/edge/acme.js +338 -0
  97. package/dist/core/edge/engine.js +500 -0
  98. package/dist/core/edge/networks.js +174 -0
  99. package/dist/core/edge/paths.js +107 -0
  100. package/dist/core/edge/routes.js +251 -0
  101. package/dist/core/edge/routeyml.js +195 -0
  102. package/dist/core/edge/runtime.js +493 -0
  103. package/dist/core/edge/spec.js +305 -0
  104. package/dist/core/edge/types.js +202 -0
  105. package/dist/core/eks-docs.js +135 -0
  106. package/dist/core/eks.js +2240 -0
  107. package/dist/core/envvars.js +562 -0
  108. package/dist/core/eventlog.js +541 -0
  109. package/dist/core/firstrun.js +153 -0
  110. package/dist/core/journal.js +691 -0
  111. package/dist/core/kube/ask.js +231 -0
  112. package/dist/core/kube/capabilities.js +269 -0
  113. package/dist/core/kube/certmanager.js +452 -0
  114. package/dist/core/kube/chart.js +413 -0
  115. package/dist/core/kube/cluster.js +196 -0
  116. package/dist/core/kube/context.js +545 -0
  117. package/dist/core/kube/endpoints.js +448 -0
  118. package/dist/core/kube/exec.js +195 -0
  119. package/dist/core/kube/forward.js +732 -0
  120. package/dist/core/kube/grafana-ingress.js +110 -0
  121. package/dist/core/kube/ingress.js +218 -0
  122. package/dist/core/kube/manifests.js +361 -0
  123. package/dist/core/kube/monitoring.js +768 -0
  124. package/dist/core/kube/names.js +237 -0
  125. package/dist/core/kube/namespace.js +678 -0
  126. package/dist/core/kube/operator.js +941 -0
  127. package/dist/core/kube/probe.js +202 -0
  128. package/dist/core/kube/reachability.js +163 -0
  129. package/dist/core/kube/release.js +439 -0
  130. package/dist/core/kube/replicaset.js +180 -0
  131. package/dist/core/kube/scale.js +398 -0
  132. package/dist/core/kube/status.js +633 -0
  133. package/dist/core/kube/tools.js +238 -0
  134. package/dist/core/kube/transfer.js +173 -0
  135. package/dist/core/kube/workspace.js +423 -0
  136. package/dist/core/lifecycle/admin.js +64 -0
  137. package/dist/core/lifecycle/create-docker.js +1533 -0
  138. package/dist/core/lifecycle/create-k8s.js +939 -0
  139. package/dist/core/lifecycle/destroy.js +339 -0
  140. package/dist/core/lifecycle/inspect.js +635 -0
  141. package/dist/core/lifecycle/naming.js +298 -0
  142. package/dist/core/lifecycle/notes.js +726 -0
  143. package/dist/core/lifecycle/ownership.js +313 -0
  144. package/dist/core/lifecycle/payload.js +401 -0
  145. package/dist/core/lifecycle/ports.js +388 -0
  146. package/dist/core/lifecycle/preconditions.js +367 -0
  147. package/dist/core/lifecycle/pruning.js +551 -0
  148. package/dist/core/lifecycle/ready.js +753 -0
  149. package/dist/core/lifecycle/request.js +525 -0
  150. package/dist/core/lifecycle/seeding.js +281 -0
  151. package/dist/core/lifecycle/sizing.js +392 -0
  152. package/dist/core/lifecycle/state.js +286 -0
  153. package/dist/core/lifecycle/tlsplan.js +704 -0
  154. package/dist/core/lifecycle/types.js +232 -0
  155. package/dist/core/loadtest.js +995 -0
  156. package/dist/core/migrate.js +612 -0
  157. package/dist/core/monitor.js +494 -0
  158. package/dist/core/postready.js +969 -0
  159. package/dist/core/promote.js +804 -0
  160. package/dist/core/rcapi.js +1285 -0
  161. package/dist/core/recovery.js +75 -0
  162. package/dist/core/runner/engine.js +394 -0
  163. package/dist/core/runner/host.js +298 -0
  164. package/dist/core/runner/locks.js +129 -0
  165. package/dist/core/runner/paths.js +173 -0
  166. package/dist/core/runner/ports.js +172 -0
  167. package/dist/core/runner/queries.js +612 -0
  168. package/dist/core/runner/record.js +563 -0
  169. package/dist/core/scaleseed.js +271 -0
  170. package/dist/core/seed-db.js +208 -0
  171. package/dist/core/sessions.js +472 -0
  172. package/dist/core/skill.js +326 -0
  173. package/dist/core/sso-identities.js +172 -0
  174. package/dist/core/sso.js +703 -0
  175. package/dist/core/tls-local.js +311 -0
  176. package/dist/core/tls.js +878 -0
  177. package/dist/core/topology.js +482 -0
  178. package/dist/core/upgrade.js +868 -0
  179. package/dist/core/users.js +739 -0
  180. package/dist/lib/audit.js +100 -0
  181. package/dist/lib/close-matches.js +238 -0
  182. package/dist/lib/compose.js +672 -0
  183. package/dist/lib/config.js +1398 -0
  184. package/dist/lib/context.js +18 -0
  185. package/dist/lib/errors.js +305 -0
  186. package/dist/lib/events.js +208 -0
  187. package/dist/lib/float-text.js +126 -0
  188. package/dist/lib/format.js +1320 -0
  189. package/dist/lib/home.js +325 -0
  190. package/dist/lib/journal.js +122 -0
  191. package/dist/lib/json-text.js +733 -0
  192. package/dist/lib/jsonout.js +382 -0
  193. package/dist/lib/lock.js +516 -0
  194. package/dist/lib/login-name.js +202 -0
  195. package/dist/lib/map-limit.js +29 -0
  196. package/dist/lib/mkdir-parents.js +90 -0
  197. package/dist/lib/mongo-kernel.js +67 -0
  198. package/dist/lib/monitoring.js +492 -0
  199. package/dist/lib/platform-name.js +59 -0
  200. package/dist/lib/presets/common.js +390 -0
  201. package/dist/lib/presets/composite.js +326 -0
  202. package/dist/lib/presets/e2ee.js +143 -0
  203. package/dist/lib/presets/email.js +172 -0
  204. package/dist/lib/presets/guides.js +27 -0
  205. package/dist/lib/presets/index.js +490 -0
  206. package/dist/lib/presets/keycloak.js +369 -0
  207. package/dist/lib/presets/ldap.js +1285 -0
  208. package/dist/lib/presets/livechat.js +220 -0
  209. package/dist/lib/presets/multi-instance.js +124 -0
  210. package/dist/lib/presets/oidc.js +161 -0
  211. package/dist/lib/presets/public.js +496 -0
  212. package/dist/lib/presets/registry.js +64 -0
  213. package/dist/lib/presets/s3-minio.js +300 -0
  214. package/dist/lib/presets/saml.js +149 -0
  215. package/dist/lib/presets/scenario.js +51 -0
  216. package/dist/lib/presets/types.js +86 -0
  217. package/dist/lib/presets/voice-pbx.js +320 -0
  218. package/dist/lib/presets/voice.js +345 -0
  219. package/dist/lib/presets/webhooks.js +182 -0
  220. package/dist/lib/redact.js +106 -0
  221. package/dist/lib/seed-options.js +68 -0
  222. package/dist/lib/seed-profiles.js +59 -0
  223. package/dist/lib/targz.js +1383 -0
  224. package/dist/lib/teammode.js +25 -0
  225. package/dist/lib/tempdir.js +162 -0
  226. package/dist/lib/unicode-tables.js +2335 -0
  227. package/dist/lib/version-spec.js +357 -0
  228. package/dist/lib/versions.js +463 -0
  229. package/dist/lib/yaml-dump.js +1361 -0
  230. package/dist/perf/baseline.js +168 -0
  231. package/dist/perf/constrain.js +296 -0
  232. package/dist/perf/k6.js +235 -0
  233. package/dist/perf/mongoprof.js +171 -0
  234. package/dist/perf/rcmetrics.js +178 -0
  235. package/dist/perf/report.js +386 -0
  236. package/dist/perf/resources.js +224 -0
  237. package/dist/perf/slo.js +111 -0
  238. package/dist/perf/timeline.js +187 -0
  239. package/dist/perf/timings.js +85 -0
  240. package/dist/perf/verdict.js +201 -0
  241. package/dist/seams/aws-cli.js +126 -0
  242. package/dist/seams/docker-cli.js +280 -0
  243. package/dist/seams/exec.js +861 -0
  244. package/dist/seams/fs/lock.js +528 -0
  245. package/dist/seams/kubectl.js +83 -0
  246. package/dist/seams/rc-http.js +921 -0
  247. package/dist/seed/apply.js +190 -0
  248. package/dist/seed/assets.js +76 -0
  249. package/dist/seed/check.js +391 -0
  250. package/dist/seed/client.js +172 -0
  251. package/dist/seed/executor.js +726 -0
  252. package/dist/seed/history.js +281 -0
  253. package/dist/seed/kinds.js +91 -0
  254. package/dist/seed/plan.js +432 -0
  255. package/dist/seed/receipt.js +339 -0
  256. package/dist/seed/repairs.js +75 -0
  257. package/dist/seed/verification.js +363 -0
  258. package/dist/seed/wording.js +248 -0
  259. package/dist/web/app.js +326 -0
  260. package/dist/web/jobs.js +510 -0
  261. package/dist/web/route-deps.js +211 -0
  262. package/dist/web/route-table.js +213 -0
  263. package/dist/web/routes/backup.js +244 -0
  264. package/dist/web/routes/clusters.js +303 -0
  265. package/dist/web/routes/data.js +187 -0
  266. package/dist/web/routes/edge.js +82 -0
  267. package/dist/web/routes/index.js +63 -0
  268. package/dist/web/routes/jobs.js +95 -0
  269. package/dist/web/routes/logs.js +297 -0
  270. package/dist/web/routes/meta.js +191 -0
  271. package/dist/web/routes/people.js +151 -0
  272. package/dist/web/routes/perf.js +95 -0
  273. package/dist/web/routes/repros.js +550 -0
  274. package/dist/web/routes/session.js +361 -0
  275. package/dist/web/routes/spa.js +198 -0
  276. package/dist/web/security.js +475 -0
  277. package/dist/web/signin.js +246 -0
  278. package/package.json +67 -32
  279. package/.eslintrc +0 -94
  280. package/.swcrc +0 -18
  281. package/dist/bin.js +0 -3
  282. package/dist/cli.js +0 -184
  283. package/dist/commands/createBranch.js +0 -192
  284. package/src/bin.js +0 -4
  285. package/src/cli.ts +0 -25
  286. package/src/commands/createBranch.ts +0 -25
  287. package/src-old/logs.js +0 -323
  288. package/src-old/md.js +0 -191
  289. package/src-old/release-table.js +0 -60
  290. package/src-old/set-version.js +0 -614
  291. package/src-old/utils.js +0 -15
@@ -0,0 +1,636 @@
1
+ import { ctx } from "./shared.js";
2
+
3
+ // ---- config-import dialog ---------------------------------------------------
4
+ let IMPORT_TARGET = null;
5
+ let IMPORT_UPLOAD_ID = null;
6
+ function openImport(name) {
7
+ IMPORT_TARGET = name;
8
+ ctx.$("#import-title").textContent = `Import settings: ${name}`;
9
+ ctx.$("#import-file").value = "";
10
+ IMPORT_UPLOAD_ID = null;
11
+ ctx.$("#import-form").only.value = "";
12
+ const plan = ctx.$("#import-plan"); plan.hidden = true; plan.innerHTML = "";
13
+ ctx.$("#import-apply").disabled = true;
14
+ ctx.$("#import-dialog").showModal();
15
+ }
16
+ async function previewImport() {
17
+ const f = ctx.$("#import-form");
18
+ if (!f.file.files.length) { ctx.toast("choose a settings.json file"); return; }
19
+ const btn = ctx.$("#import-preview");
20
+ if (btn.disabled) return; // a double-click orphaned a second upload
21
+ btn.disabled = true;
22
+ const fd = new FormData();
23
+ fd.append("file", f.file.files[0]);
24
+ fd.append("only", f.only.value.trim());
25
+ let plan;
26
+ try {
27
+ // `apiForm`, not a bare fetch: `api()` is what redirects to sign-in on 401, and
28
+ // this call opted out of it -- so an expired session showed an error inside a
29
+ // dialog that could no longer do anything. `apiForm` is the multipart sibling
30
+ // (see its comment): it parses and raises, so there is no Response here.
31
+ plan = await ctx.apiForm(`/api/repros/${IMPORT_TARGET}/config-import/plan`, {
32
+ method: "POST", body: fd });
33
+ } catch (e) { ctx.toast(e.message); return; }
34
+ finally { ctx.$("#import-preview").disabled = false; }
35
+ const box = ctx.$("#import-plan");
36
+ const c = plan.counts;
37
+ // Everything below comes from the uploaded dump's setting ids — escape all of
38
+ // it: a crafted `_id` would otherwise run script in a page holding the token.
39
+ let html = `<b>Sets ${c.apply}</b> &middot; skips ${c.redacted} the export hid (secrets) and ${c.denied} `
40
+ + "that belong to their server (its address, license, registration and the like)";
41
+ if (plan.oauth_services.length) html += `<br>Creates these custom OAuth providers first, so their settings can be set: ${escapeHtml(plan.oauth_services.join(", "))}`;
42
+ if (plan.redacted.length) html += `<br><span class="warn">Hidden in the export; set these by hand: ${escapeHtml(plan.redacted.join(", "))}</span>`;
43
+ html += "<hr>" + plan.apply.map((a) => `<div class="kv"><code>${escapeHtml(a.id)}</code> = ${escapeHtml(a.value)}</div>`).join("");
44
+ box.innerHTML = html; box.hidden = false;
45
+ IMPORT_UPLOAD_ID = plan.upload_id || null;
46
+ ctx.$("#import-apply").disabled = plan.apply.length === 0 || !IMPORT_UPLOAD_ID;
47
+ }
48
+ function escapeHtml(s) { const d = document.createElement("div"); d.textContent = s; return d.innerHTML; }
49
+ async function applyImport() {
50
+ ctx.$("#import-dialog").close();
51
+ try { const { job_id } = await ctx.api(`/api/repros/${IMPORT_TARGET}/config-import`, { method: "POST", body: JSON.stringify({ upload_id: IMPORT_UPLOAD_ID }) }); streamJob(job_id, `Importing settings: ${IMPORT_TARGET}`); }
52
+ catch (e) { ctx.toast(e.message); }
53
+ }
54
+ async function showLogs(name) {
55
+ closeJobStream(); // a plain log view must not share the dialog with a job
56
+ openJob(`Logs: ${name}`);
57
+ ctx.$("#job-log").textContent = "loading…";
58
+ try { const { logs } = await ctx.api(`/api/repros/${name}/logs?tail=200`); ctx.$("#job-log").textContent = logs || "(no output)"; }
59
+ catch (e) { ctx.$("#job-log").textContent = "error: " + e.message; }
60
+ }
61
+ function reportPrune(r) {
62
+ r = r || {};
63
+ const targets = (r.targets || []).length, removed = (r.removed || []).length;
64
+ // ORPHANED NAMESPACES COUNT AS WORK DONE. They and their PersistentVolumeClaims are
65
+ // deleted irreversibly, and reporting only `removed` said "nothing to prune" about
66
+ // a sweep that had just destroyed them -- the same defect the CLI had.
67
+ const orphans = (r.orphans || []).length;
68
+ if (orphans) ctx.toast(`removed ${orphans} orphaned namespace(s): ${(r.orphans || []).join(", ")}`, "ok");
69
+ if (!targets) { if (!orphans) ctx.toast("no taken-down workspaces to delete", "info"); return; }
70
+ if (removed === targets) { ctx.toast(`deleted ${removed} taken-down workspace${removed === 1 ? "" : "s"}`, "ok"); return; }
71
+ // prune() warns per-repro through emit; those now arrive in the job dialog, and
72
+ // the shortfall is still worth saying out loud here.
73
+ ctx.toast(`deleted ${removed} of ${targets}; ${targets - removed} could not be cleaned up`);
74
+ }
75
+
76
+ // Prune is the same story as Stop -- a synchronous call that removes containers
77
+ // and volumes for every `down` repro -- but its button lives in the static top
78
+ // bar, so unlike the cards nothing re-renders it and a local swap is enough.
79
+ async function withBusy(btn, verb, fn) {
80
+ const label = btn.textContent;
81
+ btn.disabled = true;
82
+ btn.classList.add("working");
83
+ btn.textContent = "";
84
+ btn.append(ctx.el("span", { class: "spin" }), verb);
85
+ try { await fn(); } finally {
86
+ btn.classList.remove("working");
87
+ btn.disabled = false;
88
+ btn.textContent = label;
89
+ }
90
+ }
91
+ async function doPrune() {
92
+ if (!confirm("Delete every taken-down workspace you are allowed to delete (an admin: everyone's), "
93
+ + "with its data and record? Stopped ones, and ones created with Keep, are left alone. "
94
+ + "This cannot be undone.")) return;
95
+ await withBusy(ctx.$("#btn-prune"), "Deleting…", async () => {
96
+ try {
97
+ const { job_id } = await ctx.api("/api/prune",
98
+ { method: "POST", body: JSON.stringify({ confirm: true }) });
99
+ streamJob(job_id, "Deleting taken-down workspaces", async (r) => {
100
+ reportPrune(r);
101
+ await ctx.loadRepros();
102
+ });
103
+ } catch (e) { ctx.toast(e.message); }
104
+ });
105
+ }
106
+
107
+ // ---- job streaming (SSE) ----------------------------------------------------
108
+ // One dialog, so exactly one job may own it at a time. JOB is that job; a stream
109
+ // belonging to anything else must never write into it (two jobs used to interleave
110
+ // their output and steal each other's title).
111
+ let JOB = null;
112
+
113
+ function openJob(title) { ctx.$("#job-title").textContent = title; ctx.$("#job-log").textContent = ""; ctx.$("#job-stop").hidden = true; ctx.$("#job-dialog").showModal(); }
114
+
115
+ // A job stuck on something it cannot see -- a create waiting on a port-forward -- held its
116
+ // workspace until the server was killed. Stop ends it at its next step; what it did stays.
117
+ async function stopJob(job, btn) {
118
+ if (!confirm("Stop this job? It ends at its next step; what it already did stays and nothing "
119
+ + "is deleted. If it was creating a workspace you no longer want, delete that workspace afterwards.")) return;
120
+ btn.disabled = true;
121
+ try {
122
+ await ctx.api(`/api/jobs/${job.id}/stop`, { method: "POST" });
123
+ btn.textContent = "Stopping…";
124
+ } catch (e) { btn.disabled = false; ctx.toast(e.message); }
125
+ }
126
+ // What each phase of a job DOES, as a step in the create dialog's progress.
127
+ const PHASE_STEP = {
128
+ preflight: "Checking this server", resolve: "Looking up the version", provision: "Preparing the cluster",
129
+ plan: "Working out what to build", pull: "Pulling images", create: "Writing the workspace",
130
+ boot: "Starting the containers", wait: "Waiting for Rocket.Chat to answer", post_ready: "Applying settings",
131
+ tls: "Setting up HTTPS", seed: "Adding sample data", monitor: "Attaching monitoring",
132
+ };
133
+ function logLine(ev) {
134
+ const text = (ev.pct != null ? `[${Math.round(ev.pct)}%] ` : "") + ev.message;
135
+ // A job shown INSIDE another dialog (Create a workspace) lists its events as steps:
136
+ // the newest one is running, everything before it is done.
137
+ const list = JOB && JOB.view && JOB.view.list;
138
+ // The closing "done" says nothing the heading above the list does not.
139
+ if (list && ev.level !== "error" && (ev.terminal || ev.message === "done")) return;
140
+ if (list) {
141
+ const bad = ev.level === "error";
142
+ const warn = ev.level === "warn";
143
+ const after = !!(JOB && JOB.finished);
144
+ // ONE STEP PER PHASE. A create streams every docker pull line -- hundreds of "Downloading
145
+ // 3.1MB" -- and a list of those is a log, not progress. A phase is one step, named for
146
+ // what it does, with its latest line under it; a warning or an error stands alone.
147
+ const phase = ev.phase || "info";
148
+ const last = list.lastElementChild;
149
+ if (!bad && !warn && !after && last && last.dataset.phase === phase && last.querySelector(".s.run")) {
150
+ last.querySelector(".msg").textContent = text;
151
+ return;
152
+ }
153
+ for (const s of list.querySelectorAll(".s.run")) { s.className = "s y"; s.textContent = "✓"; }
154
+ const label = !bad && !warn ? PHASE_STEP[phase] : "";
155
+ const item = ctx.el("li", { "data-phase": bad || warn ? "" : phase },
156
+ ctx.el("span", { class: "s " + (bad ? "x" : warn ? "n" : after ? "w" : "run") }, bad ? "✗" : warn ? "!" : after ? "i" : "·"),
157
+ ctx.el("span", { class: bad ? "error" : warn ? "warn" : "" },
158
+ label || text, label ? ctx.el("span", { class: "m msg", style: "display:block" }, text) : ctx.el("span", { class: "msg", hidden: "" })));
159
+ list.append(item);
160
+ const scroller = list.closest(".wzd-b");
161
+ if (scroller) scroller.scrollTop = scroller.scrollHeight;
162
+ return;
163
+ }
164
+ const line = ctx.el("div", { class: ev.level }, text);
165
+ const pre = ctx.$("#job-log"); pre.append(line); pre.scrollTop = pre.scrollHeight;
166
+ }
167
+ function closeJobStream() {
168
+ if (JOB && JOB.es) { try { JOB.es.close(); } catch (_) { /* already closed */ } }
169
+ JOB = null;
170
+ }
171
+
172
+ // `view`, when given, is where the job shows itself instead of the job dialog:
173
+ // { list, title, dialog, stop, failed } -- Create a workspace streams into its own last step.
174
+ function streamJob(jobId, title, onResult, view = null) {
175
+ closeJobStream(); // a new job supersedes whatever was showing
176
+ if (!view) openJob(title);
177
+ JOB = { id: jobId, title, onResult, idx: 0, es: null, retries: 0, finished: false, view };
178
+ // The create dialog's own progress too: a create stuck on a port-forward was the case
179
+ // Stop was built for, and it could only be stopped by going to Activity to find it.
180
+ const stop = view ? view.stop : ctx.$("#job-stop");
181
+ if (stop) {
182
+ // Offered only where the server says a Stop is safe: kinds whose half-done state was read.
183
+ const job = JOB;
184
+ Object.assign(stop, { hidden: true, disabled: false, textContent: view ? "Stop" : "Stop job",
185
+ onclick: () => stopJob(job, stop) });
186
+ ctx.api(`/api/jobs/${jobId}`).then((state) => {
187
+ if (JOB === job && !job.finished && state.stoppable) stop.hidden = false;
188
+ }).catch(() => { /* the stream reports the job either way */ });
189
+ }
190
+ connectJob(JOB);
191
+ }
192
+
193
+ function connectJob(job) {
194
+ // `since` resumes from the last event we saw, so a reconnect cannot duplicate
195
+ // or skip lines. The server has always accepted it; nothing used to send it.
196
+ const es = new EventSource(
197
+ `/api/jobs/${job.id}/stream?since=${job.idx}`);
198
+ job.es = es;
199
+ es.onmessage = (m) => {
200
+ if (JOB !== job) { es.close(); return; } // superseded — do not write here
201
+ if (m.lastEventId) job.idx = Number(m.lastEventId) + 1;
202
+ const ev = JSON.parse(m.data);
203
+ // The name a create settled on: for the title, not a step of its own.
204
+ if (ev.code === "workspace-name") {
205
+ if (job.view && job.view.named && ev.data) job.view.named(ev.data.workspace);
206
+ return;
207
+ }
208
+ logLine(ev);
209
+ if (ev.terminal) finishJob(job, ev.level === "error", ev.data || {});
210
+ };
211
+ es.onerror = () => {
212
+ es.close();
213
+ if (JOB !== job || job.finished) return;
214
+ // EventSource reports no detail, and closing it defeats its own reconnect, so
215
+ // ask the job endpoint what actually happened instead of freezing the dialog.
216
+ reconcileJob(job);
217
+ };
218
+ }
219
+
220
+ function finishJob(job, failed, data) {
221
+ job.finished = true;
222
+ if (job.es) { try { job.es.close(); } catch (_) { /* already closed */ } }
223
+ if (job.view) {
224
+ for (const s of job.view.list.querySelectorAll(".s.run")) { s.className = failed ? "s x" : "s y"; s.textContent = failed ? "✗" : "✓"; }
225
+ if (job.view.stop) job.view.stop.hidden = true;
226
+ if (failed && job.view.failed) job.view.failed(data);
227
+ } else {
228
+ ctx.$("#job-title").textContent = !failed ? "Done" : data.kind === "Stopped" ? "Stopped" : "Failed";
229
+ if (JOB === job) ctx.$("#job-stop").hidden = true;
230
+ }
231
+ if (!failed && job.onResult && data.result) job.onResult(data.result);
232
+ if (!failed) reloadForNewGrafana(data.result, false, job);
233
+ ctx.loadRepros().then(ctx.refreshDetail);
234
+ }
235
+
236
+ // A document's frame-src policy is fixed at page load. Reload after a successful
237
+ // monitoring attachment whose Grafana the page was not loaded allowing -- a public one, or
238
+ // a loopback one on a port other than the preferred 5050, which a second monitored
239
+ // workspace gets -- once the reader has closed its result, so the server can allow that
240
+ // workspace's Grafana origin for the k6 dashboard. One the page already allowed reloads
241
+ // nothing: every job on a monitored workspace carries its Grafana.
242
+ function reloadForNewGrafana(result, detached = false, job = null) {
243
+ if (!result || !result.monitoring) return;
244
+ const url = result && (result.grafana_url || (result.monitoring && result.monitoring.grafana_url));
245
+ if (!url || url === "http://localhost:5050" || url.startsWith("http://localhost:5050/")) return;
246
+ if (ctx.GRAFANAS_AT_LOAD && ctx.GRAFANAS_AT_LOAD.has(ctx.originOf(url))) return;
247
+ if (detached) { location.reload(); return; }
248
+ logLine({ level: "info", message: "Close this result to reload the GUI and enable the public Grafana dashboard." });
249
+ ((job && job.view && job.view.dialog) || ctx.$("#job-dialog")).addEventListener("close", () => location.reload(), { once: true });
250
+ }
251
+
252
+ // The slow path, for when SSE cannot be kept open. Ten seconds rather than the
253
+ // stream's immediacy: this is a fallback, and a dialog that reports the truth a few
254
+ // seconds late is worth far more than one that reports nothing at all.
255
+ function pollJobUntilDone(job) {
256
+ const tick = async () => {
257
+ if (JOB !== job || job.finished) return; // the reader closed or moved on
258
+ let state;
259
+ try { state = await ctx.api(`/api/jobs/${job.id}`); }
260
+ catch (e) {
261
+ logLine({ level: "error", message: `could not query the job: ${e.message}` });
262
+ finishJob(job, true, {});
263
+ return;
264
+ }
265
+ if (ctx.jobActive(state.status)) { setTimeout(tick, 10000); return; }
266
+ logLine(state.status === "error"
267
+ ? { level: "error", message: state.error || "failed" }
268
+ : { level: "info", message: "done" });
269
+ finishJob(job, state.status === "error",
270
+ { result: state.result, error: state.error, kind: state.error_kind });
271
+ };
272
+ setTimeout(tick, 10000);
273
+ }
274
+
275
+ async function reconcileJob(job) {
276
+ let state;
277
+ try { state = await ctx.api(`/api/jobs/${job.id}`); }
278
+ catch (e) {
279
+ logLine({ level: "error", message: `progress stream lost, and the job could not be queried: ${e.message}` });
280
+ finishJob(job, true, {});
281
+ return;
282
+ }
283
+ if (ctx.jobActive(state.status)) {
284
+ if (job.retries++ < 5) {
285
+ logLine({ level: "warn", message: "progress stream dropped — reconnecting…" });
286
+ setTimeout(() => { if (JOB === job && !job.finished) connectJob(job); }, 1000);
287
+ } else {
288
+ // GIVING UP ON THE STREAM IS NOT GIVING UP ON THE JOB. This logged "still
289
+ // running" and stopped, so a job that then finished -- or failed -- was never
290
+ // reported in the dialog the reader was watching. A reverse proxy with an idle
291
+ // SSE timeout makes that the normal case, not an edge one.
292
+ //
293
+ // The stream was only ever the fast path; `/api/jobs/<id>` carries the same
294
+ // outcome. So fall back to asking, slowly, until it reaches a terminal state.
295
+ logLine({ level: "warn", message: "the progress stream keeps dropping — "
296
+ + "watching the job's status instead; this dialog will still report the result." });
297
+ pollJobUntilDone(job);
298
+ }
299
+ return;
300
+ }
301
+ // It finished while we were disconnected; this endpoint carries the outcome.
302
+ logLine(state.status === "error"
303
+ ? { level: "error", message: state.error || "failed" }
304
+ : { level: "info", message: "done" });
305
+ // The server keeps a hundred job summaries but only the newest ten results, so
306
+ // an old run reopened from the history has nothing left to render. Say so:
307
+ // an empty panel and a discarded one look identical otherwise.
308
+ if (state.result_dropped) {
309
+ logLine({ level: "warn", message: "this job finished a while ago and its full "
310
+ + "output is no longer held in memory — the progress above is what remains." });
311
+ }
312
+ finishJob(job, state.status === "error", { result: state.result, error: state.error, kind: state.error_kind });
313
+ }
314
+
315
+ // The job keeps running server-side when the dialog is dismissed, and there is no
316
+ // job list to reopen it from -- so poll for the outcome rather than losing it. UNTIL IT
317
+ // ENDS: this gave up after 900 seconds, and a cluster build takes twenty minutes, so the
318
+ // one job long enough to be dismissed was the one whose ending was never announced.
319
+ async function watchDetachedJob(job) {
320
+ ctx.toast(`${job.title} continues in the background`, "info");
321
+ for (;;) {
322
+ await new Promise((r) => setTimeout(r, 1000));
323
+ let state;
324
+ try { state = await ctx.api(`/api/jobs/${job.id}`); } catch (_) { return; }
325
+ if (ctx.jobActive(state.status)) continue;
326
+ // A Stop somebody pressed is not a failure, and red "failed: stopped by admin" said it was.
327
+ const stopped = state.status === "error" && state.error_kind === "Stopped";
328
+ ctx.toast(stopped ? `${job.title}: ${state.error || "stopped"}`
329
+ : state.status === "error" ? `${job.title} failed: ${state.error || ""}` : `${job.title} finished`,
330
+ stopped ? "info" : state.status === "error" ? "error" : "ok");
331
+ if (state.status !== "error") reloadForNewGrafana(state.result, true);
332
+ ctx.loadRepros().then(ctx.refreshDetail);
333
+ return state;
334
+ }
335
+ }
336
+
337
+ // ---- load-test dialog -------------------------------------------------------
338
+ let PERF_TARGET = null;
339
+ function openPerf(name, monitored) {
340
+ PERF_TARGET = name;
341
+ ctx.$("#perf-title").textContent = `Load test: ${name}`;
342
+ const live = ctx.$("#perf-form").live;
343
+ live.checked = false; live.disabled = !monitored;
344
+ ctx.$("#perf-live-row").style.opacity = monitored ? "1" : ".5";
345
+ ctx.$("#perf-dialog").showModal();
346
+ }
347
+ async function submitPerf() {
348
+ const f = ctx.$("#perf-form");
349
+ const req = {
350
+ scenario: f.scenario.value, vus: parseInt(f.vus.value, 10) || 10,
351
+ duration: f.duration.value.trim() || "30s", users_n: parseInt(f.users_n.value, 10) || 0,
352
+ slo: f.slo.value.trim(), constrain: f.constrain.value.trim(),
353
+ diag: f.diag.checked, stats: f.stats.checked, live: f.live.checked,
354
+ };
355
+ ctx.$("#perf-dialog").close();
356
+ try {
357
+ const { job_id } = await ctx.api(`/api/repros/${PERF_TARGET}/loadtest`, { method: "POST", body: JSON.stringify(req) });
358
+ streamJob(job_id, `Load test: ${PERF_TARGET} (${req.scenario})`, renderPerfResult);
359
+ } catch (e) { ctx.toast(e.message); }
360
+ }
361
+ function renderCreateResult(r) {
362
+ const pre = ctx.$("#job-log");
363
+ const box = ctx.el("div", { class: "result" });
364
+ const kv = (k, v) => ctx.el("div", {}, ctx.el("b", {}, k + ": "), v);
365
+ box.append(ctx.el("div", { html: "<hr>" }));
366
+ if (r.rc_version) box.append(kv("Rocket.Chat", `${r.rc_version} · Mongo ${r.mongo_tag || "?"} · preset ${r.preset || "?"}`));
367
+ if (r.root_url) box.append(kv("URL", r.root_url));
368
+ if (r.login) box.append(kv("Login", `${r.login.user} / ${r.login.password}`));
369
+ for (const u of (r.instance_urls || [])) box.append(kv("instance", u));
370
+ if (r.grafana_url) box.append(kv("Grafana", r.grafana_url));
371
+ pre.append(box);
372
+ appendNotes(pre, r.notes);
373
+ pre.scrollTop = pre.scrollHeight;
374
+ }
375
+
376
+ // Preset notes carry the things you cannot guess: the Keycloak console URL and
377
+ // realm, the /etc/hosts line oidc and presigned s3_minio need, where Mailpit is.
378
+ // The CLI prints them after `up` and from `info`; the GUI showed them nowhere.
379
+ // A preset's notes are free prose written for a terminal, and dumping them into
380
+ // a <div> per line (or a <pre>) makes the one line that MATTERS -- the /etc/hosts
381
+ // entry `oidc` does not work without -- look exactly like the sentence beside it.
382
+ //
383
+ // Three shapes are actually in the data, and none of them are invented:
384
+ // * an INDENTED line is a thing to type or paste: " 127.0.0.1 keycloak",
385
+ // " http://localhost:8081/admin/...". It gets a code box and a Copy button.
386
+ // * a line CONTAINING a url is a place to go. The url becomes a link.
387
+ // * everything else is prose, and consecutive prose lines are one paragraph --
388
+ // they were wrapped for an 80-column terminal, not written as separate points.
389
+ // Urls become links and `backticked` spans become code. Both are already in the
390
+ // notes as plain text -- a preset that says "pass --reg-token" or "`loadtest
391
+ // --live`" is naming something you type, and leaving the backticks on screen is
392
+ // showing the reader the markup instead of the meaning.
393
+ //: Words a finished sentence does not end on. A note ending in one of these was
394
+ //: wrapped for an 80-column terminal and continues on the next line; a note ending
395
+ //: in anything else -- a name, a number, a url, punctuation -- is a complete point.
396
+ const WRAPPED_TAIL = new RegExp("\\b(?:a|an|the|and|or|but|of|to|in|on|at|by|for|from|"
397
+ + "with|is|are|was|were|be|been|being|that|which|who|as|its|their|your|our|this|"
398
+ + "these|those|into|than|then|so|if|when|while|it|not|no|any|each|per|via)$");
399
+
400
+ const TOKEN_RE = /`([^`]+)`|\bhttps?:\/\/[^\s)]+/;
401
+
402
+ function linkify(line) {
403
+ const out = ctx.el("span", {});
404
+ // "Status -> Targets", "Container logs -> Loki", "Admin → Email": the ASCII
405
+ // spelling is there because a terminal cannot render the arrow, and a browser
406
+ // can. Same character the presets already use where they were free to.
407
+ let rest = String(line).replace(/ -> /g, " → ");
408
+ for (;;) {
409
+ const m = TOKEN_RE.exec(rest);
410
+ if (!m) { out.append(rest); return out; }
411
+ out.append(rest.slice(0, m.index));
412
+ if (m[1]) out.append(ctx.el("code", { class: "inline" }, m[1]));
413
+ else out.append(ctx.el("a", { href: m[0], target: "_blank", rel: "noreferrer" }, m[0]));
414
+ rest = rest.slice(m.index + m[0].length);
415
+ }
416
+ }
417
+
418
+ // A note line that names a PLACE. Every preset that has one writes it the same
419
+ // way, because a human wrote it for a human:
420
+ // Keycloak admin console: http://localhost:8081 (admin / admin)
421
+ // Mailpit (EVERY email RC sends, for ALL users, lands here): http://localhost:8025
422
+ // Grafana: http://localhost:5050 (admin/admin; anonymous view enabled)
423
+ // That is a NAME, optionally what it is FOR, a URL, and sometimes the CREDENTIALS
424
+ // — the same four things the link rows above already show — and setting it as a
425
+ // grey paragraph buried the two facts you came for. The url must START the value:
426
+ // "Container logs -> Loki: open the 'Rocket.Chat Logs' dashboard in Grafana (…)"
427
+ // mentions a url inside a sentence, and it is a sentence, not a location.
428
+ const PLACE_RE = /^([^:()]{2,40}?)(?:\s*\(([^)]*)\))?:[ \t]+((?:https?:\/\/|<)\S*)[ \t]*(?:\(([^)]*)\))?[ \t]*\.?$/;
429
+ // "admin/admin; anonymous view enabled" is a password AND a remark; "Status ->
430
+ // Targets: rocketchat, …" is only a remark. Only the a/b shape is a credential.
431
+ const CREDS_RE = /^([\w.@+-]+ ?\/ ?[\w.@+-]+)(?:[;,]\s*(.*))?$/;
432
+ // Past this, a description stops being a column and becomes a second line —
433
+ // rather than ellipsising it away, which loses the half of it that matters.
434
+ const WHAT_MAX = 34;
435
+
436
+ // Read a preset's notes into the shapes that are in them. Indentation carries
437
+ // most of the structure, and every preset already uses it:
438
+ // 4+ spaces something to type or paste (" 127.0.0.1 keycloak")
439
+ // 2 spaces a rider on the line above (" — one shared inbox; …")
440
+ // column 0 a new point — UNLESS the line before it did not finish a
441
+ // sentence, in which case it is just terminal wrapping
442
+ // ("…can reach Keycloak at the" / "same URL RC's backend uses.")
443
+ // Joining every consecutive prose line instead, as a first pass did, turned the
444
+ // email preset's five separate points into one unreadable wall.
445
+ function parseNotes(notes) {
446
+ const items = [];
447
+ let para = null, place = null, prev = "";
448
+ for (const raw of notes || []) {
449
+ const line = String(raw);
450
+ if (!line.trim()) { para = null; place = null; prev = ""; continue; }
451
+ if (/^\s{4,}\S/.test(line)) {
452
+ items.push({ kind: "cmd", value: line.trim() });
453
+ // The paste box ENDS the row above it. saml's last line is a remark about
454
+ // the Keycloak console, but hanging it back on that row prints it above the
455
+ // url the sentence before it promised ("…or open Users directly:").
456
+ para = null; place = null; prev = line.trim();
457
+ continue;
458
+ }
459
+ const indented = /^\s{1,3}\S/.test(line);
460
+ const m = indented ? null : PLACE_RE.exec(line.trim());
461
+ if (m) {
462
+ const paren = (m[4] || "").trim();
463
+ const creds = CREDS_RE.exec(paren);
464
+ place = { kind: "place", label: m[1].trim(), what: (m[2] || "").trim(),
465
+ url: m[3], creds: creds ? creds[1] : "",
466
+ sub: creds ? (creds[2] || "").trim() : paren };
467
+ if (place.what.length > WHAT_MAX) {
468
+ place.sub = place.sub ? place.what + " · " + place.sub : place.what;
469
+ place.what = "";
470
+ }
471
+ items.push(place); para = null; prev = line;
472
+ continue;
473
+ }
474
+ if (place && indented) { // a rider on the row above
475
+ place.sub = place.sub ? place.sub + " " + line.trim() : line.trim();
476
+ prev = line;
477
+ continue;
478
+ }
479
+ // A column-0 line continues the one above ONLY if that one broke mid-sentence,
480
+ // and the reliable signal is what it ENDS with. Ending punctuation is not enough
481
+ // on its own: livechat has two separate points that each end in a url, and one
482
+ // that starts with a lowercase username.
483
+ //
484
+ // "Ends in any lowercase word" was too broad, and the Kubernetes notes are what
485
+ // proved it: "monolith on kind-houston-local — about 5 pods, namespace
486
+ // houston-knotes" is a COMPLETE point that happens to end in an identifier, and
487
+ // it was being glued to the MongoDB note that followed it — two facts in one
488
+ // bullet, in the notes a reader consults to find out what their workspace is.
489
+ //
490
+ // So the test is narrower: a line was wrapped only if it trails off in a short
491
+ // FUNCTION word, which is a thing no finished sentence ends with. `oidc`'s
492
+ // "…can reach Keycloak at the" still joins the line after it; a namespace name
493
+ // no longer does. Indented continuations (the 2-space ones `email` and `saml`
494
+ // use) never needed this test and still do not — they are handled above.
495
+ const tail = prev.trim();
496
+ const wrapped = para && WRAPPED_TAIL.test(tail) && !/\/\S*$/.test(tail);
497
+ if (!para || !(indented || wrapped)) {
498
+ para = { kind: "prose", lines: [] };
499
+ items.push(para);
500
+ }
501
+ para.lines.push(line.trim());
502
+ place = null; prev = line;
503
+ }
504
+ return items;
505
+ }
506
+
507
+ // One row shape for "a thing, and where it is", used by the links the server
508
+ // reports AND by the note lines that name one, so a scenario's console does not
509
+ // appear once as a row and again as a sentence three lines below it.
510
+ function placeRow(p) {
511
+ const real = !String(p.url || "").startsWith("<");
512
+ const row = real
513
+ ? ctx.el("a", { class: "linkrow " + (p.kind || ""), href: p.url,
514
+ target: "_blank", rel: "noreferrer" })
515
+ : ctx.el("div", { class: "linkrow static " + (p.kind || "") });
516
+ row.append(ctx.el("span", { class: "l-n" }, p.label));
517
+ if (p.what) row.append(ctx.el("span", { class: "l-w" }, p.what));
518
+ // The url as it will actually open, not as the server spelled it. The href above
519
+ // is already rewritten by localUrl(), and showing the raw one here put two
520
+ // different addresses for the same thing on one screen -- "What is in this
521
+ // workspace" saying localhost:3000 while the URL row below it said the host the
522
+ // GUI was loaded from. Only when it IS a url: `real` is false for a preset
523
+ // placeholder like `<repro-url>/livechat`, and localUrl() would resolve that
524
+ // against the page origin and produce `http://<host>/<repro-url>/livechat`.
525
+ row.append(ctx.el("span", { class: "l-u" }, p.url));
526
+ if (p.creds) row.append(ctx.el("span", { class: "l-c" }, p.creds));
527
+ if (real) row.append(ctx.el("span", { class: "l-go" }, "↗"));
528
+ if (p.sub) row.append(ctx.el("span", { class: "l-sub" }, linkify(p.sub)));
529
+ return row;
530
+ }
531
+
532
+ function renderNoteItems(box, items) {
533
+ let group = null; // consecutive places are one table
534
+ // A marker says "this is one point of several". A card holding ONE paragraph is not
535
+ // several, and the dot in front of it reads as a list with one item -- which is
536
+ // what every grouped note card became when the groups arrived and each took one
537
+ // paragraph with it.
538
+ const listed = items.filter((i) => i.kind === "prose").length > 1;
539
+ for (const it of items) {
540
+ if (it.kind !== "place") group = null;
541
+ if (it.kind === "cmd") {
542
+ box.append(ctx.el("div", { class: "note-cmd" },
543
+ ctx.el("code", {}, it.value),
544
+ ctx.el("button", { class: "cp", onclick: () => ctx.copy(it.value) }, "Copy")));
545
+ } else if (it.kind === "place") {
546
+ if (!group) { group = ctx.el("div", { class: "linkrows one" }); box.append(group); }
547
+ // `kind` on a parsed note is WHAT it is ("place"), and placeRow reads `kind` as a
548
+ // link's class ("monitor", "sidecar"): the row came out as `.place`, the Clusters
549
+ // card -- a column -- and Mailpit's description was cut off at the dialog's edge.
550
+ group.append(placeRow({ ...it, kind: "" }));
551
+ } else {
552
+ const para = ctx.el("p", { class: "note-p" + (listed ? "" : " solo") });
553
+ it.lines.forEach((l, i) => { if (i) para.append(" "); para.append(linkify(l)); });
554
+ box.append(para);
555
+ }
556
+ }
557
+ return box;
558
+ }
559
+
560
+ function noteBlock(notes) {
561
+ return renderNoteItems(ctx.el("div", { class: "notes" }), parseNotes(notes));
562
+ }
563
+
564
+ function appendNotes(parent, notes) {
565
+ if (!notes || !notes.length) return;
566
+ parent.append(ctx.el("div", { class: "section-label" }, "Using this preset"));
567
+ parent.append(noteBlock(notes));
568
+ }
569
+
570
+ function renderPerfResult(r) {
571
+ const s = r.summary || {};
572
+ const pre = ctx.$("#job-log");
573
+ const box = ctx.el("div", { class: "result" });
574
+ const pill = r.passed ? '<span class="ok">SLO PASS</span>' : (r.slo && r.slo.length ? '<span class="bad">SLO FAIL</span>' : "");
575
+ box.innerHTML =
576
+ `<hr><b>Results</b> ${pill}<br>` +
577
+ `throughput <b>${(s.rps || 0).toFixed(1)} req/s</b> (${(s.count || 0).toFixed(0)} reqs) &middot; ` +
578
+ `errors ${((s.error_rate || 0) * 100).toFixed(2)}%<br>` +
579
+ `latency p50 ${(s.p50 || 0).toFixed(0)}ms &middot; p95 <b>${(s.p95 || 0).toFixed(0)}ms</b> &middot; p99 ${(s.p99 || 0).toFixed(0)}ms`;
580
+ if (r.verdict && r.verdict.length) box.innerHTML += "<br><b>Verdict:</b><br>" + r.verdict.map((v) => "&bull; " + escapeHtml(v)).join("<br>");
581
+ pre.append(box);
582
+ // Everything below was already in the response and was being thrown away. It is
583
+ // the part a support ticket actually needs: WHICH step is slow, whether Mongo did
584
+ // a COLLSCAN, whether the Node event loop saturated, and when errors started.
585
+ ctx.renderDiagnosis(pre, r);
586
+ if (r.grafana_url) {
587
+ const url = `${r.grafana_url}/d/houston-k6-loadtest?from=now-15m&to=now&kiosk`;
588
+ pre.append(ctx.el("div", { class: "result" },
589
+ ctx.el("a", { href: url, target: "_blank", style: "text-decoration:none",
590
+ ...(ctx.remoteLoopback(url) ? { title: ctx.LOOPBACK_TITLE } : {}) }, ctx.el("button", { class: "btn small" }, "Open k6 dashboard in Grafana"))));
591
+ const frame = ctx.el("iframe", { src: url, class: "grafana-embed" });
592
+ pre.append(frame);
593
+ }
594
+ pre.scrollTop = pre.scrollHeight;
595
+ }
596
+
597
+
598
+ Object.defineProperties(ctx, {
599
+ "IMPORT_TARGET": { enumerable: true, get: () => IMPORT_TARGET, set: value => { IMPORT_TARGET = value; } },
600
+ "IMPORT_UPLOAD_ID": { enumerable: true, get: () => IMPORT_UPLOAD_ID, set: value => { IMPORT_UPLOAD_ID = value; } },
601
+ "openImport": { enumerable: true, get: () => openImport },
602
+ "previewImport": { enumerable: true, get: () => previewImport },
603
+ "escapeHtml": { enumerable: true, get: () => escapeHtml },
604
+ "applyImport": { enumerable: true, get: () => applyImport },
605
+ "showLogs": { enumerable: true, get: () => showLogs },
606
+ "reportPrune": { enumerable: true, get: () => reportPrune },
607
+ "withBusy": { enumerable: true, get: () => withBusy },
608
+ "doPrune": { enumerable: true, get: () => doPrune },
609
+ "JOB": { enumerable: true, get: () => JOB, set: value => { JOB = value; } },
610
+ "openJob": { enumerable: true, get: () => openJob },
611
+ "logLine": { enumerable: true, get: () => logLine },
612
+ "closeJobStream": { enumerable: true, get: () => closeJobStream },
613
+ "streamJob": { enumerable: true, get: () => streamJob },
614
+ "connectJob": { enumerable: true, get: () => connectJob },
615
+ "finishJob": { enumerable: true, get: () => finishJob },
616
+ "pollJobUntilDone": { enumerable: true, get: () => pollJobUntilDone },
617
+ "reconcileJob": { enumerable: true, get: () => reconcileJob },
618
+ "watchDetachedJob": { enumerable: true, get: () => watchDetachedJob },
619
+ "PERF_TARGET": { enumerable: true, get: () => PERF_TARGET, set: value => { PERF_TARGET = value; } },
620
+ "openPerf": { enumerable: true, get: () => openPerf },
621
+ "submitPerf": { enumerable: true, get: () => submitPerf },
622
+ "renderCreateResult": { enumerable: true, get: () => renderCreateResult },
623
+ "WRAPPED_TAIL": { enumerable: true, get: () => WRAPPED_TAIL },
624
+ "TOKEN_RE": { enumerable: true, get: () => TOKEN_RE },
625
+ "linkify": { enumerable: true, get: () => linkify },
626
+ "PLACE_RE": { enumerable: true, get: () => PLACE_RE },
627
+ "CREDS_RE": { enumerable: true, get: () => CREDS_RE },
628
+ "WHAT_MAX": { enumerable: true, get: () => WHAT_MAX },
629
+ "parseNotes": { enumerable: true, get: () => parseNotes },
630
+ "placeRow": { enumerable: true, get: () => placeRow },
631
+ "renderNoteItems": { enumerable: true, get: () => renderNoteItems },
632
+ "noteBlock": { enumerable: true, get: () => noteBlock },
633
+ "appendNotes": { enumerable: true, get: () => appendNotes },
634
+ "renderPerfResult": { enumerable: true, get: () => renderPerfResult },
635
+ });
636
+ export { IMPORT_TARGET, IMPORT_UPLOAD_ID, openImport, previewImport, escapeHtml, applyImport, showLogs, reportPrune, withBusy, doPrune, JOB, openJob, logLine, closeJobStream, streamJob, connectJob, finishJob, pollJobUntilDone, reconcileJob, watchDetachedJob, PERF_TARGET, openPerf, submitPerf, renderCreateResult, WRAPPED_TAIL, TOKEN_RE, linkify, PLACE_RE, CREDS_RE, WHAT_MAX, parseNotes, placeRow, renderNoteItems, noteBlock, appendNotes, renderPerfResult };