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
4 changes: 4 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default [
setTimeout: 'readonly',
NodeJS: 'readonly',
require: 'readonly',
fetch: 'readonly',
URLSearchParams: 'readonly',
},
},
plugins: {
Expand Down Expand Up @@ -50,6 +52,8 @@ export default [
__dirname: 'readonly',
clearTimeout: 'readonly',
setTimeout: 'readonly',
global: 'readonly',
fetch: 'readonly',
},
},
plugins: {
Expand Down
49 changes: 30 additions & 19 deletions src/__tests__/branches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
} from "../shared/elevenlabs-api";
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";

const TEST_CTX = { apiKey: "test-key", baseUrl: "https://api.test" };

const realFetch = global.fetch;
afterEach(() => {
global.fetch = realFetch;
});

function mockFetch(response: Record<string, unknown>): jest.Mock {
const fetchMock = jest.fn().mockResolvedValue({
ok: true,
json: async () => response,
});
global.fetch = fetchMock as unknown as typeof fetch;
return fetchMock;
}

describe("Agent branch support", () => {
function makeMockClient(opts: {
branches?: Array<{
Expand Down Expand Up @@ -190,14 +206,14 @@
});

describe("updateAgentApi with branchId", () => {
it("should not include branchId in payload when not provided", async () => {
const client = makeMockClient();
it("should not include branch_id query param when not provided", async () => {
const fetchMock = mockFetch({ agent_id: "agent_123" });
const conversationConfig = {
agent: { prompt: { prompt: "hi", temperature: 0 } },
} as unknown as Record<string, unknown>;

await updateAgentApi(
client,
TEST_CTX,
"agent_123",
"Test Agent",
conversationConfig,
Expand All @@ -207,21 +223,18 @@
"v1.0"
);

const [, payload] = (
client.conversationalAi.agents.update as jest.Mock
).mock.calls[0];

expect(payload.branchId).toBeUndefined();
const [url] = fetchMock.mock.calls[0];
expect(url).toBe("https://api.test/v1/convai/agents/agent_123");
});

it("should include branchId in payload when provided", async () => {
const client = makeMockClient();
it("should include branch_id query param when provided", async () => {
const fetchMock = mockFetch({ agent_id: "agent_123" });
const conversationConfig = {
agent: { prompt: { prompt: "hi", temperature: 0 } },
} as unknown as Record<string, unknown>;

await updateAgentApi(
client,
TEST_CTX,
"agent_123",
"Test Agent",
conversationConfig,
Expand All @@ -232,22 +245,20 @@
"agtbrch_feat456"
);

const [agentId, payload] = (
client.conversationalAi.agents.update as jest.Mock
).mock.calls[0];

expect(agentId).toBe("agent_123");
expect(payload.branchId).toBe("agtbrch_feat456");
const [url] = fetchMock.mock.calls[0];
expect(url).toBe(
"https://api.test/v1/convai/agents/agent_123?branch_id=agtbrch_feat456"
);
});

it("should return branchId from API response", async () => {
const client = makeMockClient();
mockFetch({ agent_id: "agent_123", branch_id: "agtbrch_feat" });
const conversationConfig = {
agent: { prompt: { prompt: "hi", temperature: 0 } },
} as unknown as Record<string, unknown>;

const result = await updateAgentApi(
client,
TEST_CTX,
"agent_123",
"Test Agent",
conversationConfig,
Expand Down Expand Up @@ -380,7 +391,7 @@
const loaded = (await readConfig(agentsConfigPath)) as typeof agentsConfig;

// Old agent has no branches property
expect((loaded.agents[0] as any).branches).toBeUndefined();

Check warning on line 394 in src/__tests__/branches.test.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected any. Specify a different type
// New agent has branches
expect(loaded.agents[1].branches).toBeDefined();
expect(loaded.agents[1].branches!.staging.branch_id).toBe("agtbrch_stag");
Expand Down
Loading
Loading