@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.
Files changed (194) hide show
  1. package/dist/{acp-adapter-pdy3qsvg.js → acp-adapter-fqzkxyra.js} +3 -3
  2. package/dist/{actions-pwjpn0j6.js → actions-kxek041g.js} +17 -17
  3. package/dist/{amp-adapter-cq9jgj6x.js → amp-adapter-ce7jjke4.js} +1 -1
  4. package/dist/{app-cnfffgwg.js → app-v6zz8yh0.js} +3 -3
  5. package/dist/{assistant-kpn317y1.js → assistant-m0sw9xx2.js} +18 -18
  6. package/dist/{boot-args-schema-pbbnhmc3.js → boot-args-schema-66bk37wv.js} +1 -1
  7. package/dist/{boot-reembed-9m0ysxma.js → boot-reembed-edjpwsc1.js} +1 -1
  8. package/dist/{boot-reembed-majbn53m.js → boot-reembed-y27n09tz.js} +1 -1
  9. package/dist/{boot-scrub-sweep-app8g8ym.js → boot-scrub-sweep-1xc35965.js} +3 -3
  10. package/dist/{boot-seeds-pbtmvcjm.js → boot-seeds-7hjj91qj.js} +4 -4
  11. package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
  12. package/dist/{claude-adapter-wn1g3qp5.js → claude-adapter-stw7jdcf.js} +3 -3
  13. package/dist/{claude-managed-setup-pd47nzch.js → claude-managed-setup-y6z2perp.js} +1 -1
  14. package/dist/{claude-sdk-session-3a2a6589.js → claude-sdk-session-vvya8wqk.js} +3 -3
  15. package/dist/{cli-wk18cm92.js → cli-0cq8y6m7.js} +1 -1
  16. package/dist/{cli-p1w18yhx.js → cli-1pz0330a.js} +1 -1
  17. package/dist/{cli-d3p5vwbk.js → cli-1qkz151v.js} +3 -3
  18. package/dist/{cli-89cqnasv.js → cli-26ctbcdp.js} +18 -6
  19. package/dist/{cli-syybb0p1.js → cli-2kvhc7x8.js} +7 -7
  20. package/dist/{cli-93k32c37.js → cli-3e875j5p.js} +128 -41
  21. package/dist/{cli-k0615eh8.js → cli-3sy2xags.js} +10 -10
  22. package/dist/{cli-dy32zecz.js → cli-3vmb0n58.js} +1 -1
  23. package/dist/{cli-4r05hnqa.js → cli-4vzgeta4.js} +13 -13
  24. package/dist/{cli-b5rs97a6.js → cli-5y340nzn.js} +4 -4
  25. package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
  26. package/dist/{cli-jcpr5smb.js → cli-837vfs2x.js} +2 -2
  27. package/dist/{cli-b085njxz.js → cli-959kp5h2.js} +12 -11
  28. package/dist/{cli-k93bq1wq.js → cli-97ae65rz.js} +4 -4
  29. package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
  30. package/dist/{cli-bb431xey.js → cli-a0z912j7.js} +121 -33
  31. package/dist/{cli-k26bkr9t.js → cli-b98a65ed.js} +3 -3
  32. package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
  33. package/dist/{cli-tk7cjj8h.js → cli-dzpc6en0.js} +1 -1
  34. package/dist/{cli-6mma83xa.js → cli-e1p3n5gq.js} +4 -4
  35. package/dist/{cli-re4raaj0.js → cli-f4e8r23x.js} +1 -1
  36. package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
  37. package/dist/{cli-pcad4cb1.js → cli-f6bahpn5.js} +1 -1
  38. package/dist/{cli-b8e9nb04.js → cli-fpjmegdb.js} +1 -1
  39. package/dist/{cli-0ntbxyaa.js → cli-fwy8kfd6.js} +271 -37
  40. package/dist/{cli-tacge1w0.js → cli-g5mtmf6t.js} +6 -6
  41. package/dist/{cli-sn7rtnj4.js → cli-gyt3zydq.js} +3 -3
  42. package/dist/{cli-vbh10fqa.js → cli-j24zbska.js} +3 -3
  43. package/dist/{cli-vqptjbr7.js → cli-jdknh18m.js} +10 -10
  44. package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
  45. package/dist/{cli-9vhebtjz.js → cli-mxn1qvbn.js} +3 -2
  46. package/dist/{cli-zcsw143p.js → cli-n6vtrcht.js} +1 -1
  47. package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
  48. package/dist/{cli-gax7fk3t.js → cli-pfs8adn4.js} +1 -1
  49. package/dist/{cli-1xh9a7hn.js → cli-q24n86d2.js} +2 -2
  50. package/dist/{cli-7w69ne2f.js → cli-rcecc3yq.js} +167 -43
  51. package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
  52. package/dist/{cli-yn2bbre9.js → cli-rmzsadkf.js} +1 -1
  53. package/dist/{cli-a3b239vq.js → cli-t2tma8gb.js} +1 -1
  54. package/dist/{cli-9wngrawf.js → cli-tekytdq9.js} +2 -2
  55. package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
  56. package/dist/{cli-cyhbbd1z.js → cli-w401b9tq.js} +1 -1
  57. package/dist/{cli-jywyhqws.js → cli-xf3qw745.js} +3 -3
  58. package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
  59. package/dist/{cli-yncmerje.js → cli-zh9rsbqf.js} +2 -2
  60. package/dist/cli.js +16 -16
  61. package/dist/{codex-adapter-nha71q3n.js → codex-adapter-zerf5qsp.js} +1 -1
  62. package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
  63. package/dist/{codex-session-runner-ak9x1k1h.js → codex-session-runner-89s304py.js} +1 -1
  64. package/dist/{commands-f587qpq8.js → commands-jeh1b51j.js} +3 -3
  65. package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
  66. package/dist/{controllers-connect-k5sg9m9h.js → controllers-connect-nxa1ddwn.js} +18 -18
  67. package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
  68. package/dist/{db-nzf8zb5z.js → db-2dvay0es.js} +3 -3
  69. package/dist/{db-amm8w15a.js → db-b36qn6k3.js} +2 -2
  70. package/dist/{dispatcher-89zrts8f.js → dispatcher-gndbta01.js} +16 -16
  71. package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-f75sz821.js} +1 -1
  72. package/dist/{e2b-jkwfhbcv.js → e2b-3gpc2n3w.js} +1 -1
  73. package/dist/{e2b-s16txnpx.js → e2b-jbm7mj93.js} +1 -1
  74. package/dist/{embedding-space-ezwenjmj.js → embedding-space-4p05vb2x.js} +6 -6
  75. package/dist/{embeddings-np74ht6g.js → embeddings-m6768mgh.js} +1 -1
  76. package/dist/{external-channel-z46yx9d7.js → external-channel-gjv3jne3.js} +2 -2
  77. package/dist/{fx-adapter-3q12snn6.js → fx-adapter-rpsgb1tw.js} +4 -4
  78. package/dist/{grok-adapter-ahb1w033.js → grok-adapter-n2m3zjg1.js} +4 -4
  79. package/dist/handlers-nv8edn19.js +32 -0
  80. package/dist/{heartbeat-dt9qw9c8.js → heartbeat-a1tv60gt.js} +19 -19
  81. package/dist/{hook-8k6fbz9b.js → hook-8h5dzcgq.js} +2 -2
  82. package/dist/{hook-jgcgygex.js → hook-cyaps9ba.js} +4 -4
  83. package/dist/{http-haw4r8ne.js → http-t15mhbd9.js} +1731 -77
  84. package/dist/{index-s4ewdma4.js → index-ksmyd6kc.js} +16 -16
  85. package/dist/{index-tez78qj3.js → index-qav6455f.js} +13 -11
  86. package/dist/index-rjnrje98.js +32 -0
  87. package/dist/index-tv3413wy.js +33 -0
  88. package/dist/{index-5gk12my8.js → index-w1zqf680.js} +1 -1
  89. package/dist/{keepalive-xn6s7rmg.js → keepalive-91s7hzrb.js} +3 -3
  90. package/dist/{lead-6ygbfhbh.js → lead-3hmddvrm.js} +30 -30
  91. package/dist/{maintenance-vdts800b.js → maintenance-7pjmy5xy.js} +1 -1
  92. package/dist/{oauth-refresh-sweep-094c8wfk.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
  93. package/dist/{onboard-v99eh56m.js → onboard-74st7pag.js} +3 -3
  94. package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
  95. package/dist/{otel-impl-q7yr9yp0.js → otel-impl-rnzey8cb.js} +1 -1
  96. package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-6mkwq64n.js} +3 -2
  97. package/dist/{pricing-refresh-7dh2yase.js → pricing-refresh-ha21jhk7.js} +2 -2
  98. package/dist/{rbac-roles-npbmdh77.js → rbac-roles-59dxachk.js} +2 -2
  99. package/dist/{rbac-roles-mdmc96p4.js → rbac-roles-wqhma4dr.js} +3 -3
  100. package/dist/{render-v2-twhhwmms.js → render-v2-14kpzx12.js} +3 -3
  101. package/dist/{resume-5gsrjd5e.js → resume-gsa5fb5f.js} +6 -6
  102. package/dist/{session-access-m191x30x.js → session-access-skm7bnp6.js} +4 -4
  103. package/dist/{session-source-backfill-nt923ask.js → session-source-backfill-pbqzbncv.js} +2 -2
  104. package/dist/{setup-wv467afy.js → setup-5yermsem.js} +1 -1
  105. package/dist/{work-objects-8zkrpy13.js → work-objects-xj0ck0w4.js} +19 -19
  106. package/dist/{worker-follow-up-cecqszem.js → worker-follow-up-911xc0b8.js} +18 -16
  107. package/dist/{worker-mz5z7kj0.js → worker-qgg0m2gw.js} +30 -30
  108. package/openapi.json +1741 -290
  109. package/package.json +2 -2
  110. package/src/apps/catalog.generated.json +120 -1
  111. package/src/apps/definition.ts +38 -11
  112. package/src/apps/page-validator.ts +88 -0
  113. package/src/be/db/model-profiles.ts +110 -11
  114. package/src/be/db/tasks/read.ts +20 -0
  115. package/src/be/db/workflow-run-definitions.ts +19 -8
  116. package/src/be/db-client.ts +43 -5
  117. package/src/be/db.ts +9 -3
  118. package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
  119. package/src/be/model-profile-check.ts +43 -18
  120. package/src/be/runtime-pools/routing.ts +1 -0
  121. package/src/be/savings/calibrate.ts +468 -0
  122. package/src/be/savings/compute.ts +182 -0
  123. package/src/be/savings/model.ts +406 -0
  124. package/src/be/scripts/typecheck.ts +5 -0
  125. package/src/be/seed/agent-fs-provision.ts +48 -11
  126. package/src/be/seed/workflows-seeder.ts +67 -23
  127. package/src/be/skill-parser.ts +19 -7
  128. package/src/commands/onboard/agent-fs-version.ts +1 -1
  129. package/src/commands/provider-error-class.ts +97 -0
  130. package/src/commands/runner.ts +99 -17
  131. package/src/extensions/contract-types.generated.ts +1 -1
  132. package/src/http/all-routes.ts +2 -0
  133. package/src/http/fs.ts +8 -2
  134. package/src/http/index.ts +4 -0
  135. package/src/http/model-profiles.ts +43 -10
  136. package/src/http/poll.ts +1 -0
  137. package/src/http/savings-calibration.ts +277 -0
  138. package/src/http/savings.ts +363 -0
  139. package/src/http/tasks.ts +46 -4
  140. package/src/http/trackers/authorize-gate.ts +41 -0
  141. package/src/http/trackers/jira.ts +26 -4
  142. package/src/http/trackers/linear.ts +26 -4
  143. package/src/integrations/chat-sdk/limits.ts +6 -1
  144. package/src/jira/oauth.ts +7 -1
  145. package/src/linear/README.md +2 -1
  146. package/src/linear/oauth.ts +7 -1
  147. package/src/providers/amp-adapter.ts +1 -1
  148. package/src/providers/codex-adapter.ts +3 -0
  149. package/src/providers/pi-mono-adapter.ts +6 -5
  150. package/src/providers/types.ts +7 -0
  151. package/src/scripts-runtime/sdk-allowlist.ts +11 -1
  152. package/src/scripts-runtime/swarm-sdk.ts +6 -0
  153. package/src/scripts-runtime/types/stdlib.d.ts +9 -0
  154. package/src/scripts-runtime/types/swarm-extension.d.ts +34 -0
  155. package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -0
  156. package/src/tasks/worker-follow-up.ts +142 -3
  157. package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
  158. package/src/tests/apps-chart-shell.test.ts +170 -0
  159. package/src/tests/apps-icon.test.ts +156 -2
  160. package/src/tests/chat-sdk-relay.test.ts +12 -0
  161. package/src/tests/codex-adapter.test.ts +11 -0
  162. package/src/tests/comb-default.test.ts +6 -0
  163. package/src/tests/core-auth.test.ts +7 -6
  164. package/src/tests/db-client-busy-retry.test.ts +58 -6
  165. package/src/tests/deploy-guard.test.ts +154 -0
  166. package/src/tests/docs-index-footprint.test.js +3 -3
  167. package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
  168. package/src/tests/model-profile-fallbacks.test.ts +482 -0
  169. package/src/tests/model-profiles-api.test.ts +1 -0
  170. package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
  171. package/src/tests/provider-error-class.test.ts +174 -0
  172. package/src/tests/runner-provider-fallback.test.ts +197 -0
  173. package/src/tests/savings-calibration-api.test.ts +264 -0
  174. package/src/tests/savings-calibration.test.ts +201 -0
  175. package/src/tests/savings-compute.test.ts +406 -0
  176. package/src/tests/savings-model.test.ts +287 -0
  177. package/src/tests/script-connections.test.ts +2 -0
  178. package/src/tests/sdk-allowlist.test.ts +40 -0
  179. package/src/tests/seed-workflows.test.ts +167 -11
  180. package/src/tests/skill-parser.test.ts +45 -0
  181. package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
  182. package/src/tests/workflow-definition-pinning.test.ts +128 -3
  183. package/src/tests/workflow-script-principal.test.ts +94 -4
  184. package/src/tools/app-upsert.ts +1 -1
  185. package/src/tools/model-profiles/list-model-profiles.ts +4 -2
  186. package/src/tools/update-profile.ts +1 -1
  187. package/src/types.ts +115 -33
  188. package/src/utils/constants.ts +2 -0
  189. package/templates/skills/apps/SKILL.md +62 -3
  190. package/templates/skills/apps/content.md +62 -3
  191. package/templates/skills/swarm-docs/content.md +2 -0
  192. package/dist/handlers-vbww69re.js +0 -32
  193. package/dist/index-4xwaf5th.js +0 -32
  194. package/dist/index-f0hcrs8e.js +0 -33
