Skip to content

Commit 31a967a

Browse files
committed
fix: resolve TypeScript errors in XAI provider tests
1 parent c9c0959 commit 31a967a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/agent/src/core/llm/providers/xai.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ describe('XAIProvider', () => {
8585
);
8686

8787
// Verify the request body
88-
const requestBody = JSON.parse(vi.mocked(fetch).mock.calls[0][1]!.body as string);
88+
const fetchCall = vi.mocked(fetch).mock.calls[0];
89+
const fetchOptions = fetchCall?.[1];
90+
const requestBody = fetchOptions?.body ? JSON.parse(fetchOptions.body as string) : {};
91+
8992
expect(requestBody).toEqual({
9093
model: 'grok-2-1212',
9194
messages: [{ role: 'user', content: 'Hello' }],
@@ -158,8 +161,11 @@ describe('XAIProvider', () => {
158161
// We're just checking that the structure is correct
159162
expect(result.text).toBe('');
160163
expect(result.toolCalls).toHaveLength(1);
161-
expect(result.toolCalls[0].id).toBe('call_123');
162-
expect(result.toolCalls[0].name).toBe('get_weather');
164+
165+
const firstToolCall = result.toolCalls[0];
166+
expect(firstToolCall?.id).toBe('call_123');
167+
expect(firstToolCall?.name).toBe('get_weather');
168+
163169
expect(result.tokenUsage).toBeInstanceOf(TokenUsage);
164170

165171
// Verify the fetch call
@@ -171,7 +177,10 @@ describe('XAIProvider', () => {
171177
);
172178

173179
// Verify the request body
174-
const requestBody = JSON.parse(vi.mocked(fetch).mock.calls[0][1]!.body as string);
180+
const fetchCall = vi.mocked(fetch).mock.calls[0];
181+
const fetchOptions = fetchCall?.[1];
182+
const requestBody = fetchOptions?.body ? JSON.parse(fetchOptions.body as string) : {};
183+
175184
expect(requestBody.messages).toEqual([
176185
{ role: 'system', content: 'You are a helpful assistant.' },
177186
{ role: 'user', content: 'What is the weather in New York?' },
@@ -252,7 +261,9 @@ describe('XAIProvider', () => {
252261
});
253262

254263
// Verify the request body
255-
const requestBody = JSON.parse(vi.mocked(fetch).mock.calls[0][1]!.body as string);
264+
const fetchCall = vi.mocked(fetch).mock.calls[0];
265+
const fetchOptions = fetchCall?.[1];
266+
const requestBody = fetchOptions?.body ? JSON.parse(fetchOptions.body as string) : {};
256267

257268
expect(requestBody.messages).toEqual([
258269
{ role: 'system', content: 'You are a helpful assistant.' },

0 commit comments

Comments
 (0)