@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,287 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
CURVE,
|
|
4
|
+
curve,
|
|
5
|
+
DEFAULT_OPS,
|
|
6
|
+
F_FOLLOWUP,
|
|
7
|
+
jobKey,
|
|
8
|
+
nodeOpsOf,
|
|
9
|
+
parseCalibration,
|
|
10
|
+
priceWorkflow,
|
|
11
|
+
SAVINGS_TIERS,
|
|
12
|
+
splitByDay,
|
|
13
|
+
type WorkflowFacts,
|
|
14
|
+
} from "../be/savings/model";
|
|
15
|
+
|
|
16
|
+
const facts = (over: Partial<WorkflowFacts> = {}): WorkflowFacts => ({
|
|
17
|
+
runs: 1,
|
|
18
|
+
countedRuns: 1,
|
|
19
|
+
schedRuns: 0,
|
|
20
|
+
schedEffectRuns: 0,
|
|
21
|
+
opsSum: 0,
|
|
22
|
+
agentTasks: 0,
|
|
23
|
+
agentUsd: 0,
|
|
24
|
+
agentMs: 0,
|
|
25
|
+
followupUsd: 0,
|
|
26
|
+
recordedLlmUsd: 0,
|
|
27
|
+
estimatedLlmUsd: 0,
|
|
28
|
+
computeSecs: 0,
|
|
29
|
+
...over,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const perRun = (ops: number) =>
|
|
33
|
+
SAVINGS_TIERS.map(
|
|
34
|
+
(tier) =>
|
|
35
|
+
priceWorkflow(facts({ opsSum: ops }), { tier, days: 30, band: "job" }).agentOnlyUsdPerRun,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// The report rounds its cells by hand (ultra pr-fix-loop: 3.03 vs 3.044), so allow 1.5 cents.
|
|
39
|
+
function expectReportRow(ops: number, row: number[]) {
|
|
40
|
+
perRun(ops).forEach((value, i) => {
|
|
41
|
+
expect(Math.abs(value - (row[i] as number))).toBeLessThan(0.015);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("savings model", () => {
|
|
46
|
+
test("agent-only cost of one run matches the cost report table", () => {
|
|
47
|
+
// Report table "Agent-only cost of one run", smol/regular/smart/ultra.
|
|
48
|
+
expectReportRow(11, [0.12, 0.26, 0.41, 0.82]); // claude-code-changelog-watch
|
|
49
|
+
expectReportRow(100, [0.15, 0.78, 1.46, 3.03]); // pr-fix-loop
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("every tier curve has one point per turn up to TAU_MAX", () => {
|
|
53
|
+
for (const tier of SAVINGS_TIERS) {
|
|
54
|
+
expect(CURVE[tier].usd).toHaveLength(61);
|
|
55
|
+
expect(CURVE[tier].hrs).toHaveLength(61);
|
|
56
|
+
}
|
|
57
|
+
// Interpolates and clamps.
|
|
58
|
+
expect(curve(1.5, "smart", "usd")).toBeCloseTo((0.1746 + 0.2138) / 2, 6);
|
|
59
|
+
expect(curve(0, "smart", "usd")).toBe(0.1746);
|
|
60
|
+
expect(curve(500, "smart", "usd")).toBe(2.8086);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("schedule runs are capped at 24 a day, but effect runs always count", () => {
|
|
64
|
+
const priced = priceWorkflow(
|
|
65
|
+
facts({ runs: 1100, countedRuns: 1050, schedRuns: 1000, schedEffectRuns: 800, opsSum: 0 }),
|
|
66
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
67
|
+
);
|
|
68
|
+
// max(min(1000, 720), 800) + (1050 - 1000) non-schedule runs
|
|
69
|
+
expect(priced.substitutedRuns).toBe(850);
|
|
70
|
+
expect(priced.effectRuns).toBe(80);
|
|
71
|
+
expect(priced.enabledOnlyRuns).toBe(250);
|
|
72
|
+
expect(priced.capApplied).toBe(true);
|
|
73
|
+
|
|
74
|
+
const under = priceWorkflow(facts({ runs: 10, countedRuns: 10, schedRuns: 10 }), {
|
|
75
|
+
tier: "smart",
|
|
76
|
+
days: 30,
|
|
77
|
+
band: "job",
|
|
78
|
+
});
|
|
79
|
+
expect(under.substitutedRuns).toBe(10);
|
|
80
|
+
expect(under.capApplied).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("the band is wider for one job than for a fleet sum, and p50 is the point", () => {
|
|
84
|
+
const f = facts({ runs: 100, countedRuns: 100, opsSum: 100 * 40 });
|
|
85
|
+
const job = priceWorkflow(f, { tier: "smart", days: 30, band: "job" });
|
|
86
|
+
const fleet = priceWorkflow(f, { tier: "smart", days: 30, band: "fleet" });
|
|
87
|
+
expect(job.savingUsd.p50).toBeCloseTo(fleet.savingUsd.p50, 9);
|
|
88
|
+
expect(job.savingUsd.p50).toBeCloseTo(100 * job.agentOnlyUsdPerRun, 9);
|
|
89
|
+
expect(job.savingUsd.p10).toBeLessThan(fleet.savingUsd.p10);
|
|
90
|
+
expect(job.savingUsd.p90).toBeGreaterThan(fleet.savingUsd.p90);
|
|
91
|
+
expect(job.hoursSaved.p10).toBeLessThan(job.hoursSaved.p50);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("kept agent spend appears on both sides; actual spend is per substituted run", () => {
|
|
95
|
+
const priced = priceWorkflow(
|
|
96
|
+
facts({
|
|
97
|
+
runs: 4,
|
|
98
|
+
countedRuns: 4,
|
|
99
|
+
opsSum: 40,
|
|
100
|
+
agentTasks: 2,
|
|
101
|
+
agentUsd: 8,
|
|
102
|
+
followupUsd: 2,
|
|
103
|
+
estimatedLlmUsd: 1,
|
|
104
|
+
agentMs: 7_200_000,
|
|
105
|
+
computeSecs: 3600,
|
|
106
|
+
}),
|
|
107
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
108
|
+
);
|
|
109
|
+
expect(priced.actualUsd).toBeCloseTo(11, 9);
|
|
110
|
+
// The $1 LLM estimate is not measured spend.
|
|
111
|
+
expect(priced.measuredUsd).toBeCloseTo(10, 9);
|
|
112
|
+
expect(priced.estimatedLlmUsd).toBeCloseTo(1, 9);
|
|
113
|
+
expect(priced.agentOnlyUsd.p50 - 10).toBeCloseTo(4 * priced.agentOnlyUsdPerRun, 9);
|
|
114
|
+
expect(priced.actualHours).toBeCloseTo(3, 9);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("measured spend is reported unscaled; the scaled estimate keeps the saving", () => {
|
|
118
|
+
// One $100 manual run and 999 skipped runs on one day.
|
|
119
|
+
const window = facts({ runs: 1000, countedRuns: 1, opsSum: 10, agentTasks: 1, agentUsd: 100 });
|
|
120
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 30, band: "job" });
|
|
121
|
+
expect(priced.substitutedRuns).toBe(1);
|
|
122
|
+
expect(priced.measuredUsd).toBe(100);
|
|
123
|
+
// The estimator's actual side is the scaled estimate, not the $100 measured.
|
|
124
|
+
expect(priced.actualUsd).toBeCloseTo(0.1, 9);
|
|
125
|
+
// Kept agent spend cancels: the saving is one substituted run at the unit cost.
|
|
126
|
+
expect(priced.savingUsd.p50).toBeCloseTo(priced.agentOnlyUsdPerRun, 9);
|
|
127
|
+
const [point] = splitByDay(window, [{ day: "2026-10-01", ...window }], {
|
|
128
|
+
tier: "smart",
|
|
129
|
+
days: 30,
|
|
130
|
+
});
|
|
131
|
+
expect(point?.measuredUsd).toBe(100);
|
|
132
|
+
expect(point?.actualUsd).toBeCloseTo(0.1, 9);
|
|
133
|
+
expect(point?.savingUsd).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("estimated LLM spend is reported apart from measured spend", () => {
|
|
137
|
+
// No recorded LLM cost: $5 is estimated from tokens and output size.
|
|
138
|
+
const window = facts({ runs: 1, countedRuns: 1, opsSum: 10, estimatedLlmUsd: 5 });
|
|
139
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 30, band: "job" });
|
|
140
|
+
expect(priced.measuredUsd).toBe(0);
|
|
141
|
+
expect(priced.estimatedLlmUsd).toBe(5);
|
|
142
|
+
// The saving still subtracts the estimate.
|
|
143
|
+
expect(priced.actualUsd).toBe(5);
|
|
144
|
+
expect(priced.savingUsd.p50).toBeCloseTo(priced.agentOnlyUsdPerRun - 5, 9);
|
|
145
|
+
const [point] = splitByDay(window, [{ day: "2026-10-01", ...window }], {
|
|
146
|
+
tier: "smart",
|
|
147
|
+
days: 30,
|
|
148
|
+
});
|
|
149
|
+
expect(point?.measuredUsd).toBe(0);
|
|
150
|
+
expect(point?.estimatedLlmUsd).toBe(5);
|
|
151
|
+
expect(point?.actualUsd).toBe(5);
|
|
152
|
+
expect(point?.savingUsd).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("recorded LLM cost replaces the token estimate", () => {
|
|
156
|
+
const priced = priceWorkflow(facts({ recordedLlmUsd: 2, estimatedLlmUsd: 5 }), {
|
|
157
|
+
tier: "smart",
|
|
158
|
+
days: 30,
|
|
159
|
+
band: "job",
|
|
160
|
+
});
|
|
161
|
+
expect(priced.actualUsd).toBe(2);
|
|
162
|
+
expect(priced.measuredUsd).toBe(2);
|
|
163
|
+
expect(priced.estimatedLlmUsd).toBe(0);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("a pure agent dispatcher substitutes nothing and pays no review", () => {
|
|
167
|
+
const priced = priceWorkflow(facts({ runs: 2, countedRuns: 2, agentTasks: 2, agentUsd: 4 }), {
|
|
168
|
+
tier: "smart",
|
|
169
|
+
days: 30,
|
|
170
|
+
band: "job",
|
|
171
|
+
});
|
|
172
|
+
expect(priced.agentOnlyUsdPerRun).toBe(0);
|
|
173
|
+
expect(priced.savingUsd.p50).toBe(0);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("node ops and job keys", () => {
|
|
177
|
+
const ops = nodeOpsOf(
|
|
178
|
+
{
|
|
179
|
+
nodes: [
|
|
180
|
+
{ id: "s", type: "script", config: { script: "await a(); await b()" } },
|
|
181
|
+
{ id: "bare", type: "script", config: { script: "echo hi" } },
|
|
182
|
+
{ id: "known", type: "swarm-script", config: { scriptName: "known" } },
|
|
183
|
+
{ id: "unknown", type: "swarm-script", config: { scriptName: "nope" } },
|
|
184
|
+
{ id: "n", type: "notify" },
|
|
185
|
+
{ id: "a", type: "agent-task" },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
new Map([["known", 42]]),
|
|
189
|
+
);
|
|
190
|
+
expect(Object.fromEntries(ops)).toEqual({
|
|
191
|
+
s: 2,
|
|
192
|
+
bare: 1,
|
|
193
|
+
known: 42,
|
|
194
|
+
unknown: DEFAULT_OPS,
|
|
195
|
+
n: 1,
|
|
196
|
+
a: 0,
|
|
197
|
+
});
|
|
198
|
+
expect(jobKey("pr-fix-loop-retired-2026-10-28")).toBe("pr-fix-loop");
|
|
199
|
+
expect(jobKey("pr-fix-loop")).toBe("pr-fix-loop");
|
|
200
|
+
expect(F_FOLLOWUP).toBe(0.107);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("daily split sums to the window, and capped schedule runs spread pro rata", () => {
|
|
204
|
+
// 2 days of polling every 5 minutes (288 a day) against a 1-day cap of 24,
|
|
205
|
+
// plus one manual run with an agent task and a recorded LLM cost.
|
|
206
|
+
const day1 = facts({
|
|
207
|
+
runs: 288,
|
|
208
|
+
countedRuns: 288,
|
|
209
|
+
schedRuns: 288,
|
|
210
|
+
schedEffectRuns: 3,
|
|
211
|
+
opsSum: 288 * 5,
|
|
212
|
+
recordedLlmUsd: 0.4,
|
|
213
|
+
});
|
|
214
|
+
const day2 = facts({
|
|
215
|
+
runs: 145,
|
|
216
|
+
countedRuns: 145,
|
|
217
|
+
schedRuns: 144,
|
|
218
|
+
schedEffectRuns: 0,
|
|
219
|
+
opsSum: 145 * 5,
|
|
220
|
+
agentTasks: 1,
|
|
221
|
+
agentUsd: 2,
|
|
222
|
+
followupUsd: 0.1,
|
|
223
|
+
recordedLlmUsd: 0.2,
|
|
224
|
+
});
|
|
225
|
+
const window = facts({});
|
|
226
|
+
for (const k of Object.keys(window) as (keyof WorkflowFacts)[]) window[k] = day1[k] + day2[k];
|
|
227
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 1, band: "job" });
|
|
228
|
+
expect(priced.capApplied).toBe(true);
|
|
229
|
+
const points = splitByDay(
|
|
230
|
+
window,
|
|
231
|
+
[
|
|
232
|
+
{ day: "2026-10-01", ...day1 },
|
|
233
|
+
{ day: "2026-10-02", ...day2 },
|
|
234
|
+
],
|
|
235
|
+
{ tier: "smart", days: 1 },
|
|
236
|
+
);
|
|
237
|
+
const sum = (key: "savingUsd" | "actualUsd" | "measuredUsd" | "estimatedLlmUsd") =>
|
|
238
|
+
points.reduce((s, p) => s + p[key], 0);
|
|
239
|
+
expect(sum("savingUsd")).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
240
|
+
expect(sum("actualUsd")).toBeCloseTo(priced.actualUsd, 9);
|
|
241
|
+
expect(sum("measuredUsd")).toBeCloseTo(priced.measuredUsd, 9);
|
|
242
|
+
expect(sum("estimatedLlmUsd")).toBeCloseTo(priced.estimatedLlmUsd, 9);
|
|
243
|
+
// The 24 counted schedule runs split 288:144; the manual run stays on day 2.
|
|
244
|
+
const unit = priced.agentOnlyUsdPerRun;
|
|
245
|
+
const share = priced.substitutedRuns / window.runs;
|
|
246
|
+
expect(points[0]?.savingUsd).toBeCloseTo(16 * unit - 0.4 * share, 9);
|
|
247
|
+
expect(points[1]?.savingUsd).toBeCloseTo((8 + 1) * unit - 0.2 * share, 9);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("calibration", () => {
|
|
252
|
+
const stored = (over: Record<string, unknown> = {}) =>
|
|
253
|
+
JSON.stringify({ calibratedAt: "2026-12-01", model: "claude-opus-5-5", curve: CURVE, ...over });
|
|
254
|
+
|
|
255
|
+
test("a stored curve parses as a deployment calibration", () => {
|
|
256
|
+
expect(parseCalibration(stored())).toMatchObject({
|
|
257
|
+
source: "deployment",
|
|
258
|
+
calibratedAt: "2026-12-01",
|
|
259
|
+
model: "claude-opus-5-5",
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("a missing, malformed or wrongly shaped value is null, so callers use the shipped curve", () => {
|
|
264
|
+
expect(parseCalibration(null)).toBeNull();
|
|
265
|
+
expect(parseCalibration("not json")).toBeNull();
|
|
266
|
+
expect(parseCalibration(stored({ calibratedAt: "yesterday" }))).toBeNull();
|
|
267
|
+
const short = { ...CURVE, smart: { usd: CURVE.smart.usd.slice(1), hrs: CURVE.smart.hrs } };
|
|
268
|
+
expect(parseCalibration(stored({ curve: short }))).toBeNull();
|
|
269
|
+
const zero = { ...CURVE, smol: { usd: CURVE.smol.usd.map(() => 0), hrs: CURVE.smol.hrs } };
|
|
270
|
+
expect(parseCalibration(stored({ curve: zero }))).toBeNull();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("priceWorkflow uses the given curve and the shipped one by default", () => {
|
|
274
|
+
const doubled = Object.fromEntries(
|
|
275
|
+
SAVINGS_TIERS.map((t) => [t, { usd: CURVE[t].usd.map((v) => v * 2), hrs: CURVE[t].hrs }]),
|
|
276
|
+
) as typeof CURVE;
|
|
277
|
+
const f = facts({ opsSum: 10 });
|
|
278
|
+
const base = priceWorkflow(f, { tier: "smart", days: 30, band: "job" });
|
|
279
|
+
const same = priceWorkflow(f, { tier: "smart", days: 30, band: "job", curve: CURVE });
|
|
280
|
+
const twice = priceWorkflow(f, { tier: "smart", days: 30, band: "job", curve: doubled });
|
|
281
|
+
expect(same.agentOnlyUsdPerRun).toBe(base.agentOnlyUsdPerRun);
|
|
282
|
+
expect(twice.agentOnlyUsdPerRun - F_FOLLOWUP).toBeCloseTo(
|
|
283
|
+
2 * (base.agentOnlyUsdPerRun - F_FOLLOWUP),
|
|
284
|
+
6,
|
|
285
|
+
);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
@@ -691,6 +691,8 @@ describe("script connections", () => {
|
|
|
691
691
|
markMigrationApplied(database, "281_model_profiles_pr2.sql");
|
|
692
692
|
// 283 alters workflow_runs, which this fixture does not create.
|
|
693
693
|
markMigrationApplied(database, "283_workflow_run_definitions.sql");
|
|
694
|
+
// 284 alters model_profiles (made by the skipped 220) and agent_tasks.
|
|
695
|
+
markMigrationApplied(database, "284_model_profile_fallbacks.sql");
|
|
694
696
|
|
|
695
697
|
const id = crypto.randomUUID();
|
|
696
698
|
const now = new Date().toISOString();
|
|
@@ -65,6 +65,46 @@ describe("script SDK allowlist", () => {
|
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
test("savings calibration is REST-only: reachable from scripts, not an MCP tool or bridge entry", async () => {
|
|
69
|
+
const requests: { method: string; path: string; body: unknown }[] = [];
|
|
70
|
+
const httpServer = Bun.serve({
|
|
71
|
+
port: 0,
|
|
72
|
+
async fetch(req) {
|
|
73
|
+
requests.push({
|
|
74
|
+
method: req.method,
|
|
75
|
+
path: new URL(req.url).pathname,
|
|
76
|
+
body: req.method === "POST" ? await req.json() : undefined,
|
|
77
|
+
});
|
|
78
|
+
return Response.json({ ok: true });
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const config = new SwarmConfig({
|
|
82
|
+
system: {
|
|
83
|
+
apiKey: { value: "sdk-test-key", isSecret: true },
|
|
84
|
+
agentId: { value: "sdk-test-agent", isSecret: false },
|
|
85
|
+
mcpBaseUrl: { value: `http://127.0.0.1:${httpServer.port}`, isSecret: false },
|
|
86
|
+
},
|
|
87
|
+
user: {},
|
|
88
|
+
});
|
|
89
|
+
const sdk = createSwarmSdk(config);
|
|
90
|
+
try {
|
|
91
|
+
await sdk.savings_calibrationGet();
|
|
92
|
+
await sdk.savings_calibrationRun({ days: 7, apply: true });
|
|
93
|
+
expect(requests).toEqual([
|
|
94
|
+
{ method: "GET", path: "/api/savings/calibration", body: undefined },
|
|
95
|
+
{ method: "POST", path: "/api/savings/calibration", body: { days: 7, apply: true } },
|
|
96
|
+
]);
|
|
97
|
+
} finally {
|
|
98
|
+
httpServer.stop(true);
|
|
99
|
+
}
|
|
100
|
+
// Neither an MCP tool nor an allowlist entry, so the workflow capability list and the bridge skip them.
|
|
101
|
+
for (const name of ["savings_calibrationGet", "savings_calibrationRun"]) {
|
|
102
|
+
expect((SDK_ALLOWLIST as readonly string[]).includes(name)).toBe(false);
|
|
103
|
+
expect(isMcpToolAllowedForScripts(name)).toBe(false);
|
|
104
|
+
expect(name in registeredTools).toBe(false);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
68
108
|
test("workflow_listRuns sends bounded pagination defaults and rejects an excessive limit", async () => {
|
|
69
109
|
let requestUrl: URL | undefined;
|
|
70
110
|
const httpServer = Bun.serve({
|
|
@@ -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
|