@@ -0,0 +1,170 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { parseAppDefinition } from "../apps/definition";
3
+
4
+ const fixture = (name: string) =>
5
+ Bun.file(new URL(`./fixtures/${name}`, import.meta.url)).json() as Promise<Record<string, any>>;
6
+
7
+ const definition = await fixture("app-shell-charts-definition.json.txt");
8
+
9
+ type Elements = Record<string, { type: string; props: Record<string, unknown> }>;
10
+
11
+ function withProps(page: string, elementId: string, props: Record<string, unknown>) {
12
+ const copy = structuredClone(definition);
13
+ const elements = copy.pages[page].elements as Elements;
14
+ elements[elementId]!.props = { ...elements[elementId]!.props, ...props };
15
+ return copy;
16
+ }
17
+
18
+ async function issuesFor(input: unknown) {
19
+ const parsed = await parseAppDefinition(input);
20
+ return parsed.success ? [] : parsed.issues;
21
+ }
22
+
23
+ async function pathsFor(input: unknown) {
24
+ return (await issuesFor(input)).map((i) => i.path);
25
+ }
26
+
27
+ describe("Chart, Metric sparkline and the sidebar layout", () => {
28
+ test("the sample app using all three passes validation", async () => {
29
+ const parsed = await parseAppDefinition(definition);
30
+ if (!parsed.success) console.error(parsed.issues);
31
+ expect(parsed.success).toBe(true);
32
+ });
33
+
34
+ test("Chart rejects unknown and malformed props", async () => {
35
+ const chart = "pages.overview.elements.deploysChart.props";
36
+ expect(await pathsFor(withProps("overview", "deploysChart", { colour: "red" }))).toContain(
37
+ `${chart}.colour`,
38
+ );
39
+ expect(await pathsFor(withProps("overview", "deploysChart", { kind: "pie" }))).toContain(
40
+ `${chart}.kind`,
41
+ );
42
+ expect(await pathsFor(withProps("overview", "deploysChart", { xType: "log" }))).toContain(
43
+ `${chart}.xType`,
44
+ );
45
+ expect(await pathsFor(withProps("overview", "deploysChart", { format: "bytes" }))).toContain(
46
+ `${chart}.format`,
47
+ );
48
+ expect(await pathsFor(withProps("overview", "deploysChart", { series: [] }))).toContain(
49
+ `${chart}.series`,
50
+ );
51
+ const nine = Array.from({ length: 9 }, () => ({ key: "deploys" }));
52
+ expect(await pathsFor(withProps("overview", "deploysChart", { series: nine }))).toContain(
53
+ `${chart}.series`,
54
+ );
55
+ expect(
56
+ await pathsFor(
57
+ withProps("overview", "deploysChart", { series: [{ key: "deploys", color: "pink" }] }),
58
+ ),
59
+ ).toContain(`${chart}.series.0.color`);
60
+ expect(
61
+ await pathsFor(
62
+ withProps("overview", "deploysChart", { series: [{ key: "deploys", stack: "a" }] }),
63
+ ),
64
+ ).toContain(`${chart}.series.0.stack`);
65
+ expect(
66
+ await pathsFor(
67
+ withProps("overview", "deploysChart", { series: [{ key: "deploys" }, { key: "deploys" }] }),
68
+ ),
69
+ ).toContain(`${chart}.series.1.key`);
70
+ expect(await pathsFor(withProps("overview", "deploysChart", { currency: "usd" }))).toContain(
71
+ `${chart}.currency`,
72
+ );
73
+ expect(await pathsFor(withProps("overview", "deploysChart", { height: 40 }))).toContain(
74
+ `${chart}.height`,
75
+ );
76
+ const missingX = structuredClone(definition);
77
+ delete (missingX.pages.overview.elements as Elements).deploysChart!.props.x;
78
+ expect(await pathsFor(missingX)).toContain(`${chart}.x`);
79
+ });
80
+
81
+ test("Chart x and series keys are cross-checked against the bound query's model", async () => {
82
+ expect(await issuesFor(withProps("overview", "deploysChart", { x: "day" }))).toContainEqual({
83
+ path: "pages.overview.elements.deploysChart.props.x",
84
+ message: 'unknown or hidden column "day" on model "day"',
85
+ });
86
+ expect(
87
+ await issuesFor(withProps("overview", "deploysChart", { series: [{ key: "deploy" }] })),
88
+ ).toContainEqual({
89
+ path: "pages.overview.elements.deploysChart.props.series.0.key",
90
+ message: 'unknown or hidden column "deploy" on model "day"',
91
+ });
92
+ });
93
+
94
+ test("Metric sparkline rejects malformed values and unknown props", async () => {
95
+ const tile = "pages.overview.elements.failuresTile.props";
96
+ expect(await pathsFor(withProps("overview", "failuresTile", { sparkline: ["5"] }))).toContain(
97
+ `${tile}.sparkline.0`,
98
+ );
99
+ expect(await pathsFor(withProps("overview", "failuresTile", { sparkline: 5 }))).toContain(
100
+ `${tile}.sparkline`,
101
+ );
102
+ expect(await pathsFor(withProps("overview", "failuresTile", { sparklineKey: 3 }))).toContain(
103
+ `${tile}.sparklineKey`,
104
+ );
105
+ expect(await pathsFor(withProps("overview", "failuresTile", { sparkLine: [1, 2] }))).toContain(
106
+ `${tile}.sparkLine`,
107
+ );
108
+ });
109
+
110
+ test("layout and page shell fields are validated", async () => {
111
+ expect(await pathsFor({ ...definition, layout: "tabs" })).toContain("layout");
112
+
113
+ const badIcon = structuredClone(definition);
114
+ badIcon.pages.overview.icon = "chart-pie";
115
+ expect(await issuesFor(badIcon)).toContainEqual({
116
+ path: "pages.overview.icon",
117
+ message: 'unknown icon "chart-pie"',
118
+ });
119
+
120
+ const unknownPageKey = structuredClone(definition);
121
+ unknownPageKey.pages.overview.subtitle = "x";
122
+ expect((await pathsFor(unknownPageKey)).some((p) => p.startsWith("pages.overview"))).toBe(true);
123
+
124
+ const missingHeader = structuredClone(definition);
125
+ missingHeader.pages.overview.headerActions = "nope";
126
+ expect(await issuesFor(missingHeader)).toContainEqual({
127
+ path: "pages.overview.headerActions",
128
+ message: 'element "nope" not found',
129
+ });
130
+
131
+ const doubled = structuredClone(definition);
132
+ doubled.pages.overview.elements.root.children.push("headerRefresh");
133
+ expect(await issuesFor(doubled)).toContainEqual({
134
+ path: "pages.overview.headerActions",
135
+ message: 'element "headerRefresh" is already rendered from root',
136
+ });
137
+
138
+ // The header subtree counts as reachable only through `headerActions`.
139
+ const orphan = structuredClone(definition);
140
+ delete orphan.pages.overview.headerActions;
141
+ delete orphan.layout;
142
+ expect(await pathsFor(orphan)).toContain("pages.overview.elements.headerRefresh");
143
+
144
+ const noLayout = structuredClone(definition);
145
+ delete noLayout.layout;
146
+ const paths = await pathsFor(noLayout);
147
+ expect(paths).toContain("pages.overview.headerActions");
148
+ expect(paths).toContain("pages.settings.nav");
149
+ // Icons and descriptions are harmless without the layout.
150
+ expect(paths).not.toContain("pages.overview.icon");
151
+ expect(paths).not.toContain("pages.overview.description");
152
+ });
153
+
154
+ test("existing definitions still validate and none opts into the sidebar layout", async () => {
155
+ for (const name of [
156
+ "bookmarks-definition.json.txt",
157
+ "catalog-feedback-definition.json.txt",
158
+ "catalog-inputs-definition.json.txt",
159
+ "catalog-table-definition.json.txt",
160
+ "kibo-blocks-definition.json.txt",
161
+ // prs-app-definition is left out: its script refs need a seeded DB.
162
+ ]) {
163
+ const existing = await fixture(name);
164
+ const parsed = await parseAppDefinition(existing);
165
+ if (!parsed.success) console.error(name, parsed.issues);
166
+ expect(parsed.success).toBe(true);
167
+ expect(existing.layout).toBeUndefined();
168
+ }
169
+ });
170
+ });
@@ -1,8 +1,20 @@
1
1
  import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
