@desplega.ai/agent-swarm 2.7.10 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-adapter-t949vbbp.js +15 -0
- package/dist/{actions-b8aqhrsg.js → actions-7e9czc7s.js} +18 -19
- package/dist/{amp-adapter-4c165vgn.js → amp-adapter-gv6cbb7d.js} +2 -3
- package/dist/{app-m9khefrh.js → app-b9fbkp9v.js} +3 -3
- package/dist/{assistant-rh4v3ntz.js → assistant-wjb7v4c7.js} +20 -21
- package/dist/{boot-args-schema-hwkc8bzv.js → boot-args-schema-2t37e0fe.js} +1 -1
- package/dist/{boot-reembed-5y6yw9sj.js → boot-reembed-a35nkyr1.js} +1 -1
- package/dist/{boot-reembed-fdyk55h4.js → boot-reembed-gka3zas7.js} +1 -1
- package/dist/{boot-scrub-sweep-r5r8kqsn.js → boot-scrub-sweep-65sdnp6c.js} +3 -3
- package/dist/{boot-seeds-8f9zt5cm.js → boot-seeds-x42tzytw.js} +4 -5
- package/dist/{claude-adapter-s5df247c.js → claude-adapter-v221b2fd.js} +7 -8
- package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-29eq09wd.js} +2 -2
- package/dist/{claude-managed-setup-9gsmwzyx.js → claude-managed-setup-9m6450zk.js} +2 -2
- package/dist/{claude-sdk-session-dq1j4nz9.js → claude-sdk-session-0q0ptaba.js} +9066 -8818
- package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
- package/dist/{cli-5wfz00be.js → cli-0jzra9ad.js} +2 -2
- package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
- package/dist/{cli-eqk5p56g.js → cli-2wnq8jkz.js} +9 -9
- package/dist/{cli-hfkwwy1h.js → cli-2zp0et3v.js} +21 -2
- package/dist/{cli-rt0ag4x1.js → cli-334z18y3.js} +4 -4
- package/dist/{cli-6m6b4bep.js → cli-3rkdne1h.js} +2 -2
- package/dist/{cli-3xddv0rk.js → cli-4txa0ter.js} +5 -7
- package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
- package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
- package/dist/{cli-n07eecjs.js → cli-6t09sdhy.js} +3 -3
- package/dist/{cli-38yww4e9.js → cli-6wxjceza.js} +8 -8
- package/dist/{cli-5xcb8gxq.js → cli-7b8sbmag.js} +8 -8
- package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
- package/dist/{cli-mp9aa8g5.js → cli-7p1kvkck.js} +6 -6
- package/dist/{cli-w3bk0dgv.js → cli-8aes17e4.js} +2 -2
- package/dist/{cli-n9abj89w.js → cli-8fknbnhw.js} +8 -8
- package/dist/{cli-xd5ebp64.js → cli-8kzasymh.js} +3 -3
- package/dist/{cli-2tsfpc70.js → cli-a7wvp2km.js} +1 -1
- package/dist/{cli-kx4c8j05.js → cli-abejgen1.js} +63 -19
- package/dist/{cli-36wdfzgn.js → cli-bsywb58a.js} +8 -8
- package/dist/{cli-yz7v0sh4.js → cli-c55z5chy.js} +4 -6
- package/dist/{cli-18qt3few.js → cli-deefvewm.js} +1 -1
- package/dist/{cli-jg24scat.js → cli-ee0b971j.js} +3 -3
- package/dist/cli-f3vq58d2.js +242 -0
- package/dist/{cli-3xcwp3z8.js → cli-ffhtssbp.js} +2 -2
- package/dist/{cli-rjyghzg4.js → cli-g70vxtjh.js} +2 -2
- package/dist/{cli-g1px1g2e.js → cli-gxkx0zzp.js} +1 -1
- package/dist/{cli-j7d73g1y.js → cli-h38x262p.js} +3035 -354
- package/dist/{cli-zjphdj1a.js → cli-j790gp2w.js} +40 -18
- package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
- package/dist/{cli-td33w98c.js → cli-m23zjcy2.js} +10 -10
- package/dist/{cli-8ewkreqd.js → cli-m28atx8q.js} +7 -9
- package/dist/{cli-x9exydey.js → cli-m4dqmnbp.js} +1 -1
- package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
- package/dist/{cli-mr97t7cc.js → cli-p1bq50aa.js} +263 -14
- package/dist/{cli-ttbqe3q4.js → cli-p1w18yhx.js} +1 -1
- package/dist/{cli-nj3x45rw.js → cli-p2gfst4m.js} +52 -43
- package/dist/{cli-z9cs5m0w.js → cli-pasjcnmj.js} +12 -12
- package/dist/{cli-an1knn2k.js → cli-qa4wdgsy.js} +5 -5
- package/dist/{cli-xncjscpm.js → cli-qfedvmcr.js} +50 -24
- package/dist/{cli-tmft5dz2.js → cli-qmqk2yc2.js} +1 -1
- package/dist/{cli-bxz823sz.js → cli-qsnnd04k.js} +1 -1
- package/dist/{cli-cr14kftt.js → cli-qwca7s44.js} +3 -3
- package/dist/{cli-7wz05bx3.js → cli-rfywm85n.js} +460 -737
- package/dist/{cli-v2fwbnsk.js → cli-rmmpt0wm.js} +6 -6
- package/dist/{cli-xbtq4d6s.js → cli-rzsy6nc6.js} +12 -8
- package/dist/{cli-0m7rtm11.js → cli-s7t6p9my.js} +1 -1
- package/dist/{cli-16phend6.js → cli-sdtt3men.js} +1 -1
- package/dist/{cli-pyrxt9gw.js → cli-tk7cjj8h.js} +1 -1
- package/dist/{cli-xvymtmv4.js → cli-tqegb8eq.js} +3 -3
- package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
- package/dist/{cli-h49ejvmc.js → cli-wcg8x116.js} +1 -1
- package/dist/{cli-q581b386.js → cli-wk18cm92.js} +5 -5
- package/dist/{cli-4vwxp550.js → cli-x1wa213s.js} +1 -1
- package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
- package/dist/{cli-eb2azq8n.js → cli-y97qxcfx.js} +9 -9
- package/dist/{cli-55bkx8hh.js → cli-yq3zak69.js} +1 -1
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-yr60sme6.js → codex-adapter-30j9bpzd.js} +5 -6
- package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
- package/dist/{codex-session-runner-pch8x584.js → codex-session-runner-8vp57v8w.js} +5 -6
- package/dist/{commands-phjfbkv0.js → commands-bngnz9g7.js} +3 -3
- package/dist/{controller-jkx994pz.js → controller-hxx8wwy1.js} +2 -2
- package/dist/{controllers-connect-c4448kwa.js → controllers-connect-e2b4gyxc.js} +19 -20
- package/dist/{cursor-adapter-ndebqnm8.js → cursor-adapter-n5nc3mfe.js} +1 -2
- package/dist/{db-ez6egt6v.js → db-bgm7vkc0.js} +3 -3
- package/dist/{db-ef32tbfc.js → db-c6np41ca.js} +10 -2
- package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
- package/dist/{dispatcher-g3tt9hs9.js → dispatcher-jnybck15.js} +17 -18
- package/dist/{dsh-adapter-tcyn3099.js → dsh-adapter-nrhbrjz8.js} +1 -2
- package/dist/{easter-egg-3d-e36hk5td.js → easter-egg-3d-533knw22.js} +1 -1
- package/dist/{embedding-space-4kyh5qqj.js → embedding-space-crsm2zp0.js} +6 -6
- package/dist/{embeddings-6a8v4a6t.js → embeddings-e7z3f27f.js} +1 -1
- package/dist/{execute-3cbg0twf.js → execute-b3mrb1mv.js} +1 -1
- package/dist/{external-channel-se646snz.js → external-channel-m77wf5z3.js} +2 -2
- package/dist/{fx-adapter-yw795hqq.js → fx-adapter-b6w0kf56.js} +7 -8
- package/dist/{grok-adapter-ttmcss2j.js → grok-adapter-4sqtebdk.js} +7 -8
- package/dist/handlers-kdjcyzdj.js +32 -0
- package/dist/heartbeat-xgb036sx.js +43 -0
- package/dist/{hook-g3nhexsy.js → hook-5h02c9ga.js} +6 -6
- package/dist/{hook-hq93y5ej.js → hook-xsk1jbha.js} +5 -5
- package/dist/{http-5a9p4h6y.js → http-txe7qhvn.js} +282 -140
- package/dist/{index-6haqt3v5.js → index-4a0670yh.js} +8917 -8476
- package/dist/index-835xdgnm.js +33 -0
- package/dist/index-d469300x.js +37 -0
- package/dist/index-rzqwp11g.js +32 -0
- package/dist/{index-s72rqgsx.js → index-tvfafeyy.js} +1 -1
- package/dist/{index-hgn3c961.js → index-vk63emp7.js} +978 -35
- package/dist/{index-3c5pxbge.js → index-ysvbhg5m.js} +1 -1
- package/dist/{keepalive-1j4n4dmk.js → keepalive-4zsrce78.js} +3 -3
- package/dist/lead-yqt47dkr.js +70 -0
- package/dist/{maintenance-dmghacy5.js → maintenance-86jvartk.js} +1 -1
- package/dist/{oauth-refresh-sweep-yy06c03c.js → oauth-refresh-sweep-j52kg9pr.js} +2 -2
- package/dist/{onboard-52f9t5dm.js → onboard-c2aj5p8q.js} +3 -3
- package/dist/{opencode-adapter-krnh9jkn.js → opencode-adapter-dsagkhtw.js} +5 -6
- package/dist/{otel-impl-xjqz6wjj.js → otel-impl-yyy203z8.js} +1 -1
- package/dist/{pi-mono-adapter-dbxyp0qv.js → pi-mono-adapter-546cd1cc.js} +9 -9
- package/dist/{pricing-refresh-ctdr74pd.js → pricing-refresh-1rgzqyzz.js} +2 -3
- package/dist/{rbac-roles-q0gr8eyj.js → rbac-roles-e70xfeyj.js} +4 -6
- package/dist/{rbac-roles-ehv8s10n.js → rbac-roles-q89qe8er.js} +3 -3
- package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
- package/dist/{render-v2-5b6chvcq.js → render-v2-k6tt107q.js} +3 -3
- package/dist/{resume-5a5d2845.js → resume-cnnrjfxa.js} +6 -6
- package/dist/{runtime-khxszyfp.js → runtime-1hv06jsn.js} +1 -1
- package/dist/{session-access-gj0bjhqg.js → session-access-xkxkjw3n.js} +4 -4
- package/dist/{session-source-backfill-2sy0krfk.js → session-source-backfill-1d5pdwww.js} +2 -2
- package/dist/{setup-7ssfakk1.js → setup-se8q7gkc.js} +1 -1
- package/dist/{virtual-modules-pjj0knwf.js → virtual-modules-gazyapte.js} +3 -3
- package/dist/{work-objects-bf3syvhq.js → work-objects-1kxnbzy5.js} +20 -21
- package/dist/{worker-follow-up-38xevga6.js → worker-follow-up-zqm8apt4.js} +17 -18
- package/dist/worker-j6xxtq7p.js +70 -0
- package/openapi.json +334 -7
- package/package.json +4 -4
- package/src/apps/definition.ts +11 -0
- package/src/apps/store.ts +28 -8
- package/src/be/db/model-profiles.ts +147 -38
- package/src/be/db/tasks/read.ts +5 -1
- package/src/be/db/workflow-run-definitions.ts +117 -0
- package/src/be/db.ts +24 -3
- package/src/be/memory/constants.ts +14 -1
- package/src/be/memory/key-paths.ts +8 -0
- package/src/be/memory/providers/sqlite-store.ts +160 -10
- package/src/be/memory/task-learning.ts +79 -14
- package/src/be/memory/types.ts +24 -1
- package/src/be/migrations/279_backfill_learning_expiry.sql +15 -0
- package/src/be/migrations/281_model_profiles_pr2.sql +28 -0
- package/src/be/migrations/283_workflow_run_definitions.sql +14 -0
- package/src/be/model-profile-check.ts +284 -0
- package/src/be/model-tier-resolution.ts +112 -12
- package/src/be/multi-runtime.ts +27 -0
- package/src/be/runtime-pools/routing.ts +52 -4
- package/src/be/scripts/typecheck.ts +1 -0
- package/src/be/seed-scripts/catalog/dreaming-learnings.ts +552 -0
- package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +389 -14
- package/src/be/seed-scripts/catalog/dreaming-memtax.ts +6 -3
- package/src/be/seed-scripts/index.ts +9 -0
- package/src/be/steering.ts +8 -2
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/runner.ts +32 -1
- package/src/fs/provider.ts +17 -3
- package/src/heartbeat/heartbeat.ts +12 -1
- package/src/heartbeat/index.ts +1 -0
- package/src/http/agents.ts +56 -4
- package/src/http/apps.ts +3 -1
- package/src/http/config.ts +2 -6
- package/src/http/index.ts +2 -3
- package/src/http/model-profiles.ts +58 -10
- package/src/http/poll.ts +36 -3
- package/src/http/schedules.ts +42 -3
- package/src/http/tasks.ts +37 -12
- package/src/http/workflows.ts +15 -2
- package/src/prompts/session-templates.ts +1 -1
- package/src/providers/acp-targets.ts +11 -6
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-sdk-session.ts +132 -23
- package/src/providers/codex-skill-resolver.ts +10 -4
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/devin-skill-resolver.ts +5 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/scheduler/schedule-task.ts +1 -0
- package/src/scripts-runtime/sdk-allowlist.ts +1 -0
- package/src/scripts-runtime/swarm-sdk.ts +18 -1
- package/src/scripts-runtime/types/stdlib.d.ts +1 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
- package/src/server.ts +2 -0
- package/src/slack/app.ts +93 -0
- package/src/slack/inbound-dispatch.ts +18 -1
- package/src/slack/workspace-guard.ts +345 -0
- package/src/tasks/task-terminal-effects.ts +4 -0
- package/src/tasks/worker-follow-up.ts +102 -2
- package/src/tests/acp-adapter.test.ts +82 -0
- package/src/tests/apps-icon.test.ts +120 -0
- package/src/tests/chained-task-follow-up.test.ts +248 -0
- package/src/tests/check-pr-body.test.ts +40 -0
- package/src/tests/claude-sdk-lifecycle.test.ts +216 -1
- package/src/tests/claude-sdk-process.fixture.ts +57 -0
- package/src/tests/codex-skill-resolver.test.ts +31 -0
- package/src/tests/credentials-allowlist.test.ts +470 -0
- package/src/tests/db-task-read-contract.test.ts +5 -0
- package/src/tests/db-task-write-contract.test.ts +5 -0
- package/src/tests/deferred-wake-follow-up.test.ts +47 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dreaming-learnings.test.ts +1395 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/explicit-model-validation.test.ts +2 -0
- package/src/tests/fs-provider.test.ts +42 -0
- package/src/tests/heartbeat.test.ts +28 -1
- package/src/tests/human-free-reclassify.test.ts +5 -1
- package/src/tests/list-endpoint-slimming.test.ts +17 -0
- package/src/tests/migration-283-workflow-run-definitions.test.ts +69 -0
- package/src/tests/model-profile-check.test.ts +387 -0
- package/src/tests/model-profiles-api.test.ts +528 -1
- package/src/tests/profile-claim.test.ts +415 -3
- package/src/tests/profile-tier-alias.test.ts +382 -0
- package/src/tests/schedule-profile.test.ts +359 -0
- package/src/tests/script-connections.test.ts +6 -0
- package/src/tests/script-per-script-executor.test.ts +1 -0
- package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +141 -0
- package/src/tests/seed-scripts.test.ts +2 -2
- package/src/tests/slack-inbound-receipts.test.ts +22 -2
- package/src/tests/slack-socket-ack.test.ts +16 -1
- package/src/tests/slack-workspace-guard.test.ts +905 -0
- package/src/tests/steering-core.test.ts +40 -0
- package/src/tests/store-progress-learning.test.ts +605 -20
- package/src/tests/tool-annotations.test.ts +1 -1
- package/src/tests/workflow-convergence.test.ts +46 -40
- package/src/tests/workflow-definition-pinning-recovery.test.ts +552 -0
- package/src/tests/workflow-definition-pinning.test.ts +645 -0
- package/src/tests/workflow-executors.test.ts +16 -7
- package/src/tests/workflow-foreach.test.ts +43 -20
- package/src/tests/workflow-notify-slack-ready.test.ts +161 -0
- package/src/tests/workflow-profile.test.ts +328 -0
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/memory-edit.ts +2 -1
- package/src/tools/model-profiles/check-model-profile.ts +63 -0
- package/src/tools/schedules/create-schedule.ts +45 -4
- package/src/tools/schedules/patch-schedule.ts +50 -4
- package/src/tools/schedules/update-schedule.ts +50 -4
- package/src/tools/send-task.ts +17 -2
- package/src/tools/store-progress.ts +15 -3
- package/src/tools/task-action.ts +9 -1
- package/src/tools/templates.ts +13 -0
- package/src/tools/tool-config.ts +2 -1
- package/src/tools/utils.ts +61 -4
- package/src/tools/workflows/create-workflow.ts +1 -1
- package/src/tools/workflows/retry-workflow-run.ts +1 -1
- package/src/tools/workflows/update-workflow.ts +10 -1
- package/src/types.ts +56 -1
- package/src/utils/credentials.ts +89 -12
- package/src/workflows/engine.ts +10 -1
- package/src/workflows/executors/agent-task.ts +21 -2
- package/src/workflows/executors/foreach.ts +4 -1
- package/src/workflows/executors/notify.ts +62 -6
- package/src/workflows/executors/sub-workflow.ts +1 -1
- package/src/workflows/executors/swarm-script.ts +4 -1
- package/src/workflows/foreach-driver.ts +8 -5
- package/src/workflows/limits.ts +2 -1
- package/src/workflows/model-validation.ts +27 -2
- package/src/workflows/patch-definition.ts +3 -1
- package/src/workflows/recovery.ts +6 -6
- package/src/workflows/resume.ts +9 -9
- package/src/workflows/retry-poller.ts +2 -2
- package/templates/skills/apps/SKILL.md +2 -0
- package/templates/skills/apps/content.md +2 -0
- package/templates/skills/code-quality/content.md +12 -0
- package/templates/skills/memory/content.md +8 -0
- package/templates/skills/scheduling/config.json +1 -1
- package/templates/skills/scheduling/content.md +2 -2
- package/templates/skills/swarm-docs/content.md +4 -0
- package/templates/skills/swarm-extensions/content.md +1 -1
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/templates/skills/work-on-task/SKILL.md +2 -0
- package/templates/skills/work-on-task/content.md +2 -0
- package/templates/workflows/dreaming/content.md +174 -7
- package/dist/acp-adapter-srfhs1s9.js +0 -16
- package/dist/cli-bzvs88tv.js +0 -339
- package/dist/cli-cyn9v8zr.js +0 -748
- package/dist/cli-ed6yqpf1.js +0 -779
- package/dist/handlers-17wha3ze.js +0 -33
- package/dist/heartbeat-gwewgdms.js +0 -42
- package/dist/index-8arwq8mw.js +0 -34
- package/dist/index-tpw054az.js +0 -38
- package/dist/index-waq75j2j.js +0 -31
- package/dist/lead-re73kdgc.js +0 -72
- package/dist/worker-r8mz7a65.js +0 -72
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound workspace guard: a Slack app shared by several swarms delivers each
|
|
3
|
+
* payload to any of the app's sockets, whatever its workspace. A delivery not
|
|
4
|
+
* proven to belong to this swarm's installation must reach no listener and get
|
|
5
|
+
* no ack, so Slack redelivers it and the owner can still receive it.
|
|
6
|
+
*/
|
|
7
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
8
|
+
import { unlinkSync } from "node:fs";
|
|
9
|
+
import { SlackMock } from "@desplega.ai/slack-mock";
|
|
10
|
+
import { App, LogLevel, type SlashCommand, SocketModeReceiver } from "@slack/bolt";
|
|
11
|
+
// Bolt's own reading of the flag; not re-exported from the package root.
|
|
12
|
+
import { isBodyWithTypeEnterpriseInstall } from "@slack/bolt/dist/helpers";
|
|
13
|
+
import { type SlackHarness, startSlackMock, stopSlackMock } from "../../scripts/e2e/slack";
|
|
14
|
+
import { repoRoot } from "../../scripts/e2e/sut";
|
|
15
|
+
import { closeDb, initDb } from "../be/db";
|
|
16
|
+
import { setSlackStartRetryDelaysForTests, startSlackApp, stopSlackApp } from "../slack/app";
|
|
17
|
+
import { getSlackConnectionState } from "../slack/connection-state";
|
|
18
|
+
import {
|
|
19
|
+
getSlackInboundDiagnostics,
|
|
20
|
+
resetSlackInboundCountersForTests,
|
|
21
|
+
runAdmittedSlackDelivery,
|
|
22
|
+
slackInboundOutcomeMiddleware,
|
|
23
|
+
} from "../slack/inbound-dispatch";
|
|
24
|
+
import { installSocketAckRecovery } from "../slack/socket-ack";
|
|
25
|
+
import {
|
|
26
|
+
classifyInboundOwnership,
|
|
27
|
+
getCachedSlackWorkspaceIdentity,
|
|
28
|
+
getSlackWorkspaceIdentity,
|
|
29
|
+
identityFromAuthTest,
|
|
30
|
+
installSocketWorkspaceGate,
|
|
31
|
+
isSlackEnterpriseInstall,
|
|
32
|
+
readInboundInstallations,
|
|
33
|
+
resetSlackWorkspaceGuardForTests,
|
|
34
|
+
resolveSlackIdentity,
|
|
35
|
+
type SlackWorkspaceIdentity,
|
|
36
|
+
setSlackWorkspaceIdentitySource,
|
|
37
|
+
} from "../slack/workspace-guard";
|
|
38
|
+
|
|
39
|
+
const TEST_DB_PATH = "./test-slack-workspace-guard.sqlite";
|
|
40
|
+
const testGlobals = globalThis as typeof globalThis & {
|
|
41
|
+
__testMigrationTemplate?: Uint8Array;
|
|
42
|
+
};
|
|
43
|
+
let savedMigrationTemplate: Uint8Array | undefined;
|
|
44
|
+
|
|
45
|
+
function removeTestDb(): void {
|
|
46
|
+
for (const path of [TEST_DB_PATH, `${TEST_DB_PATH}-wal`, `${TEST_DB_PATH}-shm`]) {
|
|
47
|
+
try {
|
|
48
|
+
unlinkSync(path);
|
|
49
|
+
} catch {
|
|
50
|
+
// The SQLite sidecars are not always created.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
beforeAll(() => {
|
|
56
|
+
closeDb();
|
|
57
|
+
savedMigrationTemplate = testGlobals.__testMigrationTemplate;
|
|
58
|
+
testGlobals.__testMigrationTemplate = undefined;
|
|
59
|
+
removeTestDb();
|
|
60
|
+
initDb(TEST_DB_PATH);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterAll(() => {
|
|
64
|
+
resetSlackWorkspaceGuardForTests();
|
|
65
|
+
closeDb();
|
|
66
|
+
removeTestDb();
|
|
67
|
+
testGlobals.__testMigrationTemplate = savedMigrationTemplate;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
resetSlackWorkspaceGuardForTests();
|
|
72
|
+
resetSlackInboundCountersForTests();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
resetSlackWorkspaceGuardForTests();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const OWN: SlackWorkspaceIdentity = {
|
|
80
|
+
teamId: "T_OWN",
|
|
81
|
+
enterpriseId: null,
|
|
82
|
+
isEnterpriseInstall: false,
|
|
83
|
+
};
|
|
84
|
+
const GRID_WORKSPACE: SlackWorkspaceIdentity = {
|
|
85
|
+
teamId: "T_OWN",
|
|
86
|
+
enterpriseId: "E_ORG",
|
|
87
|
+
isEnterpriseInstall: false,
|
|
88
|
+
botId: "B_WS",
|
|
89
|
+
};
|
|
90
|
+
const ORG_INSTALL: SlackWorkspaceIdentity = {
|
|
91
|
+
teamId: null,
|
|
92
|
+
enterpriseId: "E_ORG",
|
|
93
|
+
isEnterpriseInstall: true,
|
|
94
|
+
botId: "B_ORG",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// The documented slash command payload (docs.slack.dev/interactivity/implementing-slash-commands):
|
|
98
|
+
// team_id and enterprise_id. The example has no is_enterprise_install, which
|
|
99
|
+
// Bolt's SlashCommand type declares as an optional string.
|
|
100
|
+
function documentedCommand(teamId: string, enterpriseId: string | null) {
|
|
101
|
+
return {
|
|
102
|
+
token: "verification",
|
|
103
|
+
team_id: teamId,
|
|
104
|
+
team_domain: "example",
|
|
105
|
+
...(enterpriseId
|
|
106
|
+
? { enterprise_id: enterpriseId, enterprise_name: "Globular Construct Inc" }
|
|
107
|
+
: {}),
|
|
108
|
+
channel_id: "C2147483705",
|
|
109
|
+
channel_name: "test",
|
|
110
|
+
user_id: "U2147483697",
|
|
111
|
+
command: "/swarm",
|
|
112
|
+
text: "status",
|
|
113
|
+
api_app_id: "A123456",
|
|
114
|
+
response_url: "https://hooks.slack.com/commands/1/2",
|
|
115
|
+
trigger_id: "1.2.3",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// A BlockAction (docs.slack.dev/tools/bolt-js/reference/interfaces/BlockAction):
|
|
120
|
+
// is_enterprise_install is optional, and team is null for an org-wide install.
|
|
121
|
+
// `botId` adds the message the button is on, posted by that installation's bot.
|
|
122
|
+
function blockAction(
|
|
123
|
+
team: { id: string; enterprise_id?: string } | null,
|
|
124
|
+
enterpriseId: string | null,
|
|
125
|
+
flag?: boolean,
|
|
126
|
+
botId?: string,
|
|
127
|
+
) {
|
|
128
|
+
return {
|
|
129
|
+
type: "block_actions",
|
|
130
|
+
team,
|
|
131
|
+
enterprise: enterpriseId ? { id: enterpriseId, name: "Org" } : null,
|
|
132
|
+
user: { id: "U_HUMAN", team_id: team?.id ?? "T_GRANTED" },
|
|
133
|
+
api_app_id: "A123456",
|
|
134
|
+
token: "verification",
|
|
135
|
+
trigger_id: "1.2.3",
|
|
136
|
+
response_url: "https://hooks.slack.com/actions/1/2",
|
|
137
|
+
container: { type: "message", message_ts: "1.000001", channel_id: "C_1" },
|
|
138
|
+
channel: { id: "C_1", name: "general" },
|
|
139
|
+
actions: [{ type: "button", action_id: "follow_up_task", block_id: "b", action_ts: "1.1" }],
|
|
140
|
+
...(botId ? { message: { type: "message", bot_id: botId, ts: "1.000001", text: "x" } } : {}),
|
|
141
|
+
...(flag === undefined ? {} : { is_enterprise_install: flag }),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function resolveIdentityFor(
|
|
146
|
+
identity: SlackWorkspaceIdentity,
|
|
147
|
+
): Promise<SlackWorkspaceIdentity | null> {
|
|
148
|
+
setSlackWorkspaceIdentitySource(async () => identity);
|
|
149
|
+
return getSlackWorkspaceIdentity();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function authorization(teamId: string | null, enterpriseId: string | null, orgWide: boolean) {
|
|
153
|
+
return { team_id: teamId, enterprise_id: enterpriseId, is_enterprise_install: orgWide };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function eventBody(teamId: string, extra: Record<string, unknown> = {}) {
|
|
157
|
+
return {
|
|
158
|
+
type: "event_callback",
|
|
159
|
+
team_id: teamId,
|
|
160
|
+
api_app_id: "A_SHARED",
|
|
161
|
+
event_id: `Ev_${teamId}_${Math.random().toString(36).slice(2)}`,
|
|
162
|
+
authorizations: [authorization(teamId, null, false)],
|
|
163
|
+
event: {
|
|
164
|
+
type: "app_mention",
|
|
165
|
+
channel: "C_1",
|
|
166
|
+
ts: "1.000001",
|
|
167
|
+
user: "U_HUMAN",
|
|
168
|
+
text: "<@U_BOT> secret plans",
|
|
169
|
+
},
|
|
170
|
+
...extra,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function classify(identity: SlackWorkspaceIdentity | null, body: unknown) {
|
|
175
|
+
return classifyInboundOwnership(identity, readInboundInstallations(body));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const OWN_RESULT = { own: true };
|
|
179
|
+
const FOREIGN = { own: false, reason: "foreign_workspace" };
|
|
180
|
+
const UNVERIFIED = { own: false, reason: "unverified_workspace" };
|
|
181
|
+
|
|
182
|
+
describe("readInboundInstallations", () => {
|
|
183
|
+
test("Events API: only authorizations count, never the top-level team_id", () => {
|
|
184
|
+
// Slack Connect: the top-level team can be the partner workspace.
|
|
185
|
+
expect(
|
|
186
|
+
readInboundInstallations({
|
|
187
|
+
type: "event_callback",
|
|
188
|
+
team_id: "T_PARTNER",
|
|
189
|
+
authorizations: [authorization("T_OWN", "E_1", false)],
|
|
190
|
+
}),
|
|
191
|
+
).toEqual([{ teamId: "T_OWN", enterpriseId: "E_1", isEnterpriseInstall: false }]);
|
|
192
|
+
expect(readInboundInstallations({ type: "event_callback", team_id: "T_OWN" })).toEqual([]);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("interactive payloads: team.id, enterprise.id and is_enterprise_install", () => {
|
|
196
|
+
expect(
|
|
197
|
+
readInboundInstallations({
|
|
198
|
+
type: "block_actions",
|
|
199
|
+
team: { id: "T_A" },
|
|
200
|
+
enterprise: { id: "E_A" },
|
|
201
|
+
is_enterprise_install: false,
|
|
202
|
+
}),
|
|
203
|
+
).toEqual([{ teamId: "T_A", enterpriseId: "E_A", isEnterpriseInstall: false }]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("slash commands: string flags", () => {
|
|
207
|
+
expect(
|
|
208
|
+
readInboundInstallations({
|
|
209
|
+
command: "/swarm",
|
|
210
|
+
team_id: "T_A",
|
|
211
|
+
enterprise_id: "E_A",
|
|
212
|
+
is_enterprise_install: "true",
|
|
213
|
+
}),
|
|
214
|
+
).toEqual([{ teamId: "T_A", enterpriseId: "E_A", isEnterpriseInstall: true }]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("payload with no installation field", () => {
|
|
218
|
+
expect(readInboundInstallations({ type: "event_callback", event: {} })).toEqual([]);
|
|
219
|
+
expect(readInboundInstallations(undefined)).toEqual([]);
|
|
220
|
+
expect(readInboundInstallations({ team: null, authorizations: [] })).toEqual([]);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("classifyInboundOwnership", () => {
|
|
225
|
+
test("own and foreign workspace", () => {
|
|
226
|
+
expect(classify(OWN, eventBody("T_OWN"))).toEqual(OWN_RESULT);
|
|
227
|
+
expect(classify(OWN, eventBody("T_OTHER"))).toEqual(FOREIGN);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("fails closed without an identity or an installation field", () => {
|
|
231
|
+
expect(classify(null, eventBody("T_OWN"))).toEqual(UNVERIFIED);
|
|
232
|
+
expect(classify(OWN, { type: "event_callback", event: {} })).toEqual(UNVERIFIED);
|
|
233
|
+
expect(classify(OWN, { command: "/swarm" })).toEqual(UNVERIFIED);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("a workspace install never matches on the enterprise alone", () => {
|
|
237
|
+
// Sibling workspace of the same org.
|
|
238
|
+
expect(
|
|
239
|
+
classify(GRID_WORKSPACE, {
|
|
240
|
+
type: "event_callback",
|
|
241
|
+
authorizations: [authorization("T_SIBLING", "E_ORG", false)],
|
|
242
|
+
}),
|
|
243
|
+
).toEqual(FOREIGN);
|
|
244
|
+
// Org-only authorization: an org-wide install of the same app in our org.
|
|
245
|
+
expect(
|
|
246
|
+
classify(GRID_WORKSPACE, {
|
|
247
|
+
type: "event_callback",
|
|
248
|
+
authorizations: [authorization(null, "E_ORG", true)],
|
|
249
|
+
}),
|
|
250
|
+
).toEqual(FOREIGN);
|
|
251
|
+
// Interactive and command payloads with no workspace.
|
|
252
|
+
expect(
|
|
253
|
+
classify(GRID_WORKSPACE, { type: "block_actions", enterprise: { id: "E_ORG" } }),
|
|
254
|
+
).toEqual(FOREIGN);
|
|
255
|
+
expect(classify(GRID_WORKSPACE, { command: "/swarm", enterprise_id: "E_ORG" })).toEqual(
|
|
256
|
+
FOREIGN,
|
|
257
|
+
);
|
|
258
|
+
// Our workspace id on a delivery made to an org-wide install is not ours either.
|
|
259
|
+
expect(
|
|
260
|
+
classify(GRID_WORKSPACE, {
|
|
261
|
+
type: "block_actions",
|
|
262
|
+
team: { id: "T_OWN" },
|
|
263
|
+
enterprise: { id: "E_ORG" },
|
|
264
|
+
is_enterprise_install: true,
|
|
265
|
+
}),
|
|
266
|
+
).toEqual(FOREIGN);
|
|
267
|
+
expect(
|
|
268
|
+
classify(GRID_WORKSPACE, {
|
|
269
|
+
type: "event_callback",
|
|
270
|
+
authorizations: [authorization("T_OWN", "E_ORG", false)],
|
|
271
|
+
}),
|
|
272
|
+
).toEqual(OWN_RESULT);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("an org-wide install matches only deliveries made to an org-wide install", () => {
|
|
276
|
+
expect(
|
|
277
|
+
classify(ORG_INSTALL, {
|
|
278
|
+
type: "event_callback",
|
|
279
|
+
team_id: "T_ANY_WORKSPACE",
|
|
280
|
+
authorizations: [authorization(null, "E_ORG", true)],
|
|
281
|
+
}),
|
|
282
|
+
).toEqual(OWN_RESULT);
|
|
283
|
+
expect(
|
|
284
|
+
classify(ORG_INSTALL, {
|
|
285
|
+
type: "block_actions",
|
|
286
|
+
team: { id: "T_ANY_WORKSPACE" },
|
|
287
|
+
enterprise: { id: "E_ORG" },
|
|
288
|
+
is_enterprise_install: true,
|
|
289
|
+
}),
|
|
290
|
+
).toEqual(OWN_RESULT);
|
|
291
|
+
// A workspace-level install in our org belongs to another installation.
|
|
292
|
+
expect(
|
|
293
|
+
classify(ORG_INSTALL, {
|
|
294
|
+
type: "event_callback",
|
|
295
|
+
authorizations: [authorization("T_WS", "E_ORG", false)],
|
|
296
|
+
}),
|
|
297
|
+
).toEqual(FOREIGN);
|
|
298
|
+
// A delivery marked as a workspace-level install is not the org install's.
|
|
299
|
+
expect(
|
|
300
|
+
classify(ORG_INSTALL, {
|
|
301
|
+
type: "block_actions",
|
|
302
|
+
enterprise: { id: "E_ORG" },
|
|
303
|
+
is_enterprise_install: false,
|
|
304
|
+
}),
|
|
305
|
+
).toEqual(FOREIGN);
|
|
306
|
+
expect(
|
|
307
|
+
classify(ORG_INSTALL, {
|
|
308
|
+
type: "event_callback",
|
|
309
|
+
authorizations: [authorization(null, "E_OTHER", true)],
|
|
310
|
+
}),
|
|
311
|
+
).toEqual(FOREIGN);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("org install: a flag-less delivery is its own only without a workspace or by its bot", () => {
|
|
315
|
+
// Bolt reads a missing flag as a workspace install: the named workspace's.
|
|
316
|
+
expect(classify(ORG_INSTALL, documentedCommand("T_GRANTED", "E_ORG"))).toEqual(FOREIGN);
|
|
317
|
+
expect(classify(ORG_INSTALL, blockAction({ id: "T_GRANTED" }, "E_ORG"))).toEqual(FOREIGN);
|
|
318
|
+
// No workspace named, or the button sits on the org install's own message.
|
|
319
|
+
expect(classify(ORG_INSTALL, blockAction(null, "E_ORG"))).toEqual(OWN_RESULT);
|
|
320
|
+
expect(
|
|
321
|
+
classify(ORG_INSTALL, blockAction({ id: "T_GRANTED" }, "E_ORG", undefined, "B_ORG")),
|
|
322
|
+
).toEqual(OWN_RESULT);
|
|
323
|
+
// Enterprise id carried only on team.
|
|
324
|
+
expect(
|
|
325
|
+
classify(ORG_INSTALL, blockAction({ id: "T_GRANTED", enterprise_id: "E_ORG" }, null, true)),
|
|
326
|
+
).toEqual(OWN_RESULT);
|
|
327
|
+
// The org install's own commands carry the flag, from any workspace of the org.
|
|
328
|
+
const flagged = { ...documentedCommand("T_GRANTED", "E_ORG"), is_enterprise_install: "true" };
|
|
329
|
+
expect(classify(ORG_INSTALL, flagged)).toEqual(OWN_RESULT);
|
|
330
|
+
// Another enterprise or no enterprise.
|
|
331
|
+
expect(classify(ORG_INSTALL, { ...flagged, enterprise_id: "E_OTHER" })).toEqual(FOREIGN);
|
|
332
|
+
expect(classify(ORG_INSTALL, blockAction(null, "E_OTHER"))).toEqual(FOREIGN);
|
|
333
|
+
expect(classify(ORG_INSTALL, documentedCommand("T_GRANTED", null))).toEqual(FOREIGN);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("workspace install: flag-less payloads still need its workspace (B3 holds)", () => {
|
|
337
|
+
expect(classify(OWN, documentedCommand("T_OWN", null))).toEqual(OWN_RESULT);
|
|
338
|
+
expect(classify(OWN, blockAction({ id: "T_OWN" }, null))).toEqual(OWN_RESULT);
|
|
339
|
+
expect(classify(GRID_WORKSPACE, documentedCommand("T_SIBLING", "E_ORG"))).toEqual(FOREIGN);
|
|
340
|
+
expect(classify(GRID_WORKSPACE, blockAction(null, "E_ORG"))).toEqual(FOREIGN);
|
|
341
|
+
expect(
|
|
342
|
+
classify(GRID_WORKSPACE, blockAction({ id: "T_SIBLING" }, "E_ORG", undefined, "B_WS")),
|
|
343
|
+
).toEqual(FOREIGN);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("a flag-less delivery in a workspace both installs cover has exactly one owner (B6)", () => {
|
|
347
|
+
// ORG_INSTALL is granted T_OWN, where GRID_WORKSPACE is a workspace install.
|
|
348
|
+
const swarms = [GRID_WORKSPACE, ORG_INSTALL];
|
|
349
|
+
const owners = (body: unknown) => swarms.filter((swarm) => classify(swarm, body).own);
|
|
350
|
+
// A button names the bot that posted its message.
|
|
351
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG", undefined, "B_WS"))).toEqual([
|
|
352
|
+
GRID_WORKSPACE,
|
|
353
|
+
]);
|
|
354
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG", undefined, "B_ORG"))).toEqual([
|
|
355
|
+
ORG_INSTALL,
|
|
356
|
+
]);
|
|
357
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG", undefined, "B_SOMEONE_ELSE"))).toEqual([]);
|
|
358
|
+
// A view names the bot that opened it.
|
|
359
|
+
const view = (botId: string) => ({
|
|
360
|
+
type: "view_submission",
|
|
361
|
+
team: { id: "T_OWN", enterprise_id: "E_ORG" },
|
|
362
|
+
view: { id: "V_1", callback_id: "follow_up_submit", bot_id: botId },
|
|
363
|
+
});
|
|
364
|
+
expect(owners(view("B_WS"))).toEqual([GRID_WORKSPACE]);
|
|
365
|
+
expect(owners(view("B_ORG"))).toEqual([ORG_INSTALL]);
|
|
366
|
+
// No bot named: the named workspace's install claims it, as Bolt reads it.
|
|
367
|
+
expect(owners(documentedCommand("T_OWN", "E_ORG"))).toEqual([GRID_WORKSPACE]);
|
|
368
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG"))).toEqual([GRID_WORKSPACE]);
|
|
369
|
+
// No workspace named: only the org install can own it.
|
|
370
|
+
expect(owners(blockAction(null, "E_ORG"))).toEqual([ORG_INSTALL]);
|
|
371
|
+
// A flagged command goes to the install the flag names.
|
|
372
|
+
const command = (flag: string) => ({
|
|
373
|
+
...documentedCommand("T_OWN", "E_ORG"),
|
|
374
|
+
is_enterprise_install: flag,
|
|
375
|
+
});
|
|
376
|
+
expect(owners(command("true"))).toEqual([ORG_INSTALL]);
|
|
377
|
+
expect(owners(command("false"))).toEqual([GRID_WORKSPACE]);
|
|
378
|
+
// An explicit flag still decides.
|
|
379
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG", false))).toEqual([GRID_WORKSPACE]);
|
|
380
|
+
expect(owners(blockAction({ id: "T_OWN" }, "E_ORG", true))).toEqual([ORG_INSTALL]);
|
|
381
|
+
// A message shortcut's message can be anyone's: its bot proves nothing.
|
|
382
|
+
expect(
|
|
383
|
+
readInboundInstallations({
|
|
384
|
+
type: "message_action",
|
|
385
|
+
team: { id: "T_OWN" },
|
|
386
|
+
message: { bot_id: "B_WS" },
|
|
387
|
+
}),
|
|
388
|
+
).toEqual([{ teamId: "T_OWN", enterpriseId: null, isEnterpriseInstall: null }]);
|
|
389
|
+
// Without a known bot of its own, a swarm claims no bot-named delivery.
|
|
390
|
+
const { botId: _ignored, ...noBot } = GRID_WORKSPACE;
|
|
391
|
+
expect(classify(noBot, blockAction({ id: "T_OWN" }, "E_ORG", undefined, "B_WS"))).toEqual(
|
|
392
|
+
FOREIGN,
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test("picks the installation Slack's own SDK picks (B5, B6, B7)", () => {
|
|
397
|
+
// Bolt models the flag on slash commands (`SlashCommand.is_enterprise_install?: string`)
|
|
398
|
+
// and parses "true"/"false" for them; an org install's commands carry it.
|
|
399
|
+
const commandFlag: keyof SlashCommand = "is_enterprise_install";
|
|
400
|
+
const command = (flag?: string) => ({
|
|
401
|
+
...documentedCommand("T_OWN", "E_ORG"),
|
|
402
|
+
...(flag === undefined ? {} : { [commandFlag]: flag }),
|
|
403
|
+
});
|
|
404
|
+
const view = (flag?: boolean) => ({
|
|
405
|
+
type: "view_submission",
|
|
406
|
+
team: { id: "T_OWN", enterprise_id: "E_ORG" },
|
|
407
|
+
view: { id: "V_1", callback_id: "follow_up_submit" },
|
|
408
|
+
...(flag === undefined ? {} : { is_enterprise_install: flag }),
|
|
409
|
+
});
|
|
410
|
+
const event = (orgWide: boolean) => ({
|
|
411
|
+
...eventBody("T_OWN"),
|
|
412
|
+
authorizations: [authorization("T_OWN", "E_ORG", orgWide)],
|
|
413
|
+
});
|
|
414
|
+
const payloads = [
|
|
415
|
+
command(),
|
|
416
|
+
command("true"),
|
|
417
|
+
command("false"),
|
|
418
|
+
blockAction({ id: "T_OWN" }, "E_ORG"),
|
|
419
|
+
blockAction({ id: "T_OWN" }, "E_ORG", true),
|
|
420
|
+
blockAction({ id: "T_OWN" }, "E_ORG", false),
|
|
421
|
+
view(),
|
|
422
|
+
view(true),
|
|
423
|
+
view(false),
|
|
424
|
+
event(true),
|
|
425
|
+
event(false),
|
|
426
|
+
];
|
|
427
|
+
// A swarm on each installation that could hold the delivery's workspace.
|
|
428
|
+
const swarms = [GRID_WORKSPACE, ORG_INSTALL];
|
|
429
|
+
for (const body of payloads) {
|
|
430
|
+
// Bolt routes a delivery to the org install only when this returns true;
|
|
431
|
+
// otherwise @slack/oauth looks up the named workspace's installation.
|
|
432
|
+
const slackOwner = isBodyWithTypeEnterpriseInstall(body as never)
|
|
433
|
+
? ORG_INSTALL
|
|
434
|
+
: GRID_WORKSPACE;
|
|
435
|
+
expect(swarms.filter((swarm) => classify(swarm, body).own)).toEqual([slackOwner]);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test("a view opened from a Slack Connect channel is attributed to the installing workspace", () => {
|
|
440
|
+
const view = (installedTeam: string) => ({
|
|
441
|
+
type: "view_submission",
|
|
442
|
+
team: { id: "T_PARTNER" },
|
|
443
|
+
is_enterprise_install: false,
|
|
444
|
+
view: { id: "V_1", callback_id: "follow_up_submit", app_installed_team_id: installedTeam },
|
|
445
|
+
});
|
|
446
|
+
expect(classify(OWN, view("T_OWN"))).toEqual(OWN_RESULT);
|
|
447
|
+
expect(classify(OWN, view("T_OTHER"))).toEqual(FOREIGN);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe("identity", () => {
|
|
452
|
+
// The documented auth.test response (docs.slack.dev/reference/methods/auth.test).
|
|
453
|
+
const DOCUMENTED_AUTH_TEST = {
|
|
454
|
+
ok: true,
|
|
455
|
+
url: "https://subarachnoid.slack.com/",
|
|
456
|
+
team: "Subarachnoid Workspace",
|
|
457
|
+
user: "grace",
|
|
458
|
+
team_id: "T12345678",
|
|
459
|
+
user_id: "W12345678",
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
test("a documented auth.test response gives a workspace identity", () => {
|
|
463
|
+
expect(identityFromAuthTest(DOCUMENTED_AUTH_TEST, false)).toEqual({
|
|
464
|
+
teamId: "T12345678",
|
|
465
|
+
enterpriseId: null,
|
|
466
|
+
isEnterpriseInstall: false,
|
|
467
|
+
});
|
|
468
|
+
// A bot token's auth.test also names the installation's bot.
|
|
469
|
+
expect(identityFromAuthTest({ ...DOCUMENTED_AUTH_TEST, bot_id: "B12345678" }, false)).toEqual({
|
|
470
|
+
teamId: "T12345678",
|
|
471
|
+
enterpriseId: null,
|
|
472
|
+
isEnterpriseInstall: false,
|
|
473
|
+
botId: "B12345678",
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test("org-wide mode comes from trusted install metadata, never from auth.test", () => {
|
|
478
|
+
const claimsOrgWide = { ...DOCUMENTED_AUTH_TEST, is_enterprise_install: true };
|
|
479
|
+
expect(identityFromAuthTest(claimsOrgWide, false).isEnterpriseInstall).toBe(false);
|
|
480
|
+
expect(identityFromAuthTest({ ...DOCUMENTED_AUTH_TEST, enterprise_id: "E_ORG" }, true)).toEqual(
|
|
481
|
+
{ teamId: null, enterpriseId: "E_ORG", isEnterpriseInstall: true },
|
|
482
|
+
);
|
|
483
|
+
expect(isSlackEnterpriseInstall({})).toBe(false);
|
|
484
|
+
expect(isSlackEnterpriseInstall({ SLACK_ENTERPRISE_INSTALL: "true" })).toBe(true);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("auth.test without the id the install mode needs is a failed lookup", () => {
|
|
488
|
+
expect(() => identityFromAuthTest(DOCUMENTED_AUTH_TEST, true)).toThrow(/enterprise_id/);
|
|
489
|
+
expect(() => identityFromAuthTest({ enterprise_id: "E_ORG" }, false)).toThrow(/team_id/);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
test("resolved once and cached", async () => {
|
|
493
|
+
let calls = 0;
|
|
494
|
+
setSlackWorkspaceIdentitySource(async () => {
|
|
495
|
+
calls += 1;
|
|
496
|
+
return OWN;
|
|
497
|
+
});
|
|
498
|
+
await Promise.all([getSlackWorkspaceIdentity(), getSlackWorkspaceIdentity()]);
|
|
499
|
+
expect(await getSlackWorkspaceIdentity()).toEqual(OWN);
|
|
500
|
+
expect(getCachedSlackWorkspaceIdentity()).toEqual(OWN);
|
|
501
|
+
expect(calls).toBe(1);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("resolveSlackIdentity reads auth.test only, in either install mode", async () => {
|
|
505
|
+
let calls = 0;
|
|
506
|
+
const client = {
|
|
507
|
+
auth: {
|
|
508
|
+
test: async () => {
|
|
509
|
+
calls += 1;
|
|
510
|
+
return { team_id: "T_ANY", enterprise_id: "E_ORG", bot_id: "B_1" };
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
expect(await resolveSlackIdentity(client, true)).toEqual({
|
|
515
|
+
teamId: null,
|
|
516
|
+
enterpriseId: "E_ORG",
|
|
517
|
+
isEnterpriseInstall: true,
|
|
518
|
+
botId: "B_1",
|
|
519
|
+
});
|
|
520
|
+
expect(await resolveSlackIdentity(client, false)).toEqual({
|
|
521
|
+
teamId: "T_ANY",
|
|
522
|
+
enterpriseId: "E_ORG",
|
|
523
|
+
isEnterpriseInstall: false,
|
|
524
|
+
botId: "B_1",
|
|
525
|
+
});
|
|
526
|
+
expect(calls).toBe(2);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test("a failed lookup caches nothing and the next call retries", async () => {
|
|
530
|
+
let calls = 0;
|
|
531
|
+
setSlackWorkspaceIdentitySource(async () => {
|
|
532
|
+
calls += 1;
|
|
533
|
+
if (calls === 1) throw new Error("fatal_error");
|
|
534
|
+
return OWN;
|
|
535
|
+
});
|
|
536
|
+
expect(await getSlackWorkspaceIdentity()).toBeNull();
|
|
537
|
+
expect(getCachedSlackWorkspaceIdentity()).toBeNull();
|
|
538
|
+
expect(await getSlackWorkspaceIdentity()).toEqual(OWN);
|
|
539
|
+
expect(calls).toBe(2);
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
type SocketClient = SocketModeReceiver["client"];
|
|
544
|
+
|
|
545
|
+
/** A Bolt app wired like app.ts: ack recovery, then the gate, then the middleware. */
|
|
546
|
+
function buildSwarm(getIdentity: () => SlackWorkspaceIdentity | null) {
|
|
547
|
+
const receiver = new SocketModeReceiver({ appToken: "xapp-test", logLevel: LogLevel.ERROR });
|
|
548
|
+
const app = new App({
|
|
549
|
+
receiver,
|
|
550
|
+
socketMode: true,
|
|
551
|
+
logLevel: LogLevel.ERROR,
|
|
552
|
+
authorize: async () => ({ botToken: "xoxb-test", botId: "B_TEST", botUserId: "U_BOT" }),
|
|
553
|
+
});
|
|
554
|
+
const drain = installSocketAckRecovery(receiver.client, app);
|
|
555
|
+
installSocketWorkspaceGate(receiver.client, getIdentity);
|
|
556
|
+
const created: string[] = [];
|
|
557
|
+
app.use(slackInboundOutcomeMiddleware());
|
|
558
|
+
// Stands in for the mention handler's task creation.
|
|
559
|
+
app.event("app_mention", async ({ body }) => {
|
|
560
|
+
created.push(body.event_id);
|
|
561
|
+
});
|
|
562
|
+
app.command("/swarm", async ({ ack, body }) => {
|
|
563
|
+
await ack();
|
|
564
|
+
created.push(`command:${body.team_id}`);
|
|
565
|
+
});
|
|
566
|
+
app.action("follow_up_task", async ({ ack, body }) => {
|
|
567
|
+
await ack();
|
|
568
|
+
created.push(`action:${body.team?.id ?? "org"}`);
|
|
569
|
+
});
|
|
570
|
+
return { app, client: receiver.client, created, drain };
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** Emit an envelope the way SocketModeClient does; resolve with whether it was acked. */
|
|
574
|
+
async function emitEnvelope(
|
|
575
|
+
client: SocketClient,
|
|
576
|
+
type: "events_api" | "slash_commands" | "interactive",
|
|
577
|
+
body: Record<string, unknown>,
|
|
578
|
+
): Promise<boolean> {
|
|
579
|
+
let acked = false;
|
|
580
|
+
client.emit("slack_event", {
|
|
581
|
+
ack: async () => {
|
|
582
|
+
acked = true;
|
|
583
|
+
},
|
|
584
|
+
envelope_id: `env-${Math.random().toString(36).slice(2)}`,
|
|
585
|
+
type,
|
|
586
|
+
body,
|
|
587
|
+
});
|
|
588
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
589
|
+
return acked;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
describe("socket gate: before Bolt acks", () => {
|
|
593
|
+
test("a foreign delivery is neither acked nor dispatched", async () => {
|
|
594
|
+
await resolveIdentityFor(OWN);
|
|
595
|
+
const swarm = buildSwarm(() => OWN);
|
|
596
|
+
try {
|
|
597
|
+
expect(await emitEnvelope(swarm.client, "events_api", eventBody("T_OTHER"))).toBe(false);
|
|
598
|
+
expect(
|
|
599
|
+
await emitEnvelope(swarm.client, "slash_commands", { command: "/swarm", team_id: "T_X" }),
|
|
600
|
+
).toBe(false);
|
|
601
|
+
expect(swarm.created).toEqual([]);
|
|
602
|
+
|
|
603
|
+
const own = eventBody("T_OWN");
|
|
604
|
+
expect(await emitEnvelope(swarm.client, "events_api", own)).toBe(true);
|
|
605
|
+
expect(swarm.created).toEqual([own.event_id]);
|
|
606
|
+
} finally {
|
|
607
|
+
swarm.drain.stop();
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
test("fails closed until the identity resolves, and the redelivery then passes", async () => {
|
|
612
|
+
// As in app.ts: the gate reads the process-wide identity.
|
|
613
|
+
const swarm = buildSwarm(getCachedSlackWorkspaceIdentity);
|
|
614
|
+
try {
|
|
615
|
+
const body = eventBody("T_OWN");
|
|
616
|
+
expect(await emitEnvelope(swarm.client, "events_api", body)).toBe(false);
|
|
617
|
+
expect(swarm.created).toEqual([]);
|
|
618
|
+
await resolveIdentityFor(OWN);
|
|
619
|
+
expect(await emitEnvelope(swarm.client, "events_api", body)).toBe(true);
|
|
620
|
+
expect(swarm.created).toEqual([body.event_id]);
|
|
621
|
+
} finally {
|
|
622
|
+
swarm.drain.stop();
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
test("an envelope with no installation field is withheld", async () => {
|
|
627
|
+
const swarm = buildSwarm(() => OWN);
|
|
628
|
+
try {
|
|
629
|
+
const body = eventBody("T_OWN");
|
|
630
|
+
delete (body as Record<string, unknown>).authorizations;
|
|
631
|
+
expect(await emitEnvelope(swarm.client, "events_api", body)).toBe(false);
|
|
632
|
+
expect(swarm.created).toEqual([]);
|
|
633
|
+
} finally {
|
|
634
|
+
swarm.drain.stop();
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
describe("socket gate: org install buttons and slash commands", () => {
|
|
640
|
+
test("its command and buttons are handled from any workspace, with no lookup per workspace", async () => {
|
|
641
|
+
let lookups = 0;
|
|
642
|
+
setSlackWorkspaceIdentitySource(async () => {
|
|
643
|
+
lookups += 1;
|
|
644
|
+
return ORG_INSTALL;
|
|
645
|
+
});
|
|
646
|
+
await getSlackWorkspaceIdentity();
|
|
647
|
+
const swarm = buildSwarm(getCachedSlackWorkspaceIdentity);
|
|
648
|
+
try {
|
|
649
|
+
// The first interaction from a workspace the swarm has never seen.
|
|
650
|
+
const command = { ...documentedCommand("T_NEW", "E_ORG"), is_enterprise_install: "true" };
|
|
651
|
+
expect(await emitEnvelope(swarm.client, "slash_commands", command)).toBe(true);
|
|
652
|
+
const button = blockAction({ id: "T_NEWER" }, "E_ORG", undefined, "B_ORG");
|
|
653
|
+
expect(await emitEnvelope(swarm.client, "interactive", button)).toBe(true);
|
|
654
|
+
const orgSurface = blockAction(null, "E_ORG");
|
|
655
|
+
expect(await emitEnvelope(swarm.client, "interactive", orgSurface)).toBe(true);
|
|
656
|
+
expect(swarm.created).toEqual(["command:T_NEW", "action:T_NEWER", "action:org"]);
|
|
657
|
+
expect(lookups).toBe(1);
|
|
658
|
+
} finally {
|
|
659
|
+
swarm.drain.stop();
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
test("another installation's flag-less command and button are withheld", async () => {
|
|
664
|
+
await resolveIdentityFor(ORG_INSTALL);
|
|
665
|
+
const swarm = buildSwarm(getCachedSlackWorkspaceIdentity);
|
|
666
|
+
try {
|
|
667
|
+
for (const [type, body] of [
|
|
668
|
+
["slash_commands", documentedCommand("T_GRANTED", "E_OTHER")],
|
|
669
|
+
["slash_commands", documentedCommand("T_GRANTED", null)],
|
|
670
|
+
["interactive", blockAction({ id: "T_GRANTED" }, "E_OTHER")],
|
|
671
|
+
["interactive", blockAction({ id: "T_GRANTED" }, "E_ORG", false)],
|
|
672
|
+
// Flag-less and naming a workspace: that workspace's install's.
|
|
673
|
+
["slash_commands", documentedCommand("T_GRANTED", "E_ORG")],
|
|
674
|
+
] as const) {
|
|
675
|
+
expect(await emitEnvelope(swarm.client, type, body)).toBe(false);
|
|
676
|
+
}
|
|
677
|
+
expect(swarm.created).toEqual([]);
|
|
678
|
+
} finally {
|
|
679
|
+
swarm.drain.stop();
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
test("a workspace install keeps rejecting a sibling's flag-less command (B3)", async () => {
|
|
684
|
+
await resolveIdentityFor(GRID_WORKSPACE);
|
|
685
|
+
const swarm = buildSwarm(getCachedSlackWorkspaceIdentity);
|
|
686
|
+
try {
|
|
687
|
+
expect(
|
|
688
|
+
await emitEnvelope(swarm.client, "slash_commands", documentedCommand("T_SIBLING", "E_ORG")),
|
|
689
|
+
).toBe(false);
|
|
690
|
+
expect(await emitEnvelope(swarm.client, "interactive", blockAction(null, "E_ORG"))).toBe(
|
|
691
|
+
false,
|
|
692
|
+
);
|
|
693
|
+
const ownCommand = { ...documentedCommand("T_OWN", "E_ORG"), is_enterprise_install: "false" };
|
|
694
|
+
expect(await emitEnvelope(swarm.client, "slash_commands", ownCommand)).toBe(true);
|
|
695
|
+
expect(swarm.created).toEqual(["command:T_OWN"]);
|
|
696
|
+
} finally {
|
|
697
|
+
swarm.drain.stop();
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test("two swarms covering one workspace: each flag-less delivery reaches exactly one (B6)", async () => {
|
|
702
|
+
for (const [identity, other] of [
|
|
703
|
+
[GRID_WORKSPACE, ORG_INSTALL],
|
|
704
|
+
[ORG_INSTALL, GRID_WORKSPACE],
|
|
705
|
+
] as const) {
|
|
706
|
+
await resolveIdentityFor(identity);
|
|
707
|
+
const swarm = buildSwarm(getCachedSlackWorkspaceIdentity);
|
|
708
|
+
try {
|
|
709
|
+
const foreign = blockAction({ id: "T_OWN" }, "E_ORG", undefined, other.botId);
|
|
710
|
+
expect(await emitEnvelope(swarm.client, "interactive", foreign)).toBe(false);
|
|
711
|
+
const own = blockAction({ id: "T_OWN" }, "E_ORG", undefined, identity.botId);
|
|
712
|
+
expect(await emitEnvelope(swarm.client, "interactive", own)).toBe(true);
|
|
713
|
+
// A workspace-owned command: the workspace swarm handles it, the org swarm withholds it.
|
|
714
|
+
const workspaceSwarm = identity === GRID_WORKSPACE;
|
|
715
|
+
const command = documentedCommand("T_OWN", "E_ORG");
|
|
716
|
+
expect(await emitEnvelope(swarm.client, "slash_commands", command)).toBe(workspaceSwarm);
|
|
717
|
+
expect(swarm.created).toEqual(
|
|
718
|
+
workspaceSwarm ? ["action:T_OWN", "command:T_OWN"] : ["action:T_OWN"],
|
|
719
|
+
);
|
|
720
|
+
} finally {
|
|
721
|
+
swarm.drain.stop();
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
describe("middleware: deliveries that reach Bolt another way", () => {
|
|
728
|
+
test("a receipt replayed before the identity resolved fails retryably", async () => {
|
|
729
|
+
const swarm = buildSwarm(() => null);
|
|
730
|
+
try {
|
|
731
|
+
const outcome = await runAdmittedSlackDelivery(
|
|
732
|
+
"socket",
|
|
733
|
+
() => swarm.app.processEvent({ body: eventBody("T_OWN"), ack: async () => {} }),
|
|
734
|
+
{ requireBoltDispatch: true },
|
|
735
|
+
);
|
|
736
|
+
expect(outcome).toEqual({ state: "failed", code: "workspace_identity_unavailable" });
|
|
737
|
+
expect(swarm.created).toEqual([]);
|
|
738
|
+
} finally {
|
|
739
|
+
swarm.drain.stop();
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
test("a replayed receipt from another workspace resolves to ignored", async () => {
|
|
744
|
+
await resolveIdentityFor(OWN);
|
|
745
|
+
const swarm = buildSwarm(() => OWN);
|
|
746
|
+
try {
|
|
747
|
+
const outcome = await runAdmittedSlackDelivery(
|
|
748
|
+
"socket",
|
|
749
|
+
() => swarm.app.processEvent({ body: eventBody("T_OTHER"), ack: async () => {} }),
|
|
750
|
+
{ requireBoltDispatch: true },
|
|
751
|
+
);
|
|
752
|
+
expect(outcome).toEqual({ state: "ignored", code: "foreign_workspace" });
|
|
753
|
+
expect(swarm.created).toEqual([]);
|
|
754
|
+
} finally {
|
|
755
|
+
swarm.drain.stop();
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
test("an own live delivery passes; an unattributable one is ignored", async () => {
|
|
760
|
+
await resolveIdentityFor(OWN);
|
|
761
|
+
const swarm = buildSwarm(() => OWN);
|
|
762
|
+
try {
|
|
763
|
+
const own = eventBody("T_OWN");
|
|
764
|
+
await swarm.app.processEvent({ body: own, ack: async () => {} });
|
|
765
|
+
await swarm.app.processEvent({
|
|
766
|
+
body: { ...eventBody("T_OWN"), authorizations: [] },
|
|
767
|
+
ack: async () => {},
|
|
768
|
+
});
|
|
769
|
+
expect(swarm.created).toEqual([own.event_id]);
|
|
770
|
+
const { outcomes } = await getSlackInboundDiagnostics();
|
|
771
|
+
expect(outcomes.socket.processed).toBe(1);
|
|
772
|
+
expect(outcomes.socket.ignored).toBe(1);
|
|
773
|
+
} finally {
|
|
774
|
+
swarm.drain.stop();
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
describe("over a shared Slack app (slack-mock)", () => {
|
|
780
|
+
const SLACK_ENV_KEYS = [
|
|
781
|
+
"NODE_ENV",
|
|
782
|
+
"SLACK_MODE",
|
|
783
|
+
"SLACK_DISABLE",
|
|
784
|
+
"SLACK_BOT_TOKEN",
|
|
785
|
+
"SLACK_APP_TOKEN",
|
|
786
|
+
"SLACK_API_URL",
|
|
787
|
+
"SLACK_ENTERPRISE_INSTALL",
|
|
788
|
+
"SLACK_RENDER_V2",
|
|
789
|
+
] as const;
|
|
790
|
+
const savedEnv = new Map(SLACK_ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
791
|
+
let slack: SlackHarness;
|
|
792
|
+
|
|
793
|
+
beforeEach(async () => {
|
|
794
|
+
slack = await startSlackMock(false);
|
|
795
|
+
for (const key of SLACK_ENV_KEYS) delete process.env[key];
|
|
796
|
+
Object.assign(process.env, slack.mock.env, {
|
|
797
|
+
NODE_ENV: "test",
|
|
798
|
+
SLACK_DISABLE: "false",
|
|
799
|
+
SLACK_RENDER_V2: "false",
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
afterEach(async () => {
|
|
804
|
+
await stopSlackApp();
|
|
805
|
+
setSlackStartRetryDelaysForTests(null);
|
|
806
|
+
await stopSlackMock(slack, false);
|
|
807
|
+
for (const key of SLACK_ENV_KEYS) {
|
|
808
|
+
const value = savedEnv.get(key);
|
|
809
|
+
if (value === undefined) delete process.env[key];
|
|
810
|
+
else process.env[key] = value;
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
test("startup with a failed auth.test opens no socket, then retries and connects", async () => {
|
|
815
|
+
setSlackStartRetryDelaysForTests([150]);
|
|
816
|
+
// Bolt's own auth.test at construction and the guard's lookup both fail.
|
|
817
|
+
slack.mock.injectFault({ method: "auth.test", error: "fatal_error", times: 2 });
|
|
818
|
+
|
|
819
|
+
expect(await startSlackApp()).toBe(false);
|
|
820
|
+
expect(slack.mock.apiCalls("apps.connections.open")).toHaveLength(0);
|
|
821
|
+
expect(getSlackConnectionState()).toBe("disconnected");
|
|
822
|
+
expect(getCachedSlackWorkspaceIdentity()).toBeNull();
|
|
823
|
+
|
|
824
|
+
// The retry rebuilds the app, resolves the identity, then opens the socket.
|
|
825
|
+
await slack.mock.waitForConnection(10_000);
|
|
826
|
+
expect(slack.mock.apiCalls("apps.connections.open")).toHaveLength(1);
|
|
827
|
+
expect(getCachedSlackWorkspaceIdentity()?.teamId).toBe(slack.mock.team.id);
|
|
828
|
+
}, 20_000);
|
|
829
|
+
|
|
830
|
+
test("stopSlackApp cancels a pending start retry", async () => {
|
|
831
|
+
setSlackStartRetryDelaysForTests([150]);
|
|
832
|
+
slack.mock.injectFault({ method: "auth.test", error: "fatal_error", times: 2 });
|
|
833
|
+
expect(await startSlackApp()).toBe(false);
|
|
834
|
+
await stopSlackApp();
|
|
835
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
836
|
+
expect(slack.mock.apiCalls("apps.connections.open")).toHaveLength(0);
|
|
837
|
+
}, 20_000);
|
|
838
|
+
|
|
839
|
+
test("two swarms on one app: a withheld mention is redelivered, never handled by the other", async () => {
|
|
840
|
+
await slack.mock.stop();
|
|
841
|
+
// Short ack timeout so a withheld envelope is redelivered quickly.
|
|
842
|
+
slack = {
|
|
843
|
+
mock: await SlackMock.start({
|
|
844
|
+
port: 0,
|
|
845
|
+
manifest: `${repoRoot}/slack-manifest.json`,
|
|
846
|
+
ackTimeoutMs: 200,
|
|
847
|
+
maxRetries: 3,
|
|
848
|
+
}),
|
|
849
|
+
};
|
|
850
|
+
const env = slack.mock.env;
|
|
851
|
+
const owner = { teamId: slack.mock.team.id, enterpriseId: null, isEnterpriseInstall: false };
|
|
852
|
+
const other = { teamId: "T_OTHER_SWARM", enterpriseId: null, isEnterpriseInstall: false };
|
|
853
|
+
// The middleware reads the process-wide identity; each swarm's gate gets its own.
|
|
854
|
+
await resolveIdentityFor(owner);
|
|
855
|
+
|
|
856
|
+
const swarms = [owner, other].map((identity) => {
|
|
857
|
+
const receiver = new SocketModeReceiver({
|
|
858
|
+
appToken: env.SLACK_APP_TOKEN!,
|
|
859
|
+
logLevel: LogLevel.ERROR,
|
|
860
|
+
installerOptions: { clientOptions: { slackApiUrl: env.SLACK_API_URL } },
|
|
861
|
+
});
|
|
862
|
+
const app = new App({
|
|
863
|
+
token: env.SLACK_BOT_TOKEN,
|
|
864
|
+
receiver,
|
|
865
|
+
socketMode: true,
|
|
866
|
+
logLevel: LogLevel.ERROR,
|
|
867
|
+
clientOptions: { slackApiUrl: env.SLACK_API_URL },
|
|
868
|
+
});
|
|
869
|
+
installSocketWorkspaceGate(receiver.client, () => identity);
|
|
870
|
+
const seen: string[] = [];
|
|
871
|
+
app.use(slackInboundOutcomeMiddleware());
|
|
872
|
+
app.message(async ({ message }) => {
|
|
873
|
+
seen.push((message as { ts: string }).ts);
|
|
874
|
+
});
|
|
875
|
+
return { app, seen };
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
try {
|
|
879
|
+
for (const swarm of swarms) await swarm.app.start();
|
|
880
|
+
for (let i = 0; i < 20 && slack.mock.connectionCount < 2; i += 1) {
|
|
881
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
882
|
+
}
|
|
883
|
+
expect(slack.mock.connectionCount).toBe(2);
|
|
884
|
+
|
|
885
|
+
const posted: string[] = [];
|
|
886
|
+
for (let i = 0; i < 4; i += 1) {
|
|
887
|
+
const message = await slack.mock.postMessage({ channel: "general", text: `ask ${i}` });
|
|
888
|
+
posted.push(message.ts);
|
|
889
|
+
}
|
|
890
|
+
const settled = Date.now() + 8_000;
|
|
891
|
+
while (swarms[0]!.seen.length < posted.length && Date.now() < settled) {
|
|
892
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
expect([...swarms[0]!.seen].sort()).toEqual([...posted].sort());
|
|
896
|
+
expect(swarms[1]!.seen).toEqual([]);
|
|
897
|
+
const deliveries = slack.mock.deliveries().filter((d) => d.type === "events_api");
|
|
898
|
+
expect(deliveries.every((d) => d.acked)).toBe(true);
|
|
899
|
+
// Some first attempts landed on the other swarm and were redelivered, not lost.
|
|
900
|
+
expect(deliveries.some((d) => d.attempts > 1)).toBe(true);
|
|
901
|
+
} finally {
|
|
902
|
+
for (const swarm of swarms) await swarm.app.stop();
|
|
903
|
+
}
|
|
904
|
+
}, 30_000);
|
|
905
|
+
});
|