Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Anthropic from '@anthropic-ai/sdk';
import * as Sentry from '@sentry/node';
import express from 'express';

const PORT = 3333;

function startMockAnthropicServer() {
const app = express();
app.use(express.json());
Expand Down Expand Up @@ -50,16 +48,21 @@ function startMockAnthropicServer() {
},
});
});
return app.listen(PORT);

return new Promise(resolve => {
const server = app.listen(0, () => {
resolve(server);
});
});
}

async function run() {
const server = startMockAnthropicServer();
const server = await startMockAnthropicServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
const client = new Anthropic({
apiKey: 'mock-api-key',
baseURL: `http://localhost:${PORT}/anthropic`,
baseURL: `http://localhost:${server.address().port}/anthropic`,
});

// First test: basic message completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { GoogleGenAI } from '@google/genai';
import * as Sentry from '@sentry/node';
import express from 'express';

const PORT = 3333;

function startMockGoogleGenAIServer() {
const app = express();
app.use(express.json());
Expand Down Expand Up @@ -39,16 +37,20 @@ function startMockGoogleGenAIServer() {
});
});

return app.listen(PORT);
return new Promise(resolve => {
const server = app.listen(0, () => {
resolve(server);
});
});
}

async function run() {
const server = startMockGoogleGenAIServer();
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
const client = new GoogleGenAI({
apiKey: 'mock-api-key',
httpOptions: { baseUrl: `http://localhost:${PORT}` },
httpOptions: { baseUrl: `http://localhost:${server.address().port}` },
});

// Test 1: chats.create and sendMessage flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import express from 'express';
import OpenAI from 'openai';

const PORT = 3333;

function startMockOpenAiServer() {
const app = express();
app.use(express.json());
Expand Down Expand Up @@ -31,14 +29,18 @@ function startMockOpenAiServer() {
},
});
});
return app.listen(PORT);
return new Promise(resolve => {
const server = app.listen(0, () => {
resolve(server);
});
});
}

async function run() {
const server = startMockOpenAiServer();
const server = await startMockOpenAiServer();

const client = new OpenAI({
baseURL: `http://localhost:${PORT}/openai`,
baseURL: `http://localhost:${server.address().port}/openai`,
apiKey: 'mock-api-key',
});

Expand Down