@rocket.chat/houston 0.27.0-next.3 → 2.1.9

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 (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -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 +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,636 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.reproState = reproState;
37
+ exports.kubernetesState = kubernetesState;
38
+ exports.degradedReason = degradedReason;
39
+ exports.uptimeHealth = uptimeHealth;
40
+ exports.forwardGap = forwardGap;
41
+ exports.reproLinks = reproLinks;
42
+ exports.grafanaUrlOf = grafanaUrlOf;
43
+ exports.grafanaFrameOrigins = grafanaFrameOrigins;
44
+ exports.clusterOf = clusterOf;
45
+ exports.summary = summary;
46
+ exports.describe = describe;
47
+ exports.rowFor = rowFor;
48
+ exports.listRepros = listRepros;
49
+ /**
50
+ * What a workspace IS right now: its state, its health, its links, and the list.
51
+ *
52
+ * Tier 3. Reads the on-disk record and the engine; never changes either. `detail` lives next
53
+ * door in `payload` because it is the payload-shape trap -- the browser suite renders from a
54
+ * fixture of it, so a key that drifts from what this layer really returns breaks the panel in
55
+ * production with the whole suite green.
56
+ */
57
+ const config = __importStar(require("../../lib/config"));
58
+ const map_limit_1 = require("../../lib/map-limit");
59
+ const monitoring_1 = require("../../lib/monitoring");
60
+ const capabilities_1 = require("../kube/capabilities");
61
+ const context_1 = require("../kube/context");
62
+ const forward_1 = require("../kube/forward");
63
+ const names_1 = require("../kube/names");
64
+ const namespace_1 = require("../kube/namespace");
65
+ const release_1 = require("../kube/release");
66
+ const status_1 = require("../kube/status");
67
+ const host_1 = require("../runner/host");
68
+ const queries_1 = require("../runner/queries");
69
+ const record_1 = require("../runner/record");
70
+ const topology = __importStar(require("../topology"));
71
+ const naming = __importStar(require("./naming"));
72
+ const notes = __importStar(require("./notes"));
73
+ const request_1 = require("./request");
74
+ const types_1 = require("./types");
75
+ const common_1 = require("../../lib/presets/common");
76
+ const composite_1 = require("../../lib/presets/composite");
77
+ const public_1 = require("../../lib/presets/public");
78
+ const versions_1 = require("../../lib/versions");
79
+ function bag(value) {
80
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
81
+ ? value
82
+ : {};
83
+ }
84
+ function isTruthy(value) {
85
+ if (value === null || value === undefined || value === false)
86
+ return false;
87
+ if (typeof value === 'string')
88
+ return value !== '';
89
+ if (typeof value === 'number')
90
+ return value !== 0;
91
+ if (Array.isArray(value))
92
+ return value.length > 0;
93
+ if (typeof value === 'object')
94
+ return Object.keys(value).length > 0;
95
+ return true;
96
+ }
97
+ /**
98
+ * The state to report for a repro, from its Rocket.Chat container's docker `Status`
99
+ * string ("Up 2 hours (healthy)", "Restarting (1) 5 seconds ago", ...).
100
+ *
101
+ * BOTH the list and the detail panel must derive state from this, because they used to
102
+ * disagree. The list read compose's PROJECT-level aggregate, where the always-running
103
+ * Mongo put "running(" in the string and made a crash-looping RC report "running"; the
104
+ * panel checked only whether RC was literally "running" and flattened everything else to
105
+ * "stopped".
106
+ *
107
+ * `hasContainers` separates "the stack is gone" (down) from "containers exist but
108
+ * Rocket.Chat has none" (stopped).
109
+ */
110
+ function reproState(rcStatus, hasContainers) {
111
+ const s = (rcStatus || '').trim();
112
+ if (!s)
113
+ return hasContainers ? 'stopped' : 'down';
114
+ const low = s.toLowerCase();
115
+ if (low.startsWith('up')) {
116
+ // docker reports a paused container as "Up 3 days (Paused)".
117
+ return low.includes('(paused)') ? 'paused' : 'running';
118
+ }
119
+ if (low.startsWith('exited'))
120
+ return 'stopped';
121
+ // "Restarting (1) 5 seconds ago" -> restarting; "Created"/"Dead" -> as-is.
122
+ return low.split(' (')[0]?.split(' ')[0] || 'down';
123
+ }
124
+ const scopedKubernetesReads = {
125
+ workloadReplicas: status_1.workloadReplicas,
126
+ workspaceReady: status_1.workspaceReady,
127
+ terminalPodFailure: status_1.terminalPodFailure,
128
+ };
129
+ /**
130
+ * `running` / `down` for a Kubernetes workspace.
131
+ *
132
+ * `reproState()` asks docker whether the project's containers exist, so it called a live
133
+ * Kubernetes workspace `down` -- the state column was reporting on the wrong runtime
134
+ * entirely.
135
+ */
136
+ async function kubernetesState(name, meta, namespaces = capabilities_1.workspaceNamespaces, reads = scopedKubernetesReads) {
137
+ const extra = bag(meta.extra);
138
+ const context = isTruthy(extra[config.EXTRA_CONTEXT])
139
+ ? String(extra[config.EXTRA_CONTEXT])
140
+ : names_1.CONTEXT;
141
+ // "?" ON A REFUSED READ, which is the word the Docker branch one function up already
142
+ // uses when the daemon is unreachable. Without it a healthy workspace read as `down`
143
+ // whenever the cluster could not be asked. `down` is the word that invites `up --force`
144
+ // and `down --volumes`, so it is the worst available guess.
145
+ //
146
+ // ONE ROUND OF QUESTIONS, NOT FOUR IN A ROW. On EKS every kubectl call first fetches a
147
+ // token, so asking the namespace, the workload, its replicas and its pods one after
148
+ // another made each `list` -- which the GUI asks for every four seconds -- and each
149
+ // workspace panel cost four round trips. The three reads are independent; their answers
150
+ // are taken in the order the rule needs, so a missing namespace still decides first and
151
+ // a refused workload read still raises only once the namespace is known to be there.
152
+ const [held, workload, ready] = await Promise.all([
153
+ namespaces(context),
154
+ reads.workloadReplicas(name, { context }).then((replicas) => ({ replicas, failure: null }), (failure) => ({ replicas: null, failure })),
155
+ reads.workspaceReady(name, { context }),
156
+ ]);
157
+ if (held === null)
158
+ return '?';
159
+ if (!held.includes(await (0, namespace_1.namespaceFor)(name)))
160
+ return 'down';
161
+ if (workload.failure !== null)
162
+ throw workload.failure;
163
+ // The namespace EXISTING is not the workspace running. A plain `down` keeps the
164
+ // namespace and its PVC on purpose and uninstalls the release, so a torn-down workspace
165
+ // reported "starting" -- and would have reported it forever.
166
+ if (workload.replicas === null)
167
+ return 'down';
168
+ // Scaled to zero is STOPPED, not starting. `stop` is implemented as scale-to-zero and
169
+ // without this the column said "starting" for a workspace that was deliberately
170
+ // stopped and was never going to move.
171
+ if (workload.replicas === 0)
172
+ return 'stopped';
173
+ if (ready)
174
+ return 'running';
175
+ // NOT-READY IS NOT ALWAYS STARTING. For a wedged `pending-install` release or a pod in
176
+ // ImagePullBackOff / CreateContainerConfigError nothing is coming. A refused read must
177
+ // not manufacture a failure, so each probe is guarded and falls back to the honest
178
+ // "starting".
179
+ try {
180
+ if ((await reads.terminalPodFailure(name, { context })) !== null)
181
+ return 'failed';
182
+ }
183
+ catch {
184
+ // a refused probe is not evidence of failure
185
+ }
186
+ try {
187
+ const [state] = await (0, release_1.releaseState)(names_1.RELEASE, await (0, namespace_1.namespaceFor)(name), context);
188
+ if (release_1.PENDING_STATES.includes(state) || state === 'failed')
189
+ return 'failed';
190
+ }
191
+ catch {
192
+ // same
193
+ }
194
+ return 'starting';
195
+ }
196
+ /**
197
+ * Why a workspace that LOOKS running is not usable, or "".
198
+ *
199
+ * `services` is {service: docker Status string}. Reported as a distinct health rather
200
+ * than as a state, because the workspace genuinely is running -- what is wrong is that
201
+ * something it needs is not.
202
+ */
203
+ function degradedReason(services) {
204
+ for (const svc of types_1.ESSENTIAL_SERVICES) {
205
+ const status = services[svc];
206
+ if (status !== undefined && !status.startsWith('Up ')) {
207
+ const first = status.split(' (')[0]?.trim().toLowerCase() || 'not running';
208
+ return `${svc} is ${first}`;
209
+ }
210
+ }
211
+ return '';
212
+ }
213
+ /**
214
+ * Parse a docker `Status` string -> (uptime, health).
215
+ * "Up 2 hours (healthy)" -> ("2 hours", "healthy"); "Exited (0) ..." -> ("", "").
216
+ */
217
+ function uptimeHealth(status) {
218
+ if (!status)
219
+ return ['', ''];
220
+ const match = /\(([^)]+)\)/u.exec(status);
221
+ let health = match !== null && status.startsWith('Up ') ? match[1] : '';
222
+ // Docker spells the transitional one "health: starting" inside the Status string, and
223
+ // a bare "healthy"/"unhealthy" for the settled ones. Taken verbatim the panel rendered
224
+ // "Health: health: starting".
225
+ if (health.startsWith('health: '))
226
+ health = health.slice('health: '.length);
227
+ const up = status.startsWith('Up ') ? (status.slice(3).split(' (')[0]?.trim() ?? '') : '';
228
+ return [up, health];
229
+ }
230
+ /**
231
+ * Why a running Kubernetes workspace's URL will not answer, or "".
232
+ *
233
+ * Only where a pid was actually recorded: `forwardAlive(null)` is false, and reading that
234
+ * as "nothing is running" is the confusion this release spent itself removing.
235
+ */
236
+ async function forwardGap(meta) {
237
+ const extra = bag(meta.extra);
238
+ const pid = extra.port_forward_pid;
239
+ if (!isTruthy(pid))
240
+ return '';
241
+ const ns = isTruthy(extra.namespace) ? String(extra.namespace) : await (0, namespace_1.namespaceFor)(meta.name);
242
+ if (await (0, forward_1.forwardAlive)(Number(pid), { namespace: ns, hostPort: meta.hostPort }))
243
+ return '';
244
+ return ('no port-forward, so the URL will not answer — ' +
245
+ `\`houston ready --name ${meta.name}\` re-establishes it`);
246
+ }
247
+ /**
248
+ * Clickable URLs for a repro: RC, extra instances, preset sidecars (S3, Keycloak,
249
+ * Mailpit, widget), and monitoring -- [{label, url, kind}].
250
+ */
251
+ /**
252
+ * A composed workspace's presets as a list, for a reader that should not split the string.
253
+ * ABSENT for one preset, so every other workspace's payload is byte for byte what it was.
254
+ */
255
+ function presetsOf(meta) {
256
+ const names = (0, composite_1.namesOf)(scenarioOf(meta));
257
+ return names.length > 1 ? { presets: names } : {};
258
+ }
259
+ /**
260
+ * The presets without the deployment. Compose builds multi-instance through that preset, so
261
+ * the record lists it among them, and the panel showed it as a preset chip beside the
262
+ * deployment that already says so: it is the deployment, not a preset.
263
+ */
264
+ function scenarioOf(meta) {
265
+ return String(topology.axesOfMeta(meta).preset ?? meta.preset);
266
+ }
267
+ /**
268
+ * What the panel badges: the CI build a workspace runs (its ghcr tag, or ''), whether it
269
+ * was given a license, and whether Rocket.Chat refused it when `ready` last asked. Always
270
+ * present, so the panel reads one shape.
271
+ */
272
+ function buildAndLicense(meta) {
273
+ const prefix = `${versions_1.BUILD_IMAGE}:`;
274
+ const tag = meta.rcImage.startsWith(prefix) ? meta.rcImage.slice(prefix.length) : '';
275
+ const extra = bag(meta.extra);
276
+ return {
277
+ ci_build: (0, versions_1.isBuildTag)(tag) ? tag : '',
278
+ // Or one added later in Rocket.Chat itself, which `ready` found there.
279
+ licensed: extra.licensed === true || extra.license_status === 'valid',
280
+ license_refused: extra.license_status === 'refused',
281
+ };
282
+ }
283
+ /** The side ports and replicas are published on the workspace's recorded bind. */
284
+ function linkHost(meta) {
285
+ const recorded = bag(meta.extra).bind_host;
286
+ if (typeof recorded === 'string' && recorded.trim() !== '')
287
+ return (0, request_1.callHost)(recorded);
288
+ // Older records predate bind_host but already carry the address readiness uses.
289
+ try {
290
+ return (0, request_1.callHost)(new URL(meta.rootUrl).hostname);
291
+ }
292
+ catch {
293
+ return 'localhost';
294
+ }
295
+ }
296
+ function reproLinks(meta) {
297
+ const links = [{ label: 'Rocket.Chat', url: (0, record_1.externalUrl)(meta), kind: 'rc' }];
298
+ const extra = bag(meta.extra);
299
+ const host = linkHost(meta);
300
+ if ((0, record_1.externalUrl)(meta) !== meta.rootUrl) {
301
+ // Keep the plain http way in as well: with the local CA the browser warns until
302
+ // `trust-ca` has run, and behind a proxy or tunnel this is the link that works here.
303
+ links.push({ label: 'direct HTTP', url: meta.rootUrl, kind: 'rc' });
304
+ }
305
+ const n = extra.instances;
306
+ if (typeof n === 'number' && Number.isInteger(n) && n > 1) {
307
+ for (let i = 1; i <= n; i += 1) {
308
+ links.push({
309
+ label: `instance ${String(i)}`,
310
+ url: `http://${host}:${String(meta.hostPort + i)}`,
311
+ kind: 'rc',
312
+ });
313
+ }
314
+ }
315
+ // Every preset of a composed workspace, in its canonical order, on ITS ports: a second
316
+ // workspace with the same preset was given others, and the registry's open someone else's.
317
+ const held = (0, record_1.sidePortsOf)(meta);
318
+ for (const name of (0, composite_1.namesOf)(meta.preset)) {
319
+ const linked = types_1.PRESET_LINKS[name] ?? [];
320
+ const ports = linked.length > 0 ? (0, common_1.presetPorts)(name, held) : [];
321
+ for (const [label, idx] of linked) {
322
+ if (idx < ports.length) {
323
+ links.push({ label, url: `http://${host}:${String(ports[idx])}`, kind: 'sidecar' });
324
+ }
325
+ }
326
+ }
327
+ // The webhook inbox, at the session the receiver chose: linked once post-ready recorded
328
+ // it, because the receiver's root page would open a new, empty one.
329
+ const inbox = notes.inboxUrl(meta);
330
+ if (inbox !== '')
331
+ links.push({ label: 'Webhook inbox', url: inbox, kind: 'sidecar' });
332
+ // ldap's OWN Keycloak, when it federates the directory (`--set idp=saml|oidc`): it is
333
+ // published on the IdP preset's port, and linked by preset name only, so the console that
334
+ // holds the directory's SSO users had no link -- unless HTTPS added its path.
335
+ if ((0, composite_1.namesOf)(meta.preset).includes('ldap') && !links.some((link) => link.label === 'Keycloak')) {
336
+ const idp = String(bag(extra.params).idp ?? bag(bag(extra.preset_params).ldap).idp ?? '').toLowerCase();
337
+ const port = idp === 'saml' || idp === 'oidc' ? (0, common_1.presetPort)(idp, 0, held) : undefined;
338
+ if (port !== undefined) {
339
+ links.push({ label: 'Keycloak', url: `http://${host}:${String(port)}`, kind: 'sidecar' });
340
+ }
341
+ }
342
+ // Over HTTPS, a preset's own UIs at paths of the name (`lib/presets/public.ts`). Mailpit,
343
+ // Keycloak and the MinIO console then answer only under their path, so their link IS the
344
+ // public one, as is phpLDAPadmin's; the demo page keeps its own port (the cross-origin one)
345
+ // and gains the same-origin path beside it.
346
+ if (meta.publicUrl) {
347
+ const base = meta.publicUrl.replace(/\/+$/u, '');
348
+ for (const p of (0, public_1.publicPathsOf)(extra)) {
349
+ const url = `${base}${p.path}/`;
350
+ const label = {
351
+ mailpit: 'Mailpit',
352
+ keycloak: 'Keycloak',
353
+ 'widget-site': 'Widget site',
354
+ 'minio-ui': 'MinIO console',
355
+ phpldapadmin: 'phpLDAPadmin',
356
+ }[p.service] ?? p.service;
357
+ const at = links.findIndex((link) => link.label === label);
358
+ if (p.service !== 'widget-site' && at >= 0)
359
+ links[at] = { label, url, kind: 'sidecar' };
360
+ else
361
+ links.push({
362
+ label: p.service === 'widget-site' ? `${label} (same origin)` : label,
363
+ url,
364
+ kind: 'sidecar',
365
+ });
366
+ }
367
+ }
368
+ if (isTruthy(extra.monitoring)) {
369
+ links.push({
370
+ label: 'Grafana',
371
+ url: grafanaUrlOf(meta),
372
+ kind: 'monitor',
373
+ });
374
+ // Docker's alone: Kubernetes forwards Grafana and nothing else, so this link led nowhere.
375
+ if (topology.ofMeta(meta) !== topology.KUBERNETES) {
376
+ links.push({
377
+ label: 'Prometheus',
378
+ url: `http://localhost:${String((0, record_1.prometheusPortOf)(meta))}`,
379
+ kind: 'monitor',
380
+ });
381
+ }
382
+ }
383
+ return links;
384
+ }
385
+ /**
386
+ * Only houston-served TLS publishes Grafana; every cluster stack uses the sub-path. On the
387
+ * workspace's own Grafana port: a second monitored workspace's is not the preferred one.
388
+ */
389
+ function grafanaUrlOf(meta) {
390
+ const publicUrl = isTruthy(bag(meta.extra).tls) ? meta.publicUrl : '';
391
+ return (0, monitoring_1.grafanaUrl)(publicUrl, topology.ofMeta(meta) === topology.KUBERNETES || !!publicUrl, (0, record_1.grafanaPortOf)(meta));
392
+ }
393
+ /**
394
+ * Origins the GUI may embed, derived from monitored workspaces: the public name of one served
395
+ * by houston over HTTPS, and the loopback Grafana of every other, on its own port.
396
+ */
397
+ async function grafanaFrameOrigins() {
398
+ const origins = new Set();
399
+ for (const meta of await (0, record_1.listMeta)()) {
400
+ if (!isTruthy(bag(meta.extra).monitoring))
401
+ continue;
402
+ try {
403
+ const url = new URL(grafanaUrlOf(meta));
404
+ if (url.protocol === 'https:' || url.hostname === 'localhost')
405
+ origins.add(url.origin);
406
+ }
407
+ catch {
408
+ // A hand-edited invalid URL grants no iframe origin.
409
+ }
410
+ }
411
+ return [...origins].sort();
412
+ }
413
+ /**
414
+ * DERIVED here, not read out of the record. Every workspace created before the groups
415
+ * existed -- and every workspace created before the next wording fix -- gets the current
416
+ * shape and the current words, because this is a read.
417
+ *
418
+ * The recorded flat list is the fallback, and it is only reached by a workspace that has
419
+ * notes no group accounts for (a preset that has since been deleted, a note some older
420
+ * release appended by hand).
421
+ */
422
+ /**
423
+ * The cluster a Kubernetes workspace runs in: the context a command needs, and the short
424
+ * name a person recognises. Both '' for a Compose workspace, and ALWAYS present -- a key
425
+ * that appears only sometimes is how a payload drifts from what the tests render.
426
+ */
427
+ function clusterOf(meta) {
428
+ const extra = bag(meta.extra);
429
+ if (topology.ofMeta(meta) !== topology.KUBERNETES)
430
+ return { context: '', cluster: '' };
431
+ const context = isTruthy(extra[config.EXTRA_CONTEXT]) ? String(extra[config.EXTRA_CONTEXT]) : '';
432
+ return { context, cluster: context === '' ? '' : (0, context_1.shortName)(context) };
433
+ }
434
+ async function summary(meta) {
435
+ const groups = await notes.noteGroupsOf(meta);
436
+ const extra = bag(meta.extra);
437
+ const recorded = Array.isArray(extra.notes) ? extra.notes : [];
438
+ const d = {
439
+ notes: groups.length > 0 ? notes.flattenNotes(groups) : recorded,
440
+ note_groups: groups,
441
+ name: meta.name,
442
+ rc_version: meta.rcVersion,
443
+ mongo_tag: meta.mongoTag,
444
+ mongo_flavor: meta.mongoFlavor,
445
+ preset: scenarioOf(meta),
446
+ ...presetsOf(meta),
447
+ ...buildAndLicense(meta),
448
+ root_url: meta.rootUrl,
449
+ // The address a person opens, when the workspace has one: `up`'s result and the GUI's
450
+ // create dialog offered only `root_url`, the http://localhost port, which from any other
451
+ // machine is that machine's own. "" without HTTPS, as the list row and the panel say.
452
+ public_url: meta.publicUrl,
453
+ // What a person OPENS: the https name, else the address `--root-url` advertised (a
454
+ // proxy's, a tunnel's), else the loopback port. Every "Open" took `public_url || root_url`,
455
+ // which behind a tunnel is http://localhost -- the one address nobody outside can use.
456
+ open_url: (0, record_1.externalUrl)(meta),
457
+ host_port: meta.hostPort,
458
+ login: { user: config.ADMIN_USERNAME, password: meta.adminPassword || config.ADMIN_PASSWORD },
459
+ pinned: meta.pinned,
460
+ // Which runtime, and how Rocket.Chat is arranged inside it. `listRepros` has carried
461
+ // the runtime all along and the DETAIL payload had neither, so the panel rendered
462
+ // every workspace as though it were Compose -- and offered actions the Kubernetes
463
+ // path can only refuse.
464
+ runtime: topology.ofMeta(meta),
465
+ deployment: String(topology.axesOfMeta(meta).deployment ?? ''),
466
+ ...clusterOf(meta),
467
+ };
468
+ // Whether this workspace HAS sample data, and whether the readback agreed. Always
469
+ // present, never conditional -- a key that appears only sometimes is how the panel's
470
+ // payload drifts from what the tests render.
471
+ const seed = bag(extra.seed);
472
+ d.seed =
473
+ Object.keys(seed).length > 0
474
+ ? {
475
+ profile: seed.profile ?? '',
476
+ at: seed.at ?? '',
477
+ ok: bag(seed.verification).ok === true
478
+ ? true
479
+ : bag(seed.verification).ok === false
480
+ ? false
481
+ : null,
482
+ }
483
+ : null;
484
+ const n = extra.instances;
485
+ if (isTruthy(n)) {
486
+ const count = Number(n);
487
+ d.instances = count;
488
+ d.instance_urls = Array.from({ length: count }, (_unused, index) => `http://${linkHost(meta)}:${String(meta.hostPort + index + 1)}`);
489
+ }
490
+ if (isTruthy(extra.monitoring)) {
491
+ d.monitoring = true;
492
+ d.grafana_url = grafanaUrlOf(meta);
493
+ }
494
+ return d;
495
+ }
496
+ async function describe(name) {
497
+ return await summary(await (0, record_1.readMeta)(await naming.resolveName(name)));
498
+ }
499
+ /**
500
+ * One workspace as `list` and the GUI table see it.
501
+ *
502
+ * Its own function because the two runtimes answer "what state is this in" from
503
+ * different places, and the branch that decides is three lines inside fifty.
504
+ */
505
+ async function rowFor(meta, { default: defaultName, dockerUp, states, statusMap, svcMap, namespaces, kubeReads, }) {
506
+ // Compose's answer is a Docker workspace's alone: one left under a Kubernetes record (as
507
+ // 2.1.1's takeover left them) lent that row its own uptime and health.
508
+ const rcStatus = topology.ofMeta(meta) === topology.KUBERNETES ? '' : (statusMap[meta.project] ?? '');
509
+ // `states` is only consulted for "does this project have ANY container", never for the
510
+ // state itself -- see reproState. A Kubernetes workspace has no compose project, so
511
+ // asking docker whether its containers exist answered `down` for a workspace that was
512
+ // running.
513
+ let state;
514
+ if (topology.ofMeta(meta) === topology.KUBERNETES) {
515
+ state = await kubernetesState(meta.name, meta, namespaces, kubeReads);
516
+ }
517
+ else {
518
+ state = dockerUp ? reproState(rcStatus, Boolean(states[meta.project])) : '?';
519
+ }
520
+ const [uptime, health] = uptimeHealth(rcStatus);
521
+ let degradedWhy;
522
+ if (topology.ofMeta(meta) === topology.KUBERNETES) {
523
+ // `list` printed `running` beside a URL that refused connections, and only `info`
524
+ // said otherwise. A port-forward dies with its pod, so this is the NORMAL state after
525
+ // any restart. Carried in `degraded`, the field both front-ends already render for
526
+ // the Compose side.
527
+ degradedWhy = state === 'running' ? await forwardGap(meta) : '';
528
+ }
529
+ else {
530
+ degradedWhy = state === 'running' ? degradedReason(svcMap[meta.project] ?? {}) : '';
531
+ }
532
+ const degraded = degradedWhy ? 'degraded' : '';
533
+ const runtime = topology.ofMeta(meta);
534
+ const extra = bag(meta.extra);
535
+ const monitored = isTruthy(extra.monitoring);
536
+ const owner = isTruthy(extra.owner)
537
+ ? String(extra.owner)
538
+ : isTruthy(extra.created_by)
539
+ ? String(extra.created_by)
540
+ : '';
541
+ return {
542
+ name: meta.name,
543
+ created_by: owner,
544
+ owner,
545
+ made_by: isTruthy(extra.created_by) ? String(extra.created_by) : '',
546
+ rc_version: meta.rcVersion,
547
+ mongo_tag: meta.mongoTag,
548
+ host_port: meta.hostPort,
549
+ root_url: meta.rootUrl,
550
+ state,
551
+ runtime,
552
+ ...clusterOf(meta),
553
+ // The https URL when `up --https` was used; "" otherwise.
554
+ public_url: meta.publicUrl,
555
+ open_url: (0, record_1.externalUrl)(meta),
556
+ tls: isTruthy(extra.tls) ? String(extra.tls) : '',
557
+ preset: scenarioOf(meta),
558
+ ...presetsOf(meta),
559
+ pinned: meta.pinned,
560
+ default: meta.name === defaultName,
561
+ monitoring: monitored,
562
+ created_at: meta.createdAt,
563
+ uptime,
564
+ health: degraded || health || (state === 'running' ? state : ''),
565
+ degraded: degradedWhy,
566
+ grafana_url: monitored ? grafanaUrlOf(meta) : null,
567
+ links: reproLinks(meta),
568
+ };
569
+ }
570
+ function shareContextRead(probe) {
571
+ const reads = new Map();
572
+ return (context) => {
573
+ const held = reads.get(context);
574
+ if (held !== undefined)
575
+ return held;
576
+ const reading = probe(context);
577
+ reads.set(context, reading);
578
+ return reading;
579
+ };
580
+ }
581
+ async function listRepros() {
582
+ const metas = await (0, record_1.listMeta)();
583
+ const fallback = config.loadConfig().default_repro;
584
+ const defaultName = isTruthy(fallback) ? String(fallback) : '';
585
+ const dockerUp = await (0, host_1.dockerAvailable)();
586
+ const [states, svcMap] = dockerUp
587
+ ? await Promise.all([(0, queries_1.projectStates)().then((value) => value ?? {}), (0, queries_1.servicesByProject)()])
588
+ : [{}, {}];
589
+ // ONE docker ps for every service of every project, so the list and the panel cannot
590
+ // disagree about whether a workspace is degraded -- which is exactly how they came to
591
+ // disagree about `state` before reproState existed.
592
+ const statusMap = dockerUp ? await (0, queries_1.rcStatusByProject)(svcMap) : {};
593
+ // Share a cluster read only within this list. Every poll asks again so a deleted
594
+ // namespace or an unavailable cluster is never hidden behind an older answer.
595
+ const reads = new Map();
596
+ const namespaces = (context) => {
597
+ const held = reads.get(context ?? '');
598
+ if (held !== undefined)
599
+ return held;
600
+ const reading = (0, capabilities_1.workspaceNamespaces)(context);
601
+ reads.set(context ?? '', reading);
602
+ return reading;
603
+ };
604
+ // A list needs current answers, but not one kubectl process per row and per question.
605
+ // Keep these snapshots inside this call; a later poll must read the cluster again.
606
+ // Broad RBAC is optional: a refused collection falls back to the original scoped probe.
607
+ const replicas = shareContextRead(status_1.workspaceReplicasByNamespace);
608
+ const pods = shareContextRead(status_1.workspacePodsByNamespace);
609
+ const kubeReads = {
610
+ workloadReplicas: async (name, options) => {
611
+ const [seen, namespace] = await Promise.all([replicas(options.context), (0, namespace_1.namespaceFor)(name)]);
612
+ return seen === null ? await (0, status_1.workloadReplicas)(name, options) : (seen.get(namespace) ?? null);
613
+ },
614
+ workspaceReady: async (name, options) => {
615
+ const [seen, namespace] = await Promise.all([pods(options.context), (0, namespace_1.namespaceFor)(name)]);
616
+ return seen === null
617
+ ? await (0, status_1.workspaceReady)(name, options)
618
+ : (0, status_1.workspacePodsReady)(seen.get(namespace) ?? []);
619
+ },
620
+ terminalPodFailure: async (name, options) => {
621
+ const [seen, namespace] = await Promise.all([pods(options.context), (0, namespace_1.namespaceFor)(name)]);
622
+ return seen === null
623
+ ? await (0, status_1.terminalPodFailure)(name, options)
624
+ : (0, status_1.terminalFailureOfPods)(seen.get(namespace) ?? []);
625
+ },
626
+ };
627
+ return await (0, map_limit_1.mapLimit)(metas, 4, async (meta) => rowFor(meta, {
628
+ default: defaultName,
629
+ dockerUp,
630
+ states,
631
+ statusMap,
632
+ svcMap,
633
+ namespaces,
634
+ kubeReads,
635
+ }));
636
+ }