2
  import { unlink } from "node:fs/promises";
3
- import { parseAppDefinition } from "../apps/definition";
3
+ import {
4
+ type AppDefinition,
5
+ applyAppDefinitionPatch,
6
+ parseAppDefinition,
7
+ } from "../apps/definition";
4
8
  import { createApp, getApp, listApps, updateApp } from "../apps/store";
5
- import { closeDb, getDbClient, initDb } from "../be/db";
9
+ import {
10
+ closeDb,
11
+ createAgent,
12
+ getAgentById,
13
+ getDbClient,
14
+ initDb,
15
+ updateAgentProfile,
16
+ } from "../be/db";
17
+ import { AgentAvatarSchema, AgentSlackIconSchema, AppIconSchema } from "../types";
6
18
 
7
19
  const TEST_DB_PATH = `/private/tmp/test-apps-icon-${process.pid}.sqlite`;
8
20
 
@@ -118,3 +130,145 @@ describe("app icon", () => {
118
130
  expect(summary?.icon).toEqual(icon);
119
131
  });
120
132
  });
133
+
134
+ const URL_ICON = { type: "url", url: "https://example.com/icon.png" };
135
+ const AGENT_FS_ICON = { type: "agent-fs", path: "/apps/abc/icon-1.png" };
136
+ const AGENT_FS_ICON_WITH_DRIVE = {
137
+ type: "agent-fs",
138
+ path: "/apps/abc/icon-1.png",
139
+ orgId: "org-1",
140
+ driveId: "drive-1",
141
+ };
142
+
143
+ async function parseWithIcon(icon: unknown) {
144
+ return parseAppDefinition({ ...baseDefinition, icon }, { writerIsUser: true });
145
+ }
146
+
147
+ async function storedDefinition(icon: unknown): Promise<AppDefinition> {
148
+ const parsed = await parseWithIcon(icon);
149
+ if (!parsed.success) throw new Error(JSON.stringify(parsed.issues));
150
+ return parsed.definition;
151
+ }
152
+
153
+ describe("app icon url variant", () => {
154
+ test("accepts an https link", async () => {
155
+ expect(AppIconSchema.safeParse(URL_ICON).success).toBe(true);
156
+ expect((await parseWithIcon(URL_ICON)).success).toBe(true);
157
+ });
158
+
159
+ test("rejects http, javascript:, credentials, and links over 2048 characters", async () => {
160
+ const bad = [
161
+ "http://example.com/icon.png",
162
+ "javascript:alert(1)",
163
+ "https://user:pass@example.com/icon.png",
164
+ `https://example.com/${"a".repeat(2048)}`,
165
+ ];
166
+ for (const url of bad) {
167
+ expect(AppIconSchema.safeParse({ type: "url", url }).success).toBe(false);
168
+ expect((await parseWithIcon({ type: "url", url })).success).toBe(false);
169
+ }
170
+ });
171
+
172
+ test("Slack icons share the same https link rules", () => {
173
+ expect(AgentSlackIconSchema.safeParse(URL_ICON).success).toBe(true);
174
+ expect(
175
+ AgentSlackIconSchema.safeParse({ type: "url", url: "http://example.com/i.png" }).success,
176
+ ).toBe(false);
177
+ });
178
+ });
179
+
180
+ describe("app icon agent-fs variant", () => {
181
+ test("accepts a path alone or with both drive IDs", async () => {
182
+ for (const icon of [AGENT_FS_ICON, AGENT_FS_ICON_WITH_DRIVE]) {
183
+ expect(AppIconSchema.safeParse(icon).success).toBe(true);
184
+ expect((await parseWithIcon(icon)).success).toBe(true);
185
+ }
186
+ });
187
+
188
+ test("rejects a relative path, a .. segment, and a single drive ID", async () => {
189
+ const bad = [
190
+ { type: "agent-fs", path: "apps/abc/icon.png" },
191
+ { type: "agent-fs", path: "/apps/../secrets/icon.png" },
192
+ { type: "agent-fs", path: "/apps/abc/icon.png", orgId: "org-1" },
193
+ { type: "agent-fs", path: "/apps/abc/icon.png", driveId: "drive-1" },
194
+ ];
195
+ for (const icon of bad) {
196
+ expect(AppIconSchema.safeParse(icon).success).toBe(false);
197
+ expect((await parseWithIcon(icon)).success).toBe(false);
198
+ }
199
+ });
200
+ });
201
+
202
+ describe("app icon variants round trip", () => {
203
+ test("parseAppDefinition -> createApp -> listApps keeps each variant", async () => {
204
+ for (const icon of [URL_ICON, AGENT_FS_ICON, AGENT_FS_ICON_WITH_DRIVE]) {
205
+ const app = await createApp({
206
+ name: `Round trip ${icon.type}`,
207
+ definition: await storedDefinition(icon),
208
+ });
209
+ expect((await listApps()).find((summary) => summary.id === app.id)?.icon).toEqual(icon);
210
+ expect((await getApp(app.id))?.definition.icon).toEqual(icon);
211
+ }
212
+ });
213
+ });
214
+
215
+ describe("app icon merge patch", () => {
216
+ test("switching from lucide with color to url leaves no lucide keys", async () => {
217
+ const stored = await storedDefinition({ type: "lucide", icon: "star", color: "#f59e0b" });
218
+ const patched = applyAppDefinitionPatch(stored, { icon: URL_ICON });
219
+ expect(patched.success).toBe(true);
220
+ if (patched.success) {
221
+ expect((patched.definition as { icon: unknown }).icon).toEqual(URL_ICON);
222
+ const reparsed = await parseAppDefinition(patched.definition, { writerIsUser: true });
223
+ expect(reparsed.success).toBe(true);
224
+ }
225
+ });
226
+
227
+ test("switching from agent-fs to lucide leaves no agent-fs keys", async () => {
228
+ const stored = await storedDefinition(AGENT_FS_ICON_WITH_DRIVE);
229
+ const lucide = { type: "lucide", icon: "star" };
230
+ const patched = applyAppDefinitionPatch(stored, { icon: lucide });
231
+ expect(patched.success).toBe(true);
232
+ if (patched.success) {
233
+ expect((patched.definition as { icon: unknown }).icon).toEqual(lucide);
234
+ }
235
+ });
236
+
237
+ test("a null icon removes it", async () => {
238
+ const stored = await storedDefinition(URL_ICON);
239
+ const patched = applyAppDefinitionPatch(stored, { icon: null });
240
+ expect(patched.success).toBe(true);
241
+ if (patched.success) expect("icon" in (patched.definition as object)).toBe(false);
242
+ });
243
+ });
244
+
245
+ describe("agent avatars take the same icons", () => {
246
+ test("AgentAvatarSchema accepts lucide, url and agent-fs icons", () => {
247
+ expect(AgentAvatarSchema.safeParse({ type: "lucide", icon: "bot" }).success).toBe(true);
248
+ expect(AgentAvatarSchema.safeParse(URL_ICON).success).toBe(true);
249
+ expect(AgentAvatarSchema.safeParse(AGENT_FS_ICON).success).toBe(true);
250
+ });
251
+
252
+ test("AgentAvatarSchema rejects http links and a single drive ID", () => {
253
+ expect(
254
+ AgentAvatarSchema.safeParse({ type: "url", url: "http://example.com/x.png" }).success,
255
+ ).toBe(false);
256
+ expect(
257
+ AgentAvatarSchema.safeParse({ type: "agent-fs", path: "/agents/a/avatar.png", orgId: "o" })
258
+ .success,
259
+ ).toBe(false);
260
+ });
261
+
262
+ test("a url avatar round trips through the profile update, then an agent-fs one replaces it", async () => {
263
+ const agent = await createAgent({ name: "Avatar Agent", isLead: false, status: "idle" });
264
+ await updateAgentProfile(agent.id, { avatar: URL_ICON });
265
+ expect((await getAgentById(agent.id))?.avatar).toEqual(URL_ICON);
266
+
267
+ const fsAvatar = { type: "agent-fs" as const, path: `/agents/${agent.id}/avatar-1.png` };
268
+ await updateAgentProfile(agent.id, { avatar: fsAvatar });
269
+ expect((await getAgentById(agent.id))?.avatar).toEqual(fsAvatar);
270
+
271
+ await updateAgentProfile(agent.id, { avatar: null });
272
+ expect((await getAgentById(agent.id))?.avatar).toBeNull();
273
+ });
274
+ });
@@ -180,6 +180,18 @@ describe("chat relay text", () => {
180
180
  expect(chunks.join(" ")).toBe(words);
181
181
  expect(splitChatMessage("short", 4096)).toEqual(["short"]);
182
182
  });
