← Files ACE Carousel CreatorARCHIVED FILE
tests/http.integration.mjs
2 KB · Nov 3, 2026 · 19:19 UTC
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { unzipSync } from 'fflate';
import { httpServer } from '../src/server.mjs';
test('ChatGPT HTTP transport can discover tools, create a project, and download its bytes', async () => {
const configuration = { publicURL: 'http://127.0.0.1:0' };
const app = httpServer(configuration);
await new Promise((resolve, reject) => { app.once('error', reject); app.listen(0, '127.0.0.1', resolve); });
configuration.publicURL = `http://127.0.0.1:${app.address().port}`;
const client = new Client({ name: 'browser-integration-test', version: '1' });
try {
await client.connect(new StreamableHTTPClientTransport(new URL(`${configuration.publicURL}/mcp`)));
assert.equal((await client.listTools()).tools.length, 3);
const yaml = await readFile(new URL('../examples/creator-demo.yaml', import.meta.url), 'utf8');
const result = await client.callTool({ name: 'create_carousel', arguments: { yaml, filename: 'Тест из браузера' } });
assert.equal(result.isError, undefined);
assert.equal(result.structuredContent.slides, 5);
const response = await fetch(result.structuredContent.download_url);
assert.equal(response.status, 200);
assert.match(response.headers.get('content-disposition'), /attachment/);
assert.equal(response.headers.get('cache-control'), 'private, no-store');
const files = unzipSync(new Uint8Array(await response.arrayBuffer()));
assert.ok(Buffer.from(files['carousel.yaml']).toString().includes('От идеи\\nк карусели'));
assert.equal((await fetch(`${configuration.publicURL}/downloads/${'0'.repeat(48)}/other.carousel`)).status, 404);
} finally {
await client.close();
app.closeAllConnections();
await new Promise(resolve => app.close(resolve));
}
});
SHA-256: f77721afd3db1659dda0874702326c703b627185729fb2f462c1ec3dd94aa166