@desplega.ai/agent-swarm 1.161.0 → 1.162.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/README.md +3 -2
- package/dist/{acp-adapter-xx489vvb.js → acp-adapter-74m73ae9.js} +1 -1
- package/dist/{actions-ykjkn0m9.js → actions-4sr14gnt.js} +34 -31
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-0hdqa4k1.js → app-pt68fbwp.js} +13 -11
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-am2g5g8a.js → assistant-cv3jytks.js} +37 -34
- package/dist/{azure-openai-responses-fszbkp0e.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-xy9t7avg.js → boot-reembed-4ht4gqth.js} +13 -11
- package/dist/{boot-reembed-gt5gjkt4.js → boot-reembed-nxpcvpj9.js} +12 -10
- package/dist/{boot-scrub-logs-9x0985y5.js → boot-scrub-logs-k93kyw8k.js} +9 -7
- package/dist/{boot-seeds-trv0d4vg.js → boot-seeds-1skcrs0e.js} +13 -10
- package/dist/{claude-adapter-jb6e1e54.js → claude-adapter-r5g0tzge.js} +23 -20
- package/dist/{claude-managed-setup-d1q9hv2b.js → claude-managed-setup-pkyrgshb.js} +3 -2
- package/dist/{claude-sdk-session-zga700s2.js → claude-sdk-session-jxyxnrwd.js} +5565 -5512
- package/dist/{cli-we0q7t0e.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-35pj2yva.js → cli-4cwxn7gp.js} +38 -11
- package/dist/{cli-ad4qxm6j.js → cli-4dcpaefp.js} +2 -2
- package/dist/{cli-82c1pacn.js → cli-4x0csdjq.js} +71 -37
- package/dist/{cli-sqm3r5ps.js → cli-5bcd7sfy.js} +14 -18
- package/dist/{cli-d56tgd45.js → cli-5k6k8ta3.js} +2 -2
- package/dist/{cli-1er0rhz8.js → cli-5xhpb3kv.js} +15 -15
- package/dist/{cli-yrg7c73k.js → cli-7af8yhav.js} +10 -183
- package/dist/{cli-r6fsxc76.js → cli-7tre70zp.js} +513 -961
- package/dist/{cli-bh7jed3k.js → cli-8ev9xqnx.js} +34 -18
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-hn04t9db.js → cli-cebmgwsc.js} +14 -10
- package/dist/{cli-cfkrztza.js → cli-cvatsam7.js} +2 -2
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/{cli-zb6xbk61.js → cli-g739zqzt.js} +4 -4
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-5p3x4zna.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-jpf7e1zq.js → cli-hmsw1gpy.js} +3 -3
- package/dist/{cli-1cz0c18q.js → cli-jf7wmv1r.js} +2521 -733
- package/dist/{cli-qwsnmjdd.js → cli-jxs2ygaw.js} +168 -61
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-hgmnf38m.js → cli-kh04eqwe.js} +1 -1
- package/dist/{cli-0383bp7f.js → cli-kp42yek0.js} +425 -90
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-8g6mc14k.js → cli-nq7yqw7b.js} +16 -5
- package/dist/{cli-ee8bc46j.js → cli-nt8hecg9.js} +33 -32
- package/dist/{cli-9s68w752.js → cli-p0r8sxj5.js} +1 -1
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-17xpf7cm.js → cli-q24re23n.js} +6 -4
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-798vkbks.js → cli-rj0gqwwp.js} +2 -2
- package/dist/{cli-121ph74b.js → cli-rnyzn44p.js} +1 -1
- package/dist/{cli-vnnz5ncg.js → cli-s3hwpt9v.js} +95 -16
- package/dist/{cli-7119ja3w.js → cli-sptrj5f5.js} +2 -2
- package/dist/{cli-a8c82p2t.js → cli-sqvfa090.js} +13 -6
- package/dist/{cli-phfg8vy8.js → cli-swfmp1fx.js} +26 -26
- package/dist/{cli-nsdxtcbg.js → cli-tcen9p5w.js} +8 -5
- package/dist/{cli-9m03pzga.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-rtx9dygp.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-ecfxwnyb.js → cli-vy3ed88x.js} +1 -1
- package/dist/{cli-0c7ata9h.js → cli-vyqs9ya8.js} +6 -6
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-kgd3p0bm.js → cli-wjgs5wxe.js} +6 -6
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-akfj32vj.js → cli-xqpk3rp7.js} +5 -4
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-3zc55ctx.js → cli-zvhd3f64.js} +2 -2
- package/dist/{cli-ze1d3wzv.js → cli-zxqx25nz.js} +5 -5
- package/dist/cli.js +32 -25
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-04v97vep.js → codex-adapter-esvmnhn7.js} +13 -13
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-session-runner-ax69mqq3.js → codex-session-runner-ban9excr.js} +13 -13
- package/dist/{commands-18gy08n1.js → commands-75413p2n.js} +9 -7
- package/dist/{db-d2pvjpyt.js → db-7f5pecwg.js} +11 -7
- package/dist/{dispatcher-8wbwyzjg.js → dispatcher-fh9at8nz.js} +33 -30
- package/dist/{dsh-adapter-ysqk9snv.js → dsh-adapter-wpze65d4.js} +3 -3
- package/dist/{e2b-esmt1r16.js → e2b-gjgdjp91.js} +10 -9
- package/dist/{pi-logo-animation-e9a0t68z.js → easter-egg-3d-3w5c2n4c.js} +122 -68
- package/dist/{execute-cmagrbrz.js → execute-f50wg9nh.js} +29 -6
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-6b69m5kp.js → handlers-w13787bb.js} +36 -33
- package/dist/{hook-srnkt0hb.js → hook-46g1jrvx.js} +28 -15
- package/dist/{hook-k3mydf2n.js → hook-4tpts2ry.js} +20 -17
- package/dist/{http-hrf80ca1.js → http-19pzbfrt.js} +964 -176
- package/dist/{index-9rxdvj6w.js → index-8fd4dm4h.js} +34 -31
- package/dist/{index-1asbaj62.js → index-dqmp15bq.js} +35 -32
- package/dist/{index-45evq4ee.js → index-qb4q1y3e.js} +33 -30
- package/dist/{index-k4nj18qs.js → index-s75wc4wd.js} +12 -10
- package/dist/{index-xmevk2b9.js → index-scptvdxg.js} +27 -25
- package/dist/{keepalive-sfdz6ksp.js → keepalive-xa5ts9cd.js} +11 -9
- package/dist/{lead-ej91e9hw.js → lead-qp4xkvjq.js} +45 -41
- package/dist/{maintenance-80dnd7ke.js → maintenance-rm5885hm.js} +13 -11
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/{oauth-refresh-sweep-m1etk2mx.js → oauth-refresh-sweep-1csdfebf.js} +10 -8
- package/dist/{onboard-0q8sdfqc.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-n7n683p2.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-9a3nme9j.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-4wcgmvgf.js → opencode-adapter-kb3g6pkf.js} +2 -2
- package/dist/{otel-impl-hnqm9mxq.js → otel-impl-0y9knpky.js} +5 -5
- package/dist/{pi-mono-adapter-d6sqm9wr.js → pi-mono-adapter-z6s1bme2.js} +100 -19
- package/dist/{pricing-refresh-y60z64pm.js → pricing-refresh-mth26tgp.js} +11 -9
- package/dist/{rbac-roles-8pa0754b.js → rbac-roles-kwntb23q.js} +13 -9
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-418s1vj7.js → render-v2-hcm7h00y.js} +13 -11
- package/dist/{runtime-3pknc168.js → runtime-vfjsfsc5.js} +4 -4
- package/dist/{setup-yghdkj4x.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-jcceevt5.js → virtual-modules-9bv7ry91.js} +9 -8
- package/dist/{work-objects-j1sz20v9.js → work-objects-m09sxnhe.js} +36 -33
- package/dist/{worker-d4gcvkjt.js → worker-0h35rvk4.js} +45 -41
- package/openapi.json +491 -12
- package/package.json +13 -6
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +31 -6
- package/src/be/db/tasks/write.ts +5 -4
- package/src/be/db.ts +42 -18
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +35 -16
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/runner.ts +262 -68
- package/src/commands/templates.ts +10 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +13 -0
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +2 -1
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +23 -9
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/status.ts +34 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +123 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- 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/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +8 -0
- package/src/tests/rbac-engine.test.ts +19 -0
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +2 -1
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/tsconfig.json +3 -0
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tsk3nz8a.js +0 -582
- package/dist/{cli-t6v2ah3r.js → cli-twrh04ap.js} +3 -3
|
@@ -166,28 +166,146 @@ describe("send-task: requestedByUserId inheritance", () => {
|
|
|
166
166
|
expect(await requesterWasInherited(s.task!.id)).toBe(1);
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
test("
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
test("Linear tracker holder delegates two children in a row", async () => {
|
|
170
|
+
for (const variant of ["implicit", "explicit-key", "explicit-parent"]) {
|
|
171
|
+
const parentTask = await createTaskExtended("linear source task", {
|
|
172
|
+
requestedByUserId: userAId,
|
|
173
|
+
contextKey: linearContextKey({ issueIdentifier: `DES-203-${variant}` }),
|
|
174
|
+
});
|
|
175
|
+
const args =
|
|
176
|
+
variant === "explicit-key"
|
|
177
|
+
? { key: "shared/linear-child/" }
|
|
178
|
+
: variant === "explicit-parent"
|
|
179
|
+
? { parentTaskId: parentTask.id }
|
|
180
|
+
: {};
|
|
181
|
+
const result = await callSendTask(
|
|
182
|
+
server,
|
|
183
|
+
{ task: "delegated linear child", allowDuplicate: true, ...args },
|
|
184
|
+
LEAD_ID,
|
|
185
|
+
parentTask.id,
|
|
186
|
+
);
|
|
187
|
+
const s = structuredOf(result);
|
|
188
|
+
expect(s.success).toBe(true);
|
|
189
|
+
expect(s.task?.id).not.toBe(parentTask.id);
|
|
190
|
+
const created = await getTaskById(s.task!.id);
|
|
191
|
+
expect(created?.parentTaskId).toBe(parentTask.id);
|
|
192
|
+
const second = structuredOf(
|
|
193
|
+
await callSendTask(
|
|
194
|
+
server,
|
|
195
|
+
{ task: "second linear child", allowDuplicate: true, ...args },
|
|
196
|
+
LEAD_ID,
|
|
197
|
+
parentTask.id,
|
|
198
|
+
),
|
|
199
|
+
);
|
|
200
|
+
expect(second.success).toBe(true);
|
|
201
|
+
expect(second.task?.id).not.toBe(s.task?.id);
|
|
202
|
+
expect((await getTaskById(second.task!.id))?.parentTaskId).toBe(parentTask.id);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("Linear tracker child delegates a grandchild while the holder is active", async () => {
|
|
207
|
+
const holder = await createTaskExtended("active holder", {
|
|
208
|
+
contextKey: linearContextKey({ issueIdentifier: "DES-206" }),
|
|
209
|
+
});
|
|
210
|
+
const child = structuredOf(
|
|
211
|
+
await callSendTask(server, { task: "child", allowDuplicate: true }, LEAD_ID, holder.id),
|
|
212
|
+
);
|
|
213
|
+
expect(child.success).toBe(true);
|
|
214
|
+
const grandchild = structuredOf(
|
|
215
|
+
await callSendTask(
|
|
216
|
+
server,
|
|
217
|
+
{ task: "grandchild", allowDuplicate: true },
|
|
218
|
+
LEAD_ID,
|
|
219
|
+
child.task!.id,
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
expect(grandchild.success).toBe(true);
|
|
223
|
+
expect((await getTaskById(grandchild.task!.id))?.parentTaskId).toBe(child.task!.id);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("Linear tracker holder delegates after its completed child links an open PR", async () => {
|
|
227
|
+
const holder = await createTaskExtended("holder awaiting review", {
|
|
228
|
+
contextKey: linearContextKey({ issueIdentifier: "DES-207" }),
|
|
174
229
|
});
|
|
230
|
+
const child = structuredOf(
|
|
231
|
+
await callSendTask(
|
|
232
|
+
server,
|
|
233
|
+
{ task: "implementation", allowDuplicate: true },
|
|
234
|
+
LEAD_ID,
|
|
235
|
+
holder.id,
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
expect(child.success).toBe(true);
|
|
239
|
+
await getDbClient().run(
|
|
240
|
+
"UPDATE agent_tasks SET status = 'completed', vcsProvider = 'github', vcsRepo = 'desplega-ai/agent-swarm', vcsNumber = 875, vcsUrl = 'https://github.com/desplega-ai/agent-swarm/pull/875' WHERE id = ?",
|
|
241
|
+
[child.task!.id],
|
|
242
|
+
);
|
|
243
|
+
const review = structuredOf(
|
|
244
|
+
await callSendTask(
|
|
245
|
+
server,
|
|
246
|
+
{ task: "review implementation", allowDuplicate: true },
|
|
247
|
+
LEAD_ID,
|
|
248
|
+
holder.id,
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
expect(review.success).toBe(true);
|
|
252
|
+
expect((await getTaskById(review.task!.id))?.parentTaskId).toBe(holder.id);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("Linear tracker delegation skips a different active task on the same key", async () => {
|
|
256
|
+
const key = linearContextKey({ issueIdentifier: "DES-204" });
|
|
257
|
+
const other = await createTaskExtended("other active linear task", { contextKey: key });
|
|
258
|
+
const parent = await createTaskExtended("delegating linear holder");
|
|
259
|
+
// Fixture bypasses creation dedup to represent two existing holders.
|
|
260
|
+
await getDbClient().run("UPDATE agent_tasks SET contextKey = ? WHERE id = ?", [key, parent.id]);
|
|
261
|
+
const before = await getDbClient().get<{ count: number }>(
|
|
262
|
+
"SELECT COUNT(*) AS count FROM agent_tasks",
|
|
263
|
+
);
|
|
175
264
|
|
|
176
265
|
const result = await callSendTask(
|
|
177
266
|
server,
|
|
178
|
-
{ task: "
|
|
267
|
+
{ task: "blocked linear child", allowDuplicate: true },
|
|
179
268
|
LEAD_ID,
|
|
180
|
-
|
|
269
|
+
parent.id,
|
|
181
270
|
);
|
|
271
|
+
const s = structuredOf(result);
|
|
272
|
+
expect(s.success).toBe(false);
|
|
273
|
+
expect(s.message).toContain("already has active task");
|
|
274
|
+
expect(s.task?.id).toBe(other.id);
|
|
275
|
+
expect(await getDbClient().get("SELECT COUNT(*) AS count FROM agent_tasks")).toEqual(before);
|
|
276
|
+
});
|
|
182
277
|
|
|
278
|
+
test("Linear tracker completed task with an unrelated linked PR blocks delegation", async () => {
|
|
279
|
+
const key = linearContextKey({ issueIdentifier: "DES-205" });
|
|
280
|
+
const parent = await createTaskExtended("linear holder with linked PR", {
|
|
281
|
+
contextKey: key,
|
|
282
|
+
vcsProvider: "github",
|
|
283
|
+
vcsRepo: "desplega-ai/agent-swarm",
|
|
284
|
+
vcsNumber: 875,
|
|
285
|
+
vcsUrl: "https://github.com/desplega-ai/agent-swarm/pull/875",
|
|
286
|
+
});
|
|
287
|
+
await getDbClient().run("UPDATE agent_tasks SET status = 'completed' WHERE id = ?", [
|
|
288
|
+
parent.id,
|
|
289
|
+
]);
|
|
290
|
+
const unrelated = await createTaskExtended("unrelated caller");
|
|
291
|
+
await getDbClient().run("UPDATE agent_tasks SET contextKey = ? WHERE id = ?", [
|
|
292
|
+
key,
|
|
293
|
+
unrelated.id,
|
|
294
|
+
]);
|
|
295
|
+
const before = await getDbClient().get<{ count: number }>(
|
|
296
|
+
"SELECT COUNT(*) AS count FROM agent_tasks",
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
const result = await callSendTask(
|
|
300
|
+
server,
|
|
301
|
+
{ task: "blocked child after PR", allowDuplicate: true },
|
|
302
|
+
LEAD_ID,
|
|
303
|
+
unrelated.id,
|
|
304
|
+
);
|
|
183
305
|
const s = structuredOf(result);
|
|
184
|
-
expect(s.success).toBe(
|
|
185
|
-
expect(s.message).toContain("
|
|
186
|
-
expect(s.task?.id).toBe(
|
|
187
|
-
|
|
188
|
-
"SELECT COUNT(*) AS count FROM agent_tasks WHERE contextKey = ?",
|
|
189
|
-
[key],
|
|
190
|
-
)) as { count: number };
|
|
191
|
-
expect(count.count).toBe(1);
|
|
306
|
+
expect(s.success).toBe(false);
|
|
307
|
+
expect(s.message).toContain("already has linked open PR");
|
|
308
|
+
expect(s.task?.id).toBe(parent.id);
|
|
309
|
+
expect(await getDbClient().get("SELECT COUNT(*) AS count FROM agent_tasks")).toEqual(before);
|
|
192
310
|
});
|
|
193
311
|
});
|
|
@@ -71,7 +71,8 @@ describe("task lifecycle telemetry", () => {
|
|
|
71
71
|
event: "created",
|
|
72
72
|
props: {
|
|
73
73
|
taskId: task.id,
|
|
74
|
-
|
|
74
|
+
task_source: "mcp",
|
|
75
|
+
trigger_surface: "mcp",
|
|
75
76
|
hasParent: false,
|
|
76
77
|
has_repo: false,
|
|
77
78
|
priority: 60,
|
|
@@ -146,7 +147,8 @@ describe("task lifecycle telemetry", () => {
|
|
|
146
147
|
event: "cancelled",
|
|
147
148
|
props: {
|
|
148
149
|
taskId: cancelledTask.id,
|
|
149
|
-
|
|
150
|
+
task_source: "api",
|
|
151
|
+
trigger_surface: "api",
|
|
150
152
|
agentId: WORKER_ID,
|
|
151
153
|
previousStatus: "pending",
|
|
152
154
|
},
|
|
@@ -180,7 +182,8 @@ describe("task lifecycle telemetry", () => {
|
|
|
180
182
|
event: "completed",
|
|
181
183
|
props: {
|
|
182
184
|
taskId: task.id,
|
|
183
|
-
|
|
185
|
+
task_source: "mcp",
|
|
186
|
+
trigger_surface: "mcp",
|
|
184
187
|
agentId: WORKER_ID,
|
|
185
188
|
provider: "codex",
|
|
186
189
|
harnessVariant: "stock",
|
|
@@ -188,5 +191,7 @@ describe("task lifecycle telemetry", () => {
|
|
|
188
191
|
},
|
|
189
192
|
});
|
|
190
193
|
expect(calls[0]?.props.tags).toBeUndefined();
|
|
194
|
+
// The raw per-task source is `task_source`; no event carries a `source` property.
|
|
195
|
+
expect("source" in (calls[0]?.props ?? {})).toBe(false);
|
|
191
196
|
});
|
|
192
197
|
});
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { unlink } from "node:fs/promises";
|
|
3
|
+
import { closeDb, createUser, initDb } from "../be/db";
|
|
4
|
+
import { attachRole, detachRole } from "../be/rbac-roles";
|
|
5
|
+
import {
|
|
6
|
+
_getOrgIdForTests,
|
|
7
|
+
_resetTelemetryStateForTests,
|
|
8
|
+
initTelemetry,
|
|
9
|
+
setTelemetryOrgDomain,
|
|
10
|
+
track,
|
|
11
|
+
} from "../telemetry";
|
|
12
|
+
import {
|
|
13
|
+
buildContext,
|
|
14
|
+
emailDomain,
|
|
15
|
+
mapTriggerSurface,
|
|
16
|
+
mintOrgId,
|
|
17
|
+
normalizeProperties,
|
|
18
|
+
userRef,
|
|
19
|
+
validOrgDomain,
|
|
20
|
+
validOrgId,
|
|
21
|
+
} from "../telemetry-context";
|
|
22
|
+
import { _resetTelemetryIdentityForTests, computeOrgDomain } from "../telemetry-identity";
|
|
23
|
+
|
|
24
|
+
// initTelemetry no-ops when ANONYMIZED_TELEMETRY=false, and the CI env may set it.
|
|
25
|
+
process.env.ANONYMIZED_TELEMETRY = "true";
|
|
26
|
+
|
|
27
|
+
const TEST_DB_PATH = "./test-telemetry-context.sqlite";
|
|
28
|
+
|
|
29
|
+
async function removeTestDb(): Promise<void> {
|
|
30
|
+
for (const suffix of ["", "-wal", "-shm"]) {
|
|
31
|
+
try {
|
|
32
|
+
await unlink(TEST_DB_PATH + suffix);
|
|
33
|
+
} catch {
|
|
34
|
+
// File does not exist.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function memoryConfig(initial: Record<string, string> = {}) {
|
|
40
|
+
const store = new Map(Object.entries(initial));
|
|
41
|
+
const writes: Array<{ key: string; value: string }> = [];
|
|
42
|
+
return {
|
|
43
|
+
store,
|
|
44
|
+
writes,
|
|
45
|
+
get: async (key: string) => store.get(key),
|
|
46
|
+
set: async (key: string, value: string) => {
|
|
47
|
+
writes.push({ key, value });
|
|
48
|
+
store.set(key, value);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("telemetry context helpers", () => {
|
|
54
|
+
test("user_ref is stable inside an install, differs across installs, and hides the user ID", () => {
|
|
55
|
+
const a = userRef("install_aaaa", "user-1");
|
|
56
|
+
expect(a).toMatch(/^u_[0-9a-f]{32}$/);
|
|
57
|
+
expect(userRef("install_aaaa", "user-1")).toBe(a);
|
|
58
|
+
expect(userRef("install_bbbb", "user-1")).not.toBe(a);
|
|
59
|
+
expect(userRef("install_aaaa", "user-2")).not.toBe(a);
|
|
60
|
+
expect(a).not.toContain("user-1");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("emailDomain returns a lowercase hostname and never the local part", () => {
|
|
64
|
+
expect(emailDomain("Jane.Doe@Example.COM")).toBe("example.com");
|
|
65
|
+
expect(emailDomain("a@b@corp.example")).toBe("corp.example");
|
|
66
|
+
expect(emailDomain("admin@localhost")).toBeUndefined();
|
|
67
|
+
expect(emailDomain("no-at-sign")).toBeUndefined();
|
|
68
|
+
expect(emailDomain("@example.com")).toBeUndefined();
|
|
69
|
+
expect(emailDomain(null)).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("org ID and domain validators match the proxy patterns", () => {
|
|
73
|
+
expect(validOrgId(mintOrgId())).toBeDefined();
|
|
74
|
+
expect(validOrgId("org_0123456789abcdef")).toBe("org_0123456789abcdef");
|
|
75
|
+
expect(validOrgId("org_abcdefghijklmnopqrstuvwxyz0")).toBeDefined(); // 27 alphanumerics (cloud)
|
|
76
|
+
expect(validOrgId("org_short")).toBeUndefined();
|
|
77
|
+
expect(validOrgId("acme")).toBeUndefined();
|
|
78
|
+
expect(validOrgDomain("Acme.Example")).toBe("acme.example");
|
|
79
|
+
expect(validOrgDomain("user@acme.example")).toBeUndefined();
|
|
80
|
+
expect(validOrgDomain("localhost")).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("buildContext sets user_ref and user_role only for an actor", () => {
|
|
84
|
+
const base = {
|
|
85
|
+
orgId: "org_0123456789abcdef",
|
|
86
|
+
installationId: "install_test",
|
|
87
|
+
isCloud: false,
|
|
88
|
+
isE2b: false,
|
|
89
|
+
swarmVersion: "1.2.3",
|
|
90
|
+
};
|
|
91
|
+
const anonymous = buildContext(base);
|
|
92
|
+
expect(anonymous.user_ref).toBeNull();
|
|
93
|
+
expect(anonymous.user_role).toBeNull();
|
|
94
|
+
expect(anonymous.plan).toBe("self-host-free");
|
|
95
|
+
expect(anonymous.deployment).toBe("self-host");
|
|
96
|
+
|
|
97
|
+
const withActor = buildContext({
|
|
98
|
+
...base,
|
|
99
|
+
actor: { userId: "u-1", role: "admin" },
|
|
100
|
+
isCloud: true,
|
|
101
|
+
});
|
|
102
|
+
expect(withActor.user_ref).toBe(userRef("install_test", "u-1"));
|
|
103
|
+
expect(withActor.user_role).toBe("admin");
|
|
104
|
+
expect(withActor.plan).toBe("cloud");
|
|
105
|
+
expect(withActor.deployment).toBe("cloud");
|
|
106
|
+
|
|
107
|
+
expect(buildContext({ ...base, isE2b: true }).deployment).toBe("e2b");
|
|
108
|
+
expect(buildContext({ ...base, actor: { userId: null } }).user_ref).toBeNull();
|
|
109
|
+
expect(buildContext({ ...base, actor: { userId: " " } }).user_ref).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("mapTriggerSurface maps values outside the catalog enum to other", () => {
|
|
113
|
+
expect(mapTriggerSurface("slack")).toBe("slack");
|
|
114
|
+
expect(mapTriggerSurface("system")).toBe("system");
|
|
115
|
+
expect(mapTriggerSurface("carrier-pigeon")).toBe("other");
|
|
116
|
+
expect(mapTriggerSurface(null)).toBe("other");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("normalizeProperties keeps an event alive when one optional value is unsendable", () => {
|
|
120
|
+
const out = normalizeProperties("task.completed", {
|
|
121
|
+
taskId: "t-1",
|
|
122
|
+
durationMs: 12.6, // integer in the catalog
|
|
123
|
+
provider: null, // not nullable in the catalog
|
|
124
|
+
harnessVersion: undefined,
|
|
125
|
+
nan: Number.NaN,
|
|
126
|
+
});
|
|
127
|
+
expect(out.durationMs).toBe(13);
|
|
128
|
+
expect("provider" in out).toBe(false);
|
|
129
|
+
expect("harnessVersion" in out).toBe(false);
|
|
130
|
+
expect("nan" in out).toBe(false);
|
|
131
|
+
expect(out.taskId).toBe("t-1");
|
|
132
|
+
// A nullable property keeps its null: the proxy requires the key.
|
|
133
|
+
expect(normalizeProperties("session.started", { taskId: null }).taskId).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("telemetry envelope", () => {
|
|
138
|
+
const originalFetch = globalThis.fetch;
|
|
139
|
+
let sent: Array<Record<string, unknown>>;
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
_resetTelemetryStateForTests();
|
|
143
|
+
delete process.env.SWARM_ORG_ID;
|
|
144
|
+
delete process.env.SWARM_ORG_NAME;
|
|
145
|
+
delete process.env.MCP_BASE_URL;
|
|
146
|
+
process.env.ANONYMIZED_TELEMETRY = "true";
|
|
147
|
+
sent = [];
|
|
148
|
+
globalThis.fetch = (async (_url: string, init?: { body?: string }) => {
|
|
149
|
+
if (init?.body) sent.push(JSON.parse(init.body));
|
|
150
|
+
return new Response(null, { status: 204 });
|
|
151
|
+
}) as typeof fetch;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
afterEach(() => {
|
|
155
|
+
globalThis.fetch = originalFetch;
|
|
156
|
+
process.env.ANONYMIZED_TELEMETRY = "true";
|
|
157
|
+
delete process.env.SWARM_ORG_ID;
|
|
158
|
+
delete process.env.SWARM_ORG_NAME;
|
|
159
|
+
_resetTelemetryStateForTests();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
async function tick(): Promise<void> {
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// The compile-time bound on `track()` (unknown event, unknown property) is
|
|
167
|
+
// asserted in src/telemetry-types.typetest.ts: `tsconfig.json` excludes
|
|
168
|
+
// src/tests, so a `@ts-expect-error` here would never be compiled.
|
|
169
|
+
test("track before init sends nothing", async () => {
|
|
170
|
+
track({ event: "server.started", properties: { port: 3013 } });
|
|
171
|
+
await tick();
|
|
172
|
+
expect(sent).toEqual([]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("the org ID is minted once, persisted, and stable across restarts", async () => {
|
|
176
|
+
const config = memoryConfig({ telemetry_installation_id: "install_orgtest" });
|
|
177
|
+
await initTelemetry("api-server", config.get, config.set, { generateIfMissing: true });
|
|
178
|
+
const first = _getOrgIdForTests();
|
|
179
|
+
expect(first).toMatch(/^org_[0-9a-f]{16}$/);
|
|
180
|
+
expect(config.writes.filter((w) => w.key === "telemetry_org_id")).toEqual([
|
|
181
|
+
{ key: "telemetry_org_id", value: first as string },
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
// Restart: a fresh process reads the stored value and writes nothing new.
|
|
185
|
+
_resetTelemetryStateForTests();
|
|
186
|
+
await initTelemetry("api-server", config.get, config.set, { generateIfMissing: true });
|
|
187
|
+
expect(_getOrgIdForTests()).toBe(first);
|
|
188
|
+
expect(config.writes.filter((w) => w.key === "telemetry_org_id")).toHaveLength(1);
|
|
189
|
+
|
|
190
|
+
// A worker reads the same org ID and never mints one.
|
|
191
|
+
_resetTelemetryStateForTests();
|
|
192
|
+
const workerConfig = memoryConfig({ ...Object.fromEntries(config.store) });
|
|
193
|
+
await initTelemetry("worker", workerConfig.get, workerConfig.set);
|
|
194
|
+
expect(_getOrgIdForTests()).toBe(first);
|
|
195
|
+
expect(workerConfig.writes).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("SWARM_ORG_ID wins when valid and is persisted for workers; an invalid one is ignored", async () => {
|
|
199
|
+
process.env.SWARM_ORG_ID = "org_abcdefghijklmnopqrstuvwxyz0";
|
|
200
|
+
const config = memoryConfig({ telemetry_installation_id: "install_orgenv" });
|
|
201
|
+
await initTelemetry("api-server", config.get, config.set, { generateIfMissing: true });
|
|
202
|
+
expect(_getOrgIdForTests()).toBe("org_abcdefghijklmnopqrstuvwxyz0");
|
|
203
|
+
expect(config.store.get("telemetry_org_id")).toBe("org_abcdefghijklmnopqrstuvwxyz0");
|
|
204
|
+
|
|
205
|
+
_resetTelemetryStateForTests();
|
|
206
|
+
process.env.SWARM_ORG_ID = "not-an-org-id";
|
|
207
|
+
const other = memoryConfig({ telemetry_installation_id: "install_orgenv2" });
|
|
208
|
+
await initTelemetry("api-server", other.get, other.set, { generateIfMissing: true });
|
|
209
|
+
expect(_getOrgIdForTests()).toMatch(/^org_[0-9a-f]{16}$/);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("user_ref is set only when there is an actor, and the payload has no @ or raw user ID", async () => {
|
|
213
|
+
process.env.SWARM_ORG_NAME = "Acme Robotics";
|
|
214
|
+
const config = memoryConfig({ telemetry_installation_id: "install_payload" });
|
|
215
|
+
await initTelemetry("api-server", config.get, config.set, { generateIfMissing: true });
|
|
216
|
+
setTelemetryOrgDomain("corp.example");
|
|
217
|
+
|
|
218
|
+
track({ event: "server.started", properties: { port: 3013 } });
|
|
219
|
+
track({
|
|
220
|
+
event: "workflow.deleted",
|
|
221
|
+
properties: { workflowId: "wf-1" },
|
|
222
|
+
actor: { userId: "raw-user-id-7f3a" },
|
|
223
|
+
});
|
|
224
|
+
track({
|
|
225
|
+
event: "workflow.deleted",
|
|
226
|
+
properties: { workflowId: "wf-2" },
|
|
227
|
+
actor: { userId: null },
|
|
228
|
+
});
|
|
229
|
+
await tick();
|
|
230
|
+
|
|
231
|
+
expect(sent).toHaveLength(3);
|
|
232
|
+
const [system, human, nullActor] = sent as Array<{
|
|
233
|
+
schema_version: number;
|
|
234
|
+
context: Record<string, unknown>;
|
|
235
|
+
}>;
|
|
236
|
+
expect(system?.schema_version).toBe(2);
|
|
237
|
+
expect(system?.context.user_ref).toBeNull();
|
|
238
|
+
expect(system?.context.org_domain).toBe("corp.example");
|
|
239
|
+
expect(system?.context.org_name).toBe("Acme Robotics");
|
|
240
|
+
expect(system?.context.org_id).toMatch(/^org_[0-9a-f]{16}$/);
|
|
241
|
+
expect(human?.context.user_ref).toBe(userRef("install_payload", "raw-user-id-7f3a"));
|
|
242
|
+
expect(nullActor?.context.user_ref).toBeNull();
|
|
243
|
+
|
|
244
|
+
for (const payload of sent) {
|
|
245
|
+
const text = JSON.stringify(payload);
|
|
246
|
+
expect(text).not.toContain("@");
|
|
247
|
+
expect(text).not.toContain("raw-user-id-7f3a");
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("an org with no ID yet sends nothing instead of a half-identified event", async () => {
|
|
252
|
+
// A worker on an old server: installation ID known, no org ID stored.
|
|
253
|
+
const config = memoryConfig({ telemetry_installation_id: "install_noorg" });
|
|
254
|
+
await initTelemetry("worker", config.get, config.set);
|
|
255
|
+
track({ event: "server.started", properties: { port: 1 } });
|
|
256
|
+
await tick();
|
|
257
|
+
expect(sent).toEqual([]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("opted out: no network call, no install ID, no org ID minted", async () => {
|
|
261
|
+
process.env.ANONYMIZED_TELEMETRY = "false";
|
|
262
|
+
const config = memoryConfig();
|
|
263
|
+
await initTelemetry("api-server", config.get, config.set, { generateIfMissing: true });
|
|
264
|
+
track({ event: "server.started", properties: { port: 3013 } });
|
|
265
|
+
await tick();
|
|
266
|
+
expect(sent).toEqual([]);
|
|
267
|
+
expect(config.writes).toEqual([]);
|
|
268
|
+
expect(_getOrgIdForTests()).toBeUndefined();
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe("org email domain", () => {
|
|
273
|
+
beforeEach(async () => {
|
|
274
|
+
closeDb();
|
|
275
|
+
await removeTestDb();
|
|
276
|
+
initDb(TEST_DB_PATH);
|
|
277
|
+
_resetTelemetryIdentityForTests();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
afterEach(async () => {
|
|
281
|
+
closeDb();
|
|
282
|
+
await removeTestDb();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("is undefined with no users", async () => {
|
|
286
|
+
expect(await computeOrgDomain()).toBeUndefined();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test("comes from the earliest active admin, not the earliest user", async () => {
|
|
290
|
+
const member = await createUser({ name: "Early Member", email: "early@member.example" });
|
|
291
|
+
await detachRole(member.id, "admin");
|
|
292
|
+
await attachRole(member.id, "requester");
|
|
293
|
+
await Bun.sleep(5);
|
|
294
|
+
await createUser({ name: "Later Admin", email: "Boss@Admin.Example" });
|
|
295
|
+
expect(await computeOrgDomain()).toBe("admin.example");
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("falls back to the earliest user with an email when no admin has one", async () => {
|
|
299
|
+
const noEmailAdmin = await createUser({ name: "No Email" });
|
|
300
|
+
expect(noEmailAdmin.email).toBeUndefined();
|
|
301
|
+
const member = await createUser({ name: "Member", email: "m@fallback.example" });
|
|
302
|
+
await detachRole(member.id, "admin");
|
|
303
|
+
await attachRole(member.id, "requester");
|
|
304
|
+
expect(await computeOrgDomain()).toBe("fallback.example");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("skips a suspended user and an address with no valid hostname", async () => {
|
|
308
|
+
await createUser({ name: "Suspended", email: "s@suspended.example", status: "suspended" });
|
|
309
|
+
await createUser({ name: "Local", email: "root@localhost" });
|
|
310
|
+
await Bun.sleep(5);
|
|
311
|
+
await createUser({ name: "Real", email: "me@real.example" });
|
|
312
|
+
expect(await computeOrgDomain()).toBe("real.example");
|
|
313
|
+
});
|
|
314
|
+
});
|