@desplega.ai/agent-swarm 2.6.0 → 2.7.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 +2 -0
- package/dist/{acp-adapter-dgfakfpw.js → acp-adapter-ma1js5n7.js} +6 -6
- package/dist/{actions-fbqma8aa.js → actions-1vhmtvg9.js} +18 -18
- package/dist/{amp-adapter-en0jy6hs.js → amp-adapter-sxqqvmdk.js} +3 -3
- package/dist/{app-k8a5cgpp.js → app-mwx1d5a9.js} +3 -3
- package/dist/{assistant-a16433gr.js → assistant-yx1p6g82.js} +20 -20
- package/dist/{boot-reembed-f4nn561n.js → boot-reembed-5h37a2c2.js} +1 -1
- package/dist/{boot-reembed-6c1sjfnr.js → boot-reembed-7h78vmvv.js} +2 -1
- package/dist/{boot-scrub-sweep-d4w9gajf.js → boot-scrub-sweep-8mawd4gw.js} +3 -3
- package/dist/{boot-seeds-9bmkspyw.js → boot-seeds-ca84dhnn.js} +4 -4
- package/dist/{claude-adapter-nys1kjxa.js → claude-adapter-wqt4hfkq.js} +7 -7
- package/dist/{claude-managed-adapter-55207973.js → claude-managed-adapter-6fjqtr2z.js} +2 -2
- package/dist/{claude-managed-setup-3cm35gey.js → claude-managed-setup-rqv98sea.js} +2 -2
- package/dist/{claude-sdk-session-nw5yd8cp.js → claude-sdk-session-f29f3b2x.js} +7 -7
- package/dist/{cli-sxgtf5fw.js → cli-07q03xm2.js} +1 -1
- package/dist/{cli-k21gx5ht.js → cli-1hhbzkbb.js} +6 -6
- package/dist/{cli-v49fkghp.js → cli-1m9x8dr5.js} +1 -1
- package/dist/{cli-24j1jeeb.js → cli-2pvzmas1.js} +3 -3
- package/dist/{cli-w2656ka1.js → cli-2y7v133v.js} +7 -7
- package/dist/{cli-g8ka5j4j.js → cli-48gxjmcz.js} +94 -36
- package/dist/{cli-2sjhpsns.js → cli-54sj64fc.js} +1 -1
- package/dist/{cli-aj8djyqt.js → cli-60sty27p.js} +2 -2
- package/dist/{cli-4hxrf0p4.js → cli-6a9qfa8b.js} +308 -47
- package/dist/{cli-n7asmce6.js → cli-6mgdba42.js} +3 -3
- package/dist/{cli-gf95q3bm.js → cli-6srv653c.js} +3 -3
- package/dist/{cli-9abdgn5t.js → cli-86ehn4s5.js} +3 -3
- package/dist/{cli-bqztfyve.js → cli-8mbc9za9.js} +1 -1
- package/dist/{cli-a2rr0fmg.js → cli-8wmj18cz.js} +1 -1
- package/dist/{cli-c2habvsf.js → cli-9gsm2rzp.js} +8 -8
- package/dist/{cli-4rf0f5vg.js → cli-9pshx6rd.js} +4 -2
- package/dist/{cli-abkm71vr.js → cli-a6ds2epe.js} +1 -1
- package/dist/{cli-esakngh8.js → cli-a89zdqz9.js} +1 -1
- package/dist/{cli-3ndmpxxv.js → cli-ay40dnj3.js} +2 -2
- package/dist/{cli-kf4jree9.js → cli-aypd09nf.js} +1 -1
- package/dist/{cli-6y51ryva.js → cli-b3yzyc57.js} +1 -1
- package/dist/{cli-ag2yrnt5.js → cli-c668vvcf.js} +2 -2
- package/dist/{cli-5sckpqcx.js → cli-d20qvpr2.js} +1 -1
- package/dist/{cli-a34pr3w1.js → cli-e1595bgx.js} +2 -2
- package/dist/{cli-m70bajzr.js → cli-f12mr20z.js} +1 -1
- package/dist/{cli-dqygeeh5.js → cli-f1e0ptjj.js} +10 -1
- package/dist/{cli-mvjz5an3.js → cli-f4dbh7a5.js} +7 -7
- package/dist/{cli-az25fn5f.js → cli-gsfk58nw.js} +2 -2
- package/dist/{cli-1tem6ns9.js → cli-gt4h8cxw.js} +3 -2
- package/dist/{cli-cz37jqss.js → cli-h5jeg46p.js} +2 -2
- package/dist/{cli-emhjcj2y.js → cli-he9gbdx0.js} +60 -10
- package/dist/{cli-3fwqy71j.js → cli-j0ppywdr.js} +38 -31
- package/dist/{cli-5rj83bam.js → cli-j3y0x2n4.js} +34 -33
- package/dist/{cli-3gfvmzht.js → cli-j9bpmykh.js} +73 -25
- package/dist/{cli-m5a9m0ak.js → cli-kv7sbc2c.js} +3 -3
- package/dist/{cli-g20jjwt4.js → cli-m30k9777.js} +12 -12
- package/dist/{cli-683y0b3a.js → cli-m5e802r7.js} +2 -2
- package/dist/{cli-nn6vx2mq.js → cli-ptfq202x.js} +5 -3
- package/dist/{cli-d2dpf95n.js → cli-qj442fws.js} +1 -1
- package/dist/{cli-03gg9pd1.js → cli-rd5m70gj.js} +4 -4
- package/dist/{cli-gnsb1zxa.js → cli-s09j9vp5.js} +1 -1
- package/dist/{cli-zqne1qcj.js → cli-s0mgx214.js} +2 -2
- package/dist/{cli-sqma6vw1.js → cli-sgqm2582.js} +5 -5
- package/dist/{cli-nq677csy.js → cli-sjctjr48.js} +1 -1
- package/dist/{cli-3aqd4jaa.js → cli-twctnkng.js} +3 -3
- package/dist/{cli-j6rktc91.js → cli-v6shg7na.js} +1 -1
- package/dist/{cli-7enjwya9.js → cli-vz78s5wm.js} +1 -1
- package/dist/{cli-art7c1zh.js → cli-wqr7cea4.js} +4 -4
- package/dist/{cli-hfeb68z4.js → cli-x37r7qwf.js} +11 -3
- package/dist/{cli-ffvsj2qw.js → cli-yd2nreqw.js} +2 -2
- package/dist/{cli-ca6banwz.js → cli-ymjpkxgn.js} +6 -6
- package/dist/{cli-mtnj4fwa.js → cli-yxbsmx56.js} +5 -5
- package/dist/cli.js +18 -16
- package/dist/{codex-adapter-d95q4qsn.js → codex-adapter-zk59x2zh.js} +5 -5
- package/dist/{codex-hook-brpnycn5.js → codex-hook-xyjhvxwd.js} +1 -1
- package/dist/{codex-session-runner-gdwd8h0c.js → codex-session-runner-kh6s4j3n.js} +5 -5
- package/dist/{commands-jqmgk54b.js → commands-68et1qv2.js} +2 -2
- package/dist/{controller-z3jq589f.js → controller-fyrbnzg4.js} +2 -2
- package/dist/{controllers-connect-r2za39ef.js → controllers-connect-nep9h2xv.js} +19 -19
- package/dist/{cursor-adapter-4mr4jgkw.js → cursor-adapter-yss3pg7t.js} +1 -1
- package/dist/{db-w36wwb5g.js → db-28gjyvxj.js} +2 -2
- package/dist/{db-ppv2tze7.js → db-8ftwvzba.js} +3 -3
- package/dist/{dispatcher-pv5h77vf.js → dispatcher-hayexmkr.js} +17 -17
- package/dist/{dsh-adapter-d4pdpb3r.js → dsh-adapter-46wawff9.js} +1 -1
- package/dist/{easter-egg-3d-4sp4dvmc.js → easter-egg-3d-8d1e0h4m.js} +1 -1
- package/dist/{execute-jev839y1.js → execute-cjrfxfnm.js} +1 -1
- package/dist/{external-channel-y6nkzhnn.js → external-channel-xbmxcg09.js} +2 -2
- package/dist/{grok-adapter-t08b9ntm.js → grok-adapter-ag4wks2a.js} +7 -7
- package/dist/handlers-tzmevqb5.js +41 -0
- package/dist/{heartbeat-vn31xwdk.js → heartbeat-psfvcgwp.js} +20 -20
- package/dist/{hook-6d0zbvvt.js → hook-8pz04697.js} +5 -5
- package/dist/{hook-cpjs8q51.js → hook-cyq4mryn.js} +6 -6
- package/dist/{http-9c6medda.js → http-haj1nd6k.js} +109 -114
- package/dist/{index-qhjf2htm.js → index-jwt2bj6f.js} +261 -96
- package/dist/{index-g6k9tctj.js → index-q52f47pe.js} +1 -1
- package/dist/{index-pkma1yf8.js → index-syvhnvtw.js} +1 -1
- package/dist/{index-yqgbfgaj.js → index-y1ajx04a.js} +20 -20
- package/dist/{index-k0yt1tvq.js → index-z5h22pes.js} +17 -17
- package/dist/{index-38t35h0n.js → index-zyq8ct52.js} +17 -17
- package/dist/{keepalive-em0117bp.js → keepalive-xdvsamvj.js} +3 -3
- package/dist/{lead-23e7z59t.js → lead-hqg57kdp.js} +35 -35
- package/dist/{maintenance-kbme3qy9.js → maintenance-4y2xzh3a.js} +1 -1
- package/dist/{oauth-refresh-sweep-xysj4yse.js → oauth-refresh-sweep-jd4r7zbs.js} +8 -3
- package/dist/{onboard-p6q0vz97.js → onboard-18447q9q.js} +5 -5
- package/dist/{opencode-adapter-esv3k9yn.js → opencode-adapter-26b2frdf.js} +5 -5
- package/dist/{otel-impl-54qhqh1z.js → otel-impl-f9tgr8yw.js} +1 -1
- package/dist/{pi-mono-adapter-mymbwhj0.js → pi-mono-adapter-qn6qbga1.js} +33 -12
- package/dist/{pricing-refresh-yb75wv33.js → pricing-refresh-dw2tgb53.js} +3 -3
- package/dist/{rbac-roles-1vp2mw4p.js → rbac-roles-aygm2760.js} +2 -2
- package/dist/{rbac-roles-dexhc9x8.js → rbac-roles-s4nwj2m3.js} +1 -1
- package/dist/{render-v2-tjay5hhf.js → render-v2-yfvdfr0x.js} +3 -3
- package/dist/{resume-8ayf37g5.js → resume-1bmvjbf3.js} +7 -7
- package/dist/{runtime-hqe5cqcd.js → runtime-f7tpzedy.js} +1 -1
- package/dist/{session-access-fdhp987s.js → session-access-r5garej6.js} +4 -4
- package/dist/{session-source-backfill-qgtc86z1.js → session-source-backfill-424wzv0r.js} +2 -2
- package/dist/{setup-4rrmqcq3.js → setup-8tygvxkq.js} +1 -1
- package/dist/{virtual-modules-52km00d6.js → virtual-modules-xsw323b3.js} +2 -2
- package/dist/{work-objects-p28fgd70.js → work-objects-ggnghpgf.js} +20 -20
- package/dist/{worker-e3w7vye1.js → worker-sqjd1nqf.js} +35 -35
- package/openapi.json +69 -1
- package/package.json +5 -3
- package/src/be/automation-preflight.ts +2 -0
- package/src/be/db/api-keys.ts +9 -0
- package/src/be/db/workflow-runs.ts +36 -5
- package/src/be/db.ts +80 -22
- package/src/be/memory/task-learning.ts +155 -0
- package/src/be/migrations/245_script_executor.sql +3 -0
- package/src/be/oauth-refresh-sweep.ts +2 -1
- package/src/be/scripts/boot-reembed.ts +2 -0
- package/src/be/scripts/db.ts +14 -4
- package/src/be/scripts/embeddings.ts +2 -0
- package/src/be/scripts/run-saved.ts +1 -0
- package/src/be/scripts/typecheck.ts +9 -3
- package/src/be/seed-skills/index.ts +7 -0
- package/src/commands/onboard/compose-generator.ts +5 -3
- package/src/commands/provider-credentials.ts +2 -1
- package/src/heartbeat/heartbeat.ts +14 -1
- package/src/heartbeat/script-runner-probe.ts +47 -0
- package/src/http/api-keys.ts +24 -9
- package/src/http/idempotency-key.ts +1 -1
- package/src/http/index.ts +3 -3
- package/src/http/pages-public.ts +38 -5
- package/src/http/scripts.ts +27 -0
- package/src/http/workflows.ts +10 -0
- package/src/http/x.ts +5 -0
- package/src/prompts/base-prompt.ts +21 -1
- package/src/prompts/session-templates.ts +17 -3
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +41 -11
- package/src/scheduler/scheduler.ts +2 -1
- package/src/scripts-runtime/eval-harness.ts +8 -1
- package/src/scripts-runtime/executors/native.ts +22 -16
- package/src/scripts-runtime/executors/quickjs-prelude.ts +103 -1
- package/src/scripts-runtime/executors/quickjs-runner.ts +2 -1
- package/src/scripts-runtime/executors/quickjs.ts +7 -0
- package/src/scripts-runtime/executors/registry.ts +32 -0
- package/src/scripts-runtime/executors/types.ts +7 -0
- package/src/scripts-runtime/host-validated-args.ts +133 -0
- package/src/scripts-runtime/loader.ts +30 -3
- package/src/scripts-runtime/swarm-sdk.ts +9 -2
- package/src/scripts-runtime/types/stdlib.d.ts +9 -1
- package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -1
- package/src/tests/api-key-status-by-suffix.test.ts +242 -0
- package/src/tests/base-prompt.test.ts +70 -2
- package/src/tests/community-linear-delivery-loop.test.ts +2099 -0
- package/src/tests/credential-check.test.ts +4 -2
- package/src/tests/docs-index.test.ts +135 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/fetch-resolved-env.test.ts +16 -2
- package/src/tests/heartbeat-checklist.test.ts +89 -0
- package/src/tests/heartbeat-script-runner-probe.test.ts +83 -0
- package/src/tests/oauth-refresh-sweep.test.ts +34 -1
- package/src/tests/onboard-compose.test.ts +20 -0
- package/src/tests/opencode-adapter.test.ts +2 -1
- package/src/tests/pages-frame-ancestors.test.ts +162 -0
- package/src/tests/pi-codemode.test.ts +2 -1
- package/src/tests/pi-mono-adapter.test.ts +54 -0
- package/src/tests/pi-native-mcp.test.ts +13 -1
- package/src/tests/pi-tool-exposure.test.ts +8 -8
- package/src/tests/probe-tool-schema-tokens.test.ts +144 -0
- package/src/tests/prompt-template-session.test.ts +4 -3
- package/src/tests/request-composition-derive.test.ts +329 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-executor-conformance.test.ts +36 -1
- package/src/tests/script-executor-quickjs-pool.test.ts +50 -0
- package/src/tests/script-executor-quickjs.test.ts +140 -0
- package/src/tests/script-host-validated-args-native.test.ts +196 -0
- package/src/tests/script-per-script-executor.test.ts +415 -0
- package/src/tests/scripts-external-api.test.ts +45 -0
- package/src/tests/sdk-allowlist.test.ts +3 -2
- package/src/tests/self-improvement.test.ts +4 -4
- package/src/tests/store-progress-learning.test.ts +288 -0
- package/src/tests/ui-logs-parser.test.ts +180 -0
- package/src/tests/workflow-engine-v2.test.ts +116 -1
- package/src/tests/workflow-mcp-trigger-schema.test.ts +209 -0
- package/src/tests/workflow-run-finished-event.test.ts +263 -0
- package/src/tests/workflow-swarm-script.test.ts +34 -0
- package/src/tools/script-common.ts +1 -0
- package/src/tools/script-run.ts +7 -0
- package/src/tools/script-upsert.ts +7 -0
- package/src/tools/store-progress.ts +67 -1
- package/src/tools/workflows/trigger-workflow.ts +104 -10
- package/src/types.ts +12 -1
- package/src/utils/credentials.ts +5 -2
- package/src/workflows/engine.ts +18 -16
- package/src/workflows/executors/swarm-script.ts +5 -0
- package/src/workflows/foreach-driver.ts +5 -11
- package/src/workflows/node-timeout.ts +30 -0
- package/templates/community/linear-delivery-loop/PLAYBOOK.md +323 -0
- package/templates/community/linear-delivery-loop/README.md +38 -0
- package/templates/community/linear-delivery-loop/config.example.json +31 -0
- package/templates/community/linear-delivery-loop/lead-prompt.md +34 -0
- package/templates/community/linear-delivery-loop/schedule.json +10 -0
- package/templates/community/linear-delivery-loop/scripts/linear-delivery-setup.ts +148 -0
- package/templates/community/linear-delivery-loop/scripts/linear-delivery-tick.ts +1781 -0
- package/templates/skills/swarm-docs/config.json +14 -0
- package/templates/skills/swarm-docs/content.md +144 -0
- package/dist/handlers-eqsnmv95.js +0 -41
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key status is matched by key suffix when the caller sends its pool
|
|
3
|
+
* (`GET /api/keys/available?keySuffixes=`), so two agent-scoped pools with
|
|
4
|
+
* different keys at the same index do not bench each other (issue #2425).
|
|
5
|
+
*/
|
|
6
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
7
|
+
import { unlink } from "node:fs/promises";
|
|
8
|
+
import { createServer as createHttpServer, type Server } from "node:http";
|
|
9
|
+
import {
|
|
10
|
+
closeDb,
|
|
11
|
+
getAvailableKeyIndices,
|
|
12
|
+
initDb,
|
|
13
|
+
markKeyRateLimited,
|
|
14
|
+
recordKeyRateLimitWindows,
|
|
15
|
+
} from "../be/db";
|
|
16
|
+
import { recordKeyValidation } from "../be/db/api-keys";
|
|
17
|
+
import { handleApiKeys } from "../http/api-keys";
|
|
18
|
+
import { resolveCredentialPools } from "../utils/credentials";
|
|
19
|
+
import { listenOnFreePort } from "./test-net";
|
|
20
|
+
|
|
21
|
+
const TEST_DB = `./test-api-key-status-by-suffix-${Date.now()}.sqlite`;
|
|
22
|
+
const FUTURE = () => new Date(Date.now() + 3_600_000).toISOString();
|
|
23
|
+
|
|
24
|
+
// Agent A and agent B each pool two keys; index 1 differs between them.
|
|
25
|
+
const POOL_A = ["example-key-shared", "example-key-aaaa1"];
|
|
26
|
+
const POOL_B = ["example-key-shared", "example-key-bbbb2"];
|
|
27
|
+
const suffixes = (pool: string[]) => pool.map((key) => key.slice(-5));
|
|
28
|
+
|
|
29
|
+
describe("key status by suffix", () => {
|
|
30
|
+
let server: Server;
|
|
31
|
+
let baseUrl = "";
|
|
32
|
+
|
|
33
|
+
const getAvailable = async (query: string) => {
|
|
34
|
+
const res = await fetch(`${baseUrl}/api/keys/available?${query}`);
|
|
35
|
+
return { status: res.status, body: (await res.json()) as Record<string, unknown> };
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
process.env.DB_PATH = TEST_DB;
|
|
40
|
+
initDb(TEST_DB);
|
|
41
|
+
server = createHttpServer(async (req, res) => {
|
|
42
|
+
const url = new URL(req.url || "/", "http://localhost");
|
|
43
|
+
const pathSegments = url.pathname.split("/").filter(Boolean);
|
|
44
|
+
const handled = await handleApiKeys(req, res, pathSegments, url.searchParams);
|
|
45
|
+
if (!handled) {
|
|
46
|
+
res.writeHead(404);
|
|
47
|
+
res.end();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const port = await listenOnFreePort(server);
|
|
51
|
+
baseUrl = `http://127.0.0.1:${port}`;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterAll(async () => {
|
|
55
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
56
|
+
closeDb();
|
|
57
|
+
await unlink(TEST_DB).catch(() => {});
|
|
58
|
+
await unlink(`${TEST_DB}-wal`).catch(() => {});
|
|
59
|
+
await unlink(`${TEST_DB}-shm`).catch(() => {});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a rate limit on agent A's key at index 1 does not bench agent B's key at index 1", async () => {
|
|
63
|
+
// Workers report at global scope, by suffix and index.
|
|
64
|
+
await markKeyRateLimited("OPENAI_API_KEY", "aaaa1", 1, FUTURE());
|
|
65
|
+
|
|
66
|
+
const a = await getAvailableKeyIndices("OPENAI_API_KEY", 2, "global", null, undefined, [
|
|
67
|
+
...suffixes(POOL_A),
|
|
68
|
+
]);
|
|
69
|
+
const b = await getAvailableKeyIndices("OPENAI_API_KEY", 2, "global", null, undefined, [
|
|
70
|
+
...suffixes(POOL_B),
|
|
71
|
+
]);
|
|
72
|
+
expect(a.availableIndices).toEqual([0]);
|
|
73
|
+
expect(b.availableIndices).toEqual([0, 1]);
|
|
74
|
+
|
|
75
|
+
// Control: the index read (no suffixes) still benches index 1 for everyone.
|
|
76
|
+
const legacy = await getAvailableKeyIndices("OPENAI_API_KEY", 2);
|
|
77
|
+
expect(legacy.availableIndices).toEqual([0]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("a rejection on agent A's key does not bench agent B's key at the same index", async () => {
|
|
81
|
+
await recordKeyValidation(
|
|
82
|
+
"GEMINI_API_KEY",
|
|
83
|
+
[{ keyIndex: 1, keySuffix: "aaaa1", ok: false, httpStatus: 401 }],
|
|
84
|
+
"global",
|
|
85
|
+
null,
|
|
86
|
+
{ retireAbsent: false },
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const a = await getAvailable(
|
|
90
|
+
`keyType=GEMINI_API_KEY&totalKeys=2&keySuffixes=${suffixes(POOL_A).join(",")}`,
|
|
91
|
+
);
|
|
92
|
+
const b = await getAvailable(
|
|
93
|
+
`keyType=GEMINI_API_KEY&totalKeys=2&keySuffixes=${suffixes(POOL_B).join(",")}`,
|
|
94
|
+
);
|
|
95
|
+
expect(a.body).toMatchObject({ availableIndices: [0], rejectedIndices: [1] });
|
|
96
|
+
expect(b.body).toMatchObject({ availableIndices: [0, 1], rejectedIndices: [] });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("one key in two scopes has one state, at each pool's own position", async () => {
|
|
100
|
+
// The shared key sits at index 0 for A and B, and at index 2 in a third pool.
|
|
101
|
+
await markKeyRateLimited("ANTHROPIC_API_KEY", "hared", 0, FUTURE());
|
|
102
|
+
// A row of the same key in an agent scope (for example a dashboard check) also counts.
|
|
103
|
+
await recordKeyValidation(
|
|
104
|
+
"ANTHROPIC_API_KEY",
|
|
105
|
+
[{ keyIndex: 0, keySuffix: "hared", ok: false, httpStatus: 401 }],
|
|
106
|
+
"agent",
|
|
107
|
+
"agent-b",
|
|
108
|
+
{ retireAbsent: false },
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const b = await getAvailableKeyIndices("ANTHROPIC_API_KEY", 2, "global", null, undefined, [
|
|
112
|
+
...suffixes(POOL_B),
|
|
113
|
+
]);
|
|
114
|
+
expect(b.availableIndices).toEqual([1]);
|
|
115
|
+
expect(b.rejectedIndices).toEqual([0]);
|
|
116
|
+
|
|
117
|
+
const reordered = ["example-key-ccccc", "example-key-ddddd", "example-key-shared"];
|
|
118
|
+
const c = await getAvailableKeyIndices("ANTHROPIC_API_KEY", 3, "global", null, undefined, [
|
|
119
|
+
...suffixes(reordered),
|
|
120
|
+
]);
|
|
121
|
+
expect(c.availableIndices).toEqual([0, 1]);
|
|
122
|
+
expect(c.rejectedIndices).toEqual([2]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("model window blocks map to the caller's positions", async () => {
|
|
126
|
+
const resetsAt = Math.floor(Date.now() / 1000) + 3600;
|
|
127
|
+
await recordKeyRateLimitWindows("CLAUDE_CODE_OAUTH_TOKEN", "aaaa1", 1, {
|
|
128
|
+
seven_day_opus: { status: "rejected", resetsAt, lastSeenAt: new Date().toISOString() },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const a = await getAvailableKeyIndices(
|
|
132
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
133
|
+
2,
|
|
134
|
+
"global",
|
|
135
|
+
null,
|
|
136
|
+
"opus",
|
|
137
|
+
suffixes(POOL_A),
|
|
138
|
+
);
|
|
139
|
+
const b = await getAvailableKeyIndices(
|
|
140
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
141
|
+
2,
|
|
142
|
+
"global",
|
|
143
|
+
null,
|
|
144
|
+
"opus",
|
|
145
|
+
suffixes(POOL_B),
|
|
146
|
+
);
|
|
147
|
+
expect(a.availableIndices).toEqual([0]);
|
|
148
|
+
expect(a.modelBlockedIndices).toEqual([1]);
|
|
149
|
+
expect(b.availableIndices).toEqual([0, 1]);
|
|
150
|
+
expect(b.modelBlockedIndices).toEqual([]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("two pool keys with the same suffix keep the index read: one bench does not bench both", async () => {
|
|
154
|
+
// a-same1 and b-same1 share one status row; a rate limit at index 0 must leave index 1.
|
|
155
|
+
await markKeyRateLimited("MISTRAL_API_KEY", "same1", 0, FUTURE());
|
|
156
|
+
|
|
157
|
+
const res = await getAvailable("keyType=MISTRAL_API_KEY&totalKeys=2&keySuffixes=same1,same1");
|
|
158
|
+
expect(res.body).toMatchObject({ availableIndices: [1] });
|
|
159
|
+
// Control: the index read gives the same answer.
|
|
160
|
+
const legacy = await getAvailableKeyIndices("MISTRAL_API_KEY", 2);
|
|
161
|
+
expect(legacy.availableIndices).toEqual([1]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("validation success and a rate-limit clear at global scope reach the key's agent-scoped rows", async () => {
|
|
165
|
+
const post = (path: string, body: unknown) =>
|
|
166
|
+
fetch(`${baseUrl}/api/keys/${path}`, {
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: { "Content-Type": "application/json" },
|
|
169
|
+
body: JSON.stringify(body),
|
|
170
|
+
});
|
|
171
|
+
const available = () =>
|
|
172
|
+
getAvailable(
|
|
173
|
+
`keyType=DEEPSEEK_API_KEY&totalKeys=2&keySuffixes=${suffixes(POOL_A).join(",")}`,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// 401 for aaaa1 at agent scope, then OK at global scope.
|
|
177
|
+
const keys = (ok: boolean) => [
|
|
178
|
+
{ keyIndex: 1, keySuffix: "aaaa1", ok, ...(ok ? {} : { httpStatus: 401 }) },
|
|
179
|
+
];
|
|
180
|
+
expect(
|
|
181
|
+
(
|
|
182
|
+
await post("report-validation", {
|
|
183
|
+
keyType: "DEEPSEEK_API_KEY",
|
|
184
|
+
keys: keys(false),
|
|
185
|
+
scope: "agent",
|
|
186
|
+
scopeId: "agent-a",
|
|
187
|
+
})
|
|
188
|
+
).status,
|
|
189
|
+
).toBe(200);
|
|
190
|
+
expect((await available()).body).toMatchObject({ rejectedIndices: [1] });
|
|
191
|
+
expect(
|
|
192
|
+
(await post("report-validation", { keyType: "DEEPSEEK_API_KEY", keys: keys(true) })).status,
|
|
193
|
+
).toBe(200);
|
|
194
|
+
expect((await available()).body).toMatchObject({
|
|
195
|
+
availableIndices: [0, 1],
|
|
196
|
+
rejectedIndices: [],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// A rate limit on the agent-scoped row, cleared by the worker's global-scope recheck.
|
|
200
|
+
await markKeyRateLimited("DEEPSEEK_API_KEY", "aaaa1", 1, FUTURE(), "agent", "agent-a");
|
|
201
|
+
expect((await available()).body).toMatchObject({ availableIndices: [0] });
|
|
202
|
+
const clear = await post("clear-rate-limit", {
|
|
203
|
+
keyType: "DEEPSEEK_API_KEY",
|
|
204
|
+
keySuffix: "aaaa1",
|
|
205
|
+
});
|
|
206
|
+
expect(((await clear.json()) as { cleared: boolean }).cleared).toBe(true);
|
|
207
|
+
expect((await available()).body).toMatchObject({ availableIndices: [0, 1] });
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("the route rejects a suffix list that does not match totalKeys", async () => {
|
|
211
|
+
const res = await getAvailable("keyType=OPENAI_API_KEY&totalKeys=3&keySuffixes=hared,aaaa1");
|
|
212
|
+
expect(res.status).toBe(400);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("worker key selection skips its own benched key and keeps the other pool's", async () => {
|
|
216
|
+
await markKeyRateLimited("OPENROUTER_API_KEY", "aaaa1", 1, FUTURE());
|
|
217
|
+
await markKeyRateLimited("OPENROUTER_API_KEY", "hared", 0, FUTURE());
|
|
218
|
+
|
|
219
|
+
for (let i = 0; i < 10; i++) {
|
|
220
|
+
const envA: Record<string, string | undefined> = { OPENROUTER_API_KEY: POOL_A.join(",") };
|
|
221
|
+
const [selA] = await resolveCredentialPools(envA, {
|
|
222
|
+
apiUrl: baseUrl,
|
|
223
|
+
apiKey: "test",
|
|
224
|
+
provider: "opencode",
|
|
225
|
+
model: "google/gemini-3-flash-preview",
|
|
226
|
+
});
|
|
227
|
+
// Both of A's keys are benched: best-effort fallback.
|
|
228
|
+
expect(selA!.isRateLimitFallback).toBe(true);
|
|
229
|
+
|
|
230
|
+
const envB: Record<string, string | undefined> = { OPENROUTER_API_KEY: POOL_B.join(",") };
|
|
231
|
+
const [selB] = await resolveCredentialPools(envB, {
|
|
232
|
+
apiUrl: baseUrl,
|
|
233
|
+
apiKey: "test",
|
|
234
|
+
provider: "opencode",
|
|
235
|
+
model: "google/gemini-3-flash-preview",
|
|
236
|
+
});
|
|
237
|
+
expect(selB!.isRateLimitFallback).toBe(false);
|
|
238
|
+
expect(selB!.index).toBe(1);
|
|
239
|
+
expect(envB.OPENROUTER_API_KEY).toBe("example-key-bbbb2");
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -787,12 +787,78 @@ describe("getBasePrompt: tools and skills section", () => {
|
|
|
787
787
|
);
|
|
788
788
|
});
|
|
789
789
|
|
|
790
|
+
test("pi with deferral points installed MCP servers at tool search", async () => {
|
|
791
|
+
const result = await getBasePrompt({
|
|
792
|
+
...minimalArgs,
|
|
793
|
+
provider: "pi",
|
|
794
|
+
traits: { ...localTraits, hasToolSearch: true },
|
|
795
|
+
mcpServers: ["linear"],
|
|
796
|
+
});
|
|
797
|
+
expect(result).toContain(
|
|
798
|
+
"Connected MCP servers: linear. Load their tools with your harness tool search.",
|
|
799
|
+
);
|
|
800
|
+
expect(result).not.toContain("Their tools are in your tool list.");
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
test("pi without deferral keeps installed MCP servers in the tool list", async () => {
|
|
804
|
+
const result = await getBasePrompt({
|
|
805
|
+
...minimalArgs,
|
|
806
|
+
provider: "pi",
|
|
807
|
+
traits: { ...localTraits, hasToolSearch: false },
|
|
808
|
+
mcpServers: ["linear"],
|
|
809
|
+
});
|
|
810
|
+
expect(result).toContain("Connected MCP servers: linear. Their tools are in your tool list.");
|
|
811
|
+
});
|
|
812
|
+
|
|
790
813
|
test("omits the MCP server line for an empty list", async () => {
|
|
791
814
|
const result = await getBasePrompt({ ...minimalArgs, mcpServers: [] });
|
|
792
815
|
expect(result).not.toContain("Connected MCP servers");
|
|
793
816
|
});
|
|
794
817
|
});
|
|
795
818
|
|
|
819
|
+
describe("getBasePrompt: lead docs pointer", () => {
|
|
820
|
+
const DOCS_LINE =
|
|
821
|
+
"Load the `swarm-docs` skill only when a person asks for something no skill, workflow, schedule or memory of yours covers, or asks where something is documented. Then follow its offer rules.";
|
|
822
|
+
const withDocs = [
|
|
823
|
+
{ name: "commit", description: "Create a commit" },
|
|
824
|
+
{ name: "swarm-docs", description: "docs index" },
|
|
825
|
+
];
|
|
826
|
+
|
|
827
|
+
test("renders for a lead that has the swarm-docs skill", async () => {
|
|
828
|
+
const result = await getBasePrompt({
|
|
829
|
+
...minimalArgs,
|
|
830
|
+
role: "lead",
|
|
831
|
+
traits: localTraits,
|
|
832
|
+
skillsSummary: withDocs,
|
|
833
|
+
});
|
|
834
|
+
expect(result).toContain(DOCS_LINE);
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
test("drops the line when swarm-docs is disabled for the lead", async () => {
|
|
838
|
+
const result = await getBasePrompt({
|
|
839
|
+
...minimalArgs,
|
|
840
|
+
role: "lead",
|
|
841
|
+
traits: localTraits,
|
|
842
|
+
skillsSummary: [{ name: "commit", description: "Create a commit" }],
|
|
843
|
+
});
|
|
844
|
+
expect(result).not.toContain(DOCS_LINE);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
test("renders when the skill list is unknown (claude-managed)", async () => {
|
|
848
|
+
const result = await getBasePrompt({ ...minimalArgs, role: "lead", traits: managedTraits });
|
|
849
|
+
expect(result).toContain(DOCS_LINE);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
test("never renders for a worker", async () => {
|
|
853
|
+
const result = await getBasePrompt({
|
|
854
|
+
...minimalArgs,
|
|
855
|
+
traits: localTraits,
|
|
856
|
+
skillsSummary: withDocs,
|
|
857
|
+
});
|
|
858
|
+
expect(result).not.toContain(DOCS_LINE);
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
|
|
796
862
|
// ---------------------------------------------------------------------------
|
|
797
863
|
// 10. Repository
|
|
798
864
|
// ---------------------------------------------------------------------------
|
|
@@ -1015,14 +1081,16 @@ describe("getBasePrompt: size budget", () => {
|
|
|
1015
1081
|
expect(result.length).toBeLessThan(5_750);
|
|
1016
1082
|
});
|
|
1017
1083
|
|
|
1018
|
-
|
|
1084
|
+
// The lead ceiling includes the swarm-docs pointer (~190 chars), which renders
|
|
1085
|
+
// while the skill list is still unknown.
|
|
1086
|
+
test("a fresh claude lead stays under 6,100 characters", async () => {
|
|
1019
1087
|
const result = await getBasePrompt({
|
|
1020
1088
|
...minimalArgs,
|
|
1021
1089
|
role: "lead",
|
|
1022
1090
|
name: "Cora",
|
|
1023
1091
|
traits: localTraits,
|
|
1024
1092
|
});
|
|
1025
|
-
expect(result.length).toBeLessThan(
|
|
1093
|
+
expect(result.length).toBeLessThan(6_100);
|
|
1026
1094
|
});
|
|
1027
1095
|
|
|
1028
1096
|
test("Picateclas spawn-OOM hardening: the kitchen sink stays below MAX_ARG_STRLEN", async () => {
|