Skip to content

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

6.1 KB
Raw Blame
import { describe, expect, test } from 'bun:test';

import { HOME_INTENTS } from '../../lib/home-navigation';

const read = (path: string) => Bun.file(new URL(`../../${path}`, import.meta.url)).text();

/**
 * Auth guides retain their URLs; managed vs custom auth is listed under
 * Production readiness. Shared connections lives under Extend sessions.
 */
const AUTH_GUIDES = [
  'manually-authenticating',
  'managing-multiple-connected-accounts',
  'importing-existing-connections',
  'custom-app-vs-managed-app',
  'programmatic-auth-configs',
  'controlling-scopes',
  'white-labeling-authentication',
];

const GUIDE_URLS = [
  ...AUTH_GUIDES.map(guide => `/docs/authentication/${guide}`),
  '/docs/extending-sessions/shared-connections',
];

describe('getting-started routing policy', () => {
  test('publishes native plugins for both supported agent hosts', async () => {
    const plugins = await read('content/docs/agent-plugins.mdx');

    expect(plugins).toContain('Agent plugins let Codex and Claude Code use Composio');
    expect(plugins).toContain('composio setup --target codex');
    expect(plugins).toContain('composio setup --target claude');
    expect(plugins).toContain('codex plugin marketplace add');
    expect(plugins).toContain('/plugin marketplace add');
    expect(plugins).toContain('composio search');
    expect(plugins).toContain('composio link');
    expect(plugins).toContain('composio execute');
    expect(plugins).toContain('composio --install-skill composio-cli claude');
    expect(plugins).toContain('composio --install-skill composio-cli codex');
    expect(plugins).toContain('composio setup --target auto --yes');
    expect(plugins).toContain('### Codex');
    expect(plugins).toContain('### Claude Code');
    expect(plugins).not.toContain('<Tabs');
  });

  test('keeps native plugins ahead of CLI and explicit MCP on Welcome', () => {
    expect(HOME_INTENTS[1].links.map(link => link.href)).toEqual([
      '/docs/agent-plugins',
      '/docs/cli',
      '/docs/composio-connect',
    ]);
  });

  test('keeps progressive authentication guides in the human hub and the sidebar', async () => {
    const [authentication, authMeta, sessionsMeta, readinessMeta] = await Promise.all([
      read('content/docs/authentication/index.mdx'),
      read('content/docs/authentication/meta.json'),
      read('content/docs/extending-sessions/meta.json'),
      read('content/docs/poc-to-prod/meta.json'),
    ]);
    const authPages = JSON.parse(authMeta).pages as string[];
    const sessionPages = JSON.parse(sessionsMeta).pages as string[];

    for (const guide of AUTH_GUIDES) {
      expect(authentication).toContain(`href="/docs/authentication/${guide}"`);
      if (guide === 'custom-app-vs-managed-app') {
        expect(authPages).not.toContain(guide);
        expect(JSON.parse(readinessMeta).pages).toContain(`../authentication/${guide}`);
      } else {
        expect(authPages).toContain(guide);
      }
    }

    expect(authentication).toContain('href="/docs/extending-sessions/shared-connections"');
    expect(sessionPages).toContain('shared-connections');
  });

  /**
   * Asserts the generated bytes, not the meta.json inputs. These guides used to
   * be listed in llms.txt by a hardcoded `AUTHENTICATION_GUIDE_URLS` constant
   * because they had been dropped from the page tree; they are emitted by the
   * page-tree walk now, so a regression in that walk — not just in the meta
   * files — has to fail something.
   */
  test('emits every authentication guide into llms.txt exactly once', async () => {
    const { GET } = await import('../../app/llms.txt/route');
    const llms = await (await GET()).text();

    for (const url of ['/docs/authentication', ...GUIDE_URLS]) {
      const occurrences = llms.split(`https://docs.composio.dev${url}.md`).length - 1;
      expect(occurrences, `${url} appears ${occurrences}x in llms.txt`).toBe(1);
    }
  });

  /**
   * `nearest` is the closest preceding heading of any level. Markdown headings
   * do not close, so it is what an agent reads a URL as belonging to: a page
   * emitted after a folder reads as one of that folder's children even though
   * the sidebar shows it as a sibling.
   */
  test('files each page under the section it belongs to', async () => {
    const { GET } = await import('../../app/llms.txt/route');
    const lines = (await (await GET()).text()).split('\n');

    const sectionOf = (url: string) => {
      const index = lines.findIndex(line => line.endsWith(`${url}.md`));
      expect(index, `${url} missing from llms.txt`).toBeGreaterThan(-1);
      const preceding = lines.slice(0, index);
      return {
        section: preceding.findLast(line => line.startsWith('## ')),
        nearest: preceding.findLast(line => line.startsWith('#')),
      };
    };

    for (const guide of AUTH_GUIDES) {
      expect(sectionOf(`/docs/authentication/${guide}`)).toEqual({
        section: guide === 'custom-app-vs-managed-app' ? '## Guides' : '## Core concepts',
        nearest: guide === 'custom-app-vs-managed-app' ? '### Production readiness' : '### Authentication',
      });
    }

    expect(sectionOf('/docs/authentication')).toEqual({
      section: '## Core concepts',
      nearest: '### Authentication',
    });

    expect(sectionOf('/docs/extending-sessions/shared-connections')).toEqual({
      section: '## Guides',
      nearest: '### Extend sessions',
    });

    // Siblings that follow the Authentication folder in meta.json. These fell
    // under `### Authentication` when folders were emitted in meta.json order.
    for (const sibling of ['/docs/triggers', '/docs/skills']) {
      expect(sectionOf(sibling)).toEqual({
        section: '## Core concepts',
        nearest: '## Core concepts',
      });
    }

    // Same failure mode, pre-dating this folder: Get Started's pages sit after
    // the `providers` folder and used to read as SDKs-and-frameworks children.
    for (const sibling of ['/docs/agent-plugins', '/docs/cli', '/docs/composio-connect']) {
      expect(sectionOf(sibling)).toEqual({
        section: '## Get Started',
        nearest: '## Get Started',
      });
    }

    expect(lines).not.toContain('## Authentication guides');
  });
});