@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 67 lines 2.55 KB
Raw
1 /**
2 * Production-URL guard for published docs artifacts.
3 *
4 * The "Docs - Update Data" workflow fetches the OpenAPI specs and toolkit data
5 * from STAGING every ~5h and auto-commits the regenerated files. Staging hosts
6 * have leaked into the committed docs before (the API-reference curl base URL
7 * pointed at `http://staging-apollo.composio.dev`), so this test fails CI on any
8 * regeneration PR that ships a non-production host.
9 *
10 * This is an independent oracle: the expected production URL and the banned
11 * staging hosts are stated here directly and are intentionally NOT imported from
12 * scripts/production-api.mjs. A wrong edit to that generator constant must make
13 * this test fail, not move the expectation with it.
14 */
15 import { describe, test, expect } from "bun:test";
16 import { readFile, readdir } from "fs/promises";
17 import { join } from "path";
18
19 const PUBLIC_DIR = join(import.meta.dir, "../../public");
20 const DATA_DIR = join(PUBLIC_DIR, "data");
21
22 const EXPECTED_SERVER = {
23 url: "https://backend.composio.dev",
24 description: "PRODUCTION API",
25 };
26
27 // Any non-production Composio host must never appear in published data.
28 const STAGING_HOST_RE = /staging-[a-z0-9-]*\.composio\.dev/gi;
29
30 const OPENAPI_SPECS = ["openapi.json", "openapi-v3.json"];
31
32 /** Read a file and return the distinct staging hosts it mentions, if any. */
33 async function findStagingHosts(absPath: string): Promise<string[]> {
34 const contents = await readFile(absPath, "utf-8");
35 const matches = contents.match(STAGING_HOST_RE) ?? [];
36 const distinctHosts = [...new Set(matches)];
37 return distinctHosts;
38 }
39
40 describe("OpenAPI specs - production server", () => {
41 test.each(OPENAPI_SPECS)("%s servers[0] is the production API", async (spec) => {
42 const raw = await readFile(join(PUBLIC_DIR, spec), "utf-8");
43 const { servers } = JSON.parse(raw);
44 expect(servers).toEqual([EXPECTED_SERVER]);
45 });
46 });
47
48 describe("Published docs data - no staging hosts", () => {
49 test.each(OPENAPI_SPECS)("%s has no staging host", async (spec) => {
50 const stagingHosts = await findStagingHosts(join(PUBLIC_DIR, spec));
51 expect(stagingHosts).toEqual([]);
52 });
53
54 test("every public/data/*.json has no staging host", async () => {
55 const jsonFiles = (await readdir(DATA_DIR)).filter((file) => file.endsWith(".json"));
56
57 const offenders: string[] = [];
58 for (const file of jsonFiles) {
59 const stagingHosts = await findStagingHosts(join(DATA_DIR, file));
60 if (stagingHosts.length > 0) {
61 offenders.push(`${file}: ${stagingHosts.join(", ")}`);
62 }
63 }
64
65 expect(offenders).toEqual([]);
66 });
67 });