Skip to content

Commit ed81e9a

Browse files
committed
fix unit tests
1 parent ad9c7a9 commit ed81e9a

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

.agents/__tests__/context-pruner.test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,22 @@ describe('context-pruner edge cases', () => {
307307
content,
308308
})
309309

310-
const createTerminalToolMessage = (command: string, output: string): any => ({
310+
const createTerminalToolMessage = (
311+
command: string,
312+
output: string,
313+
): ToolMessage => ({
311314
role: 'tool',
312-
content: {
313-
type: 'tool-result',
314-
toolCallId: 'test-id',
315-
toolName: 'run_terminal_command',
316-
output: [
317-
{
318-
type: 'json',
319-
value: {
320-
command,
321-
stdout: output,
322-
},
315+
toolCallId: 'test-id',
316+
toolName: 'run_terminal_command',
317+
content: [
318+
{
319+
type: 'json',
320+
value: {
321+
command,
322+
stdout: output,
323323
},
324-
],
325-
},
324+
},
325+
],
326326
})
327327

328328
const runHandleSteps = (messages: Message[]) => {
@@ -441,21 +441,21 @@ describe('context-pruner edge cases', () => {
441441
// Create content large enough to exceed 200k token limit to trigger pruning
442442
const largeContent = 'x'.repeat(150000)
443443

444-
const createToolMessage = (toolName: string, size: number): any => ({
444+
const createToolMessage = (
445+
toolName: string,
446+
size: number,
447+
): ToolMessage => ({
445448
role: 'tool',
446-
content: {
447-
type: 'tool-result',
448-
toolCallId: 'test-id',
449-
toolName,
450-
output: [
451-
{
452-
type: 'json',
453-
value: {
454-
data: 'a'.repeat(size),
455-
},
449+
toolCallId: 'test-id',
450+
toolName,
451+
content: [
452+
{
453+
type: 'json',
454+
value: {
455+
data: 'a'.repeat(size),
456456
},
457-
],
458-
},
457+
},
458+
],
459459
})
460460

461461
const messages = [

common/src/util/__tests__/messages.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ describe('convertCbToModelMessages', () => {
210210
})
211211

212212
expect(result).toEqual([
213-
{
213+
expect.objectContaining({
214214
role: 'user',
215215
content: [
216216
expect.objectContaining({
217217
type: 'text',
218218
}),
219219
],
220-
},
220+
}),
221221
])
222222
expect((result as any)[0].content[0].text).toContain('<tool_result>')
223223
})
@@ -243,14 +243,14 @@ describe('convertCbToModelMessages', () => {
243243
})
244244

245245
expect(result).toEqual([
246-
{
246+
expect.objectContaining({
247247
role: 'user',
248248
content: [
249249
expect.objectContaining({
250250
type: 'file',
251251
}),
252252
],
253-
},
253+
}),
254254
])
255255
})
256256

@@ -260,7 +260,10 @@ describe('convertCbToModelMessages', () => {
260260
role: 'tool',
261261
toolName: 'test_tool',
262262
toolCallId: 'call_123',
263-
content: [toolJsonContent({ result1: 'success' })],
263+
content: [
264+
toolJsonContent({ result1: 'success' }),
265+
toolJsonContent({ result2: 'also success' }),
266+
],
264267
},
265268
]
266269

@@ -269,6 +272,7 @@ describe('convertCbToModelMessages', () => {
269272
includeCacheControl: false,
270273
})
271274

275+
console.dir({ result }, { depth: null })
272276
// Multiple tool outputs are aggregated into one user message
273277
expect(result).toEqual([
274278
expect.objectContaining({

packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ describe('runProgrammaticStep', () => {
330330
}
331331
options.toolResults.push(toolResult)
332332

333-
options.state.messages.push({
334-
role: 'tool',
335-
content: toolResult,
336-
})
333+
options.state.messages.push(toolResult)
337334
}
338335
// Return a value to satisfy the call
339336
return {}

packages/agent-runtime/src/tools/tool-executor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ export function executeToolCall<T extends ToolName>(
299299
toolResults.push(toolResult)
300300

301301
if (!excludeToolFromMessageHistory) {
302-
state.messages.push({
303-
role: 'tool' as const,
304-
content: toolResult,
305-
})
302+
state.messages.push(toolResult)
306303
}
307304

308305
// After tool completes, resolve any pending creditsUsed promise

0 commit comments

Comments
 (0)