@desplega.ai/agent-swarm 2.8.1 → 2.8.2
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 → acp-adapter-fqzkxyra.js} +3 -3
- package/dist/{actions-pwjpn0j6.js → actions-kxek041g.js} +17 -17
- package/dist/{amp-adapter-cq9jgj6x.js → amp-adapter-ce7jjke4.js} +1 -1
- package/dist/{app-cnfffgwg.js → app-v6zz8yh0.js} +3 -3
- package/dist/{assistant-kpn317y1.js → assistant-m0sw9xx2.js} +18 -18
- package/dist/{boot-args-schema-pbbnhmc3.js → boot-args-schema-66bk37wv.js} +1 -1
- package/dist/{boot-reembed-9m0ysxma.js → boot-reembed-edjpwsc1.js} +1 -1
- package/dist/{boot-reembed-majbn53m.js → boot-reembed-y27n09tz.js} +1 -1
- package/dist/{boot-scrub-sweep-app8g8ym.js → boot-scrub-sweep-1xc35965.js} +3 -3
- package/dist/{boot-seeds-pbtmvcjm.js → boot-seeds-7hjj91qj.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
- package/dist/{claude-adapter-wn1g3qp5.js → claude-adapter-stw7jdcf.js} +3 -3
- package/dist/{claude-managed-setup-pd47nzch.js → claude-managed-setup-y6z2perp.js} +1 -1
- package/dist/{claude-sdk-session-3a2a6589.js → claude-sdk-session-vvya8wqk.js} +3 -3
- package/dist/{cli-wk18cm92.js → cli-0cq8y6m7.js} +1 -1
- package/dist/{cli-p1w18yhx.js → cli-1pz0330a.js} +1 -1
- package/dist/{cli-d3p5vwbk.js → cli-1qkz151v.js} +3 -3
- package/dist/{cli-89cqnasv.js → cli-26ctbcdp.js} +18 -6
- package/dist/{cli-syybb0p1.js → cli-2kvhc7x8.js} +7 -7
- package/dist/{cli-93k32c37.js → cli-3e875j5p.js} +128 -41
- package/dist/{cli-k0615eh8.js → cli-3sy2xags.js} +10 -10
- package/dist/{cli-dy32zecz.js → cli-3vmb0n58.js} +1 -1
- package/dist/{cli-4r05hnqa.js → cli-4vzgeta4.js} +13 -13
- package/dist/{cli-b5rs97a6.js → cli-5y340nzn.js} +4 -4
- package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
- package/dist/{cli-jcpr5smb.js → cli-837vfs2x.js} +2 -2
- package/dist/{cli-b085njxz.js → cli-959kp5h2.js} +12 -11
- package/dist/{cli-k93bq1wq.js → cli-97ae65rz.js} +4 -4
- package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
- package/dist/{cli-bb431xey.js → cli-a0z912j7.js} +121 -33
- package/dist/{cli-k26bkr9t.js → cli-b98a65ed.js} +3 -3
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-tk7cjj8h.js → cli-dzpc6en0.js} +1 -1
- package/dist/{cli-6mma83xa.js → cli-e1p3n5gq.js} +4 -4
- package/dist/{cli-re4raaj0.js → cli-f4e8r23x.js} +1 -1
- package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
- package/dist/{cli-pcad4cb1.js → cli-f6bahpn5.js} +1 -1
- package/dist/{cli-b8e9nb04.js → cli-fpjmegdb.js} +1 -1
- package/dist/{cli-0ntbxyaa.js → cli-fwy8kfd6.js} +271 -37
- package/dist/{cli-tacge1w0.js → cli-g5mtmf6t.js} +6 -6
- package/dist/{cli-sn7rtnj4.js → cli-gyt3zydq.js} +3 -3
- package/dist/{cli-vbh10fqa.js → cli-j24zbska.js} +3 -3
- package/dist/{cli-vqptjbr7.js → cli-jdknh18m.js} +10 -10
- package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
- package/dist/{cli-9vhebtjz.js → cli-mxn1qvbn.js} +3 -2
- package/dist/{cli-zcsw143p.js → cli-n6vtrcht.js} +1 -1
- package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
- package/dist/{cli-gax7fk3t.js → cli-pfs8adn4.js} +1 -1
- package/dist/{cli-1xh9a7hn.js → cli-q24n86d2.js} +2 -2
- package/dist/{cli-7w69ne2f.js → cli-rcecc3yq.js} +167 -43
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-yn2bbre9.js → cli-rmzsadkf.js} +1 -1
- package/dist/{cli-a3b239vq.js → cli-t2tma8gb.js} +1 -1
- package/dist/{cli-9wngrawf.js → cli-tekytdq9.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
- package/dist/{cli-cyhbbd1z.js → cli-w401b9tq.js} +1 -1
- package/dist/{cli-jywyhqws.js → cli-xf3qw745.js} +3 -3
- package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
- package/dist/{cli-yncmerje.js → cli-zh9rsbqf.js} +2 -2
- package/dist/cli.js +16 -16
- package/dist/{codex-adapter-nha71q3n.js → codex-adapter-zerf5qsp.js} +1 -1
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
- package/dist/{codex-session-runner-ak9x1k1h.js → codex-session-runner-89s304py.js} +1 -1
- package/dist/{commands-f587qpq8.js → commands-jeh1b51j.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
- package/dist/{controllers-connect-k5sg9m9h.js → controllers-connect-nxa1ddwn.js} +18 -18
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
- package/dist/{db-nzf8zb5z.js → db-2dvay0es.js} +3 -3
- package/dist/{db-amm8w15a.js → db-b36qn6k3.js} +2 -2
- package/dist/{dispatcher-89zrts8f.js → dispatcher-gndbta01.js} +16 -16
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-f75sz821.js} +1 -1
- package/dist/{e2b-jkwfhbcv.js → e2b-3gpc2n3w.js} +1 -1
- package/dist/{e2b-s16txnpx.js → e2b-jbm7mj93.js} +1 -1
- package/dist/{embedding-space-ezwenjmj.js → embedding-space-4p05vb2x.js} +6 -6
- package/dist/{embeddings-np74ht6g.js → embeddings-m6768mgh.js} +1 -1
- package/dist/{external-channel-z46yx9d7.js → external-channel-gjv3jne3.js} +2 -2
- package/dist/{fx-adapter-3q12snn6.js → fx-adapter-rpsgb1tw.js} +4 -4
- package/dist/{grok-adapter-ahb1w033.js → grok-adapter-n2m3zjg1.js} +4 -4
- package/dist/handlers-nv8edn19.js +32 -0
- package/dist/{heartbeat-dt9qw9c8.js → heartbeat-a1tv60gt.js} +19 -19
- package/dist/{hook-8k6fbz9b.js → hook-8h5dzcgq.js} +2 -2
- package/dist/{hook-jgcgygex.js → hook-cyaps9ba.js} +4 -4
- package/dist/{http-haw4r8ne.js → http-t15mhbd9.js} +1731 -77
- package/dist/{index-s4ewdma4.js → index-ksmyd6kc.js} +16 -16
- package/dist/{index-tez78qj3.js → index-qav6455f.js} +13 -11
- package/dist/index-rjnrje98.js +32 -0
- package/dist/index-tv3413wy.js +33 -0
- package/dist/{index-5gk12my8.js → index-w1zqf680.js} +1 -1
- package/dist/{keepalive-xn6s7rmg.js → keepalive-91s7hzrb.js} +3 -3
- package/dist/{lead-6ygbfhbh.js → lead-3hmddvrm.js} +30 -30
- package/dist/{maintenance-vdts800b.js → maintenance-7pjmy5xy.js} +1 -1
- package/dist/{oauth-refresh-sweep-094c8wfk.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
- package/dist/{onboard-v99eh56m.js → onboard-74st7pag.js} +3 -3
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
- package/dist/{otel-impl-q7yr9yp0.js → otel-impl-rnzey8cb.js} +1 -1
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-6mkwq64n.js} +3 -2
- package/dist/{pricing-refresh-7dh2yase.js → pricing-refresh-ha21jhk7.js} +2 -2
- package/dist/{rbac-roles-npbmdh77.js → rbac-roles-59dxachk.js} +2 -2
- package/dist/{rbac-roles-mdmc96p4.js → rbac-roles-wqhma4dr.js} +3 -3
- package/dist/{render-v2-twhhwmms.js → render-v2-14kpzx12.js} +3 -3
- package/dist/{resume-5gsrjd5e.js → resume-gsa5fb5f.js} +6 -6
- package/dist/{session-access-m191x30x.js → session-access-skm7bnp6.js} +4 -4
- package/dist/{session-source-backfill-nt923ask.js → session-source-backfill-pbqzbncv.js} +2 -2
- package/dist/{setup-wv467afy.js → setup-5yermsem.js} +1 -1
- package/dist/{work-objects-8zkrpy13.js → work-objects-xj0ck0w4.js} +19 -19
- package/dist/{worker-follow-up-cecqszem.js → worker-follow-up-911xc0b8.js} +18 -16
- package/dist/{worker-mz5z7kj0.js → worker-qgg0m2gw.js} +30 -30
- package/openapi.json +1741 -290
- package/package.json +2 -2
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +20 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +9 -3
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- package/src/be/model-profile-check.ts +43 -18
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +182 -0
- package/src/be/savings/model.ts +406 -0
- package/src/be/scripts/typecheck.ts +5 -0
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- package/src/be/skill-parser.ts +19 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +99 -17
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +4 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +1 -0
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +363 -0
- package/src/http/tasks.ts +46 -4
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/codex-adapter.ts +3 -0
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- package/src/scripts-runtime/sdk-allowlist.ts +11 -1
- package/src/scripts-runtime/swarm-sdk.ts +6 -0
- package/src/scripts-runtime/types/stdlib.d.ts +9 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +34 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -0
- package/src/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- package/src/tests/codex-adapter.test.ts +11 -0
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- package/src/tests/deploy-guard.test.ts +154 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compute.test.ts +406 -0
- package/src/tests/savings-model.test.ts +287 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/sdk-allowlist.test.ts +40 -0
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +115 -33
- package/src/utils/constants.ts +2 -0
- package/templates/skills/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- package/dist/handlers-vbww69re.js +0 -32
- package/dist/index-4xwaf5th.js +0 -32
- package/dist/index-f0hcrs8e.js +0 -33
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starting the Linear / Jira tracker OAuth flow is an admin action: the
|
|
3
|
+
* resulting tokens land on the swarm-wide `default` authorization (and Jira
|
|
4
|
+
* also persists the consenting account's cloudId). The authorize routes must
|
|
5
|
+
* therefore sit behind the API bearer plus the `oauth-authorization.manage`
|
|
6
|
+
* permission, while the provider callbacks stay public and state-bound.
|
|
7
|
+
*
|
|
8
|
+
* The test drives the real `handleCore` auth gate and the real tracker
|
|
9
|
+
* handlers in-process, against a loopback mock token endpoint.
|
|
10
|
+
*/
|
|
11
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
12
|
+
import { unlink } from "node:fs/promises";
|
|
13
|
+
import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
|
14
|
+
import { closeDb, createAgent, createUser, getDbClient, initDb } from "../be/db";
|
|
15
|
+
import { getOAuthTokens, storeOAuthTokens, upsertOAuthApp } from "../be/db-queries/oauth";
|
|
16
|
+
import { type IdentityActor, mintSessionToken, mintToken } from "../be/users";
|
|
17
|
+
import { handleCore } from "../http/core";
|
|
18
|
+
import { handleTrackers } from "../http/trackers";
|
|
19
|
+
import { getPathSegments } from "../http/utils";
|
|
20
|
+
import { getJiraMetadata, updateJiraMetadata } from "../jira/metadata";
|
|
21
|
+
import { listenOnFreePort } from "./test-net";
|
|
22
|
+
|
|
23
|
+
const TEST_DB_PATH = "./test-tracker-oauth-authorize-auth.sqlite";
|
|
24
|
+
const API_KEY = "example-tracker-authorize-api-key";
|
|
25
|
+
const LEAD_ID = "aaaa9200-0000-4000-8000-000000000001";
|
|
26
|
+
const WORKER_ID = "aaaa9200-0000-4000-8000-000000000002";
|
|
27
|
+
const ACTOR: IdentityActor = { kind: "operator", id: "tracker-oauth-authorize-auth-test" };
|
|
28
|
+
|
|
29
|
+
// Token value A is what the swarm holds; B is what the mock provider issues.
|
|
30
|
+
const TOKEN_A = { linear: "example-linear-token-a", jira: "example-jira-token-a" } as const;
|
|
31
|
+
const TOKEN_B = { linear: "example-linear-token-b", jira: "example-jira-token-b" } as const;
|
|
32
|
+
const CLOUD_A = { cloudId: "cloud-a", siteUrl: "https://site-a.example.test" };
|
|
33
|
+
const CLOUD_B = { cloudId: "cloud-b", siteUrl: "https://site-b.example.test" };
|
|
34
|
+
|
|
35
|
+
type Provider = "linear" | "jira";
|
|
36
|
+
|
|
37
|
+
let providerServer: ReturnType<typeof Bun.serve>;
|
|
38
|
+
let providerBase = "";
|
|
39
|
+
let appServer: Server;
|
|
40
|
+
let appBase = "";
|
|
41
|
+
let userId = "";
|
|
42
|
+
let userToken = "";
|
|
43
|
+
let leadSessionToken = "";
|
|
44
|
+
let workerSessionToken = "";
|
|
45
|
+
|
|
46
|
+
const ENV_KEYS = [
|
|
47
|
+
"LINEAR_CLIENT_ID",
|
|
48
|
+
"LINEAR_DISABLE",
|
|
49
|
+
"LINEAR_ENABLED",
|
|
50
|
+
"JIRA_CLIENT_ID",
|
|
51
|
+
"JIRA_DISABLE",
|
|
52
|
+
"JIRA_ENABLED",
|
|
53
|
+
] as const;
|
|
54
|
+
const savedEnv = new Map<string, string | undefined>();
|
|
55
|
+
const originalFetch = globalThis.fetch;
|
|
56
|
+
|
|
57
|
+
function appServerFor(): Server {
|
|
58
|
+
return createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
|
59
|
+
const myAgentId = req.headers["x-agent-id"] as string | undefined;
|
|
60
|
+
if (await handleCore(req, res, myAgentId, API_KEY)) return;
|
|
61
|
+
if (await handleTrackers(req, res, getPathSegments(req.url || ""))) return;
|
|
62
|
+
res.writeHead(404);
|
|
63
|
+
res.end("not found");
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function seedDefaultAuthorizations(): Promise<void> {
|
|
68
|
+
const future = new Date(Date.now() + 3_600_000).toISOString();
|
|
69
|
+
for (const provider of ["linear", "jira"] as const) {
|
|
70
|
+
await storeOAuthTokens(provider, {
|
|
71
|
+
accessToken: TOKEN_A[provider],
|
|
72
|
+
refreshToken: `${TOKEN_A[provider]}-refresh`,
|
|
73
|
+
expiresAt: future,
|
|
74
|
+
scope: "read",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
await updateJiraMetadata(CLOUD_A);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Run the full authorize → provider consent → callback dance as `headers`. */
|
|
81
|
+
async function runOAuthDance(provider: Provider, headers: Record<string, string>) {
|
|
82
|
+
const authorize = await originalFetch(`${appBase}/api/trackers/${provider}/authorize`, {
|
|
83
|
+
headers,
|
|
84
|
+
redirect: "manual",
|
|
85
|
+
});
|
|
86
|
+
const location = authorize.headers.get("location");
|
|
87
|
+
const state = location ? new URL(location).searchParams.get("state") : null;
|
|
88
|
+
let callbackStatus: number | null = null;
|
|
89
|
+
if (state) {
|
|
90
|
+
// The provider sends the browser back with a code and the state; no bearer.
|
|
91
|
+
const callback = await originalFetch(
|
|
92
|
+
`${appBase}/api/trackers/${provider}/callback?code=example-code&state=${encodeURIComponent(state)}`,
|
|
93
|
+
{ redirect: "manual" },
|
|
94
|
+
);
|
|
95
|
+
callbackStatus = callback.status;
|
|
96
|
+
await callback.text();
|
|
97
|
+
} else {
|
|
98
|
+
await authorize.text();
|
|
99
|
+
}
|
|
100
|
+
return { authorizeStatus: authorize.status, state, callbackStatus };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
beforeAll(async () => {
|
|
104
|
+
for (const key of ENV_KEYS) savedEnv.set(key, process.env[key]);
|
|
105
|
+
process.env.LINEAR_CLIENT_ID = "example-linear-client";
|
|
106
|
+
process.env.JIRA_CLIENT_ID = "example-jira-client";
|
|
107
|
+
for (const key of ["LINEAR_DISABLE", "LINEAR_ENABLED", "JIRA_DISABLE", "JIRA_ENABLED"]) {
|
|
108
|
+
delete process.env[key];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await unlink(TEST_DB_PATH).catch(() => {});
|
|
112
|
+
initDb(TEST_DB_PATH);
|
|
113
|
+
await createAgent({ id: LEAD_ID, name: "tracker-lead", isLead: true, status: "idle" });
|
|
114
|
+
await createAgent({ id: WORKER_ID, name: "tracker-worker", isLead: false, status: "idle" });
|
|
115
|
+
const user = await createUser({ name: "Tracker Admin", email: "tracker-admin@example.test" });
|
|
116
|
+
userId = user.id;
|
|
117
|
+
userToken = (await mintToken(user.id, "tracker-admin", ACTOR)).plaintext;
|
|
118
|
+
// Per-agent session tokens: the shared swarm key alone resolves to the operator.
|
|
119
|
+
leadSessionToken = (await mintSessionToken(LEAD_ID, crypto.randomUUID(), 60_000)).plaintext;
|
|
120
|
+
workerSessionToken = (await mintSessionToken(WORKER_ID, crypto.randomUUID(), 60_000)).plaintext;
|
|
121
|
+
|
|
122
|
+
providerServer = Bun.serve({
|
|
123
|
+
port: 0,
|
|
124
|
+
async fetch(req) {
|
|
125
|
+
const url = new URL(req.url);
|
|
126
|
+
const provider = url.pathname.split("/")[1] as Provider;
|
|
127
|
+
if (url.pathname.endsWith("/token") && (provider === "linear" || provider === "jira")) {
|
|
128
|
+
await req.text();
|
|
129
|
+
return Response.json({
|
|
130
|
+
access_token: TOKEN_B[provider],
|
|
131
|
+
refresh_token: `${TOKEN_B[provider]}-refresh`,
|
|
132
|
+
token_type: "Bearer",
|
|
133
|
+
expires_in: 3600,
|
|
134
|
+
scope: "read write",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return new Response("not found", { status: 404 });
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
providerBase = `http://localhost:${providerServer.port}`;
|
|
141
|
+
|
|
142
|
+
appServer = appServerFor();
|
|
143
|
+
appBase = `http://localhost:${await listenOnFreePort(appServer)}`;
|
|
144
|
+
|
|
145
|
+
// The tracker post-processing calls fixed provider hosts (Linear GraphQL for
|
|
146
|
+
// the bot user id, Atlassian accessible-resources for the cloudId). Answer
|
|
147
|
+
// them locally; everything else goes to the real fetch.
|
|
148
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
149
|
+
const url = new URL(input instanceof Request ? input.url : String(input));
|
|
150
|
+
if (url.host === "api.linear.app") {
|
|
151
|
+
return Response.json({ data: { viewer: { id: "bot-b", organization: { id: "org-b" } } } });
|
|
152
|
+
}
|
|
153
|
+
if (url.host === "api.atlassian.com" && url.pathname.endsWith("/accessible-resources")) {
|
|
154
|
+
return Response.json([{ id: CLOUD_B.cloudId, url: CLOUD_B.siteUrl, name: "b", scopes: [] }]);
|
|
155
|
+
}
|
|
156
|
+
return originalFetch(input, init);
|
|
157
|
+
}) as typeof fetch;
|
|
158
|
+
|
|
159
|
+
for (const provider of ["linear", "jira"] as const) {
|
|
160
|
+
await upsertOAuthApp(provider, {
|
|
161
|
+
clientId: `example-${provider}-client`,
|
|
162
|
+
clientSecret: `example-${provider}-client-secret`,
|
|
163
|
+
authorizeUrl: `${providerBase}/${provider}/authorize`,
|
|
164
|
+
tokenUrl: `${providerBase}/${provider}/token`,
|
|
165
|
+
redirectUri: `${appBase}/api/trackers/${provider}/callback`,
|
|
166
|
+
scopes: "read,write",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
afterAll(async () => {
|
|
172
|
+
globalThis.fetch = originalFetch;
|
|
173
|
+
for (const [key, value] of savedEnv) {
|
|
174
|
+
if (value === undefined) delete process.env[key];
|
|
175
|
+
else process.env[key] = value;
|
|
176
|
+
}
|
|
177
|
+
appServer.close();
|
|
178
|
+
await providerServer.stop(true);
|
|
179
|
+
closeDb();
|
|
180
|
+
for (const suffix of ["", "-wal", "-shm"])
|
|
181
|
+
await unlink(`${TEST_DB_PATH}${suffix}`).catch(() => {});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
beforeEach(async () => {
|
|
185
|
+
await seedDefaultAuthorizations();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("tracker OAuth authorize requires an admin bearer", () => {
|
|
189
|
+
test("an anonymous caller cannot rebind the Linear default authorization", async () => {
|
|
190
|
+
const dance = await runOAuthDance("linear", {});
|
|
191
|
+
const tokens = await getOAuthTokens("linear");
|
|
192
|
+
expect({ authorizeStatus: dance.authorizeStatus, accessToken: tokens?.accessToken }).toEqual({
|
|
193
|
+
authorizeStatus: 401,
|
|
194
|
+
accessToken: TOKEN_A.linear,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("an anonymous caller cannot rebind the Jira default authorization or cloudId", async () => {
|
|
199
|
+
const dance = await runOAuthDance("jira", {});
|
|
200
|
+
const tokens = await getOAuthTokens("jira");
|
|
201
|
+
const meta = await getJiraMetadata();
|
|
202
|
+
expect({
|
|
203
|
+
authorizeStatus: dance.authorizeStatus,
|
|
204
|
+
accessToken: tokens?.accessToken,
|
|
205
|
+
cloudId: meta.cloudId,
|
|
206
|
+
siteUrl: meta.siteUrl,
|
|
207
|
+
}).toEqual({
|
|
208
|
+
authorizeStatus: 401,
|
|
209
|
+
accessToken: TOKEN_A.jira,
|
|
210
|
+
cloudId: CLOUD_A.cloudId,
|
|
211
|
+
siteUrl: CLOUD_A.siteUrl,
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("a non-lead agent is refused", async () => {
|
|
216
|
+
for (const provider of ["linear", "jira"] as const) {
|
|
217
|
+
const res = await originalFetch(`${appBase}/api/trackers/${provider}/authorize`, {
|
|
218
|
+
headers: { Authorization: `Bearer ${workerSessionToken}` },
|
|
219
|
+
redirect: "manual",
|
|
220
|
+
});
|
|
221
|
+
expect(res.status).toBe(403);
|
|
222
|
+
await res.text();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("the lead agent can still start the flow (302 to the provider)", async () => {
|
|
227
|
+
const res = await originalFetch(`${appBase}/api/trackers/linear/authorize`, {
|
|
228
|
+
headers: { Authorization: `Bearer ${leadSessionToken}` },
|
|
229
|
+
redirect: "manual",
|
|
230
|
+
});
|
|
231
|
+
expect(res.status).toBe(302);
|
|
232
|
+
expect(res.headers.get("location")).toStartWith(`${providerBase}/linear/authorize?`);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("an admin completes the dance; the callback stays public and lands the new grant", async () => {
|
|
236
|
+
const linear = await runOAuthDance("linear", { Authorization: `Bearer ${API_KEY}` });
|
|
237
|
+
expect(linear).toMatchObject({ authorizeStatus: 302, callbackStatus: 200 });
|
|
238
|
+
expect((await getOAuthTokens("linear"))?.accessToken).toBe(TOKEN_B.linear);
|
|
239
|
+
|
|
240
|
+
const jira = await runOAuthDance("jira", { Authorization: `Bearer ${API_KEY}` });
|
|
241
|
+
expect(jira).toMatchObject({ authorizeStatus: 302, callbackStatus: 200 });
|
|
242
|
+
expect((await getOAuthTokens("jira"))?.accessToken).toBe(TOKEN_B.jira);
|
|
243
|
+
expect((await getJiraMetadata()).cloudId).toBe(CLOUD_B.cloudId);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("format=json returns the consent URL and records the initiating user", async () => {
|
|
247
|
+
for (const provider of ["linear", "jira"] as const) {
|
|
248
|
+
const res = await originalFetch(`${appBase}/api/trackers/${provider}/authorize?format=json`, {
|
|
249
|
+
headers: { Authorization: `Bearer ${userToken}` },
|
|
250
|
+
});
|
|
251
|
+
expect(res.status).toBe(200);
|
|
252
|
+
const body = (await res.json()) as { authorizeUrl: string };
|
|
253
|
+
expect(body.authorizeUrl).toStartWith(`${providerBase}/${provider}/authorize?`);
|
|
254
|
+
const state = new URL(body.authorizeUrl).searchParams.get("state");
|
|
255
|
+
const pending = await getDbClient().get<{ userId: string | null; flow: string }>(
|
|
256
|
+
"SELECT userId, flow FROM oauth_pending WHERE state = ?",
|
|
257
|
+
[state],
|
|
258
|
+
);
|
|
259
|
+
expect(pending).toEqual({ userId, flow: "tracker" });
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
|
|
1
|
+
import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import * as db from "../be/db";
|
|
@@ -20,7 +20,12 @@ import {
|
|
|
20
20
|
resolveWaitState,
|
|
21
21
|
toPinnedDefinition,
|
|
22
22
|
} from "../be/db";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getPinnedRunDefinition,
|
|
25
|
+
hashPinnedDefinition,
|
|
26
|
+
mergePinnedDefinition,
|
|
27
|
+
} from "../be/db/workflow-run-definitions";
|
|
28
|
+
import type { DbParam } from "../be/db-client";
|
|
24
29
|
import {
|
|
25
30
|
type ExecutorMeta,
|
|
26
31
|
type Workflow,
|
|
@@ -577,7 +582,14 @@ describe("pinned definition storage", () => {
|
|
|
577
582
|
expect(rowsAfter?.n).toBe(rowsBefore?.n);
|
|
578
583
|
});
|
|
579
584
|
|
|
580
|
-
test(
|
|
585
|
+
test.each([
|
|
586
|
+
"running",
|
|
587
|
+
"waiting",
|
|
588
|
+
"completed",
|
|
589
|
+
"failed",
|
|
590
|
+
"skipped",
|
|
591
|
+
"cancelled",
|
|
592
|
+
] as const)("deleteWorkflow preserves unrelated snapshots and snapshots shared with a %s run", async (status) => {
|
|
581
593
|
const wf1 = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
582
594
|
const wf2 = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
583
595
|
const run1 = await startOnA(wf1);
|
|
@@ -585,9 +597,11 @@ describe("pinned definition storage", () => {
|
|
|
585
597
|
const run3 = await startOnA(wf2);
|
|
586
598
|
const h1 = (await pinHash(run1))!;
|
|
587
599
|
const h2 = (await pinHash(run2))!;
|
|
600
|
+
const unrelated = await pinWorkflowDefinition({ ...wf1, name: "unrelated orphan" });
|
|
588
601
|
expect(h1).not.toBe(h2);
|
|
589
602
|
// A wf2 run shares wf1's snapshot row, as identical content does.
|
|
590
603
|
await getDbClient().run("UPDATE workflow_runs SET definitionHash = ? WHERE id = ?", [h1, run3]);
|
|
604
|
+
await db.updateWorkflowRun(run3, { status });
|
|
591
605
|
const exists = async (hash: string) =>
|
|
592
606
|
(await getDbClient().get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [hash])) !=
|
|
593
607
|
null;
|
|
@@ -595,10 +609,121 @@ describe("pinned definition storage", () => {
|
|
|
595
609
|
await deleteWorkflow(wf1.id);
|
|
596
610
|
expect(await exists(h1)).toBe(true);
|
|
597
611
|
expect(await exists(h2)).toBe(true);
|
|
612
|
+
expect(await exists(unrelated)).toBe(true);
|
|
598
613
|
|
|
599
614
|
await deleteWorkflow(wf2.id);
|
|
600
615
|
expect(await exists(h1)).toBe(false);
|
|
601
616
|
expect(await exists(h2)).toBe(false);
|
|
617
|
+
expect(await exists(unrelated)).toBe(true);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
test.each([
|
|
621
|
+
"no runs",
|
|
622
|
+
"unpinned run",
|
|
623
|
+
"missing workflow",
|
|
624
|
+
])("deleteWorkflow leaves unrelated snapshots alone with %s", async (scenario) => {
|
|
625
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
626
|
+
const unrelated = await pinWorkflowDefinition(workflow);
|
|
627
|
+
if (scenario === "unpinned run") {
|
|
628
|
+
await db.createWorkflowRun({ id: crypto.randomUUID(), workflowId: workflow.id });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
expect(
|
|
632
|
+
await deleteWorkflow(scenario === "missing workflow" ? crypto.randomUUID() : workflow.id),
|
|
633
|
+
).toBe(scenario !== "missing workflow");
|
|
634
|
+
expect(
|
|
635
|
+
await getDbClient().get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [unrelated]),
|
|
636
|
+
).not.toBeNull();
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("deleteWorkflow uses indexed snapshot cleanup across many definitions, including FK checks", async () => {
|
|
640
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
641
|
+
const client = getDbClient();
|
|
642
|
+
const hashes: string[] = [];
|
|
643
|
+
await client.transaction(async () => {
|
|
644
|
+
for (let version = 0; version < 121; version++) {
|
|
645
|
+
const definitionHash = await pinWorkflowDefinition({
|
|
646
|
+
...workflow,
|
|
647
|
+
description: `v${version}`,
|
|
648
|
+
});
|
|
649
|
+
hashes.push(definitionHash);
|
|
650
|
+
await db.createWorkflowRun({
|
|
651
|
+
id: crypto.randomUUID(),
|
|
652
|
+
workflowId: workflow.id,
|
|
653
|
+
definitionHash,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// Explain the statements actually used by the public delete path. The
|
|
659
|
+
// spies pass through to the real database, including its FK enforcement.
|
|
660
|
+
const querySpy = spyOn(client, "query");
|
|
661
|
+
const runSpy = spyOn(client, "run");
|
|
662
|
+
let queries: typeof querySpy.mock.calls = [];
|
|
663
|
+
let deletes: typeof runSpy.mock.calls = [];
|
|
664
|
+
try {
|
|
665
|
+
expect(await deleteWorkflow(workflow.id)).toBe(true);
|
|
666
|
+
queries = querySpy.mock.calls.filter(([sql]) => sql.includes("definitionHash"));
|
|
667
|
+
deletes = runSpy.mock.calls.filter(([sql]) =>
|
|
668
|
+
sql.includes("DELETE FROM workflow_run_definitions"),
|
|
669
|
+
);
|
|
670
|
+
} finally {
|
|
671
|
+
querySpy.mockRestore();
|
|
672
|
+
runSpy.mockRestore();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const explain = (sql: string, params: DbParam[] = []) => {
|
|
676
|
+
// Finalize EXPLAIN explicitly: Bun 1.4.4 can leave a cached DELETE plan
|
|
677
|
+
// active after .all(), which blocks later transaction commits.
|
|
678
|
+
const statement = db
|
|
679
|
+
.getDb()
|
|
680
|
+
.prepare<{ detail: string }, DbParam[]>(`EXPLAIN QUERY PLAN ${sql}`);
|
|
681
|
+
try {
|
|
682
|
+
return statement
|
|
683
|
+
.all(...params)
|
|
684
|
+
.map((row) => row.detail)
|
|
685
|
+
.join("\n");
|
|
686
|
+
} finally {
|
|
687
|
+
statement.finalize();
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
expect(deletes.length).toBeGreaterThan(0);
|
|
691
|
+
for (const [sql, params] of deletes) {
|
|
692
|
+
const plan = explain(sql, params);
|
|
693
|
+
expect(plan).toMatch(/SEARCH workflow_run_definitions USING (COVERING )?INDEX .*\(hash=\?\)/);
|
|
694
|
+
expect(plan).toContain("SEARCH r USING COVERING INDEX idx_workflow_runs_definitionHash");
|
|
695
|
+
expect(plan).toContain(
|
|
696
|
+
"SEARCH workflow_runs USING COVERING INDEX idx_workflow_runs_definitionHash",
|
|
697
|
+
);
|
|
698
|
+
expect(plan).not.toMatch(/SCAN (workflow_run_definitions|workflow_runs|r)\b/);
|
|
699
|
+
}
|
|
700
|
+
expect(queries.length).toBeGreaterThan(0);
|
|
701
|
+
for (const [sql, params] of queries) {
|
|
702
|
+
const plan = explain(sql, params);
|
|
703
|
+
expect(plan).toMatch(/SEARCH workflow_runs USING INDEX .*\(workflowId=\?\)/);
|
|
704
|
+
expect(plan).not.toContain("SCAN workflow_runs");
|
|
705
|
+
}
|
|
706
|
+
for (const hash of hashes) {
|
|
707
|
+
expect(
|
|
708
|
+
await client.get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [hash]),
|
|
709
|
+
).toBeNull();
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
test("deleteWorkflow rolls snapshot cleanup back with the runs", async () => {
|
|
714
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
715
|
+
const runId = await startOnA(workflow);
|
|
716
|
+
const hash = await pinHash(runId);
|
|
717
|
+
await expect(
|
|
718
|
+
getDbClient().transaction(async () => {
|
|
719
|
+
await deleteWorkflow(workflow.id);
|
|
720
|
+
throw new Error("abort delete");
|
|
721
|
+
}),
|
|
722
|
+
).rejects.toThrow("abort delete");
|
|
723
|
+
|
|
724
|
+
expect(await getWorkflow(workflow.id)).not.toBeNull();
|
|
725
|
+
expect(await pinHash(runId)).toBe(hash);
|
|
726
|
+
expect(await getPinnedRunDefinition(runId)).not.toBeNull();
|
|
602
727
|
});
|
|
603
728
|
});
|
|
604
729
|
|
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
type ServerResponse,
|
|
8
8
|
} from "node:http";
|
|
9
9
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import dreamingConfig from "../../templates/workflows/dreaming/config.json" with { type: "text" };
|
|
11
|
+
import dreamingContent from "../../templates/workflows/dreaming/content.md" with { type: "text" };
|
|
10
12
|
import {
|
|
11
13
|
closeDb,
|
|
12
14
|
completeTask,
|
|
15
|
+
computeContentHash,
|
|
13
16
|
createAgent,
|
|
14
17
|
createScheduledTask,
|
|
15
18
|
createWorkflow,
|
|
@@ -24,9 +27,15 @@ import {
|
|
|
24
27
|
import { upsertScriptByName } from "../be/scripts/db";
|
|
25
28
|
import { setScriptEmbeddingProviderForTests } from "../be/scripts/embeddings";
|
|
26
29
|
import * as runCredential from "../be/scripts/run-credential";
|
|
27
|
-
import { runSeeder } from "../be/seed";
|
|
30
|
+
import { getSeedState, runSeeder } from "../be/seed";
|
|
28
31
|
import { createSchedulesSeeder } from "../be/seed/schedules-seeder";
|
|
29
|
-
import {
|
|
32
|
+
import { recordSeedState } from "../be/seed/state-db";
|
|
33
|
+
import {
|
|
34
|
+
canonicalJson,
|
|
35
|
+
createWorkflowsSeeder,
|
|
36
|
+
loadSeedWorkflows,
|
|
37
|
+
seededWorkflowState,
|
|
38
|
+
} from "../be/seed/workflows-seeder";
|
|
30
39
|
import { getPathSegments, parseQueryParams } from "../http/utils";
|
|
31
40
|
import { handleWorkflows } from "../http/workflows";
|
|
32
41
|
import { dispatchScheduleTarget } from "../scheduler/scheduler";
|
|
@@ -168,6 +177,22 @@ afterAll(async () => {
|
|
|
168
177
|
});
|
|
169
178
|
|
|
170
179
|
/** Put the seeded dreaming row back after a test edits it. */
|
|
180
|
+
/** The built-in dreaming template, with `marker` appended to the synthesize prompt. */
|
|
181
|
+
function dreamingSource(marker?: string): { config: string; content: string } {
|
|
182
|
+
const content = dreamingContent as unknown as string;
|
|
183
|
+
if (!marker) return { config: dreamingConfig as unknown as string, content };
|
|
184
|
+
const match = content.match(/```json\s*\n([\s\S]*?)\n```/)!;
|
|
185
|
+
const payload = JSON.parse(match[1]!) as {
|
|
186
|
+
nodes: { id: string; config: Record<string, unknown> }[];
|
|
187
|
+
};
|
|
188
|
+
const synthesize = payload.nodes.find((node) => node.id === "synthesize")!;
|
|
189
|
+
synthesize.config.template = `${synthesize.config.template as string}\n${marker}`;
|
|
190
|
+
return {
|
|
191
|
+
config: dreamingConfig as unknown as string,
|
|
192
|
+
content: content.replace(match[1]!, () => JSON.stringify(payload)),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
171
196
|
async function restoreDreaming(): Promise<void> {
|
|
172
197
|
await updateWorkflow(dreaming.id, {
|
|
173
198
|
description: dreaming.description,
|
|
@@ -364,24 +389,89 @@ describe("swarm-script principal for a creator-less workflow", () => {
|
|
|
364
389
|
expect(calls).toEqual([]);
|
|
365
390
|
});
|
|
366
391
|
|
|
367
|
-
test("a creator-less schedule refuses the lead for
|
|
392
|
+
test("a creator-less schedule refuses the lead for a legacy-state edit with no seeded snapshot", async () => {
|
|
368
393
|
const schedule = await createScheduledTask({
|
|
369
394
|
name: `principal-unsnapshotted-${crypto.randomUUID().slice(0, 8)}`,
|
|
370
395
|
cronExpression: "0 0 1 1 *",
|
|
371
396
|
targetType: "workflow",
|
|
372
397
|
workflowId: dreaming.id,
|
|
373
398
|
});
|
|
374
|
-
|
|
399
|
+
const state = await getSeedState("workflow", "dreaming");
|
|
400
|
+
// Older releases recorded a whole-workflow hash, which a description edit
|
|
401
|
+
// changes. Delete the history so no snapshot proves the seeded state.
|
|
402
|
+
const [seed] = loadSeedWorkflows([dreamingSource()]);
|
|
403
|
+
await recordSeedState("workflow", "dreaming", computeContentHash(canonicalJson(seed)));
|
|
375
404
|
await getDbClient().run("DELETE FROM workflow_versions WHERE workflowId = ?", [dreaming.id]);
|
|
376
405
|
await updateWorkflow(dreaming.id, { description: "edited without a snapshot" });
|
|
377
406
|
try {
|
|
378
407
|
await expect(dispatchScheduleTarget(schedule)).rejects.toThrow("were edited");
|
|
379
408
|
} finally {
|
|
380
409
|
await restoreDreaming();
|
|
410
|
+
await recordSeedState("workflow", "dreaming", state!.seededHash);
|
|
381
411
|
}
|
|
382
412
|
expect(calls).toEqual([]);
|
|
383
413
|
});
|
|
384
414
|
|
|
415
|
+
test("a creator-less schedule refuses the lead for a node edit with no seeded snapshot", async () => {
|
|
416
|
+
const schedule = await createScheduledTask({
|
|
417
|
+
name: `principal-unsnapshotted-node-${crypto.randomUUID().slice(0, 8)}`,
|
|
418
|
+
cronExpression: "0 0 1 1 *",
|
|
419
|
+
targetType: "workflow",
|
|
420
|
+
workflowId: dreaming.id,
|
|
421
|
+
});
|
|
422
|
+
await getDbClient().run("DELETE FROM workflow_versions WHERE workflowId = ?", [dreaming.id]);
|
|
423
|
+
const [gather, ...rest] = dreaming.definition.nodes;
|
|
424
|
+
await updateWorkflow(dreaming.id, {
|
|
425
|
+
definition: {
|
|
426
|
+
...dreaming.definition,
|
|
427
|
+
nodes: [{ ...gather!, config: { ...gather!.config, scriptName: "evil" } }, ...rest],
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
try {
|
|
431
|
+
await expect(dispatchScheduleTarget(schedule)).rejects.toThrow("were edited");
|
|
432
|
+
} finally {
|
|
433
|
+
await restoreDreaming();
|
|
434
|
+
}
|
|
435
|
+
expect(calls).toEqual([]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("a template update on input-tuned dreaming with legacy seed state keeps the lead", async () => {
|
|
439
|
+
// The live shape: seeded under a whole-workflow hash, then the lead set
|
|
440
|
+
// `input` through update-workflow, then a release changed the template.
|
|
441
|
+
const state = await getSeedState("workflow", "dreaming");
|
|
442
|
+
const [seed] = loadSeedWorkflows([dreamingSource()]);
|
|
443
|
+
await recordSeedState("workflow", "dreaming", computeContentHash(canonicalJson(seed)));
|
|
444
|
+
const tunedInput = { ...dreaming.input, leadAgentId: leadId, slackChannel: "C123" };
|
|
445
|
+
await snapshotAndUpdateWorkflow(
|
|
446
|
+
dreaming.id,
|
|
447
|
+
{ input: tunedInput },
|
|
448
|
+
{ changedByAgentId: leadId },
|
|
449
|
+
);
|
|
450
|
+
const schedule = await createScheduledTask({
|
|
451
|
+
name: `principal-template-update-${crypto.randomUUID().slice(0, 8)}`,
|
|
452
|
+
cronExpression: "0 0 1 1 *",
|
|
453
|
+
targetType: "workflow",
|
|
454
|
+
workflowId: dreaming.id,
|
|
455
|
+
});
|
|
456
|
+
try {
|
|
457
|
+
const result = await runSeeder(createWorkflowsSeeder([dreamingSource("TEMPLATE UPDATE")]), {
|
|
458
|
+
quiet: true,
|
|
459
|
+
});
|
|
460
|
+
expect(result).toMatchObject({ updated: 1, skippedUserModified: 0, failed: [] });
|
|
461
|
+
const live = (await listWorkflows()).find((w) => w.name === "dreaming")!;
|
|
462
|
+
expect(live.input).toEqual(tunedInput);
|
|
463
|
+
expect(JSON.stringify(live.definition)).toContain("TEMPLATE UPDATE");
|
|
464
|
+
expect(await seededWorkflowState(live)).toBe("pristine");
|
|
465
|
+
|
|
466
|
+
await dispatchScheduleTarget(schedule);
|
|
467
|
+
expect(gatherPrincipals()).toEqual([leadId]);
|
|
468
|
+
expect(calls[0]?.args.leadAgentId).toBe(leadId);
|
|
469
|
+
} finally {
|
|
470
|
+
await restoreDreaming();
|
|
471
|
+
await recordSeedState("workflow", "dreaming", state!.seededHash);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
385
475
|
test("a long successful night does not make the next nightly fire skip", async () => {
|
|
386
476
|
const schedule = await createScheduledTask({
|
|
387
477
|
name: `principal-long-${crypto.randomUUID().slice(0, 8)}`,
|
package/src/tools/app-upsert.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const registerAppUpsertTool = (server: McpServer) => {
|
|
|
24
24
|
{
|
|
25
25
|
title: "Create or update an app",
|
|
26
26
|
description:
|
|
27
|
-
|
|
27
|
+
'Stores a schema-backed app definition with models, queries/actions, pages, reusable elements, optional userConfig fields, an optional top-level theme (a dashboard preset slug for the app\'s canvas: hive (stock; omit to inherit the viewer\'s theme), meadow, iris, rose, cobalt, ember, carbon, paper (the warm editorial paper look), plus the classic presets github, vscode, material, solarized, tokyo, monokai, gruvbox, catppuccin; viewers can override it per-user; unknown slugs degrade to the viewer\'s dashboard theme), and an optional top-level icon shown on the dashboard Apps page, one of { type: "lucide", icon: "<kebab-case lucide icon name>", color?: "#RRGGBB" } (an unrecognized name shows a generic default), { type: "url", url: "https://..." } (https only, no credentials), or { type: "agent-fs", path: "/apps/<appId>/icon.png" } (swarm drive; add orgId and driveId for another drive); the dashboard shows a glyph when an image cannot load, and a patch replaces icon whole, then returns its dashboard URL. userConfig is versioned schema only; each user\'s values are stored separately, survive rollback, and schema changes are always compatible. Pages may bind a declared field read-only at exactly /user/<field>; pure and bound reusable elements must receive that value through a prop. Elements are private by default: pure elements read declared props, allow $item/$index inside repeats, may expose one leaf ElementSlot, and cannot invoke actions; bound elements may use the defining app\'s queries/actions, while exported bound elements cannot navigate. Prop kinds include enum with a required non-empty enum values array. Pages or elements reuse them with literal ElementRef targets, and cross-app refs require export: true. Zero-model pure-UI apps are valid. Pass appId to update; breaking a referenced export is blocked by the compatibility gate unless forceElementBreak explicitly names it.',
|
|
28
28
|
annotations: { destructiveHint: false },
|
|
29
29
|
inputSchema: z.object({
|
|
30
30
|
name: z.string().min(1).describe("Human-readable app name."),
|
|
@@ -10,7 +10,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
10
10
|
{
|
|
11
11
|
title: "List Model Profiles",
|
|
12
12
|
description:
|
|
13
|
-
"List model profiles: named harness + model + effort combinations. Pass a profile's name as `profile` on send-task to run that task on it, or set it as an agent's default through PATCH /api/agents/{id}/runtime. A profile runs only on its own harness. Filter by `harness` to see what an agent on that harness can run.",
|
|
13
|
+
"List model profiles: named harness + model + effort combinations. Pass a profile's name as `profile` on send-task to run that task on it, or set it as an agent's default through PATCH /api/agents/{id}/runtime. A profile runs only on its own harness. `fallbacks` are the same-harness profiles a task hops to, in order, when a provider error (rate limit, seat, overload, auth, empty key pool) ends it. Filter by `harness` to see what an agent on that harness can run.",
|
|
14
14
|
annotations: { readOnlyHint: true },
|
|
15
15
|
inputSchema: z.object({
|
|
16
16
|
harness: ProviderNameSchema.optional().describe(
|
|
@@ -26,6 +26,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
26
26
|
model: z.string().optional(),
|
|
27
27
|
effort: z.string().nullable().optional(),
|
|
28
28
|
description: z.string().nullable().optional(),
|
|
29
|
+
fallbacks: z.array(z.string()).optional(),
|
|
29
30
|
}),
|
|
30
31
|
)
|
|
31
32
|
.optional(),
|
|
@@ -35,7 +36,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
35
36
|
const profiles = await listModelProfiles({ harness });
|
|
36
37
|
const lines = profiles.map(
|
|
37
38
|
(p) =>
|
|
38
|
-
`${p.name}: ${p.harness} / ${p.model}${p.effort ? ` / effort ${p.effort}` : ""}${p.description ? ` (${p.description})` : ""}`,
|
|
39
|
+
`${p.name}: ${p.harness} / ${p.model}${p.effort ? ` / effort ${p.effort}` : ""}${p.fallbacks.length > 0 ? ` → fallbacks ${p.fallbacks.join(", ")}` : ""}${p.description ? ` (${p.description})` : ""}`,
|
|
39
40
|
);
|
|
40
41
|
return toolOk(`${profiles.length} model profile(s)${harness ? ` for ${harness}` : ""}.`, {
|
|
41
42
|
details: lines.join("\n"),
|
|
@@ -46,6 +47,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
46
47
|
model: p.model,
|
|
47
48
|
effort: p.effort,
|
|
48
49
|
description: p.description,
|
|
50
|
+
fallbacks: p.fallbacks,
|
|
49
51
|
})),
|
|
50
52
|
},
|
|
51
53
|
});
|
|
@@ -159,7 +159,7 @@ export const registerUpdateProfileTool = (server: McpServer) => {
|
|
|
159
159
|
avatar: AgentAvatarSchema.nullable()
|
|
160
160
|
.optional()
|
|
161
161
|
.describe(
|
|
162
|
-
"Custom avatar: { type: 'lucide', icon: '<kebab-case-lucide-name>', color?: '#RRGGBB' }. Pass null to reset to the default deterministic icon/color.",
|
|
162
|
+
"Custom avatar, one of: { type: 'lucide', icon: '<kebab-case-lucide-name>', color?: '#RRGGBB' }; { type: 'url', url: 'https://…' } (https image, no credentials); { type: 'agent-fs', path: '/agents/<id>/avatar.png', orgId?, driveId? } (an image in agent-fs; pass both IDs or neither for the swarm drive). An image that cannot load falls back to the default glyph. Pass null to reset to the default deterministic icon/color.",
|
|
163
163
|
),
|
|
164
164
|
slackIcon: AgentSlackIconSchema.nullable()
|
|
165
165
|
.optional()
|