@desplega.ai/agent-swarm 2.7.9 → 2.7.10
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-dn4gdsgr.js → acp-adapter-srfhs1s9.js} +5 -5
- package/dist/{actions-g563mbn2.js → actions-b8aqhrsg.js} +19 -18
- package/dist/{amp-adapter-q61w05eb.js → amp-adapter-4c165vgn.js} +1 -1
- package/dist/app-m9khefrh.js +20 -0
- package/dist/{assistant-p477rjwj.js → assistant-rh4v3ntz.js} +21 -20
- package/dist/{boot-args-schema-h4qj462e.js → boot-args-schema-hwkc8bzv.js} +1 -1
- package/dist/{boot-reembed-n1ehfbsw.js → boot-reembed-5y6yw9sj.js} +1 -1
- package/dist/{boot-reembed-qw4mc0pt.js → boot-reembed-fdyk55h4.js} +1 -1
- package/dist/{boot-scrub-sweep-9w9jp4sm.js → boot-scrub-sweep-r5r8kqsn.js} +3 -3
- package/dist/{boot-seeds-qdaf3sdy.js → boot-seeds-8f9zt5cm.js} +5 -5
- package/dist/{claude-adapter-348p5hx9.js → claude-adapter-s5df247c.js} +5 -5
- package/dist/{claude-managed-setup-7787fxtp.js → claude-managed-setup-9gsmwzyx.js} +1 -1
- package/dist/{claude-sdk-session-hbszbt8a.js → claude-sdk-session-dq1j4nz9.js} +5 -5
- package/dist/{cli-btf6fw39.js → cli-0m7rtm11.js} +1 -1
- package/dist/{cli-cseh6f8w.js → cli-16phend6.js} +1 -1
- package/dist/{cli-ms5m5r1y.js → cli-18qt3few.js} +1 -1
- package/dist/{cli-sgs5k6yd.js → cli-2tsfpc70.js} +1 -1
- package/dist/{cli-rwymrnaz.js → cli-36wdfzgn.js} +8 -8
- package/dist/{cli-qzt90yze.js → cli-38yww4e9.js} +8 -8
- package/dist/{cli-2a8py3sx.js → cli-3xddv0rk.js} +4 -4
- package/dist/{cli-p0m0p34z.js → cli-4vwxp550.js} +2 -2
- package/dist/{cli-bc779n4v.js → cli-55bkx8hh.js} +1 -1
- package/dist/{cli-21159vea.js → cli-5wfz00be.js} +2 -2
- package/dist/{cli-9aezs55w.js → cli-5xcb8gxq.js} +4 -4
- package/dist/{cli-12xyjhws.js → cli-6m6b4bep.js} +2 -2
- package/dist/{cli-fayav105.js → cli-7wz05bx3.js} +292 -83
- package/dist/{cli-y8nbefpb.js → cli-8ewkreqd.js} +9 -5
- package/dist/{cli-0whpms1z.js → cli-an1knn2k.js} +4 -4
- package/dist/{cli-qmd3mse0.js → cli-bxz823sz.js} +1 -1
- package/dist/{cli-a0657jmf.js → cli-bzvs88tv.js} +1 -1
- package/dist/{cli-agyaeef4.js → cli-cr14kftt.js} +2 -2
- package/dist/{cli-715t1gx6.js → cli-eb2azq8n.js} +3 -3
- package/dist/{cli-530hkwdy.js → cli-ed6yqpf1.js} +2 -2
- package/dist/{cli-k70e3x9e.js → cli-eqk5p56g.js} +3 -3
- package/dist/{cli-4t0fmf3z.js → cli-g1px1g2e.js} +1 -1
- package/dist/{cli-09kmfkmq.js → cli-h49ejvmc.js} +1 -1
- package/dist/{cli-cvs2r2vq.js → cli-hfkwwy1h.js} +39 -5
- package/dist/{cli-neyag5p6.js → cli-j7d73g1y.js} +371 -116
- package/dist/{cli-p17970qv.js → cli-jg24scat.js} +2 -2
- package/dist/{cli-varqt4d1.js → cli-kx4c8j05.js} +16 -13
- package/dist/{cli-jfx48xrj.js → cli-mp9aa8g5.js} +1 -1
- package/dist/{cli-605nn699.js → cli-mr97t7cc.js} +644 -225
- package/dist/{cli-v3cf1ts9.js → cli-n07eecjs.js} +3 -3
- package/dist/{cli-y5rbvxhc.js → cli-n515ex5z.js} +14 -14
- package/dist/{cli-3tqcamp6.js → cli-n9abj89w.js} +13 -12
- package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
- package/dist/{cli-xk879m3k.js → cli-nj3x45rw.js} +27 -27
- package/dist/{cli-9r5gtwjr.js → cli-pyrxt9gw.js} +196 -1
- package/dist/{cli-mnrkgg60.js → cli-q581b386.js} +2 -2
- package/dist/{cli-hwprv9e4.js → cli-rjyghzg4.js} +2 -2
- package/dist/{cli-650zv9q9.js → cli-rt0ag4x1.js} +3 -3
- package/dist/{cli-vxh6acp7.js → cli-td33w98c.js} +2 -2
- package/dist/{cli-tqq0hspb.js → cli-tmft5dz2.js} +1 -1
- package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
- package/dist/{cli-qkdmz8c8.js → cli-ttbqe3q4.js} +1 -1
- package/dist/{cli-zgv8gxgs.js → cli-v2fwbnsk.js} +6 -6
- package/dist/{cli-b932gexn.js → cli-w3bk0dgv.js} +1 -1
- package/dist/{cli-serm8zrx.js → cli-x9exydey.js} +1 -1
- package/dist/{cli-hae9j8sv.js → cli-xbtq4d6s.js} +3 -3
- package/dist/{cli-587857ys.js → cli-xd5ebp64.js} +3 -3
- package/dist/{cli-ejkvvqbe.js → cli-xncjscpm.js} +10 -10
- package/dist/{cli-gce09r66.js → cli-xvymtmv4.js} +2 -2
- package/dist/{cli-btc9cb4c.js → cli-yz7v0sh4.js} +2 -2
- package/dist/{cli-sya22y84.js → cli-z9cs5m0w.js} +3 -3
- package/dist/{cli-2ccpqyyf.js → cli-zjphdj1a.js} +71 -10
- package/dist/cli.js +15 -15
- package/dist/{codex-adapter-ysq6bzha.js → codex-adapter-yr60sme6.js} +3 -3
- package/dist/{codex-session-runner-qakzfx93.js → codex-session-runner-pch8x584.js} +3 -3
- package/dist/{commands-rs7hkv9r.js → commands-phjfbkv0.js} +3 -3
- package/dist/{controller-r5x9bg6e.js → controller-jkx994pz.js} +2 -2
- package/dist/{controllers-connect-498hrxvk.js → controllers-connect-c4448kwa.js} +20 -19
- package/dist/{cursor-adapter-d46qszer.js → cursor-adapter-ndebqnm8.js} +1 -1
- package/dist/{db-pm96nhdb.js → db-ef32tbfc.js} +4 -2
- package/dist/{db-s13dqhr6.js → db-ez6egt6v.js} +3 -3
- package/dist/{dispatcher-j3h81t7m.js → dispatcher-g3tt9hs9.js} +18 -17
- package/dist/{dsh-adapter-rw0d5rc4.js → dsh-adapter-tcyn3099.js} +1 -1
- package/dist/{easter-egg-3d-qtgfxgze.js → easter-egg-3d-e36hk5td.js} +1 -1
- package/dist/{embedding-space-xh8p4q4x.js → embedding-space-4kyh5qqj.js} +6 -6
- package/dist/{embeddings-wp745m91.js → embeddings-6a8v4a6t.js} +1 -1
- package/dist/{execute-2fzb9z74.js → execute-3cbg0twf.js} +1 -1
- package/dist/{external-channel-ys21h3sy.js → external-channel-se646snz.js} +2 -2
- package/dist/{fx-adapter-vz0b9z3g.js → fx-adapter-yw795hqq.js} +6 -6
- package/dist/{google-generative-ai-ytpgncx9.js → google-generative-ai-h7s3e9kk.js} +1 -1
- package/dist/{google-vertex-tqhze5j7.js → google-vertex-fhxaafzw.js} +1 -1
- package/dist/{grok-adapter-spea7zkj.js → grok-adapter-ttmcss2j.js} +6 -6
- package/dist/handlers-17wha3ze.js +33 -0
- package/dist/{heartbeat-8phn1kdq.js → heartbeat-gwewgdms.js} +21 -20
- package/dist/{hook-amcj4s10.js → hook-g3nhexsy.js} +5 -5
- package/dist/{hook-bc6n49qn.js → hook-hq93y5ej.js} +4 -4
- package/dist/{http-7374brv5.js → http-5a9p4h6y.js} +210 -69
- package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
- package/dist/{index-5a9jtqde.js → index-0rvk3vd4.js} +46 -46
- package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
- package/dist/{index-p4hjwbvw.js → index-3c5pxbge.js} +1 -1
- package/dist/{index-q5cmtbz5.js → index-6haqt3v5.js} +12296 -11042
- package/dist/index-8arwq8mw.js +34 -0
- package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
- package/dist/{index-c9y31ytf.js → index-hgn3c961.js} +12 -11
- package/dist/{index-hsad2t3r.js → index-m5gx1xd6.js} +38 -38
- package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
- package/dist/{index-w4m9z29z.js → index-s72rqgsx.js} +1 -1
- package/dist/index-tpw054az.js +38 -0
- package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
- package/dist/index-waq75j2j.js +31 -0
- package/dist/{keepalive-wy29kbrg.js → keepalive-1j4n4dmk.js} +3 -3
- package/dist/lead-re73kdgc.js +72 -0
- package/dist/{maintenance-h2ds9w6c.js → maintenance-dmghacy5.js} +1 -1
- package/dist/{oauth-refresh-sweep-q7mtbyp3.js → oauth-refresh-sweep-yy06c03c.js} +2 -2
- package/dist/{onboard-vw8r2fdw.js → onboard-52f9t5dm.js} +3 -3
- package/dist/{opencode-adapter-mtb0953j.js → opencode-adapter-krnh9jkn.js} +4 -4
- package/dist/{otel-impl-j42czw3r.js → otel-impl-xjqz6wjj.js} +1 -1
- package/dist/{pi-mono-adapter-zk8pg9jr.js → pi-mono-adapter-dbxyp0qv.js} +6 -6
- package/dist/{pricing-refresh-x7nhv23d.js → pricing-refresh-ctdr74pd.js} +3 -3
- package/dist/{rbac-roles-bzvee6cf.js → rbac-roles-ehv8s10n.js} +3 -3
- package/dist/{rbac-roles-9044425x.js → rbac-roles-q0gr8eyj.js} +2 -2
- package/dist/{render-v2-t7bn4skz.js → render-v2-5b6chvcq.js} +9 -4
- package/dist/{resume-x94gemep.js → resume-5a5d2845.js} +6 -6
- package/dist/{runtime-breq6fmv.js → runtime-khxszyfp.js} +1 -1
- package/dist/{session-access-q7dmqjvt.js → session-access-gj0bjhqg.js} +4 -4
- package/dist/{session-source-backfill-440ysamr.js → session-source-backfill-2sy0krfk.js} +2 -2
- package/dist/{setup-07n4727s.js → setup-7ssfakk1.js} +1 -1
- package/dist/{virtual-modules-z5h6mcyf.js → virtual-modules-pjj0knwf.js} +3 -3
- package/dist/{work-objects-pnq5y534.js → work-objects-bf3syvhq.js} +22 -21
- package/dist/{worker-follow-up-7z1gfkr8.js → worker-follow-up-38xevga6.js} +18 -17
- package/dist/worker-r8mz7a65.js +72 -0
- package/openapi.json +1 -1
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +55 -0
- package/src/apps/page-validator.ts +19 -0
- package/src/assets/key.ts +77 -4
- package/src/be/db/session-labels.ts +57 -0
- package/src/be/db/session-tree.ts +51 -7
- package/src/be/db/slack-trees.ts +146 -0
- package/src/be/db/tasks/read.ts +102 -7
- package/src/be/db-client.ts +8 -2
- package/src/be/db.ts +95 -84
- package/src/be/event-loop-lag.ts +146 -0
- package/src/be/mcp-overflow-sweep.ts +2 -1
- package/src/be/memory/providers/sqlite-store.ts +39 -8
- package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
- package/src/be/swarm-config-guard.ts +2 -0
- package/src/commands/context-preamble.ts +258 -0
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/extensions/catalog.generated.json +3 -3
- package/src/heartbeat/heartbeat.ts +5 -4
- package/src/http/core.ts +9 -3
- package/src/http/index.ts +10 -6
- package/src/http/memory.ts +9 -4
- package/src/http/sessions.ts +16 -3
- package/src/http/utils.ts +18 -0
- package/src/http/webhooks.ts +48 -0
- package/src/integrations/chat-sdk/commands.ts +167 -31
- package/src/integrations/chat-sdk/inbound.ts +10 -8
- package/src/integrations/chat-sdk/message-text.ts +117 -0
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/scheduler/scheduler.ts +4 -1
- package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
- package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
- package/src/scripts-runtime/quickjs-compat.ts +0 -1
- package/src/slack/app.ts +332 -10
- package/src/slack/handlers.ts +9 -2
- package/src/slack/index.ts +7 -1
- package/src/slack/lifecycle-lock.ts +29 -0
- package/src/slack/render-v2.ts +424 -212
- package/src/slack/socket-fence.ts +64 -0
- package/src/slack/watcher.ts +42 -8
- package/src/tests/apps-schema-form.test.ts +151 -0
- package/src/tests/chat-sdk-commands.test.ts +359 -2
- package/src/tests/chat-sdk-inbound.test.ts +20 -0
- package/src/tests/chat-sdk-slack.test.ts +189 -1
- package/src/tests/db-client-busy-retry.test.ts +69 -18
- package/src/tests/db-client.test.ts +26 -1
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/event-loop-lag.test.ts +184 -0
- package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
- package/src/tests/github-webhook-early-ack.test.ts +144 -0
- package/src/tests/http-api-integration.test.ts +2 -0
- package/src/tests/http-log-scrubbing.test.ts +68 -2
- package/src/tests/kv-storage.test.ts +92 -1
- package/src/tests/memory-key-paths.test.ts +57 -0
- package/src/tests/memory-retrieval-purge.test.ts +19 -0
- package/src/tests/quickjs-compat.test.ts +1 -1
- package/src/tests/runner-context-preamble.test.ts +552 -0
- package/src/tests/script-connections.test.ts +3 -0
- package/src/tests/script-executor-conformance.test.ts +188 -0
- package/src/tests/sessions-tree.test.ts +133 -2
- package/src/tests/slack-app-icon.test.ts +4 -0
- package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
- package/src/tests/slack-file-tools-attachments.test.ts +1 -0
- package/src/tests/slack-read-boundaries.test.ts +4 -3
- package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
- package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
- package/src/tests/slack-socket-watchdog.test.ts +748 -0
- package/src/tests/vcs-identity-inheritance.test.ts +85 -0
- package/src/tools/utils.ts +16 -7
- package/templates/extensions/comms-adherence-gate/README.md +25 -0
- package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
- package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
- package/templates/skills/apps/SKILL.md +7 -0
- package/templates/skills/apps/content.md +7 -0
- package/dist/app-a66ssc4k.js +0 -17
- package/dist/handlers-crckt5dq.js +0 -32
- package/dist/index-4x08sjtk.js +0 -30
- package/dist/index-8ybffts4.js +0 -37
- package/dist/index-nfy4kkg5.js +0 -33
- package/dist/lead-zdqxsvjn.js +0 -71
- package/dist/worker-y62rvvq3.js +0 -71
- package/dist/{cli-gxy8y1dt.js → cli-8bpgbr8k.js} +3 -3
|
@@ -151,6 +151,102 @@ const echoServer = Bun.serve({
|
|
|
151
151
|
afterAll(() => echoServer.stop(true));
|
|
152
152
|
|
|
153
153
|
const PARITY_PROBES: Record<string, string> = {
|
|
154
|
+
"structuredClone graphs and built-ins": `async () => {
|
|
155
|
+
class Model { constructor() { this.value = 7; } }
|
|
156
|
+
const shared = { value: 1 };
|
|
157
|
+
const original = { shared, again: shared, model: new Model(), array: [, undefined, -0, NaN, Infinity, 12n] };
|
|
158
|
+
original.self = original;
|
|
159
|
+
const copy = structuredClone(original);
|
|
160
|
+
copy.shared.value = 2;
|
|
161
|
+
const date = structuredClone(new Date(123));
|
|
162
|
+
const regexp = /hello/gi;
|
|
163
|
+
regexp.lastIndex = 4;
|
|
164
|
+
const clonedRegexp = structuredClone(regexp);
|
|
165
|
+
const map = new Map([[shared, shared]]);
|
|
166
|
+
map.set(map, new Set([shared, map]));
|
|
167
|
+
const clonedMap = structuredClone(map);
|
|
168
|
+
const key = [...clonedMap.keys()][0];
|
|
169
|
+
const boxed = [new Boolean(false), new Number(NaN), new String('text'), Object(12n)].map(value => {
|
|
170
|
+
const cloned = structuredClone(value);
|
|
171
|
+
return [typeof cloned, typeof cloned.valueOf(), String(cloned.valueOf()), cloned !== value];
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
cycle: copy.self === copy, shared: copy.shared === copy.again, independent: shared.value === 1,
|
|
175
|
+
model: [Object.getPrototypeOf(copy.model) === Object.prototype, copy.model.value],
|
|
176
|
+
array: [copy.array.length, 0 in copy.array, 1 in copy.array, Object.is(copy.array[2], -0), Number.isNaN(copy.array[3]), copy.array[4] === Infinity, String(copy.array[5])],
|
|
177
|
+
date: [date instanceof Date, date.getTime()],
|
|
178
|
+
regexp: [clonedRegexp instanceof RegExp, clonedRegexp.source, clonedRegexp.flags, clonedRegexp.lastIndex],
|
|
179
|
+
map: [clonedMap instanceof Map, key !== shared, clonedMap.get(key) === key, clonedMap.get(clonedMap) instanceof Set, clonedMap.get(clonedMap).has(key), clonedMap.get(clonedMap).has(clonedMap)],
|
|
180
|
+
boxed,
|
|
181
|
+
};
|
|
182
|
+
}`,
|
|
183
|
+
"structuredClone error subtypes": `async () => {
|
|
184
|
+
const types = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError];
|
|
185
|
+
const errors = types.map(Type => {
|
|
186
|
+
const error = new Type('bad');
|
|
187
|
+
error.extra = 'ignored';
|
|
188
|
+
const cloned = structuredClone(error);
|
|
189
|
+
return [cloned instanceof Type, cloned.name, cloned.message, Object.hasOwn(cloned, 'extra')];
|
|
190
|
+
});
|
|
191
|
+
return errors;
|
|
192
|
+
}`,
|
|
193
|
+
"structuredClone ignores overridden binary accessors": `async () => {
|
|
194
|
+
const buffer = new ArrayBuffer(16);
|
|
195
|
+
new Uint8Array(buffer).set([1, 2, 3, 4]);
|
|
196
|
+
buffer.slice = () => buffer;
|
|
197
|
+
Object.defineProperty(buffer, 'byteLength', { get() { throw Error('byteLength'); } });
|
|
198
|
+
const view = new Uint16Array(buffer, 2, 3);
|
|
199
|
+
view.constructor = Array;
|
|
200
|
+
for (const name of ['buffer', 'byteOffset', 'byteLength', 'length']) {
|
|
201
|
+
Object.defineProperty(view, name, { get() { throw Error(name); } });
|
|
202
|
+
}
|
|
203
|
+
Object.defineProperty(view, Symbol.toStringTag, { get() { throw Error('tag'); } });
|
|
204
|
+
const data = new DataView(buffer, 1, 4);
|
|
205
|
+
const copy = structuredClone({ buffer, view, data });
|
|
206
|
+
new Uint8Array(copy.buffer)[0] = 9;
|
|
207
|
+
const typed = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array].map(Type => {
|
|
208
|
+
const value = new Type(2);
|
|
209
|
+
const cloned = structuredClone(value);
|
|
210
|
+
return [cloned instanceof Type, cloned.length, cloned.buffer !== value.buffer];
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
independent: copy.buffer !== buffer && new Uint8Array(buffer)[0] === 1,
|
|
214
|
+
bytes: Array.from(new Uint8Array(copy.buffer)),
|
|
215
|
+
view: [copy.view instanceof Uint16Array, copy.view.buffer === copy.buffer, copy.view.byteOffset, copy.view.length],
|
|
216
|
+
data: [copy.data instanceof DataView, copy.data.buffer === copy.buffer, copy.data.byteOffset, copy.data.byteLength],
|
|
217
|
+
typed,
|
|
218
|
+
};
|
|
219
|
+
}`,
|
|
220
|
+
"structuredClone property snapshots and symbols": `async () => {
|
|
221
|
+
const original = {
|
|
222
|
+
get a() { delete this.b; this.c = 3; return 1; }, b: 2,
|
|
223
|
+
get [Symbol.toStringTag]() { throw Error('symbol getter ran'); },
|
|
224
|
+
};
|
|
225
|
+
Object.defineProperty(original, '__proto__', { value: { marker: true }, enumerable: true });
|
|
226
|
+
Object.defineProperty(original, 'hidden', { get() { throw Error('hidden getter ran'); } });
|
|
227
|
+
const copy = structuredClone(original);
|
|
228
|
+
return {
|
|
229
|
+
keys: Object.keys(copy), a: copy.a, hasB: Object.hasOwn(copy, 'b'), hasC: Object.hasOwn(copy, 'c'),
|
|
230
|
+
proto: [Object.getPrototypeOf(copy) === Object.prototype, Object.hasOwn(copy, '__proto__'), copy.__proto__.marker],
|
|
231
|
+
symbols: Object.getOwnPropertySymbols(copy).length,
|
|
232
|
+
};
|
|
233
|
+
}`,
|
|
234
|
+
"structuredClone rejects uncloneable values": `async () => {
|
|
235
|
+
const failures = [Symbol('x'), Object(Symbol('x')), () => {}, new WeakMap(), new WeakSet(), Promise.resolve(1), { nested: () => {} }];
|
|
236
|
+
return failures.map(value => {
|
|
237
|
+
try { structuredClone(value); return 'accepted'; } catch(error) { return error.name; }
|
|
238
|
+
});
|
|
239
|
+
}`,
|
|
240
|
+
"structuredClone argument and getter behavior": `async () => {
|
|
241
|
+
const thrown = new RangeError('getter');
|
|
242
|
+
const getter = { get value() { throw thrown; } };
|
|
243
|
+
const copy = structuredClone({ value: 1 }, { transfer: [] });
|
|
244
|
+
let missing;
|
|
245
|
+
try { structuredClone(); } catch (error) { missing = error.name; }
|
|
246
|
+
let sameError;
|
|
247
|
+
try { structuredClone(getter); } catch (error) { sameError = error === thrown; }
|
|
248
|
+
return { copy, missing, sameError };
|
|
249
|
+
}`,
|
|
154
250
|
URL: `async () => {
|
|
155
251
|
const cases = [
|
|
156
252
|
["https://user:pa ss@Example.COM:443/a/./b/../c d?q=1 2&x='y'#frag ment"],
|
|
@@ -383,6 +479,98 @@ describe("quickjs parity shims match native and Bun", () => {
|
|
|
383
479
|
}
|
|
384
480
|
});
|
|
385
481
|
|
|
482
|
+
describe("quickjs structuredClone boundaries", () => {
|
|
483
|
+
test("snapshots Map and Set entries before getters can mutate them", async () => {
|
|
484
|
+
// StructuredSerializeInternal snapshots collections before recursing. Bun's
|
|
485
|
+
// current live traversal differs, so use the standard's result as the oracle.
|
|
486
|
+
const output = await new QuickJSScriptExecutor().run(
|
|
487
|
+
input({
|
|
488
|
+
source: `export default async () => {
|
|
489
|
+
const map = new Map();
|
|
490
|
+
map.set('first', { get value() { map.delete('second'); map.set('third', 3); return 1; } });
|
|
491
|
+
map.set('second', 2);
|
|
492
|
+
const set = new Set();
|
|
493
|
+
set.add({ get value() { set.delete(2); set.add(3); return 1; } });
|
|
494
|
+
set.add(2);
|
|
495
|
+
return { map: [...structuredClone(map)], set: [...structuredClone(set)] };
|
|
496
|
+
};`,
|
|
497
|
+
}),
|
|
498
|
+
);
|
|
499
|
+
expect(output.error).toBeUndefined();
|
|
500
|
+
expect(output.result).toEqual({
|
|
501
|
+
map: [
|
|
502
|
+
["first", { value: 1 }],
|
|
503
|
+
["second", 2],
|
|
504
|
+
],
|
|
505
|
+
set: [{ value: 1 }, 2],
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test("rejects transfers without detaching the source buffer", async () => {
|
|
510
|
+
const output = await new QuickJSScriptExecutor().run(
|
|
511
|
+
input({
|
|
512
|
+
source: `export default async () => {
|
|
513
|
+
const buffer = new ArrayBuffer(8);
|
|
514
|
+
try { structuredClone(buffer, { transfer: [buffer] }); }
|
|
515
|
+
catch (error) { return { name: error.name, message: error.message, byteLength: buffer.byteLength }; }
|
|
516
|
+
};`,
|
|
517
|
+
}),
|
|
518
|
+
);
|
|
519
|
+
expect(output.error).toBeUndefined();
|
|
520
|
+
expect(output.result).toEqual({
|
|
521
|
+
name: "DataCloneError",
|
|
522
|
+
message: "quickjs structuredClone does not support transfers",
|
|
523
|
+
byteLength: 8,
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test("rejects shared, resizable and detached buffers instead of changing their semantics", async () => {
|
|
528
|
+
const output = await new QuickJSScriptExecutor().run(
|
|
529
|
+
input({
|
|
530
|
+
source: `export default async () => {
|
|
531
|
+
const resizable = new ArrayBuffer(8, { maxByteLength: 16 });
|
|
532
|
+
const detached = new ArrayBuffer(8);
|
|
533
|
+
const view = new Uint8Array(detached);
|
|
534
|
+
detached.transfer();
|
|
535
|
+
return [new SharedArrayBuffer(8), resizable, new Uint8Array(resizable), detached, view].map(value => {
|
|
536
|
+
try { structuredClone(value); return 'accepted'; }
|
|
537
|
+
catch (error) { return error.name; }
|
|
538
|
+
});
|
|
539
|
+
};`,
|
|
540
|
+
}),
|
|
541
|
+
);
|
|
542
|
+
expect(output.error).toBeUndefined();
|
|
543
|
+
expect(output.result).toEqual(Array(5).fill("DataCloneError"));
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test("uses captured intrinsics and a fresh clone function on the next run", async () => {
|
|
547
|
+
const executor = new QuickJSScriptExecutor();
|
|
548
|
+
const output = await executor.run(
|
|
549
|
+
input({
|
|
550
|
+
source: `export default async () => {
|
|
551
|
+
const value = { map: new Map([['x', 7]]), bytes: new Uint8Array([1, 2]), error: new TypeError('bad') };
|
|
552
|
+
const Type = TypeError;
|
|
553
|
+
const broken = () => { throw Error('replaced intrinsic'); };
|
|
554
|
+
Map.prototype.set = broken;
|
|
555
|
+
Uint8Array.prototype.set = broken;
|
|
556
|
+
Error.isError = broken;
|
|
557
|
+
globalThis.TypeError = broken;
|
|
558
|
+
const copy = structuredClone(value);
|
|
559
|
+
globalThis.structuredClone = broken;
|
|
560
|
+
return [copy.map.get('x'), copy.bytes[1], copy.error instanceof Type];
|
|
561
|
+
};`,
|
|
562
|
+
}),
|
|
563
|
+
);
|
|
564
|
+
expect(output.error).toBeUndefined();
|
|
565
|
+
expect(output.result).toEqual([7, 2, true]);
|
|
566
|
+
const next = await executor.run(
|
|
567
|
+
input({ source: "export default async () => structuredClone({ value: 7 });" }),
|
|
568
|
+
);
|
|
569
|
+
expect(next.error).toBeUndefined();
|
|
570
|
+
expect(next.result).toEqual({ value: 7 });
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
386
574
|
describe("native-only executor behavior", () => {
|
|
387
575
|
test.skipIf(SKIP_SANDBOX_SPAWN_TESTS)("timeout maps to timeout", async () => {
|
|
388
576
|
const output = await new NativeScriptExecutor().run(
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
test,
|
|
10
10
|
} from "bun:test";
|
|
11
11
|
import { createServer, type Server } from "node:http";
|
|
12
|
-
import { keyPrefixRange, sessionGroupKey } from "../assets/key";
|
|
12
|
+
import { keyPrefixRange, sessionGroupKey, sessionResourceGroupOf } from "../assets/key";
|
|
13
13
|
import {
|
|
14
14
|
isSourceThreadKey,
|
|
15
15
|
NESTED_THREAD_MIN_ROOTS,
|
|
@@ -19,10 +19,13 @@ import {
|
|
|
19
19
|
closeDb,
|
|
20
20
|
countSessions,
|
|
21
21
|
createAgent,
|
|
22
|
+
createPage,
|
|
23
|
+
createScheduledTask,
|
|
22
24
|
createSessionCost,
|
|
23
25
|
createSteeringMessage,
|
|
24
26
|
createTaskExtended,
|
|
25
27
|
createUser,
|
|
28
|
+
createWorkflow,
|
|
26
29
|
getDbClient,
|
|
27
30
|
initDb,
|
|
28
31
|
listRecentSessions,
|
|
@@ -147,7 +150,7 @@ async function ids(extra: SessionFilters) {
|
|
|
147
150
|
describe("session groups and prefix bounds", () => {
|
|
148
151
|
test("leaf helpers preserve group names and namespace roots", () => {
|
|
149
152
|
expect(keyPrefixRange("shared/a/")).toEqual({ lo: "shared/a/", hi: "shared/a0" });
|
|
150
|
-
for (const kind of ["task", "thread", "schedule", "workflow"]) {
|
|
153
|
+
for (const kind of ["task", "thread", "schedule", "workflow", "page", "app", "script", "fs"]) {
|
|
151
154
|
expect(sessionGroupKey(`shared/a/${kind}:abc/`)).toBe("shared/a/");
|
|
152
155
|
}
|
|
153
156
|
for (const key of [
|
|
@@ -214,6 +217,134 @@ describe("session groups and prefix bounds", () => {
|
|
|
214
217
|
});
|
|
215
218
|
});
|
|
216
219
|
|
|
220
|
+
describe("resource groups", () => {
|
|
221
|
+
test("a resource leaf at a namespace root is its own group; task stays No group", () => {
|
|
222
|
+
const me = `personal/${owner.id}/`;
|
|
223
|
+
const cases: Array<[string, string]> = [
|
|
224
|
+
["shared/task:t1/", "shared/"],
|
|
225
|
+
[`${me}task:t1/`, me],
|
|
226
|
+
["shared/thread:t1/", "shared/"],
|
|
227
|
+
["shared/page:p1/", "shared/page:p1/"],
|
|
228
|
+
["shared/workflow:w1/", "shared/workflow:w1/"],
|
|
229
|
+
[`${me}schedule:s1/`, `${me}schedule:s1/`],
|
|
230
|
+
["shared/script:x1/", "shared/script:x1/"],
|
|
231
|
+
["shared/fs:agent-fs:f1/", "shared/fs:agent-fs:f1/"],
|
|
232
|
+
["shared/app:a1/action:send/", "shared/app:a1/action:send/"],
|
|
233
|
+
["shared/workflow:w1/task:t1/", "shared/workflow:w1/"],
|
|
234
|
+
["shared/northwind/page:p1/", "shared/northwind/"],
|
|
235
|
+
];
|
|
236
|
+
for (const [key, group] of cases) expect([key, sessionGroupKey(key)]).toEqual([key, group]);
|
|
237
|
+
expect(sessionResourceGroupOf("shared/app:a1/action:send/")).toEqual({
|
|
238
|
+
kind: "app",
|
|
239
|
+
id: "a1",
|
|
240
|
+
base: "shared/",
|
|
241
|
+
resourceKey: "shared/app:a1/",
|
|
242
|
+
action: "send",
|
|
243
|
+
});
|
|
244
|
+
expect(sessionResourceGroupOf("shared/page:p1/action:x/")).toBeNull();
|
|
245
|
+
expect(sessionResourceGroupOf("shared/northwind/page:p1/")).toBeNull();
|
|
246
|
+
expect(sessionResourceGroupOf("shared/")).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("tree, lists and the Inbox agree; No group keeps only task leaves", async () => {
|
|
250
|
+
const loose = await task("shared/task:loose/");
|
|
251
|
+
const page = await task("shared/page:p1/");
|
|
252
|
+
const workflow = await task("shared/workflow:w1/");
|
|
253
|
+
const workflowChild = await task("shared/workflow:w1/task:c1/");
|
|
254
|
+
const schedule = await task(`personal/${owner.id}/schedule:s1/`);
|
|
255
|
+
const action = await task("shared/app:a1/action:send/");
|
|
256
|
+
const filed = await task("shared/northwind/workflow:w2/");
|
|
257
|
+
expect(await ids({ noGroup: true })).toEqual([loose.id]);
|
|
258
|
+
expect(await ids({ groupKey: "shared/page:p1/" })).toEqual([page.id]);
|
|
259
|
+
expect(await ids({ groupKey: "shared/workflow:w1/" })).toEqual(
|
|
260
|
+
[workflow.id, workflowChild.id].sort(),
|
|
261
|
+
);
|
|
262
|
+
expect(await ids({ groupKey: `personal/${owner.id}/schedule:s1/` })).toEqual([schedule.id]);
|
|
263
|
+
expect(await ids({ groupKey: "shared/app:a1/" })).toEqual([]);
|
|
264
|
+
expect(await ids({ groupKey: "shared/app:a1/action:send/" })).toEqual([action.id]);
|
|
265
|
+
expect(await ids({ groupKey: "shared/northwind/" })).toEqual([filed.id]);
|
|
266
|
+
// Resource sections file on their own, like sources: their sessions stay in the Inbox.
|
|
267
|
+
const inbox = [loose, page, workflow, workflowChild, schedule, action].map((r) => r.id).sort();
|
|
268
|
+
expect(await ids({ triage: "inbox" })).toEqual(inbox);
|
|
269
|
+
|
|
270
|
+
const tree = await getSessionTree(actor(), NOW);
|
|
271
|
+
expect(tree.noGroup.total).toBe(1);
|
|
272
|
+
expect(tree.inbox.total).toBe(6);
|
|
273
|
+
const totals = Object.fromEntries(tree.groups.map((g) => [g.key, g.total]));
|
|
274
|
+
expect(totals).toEqual({
|
|
275
|
+
"shared/app:a1/action:send/": 1,
|
|
276
|
+
"shared/northwind/": 1,
|
|
277
|
+
"shared/page:p1/": 1,
|
|
278
|
+
"shared/workflow:w1/": 2,
|
|
279
|
+
[`personal/${owner.id}/schedule:s1/`]: 1,
|
|
280
|
+
});
|
|
281
|
+
expect(tree.resourceGroups).toEqual(
|
|
282
|
+
[
|
|
283
|
+
"shared/app:a1/",
|
|
284
|
+
"shared/app:a1/action:send/",
|
|
285
|
+
"shared/page:p1/",
|
|
286
|
+
"shared/workflow:w1/",
|
|
287
|
+
`personal/${owner.id}/schedule:s1/`,
|
|
288
|
+
].sort(),
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("the route labels resource groups by name, and a deleted resource gets none", async () => {
|
|
293
|
+
const agent = await createAgent({ name: "page-agent", isLead: false, status: "idle" });
|
|
294
|
+
const page = await createPage({
|
|
295
|
+
agentId: agent.id,
|
|
296
|
+
slug: `pricing-${crypto.randomUUID()}`,
|
|
297
|
+
title: "Pricing review",
|
|
298
|
+
contentType: "text/html",
|
|
299
|
+
body: "<h1>Pricing</h1>",
|
|
300
|
+
});
|
|
301
|
+
const workflow = await createWorkflow({
|
|
302
|
+
name: "Nightly digest",
|
|
303
|
+
definition: { nodes: [] },
|
|
304
|
+
});
|
|
305
|
+
const schedule = await createScheduledTask({
|
|
306
|
+
name: "Morning sweep",
|
|
307
|
+
cronExpression: "0 9 * * *",
|
|
308
|
+
taskTemplate: "Sweep",
|
|
309
|
+
});
|
|
310
|
+
// Each resource's own default key is its session group.
|
|
311
|
+
for (const resource of [page, workflow, schedule]) await task(resource.key);
|
|
312
|
+
await task("shared/workflow:deleted1/");
|
|
313
|
+
await task("shared/app:gone/action:send/");
|
|
314
|
+
const res = await fetch(`${baseUrl}/api/session-tree?show=all`, {
|
|
315
|
+
headers: { "x-swarm-user-id": owner.id },
|
|
316
|
+
});
|
|
317
|
+
expect(res.status).toBe(200);
|
|
318
|
+
const body = (await res.json()) as { labels: Record<string, string>; resourceGroups?: unknown };
|
|
319
|
+
expect(body.resourceGroups).toBeUndefined();
|
|
320
|
+
expect(body.labels).toEqual({
|
|
321
|
+
[`shared/page:${page.id}/`]: "Pricing review",
|
|
322
|
+
[`shared/workflow:${workflow.id}/`]: "Nightly digest",
|
|
323
|
+
[`shared/schedule:${schedule.id}/`]: "Morning sweep",
|
|
324
|
+
"shared/app:gone/action:send/": "send",
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("resource groups are read-only: no prefix rename or delete", async () => {
|
|
329
|
+
await task("shared/workflow:w1/");
|
|
330
|
+
const move = (body: { from: string; to: string | null }) =>
|
|
331
|
+
fetch(`${baseUrl}/api/session-moves/prefix`, {
|
|
332
|
+
method: "POST",
|
|
333
|
+
headers: { "content-type": "application/json", "x-swarm-user-id": owner.id },
|
|
334
|
+
body: JSON.stringify(body),
|
|
335
|
+
});
|
|
336
|
+
for (const body of [
|
|
337
|
+
{ from: "shared/workflow:w1/", to: "shared/renamed/" },
|
|
338
|
+
{ from: "shared/workflow:w1/", to: null },
|
|
339
|
+
{ from: "shared/a/", to: "shared/page:p1/" },
|
|
340
|
+
]) {
|
|
341
|
+
const res = await move(body);
|
|
342
|
+
expect(res.status).toBe(400);
|
|
343
|
+
expect(await res.text()).toContain("Resource groups are read-only.");
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
217
348
|
describe("nested source thread groups", () => {
|
|
218
349
|
const channel = "shared/slack/c1/";
|
|
219
350
|
const thread = `${channel}thread:1.2/`;
|
|
@@ -25,7 +25,11 @@ const server = Bun.serve({
|
|
|
25
25
|
});
|
|
26
26
|
const slackApiUrl = `http://localhost:${server.port}/api/`;
|
|
27
27
|
let token: string | null = null;
|
|
28
|
+
// Spread the real module so a later file in the same process still finds
|
|
29
|
+
// every export (bun keeps module mocks for the whole process).
|
|
30
|
+
const realSlackApp = await import("../slack/app");
|
|
28
31
|
mock.module("../slack/app", () => ({
|
|
32
|
+
...realSlackApp,
|
|
29
33
|
getSlackApp: () => (token ? { client: { token, slackApiUrl } } : null),
|
|
30
34
|
}));
|
|
31
35
|
const { getSlackAppIconUrl } = await import("../slack/app-icon");
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A top-level message in a 1:1 DM with the bot is addressed to the bot even
|
|
3
|
+
* without an @-mention. Bolt's Assistant middleware claims only DM messages
|
|
4
|
+
* that carry `thread_ts`, so a top-level DM reaches registerMessageHandler,
|
|
5
|
+
* which used to drop it as `not_addressed` unless it tagged the bot.
|
|
6
|
+
*
|
|
7
|
+
* These tests drive the real message handler and read the delivery outcome.
|
|
8
|
+
*/
|
|
9
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
10
|
+
import * as dbModule from "../be/db";
|
|
11
|
+
import * as slackEnrichModule from "../slack/enrich";
|
|
12
|
+
import * as slackEventDedupModule from "../slack/event-dedup";
|
|
13
|
+
import { runAdmittedSlackDelivery } from "../slack/inbound-dispatch";
|
|
14
|
+
import * as inboundFilesModule from "../slack/inbound-files";
|
|
15
|
+
import * as siblingAwarenessModule from "../tasks/sibling-awareness";
|
|
16
|
+
|
|
17
|
+
const BOT_USER_ID = "U_BOT_DM_IMPLICIT";
|
|
18
|
+
const OTHER_USER_ID = "U0831BS93V1";
|
|
19
|
+
const LEAD = { id: "lead-dm-implicit-1", name: "TestLead", isLead: true, status: "idle" };
|
|
20
|
+
|
|
21
|
+
const originalEnv = {
|
|
22
|
+
ADDITIVE_SLACK: process.env.ADDITIVE_SLACK,
|
|
23
|
+
SLACK_ALLOWED_EMAIL_DOMAINS: process.env.SLACK_ALLOWED_EMAIL_DOMAINS,
|
|
24
|
+
SLACK_ALLOWED_USER_IDS: process.env.SLACK_ALLOWED_USER_IDS,
|
|
25
|
+
SLACK_RENDER_V2: process.env.SLACK_RENDER_V2,
|
|
26
|
+
SLACK_THREAD_WAKE_ON_ANY_MESSAGE: process.env.SLACK_THREAD_WAKE_ON_ANY_MESSAGE,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type MessageEventArg = {
|
|
30
|
+
channel: string;
|
|
31
|
+
channel_type?: string;
|
|
32
|
+
ts: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
user?: string;
|
|
35
|
+
subtype?: string;
|
|
36
|
+
thread_ts?: string;
|
|
37
|
+
files?: Array<{ id: string; name: string; mimetype: string; size: number }>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type HandlerArgs = {
|
|
41
|
+
event: MessageEventArg;
|
|
42
|
+
body: Record<string, unknown>;
|
|
43
|
+
client: typeof mockClient;
|
|
44
|
+
say: (args: unknown) => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const mockClient = {
|
|
48
|
+
auth: { test: async () => ({ user_id: BOT_USER_ID, bot_id: "B_BOT_DM_IMPLICIT" }) },
|
|
49
|
+
conversations: { replies: async () => ({ messages: [], ok: true }) },
|
|
50
|
+
reactions: { add: async () => ({ ok: true }), remove: async () => ({ ok: true }) },
|
|
51
|
+
chat: { postMessage: async () => ({ ok: true }) },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let createTaskSpy: any;
|
|
55
|
+
let getAllAgentsSpy: any;
|
|
56
|
+
let fetchSlackFilesSpy: any;
|
|
57
|
+
const spies: any[] = [];
|
|
58
|
+
let handler: (args: HandlerArgs) => Promise<void>;
|
|
59
|
+
let resetCaches: () => void;
|
|
60
|
+
let sequence = 0;
|
|
61
|
+
|
|
62
|
+
function emptyInbound(files: inboundFilesModule.InboundSlackFiles["files"] = []) {
|
|
63
|
+
return {
|
|
64
|
+
files,
|
|
65
|
+
fetched: [],
|
|
66
|
+
failed: [],
|
|
67
|
+
async [Symbol.asyncDispose]() {},
|
|
68
|
+
} as inboundFilesModule.InboundSlackFiles;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function installSpyImplementations(): void {
|
|
72
|
+
createTaskSpy.mockImplementation(async () => ({ id: "mock-task-dm-implicit" }));
|
|
73
|
+
getAllAgentsSpy.mockImplementation(async () => [LEAD]);
|
|
74
|
+
fetchSlackFilesSpy.mockImplementation(async (_client: unknown, files: unknown) =>
|
|
75
|
+
emptyInbound((files as inboundFilesModule.InboundSlackFiles["files"]) ?? []),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function deliver(event: Omit<MessageEventArg, "ts" | "user">) {
|
|
80
|
+
sequence += 1;
|
|
81
|
+
const ts = `2000000002.${String(sequence).padStart(6, "0")}`;
|
|
82
|
+
// A distinct sender per message keeps the per-user rate limit out of play.
|
|
83
|
+
const user = `U_HUMAN_DM_${sequence}`;
|
|
84
|
+
const outcome = await runAdmittedSlackDelivery("socket", () =>
|
|
85
|
+
handler({
|
|
86
|
+
event: { ...event, ts, user },
|
|
87
|
+
body: { event_id: `evt_dm_implicit_${sequence}` },
|
|
88
|
+
client: mockClient,
|
|
89
|
+
say: mock(async () => {}),
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
return { outcome, ts };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
process.env.ADDITIVE_SLACK = "false";
|
|
97
|
+
process.env.SLACK_RENDER_V2 = "false";
|
|
98
|
+
delete process.env.SLACK_ALLOWED_EMAIL_DOMAINS;
|
|
99
|
+
delete process.env.SLACK_ALLOWED_USER_IDS;
|
|
100
|
+
delete process.env.SLACK_THREAD_WAKE_ON_ANY_MESSAGE;
|
|
101
|
+
|
|
102
|
+
createTaskSpy = spyOn(siblingAwarenessModule, "createTaskWithSiblingAwareness");
|
|
103
|
+
getAllAgentsSpy = spyOn(dbModule, "getAllAgents");
|
|
104
|
+
fetchSlackFilesSpy = spyOn(inboundFilesModule, "fetchSlackFiles");
|
|
105
|
+
spies.push(
|
|
106
|
+
createTaskSpy,
|
|
107
|
+
getAllAgentsSpy,
|
|
108
|
+
fetchSlackFilesSpy,
|
|
109
|
+
spyOn(dbModule, "getAgentWorkingOnThread").mockImplementation(async () => null),
|
|
110
|
+
spyOn(dbModule, "getLeadAgent").mockImplementation(async () => LEAD as any),
|
|
111
|
+
spyOn(dbModule, "getAgentById").mockImplementation(async (id: string) =>
|
|
112
|
+
id === LEAD.id ? (LEAD as any) : null,
|
|
113
|
+
),
|
|
114
|
+
spyOn(dbModule, "getMostRecentTaskInThread").mockImplementation(async () => null),
|
|
115
|
+
spyOn(dbModule, "getTasksByAgentId").mockImplementation(async () => []),
|
|
116
|
+
spyOn(slackEnrichModule, "resolveSlackUserId").mockImplementation(async () => undefined),
|
|
117
|
+
spyOn(slackEnrichModule, "enrichSlackUserEmail").mockImplementation(async () => null),
|
|
118
|
+
spyOn(slackEventDedupModule, "wasEventSeen").mockImplementation(() => false),
|
|
119
|
+
);
|
|
120
|
+
installSpyImplementations();
|
|
121
|
+
|
|
122
|
+
const handlers = await import("../slack/handlers");
|
|
123
|
+
resetCaches = handlers.resetSlackHandlerCachesForTesting;
|
|
124
|
+
resetCaches();
|
|
125
|
+
handlers.registerMessageHandler({
|
|
126
|
+
event: (eventType: string, fn: (args: HandlerArgs) => Promise<void>) => {
|
|
127
|
+
if (eventType === "message") handler = fn;
|
|
128
|
+
},
|
|
129
|
+
} as any);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
for (const spy of spies) spy.mockClear();
|
|
134
|
+
installSpyImplementations();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
afterAll(() => {
|
|
138
|
+
for (const [key, value] of Object.entries(originalEnv)) {
|
|
139
|
+
if (value === undefined) delete process.env[key];
|
|
140
|
+
else process.env[key] = value;
|
|
141
|
+
}
|
|
142
|
+
mock.restore();
|
|
143
|
+
resetCaches();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("registerMessageHandler — top-level 1:1 DM is addressed to the bot", () => {
|
|
147
|
+
test("untagged top-level DM creates a Lead task", async () => {
|
|
148
|
+
const { outcome, ts } = await deliver({
|
|
149
|
+
channel: "D_DM_IMPLICIT",
|
|
150
|
+
channel_type: "im",
|
|
151
|
+
text: "Can you check why the nightly digest did not post?",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(outcome.state).toBe("processed");
|
|
155
|
+
expect(createTaskSpy).toHaveBeenCalledTimes(1);
|
|
156
|
+
const [description, options] = createTaskSpy.mock.calls[0];
|
|
157
|
+
expect(description).toContain("Can you check why the nightly digest did not post?");
|
|
158
|
+
expect(options).toMatchObject({ agentId: LEAD.id, slackTriggerMessageTs: ts });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("untagged top-level DM creates a Lead task when no agent is online", async () => {
|
|
162
|
+
getAllAgentsSpy.mockImplementation(async () => []);
|
|
163
|
+
const { outcome } = await deliver({
|
|
164
|
+
channel: "D_DM_IMPLICIT",
|
|
165
|
+
channel_type: "im",
|
|
166
|
+
text: "Queue this for later please",
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(outcome.state).toBe("processed");
|
|
170
|
+
expect(createTaskSpy).toHaveBeenCalledTimes(1);
|
|
171
|
+
expect(createTaskSpy.mock.calls[0][1]).toMatchObject({ agentId: LEAD.id });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("untagged top-level DM with a file upload plus text creates a task", async () => {
|
|
175
|
+
const { outcome } = await deliver({
|
|
176
|
+
channel: "D_DM_IMPLICIT",
|
|
177
|
+
channel_type: "im",
|
|
178
|
+
subtype: "file_share",
|
|
179
|
+
text: "What is wrong in this screenshot?",
|
|
180
|
+
files: [{ id: "F_DM_IMPLICIT", name: "shot.png", mimetype: "image/png", size: 2048 }],
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
expect(outcome.state).toBe("processed");
|
|
184
|
+
expect(fetchSlackFilesSpy).toHaveBeenCalledTimes(1);
|
|
185
|
+
expect(createTaskSpy).toHaveBeenCalledTimes(1);
|
|
186
|
+
const [description, options] = createTaskSpy.mock.calls[0];
|
|
187
|
+
expect(description).toContain("What is wrong in this screenshot?");
|
|
188
|
+
expect(description).toContain("shot.png");
|
|
189
|
+
expect(options).toMatchObject({ agentId: LEAD.id });
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("DM that tags only another user creates no task", async () => {
|
|
193
|
+
const { outcome } = await deliver({
|
|
194
|
+
channel: "D_DM_IMPLICIT",
|
|
195
|
+
channel_type: "im",
|
|
196
|
+
text: `<@${OTHER_USER_ID}> can you take a look?`,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(outcome).toEqual({ state: "ignored", code: "not_addressed" });
|
|
200
|
+
expect(createTaskSpy).not.toHaveBeenCalled();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("untagged top-level channel message stays not_addressed", async () => {
|
|
204
|
+
const { outcome } = await deliver({
|
|
205
|
+
channel: "C_CHANNEL_IMPLICIT",
|
|
206
|
+
channel_type: "channel",
|
|
207
|
+
text: "Can you check why the nightly digest did not post?",
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(outcome).toEqual({ state: "ignored", code: "not_addressed" });
|
|
211
|
+
expect(createTaskSpy).not.toHaveBeenCalled();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("untagged top-level group DM (mpim) message stays not_addressed", async () => {
|
|
215
|
+
const { outcome } = await deliver({
|
|
216
|
+
channel: "G_MPIM_IMPLICIT",
|
|
217
|
+
channel_type: "mpim",
|
|
218
|
+
text: "Can you check why the nightly digest did not post?",
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(outcome).toEqual({ state: "ignored", code: "not_addressed" });
|
|
222
|
+
expect(createTaskSpy).not.toHaveBeenCalled();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("untagged DM thread reply with no swarm activity stays not_addressed", async () => {
|
|
226
|
+
const { outcome } = await deliver({
|
|
227
|
+
channel: "D_DM_IMPLICIT",
|
|
228
|
+
channel_type: "im",
|
|
229
|
+
thread_ts: "2000000001.000001",
|
|
230
|
+
text: "Following up on this",
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(outcome).toEqual({ state: "ignored", code: "not_addressed" });
|
|
234
|
+
expect(createTaskSpy).not.toHaveBeenCalled();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -66,6 +66,7 @@ mock.module("../slack/app", () => ({
|
|
|
66
66
|
initSlackApp: async () => null,
|
|
67
67
|
startSlackApp: async () => {},
|
|
68
68
|
stopSlackApp: async () => {},
|
|
69
|
+
stopSlackAppUnderLifecycleLock: async () => {},
|
|
69
70
|
}));
|
|
70
71
|
|
|
71
72
|
function addSlackFile(id: string, name: string, bytes: Uint8Array, path = "files-pri"): SlackFile {
|
|
@@ -22,7 +22,11 @@ const busyMessages = Array.from({ length: FULL_MESSAGE_COUNT }, (_, index) => ({
|
|
|
22
22
|
ts: `1700000000.${String(index).padStart(6, "0")}`,
|
|
23
23
|
}));
|
|
24
24
|
|
|
25
|
+
// Spread the real module so a later file in the same process still finds
|
|
26
|
+
// every export (bun keeps module mocks for the whole process).
|
|
27
|
+
const realSlackApp = await import("../slack/app");
|
|
25
28
|
mock.module("../slack/app", () => ({
|
|
29
|
+
...realSlackApp,
|
|
26
30
|
getSlackApp: () => ({
|
|
27
31
|
client: {
|
|
28
32
|
auth: { test: async () => ({ user_id: "U_BOT" }) },
|
|
@@ -36,9 +40,6 @@ mock.module("../slack/app", () => ({
|
|
|
36
40
|
},
|
|
37
41
|
},
|
|
38
42
|
}),
|
|
39
|
-
initSlackApp: async () => null,
|
|
40
|
-
startSlackApp: async () => {},
|
|
41
|
-
stopSlackApp: async () => {},
|
|
42
43
|
}));
|
|
43
44
|
|
|
44
45
|
type RegisteredTool = {
|