Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * Regression tests for the raw-API-to-Toolkit transformation in |
| 3 | * scripts/generate-toolkits.ts. |
| 4 | * |
| 5 | * The zod-based rewrite of transformToolkit/authConfigFields/ |
| 6 | * transformAuthConfigField parses raw API payloads leniently and rebuilds the |
| 7 | * toolkit catalog field by field, so these tests pin the shapes |
| 8 | * public/data/toolkits.json is expected to carry (see toolkit-schema.test.ts |
| 9 | * for the sibling API-schema coverage). |
| 10 | * |
| 11 | * Only the pure transforms are exercised here — fetchToolkits, |
| 12 | * fetchToolsForToolkit, fetchTriggersForToolkit, fetchAuthConfigDetails, and |
| 13 | * main() all perform network I/O and are intentionally not covered by this |
| 14 | * suite. |
| 15 | */ |
| 16 | import { describe, test, expect } from "bun:test"; |
| 17 | import { |
| 18 | authConfigFields, |
| 19 | parseNamedItems, |
| 20 | shouldPublishToolkit, |
| 21 | transformAuthConfigField, |
| 22 | transformAuthConfigDetail, |
| 23 | transformToolkit, |
| 24 | } from "../../scripts/generate-toolkits"; |
| 25 | import { |
| 26 | generateIndexMdx, |
| 27 | generateToolMdx, |
| 28 | } from "../../scripts/generate-meta-tools"; |
| 29 | |
| 30 | describe("transformToolkit", () => { |
| 31 | test("excludes the synthetic test_app catalog residue from public docs", () => { |
| 32 | expect(shouldPublishToolkit({ slug: "test_app" })).toBe(false); |
| 33 | expect(shouldPublishToolkit({ slug: "TEST_APP" })).toBe(false); |
| 34 | expect(shouldPublishToolkit({ slug: "gmail" })).toBe(true); |
| 35 | }); |
| 36 | |
| 37 | test("maps a representative full toolkit object end to end", () => { |
| 38 | const toolkit = transformToolkit({ |
| 39 | slug: "GITHUB", |
| 40 | name: "GitHub", |
| 41 | description: "toolkit-level description", |
| 42 | meta: { |
| 43 | logo: "https://logo.example/github.png", |
| 44 | description: "meta description wins over toolkit description", |
| 45 | categories: [{ name: "dev-tools" }, "productivity"], |
| 46 | }, |
| 47 | auth_schemes: ["OAUTH2", "API_KEY", 123], |
| 48 | composio_managed_auth_schemes: ["OAUTH2"], |
| 49 | tool_count: 42, |
| 50 | trigger_count: 3, |
| 51 | }); |
| 52 | |
| 53 | expect(toolkit.slug).toBe("github"); |
| 54 | expect(toolkit.name).toBe("GitHub"); |
| 55 | expect(toolkit.logo).toBe("https://logo.example/github.png"); |
| 56 | expect(toolkit.description).toBe("meta description wins over toolkit description"); |
| 57 | expect(toolkit.category).toBe("dev-tools"); |
| 58 | expect(toolkit.authSchemes).toEqual(["OAUTH2", "API_KEY"]); |
| 59 | expect(toolkit.composioManagedAuthSchemes).toEqual(["OAUTH2"]); |
| 60 | expect(toolkit.toolCount).toBe(42); |
| 61 | expect(toolkit.triggerCount).toBe(3); |
| 62 | expect(toolkit.version).toBeNull(); |
| 63 | expect(toolkit.tools).toEqual([]); |
| 64 | expect(toolkit.triggers).toEqual([]); |
| 65 | }); |
| 66 | |
| 67 | test("slug is lowercased regardless of API casing", () => { |
| 68 | const toolkit = transformToolkit({ slug: "SlAcK" }); |
| 69 | expect(toolkit.slug).toBe("slack"); |
| 70 | }); |
| 71 | |
| 72 | test("falls back to logo/description/auth_schemes on toolkit root when meta is absent", () => { |
| 73 | const toolkit = transformToolkit({ |
| 74 | slug: "notion", |
| 75 | logo: "https://logo.example/notion.png", |
| 76 | description: "root description", |
| 77 | authSchemes: ["OAUTH2"], |
| 78 | composioManagedAuthSchemes: ["OAUTH2"], |
| 79 | }); |
| 80 | |
| 81 | expect(toolkit.logo).toBe("https://logo.example/notion.png"); |
| 82 | expect(toolkit.description).toBe("root description"); |
| 83 | expect(toolkit.authSchemes).toEqual(["OAUTH2"]); |
| 84 | expect(toolkit.composioManagedAuthSchemes).toEqual(["OAUTH2"]); |
| 85 | }); |
| 86 | |
| 87 | test("omits composioManagedAuthSchemes entirely when empty (not an empty array)", () => { |
| 88 | const toolkit = transformToolkit({ slug: "test" }); |
| 89 | expect(toolkit).not.toHaveProperty("composioManagedAuthSchemes"); |
| 90 | }); |
| 91 | |
| 92 | test("empty-string name falls back to the original-casing slug", () => { |
| 93 | const toolkit = transformToolkit({ slug: "GitHub", name: "" }); |
| 94 | expect(toolkit.name).toBe("GitHub"); |
| 95 | }); |
| 96 | |
| 97 | test("missing name falls back to the original-casing slug", () => { |
| 98 | const toolkit = transformToolkit({ slug: "GitHub" }); |
| 99 | expect(toolkit.name).toBe("GitHub"); |
| 100 | }); |
| 101 | |
| 102 | test("empty meta values fall back to root logo and description", () => { |
| 103 | const toolkit = transformToolkit({ |
| 104 | slug: "github", |
| 105 | logo: "https://logo.example/github.png", |
| 106 | description: "root description", |
| 107 | meta: { logo: "", description: "" }, |
| 108 | }); |
| 109 | |
| 110 | expect(toolkit.logo).toBe("https://logo.example/github.png"); |
| 111 | expect(toolkit.description).toBe("root description"); |
| 112 | }); |
| 113 | |
| 114 | test("non-string tool_count/trigger_count are dropped in favor of the numeric fallback", () => { |
| 115 | const toolkit = transformToolkit({ |
| 116 | slug: "test", |
| 117 | tool_count: "42", |
| 118 | trigger_count: null, |
| 119 | }); |
| 120 | expect(toolkit.toolCount).toBe(0); |
| 121 | expect(toolkit.triggerCount).toBe(0); |
| 122 | }); |
| 123 | |
| 124 | test("non-string auth_schemes members are filtered out of the array", () => { |
| 125 | const toolkit = transformToolkit({ |
| 126 | slug: "test", |
| 127 | auth_schemes: ["OAUTH2", 42, null, "API_KEY", { scheme: "x" }], |
| 128 | }); |
| 129 | expect(toolkit.authSchemes).toEqual(["OAUTH2", "API_KEY"]); |
| 130 | }); |
| 131 | |
| 132 | test("non-array auth_schemes yields an empty array, never a non-array value", () => { |
| 133 | const toolkit = transformToolkit({ slug: "test", auth_schemes: "OAUTH2" }); |
| 134 | expect(Array.isArray(toolkit.authSchemes)).toBe(true); |
| 135 | expect(toolkit.authSchemes).toEqual([]); |
| 136 | }); |
| 137 | |
| 138 | test("category falls back to null when the first category entry has no string name", () => { |
| 139 | const toolkit = transformToolkit({ |
| 140 | slug: "test", |
| 141 | meta: { categories: [{ notName: "x" }] }, |
| 142 | }); |
| 143 | expect(toolkit.category).toBeNull(); |
| 144 | }); |
| 145 | |
| 146 | test("category is null when categories is absent or not an array", () => { |
| 147 | expect(transformToolkit({ slug: "test" }).category).toBeNull(); |
| 148 | expect(transformToolkit({ slug: "test", meta: { categories: "dev-tools" } }).category).toBeNull(); |
| 149 | }); |
| 150 | |
| 151 | test("empty category names fall back to null", () => { |
| 152 | expect(transformToolkit({ slug: "test", meta: { categories: [""] } }).category).toBeNull(); |
| 153 | expect( |
| 154 | transformToolkit({ slug: "test", meta: { categories: [{ name: "" }] } }).category |
| 155 | ).toBeNull(); |
| 156 | }); |
| 157 | |
| 158 | test("malformed/empty input objects do not throw", () => { |
| 159 | expect(() => transformToolkit({})).not.toThrow(); |
| 160 | expect(() => transformToolkit(null)).not.toThrow(); |
| 161 | expect(() => transformToolkit(undefined)).not.toThrow(); |
| 162 | expect(() => transformToolkit("not-an-object")).not.toThrow(); |
| 163 | expect(() => transformToolkit(42)).not.toThrow(); |
| 164 | expect(() => transformToolkit([])).not.toThrow(); |
| 165 | |
| 166 | const toolkit = transformToolkit(null); |
| 167 | expect(toolkit.slug).toBe(""); |
| 168 | expect(toolkit.name).toBe(""); |
| 169 | expect(toolkit.logo).toBeNull(); |
| 170 | expect(toolkit.description).toBe(""); |
| 171 | expect(toolkit.authSchemes).toEqual([]); |
| 172 | expect(toolkit.toolCount).toBe(0); |
| 173 | expect(toolkit.triggerCount).toBe(0); |
| 174 | }); |
| 175 | }); |
| 176 | |
| 177 | describe("transformAuthConfigField", () => { |
| 178 | test("maps a representative required field", () => { |
| 179 | const field = transformAuthConfigField( |
| 180 | { |
| 181 | name: "api_key", |
| 182 | displayName: "API Key", |
| 183 | type: "string", |
| 184 | description: "Your API key", |
| 185 | required: true, |
| 186 | default: "fallback-value", |
| 187 | }, |
| 188 | false |
| 189 | ); |
| 190 | |
| 191 | expect(field).toEqual({ |
| 192 | name: "api_key", |
| 193 | displayName: "API Key", |
| 194 | type: "string", |
| 195 | description: "Your API key", |
| 196 | required: true, |
| 197 | default: "fallback-value", |
| 198 | }); |
| 199 | }); |
| 200 | |
| 201 | test("displayName falls back to name when absent", () => { |
| 202 | const field = transformAuthConfigField({ name: "client_id" }, true); |
| 203 | expect(field.displayName).toBe("client_id"); |
| 204 | }); |
| 205 | |
| 206 | test("empty displayName falls back to name", () => { |
| 207 | const field = transformAuthConfigField({ name: "client_id", displayName: "" }, true); |
| 208 | expect(field.displayName).toBe("client_id"); |
| 209 | }); |
| 210 | |
| 211 | test("required falls back to the caller-supplied requirement when the API omits it", () => { |
| 212 | const required = transformAuthConfigField({ name: "x" }, true); |
| 213 | const optional = transformAuthConfigField({ name: "x" }, false); |
| 214 | expect(required.required).toBe(true); |
| 215 | expect(optional.required).toBe(false); |
| 216 | }); |
| 217 | |
| 218 | test("type defaults to 'string' when missing or non-string", () => { |
| 219 | expect(transformAuthConfigField({ name: "x" }, false).type).toBe("string"); |
| 220 | expect(transformAuthConfigField({ name: "x", type: 7 }, false).type).toBe("string"); |
| 221 | }); |
| 222 | |
| 223 | test("scalar defaults are preserved as strings while structured values are dropped", () => { |
| 224 | expect(transformAuthConfigField({ name: "x", default: 5 }, false).default).toBe("5"); |
| 225 | expect(transformAuthConfigField({ name: "x", default: false }, false).default).toBe("false"); |
| 226 | expect(transformAuthConfigField({ name: "x", default: { a: 1 } }, false).default).toBeNull(); |
| 227 | expect(transformAuthConfigField({ name: "x", default: ["a"] }, false).default).toBeNull(); |
| 228 | expect(transformAuthConfigField({ name: "x", default: null }, false).default).toBeNull(); |
| 229 | expect(transformAuthConfigField({ name: "x" }, false).default).toBeNull(); |
| 230 | }); |
| 231 | |
| 232 | test("malformed/empty input does not throw", () => { |
| 233 | expect(() => transformAuthConfigField(null, false)).not.toThrow(); |
| 234 | expect(() => transformAuthConfigField(undefined, true)).not.toThrow(); |
| 235 | expect(() => transformAuthConfigField("nope", false)).not.toThrow(); |
| 236 | expect(() => transformAuthConfigField(42, false)).not.toThrow(); |
| 237 | |
| 238 | const field = transformAuthConfigField(null, true); |
| 239 | expect(field.name).toBe(""); |
| 240 | expect(field.displayName).toBe(""); |
| 241 | expect(field.type).toBe("string"); |
| 242 | expect(field.description).toBe(""); |
| 243 | expect(field.required).toBe(true); |
| 244 | expect(field.default).toBeNull(); |
| 245 | }); |
| 246 | }); |
| 247 | |
| 248 | describe("transformAuthConfigDetail", () => { |
| 249 | test("empty names fall back to the auth mode", () => { |
| 250 | const detail = transformAuthConfigDetail({ mode: "oauth2", name: "" }); |
| 251 | expect(detail?.name).toBe("oauth2"); |
| 252 | }); |
| 253 | |
| 254 | test("non-object entries are dropped", () => { |
| 255 | expect(transformAuthConfigDetail(null)).toBeNull(); |
| 256 | expect(transformAuthConfigDetail("oauth2")).toBeNull(); |
| 257 | }); |
| 258 | }); |
| 259 | |
| 260 | describe("authConfigFields", () => { |
| 261 | const rawAuthConfig = { |
| 262 | fields: { |
| 263 | auth_config_creation: { |
| 264 | required: [{ name: "client_id" }, { name: "client_secret" }], |
| 265 | optional: [{ name: "redirect_url" }], |
| 266 | }, |
| 267 | connected_account_initiation: { |
| 268 | required: [{ name: "code" }], |
| 269 | optional: "not-an-array", |
| 270 | }, |
| 271 | }, |
| 272 | }; |
| 273 | |
| 274 | test("extracts the required/optional field lists for a given phase", () => { |
| 275 | const required = authConfigFields(rawAuthConfig, "auth_config_creation", "required"); |
| 276 | const optional = authConfigFields(rawAuthConfig, "auth_config_creation", "optional"); |
| 277 | |
| 278 | expect(required.map(f => f.name)).toEqual(["client_id", "client_secret"]); |
| 279 | expect(required.every(f => f.required)).toBe(true); |
| 280 | expect(optional.map(f => f.name)).toEqual(["redirect_url"]); |
| 281 | expect(optional.every(f => f.required)).toBe(false); |
| 282 | }); |
| 283 | |
| 284 | test("non-array requirement lists always yield an array, never throwing", () => { |
| 285 | const optional = authConfigFields(rawAuthConfig, "connected_account_initiation", "optional"); |
| 286 | expect(Array.isArray(optional)).toBe(true); |
| 287 | expect(optional).toEqual([]); |
| 288 | }); |
| 289 | |
| 290 | test("malformed/empty input objects do not throw and yield an empty array", () => { |
| 291 | expect(() => authConfigFields({}, "auth_config_creation", "required")).not.toThrow(); |
| 292 | expect(authConfigFields({}, "auth_config_creation", "required")).toEqual([]); |
| 293 | expect(authConfigFields({ fields: null }, "auth_config_creation", "required")).toEqual([]); |
| 294 | }); |
| 295 | }); |
| 296 | |
| 297 | describe("generated meta-tool MDX", () => { |
| 298 | test("encodes table delimiters in generated index descriptions", () => { |
| 299 | const tool = { |
| 300 | slug: "COMPOSIO_X", |
| 301 | displayName: "Composio X", |
| 302 | description: String.raw`Compare \| and | values`, |
| 303 | }; |
| 304 | |
| 305 | expect(generateIndexMdx([tool])).toContain(String.raw`Compare \| and | values`); |
| 306 | }); |
| 307 | |
| 308 | test("serializes generated frontmatter descriptions as YAML strings", () => { |
| 309 | const tool = { |
| 310 | slug: "COMPOSIO_X", |
| 311 | displayName: "Composio X", |
| 312 | description: 'Use "quotes" at C:\\tools', |
| 313 | }; |
| 314 | |
| 315 | expect(generateToolMdx(tool)).toContain('description: "Use \\"quotes\\" at C:\\\\tools"'); |
| 316 | }); |
| 317 | |
| 318 | test("serializes generated frontmatter titles as YAML strings", () => { |
| 319 | const tool = { |
| 320 | slug: "COMPOSIO_X", |
| 321 | displayName: 'Search: "Advanced" Tools', |
| 322 | description: "Searches", |
| 323 | }; |
| 324 | |
| 325 | expect(generateToolMdx(tool)).toContain('title: "Search: \\"Advanced\\" Tools"\n'); |
| 326 | expect(generateToolMdx({ ...tool, displayName: "Line\n---\n{evil}" })).toContain('title: "Line\\n---\\n{evil}"\n'); |
| 327 | expect(generateToolMdx({ ...tool, displayName: "null" })).toContain('title: "null"\n'); |
| 328 | expect(generateToolMdx({ ...tool, displayName: "Search Tools" })).toContain("title: Search Tools\n"); |
| 329 | }); |
| 330 | }); |
| 331 | |
| 332 | describe("parseNamedItems", () => { |
| 333 | test("empty names fall back to display names", () => { |
| 334 | expect( |
| 335 | parseNamedItems([ |
| 336 | { |
| 337 | slug: "GMAIL_SEND_EMAIL", |
| 338 | name: "", |
| 339 | display_name: "Send email", |
| 340 | description: "Sends an email", |
| 341 | }, |
| 342 | ])[0]?.name |
| 343 | ).toBe("Send email"); |
| 344 | }); |
| 345 | }); |