183
+
184
+ test("splitChatMessage does not loop on a surrogate pair at a tiny limit", () => {
185
+ // A one-code-unit limit is smaller than an emoji: keep the pair whole.
186
+ expect(splitChatMessage("😀", 1)).toEqual(["😀"]);
187
+ // The cut still advances when text continues past the pair.
188
+ expect(splitChatMessage("a😀b", 1)).toEqual(["a", "😀", "b"]);
189
+ // A limit-wide window still never splits a pair.
190
+ const emojiChunks = splitChatMessage("😀😀😀", 2);
191
+ expect(emojiChunks).toEqual(["😀", "😀", "😀"]);
192
+ // A pair straddling the window edge moves the cut back, not to zero.
193
+ expect(splitChatMessage("ab😀cd", 3)).toEqual(["ab", "😀c", "d"]);
194
+ });
183
195
  });
184
196
 
185
197
  describe("chat relay watcher", () => {
@@ -18,6 +18,7 @@ import {
18
18
  } from "node:fs";
19
19
  import { homedir, tmpdir } from "node:os";
20
20
  import { join } from "node:path";
21
+ import { classifyProviderErrorOf } from "../commands/provider-error-class";
21
22
  import { renderContextBoundNote } from "../prompts/context-bound-note";
22
23
  import type {
23
24
  AgentMessageItem,
@@ -2682,6 +2683,16 @@ describe("CodexSession — rate-limit error preservation", () => {
2682
2683
  expect(result.isError).toBe(true);
2683
2684
  expect(result.rateLimitResetAt).toBeUndefined();
2684
2685
  });
2686
+
2687
+ test("an unexpected throw is a harness error: a 503 in its text never moves the task to a fallback profile", async () => {
2688
+ const { result } = await runSessionWithThrowingThread(
2689
+ [{ type: "thread.started", thread_id: "thread-mcp-503" }, { type: "turn.started" }],
2690
+ new Error("MCP error -32000: HTTP 503 Service Unavailable"),
2691
+ testConfig({ logFile: join(tmpLogDir, "mcp-503.log"), cwd: "" }),
2692
+ );
2693
+ expect(result.errorOrigin).toBe("harness");
2694
+ expect(classifyProviderErrorOf(result, result.failureReason, "gpt-6.1-sol")).toBeNull();
2695
+ });
2685
2696
  });
2686
2697
 
2687
2698
  describe("CodexSession context-bound note", () => {
@@ -75,12 +75,14 @@ describe("isBrowserReachableUrl", () => {
75
75
  "http://172.31.255.255",
76
76
  "http://192.168.1.10:7433",
77
77
  "http://169.254.169.254",
78
+ "http://0.0.0.0:7433",
78
79
  "http://[fd00::1]:7433",
79
80
  "http://[fe80::1]:7433",
80
81
  "http://[::ffff:10.0.0.5]:7433",
81
82
  "http://[::ffff:192.168.1.10]:7433",
82
83
  "http://[::ffff:172.16.0.1]:7433",
83
84
  "http://[::ffff:169.254.169.254]",
85
+ "http://[::ffff:0.0.0.0]:7433",
84
86
  "http://[::]:7433",
85
87
  "http://[ff02::1]:7433",
86
88
  "http://[ff00::1]:7433",
@@ -89,6 +91,10 @@ describe("isBrowserReachableUrl", () => {
89
91
  }
90
92
  });
91
93
 
94
+ test("treats 0.0.0.0 as unreachable", () => {
95
+ expect(isBrowserReachableUrl("http://0.0.0.0:7433")).toBe(false);
96
+ });
97
+
92
98
  test("an unparseable value is not reachable", () => {
93
99
  expect(isBrowserReachableUrl("agent-fs:7433")).toBe(false);
94
100
  expect(isBrowserReachableUrl("")).toBe(false);
@@ -98,18 +98,19 @@ describe("handleCore auth middleware (route() auth.apiKey=false is honored)", ()
98
98
  expect(res.status).not.toBe(401);
99
99
  });
100
100
 
101
- test("Linear webhook/authorize/callback are still public", async () => {
102
- for (const path of [
103
- "/api/trackers/linear/authorize",
104
- "/api/trackers/linear/callback",
105
- "/api/trackers/linear/webhook",
106
- ]) {
101
+ test("Linear webhook/callback are still public", async () => {
102
+ for (const path of ["/api/trackers/linear/callback", "/api/trackers/linear/webhook"]) {
107
103
  const method = path.endsWith("/webhook") ? "POST" : "GET";
108
104
  const res = await fetch(`http://localhost:${port}${path}`, { method });
109
105
  expect(res.status).not.toBe(401);
110
106
  }
111
107
  });
112
108
 
109
+ test("Linear authorize requires a Bearer (it starts an admin OAuth flow)", async () => {
110
+ const res = await fetch(`http://localhost:${port}/api/trackers/linear/authorize`);
111
+ expect(res.status).toBe(401);
112
+ });
113
+
113
114
  test("Workflow webhook trigger is still public", async () => {
114
115
  const res = await fetch(`http://localhost:${port}/api/webhooks/some-workflow-id`, {
115
116
  method: "POST",
@@ -1,7 +1,7 @@
1
1
  import { Database } from "bun:sqlite";
2
2
  import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
3
3
  import { unlink } from "node:fs/promises";
4
- import { createBunSqliteClient, type DbClient } from "../be/db-client";
4
+ import { createBunSqliteClient, type DbClient, DbTransactionDeadlineError } from "../be/db-client";
5
5
 
6
6
  // Cross-process SQLITE_BUSY retry: a second connection on the same file plays
7
7
  // the external lock holder (litestream checkpoint, CLI access). The client's
@@ -356,7 +356,6 @@ describe("db-client SQLITE_BUSY retry", () => {
356
356
  }) as unknown as typeof main.query);
357
357
  const released = holdWriteLock(1_500);
358
358
 
359
- const startedAt = performance.now();
360
359
  let results: PromiseSettledResult<unknown>[];
361
360
  try {
362
361
  results = await Promise.allSettled(
@@ -369,7 +368,6 @@ describe("db-client SQLITE_BUSY retry", () => {
369
368
  execSpy.mockRestore();
370
369
  querySpy.mockRestore();
371
370
  }
372
- const wallMs = performance.now() - startedAt;
373
371
  const messages = warn.mock.calls.map((c) => String(c[0]));
374
372
  warn.mockRestore();
375
373
 
@@ -393,13 +391,19 @@ describe("db-client SQLITE_BUSY retry", () => {
393
391
  // attempt that waits any time (even 10ms x hundreds of attempts) shows up
394
392
  // here as more spinning attempts than the gate reported probes.
395
393
  expect(spinning).toBe(probes);
396
- // Ungated the crowd needed several seconds of spin rounds after release.
397
- expect(wallMs).toBeLessThan(3_000);
394
+ // No wall-clock bound on purpose. Idle, the crowd finishes in ~1.85s
395
+ // (1.5s hold plus the post-release backoff); a loaded CI runner stretched
396
+ // that past 3s twice although the gate held, so a time limit measured the
397
+ // runner. "Ungated the crowd spins for seconds" is already asserted above
398
+ // by counting spinning attempts, and the per-test timeout still fails a
399
+ // crowd that never drains.
398
400
  const rows = await crowdClient.query<{ n: number }>(
399
401
  "SELECT COUNT(*) AS n FROM items WHERE name LIKE 'crowd-%'",
400
402
  );
401
403
  expect(rows[0]?.n).toBe(writers);
402
- });
404
+ // The test spends 1.5s in the hold alone, so the 5s default leaves a
405
+ // loaded runner under 3s of slack; 15s keeps a hung crowd a failure.
406
+ }, 15_000);
403
407
 
404
408
  test("a held lock past the budget fails fast for the whole crowd", async () => {
405
409
  const crowdClient = createBunSqliteClient(() => main, {
@@ -438,4 +442,52 @@ describe("db-client SQLITE_BUSY retry", () => {
438
442
  );
439
443
  expect(rows.map((r) => r.name)).toEqual(["after-hold", "after-second-hold"]);
440
444
  });
445
+ describe("transaction deadlineAt", () => {
446
+ const names = async () =>
447
+ (await client.query<{ name: string }>("SELECT name FROM items ORDER BY id")).map(
448
+ (r) => r.name,
449
+ );
450
+
451
+ test("BEGIN stops retrying at the deadline instead of outwaiting the holder", async () => {
452
+ const released = holdWriteLock(600);
453
+ const startedAt = performance.now();
454
+ await expect(
455
+ client.transaction(
456
+ async (tx) => {
457
+ await tx.run("INSERT INTO items (name) VALUES ('late')");
458
+ },
459
+ { deadlineAt: Date.now() + 150 },
460
+ ),
461
+ ).rejects.toBeInstanceOf(DbTransactionDeadlineError);
462
+ expect(performance.now() - startedAt).toBeLessThan(500);
463
+ await released;
464
+ expect(await names()).toEqual(["locker"]);
465
+ });
466
+
467
+ test("a callback that outlives the deadline is rolled back, not committed", async () => {
468
+ await expect(
469
+ client.transaction(
470
+ async (tx) => {
471
+ await tx.run("INSERT INTO items (name) VALUES ('slow')");
472
+ await new Promise((r) => setTimeout(r, 120));
473
+ },
474
+ { deadlineAt: Date.now() + 60 },
475
+ ),
476
+ ).rejects.toBeInstanceOf(DbTransactionDeadlineError);
477
+ expect(await names()).toEqual([]);
478
+ // The connection is not left inside the transaction.
479
+ await client.run("INSERT INTO items (name) VALUES ('after')");
480
+ expect(await names()).toEqual(["after"]);
481
+ });
482
+
483
+ test("a transaction inside its deadline commits as before", async () => {
484
+ await client.transaction(
485
+ async (tx) => {
486
+ await tx.run("INSERT INTO items (name) VALUES ('ok')");
487
+ },
488
+ { deadlineAt: Date.now() + 5_000 },
489
+ );
490
+ expect(await names()).toEqual(["ok"]);
491
+ });
492
+ });
441
493
  });