Files
claude-subconscious/scripts/conversation_utils.test.ts
Cameron 04c342327e fix(api): normalize Letta URLs and avoid self-hosted conversations redirect (#31)
Use a shared URL builder across scripts and update createConversation to call /v1/conversations/ with query params to avoid HTTPS->HTTP redirect failures behind reverse proxies. This also deduplicates LETTA_API_BASE handling and adds regression tests for trailing-slash behavior.

👾 Generated with [Letta Code](https://letta.com)

Co-authored-by: Letta Code <noreply@letta.com>
2026-03-17 10:21:03 -07:00

37 lines
1.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
describe('createConversation', () => {
afterEach(() => {
fetchMock.mockReset();
vi.unstubAllEnvs();
vi.resetModules();
});
it('uses trailing-slash conversations endpoint with agent_id query', async () => {
vi.stubEnv('LETTA_BASE_URL', 'https://letta.example.com');
fetchMock.mockResolvedValue({
ok: true,
json: async () => ({ id: 'conversation-123' }),
});
const { createConversation } = await import('./conversation_utils.js');
const conversationId = await createConversation('test-key', 'agent-123');
expect(conversationId).toBe('conversation-123');
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith(
'https://letta.example.com/v1/conversations/?agent_id=agent-123',
expect.objectContaining({
method: 'POST',
headers: expect.objectContaining({
Authorization: 'Bearer test-key',
}),
}),
);
});
});