@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,363 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyBatch = verifyBatch;
4
+ /** Verify the latest batch by identity, including actors, assets, and room relationships. */
5
+ const node_crypto_1 = require("node:crypto");
6
+ const errors_1 = require("../lib/errors");
7
+ const rcapi_1 = require("../core/rcapi");
8
+ const kinds_1 = require("./kinds");
9
+ const client_1 = require("./client");
10
+ const assets_1 = require("./assets");
11
+ async function verifyBatch(rootUrl, admin, plan, receipt, tokens, summary) {
12
+ const client = new client_1.Client(rootUrl);
13
+ const adminHdr = (0, rcapi_1.authHeaders)(admin);
14
+ const faults = [];
15
+ const unreadable = [];
16
+ const rooms = [];
17
+ const counts = {
18
+ messages: 0,
19
+ replies: 0,
20
+ reactions: 0,
21
+ pins: 0,
22
+ stars: 0,
23
+ mentions: 0,
24
+ edits: 0,
25
+ files: 0,
26
+ thread_parents: 0,
27
+ };
28
+ let checked = 0;
29
+ let checks = 0;
30
+ const fault = (kind, room, want, got, detail = '') => {
31
+ faults.push({ kind, room, want, got, detail });
32
+ };
33
+ const expect = (ok, kind, room, want, got) => {
34
+ checks += 1;
35
+ if (!ok)
36
+ fault(kind, room, want, got);
37
+ return ok;
38
+ };
39
+ for (const failed of (0, client_1.list)(summary.failed))
40
+ fault('execution', (0, client_1.id)(failed.name), 'completed', failed.why);
41
+ for (const failed of (0, client_1.list)(summary.users_failed))
42
+ fault('login', (0, client_1.id)(failed.username), 'named participant', failed.why);
43
+ const dates = (0, client_1.list)(receipt.done('history:timeline')?.messages);
44
+ if (plan.historyDays !== null)
45
+ expect(receipt.done('history:timeline') !== null && receipt.done('history:metadata')?.ok === true, 'history', 'history', 'completed timestamp adjustment', 'not completed');
46
+ const expectedDates = new Map(dates.map((m) => [(0, client_1.id)(m.id), (0, client_1.id)(m.ts)]));
47
+ const userEntries = [...receipt.entries.entries()].filter(([key, line]) => key.startsWith('user:') && line.state === 'done');
48
+ for (const [key, line] of userEntries) {
49
+ const username = key.slice(5);
50
+ try {
51
+ const user = (0, client_1.map)((await client.get('/api/v1/users.info', adminHdr, { userId: (0, client_1.id)(line.data.id) })).user);
52
+ expect(user._id === line.data.id && user.username === username, 'identity', username, line.data.id, user._id);
53
+ if (line.data.new === true) {
54
+ const index = userEntries.findIndex(([k]) => k === key);
55
+ const desired = (0, assets_1.profile)(username, index);
56
+ expect(user.name === desired.name && user.bio === desired.bio, 'profile', username, desired, { name: user.name, bio: user.bio });
57
+ const avatar = await rcapi_1.rcapi.download(rootUrl, `/avatar/${encodeURIComponent(username)}`, adminHdr);
58
+ expect(avatar.ok && avatar.headers['content-type']?.includes('image/') === true, 'avatar', username, 'image', avatar.status);
59
+ }
60
+ }
61
+ catch (error) {
62
+ unreadable.push({
63
+ what: username,
64
+ why: error instanceof Error ? error.message : String(error),
65
+ });
66
+ }
67
+ }
68
+ expect(userEntries.length === plan.users, 'users', 'users', plan.users, userEntries.length);
69
+ try {
70
+ const emojis = (0, client_1.list)((0, client_1.map)((await client.get('/api/v1/emoji-custom.list', adminHdr)).emojis).update);
71
+ for (const name of plan.customEmoji)
72
+ expect(emojis.some((e) => e.name === name && e._id === receipt.done(`emoji:${name}`)?.id), 'emoji', name, 'owned asset', 'missing');
73
+ }
74
+ catch (error) {
75
+ unreadable.push({
76
+ what: 'custom emoji',
77
+ why: error instanceof Error ? error.message : String(error),
78
+ });
79
+ }
80
+ for (const spec of plan.rooms) {
81
+ const created = receipt.done(`room:${spec.name}`);
82
+ if (created === null) {
83
+ fault('missing', spec.name, 'created room', 'no receipt');
84
+ continue;
85
+ }
86
+ const rid = (0, client_1.id)(created.rid);
87
+ const owner = tokens[spec.members[0] ?? ''];
88
+ const dm = [kinds_1.DM, kinds_1.GROUP_DM].includes(spec.kind);
89
+ const headers = dm ? (owner === undefined ? null : (0, rcapi_1.authHeaders)(owner)) : adminHdr;
90
+ if (headers === null) {
91
+ unreadable.push({ what: spec.name, why: 'participant could not log in' });
92
+ continue;
93
+ }
94
+ try {
95
+ const actualRoom = dm
96
+ ? (0, client_1.list)((await client.get('/api/v1/im.list', headers, { count: 0 })).ims).find((r) => r._id === rid)
97
+ : await client.room(rid, adminHdr);
98
+ if (actualRoom === undefined || (0, client_1.id)(actualRoom._id) === '')
99
+ throw new errors_1.CreateFailedError('room readback returned no identity');
100
+ expect(actualRoom._id === rid, 'room', spec.name, rid, actualRoom._id);
101
+ if (!dm && spec.kind !== kinds_1.ARCHIVED) {
102
+ const detail = (0, client_1.map)((await client.get('/api/v1/rooms.info', adminHdr, { roomId: rid })).room);
103
+ if (detail._id !== rid)
104
+ throw new errors_1.CreateFailedError('room details returned no matching identity');
105
+ Object.assign(actualRoom, detail);
106
+ }
107
+ const type = (0, client_1.id)(actualRoom.t) || (0, client_1.id)(created.type);
108
+ const api = type === 'd' ? 'im' : type === 'p' ? 'groups' : 'channels';
109
+ const messages = await client.pages(`/api/v1/${api}.messages`, headers, 'messages', {
110
+ roomId: rid,
111
+ });
112
+ const byId = new Map(messages.map((m) => [(0, client_1.id)(m._id), m]));
113
+ if (dm) {
114
+ const participants = Array.isArray(actualRoom.usernames)
115
+ ? actualRoom.usernames
116
+ : [];
117
+ expect(participants.length === spec.members.length &&
118
+ spec.members.every((n) => participants.includes(n)), 'participants', spec.name, spec.members, participants);
119
+ }
120
+ else {
121
+ const members = await client.pages(`/api/v1/${type === 'p' ? 'groups' : 'channels'}.members`, headers, 'members', { roomId: rid });
122
+ for (const username of spec.members)
123
+ expect(members.some((m) => m._id === receipt.done(`user:${username}`)?.id), 'member', spec.name, username, 'missing');
124
+ }
125
+ if (created.teamId !== '' && spec.kind !== kinds_1.DISCUSSION) {
126
+ expect(actualRoom.teamId === created.teamId, 'team', spec.name, created.teamId, actualRoom.teamId);
127
+ const members = await client.pages('/api/v1/teams.members', adminHdr, 'members', {
128
+ teamId: (0, client_1.id)(created.teamId),
129
+ });
130
+ for (const username of spec.members)
131
+ expect(members.some((m) => (0, client_1.id)((0, client_1.map)(m.user ?? m)._id) === receipt.done(`user:${username}`)?.id), 'team-member', spec.name, username, 'missing');
132
+ }
133
+ if (spec.kind === kinds_1.DISCUSSION) {
134
+ const parent = (0, client_1.id)(receipt.done(`room:${spec.parent}`)?.rid);
135
+ expect(actualRoom.prid === parent && actualRoom.fname === spec.name, 'discussion', spec.name, { parent, title: spec.name }, { parent: actualRoom.prid, title: actualRoom.fname });
136
+ }
137
+ let roomMessages = 0;
138
+ let roomReplies = 0;
139
+ let roomReacted = 0;
140
+ for (const item of spec.content) {
141
+ const recorded = receipt.done(`message:${spec.name}:${item.key}`);
142
+ if (recorded === null) {
143
+ fault('message', spec.name, item.key, 'no receipt');
144
+ continue;
145
+ }
146
+ const message = byId.get((0, client_1.id)(recorded.id));
147
+ if (message === undefined) {
148
+ fault('message', spec.name, recorded.id, 'absent');
149
+ continue;
150
+ }
151
+ counts.messages = (counts.messages ?? 0) + 1;
152
+ roomMessages += 1;
153
+ if (item.kind === 'reply') {
154
+ roomReplies += 1;
155
+ counts.replies = (counts.replies ?? 0) + 1;
156
+ }
157
+ const uid = item.author === '' ? admin.userId : (0, client_1.id)(receipt.done(`user:${item.author}`)?.id);
158
+ expect(message.rid === rid && (0, client_1.id)((0, client_1.map)(message.u)._id) === uid, 'author', spec.name, { rid, userId: uid }, { rid: message.rid, userId: (0, client_1.map)(message.u)._id });
159
+ expect(message.msg === (item.editedText || item.text), 'text', spec.name, item.editedText || item.text, message.msg);
160
+ const parent = item.parent === '' ? '' : (0, client_1.id)(receipt.done(`message:${spec.name}:${item.parent}`)?.id);
161
+ expect((0, client_1.id)(message.tmid) === parent, 'thread-parent', spec.name, parent, (0, client_1.id)(message.tmid));
162
+ const ts = expectedDates.get((0, client_1.id)(message._id));
163
+ if (ts !== undefined)
164
+ expect(message.ts === ts, 'date', spec.name, ts, message.ts);
165
+ if (item.reactions.length > 0)
166
+ roomReacted += 1;
167
+ for (const action of item.reactions) {
168
+ const usernames = (0, client_1.map)((0, client_1.map)(message.reactions)[action.emoji]).usernames;
169
+ if (expect(Array.isArray(usernames) && usernames.includes(action.author), 'reaction', spec.name, action, 'missing'))
170
+ counts.reactions = (counts.reactions ?? 0) + 1;
171
+ }
172
+ if (item.pin) {
173
+ if (expect(message.pinned === true, 'pin', spec.name, true, message.pinned))
174
+ counts.pins = (counts.pins ?? 0) + 1;
175
+ }
176
+ if (item.star !== '') {
177
+ const actor = tokens[item.star];
178
+ if (actor === undefined)
179
+ throw new errors_1.CreateFailedError('star owner could not sign in');
180
+ const personal = (0, client_1.map)((await client.get('/api/v1/chat.getMessage', (0, rcapi_1.authHeaders)(actor), {
181
+ msgId: (0, client_1.id)(recorded.id),
182
+ })).message);
183
+ if (expect(personal._id === recorded.id &&
184
+ (0, client_1.list)(personal.starred).some((s) => s._id === receipt.done(`user:${item.star}`)?.id), 'star', spec.name, item.star, 'missing'))
185
+ counts.stars = (counts.stars ?? 0) + 1;
186
+ }
187
+ if (item.mention !== '') {
188
+ if (expect((0, client_1.list)(message.mentions).some((m) => m.username === item.mention), 'mention', spec.name, item.mention, message.mentions))
189
+ counts.mentions = (counts.mentions ?? 0) + 1;
190
+ }
191
+ if (item.editedText !== '') {
192
+ if (expect((0, client_1.id)((0, client_1.map)(message.editedBy)._id) === uid && typeof message.editedAt === 'string', 'edit', spec.name, 'editor and action date', { editor: (0, client_1.map)(message.editedBy)._id, date: message.editedAt }))
193
+ counts.edits = (counts.edits ?? 0) + 1;
194
+ }
195
+ if (item.kind === 'main' && spec.threads.includes(Number(item.key.slice(5)))) {
196
+ if (expect(Number(message.tcount) >= spec.replyCount, 'thread', spec.name, spec.replyCount, message.tcount))
197
+ counts.thread_parents = (counts.thread_parents ?? 0) + 1;
198
+ }
199
+ if (item.kind === 'file') {
200
+ const upload = receipt.done(`upload:${spec.name}:${item.key}`);
201
+ expect(upload !== null && (0, client_1.id)((0, client_1.map)(message.file)._id) === upload.id, 'file', spec.name, upload?.id, (0, client_1.map)(message.file)._id);
202
+ const auth = tokens[item.author] ?? (item.author === '' ? admin : undefined);
203
+ if (auth === undefined)
204
+ throw new errors_1.CreateFailedError('file uploader could not sign in');
205
+ const url = new URL((0, client_1.id)(upload?.url), rootUrl);
206
+ url.searchParams.set('rc_uid', auth.userId);
207
+ url.searchParams.set('rc_token', auth.token);
208
+ const downloaded = await rcapi_1.rcapi.download(rootUrl, url.href, (0, rcapi_1.authHeaders)(auth));
209
+ const bytes = downloaded.bytes;
210
+ if (expect(downloaded.ok &&
211
+ bytes !== undefined &&
212
+ (0, node_crypto_1.createHash)('sha256').update(bytes).digest('hex') === upload?.sha256, 'download', spec.name, 'packaged bytes', downloaded.status))
213
+ counts.files = (counts.files ?? 0) + 1;
214
+ }
215
+ }
216
+ const opening = [...receipt.entries.values()].filter((e) => e.state === 'done' && e.key.startsWith(`opening:${spec.name}:`));
217
+ for (const e of opening) {
218
+ const m = byId.get((0, client_1.id)(e.data.id));
219
+ expect(m !== undefined, 'opening', spec.name, e.data.id, 'absent');
220
+ const ts = expectedDates.get((0, client_1.id)(e.data.id));
221
+ if (ts !== undefined)
222
+ expect(m?.ts === ts, 'opening-date', spec.name, ts, m?.ts);
223
+ }
224
+ if (spec.kind === kinds_1.READ_ONLY)
225
+ expect(actualRoom.ro === true, 'read-only', spec.name, true, actualRoom.ro);
226
+ if (spec.kind === kinds_1.BROADCAST)
227
+ expect(actualRoom.broadcast === true && actualRoom.ro === true, 'broadcast', spec.name, true, { broadcast: actualRoom.broadcast, ro: actualRoom.ro });
228
+ if (spec.kind === kinds_1.ARCHIVED)
229
+ expect(actualRoom.archived === true, 'archived', spec.name, true, actualRoom.archived);
230
+ if (spec.kind === kinds_1.PERMISSIONS) {
231
+ const roles = (0, client_1.list)((await client.get('/api/v1/groups.roles', adminHdr, { roomId: rid })).roles);
232
+ for (const [username, role] of [
233
+ ['alice', 'owner'],
234
+ ['bob', 'moderator'],
235
+ ])
236
+ expect(roles.some((r) => (0, client_1.map)(r.u).username === username && Array.isArray(r.roles) && r.roles.includes(role)), 'role', spec.name, { username, role }, roles);
237
+ const muted = actualRoom.muted;
238
+ expect(Array.isArray(muted) &&
239
+ (muted.includes('carol') || muted.includes(receipt.done('user:carol')?.id)), 'muted', spec.name, 'carol', muted);
240
+ const outsider = tokens.dave;
241
+ if (outsider === undefined)
242
+ throw new errors_1.CreateFailedError('permissions outsider could not sign in');
243
+ let denied = false;
244
+ try {
245
+ await client.get('/api/v1/groups.history', (0, rcapi_1.authHeaders)(outsider), { roomId: rid });
246
+ }
247
+ catch (error) {
248
+ if (error instanceof client_1.ApiRejected && [400, 403, 404].includes(error.status))
249
+ denied = true;
250
+ else
251
+ throw error;
252
+ }
253
+ expect(denied, 'privacy', spec.name, 'outsider denied', 'access granted');
254
+ }
255
+ if ([kinds_1.READ_ONLY, kinds_1.BROADCAST, kinds_1.PERMISSIONS].includes(spec.kind)) {
256
+ const username = spec.kind === kinds_1.PERMISSIONS ? 'carol' : (spec.members[1] ?? spec.members[0] ?? '');
257
+ const auth = tokens[username];
258
+ if (auth === undefined)
259
+ throw new errors_1.CreateFailedError('scenario participant could not sign in');
260
+ const key = `probe:${spec.name}`;
261
+ const mid = receipt.identifier(key);
262
+ const text = 'Houston scenario permission verification';
263
+ const absent = (error) => error instanceof client_1.ApiRejected &&
264
+ [400, 404].includes(error.status) &&
265
+ ['error-invalid-message', 'error-message-not-found', 'error-invalid-message-id'].includes(error.errorType);
266
+ const clean = async () => {
267
+ try {
268
+ await client.post('/api/v1/chat.delete', adminHdr, { roomId: rid, msgId: mid });
269
+ }
270
+ catch (error) {
271
+ if (!absent(error))
272
+ throw error;
273
+ }
274
+ };
275
+ const outcome = await receipt.step(key, { id: mid, rid, userId: auth.userId }, async () => {
276
+ let denied = false;
277
+ try {
278
+ const body = await client.post('/api/v1/chat.sendMessage', (0, rcapi_1.authHeaders)(auth), {
279
+ message: { _id: mid, rid, msg: text },
280
+ });
281
+ if ((0, client_1.map)(body.message)._id !== mid)
282
+ throw new errors_1.ConflictError('scenario probe returned no matching identity');
283
+ }
284
+ catch (error) {
285
+ if (error instanceof client_1.ApiRejected &&
286
+ [400, 403].includes(error.status) &&
287
+ /not-allowed|read.?only|muted|permission|unauthorized/iu.test(error.errorType))
288
+ denied = true;
289
+ else
290
+ throw error;
291
+ }
292
+ receipt.record(`probe-result:${spec.name}`, 'done', { denied });
293
+ if (!denied)
294
+ await clean();
295
+ return { denied };
296
+ }, async () => {
297
+ const saved = receipt.done(`probe-result:${spec.name}`);
298
+ if (saved?.denied === true)
299
+ return saved;
300
+ const message = await client.pendingMessage(mid, rid, api, (0, rcapi_1.authHeaders)(auth));
301
+ if (message === null)
302
+ return saved?.denied === false ? saved : null;
303
+ if (message._id !== mid ||
304
+ message.rid !== rid ||
305
+ (0, client_1.map)(message.u)._id !== auth.userId ||
306
+ message.msg !== text)
307
+ throw new errors_1.ConflictError('pending scenario probe identity changed');
308
+ receipt.record(`probe-result:${spec.name}`, 'done', { denied: false });
309
+ await clean();
310
+ return { denied: false };
311
+ });
312
+ const denied = outcome.denied === true;
313
+ expect(denied, 'posting-permission', spec.name, 'ordinary member denied', 'posting allowed');
314
+ }
315
+ if (plan.historyDays !== null) {
316
+ const first = spec.content.find((c) => c.kind === 'main');
317
+ const firstId = first === undefined ? '' : (0, client_1.id)(receipt.done(`message:${spec.name}:${first.key}`)?.id);
318
+ if (firstId !== '') {
319
+ const ref = Date.parse(receipt.manifest.reference);
320
+ const format = (time) => {
321
+ const d = new Date(time);
322
+ return `${String(d.getUTCDate()).padStart(2, '0')}/${String(d.getUTCMonth() + 1).padStart(2, '0')}/${d.getUTCFullYear()}`;
323
+ };
324
+ const matches = await client.pages('/api/v1/chat.search', headers, 'messages', {
325
+ roomId: rid,
326
+ searchText: `INC-4821 after:${format(ref - (plan.historyDays + 1) * 86400000)} before:${format(ref + 86400000)}`,
327
+ });
328
+ expect(matches.some((m) => m._id === firstId), 'date-search', spec.name, firstId, 'absent');
329
+ }
330
+ }
331
+ checked += 1;
332
+ rooms.push({
333
+ kind: spec.kind,
334
+ name: spec.name,
335
+ rid,
336
+ found: true,
337
+ messages: roomMessages,
338
+ replies: roomReplies,
339
+ reacted: roomReacted,
340
+ threads: spec.threads.length,
341
+ in_team: true,
342
+ unreadable: '',
343
+ participants: spec.members,
344
+ });
345
+ }
346
+ catch (error) {
347
+ unreadable.push({
348
+ what: spec.name,
349
+ why: error instanceof Error ? error.message : String(error),
350
+ });
351
+ }
352
+ }
353
+ return {
354
+ ok: faults.length > 0 ? false : unreadable.length > 0 ? null : true,
355
+ faults,
356
+ extra: [],
357
+ unreadable,
358
+ checked,
359
+ checks_completed: checks,
360
+ rooms,
361
+ features: counts,
362
+ };
363
+ }
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EMOJI = exports.REPLIES = exports.MESSAGES = exports.DISCUSSION_NAMES = exports.TEAM_CHANNEL_NAMES = exports.TEAM_NAMES = exports.PRIVATE_NAMES = exports.CHANNEL_NAMES = exports.FIRST_NAMES = void 0;
4
+ exports.username = username;
5
+ exports.poolName = poolName;
6
+ exports.channelName = channelName;
7
+ exports.privateName = privateName;
8
+ exports.teamName = teamName;
9
+ exports.teamChannelName = teamChannelName;
10
+ exports.members = members;
11
+ exports.threads = threads;
12
+ exports.dmPair = dmPair;
13
+ exports.conversation = conversation;
14
+ exports.threadReply = threadReply;
15
+ exports.isContent = isContent;
16
+ exports.inTeam = inTeam;
17
+ /**
18
+ * The name pools and the deterministic choices made from them.
19
+ *
20
+ * Tier 1. Every function here is pure and deterministic, which is the property the whole
21
+ * package rests on: a plan that cannot say what a room will contain is a plan nothing can
22
+ * check.
23
+ */
24
+ const format_1 = require("../lib/format");
25
+ const kinds_1 = require("./kinds");
26
+ // Realistic pools; overflow gets a numeric suffix (e.g. alice, bob, …, alice2).
27
+ // NOTE: deliberately avoids `userN` names, which the ldap/saml presets use.
28
+ exports.FIRST_NAMES = Object.freeze([
29
+ 'alice',
30
+ 'bob',
31
+ 'carol',
32
+ 'dave',
33
+ 'erin',
34
+ 'frank',
35
+ 'grace',
36
+ 'heidi',
37
+ 'ivan',
38
+ 'judy',
39
+ 'mallory',
40
+ 'niaj',
41
+ 'olivia',
42
+ 'peggy',
43
+ 'quinn',
44
+ 'rupert',
45
+ 'sybil',
46
+ 'trent',
47
+ 'uma',
48
+ 'victor',
49
+ 'wendy',
50
+ 'xavier',
51
+ 'yvonne',
52
+ 'zack',
53
+ ]);
54
+ exports.CHANNEL_NAMES = Object.freeze([
55
+ 'team-chat',
56
+ 'dev',
57
+ 'support',
58
+ 'random',
59
+ 'announcements',
60
+ 'design',
61
+ 'qa',
62
+ 'ops',
63
+ 'product',
64
+ 'sales',
65
+ 'incidents',
66
+ 'watercooler',
67
+ ]);
68
+ exports.PRIVATE_NAMES = Object.freeze([
69
+ 'leadership',
70
+ 'private-project',
71
+ 'security',
72
+ 'hiring',
73
+ ]);
74
+ exports.TEAM_NAMES = Object.freeze([
75
+ 'platform',
76
+ 'customer-success',
77
+ 'infrastructure',
78
+ ]);
79
+ exports.TEAM_CHANNEL_NAMES = Object.freeze([
80
+ 'planning',
81
+ 'standup',
82
+ 'incidents',
83
+ 'releases',
84
+ ]);
85
+ exports.DISCUSSION_NAMES = Object.freeze([
86
+ 'customer escalation 4821',
87
+ 'rollback plan',
88
+ 'release checklist',
89
+ 'post-mortem draft',
90
+ 'capacity for Q3',
91
+ 'onboarding questions',
92
+ ]);
93
+ exports.MESSAGES = Object.freeze([
94
+ 'Hey team, any update on this?',
95
+ 'Can someone review my PR when you get a chance?',
96
+ 'Deploying to staging now 🚀',
97
+ 'Heads up: maintenance window tonight at 10pm.',
98
+ 'Thanks, that fixed it!',
99
+ "I'm seeing the same issue on my end.",
100
+ "Let's sync about this in standup.",
101
+ 'Docs are updated, please take a look.',
102
+ "Good morning! What's on the agenda today?",
103
+ 'Anyone free for a quick call?',
104
+ 'Ticket #4821 is resolved.',
105
+ 'Nice work everyone 👏',
106
+ 'Reminder: submit your timesheets.',
107
+ 'Rolling back the last change, it broke the build.',
108
+ 'LGTM ✅',
109
+ 'Where did we land on the pricing question?',
110
+ ]);
111
+ exports.REPLIES = Object.freeze([
112
+ 'Good catch — looking now.',
113
+ 'Same here, reproduced on the test workspace.',
114
+ 'Fixed in the branch, pushing shortly.',
115
+ 'Can you share the log line?',
116
+ "Agreed, let's do that.",
117
+ ]);
118
+ exports.EMOJI = Object.freeze([':+1:', ':tada:', ':eyes:', ':rocket:']);
119
+ function username(i) {
120
+ const base = exports.FIRST_NAMES[i % exports.FIRST_NAMES.length];
121
+ const grp = Math.floor(i / exports.FIRST_NAMES.length);
122
+ return grp === 0 ? base : `${base}${String(grp + 1)}`;
123
+ }
124
+ function poolName(pool, i, sep = '-') {
125
+ const base = pool[i % pool.length];
126
+ const grp = Math.floor(i / pool.length);
127
+ return grp === 0 ? base : `${base}${sep}${String(grp + 1)}`;
128
+ }
129
+ function channelName(i) {
130
+ return poolName(exports.CHANNEL_NAMES, i);
131
+ }
132
+ function privateName(i) {
133
+ return poolName(exports.PRIVATE_NAMES, i);
134
+ }
135
+ function teamName(i) {
136
+ return poolName(exports.TEAM_NAMES, i);
137
+ }
138
+ /**
139
+ * Prefixed with the team, because a channel name is unique workspace-wide.
140
+ *
141
+ * Two teams both wanting `planning` is the common case, and the second create would fail
142
+ * with a name clash rather than producing the second team's channel.
143
+ */
144
+ function teamChannelName(teamI, i) {
145
+ return `${teamName(teamI)}-${poolName(exports.TEAM_CHANNEL_NAMES, i)}`;
146
+ }
147
+ /**
148
+ * A rotating window over the user list: deterministic, and varied per room.
149
+ *
150
+ * `random.sample` gave a different membership on every run, which is why nothing
151
+ * downstream could state what a room would contain. The stride of 3 keeps consecutive
152
+ * rooms from having identical membership without needing randomness.
153
+ */
154
+ function members(names, index, size) {
155
+ if (names.length === 0)
156
+ return [];
157
+ const width = Math.max(1, Math.min(size, names.length));
158
+ const out = [];
159
+ for (let j = 0; j < width; j += 1)
160
+ out.push(names[(index * 3 + j) % names.length]);
161
+ return out;
162
+ }
163
+ function threads(messages, every = kinds_1.THREAD_EVERY) {
164
+ if (messages === 0)
165
+ return [];
166
+ const out = [];
167
+ for (let i = 0; i < messages; i += every)
168
+ out.push(i);
169
+ return out;
170
+ }
171
+ /**
172
+ * The i-th DM pair, walking increasing gaps so no pair repeats early.
173
+ *
174
+ * A random pair per DM drew with replacement across DMs, so the same pair could be
175
+ * picked twice -- and the second `im.create` returns the SAME room, so a plan asking for
176
+ * five DM rooms could produce four.
177
+ *
178
+ * Walking `gap` gives `n * floor((n - 1) / 2)` distinct pairs before any repeats. The bound is
179
+ * not `n * (n // 2)`: at `gap == n / 2` on an even user count the pair {a, a + gap} is the
180
+ * same unordered pair as {a + gap, a}, so that last band of gaps yields half as many. No
181
+ * profile comes near the limit -- `large` asks for 20 DMs from 100 users, where the bound
182
+ * is 4,950 -- but a caller passing --users 4 with 20 DMs would, and it should get repeats
183
+ * rather than a wrong promise.
184
+ */
185
+ function dmPair(names, i) {
186
+ const n = names.length;
187
+ // The gap wraps within 1..n-1 so it can never be a multiple of n, because a gap of 0
188
+ // pairs a user WITH THEMSELVES -- `im.create` accepts that and makes a self-DM, which is
189
+ // a real Rocket.Chat object and not what a plan asking for a conversation between two
190
+ // people meant. It appeared the moment `--users 2` was passed with the default five DMs.
191
+ let remaining = i;
192
+ for (let gap = 1; gap <= Math.floor(n / 2); gap += 1) {
193
+ const width = gap * 2 === n ? n / 2 : n;
194
+ if (remaining < width)
195
+ return [names[remaining], names[(remaining + gap) % n]];
196
+ remaining -= width;
197
+ }
198
+ return dmPair(names, i % Math.max(1, (n * (n - 1)) / 2));
199
+ }
200
+ function conversation(room, index, mention = '', emoji = '') {
201
+ const topic = ['deployment review', 'incident response', 'customer support', 'sprint planning'][index % 4];
202
+ const formats = [
203
+ `**INC-4821 ${topic}** in #${room}. Checkpoint ${index + 1}: review the evidence before the next step.`,
204
+ `INC-4821 ${topic}\n- reproduce the reported behavior\n- record the result\n- agree on the next checkpoint`,
205
+ `INC-4821 ${topic}\n> Keep the customer updated with the observed result.\n\nReview: [Rocket.Chat documentation](https://docs.rocket.chat/)`,
206
+ `INC-4821 ${topic}\n\`\`\`text\nstatus=under-review\ncheckpoint=${index + 1}\n\`\`\`\nनमस्ते · مرحبا · 你好`,
207
+ ];
208
+ return `${formats[index % formats.length]}${mention === '' ? '' : ` @${mention}, please review.`}${emoji === '' ? '' : ` :${emoji}:`}`;
209
+ }
210
+ function threadReply(room, parentIndex, replyIndex) {
211
+ const replies = [
212
+ 'I checked the reproduction steps',
213
+ 'The logs support this checkpoint',
214
+ 'I added the customer context',
215
+ 'The next action is assigned',
216
+ 'I reviewed the rollback notes',
217
+ ];
218
+ return `INC-4821 #${room}, checkpoint ${parentIndex + 1}: ${replies[(Math.floor(parentIndex / kinds_1.THREAD_EVERY) + replyIndex) % replies.length]}. Follow-up ${replyIndex + 1}.`;
219
+ }
220
+ /**
221
+ * A message with a `t` is the SERVER talking about the room, not a person talking in it.
222
+ *
223
+ * Rather than list them (there are dozens -- `uj`, `au`, `ru`, `room_changed_topic`,
224
+ * `discussion-created`, ...), anything carrying a `t` at all is treated as a system
225
+ * message, which is what the client does to decide whether to render it as a grey line.
226
+ */
227
+ function isContent(message) {
228
+ // No truthy `t` (`isTruthy`: an empty list is no `t` either), and a message that is not
229
+ // a mapping raises, which ends the readback as it always has.
230
+ return !(0, format_1.isTruthy)((0, format_1.dictGetChecked)(message, 't'));
231
+ }
232
+ async function inTeam(get, hdr, teamName_, roomName) {
233
+ // Each member read, `or` and loop by the established rules (`dictGetChecked`, `orElse`,
234
+ // `iterateChecked`), stopping at the first room that matches.
235
+ const [body] = await get('/api/v1/teams.info', hdr, { teamName: teamName_ });
236
+ const teamId = (0, format_1.dictGetChecked)((0, format_1.orElse)((0, format_1.dictGetChecked)((0, format_1.orElse)(body, {}), 'teamInfo'), {}), '_id');
237
+ if (!(0, format_1.isTruthy)(teamId))
238
+ return false;
239
+ const [rooms] = await get('/api/v1/teams.listRooms', hdr, {
240
+ teamId: typeof teamId === 'string' ? teamId : (0, format_1.storedText)(teamId),
241
+ count: 100,
242
+ });
243
+ for (const r of (0, format_1.iterateChecked)((0, format_1.orElse)((0, format_1.dictGetChecked)((0, format_1.orElse)(rooms, {}), 'rooms'), []))) {
244
+ if ((0, format_1.dictGetChecked)(r, 'name') === roomName)
245
+ return true;
246
+ }
247
+ return false;
248
+ }