@desplega.ai/agent-swarm 2.8.0 → 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-t949vbbp.js → acp-adapter-fqzkxyra.js} +3 -3
- package/dist/{actions-7e9czc7s.js → actions-kxek041g.js} +18 -18
- package/dist/{amp-adapter-gv6cbb7d.js → amp-adapter-ce7jjke4.js} +1 -1
- package/dist/{app-b9fbkp9v.js → app-v6zz8yh0.js} +3 -3
- package/dist/{assistant-wjb7v4c7.js → assistant-m0sw9xx2.js} +19 -19
- package/dist/{boot-args-schema-2t37e0fe.js → boot-args-schema-66bk37wv.js} +1 -1
- package/dist/{boot-reembed-gka3zas7.js → boot-reembed-edjpwsc1.js} +1 -1
- package/dist/{boot-reembed-a35nkyr1.js → boot-reembed-y27n09tz.js} +1 -1
- package/dist/{boot-scrub-sweep-65sdnp6c.js → boot-scrub-sweep-1xc35965.js} +3 -3
- package/dist/{boot-seeds-x42tzytw.js → boot-seeds-7hjj91qj.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
- package/dist/{claude-adapter-v221b2fd.js → claude-adapter-stw7jdcf.js} +3 -3
- package/dist/{claude-managed-adapter-29eq09wd.js → claude-managed-adapter-jh6c523j.js} +2 -2
- package/dist/{claude-managed-setup-9m6450zk.js → claude-managed-setup-y6z2perp.js} +5 -5
- package/dist/{claude-sdk-session-0q0ptaba.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-y97qxcfx.js → cli-1qkz151v.js} +3 -3
- package/dist/{cli-qwca7s44.js → cli-26ctbcdp.js} +18 -6
- package/dist/{cli-8fknbnhw.js → cli-2kvhc7x8.js} +7 -7
- package/dist/{cli-rfywm85n.js → cli-3e875j5p.js} +136 -49
- package/dist/{cli-6wxjceza.js → cli-3sy2xags.js} +10 -10
- package/dist/{cli-a7wvp2km.js → cli-3vmb0n58.js} +1 -1
- package/dist/{cli-p1bq50aa.js → cli-4vzgeta4.js} +13 -13
- package/dist/{cli-m28atx8q.js → cli-5y340nzn.js} +4 -4
- package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- package/dist/{cli-ee0b971j.js → cli-837vfs2x.js} +2 -2
- package/dist/{cli-abejgen1.js → cli-959kp5h2.js} +12 -11
- package/dist/{cli-8kzasymh.js → cli-97ae65rz.js} +4 -4
- package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
- package/dist/{cli-p2gfst4m.js → cli-a0z912j7.js} +123 -35
- package/dist/{cli-4txa0ter.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-qa4wdgsy.js → cli-e1p3n5gq.js} +4 -4
- package/dist/{cli-gxkx0zzp.js → cli-f4e8r23x.js} +1 -1
- package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
- package/dist/{cli-wcg8x116.js → cli-f6bahpn5.js} +1 -1
- package/dist/{cli-qsnnd04k.js → cli-fpjmegdb.js} +1 -1
- package/dist/{cli-j790gp2w.js → cli-fwy8kfd6.js} +271 -37
- package/dist/{cli-rmmpt0wm.js → cli-g5mtmf6t.js} +6 -6
- package/dist/{cli-rzsy6nc6.js → cli-gyt3zydq.js} +3 -3
- package/dist/{cli-pasjcnmj.js → cli-j24zbska.js} +3 -3
- package/dist/{cli-qfedvmcr.js → cli-jdknh18m.js} +10 -10
- package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-2wnq8jkz.js → cli-mxn1qvbn.js} +3 -2
- package/dist/{cli-s7t6p9my.js → cli-n6vtrcht.js} +1 -1
- package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
- package/dist/{cli-yq3zak69.js → cli-pfs8adn4.js} +1 -1
- package/dist/{cli-c55z5chy.js → cli-q24n86d2.js} +2 -2
- package/dist/{cli-h38x262p.js → cli-rcecc3yq.js} +167 -43
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-sdtt3men.js → cli-rmzsadkf.js} +1 -1
- package/dist/{cli-f3vq58d2.js → cli-t2tma8gb.js} +1 -1
- package/dist/{cli-m23zjcy2.js → cli-tekytdq9.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
- package/dist/{cli-ffhtssbp.js → cli-vj75tyaw.js} +1 -1
- package/dist/{cli-deefvewm.js → cli-w401b9tq.js} +1 -1
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-6t09sdhy.js → cli-xf3qw745.js} +3 -3
- package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
- package/dist/{cli-334z18y3.js → cli-zh9rsbqf.js} +3 -3
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-30j9bpzd.js → codex-adapter-zerf5qsp.js} +1 -1
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
- package/dist/{codex-session-runner-8vp57v8w.js → codex-session-runner-89s304py.js} +1 -1
- package/dist/{commands-bngnz9g7.js → commands-jeh1b51j.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
- package/dist/{controllers-connect-e2b4gyxc.js → controllers-connect-nxa1ddwn.js} +19 -19
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
- package/dist/{db-bgm7vkc0.js → db-2dvay0es.js} +3 -3
- package/dist/{db-c6np41ca.js → db-b36qn6k3.js} +2 -2
- package/dist/{dispatcher-jnybck15.js → dispatcher-gndbta01.js} +17 -17
- 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-crsm2zp0.js → embedding-space-4p05vb2x.js} +6 -6
- package/dist/{embeddings-e7z3f27f.js → embeddings-m6768mgh.js} +1 -1
- package/dist/{external-channel-m77wf5z3.js → external-channel-gjv3jne3.js} +2 -2
- package/dist/{fx-adapter-b6w0kf56.js → fx-adapter-rpsgb1tw.js} +4 -4
- package/dist/{grok-adapter-4sqtebdk.js → grok-adapter-n2m3zjg1.js} +4 -4
- package/dist/handlers-nv8edn19.js +32 -0
- package/dist/{heartbeat-xgb036sx.js → heartbeat-a1tv60gt.js} +20 -20
- package/dist/{hook-xsk1jbha.js → hook-8h5dzcgq.js} +2 -2
- package/dist/{hook-5h02c9ga.js → hook-cyaps9ba.js} +4 -4
- package/dist/{http-txe7qhvn.js → http-t15mhbd9.js} +1733 -79
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- 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-ksmyd6kc.js +37 -0
- package/dist/{index-vk63emp7.js → index-qav6455f.js} +14 -12
- package/dist/index-rjnrje98.js +32 -0
- package/dist/index-tv3413wy.js +33 -0
- package/dist/{index-ysvbhg5m.js → index-w1zqf680.js} +1 -1
- package/dist/{keepalive-4zsrce78.js → keepalive-91s7hzrb.js} +3 -3
- package/dist/lead-3hmddvrm.js +70 -0
- package/dist/{maintenance-86jvartk.js → maintenance-7pjmy5xy.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-j52kg9pr.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
- package/dist/{onboard-c2aj5p8q.js → onboard-74st7pag.js} +3 -3
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
- package/dist/{otel-impl-yyy203z8.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-1rgzqyzz.js → pricing-refresh-ha21jhk7.js} +2 -2
- package/dist/{rbac-roles-e70xfeyj.js → rbac-roles-59dxachk.js} +2 -2
- package/dist/{rbac-roles-q89qe8er.js → rbac-roles-wqhma4dr.js} +3 -3
- package/dist/{render-v2-k6tt107q.js → render-v2-14kpzx12.js} +3 -3
- package/dist/{resume-cnnrjfxa.js → resume-gsa5fb5f.js} +6 -6
- package/dist/{session-access-xkxkjw3n.js → session-access-skm7bnp6.js} +4 -4
- package/dist/{session-source-backfill-1d5pdwww.js → session-source-backfill-pbqzbncv.js} +2 -2
- package/dist/{setup-se8q7gkc.js → setup-5yermsem.js} +1 -1
- package/dist/{work-objects-1kxnbzy5.js → work-objects-xj0ck0w4.js} +20 -20
- package/dist/{worker-follow-up-zqm8apt4.js → worker-follow-up-911xc0b8.js} +19 -17
- package/dist/worker-qgg0m2gw.js +70 -0
- package/openapi.json +1741 -290
- package/package.json +3 -3
- 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/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -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/mcp-tools.test.ts +1 -1
- 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/script-native-unawaited-drain.test.ts +167 -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/script-run.ts +1 -1
- 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/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/dist/handlers-kdjcyzdj.js +0 -32
- package/dist/index-835xdgnm.js +0 -33
- package/dist/index-d469300x.js +0 -37
- package/dist/index-rzqwp11g.js +0 -32
- package/dist/lead-yqt47dkr.js +0 -70
- package/dist/worker-j6xxtq7p.js +0 -70
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
|
-
import { closeDb, initDb, listWorkflows, updateWorkflow } from "../be/db";
|
|
3
|
+
import { closeDb, computeContentHash, initDb, listWorkflows, updateWorkflow } from "../be/db";
|
|
4
4
|
import { getSeedState, runSeeder } from "../be/seed";
|
|
5
|
+
import { recordSeedState } from "../be/seed/state-db";
|
|
5
6
|
import {
|
|
7
|
+
canonicalJson,
|
|
6
8
|
createWorkflowsSeeder,
|
|
7
9
|
loadSeedWorkflows,
|
|
10
|
+
seededWorkflowState,
|
|
8
11
|
type WorkflowTemplateSource,
|
|
9
12
|
} from "../be/seed/workflows-seeder";
|
|
13
|
+
import { snapshotAndUpdateWorkflow } from "../workflows/version";
|
|
10
14
|
|
|
11
15
|
const TEST_DB_PATH = "./test-seed-workflows.sqlite";
|
|
12
16
|
|
|
@@ -20,7 +24,11 @@ async function removeDbFiles(): Promise<void> {
|
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
function workflowSource(
|
|
27
|
+
function workflowSource(
|
|
28
|
+
template = "Do the work.",
|
|
29
|
+
description = "Seeded workflow.",
|
|
30
|
+
input: Record<string, string> = { channel: "" },
|
|
31
|
+
) {
|
|
24
32
|
return {
|
|
25
33
|
config: JSON.stringify({
|
|
26
34
|
name: "test-seeded-workflow",
|
|
@@ -31,10 +39,43 @@ function workflowSource(template = "Do the work.", description = "Seeded workflo
|
|
|
31
39
|
}),
|
|
32
40
|
content: `# Test\n\n\`\`\`json\n${JSON.stringify({
|
|
33
41
|
nodes: [{ id: "work", type: "agent-task", config: { template } }],
|
|
42
|
+
input,
|
|
34
43
|
})}\n\`\`\``,
|
|
35
44
|
} satisfies WorkflowTemplateSource;
|
|
36
45
|
}
|
|
37
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Overwrite the recorded seed state with the hash older releases stored: the
|
|
49
|
+
* whole template workflow, operator settings included.
|
|
50
|
+
*/
|
|
51
|
+
async function recordLegacySeedState(source: WorkflowTemplateSource): Promise<void> {
|
|
52
|
+
const [workflow] = loadSeedWorkflows([source]);
|
|
53
|
+
await recordSeedState("workflow", workflow!.name, computeContentHash(canonicalJson(workflow)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A real node edit on top of operator settings. */
|
|
57
|
+
const NODE_EDIT = {
|
|
58
|
+
nodes: [{ id: "ui-edit", type: "agent-task", config: { template: "Edited." } }],
|
|
59
|
+
onNodeFailure: "fail",
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
/** Operator settings, made the way the update-workflow tool makes them. */
|
|
63
|
+
async function tuneSettings(id: string): Promise<void> {
|
|
64
|
+
await snapshotAndUpdateWorkflow(id, {
|
|
65
|
+
input: { channel: "C123" },
|
|
66
|
+
enabled: true,
|
|
67
|
+
description: "Tuned by the operator.",
|
|
68
|
+
cooldown: { hours: 22, from: "start" },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const TUNED = {
|
|
73
|
+
input: { channel: "C123" },
|
|
74
|
+
enabled: true,
|
|
75
|
+
description: "Tuned by the operator.",
|
|
76
|
+
cooldown: { hours: 22, from: "start" },
|
|
77
|
+
};
|
|
78
|
+
|
|
38
79
|
/** A zero-config candidate: no requires, no placeholders — eligible for auto-enable. */
|
|
39
80
|
function zeroConfigWorkflowSource(opts?: {
|
|
40
81
|
name?: string;
|
|
@@ -175,21 +216,135 @@ describe("workflows seeder", () => {
|
|
|
175
216
|
expect(second).toMatchObject({ skippedUnchanged: 1, updated: 0, failed: [] });
|
|
176
217
|
});
|
|
177
218
|
|
|
178
|
-
test("
|
|
219
|
+
test("an input-only edit still gets the template update and keeps the live input", async () => {
|
|
220
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
221
|
+
const seeded = await getWorkflow();
|
|
222
|
+
await snapshotAndUpdateWorkflow(seeded!.id, { input: { channel: "C123" } });
|
|
223
|
+
|
|
224
|
+
const update = createWorkflowsSeeder([workflowSource("Source update.")]);
|
|
225
|
+
const result = await runSeeder(update, { quiet: true });
|
|
226
|
+
expect(result).toMatchObject({ updated: 1, skippedUserModified: 0, failed: [] });
|
|
227
|
+
const live = await getWorkflow();
|
|
228
|
+
expect(live?.definition.nodes[0]?.config.template).toBe("Source update.");
|
|
229
|
+
expect(live?.input).toEqual({ channel: "C123" });
|
|
230
|
+
expect((await getSeedState("workflow", live!.name))?.seededHash).toBe(
|
|
231
|
+
update.items()[0]!.contentHash,
|
|
232
|
+
);
|
|
233
|
+
expect(await seededWorkflowState(live!)).toBe("pristine");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("a template update keeps every operator setting", async () => {
|
|
237
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
238
|
+
await tuneSettings((await getWorkflow())!.id);
|
|
239
|
+
|
|
240
|
+
const result = await runSeeder(
|
|
241
|
+
createWorkflowsSeeder([workflowSource("Source update.", "New template description.")]),
|
|
242
|
+
{ quiet: true },
|
|
243
|
+
);
|
|
244
|
+
expect(result).toMatchObject({ updated: 1, failed: [] });
|
|
245
|
+
const live = await getWorkflow();
|
|
246
|
+
expect(live).toMatchObject(TUNED);
|
|
247
|
+
expect(live?.definition.nodes[0]?.config.template).toBe("Source update.");
|
|
248
|
+
expect(await seededWorkflowState(live!)).toBe("pristine");
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("a template update adds new input keys without touching live values", async () => {
|
|
252
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
253
|
+
await snapshotAndUpdateWorkflow((await getWorkflow())!.id, { input: { channel: "C123" } });
|
|
254
|
+
|
|
255
|
+
await runSeeder(
|
|
256
|
+
createWorkflowsSeeder([
|
|
257
|
+
workflowSource("Source update.", undefined, { channel: "", newKey: "default" }),
|
|
258
|
+
]),
|
|
259
|
+
{ quiet: true },
|
|
260
|
+
);
|
|
261
|
+
expect((await getWorkflow())?.input).toEqual({ channel: "C123", newKey: "default" });
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("preserves a node edit made together with operator settings", async () => {
|
|
179
265
|
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
180
266
|
const seeded = await getWorkflow();
|
|
181
|
-
await
|
|
267
|
+
await tuneSettings(seeded!.id);
|
|
268
|
+
await snapshotAndUpdateWorkflow(seeded!.id, { definition: NODE_EDIT });
|
|
182
269
|
|
|
183
270
|
const result = await runSeeder(createWorkflowsSeeder([workflowSource("Source update.")]), {
|
|
184
271
|
quiet: true,
|
|
185
272
|
});
|
|
186
|
-
expect(result
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
273
|
+
expect(result).toMatchObject({ updated: 0, skippedUserModified: 1, failed: [] });
|
|
274
|
+
const live = await getWorkflow();
|
|
275
|
+
expect(live?.definition.nodes[0]?.id).toBe("ui-edit");
|
|
276
|
+
expect(await seededWorkflowState(live!)).toBe("edited");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("legacy whole-workflow seed state", () => {
|
|
280
|
+
test("an input-only edit with a seeded snapshot gets the update and the state migrates", async () => {
|
|
281
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
282
|
+
await recordLegacySeedState(workflowSource());
|
|
283
|
+
await tuneSettings((await getWorkflow())!.id);
|
|
284
|
+
// Before the update the workflow still reads pristine (the scheduler's view).
|
|
285
|
+
expect(await seededWorkflowState((await getWorkflow())!)).toBe("pristine");
|
|
286
|
+
|
|
287
|
+
const update = createWorkflowsSeeder([workflowSource("Source update.")]);
|
|
288
|
+
const result = await runSeeder(update, { quiet: true });
|
|
289
|
+
expect(result).toMatchObject({ updated: 1, skippedUserModified: 0, failed: [] });
|
|
290
|
+
const live = await getWorkflow();
|
|
291
|
+
expect(live).toMatchObject(TUNED);
|
|
292
|
+
expect(live?.definition.nodes[0]?.config.template).toBe("Source update.");
|
|
293
|
+
expect((await getSeedState("workflow", live!.name))?.seededHash).toBe(
|
|
294
|
+
update.items()[0]!.contentHash,
|
|
295
|
+
);
|
|
296
|
+
expect(await seededWorkflowState(live!)).toBe("pristine");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("an untouched workflow gets the update", async () => {
|
|
300
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
301
|
+
await recordLegacySeedState(workflowSource());
|
|
302
|
+
|
|
303
|
+
const result = await runSeeder(createWorkflowsSeeder([workflowSource("Source update.")]), {
|
|
304
|
+
quiet: true,
|
|
305
|
+
});
|
|
306
|
+
expect(result).toMatchObject({ updated: 1, failed: [] });
|
|
307
|
+
expect((await getWorkflow())?.definition.nodes[0]?.config.template).toBe("Source update.");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("a node edit is preserved", async () => {
|
|
311
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
312
|
+
await recordLegacySeedState(workflowSource());
|
|
313
|
+
const seeded = await getWorkflow();
|
|
314
|
+
await snapshotAndUpdateWorkflow(seeded!.id, {
|
|
315
|
+
input: { channel: "C123" },
|
|
316
|
+
definition: NODE_EDIT,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const result = await runSeeder(createWorkflowsSeeder([workflowSource("Source update.")]), {
|
|
320
|
+
quiet: true,
|
|
321
|
+
});
|
|
322
|
+
expect(result).toMatchObject({ updated: 0, skippedUserModified: 1, failed: [] });
|
|
323
|
+
expect((await getWorkflow())?.definition.nodes[0]?.id).toBe("ui-edit");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("a settings edit with no seeded snapshot is preserved", async () => {
|
|
327
|
+
await runSeeder(createWorkflowsSeeder([workflowSource()]), { quiet: true });
|
|
328
|
+
await recordLegacySeedState(workflowSource());
|
|
329
|
+
await updateWorkflow((await getWorkflow())!.id, { input: { channel: "C123" } });
|
|
330
|
+
|
|
331
|
+
const result = await runSeeder(createWorkflowsSeeder([workflowSource("Source update.")]), {
|
|
332
|
+
quiet: true,
|
|
333
|
+
});
|
|
334
|
+
expect(result).toMatchObject({ updated: 0, skippedUserModified: 1, failed: [] });
|
|
335
|
+
expect(await seededWorkflowState((await getWorkflow())!)).toBe("edited");
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("a workflow already matching the template re-baselines to the new hash", async () => {
|
|
339
|
+
const seeder = createWorkflowsSeeder([workflowSource()]);
|
|
340
|
+
await runSeeder(seeder, { quiet: true });
|
|
341
|
+
await recordLegacySeedState(workflowSource());
|
|
342
|
+
|
|
343
|
+
const result = await runSeeder(seeder, { quiet: true });
|
|
344
|
+
expect(result).toMatchObject({ skippedUnchanged: 1, updated: 0, failed: [] });
|
|
345
|
+
expect((await getSeedState("workflow", "test-seeded-workflow"))?.seededHash).toBe(
|
|
346
|
+
seeder.items()[0]!.contentHash,
|
|
347
|
+
);
|
|
193
348
|
});
|
|
194
349
|
});
|
|
195
350
|
|
|
@@ -208,6 +363,7 @@ describe("workflows seeder", () => {
|
|
|
208
363
|
});
|
|
209
364
|
expect(result.skippedUserModified).toBe(1);
|
|
210
365
|
expect((await getWorkflow())?.definition.nodes[0]?.id).toBe("ui-edit");
|
|
366
|
+
expect(await seededWorkflowState((await getWorkflow())!)).toBe("edited");
|
|
211
367
|
});
|
|
212
368
|
|
|
213
369
|
test("updates a pristine workflow when its template changes", async () => {
|
|
@@ -5,6 +5,51 @@ import { parseSkillContent } from "../be/skill-parser";
|
|
|
5
5
|
// ─── Valid Parsing ──────────────────────────────────────────────────────────
|
|
6
6
|
|
|
7
7
|
describe("parseSkillContent — valid inputs", () => {
|
|
8
|
+
test.each([">", "|", ">-", "|-", ">+", "|+"])("parses ponytail block description %s", (style) => {
|
|
9
|
+
const lines = [
|
|
10
|
+
"Lazy senior dev mode: the smallest change that fully solves the task, and a",
|
|
11
|
+
"reply a busy human understands in one read. Use on any coding task (writing,",
|
|
12
|
+
"fixing, refactoring, reviewing, choosing dependencies) and when the user says",
|
|
13
|
+
'"ponytail", "be lazy", "simplest solution", "yagni", or complains about',
|
|
14
|
+
"over-engineering or bloat. Levels: lite, full (default), ultra.",
|
|
15
|
+
];
|
|
16
|
+
const content = `---
|
|
17
|
+
name: ponytail
|
|
18
|
+
description: ${style}
|
|
19
|
+
${lines.map((line) => ` ${line}`).join("\n")}
|
|
20
|
+
argument-hint: "[lite|full|ultra|off]"
|
|
21
|
+
license: MIT
|
|
22
|
+
---
|
|
23
|
+
# Ponytail`;
|
|
24
|
+
|
|
25
|
+
const result = parseSkillContent(content);
|
|
26
|
+
const separator = style.startsWith(">") ? " " : "\n";
|
|
27
|
+
expect(result.description).toBe(lines.join(separator) + (style.endsWith("-") ? "" : "\n"));
|
|
28
|
+
expect(result.name).toBe("ponytail");
|
|
29
|
+
expect(result.body).toBe("# Ponytail");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
for (const style of ["|", ">", "|-", ">-", "|+", ">+"]) {
|
|
33
|
+
test.each([0, 2])(`preserves following metadata with ${style} at indentation %i`, (indent) => {
|
|
34
|
+
const padding = " ".repeat(indent);
|
|
35
|
+
const result = parseSkillContent(
|
|
36
|
+
`---\n${padding}name: test\n${padding}description: ${style}\n${padding} Hello\n${padding} model: part of the description\n\n${padding}model: opus\n${padding}effort: high\n---\nBody`,
|
|
37
|
+
);
|
|
38
|
+
const ending = style.endsWith("-") ? "" : style.endsWith("+") ? "\n\n" : "\n";
|
|
39
|
+
expect(result.description).toBe(`Hello\n model: part of the description${ending}`);
|
|
40
|
+
expect(result.model).toBe("opus");
|
|
41
|
+
expect(result.effort).toBe("high");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test.each([false, true])(`honors ${style} trailing blank lines, last field: %s`, (last) => {
|
|
45
|
+
const result = parseSkillContent(
|
|
46
|
+
`---\nname: test\ndescription: ${style}\n Hello\n world\n\n\n${last ? "" : "model: opus\n"}---\nBody`,
|
|
47
|
+
);
|
|
48
|
+
const ending = style.endsWith("-") ? "" : style.endsWith("+") ? "\n\n\n" : "\n";
|
|
49
|
+
expect(result.description).toBe(`Hello${style.startsWith(">") ? " " : "\n"}world${ending}`);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
8
53
|
test("parses minimal frontmatter with body", () => {
|
|
9
54
|
const content = `---
|
|
10
55
|
name: my-skill
|
|
@@ -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
|
+
});
|