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
| 1 | import { afterEach, expect, test } from 'bun:test'; |
| 2 | import { mkdtemp, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises'; |
| 3 | import { tmpdir } from 'node:os'; |
| 4 | import { dirname, join, resolve } from 'node:path'; |
| 5 | import { fileURLToPath, pathToFileURL } from 'node:url'; |
| 6 | import { createElement } from 'react'; |
| 7 | import { renderToStaticMarkup } from 'react-dom/server'; |
| 8 | import { compile, run } from '@mdx-js/mdx'; |
| 9 | import * as runtime from 'react/jsx-runtime'; |
| 10 | import { applyMdxPreset } from 'fumadocs-mdx/config'; |
| 11 | import { frontmatter } from 'fumadocs-core/content/md/frontmatter'; |
| 12 | import { remarkLLMs } from 'fumadocs-core/mdx-plugins/remark-llms'; |
| 13 | import * as BunServices from '@effect/platform-bun/BunServices'; |
| 14 | import { Effect } from 'effect'; |
| 15 | import type { |
| 16 | ReleaseDocumentationPlan, |
| 17 | ReleaseNoteOptions, |
| 18 | } from '../../scripts/generate-sdk-release-notes'; |
| 19 | |
| 20 | const docsRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); |
| 21 | const fixtures: string[] = []; |
| 22 | |
| 23 | async function fixture() { |
| 24 | const directory = await mkdtemp(join(tmpdir(), 'composio-release-docs-')); |
| 25 | fixtures.push(directory); |
| 26 | return directory; |
| 27 | } |
| 28 | |
| 29 | afterEach(async () => { |
| 30 | await Promise.all( |
| 31 | fixtures.splice(0).map(directory => rm(directory, { recursive: true, force: true })) |
| 32 | ); |
| 33 | }); |
| 34 | |
| 35 | const plan: ReleaseDocumentationPlan = { |
| 36 | releases: [ |
| 37 | { name: '@composio/core', language: 'typescript', newVersion: '0.28.0' }, |
| 38 | { name: '@composio/python-sdk', language: 'python', newVersion: '0.30.1' }, |
| 39 | ], |
| 40 | changesets: [{ summary: 'Keep reviewed migration guidance.' }], |
| 41 | }; |
| 42 | const options = { |
| 43 | releaseId: 'request-42', |
| 44 | date: '2026-11-03', |
| 45 | requestUrl: 'https://github.com/ComposioHQ/composio/issues/42', |
| 46 | }; |
| 47 | |
| 48 | test('historical release code renders with old docs SDK pins while maintained guide code fails', async () => { |
| 49 | const directory = await fixture(); |
| 50 | await symlink(join(docsRoot, 'node_modules'), join(directory, 'node_modules'), 'dir'); |
| 51 | await mkdir(join(directory, 'changelog')); |
| 52 | await mkdir(join(directory, 'guides')); |
| 53 | const content = `---\ntitle: Release fixture\ndate: '2026-11-03'\n---\n\nSee the [release request](${options.requestUrl}).\n\n\`\`\`typescript\nimport { Composio } from '@composio/core';\nconst composio = new Composio({ apiKey: 'fixture' });\ncomposio.unpublishedReleaseFixture();\n\`\`\`\n\n\`\`\`mermaid\ngraph TD\n A --> B\n\`\`\`\n`; |
| 54 | const historical = join(directory, 'changelog/release.mdx'); |
| 55 | const guide = join(directory, 'guides/current.mdx'); |
| 56 | await writeFile(historical, content); |
| 57 | await writeFile(guide, content); |
| 58 | const previousDirectory = process.cwd(); |
| 59 | const previousEnvironment = process.env.NODE_ENV; |
| 60 | process.chdir(directory); |
| 61 | process.env.NODE_ENV = 'production'; |
| 62 | try { |
| 63 | const source: typeof import('../../source.config') = await import( |
| 64 | `${pathToFileURL(join(docsRoot, 'source.config.ts')).href}?release-docs=${Date.now()}` |
| 65 | ); |
| 66 | const compileCollection = async (path: string, historical: boolean) => { |
| 67 | const collection = historical ? source.changelog : source.docs.docs; |
| 68 | const global = source.default.mdxOptions; |
| 69 | const globalOptions = typeof global === 'function' ? await global() : global; |
| 70 | const configured = collection.mdxOptions ?? applyMdxPreset(globalOptions); |
| 71 | const mdxOptions = |
| 72 | typeof configured === 'function' ? await configured('bundler') : configured; |
| 73 | const matter = frontmatter(await readFile(path, 'utf8')); |
| 74 | const file = await compile( |
| 75 | { value: matter.content, path }, |
| 76 | { |
| 77 | ...mdxOptions, |
| 78 | outputFormat: 'function-body', |
| 79 | development: false, |
| 80 | remarkPlugins: [ |
| 81 | ...(mdxOptions.remarkPlugins ?? []), |
| 82 | ...(collection.postprocess?.includeProcessedMarkdown ? [remarkLLMs] : []), |
| 83 | ], |
| 84 | } |
| 85 | ); |
| 86 | return run(String(file), { ...runtime, baseUrl: pathToFileURL(path) }); |
| 87 | }; |
| 88 | const compiled = await compileCollection(historical, true); |
| 89 | const html = renderToStaticMarkup( |
| 90 | createElement(compiled.default, { |
| 91 | components: { |
| 92 | Mermaid: ({ chart }: { chart: string }) => createElement('pre', null, chart), |
| 93 | }, |
| 94 | }) |
| 95 | ); |
| 96 | expect(html).toContain(`href="${options.requestUrl}"`); |
| 97 | expect(html).toContain('unpublishedReleaseFixture'); |
| 98 | expect(html).toContain('graph TD'); |
| 99 | expect(compiled._markdown).toContain(`[release request](${options.requestUrl})`); |
| 100 | expect(compiled._markdown).toContain('unpublishedReleaseFixture'); |
| 101 | await expect(compileCollection(guide, false)).rejects.toThrow('unpublishedReleaseFixture'); |
| 102 | } finally { |
| 103 | process.chdir(previousDirectory); |
| 104 | if (previousEnvironment === undefined) delete process.env.NODE_ENV; |
| 105 | else process.env.NODE_ENV = previousEnvironment; |
| 106 | } |
| 107 | }, 30000); |
| 108 | |
| 109 | const generateSdkReleaseNotes = async ( |
| 110 | directory: string, |
| 111 | value: ReleaseDocumentationPlan, |
| 112 | input: ReleaseNoteOptions |
| 113 | ) => { |
| 114 | const notes = await import('../../scripts/generate-sdk-release-notes'); |
| 115 | return Effect.runPromise( |
| 116 | notes.generateSdkReleaseNotes(directory, value, input).pipe(Effect.provide(BunServices.layer)) |
| 117 | ); |
| 118 | }; |
| 119 | |
| 120 | test('release notes record the planned versions and changeset summaries once', async () => { |
| 121 | const directory = await fixture(); |
| 122 | const contents = await readFile( |
| 123 | join(directory, await generateSdkReleaseNotes(directory, plan, options)), |
| 124 | 'utf8' |
| 125 | ); |
| 126 | expect(contents).toContain('sdkRelease: "request-42"'); |
| 127 | expect(contents).toContain('| Python `composio` | `0.30.1` |'); |
| 128 | expect(contents).toContain('| TypeScript `@composio/core` | `0.28.0` |'); |
| 129 | expect(contents).toContain(`[release request](${options.requestUrl})`); |
| 130 | expect(contents.match(/Keep reviewed migration guidance\./g)).toHaveLength(1); |
| 131 | }); |
| 132 | |
| 133 | test('no-op plans create no changelog', async () => { |
| 134 | const directory = await fixture(); |
| 135 | await expect( |
| 136 | generateSdkReleaseNotes(directory, { ...plan, releases: [], changesets: [] }, options) |
| 137 | ).rejects.toThrow('Nothing to document'); |
| 138 | expect( |
| 139 | await Bun.file(join(directory, 'docs/content/changelog/11-03-26-sdk-request-42.mdx')).exists() |
| 140 | ).toBe(false); |
| 141 | }); |
| 142 | |
| 143 | test('changeset summaries render as literal Markdown, never as MDX code', async () => { |
| 144 | const { literalMdx } = await import('../../scripts/generate-sdk-release-notes'); |
| 145 | const summary = [ |
| 146 | 'import fs from "node:fs"', |
| 147 | 'Adds {globalThis.injected = true} and <script>alert(1)</script>.', |
| 148 | 'Escaped \\`{globalThis.injected = true}` and mismatched `{globalThis.injected = true}`` runs.', |
| 149 | 'Keep `{inline}` and:', |
| 150 | '```ts\nconst value = { a: 1 };\n```', |
| 151 | ].join('\n\n'); |
| 152 | const file = await compile(literalMdx(summary), { |
| 153 | outputFormat: 'function-body', |
| 154 | development: false, |
| 155 | }); |
| 156 | const compiled = await run(String(file), { ...runtime, baseUrl: import.meta.url }); |
| 157 | const html = renderToStaticMarkup(createElement(compiled.default)); |
| 158 | expect((globalThis as { injected?: boolean }).injected).toBeUndefined(); |
| 159 | expect(html).toContain('import fs from'); |
| 160 | expect(html).toContain('{globalThis.injected = true}'); |
| 161 | expect(html).toContain('<script>'); |
| 162 | expect(html).toContain('<code>{inline}</code>'); |
| 163 | expect(html).toContain('const value = { a: 1 };'); |
| 164 | }); |