@desplega.ai/agent-swarm 2.7.10 → 2.8.1
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-pdy3qsvg.js +15 -0
- package/dist/{actions-b8aqhrsg.js → actions-pwjpn0j6.js} +19 -20
- package/dist/{amp-adapter-4c165vgn.js → amp-adapter-cq9jgj6x.js} +2 -3
- package/dist/{app-m9khefrh.js → app-cnfffgwg.js} +3 -3
- package/dist/{assistant-rh4v3ntz.js → assistant-kpn317y1.js} +21 -22
- package/dist/{boot-args-schema-hwkc8bzv.js → boot-args-schema-pbbnhmc3.js} +1 -1
- package/dist/{boot-reembed-fdyk55h4.js → boot-reembed-9m0ysxma.js} +1 -1
- package/dist/{boot-reembed-5y6yw9sj.js → boot-reembed-majbn53m.js} +1 -1
- package/dist/{boot-scrub-sweep-r5r8kqsn.js → boot-scrub-sweep-app8g8ym.js} +3 -3
- package/dist/{boot-seeds-8f9zt5cm.js → boot-seeds-pbtmvcjm.js} +4 -5
- package/dist/{claude-adapter-s5df247c.js → claude-adapter-wn1g3qp5.js} +7 -8
- package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-jh6c523j.js} +3 -3
- package/dist/{claude-managed-setup-9gsmwzyx.js → claude-managed-setup-pd47nzch.js} +6 -6
- package/dist/{claude-sdk-session-dq1j4nz9.js → claude-sdk-session-3a2a6589.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-zjphdj1a.js → cli-0ntbxyaa.js} +40 -18
- package/dist/{cli-yz7v0sh4.js → cli-1xh9a7hn.js} +4 -6
- package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
- package/dist/{cli-hfkwwy1h.js → cli-2zp0et3v.js} +21 -2
- package/dist/{cli-6m6b4bep.js → cli-3rkdne1h.js} +2 -2
- package/dist/{cli-mr97t7cc.js → cli-4r05hnqa.js} +263 -14
- package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
- package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
- package/dist/{cli-an1knn2k.js → cli-6mma83xa.js} +5 -5
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- 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-j7d73g1y.js → cli-7w69ne2f.js} +3035 -354
- package/dist/{cli-cr14kftt.js → cli-89cqnasv.js} +3 -3
- package/dist/{cli-w3bk0dgv.js → cli-8aes17e4.js} +2 -2
- package/dist/{cli-7wz05bx3.js → cli-93k32c37.js} +468 -745
- package/dist/{cli-eqk5p56g.js → cli-9vhebtjz.js} +9 -9
- package/dist/{cli-td33w98c.js → cli-9wngrawf.js} +10 -10
- package/dist/cli-a3b239vq.js +242 -0
- package/dist/{cli-kx4c8j05.js → cli-b085njxz.js} +63 -19
- package/dist/{cli-8ewkreqd.js → cli-b5rs97a6.js} +7 -9
- package/dist/{cli-bxz823sz.js → cli-b8e9nb04.js} +1 -1
- package/dist/{cli-nj3x45rw.js → cli-bb431xey.js} +52 -43
- package/dist/{cli-36wdfzgn.js → cli-bsywb58a.js} +8 -8
- package/dist/{cli-18qt3few.js → cli-cyhbbd1z.js} +1 -1
- package/dist/{cli-eb2azq8n.js → cli-d3p5vwbk.js} +9 -9
- package/dist/{cli-2tsfpc70.js → cli-dy32zecz.js} +1 -1
- package/dist/{cli-rjyghzg4.js → cli-g70vxtjh.js} +2 -2
- package/dist/{cli-55bkx8hh.js → cli-gax7fk3t.js} +1 -1
- package/dist/{cli-jg24scat.js → cli-jcpr5smb.js} +3 -3
- package/dist/{cli-n07eecjs.js → cli-jywyhqws.js} +3 -3
- package/dist/{cli-38yww4e9.js → cli-k0615eh8.js} +8 -8
- package/dist/{cli-3xddv0rk.js → cli-k26bkr9t.js} +5 -7
- package/dist/{cli-xd5ebp64.js → cli-k93bq1wq.js} +3 -3
- package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
- package/dist/{cli-x9exydey.js → cli-m4dqmnbp.js} +1 -1
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
- package/dist/{cli-ttbqe3q4.js → cli-p1w18yhx.js} +1 -1
- package/dist/{cli-h49ejvmc.js → cli-pcad4cb1.js} +1 -1
- package/dist/{cli-tmft5dz2.js → cli-qmqk2yc2.js} +1 -1
- package/dist/{cli-g1px1g2e.js → cli-re4raaj0.js} +1 -1
- package/dist/{cli-xbtq4d6s.js → cli-sn7rtnj4.js} +12 -8
- package/dist/{cli-n9abj89w.js → cli-syybb0p1.js} +8 -8
- package/dist/{cli-v2fwbnsk.js → cli-tacge1w0.js} +6 -6
- 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-z9cs5m0w.js → cli-vbh10fqa.js} +12 -12
- package/dist/{cli-3xcwp3z8.js → cli-vj75tyaw.js} +3 -3
- package/dist/{cli-xncjscpm.js → cli-vqptjbr7.js} +50 -24
- package/dist/{cli-q581b386.js → cli-wk18cm92.js} +5 -5
- package/dist/{cli-4vwxp550.js → cli-x1wa213s.js} +1 -1
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
- package/dist/{cli-16phend6.js → cli-yn2bbre9.js} +1 -1
- package/dist/{cli-rt0ag4x1.js → cli-yncmerje.js} +5 -5
- package/dist/{cli-0m7rtm11.js → cli-zcsw143p.js} +1 -1
- package/dist/cli.js +18 -18
- package/dist/{codex-adapter-yr60sme6.js → codex-adapter-nha71q3n.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-ak9x1k1h.js} +5 -6
- package/dist/{commands-phjfbkv0.js → commands-f587qpq8.js} +3 -3
- package/dist/{controller-jkx994pz.js → controller-hxx8wwy1.js} +2 -2
- package/dist/{controllers-connect-c4448kwa.js → controllers-connect-k5sg9m9h.js} +20 -21
- package/dist/{cursor-adapter-ndebqnm8.js → cursor-adapter-n5nc3mfe.js} +1 -2
- package/dist/{db-ef32tbfc.js → db-amm8w15a.js} +10 -2
- package/dist/{db-ez6egt6v.js → db-nzf8zb5z.js} +3 -3
- package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
- package/dist/{dispatcher-g3tt9hs9.js → dispatcher-89zrts8f.js} +18 -19
- 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-ezwenjmj.js} +6 -6
- package/dist/{embeddings-6a8v4a6t.js → embeddings-np74ht6g.js} +1 -1
- package/dist/{execute-3cbg0twf.js → execute-b3mrb1mv.js} +1 -1
- package/dist/{external-channel-se646snz.js → external-channel-z46yx9d7.js} +2 -2
- package/dist/{fx-adapter-yw795hqq.js → fx-adapter-3q12snn6.js} +7 -8
- package/dist/{grok-adapter-ttmcss2j.js → grok-adapter-ahb1w033.js} +7 -8
- package/dist/handlers-vbww69re.js +32 -0
- package/dist/heartbeat-dt9qw9c8.js +43 -0
- package/dist/{hook-hq93y5ej.js → hook-8k6fbz9b.js} +5 -5
- package/dist/{hook-g3nhexsy.js → hook-jgcgygex.js} +6 -6
- package/dist/{http-5a9p4h6y.js → http-haw4r8ne.js} +284 -142
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/{index-6haqt3v5.js → index-4a0670yh.js} +8917 -8476
- package/dist/index-4xwaf5th.js +32 -0
- package/dist/{index-3c5pxbge.js → index-5gk12my8.js} +1 -1
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- package/dist/index-f0hcrs8e.js +33 -0
- package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
- package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
- package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
- package/dist/index-s4ewdma4.js +37 -0
- package/dist/{index-hgn3c961.js → index-tez78qj3.js} +979 -36
- package/dist/{index-s72rqgsx.js → index-tvfafeyy.js} +1 -1
- package/dist/{keepalive-1j4n4dmk.js → keepalive-xn6s7rmg.js} +3 -3
- package/dist/lead-6ygbfhbh.js +70 -0
- package/dist/{maintenance-dmghacy5.js → maintenance-vdts800b.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-yy06c03c.js → oauth-refresh-sweep-094c8wfk.js} +2 -2
- package/dist/{onboard-52f9t5dm.js → onboard-v99eh56m.js} +3 -3
- package/dist/{opencode-adapter-krnh9jkn.js → opencode-adapter-dsagkhtw.js} +5 -6
- package/dist/{otel-impl-xjqz6wjj.js → otel-impl-q7yr9yp0.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-7dh2yase.js} +2 -3
- package/dist/{rbac-roles-ehv8s10n.js → rbac-roles-mdmc96p4.js} +3 -3
- package/dist/{rbac-roles-q0gr8eyj.js → rbac-roles-npbmdh77.js} +4 -6
- package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
- package/dist/{render-v2-5b6chvcq.js → render-v2-twhhwmms.js} +3 -3
- package/dist/{resume-5a5d2845.js → resume-5gsrjd5e.js} +6 -6
- package/dist/{runtime-khxszyfp.js → runtime-1hv06jsn.js} +1 -1
- package/dist/{session-access-gj0bjhqg.js → session-access-m191x30x.js} +4 -4
- package/dist/{session-source-backfill-2sy0krfk.js → session-source-backfill-nt923ask.js} +2 -2
- package/dist/{setup-7ssfakk1.js → setup-wv467afy.js} +1 -1
- package/dist/{virtual-modules-pjj0knwf.js → virtual-modules-gazyapte.js} +3 -3
- package/dist/{work-objects-bf3syvhq.js → work-objects-8zkrpy13.js} +21 -22
- package/dist/{worker-follow-up-38xevga6.js → worker-follow-up-cecqszem.js} +18 -19
- package/dist/worker-mz5z7kj0.js +70 -0
- package/openapi.json +334 -7
- package/package.json +5 -5
- 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/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -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/mcp-tools.test.ts +1 -1
- 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-native-unawaited-drain.test.ts +167 -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/script-run.ts +1 -1
- 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 +2 -2
- package/templates/skills/swarm-scripts/content.md +2 -2
- 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,359 @@
|
|
|
1
|
+
// `profile` on schedules (plan phase 6): create, update and patch validate it
|
|
2
|
+
// with the profile check when the target agent is known, profile and
|
|
3
|
+
// model/modelTier are exclusive (setting one clears the other), and a fired
|
|
4
|
+
// task carries the schedule's profile. HTTP and the MCP tools agree.
|
|
5
|
+
|
|
6
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
7
|
+
import { unlink } from "node:fs/promises";
|
|
8
|
+
import { createServer, type Server } from "node:http";
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
import {
|
|
12
|
+
closeDb,
|
|
13
|
+
createAgent,
|
|
14
|
+
createScheduledTask,
|
|
15
|
+
getDbClient,
|
|
16
|
+
getScheduledTaskById,
|
|
17
|
+
initDb,
|
|
18
|
+
} from "../be/db";
|
|
19
|
+
import { updateAgentCredStatus } from "../be/db/agents";
|
|
20
|
+
import { createModelProfile, deleteModelProfile } from "../be/db/model-profiles";
|
|
21
|
+
import { reloadModelsCatalog } from "../be/model-catalog-store";
|
|
22
|
+
import { handleSchedules } from "../http/schedules";
|
|
23
|
+
import { registerCreateScheduleTool } from "../tools/schedules/create-schedule";
|
|
24
|
+
import { registerPatchScheduleTool } from "../tools/schedules/patch-schedule";
|
|
25
|
+
import { registerUpdateScheduleTool } from "../tools/schedules/update-schedule";
|
|
26
|
+
import type { AgentCredStatus } from "../types";
|
|
27
|
+
import { setRequestAuth } from "../utils/request-auth-context";
|
|
28
|
+
import { listenOnFreePort } from "./test-net";
|
|
29
|
+
|
|
30
|
+
const TEST_DB_PATH = "./test-schedule-profile.sqlite";
|
|
31
|
+
|
|
32
|
+
async function removeDbFiles(path: string): Promise<void> {
|
|
33
|
+
for (const suffix of ["", "-wal", "-shm"]) {
|
|
34
|
+
await unlink(path + suffix).catch(() => undefined);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const READY: AgentCredStatus = {
|
|
39
|
+
ready: true,
|
|
40
|
+
missing: [],
|
|
41
|
+
satisfiedBy: "env",
|
|
42
|
+
hint: null,
|
|
43
|
+
liveTest: null,
|
|
44
|
+
latestModel: null,
|
|
45
|
+
reportedAt: Date.now(),
|
|
46
|
+
reportKind: "boot",
|
|
47
|
+
bedrock: null,
|
|
48
|
+
acp: null,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let server: Server;
|
|
52
|
+
let baseUrl = "";
|
|
53
|
+
let claudeId = "";
|
|
54
|
+
let codexId = "";
|
|
55
|
+
let mcp: McpServer;
|
|
56
|
+
|
|
57
|
+
beforeAll(async () => {
|
|
58
|
+
await removeDbFiles(TEST_DB_PATH);
|
|
59
|
+
initDb(TEST_DB_PATH);
|
|
60
|
+
await reloadModelsCatalog();
|
|
61
|
+
claudeId = (
|
|
62
|
+
await createAgent({
|
|
63
|
+
name: "sp-claude",
|
|
64
|
+
isLead: false,
|
|
65
|
+
status: "idle",
|
|
66
|
+
harnessProvider: "claude",
|
|
67
|
+
})
|
|
68
|
+
).id;
|
|
69
|
+
await updateAgentCredStatus(claudeId, READY);
|
|
70
|
+
codexId = (
|
|
71
|
+
await createAgent({ name: "sp-codex", isLead: false, status: "idle", harnessProvider: "codex" })
|
|
72
|
+
).id;
|
|
73
|
+
await updateAgentCredStatus(codexId, READY);
|
|
74
|
+
await createModelProfile({ name: "sp-claude-opus", harness: "claude", model: "opus" });
|
|
75
|
+
await createModelProfile({ name: "sp-claude-held", harness: "claude", model: "sonnet" });
|
|
76
|
+
|
|
77
|
+
server = createServer((req, res) => {
|
|
78
|
+
setRequestAuth(req, { kind: "operator", fingerprint: "schedule-profile-test" });
|
|
79
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
80
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
81
|
+
void (async () => {
|
|
82
|
+
res.setHeader("Content-Type", "application/json");
|
|
83
|
+
if (await handleSchedules(req, res, segments, url.searchParams, undefined)) return;
|
|
84
|
+
res.writeHead(404);
|
|
85
|
+
res.end("{}");
|
|
86
|
+
})();
|
|
87
|
+
});
|
|
88
|
+
baseUrl = `http://localhost:${await listenOnFreePort(server)}`;
|
|
89
|
+
|
|
90
|
+
mcp = new McpServer({ name: "schedule-profile-test", version: "1.0.0" });
|
|
91
|
+
registerCreateScheduleTool(mcp);
|
|
92
|
+
registerUpdateScheduleTool(mcp);
|
|
93
|
+
registerPatchScheduleTool(mcp);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
afterAll(async () => {
|
|
97
|
+
server.close();
|
|
98
|
+
closeDb();
|
|
99
|
+
await removeDbFiles(TEST_DB_PATH);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
async function api(method: string, path: string, body?: unknown) {
|
|
103
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
104
|
+
method,
|
|
105
|
+
headers: { "content-type": "application/json" },
|
|
106
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
107
|
+
});
|
|
108
|
+
const text = await res.text();
|
|
109
|
+
return { status: res.status, body: text ? (JSON.parse(text) as Record<string, any>) : {} };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type ToolOutput = { success: boolean; message: string; schedule?: Record<string, any> };
|
|
113
|
+
|
|
114
|
+
async function tool(name: string, args: Record<string, unknown>): Promise<ToolOutput> {
|
|
115
|
+
const tools = (
|
|
116
|
+
mcp as unknown as {
|
|
117
|
+
_registeredTools: Record<
|
|
118
|
+
string,
|
|
119
|
+
{ handler: (a: unknown, e: unknown) => Promise<CallToolResult> }
|
|
120
|
+
>;
|
|
121
|
+
}
|
|
122
|
+
)._registeredTools;
|
|
123
|
+
const result = await tools[name]!.handler(args, {
|
|
124
|
+
sessionId: "schedule-profile-test",
|
|
125
|
+
requestInfo: { headers: { "x-agent-id": claudeId } },
|
|
126
|
+
});
|
|
127
|
+
return result.structuredContent as ToolOutput;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let counter = 0;
|
|
131
|
+
function scheduleName(): string {
|
|
132
|
+
counter++;
|
|
133
|
+
return `sp-${counter}-${Date.now()}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function base(extra: Record<string, unknown> = {}) {
|
|
137
|
+
return { name: scheduleName(), taskTemplate: "tick", intervalMs: 3_600_000, ...extra };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
describe("HTTP create", () => {
|
|
141
|
+
test("a profile on a passing agent saves, and the fired task carries it", async () => {
|
|
142
|
+
const created = await api(
|
|
143
|
+
"POST",
|
|
144
|
+
"/api/schedules",
|
|
145
|
+
base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
|
|
146
|
+
);
|
|
147
|
+
expect(created.status).toBe(201);
|
|
148
|
+
expect(created.body.profile).toBe("sp-claude-opus");
|
|
149
|
+
|
|
150
|
+
const fired = await api("POST", `/api/schedules/${created.body.id}/run`);
|
|
151
|
+
expect(fired.status).toBe(200);
|
|
152
|
+
expect(fired.body.task.profile).toBe("sp-claude-opus");
|
|
153
|
+
const row = await getDbClient().get<{ profile: string | null }>(
|
|
154
|
+
"SELECT profile FROM agent_tasks WHERE id = ?",
|
|
155
|
+
[fired.body.task.id],
|
|
156
|
+
);
|
|
157
|
+
expect(row?.profile).toBe("sp-claude-opus");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("a pool schedule takes a profile without an agent check", async () => {
|
|
161
|
+
const created = await api("POST", "/api/schedules", base({ profile: "sp-claude-opus" }));
|
|
162
|
+
expect(created.status).toBe(201);
|
|
163
|
+
expect(created.body.profile).toBe("sp-claude-opus");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("an agent that fails the check is a 400", async () => {
|
|
167
|
+
const res = await api(
|
|
168
|
+
"POST",
|
|
169
|
+
"/api/schedules",
|
|
170
|
+
base({ targetAgentId: codexId, profile: "sp-claude-opus" }),
|
|
171
|
+
);
|
|
172
|
+
expect(res.status).toBe(400);
|
|
173
|
+
expect(String(res.body.error)).toContain('Model profile "sp-claude-opus" fails harness');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("an unknown profile is a 400", async () => {
|
|
177
|
+
const res = await api("POST", "/api/schedules", base({ profile: "sp-no-such-profile" }));
|
|
178
|
+
expect(res.status).toBe(400);
|
|
179
|
+
expect(String(res.body.error)).toContain('Unknown model profile "sp-no-such-profile"');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("profile together with model or modelTier is a 400", async () => {
|
|
183
|
+
for (const extra of [{ model: "opus" }, { modelTier: "smart" }]) {
|
|
184
|
+
const res = await api(
|
|
185
|
+
"POST",
|
|
186
|
+
"/api/schedules",
|
|
187
|
+
base({ targetAgentId: claudeId, profile: "sp-claude-opus", ...extra }),
|
|
188
|
+
);
|
|
189
|
+
expect(res.status).toBe(400);
|
|
190
|
+
expect(String(res.body.error)).toContain("not both");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("HTTP update and patch", () => {
|
|
196
|
+
test("setting profile clears model and modelTier; setting modelTier clears profile", async () => {
|
|
197
|
+
for (const method of ["PUT", "PATCH"]) {
|
|
198
|
+
const created = await api(
|
|
199
|
+
"POST",
|
|
200
|
+
"/api/schedules",
|
|
201
|
+
base({ targetAgentId: claudeId, modelTier: "smart" }),
|
|
202
|
+
);
|
|
203
|
+
expect(created.status).toBe(201);
|
|
204
|
+
const id = created.body.id as string;
|
|
205
|
+
|
|
206
|
+
const set = await api(method, `/api/schedules/${id}`, { profile: "sp-claude-opus" });
|
|
207
|
+
expect(set.status).toBe(200);
|
|
208
|
+
expect(set.body.profile).toBe("sp-claude-opus");
|
|
209
|
+
expect(set.body.modelTier).toBeUndefined();
|
|
210
|
+
expect(set.body.model).toBeUndefined();
|
|
211
|
+
|
|
212
|
+
const back = await api(method, `/api/schedules/${id}`, { modelTier: "regular" });
|
|
213
|
+
expect(back.status).toBe(200);
|
|
214
|
+
expect(back.body.modelTier).toBe("regular");
|
|
215
|
+
expect(back.body.profile).toBeUndefined();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("setting model clears profile, and null clears it", async () => {
|
|
220
|
+
const created = await api(
|
|
221
|
+
"POST",
|
|
222
|
+
"/api/schedules",
|
|
223
|
+
base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
|
|
224
|
+
);
|
|
225
|
+
const id = created.body.id as string;
|
|
226
|
+
const model = await api("PATCH", `/api/schedules/${id}`, { model: "sonnet" });
|
|
227
|
+
expect(model.status).toBe(200);
|
|
228
|
+
expect(model.body.profile).toBeUndefined();
|
|
229
|
+
|
|
230
|
+
const reset = await api("PATCH", `/api/schedules/${id}`, {
|
|
231
|
+
model: null,
|
|
232
|
+
profile: "sp-claude-opus",
|
|
233
|
+
});
|
|
234
|
+
expect(reset.body.profile).toBe("sp-claude-opus");
|
|
235
|
+
expect((await getScheduledTaskById(id))?.profile).toBe("sp-claude-opus");
|
|
236
|
+
const cleared = await api("PATCH", `/api/schedules/${id}`, { profile: null });
|
|
237
|
+
expect(cleared.status).toBe(200);
|
|
238
|
+
expect(cleared.body.profile).toBeUndefined();
|
|
239
|
+
// The stored row, not just the response: PATCH null clears the column.
|
|
240
|
+
expect((await getScheduledTaskById(id))?.profile ?? null).toBeNull();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("profile and model in one body is a 400", async () => {
|
|
244
|
+
const created = await api("POST", "/api/schedules", base({ targetAgentId: claudeId }));
|
|
245
|
+
const id = created.body.id as string;
|
|
246
|
+
for (const method of ["PUT", "PATCH"]) {
|
|
247
|
+
const res = await api(method, `/api/schedules/${id}`, {
|
|
248
|
+
profile: "sp-claude-opus",
|
|
249
|
+
modelTier: "smart",
|
|
250
|
+
});
|
|
251
|
+
expect(res.status).toBe(400);
|
|
252
|
+
expect(String(res.body.error)).toContain("not both");
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("a new profile, or a move to an agent that fails it, is re-checked", async () => {
|
|
257
|
+
const created = await api("POST", "/api/schedules", base({ targetAgentId: codexId }));
|
|
258
|
+
const codexSchedule = created.body.id as string;
|
|
259
|
+
const refused = await api("PUT", `/api/schedules/${codexSchedule}`, {
|
|
260
|
+
profile: "sp-claude-opus",
|
|
261
|
+
});
|
|
262
|
+
expect(refused.status).toBe(400);
|
|
263
|
+
expect(String(refused.body.error)).toContain("fails harness");
|
|
264
|
+
|
|
265
|
+
const profiled = await api(
|
|
266
|
+
"POST",
|
|
267
|
+
"/api/schedules",
|
|
268
|
+
base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
|
|
269
|
+
);
|
|
270
|
+
const id = profiled.body.id as string;
|
|
271
|
+
for (const method of ["PUT", "PATCH"]) {
|
|
272
|
+
const moved = await api(method, `/api/schedules/${id}`, { targetAgentId: codexId });
|
|
273
|
+
expect(moved.status).toBe(400);
|
|
274
|
+
expect(String(moved.body.error)).toContain("fails harness");
|
|
275
|
+
}
|
|
276
|
+
const unrelated = await api("PATCH", `/api/schedules/${id}`, { description: "still claude" });
|
|
277
|
+
expect(unrelated.status).toBe(200);
|
|
278
|
+
expect(unrelated.body.profile).toBe("sp-claude-opus");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("an unknown profile on update is a 400", async () => {
|
|
282
|
+
const created = await api("POST", "/api/schedules", base());
|
|
283
|
+
const res = await api("PATCH", `/api/schedules/${created.body.id}`, {
|
|
284
|
+
profile: "sp-no-such-profile",
|
|
285
|
+
});
|
|
286
|
+
expect(res.status).toBe(400);
|
|
287
|
+
expect(String(res.body.error)).toContain("Unknown model profile");
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("schedule reference guard", () => {
|
|
292
|
+
test("a profile a schedule names cannot be deleted", async () => {
|
|
293
|
+
await createScheduledTask({
|
|
294
|
+
name: scheduleName(),
|
|
295
|
+
intervalMs: 3_600_000,
|
|
296
|
+
taskTemplate: "tick",
|
|
297
|
+
profile: "sp-claude-held",
|
|
298
|
+
});
|
|
299
|
+
expect(await deleteModelProfile("sp-claude-held")).toBe("in-use");
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe("MCP tool parity", () => {
|
|
304
|
+
test("create-schedule: passing agent saves, failing agent and profile+model refuse", async () => {
|
|
305
|
+
const ok = await tool("create-schedule", {
|
|
306
|
+
...base({ targetAgentId: claudeId, profile: "sp-claude-opus" }),
|
|
307
|
+
});
|
|
308
|
+
expect(ok.success).toBe(true);
|
|
309
|
+
expect(ok.schedule?.profile).toBe("sp-claude-opus");
|
|
310
|
+
|
|
311
|
+
const failing = await tool("create-schedule", {
|
|
312
|
+
...base({ targetAgentId: codexId, profile: "sp-claude-opus" }),
|
|
313
|
+
});
|
|
314
|
+
expect(failing.success).toBe(false);
|
|
315
|
+
expect(failing.message).toContain("fails harness");
|
|
316
|
+
|
|
317
|
+
const both = await tool("create-schedule", {
|
|
318
|
+
...base({ targetAgentId: claudeId, profile: "sp-claude-opus", modelTier: "smart" }),
|
|
319
|
+
});
|
|
320
|
+
expect(both.success).toBe(false);
|
|
321
|
+
expect(both.message).toContain("not both");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
for (const name of ["update-schedule", "patch-schedule"]) {
|
|
325
|
+
test(`${name}: setting profile clears modelTier, the reverse clears profile, a fail refuses`, async () => {
|
|
326
|
+
const schedule = await createScheduledTask({
|
|
327
|
+
name: scheduleName(),
|
|
328
|
+
intervalMs: 3_600_000,
|
|
329
|
+
taskTemplate: "tick",
|
|
330
|
+
targetAgentId: claudeId,
|
|
331
|
+
modelTier: "smart",
|
|
332
|
+
createdByAgentId: claudeId,
|
|
333
|
+
});
|
|
334
|
+
const set = await tool(name, { scheduleId: schedule.id, profile: "sp-claude-opus" });
|
|
335
|
+
expect(set.success).toBe(true);
|
|
336
|
+
let row = await getScheduledTaskById(schedule.id);
|
|
337
|
+
expect(row?.profile).toBe("sp-claude-opus");
|
|
338
|
+
expect(row?.modelTier).toBeUndefined();
|
|
339
|
+
|
|
340
|
+
const both = await tool(name, {
|
|
341
|
+
scheduleId: schedule.id,
|
|
342
|
+
profile: "sp-claude-opus",
|
|
343
|
+
model: "opus",
|
|
344
|
+
});
|
|
345
|
+
expect(both.success).toBe(false);
|
|
346
|
+
expect(both.message).toContain("not both");
|
|
347
|
+
|
|
348
|
+
const moved = await tool(name, { scheduleId: schedule.id, targetAgentId: codexId });
|
|
349
|
+
expect(moved.success).toBe(false);
|
|
350
|
+
expect(moved.message).toContain("fails harness");
|
|
351
|
+
|
|
352
|
+
const back = await tool(name, { scheduleId: schedule.id, modelTier: "regular" });
|
|
353
|
+
expect(back.success).toBe(true);
|
|
354
|
+
row = await getScheduledTaskById(schedule.id);
|
|
355
|
+
expect(row?.modelTier).toBe("regular");
|
|
356
|
+
expect(row?.profile).toBeUndefined();
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
});
|
|
@@ -685,6 +685,12 @@ describe("script connections", () => {
|
|
|
685
685
|
// 278 indexes agent_tasks columns and alters slack_messages, neither of
|
|
686
686
|
// which this fixture's partial schema has.
|
|
687
687
|
markMigrationApplied(database, "278_slack_render_v2_reconcile.sql");
|
|
688
|
+
// 279 backfills agent_memory, which this migration-112-only fixture does not create.
|
|
689
|
+
markMigrationApplied(database, "279_backfill_learning_expiry.sql");
|
|
690
|
+
// 281 alters model_profiles (made by the skipped 220) and scheduled_tasks.
|
|
691
|
+
markMigrationApplied(database, "281_model_profiles_pr2.sql");
|
|
692
|
+
// 283 alters workflow_runs, which this fixture does not create.
|
|
693
|
+
markMigrationApplied(database, "283_workflow_run_definitions.sql");
|
|
688
694
|
|
|
689
695
|
const id = crypto.randomUUID();
|
|
690
696
|
const now = new Date().toISOString();
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { NativeScriptExecutor } from "../scripts-runtime/executors/native";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_SCRIPT_RESOURCES,
|
|
5
|
+
type ExecutorInput,
|
|
6
|
+
UNAWAITED_WORK_DRAIN_MS,
|
|
7
|
+
} from "../scripts-runtime/executors/types";
|
|
8
|
+
import { SKIP_SANDBOX_SPAWN_TESTS } from "./sandbox-spawn-test-helpers";
|
|
9
|
+
|
|
10
|
+
// A native run used to stay open until every call the script started had
|
|
11
|
+
// settled, even after its default export resolved. A parent that raced a slow
|
|
12
|
+
// nested `ctx.swarm.script_run` against a 100 ms deadline therefore still ran
|
|
13
|
+
// to the 30 s wall, was classified `timeout`, and lost its result. These tests
|
|
14
|
+
// drive the real swarm-sdk against a stand-in API: the nested script_run
|
|
15
|
+
// request is held open for 40 s, like a child that sleeps 40 s.
|
|
16
|
+
|
|
17
|
+
const CHILD_HOLD_MS = 40_000;
|
|
18
|
+
// The production wall. Keeping it here makes the old behaviour fail this file
|
|
19
|
+
// the same way the measured runs failed: at 30 s, with error "timeout".
|
|
20
|
+
const WALL_CLOCK_MS = DEFAULT_SCRIPT_RESOURCES.wallClockMs;
|
|
21
|
+
const TEST_BUDGET_MS = WALL_CLOCK_MS + 15_000;
|
|
22
|
+
|
|
23
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
24
|
+
const held = new Set<() => void>();
|
|
25
|
+
let scriptRunRequests = 0;
|
|
26
|
+
let kvWrites: Array<{ path: string; body: unknown }> = [];
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
server = Bun.serve({
|
|
30
|
+
port: 0,
|
|
31
|
+
async fetch(req) {
|
|
32
|
+
const url = new URL(req.url);
|
|
33
|
+
if (req.method === "POST" && url.pathname === "/api/scripts/run") {
|
|
34
|
+
scriptRunRequests++;
|
|
35
|
+
await new Promise<void>((resolve) => {
|
|
36
|
+
const release = () => {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
held.delete(release);
|
|
39
|
+
resolve();
|
|
40
|
+
};
|
|
41
|
+
const timer = setTimeout(release, CHILD_HOLD_MS);
|
|
42
|
+
held.add(release);
|
|
43
|
+
});
|
|
44
|
+
return Response.json({ result: "child-finished" });
|
|
45
|
+
}
|
|
46
|
+
if (req.method === "PUT" && url.pathname.startsWith("/api/kv/")) {
|
|
47
|
+
const body = await req.json();
|
|
48
|
+
// Answer slowly so the write is still in flight when the script returns.
|
|
49
|
+
await Bun.sleep(300);
|
|
50
|
+
kvWrites.push({ path: url.pathname, body });
|
|
51
|
+
return Response.json({ ok: true });
|
|
52
|
+
}
|
|
53
|
+
return new Response("not found", { status: 404 });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterAll(() => {
|
|
59
|
+
for (const release of [...held]) release();
|
|
60
|
+
server.stop(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
scriptRunRequests = 0;
|
|
65
|
+
kvWrites = [];
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function input(source: string): ExecutorInput {
|
|
69
|
+
return {
|
|
70
|
+
source,
|
|
71
|
+
args: {},
|
|
72
|
+
configPayload: {
|
|
73
|
+
system: {
|
|
74
|
+
apiKey: { value: "drain-test-secret", isSecret: true },
|
|
75
|
+
agentId: { value: "00000000-0000-4000-8000-000000000001", isSecret: false },
|
|
76
|
+
mcpBaseUrl: { value: `http://127.0.0.1:${server.port}`, isSecret: false },
|
|
77
|
+
},
|
|
78
|
+
user: {},
|
|
79
|
+
},
|
|
80
|
+
resources: { ...DEFAULT_SCRIPT_RESOURCES, memoryMb: 2048, wallClockMs: WALL_CLOCK_MS },
|
|
81
|
+
fsMode: "none",
|
|
82
|
+
network: "open",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const spawnTest = test.skipIf(SKIP_SANDBOX_SPAWN_TESTS);
|
|
87
|
+
|
|
88
|
+
describe("native run settles when the entry function resolves", () => {
|
|
89
|
+
spawnTest(
|
|
90
|
+
"a Promise.race deadline bounds a run whose nested script_run is still pending",
|
|
91
|
+
async () => {
|
|
92
|
+
const output = await new NativeScriptExecutor().run(
|
|
93
|
+
input(`
|
|
94
|
+
export default async (_args, ctx) => {
|
|
95
|
+
const child = ctx.swarm
|
|
96
|
+
.script_run({ source: "export default async () => { await Bun.sleep(40000); return 1; }", args: {} })
|
|
97
|
+
.then(() => "child");
|
|
98
|
+
const deadline = new Promise((resolve) => setTimeout(() => resolve("deadline"), 100));
|
|
99
|
+
return { winner: await Promise.race([child, deadline]) };
|
|
100
|
+
};
|
|
101
|
+
`),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(scriptRunRequests).toBe(1);
|
|
105
|
+
expect(output.error).toBeUndefined();
|
|
106
|
+
expect(output.exitCode).toBe(0);
|
|
107
|
+
expect(output.result).toEqual({ winner: "deadline" });
|
|
108
|
+
expect(output.durationMs).toBeLessThan(5_000);
|
|
109
|
+
expect(output.stderr).toContain("un-awaited calls were still pending");
|
|
110
|
+
},
|
|
111
|
+
TEST_BUDGET_MS,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
spawnTest(
|
|
115
|
+
"an un-awaited kv_set still lands, and a run with nothing pending exits without waiting",
|
|
116
|
+
async () => {
|
|
117
|
+
const output = await new NativeScriptExecutor().run(
|
|
118
|
+
input(`
|
|
119
|
+
export default async (_args, ctx) => {
|
|
120
|
+
// Fired without await: the request is in flight when the script returns.
|
|
121
|
+
void ctx.swarm.kv_set({ key: "fired-at-return", value: "a" });
|
|
122
|
+
// Started later, still inside the drain window.
|
|
123
|
+
void (async () => {
|
|
124
|
+
await Bun.sleep(500);
|
|
125
|
+
await ctx.swarm.kv_set({ key: "fired-after-500ms", value: "b" });
|
|
126
|
+
})();
|
|
127
|
+
return "returned";
|
|
128
|
+
};
|
|
129
|
+
`),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(output.error).toBeUndefined();
|
|
133
|
+
expect(output.result).toBe("returned");
|
|
134
|
+
expect(kvWrites.map((w) => w.path).sort()).toEqual([
|
|
135
|
+
"/api/kv/fired-after-500ms",
|
|
136
|
+
"/api/kv/fired-at-return",
|
|
137
|
+
]);
|
|
138
|
+
// Both writes settled on their own, so the drain timer never fired.
|
|
139
|
+
expect(output.stderr).not.toContain("un-awaited calls were still pending");
|
|
140
|
+
expect(output.durationMs).toBeLessThan(UNAWAITED_WORK_DRAIN_MS + 2_000);
|
|
141
|
+
},
|
|
142
|
+
TEST_BUDGET_MS,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
spawnTest(
|
|
146
|
+
"an un-awaited call that starts after the drain window is stopped and reported",
|
|
147
|
+
async () => {
|
|
148
|
+
const output = await new NativeScriptExecutor().run(
|
|
149
|
+
input(`
|
|
150
|
+
export default async (_args, ctx) => {
|
|
151
|
+
void (async () => {
|
|
152
|
+
await Bun.sleep(${UNAWAITED_WORK_DRAIN_MS + 1_500});
|
|
153
|
+
await ctx.swarm.kv_set({ key: "too-late", value: "c" });
|
|
154
|
+
})();
|
|
155
|
+
return "returned";
|
|
156
|
+
};
|
|
157
|
+
`),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(output.error).toBeUndefined();
|
|
161
|
+
expect(output.result).toBe("returned");
|
|
162
|
+
expect(kvWrites).toEqual([]);
|
|
163
|
+
expect(output.stderr).toContain("un-awaited calls were still pending");
|
|
164
|
+
},
|
|
165
|
+
TEST_BUDGET_MS,
|
|
166
|
+
);
|
|
167
|
+
});
|
|
@@ -347,6 +347,7 @@ describe("scripts DB & runSavedScriptAsAgent executor persistence (#2013)", () =
|
|
|
347
347
|
const wfExecutor = new SwarmScriptExecutor({
|
|
348
348
|
db: {
|
|
349
349
|
getWorkflow: async () => null,
|
|
350
|
+
getRunWorkflow: async () => null,
|
|
350
351
|
} as never,
|
|
351
352
|
eventBus: { emit: () => {} } as never,
|
|
352
353
|
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outer `success` on generic MCP bridge calls. The bridge answers HTTP 200 with
|
|
3
|
+
* the tool's structuredContent, so a tool refusal (toolErr) arrives as 200 with
|
|
4
|
+
* `data.success === false`. The SDK must surface that as outer `success: false`
|
|
5
|
+
* while leaving `status` and `data` untouched, mirror the refusal `message`,
|
|
6
|
+
* and must not throw.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
10
|
+
import { unlink } from "node:fs/promises";
|
|
11
|
+
import { createServer as createHttpServer, type Server } from "node:http";
|
|
12
|
+
import { closeDb, createAgent, initDb } from "../be/db";
|
|
13
|
+
import { handleMcpBridge } from "../http/mcp-bridge";
|
|
14
|
+
import { getPathSegments, parseQueryParams } from "../http/utils";
|
|
15
|
+
import { SwarmConfig } from "../scripts-runtime/swarm-config";
|
|
16
|
+
import { createSwarmSdk } from "../scripts-runtime/swarm-sdk";
|
|
17
|
+
import { listenOnFreePort } from "./test-net";
|
|
18
|
+
|
|
19
|
+
const TEST_DB_PATH = "./test-scripts-sdk-bridge-tool-failure.sqlite";
|
|
20
|
+
const API_KEY = "example-scripts-sdk-bridge-tool-failure-key-1234567890";
|
|
21
|
+
let baseUrl = "";
|
|
22
|
+
let server: Server;
|
|
23
|
+
|
|
24
|
+
async function removeDbFiles(path: string): Promise<void> {
|
|
25
|
+
for (const suffix of ["", "-wal", "-shm"]) {
|
|
26
|
+
await unlink(path + suffix).catch(() => {});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sdkFor(agentId: string, mcpBaseUrl: string) {
|
|
31
|
+
return createSwarmSdk(
|
|
32
|
+
new SwarmConfig({
|
|
33
|
+
system: {
|
|
34
|
+
apiKey: { value: API_KEY, isSecret: true },
|
|
35
|
+
agentId: { value: agentId, isSecret: false },
|
|
36
|
+
mcpBaseUrl: { value: mcpBaseUrl, isSecret: false },
|
|
37
|
+
},
|
|
38
|
+
user: {},
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Serves one fixed bridge response, to pin the SDK's mapping per body shape. */
|
|
44
|
+
async function withBridgeStub<T>(
|
|
45
|
+
body: unknown,
|
|
46
|
+
status: number,
|
|
47
|
+
fn: (url: string) => Promise<T>,
|
|
48
|
+
): Promise<T> {
|
|
49
|
+
const stub = Bun.serve({
|
|
50
|
+
port: 0,
|
|
51
|
+
fetch: () => Response.json(body, { status }),
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
return await fn(`http://127.0.0.1:${stub.port}`);
|
|
55
|
+
} finally {
|
|
56
|
+
stub.stop(true);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
beforeAll(async () => {
|
|
61
|
+
await removeDbFiles(TEST_DB_PATH);
|
|
62
|
+
initDb(TEST_DB_PATH);
|
|
63
|
+
server = createHttpServer(async (req, res) => {
|
|
64
|
+
const myAgentId = (req.headers["x-agent-id"] as string | undefined) ?? undefined;
|
|
65
|
+
const segments = getPathSegments(req.url ?? "");
|
|
66
|
+
const query = parseQueryParams(req.url ?? "");
|
|
67
|
+
if (await handleMcpBridge(req, res, segments, query, myAgentId)) return;
|
|
68
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
69
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
70
|
+
});
|
|
71
|
+
const port = await listenOnFreePort(server);
|
|
72
|
+
baseUrl = `http://localhost:${port}`;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
afterAll(async () => {
|
|
76
|
+
await new Promise<void>((resolve) => {
|
|
77
|
+
server.close(() => resolve());
|
|
78
|
+
});
|
|
79
|
+
closeDb();
|
|
80
|
+
await removeDbFiles(TEST_DB_PATH);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("generic MCP bridge: tool refusal sets outer success false", () => {
|
|
84
|
+
test("skill_update with the wrong id field is a refusal, not a success", async () => {
|
|
85
|
+
const agentId = crypto.randomUUID();
|
|
86
|
+
await createAgent({
|
|
87
|
+
id: agentId,
|
|
88
|
+
name: "bridge-failure-agent",
|
|
89
|
+
isLead: false,
|
|
90
|
+
status: "idle",
|
|
91
|
+
capabilities: [],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = (await sdkFor(agentId, baseUrl).skill_update({
|
|
95
|
+
id: crypto.randomUUID(),
|
|
96
|
+
})) as { success: boolean; status: number; data: Record<string, unknown> };
|
|
97
|
+
|
|
98
|
+
expect(result.status).toBe(200);
|
|
99
|
+
expect(result.data.success).toBe(false);
|
|
100
|
+
expect(result.data.message).toBe("skillId is required.");
|
|
101
|
+
expect(result.success).toBe(false);
|
|
102
|
+
expect((result as { message?: unknown }).message).toBe("skillId is required.");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("an inner success keeps outer success true", async () => {
|
|
106
|
+
const body = { success: true, message: "Posted.", ts: "1" };
|
|
107
|
+
const result = await withBridgeStub(body, 200, (url) =>
|
|
108
|
+
sdkFor("agent-sdk", url).slack_post({ channelId: "C1", message: "hi" }),
|
|
109
|
+
);
|
|
110
|
+
expect(result).toEqual({ success: true, status: 200, data: body });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("an inner failure keeps status and data unchanged and mirrors the message", async () => {
|
|
114
|
+
const body = { success: false, message: "Channel not found." };
|
|
115
|
+
const result = await withBridgeStub(body, 200, (url) =>
|
|
116
|
+
sdkFor("agent-sdk", url).slack_post({ channelId: "C1", message: "hi" }),
|
|
117
|
+
);
|
|
118
|
+
expect(result).toEqual({
|
|
119
|
+
success: false,
|
|
120
|
+
status: 200,
|
|
121
|
+
data: body,
|
|
122
|
+
message: "Channel not found.",
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a body without a success flag follows the HTTP status", async () => {
|
|
127
|
+
const body = { result: "plain text tool output" };
|
|
128
|
+
const result = await withBridgeStub(body, 200, (url) =>
|
|
129
|
+
sdkFor("agent-sdk", url).slack_post({ channelId: "C1", message: "hi" }),
|
|
130
|
+
);
|
|
131
|
+
expect(result).toEqual({ success: true, status: 200, data: body });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("an HTTP error still reports success false without throwing", async () => {
|
|
135
|
+
const body = { error: "Tool 'x' not found in the MCP registry" };
|
|
136
|
+
const result = await withBridgeStub(body, 404, (url) =>
|
|
137
|
+
sdkFor("agent-sdk", url).slack_post({ channelId: "C1", message: "hi" }),
|
|
138
|
+
);
|
|
139
|
+
expect(result).toEqual({ success: false, status: 404, data: body });
|
|
140
|
+
});
|
|
141
|
+
});
|